Skip to content

Commit c3ed5ca

Browse files
committed
FINERACT-2389: EMI rounding handling
1 parent 6d051f5 commit c3ed5ca

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/factory/LoanProductsRequestFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ public PostLoanProductsRequest defaultLoanProductsRequestLP2() {
823823
.inMultiplesOf(0)//
824824
.installmentAmountInMultiplesOf(1)//
825825
.useBorrowerCycle(false)//
826-
.minPrincipal(100.0)//
826+
.minPrincipal(1.0)//
827827
.principal(1000.0)//
828828
.maxPrincipal(10000.0)//
829829
.minNumberOfRepayments(1)//
@@ -1046,7 +1046,7 @@ public PostLoanProductsRequest defaultLoanProductsRequestLP2Emi() {
10461046
.digitsAfterDecimal(2)//
10471047
.inMultiplesOf(0)//
10481048
.useBorrowerCycle(false)//
1049-
.minPrincipal(10.0)//
1049+
.minPrincipal(1.0)//
10501050
.principal(1000.0)//
10511051
.maxPrincipal(10000.0)//
10521052
.minNumberOfRepayments(1)//
@@ -1295,7 +1295,7 @@ public PostLoanProductsRequest defaultLoanProductsRequestLP2ChargeOffReasonToExp
12951295
.inMultiplesOf(0)//
12961296
.installmentAmountInMultiplesOf(1)//
12971297
.useBorrowerCycle(false)//
1298-
.minPrincipal(100.0)//
1298+
.minPrincipal(1.0)//
12991299
.principal(1000.0)//
13001300
.maxPrincipal(10000.0)//
13011301
.minNumberOfRepayments(1)//
@@ -1534,7 +1534,7 @@ public PostLoanProductsRequest defaultLoanProductsRequestLP2CapitalizedIncome()
15341534
.inMultiplesOf(0)//
15351535
.installmentAmountInMultiplesOf(1)//
15361536
.useBorrowerCycle(false)//
1537-
.minPrincipal(100.0)//
1537+
.minPrincipal(1.0)//
15381538
.principal(1000.0)//
15391539
.maxPrincipal(10000.0)//
15401540
.minNumberOfRepayments(1)//

fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,11 +1398,23 @@ private void calculateEMIOnNewModelAndMerge(List<RepaymentPeriod> repaymentPerio
13981398

13991399
private Money applyInstallmentAmountInMultiplesOf(final ProgressiveLoanInterestScheduleModel scheduleModel,
14001400
final Money equalMonthlyInstallment) {
1401-
return scheduleModel.installmentAmountInMultiplesOf() != null
1402-
? Money.roundToMultiplesOf(equalMonthlyInstallment, scheduleModel.installmentAmountInMultiplesOf())
1401+
return scheduleModel.installmentAmountInMultiplesOf() != null && scheduleModel.installmentAmountInMultiplesOf() > 0
1402+
? safeRoundingForEMI(equalMonthlyInstallment, scheduleModel.installmentAmountInMultiplesOf())
14031403
: equalMonthlyInstallment;
14041404
}
14051405

1406+
/**
1407+
* Rounds the EMI to the nearest multiple of the given number. If the rounded EMI is zero, it adds one multiple of
1408+
* the given number to it.
1409+
*/
1410+
private Money safeRoundingForEMI(Money unRoundedEMI, Integer multiplesOf) {
1411+
Money roundedEMI = Money.roundToMultiplesOf(unRoundedEMI, multiplesOf);
1412+
if (roundedEMI.isZero()) {
1413+
roundedEMI = roundedEMI.add(BigDecimal.ONE.multiply(BigDecimal.valueOf(multiplesOf)));
1414+
}
1415+
return roundedEMI;
1416+
}
1417+
14061418
public EmiAdjustment getEmiAdjustment(final List<RepaymentPeriod> repaymentPeriods) {
14071419
for (int idx = repaymentPeriods.size() - 1; idx > 0; --idx) {
14081420
RepaymentPeriod lastPeriod = repaymentPeriods.get(idx);

0 commit comments

Comments
 (0)