This is an automated email from the ASF dual-hosted git repository.

arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 4a77dafc5 [FINERACT-1971] LoanRepaymentDueBusinessEvent shouldn't be 
sent if the loan is not disbursed or the outstanding balance is greater than 0
4a77dafc5 is described below

commit 4a77dafc5ad6875a3f4064fefcf0f57db81970e2
Author: taskain7 <[email protected]>
AuthorDate: Tue Oct 10 02:20:17 2023 +0200

    [FINERACT-1971] LoanRepaymentDueBusinessEvent shouldn't be sent if the loan 
is not disbursed or the outstanding balance is greater than 0
---
 .../fineract/cob/loan/CheckLoanRepaymentDueBusinessStep.java     | 9 ++++++++-
 .../fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java | 7 +++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

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 153a064e4..1bd638ab5 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
@@ -18,7 +18,9 @@
  */
 package org.apache.fineract.cob.loan;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
+import java.util.Arrays;
 import java.util.List;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -28,6 +30,7 @@ import 
org.apache.fineract.infrastructure.event.business.domain.loan.repayment.L
 import 
org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
 import 
org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
 import org.springframework.stereotype.Component;
 
 @Slf4j
@@ -51,7 +54,11 @@ public class CheckLoanRepaymentDueBusinessStep implements 
LoanCOBBusinessStep {
         final List<LoanRepaymentScheduleInstallment> 
loanRepaymentScheduleInstallments = loan.getRepaymentScheduleInstallments();
         for (LoanRepaymentScheduleInstallment repaymentSchedule : 
loanRepaymentScheduleInstallments) {
             LocalDate repaymentDate = repaymentSchedule.getDueDate();
-            if 
(repaymentDate.minusDays(numberOfDaysBeforeDueDateToRaiseEvent).equals(currentDate))
 {
+            List<LoanStatus> 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) {
                 businessEventNotifierService.notifyPostBusinessEvent(new 
LoanRepaymentDueBusinessEvent(repaymentSchedule));
                 break;
             }
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 0de449f9b..6b2bacc65 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
@@ -42,6 +42,7 @@ import 
org.apache.fineract.infrastructure.event.business.domain.loan.repayment.L
 import 
org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
 import 
org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
+import org.apache.fineract.portfolio.loanaccount.domain.LoanSummary;
 import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -77,6 +78,7 @@ public class CheckLoanRepaymentDueBusinessStepTest {
         LocalDate loanInstallmentRepaymentDueDate = 
DateUtils.getBusinessLocalDate().plusDays(1);
         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));
@@ -84,6 +86,8 @@ public class CheckLoanRepaymentDueBusinessStepTest {
         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
         Loan processedLoan = underTest.execute(loanForProcessing);
@@ -127,6 +131,7 @@ public class CheckLoanRepaymentDueBusinessStepTest {
         LocalDate loanInstallmentRepaymentDueDate = 
DateUtils.getBusinessLocalDate().plusDays(1);
         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));
@@ -135,6 +140,8 @@ public class CheckLoanRepaymentDueBusinessStepTest {
         // 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
         Loan processedLoan = underTest.execute(loanForProcessing);

Reply via email to