From c0d0b565cbf4f1d9d4753674fb13803dd768e3ba Mon Sep 17 00:00:00 2001 From: taskain7 Date: Tue, 10 Oct 2023 02:20:17 +0200 Subject: [PATCH] [FINERACT-1971] LoanRepaymentDueBusinessEvent shouldn't be sent if the loan is not disbursed or the outstanding balance is greater than 0 --- .../CheckLoanRepaymentDueBusinessStep.java | 13 ++++++++--- ...CheckLoanRepaymentDueBusinessStepTest.java | 22 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStep.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStep.java index 1bd638ab5..944031579 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStep.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStep.java @@ -56,9 +56,8 @@ public class CheckLoanRepaymentDueBusinessStep implements LoanCOBBusinessStep { LocalDate repaymentDate = repaymentSchedule.getDueDate(); List nonDisbursedStatuses = Arrays.asList(LoanStatus.INVALID, LoanStatus.SUBMITTED_AND_PENDING_APPROVAL, LoanStatus.APPROVED); - if (repaymentDate.minusDays(numberOfDaysBeforeDueDateToRaiseEvent).equals(currentDate) - && !nonDisbursedStatuses.contains(loan.getStatus()) - && loan.getLoanSummary().getTotalOutstanding().compareTo(BigDecimal.ZERO) > 0) { + if (isDueEventNeededToBeSent(loan, numberOfDaysBeforeDueDateToRaiseEvent, currentDate, repaymentSchedule, repaymentDate, + nonDisbursedStatuses)) { businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentDueBusinessEvent(repaymentSchedule)); break; } @@ -76,4 +75,12 @@ public class CheckLoanRepaymentDueBusinessStep implements LoanCOBBusinessStep { public String getHumanReadableName() { return "Check loan repayment due"; } + + private static boolean isDueEventNeededToBeSent(Loan loan, Long numberOfDaysBeforeDueDateToRaiseEvent, LocalDate currentDate, + LoanRepaymentScheduleInstallment repaymentScheduleInstallment, LocalDate repaymentDate, List nonDisbursedStatuses) { + return repaymentDate.minusDays(numberOfDaysBeforeDueDateToRaiseEvent).equals(currentDate) + && !nonDisbursedStatuses.contains(loan.getStatus()) + && loan.getLoanSummary().getTotalOutstanding().compareTo(BigDecimal.ZERO) > 0 + && repaymentScheduleInstallment.getDue(loan.getCurrency()).isGreaterThanZero(); + } } diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java index 6b2bacc65..5376ad815 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java @@ -40,6 +40,8 @@ import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; import org.apache.fineract.infrastructure.event.business.domain.loan.repayment.LoanRepaymentDueBusinessEvent; import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService; +import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; +import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment; import org.apache.fineract.portfolio.loanaccount.domain.LoanSummary; @@ -79,15 +81,19 @@ public class CheckLoanRepaymentDueBusinessStepTest { Loan loanForProcessing = Mockito.mock(Loan.class); LoanProduct loanProduct = Mockito.mock(LoanProduct.class); LoanSummary loanSummary = Mockito.mock(LoanSummary.class); - LoanRepaymentScheduleInstallment repaymentInstallment = new LoanRepaymentScheduleInstallment(loanForProcessing, 1, - LocalDate.now(ZoneId.systemDefault()), loanInstallmentRepaymentDueDate, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), - BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0)); + MonetaryCurrency currency = Mockito.mock(MonetaryCurrency.class); + Money money = Mockito.mock(Money.class); + LoanRepaymentScheduleInstallment repaymentInstallment = Mockito.mock(LoanRepaymentScheduleInstallment.class); List loanRepaymentScheduleInstallments = Arrays.asList(repaymentInstallment); + when(repaymentInstallment.getDueDate()).thenReturn(loanInstallmentRepaymentDueDate); when(loanForProcessing.getLoanProduct()).thenReturn(loanProduct); when(loanProduct.getDueDaysForRepaymentEvent()).thenReturn(null); when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments); when(loanForProcessing.getLoanSummary()).thenReturn(loanSummary); when(loanForProcessing.getLoanSummary().getTotalOutstanding()).thenReturn(BigDecimal.ONE); + when(loanForProcessing.getCurrency()).thenReturn(currency); + when(repaymentInstallment.getDue(currency)).thenReturn(money); + when(money.isGreaterThanZero()).thenReturn(true); // when Loan processedLoan = underTest.execute(loanForProcessing); @@ -132,16 +138,20 @@ public class CheckLoanRepaymentDueBusinessStepTest { Loan loanForProcessing = Mockito.mock(Loan.class); LoanProduct loanProduct = Mockito.mock(LoanProduct.class); LoanSummary loanSummary = Mockito.mock(LoanSummary.class); - LoanRepaymentScheduleInstallment repaymentInstallment = new LoanRepaymentScheduleInstallment(loanForProcessing, 1, - LocalDate.now(ZoneId.systemDefault()), loanInstallmentRepaymentDueDate, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), - BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0)); + MonetaryCurrency currency = Mockito.mock(MonetaryCurrency.class); + Money money = Mockito.mock(Money.class); + LoanRepaymentScheduleInstallment repaymentInstallment = Mockito.mock(LoanRepaymentScheduleInstallment.class); List loanRepaymentScheduleInstallments = Arrays.asList(repaymentInstallment); + when(repaymentInstallment.getDueDate()).thenReturn(loanInstallmentRepaymentDueDate); when(loanForProcessing.getLoanProduct()).thenReturn(loanProduct); // Loan Product setting overrides global settings when(loanProduct.getDueDaysForRepaymentEvent()).thenReturn(1); when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments); when(loanForProcessing.getLoanSummary()).thenReturn(loanSummary); when(loanForProcessing.getLoanSummary().getTotalOutstanding()).thenReturn(BigDecimal.ONE); + when(loanForProcessing.getCurrency()).thenReturn(currency); + when(repaymentInstallment.getDue(currency)).thenReturn(money); + when(money.isGreaterThanZero()).thenReturn(true); // when Loan processedLoan = underTest.execute(loanForProcessing);