FINERACT-1981: Fix Better EMI check in EMI Calculator

This commit is contained in:
Janos Meszaros
2024-10-21 17:34:44 +02:00
committed by Adam Saghy
parent 482983f23d
commit 84d606552d
3 changed files with 41 additions and 4 deletions
@@ -155,7 +155,7 @@ public class RepaymentPeriod {
.minus(getDuePrincipal())//
.plus(getPaidPrincipal());//
return MathUtil.negativeToZero(calculatedOutStandingLoanBalance);
}, () -> interestPeriods);
}, () -> new Object[] { paidPrincipal, paidInterest, interestPeriods });
}
return outstandingBalanceCalculation.get();
}
@@ -186,9 +186,6 @@ public final class ProgressiveEMICalculator implements EMICalculator {
calculateOutstandingBalance(scheduleModel);
calculateLastUnpaidRepaymentPeriodEMI(scheduleModel);
checkAndAdjustEmiIfNeededOnRelatedRepaymentPeriods(scheduleModel, relatedRepaymentPeriods);
// TODO: optimalize
calculateOutstandingBalance(scheduleModel);
calculateLastUnpaidRepaymentPeriodEMI(scheduleModel);
}
private void calculateLastUnpaidRepaymentPeriodEMI(ProgressiveLoanInterestScheduleModel scheduleModel) {
@@ -235,6 +232,8 @@ public final class ProgressiveEMICalculator implements EMICalculator {
period.setEmi(adjustedEqualMonthlyInstallmentValue);
}
});
calculateOutstandingBalance(newScheduleModel);
calculateLastUnpaidRepaymentPeriodEMI(newScheduleModel);
final Money newEmiDifference = getDifferenceBetweenLastTwoPeriod(newScheduleModel.repaymentPeriods(), scheduleModel);
final boolean newEmiHasLessDifference = newEmiDifference.abs().isLessThan(emiDifference.abs());
if (!newEmiHasLessDifference) {
@@ -252,6 +251,7 @@ public final class ProgressiveEMICalculator implements EMICalculator {
final RepaymentPeriod newRepaymentPeriod = relatedPeriodFromNewModelIterator.next();
relatedRepaymentPeriod.setEmi(newRepaymentPeriod.getEmi());
});
calculateOutstandingBalance(scheduleModel);
}
}