diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleCalculationPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleCalculationPlatformServiceImpl.java index eb8d5aff40..f2e5242b73 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleCalculationPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleCalculationPlatformServiceImpl.java @@ -321,8 +321,7 @@ public void getFeeChargesDetail(LoanScheduleData loanScheduleData, final Long lo BigDecimal voluntaryInsurancePaid = voluntaryInsuranceCharges.stream().flatMap(lic -> lic.installmentCharges().stream()).filter( lc -> Objects.equals(repaymentScheduleInstallment.getInstallmentNumber(), lc.getInstallment().getInstallmentNumber())) .map(LoanInstallmentCharge::getAmountPaid).reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal voluntaryInsuranceWaived = voluntaryInsurancePaid = voluntaryInsuranceCharges.stream() - .flatMap(lic -> lic.installmentCharges().stream()) + BigDecimal voluntaryInsuranceWaived = voluntaryInsuranceCharges.stream().flatMap(lic -> lic.installmentCharges().stream()) .filter(lc -> Objects.equals(repaymentScheduleInstallment.getInstallmentNumber(), lc.getInstallment().getInstallmentNumber())) .map(LoanInstallmentCharge::getAmountWaived).reduce(BigDecimal.ZERO, BigDecimal::add); 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 3876f033e6..c4d2cc2f7e 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 @@ -1549,11 +1549,10 @@ public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Lo } ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom); - + final int initialNumberOfRepayments = Optional.ofNullable(loan.getRepaymentScheduleInstallments()).orElse(new ArrayList<>()).size(); final ChangedTransactionDetail changedTransactionDetail = loan.adjustExistingTransaction(newTransactionDetail, defaultLoanLifecycleStateMachine, transactionToAdjust, existingTransactionIds, existingReversedTransactionIds, scheduleGeneratorDTO, reversalTxnExternalId); - boolean thereIsNewTransaction = newTransactionDetail.isGreaterThanZero(loan.getPrincipal().getCurrency()); if (thereIsNewTransaction) { if (paymentDetail != null) { @@ -1589,7 +1588,11 @@ public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Lo replayedTransactionBusinessEventService.raiseTransactionReplayedEvents(changedTransactionDetail); } loan = saveAndFlushLoanWithDataIntegrityViolationChecks(loan); - + final int newNumberOfRepayments = Optional.ofNullable(loan.getRepaymentScheduleInstallments()).orElse(new ArrayList<>()).size(); + if (newNumberOfRepayments > initialNumberOfRepayments) { + loan.regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO); + loan = saveAndFlushLoanWithDataIntegrityViolationChecks(loan); + } final String noteText = command.stringValueOfParameterNamed("note"); if (StringUtils.isNotBlank(noteText)) { changes.put("note", noteText);