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

adamsaghy 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 8b2c9da80 FINERACT-1971: Installment level delinquency for loan 
modification
8b2c9da80 is described below

commit 8b2c9da80468bae94d57bd5d25c0980a73539215
Author: Ruchi Dhamankar <[email protected]>
AuthorDate: Tue May 14 19:18:08 2024 +0530

    FINERACT-1971: Installment level delinquency for loan modification
---
 .../loanaccount/api/LoansApiResourceSwagger.java   |   2 +
 ...alculateLoanScheduleQueryFromApiJsonHelper.java |   2 +-
 .../LoanApplicationCommandFromApiJsonHelper.java   |  14 +++
 ...ationWritePlatformServiceJpaRepositoryImpl.java |   8 ++
 ...allmentLevelDelinquencyAPIIntegrationTests.java | 137 +++++++++++++++++++++
 .../common/loans/LoanTransactionHelper.java        |   8 ++
 6 files changed, 170 insertions(+), 1 deletion(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResourceSwagger.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResourceSwagger.java
index ab434a921..3b46577af 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResourceSwagger.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResourceSwagger.java
@@ -1372,6 +1372,8 @@ final class LoansApiResourceSwagger {
         public List<PutLoansLoanIdDisbursementData> disbursementData;
         @Schema(example = "HORIZONTAL")
         public String loanScheduleProcessingType;
+        @Schema(example = "false")
+        public Boolean enableInstallmentLevelDelinquency;
 
         static final class PutLoansLoanIdChanges {
 
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java
index affcf2284..850e25ce6 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java
@@ -71,7 +71,7 @@ public final class 
CalculateLoanScheduleQueryFromApiJsonHelper {
             LoanApiConstants.repaymentFrequencyDayOfWeekTypeParameterName, 
LoanApiConstants.isTopup, LoanApiConstants.loanIdToClose,
             LoanApiConstants.datatables, 
LoanApiConstants.isEqualAmortizationParam, 
LoanProductConstants.RATES_PARAM_NAME,
             LoanApiConstants.daysInYearTypeParameterName, 
LoanApiConstants.fixedPrincipalPercentagePerInstallmentParamName,
-            LoanProductConstants.FIXED_LENGTH));
+            LoanProductConstants.FIXED_LENGTH, 
LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY));
 
     private final FromJsonHelper fromApiJsonHelper;
 
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
index 941dc8d1a..b8a5fff5b 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
@@ -1134,6 +1134,20 @@ public final class 
LoanApplicationCommandFromApiJsonHelper {
             
advancedPaymentAllocationsValidator.checkGroupingOfAllocationRules(allocationRules);
         }
 
+        if 
(this.fromApiJsonHelper.parameterExists(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY,
 element)) {
+            final Boolean isEnableInstallmentLevelDelinquency = 
this.fromApiJsonHelper
+                    
.extractBooleanNamed(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY, 
element);
+            
baseDataValidator.reset().parameter(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY)
+                    
.value(isEnableInstallmentLevelDelinquency).validateForBooleanValue();
+            if (loanProduct.getDelinquencyBucket() == null) {
+                if (isEnableInstallmentLevelDelinquency) {
+                    
baseDataValidator.reset().parameter(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY).failWithCode(
+                            
"can.be.enabled.for.loan.with.loan.product.having.valid.delinquency.bucket",
+                            "Installment level delinquency cannot be enabled 
for a loan if Delinquency bucket is not configured for loan product");
+                }
+            }
+        }
+
         if (!dataValidationErrors.isEmpty()) {
             throw new 
PlatformApiDataValidationException("validation.msg.validation.errors.exist", 
"Validation errors exist.",
                     dataValidationErrors);
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
index 96ab3a928..c54983445 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java
@@ -970,6 +970,14 @@ public class 
LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
                 
existingLoanApplication.updateLoanCharges(possiblyModifedLoanCharges);
             }
 
+            // update installment level delinquency
+            if 
(command.isChangeInBooleanParameterNamed(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY,
+                    
existingLoanApplication.isEnableInstallmentLevelDelinquency())) {
+                final Boolean enableInstallmentLevelDelinquency = command
+                        
.booleanObjectValueOfParameterNamed(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY);
+                
existingLoanApplication.updateEnableInstallmentLevelDelinquency(enableInstallmentLevelDelinquency);
+            }
+
             if (changes.containsKey("recalculateLoanSchedule")) {
                 changes.remove("recalculateLoanSchedule");
 
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java
index 19a8e9c34..ceb924bdc 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java
@@ -20,6 +20,7 @@ package org.apache.fineract.integrationtests;
 
 import static 
org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -31,7 +32,10 @@ import 
org.apache.fineract.client.models.GetLoansLoanIdLoanInstallmentLevelDelin
 import org.apache.fineract.client.models.GetLoansLoanIdResponse;
 import org.apache.fineract.client.models.PostLoanProductsRequest;
 import org.apache.fineract.client.models.PostLoanProductsResponse;
+import org.apache.fineract.client.models.PostLoansResponse;
 import org.apache.fineract.client.models.PutLoanProductsProductIdRequest;
+import org.apache.fineract.client.models.PutLoansLoanIdRequest;
+import org.apache.fineract.client.models.PutLoansLoanIdResponse;
 import org.apache.fineract.client.util.CallFailedRuntimeException;
 import org.apache.fineract.integrationtests.common.ClientHelper;
 import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
@@ -411,6 +415,139 @@ public class 
InstallmentLevelDelinquencyAPIIntegrationTests extends BaseLoanInte
 
     }
 
+    @Test
+    public void testLoanInstallmentLevelSettingModification() {
+        runAt("31 May 2023", () -> {
+            // Create Client
+            Long clientId = 
clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
+
+            // Create DelinquencyBuckets
+            Integer delinquencyBucketId = 
DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec, 
List.of(//
+                    Pair.of(1, 10), //
+                    Pair.of(11, 30), //
+                    Pair.of(31, 60), //
+                    Pair.of(61, null)//
+            ));
+
+            // Create Loan Product
+            PostLoanProductsRequest loanProductsRequest = 
create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
+                    InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
+
+            // set delinquency bucket
+            
loanProductsRequest.setDelinquencyBucketId(delinquencyBucketId.longValue());
+            PostLoanProductsResponse loanProductResponse = 
loanProductHelper.createLoanProduct(loanProductsRequest);
+
+            // Apply for loan
+            Long loanId = loanTransactionHelper
+                    .applyLoan(applyLoanRequest(clientId, 
loanProductResponse.getResourceId(), "01 January 2023", 1250.0, 4))
+                    .getResourceId();
+
+            // verify installment level delinquency setting for loan
+            GetLoansLoanIdResponse loanResponse = 
loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId.intValue());
+            
assertThat(loanResponse.getEnableInstallmentLevelDelinquency()).isFalse();
+
+            // Modify installment level delinquency as true for loan
+            PutLoansLoanIdResponse loansModificationResponse = 
loanTransactionHelper.modifyApplicationForLoan(loanId, "modify",
+                    new 
PutLoansLoanIdRequest().clientId(clientId).productId(loanProductResponse.getResourceId()).loanType("individual")
+                            
.enableInstallmentLevelDelinquency(true).locale("en").dateFormat(DATETIME_PATTERN));
+
+            // verify installment level delinquency setting for loan
+            loanResponse = loanTransactionHelper.getLoan(requestSpec, 
responseSpec, loanId.intValue());
+            
assertThat(loanResponse.getEnableInstallmentLevelDelinquency()).isTrue();
+
+            // Approve Loan
+            loanTransactionHelper.approveLoan(loanId, 
approveLoanRequest(1250.0, "01 January 2023"));
+
+            // Disburse Loan
+            disburseLoan(loanId, BigDecimal.valueOf(1250), "01 January 2023");
+
+            // Verify Repayment Schedule and Due Dates
+            verifyRepaymentSchedule(loanId, //
+                    installment(1250.0, null, "01 January 2023"), //
+                    installment(312.0, false, "31 January 2023"), // 120 days 
delinquent -> range4
+                    installment(312.0, false, "02 March 2023"), // 90 days 
delinquent -> range4
+                    installment(312.0, false, "01 April 2023"), // 60 days 
delinquent -> range3
+                    installment(314.0, false, "01 May 2023") // 30 days 
delinquent -> range2
+            );
+
+            // since the installment level delinquency is modified as true for 
loan, therefore it
+            // is calculated
+            verifyDelinquency(loanId, 120, "1250.0", //
+                    delinquency(11, 30, "314.0"), // 4th installment
+                    delinquency(31, 60, "312.0"), // 3rd installment
+                    delinquency(61, null, "624.0") // 1st installment + 2nd 
installment
+            );
+
+        });
+
+    }
+
+    @Test
+    public void 
tesInstallmentLevelSettingModificationForLoanWithLoanProductWithoutDelinquencyBucketValidation()
 {
+
+        runAt("31 May 2023", () -> {
+            // Create Client
+            Long clientId = 
clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
+
+            // Create Loan Product without delinquency bucket
+            PostLoanProductsRequest loanProductsRequest = 
create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
+                    InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
+            PostLoanProductsResponse loanProductResponse = 
loanProductHelper.createLoanProduct(loanProductsRequest);
+
+            // Apply for loan
+            Long loanId = loanTransactionHelper
+                    .applyLoan(applyLoanRequest(clientId, 
loanProductResponse.getResourceId(), "01 January 2023", 1250.0, 4))
+                    .getResourceId();
+
+            // Modify Loan with installment level delinquency setting
+            CallFailedRuntimeException callFailedRuntimeException = 
Assertions.assertThrows(CallFailedRuntimeException.class,
+                    () -> 
loanTransactionHelper.modifyApplicationForLoan(loanId, "modify",
+                            new 
PutLoansLoanIdRequest().clientId(clientId).productId(loanProductResponse.getResourceId())
+                                    
.loanType("individual").enableInstallmentLevelDelinquency(true).locale("en")
+                                    .dateFormat(DATETIME_PATTERN)));
+
+            
Assertions.assertTrue(callFailedRuntimeException.getMessage().contains(
+                    "Installment level delinquency cannot be enabled for a 
loan if Delinquency bucket is not configured for loan product"));
+
+        });
+    }
+
+    @Test
+    public void 
testCalculateRepaymentScheduleWorksWithInstallmentLevelDelinquencySetting() {
+        runAt("31 May 2023", () -> {
+            // Create Client
+            Long clientId = 
clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
+
+            // Create DelinquencyBuckets
+            Integer delinquencyBucketId = 
DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec, 
List.of(//
+                    Pair.of(1, 10), //
+                    Pair.of(11, 30), //
+                    Pair.of(31, 60), //
+                    Pair.of(61, null)//
+            ));
+
+            // Create Loan Product
+            PostLoanProductsRequest loanProductsRequest = 
create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
+                    InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
+
+            // set installment level delinquency as false
+            loanProductsRequest.setEnableInstallmentLevelDelinquency(false);
+            
loanProductsRequest.setDelinquencyBucketId(delinquencyBucketId.longValue());
+            PostLoanProductsResponse loanProductResponse = 
loanProductHelper.createLoanProduct(loanProductsRequest);
+
+            // run calculateLoanSchedule command works, while Applying for 
loan with installment level delinquency
+            PostLoansResponse loansResponse = loanTransactionHelper
+                    
.calculateRepaymentScheduleForApplyLoan(applyLoanRequest(clientId, 
loanProductResponse.getResourceId(),
+                            "01 January 2023", 1250.0, 4, req -> 
req.setEnableInstallmentLevelDelinquency(true)), "calculateLoanSchedule");
+
+            assertThat(loansResponse).isNotNull();
+            assertNotNull(loansResponse.getPeriods());
+            assertThat(loansResponse.getPeriods().size()).isEqualTo(5);
+
+        });
+
+    }
+
     @Test
     public void 
tesInstallmentLevelSettingForLoanProductWithoutDelinquencyBucketValidation() {
 
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
index 03a2e81f8..1c96f3a9e 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
@@ -2019,4 +2019,12 @@ public class LoanTransactionHelper extends 
IntegrationTest {
         return ok(fineract().loans.stateTransitions(loanId, request, 
"undoapproval"));
     }
 
+    public PutLoansLoanIdResponse modifyApplicationForLoan(final Long loanId, 
final String command, final PutLoansLoanIdRequest request) {
+        return ok(fineract().loans.modifyLoanApplication(loanId, request, 
command));
+    }
+
+    public PostLoansResponse 
calculateRepaymentScheduleForApplyLoan(PostLoansRequest request, String 
command) {
+        return 
ok(fineract().loans.calculateLoanScheduleOrSubmitLoanApplication(request, 
command));
+    }
+
 }

Reply via email to