diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index f7f77c6cf52..94be096f733 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -3286,24 +3286,22 @@ public CommandProcessingResult chargeOff(JsonCommand command) { final ProgressiveLoanInterestScheduleModel scheduleModel = result.getRight(); - repaymentScheduleInstallments.stream() - .filter(installment -> !installment.getFromDate().isAfter(transactionDate) && installment.getDueDate().isAfter(transactionDate)) - .forEach(installment -> { - final BigDecimal newInterest = emiCalculator - .getPeriodInterestTillDate(scheduleModel, installment.getDueDate(), transactionDate).getAmount(); - final BigDecimal interestRemoved = installment.getInterestCharged().subtract(newInterest); - installment.updatePrincipal(defaultToZeroIfNull(installment.getPrincipal()).add(interestRemoved)); - installment.updateInterestCharged(newInterest); + repaymentScheduleInstallments.stream().filter(installment -> !installment.getFromDate().isAfter(transactionDate) + && installment.getDueDate().isAfter(transactionDate)).forEach(installment -> { + final BigDecimal newInterest = emiCalculator + .getPeriodInterestTillDate(scheduleModel, installment.getDueDate(), transactionDate).getAmount(); + final BigDecimal interestRemoved = installment.getInterestCharged().subtract(newInterest); + installment.updatePrincipal(defaultToZeroIfNull(installment.getPrincipal()).add(interestRemoved)); + installment.updateInterestCharged(newInterest); }); } else { calculatePartialPeriodInterest(loan, transactionDate); } - repaymentScheduleInstallments.stream() - .filter(installment -> installment.getFromDate().isAfter(transactionDate)) + repaymentScheduleInstallments.stream().filter(installment -> installment.getFromDate().isAfter(transactionDate)) .forEach(installment -> { - installment.updatePrincipal(defaultToZeroIfNull(installment.getPrincipal()).add(installment.getInterestCharged())); - installment.updateInterestCharged(BigDecimal.ZERO); + installment.updatePrincipal(defaultToZeroIfNull(installment.getPrincipal()).add(installment.getInterestCharged())); + installment.updateInterestCharged(BigDecimal.ZERO); }); loan.updateLoanSummaryDerivedFields();