FINERACT-2389: EMI rounding handling

This commit is contained in:
Adam Saghy
2025-12-11 17:08:57 +01:00
parent 6d051f5a2f
commit c3ed5caab2
2 changed files with 18 additions and 6 deletions
@@ -823,7 +823,7 @@ public class LoanProductsRequestFactory {
.inMultiplesOf(0)// .inMultiplesOf(0)//
.installmentAmountInMultiplesOf(1)// .installmentAmountInMultiplesOf(1)//
.useBorrowerCycle(false)// .useBorrowerCycle(false)//
.minPrincipal(100.0)// .minPrincipal(1.0)//
.principal(1000.0)// .principal(1000.0)//
.maxPrincipal(10000.0)// .maxPrincipal(10000.0)//
.minNumberOfRepayments(1)// .minNumberOfRepayments(1)//
@@ -1046,7 +1046,7 @@ public class LoanProductsRequestFactory {
.digitsAfterDecimal(2)// .digitsAfterDecimal(2)//
.inMultiplesOf(0)// .inMultiplesOf(0)//
.useBorrowerCycle(false)// .useBorrowerCycle(false)//
.minPrincipal(10.0)// .minPrincipal(1.0)//
.principal(1000.0)// .principal(1000.0)//
.maxPrincipal(10000.0)// .maxPrincipal(10000.0)//
.minNumberOfRepayments(1)// .minNumberOfRepayments(1)//
@@ -1295,7 +1295,7 @@ public class LoanProductsRequestFactory {
.inMultiplesOf(0)// .inMultiplesOf(0)//
.installmentAmountInMultiplesOf(1)// .installmentAmountInMultiplesOf(1)//
.useBorrowerCycle(false)// .useBorrowerCycle(false)//
.minPrincipal(100.0)// .minPrincipal(1.0)//
.principal(1000.0)// .principal(1000.0)//
.maxPrincipal(10000.0)// .maxPrincipal(10000.0)//
.minNumberOfRepayments(1)// .minNumberOfRepayments(1)//
@@ -1534,7 +1534,7 @@ public class LoanProductsRequestFactory {
.inMultiplesOf(0)// .inMultiplesOf(0)//
.installmentAmountInMultiplesOf(1)// .installmentAmountInMultiplesOf(1)//
.useBorrowerCycle(false)// .useBorrowerCycle(false)//
.minPrincipal(100.0)// .minPrincipal(1.0)//
.principal(1000.0)// .principal(1000.0)//
.maxPrincipal(10000.0)// .maxPrincipal(10000.0)//
.minNumberOfRepayments(1)// .minNumberOfRepayments(1)//
@@ -1398,11 +1398,23 @@ public final class ProgressiveEMICalculator implements EMICalculator {
private Money applyInstallmentAmountInMultiplesOf(final ProgressiveLoanInterestScheduleModel scheduleModel, private Money applyInstallmentAmountInMultiplesOf(final ProgressiveLoanInterestScheduleModel scheduleModel,
final Money equalMonthlyInstallment) { final Money equalMonthlyInstallment) {
return scheduleModel.installmentAmountInMultiplesOf() != null return scheduleModel.installmentAmountInMultiplesOf() != null && scheduleModel.installmentAmountInMultiplesOf() > 0
? Money.roundToMultiplesOf(equalMonthlyInstallment, scheduleModel.installmentAmountInMultiplesOf()) ? safeRoundingForEMI(equalMonthlyInstallment, scheduleModel.installmentAmountInMultiplesOf())
: equalMonthlyInstallment; : equalMonthlyInstallment;
} }
/**
* Rounds the EMI to the nearest multiple of the given number. If the rounded EMI is zero, it adds one multiple of
* the given number to it.
*/
private Money safeRoundingForEMI(Money unRoundedEMI, Integer multiplesOf) {
Money roundedEMI = Money.roundToMultiplesOf(unRoundedEMI, multiplesOf);
if (roundedEMI.isZero()) {
roundedEMI = roundedEMI.add(BigDecimal.ONE.multiply(BigDecimal.valueOf(multiplesOf)));
}
return roundedEMI;
}
public EmiAdjustment getEmiAdjustment(final List<RepaymentPeriod> repaymentPeriods) { public EmiAdjustment getEmiAdjustment(final List<RepaymentPeriod> repaymentPeriods) {
for (int idx = repaymentPeriods.size() - 1; idx > 0; --idx) { for (int idx = repaymentPeriods.size() - 1; idx > 0; --idx) {
RepaymentPeriod lastPeriod = repaymentPeriods.get(idx); RepaymentPeriod lastPeriod = repaymentPeriods.get(idx);