From 189b94bd1951f8a2b6766e0d80fd383b7c38b02c Mon Sep 17 00:00:00 2001 From: taskain7 Date: Thu, 18 Jan 2024 10:15:50 +0100 Subject: [PATCH] FINERACT-2041: totalRepaymentAmount includes down payment transactions --- .../loanaccount/data/LoanSummaryData.java | 10 +++++++- ...nRepaymentScheduleWithDownPaymentTest.java | 25 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) 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 f0c8197f2a9..73e7be47a33 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 @@ -180,7 +180,7 @@ public static LoanSummaryData withTransactionAmountsSummary(final LoanSummaryDat loanTransactions); totalCreditBalanceRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.CREDIT_BALANCE_REFUND, loanTransactions); - totalRepaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.REPAYMENT, loanTransactions); + totalRepaymentTransaction = computeTotalRepaymentTransactionAmount(loanTransactions); totalRepaymentTransactionReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.REPAYMENT, loanTransactions); } @@ -227,4 +227,12 @@ private static BigDecimal computeTotalAmountForNonReversedTransactions(LoanTrans transaction -> transaction.getType().getCode().equals(transactionType.getCode()) && transaction.getReversedOnDate() == null) .map(txn -> txn.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); } + + private static BigDecimal computeTotalRepaymentTransactionAmount(Collection loanTransactions) { + BigDecimal totalRepaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.REPAYMENT, + loanTransactions); + BigDecimal totalDownPaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.DOWN_PAYMENT, + loanTransactions); + return totalRepaymentTransaction.add(totalDownPaymentTransaction); + } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanRepaymentScheduleWithDownPaymentTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanRepaymentScheduleWithDownPaymentTest.java index 6979e605430..3dd00a8d04b 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanRepaymentScheduleWithDownPaymentTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanRepaymentScheduleWithDownPaymentTest.java @@ -36,6 +36,7 @@ import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod; import org.apache.fineract.client.models.GetLoansLoanIdResponse; +import org.apache.fineract.client.models.GetLoansLoanIdSummary; import org.apache.fineract.client.models.PostChargesResponse; import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; @@ -142,6 +143,7 @@ public void loanRepaymentScheduleWithSimpleDisbursementAndAutoRepaymentDownPayme final Integer loanId = createApproveAndDisburseLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "1", "0"); GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue()); + GetLoansLoanIdSummary summary = loanDetails.getSummary(); assertNotNull(loanDetails); assertEquals(enableDownPayment, loanDetails.getEnableDownPayment()); @@ -157,7 +159,8 @@ public void loanRepaymentScheduleWithSimpleDisbursementAndAutoRepaymentDownPayme assertTrue(periods.stream() // .anyMatch(period -> expectedDownPaymentAmount.equals(period.getTotalPaidForPeriod()) // && expectedDownPaymentDueDate.equals(period.getDueDate()))); - assertEquals(expectedRepaymentAmount, loanDetails.getSummary().getTotalOutstanding()); + assertEquals(expectedRepaymentAmount, summary.getTotalOutstanding()); + assertEquals(expectedDownPaymentAmount, summary.getTotalRepaymentTransaction()); assertTrue(periods.stream().anyMatch(period -> expectedRepaymentAmount.equals(period.getTotalDueForPeriod()) && expectedRepaymentDueDate.equals(period.getDueDate()))); } @@ -286,6 +289,7 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndA final Integer loanId = createApproveAndDisburseTwiceLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "1", "0"); GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue()); + GetLoansLoanIdSummary summary = loanDetails.getSummary(); assertNotNull(loanDetails); assertEquals(enableDownPayment, loanDetails.getEnableDownPayment()); @@ -299,6 +303,7 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndA LocalDate expectedSecondDownPaymentDueDate = LocalDate.of(2022, 9, 4); Double expectedRepaymentAmount = 750.00; LocalDate expectedRepaymentDueDate = LocalDate.of(2022, 10, 3); + Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount; assertTrue(periods.stream() // .anyMatch(period -> expectedFirstDownPaymentAmount.equals(period.getTotalPaidForPeriod()) // @@ -308,7 +313,8 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndA && expectedSecondDownPaymentDueDate.equals(period.getDueDate()))); assertTrue(periods.stream().anyMatch(period -> expectedRepaymentAmount.equals(period.getTotalDueForPeriod()) && expectedRepaymentDueDate.equals(period.getDueDate()))); - assertEquals(expectedRepaymentAmount, loanDetails.getSummary().getTotalOutstanding()); + assertEquals(expectedRepaymentAmount, summary.getTotalOutstanding()); + assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction()); } @Test @@ -338,6 +344,7 @@ public void loanRepaymentScheduleWithMultiDisbursementProductOneDisbursementAndT final Integer loanId = createApproveAndDisburseLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "3", "0"); GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue()); + GetLoansLoanIdSummary summary = loanDetails.getSummary(); assertNotNull(loanDetails); assertEquals(enableDownPayment, loanDetails.getEnableDownPayment()); @@ -356,6 +363,8 @@ public void loanRepaymentScheduleWithMultiDisbursementProductOneDisbursementAndT LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3); Double outstandingBalanceOnThirdRepayment = 0.00; + assertEquals(expectedDownPaymentAmount, summary.getTotalRepaymentTransaction()); + GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0); assertEquals(expectedDownPaymentDueDate, firstDisbursementPeriod.getDueDate()); assertEquals(expectedOutstandingLoanBalanceOnDisbursement, firstDisbursementPeriod.getPrincipalLoanBalanceOutstanding()); @@ -407,6 +416,7 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndT final Integer loanId = createApproveAndDisburseTwiceLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "3", "0"); GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue()); + GetLoansLoanIdSummary summary = loanDetails.getSummary(); assertNotNull(loanDetails); assertEquals(enableDownPayment, loanDetails.getEnableDownPayment()); @@ -429,6 +439,9 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndT Double outstandingBalanceOnSecondRepayment = 250.00; LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3); Double outstandingBalanceOnThirdRepayment = 0.00; + Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount; + + assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction()); GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0); assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate()); @@ -566,6 +579,7 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndT assertNotNull(postLoansLoanIdChargesResponse); GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue()); + GetLoansLoanIdSummary summary = loanDetails.getSummary(); assertNotNull(loanDetails); assertEquals(enableDownPayment, loanDetails.getEnableDownPayment()); @@ -589,6 +603,9 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndT Double outstandingBalanceOnSecondRepayment = 250.00; LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3); Double outstandingBalanceOnThirdRepayment = 0.00; + Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount; + + assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction()); GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0); assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate()); @@ -729,6 +746,7 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndT assertNotNull(postLoansLoanIdChargesResponse); GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue()); + GetLoansLoanIdSummary summary = loanDetails.getSummary(); assertNotNull(loanDetails); assertEquals(enableDownPayment, loanDetails.getEnableDownPayment()); @@ -755,6 +773,9 @@ public void loanRepaymentScheduleWithMultiDisbursementProductTwoDisbursementAndT Double outstandingBalanceOnSecondRepayment = 250.00; LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3); Double outstandingBalanceOnThirdRepayment = 0.00; + Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount; + + assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction()); GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0); assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate());