Update: Cater for loans with no schedule at disburse time

This commit is contained in:
John Woodlock
2022-05-16 18:56:25 +02:00
committed by Arnold Gálovics
parent 66621dcc81
commit c1a3b98edd
7 changed files with 249 additions and 18 deletions
@@ -2481,17 +2481,8 @@ public class Loan extends AbstractPersistableCustom {
private void regenerateRepaymentScheduleWithInterestRecalculationIfNeeded(boolean interestRecalculationEnabledParam,
boolean disbursementMissedParam, ScheduleGeneratorDTO scheduleGeneratorDTO, AppUser currentUser) {
/*
* There may be no schedule built pre-disbursal e.g. multi-disbursal products that disallow expected
* disbursements
*/
LocalDate firstInstallmentDueDate = null;
LoanRepaymentScheduleInstallment firstInstallment = fetchRepaymentScheduleInstallment(1);
if (firstInstallment == null) {
firstInstallmentDueDate = LocalDate.now(DateUtils.getDateTimeZoneOfTenant());
} else {
firstInstallmentDueDate = firstInstallment.getDueDate();
}
LocalDate firstInstallmentDueDate = fetchRepaymentScheduleInstallment(1).getDueDate();
if (interestRecalculationEnabledParam
&& (firstInstallmentDueDate.isBefore(LocalDate.now(DateUtils.getDateTimeZoneOfTenant())) || disbursementMissedParam)) {
regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser);
@@ -513,6 +513,12 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
loan.addLoanTransaction(disbursementTransaction);
}
if (loan.getRepaymentScheduleInstallments().size() == 0) {
/*
* If no schedule, generate one (applicable to non-tranche multi-disbursal loans)
*/
recalculateSchedule = true;
}
regenerateScheduleOnDisbursement(command, loan, recalculateSchedule, scheduleGeneratorDTO, nextPossibleRepaymentDate,
rescheduledRepaymentDate);
if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {