Search in sources :

Example 6 with RepayLoanDto

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

the class LoanAccountServiceFacadeWebTierTest method shouldReturnRepayLoanDtoWithAllDataPopulatedForDecliningBalanceInterestRecalculation.

@Test
public void shouldReturnRepayLoanDtoWithAllDataPopulatedForDecliningBalanceInterestRecalculation() {
    setMifosUserFromContext();
    String accountNumber = "1234";
    LoanBO loanBO = mock(LoanBO.class);
    Money repaymentAmount = TestUtils.createMoney("1234");
    Money interest = TestUtils.createMoney("100");
    DateTime currentDate = new DateTime(2010, 10, 30, 0, 0, 0, 0);
    new DateTimeService().setCurrentDateTime(currentDate);
    RepaymentResultsHolder repaymentResultsHolder = new RepaymentResultsHolder();
    repaymentResultsHolder.setTotalRepaymentAmount(repaymentAmount.getAmount());
    repaymentResultsHolder.setWaiverAmount(interest.getAmount());
    when(loanDao.findByGlobalAccountNum(accountNumber)).thenReturn(loanBO);
    when(scheduleCalculatorAdaptor.computeRepaymentAmount(loanBO, currentDate.toDate())).thenReturn(repaymentResultsHolder);
    when(loanBO.getCurrency()).thenReturn(repaymentAmount.getCurrency());
    when(loanBO.isDecliningBalanceInterestRecalculation()).thenReturn(true);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(accountNumber);
    verify(loanDao).findByGlobalAccountNum(accountNumber);
    verify(scheduleCalculatorAdaptor).computeRepaymentAmount(loanBO, currentDate.toDate());
    verify(loanBO, never()).waiverAmount();
    verify(loanBO, never()).getEarlyRepayAmount();
    verify(loanBO).isDecliningBalanceInterestRecalculation();
    assertEquals(repayLoanDto.getEarlyRepaymentMoney(), repaymentAmount.toString());
    assertEquals(repayLoanDto.getWaivedRepaymentMoney(), repaymentAmount.subtract(interest).toString());
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) DateTimeService(org.mifos.framework.util.DateTimeService) DateTime(org.joda.time.DateTime) RepaymentResultsHolder(org.mifos.accounts.loan.business.RepaymentResultsHolder) Test(org.junit.Test)

Example 7 with RepayLoanDto

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

the class LoanAccountServiceFacadeWebTierTest method shouldReturnRepayLoanDtoWithAllDataPopulated.

@Test
public void shouldReturnRepayLoanDtoWithAllDataPopulated() {
    setMifosUserFromContext();
    String accountNumber = "1234";
    LoanBO loanBO = mock(LoanBO.class);
    Money repaymentAmount = TestUtils.createMoney("1234");
    Money interest = TestUtils.createMoney("100");
    when(loanDao.findByGlobalAccountNum(accountNumber)).thenReturn(loanBO);
    when(loanBO.getEarlyRepayAmount()).thenReturn(repaymentAmount);
    when(loanBO.waiverAmount()).thenReturn(interest);
    when(loanBO.isDecliningBalanceInterestRecalculation()).thenReturn(false);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    Money waivedAmount = repaymentAmount.subtract(interest);
    RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(accountNumber);
    verify(loanDao).findByGlobalAccountNum(accountNumber);
    verify(loanBO).waiverAmount();
    verify(loanBO).getEarlyRepayAmount();
    verify(loanBO).isDecliningBalanceInterestRecalculation();
    assertEquals(repayLoanDto.getEarlyRepaymentMoney(), repaymentAmount.toString());
    assertEquals(repayLoanDto.getWaivedRepaymentMoney(), waivedAmount.toString());
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) Test(org.junit.Test)

Example 8 with RepayLoanDto

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

the class LoanAccountRESTController method isLoanInterestWaivable.

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/interestWaivable", method = RequestMethod.GET)
@ResponseBody
public Map<String, String> isLoanInterestWaivable(@PathVariable String globalAccountNum) throws Exception {
    RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
    Map<String, String> map = new HashMap<String, String>();
    map.put("isInterestWaivable", Boolean.toString(repayLoanDto.shouldWaiverInterest()));
    map.put("defaultValue", Boolean.toString(repayLoanDto.shouldWaiverInterest()));
    return map;
}
Also used : HashMap(java.util.HashMap) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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