Search in sources :

Example 1 with RepayLoanActionForm

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

Example 2 with RepayLoanActionForm

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);
}
Also used : RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) HashMap(java.util.HashMap) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto)

Example 3 with RepayLoanActionForm

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()));
}
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 4 with RepayLoanActionForm

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()));
}
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 5 with RepayLoanActionForm

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()));
}
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)

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