Search in sources :

Example 16 with ScheduledDateGeneration

use of org.mifos.schedule.ScheduledDateGeneration 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 17 with ScheduledDateGeneration

use of org.mifos.schedule.ScheduledDateGeneration in project head by mifos.

the class ApplyHolidayChangesHelper method reschedule.

private void reschedule(Holiday holiday, AccountBatch accountBatch) throws PersistenceException {
    long rescheduleStartTime = new DateTimeService().getCurrentDateTime().getMillis();
    List<Object[]> accountIdsArray = accountBatch.getAccountIdsWithDatesIn(holiday);
    accountCount = accountIdsArray.size();
    logMessage("No. of " + accountBatch.getAccountTypeName() + " Accounts to Process: " + accountCount + " : Query took: " + (new DateTimeService().getCurrentDateTime().getMillis() - rescheduleStartTime) + " ms");
    rollingStartTime = new DateTimeService().getCurrentDateTime().getMillis();
    currentRecordNumber = 0;
    StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    for (Object[] accountIds : accountIdsArray) {
        Integer accountId = (Integer) accountIds[0];
        Short officeId = (Short) accountIds[1];
        Integer meetingId = (Integer) accountIds[2];
        currentRecordNumber++;
        ScheduledDateGeneration officeScheduledDateGeneration = getScheduledDateGeneration(officeId);
        DateTime amendedThruDate = holiday.getThruDate();
        // Normal holidays only affect installments between the fromDate and thruDate
        if (holiday.getRepaymentRuleType().getValue().equals(RepaymentRuleTypes.REPAYMENT_MORATORIUM.getValue())) {
            amendedThruDate = holiday.getThruDate().plusYears(10);
        }
        List<AccountActionDateEntity> futureAffectedInstallments = accountBatch.getAffectedInstallments(accountId, holiday.getFromDate(), amendedThruDate);
        MeetingBO meeting = (MeetingBO) StaticHibernateUtil.getSessionTL().get(MeetingBO.class, meetingId);
        rescheduleDatesForNewHolidays(officeScheduledDateGeneration, futureAffectedInstallments, meeting);
        houseKeeping();
    }
    StaticHibernateUtil.commitTransaction();
    long rescheduleEndTime = new DateTimeService().getCurrentDateTime().getMillis();
    String message = "" + currentRecordNumber + " updated, " + (accountCount - currentRecordNumber) + " remaining, batch time: " + (rescheduleEndTime - rollingStartTime) + " ms";
    logMessage(message);
    String finalMessage = accountBatch.getAccountTypeName() + " accounts Processed in: " + (rescheduleEndTime - rescheduleStartTime) + " ms";
    logMessage(finalMessage);
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) DateTime(org.joda.time.DateTime) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 18 with ScheduledDateGeneration

use of org.mifos.schedule.ScheduledDateGeneration 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

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