You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ar...@apache.org on 2022/12/14 11:36:00 UTC

[fineract] branch develop updated: FINERACT-1818-New-Parameter-Loan-Api

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

arnold 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 be958b9ae  FINERACT-1818-New-Parameter-Loan-Api
be958b9ae is described below

commit be958b9aef15c88ab6f4ff3cd32220456db113ba
Author: Ruchi Dhamankar <ru...@gmail.com>
AuthorDate: Tue Dec 13 21:40:49 2022 +0530

     FINERACT-1818-New-Parameter-Loan-Api
---
 .../loanaccount/api/LoansApiResource.java          |  7 +--
 .../loanaccount/data/LoanSummaryData.java          | 60 +++++++++++++---------
 2 files changed, 40 insertions(+), 27 deletions(-)

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 162ee82e8..ff47b912b 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
@@ -508,6 +508,7 @@ public class LoansApiResource {
 
         final Set<String> mandatoryResponseParameters = new HashSet<>();
         final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
+        final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId);
         if (!associationParameters.isEmpty()) {
             if (associationParameters.contains(DataTableApiConstant.allAssociateParamName)) {
                 associationParameters.addAll(Arrays.asList(DataTableApiConstant.repaymentScheduleAssociateParamName,
@@ -530,7 +531,6 @@ public class LoansApiResource {
 
             if (associationParameters.contains(DataTableApiConstant.transactionsAssociateParamName)) {
                 mandatoryResponseParameters.add(DataTableApiConstant.transactionsAssociateParamName);
-                final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService.retrieveLoanTransactions(loanId);
                 if (!CollectionUtils.isEmpty(currentLoanRepayments)) {
                     loanRepayments = currentLoanRepayments;
                 }
@@ -716,8 +716,9 @@ public class LoansApiResource {
         }
 
         // updating summary with transaction amounts summary
-        if (loanRepayments != null) {
-            loanBasicDetails.setSummary(LoanSummaryData.withTransactionAmountsSummary(loanBasicDetails.getSummary(), loanRepayments));
+        if (loanBasicDetails.getSummary() != null) {
+            loanBasicDetails
+                    .setSummary(LoanSummaryData.withTransactionAmountsSummary(loanBasicDetails.getSummary(), currentLoanRepayments));
         }
 
         final LoanAccountData loanAccount = LoanAccountData.associationsAndTemplate(loanBasicDetails, repaymentSchedule, loanRepayments,
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanSummaryData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanSummaryData.java
index ee2c9797a..11114719d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanSummaryData.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/data/LoanSummaryData.java
@@ -25,6 +25,7 @@ import lombok.Data;
 import lombok.experimental.Accessors;
 import org.apache.fineract.organisation.monetary.data.CurrencyData;
 import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
+import org.springframework.util.CollectionUtils;
 
 /**
  * Immutable data object representing loan summary information.
@@ -143,30 +144,41 @@ public class LoanSummaryData {
     public static LoanSummaryData withTransactionAmountsSummary(final LoanSummaryData defaultSummaryData,
             final Collection<LoanTransactionData> loanTransactions) {
 
-        BigDecimal totalMerchantRefund = computeTotalAmountForNonReversedTransactions(LoanTransactionType.MERCHANT_ISSUED_REFUND,
-                loanTransactions);
-        BigDecimal totalMerchantRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.MERCHANT_ISSUED_REFUND,
-                loanTransactions);
-        BigDecimal totalPayoutRefund = computeTotalAmountForNonReversedTransactions(LoanTransactionType.PAYOUT_REFUND, loanTransactions);
-        BigDecimal totalPayoutRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.PAYOUT_REFUND,
-                loanTransactions);
-        BigDecimal totalGoodwillCredit = computeTotalAmountForNonReversedTransactions(LoanTransactionType.GOODWILL_CREDIT,
-                loanTransactions);
-        BigDecimal totalGoodwillCreditReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.GOODWILL_CREDIT,
-                loanTransactions);
-        BigDecimal totalChargeAdjustment = computeTotalAmountForNonReversedTransactions(LoanTransactionType.CHARGE_ADJUSTMENT,
-                loanTransactions);
-        BigDecimal totalChargeAdjustmentReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.CHARGE_ADJUSTMENT,
-                loanTransactions);
-        BigDecimal totalChargeback = computeTotalAmountForNonReversedTransactions(LoanTransactionType.CHARGEBACK, loanTransactions);
-        BigDecimal totalCreditBalanceRefund = computeTotalAmountForNonReversedTransactions(LoanTransactionType.CREDIT_BALANCE_REFUND,
-                loanTransactions);
-        BigDecimal totalCreditBalanceRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.CREDIT_BALANCE_REFUND,
-                loanTransactions);
-        BigDecimal totalRepaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.REPAYMENT,
-                loanTransactions);
-        BigDecimal totalRepaymentTransactionReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.REPAYMENT,
-                loanTransactions);
+        BigDecimal totalMerchantRefund = BigDecimal.ZERO;
+        BigDecimal totalMerchantRefundReversed = BigDecimal.ZERO;
+        BigDecimal totalPayoutRefund = BigDecimal.ZERO;
+        BigDecimal totalPayoutRefundReversed = BigDecimal.ZERO;
+        BigDecimal totalGoodwillCredit = BigDecimal.ZERO;
+        BigDecimal totalGoodwillCreditReversed = BigDecimal.ZERO;
+        BigDecimal totalChargeAdjustment = BigDecimal.ZERO;
+        BigDecimal totalChargeAdjustmentReversed = BigDecimal.ZERO;
+        BigDecimal totalChargeback = BigDecimal.ZERO;
+        BigDecimal totalCreditBalanceRefund = BigDecimal.ZERO;
+        BigDecimal totalCreditBalanceRefundReversed = BigDecimal.ZERO;
+        BigDecimal totalRepaymentTransaction = BigDecimal.ZERO;
+        BigDecimal totalRepaymentTransactionReversed = BigDecimal.ZERO;
+
+        if (!CollectionUtils.isEmpty(loanTransactions)) {
+
+            totalMerchantRefund = computeTotalAmountForNonReversedTransactions(LoanTransactionType.MERCHANT_ISSUED_REFUND,
+                    loanTransactions);
+            totalMerchantRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.MERCHANT_ISSUED_REFUND,
+                    loanTransactions);
+            totalPayoutRefund = computeTotalAmountForNonReversedTransactions(LoanTransactionType.PAYOUT_REFUND, loanTransactions);
+            totalPayoutRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.PAYOUT_REFUND, loanTransactions);
+            totalGoodwillCredit = computeTotalAmountForNonReversedTransactions(LoanTransactionType.GOODWILL_CREDIT, loanTransactions);
+            totalGoodwillCreditReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.GOODWILL_CREDIT, loanTransactions);
+            totalChargeAdjustment = computeTotalAmountForNonReversedTransactions(LoanTransactionType.CHARGE_ADJUSTMENT, loanTransactions);
+            totalChargeAdjustmentReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.CHARGE_ADJUSTMENT,
+                    loanTransactions);
+            totalChargeback = computeTotalAmountForNonReversedTransactions(LoanTransactionType.CHARGEBACK, loanTransactions);
+            totalCreditBalanceRefund = computeTotalAmountForNonReversedTransactions(LoanTransactionType.CREDIT_BALANCE_REFUND,
+                    loanTransactions);
+            totalCreditBalanceRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.CREDIT_BALANCE_REFUND,
+                    loanTransactions);
+            totalRepaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.REPAYMENT, loanTransactions);
+            totalRepaymentTransactionReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.REPAYMENT, loanTransactions);
+        }
 
         return new LoanSummaryData(defaultSummaryData.currency, defaultSummaryData.principalDisbursed,
                 defaultSummaryData.principalAdjustments, defaultSummaryData.principalPaid, defaultSummaryData.principalWrittenOff,