adamsaghy commented on code in PR #6081:
URL: https://github.com/apache/fineract/pull/6081#discussion_r3638369142


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanTransactionReprocessingServiceImpl.java:
##########
@@ -146,22 +186,25 @@ private void reprocessTransactions(final 
WorkingCapitalLoan loan, final List<Wor
             principalPayments.add(new 
PrincipalPayment(txn.getTransactionDate(), plan.principalPortion()));
         }
 
-        // The recomputed overpayment ignores refunds already paid out, so 
subtract non-reversed CBRs to avoid
-        // resurrecting a refunded overpayment. Floored at zero; the 
over-refund case is out of scope here.
-        final BigDecimal creditBalanceRefundTotal = allTransactions.stream()
-                .filter(txn -> !txn.isReversed() && txn.getTypeOf() == 
LoanTransactionType.CREDIT_BALANCE_REFUND)
-                
.map(WorkingCapitalLoanTransaction::getTransactionAmount).reduce(BigDecimal.ZERO,
 BigDecimal::add);
-        if (creditBalanceRefundTotal.signum() > 0) {
-            
balance.setOverpaymentAmount(balance.getOverpaymentAmount().subtract(creditBalanceRefundTotal).max(BigDecimal.ZERO));
-        }
-
         allocationRepository.saveAll(updatedAllocations);
         chargeRepository.saveAll(charges);
         balanceRepository.saveAndFlush(balance);
 
-        // The amortization schedule depends only on the principal paid per 
day, which can shift when the principal
-        // portions are re-allocated; rebuild it from the recomputed portions.
-        
amortizationScheduleWriteService.rebuildScheduleFromPrincipalPayments(loan, 
principalPayments);
+        // The amortization schedule depends on the principal paid per day, 
which can shift when the principal portions
+        // are re-allocated; rebuild it from the recomputed portions, then 
re-inject the over-refunded principal on the
+        // date of the CBR that created it.
+        
amortizationScheduleWriteService.rebuildScheduleFromPrincipalPayments(loan, 
principalPayments, principalAdjustments);
+
+        // On an accounting-enabled loan the re-allocation changed the 
principal/overpayment split of the surviving
+        // transactions, so their booking-time journal entries are stale (an 
overpayment leg shrinks, a refund turns
+        // into extra-lending principal). Restate each surviving transaction's 
entries from its recomputed allocation.
+        if (correctAccounting && 
loan.getLoanProduct().getAccountingRule().isAccrualWithDeferredRevenueAmortization())
 {
+            for (final WorkingCapitalLoanTransactionAllocation allocation : 
updatedAllocations) {
+                final WorkingCapitalLoanTransaction txn = 
allocation.getWcLoanTransaction();
+                final BigDecimal creditBalanceRefundExcess = 
creditBalanceRefundExcessByTxnId.getOrDefault(txn.getId(), BigDecimal.ZERO);
+                accountingProcessor.restateJournalEntries(loan, txn, 
allocation, creditBalanceRefundExcess, false);

Review Comment:
   Ohh.. we dont have overpayment portion allocation :/ 



-- 
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]

Reply via email to