Cocoa-Puffs commented on code in PR #6104:
URL: https://github.com/apache/fineract/pull/6104#discussion_r3614321691


##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanDelinquencyRangeScheduleServiceImpl.java:
##########
@@ -294,6 +297,39 @@ public void resumeActivePause(final WorkingCapitalLoan 
loan, final WorkingCapita
         recalculateDelinquencyAfterPauseResume(loan, businessDate);
     }
 
+    @Override
+    public void resetPeriods(WorkingCapitalLoan loan, 
WorkingCapitalLoanDelinquencyAction action) {
+        LocalDate resetDate = action.getStartDate();
+        final List<WorkingCapitalLoanDelinquencyRangeSchedule> periods = 
loanDelinquencyRangeScheduleRepository
+                .findByLoanIdOrderByPeriodNumberAsc(loan.getId());
+        periods.stream().filter(p -> !Objects.equals(p.getReset(), true) && 
p.getToDate().isBefore(action.getStartDate()))

Review Comment:
   Would it make sense to replace the in memory filtering for a dedicated query?



##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanDelinquencyRangeScheduleServiceImpl.java:
##########
@@ -294,6 +297,39 @@ public void resumeActivePause(final WorkingCapitalLoan 
loan, final WorkingCapita
         recalculateDelinquencyAfterPauseResume(loan, businessDate);
     }
 
+    @Override
+    public void resetPeriods(WorkingCapitalLoan loan, 
WorkingCapitalLoanDelinquencyAction action) {
+        LocalDate resetDate = action.getStartDate();
+        final List<WorkingCapitalLoanDelinquencyRangeSchedule> periods = 
loanDelinquencyRangeScheduleRepository
+                .findByLoanIdOrderByPeriodNumberAsc(loan.getId());
+        periods.stream().filter(p -> !Objects.equals(p.getReset(), true) && 
p.getToDate().isBefore(action.getStartDate()))
+                .forEach(p1 -> resetPeriod(p1, resetDate));
+    }
+
+    private void resetPeriod(WorkingCapitalLoanDelinquencyRangeSchedule 
period, LocalDate resetDate) {
+        period.reset();
+        
delinquencyClassificationService.applyDelinquencyTagForRange(period.getLoan(), 
period, null, resetDate);
+    }
+
+    @Override
+    public void undoResetPeriods(WorkingCapitalLoan loan, 
WorkingCapitalLoanDelinquencyAction action,
+            List<WorkingCapitalLoanDelinquencyAction> 
byWorkingCapitalLoanIdOrderById) {
+
+        List<WorkingCapitalLoanDelinquencyAction> activeResets = 
byWorkingCapitalLoanIdOrderById.stream()
+                .filter(a -> DelinquencyAction.RESET.equals(a.getAction()) && 
a.getEndDate() == null).toList();
+        if (!activeResets.isEmpty()) {
+            activeResets.getLast().setEndDate(action.getStartDate());
+        }
+        LocalDate lastActiveResetStartDate = activeResets.size() >= 2 ? 
activeResets.get(activeResets.size() - 2).getStartDate() : null;
+        final List<WorkingCapitalLoanDelinquencyRangeSchedule> periods = 
loanDelinquencyRangeScheduleRepository
+                .findByLoanIdOrderByPeriodNumberAsc(loan.getId());
+        periods.stream()
+                .filter(p -> Objects.equals(p.getReset(), true) && 
p.getToDate().isBefore(action.getStartDate())

Review Comment:
   Would it make sense to replace the in memory filtering for a dedicated query?



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