use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanActionStrutsTest method testMakeRepaymentForCurrentDateLiesBetweenInstallmentDatesWithInterestWaiver.
@Test
public void testMakeRepaymentForCurrentDateLiesBetweenInstallmentDatesWithInterestWaiver() throws Exception {
setMifosUserFromContext();
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
accountBO.changeFirstInstallmentDateBy(-1);
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);
setActionForm(repayLoanActionForm);
repayLoanActionForm.setDateOfPayment("23/12/2010");
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 RepayLoanAction method loadRepayment.
@TransactionDemarcate(joinToken = true)
public ActionForward loadRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Loading repay loan page");
RepayLoanActionForm actionForm = (RepayLoanActionForm) form;
actionForm.setReceiptNumber(null);
actionForm.setReceiptDate(null);
actionForm.setPaymentTypeId(null);
actionForm.setWaiverInterest(true);
actionForm.setDateOfPayment(DateUtils.makeDateAsSentFromBrowser());
actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
actionForm.setPrintReceipt(false);
actionForm.setTruePrintReceipt(false);
UserContext userContext = getUserContext(request);
String globalAccountNum = request.getParameter("globalAccountNum");
RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
java.util.Date lastPaymentDate = new java.util.Date(0);
AccountPaymentEntity lastPayment = loan.findMostRecentNonzeroPaymentByPaymentDate();
if (lastPayment != null) {
lastPaymentDate = lastPayment.getPaymentDate();
}
actionForm.setLastPaymentDate(lastPaymentDate);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, repayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, repayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney()), request);
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney()), request);
SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, repayLoanDto.getSavingsAccountsForTransfer(), request);
List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
return mapping.findForward(Constants.LOAD_SUCCESS);
}
use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanAction method previous.
@TransactionDemarcate(joinToken = true)
public ActionForward previous(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
//workaround for checkbox problem
RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
repayLoanActionForm.setTruePrintReceipt(repayLoanActionForm.getPrintReceipt());
repayLoanActionForm.setPrintReceipt(false);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, ((RepayLoanActionForm) form).isWaiverInterest(), request);
return mapping.findForward(Constants.PREVIOUS_SUCCESS);
}
use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.
the class RepayLoanAction method makeRepayment.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward makeRepayment(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");
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 = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
if (repayLoanActionForm.isSavingsTransfer()) {
this.loanAccountServiceFacade.makeEarlyRepaymentFromSavings(repayLoanInfoDto, repayLoanActionForm.getAccountForTransfer());
} else {
this.loanAccountServiceFacade.makeEarlyRepayment(repayLoanInfoDto);
}
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 validate.
@TransactionDemarcate(joinToken = true)
public ActionForward validate(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
String method = (String) request.getAttribute("methodCalled");
logger.debug("In RepayLoanAction::validate(), method: " + method);
String forward = null;
//workaround for checkbox problem
RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
repayLoanActionForm.setTruePrintReceipt(repayLoanActionForm.getPrintReceipt());
repayLoanActionForm.setPrintReceipt(false);
if (method != null && method.equals("preview")) {
forward = ActionForwards.preview_failure.toString();
} else {
forward = ActionForwards.update_failure.toString();
}
return mapping.findForward(forward);
}
Aggregations