FINERACT-2017: Fix apply holidays to loans job

This commit is contained in:
mariiaKraievska
2023-12-19 15:49:56 +01:00
committed by Adam Saghy
parent aff009c400
commit 8d6528408d
4 changed files with 97 additions and 9 deletions
@@ -18,6 +18,8 @@
*/
package org.apache.fineract.portfolio.loanaccount.jobs.applyholidaystoloans;
import static org.apache.fineract.infrastructure.core.service.DateUtils.isDateWithinRange;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
@@ -129,13 +131,13 @@ public class ApplyHolidaysToLoansTasklet implements Tasklet {
loanRepaymentScheduleInstallment.updateFromDate(tmpFromDate);
}
if (!DateUtils.isBefore(oldDueDate, holiday.getFromDate())) {
if (isDateWithinRange(oldDueDate, holiday.getFromDate(), holiday.getToDate())) {
// FIXME: AA do we need to apply non-working days.
// Assuming holiday's repayment reschedule to date cannot be
// created on a non-working day.
adjustedRescheduleToDate = scheduledDateGenerator.generateNextRepaymentDate(adjustedRescheduleToDate, loanApplicationTerms,
false);
adjustedRescheduleToDate = scheduledDateGenerator.generateNextRepaymentDateWhenHolidayApply(adjustedRescheduleToDate,
loanApplicationTerms);
loanRepaymentScheduleInstallment.updateDueDate(adjustedRescheduleToDate);
}
tmpFromDate = loanRepaymentScheduleInstallment.getDueDate();
@@ -358,4 +358,42 @@ public class DefaultScheduledDateGenerator implements ScheduledDateGenerator {
}
return adjustedDate;
}
public LocalDate generateNextRepaymentDateWhenHolidayApply(final LocalDate lastRepaymentDate,
final LoanApplicationTerms loanApplicationTerms) {
LocalDate seedDate;
String reccuringString;
Calendar currentCalendar = loanApplicationTerms.getLoanCalendar();
LocalDate dueRepaymentPeriodDate = lastRepaymentDate;
dueRepaymentPeriodDate = (LocalDate) CalendarUtils.adjustDate(dueRepaymentPeriodDate, loanApplicationTerms.getSeedDate(),
loanApplicationTerms.getRepaymentPeriodFrequencyType());
if (currentCalendar != null) {
// If we have currentCalendar object, this means there is a
// calendar associated with
// the loan, and we should use it in order to calculate next
// repayment
CalendarHistory calendarHistory = null;
CalendarHistoryDataWrapper calendarHistoryDataWrapper = loanApplicationTerms.getCalendarHistoryDataWrapper();
if (calendarHistoryDataWrapper != null) {
calendarHistory = loanApplicationTerms.getCalendarHistoryDataWrapper().getCalendarHistory(dueRepaymentPeriodDate);
}
// get the start date from the calendar history
if (calendarHistory == null) {
seedDate = currentCalendar.getStartDateLocalDate();
reccuringString = currentCalendar.getRecurrence();
} else {
seedDate = calendarHistory.getStartDate();
reccuringString = calendarHistory.getRecurrence();
}
dueRepaymentPeriodDate = CalendarUtils.getNextRepaymentMeetingDate(reccuringString, seedDate, lastRepaymentDate,
loanApplicationTerms.getRepaymentEvery(),
CalendarUtils.getMeetingFrequencyFromPeriodFrequencyType(loanApplicationTerms.getLoanTermPeriodFrequencyType()),
loanApplicationTerms.isSkipRepaymentOnFirstDayofMonth(), loanApplicationTerms.getNumberOfdays());
}
return dueRepaymentPeriodDate;
}
}