FINERACT-1981: pay-off transaction for progressive loans

This commit is contained in:
Kristof Jozsa
2024-08-22 13:17:30 +02:00
committed by Adam Saghy
parent 5ebd3429c6
commit 80f4627623
2 changed files with 19 additions and 3 deletions
@@ -264,10 +264,10 @@ public class ProgressiveLoanScheduleGenerator implements LoanScheduleGenerator {
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());
@@ -136,7 +136,7 @@ class ProgressiveLoanScheduleGeneratorTest {
}
@Test
public void calculateSameDayPayoff() {
public void calculateSameDayPayoff_TILL_PRE_CLOSURE_DATE() {
LoanApplicationTerms terms = mock(LoanApplicationTerms.class);
when(terms.getPreClosureInterestCalculationStrategy()).thenReturn(TILL_PRE_CLOSURE_DATE);
@@ -151,6 +151,22 @@ class ProgressiveLoanScheduleGeneratorTest {
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);