From ee725a1867649807a4eabd18d8c8faf5dfb8cfc2 Mon Sep 17 00:00:00 2001 From: "adam.magyari" Date: Thu, 5 Dec 2024 15:42:33 +0100 Subject: [PATCH] FINERACT-1981: fix post maturity charge removed by cob on progressive loan --- .../service/LoanScheduleService.java | 4 +- .../LoanChargeProgressiveTest.java | 68 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeProgressiveTest.java diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanScheduleService.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanScheduleService.java index b7fe87bb2b..6d87e9d546 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanScheduleService.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanScheduleService.java @@ -29,6 +29,7 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanCharge; import org.apache.fineract.portfolio.loanaccount.loanschedule.data.LoanScheduleDTO; import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleModel; +import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleType; @RequiredArgsConstructor public class LoanScheduleService { @@ -98,7 +99,8 @@ public void regenerateRepaymentScheduleWithInterestRecalculation(final Loan loan for (final LoanCharge loanCharge : charges) { if (!loanCharge.isDueAtDisbursement()) { loan.updateOverdueScheduleInstallment(loanCharge); - if (loanCharge.getDueLocalDate() == null || !DateUtils.isBefore(lastRepaymentDate, loanCharge.getDueLocalDate())) { + if (loanCharge.getDueLocalDate() == null || (!DateUtils.isBefore(lastRepaymentDate, loanCharge.getDueLocalDate()) + && !loan.getLoanProductRelatedDetail().getLoanScheduleType().equals(LoanScheduleType.PROGRESSIVE))) { if ((loanCharge.isInstalmentFee() || !loanCharge.isWaived()) && (loanCharge.getDueLocalDate() == null || !DateUtils.isAfter(lastTransactionDate, loanCharge.getDueLocalDate()))) { loanChargeService.recalculateLoanCharge(loan, loanCharge, generatorDTO.getPenaltyWaitPeriod()); 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 new file mode 100644 index 0000000000..bdda9fbf6e --- /dev/null +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeProgressiveTest.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import java.math.BigDecimal; +import java.util.List; +import org.apache.fineract.client.models.GetLoansLoanIdLoanChargeData; +import org.apache.fineract.client.models.GetLoansLoanIdResponse; +import org.apache.fineract.client.models.PostLoanProductsResponse; +import org.apache.fineract.client.models.PostLoansResponse; +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; + +public class LoanChargeProgressiveTest extends BaseLoanIntegrationTest { + + private Long clientId; + private Long loanId; + + // create client, progressive loan product, loan with disburse limit 1000 for the client, + // and disburse 250 on 01 June 2024 + @BeforeEach + public void beforeEach() { + runAt("01 June 2024", () -> { + clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId(); + final PostLoanProductsResponse loanProductsResponse = loanProductHelper.createLoanProduct(create4IProgressive()); + PostLoansResponse postLoansResponse = loanTransactionHelper.applyLoan( + applyLP2ProgressiveLoanRequest(clientId, loanProductsResponse.getResourceId(), "01 June 2024", 1000.0, 10.0, 4, null)); + loanId = postLoansResponse.getLoanId(); + loanTransactionHelper.approveLoan(loanId, approveLoanRequest(1000.0, "01 June 2024")); + disburseLoan(loanId, BigDecimal.valueOf(250.0), "01 June 2024"); + }); + } + + @Test + public void loanChargeAfterMaturityTest() { + runAt("02 October 2024", () -> { + addLoanCharge(loanId, 6L, "02 October 2024", 25.0d); + + final GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); + final List charges = loanDetails.getCharges(); + Assertions.assertFalse(charges.isEmpty()); + + executeInlineCOB(loanId); + + final GetLoansLoanIdResponse loanDetails2 = loanTransactionHelper.getLoanDetails(loanId); + final List charges2 = loanDetails2.getCharges(); + Assertions.assertNull(charges2); + }); + } +}