You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ad...@apache.org on 2023/04/05 20:58:27 UTC
[fineract] branch develop updated: FINERACT-1724-Last-repayment-amount-date-closed-overpaid-loans
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 b555b3584 FINERACT-1724-Last-repayment-amount-date-closed-overpaid-loans
b555b3584 is described below
commit b555b358452d32296cf31d2c2c3a4df237a97fd9
Author: Ruchi Dhamankar <ru...@gmail.com>
AuthorDate: Fri Mar 31 19:05:53 2023 +0530
FINERACT-1724-Last-repayment-amount-date-closed-overpaid-loans
---
.../loan/LoanBusinessEventSerializer.java | 6 +-
.../loanaccount/api/LoansApiResource.java | 6 +-
.../LoanLastRepaymentDetailsTest.java | 201 +++++++++++++++++++++
3 files changed, 205 insertions(+), 8 deletions(-)
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanBusinessEventSerializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanBusinessEventSerializer.java
index be7d8343e..e7477b843 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanBusinessEventSerializer.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanBusinessEventSerializer.java
@@ -65,10 +65,8 @@ public class LoanBusinessEventSerializer extends AbstractBusinessEventSerializer
data.setCharges(loanCharges);
}
- if (data.isActive()) {
- CollectionData delinquentData = delinquencyReadPlatformService.calculateLoanCollectionData(loanId);
- data.setDelinquent(delinquentData);
- }
+ CollectionData delinquentData = delinquencyReadPlatformService.calculateLoanCollectionData(loanId);
+ data.setDelinquent(delinquentData);
if (data.getSummary() != null) {
final Collection<LoanTransactionData> currentLoanTransactions = service.retrieveLoanTransactions(loanId);
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java
index e167596b8..9de6673bb 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/LoansApiResource.java
@@ -843,10 +843,8 @@ public class LoansApiResource {
Collection<LoanTermVariationsData> emiAmountVariations = null;
Collection<LoanCollateralResponseData> loanCollateralManagements;
Collection<LoanCollateralManagementData> loanCollateralManagementData = new ArrayList<>();
- CollectionData collectionData = CollectionData.template();
- if (loanBasicDetails.isActive()) {
- collectionData = this.delinquencyReadPlatformService.calculateLoanCollectionData(resolvedLoanId);
- }
+ CollectionData collectionData = this.delinquencyReadPlatformService.calculateLoanCollectionData(resolvedLoanId);
+
final Set<String> mandatoryResponseParameters = new HashSet<>();
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(resolvedLoanId);
diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanLastRepaymentDetailsTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanLastRepaymentDetailsTest.java
new file mode 100644
index 000000000..25c29187f
--- /dev/null
+++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanLastRepaymentDetailsTest.java
@@ -0,0 +1,201 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.util.HashMap;
+import java.util.UUID;
+import org.apache.fineract.client.models.GetDelinquencyBucketsResponse;
+import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
+import org.apache.fineract.client.models.GetLoansLoanIdResponse;
+import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest;
+import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import org.apache.fineract.integrationtests.common.products.DelinquencyBucketsHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class LoanLastRepaymentDetailsTest {
+
+ private ResponseSpecification responseSpec;
+ private ResponseSpecification responseSpecErr400;
+ private ResponseSpecification responseSpecErr503;
+ private RequestSpecification requestSpec;
+ private ClientHelper clientHelper;
+ private LoanTransactionHelper loanTransactionHelper;
+ private DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().appendPattern("dd MMMM yyyy").toFormatter();
+
+ @BeforeEach
+ public void setup() {
+ Utils.initializeRESTAssured();
+ this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+ this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.responseSpecErr400 = new ResponseSpecBuilder().expectStatusCode(400).build();
+ this.responseSpecErr503 = new ResponseSpecBuilder().expectStatusCode(503).build();
+ this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
+ this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
+ }
+
+ @Test
+ public void loanLastRepaymentDetailsTestClosedLoan() {
+ // Loan ExternalId
+ String loanExternalIdStr = UUID.randomUUID().toString();
+
+ // Delinquency Bucket
+ final Integer delinquencyBucketId = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec);
+ final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec,
+ delinquencyBucketId);
+
+ // Client and Loan account creation
+
+ final Integer clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId().intValue();
+ final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper,
+ delinquencyBucketId);
+ assertNotNull(getLoanProductsProductResponse);
+
+ final Integer loanId = createLoanAccount(clientId, getLoanProductsProductResponse.getId(), loanExternalIdStr);
+
+ // make Repayments
+ final PostLoansLoanIdTransactionsResponse repaymentTransaction_1 = loanTransactionHelper.makeLoanRepayment(loanExternalIdStr,
+ new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate("5 September 2022").locale("en")
+ .transactionAmount(500.0));
+
+ GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails((long) loanId);
+
+ // verify loan is active and last repayment details
+ LocalDate lastRepaymentDate_1 = LocalDate.of(2022, 9, 5);
+ assertNotNull(loanDetails);
+ assertTrue(loanDetails.getStatus().getActive());
+ assertNotNull(loanDetails.getDelinquent());
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentAmount());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentAmount(), 500);
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentDate());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentDate(), lastRepaymentDate_1);
+
+ final PostLoansLoanIdTransactionsResponse repaymentTransaction_2 = loanTransactionHelper.makeLoanRepayment(loanExternalIdStr,
+ new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate("6 September 2022").locale("en")
+ .transactionAmount(500.0));
+
+ // verify loan is closed and last repayment details
+
+ loanDetails = loanTransactionHelper.getLoanDetails((long) loanId);
+
+ LocalDate lastRepaymentDate_2 = LocalDate.of(2022, 9, 6);
+ assertNotNull(loanDetails);
+ assertTrue(loanDetails.getStatus().getClosedObligationsMet());
+ assertNotNull(loanDetails.getDelinquent());
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentAmount());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentAmount(), 500);
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentDate());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentDate(), lastRepaymentDate_2);
+
+ }
+
+ @Test
+ public void loanLastRepaymentDetailsTestOverpaidLoan() {
+ // Loan ExternalId
+ String loanExternalIdStr = UUID.randomUUID().toString();
+
+ // Delinquency Bucket
+ final Integer delinquencyBucketId = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec);
+ final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec,
+ delinquencyBucketId);
+
+ // Client and Loan account creation
+
+ final Integer clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId().intValue();
+ final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper,
+ delinquencyBucketId);
+ assertNotNull(getLoanProductsProductResponse);
+
+ final Integer loanId = createLoanAccount(clientId, getLoanProductsProductResponse.getId(), loanExternalIdStr);
+
+ // make Repayments
+ final PostLoansLoanIdTransactionsResponse repaymentTransaction_1 = loanTransactionHelper.makeLoanRepayment(loanExternalIdStr,
+ new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate("5 September 2022").locale("en")
+ .transactionAmount(500.0));
+
+ GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails((long) loanId);
+
+ // verify loan is active and last repayment details
+ LocalDate lastRepaymentDate_1 = LocalDate.of(2022, 9, 5);
+ assertNotNull(loanDetails);
+ assertTrue(loanDetails.getStatus().getActive());
+ assertNotNull(loanDetails.getDelinquent());
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentAmount());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentAmount(), 500);
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentDate());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentDate(), lastRepaymentDate_1);
+
+ final PostLoansLoanIdTransactionsResponse repaymentTransaction_2 = loanTransactionHelper.makeLoanRepayment(loanExternalIdStr,
+ new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate("6 September 2022").locale("en")
+ .transactionAmount(600.0));
+
+ // verify loan is overpaid and last repayment details
+ loanDetails = loanTransactionHelper.getLoanDetails((long) loanId);
+
+ LocalDate lastRepaymentDate_2 = LocalDate.of(2022, 9, 6);
+ assertNotNull(loanDetails);
+ assertTrue(loanDetails.getStatus().getOverpaid());
+ assertNotNull(loanDetails.getDelinquent());
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentAmount());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentAmount(), 600);
+ assertNotNull(loanDetails.getDelinquent().getLastRepaymentDate());
+ assertEquals(loanDetails.getDelinquent().getLastRepaymentDate(), lastRepaymentDate_2);
+
+ }
+
+ private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
+ final Integer delinquencyBucketId) {
+ final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
+ final Integer loanProductId = loanTransactionHelper.getLoanProductId(Utils.convertToJson(loanProductMap));
+ return loanTransactionHelper.getLoanProduct(loanProductId);
+ }
+
+ private Integer createLoanAccount(final Integer clientID, final Long loanProductID, final String externalId) {
+
+ String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal("1000").withLoanTermFrequency("1")
+ .withLoanTermFrequencyAsMonths().withNumberOfRepayments("1").withRepaymentEveryAfter("1")
+ .withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("0").withInterestTypeAsFlatBalance()
+ .withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
+ .withExpectedDisbursementDate("03 September 2022").withSubmittedOnDate("01 September 2022").withLoanType("individual")
+ .withExternalId(externalId).build(clientID.toString(), loanProductID.toString(), null);
+
+ final Integer loanId = loanTransactionHelper.getLoanId(loanApplicationJSON);
+ loanTransactionHelper.approveLoan("02 September 2022", "1000", loanId, null);
+ loanTransactionHelper.disburseLoanWithNetDisbursalAmount("03 September 2022", loanId, "1000");
+ return loanId;
+ }
+}