use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class ClientServiceFacadeWebTier method createNewClient.
@Override
public CustomerDetailsDto createNewClient(ClientCreationDetail clientCreationDetail, MeetingDto meetingDto, List<SavingsDetailDto> allowedSavingProducts) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
try {
ClientBO client = null;
List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(clientCreationDetail.getFeesToApply());
List<SavingsOfferingBO> selectedOfferings = new ArrayList<SavingsOfferingBO>();
for (Short productId : clientCreationDetail.getSelectedSavingProducts()) {
if (productId != null) {
for (SavingsDetailDto savingsOffering : allowedSavingProducts) {
if (productId.equals(savingsOffering.getPrdOfferingId())) {
SavingsOfferingBO savingsProduct = savingsProductDao.findById(productId.intValue());
selectedOfferings.add(savingsProduct);
}
}
}
}
List<ClientInitialSavingsOfferingEntity> offeringsAssociatedInCreate = new ArrayList<ClientInitialSavingsOfferingEntity>();
for (SavingsOfferingBO offering : selectedOfferings) {
offeringsAssociatedInCreate.add(new ClientInitialSavingsOfferingEntity(null, offering));
}
Short personnelId = null;
Short officeId = null;
ClientNameDetailDto spouseNameDetailView = null;
if (ClientRules.isFamilyDetailsRequired()) {
// actionForm.setFamilyDateOfBirth();
// actionForm.constructFamilyDetails();
} else {
spouseNameDetailView = clientCreationDetail.getSpouseFatherName();
}
String secondMiddleName = null;
ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getClientNameDetailDto());
ClientNameDetailEntity spouseFatherNameDetailEntity = null;
if (spouseNameDetailView != null) {
spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, spouseNameDetailView);
}
ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
DateTime dob = new DateTime(clientCreationDetail.getDateOfBirth());
boolean trainedBool = clientCreationDetail.isTrained();
DateTime trainedDateTime = null;
if (clientCreationDetail.getTrainedDate() != null) {
trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
}
String clientFirstName = clientCreationDetail.getClientNameDetailDto().getFirstName();
String clientLastName = clientCreationDetail.getClientNameDetailDto().getLastName();
String secondLastName = clientCreationDetail.getClientNameDetailDto().getSecondLastName();
CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
PersonnelBO formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
Address address = null;
if (clientCreationDetail.getAddress() != null) {
AddressDto dto = clientCreationDetail.getAddress();
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
if (YesNoFlag.YES.getValue().equals(clientCreationDetail.getGroupFlag())) {
Integer parentGroupId = Integer.parseInt(clientCreationDetail.getParentGroupId());
CustomerBO group = this.customerDao.findCustomerById(parentGroupId);
if (group.getPersonnel() != null) {
personnelId = group.getPersonnel().getPersonnelId();
}
officeId = group.getOffice().getOfficeId();
client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), group, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
if (ClientRules.isFamilyDetailsRequired()) {
client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
}
this.customerService.createClient(client, client.getCustomerMeetingValue(), feesForCustomerAccount, selectedOfferings);
} else {
personnelId = clientCreationDetail.getLoanOfficerId();
officeId = clientCreationDetail.getOfficeId();
PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(personnelId);
OfficeBO office = this.officeDao.findOfficeById(officeId);
int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
MeetingBO clientMeeting = null;
if (meetingDto != null) {
clientMeeting = new MeetingFactory().create(meetingDto);
clientMeeting.setUserContext(userContext);
}
client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
if (ClientRules.isFamilyDetailsRequired()) {
client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
}
try {
personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.customerService.createClient(client, clientMeeting, feesForCustomerAccount, selectedOfferings);
}
clientPhotoService.create(client.getCustomerId().longValue(), clientCreationDetail.getPicture());
return new CustomerDetailsDto(client.getCustomerId(), client.getGlobalCustNum());
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e.getValues(), e);
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class CenterServiceFacadeWebTier method retrieveAccountTransactionHistory.
@Override
public List<TransactionHistoryDto> retrieveAccountTransactionHistory(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
AccountBO account = new AccountBusinessService().findBySystemId(globalAccountNum);
CustomerBO customerBO = account.getCustomer();
account.updateDetails(userContext);
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
List<TransactionHistoryDto> transactionHistories = account.getTransactionHistoryView();
for (TransactionHistoryDto transactionHistoryDto : transactionHistories) {
transactionHistoryDto.setUserPrefferedPostedDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), transactionHistoryDto.getPostedDate().toString()));
transactionHistoryDto.setUserPrefferedTransactionDate(DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), transactionHistoryDto.getTransactionDate().toString()));
}
return transactionHistories;
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBOTest method testInvalidConnectionForSave.
@Test
@ExpectedException(value = AccountException.class)
public void testInvalidConnectionForSave() throws PersistenceException {
final LegacyAccountDao legacyAccountDao = mock(LegacyAccountDao.class);
LoanBO loanBO = new LoanBO() {
@Override
public LegacyAccountDao getlegacyAccountDao() {
return legacyAccountDao;
}
};
try {
when(legacyAccountDao.createOrUpdate(loanBO)).thenThrow(new PersistenceException("some exception"));
loanBO.update();
junit.framework.Assert.fail("should fail because of invalid session");
} catch (AccountException e) {
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class WebTierAccountServiceFacade method applyHistoricalAdjustment.
@Override
public void applyHistoricalAdjustment(String globalAccountNum, Integer paymentId, String adjustmentNote, Short personnelId, AdjustedPaymentDto adjustedPaymentDto) {
try {
AccountBO accountBO = accountBusinessService.findBySystemId(globalAccountNum);
accountBO.setUserContext(getUserContext());
checkPermissionForAdjustment(accountBO);
PersonnelBO personnelBO = personnelPersistence.findPersonnelById(personnelId);
AccountPaymentEntity accountPaymentEntity = accountBO.findPaymentById(paymentId);
if (accountPaymentEntity == null) {
throw new AccountException(AccountExceptionConstants.CANNOTADJUST);
}
monthClosingServiceFacade.validateTransactionDate(accountPaymentEntity.getPaymentDate());
PaymentDto otherTransferPayment = accountPaymentEntity.getOtherTransferPaymentDto();
//flush to avoid proxy casting problems
transactionHelper.flushAndClearSession();
transactionHelper.startTransaction();
Integer newSavingsPaymentId = null;
if (otherTransferPayment != null) {
SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(otherTransferPayment.getAccountId().longValue(), (adjustedPaymentDto == null) ? 0 : Double.valueOf(adjustedPaymentDto.getAmount()), adjustmentNote, otherTransferPayment.getPaymentId(), (adjustedPaymentDto == null) ? otherTransferPayment.getPaymentDate() : new LocalDate(adjustedPaymentDto.getPaymentDate()));
PaymentDto newSavingsPayment = this.savingsServiceFacade.adjustTransaction(savingsAdjustment, true);
newSavingsPaymentId = (newSavingsPayment == null) ? null : newSavingsPayment.getPaymentId();
}
//reload after flush & clear
accountBO = accountBusinessService.findBySystemId(globalAccountNum);
accountBO.setUserContext(getUserContext());
AccountPaymentEntity adjustedPayment = null;
Integer adjustedId;
Stack<PaymentData> paymentsToBeReapplied = new Stack<PaymentData>();
Map<Integer, Stack<PaymentData>> memberPaymentsToBeReappliedMap = new HashMap<Integer, Stack<PaymentData>>();
if (accountBO.isGroupLoanAccount()) {
for (LoanBO memberAccount : ((LoanBO) accountBO).getMemberAccounts()) {
Stack<PaymentData> memberPaymentsToBeReapplied = new Stack<PaymentData>();
memberPaymentsToBeReappliedMap.put(memberAccount.getAccountId(), memberPaymentsToBeReapplied);
}
}
do {
adjustedPayment = accountBO.getLastPmntToBeAdjusted();
if (adjustedPayment == null) {
break;
}
adjustedId = adjustedPayment.getPaymentId();
if (!accountPaymentEntity.getPaymentId().equals(adjustedId)) {
PersonnelBO paymentCreator = (adjustedPayment.getCreatedByUser() == null) ? personnelBO : adjustedPayment.getCreatedByUser();
PaymentData paymentData = accountBO.createPaymentData(adjustedPayment.getAmount(), adjustedPayment.getPaymentDate(), adjustedPayment.getReceiptNumber(), adjustedPayment.getReceiptDate(), adjustedPayment.getPaymentType().getId(), paymentCreator);
paymentData.setOtherTransferPayment(adjustedPayment.getOtherTransferPayment());
paymentsToBeReapplied.push(paymentData);
// handling new Group Loan Members payments
for (AccountPaymentEntity memberAdjustedPayment : adjustedPayment.getMemberPayments()) {
PaymentData memberPaymentData = memberAdjustedPayment.getAccount().createPaymentData(memberAdjustedPayment.getAmount(), adjustedPayment.getPaymentDate(), adjustedPayment.getReceiptNumber(), adjustedPayment.getReceiptDate(), adjustedPayment.getPaymentType().getId(), paymentCreator);
memberPaymentsToBeReappliedMap.get(memberAdjustedPayment.getAccount().getAccountId()).push(memberPaymentData);
}
}
transactionHelper.flushAndClearSession();
//reload after flush & clear
accountBO = accountBusinessService.findBySystemId(globalAccountNum);
accountBO.setUserContext(getUserContext());
accountBO.adjustLastPayment(adjustmentNote, personnelBO);
legacyAccountDao.createOrUpdate(accountBO);
//adjust New Group Loan member payments
if (accountBO.isGroupLoanAccount()) {
for (LoanBO memberAccount : ((LoanBO) accountBO).getMemberAccounts()) {
AccountPaymentEntity memberPayment = memberAccount.getLastPmntToBeAdjusted();
if (memberPayment.getParentPaymentId() == null) {
continue;
}
memberAccount.setUserContext(getUserContext());
memberAccount.adjustLastPayment(adjustmentNote, personnelBO);
legacyAccountDao.createOrUpdate(memberAccount);
}
}
transactionHelper.flushSession();
} while (!accountPaymentEntity.getPaymentId().equals(adjustedId));
if (adjustedPaymentDto != null) {
//reapply adjusted payment
PersonnelBO paymentCreator = (accountPaymentEntity.getCreatedByUser() == null) ? personnelBO : accountPaymentEntity.getCreatedByUser();
Money amount = new Money(accountBO.getCurrency(), adjustedPaymentDto.getAmount());
PaymentData paymentData = accountBO.createPaymentData(amount, adjustedPaymentDto.getPaymentDate(), accountPaymentEntity.getReceiptNumber(), accountPaymentEntity.getReceiptDate(), adjustedPaymentDto.getPaymentType(), paymentCreator);
paymentData.setAdjustment(true);
//new adjusted savings payment must be tied to this payment
if (newSavingsPaymentId != null) {
AccountPaymentEntity newSvngPayment = legacyAccountDao.findPaymentById(newSavingsPaymentId);
paymentData.setOtherTransferPayment(newSvngPayment);
}
accountBO.applyPayment(paymentData);
legacyAccountDao.createOrUpdate(accountBO);
transactionHelper.flushSession();
// handling new Group Loan Members payments
if (accountBO.isGroupLoanAccount()) {
for (AdjustedPaymentDto adjustedMemberPayment : adjustedPaymentDto.getMemberPayments()) {
AccountBO memberAccount = ((LoanBO) accountBO).findMemberById(adjustedMemberPayment.getAccountId());
BigDecimal adjustedMemberPaymentAmount = BigDecimal.ZERO;
if (!StringUtils.isBlank(adjustedMemberPayment.getAmount())) {
adjustedMemberPaymentAmount = new BigDecimal(adjustedMemberPayment.getAmount());
}
Money memberAmount = new Money(memberAccount.getCurrency(), adjustedMemberPaymentAmount.toString());
PaymentData memberPaymentData = memberAccount.createPaymentData(memberAmount, adjustedPaymentDto.getPaymentDate(), accountPaymentEntity.getReceiptNumber(), accountPaymentEntity.getReceiptDate(), adjustedPaymentDto.getPaymentType(), paymentCreator);
memberPaymentData.setParentPayment(accountBO.getLastPmnt());
memberAccount.applyPayment(memberPaymentData);
legacyAccountDao.createOrUpdate(memberAccount);
}
}
}
while (!paymentsToBeReapplied.isEmpty()) {
PaymentData paymentData = paymentsToBeReapplied.pop();
//avoid lazy loading exception
if (paymentData.getOtherTransferPayment() != null) {
legacyAccountDao.updatePayment(paymentData.getOtherTransferPayment());
}
accountBO.applyPayment(paymentData);
legacyAccountDao.createOrUpdate(accountBO);
transactionHelper.flushSession();
if (accountBO.isGroupLoanAccount()) {
for (LoanBO memberAccount : ((LoanBO) accountBO).getMemberAccounts()) {
PaymentData memberPaymentData = memberPaymentsToBeReappliedMap.get(memberAccount.getAccountId()).pop();
memberPaymentData.setParentPayment(accountBO.getLastPmnt());
memberAccount.applyPayment(memberPaymentData);
legacyAccountDao.createOrUpdate(memberAccount);
}
}
}
transactionHelper.commitTransaction();
} catch (ServiceException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (AccountException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (PersistenceException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (RuntimeException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class WebTierAccountServiceFacade method getApplicableFees.
@Override
public List<ApplicableCharge> getApplicableFees(Integer accountId) {
try {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
AccountBO account = this.accountBusinessService.getAccount(accountId);
try {
personnelDao.checkAccessPermission(userContext, account.getOfficeId(), account.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
return new AccountBusinessService().getAppllicableFees(accountId, userContext);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
}
Aggregations