From 3e375b6b39465c13d5ac165a170ec6a0c8e28b00 Mon Sep 17 00:00:00 2001 From: "adam.magyari" Date: Mon, 9 Dec 2024 17:18:18 +0100 Subject: [PATCH] FINERACT-1971: update installment accrued portions on charge accrual --- .../portfolio/loanaccount/domain/Loan.java | 6 ++++- .../LoanChargeProgressiveTest.java | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java index cc8039f159..8044de62cf 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java @@ -768,7 +768,11 @@ public LoanTransaction handleChargeAppliedTransaction(final LoanCharge loanCharg final LoanTransaction applyLoanChargeTransaction = LoanTransaction.accrueLoanCharge(this, getOffice(), chargeAmount, transactionDate, feeCharges, penaltyCharges, externalId); - Integer installmentNumber = null; + final LoanRepaymentScheduleInstallment installmentForCharge = this.getRelatedRepaymentScheduleInstallment(loanCharge.getDueDate()); + installmentForCharge.updateAccrualPortion(installmentForCharge.getInterestAccrued(this.getCurrency()), + installmentForCharge.getFeeAccrued(this.getCurrency()).add(feeCharges), + installmentForCharge.getPenaltyAccrued(this.getCurrency()).add(penaltyCharges)); + Integer installmentNumber = installmentForCharge.getInstallmentNumber(); final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(applyLoanChargeTransaction, loanCharge, loanCharge.getAmount(getCurrency()).getAmount(), installmentNumber); applyLoanChargeTransaction.getLoanChargesPaid().add(loanChargePaidBy); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeProgressiveTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeProgressiveTest.java index d7babdff4d..5b7de1503d 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeProgressiveTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeProgressiveTest.java @@ -25,7 +25,9 @@ import org.apache.fineract.client.models.PostChargesResponse; import org.apache.fineract.client.models.PostLoanProductsResponse; import org.apache.fineract.client.models.PostLoansResponse; +import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.ClientHelper; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -65,4 +67,26 @@ public void loanChargeAfterMaturityTest() { validateRepaymentPeriod(loanDetails2, 5, LocalDate.of(2024, 10, 2), 0, 20, 0, 0); }); } + + @Test + public void immediateChargeAccrualPostMaturityTest() { + runAt("03 October 2024", () -> { + executeInlineCOB(loanId); + globalConfigurationHelper.manageConfigurations(GlobalConfigurationConstants.ENABLE_IMMEDIATE_CHARGE_ACCRUAL_POST_MATURITY, + true); + final PostChargesResponse chargeResponse = createCharge(20.0d, "EUR"); + addLoanCharge(loanId, chargeResponse.getResourceId(), "03 October 2024", 20.0d); + final GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); + Assertions.assertTrue( + loanDetails.getTransactions().stream().anyMatch(t -> t.getType().getAccrual() && t.getAmount().equals(20.0d))); + }); + runAt("04 October 2024", () -> { + globalConfigurationHelper.manageConfigurations(GlobalConfigurationConstants.ENABLE_IMMEDIATE_CHARGE_ACCRUAL_POST_MATURITY, + false); + executeInlineCOB(loanId); + final GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); + Assertions.assertTrue( + loanDetails.getTransactions().stream().anyMatch(t -> t.getType().getAccrual() && t.getAmount().equals(20.0d))); + }); + } }