Search in sources :

Example 6 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

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

the class AnyScheduledEventLoanInstallmentGenerator method generate.

@Override
public List<InstallmentDate> generate(LocalDate actualDisbursementDate, int numberOfInstallments, GraceType graceType, int gracePeriodDuration, Short officeId) {
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    if (numberOfInstallments > 0) {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();
        LocalDate startFromMeetingDate = null;
        if (scheduledEvent instanceof DailyScheduledEvent) {
            startFromMeetingDate = actualDisbursementDate.plusDays(scheduledEvent.getEvery());
        } else {
            startFromMeetingDate = actualDisbursementDate.plusDays(1);
        }
        holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toString());
        int occurrences = numberOfInstallments;
        if (graceType == GraceType.GRACEONALLREPAYMENTS) {
            occurrences += gracePeriodDuration;
        }
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
        List<Date> dueDates = new ArrayList<Date>();
        List<DateTime> installmentDateTimes = dateGeneration.generateScheduledDates(occurrences, startFromMeetingDate.toDateMidnight().toDateTime(), scheduledEvent, false);
        for (DateTime installmentDate : installmentDateTimes) {
            dueDates.add(installmentDate.toDate());
        }
        installmentDates = createInstallmentDates(dueDates);
        if (graceType == GraceType.GRACEONALLREPAYMENTS) {
            removeInstallmentsNeedNotPay(gracePeriodDuration, installmentDates);
        }
    }
    return installmentDates;
}
Also used : DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) 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 7 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

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

the class AccountBO method getFeeDates.

public final List<Date> getFeeDates(final MeetingBO feeMeetingFrequency, final List<InstallmentDate> installmentDates, final boolean adjustForHolidays) {
    MeetingBO customerMeeting = getCustomer().getCustomerMeetingValue();
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
    List<Holiday> holidays;
    if (adjustForHolidays) {
        holidays = holidayDao.findAllHolidaysThisYearAndNext(getOffice().getOfficeId());
    } else {
        holidays = new ArrayList<Holiday>();
    }
    DateTime startFromMeetingDate = new DateTime(installmentDates.get(0).getInstallmentDueDate());
    DateTime repaymentEndDatetime = new DateTime(installmentDates.get(installmentDates.size() - 1).getInstallmentDueDate());
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customerMeeting, feeMeetingFrequency);
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
    List<DateTime> feeScheduleDates = dateGeneration.generateScheduledDatesThrough(startFromMeetingDate, repaymentEndDatetime, scheduledEvent, true);
    List<Date> feeSchedulesAsJavaDates = new ArrayList<Date>();
    for (DateTime feeSchedule : feeScheduleDates) {
        feeSchedulesAsJavaDates.add(feeSchedule.toDate());
    }
    return feeSchedulesAsJavaDates;
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate) 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 8 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

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

the class TestObjectFactory method getMeetingDatesThroughTo.

public static List<Date> getMeetingDatesThroughTo(short officeId, final MeetingBO meeting, Date endDate) {
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    List<Holiday> upcomingHolidays = ApplicationContextProvider.getBean(HolidayDao.class).findAllHolidaysThisYearAndNext(officeId);
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
    DateTime meetingStartDate = new DateTime(meeting.getMeetingStartDate());
    DateTime endDateTime = new DateTime(endDate);
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, upcomingHolidays);
    List<DateTime> allDates = dateGeneration.generateScheduledDatesThrough(meetingStartDate, endDateTime, scheduledEvent, false);
    List<Date> dates = new ArrayList<Date>();
    for (DateTime dateTime : allDates) {
        dates.add(dateTime.toDate());
    }
    return dates;
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ArrayList(java.util.ArrayList) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) DateTime(org.joda.time.DateTime) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) 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 9 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

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

the class TestObjectFactory method getMeetingDates.

public static List<Date> getMeetingDates(short officeId, final MeetingBO meeting, final int occurrences) {
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    List<Holiday> upcomingHolidays = ApplicationContextProvider.getBean(HolidayDao.class).findAllHolidaysThisYearAndNext(officeId);
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
    DateTime meetingStartDate = new DateTime(meeting.getMeetingStartDate());
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, upcomingHolidays);
    List<DateTime> allDates = dateGeneration.generateScheduledDates(occurrences, meetingStartDate, scheduledEvent, false);
    List<Date> dates = new ArrayList<Date>();
    for (DateTime dateTime : allDates) {
        dates.add(dateTime.toDate());
    }
    return dates;
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ArrayList(java.util.ArrayList) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) DateTime(org.joda.time.DateTime) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) 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 10 with HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration

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

the class AccountBO method getInstallmentDates.

/**
     * @deprecated - used to create installment dates based on 'loan meeting' and working das, holidays, moratoria etc
     *
     * better to pull capability of creating 'installments' out of loan into something more reuseable and isolated
     */
@Deprecated
public final List<InstallmentDate> getInstallmentDates(final MeetingBO meeting, final Short noOfInstallments, final Short installmentToSkip, final boolean isRepaymentIndepOfMeetingEnabled, final boolean adjustForHolidays) {
    logger.debug("Generating intallment dates");
    List<InstallmentDate> dueInstallmentDates = new ArrayList<InstallmentDate>();
    if (noOfInstallments > 0) {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();
        DateTime startFromMeetingDate = new DateTime(meeting.getMeetingStartDate());
        if (adjustForHolidays) {
            HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
            holidays = holidayDao.findAllHolidaysFromDateAndNext(getOffice().getOfficeId(), startFromMeetingDate.toLocalDate().toString());
        }
        final int occurrences = noOfInstallments + installmentToSkip;
        ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
        List<Date> dueDates = new ArrayList<Date>();
        // FIXME - keithw - this whole area of installment creation should be pulled out of domain
        DateTime startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate;
        if (this.isLoanAccount()) {
            // 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 : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) 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)

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