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


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -344,12 +344,43 @@ public ChangedTransactionDetail 
processLatestTransaction(LoanTransaction loanTra
             case REAMORTIZE -> handleReAmortization(loanTransaction, ctx);
             case REAGE -> handleReAge(loanTransaction, ctx);
             case ACCRUAL_ACTIVITY -> calculateAccrualActivity(loanTransaction, 
ctx);
+            case CONTRACT_TERMINATION -> 
handleContractTermination(loanTransaction, ctx);
             // TODO: Cover rest of the transaction types
             default -> log.warn("Unhandled transaction processing for 
transaction type: {}", loanTransaction.getTypeOf());
         }
         return ctx.getChangedTransactionDetail();
     }
 
+    private void handleContractTermination(final LoanTransaction 
loanTransaction, final TransactionCtx transactionCtx) {
+        handleAccelerateMaturityDate(loanTransaction, transactionCtx);
+
+        final BigDecimal newInterest = 
getInterestTillChargeOffForPeriod(loanTransaction.getLoan(), 
loanTransaction.getTransactionDate(),
+                transactionCtx);
+        createMissingAccrualTransactionDuringChargeOffIfNeeded(newInterest, 
loanTransaction, loanTransaction.getTransactionDate(),
+                transactionCtx);
+
+        loanTransaction.resetDerivedComponents();
+        // determine how much is outstanding total and breakdown for 
principal, interest and charges
+        Money principalPortion = Money.zero(transactionCtx.getCurrency());
+        Money interestPortion = Money.zero(transactionCtx.getCurrency());
+        Money feeChargesPortion = Money.zero(transactionCtx.getCurrency());
+        Money penaltyChargesPortion = Money.zero(transactionCtx.getCurrency());
+        for (final LoanRepaymentScheduleInstallment currentInstallment : 
transactionCtx.getInstallments()) {
+            principalPortion = 
principalPortion.plus(currentInstallment.getPrincipalOutstanding(transactionCtx.getCurrency()));
+            interestPortion = 
interestPortion.plus(currentInstallment.getInterestOutstanding(transactionCtx.getCurrency()));
+            feeChargesPortion = 
feeChargesPortion.plus(currentInstallment.getFeeChargesOutstanding(transactionCtx.getCurrency()));
+            penaltyChargesPortion = penaltyChargesPortion
+                    
.plus(currentInstallment.getPenaltyChargesOutstanding(transactionCtx.getCurrency()));
+        }
+
+        loanTransaction.updateComponentsAndTotal(principalPortion, 
interestPortion, feeChargesPortion, penaltyChargesPortion);
+
+        if (isAllComponentsZero(principalPortion, interestPortion, 
feeChargesPortion, penaltyChargesPortion)
+                && loanTransaction.isNotReversed()) {
+            loanTransaction.reverse();

Review Comment:
   Once this reversed, do we add as transaction change and return to caller to 
throw LoanAdjusted business event?



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