Search in sources :

Example 16 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

use of org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration in project head by mifos.

the class IndependentOfCustomerMeetingScheduleLoanInstallmentGenerator method getInstallmentDates.

private final List<InstallmentDate> getInstallmentDates(final ScheduledEvent scheduledEvent, LocalDate meetingStartDate, final int noOfInstallments, final int installmentToSkip, Short officeId) {
    List<InstallmentDate> dueInstallmentDates = new ArrayList<InstallmentDate>();
    if (noOfInstallments > 0) {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();
        DateTime startFromMeetingDate = meetingStartDate.toDateMidnight().toDateTime();
        holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toLocalDate().toString());
        final int occurrences = noOfInstallments + installmentToSkip;
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
        List<Date> dueDates = new ArrayList<Date>();
        DateTime startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate;
        // ensure loans that are created or disbursed on a meeting date start on next valid meeting date and not todays meeting
        // ensure loans that are created or disbursed before a meeting date start on next valid meeting date
        startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate.plusDays(1);
        List<DateTime> installmentDates = dateGeneration.generateScheduledDates(occurrences, startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments, scheduledEvent, false);
        for (DateTime installmentDate : installmentDates) {
            dueDates.add(installmentDate.toDate());
        }
        dueInstallmentDates = createInstallmentDates(installmentToSkip, dueDates);
    }
    return dueInstallmentDates;
}
Also used : ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 17 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

use of org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration in project head by mifos.

the class CustomerAccountBO method regenerateFutureInstallments.

@Override
protected void regenerateFutureInstallments(final AccountActionDateEntity nextInstallment, final List<Days> workingDays, final List<Holiday> holidays) throws AccountException {
    int numberOfInstallmentsToGenerate = getLastInstallmentId();
    MeetingBO meeting = getMeetingForAccount();
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
    LocalDate currentDate = new LocalDate();
    LocalDate thisIntervalStartDate = meeting.startDateForMeetingInterval(currentDate);
    LocalDate nextMatchingDate = new LocalDate(scheduledEvent.nextEventDateAfter(thisIntervalStartDate.toDateTimeAtStartOfDay()));
    DateTime futureIntervalStartDate = meeting.startDateForMeetingInterval(nextMatchingDate).toDateTimeAtStartOfDay();
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
    List<DateTime> meetingDates = dateGeneration.generateScheduledDates(numberOfInstallmentsToGenerate, futureIntervalStartDate, scheduledEvent, true);
    updateSchedule(nextInstallment.getInstallmentId(), meetingDates);
}
Also used : DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 18 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

use of org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration in project head by mifos.

the class ApplyHolidayChangesHelper method getScheduledDateGeneration.

private ScheduledDateGeneration getScheduledDateGeneration(Short officeId) {
    ScheduledDateGeneration scheduledDateGeneration = officeScheduledDateGenerationMap.get(officeId);
    if (scheduledDateGeneration != null) {
        return scheduledDateGeneration;
    }
    List<Holiday> futureHolidays = getHolidayDao().findCurrentAndFutureOfficeHolidaysEarliestFirst(officeId);
    scheduledDateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, futureHolidays);
    officeScheduledDateGenerationMap.put(officeId, scheduledDateGeneration);
    return scheduledDateGeneration;
}
Also used : HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) Holiday(org.mifos.application.holiday.business.Holiday) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Aggregations

HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)18 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)17 DateTime (org.joda.time.DateTime)15 LocalDate (org.joda.time.LocalDate)12 ScheduledEvent (org.mifos.schedule.ScheduledEvent)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 Holiday (org.mifos.application.holiday.business.Holiday)9 FiscalCalendarRules (org.mifos.config.FiscalCalendarRules)7 Days (org.joda.time.Days)6 InterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent)6 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)5 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)4 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 SavingsInterestScheduledEventFactory (org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory)3 CustomerBO (org.mifos.customers.business.CustomerBO)2 DailyScheduledEvent (org.mifos.schedule.internal.DailyScheduledEvent)2 List (java.util.List)1 Before (org.junit.Before)1