use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class LoanDisbursementAction method update.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;
UserContext uc = getUserContext(request);
Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());
Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
Integer accountForTransferId = (StringUtils.isBlank(actionForm.getAccountForTransfer())) ? null : legacyAccountDao.getAccountIdByGlobalAccountNumber(actionForm.getAccountForTransfer());
AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);
Date originalDisbursementDate = DateUtils.getDateWithoutTimeStamp(((LoanBO) accountBO).getDisbursementDate());
createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);
try {
String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
String paymentTypeIdStringForFees = actionForm.getPaymentModeOfPayment();
Short paymentTypeIdForDisbursement = StringUtils.isEmpty(paymentTypeIdStringForDisbursement) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForDisbursement);
Short paymentTypeIdForFees = StringUtils.isEmpty(paymentTypeIdStringForFees) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForFees);
Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
final String comment = "";
final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
CustomerDto customerDto = null;
PaymentTypeDto paymentType = null;
AccountPaymentParametersDto loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(loanAccountId), disbursalAmount, new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
monthClosingServiceFacade.validateTransactionDate(trxnDate);
// GLIM
List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
for (LoanBO individual : individualLoans) {
if (!loanAccountServiceFacade.isTrxnDateValid(Integer.valueOf(individual.getAccountId()), trxnDate)) {
throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
}
}
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
for (LoanBO individual : individualLoans) {
loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(individual.getAccountId()), individual.getLoanAmount().getAmount(), new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
}
if (!((LoanBO) accountBO).isFixedRepaymentSchedule() && !originalDisbursementDate.equals(((LoanBO) accountBO).getDisbursementDate())) {
this.loanAccountServiceFacade.updateMemberLoansFeeAmounts(loanAccountId);
}
} catch (BusinessRuleException e) {
throw new AccountException(e.getMessage());
} catch (MifosRuntimeException e) {
if (e.getCause() != null && e.getCause() instanceof AccountException) {
throw new AccountException(e.getCause().getMessage());
}
String msg = "errors.cannotDisburseLoan.because.disburseFailed";
logger.error(msg, e);
throw new AccountException(msg);
} catch (Exception e) {
String msg = "errors.cannotDisburseLoan.because.disburseFailed";
logger.error(msg, e);
throw new AccountException(msg);
}
return mapping.findForward(Constants.UPDATE_SUCCESS);
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class ApplyCustomerFeeChangesHelper method execute.
@Override
public void execute(@SuppressWarnings("unused") long timeInMillis) throws BatchJobException {
List<String> errorList = new ArrayList<String>();
List<Short> updatedFeeIds = new ArrayList<Short>();
try {
updatedFeeIds = getFeeDao().getUpdatedFeesForCustomer();
} catch (Exception e) {
errorList.add(e.getMessage());
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
for (Short feeId : updatedFeeIds) {
try {
FeeBO hydratedFee = getFeeDao().findById(feeId);
if (!hydratedFee.getFeeChangeType().equals(FeeChangeType.NOT_UPDATED)) {
List<AccountBO> accounts = new CustomerPersistence().getCustomerAccountsForFee(hydratedFee.getFeeId());
if (accounts != null && accounts.size() > 0) {
for (AccountBO account : accounts) {
updateAccountFee(account, hydratedFee);
}
}
}
hydratedFee.updateFeeChangeType(FeeChangeType.NOT_UPDATED);
UserContext userContext = new UserContext();
userContext.setId(PersonnelConstants.SYSTEM_USER);
hydratedFee.setUserContext(userContext);
hydratedFee.save();
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
errorList.add("feeId: " + feeId);
}
}
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class SavingsCloseTest method whenClosingAccountShouldCreateStatusChangeHistoryForClosure.
@Test
public void whenClosingAccountShouldCreateStatusChangeHistoryForClosure() {
Money remainingBalance = TestUtils.createMoney("100");
savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
CustomerBO customer = new ClientBuilder().buildForUnitTests();
PersonnelBO loggedInUser = new PersonnelBuilder().build();
// pre verification
assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(1));
// exercise test
savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
// verification
assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(2));
AccountStatusChangeHistoryEntity closure = savingsAccount.getAccountStatusChangeHistory().get(1);
assertThat(closure.getAccount(), is((AccountBO) savingsAccount));
assertTrue(closure.getOldStatus().isInState(AccountState.SAVINGS_ACTIVE));
assertTrue(closure.getNewStatus().isInState(AccountState.SAVINGS_CLOSED));
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class StandardAccountService method handleParentGroupLoanPayment.
/**
* Handles parent NOT-GLIM group loan payment.
*/
private void handleParentGroupLoanPayment(AccountBO account, AccountPaymentParametersDto parentPaymentParametersDto, Integer savingsPaymentId, AccountPaymentEntity paymentEntity) throws PersistenceException, AccountException {
if (account instanceof LoanBO && account.isParentGroupLoanAccount()) {
if (parentPaymentParametersDto.getMemberInfo() == null || parentPaymentParametersDto.getMemberInfo().isEmpty()) {
createMembersLoanPaymentsData(parentPaymentParametersDto);
}
for (Map.Entry<Integer, String> member : parentPaymentParametersDto.getMemberInfo().entrySet()) {
AccountBO memberAcc = this.legacyAccountDao.getAccount(member.getKey());
if (null == parentPaymentParametersDto.getMemberAccountIdToRepay() || (null != parentPaymentParametersDto.getMemberAccountIdToRepay() && !parentPaymentParametersDto.getMemberAccountIdToRepay().equals(memberAcc.getAccountId()))) {
AccountPaymentParametersDto memberAccountPaymentParametersDto = new AccountPaymentParametersDto(parentPaymentParametersDto.getUserMakingPayment(), new AccountReferenceDto(memberAcc.getAccountId()), new BigDecimal(member.getValue()), parentPaymentParametersDto.getPaymentDate(), parentPaymentParametersDto.getPaymentType(), parentPaymentParametersDto.getComment(), parentPaymentParametersDto.getReceiptDate(), parentPaymentParametersDto.getReceiptId(), memberAcc.getCustomer().toCustomerDto());
if (parentPaymentParametersDto.getPaymentOptions().contains(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS)) {
memberAccountPaymentParametersDto.addPaymentOption(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS);
}
makePaymentNoCommit(memberAccountPaymentParametersDto, savingsPaymentId, paymentEntity);
} else {
AccountPaymentDto paymentDto = new AccountPaymentDto(Double.valueOf(member.getValue()), parentPaymentParametersDto.getPaymentDate().toDateMidnight().toDate(), parentPaymentParametersDto.getReceiptId(), reciptDateNullValidation(parentPaymentParametersDto.getReceiptDate()), parentPaymentParametersDto.getPaymentType().getValue());
((LoanBO) memberAcc).makeEarlyRepayment(paymentDto, parentPaymentParametersDto.getUserMakingPayment().getUserId(), parentPaymentParametersDto.getRepayLoanInfoDto().isWaiveInterest(), new Money(account.getCurrency(), parentPaymentParametersDto.getInterestDueForCurrentInstalmanet()));
}
}
}
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class StandardAccountService method doesTransactionIntroduceOverpayment.
public boolean doesTransactionIntroduceOverpayment(AccountPaymentParametersDto payment) throws Exception {
AccountBO account = this.legacyAccountDao.getAccount(payment.getAccountId());
Money amount = new Money(account.getCurrency(), payment.getPaymentAmount());
return amount.isGreaterThan(((LoanBO) account).getTotalRepayableAmount());
}
Aggregations