use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanAction method makeGroupRepayment.
public ActionForward makeGroupRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Performing loan repayment");
UserContext userContext = getUserContext(request);
RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
Date receiptDate = null;
if (StringUtils.isNotEmpty(repayLoanActionForm.getReceiptDate())) {
receiptDate = repayLoanActionForm.getReceiptDateValue(userContext.getPreferredLocale());
}
String globalAccountNum = request.getParameter("globalAccountNum");
LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
String forward = Constants.UPDATE_SUCCESS;
BigDecimal totalRepaymentAmount = ((Money) SessionUtils.getAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request)).getAmount();
BigDecimal waivedAmount = ((Money) SessionUtils.getAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request)).getAmount();
RepayLoanInfoDto repayLoanInfoDto = null;
Map<String, Double> memberRepayment = new HashMap<String, Double>();
if (loan.isGroupLoanAccountParent()) {
memberRepayment = (Map<String, Double>) SessionUtils.getAttribute(LoanConstants.MEMBER_LOAN_REPAYMENT, request);
repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
} else if (loan.isGroupLoanAccountMember()) {
repayLoanInfoDto = new RepayLoanInfoDto(loan.getParentAccount().getGlobalAccountNum(), repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
memberRepayment.put(loan.getAccountId().toString(), Double.valueOf(repayLoanInfoDto.getEarlyRepayAmount()));
}
if (repayLoanActionForm.isSavingsTransfer()) {
this.loanAccountServiceFacade.makeEarlyRepaymentFromSavings(repayLoanInfoDto, repayLoanActionForm.getAccountForTransfer());
} else {
this.loanAccountServiceFacade.makeEarlyGroupRepayment(repayLoanInfoDto, memberRepayment);
}
SessionUtils.removeAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request);
SessionUtils.removeAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request);
SessionUtils.removeAttribute(Constants.ACCOUNTS_FOR_TRANSFER, request);
request.getSession().setAttribute("globalAccountNum", globalAccountNum);
if (repayLoanActionForm.getPrintReceipt()) {
return mapping.findForward(ActionForwards.printPaymentReceipt.toString());
}
return mapping.findForward(forward);
}
use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanAction method makeGroupMemberRepayment.
public ActionForward makeGroupMemberRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Performing loan repayment");
UserContext userContext = getUserContext(request);
UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
String globalAccountNum = request.getParameter("globalAccountNum");
String forward = Constants.UPDATE_SUCCESS;
Date receiptDate = null;
if (StringUtils.isNotEmpty(repayLoanActionForm.getReceiptDate())) {
receiptDate = repayLoanActionForm.getReceiptDateValue(userContext.getPreferredLocale());
}
PaymentTypeDto paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(repayLoanActionForm.getPaymentTypeId()));
LoanBO acctualMemberAccount = loanDao.findByGlobalAccountNum(globalAccountNum);
Integer accountId = acctualMemberAccount.getAccountId();
AccountPaymentDto accountPaymentDto = this.accountServiceFacade.getAccountPaymentInformation(accountId, repayLoanActionForm.getPaymentTypeId(), userContext.getLocaleId(), userReferenceDto, repayLoanActionForm.getDateOfPaymentValue(defaultLocale));
LoanBO parrentAccount = acctualMemberAccount.getParentAccount();
Integer parentAccountId = parrentAccount.getAccountId();
AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(parentAccountId), new BigDecimal(repayLoanActionForm.getAmount()), new LocalDate(DateUtils.getDate(repayLoanActionForm.getDateOfPayment())), paymentTypeDto, AccountConstants.NO_COMMENT, new LocalDate(DateUtils.getDate(repayLoanActionForm.getReceiptDate())), repayLoanActionForm.getReceiptNumber(), accountPaymentDto.getCustomerDto());
BigDecimal totalRepaymentAmount = ((Money) SessionUtils.getAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request)).getAmount();
BigDecimal waivedAmount = ((Money) SessionUtils.getAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request)).getAmount();
RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
HashMap<Integer, String> individualValues = new HashMap<Integer, String>();
for (LoanBO member : loanDao.findIndividualLoans(parentAccountId)) {
if (member.isAccountActive()) {
if (member.getAccountId().equals(acctualMemberAccount.getAccountId())) {
individualValues.put(member.getAccountId(), repayLoanActionForm.getAmount());
} else {
individualValues.put(member.getAccountId(), "0.0");
}
}
}
accountPaymentParametersDto.setMemberInfo(individualValues);
accountPaymentParametersDto.setMemberAccountIdToRepay(accountId);
accountPaymentParametersDto.setRepayLoanInfoDto(repayLoanInfoDto);
accountPaymentParametersDto.setInterestDueForCurrentInstalmanet(this.loanAccountServiceFacade.calculateInterestDueForCurrentInstalmanet(repayLoanInfoDto));
if (repayLoanActionForm.isSavingsTransfer()) {
this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, repayLoanActionForm.getAccountForTransfer());
} else {
this.accountServiceFacade.makePayment(accountPaymentParametersDto);
}
SessionUtils.removeAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request);
SessionUtils.removeAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request);
SessionUtils.removeAttribute(Constants.ACCOUNTS_FOR_TRANSFER, request);
request.getSession().setAttribute("globalAccountNum", globalAccountNum);
if (repayLoanActionForm.getPrintReceipt()) {
return mapping.findForward(ActionForwards.printPaymentReceipt.toString());
}
return mapping.findForward(forward);
}
use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanActionStrutsTest method testMakeRepaymentForCurrentDateSameAsInstallmentDate.
@Test
public void testMakeRepaymentForCurrentDateSameAsInstallmentDate() throws Exception {
setMifosUserFromContext();
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
Money amount = ((LoanBO) accountBO).getEarlyRepayAmount();
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, Money.zero(), request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, amount, request);
setRequestPathInfo("/repayLoanAction");
addRequestParameter("method", "makeRepayment");
addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
addRequestParameter("paymentTypeId", "1");
addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
RepayLoanActionForm repayLoanActionForm = new RepayLoanActionForm();
repayLoanActionForm.setAmount(amount.toString());
repayLoanActionForm.setWaiverInterest(false);
repayLoanActionForm.setDateOfPayment("23/12/2010");
setActionForm(repayLoanActionForm);
actionPerform();
verifyForward(Constants.UPDATE_SUCCESS);
Assert.assertEquals(accountBO.getAccountState().getId(), Short.valueOf(AccountStates.LOANACC_OBLIGATIONSMET));
LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
Assert.assertEquals(amount, loanSummaryEntity.getPrincipalPaid().add(loanSummaryEntity.getFeesPaid()).add(loanSummaryEntity.getInterestPaid()).add(loanSummaryEntity.getPenaltyPaid()));
}
use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanActionStrutsTest method testMakeRepaymentForCurrentDateSameAsInstallmentDateWithInterestWaiver.
@Test
public void testMakeRepaymentForCurrentDateSameAsInstallmentDateWithInterestWaiver() throws Exception {
setMifosUserFromContext();
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
Money amount = ((LoanBO) accountBO).getEarlyRepayAmount();
Money waivedAmount = amount.subtract(((LoanBO) accountBO).waiverAmount());
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, waivedAmount, request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, amount, request);
setRequestPathInfo("/repayLoanAction");
addRequestParameter("method", "makeRepayment");
addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
addRequestParameter("paymentTypeId", "1");
addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
RepayLoanActionForm repayLoanActionForm = new RepayLoanActionForm();
repayLoanActionForm.setAmount(amount.toString());
repayLoanActionForm.setWaiverInterest(true);
repayLoanActionForm.setDateOfPayment("23/12/2010");
setActionForm(repayLoanActionForm);
actionPerform();
verifyForward(Constants.UPDATE_SUCCESS);
Assert.assertEquals(accountBO.getAccountState().getId(), Short.valueOf(AccountStates.LOANACC_OBLIGATIONSMET));
LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
Assert.assertEquals(waivedAmount, loanSummaryEntity.getPrincipalPaid().add(loanSummaryEntity.getFeesPaid()).add(loanSummaryEntity.getInterestPaid()).add(loanSummaryEntity.getPenaltyPaid()));
}
use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanActionStrutsTest method testMakeRepaymentForCurrentDateLiesBetweenInstallmentDates.
@Test
public void testMakeRepaymentForCurrentDateLiesBetweenInstallmentDates() throws Exception {
setMifosUserFromContext();
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
accountBO.changeFirstInstallmentDateBy(-1);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
Money amount = ((LoanBO) accountBO).getEarlyRepayAmount();
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, Money.zero(), request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, amount, request);
setRequestPathInfo("/repayLoanAction");
addRequestParameter("method", "makeRepayment");
addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
addRequestParameter("paymentTypeId", "1");
addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
RepayLoanActionForm repayLoanActionForm = new RepayLoanActionForm();
repayLoanActionForm.setAmount(amount.toString());
repayLoanActionForm.setWaiverInterest(false);
repayLoanActionForm.setDateOfPayment("23/12/2010");
setActionForm(repayLoanActionForm);
actionPerform();
verifyForward(Constants.UPDATE_SUCCESS);
Assert.assertEquals(accountBO.getAccountState().getId(), Short.valueOf(AccountStates.LOANACC_OBLIGATIONSMET));
LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
Assert.assertEquals(amount, loanSummaryEntity.getPrincipalPaid().add(loanSummaryEntity.getFeesPaid()).add(loanSummaryEntity.getInterestPaid()).add(loanSummaryEntity.getPenaltyPaid()));
}
Aggregations