FINERACT-2201: [Bug] - Negative numbers in case of progressive interest bearing loans - Reamortization

This commit is contained in:
Soma Sörös
2025-03-12 12:33:42 +00:00
committed by Adam Saghy
parent 1fb5e3da43
commit a28b9332b9
3 changed files with 584 additions and 4 deletions
@@ -33,6 +33,7 @@ import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@@ -1940,6 +1941,14 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
Money evenPortion = transactionAmountUnprocessed.dividedBy(numberOfInstallments, MoneyHelper.getMathContext());
// Adjustment might be needed due to the divide operation and the rounding mode
Money balanceAdjustment = transactionAmountUnprocessed.minus(evenPortion.multipliedBy(numberOfInstallments));
if (evenPortion.add(balanceAdjustment).isLessThanZero()) {
// Note: Rounding mode DOWN grants that evenPortion cant pay more than unprocessed
// transaction amount.
evenPortion = transactionAmountUnprocessed.dividedBy(numberOfInstallments,
new MathContext(MoneyHelper.getMathContext().getPrecision(), RoundingMode.DOWN));
balanceAdjustment = transactionAmountUnprocessed.minus(evenPortion.multipliedBy(numberOfInstallments));
}
for (LoanRepaymentScheduleInstallment inAdvanceInstallment : inAdvanceInstallments) {
Set<LoanCharge> inAdvanceInstallmentCharges = getLoanChargesOfInstallment(charges, inAdvanceInstallment,
firstNormalInstallmentNumber);