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


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanWritePlatformServiceImpl.java:
##########
@@ -969,6 +985,72 @@ public CommandProcessingResult 
updatePeriodPaymentRate(final Long loanId, final
                 .withLoanId(loanId).with(changes).build();
     }
 
+    public CommandProcessingResult undoTransaction(final WorkingCapitalLoan 
loan, final WorkingCapitalLoanTransaction transaction,
+            JsonCommand command) {
+
+        validator.validateUndoTransaction(command, loan, transaction);
+
+        Map<String, Object> changes = new HashMap<>();
+        changes.put("reversed", true);
+        transaction.setReversed(true);
+
+        ExternalId reversalExternalId = externalIdFactory
+                
.create(command.stringValueOfParameterNamedAllowingNull(WorkingCapitalLoanConstants.reversalExternalIdParamName));
+        transaction.setReversalExternalId(reversalExternalId);
+        changes.put("reversalExternalId", reversalExternalId);
+
+        LocalDate reversedOnDate = ThreadLocalContextUtil.getBusinessDate();
+        transaction.setReversedOnDate(reversedOnDate);
+        changes.put("reversedOnDate", reversedOnDate);
+
+        if (loan.getLoanProduct().getAccountingRule().isCashBased()) {
+            accountingProcessor.postReversalJournalEntries(loan, transaction);
+        }
+
+        final List<WorkingCapitalLoanCharge> charges = 
this.chargeRepository.findByLoanIdAndActiveTrueOrderByDueDateAscIdAsc(loan.getId());
+        if (charges.isEmpty()) {
+            amortizationScheduleWriteService.applyRepaymentUndo(loan, 
transaction.getTransactionDate(),
+                    transaction.getAllocation().getPrincipalPortion());
+            updateBalanceOnUndoRepayment(loan, 
transaction.getTransactionAmount());
+        } else {
+            final List<WorkingCapitalLoanTransaction> transactionsToReprocess 
= transactionRepository
+                    
.findByWcLoan_IdOrderByTransactionDateAscIdAsc(loan.getId()).stream()
+                    .filter(tr -> Objects.equals(tr.getId(), 
transaction.getId())).toList();
+            transactionReprocessingService.reprocessTransactions(loan, 
transactionsToReprocess);
+        }
+
+        breachScheduleService.applyRepaymentUndo(loan.getId(), 
transaction.getTransactionDate(),
+                transaction.getAllocation().getPrincipalPortion());
+        makePaymentUndoForDelinquency(loan.getId(), loan, 
transaction.getAllocation().getPrincipalPortion(),
+                ThreadLocalContextUtil.getBusinessDate());

Review Comment:
   It would be better to uniform the way for delinquency and breach... same 
incoming parameters, same service based logic.



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