diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java index ca12f008b..a42db60b9 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java @@ -1888,6 +1888,25 @@ public class LoanStepDef extends AbstractStepDef { .isEqualTo(totalOutstandingExpected); } + @Then("Loan has {double} interest outstanding amount") + public void loanInterestOutstanding(double totalInterestOutstandingExpected) throws IOException { + final Response loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE); + assert loanCreateResponse.body() != null; + final long loanId = loanCreateResponse.body().getLoanId(); + + final Response loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "", "", "").execute(); + ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse); + testContext().set(TestContextKey.LOAN_RESPONSE, loanDetailsResponse); + + assert loanDetailsResponse.body() != null; + assert loanDetailsResponse.body().getSummary() != null; + assert loanDetailsResponse.body().getSummary().getInterestOutstanding() != null; + final double totalInterestOutstandingActual = loanDetailsResponse.body().getSummary().getInterestOutstanding().doubleValue(); + assertThat(totalInterestOutstandingActual) + .as(ErrorMessageHelper.wrongAmountInTotalOutstanding(totalInterestOutstandingActual, totalInterestOutstandingExpected)) + .isEqualTo(totalInterestOutstandingExpected); + } + @Then("Loan has {double} overpaid amount") public void loanOverpaid(double totalOverpaidExpected) throws IOException { Response loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE); @@ -1922,6 +1941,24 @@ public class LoanStepDef extends AbstractStepDef { .isEqualTo(totalOverdueExpected); } + @Then("Loan has {double} total interest overdue amount") + public void loanInterestOverdue(final double totalInterestOverdueExpected) throws IOException { + final Response loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE); + assert loanCreateResponse.body() != null; + final long loanId = loanCreateResponse.body().getLoanId(); + + final Response loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "", "", "").execute(); + ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse); + testContext().set(TestContextKey.LOAN_RESPONSE, loanDetailsResponse); + + assert Objects.requireNonNull(loanDetailsResponse.body()).getSummary() != null; + assert loanDetailsResponse.body().getSummary().getInterestOverdue() != null; + final double totalInterestOverdueActual = loanDetailsResponse.body().getSummary().getInterestOverdue().doubleValue(); + assertThat(totalInterestOverdueActual) + .as(ErrorMessageHelper.wrongAmountInTotalOverdue(totalInterestOverdueActual, totalInterestOverdueExpected)) + .isEqualTo(totalInterestOverdueExpected); + } + @Then("Loan has {double} last payment amount") public void loanLastPaymentAmount(double lastPaymentAmountExpected) throws IOException { Response loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE); diff --git a/fineract-e2e-tests-runner/src/test/resources/features/EMICalculation.feature b/fineract-e2e-tests-runner/src/test/resources/features/EMICalculation.feature index 0a8affcb7..bfdcc26f4 100644 --- a/fineract-e2e-tests-runner/src/test/resources/features/EMICalculation.feature +++ b/fineract-e2e-tests-runner/src/test/resources/features/EMICalculation.feature @@ -2171,6 +2171,10 @@ Feature: EMI calculation and repayment schedule checks for interest bearing loan Then Loan Repayment schedule has the following data in Total row: | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | | 100.0 | 2.21 | 0.0 | 0.0 | 102.21 | 0.0 | 0.0 | 0.0 | 102.21 | + Then Loan has 102.21 outstanding amount + Then Loan has 2.21 interest outstanding amount + Then Loan has 34.02 total overdue amount + Then Loan has 1.16 total interest overdue amount Then Loan Transactions tab has the following data: | Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed | | 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 | false | false | diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 1ce81ca00..43b64bf74 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -2428,6 +2428,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf } else { loanScheduleService.recalculateScheduleFromLastTransaction(loan, null, existingTransactionIds, existingReversedTransactionIds, true); + loanBalanceService.updateLoanSummaryDerivedFields(loan); loan = saveAndFlushLoanWithDataIntegrityViolationChecks(loan); businessEventNotifierService.notifyPostBusinessEvent(new LoanInterestRecalculationBusinessEvent(loan)); }