diff --git a/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature b/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature index f72490351..f19e0bb93 100644 --- a/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature +++ b/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature @@ -6933,3 +6933,145 @@ Feature: Loan | 10 April 2024 | Accrual | 1.72 | 0.0 | 1.72 | 0.0 | 0.0 | 0.0 | false | false | Then Loan status will be "CLOSED_OBLIGATIONS_MET" Then Loan has 0 outstanding amount + +# @TestRailId:C_1 + Scenario: Verify repayment schedule and accrual transactions created after penalty is added for paid off loan on maturity date + When Admin sets the business date to "08 May 2024" + And Admin creates a client with random data + When Admin creates a fully customized loan with the following data: + | LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy | + | LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_ACCRUAL_ACTIVITY | 08 May 2024 | 1000 | 12.19 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 3 | MONTHS | 1 | MONTHS | 3 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION | + And Admin successfully approves the loan on "08 May 2024" with "1000" amount and expected disbursement date on "08 May 2024" + When Admin successfully disburse the loan on "08 May 2024" with "1000" EUR transaction amount + Then Loan Repayment schedule has 3 periods, with the following data for periods: + | Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | | | 08 May 2024 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | | + | 1 | 31 | 08 June 2024 | | 670.03 | 329.97 | 10.16 | 0.0 | 0.0 | 340.13 | 0.0 | 0.0 | 0.0 | 340.13 | + | 2 | 30 | 08 July 2024 | | 336.71 | 333.32 | 6.81 | 0.0 | 0.0 | 340.13 | 0.0 | 0.0 | 0.0 | 340.13 | + | 3 | 31 | 08 August 2024 | | 0.0 | 336.71 | 3.42 | 0.0 | 0.0 | 340.13 | 0.0 | 0.0 | 0.0 | 340.13 | + And Loan Repayment schedule has the following data in Total row: + | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | 1000.0 | 20.39 | 0.0 | 0.0 | 1020.39 | 0.0 | 0.0 | 0.0 | 1020.39 | + And Loan Transactions tab has the following data: + | Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed | + | 08 May 2024 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false | + When Admin sets the business date to "08 June 2024" + And Customer makes "AUTOPAY" repayment on "08 June 2024" with 340.13 EUR transaction amount + When Admin sets the business date to "08 July 2024" + And Customer makes "AUTOPAY" repayment on "08 July 2024" with 340.13 EUR transaction amount + When Admin sets the business date to "08 August 2024" + And Admin runs inline COB job for Loan + And Customer makes "AUTOPAY" repayment on "08 August 2024" with 340.13 EUR transaction amount + Then Loan Repayment schedule has 3 periods, with the following data for periods: + | Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | | | 08 May 2024 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | | + | 1 | 31 | 08 June 2024 | 08 June 2024 | 670.03 | 329.97 | 10.16 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 2 | 30 | 08 July 2024 | 08 July 2024 | 336.71 | 333.32 | 6.81 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 3 | 31 | 08 August 2024 | 08 August 2024 | 0.0 | 336.71 | 3.42 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + And Loan Repayment schedule has the following data in Total row: + | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | 1000.0 | 20.39 | 0.0 | 0.0 | 1020.39 | 1020.39 | 0.0 | 0.0 | 0.0 | + And Loan Transactions tab has the following data: + | Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed | + | 08 May 2024 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false | + | 08 June 2024 | Repayment | 340.13 | 329.97 | 10.16 | 0.0 | 0.0 | 670.03 | false | false | + | 08 June 2024 | Accrual Activity | 10.16 | 0.0 | 10.16 | 0.0 | 0.0 | 0.0 | false | false | + | 08 July 2024 | Repayment | 340.13 | 333.32 | 6.81 | 0.0 | 0.0 | 336.71 | false | false | + | 08 July 2024 | Accrual Activity | 6.81 | 0.0 | 6.81 | 0.0 | 0.0 | 0.0 | false | false | + | 07 August 2024 | Accrual | 20.28 | 0.0 | 20.28 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Repayment | 340.13 | 336.71 | 3.42 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 0.11 | 0.0 | 0.11 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual Activity | 3.42 | 0.0 | 3.42 | 0.0 | 0.0 | 0.0 | false | false | +# --- add penalty for paid off loan on maturity date ---# + When Admin adds "LOAN_NSF_FEE" due date charge with "08 August 2024" due date and 2.8 EUR transaction amount + Then Loan Repayment schedule has 3 periods, with the following data for periods: + | Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | | | 08 May 2024 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | | + | 1 | 31 | 08 June 2024 | 08 June 2024 | 670.03 | 329.97 | 10.16 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 2 | 30 | 08 July 2024 | 08 July 2024 | 336.71 | 333.32 | 6.81 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 3 | 31 | 08 August 2024 | | 0.0 | 336.71 | 3.42 | 0.0 | 2.8 | 342.93 | 340.13 | 0.0 | 0.0 | 2.8 | + And Loan Repayment schedule has the following data in Total row: + | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | 1000.0 | 20.39 | 0.0 | 2.8 | 1023.19 | 1020.39 | 0.0 | 0.0 | 2.8 | + And Loan Transactions tab has the following data: + | Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed | + | 08 May 2024 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false | + | 08 June 2024 | Repayment | 340.13 | 329.97 | 10.16 | 0.0 | 0.0 | 670.03 | false | false | + | 08 June 2024 | Accrual Activity | 10.16 | 0.0 | 10.16 | 0.0 | 0.0 | 0.0 | false | false | + | 08 July 2024 | Repayment | 340.13 | 333.32 | 6.81 | 0.0 | 0.0 | 336.71 | false | false | + | 08 July 2024 | Accrual Activity | 6.81 | 0.0 | 6.81 | 0.0 | 0.0 | 0.0 | false | false | + | 07 August 2024 | Accrual | 20.28 | 0.0 | 20.28 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Repayment | 340.13 | 336.71 | 3.42 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 0.11 | 0.0 | 0.11 | 0.0 | 0.0 | 0.0 | false | false | + When Admin sets the business date to "09 August 2024" + And Admin runs inline COB job for Loan + Then Loan Repayment schedule has 3 periods, with the following data for periods: + | Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | | | 08 May 2024 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | | + | 1 | 31 | 08 June 2024 | 08 June 2024 | 670.03 | 329.97 | 10.16 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 2 | 30 | 08 July 2024 | 08 July 2024 | 336.71 | 333.32 | 6.81 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 3 | 31 | 08 August 2024 | | 0.0 | 336.71 | 3.42 | 0.0 | 2.8 | 342.93 | 340.13 | 0.0 | 0.0 | 2.8 | + And Loan Repayment schedule has the following data in Total row: + | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | 1000.0 | 20.39 | 0.0 | 2.8 | 1023.19 | 1020.39 | 0.0 | 0.0 | 2.8 | + And Loan Transactions tab has the following data: + | Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed | + | 08 May 2024 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false | + | 08 June 2024 | Repayment | 340.13 | 329.97 | 10.16 | 0.0 | 0.0 | 670.03 | false | false | + | 08 June 2024 | Accrual Activity | 10.16 | 0.0 | 10.16 | 0.0 | 0.0 | 0.0 | false | false | + | 08 July 2024 | Repayment | 340.13 | 333.32 | 6.81 | 0.0 | 0.0 | 336.71 | false | false | + | 08 July 2024 | Accrual Activity | 6.81 | 0.0 | 6.81 | 0.0 | 0.0 | 0.0 | false | false | + | 07 August 2024 | Accrual | 20.28 | 0.0 | 20.28 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Repayment | 340.13 | 336.71 | 3.42 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 0.11 | 0.0 | 0.11 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 2.8 | 0.0 | 0.0 | 0.0 | 2.8 | 0.0 | false | false | + | 08 August 2024 | Accrual Activity | 6.22 | 0.0 | 3.42 | 0.0 | 2.8 | 0.0 | false | false | + When Admin sets the business date to "15 August 2024" + And Admin runs inline COB job for Loan + And Customer makes "AUTOPAY" repayment on "15 August 2024" with 2.8 EUR transaction amount + Then Loan Repayment schedule has 3 periods, with the following data for periods: + | Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | | | 08 May 2024 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | | + | 1 | 31 | 08 June 2024 | 08 June 2024 | 670.03 | 329.97 | 10.16 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 2 | 30 | 08 July 2024 | 08 July 2024 | 336.71 | 333.32 | 6.81 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 3 | 31 | 08 August 2024 | 15 August 2024 | 0.0 | 336.71 | 3.42 | 0.0 | 2.8 | 342.93 | 342.93 | 0.0 | 2.8 | 0.0 | + And Loan Repayment schedule has the following data in Total row: + | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | 1000.0 | 20.39 | 0.0 | 2.8 | 1023.19 | 1023.19 | 0.0 | 2.8 | 0.0 | + And Loan Transactions tab has the following data: + | Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed | + | 08 May 2024 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false | + | 08 June 2024 | Repayment | 340.13 | 329.97 | 10.16 | 0.0 | 0.0 | 670.03 | false | false | + | 08 June 2024 | Accrual Activity | 10.16 | 0.0 | 10.16 | 0.0 | 0.0 | 0.0 | false | false | + | 08 July 2024 | Repayment | 340.13 | 333.32 | 6.81 | 0.0 | 0.0 | 336.71 | false | false | + | 08 July 2024 | Accrual Activity | 6.81 | 0.0 | 6.81 | 0.0 | 0.0 | 0.0 | false | false | + | 07 August 2024 | Accrual | 20.28 | 0.0 | 20.28 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Repayment | 340.13 | 336.71 | 3.42 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 0.11 | 0.0 | 0.11 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 2.8 | 0.0 | 0.0 | 0.0 | 2.8 | 0.0 | false | false | + | 08 August 2024 | Accrual Activity | 6.22 | 0.0 | 3.42 | 0.0 | 2.8 | 0.0 | false | false | + | 15 August 2024 | Repayment | 2.8 | 0.0 | 0.0 | 0.0 | 2.8 | 0.0 | false | false | + When Admin sets the business date to "16 August 2024" + And Admin runs inline COB job for Loan + Then Loan Repayment schedule has 3 periods, with the following data for periods: + | Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | | | 08 May 2024 | | 1000.0 | | | 0.0 | | 0.0 | 0.0 | | | | + | 1 | 31 | 08 June 2024 | 08 June 2024 | 670.03 | 329.97 | 10.16 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 2 | 30 | 08 July 2024 | 08 July 2024 | 336.71 | 333.32 | 6.81 | 0.0 | 0.0 | 340.13 | 340.13 | 0.0 | 0.0 | 0.0 | + | 3 | 31 | 08 August 2024 | 15 August 2024 | 0.0 | 336.71 | 3.42 | 0.0 | 2.8 | 342.93 | 342.93 | 0.0 | 2.8 | 0.0 | + And Loan Repayment schedule has the following data in Total row: + | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding | + | 1000.0 | 20.39 | 0.0 | 2.8 | 1023.19 | 1023.19 | 0.0 | 2.8 | 0.0 | + And Loan Transactions tab has the following data: + | Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed | + | 08 May 2024 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false | + | 08 June 2024 | Repayment | 340.13 | 329.97 | 10.16 | 0.0 | 0.0 | 670.03 | false | false | + | 08 June 2024 | Accrual Activity | 10.16 | 0.0 | 10.16 | 0.0 | 0.0 | 0.0 | false | false | + | 08 July 2024 | Repayment | 340.13 | 333.32 | 6.81 | 0.0 | 0.0 | 336.71 | false | false | + | 08 July 2024 | Accrual Activity | 6.81 | 0.0 | 6.81 | 0.0 | 0.0 | 0.0 | false | false | + | 07 August 2024 | Accrual | 20.28 | 0.0 | 20.28 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Repayment | 340.13 | 336.71 | 3.42 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 0.11 | 0.0 | 0.11 | 0.0 | 0.0 | 0.0 | false | false | + | 08 August 2024 | Accrual | 2.8 | 0.0 | 0.0 | 0.0 | 2.8 | 0.0 | false | false | + | 08 August 2024 | Accrual Activity | 6.22 | 0.0 | 3.42 | 0.0 | 2.8 | 0.0 | false | false | + | 15 August 2024 | Repayment | 2.8 | 0.0 | 0.0 | 0.0 | 2.8 | 0.0 | false | false | diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualsProcessingServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualsProcessingServiceImpl.java index 6dd45dcec..976835c2a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualsProcessingServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualsProcessingServiceImpl.java @@ -358,7 +358,7 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing if (progressiveAccrual && accruedTill != null && !DateUtils.isAfter(tillDate, accruedTill)) { if (isFinal) { reverseTransactionsAfter(existingAccruals, accrualDate, addJournal); - } else if (existingAccruals.stream().anyMatch(t -> !t.isReversed() && !DateUtils.isBefore(t.getDateOf(), accrualDate))) { + } else if (isExistAccrualAfterDate(existingAccruals, accrualDate) && hasNoActiveChargeOnDate(loan, accrualDate)) { return; } } @@ -445,6 +445,14 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing } } + private boolean isExistAccrualAfterDate(List existingAccruals, LocalDate accrualDate) { + return existingAccruals.stream().anyMatch(t -> !t.isReversed() && !DateUtils.isBefore(t.getDateOf(), accrualDate)); + } + + private boolean hasNoActiveChargeOnDate(Loan loan, LocalDate accrualDate) { + return loan.getLoanCharges(t -> t.isActive() && DateUtils.isEqual(t.getDueDate(), accrualDate)).isEmpty(); + } + private AccrualPeriodsData calculateAccrualAmounts(@NotNull final Loan loan, @NotNull final LocalDate tillDate, final boolean periodic, final boolean isFinal, final boolean chargeOnDueDate) { final LoanProductRelatedDetail productDetail = loan.getLoanProductRelatedDetail();