Search in sources :

Example 6 with RepayLoanInfoDto

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

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

the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepaymentFromSavings.

@Test
public void testMakeEarlyRepaymentFromSavings() throws AccountException, PersistenceException {
    final String savingsAccGlobalNum = "0001-00000009";
    setMifosUserFromContext();
    when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
    when(loanDao.findById(0)).thenReturn(loanBO);
    final java.sql.Date date = new java.sql.Date(new Date().getTime());
    when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
    when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
    when(loanBO.getCurrency()).thenReturn(rupee);
    boolean waiveInterest = true;
    when(loanBO.isInterestWaived()).thenReturn(waiveInterest);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    when(customer.getCustomerId()).thenReturn(2);
    when(savingsServiceFacade.retrieveSavingsAccountDetails(savingsAccGlobalNum)).thenReturn(savingsAccountDetailDto);
    when(savingsAccountDetailDto.getCustomerId()).thenReturn(2);
    when(savingsAccountDetailDto.getAccountId()).thenReturn(1);
    String paymentMethod = "4";
    String receiptNumber = "001";
    when(savingsServiceFacade.withdraw(any(SavingsWithdrawalDto.class), eq(true))).thenReturn(withdrawal);
    when(withdrawal.getPaymentId()).thenReturn(1);
    loanAccountServiceFacade.makeEarlyRepaymentFromSavings(new RepayLoanInfoDto("1", "100", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.TEN, BigDecimal.ZERO), savingsAccGlobalNum);
    ArgumentCaptor<SavingsWithdrawalDto> withdrawal = ArgumentCaptor.forClass(SavingsWithdrawalDto.class);
    verify(savingsServiceFacade).withdraw(withdrawal.capture(), eq(true));
    final Long savingsId = savingsAccountDetailDto.getAccountId().longValue();
    final Long customerId = savingsAccountDetailDto.getCustomerId().longValue();
    final LocalDate trxnDate = new LocalDate(date);
    final LocalDate receiptDate = new LocalDate(date);
    final Double amount = Double.parseDouble("100");
    final Integer modeOfPayment = 4;
    AccountPaymentDto paymentDto = new AccountPaymentDto(amount, date, receiptNumber, date, Short.valueOf((short) 1));
    assertEquals(withdrawal.getValue().getAmount(), amount);
    assertEquals(withdrawal.getValue().getSavingsId(), savingsId);
    assertEquals(withdrawal.getValue().getCustomerId(), customerId);
    assertEquals(withdrawal.getValue().getDateOfWithdrawal(), trxnDate);
    assertEquals(withdrawal.getValue().getDateOfReceipt(), receiptDate);
    assertEquals(withdrawal.getValue().getModeOfPayment(), modeOfPayment);
    assertEquals(withdrawal.getValue().getPreferredLocale(), userContext.getPreferredLocale());
    verify(loanBO).makeEarlyRepayment(paymentDto, (short) 1, waiveInterest, new Money(rupee, BigDecimal.ZERO), 1, null);
}
Also used : RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Test(org.junit.Test)

Example 8 with RepayLoanInfoDto

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

the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepayment.

@Test
public void testMakeEarlyRepayment() throws AccountException, PersistenceException {
    setMifosUserFromContext();
    when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
    when(loanDao.findById(0)).thenReturn(loanBO);
    java.sql.Date date = new java.sql.Date(new Date().getTime());
    when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
    when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
    when(loanBO.getCurrency()).thenReturn(rupee);
    boolean waiveInterest = true;
    when(loanBO.isInterestWaived()).thenReturn(waiveInterest);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    when(customer.getCustomerId()).thenReturn(2);
    String paymentMethod = "1";
    String receiptNumber = "001";
    org.mifos.dto.domain.AccountPaymentDto paymentDto = new org.mifos.dto.domain.AccountPaymentDto(new Double(100), date, receiptNumber, date, Short.valueOf((short) 1));
    loanAccountServiceFacade.makeEarlyRepayment(new RepayLoanInfoDto("1", "100", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.TEN, BigDecimal.ZERO));
    verify(loanBO).makeEarlyRepayment(paymentDto, (short) 1, waiveInterest, new Money(rupee, BigDecimal.ZERO));
    verify(loanBusinessService).computeExtraInterest(loanBO, date);
}
Also used : RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Test(org.junit.Test)

Example 9 with RepayLoanInfoDto

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

the class LoanAccountServiceFacadeWebTierTest method testValidateMakeEarlyRepayment.

@Test
public void testValidateMakeEarlyRepayment() throws AccountException, PersistenceException {
    setMifosUserFromContext();
    when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
    when(loanDao.findById(0)).thenReturn(loanBO);
    boolean actualWaiveInterestValue = false;
    java.sql.Date date = mock(java.sql.Date.class);
    when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
    when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
    when(loanBO.isInterestWaived()).thenReturn(actualWaiveInterestValue);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    when(customer.getCustomerId()).thenReturn(2);
    try {
        loanAccountServiceFacade.makeEarlyRepayment(new RepayLoanInfoDto("1", "100", "001", mock(java.sql.Date.class), "1", (short) 1, true, date, BigDecimal.ZERO, BigDecimal.ZERO));
    } catch (BusinessRuleException e) {
        verify(loanBO, never()).makeEarlyRepayment((AccountPaymentDto) anyObject(), (Short) anyObject(), anyBoolean(), Matchers.<Money>anyObject());
        verify(loanBO, never()).getCurrency();
        verify(loanBusinessService, never()).computeExtraInterest(eq(loanBO), Matchers.<Date>anyObject());
        assertThat(e.getMessageKey(), is(LoanConstants.WAIVER_INTEREST_NOT_CONFIGURED));
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

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