Search in sources :

Example 6 with RepayLoanActionForm

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()));
}
Also used : Money(org.mifos.framework.util.helpers.Money) LoanBO(org.mifos.accounts.loan.business.LoanBO) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) LoanSummaryEntity(org.mifos.accounts.loan.business.LoanSummaryEntity) Test(org.junit.Test)

Example 7 with RepayLoanActionForm

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);
}
Also used : UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 8 with RepayLoanActionForm

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);
}
Also used : RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 9 with RepayLoanActionForm

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);
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) UserContext(org.mifos.security.util.UserContext) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 10 with RepayLoanActionForm

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);
}
Also used : RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

RepayLoanActionForm (org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm)11 Money (org.mifos.framework.util.helpers.Money)9 LoanBO (org.mifos.accounts.loan.business.LoanBO)8 Date (java.sql.Date)5 LocalDate (org.joda.time.LocalDate)5 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)5 UserContext (org.mifos.security.util.UserContext)5 Test (org.junit.Test)4 LoanSummaryEntity (org.mifos.accounts.loan.business.LoanSummaryEntity)4 BigDecimal (java.math.BigDecimal)3 HashMap (java.util.HashMap)3 RepayLoanInfoDto (org.mifos.dto.screen.RepayLoanInfoDto)3 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)2 RepayLoanDto (org.mifos.dto.screen.RepayLoanDto)2 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)1 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)1 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)1 PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)1 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)1