Search in sources :

Example 1 with DailyScheduledEvent

use of org.mifos.schedule.internal.DailyScheduledEvent 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 2 with DailyScheduledEvent

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

the class CustomerAccountBO method createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer.

/**
     * Create an initial meeting schedule with fees attached, if any.
     *
     * <p>PostConditions:</p>
     *
     * <ul>
     * <li> <code>numberOfMeetingDatesToGenerateOnCreation</code> {@link CustomerScheduleEntity}s are created
     *      starting with <code>customerMeeting</code>'s start date, scheduled according to <code>customerMeeting</code>'s
     *      frequency and recurrence, and subject to rules for scheduling around on working days and around holidays. See
     *      {@link HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration} for scheduling rules.</li>
     * <li> One-time upfront fees are attached to the first meeting.</li>
     * <li> Periodic fees are attached to the first meeting and subsequent meetings that match the fee's frequency
     *      and recurrence</li>
     * <li> The <code>lastAppliedDate</code> for each fee is set to the date of the latest meeting to which the fee
     *      is attached
     * </ul>
     */
public void createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(CustomerBO customer, List<AccountFeesEntity> accountFees, MeetingBO customerMeeting, CalendarEvent applicableCalendarEvents, DateTime scheduleGenerationStartingFrom) {
    final ScheduledEvent customerMeetingEvent = new RecurringScheduledEventFactoryImpl().createScheduledEventFrom(customerMeeting);
    DateTime beginningFrom = scheduleGenerationStartingFrom;
    // synch up generated schedule for center/group/client or group/client hierarchy
    CustomerBO upmostParent = upmostParentOf(customer);
    if (upmostParent != null) {
        LocalDate parentCustomerActiviationDate = new LocalDate(upmostParent.getCustomerActivationDate());
        LocalDate childCustomerActiviationDate = new LocalDate(customer.getCustomerActivationDate());
        LocalDate validCustomerMeetingMatch = null;
        if (customerMeetingEvent instanceof DailyScheduledEvent) {
            validCustomerMeetingMatch = new LocalDate(parentCustomerActiviationDate.toDateMidnight().toDateTime());
        } else {
            validCustomerMeetingMatch = new LocalDate(customerMeetingEvent.nearestMatchNotTakingIntoAccountScheduleFrequency(parentCustomerActiviationDate.toDateMidnight().toDateTime()));
        }
        while (childCustomerActiviationDate.isAfter(validCustomerMeetingMatch)) {
            validCustomerMeetingMatch = new LocalDate(customerMeetingEvent.rollFrowardDateByFrequency(validCustomerMeetingMatch.toDateMidnight().toDateTime()));
        }
        beginningFrom = validCustomerMeetingMatch.toDateMidnight().toDateTime();
    }
    DateTime meetingStartDate = new DateTime(customer.getCustomerMeetingValue().getMeetingStartDate());
    if (beginningFrom.isBefore(meetingStartDate)) {
        beginningFrom = meetingStartDate;
    }
    createInitialSetOfCustomerScheduleEntities(customer, beginningFrom, applicableCalendarEvents, customerMeetingEvent);
    applyFeesToInitialSetOfInstallments(new ArrayList<AccountFeesEntity>(accountFees), customerMeetingEvent);
}
Also used : DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) RecurringScheduledEventFactoryImpl(org.mifos.clientportfolio.newloan.domain.RecurringScheduledEventFactoryImpl) DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Aggregations

DateTime (org.joda.time.DateTime)2 LocalDate (org.joda.time.LocalDate)2 DailyScheduledEvent (org.mifos.schedule.internal.DailyScheduledEvent)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Days (org.joda.time.Days)1 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)1 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)1 Holiday (org.mifos.application.holiday.business.Holiday)1 RecurringScheduledEventFactoryImpl (org.mifos.clientportfolio.newloan.domain.RecurringScheduledEventFactoryImpl)1 FiscalCalendarRules (org.mifos.config.FiscalCalendarRules)1 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)1 ScheduledEvent (org.mifos.schedule.ScheduledEvent)1 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)1