FINERACT-2221: Fix - Interest not counted towards totalUnpaidPayableNotDueInterest after partial repayment
This commit is contained in:
+10
@@ -182,6 +182,16 @@ public class ProgressiveLoanScheduleGenerator implements LoanScheduleGenerator {
|
||||
.principal(outstandingAmounts.getOutstandingPrincipal()) //
|
||||
.interest(outstandingAmounts.getOutstandingInterest());//
|
||||
|
||||
// We need to deduct any paid amount if there is no interest recalculation
|
||||
if (!loan.isInterestRecalculationEnabled()) {
|
||||
BigDecimal paidInterest = installments.stream().map(LoanRepaymentScheduleInstallment::getInterestPaid).reduce(BigDecimal.ZERO,
|
||||
BigDecimal::add);
|
||||
BigDecimal paidPrincipal = installments.stream().map(LoanRepaymentScheduleInstallment::getPrincipal).reduce(BigDecimal.ZERO,
|
||||
BigDecimal::add);
|
||||
result.principal().minus(paidPrincipal);
|
||||
result.interest().minus(paidInterest);
|
||||
}
|
||||
|
||||
installments.forEach(installment -> {
|
||||
if (installment.isAdditional()) {
|
||||
result.plusPrincipal(installment.getPrincipalOutstanding(currency))
|
||||
|
||||
+1
-1
@@ -298,7 +298,7 @@ public class ProgressiveLoanInterestScheduleModel {
|
||||
* @return
|
||||
*/
|
||||
public Money getTotalDueInterest() {
|
||||
return repaymentPeriods().stream().map(RepaymentPeriod::getCalculatedDueInterest).reduce(zero(), Money::plus);
|
||||
return repaymentPeriods().stream().map(RepaymentPeriod::getDueInterest).reduce(zero(), Money::plus);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-4
@@ -1302,10 +1302,9 @@ class ProgressiveEMICalculatorTest {
|
||||
final LocalDate dueDate = LocalDate.of(2024, 2, 1);
|
||||
final LocalDate startDay = LocalDate.of(2024, 1, 1);
|
||||
|
||||
// TODO: work on interest calculation
|
||||
// emiCalculator.payInterest(interestModel, dueDate, startDay.plusDays(3), toMoney(0.56));
|
||||
// emiCalculator.chargebackInterest(interestModel, startDay.plusDays(3), toMoney(0.0));
|
||||
// emiCalculator.addBalanceCorrection(interestModel, startDay.plusDays(3), toMoney(0.0));
|
||||
emiCalculator.payInterest(interestModel, dueDate, startDay.plusDays(3), toMoney(0.56));
|
||||
emiCalculator.chargebackInterest(interestModel, startDay.plusDays(3), toMoney(0.0));
|
||||
emiCalculator.addBalanceCorrection(interestModel, startDay.plusDays(3), toMoney(0.0));
|
||||
|
||||
checkDailyInterest(interestModel, dueDate, startDay, 1, 0.19, 0.19);
|
||||
checkDailyInterest(interestModel, dueDate, startDay, 2, 0.19, 0.38);
|
||||
|
||||
Reference in New Issue
Block a user