Ralph Hopman created FINERACT-2566:
--------------------------------------

             Summary: Refresh loan summary after account-transfer disbursement 
charge collection
                 Key: FINERACT-2566
                 URL: https://issues.apache.org/jira/browse/FINERACT-2566
             Project: Apache Fineract
          Issue Type: Bug
          Components: Charges, Loan
            Reporter: Ralph Hopman
            Assignee: Ralph Hopman


When a loan is disbursed and one or more loan charges have their payment mode 
set to *Account Transfer* ({{{}ACCOUNT_TRANSFER{}}}), the system collects each 
charge by calling {{transferFunds()}} on the linked savings account. This 
creates a {{REPAYMENT_AT_DISBURSEMENT}} loan transaction and marks the charge 
as paid.

However, {{transferFunds()}} does *not* recompute the {{LoanSummary}} derived 
fields. As a result, fields such as {{{}feeChargesPaid{}}}, 
{{{}feeChargesOutstanding{}}}, and {{totalOutstanding}} remain stale, 
reflecting the values computed during the {{saveAndFlush}} that preceded the 
charge loop.

This causes the loan balance to appear higher than what the client actually 
owes after disbursement.
h2. Steps to Reproduce
 # Create a loan product with a disbursement charge configured with payment 
mode {*}Account Transfer{*}.
 # Link a savings account to the loan.
 # Approve and disburse the loan.
 # Observe that {{LoanSummary.totalOutstanding}} and {{feeChargesOutstanding}} 
do not reflect the charge collection.

h2. Root Cause

In {{{}LoanWritePlatformServiceJpaRepositoryImpl#disburseLoan(){}}}, after the 
loop that calls {{accountTransfersWritePlatformService.transferFunds()}} for 
each entry in {{{}disBuLoanCharges{}}}, there is no subsequent call to 
{{loanBalanceService.updateLoanSummaryDerivedFields(loan)}} or a flush. The 
summary is therefore out of sync for the remainder of the disbursement flow and 
is persisted in a stale state.
h2. Proposed Fix

After the {{disBuLoanCharges}} transfer loop, when the map is non-empty, call:
{code:java}
if (!disBuLoanCharges.isEmpty()) {
    loanBalanceService.updateLoanSummaryDerivedFields(loan);
    saveAndFlushLoanWithDataIntegrityViolationChecks(loan);
}
{code}
h2. Acceptance Criteria
 * When a loan with an {{ACCOUNT_TRANSFER}} disbursement charge is disbursed, 
{{LoanSummary}} derived fields ({{{}feeChargesPaid{}}}, 
{{{}feeChargesOutstanding{}}}, {{{}totalOutstanding{}}}) must reflect the 
collected charge amounts.
 * When a loan has *no* {{ACCOUNT_TRANSFER}} disbursement charges, the existing 
behaviour is unchanged (no extra summary refresh is performed).
 * Unit tests cover both branches:
 ** A loan with an {{ACCOUNT_TRANSFER}} disbursement charge triggers exactly 
two calls to {{{}updateLoanSummaryDerivedFields{}}}.
 ** A loan with only {{REGULAR}} disbursement charges (or none) triggers 
exactly one call.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to