Skip to content

Commit

Permalink
FINERACT-2041: totalRepaymentAmount includes down payment transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
taskain7 authored and adamsaghy committed Jan 18, 2024
1 parent 89c3dc3 commit 189b94b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<LoanTransactionData> loanTransactions) {
BigDecimal totalRepaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.REPAYMENT,
loanTransactions);
BigDecimal totalDownPaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.DOWN_PAYMENT,
loanTransactions);
return totalRepaymentTransaction.add(totalDownPaymentTransaction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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())));
}
Expand Down Expand Up @@ -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());
Expand All @@ -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()) //
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit 189b94b

Please sign in to comment.