This is an automated email from the ASF dual-hosted git repository.

adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 5137fd65a FINERACT-2081: Charge-off optimalization
5137fd65a is described below

commit 5137fd65afb18ca0790aa4dc2b8e81309c731ff2
Author: Adam Saghy <[email protected]>
AuthorDate: Fri Feb 21 10:54:30 2025 +0100

    FINERACT-2081: Charge-off optimalization
---
 .../apache/fineract/portfolio/loanaccount/domain/Loan.java   |  4 ++++
 .../service/LoanDownPaymentHandlerServiceImpl.java           |  2 +-
 .../loanaccount/domain/LoanAccountDomainServiceJpa.java      |  2 +-
 .../service/LoanChargeWritePlatformServiceImpl.java          |  8 ++++----
 .../service/LoanWritePlatformServiceJpaRepositoryImpl.java   | 12 ++++++------
 .../service/ProgressiveLoanInterestRefundServiceImpl.java    |  2 +-
 .../loanaccount/service/reaging/LoanReAgingServiceImpl.java  |  2 +-
 7 files changed, 18 insertions(+), 14 deletions(-)

diff --git 
a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
 
b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
index 50230e0cc..87f89ef7b 100644
--- 
a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
+++ 
b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
@@ -3584,4 +3584,8 @@ public class Loan extends 
AbstractAuditableWithUTCDateTimeCustom<Long> {
     public boolean hasChargeOffTransaction() {
         return 
getLoanTransactions().stream().anyMatch(LoanTransaction::isChargeOff);
     }
+
+    public boolean hasAccelerateChargeOffStrategy() {
+        return 
LoanChargeOffBehaviour.ACCELERATE_MATURITY.equals(getLoanProductRelatedDetail().getChargeOffBehaviour());
+    }
 }
diff --git 
a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanDownPaymentHandlerServiceImpl.java
 
b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanDownPaymentHandlerServiceImpl.java
index 139603d52..743d13363 100644
--- 
a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanDownPaymentHandlerServiceImpl.java
+++ 
b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanDownPaymentHandlerServiceImpl.java
@@ -154,7 +154,7 @@ public class LoanDownPaymentHandlerServiceImpl implements 
LoanDownPaymentHandler
         if (reprocess) {
             if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
                 
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
                 loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
             }
             reprocessLoanTransactionsService.reprocessTransactions(loan);
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
index 91b90cf75..95ca92eda 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
@@ -891,7 +891,7 @@ public class LoanAccountDomainServiceJpa implements 
LoanAccountDomainService {
         } else {
             if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
                 
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
                 loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
             }
             loan.getLoanTransactions().add(refundTransaction);
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java
index c6f461029..93ab1a773 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeWritePlatformServiceImpl.java
@@ -288,7 +288,7 @@ public class LoanChargeWritePlatformServiceImpl implements 
LoanChargeWritePlatfo
         }
 
         if (reprocessRequired) {
-            if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+            if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction() 
&& loan.hasAccelerateChargeOffStrategy()) {
                 final ScheduleGeneratorDTO scheduleGeneratorDTO = 
loanUtilService.buildScheduleGeneratorDTO(loan, null);
                 loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
             }
@@ -830,7 +830,7 @@ public class LoanChargeWritePlatformServiceImpl implements 
LoanChargeWritePlatfo
 
             if (reprocessRequired) {
                 addInstallmentIfPenaltyAppliedAfterLastDueDate(loan, 
lastChargeDate);
-                if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+                if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
                     final ScheduleGeneratorDTO scheduleGeneratorDTO = 
loanUtilService.buildScheduleGeneratorDTO(loan, null);
                     loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
                 }
@@ -865,7 +865,7 @@ public class LoanChargeWritePlatformServiceImpl implements 
LoanChargeWritePlatfo
                 .determineProcessor(loan.transactionProcessingStrategy());
         loan.addLoanTransaction(loanChargeAdjustmentTransaction);
         if (loan.isInterestBearingAndInterestRecalculationEnabled()) {
-            if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+            if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction() 
&& loan.hasAccelerateChargeOffStrategy()) {
                 final ScheduleGeneratorDTO scheduleGeneratorDTO = 
loanUtilService.buildScheduleGeneratorDTO(loan, null);
                 loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
             }
@@ -1446,7 +1446,7 @@ public class LoanChargeWritePlatformServiceImpl 
implements LoanChargeWritePlatfo
         if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()
                 && DateUtils.isBefore(loanCharge.getDueLocalDate(), 
businessDate)) {
             
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-        } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+        } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
             loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
         }
         // Waive of charges whose due date falls after latest 'repayment' 
transaction don't require entire loan schedule
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
index cf3a0f9eb..d7f1fd603 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
@@ -1106,7 +1106,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl 
implements LoanWritePlatf
     private void reprocessChangedLoanTransactions(Loan loan, 
ScheduleGeneratorDTO scheduleGeneratorDTO) {
         if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
             
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-        } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+        } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
             loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
         }
 
@@ -2628,7 +2628,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl 
implements LoanWritePlatf
 
             if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
                 
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
                 loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
                 
reprocessLoanTransactionsService.processPostDisbursementTransactions(loan);
             }
@@ -2782,7 +2782,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl 
implements LoanWritePlatf
                 || rescheduledRepaymentDate != null) {
             if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
                 
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
                 loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
             }
         }
@@ -3502,7 +3502,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl 
implements LoanWritePlatf
             loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
             if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
                 
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+            } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
                 loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
             }
             reprocessLoanTransactionsService.reprocessTransactions(loan);
@@ -3615,7 +3615,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl 
implements LoanWritePlatf
 
         if (loan.isCumulativeSchedule() && 
loan.isInterestBearingAndInterestRecalculationEnabled()) {
             
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, 
scheduleGeneratorDTO);
-        } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction()) {
+        } else if (loan.isProgressiveSchedule() && 
loan.hasChargeOffTransaction() && loan.hasAccelerateChargeOffStrategy()) {
             loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
         }
 
@@ -3684,7 +3684,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl 
implements LoanWritePlatf
                 "reversed");
         writeOffTransaction.reverse();
         
loanLifecycleStateMachine.transition(LoanEvent.WRITE_OFF_OUTSTANDING_UNDO, 
loan);
-        if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction()) {
+        if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction() && 
loan.hasAccelerateChargeOffStrategy()) {
             final ScheduleGeneratorDTO scheduleGeneratorDTO = 
loanUtilService.buildScheduleGeneratorDTO(loan, null);
             loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
         }
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanInterestRefundServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanInterestRefundServiceImpl.java
index 949e3619a..5079af324 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanInterestRefundServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanInterestRefundServiceImpl.java
@@ -84,7 +84,7 @@ public class ProgressiveLoanInterestRefundServiceImpl 
implements InterestRefundS
         List<LoanRepaymentScheduleInstallment> installmentsToReprocess = new 
ArrayList<>(
                 loan.getRepaymentScheduleInstallments().stream().filter(i -> 
!i.isReAged() && !i.isAdditional()).toList());
 
-        if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction()) {
+        if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction() && 
loan.hasAccelerateChargeOffStrategy()) {
             final ScheduleGeneratorDTO scheduleGeneratorDTO = 
loanUtilService.buildScheduleGeneratorDTO(loan, null);
             loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
         }
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java
index dd8071ffa..bd8d32043 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/reaging/LoanReAgingServiceImpl.java
@@ -128,7 +128,7 @@ public class LoanReAgingServiceImpl {
         }
         reverseReAgeTransaction(reAgeTransaction, command);
         loanTransactionRepository.saveAndFlush(reAgeTransaction);
-        if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction()) {
+        if (loan.isProgressiveSchedule() && loan.hasChargeOffTransaction() && 
loan.hasAccelerateChargeOffStrategy()) {
             final ScheduleGeneratorDTO scheduleGeneratorDTO = 
loanUtilService.buildScheduleGeneratorDTO(loan, null);
             loanScheduleService.regenerateRepaymentSchedule(loan, 
scheduleGeneratorDTO);
         }

Reply via email to