[FINERACT-1958] Repayment schedule recalculation fix for multidisburse down payment

This commit is contained in:
taskain7
2023-08-23 10:36:55 +02:00
parent bfa6a6605b
commit 3885104767
3 changed files with 132 additions and 17 deletions
@@ -284,6 +284,15 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
// backup for pre-close transaction
updateCompoundingDetails(scheduleParams, periodStartDateApplicableForInterest);
if (loanApplicationTerms.isMultiDisburseLoan() && loanApplicationTerms.isDownPaymentEnabled()) {
long numberOfDownPaymentPeriods = periods.stream() //
.filter(LoanScheduleModelPeriod::isDownPaymentPeriod).count();
Long notApplicableForInstallmentRecalculationDownPaymentPeriods = numberOfDownPaymentPeriods - 1;
// Only the first down payment installment counts for the number of repayments
scheduleParams.setPeriodNumber(
scheduleParams.getPeriodNumber() - notApplicableForInstallmentRecalculationDownPaymentPeriods.intValue());
}
// 5 determine principal,interest of repayment period
PrincipalInterest principalInterestForThisPeriod = calculatePrincipalInterestComponentsForPeriod(
this.paymentPeriodsInOneYearCalculator, currentPeriodParams.getInterestCalculationGraceOnRepaymentPeriodFraction(),
@@ -1221,7 +1221,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
periods.add(periodData);
this.outstandingLoanPrincipalBalance = this.outstandingLoanPrincipalBalance.add(data.getPrincipal());
disbursementPeriodIds.add(data.getId());
} else if (data.isDueForDisbursement(fromDate, dueDate)) {
} else if (data.isDueForDisbursement(fromDate, dueDate) && !disbursementPeriodIds.contains(data.getId())) {
if (!excludePastUndisbursed || data.isDisbursed()
|| !data.disbursementDate().isBefore(DateUtils.getBusinessLocalDate())) {
principal = principal.add(data.getPrincipal());
@@ -1235,7 +1235,23 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService, Loa
}
periods.add(periodData);
this.outstandingLoanPrincipalBalance = this.outstandingLoanPrincipalBalance.add(data.getPrincipal());
disbursementPeriodIds.add(data.getId());
}
} else if (fromDate.equals(dueDate) && data.disbursementDate().equals(fromDate)
&& !disbursementPeriodIds.contains(data.getId())) {
principal = principal.add(data.getPrincipal());
LoanSchedulePeriodData periodData = null;
if (data.getChargeAmount() == null) {
periodData = LoanSchedulePeriodData.disbursementOnlyPeriod(data.disbursementDate(), data.getPrincipal(),
disbursementChargeAmount, data.isDisbursed());
} else {
periodData = LoanSchedulePeriodData.disbursementOnlyPeriod(data.disbursementDate(), data.getPrincipal(),
disbursementChargeAmount.add(data.getChargeAmount()).subtract(waivedChargeAmount),
data.isDisbursed());
}
periods.add(periodData);
this.outstandingLoanPrincipalBalance = this.outstandingLoanPrincipalBalance.add(data.getPrincipal());
disbursementPeriodIds.add(data.getId());
}
}
}