Skip to content

Commit aead4ef

Browse files
committed
FINERACT-2520: Add disbursement charges to total repayment expected
Signed-off-by: Wiki05 <vigneshdev1022@gmail.com> Signed-off-by: Vignesh <vigneshdev1022@gmail.com>
1 parent 04b015d commit aead4ef

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public LoanScheduleModel generate(final MathContext mc, final LoanApplicationTer
144144
scheduleParams.incrementPeriodNumber();
145145
}
146146

147+
if (chargesDueAtTimeOfDisbursement.compareTo(BigDecimal.ZERO) > 0) {
148+
scheduleParams.addTotalRepaymentExpected(Money.of(currency, chargesDueAtTimeOfDisbursement, mc));
149+
}
150+
147151
if (loanApplicationTerms.isMultiDisburseLoan()) {
148152
processDisbursements(loanApplicationTerms, disbursementDataList, scheduleParams, interestScheduleModel, periods,
149153
chargesDueAtTimeOfDisbursement, true, mc);

fineract-progressive-loan/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanScheduleGeneratorTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class LoanScheduleGeneratorTest {
4949
private static final CurrencyData CURRENCY = APPLICATION_CURRENCY.toData();
5050
private static final BigDecimal DISBURSEMENT_AMOUNT = BigDecimal.valueOf(192.22);
5151
private static final BigDecimal DISBURSEMENT_AMOUNT_100 = BigDecimal.valueOf(100);
52+
private static final BigDecimal DISBURSEMENT_CHARGE = BigDecimal.valueOf(10.0);
5253
private static final BigDecimal NOMINAL_INTEREST_RATE = BigDecimal.valueOf(9.99);
5354
private static final int NUMBER_OF_REPAYMENTS = 6;
5455
private static final int REPAYMENT_FREQUENCY = 1;
@@ -168,4 +169,37 @@ private void checkDownPaymentPeriod(LoanSchedulePlanDownPaymentPeriod period, in
168169
assertEquals(0, expectedTotalDue.compareTo(period.getTotalDueAmount()));
169170
assertEquals(0, expectedOutstandingLoanBalance.compareTo(period.getOutstandingLoanBalance()));
170171
}
172+
173+
@Test
174+
void testGenerateLoanScheduleWithDisbursementCharges() {
175+
LoanRepaymentScheduleModelData modelData = new LoanRepaymentScheduleModelData(LocalDate.of(2024, 1, 1), CURRENCY,
176+
DISBURSEMENT_AMOUNT, DISBURSEMENT_DATE, NUMBER_OF_REPAYMENTS, REPAYMENT_FREQUENCY, REPAYMENT_FREQUENCY_TYPE,
177+
NOMINAL_INTEREST_RATE, false, DaysInMonthType.DAYS_30, DaysInYearType.DAYS_360, null, null, null, false, null,
178+
InterestMethod.DECLINING_BALANCE, true, false);
179+
180+
ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator();
181+
ProgressiveLoanScheduleGenerator generator = new ProgressiveLoanScheduleGenerator(scheduledDateGenerator, emiCalculator,
182+
interestScheduleModelRepositoryWrapperMock);
183+
generator.setLoanTransactionProcessingService(loanTransactionProcessingService);
184+
185+
LoanSchedulePlan loanSchedule = generator.generate(mc, modelData);
186+
187+
BigDecimal totalPrincipal = BigDecimal.ZERO;
188+
BigDecimal totalInterest = BigDecimal.ZERO;
189+
BigDecimal totalDueAmount = BigDecimal.ZERO;
190+
191+
for (var period : loanSchedule.getPeriods()) {
192+
if (period instanceof LoanSchedulePlanRepaymentPeriod repayment) {
193+
totalPrincipal = totalPrincipal.add(repayment.getPrincipalAmount());
194+
totalInterest = totalInterest.add(repayment.getInterestAmount());
195+
totalDueAmount = totalDueAmount.add(repayment.getTotalDueAmount());
196+
}
197+
}
198+
199+
BigDecimal expectedTotalWithCharge = totalPrincipal.add(totalInterest).add(DISBURSEMENT_CHARGE);
200+
201+
assertEquals(0, expectedTotalWithCharge.stripTrailingZeros()
202+
.compareTo(totalDueAmount.stripTrailingZeros()));
203+
}
204+
171205
}

0 commit comments

Comments
 (0)