From 69c25c282bf80d8a550877bbbcb0d4520a88036a Mon Sep 17 00:00:00 2001 From: Adam Saghy Date: Thu, 15 Dec 2022 16:24:24 +0100 Subject: [PATCH] FINERACT-1734: Trigger LoanBalanceChangedBusinessEvent for charges --- .../LoanChargeWritePlatformServiceImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java index 18b38e0a6..7f4dc2fef 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java @@ -262,6 +262,7 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo this.loanAccountDomainService.setLoanDelinquencyTag(loan, DateUtils.getBusinessLocalDate()); businessEventNotifierService.notifyPostBusinessEvent(new LoanAddChargeBusinessEvent(loanCharge)); + businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); return new CommandProcessingResultBuilder().withCommandId(command.commandId()) // .withEntityId(loanCharge.getId()) // .withEntityExternalId(loanCharge.getExternalId()) // @@ -366,7 +367,7 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo undoWaivedCharge(changes, loan, loanTransaction, loanChargePaidBy); businessEventNotifierService.notifyPostBusinessEvent(new LoanWaiveChargeUndoBusinessEvent(loanCharge)); - + businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); changes.put("principalPortion", loanTransaction.getPrincipalPortion()); changes.put("interestPortion", loanTransaction.getInterestPortion()); changes.put("feeChargesPortion", loanTransaction.getFeeChargesPortion()); @@ -500,7 +501,7 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo this.loanAccountDomainService.setLoanDelinquencyTag(loan, DateUtils.getBusinessLocalDate()); businessEventNotifierService.notifyPostBusinessEvent(new LoanWaiveChargeBusinessEvent(loanCharge)); - + businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(loanChargeId) // @@ -627,6 +628,7 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo AccountTransferDetails transferDetails = this.accountTransferDetailRepository.findById(transferTransactionId) .orElseThrow(() -> new AccountTransferNotFoundException(transferTransactionId)); LoanTransaction loanTransaction = transferDetails.getAccountTransferTransactions().get(0).getToLoanTransaction(); + businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(loanChargeId) // @@ -756,7 +758,6 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo this.loanAccountDomainService.recalculateAccruals(loan); } this.loanAccountDomainService.setLoanDelinquencyTag(loan, DateUtils.getBusinessLocalDate()); - businessEventNotifierService.notifyPostBusinessEvent(new LoanApplyOverdueChargeBusinessEvent(loan)); } } @@ -1021,14 +1022,12 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo LoanRepaymentScheduleInstallment installment = null; LocalDate lastChargeAppliedDate = dueDate; + LocalDate recalculateFrom = DateUtils.getBusinessLocalDate(); if (!scheduleDates.isEmpty()) { installment = loan.fetchRepaymentScheduleInstallment(periodNumber); lastChargeAppliedDate = installment.getDueDate(); - } - LocalDate recalculateFrom = DateUtils.getBusinessLocalDate(); - - if (loan != null) { businessEventNotifierService.notifyPreBusinessEvent(new LoanApplyOverdueChargeBusinessEvent(loan)); + for (Map.Entry entry : scheduleDates.entrySet()) { final LoanCharge loanCharge = loanChargeAssembler.createNewFromJson(loan, chargeDefinition, command, entry.getValue()); @@ -1049,6 +1048,8 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo lastChargeAppliedDate = entry.getValue(); } } + businessEventNotifierService.notifyPostBusinessEvent(new LoanApplyOverdueChargeBusinessEvent(loan)); + businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); } return new LoanOverdueDTO(loan, runInterestRecalculation, recalculateFrom, lastChargeAppliedDate);