Search in sources :

Example 6 with RepaymentResultsHolder

use of org.mifos.accounts.loan.business.RepaymentResultsHolder in project head by mifos.

the class Schedule method computePayableAmountForFutureInstallments.

public RepaymentResultsHolder computePayableAmountForFutureInstallments(Date asOfDate) {
    List<Installment> futureInstallments = getInstallmentsOnOrAfter(asOfDate);
    RepaymentResultsHolder repaymentResultsHolder = new RepaymentResultsHolder();
    BigDecimal payableAmount = BigDecimal.ZERO;
    repaymentResultsHolder.setWaiverAmount(BigDecimal.ZERO);
    if (!futureInstallments.isEmpty()) {
        BigDecimal outstandingPrincipal = getOutstandingPrincipal(asOfDate);
        Installment firstFutureInstallment = futureInstallments.get(0);
        BigDecimal interestDue = computeAndAdjustInterest(firstFutureInstallment, getDurationForAdjustment(firstFutureInstallment, asOfDate), outstandingPrincipal);
        repaymentResultsHolder.setWaiverAmount(interestDue);
        payableAmount = payableAmount.add(interestDue).add(firstFutureInstallment.getExtraInterestDue()).add(firstFutureInstallment.getFeesDue()).add(firstFutureInstallment.getMiscFeesDue()).add(firstFutureInstallment.getPenaltyDue()).add(firstFutureInstallment.getMiscPenaltyDue());
        for (Installment futureInstallment : futureInstallments) {
            payableAmount = payableAmount.add(futureInstallment.getPrincipalDue());
        }
    }
    repaymentResultsHolder.setTotalRepaymentAmount(payableAmount);
    return repaymentResultsHolder;
}
Also used : RepaymentResultsHolder(org.mifos.accounts.loan.business.RepaymentResultsHolder) BigDecimal(java.math.BigDecimal)

Example 7 with RepaymentResultsHolder

use of org.mifos.accounts.loan.business.RepaymentResultsHolder 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 8 with RepaymentResultsHolder

use of org.mifos.accounts.loan.business.RepaymentResultsHolder 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)

Aggregations

RepaymentResultsHolder (org.mifos.accounts.loan.business.RepaymentResultsHolder)8 Test (org.junit.Test)5 Installment (org.mifos.accounts.loan.schedule.domain.Installment)4 Schedule (org.mifos.accounts.loan.schedule.domain.Schedule)4 BigDecimal (java.math.BigDecimal)2 LoanBO (org.mifos.accounts.loan.business.LoanBO)2 RepayLoanDto (org.mifos.dto.screen.RepayLoanDto)2 Money (org.mifos.framework.util.helpers.Money)2 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 SavingsDetailDto (org.mifos.dto.domain.SavingsDetailDto)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 MifosUser (org.mifos.security.MifosUser)1 UserContext (org.mifos.security.util.UserContext)1