diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyReadPlatformServiceImpl.java index ac8cca7619f..e12ab385b80 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyReadPlatformServiceImpl.java @@ -126,6 +126,11 @@ public CollectionData calculateLoanCollectionData(final Long loanId) { if (optLoan.isPresent()) { final Loan loan = optLoan.get(); + // If the Loan is not Active yet, return template data + if (loan.isSubmittedAndPendingApproval() || loan.isApproved()) { + return CollectionData.template(); + } + final List savedDelinquencyList = retrieveLoanDelinquencyActions(loanId); List effectiveDelinquencyList = delinquencyEffectivePauseHelper .calculateEffectiveDelinquencyList(savedDelinquencyList); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java index b8898ce0025..80b8e966950 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java @@ -1571,6 +1571,58 @@ public void testDelinquencyWithMultiplePausePeriodsWithInstallmentLevelDelinquen } } + @Test + public void testLoanClassificationOnyForActiveLoan() { + + // Given + final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + + ArrayList rangeIds = new ArrayList<>(); + // First Range + String jsonRange = DelinquencyRangesHelper.getAsJSON(4, 30); + PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, + jsonRange); + rangeIds.add(delinquencyRangeResponse.getResourceId()); + + String jsonBucket = DelinquencyBucketsHelper.getAsJSON(rangeIds); + PostDelinquencyBucketResponse delinquencyBucketResponse = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, + responseSpec, jsonBucket); + assertNotNull(delinquencyBucketResponse); + final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec, + delinquencyBucketResponse.getResourceId()); + + // Client and Loan account creation + final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012"); + final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper, + Math.toIntExact(delinquencyBucket.getId()), null); + assertNotNull(getLoanProductsProductResponse); + + final LocalDate todaysDate = Utils.getLocalDateOfTenant(); + // Older date to have more than one overdue installment + LocalDate transactionDate = todaysDate.minusDays(37); + String operationDate = Utils.dateFormatter.format(transactionDate); + + // Create Loan Application + final Integer loanId = createLoanApplication(loanTransactionHelper, clientId.toString(), + getLoanProductsProductResponse.getId().toString(), operationDate, null); + + // Evaluate default delinquent values in No Active Loan + GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId); + assertNotNull(getLoansLoanIdResponse); + assertNotNull(getLoansLoanIdResponse.getDelinquent()); + assertEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentDays()); + assertEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentAmount()); + + // Loan Disbursement + disburseLoanAccount(loanTransactionHelper, loanId, operationDate); + // Evaluate default delinquent values in No Active Loan + getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId); + assertNotNull(getLoansLoanIdResponse); + assertNotNull(getLoansLoanIdResponse.getDelinquent()); + assertNotEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentDays()); + assertNotEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentAmount()); + } + private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper, final Integer delinquencyBucketId, final String inArrearsTolerance) { final HashMap loanProductMap = new LoanProductTestBuilder().withInArrearsTolerance(inArrearsTolerance).build(null, @@ -1595,8 +1647,8 @@ private PutLoanProductsProductIdResponse updateLoanProduct(LoanTransactionHelper return loanTransactionHelper.updateLoanProduct(id, requestModifyLoan); } - private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId, - final String operationDate, final String inArrearsTolerance) { + private Integer createLoanApplication(final LoanTransactionHelper loanTransactionHelper, final String clientId, + final String loanProductId, final String operationDate, final String inArrearsTolerance) { final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(principalAmount).withLoanTermFrequency("12") .withLoanTermFrequencyAsMonths().withNumberOfRepayments("12").withRepaymentEveryAfter("1") .withRepaymentFrequencyTypeAsMonths() // @@ -1608,7 +1660,17 @@ private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHel .build(clientId, loanProductId, null); final Integer loanId = loanTransactionHelper.getLoanId(loanApplicationJSON); loanTransactionHelper.approveLoan(operationDate, principalAmount, loanId, null); + return loanId; + } + + private void disburseLoanAccount(final LoanTransactionHelper loanTransactionHelper, final Integer loanId, final String operationDate) { loanTransactionHelper.disburseLoanWithNetDisbursalAmount(operationDate, loanId, principalAmount); + } + + private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId, + final String operationDate, final String inArrearsTolerance) { + final Integer loanId = createLoanApplication(loanTransactionHelper, clientId, loanProductId, operationDate, inArrearsTolerance); + disburseLoanAccount(loanTransactionHelper, loanId, operationDate); return loanId; }