galovics commented on code in PR #4283:
URL: https://github.com/apache/fineract/pull/4283#discussion_r1929538917


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -1229,12 +1229,41 @@ private void handleAccelerateMaturityChargeOff(final 
LoanTransaction loanTransac
             }
 
             currentInstallment.updateDueDate(transactionDate);
-            final BigDecimal futurePrincipal = installments.stream()
-                    .filter(installment -> 
transactionDate.isBefore(installment.getDueDate()))
-                    
.map(LoanRepaymentScheduleInstallment::getPrincipal).reduce(BigDecimal.ZERO, 
BigDecimal::add);
+
+            final List<LoanRepaymentScheduleInstallment> futureInstallments = 
installments.stream()
+                    .filter(installment -> 
transactionDate.isBefore(installment.getDueDate())).toList();
+
+            final BigDecimal futurePrincipal = 
futureInstallments.stream().map(LoanRepaymentScheduleInstallment::getPrincipal)
+                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, 
BigDecimal::add);
+
+            final BigDecimal futureFee = 
futureInstallments.stream().map(LoanRepaymentScheduleInstallment::getFeeChargesCharged)
+                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, 
BigDecimal::add);
+
+            final BigDecimal futurePenalty = 
futureInstallments.stream().map(LoanRepaymentScheduleInstallment::getPenaltyCharges)
+                    .filter(Objects::nonNull).reduce(BigDecimal.ZERO, 
BigDecimal::add);
+
             
currentInstallment.updatePrincipal(MathUtil.nullToZero(currentInstallment.getPrincipal()).add(futurePrincipal));
+
             final List<LoanRepaymentScheduleInstallment> 
installmentsUpToTransactionDate = installments.stream()
-                    .filter(installment -> 
transactionDate.isAfter(installment.getFromDate())).toList();
+                    .filter(installment -> 
transactionDate.isAfter(installment.getFromDate()))
+                    .collect(Collectors.toCollection(ArrayList::new));
+
+            if (futureFee.compareTo(BigDecimal.ZERO) > 0 || 
futurePenalty.compareTo(BigDecimal.ZERO) > 0) {
+                final Optional<LocalDate> latestDueDate = 
loan.getCharges().stream()
+                        .filter(loanCharge -> loanCharge.isActive() && 
loanCharge.isNotFullyPaid()).map(LoanCharge::getDueDate)
+                        .max(LocalDate::compareTo);
+
+                if (latestDueDate.isPresent()) {
+                    final LoanRepaymentScheduleInstallment lastInstallment = 
installmentsUpToTransactionDate
+                            .get(installmentsUpToTransactionDate.size() - 1);
+
+                    final LoanRepaymentScheduleInstallment 
instalmentForCharges = new LoanRepaymentScheduleInstallment(loan,

Review Comment:
   typo in variable name (missing an extra "l" in installment)



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