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;
}
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);
}
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));
}
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));
}
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));
}
Aggregations