Search in sources :

Example 1 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 2 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 3 with RepaymentResultsHolder

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

the class ScheduleCalculatorTest method shouldComputeRepaymentAmountWhenOnDateExcessPaymentMade.

@Test
public void shouldComputeRepaymentAmountWhenOnDateExcessPaymentMade() {
    Installment installment1 = getInstallment(1, getDate(25, 9, 2010), 242.24, 20.40, 0);
    Installment installment2 = getInstallment(2, getDate(25, 10, 2010), 247.67, 14.96, 0);
    Installment installment3 = getInstallment(3, getDate(25, 11, 2010), 252.22, 10.40, 0);
    Installment installment4 = getInstallment(4, getDate(25, 12, 2010), 257.87, 5.09, 0);
    schedule = new Schedule(getDate(25, 8, 2010), 0.000658, BigDecimal.valueOf(1000d), asList(installment1, installment2, installment3, installment4));
    scheduleCalculator.applyPayment(schedule, BigDecimal.valueOf(500d), getDate(30, 10, 2010), false);
    RepaymentResultsHolder repaymentResultsHolder = scheduleCalculator.computeRepaymentAmount(schedule, getDate(25, 12, 2010));
    assertThat(repaymentResultsHolder.getTotalRepaymentAmount().doubleValue(), is(563.36));
    assertThat(repaymentResultsHolder.getWaiverAmount().doubleValue(), is(5.09));
}
Also used : Installment(org.mifos.accounts.loan.schedule.domain.Installment) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) RepaymentResultsHolder(org.mifos.accounts.loan.business.RepaymentResultsHolder) Test(org.junit.Test)

Example 4 with RepaymentResultsHolder

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

the class ScheduleCalculatorTest method shouldComputeRepaymentAmountWhenLateExcessPaymentMade.

@Test
public void shouldComputeRepaymentAmountWhenLateExcessPaymentMade() {
    Installment installment1 = getInstallment(1, getDate(25, 9, 2010), 242.24, 20.40, 0);
    Installment installment2 = getInstallment(2, getDate(25, 10, 2010), 247.67, 14.96, 0);
    Installment installment3 = getInstallment(3, getDate(25, 11, 2010), 252.22, 10.40, 0);
    Installment installment4 = getInstallment(4, getDate(25, 12, 2010), 257.87, 5.09, 0);
    schedule = new Schedule(getDate(25, 8, 2010), 0.000658, BigDecimal.valueOf(1000d), asList(installment1, installment2, installment3, installment4));
    scheduleCalculator.applyPayment(schedule, BigDecimal.valueOf(500d), getDate(30, 10, 2010), false);
    RepaymentResultsHolder repaymentResultsHolder = scheduleCalculator.computeRepaymentAmount(schedule, getDate(30, 11, 2010));
    assertThat(repaymentResultsHolder.getTotalRepaymentAmount().doubleValue(), is(554.46));
    assertThat(repaymentResultsHolder.getWaiverAmount().doubleValue(), is(0.85));
}
Also used : Installment(org.mifos.accounts.loan.schedule.domain.Installment) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) RepaymentResultsHolder(org.mifos.accounts.loan.business.RepaymentResultsHolder) Test(org.junit.Test)

Example 5 with RepaymentResultsHolder

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

the class ScheduleCalculatorTest method shouldComputeRepaymentAmountWhenNoPastPaymentsMade.

@Test
public void shouldComputeRepaymentAmountWhenNoPastPaymentsMade() {
    Installment installment1 = getInstallment(1, getDate(25, 9, 2010), 242.24, 20.40, 0);
    Installment installment2 = getInstallment(2, getDate(25, 10, 2010), 247.67, 14.96, 0);
    Installment installment3 = getInstallment(3, getDate(25, 11, 2010), 252.22, 10.40, 0);
    Installment installment4 = getInstallment(4, getDate(25, 12, 2010), 257.87, 5.09, 0);
    schedule = new Schedule(getDate(25, 8, 2010), 0.000658, BigDecimal.valueOf(1000d), asList(installment1, installment2, installment3, installment4));
    RepaymentResultsHolder repaymentResultsHolder = scheduleCalculator.computeRepaymentAmount(schedule, getDate(30, 11, 2010));
    assertThat(repaymentResultsHolder.getTotalRepaymentAmount().doubleValue(), is(1063.83));
    assertThat(repaymentResultsHolder.getWaiverAmount().doubleValue(), is(0.85));
}
Also used : Installment(org.mifos.accounts.loan.schedule.domain.Installment) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) 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