Search in sources :

Example 1 with RepayLoanInfoDto

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

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

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

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

the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepaymentForNotWaiverInterestLoanProduct.

@Test
public void testMakeEarlyRepaymentForNotWaiverInterestLoanProduct() throws AccountException, PersistenceException {
    setMifosUserFromContext();
    when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
    when(loanDao.findById(0)).thenReturn(loanBO);
    boolean waiveInterest = false;
    when(loanBO.getCurrency()).thenReturn(rupee);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    when(customer.getCustomerId()).thenReturn(2);
    LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity() {
    };
    loanScheduleEntity.setInterest(new Money(rupee, 100d));
    when(loanBO.getDetailsOfNextInstallment()).thenReturn(loanScheduleEntity);
    java.sql.Date date = mock(java.sql.Date.class);
    when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
    when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
    when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
    String paymentMethod = "1";
    String receiptNumber = "001";
    AccountPaymentDto paymentDto = new AccountPaymentDto(new Double(100), date, receiptNumber, date, Short.valueOf((short) 1));
    loanAccountServiceFacade.makeEarlyRepayment(new RepayLoanInfoDto("1", "100.0", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.ZERO, BigDecimal.ZERO));
    short userId = (short) 1;
    verify(loanBO).makeEarlyRepayment(paymentDto, userId, waiveInterest, new Money(rupee, 100d));
    verify(loanBusinessService).computeExtraInterest(loanBO, date);
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Test(org.junit.Test)

Example 5 with RepayLoanInfoDto

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

Aggregations

RepayLoanInfoDto (org.mifos.dto.screen.RepayLoanInfoDto)9 Money (org.mifos.framework.util.helpers.Money)8 LocalDate (org.joda.time.LocalDate)7 BigDecimal (java.math.BigDecimal)5 Date (java.sql.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 AccountPaymentDto (org.mifos.dto.domain.AccountPaymentDto)4 Date (java.util.Date)3 RepayLoanActionForm (org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm)3 UserContext (org.mifos.security.util.UserContext)3 RepayLoanDto (org.mifos.dto.screen.RepayLoanDto)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DateTime (org.joda.time.DateTime)1 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)1 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 AmountWithInterest (org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest)1