FINERACT-2041: totalRepaymentAmount includes down payment transactions
This commit is contained in:
+9
-1
@@ -180,7 +180,7 @@ public class LoanSummaryData {
|
|||||||
loanTransactions);
|
loanTransactions);
|
||||||
totalCreditBalanceRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.CREDIT_BALANCE_REFUND,
|
totalCreditBalanceRefundReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.CREDIT_BALANCE_REFUND,
|
||||||
loanTransactions);
|
loanTransactions);
|
||||||
totalRepaymentTransaction = computeTotalAmountForNonReversedTransactions(LoanTransactionType.REPAYMENT, loanTransactions);
|
totalRepaymentTransaction = computeTotalRepaymentTransactionAmount(loanTransactions);
|
||||||
totalRepaymentTransactionReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.REPAYMENT, loanTransactions);
|
totalRepaymentTransactionReversed = computeTotalAmountForReversedTransactions(LoanTransactionType.REPAYMENT, loanTransactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,4 +227,12 @@ public class LoanSummaryData {
|
|||||||
transaction -> transaction.getType().getCode().equals(transactionType.getCode()) && transaction.getReversedOnDate() == null)
|
transaction -> transaction.getType().getCode().equals(transactionType.getCode()) && transaction.getReversedOnDate() == null)
|
||||||
.map(txn -> txn.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-2
@@ -36,6 +36,7 @@ import org.apache.fineract.client.models.GetDelinquencyBucketsResponse;
|
|||||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||||
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
|
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
|
||||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
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.PostChargesResponse;
|
||||||
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
|
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
|
||||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||||
@@ -142,6 +143,7 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
final Integer loanId = createApproveAndDisburseLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "1", "0");
|
final Integer loanId = createApproveAndDisburseLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "1", "0");
|
||||||
|
|
||||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
||||||
|
GetLoansLoanIdSummary summary = loanDetails.getSummary();
|
||||||
|
|
||||||
assertNotNull(loanDetails);
|
assertNotNull(loanDetails);
|
||||||
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
||||||
@@ -157,7 +159,8 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
assertTrue(periods.stream() //
|
assertTrue(periods.stream() //
|
||||||
.anyMatch(period -> expectedDownPaymentAmount.equals(period.getTotalPaidForPeriod()) //
|
.anyMatch(period -> expectedDownPaymentAmount.equals(period.getTotalPaidForPeriod()) //
|
||||||
&& expectedDownPaymentDueDate.equals(period.getDueDate())));
|
&& 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())
|
assertTrue(periods.stream().anyMatch(period -> expectedRepaymentAmount.equals(period.getTotalDueForPeriod())
|
||||||
&& expectedRepaymentDueDate.equals(period.getDueDate())));
|
&& expectedRepaymentDueDate.equals(period.getDueDate())));
|
||||||
}
|
}
|
||||||
@@ -286,6 +289,7 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
final Integer loanId = createApproveAndDisburseTwiceLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "1", "0");
|
final Integer loanId = createApproveAndDisburseTwiceLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "1", "0");
|
||||||
|
|
||||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
||||||
|
GetLoansLoanIdSummary summary = loanDetails.getSummary();
|
||||||
|
|
||||||
assertNotNull(loanDetails);
|
assertNotNull(loanDetails);
|
||||||
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
||||||
@@ -299,6 +303,7 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
LocalDate expectedSecondDownPaymentDueDate = LocalDate.of(2022, 9, 4);
|
LocalDate expectedSecondDownPaymentDueDate = LocalDate.of(2022, 9, 4);
|
||||||
Double expectedRepaymentAmount = 750.00;
|
Double expectedRepaymentAmount = 750.00;
|
||||||
LocalDate expectedRepaymentDueDate = LocalDate.of(2022, 10, 3);
|
LocalDate expectedRepaymentDueDate = LocalDate.of(2022, 10, 3);
|
||||||
|
Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount;
|
||||||
|
|
||||||
assertTrue(periods.stream() //
|
assertTrue(periods.stream() //
|
||||||
.anyMatch(period -> expectedFirstDownPaymentAmount.equals(period.getTotalPaidForPeriod()) //
|
.anyMatch(period -> expectedFirstDownPaymentAmount.equals(period.getTotalPaidForPeriod()) //
|
||||||
@@ -308,7 +313,8 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
&& expectedSecondDownPaymentDueDate.equals(period.getDueDate())));
|
&& expectedSecondDownPaymentDueDate.equals(period.getDueDate())));
|
||||||
assertTrue(periods.stream().anyMatch(period -> expectedRepaymentAmount.equals(period.getTotalDueForPeriod())
|
assertTrue(periods.stream().anyMatch(period -> expectedRepaymentAmount.equals(period.getTotalDueForPeriod())
|
||||||
&& expectedRepaymentDueDate.equals(period.getDueDate())));
|
&& expectedRepaymentDueDate.equals(period.getDueDate())));
|
||||||
assertEquals(expectedRepaymentAmount, loanDetails.getSummary().getTotalOutstanding());
|
assertEquals(expectedRepaymentAmount, summary.getTotalOutstanding());
|
||||||
|
assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -338,6 +344,7 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
final Integer loanId = createApproveAndDisburseLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "3", "0");
|
final Integer loanId = createApproveAndDisburseLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "3", "0");
|
||||||
|
|
||||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
||||||
|
GetLoansLoanIdSummary summary = loanDetails.getSummary();
|
||||||
|
|
||||||
assertNotNull(loanDetails);
|
assertNotNull(loanDetails);
|
||||||
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
||||||
@@ -356,6 +363,8 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
||||||
Double outstandingBalanceOnThirdRepayment = 0.00;
|
Double outstandingBalanceOnThirdRepayment = 0.00;
|
||||||
|
|
||||||
|
assertEquals(expectedDownPaymentAmount, summary.getTotalRepaymentTransaction());
|
||||||
|
|
||||||
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
||||||
assertEquals(expectedDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
assertEquals(expectedDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
||||||
assertEquals(expectedOutstandingLoanBalanceOnDisbursement, firstDisbursementPeriod.getPrincipalLoanBalanceOutstanding());
|
assertEquals(expectedOutstandingLoanBalanceOnDisbursement, firstDisbursementPeriod.getPrincipalLoanBalanceOutstanding());
|
||||||
@@ -407,6 +416,7 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
final Integer loanId = createApproveAndDisburseTwiceLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "3", "0");
|
final Integer loanId = createApproveAndDisburseTwiceLoanAccount(clientId, loanProductId.longValue(), loanExternalIdStr, "3", "0");
|
||||||
|
|
||||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
||||||
|
GetLoansLoanIdSummary summary = loanDetails.getSummary();
|
||||||
|
|
||||||
assertNotNull(loanDetails);
|
assertNotNull(loanDetails);
|
||||||
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
||||||
@@ -429,6 +439,9 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
Double outstandingBalanceOnSecondRepayment = 250.00;
|
Double outstandingBalanceOnSecondRepayment = 250.00;
|
||||||
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
||||||
Double outstandingBalanceOnThirdRepayment = 0.00;
|
Double outstandingBalanceOnThirdRepayment = 0.00;
|
||||||
|
Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount;
|
||||||
|
|
||||||
|
assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction());
|
||||||
|
|
||||||
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
||||||
assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
||||||
@@ -566,6 +579,7 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
assertNotNull(postLoansLoanIdChargesResponse);
|
assertNotNull(postLoansLoanIdChargesResponse);
|
||||||
|
|
||||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
||||||
|
GetLoansLoanIdSummary summary = loanDetails.getSummary();
|
||||||
|
|
||||||
assertNotNull(loanDetails);
|
assertNotNull(loanDetails);
|
||||||
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
||||||
@@ -589,6 +603,9 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
Double outstandingBalanceOnSecondRepayment = 250.00;
|
Double outstandingBalanceOnSecondRepayment = 250.00;
|
||||||
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
||||||
Double outstandingBalanceOnThirdRepayment = 0.00;
|
Double outstandingBalanceOnThirdRepayment = 0.00;
|
||||||
|
Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount;
|
||||||
|
|
||||||
|
assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction());
|
||||||
|
|
||||||
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
||||||
assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
||||||
@@ -729,6 +746,7 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
assertNotNull(postLoansLoanIdChargesResponse);
|
assertNotNull(postLoansLoanIdChargesResponse);
|
||||||
|
|
||||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId.longValue());
|
||||||
|
GetLoansLoanIdSummary summary = loanDetails.getSummary();
|
||||||
|
|
||||||
assertNotNull(loanDetails);
|
assertNotNull(loanDetails);
|
||||||
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
assertEquals(enableDownPayment, loanDetails.getEnableDownPayment());
|
||||||
@@ -755,6 +773,9 @@ public class LoanRepaymentScheduleWithDownPaymentTest {
|
|||||||
Double outstandingBalanceOnSecondRepayment = 250.00;
|
Double outstandingBalanceOnSecondRepayment = 250.00;
|
||||||
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
LocalDate expectedThirdRepaymentDueDate = LocalDate.of(2022, 12, 3);
|
||||||
Double outstandingBalanceOnThirdRepayment = 0.00;
|
Double outstandingBalanceOnThirdRepayment = 0.00;
|
||||||
|
Double expectedTotalRepaymentAmount = expectedFirstDownPaymentAmount + expectedSecondDownPaymentAmount;
|
||||||
|
|
||||||
|
assertEquals(expectedTotalRepaymentAmount, summary.getTotalRepaymentTransaction());
|
||||||
|
|
||||||
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
GetLoansLoanIdRepaymentPeriod firstDisbursementPeriod = periods.get(0);
|
||||||
assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
assertEquals(expectedFirstDownPaymentDueDate, firstDisbursementPeriod.getDueDate());
|
||||||
|
|||||||
Reference in New Issue
Block a user