Skip to content

Commit c167e38

Browse files
committed
FINERACT-2181: Cumulative loan reschedule and downpayment fix
1 parent dd4ca4d commit c167e38

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

fineract-e2e-tests-runner/src/test/resources/features/LoanDownPayment.feature

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ Feature: Loan DownPayment
11111111
| 2 | 31 | 01 February 2022 | 15 February 2022 | 500.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 250.0 | 0.0 | 250.0 | 0.0 |
11121112
| | | 15 February 2022 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
11131113
| 3 | 0 | 15 February 2022 | | 1250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 |
1114-
| 4 | 28 | 01 March 2022 | | 750.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 |
1115-
| 5 | 31 | 01 April 2022 | | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 |
1114+
| 4 | 28 | 01 March 2022 | | 625.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
1115+
| 5 | 31 | 01 April 2022 | | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
11161116
Then Loan Repayment schedule has the following data in Total row:
11171117
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
11181118
| 2000.0 | 0 | 0 | 0 | 2000.0 | 500.0 | 0 | 250 | 1500 |
@@ -1162,8 +1162,8 @@ Feature: Loan DownPayment
11621162
| 2 | 31 | 01 February 2022 | | 500.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 |
11631163
| | | 15 February 2022 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
11641164
| 3 | 0 | 15 February 2022 | | 1250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 |
1165-
| 4 | 28 | 01 March 2022 | | 750.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 |
1166-
| 5 | 31 | 01 April 2022 | | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 |
1165+
| 4 | 28 | 01 March 2022 | | 625.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
1166+
| 5 | 31 | 01 April 2022 | | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
11671167
Then Loan Repayment schedule has the following data in Total row:
11681168
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
11691169
| 2000.0 | 0 | 0 | 0 | 2000.0 | 250.0 | 0 | 0 | 1750 |
@@ -1175,8 +1175,8 @@ Feature: Loan DownPayment
11751175
| 2 | 31 | 01 February 2022 | 15 February 2022 | 500.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 250.0 | 0.0 | 250.0 | 0.0 |
11761176
| | | 15 February 2022 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
11771177
| 3 | 0 | 15 February 2022 | | 1250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 |
1178-
| 4 | 28 | 01 March 2022 | | 750.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 |
1179-
| 5 | 31 | 01 April 2022 | | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 |
1178+
| 4 | 28 | 01 March 2022 | | 625.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
1179+
| 5 | 31 | 01 April 2022 | | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
11801180
Then Loan Repayment schedule has the following data in Total row:
11811181
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
11821182
| 2000.0 | 0 | 0 | 0 | 2000.0 | 500.0 | 0 | 250 | 1500 |
@@ -1227,8 +1227,8 @@ Feature: Loan DownPayment
12271227
| 2 | 31 | 01 February 2022 | 01 February 2022 | 500.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 |
12281228
| | | 15 February 2022 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
12291229
| 3 | 0 | 15 February 2022 | 15 February 2022 | 1250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 |
1230-
| 4 | 28 | 01 March 2022 | | 750.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 |
1231-
| 5 | 31 | 01 April 2022 | | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 |
1230+
| 4 | 28 | 01 March 2022 | | 625.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
1231+
| 5 | 31 | 01 April 2022 | | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
12321232
Then Loan Repayment schedule has the following data in Total row:
12331233
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
12341234
| 2000.0 | 0 | 0 | 0 | 2000.0 | 750.0 | 0 | 0 | 1250 |
@@ -1291,8 +1291,8 @@ Feature: Loan DownPayment
12911291
| 2 | 31 | 01 February 2022 | 01 February 2022 | 500.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 |
12921292
| | | 15 February 2022 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
12931293
| 3 | 0 | 15 February 2022 | | 1250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 |
1294-
| 4 | 28 | 01 March 2022 | | 750.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 |
1295-
| 5 | 31 | 01 April 2022 | | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 |
1294+
| 4 | 28 | 01 March 2022 | | 625.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
1295+
| 5 | 31 | 01 April 2022 | | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
12961296
Then Loan Repayment schedule has the following data in Total row:
12971297
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
12981298
| 2000.0 | 0 | 0 | 0 | 2000.0 | 500.0 | 0 | 0 | 1500 |
@@ -1304,8 +1304,8 @@ Feature: Loan DownPayment
13041304
| 2 | 31 | 01 February 2022 | 01 February 2022 | 500.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 |
13051305
| | | 15 February 2022 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | |
13061306
| 3 | 0 | 15 February 2022 | 15 February 2022 | 1250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 |
1307-
| 4 | 28 | 01 March 2022 | | 750.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 0.0 | 0.0 | 0.0 | 500.0 |
1308-
| 5 | 31 | 01 April 2022 | | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 | 0.0 | 0.0 | 0.0 | 750.0 |
1307+
| 4 | 28 | 01 March 2022 | | 625.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
1308+
| 5 | 31 | 01 April 2022 | | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 | 0.0 | 0.0 | 0.0 | 625.0 |
13091309
Then Loan Repayment schedule has the following data in Total row:
13101310
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
13111311
| 2000.0 | 0 | 0 | 0 | 2000.0 | 750.0 | 0 | 0 | 1250 |

fineract-e2e-tests-runner/src/test/resources/features/LoanReschedule.feature

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,6 @@ Feature: LoanReschedule
344344
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
345345
| 1400.0 | 0.0 | 0.0 | 0.0 | 1400.0 | 350.0 | 0.0 | 0.0 | 1050.0 |
346346

347-
# TODO unskip and check when PS-1729 is done
348-
@Skip
349347
@TestRailId:C2998
350348
Scenario: Verify that reschedule: add extra terms working properly with auto downpayment and 2nd disbursement after reschedule and first installment
351349
When Admin sets the business date to "01 October 2023"

fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/AbstractCumulativeLoanScheduleGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,8 @@ private void processDisbursements(final LoanApplicationTerms loanApplicationTerm
10581058
scheduleParams.addOutstandingBalance(remainingPrincipal);
10591059
scheduleParams.addPrincipalToBeScheduled(remainingPrincipal);
10601060
loanApplicationTerms.setPrincipal(loanApplicationTerms.getPrincipal().plus(remainingPrincipal));
1061+
loanApplicationTerms.updateAccountedTillPeriod(scheduleParams.getPeriodNumber() - 1,
1062+
scheduleParams.getTotalCumulativePrincipal(), scheduleParams.getTotalCumulativeInterest(), 0);
10611063
}
10621064
}
10631065
}

fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,12 @@ private Money flatInterestPerInstallment(final MathContext mc, final Money total
11791179
.dividedBy(Long.valueOf(this.actualNumberOfRepayments) - defaultToZeroIfNull(this.excludePeriodsForCalculation), mc);
11801180
if (this.excludePeriodsForCalculation < this.periodsCompleted) {
11811181
Money interestLeft = this.totalInterestDue.minus(this.totalInterestAccounted);
1182-
interestPerInstallment = interestLeft
1183-
.dividedBy(Long.valueOf(this.actualNumberOfRepayments) - defaultToZeroIfNull(this.periodsCompleted), mc);
1182+
long remainingPeriods = Long.valueOf(this.actualNumberOfRepayments) - defaultToZeroIfNull(this.periodsCompleted);
1183+
if (remainingPeriods > 0) {
1184+
interestPerInstallment = interestLeft.dividedBy(remainingPeriods, mc);
1185+
} else {
1186+
interestPerInstallment = interestLeft;
1187+
}
11841188
}
11851189

11861190
return interestPerInstallment;
@@ -1195,8 +1199,12 @@ private Money calculateTotalPrincipalPerPeriodWithoutGrace(final MathContext mc,
11951199
principalPerPeriod = this.principal.minus(totalPrincipalAccounted)
11961200
.percentageOf(this.fixedPrincipalPercentagePerInstallment, mc).plus(this.adjustPrincipalForFlatLoans);
11971201
} else {
1198-
principalPerPeriod = this.principal.minus(totalPrincipalAccounted).dividedBy(totalRepaymentsWithCapitalPayment, mc)
1199-
.plus(this.adjustPrincipalForFlatLoans);
1202+
if (totalRepaymentsWithCapitalPayment > 0) {
1203+
principalPerPeriod = this.principal.minus(totalPrincipalAccounted).dividedBy(totalRepaymentsWithCapitalPayment, mc)
1204+
.plus(this.adjustPrincipalForFlatLoans);
1205+
} else {
1206+
principalPerPeriod = this.principal.minus(totalPrincipalAccounted).plus(this.adjustPrincipalForFlatLoans);
1207+
}
12001208
}
12011209
if (isPrincipalGraceApplicableForThisPeriod(periodNumber)) {
12021210
principalPerPeriod = principalPerPeriod.zero();
@@ -1283,7 +1291,11 @@ private Money calculateTotalFlatInterestForInstallmentAveragingOutGracePeriods(f
12831291
Money interestLeft = this.totalInterestDue.minus(this.totalInterestAccounted);
12841292
Integer interestDuePeriods = calculateNumberOfRemainingInterestPaymentPeriods(this.actualNumberOfRepayments,
12851293
this.periodsCompleted);
1286-
interestForInstallment = interestLeft.dividedBy(Long.valueOf(interestDuePeriods), mc);
1294+
if (interestDuePeriods != null && interestDuePeriods > 0) {
1295+
interestForInstallment = interestLeft.dividedBy(Long.valueOf(interestDuePeriods), mc);
1296+
} else {
1297+
interestForInstallment = interestLeft;
1298+
}
12871299
}
12881300
if (!this.periodNumbersApplicableForInterestGrace.isEmpty()) {
12891301
int periodsElapsed = calculateLastInterestGracePeriod(periodNumber);

integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanProductRepaymentStartDateConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ public void loanAccountWithLoanProductRepaymentStartDateTypeAsSubmittedOnDateSch
268268
assertEquals(2, loanDetails.getRepaymentSchedule().getPeriods().get(3).getPeriod());
269269
assertEquals(LocalDate.of(2023, 4, 3), loanDetails.getRepaymentSchedule().getPeriods().get(3).getFromDate());
270270
assertEquals(LocalDate.of(2023, 5, 3), loanDetails.getRepaymentSchedule().getPeriods().get(3).getDueDate());
271-
assertEquals(333.33,
271+
assertEquals(416.66,
272272
Utils.getDoubleValue(loanDetails.getRepaymentSchedule().getPeriods().get(3).getTotalInstallmentAmountForPeriod()));
273273

274274
// third period [2023-05-03 to 2023-06-03]
275275
assertEquals(3, loanDetails.getRepaymentSchedule().getPeriods().get(4).getPeriod());
276276
assertEquals(LocalDate.of(2023, 5, 3), loanDetails.getRepaymentSchedule().getPeriods().get(4).getFromDate());
277277
assertEquals(LocalDate.of(2023, 6, 3), loanDetails.getRepaymentSchedule().getPeriods().get(4).getDueDate());
278-
assertEquals(500.00,
278+
assertEquals(416.67,
279279
Utils.getDoubleValue(loanDetails.getRepaymentSchedule().getPeriods().get(4).getTotalInstallmentAmountForPeriod()));
280280

281281
} finally {

integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionAccrualActivityPostingTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,21 +1203,21 @@ public void testAccrualActivityPostingForMultiDisburseLoan() {
12031203
loanTransactionHelper.disburseLoan(loanId.get(), new PostLoansLoanIdRequest().actualDisbursementDate(disbursementDay2)
12041204
.dateFormat(DATETIME_PATTERN).transactionAmount(BigDecimal.valueOf(500.0)).locale("en"));
12051205
verifyTransactions(loanId.get(),
1206-
transaction(500.0, "Disbursement", disbursementDay2, 479.16, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, false), //
1207-
transaction(650.0, "Repayment", repaymentDate1, 0.0, 520.84, 59.16, 40.0, 30.0, 0.0, 0.0, false), //
1206+
transaction(500.0, "Disbursement", disbursementDay2, 479.18, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, false), //
1207+
transaction(650.0, "Repayment", repaymentDate1, 0.0, 520.82, 59.18, 40.0, 30.0, 0.0, 0.0, false), //
12081208
transaction(89.72, "Accrual Activity", repaymentPeriod1DueDate, 0.0, 0.0, 19.72, 40.0, 30.0, 0.0, 0.0, false), //
12091209
transaction(500.0, "Disbursement", disbursementDay, 500.0, 0, 0, 0, 0, 0, 0, false) //
12101210
);
12111211
});
12121212
runAt(repaymentPeriod2CloseDate, () -> {
12131213
inlineLoanCOBHelper.executeInlineCOB(List.of(loanId.get()));
12141214
verifyTransactions(loanId.get(),
1215-
transaction(500.0, "Disbursement", disbursementDay2, 479.16, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, false), //
1216-
transaction(650.0, "Repayment", repaymentDate1, 0.0, 520.84, 59.16, 40.0, 30.0, 0.0, 0.0, false), //
1215+
transaction(500.0, "Disbursement", disbursementDay2, 479.18, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, false), //
1216+
transaction(650.0, "Repayment", repaymentDate1, 0.0, 520.82, 59.18, 40.0, 30.0, 0.0, 0.0, false), //
12171217
transaction(89.72, "Accrual Activity", repaymentPeriod1DueDate, 0.0, 0.0, 19.72, 40.0, 30.0, 0.0, 0.0, false), //
12181218
transaction(89.72, "Accrual", repaymentPeriod1DueDate, 0.0, 0.0, 19.72, 40.0, 30.0, 0.0, 0.0, false), //
1219-
transaction(19.72, "Accrual", repaymentPeriod2DueDate, 0.0, 0.0, 19.72, 0.0, 0.0, 0.0, 0.0, false), //
1220-
transaction(19.72, "Accrual Activity", repaymentPeriod2DueDate, 0.0, 0.0, 19.72, 0.0, 0.0, 0.0, 0.0, false), //
1219+
transaction(19.73, "Accrual", repaymentPeriod2DueDate, 0.0, 0.0, 19.73, 0.0, 0.0, 0.0, 0.0, false), //
1220+
transaction(19.73, "Accrual Activity", repaymentPeriod2DueDate, 0.0, 0.0, 19.73, 0.0, 0.0, 0.0, 0.0, false), //
12211221
transaction(500.0, "Disbursement", disbursementDay, 500.0, 0, 0, 0, 0, 0, 0, false) //
12221222
);
12231223
});

0 commit comments

Comments
 (0)