@@ -1265,6 +1265,73 @@ public void test_dailyInterest_disbursedAmt1000_dayInYears360_daysInMonth30_repa
1265
1265
checkDailyInterest (interestModel , dueDate , startDay , 31 , 0.18 , 5.83 );
1266
1266
}
1267
1267
1268
+ @ Test
1269
+ public void test_dailyInterest_chargeback_disbursedAmt1000_dayInYears360_daysInMonth30_repayIn1Month () {
1270
+
1271
+ final List <LoanScheduleModelRepaymentPeriod > expectedRepaymentPeriods = new ArrayList <>();
1272
+
1273
+ expectedRepaymentPeriods .add (repayment (1 , LocalDate .of (2024 , 1 , 1 ), LocalDate .of (2024 , 2 , 1 )));
1274
+
1275
+ final BigDecimal interestRate = BigDecimal .valueOf (7.0 );
1276
+ final Integer installmentAmountInMultiplesOf = null ;
1277
+
1278
+ Mockito .when (loanProductRelatedDetail .getAnnualNominalInterestRate ()).thenReturn (interestRate );
1279
+ Mockito .when (loanProductRelatedDetail .getDaysInYearType ()).thenReturn (DaysInYearType .DAYS_360 .getValue ());
1280
+ Mockito .when (loanProductRelatedDetail .getDaysInMonthType ()).thenReturn (DaysInMonthType .DAYS_30 .getValue ());
1281
+ Mockito .when (loanProductRelatedDetail .getRepaymentPeriodFrequencyType ()).thenReturn (PeriodFrequencyType .MONTHS );
1282
+ Mockito .when (loanProductRelatedDetail .getRepayEvery ()).thenReturn (1 );
1283
+ Mockito .when (loanProductRelatedDetail .getCurrencyData ()).thenReturn (currency );
1284
+
1285
+ final ProgressiveLoanInterestScheduleModel interestModel = emiCalculator .generatePeriodInterestScheduleModel (
1286
+ expectedRepaymentPeriods , loanProductRelatedDetail , List .of (), installmentAmountInMultiplesOf , mc );
1287
+
1288
+ final Money disbursedAmount = toMoney (1000.0 );
1289
+ emiCalculator .addDisbursement (interestModel , LocalDate .of (2024 , 1 , 1 ), disbursedAmount );
1290
+
1291
+ checkPeriod (interestModel , 0 , 0 , 1005.83 , 0.0 , 0.0 , 5.83 , 1000.0 , 0.0 );
1292
+ checkPeriod (interestModel , 0 , 1 , 1005.83 , 0.005833333333 , 5.83 , 1000.0 , 0.0 );
1293
+
1294
+ final LocalDate dueDate = LocalDate .of (2024 , 2 , 1 );
1295
+ final LocalDate startDay = LocalDate .of (2024 , 1 , 1 );
1296
+
1297
+ // TODO: work on interest calculation
1298
+ // emiCalculator.payInterest(interestModel, dueDate, startDay.plusDays(3), toMoney(0.56));
1299
+ // emiCalculator.chargebackInterest(interestModel, startDay.plusDays(3), toMoney(0.0));
1300
+ // emiCalculator.addBalanceCorrection(interestModel, startDay.plusDays(3), toMoney(0.0));
1301
+
1302
+ checkDailyInterest (interestModel , dueDate , startDay , 1 , 0.19 , 0.19 );
1303
+ checkDailyInterest (interestModel , dueDate , startDay , 2 , 0.19 , 0.38 );
1304
+ checkDailyInterest (interestModel , dueDate , startDay , 3 , 0.18 , 0.56 );
1305
+ checkDailyInterest (interestModel , dueDate , startDay , 4 , 0.19 , 0.75 );
1306
+ checkDailyInterest (interestModel , dueDate , startDay , 5 , 0.19 , 0.94 );
1307
+ checkDailyInterest (interestModel , dueDate , startDay , 6 , 0.19 , 1.13 );
1308
+ checkDailyInterest (interestModel , dueDate , startDay , 7 , 0.19 , 1.32 );
1309
+ checkDailyInterest (interestModel , dueDate , startDay , 8 , 0.19 , 1.51 );
1310
+ checkDailyInterest (interestModel , dueDate , startDay , 9 , 0.18 , 1.69 );
1311
+ checkDailyInterest (interestModel , dueDate , startDay , 10 , 0.19 , 1.88 );
1312
+ checkDailyInterest (interestModel , dueDate , startDay , 11 , 0.19 , 2.07 );
1313
+ checkDailyInterest (interestModel , dueDate , startDay , 12 , 0.19 , 2.26 );
1314
+ checkDailyInterest (interestModel , dueDate , startDay , 13 , 0.19 , 2.45 );
1315
+ checkDailyInterest (interestModel , dueDate , startDay , 14 , 0.18 , 2.63 );
1316
+ checkDailyInterest (interestModel , dueDate , startDay , 15 , 0.19 , 2.82 );
1317
+ checkDailyInterest (interestModel , dueDate , startDay , 16 , 0.19 , 3.01 );
1318
+ checkDailyInterest (interestModel , dueDate , startDay , 17 , 0.19 , 3.20 );
1319
+ checkDailyInterest (interestModel , dueDate , startDay , 18 , 0.19 , 3.39 );
1320
+ checkDailyInterest (interestModel , dueDate , startDay , 19 , 0.19 , 3.58 );
1321
+ checkDailyInterest (interestModel , dueDate , startDay , 20 , 0.18 , 3.76 );
1322
+ checkDailyInterest (interestModel , dueDate , startDay , 21 , 0.19 , 3.95 );
1323
+ checkDailyInterest (interestModel , dueDate , startDay , 22 , 0.19 , 4.14 );
1324
+ checkDailyInterest (interestModel , dueDate , startDay , 23 , 0.19 , 4.33 );
1325
+ checkDailyInterest (interestModel , dueDate , startDay , 24 , 0.19 , 4.52 );
1326
+ checkDailyInterest (interestModel , dueDate , startDay , 25 , 0.18 , 4.7 );
1327
+ checkDailyInterest (interestModel , dueDate , startDay , 26 , 0.19 , 4.89 );
1328
+ checkDailyInterest (interestModel , dueDate , startDay , 27 , 0.19 , 5.08 );
1329
+ checkDailyInterest (interestModel , dueDate , startDay , 28 , 0.19 , 5.27 );
1330
+ checkDailyInterest (interestModel , dueDate , startDay , 29 , 0.19 , 5.46 );
1331
+ checkDailyInterest (interestModel , dueDate , startDay , 30 , 0.19 , 5.65 );
1332
+ checkDailyInterest (interestModel , dueDate , startDay , 31 , 0.18 , 5.83 );
1333
+ }
1334
+
1268
1335
@ Test
1269
1336
public void test_dailyInterest_disbursedAmt2000_dayInYears360_daysInMonth30_repayIn2Month () {
1270
1337
@@ -2759,11 +2826,10 @@ private static LoanRepaymentScheduleInstallment createPeriod(int periodId, Local
2759
2826
2760
2827
private static void checkDailyInterest (final ProgressiveLoanInterestScheduleModel interestModel , final LocalDate repaymentPeriodDueDate ,
2761
2828
final LocalDate interestStartDay , final int dayOffset , final double dailyInterest , final double interest ) {
2762
- Money previousInterest = emiCalculator
2763
- .getDueAmounts (interestModel , repaymentPeriodDueDate , interestStartDay .plusDays (dayOffset - 1 )).getDueInterest ();
2764
- Money currentInterest = emiCalculator .getDueAmounts (interestModel , repaymentPeriodDueDate , interestStartDay .plusDays (dayOffset ))
2765
- .getDueInterest ();
2766
-
2829
+ Money previousInterest = emiCalculator .getPeriodInterestTillDate (interestModel , repaymentPeriodDueDate ,
2830
+ interestStartDay .plusDays (dayOffset - 1 ), true );
2831
+ Money currentInterest = emiCalculator .getPeriodInterestTillDate (interestModel , repaymentPeriodDueDate ,
2832
+ interestStartDay .plusDays (dayOffset ), true );
2767
2833
Assertions .assertEquals (dailyInterest , toDouble (currentInterest .minus (previousInterest )));
2768
2834
Assertions .assertEquals (interest , toDouble (currentInterest ));
2769
2835
}
0 commit comments