Search in sources :

Example 11 with Holiday

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

the class SavingsBO method goActiveForFristTimeAndGenerateSavingsSchedule.

/**
     * use minimal constructor which generates scheduled savings payments correctly and does not
     * do through this method.
     */
@Deprecated
private void goActiveForFristTimeAndGenerateSavingsSchedule(final CustomerBO customer) throws AccountException {
    HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
    CalendarEvent futureCalendarEventsApplicableToOffice = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
    this.activationDate = new DateTime(new DateTimeService().getCurrentJavaDateTime()).toDate();
    List<Days> workingDays = futureCalendarEventsApplicableToOffice.getWorkingDays();
    List<Holiday> holidays = futureCalendarEventsApplicableToOffice.getHolidays();
    logger.debug("In SavingsBO::generateDepositAccountActions()");
    // center/group with individual deposits, insert row for every client
    if (this.getCustomer().getCustomerMeeting() != null && this.getCustomer().getCustomerMeeting().getMeeting() != null) {
        MeetingBO depositSchedule = this.getCustomer().getCustomerMeeting().getMeeting();
        if (this.getCustomer().getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || this.getCustomer().getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && this.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
            this.generateDepositAccountActions(this.getCustomer(), depositSchedule, workingDays, holidays, new DateTime(this.activationDate));
        } else {
            List<CustomerBO> children;
            try {
                children = this.getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.ACTIVE_AND_ONHOLD);
            } catch (CustomerException ce) {
                throw new AccountException(ce);
            }
            for (CustomerBO customer1 : children) {
                this.generateDepositAccountActions(customer1, depositSchedule, workingDays, holidays, new DateTime(this.activationDate));
            }
        }
    }
    InterestScheduledEvent interestPostingEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(this.savingsOffering.getFreqOfPostIntcalc().getMeeting());
    this.nextIntPostDate = interestPostingEvent.nextMatchingDateAfter(new LocalDate(startOfFiscalYear()), new LocalDate(this.activationDate)).toDateMidnight().toDate();
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) CustomerException(org.mifos.customers.exceptions.CustomerException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CalendarEvent(org.mifos.calendar.CalendarEvent) LocalDate(org.joda.time.LocalDate) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) DateTime(org.joda.time.DateTime) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) AccountException(org.mifos.accounts.exceptions.AccountException) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 12 with Holiday

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

the class HolidayDaoHibernateIntegrationTest method shouldSaveFutureHoliday.

@Test
public void shouldSaveFutureHoliday() throws Exception {
    List<Holiday> holidays = holidayDao.findAllHolidaysThisYearAndNext((short) 1);
    int initialCount = holidays.size();
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    Holiday futureHoliday = new HolidayBuilder().from(new DateTime()).to(new DateTime().plusDays(1)).appliesTo(headOffice).build();
    StaticHibernateUtil.startTransaction();
    holidayDao.save(futureHoliday);
    StaticHibernateUtil.flushSession();
    holidays = holidayDao.findAllHolidaysThisYearAndNext(headOffice.getOfficeId());
    assertFalse(holidays.isEmpty());
    assertThat(holidays.size() - initialCount, is(1));
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) OfficeBO(org.mifos.customers.office.business.OfficeBO) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 13 with Holiday

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

the class HolidayDaoHibernateIntegrationTest method shouldFindAllHolidaysOrderedByFromDateAscending.

@Ignore
@Test
public void shouldFindAllHolidaysOrderedByFromDateAscending() throws Exception {
    DateTime secondlastDayOfYear = new DateTime().withMonthOfYear(12).withDayOfMonth(30).toDateMidnight().toDateTime();
    DateTime lastDayOfYear = secondlastDayOfYear.plusDays(1);
    DateTime secondOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(2).toDateMidnight().toDateTime();
    DateTime thirdOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(3).toDateMidnight().toDateTime();
    List<Holiday> holidays = holidayDao.findAllHolidaysThisYearAndNext(new Short("1"));
    int initialCountOfHolidays = holidays.size();
    List<Holiday> futureHolidays = holidayDao.findAllHolidaysFromDateAndNext(new Short("1"), secondOfJanNextYear.toLocalDate().toString());
    int initialCountOfFutureHolidays = futureHolidays.size();
    Holiday holiday1 = new HolidayBuilder().from(secondlastDayOfYear).to(secondlastDayOfYear).build();
    Holiday holiday2 = new HolidayBuilder().from(secondOfJanNextYear).to(secondOfJanNextYear).build();
    Holiday holiday3 = new HolidayBuilder().from(thirdOfJanNextYear).to(thirdOfJanNextYear).build();
    Holiday holiday4 = new HolidayBuilder().from(lastDayOfYear).to(lastDayOfYear).build();
    insertHoliday(holiday2);
    insertHoliday(holiday3);
    insertHoliday(holiday1);
    insertHoliday(holiday4);
    holidays = holidayDao.findAllHolidaysThisYearAndNext(new Short("1"));
    assertThat(holidays.size() - initialCountOfHolidays, is(4));
    assertTrue(holidays.get(0).encloses(secondlastDayOfYear.toDate()));
    assertTrue(holidays.get(1).encloses(lastDayOfYear.toDate()));
    assertTrue(holidays.get(2).encloses(secondOfJanNextYear.toDate()));
    assertTrue(holidays.get(3).encloses(thirdOfJanNextYear.toDate()));
    futureHolidays = holidayDao.findAllHolidaysFromDateAndNext(new Short("1"), secondOfJanNextYear.toLocalDate().toString());
    assertThat(futureHolidays.size() - initialCountOfFutureHolidays, is(2));
    assertTrue(futureHolidays.get(0).encloses(secondOfJanNextYear.toDate()));
    assertTrue(futureHolidays.get(1).encloses(thirdOfJanNextYear.toDate()));
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with Holiday

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

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

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