diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGenerator.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGenerator.java index e28da69967f..c56db656baf 100644 --- a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGenerator.java +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGenerator.java @@ -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()); diff --git a/fineract-progressive-loan/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGeneratorTest.java b/fineract-progressive-loan/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGeneratorTest.java index 9da9156b15a..214bff051c9 100644 --- a/fineract-progressive-loan/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGeneratorTest.java +++ b/fineract-progressive-loan/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/ProgressiveLoanScheduleGeneratorTest.java @@ -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); @@ -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 rows) { Loan loan = mock(Loan.class);