Search in sources :

Example 11 with RepayLoanActionForm

use of org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm in project head by mifos.

the class RepayLoanAction method loadGroupRepayment.

@TransactionDemarcate(joinToken = true)
public ActionForward loadGroupRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.info("Loading repay group 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);
    LoanBO parent = loanDao.findByGlobalAccountNum(request.getParameter("globalAccountNum"));
    RepayLoanDto parentRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(parent.getGlobalAccountNum());
    Map<String, Double> memberNumWithAmount = new HashMap<String, Double>();
    Money earlyRepaymentMoney;
    Money waivedRepaymentMoney;
    if (parent.isGroupLoanAccountMember()) {
        earlyRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getEarlyRepaymentMoney());
        waivedRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getWaivedRepaymentMoney());
    } else {
        earlyRepaymentMoney = new Money(parent.getCurrency());
        waivedRepaymentMoney = new Money(parent.getCurrency());
    }
    for (LoanBO member : parent.getMemberAccounts()) {
        RepayLoanDto memberRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(member.getGlobalAccountNum());
        earlyRepaymentMoney = earlyRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getEarlyRepaymentMoney()));
        waivedRepaymentMoney = waivedRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getWaivedRepaymentMoney()));
        memberNumWithAmount.put(member.getAccountId().toString(), Double.valueOf(memberRepayLoanDto.getEarlyRepaymentMoney()));
    }
    java.util.Date lastPaymentDate = new java.util.Date(0);
    AccountPaymentEntity lastPayment = parent.findMostRecentNonzeroPaymentByPaymentDate();
    if (lastPayment != null) {
        lastPaymentDate = lastPayment.getPaymentDate();
    }
    actionForm.setLastPaymentDate(lastPaymentDate);
    SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, parentRepayLoanDto.shouldWaiverInterest(), request);
    SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, parentRepayLoanDto.shouldWaiverInterest(), request);
    SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, earlyRepaymentMoney, request);
    SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, waivedRepaymentMoney, request);
    SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, parentRepayLoanDto.getSavingsAccountsForTransfer(), request);
    SessionUtils.setMapAttribute(LoanConstants.MEMBER_LOAN_REPAYMENT, new HashMap<String, Double>(memberNumWithAmount), request);
    List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
    return mapping.findForward(Constants.LOAD_GROUP_SUCCESS);
}
Also used : HashMap(java.util.HashMap) 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)

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