FINERACT-2221: Fix - Interest not counted towards totalUnpaidPayableNotDueInterest after partial repayment

This commit is contained in:
Adam Saghy
2025-03-24 14:23:00 +01:00
parent 2251ee0da6
commit b2af4a635c
11 changed files with 261 additions and 46 deletions
@@ -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))
@@ -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);
}
/**
@@ -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);