Skip to content

Commit

Permalink
FINERACT-1981: pay-off transaction for progressive loans
Browse files Browse the repository at this point in the history
  • Loading branch information
kjozsa authored and adamsaghy committed Aug 22, 2024
1 parent 5ebd342 commit 80f4627
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ public OutstandingAmountsDTO calculatePrepaymentAmount(MonetaryCurrency currency
log.debug("calculating prepayment amount till rest frequency date (Strategy B)");
OutstandingAmountsDTO outstandingAmounts = new OutstandingAmountsDTO(currency);
loan.getRepaymentScheduleInstallments().forEach(installment -> {
boolean isPayoffAfterInstallmentFrom = installment.getFromDate().isAfter(onDate);
boolean isPayoffBeforeInstallment = installment.getFromDate().isBefore(onDate);

outstandingAmounts.plusPrincipal(installment.getPrincipalOutstanding(currency));
if (!isPayoffAfterInstallmentFrom) {
if (isPayoffBeforeInstallment) {
outstandingAmounts.plusInterest(installment.getInterestOutstanding(currency));
} else {
log.debug("Payoff after installment {}, not counting interest", installment.getDueDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void calculatePrepaymentAmount_TILL_REST_FREQUENCY_DATE() {
}

@Test
public void calculateSameDayPayoff() {
public void calculateSameDayPayoff_TILL_PRE_CLOSURE_DATE() {
LoanApplicationTerms terms = mock(LoanApplicationTerms.class);
when(terms.getPreClosureInterestCalculationStrategy()).thenReturn(TILL_PRE_CLOSURE_DATE);

Expand All @@ -151,6 +151,22 @@ public void calculateSameDayPayoff() {
assertEquals(BigDecimal.valueOf(200.0).longValue(), amounts.getTotalOutstanding().getAmount().longValue());
}

@Test
public void calculateSameDayPayoff_TILL_REST_FREQUENCY_DATE() {
LoanApplicationTerms terms = mock(LoanApplicationTerms.class);
when(terms.getPreClosureInterestCalculationStrategy()).thenReturn(TILL_REST_FREQUENCY_DATE);

Loan loan = prepareLoanWithInstallments(List.of(
new TestRow(LocalDate.of(2024, 1, 1), LocalDate.of(2024, 2, 1), BigDecimal.valueOf(102), BigDecimal.valueOf(100),
BigDecimal.valueOf(2), ZERO, ZERO, false),
new TestRow(LocalDate.of(2024, 2, 1), LocalDate.of(2024, 3, 1), BigDecimal.valueOf(102), BigDecimal.valueOf(100),
BigDecimal.valueOf(2), ZERO, ZERO, false)));

OutstandingAmountsDTO amounts = generator.calculatePrepaymentAmount(usd, LocalDate.of(2024, 1, 1), terms, MathContext.DECIMAL32,
loan, holidays, processor);
assertEquals(BigDecimal.valueOf(200.0).longValue(), amounts.getTotalOutstanding().getAmount().longValue());
}

@NotNull
private Loan prepareLoanWithInstallments(List<TestRow> rows) {
Loan loan = mock(Loan.class);
Expand Down

0 comments on commit 80f4627

Please sign in to comment.