mariiaKraievska commented on code in PR #4745:
URL: https://github.com/apache/fineract/pull/4745#discussion_r2154380153


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/contracttermination/LoanContractTerminationServiceImpl.java:
##########
@@ -116,6 +125,69 @@ public CommandProcessingResult 
applyContractTermination(final JsonCommand comman
                 .with(changes).build();
     }
 
+    public CommandProcessingResult undoContractTermination(final JsonCommand 
command) {
+        final Long loanId = command.getLoanId();
+
+        loanTransactionValidator.validateContractTerminationUndo(command, 
loanId);
+
+        final Loan loan = loanAssembler.assembleFrom(loanId);
+        final LoanTransaction contractTerminationTransaction = 
loan.findContractTerminationTransaction();
+
+        businessEventNotifierService.notifyPreBusinessEvent(new 
LoanUndoContractTerminationBusinessEvent(contractTerminationTransaction));
+        businessEventNotifierService.notifyPreBusinessEvent(
+                new LoanAdjustTransactionBusinessEvent(new 
LoanAdjustTransactionBusinessEvent.Data(contractTerminationTransaction)));
+
+        // check if reversalExternalId is provided
+        final String reversalExternalId = 
command.stringValueOfParameterNamedAllowingNull(LoanApiConstants.REVERSAL_EXTERNAL_ID_PARAMNAME);
+        final ExternalId reversalTxnExternalId = 
ExternalIdFactory.produce(reversalExternalId);
+        final Map<String, Object> changes = new LinkedHashMap<>();
+
+        // Add note if provided
+        final String noteText = command.stringValueOfParameterNamed("note");
+        if (StringUtils.isNotBlank(noteText)) {
+            changes.put("note", noteText);
+            final Note note = Note.loanTransactionNote(loan, 
contractTerminationTransaction, noteText);
+            noteRepository.save(note);
+        }
+
+        
loanChargeValidator.validateRepaymentTypeTransactionNotBeforeAChargeRefund(contractTerminationTransaction.getLoan(),
+                contractTerminationTransaction, "reversed");
+        contractTerminationTransaction.reverse(reversalTxnExternalId);
+        contractTerminationTransaction.manuallyAdjustedOrReversed();
+
+        loan.liftContractTerminationSubStatus();
+        changes.put(LoanApiConstants.subStatusAttributeName, 
loan.getLoanSubStatus());
+        loanTransactionRepository.saveAndFlush(contractTerminationTransaction);
+
+        final ScheduleGeneratorDTO scheduleGeneratorDTO = 
this.loanUtilService.buildScheduleGeneratorDTO(loan, null, null);
+        if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
+            
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
+        } else if (loan.isProgressiveSchedule()) {
+            loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
+        }
+
+        reprocessLoanTransactionsService.reprocessTransactions(loan);
+
+        loanRepository.save(loan);

Review Comment:
   Done



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