mariiaKraievska commented on code in PR #5112:
URL: https://github.com/apache/fineract/pull/5112#discussion_r2503286362


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -3317,17 +3335,6 @@ private void 
handleReAgeWithInterestRecalculationEnabled(final LoanTransaction l
             }
         });

Review Comment:
   Done



##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -3297,17 +3297,35 @@ private void 
handleReAgeWithInterestRecalculationEnabled(final LoanTransaction l
         final LocalDate reAgingStartDate = 
loanTransaction.getLoanReAgeParameter().getStartDate();
 
         final List<RepaymentPeriod> periodsBeforeReAging = 
repaymentPeriods.stream()
-                .filter(rp -> rp.getFromDate().isBefore(reAgingStartDate) && 
!rp.isFullyPaid()).toList();
+                .filter(rp -> 
rp.getFromDate().isBefore(reAgingStartDate)).toList();
 
-        final RepaymentPeriod lastPeriod = periodsBeforeReAging.getLast();
+        // Define the date, which must match reAgingStartDate
+        final LocalDate expectedReAgingDate = periodsBeforeReAging.isEmpty() ? 
repaymentPeriods.getFirst().getFromDate()
+                : periodsBeforeReAging.getLast().getDueDate();
 
-        if (!lastPeriod.getDueDate().isEqual(reAgingStartDate)) {
+        if (!expectedReAgingDate.isEqual(reAgingStartDate)) {
             // TODO: implement logic when re-aging changes the due dates
             throw new NotImplementedException("Logic when re-aging changes the 
due dates not implemented");
         }
 
-        final BigDecimal interestBeforeReAging = emiCalculator
-                .getPeriodInterestTillDate(ctx.getModel(), 
lastPeriod.getDueDate(), transactionDate, false).getAmount();
+        final AtomicReference<BigDecimal> interestFromZeroedInstallments = new 
AtomicReference<>(ZERO);
+
+        final List<RepaymentPeriod> unpaidPeriodsBeforeReAging = 
periodsBeforeReAging.stream().filter(rp -> !rp.isFullyPaid()).toList();
+
+        if (!unpaidPeriodsBeforeReAging.isEmpty()) {
+            final RepaymentPeriod lastUnpaidPeriod = 
unpaidPeriodsBeforeReAging.getLast();
+            final BigDecimal partialDueInterestOfLastUnpaidPeriod = 
emiCalculator
+                    .getPeriodInterestTillDate(ctx.getModel(), 
lastUnpaidPeriod.getDueDate(), transactionDate, false).getAmount();
+
+            installments.stream().filter(
+                    installment -> !installment.isObligationsMet() && 
!installment.getDueDate().isAfter(lastUnpaidPeriod.getFromDate()))
+                    .forEach(installment -> {
+                        final BigDecimal currentInterest = 
interestFromZeroedInstallments.get();
+                        final BigDecimal additionalInterest = 
MathUtil.nullToZero(installment.getInterestOutstanding(currency).getAmount());
+                        
interestFromZeroedInstallments.set(currentInterest.add(additionalInterest));
+                    });
+            
interestFromZeroedInstallments.set(interestFromZeroedInstallments.get().add(partialDueInterestOfLastUnpaidPeriod));

Review Comment:
   Done



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