MIFOSX-1358,MIFOSX-1357

This commit is contained in:
Madhukar
2014-06-26 08:12:10 +05:30
parent 1eff0f138e
commit fc2d90db7b
5 changed files with 639 additions and 8 deletions
@@ -7,7 +7,19 @@ import org.mifosplatform.organisation.holiday.domain.Holiday;
public class HolidayUtil {
public static LocalDate getRepaymentRescheduleDateToIfHoliday(final LocalDate repaymentDate, final List<Holiday> holidays) {
public static LocalDate getRepaymentRescheduleDateToIfHoliday(LocalDate repaymentDate, final List<Holiday> holidays) {
for (final Holiday holiday : holidays) {
if (repaymentDate.equals(holiday.getFromDateLocalDate()) || repaymentDate.equals(holiday.getToDateLocalDate())
|| (repaymentDate.isAfter(holiday.getFromDateLocalDate()) && repaymentDate.isBefore(holiday.getToDateLocalDate()))) {
repaymentDate = getRepaymentRescheduleDateIfHoliday(repaymentDate, holidays);
}
}
return repaymentDate;
}
private static LocalDate getRepaymentRescheduleDateIfHoliday(final LocalDate repaymentDate, final List<Holiday> holidays) {
for (final Holiday holiday : holidays) {
if (repaymentDate.equals(holiday.getFromDateLocalDate()) || repaymentDate.equals(holiday.getToDateLocalDate())
|| (repaymentDate.isAfter(holiday.getFromDateLocalDate()) && repaymentDate.isBefore(holiday.getToDateLocalDate()))) {
@@ -40,4 +40,8 @@ public class WorkingDaysUtil {
public static boolean isWorkingDay(final WorkingDays workingDays, final LocalDate date) {
return CalendarUtils.isValidRedurringDate(workingDays.getRecurrence(), date, date);
}
public static boolean isNonWorkingDay(final WorkingDays workingDays, final LocalDate date) {
return !isWorkingDay(workingDays, date);
}
}
@@ -2112,6 +2112,7 @@ public class Loan extends AbstractPersistable<Long> {
existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
reverseExistingTransactions();
updateLoanSummaryDerivedFields();
}
@@ -53,10 +53,19 @@ public class DefaultScheduledDateGenerator implements ScheduledDateGenerator {
@Override
public LocalDate adjustRepaymentDate(final LocalDate dueRepaymentPeriodDate, final LoanApplicationTerms loanApplicationTerms,
final boolean isHolidayEnabled, final List<Holiday> holidays, final WorkingDays workingDays) {
LocalDate adjustedDate = dueRepaymentPeriodDate;
final LocalDate nextDueRepaymentPeriodDate = getRepaymentPeriodDate(loanApplicationTerms.getRepaymentPeriodFrequencyType(),
loanApplicationTerms.getRepaymentEvery(), adjustedDate);
adjustedDate = WorkingDaysUtil.getOffSetDateIfNonWorkingDay(adjustedDate, nextDueRepaymentPeriodDate, workingDays);
/**
* Fix for https://mifosforge.jira.com/browse/MIFOSX-1357
*/
// recursively check for the next working day.
while (WorkingDaysUtil.isNonWorkingDay(workingDays, adjustedDate)) {
final LocalDate nextDueRepaymentPeriodDate = getRepaymentPeriodDate(loanApplicationTerms.getRepaymentPeriodFrequencyType(),
loanApplicationTerms.getRepaymentEvery(), adjustedDate);
adjustedDate = WorkingDaysUtil.getOffSetDateIfNonWorkingDay(adjustedDate, nextDueRepaymentPeriodDate, workingDays);
}
if (isHolidayEnabled) {
adjustedDate = HolidayUtil.getRepaymentRescheduleDateToIfHoliday(adjustedDate, holidays);
}