[
https://issues.apache.org/jira/browse/FINERACT-3012?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Senesh Perera updated FINERACT-3012:
------------------------------------
Affects Version/s: 1.16.1
> Free withdrawal count never restarts when restart frequency is in DAYS
> (DAYS.between arguments reversed)
> --------------------------------------------------------------------------------------------------------
>
> Key: FINERACT-3012
> URL: https://issues.apache.org/jira/browse/FINERACT-3012
> Project: Apache Fineract
> Issue Type: Bug
> Affects Versions: 1.16.1
> Reporter: Senesh Perera
> Assignee: Senesh Perera
> Priority: Major
>
> h3. Problem
> When a withdrawal fee charge uses free withdrawals with a restart period
> in DAYS, the free withdrawal count never restarts. After the free
> withdrawals are used, the customer pays the fee on every later
> withdrawal, forever.
> h3. Cause
> In {{SavingsAccount.resetFreeChargeDaysCount}} (fineract-savings), the
> DAYS branch computes the elapsed days with the arguments reversed:
> {code:java}
> completedDays = DAYS.between(DateUtils.getBusinessLocalDate(),
> this.activatedOnDate);
> ...
> completedDays = DAYS.between(DateUtils.getBusinessLocalDate(), resetDate);
> {code}
> {{ChronoUnit.DAYS.between(a, b)}} returns b minus a. Here the start date
> is today, so the result is zero or negative. The restart period must be
> greater than 0, so {{totalDays < restartPeriod}} is always true and the
> restart branch ({{discountCharge}}) can never run.
> h3. History
> Before the Date to LocalDate refactor in commit 1db8ef46fc (2022-07-12),
> the code computed (business date - activated date), which is positive.
> The refactor reversed the arguments. FINERACT-1955 (71afd6dead) only
> changed the type and did not fix the order.
> h3. Example
> Withdrawal fee: flat 10. Free withdrawals: 2. Restart every 7 DAYS.
> Account activated 2026-01-01.
> || Withdrawal date || Current result || Expected ||
> | 2026-01-02 | free (count 1) | free |
> | 2026-01-03 | free (count 2) | free |
> | 2026-01-04 | fee 10 | fee 10 |
> | 2026-01-15 (14 days later) | *fee 10* | free, count restarts to 1 |
> h3. Verified with a unit test
> I wrote a unit test that reproduces this. It fails today with
> "fee charged on 2026-01-15: expected 0 but was 10.00". A control test
> with MONTHS as the restart frequency passes, so the test setup is fine.
> h3. Notes
> * Only the DAYS branch is affected by this ordering problem. The MONTHS
> branch works.
> * No existing test covers free withdrawals (I searched for
> freeWithdrawal, enableFreeWithdrawalCharge, restartCountFrequency).
> * Related but different: FINERACT-1374 (original feature),
> FINERACT-1390, FINERACT-2952, FINERACT-2635.
> * Separate topic, not part of this fix: WEEKS and YEARS are handled by
> the same DAYS branch, so they are treated as days. I can open a
> separate ticket for that.
> h3. Proposed fix
> Swap the arguments so the start date comes first. I would like to work
> on this and open a small PR with the fix and the test.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)