Farooq Ayoade created FINERACT-3198:
---------------------------------------

             Summary: Closing a fixed deposit with "reinvest principal only" 
(onAccountClosureId 400) reinvests the interest too
                 Key: FINERACT-3198
                 URL: https://issues.apache.org/jira/browse/FINERACT-3198
             Project: Apache Fineract
          Issue Type: Bug
            Reporter: Farooq Ayoade



h3. Summary

{{POST /fixeddepositaccounts/\{id\}?command=close}} accepts an 
{{onAccountClosureId}} of {{300}}
(reinvest principal *and* interest) or {{400}} (reinvest principal *only*). The 
two behave the same:
both roll the whole matured balance into the new deposit. A depositor who asked 
to take the interest
and reinvest only the principal has the interest reinvested as well, with no 
error and nothing in the
response to show it.

h3. Steps to reproduce

# Open, approve and activate a fixed deposit, and let it mature with interest 
posted, e.g. principal
1,000,000 matured to 1,120,000.
# {{POST /fixeddepositaccounts/\{id\}?command=close}} with
{noformat}{"closedOnDate":"...","onAccountClosureId":400,"dateFormat":"...","locale":"en"}{noformat}
The response is 200.
# {{GET}} the newly created deposit: {{depositAmount}} is *1,120,000* (the 
matured balance).
Expected *1,000,000* (the original deposit), with the 120,000 of interest paid 
out.
# Closing the same way with {{onAccountClosureId: 300}} produces exactly the 
same new deposit.

h3. Root cause

{{DepositAccountDomainServiceJpa}} has two closure handlers, and only one of 
them reads the choice.

{{handleFDAccountMaturityClosure(...)}}, used by the maturity-instruction path, 
branches correctly:
{code:java}
BigDecimal reInvestAmount;
if (onClosureType == DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY) {
    reInvestAmount = account.getDepositAmount();
} else {
    reInvestAmount = account.getAccountBalance();
}
{code}

{{handleFDAccountClosure(...)}}, which {{?command=close}} reaches through
{{DepositAccountWritePlatformServiceJpaRepositoryImpl}}, tests for both 
reinvest types in a single
{{if}} and then ignores which one it got:
{code:java}
FixedDepositAccount reinvestedDeposit = 
account.reInvest(account.getAccountBalance(), externalId);
{code}

h3. Proposed fix

Give {{handleFDAccountClosure}} the same branch as its maturity counterpart.

The withdrawal amount does not change. The manual close ends in 
{{account.close(user, command, changes)}},
and {{SavingsAccount.close()}} fails with {{results.in.balance.not.zero}} 
unless the balance is zero,
so the closing account must still withdraw its whole balance. The interest that 
is not reinvested
leaves the account as a payout to the depositor. The maturity path can withdraw 
the principal alone
because it does not close the account: its {{account.close(...)}} call is 
commented out.

h3. Impact

Only {{onAccountClosureId: 400}} changes; {{300}} is untouched. Anyone relying 
on 400 behaving like
300 will see the new deposit hold the principal and the interest paid out, 
which is what the option
says it does.

h3. Related

* FINERACT-3022 (PR #6788) fixed the reinvest amount on the maturity-job path 
({{updateMaturityDetails}}).
It does not touch {{handleFDAccountClosure}}.
* FINERACT-2376 (PR #5061) fixed a 500 on this close path, not the amount.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to