adamsaghy commented on code in PR #5167:
URL: https://github.com/apache/fineract/pull/5167#discussion_r2584097594
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -309,10 +309,92 @@ private void processLoanTermVariation(final
List<LoanRepaymentScheduleInstallmen
case INTEREST_PAUSE -> handleInterestPause(installments,
termVariationsData, scheduleModel);
case INTEREST_RATE_FROM_INSTALLMENT ->
handleChangeInterestRate(installments, termVariationsData, scheduleModel);
case EXTEND_REPAYMENT_PERIOD ->
handleExtraRepaymentPeriod(installments, termVariationsData, scheduleModel);
+ case DUE_DATE ->
handleDueDateChangeOnRepaymentPeriod(installments, termVariationsData,
scheduleModel);
default -> throw new IllegalStateException("Unhandled
LoanTermVariationType.");
}
}
+ private void handleDueDateChangeOnRepaymentPeriod(final
List<LoanRepaymentScheduleInstallment> installments,
+ final LoanTermVariationsData termVariationsData, final
ProgressiveLoanInterestScheduleModel scheduleModel) {
+ final LocalDate targetRepaymentPeriodDueDate =
termVariationsData.getTermVariationApplicableFrom();
+ final LocalDate newDueDate = termVariationsData.getDateValue();
+ final Loan loan = installments.getFirst().getLoan();
+ final LoanApplicationTerms loanApplicationTerms = new
LoanApplicationTerms.Builder() //
+ .currency(loan.getCurrency().toData()) //
+
.repaymentEvery(loan.getLoanProductRelatedDetail().getRepayEvery()) //
+
.repaymentPeriodFrequencyType(loan.getLoanProductRelatedDetail().getRepaymentPeriodFrequencyType())
//
+
.fixedLength(loan.getLoanProductRelatedDetail().getFixedLength()) //
+ .seedDate(newDueDate) //
+ .build();
+ emiCalculator.changeDueDate(scheduleModel, loanApplicationTerms,
targetRepaymentPeriodDueDate, newDueDate);
+
+ IntStream.range(0, installments.size()).filter(i ->
installments.get(i).getDueDate().equals(targetRepaymentPeriodDueDate))
+ .findFirst().ifPresent(targetInstallmentIndex -> {
+ long scheduleModelStartIndex = installments.subList(0,
targetInstallmentIndex).stream()
+ .filter(inst -> !inst.isDownPayment() &&
!inst.isAdditional()).count();
+
+ for (int i = targetInstallmentIndex; i <
installments.size(); i++) {
+ final LoanRepaymentScheduleInstallment installment =
installments.get(i);
+ if (installment.isDownPayment() ||
installment.isAdditional()) {
+ continue;
+ }
+ if (scheduleModelStartIndex >=
scheduleModel.repaymentPeriods().size()) {
+ break;
+ }
+
+ final RepaymentPeriod repaymentPeriod =
scheduleModel.repaymentPeriods().get((int) scheduleModelStartIndex);
+
+ if (isNotObligationsMet(installment)) {
+
installment.updateFromDate(repaymentPeriod.getFromDate());
+
installment.updateDueDate(repaymentPeriod.getDueDate());
+
installment.updatePrincipal(repaymentPeriod.getDuePrincipal().getAmount());
+
installment.updateInterestCharged(repaymentPeriod.getDueInterest().getAmount());
+ }
+
+ scheduleModelStartIndex++;
+ }
+ });
+
+ mergeAdditionalInstallmentsBeforeMaturityDate(installments,
scheduleModel, loan);
+
+
installments.sort(Comparator.comparing(LoanRepaymentScheduleInstallment::getDueDate));
+ int installmentNumber = 1;
+ for (LoanRepaymentScheduleInstallment installment : installments) {
+ installment.updateInstallmentNumber(installmentNumber++);
+ }
Review Comment:
I am not sure we need this. can the order of the installments change? no
additional or removed installment involved, no?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]