Skip to content

Commit d3b6265

Browse files
ruchiDadamsaghy
authored andcommitted
FINERACT-1971:Installment Delinquency value with delinquency pause
1 parent 89750ee commit d3b6265

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

fineract-provider/src/main/java/org/apache/fineract/cob/loan/SetLoanDelinquencyTagsBusinessStep.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Optional;
2626
import lombok.RequiredArgsConstructor;
2727
import lombok.extern.slf4j.Slf4j;
28-
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
2928
import org.apache.fineract.infrastructure.core.domain.ActionContext;
3029
import org.apache.fineract.infrastructure.core.domain.ExternalId;
3130
import org.apache.fineract.infrastructure.core.service.DateUtils;
@@ -97,9 +96,9 @@ public Loan execute(Loan loan) {
9796
}
9897

9998
private boolean isDelinquencyOnPause(Loan loan, List<LoanDelinquencyActionData> effectiveDelinquencyList) {
100-
LocalDate cobBusinessDate = ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE);
101-
boolean isPaused = isPausedOnDate(cobBusinessDate, effectiveDelinquencyList);
102-
boolean wasPausedOneDayBefore = isPausedOnDate(cobBusinessDate.minusDays(1), effectiveDelinquencyList);
99+
LocalDate businessDate = DateUtils.getBusinessLocalDate();
100+
boolean isPaused = isPausedOnDate(businessDate, effectiveDelinquencyList);
101+
boolean wasPausedOneDayBefore = isPausedOnDate(businessDate.minusDays(1), effectiveDelinquencyList);
103102
if ((isPaused && !wasPausedOneDayBefore) || (!isPaused && wasPausedOneDayBefore)) {
104103
businessEventNotifierService.notifyPostBusinessEvent(new LoanDelinquencyRangeChangeBusinessEvent(loan));
105104
}

integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyActionIntegrationTests.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.fineract.integrationtests.common.ClientHelper;
5050
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
5151
import org.apache.fineract.integrationtests.common.products.DelinquencyBucketsHelper;
52+
import org.apache.fineract.integrationtests.inlinecob.InlineLoanCOBHelper;
5253
import org.junit.jupiter.api.Assertions;
5354
import org.junit.jupiter.api.Test;
5455
import org.junit.jupiter.api.extension.ExtendWith;
@@ -266,7 +267,7 @@ public void testVerifyLoanDelinquencyRecalculationForBackdatedPauseDelinquencyAc
266267
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
267268

268269
// Create Loan Product
269-
Long loanProductId = createLoanProductWith25PctDownPaymentAndDelinquencyBucket(true, true, true);
270+
Long loanProductId = createLoanProductWith25PctDownPaymentAndDelinquencyBucket(true, true, true, 3);
270271

271272
// Apply and Approve Loan
272273
Long loanId = applyAndApproveLoan(clientId, loanProductId, "25 December 2022", 1500.0, 3,
@@ -322,6 +323,48 @@ public void testValidationErrorIsThrownWhenCreatingActionThatOverlaps() {
322323
});
323324
}
324325

326+
@Test
327+
public void testLoanAndInstallmentDelinquencyCalculationForCOBAfterPausePeriodEndTest() {
328+
runAt("01 November 2023", () -> {
329+
// Create Client
330+
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
331+
332+
// Create Loan Product
333+
Long loanProductId = createLoanProductWith25PctDownPaymentAndDelinquencyBucket(true, true, true, 0);
334+
335+
// Apply and Approve Loan
336+
Long loanId = applyAndApproveLoan(clientId, loanProductId, "01 November 2023", 1000.0, 3, req -> {
337+
req.submittedOnDate("01 November 2023");
338+
req.setLoanTermFrequency(45);
339+
req.setRepaymentEvery(15);
340+
req.setGraceOnArrearsAgeing(0);
341+
});
342+
343+
// Partial Loan amount Disbursement
344+
disburseLoan(loanId, BigDecimal.valueOf(100.00), "01 November 2023");
345+
346+
// Update business date
347+
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("05 November 2023")
348+
.dateFormat(DATETIME_PATTERN).locale("en"));
349+
350+
// Create Delinquency Pause for the Loan
351+
PostLoansDelinquencyActionResponse response = loanTransactionHelper.createLoanDelinquencyAction(loanId, PAUSE,
352+
"16 November 2023", "25 November 2023");
353+
354+
// run cob for business date 26 November
355+
final InlineLoanCOBHelper inlineLoanCOBHelper = new InlineLoanCOBHelper(requestSpec, responseSpec);
356+
businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("26 November 2023")
357+
.dateFormat(DATETIME_PATTERN).locale("en"));
358+
inlineLoanCOBHelper.executeInlineCOB(List.of(loanId.longValue()));
359+
360+
// Loan delinquency data
361+
verifyLoanDelinquencyData(loanId, 1, new InstallmentDelinquencyData(1, 3, BigDecimal.valueOf(25.0)));
362+
363+
// Validate Delinquency Pause Period on Loan
364+
validateLoanDelinquencyPausePeriods(loanId, pausePeriods("16 November 2023", "25 November 2023", false));
365+
});
366+
}
367+
325368
private void validateLoanDelinquencyPausePeriods(Long loanId, GetLoansLoanIdDelinquencyPausePeriod... pausePeriods) {
326369
GetLoansLoanIdResponse loan = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId.intValue());
327370
Assertions.assertNotNull(loan.getDelinquent());
@@ -388,7 +431,7 @@ private Long createLoanProductWith25PctDownPayment(boolean autoDownPaymentEnable
388431
}
389432

390433
private Long createLoanProductWith25PctDownPaymentAndDelinquencyBucket(boolean autoDownPaymentEnabled, boolean multiDisburseEnabled,
391-
boolean installmentLevelDelinquencyEnabled) {
434+
boolean installmentLevelDelinquencyEnabled, Integer graceOnArrearsAging) {
392435
// Create DelinquencyBuckets
393436
Integer delinquencyBucketId = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec, List.of(//
394437
Pair.of(1, 3), //
@@ -400,6 +443,7 @@ private Long createLoanProductWith25PctDownPaymentAndDelinquencyBucket(boolean a
400443
product.setDelinquencyBucketId(delinquencyBucketId.longValue());
401444
product.setMultiDisburseLoan(multiDisburseEnabled);
402445
product.setEnableDownPayment(true);
446+
product.setGraceOnArrearsAgeing(graceOnArrearsAging);
403447

404448
product.setDisbursedAmountPercentageForDownPayment(DOWN_PAYMENT_PERCENTAGE);
405449
product.setEnableAutoRepaymentForDownPayment(autoDownPaymentEnabled);

0 commit comments

Comments
 (0)