Search in sources :

Example 1 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class GenerateMeetingsForCustomerAndSavingsHelper method execute.

@Override
public void execute(@SuppressWarnings("unused") final long timeInMillis) throws BatchJobException {
    workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    officeCurrentAndFutureHolidays = new HashMap<Short, List<Holiday>>();
    long taskStartTime = new DateTimeService().getCurrentDateTime().getMillis();
    List<Integer> customerAndSavingsAccountIds = findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated();
    int accountCount = customerAndSavingsAccountIds.size();
    if (accountCount == 0) {
        return;
    }
    List<String> errorList = new ArrayList<String>();
    int currentRecordNumber = 0;
    int outputIntervalForBatchJobs = GeneralConfig.getOutputIntervalForBatchJobs();
    int batchSize = GeneralConfig.getBatchSizeForBatchJobs();
    // jpw - hardcoded recordCommittingSize to 500 because now only accounts that need more schedules are returned
    int recordCommittingSize = 500;
    infoLogBatchParameters(accountCount, outputIntervalForBatchJobs, batchSize, recordCommittingSize);
    long startTime = new DateTimeService().getCurrentDateTime().getMillis();
    Integer currentAccountId = null;
    int updatedRecordCount = 0;
    try {
        StaticHibernateUtil.getSessionTL();
        StaticHibernateUtil.startTransaction();
        for (Integer accountId : customerAndSavingsAccountIds) {
            currentRecordNumber++;
            currentAccountId = accountId;
            AccountBO accountBO = legacyAccountDao.getAccount(accountId);
            List<Holiday> currentAndFutureHolidays = getOfficeCurrentAndFutureHolidays(accountBO.getOffice().getOfficeId());
            ScheduledDateGeneration scheduleGenerationStrategy = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, currentAndFutureHolidays);
            if (accountBO instanceof CustomerAccountBO) {
                ((CustomerAccountBO) accountBO).generateNextSetOfMeetingDates(scheduleGenerationStrategy);
                updatedRecordCount++;
            } else if (accountBO instanceof SavingsBO) {
                ((SavingsBO) accountBO).generateNextSetOfMeetingDates(workingDays, currentAndFutureHolidays);
                updatedRecordCount++;
            }
            if (currentRecordNumber % batchSize == 0) {
                StaticHibernateUtil.flushAndClearSession();
                getLogger().debug("completed HibernateUtil.flushAndClearSession()");
            }
            if (updatedRecordCount > 0) {
                if (updatedRecordCount % recordCommittingSize == 0) {
                    StaticHibernateUtil.commitTransaction();
                    StaticHibernateUtil.getSessionTL();
                    StaticHibernateUtil.startTransaction();
                }
            }
            if (currentRecordNumber % outputIntervalForBatchJobs == 0) {
                long time = System.currentTimeMillis();
                String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
                logMessage(message);
                startTime = time;
            }
        }
        StaticHibernateUtil.commitTransaction();
        long time = System.currentTimeMillis();
        String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
        logMessage(message);
    } catch (Exception e) {
        logMessage("account " + currentAccountId.intValue() + " exception " + e.getMessage());
        StaticHibernateUtil.rollbackTransaction();
        errorList.add(currentAccountId.toString());
        getLogger().error("Unable to generate schedules for account with ID " + currentAccountId, e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
    logMessage("GenerateMeetingsForCustomerAndSavings ran in " + (new DateTimeService().getCurrentDateTime().getMillis() - taskStartTime));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Holiday(org.mifos.application.holiday.business.Holiday) ArrayList(java.util.ArrayList) List(java.util.List) DateTimeService(org.mifos.framework.util.DateTimeService) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 2 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class HolidayDaoHibernate method findCalendarEventsForThisYearAndNext.

@Override
public final CalendarEvent findCalendarEventsForThisYearAndNext(short officeId) {
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    List<Holiday> upcomingHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(officeId);
    return new CalendarEvent(workingDays, upcomingHolidays);
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) CalendarEvent(org.mifos.calendar.CalendarEvent) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules)

Example 3 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class HolidayServiceFacadeWebTier method validateDisbursementDateForNewLoan.

@Override
public void validateDisbursementDateForNewLoan(Short officeId, DateTime disbursementDate) {
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    validateDisbursementDateIsWorkingDay(disbursementDate, workingDays);
    List<Holiday> holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, new LocalDate(disbursementDate).toString());
    validateDisbursementDateIsNotInHoliday(disbursementDate, holidays);
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) OfficeHoliday(org.mifos.dto.domain.OfficeHoliday) Days(org.joda.time.Days) LocalDate(org.joda.time.LocalDate) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules)

Example 4 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class MoratoriumStrategy method shiftDatePastNonMoratoriumHoliday.

/**
     * Given that the date is in a non-moratorium holiday, shift it past the holiday until either it is no longer
     * in a holiday or moratorium, or until it no longer moves (e.g., lands in a same-day holiday).
     *
     * <p> If the date shifts into a moratorium period, then shift it out using the RepaymentRuleType of
     * the most recent non-moratorium holiday that the date was shifted out of. For example, if shifting
     * the date out of a next-working-day holiday lands it in a moratorium period, then use the
     * next-working-day repayment rule to shift it past the moratorium period.</p>
     *
     * @param date the DateTime to be shifted
     * @return the shifted date
     */
private DateTime shiftDatePastNonMoratoriumHoliday(DateTime date) {
    assert date != null;
    assert isEnclosedByAHoliday(date);
    assert !isEnclosedByAHolidayWithRepaymentRule(date, RepaymentRuleTypes.REPAYMENT_MORATORIUM);
    Holiday currentlyEnclosingHoliday = getHolidayEnclosing(date);
    RepaymentRuleTypes mostRecentNonMoratoriumRepaymentRule = //never REPAYMENT_MORATORIUM
    currentlyEnclosingHoliday.getRepaymentRuleType();
    DateTime previousDate = null;
    DateTime adjustedDate = date;
    do {
        previousDate = adjustedDate;
        if (currentlyEnclosingHoliday.getRepaymentRuleType() == RepaymentRuleTypes.REPAYMENT_MORATORIUM) {
            adjustedDate = buildHolidayFromCurrentHolidayWithRepaymentRule(currentlyEnclosingHoliday, mostRecentNonMoratoriumRepaymentRule).adjust(previousDate, workingDays, scheduledEvent);
        } else {
            adjustedDate = (new BasicWorkingDayStrategy(workingDays)).adjust(currentlyEnclosingHoliday.adjust(previousDate, workingDays, scheduledEvent));
            mostRecentNonMoratoriumRepaymentRule = currentlyEnclosingHoliday.getRepaymentRuleType();
        }
        if (isEnclosedByAHoliday(adjustedDate)) {
            currentlyEnclosingHoliday = getHolidayEnclosing(adjustedDate);
        }
    } while (isEnclosedByAHoliday(adjustedDate) && (!adjustedDate.equals(previousDate)));
    return adjustedDate;
}
Also used : RepaymentRuleTypes(org.mifos.application.holiday.util.helpers.RepaymentRuleTypes) Holiday(org.mifos.application.holiday.business.Holiday) DateTime(org.joda.time.DateTime)

Example 5 with Holiday

use of org.mifos.application.holiday.business.Holiday 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)

Aggregations

Holiday (org.mifos.application.holiday.business.Holiday)54 Test (org.junit.Test)32 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)28 DateTime (org.joda.time.DateTime)22 ArrayList (java.util.ArrayList)16 Days (org.joda.time.Days)13 FiscalCalendarRules (org.mifos.config.FiscalCalendarRules)13 LocalDate (org.joda.time.LocalDate)10 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)9 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)8 Date (java.util.Date)7 DateMidnight (org.joda.time.DateMidnight)6 Ignore (org.junit.Ignore)6 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)6 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)4 DateTimeService (org.mifos.framework.util.DateTimeService)4 Before (org.junit.Before)3 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)3 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3