oleksii-novikov-onix commented on code in PR #5983:
URL: https://github.com/apache/fineract/pull/5983#discussion_r3441406180
##########
fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanBreachScheduleServiceImpl.java:
##########
@@ -170,6 +179,66 @@ public List<WorkingCapitalLoanBreachScheduleData>
retrieveBreachSchedule(final L
return mapper.toDataList(periods);
}
+ @Override
+ public void recalculatePeriodsForPauses(final WorkingCapitalLoan loan) {
+ final Optional<WorkingCapitalBreach> breachOpt = getBreachConfig(loan);
+ if (breachOpt.isEmpty()) {
+ return;
+ }
+ final List<WorkingCapitalLoanBreachSchedule> periods =
repository.findByLoanIdOrderByPeriodNumberAsc(loan.getId());
+ if (periods.isEmpty()) {
+ return;
+ }
+ final WorkingCapitalBreach breach = breachOpt.get();
+ final List<WorkingCapitalLoanBreachAction> recordedPauses =
findRecordedPauses(loan.getId());
+ final LocalDate businessDate = DateUtils.getBusinessLocalDate();
+ LocalDate fromDate = periods.getFirst().getFromDate();
+ for (final WorkingCapitalLoanBreachSchedule period : periods) {
+ period.setFromDate(fromDate);
+ period.setToDate(calculateToDate(fromDate,
breach.getBreachFrequency(), breach.getBreachFrequencyType()));
+ applyRecordedPauses(period, recordedPauses);
+ recomputeBreach(period, businessDate);
+ fromDate = period.getToDate().plusDays(1);
+ }
+ repository.saveAll(periods);
+ log.debug("Recalculated breach schedule periods for WC loan {} by
replaying {} recorded pauses", loan.getId(),
+ recordedPauses.size());
+ }
+
+ private void recomputeBreach(final WorkingCapitalLoanBreachSchedule
period, final LocalDate businessDate) {
+ if (period.getOutstandingAmount().compareTo(BigDecimal.ZERO) == 0) {
+ period.setBreach(false);
+ } else if (businessDate.isAfter(period.getToDate())) {
+ // COB evaluates with effective date businessDate-1, so breach is
set only after the toDate has passed
+ period.setBreach(true);
+ } else {
+ period.setBreach(null);
+ }
+ }
+
+ private List<WorkingCapitalLoanBreachAction> findRecordedPauses(final Long
loanId) {
+ return
breachActionRepository.findByWorkingCapitalLoanIdOrderById(loanId).stream()
+ .filter(action ->
WorkingCapitalLoanBreachActionType.PAUSE.equals(action.getAction()))
+
.sorted(Comparator.comparing(WorkingCapitalLoanBreachAction::getStartDate)).toList();
+ }
+
+ private void applyRecordedPauses(final WorkingCapitalLoanBreachSchedule
period,
+ final List<WorkingCapitalLoanBreachAction> pauseActions) {
+ for (final WorkingCapitalLoanBreachAction pause : pauseActions) {
+ final LocalDate pauseStart = pause.getStartDate();
Review Comment:
@ruzeynalov @adamsaghy The half-open interval (exclusive endDate) is
consistent with the delinquency code (which the breach logic mirrors). I will
update the fineract-doc accordingly.
--
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]