FINERACT-2413: Re-amortization reverse replay handling

This commit is contained in:
Oleksii Novikov
2025-12-18 12:37:52 +01:00
committed by Adam Saghy
parent e8e9fb139d
commit 630f41f11f
8 changed files with 208 additions and 178 deletions
@@ -643,6 +643,11 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
loanTransaction.updateComponentsAndTotal(totalOverDuePrincipal, totalOverDueInterest, Money.zero(currency),
Money.zero(currency));
if (totalOverDuePrincipal.isZero() && totalOverDueInterest.isZero() && loanTransaction.isNotReversed()) {
loanTransaction.reverse();
return;
}
emiCalculator.updateModelRepaymentPeriodsDuringReAmortizationWithEqualInterestSplit(progressiveTransactionCtx.getModel(),
transactionDate);
updateInstallmentsByRepaymentPeriods(loanTransaction, progressiveTransactionCtx);
@@ -720,6 +725,11 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
Money.zero(transactionCtx.getCurrency()), Money.zero(transactionCtx.getCurrency()),
Money.zero(transactionCtx.getCurrency()));
if (MathUtil.isEqualTo(overallOverDuePrincipal, ZERO) && loanTransaction.isNotReversed()) {
loanTransaction.reverse();
return;
}
LoanRepaymentScheduleInstallment lastFutureInstallment = futureInstallments.stream()
.max(Comparator.comparing(LoanRepaymentScheduleInstallment::getDueDate)).get();
BigDecimal reAmortizationAmountPerInstallment = overallOverDuePrincipal.divide(BigDecimal.valueOf(futureInstallments.size()),
@@ -762,6 +772,11 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
loanTransaction.resetDerivedComponents();
loanTransaction.updateComponentsAndTotal(totalOverDuePrincipal, totalOverDueInterest, Money.zero(currency), Money.zero(currency));
if (totalOverDuePrincipal.isZero() && totalOverDueInterest.isZero() && loanTransaction.isNotReversed()) {
loanTransaction.reverse();
return;
}
// Update the existing model with re-amortized periods
emiCalculator.updateModelRepaymentPeriodsDuringReAmortization(ctx.getModel(), transactionDate);
updateInstallmentsByRepaymentPeriods(loanTransaction, ctx);