Samer-Melhem-FOO opened a new pull request, #6744: URL: https://github.com/apache/fineract/pull/6744
## Description JIRA: [FINERACT-2998](https://issues.apache.org/jira/browse/FINERACT-2998) **Depends on #6742 (FINERACT-2997).** This branch is stacked on it because both change the same accrual loop in `addAccruals`; only the second commit, `FINERACT-2998: Date a cumulative accrual catch-up on the run date`, belongs to this PR. I will rebase it onto `develop` once #6742 is merged. A cumulative periodic-accrual run posts one accrual per installment, back-dated to each installment's due date. A catch-up after missed runs (or after a loan leaves NPA) is therefore spread over the missed days, and fails outright when those days fall inside a closed accounting period ("Journal entry cannot be made prior to last account closing date for the branch"), so the loan gets no accrual at all. The back-dating exists because cumulative reprocessing attributes accruals to installments by date and reverses any whose installment looks over-accrued; a single catch-up dated on the run date would be reversed on the next reprocess. So the fix changes both sides: - `addAccruals`: a cumulative run posts one accrual dated on the run date, merged as the final and progressive paths already are; merged interest portions are floored at zero. - `calcInterestAccruedAmount`: the cumulative path reads the installment's own `interestAccrued` instead of summing accruals dated in its window. - `reprocessPeriodicAccruals` (cumulative): new `reallocateCumulativeAccruals` fills accruals into installments in order (as the progressive path does) and reverses the latest only on real over-accrual: interest above what is accruable to the business date, or fees/penalties above what the schedule charges. Accruals after the last due date stay with `adjustAccrualsAfter`. ### Testing - Unit: three new tests in `LoanAccrualsProcessingServiceImplTest` (a catch-up is reallocated to earlier installments without being reversed, accrual adjustments are netted, the latest accrual is reversed on real over-accrual). They fail without the change and pass with it; the class passes (46 tests); `spotlessJavaCheck` is clean. - Live, against PostgreSQL, periodic-accrual product with 12 daily installments, one "Add Periodic Accrual Transactions" run after four missed days: - Before: four accruals dated on each installment's due date (8.22, 7.54, 6.86, 6.18). With an office accounting closure two days before the run, the job fails with the closed-period error and the loan gets no accrual. - After: one accrual of 28.80 dated on the run date; a repayment and its undo (reprocess) reverse nothing. With the same closure, the job succeeds and the loan gets one accrual of 28.80 dated on the run date. ## Checklist - [x] Write the commit message as per [our guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests) - [x] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers. - [x] Create/update [unit or integration tests](https://fineract.apache.org/docs/current/#_testing) for verifying the changes made. - [x] Follow our [coding conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions). - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes (no API change) - [x] [This PR must not be a "code dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit). Large changes can be made in a branch, with assistance. Ask for help on the [developer mailing list](https://fineract.apache.org/#contribute). - [x] If merging this PR resolves a JIRA issue, I will mark that issue as resolved and set "Fix Version/s" appropriately. - [x] I followed the [AI Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
