Search in sources :

Example 1 with RepayLoanDto

use of org.mifos.dto.screen.RepayLoanDto in project head by mifos.

the class LoanAccountServiceFacadeWebTier method generateAmountWithInterest.

private Map<String, AmountWithInterest> generateAmountWithInterest(Map<String, Double> memberNumWithAmount, RepayLoanInfoDto parentRLIDto) {
    Map<String, AmountWithInterest> awi = new HashMap<String, AmountWithInterest>();
    for (Map.Entry<String, Double> entry : memberNumWithAmount.entrySet()) {
        LoanBO loan = this.loanDao.findById(Integer.valueOf(entry.getKey()));
        String globalAccountNum = loan.getGlobalAccountNum();
        RepayLoanDto memberRLDto = retrieveLoanRepaymentDetails(globalAccountNum);
        RepayLoanInfoDto memberRLIDto = new RepayLoanInfoDto(globalAccountNum, memberRLDto.getEarlyRepaymentMoney(), parentRLIDto.getReceiptNumber(), parentRLIDto.getReceiptDate(), parentRLIDto.getPaymentTypeId(), parentRLIDto.getId(), parentRLIDto.isWaiveInterest(), parentRLIDto.getDateOfPayment(), new BigDecimal(entry.getValue()), new BigDecimal(memberRLDto.getWaivedRepaymentMoney()));
        awi.put(entry.getKey(), new org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest(entry.getValue(), calculateInterestDueForCurrentInstalmanet(memberRLIDto)));
    }
    return awi;
}
Also used : AmountWithInterest(org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) AmountWithInterest(org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest) BigDecimal(java.math.BigDecimal) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) AccountPaymentDto(org.mifos.dto.screen.AccountPaymentDto) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 2 with RepayLoanDto

use of org.mifos.dto.screen.RepayLoanDto in project head by mifos.

the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentDetails.

@Override
public RepayLoanDto retrieveLoanRepaymentDetails(String globalAccountNumber) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNumber);
    try {
        personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    Money repaymentAmount;
    Money waiverAmount;
    if (loan.isDecliningBalanceInterestRecalculation()) {
        RepaymentResultsHolder repaymentResultsHolder = scheduleCalculatorAdaptor.computeRepaymentAmount(loan, DateUtils.getCurrentDateWithoutTimeStamp());
        repaymentAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getTotalRepaymentAmount());
        waiverAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getWaiverAmount());
    } else {
        repaymentAmount = loan.getEarlyRepayAmount();
        waiverAmount = loan.waiverAmount();
    }
    Money waivedRepaymentAmount = repaymentAmount.subtract(waiverAmount);
    List<SavingsDetailDto> savingsInUse = clientServiceFacade.retrieveSavingsInUseForClient(loan.getCustomer().getCustomerId());
    List<SavingsDetailDto> accountsForTransfer = new ArrayList<SavingsDetailDto>();
    if (savingsInUse != null) {
        for (SavingsDetailDto savingsAccount : savingsInUse) {
            if (savingsAccount.getAccountStateId().equals(AccountState.SAVINGS_ACTIVE.getValue())) {
                accountsForTransfer.add(savingsAccount);
            }
        }
    }
    return new RepayLoanDto(repaymentAmount.toString(), waivedRepaymentAmount.toString(), loan.isInterestWaived(), accountsForTransfer);
}
Also used : Money(org.mifos.framework.util.helpers.Money) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) RepaymentResultsHolder(org.mifos.accounts.loan.business.RepaymentResultsHolder) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with RepayLoanDto

use of org.mifos.dto.screen.RepayLoanDto in project head by mifos.

the class LoanAccountRESTController method fullRepay.

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/fullrepay", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> fullRepay(@PathVariable String globalAccountNum, @RequestParam(required = false) String paymentDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam(required = false) Short paymentModeId, @RequestParam Boolean waiveInterest) throws Exception {
    LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    validateLoanAccountState(loan);
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
    DateTime today = new DateTime();
    Date paymentDateTime = new Date(today.toDate().getTime());
    if (paymentDate != null && !paymentDate.isEmpty()) {
        paymentDateTime = new Date(validateDateString(paymentDate, format).toDate().getTime());
    }
    String receiptIdString = null;
    if (receiptId != null) {
        receiptIdString = receiptId.toString();
    }
    Date receiptDateTime = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptDateTime = new Date(validateDateString(receiptDate, format).toDate().getTime());
    }
    String paymentTypeId = null;
    if (paymentModeId != null) {
        paymentTypeId = paymentModeId.toString();
    }
    validateDisbursementPaymentTypeId(paymentModeId, accountService.getLoanPaymentTypes());
    BigDecimal totalRepaymentAmount = (new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney())).getAmount();
    BigDecimal waivedAmount = (new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney())).getAmount();
    BigDecimal earlyRepayAmount = totalRepaymentAmount;
    if (Boolean.TRUE.equals(waiveInterest)) {
        earlyRepayAmount = waivedAmount;
    }
    RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, Double.toString(earlyRepayAmount.doubleValue()), receiptIdString, receiptDateTime, paymentTypeId, (short) user.getUserId(), waiveInterest.booleanValue(), paymentDateTime, totalRepaymentAmount, waivedAmount);
    Money outstandingBeforePayment = loan.getLoanSummary().getOutstandingBalance();
    this.loanAccountServiceFacade.makeEarlyRepaymentWithCommit(repayLoanInfoDto);
    CustomerBO client = loan.getCustomer();
    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("paymentDate", today.toLocalDate().toString());
    map.put("paymentTime", today.toLocalTime().toString());
    map.put("paymentAmount", loan.getLastPmnt().getAmount().toString());
    map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforePayment", outstandingBeforePayment.toString());
    map.put("outstandingAfterPayment", loan.getLoanSummary().getOutstandingBalance().toString());
    return map;
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) HashMap(java.util.HashMap) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTime(org.joda.time.DateTime) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RepayLoanDto

use of org.mifos.dto.screen.RepayLoanDto 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 5 with RepayLoanDto

use of org.mifos.dto.screen.RepayLoanDto 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

RepayLoanDto (org.mifos.dto.screen.RepayLoanDto)8 LoanBO (org.mifos.accounts.loan.business.LoanBO)7 Money (org.mifos.framework.util.helpers.Money)6 HashMap (java.util.HashMap)4 Date (java.sql.Date)3 LocalDate (org.joda.time.LocalDate)3 UserContext (org.mifos.security.util.UserContext)3 BigDecimal (java.math.BigDecimal)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.Test)2 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 RepaymentResultsHolder (org.mifos.accounts.loan.business.RepaymentResultsHolder)2 RepayLoanActionForm (org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm)2 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)2 RepayLoanInfoDto (org.mifos.dto.screen.RepayLoanInfoDto)2 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)2 MifosUser (org.mifos.security.MifosUser)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ArrayList (java.util.ArrayList)1