[FINERACT-1971] LoanRepaymentDueBusinessEvent shouldn't be sent if the loan is not disbursed or the outstanding balance is greater than 0
This commit is contained in:
+10
-3
@@ -56,9 +56,8 @@ public class CheckLoanRepaymentDueBusinessStep implements LoanCOBBusinessStep {
|
||||
LocalDate repaymentDate = repaymentSchedule.getDueDate();
|
||||
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) {
|
||||
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<LoanStatus> nonDisbursedStatuses) {
|
||||
return repaymentDate.minusDays(numberOfDaysBeforeDueDateToRaiseEvent).equals(currentDate)
|
||||
&& !nonDisbursedStatuses.contains(loan.getStatus())
|
||||
&& loan.getLoanSummary().getTotalOutstanding().compareTo(BigDecimal.ZERO) > 0
|
||||
&& repaymentScheduleInstallment.getDue(loan.getCurrency()).isGreaterThanZero();
|
||||
}
|
||||
}
|
||||
|
||||
+16
-6
@@ -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<LoanRepaymentScheduleInstallment> 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<LoanRepaymentScheduleInstallment> 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);
|
||||
|
||||
Reference in New Issue
Block a user