FINERACT-1971: Fix EMI Calculator: Last Unpaid Repayment Period Handling.

call calculateLastUnpaidRepaymentPeriodEMI recursively when emi would be less than zero to adjust remaining emi correction for previous period.
This commit is contained in:
Soma Sörös
2025-01-10 13:53:07 +01:00
committed by Adam Saghy
parent cee5b43b71
commit 100405a579
4 changed files with 202 additions and 1 deletions
@@ -307,7 +307,13 @@ public final class ProgressiveEMICalculator implements EMICalculator {
Money diff = totalDisbursedAmount.plus(totalDueInterest, mc).minus(totalEMI, mc);
Optional<RepaymentPeriod> findLastUnpaidRepaymentPeriod = scheduleModel.repaymentPeriods().stream().filter(rp -> !rp.isFullyPaid())
.reduce((first, second) -> second);
findLastUnpaidRepaymentPeriod.ifPresent(repaymentPeriod -> repaymentPeriod.setEmi(repaymentPeriod.getEmi().add(diff, mc)));
findLastUnpaidRepaymentPeriod.ifPresent(repaymentPeriod -> {
repaymentPeriod.setEmi(repaymentPeriod.getEmi().add(diff, mc));
if (repaymentPeriod.getEmi().isLessThanZero()) {
repaymentPeriod.setEmi(repaymentPeriod.getEmi().zero());
calculateLastUnpaidRepaymentPeriodEMI(scheduleModel);
}
});
}
private void calculateOutstandingBalance(ProgressiveLoanInterestScheduleModel scheduleModel) {