-
Notifications
You must be signed in to change notification settings - Fork 2.5k
FINERACT-1890-LoanAccrualTransaction-created-event #3073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.fineract.infrastructure.event.business.domain.loan.transaction; | ||
|
|
||
| import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction; | ||
|
|
||
| public class LoanAccrualTransactionCreatedBusinessEvent extends LoanTransactionBusinessEvent { | ||
|
|
||
| private static final String TYPE = "LoanAccrualTransactionCreatedBusinessEvent"; | ||
|
|
||
| public LoanAccrualTransactionCreatedBusinessEvent(LoanTransaction value) { | ||
| super(value); | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return TYPE; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; | ||
| import org.apache.fineract.infrastructure.event.business.domain.loan.LoanBalanceChangedBusinessEvent; | ||
| import org.apache.fineract.infrastructure.event.business.domain.loan.LoanBusinessEvent; | ||
| import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanAccrualTransactionCreatedBusinessEvent; | ||
| import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanChargePaymentPostBusinessEvent; | ||
| import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanChargePaymentPreBusinessEvent; | ||
| import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanCreditBalanceRefundPostBusinessEvent; | ||
|
|
@@ -90,6 +91,7 @@ | |
| import org.apache.fineract.portfolio.loanaccount.data.LoanScheduleDelinquencyData; | ||
| import org.apache.fineract.portfolio.loanaccount.data.ScheduleGeneratorDTO; | ||
| import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualPlatformService; | ||
| import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualTransactionBusinessEventService; | ||
| import org.apache.fineract.portfolio.loanaccount.service.LoanAssembler; | ||
| import org.apache.fineract.portfolio.loanaccount.service.LoanUtilService; | ||
| import org.apache.fineract.portfolio.loanaccount.service.ReplayedTransactionBusinessEventService; | ||
|
|
@@ -130,6 +132,7 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService { | |
| private final LoanLifecycleStateMachine defaultLoanLifecycleStateMachine; | ||
| private final ExternalIdFactory externalIdFactory; | ||
| private final ReplayedTransactionBusinessEventService replayedTransactionBusinessEventService; | ||
| private final LoanAccrualTransactionBusinessEventService loanAccrualTransactionBusinessEventService; | ||
|
|
||
| @Transactional | ||
| @Override | ||
|
|
@@ -227,7 +230,7 @@ public LoanTransaction makeRepayment(final LoanTransactionType repaymentTransact | |
| } | ||
|
|
||
| postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer, isLoanToLoanTransfer); | ||
|
|
||
| loanAccrualTransactionBusinessEventService.raiseBusinessEventForAccrualTransactions(loan, existingTransactionIds); | ||
| recalculateAccruals(loan); | ||
|
|
||
| setLoanDelinquencyTag(loan, transactionDate); | ||
|
|
@@ -405,6 +408,8 @@ public LoanTransaction makeChargePayment(final Loan loan, final Long chargeId, f | |
| } | ||
|
|
||
| postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer); | ||
| loanAccrualTransactionBusinessEventService.raiseBusinessEventForAccrualTransactions(loan, existingTransactionIds); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please raise the event after the "recalculateAccruals" method which might created new Accrual transaction as well. |
||
|
|
||
| recalculateAccruals(loan); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanChargePaymentPostBusinessEvent(newPaymentTransaction)); | ||
|
|
@@ -480,6 +485,7 @@ public LoanTransaction makeRefund(final Long accountId, final CommandProcessingR | |
| } | ||
|
|
||
| postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer); | ||
| loanAccrualTransactionBusinessEventService.raiseBusinessEventForAccrualTransactions(loan, existingTransactionIds); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanRefundPostBusinessEvent(newRefundTransaction)); | ||
| builderResult.withEntityId(newRefundTransaction.getId()).withOfficeId(loan.getOfficeId()).withClientId(loan.getClientId()) | ||
|
|
@@ -734,6 +740,7 @@ public LoanTransaction makeRefundForActiveLoan(Long accountId, CommandProcessing | |
| } | ||
|
|
||
| postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, false); | ||
| loanAccrualTransactionBusinessEventService.raiseBusinessEventForAccrualTransactions(loan, existingTransactionIds); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please raise the event after the "recalculateAccruals" method which might created new Accrual transaction as well. |
||
| recalculateAccruals(loan); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanRefundPostBusinessEvent(newRefundTransaction)); | ||
|
|
@@ -845,6 +852,7 @@ public LoanTransaction foreCloseLoan(final Loan loan, final LocalDate foreClosur | |
| } | ||
|
|
||
| postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, false); | ||
| loanAccrualTransactionBusinessEventService.raiseBusinessEventForAccrualTransactions(loan, existingTransactionIds); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanBalanceChangedBusinessEvent(loan)); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanForeClosurePostBusinessEvent(payment)); | ||
| return payment; | ||
|
|
@@ -946,6 +954,7 @@ public void applyIncomeAccrualTransaction(Loan loan) { | |
| } | ||
| saveLoanTransactionWithDataIntegrityViolationChecks(accrualTransaction); | ||
| loan.addLoanTransaction(accrualTransaction); | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanAccrualTransactionCreatedBusinessEvent(accrualTransaction)); | ||
|
|
||
| loan.getRepaymentScheduleInstallments().forEach(installment -> { | ||
| installment.updateAccrualPortion( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ | |
| import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequest; | ||
| import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanRescheduleRequestRepository; | ||
| import org.apache.fineract.portfolio.loanaccount.rescheduleloan.exception.LoanRescheduleRequestNotFoundException; | ||
| import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualTransactionBusinessEventService; | ||
| import org.apache.fineract.portfolio.loanaccount.service.LoanAssembler; | ||
| import org.apache.fineract.portfolio.loanaccount.service.LoanUtilService; | ||
| import org.apache.fineract.portfolio.loanaccount.service.ReplayedTransactionBusinessEventService; | ||
|
|
@@ -115,6 +116,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche | |
| private final LoanAccountDomainService loanAccountDomainService; | ||
| private final LoanRepaymentScheduleInstallmentRepository repaymentScheduleInstallmentRepository; | ||
| private final ReplayedTransactionBusinessEventService replayedTransactionBusinessEventService; | ||
| private final LoanAccrualTransactionBusinessEventService loanAccrualTransactionBusinessEventService; | ||
|
|
||
| /** | ||
| * create a new instance of the LoanRescheduleRequest object from the JsonCommand object and persist | ||
|
|
@@ -459,6 +461,7 @@ public CommandProcessingResult approve(JsonCommand jsonCommand) { | |
| // update the loan object | ||
| loan = saveAndFlushLoanWithDataIntegrityViolationChecks(loan); | ||
| postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds); | ||
| loanAccrualTransactionBusinessEventService.raiseBusinessEventForAccrualTransactions(loan, existingTransactionIds); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please raise the event after the "recalculateAccruals" method which might created new Accrual transaction as well. |
||
|
|
||
| this.loanAccountDomainService.recalculateAccruals(loan, true); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.fineract.portfolio.loanaccount.service; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.fineract.portfolio.loanaccount.domain.Loan; | ||
|
|
||
| public interface LoanAccrualTransactionBusinessEventService { | ||
|
|
||
| void raiseBusinessEventForAccrualTransactions(Loan loan, List<Long> existingTransactionIds); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.fineract.portfolio.loanaccount.service; | ||
|
|
||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanAccrualTransactionCreatedBusinessEvent; | ||
| import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; | ||
| import org.apache.fineract.portfolio.loanaccount.domain.Loan; | ||
| import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class LoanAccrualTransactionBusinessEventServiceImpl implements LoanAccrualTransactionBusinessEventService { | ||
|
|
||
| private final BusinessEventNotifierService businessEventNotifierService; | ||
|
|
||
| @Override | ||
| public void raiseBusinessEventForAccrualTransactions(Loan loan, List<Long> existingTransactionIds) { | ||
| for (final LoanTransaction transaction : loan.getLoanTransactions()) { | ||
| if (transaction.isNotReversed() && transaction.isAccrual() && !existingTransactionIds.contains(transaction.getId())) { | ||
| businessEventNotifierService.notifyPostBusinessEvent(new LoanAccrualTransactionCreatedBusinessEvent(transaction)); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please raise the event after the "recalculateAccruals" method which might created new Accrual transaction as well.