adamsaghy commented on code in PR #5053:
URL: https://github.com/apache/fineract/pull/5053#discussion_r2464864055


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -559,6 +566,92 @@ private void 
calculateEMIValueAndRateFactorsForDecliningBalanceInterestMethod(fi
         }
     }
 
+    @Override
+    public void updateModelRepaymentPeriodsDuringReAge(final 
ProgressiveLoanInterestScheduleModel scheduleModel,
+            final LoanTransaction loanTransaction, final LoanApplicationTerms 
loanApplicationTerms, final MathContext mc) {
+        final LoanReAgeParameter loanReAgeParameter = 
loanTransaction.getLoanReAgeParameter();
+        final LocalDate reAgingStartDate = loanReAgeParameter.getStartDate();
+        final LocalDate transactionDate = loanTransaction.getTransactionDate();
+        final List<RepaymentPeriod> existingRepaymentPeriods = 
scheduleModel.repaymentPeriods();
+
+        final List<RepaymentPeriod> periodsBeforeReAging = 
existingRepaymentPeriods.stream()
+                .filter(rp -> rp.getFromDate().isBefore(reAgingStartDate) && 
!rp.isFullyPaid()).toList();
+
+        periodsBeforeReAging.forEach(rp -> {
+            final InterestPeriod lastInterestPeriod = 
rp.getInterestPeriods().getLast();
+            
lastInterestPeriod.addBalanceCorrectionAmount(rp.getOutstandingPrincipal().negated());
+            rp.setEmi(rp.getTotalPaidAmount());
+        });
+
+        final LocalDate periodStartDate = switch 
(loanReAgeParameter.getFrequencyType()) {
+            case DAYS -> 
reAgingStartDate.minusDays(loanReAgeParameter.getFrequencyNumber());
+            case WEEKS -> 
reAgingStartDate.minusWeeks(loanReAgeParameter.getFrequencyNumber());
+            case MONTHS -> 
reAgingStartDate.minusMonths(loanReAgeParameter.getFrequencyNumber());
+            case YEARS -> 
reAgingStartDate.minusYears(loanReAgeParameter.getFrequencyNumber());
+            case WHOLE_TERM -> throw new IllegalStateException("Unexpected 
RecalculationFrequencyType: WHOLE_TERM");
+            case INVALID -> throw new IllegalStateException("Unexpected 
RecalculationFrequencyType: INVALID");
+        };
+
+        LocalDate disbursementDate = transactionDate;
+        if (!reAgingStartDate.isAfter(transactionDate)) {
+            disbursementDate = periodStartDate;
+        }

Review Comment:
   Lets extract into a method and leave a short description what it does, like: 
calculating the reage start date which is used to calculate the due date, etc.



-- 
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]

Reply via email to