Search in sources :

Example 26 with Holiday

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

the class HolidayAndWorkingDaysScheduledDateGenerationTest method setupAndInjectDependencies.

@Before
public void setupAndInjectDependencies() {
    workingDays = Arrays.asList(DayOfWeek.mondayAsDay(), DayOfWeek.tuesdayAsDay(), DayOfWeek.wednesdayAsDay(), DayOfWeek.thursdayAsDay(), DayOfWeek.fridayAsDay());
    List<Holiday> upcomingHolidays = new ArrayList<Holiday>();
    scheduleGeneration = new HolidayAndWorkingDaysScheduledDateGeneration(workingDays, upcomingHolidays);
}
Also used : HolidayAndWorkingDaysScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysScheduledDateGeneration) Holiday(org.mifos.application.holiday.business.Holiday) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 27 with Holiday

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

the class HolidayDaoHibernate method validateNoExtraFutureHolidaysApplicableOnParentOffice.

@Override
public void validateNoExtraFutureHolidaysApplicableOnParentOffice(Short oldParentOfficeId, Short newParentOfficeId) throws ApplicationException {
    List<Holiday> previousApplicableHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(oldParentOfficeId);
    List<Holiday> possibleApplicableHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(newParentOfficeId);
    if (previousApplicableHolidays.size() != possibleApplicableHolidays.size()) {
        throw new ApplicationException(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT);
    }
    for (Holiday holiday : previousApplicableHolidays) {
        HolidayBO applicableHoliday = (HolidayBO) holiday;
        if (!possibleApplicableHolidays.contains(applicableHoliday)) {
            throw new ApplicationException(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT);
        }
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) Holiday(org.mifos.application.holiday.business.Holiday) HolidayBO(org.mifos.application.holiday.business.HolidayBO)

Example 28 with Holiday

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

Example 29 with Holiday

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

the class CustomerServiceImpl method generateSavingSchedulesForGroupAndCenterSavingAccounts.

private void generateSavingSchedulesForGroupAndCenterSavingAccounts(ClientBO client) {
    try {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();
        UserContext userContext = client.getUserContext();
        CustomerBO group = client.getParentCustomer();
        if (group != null) {
            List<SavingsBO> groupSavingAccounts = new CustomerPersistence().retrieveSavingsAccountForCustomer(group.getCustomerId());
            CustomerBO center = group.getParentCustomer();
            if (center != null) {
                List<SavingsBO> centerSavingAccounts = new CustomerPersistence().retrieveSavingsAccountForCustomer(center.getCustomerId());
                groupSavingAccounts.addAll(centerSavingAccounts);
            }
            for (SavingsBO savings : groupSavingAccounts) {
                savings.setUserContext(userContext);
                if (client.getCustomerMeetingValue() != null) {
                    if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
                        DateTime today = new DateTime().toDateMidnight().toDateTime();
                        savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), workingDays, holidays, today);
                    }
                }
            }
        }
    } catch (PersistenceException pe) {
        throw new MifosRuntimeException(pe);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) DateTime(org.joda.time.DateTime) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 30 with Holiday

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

the class AccountRegenerateScheduleIntegrationTestCase method testChangeInMeetingScheduleForDates.

public void testChangeInMeetingScheduleForDates(MeetingBO customerMeeting, MeetingBO loanMeeting, MeetingBO newMeeting, LocalDate startDate, LocalDate dateWhenMeetingWillBeChanged, boolean useClosedAndCancelled) throws Exception {
    log("Start: " + startDate + ", Test: " + dateWhenMeetingWillBeChanged);
    accountBO = createLoanAccount(customerMeeting, loanMeeting);
    savingsBO = createSavingsAccount(customerMeeting);
    // center initially set up with meeting today
    center = TestObjectFactory.getCenter(center.getCustomerId());
    accountBO = TestObjectFactory.getObject(LoanBO.class, accountBO.getAccountId());
    if (useClosedAndCancelled) {
        PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
        accountBO.changeStatus(AccountState.LOAN_CANCELLED, null, "", loggedInUser);
        savingsBO.changeStatus(AccountState.SAVINGS_CANCELLED.getValue(), null, "", loggedInUser);
        CustomerStatusEntity customerStatusEntity = new CustomerStatusEntity(CustomerStatus.GROUP_CLOSED);
        CustomerBOTestUtils.setCustomerStatus(group, customerStatusEntity);
        StaticHibernateUtil.flushSession();
    }
    new DateTimeService().setCurrentDateTime(dateWhenMeetingWillBeChanged.toDateTimeAtStartOfDay());
    CustomerService customerService = ApplicationContextProvider.getBean(CustomerService.class);
    newMeeting.updateDetails(TestUtils.makeUser());
    customerService.updateCustomerMeetingSchedule(newMeeting, center);
    TestObjectFactory.updateObject(center);
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    List<Holiday> holidays = new ArrayList<Holiday>();
    boolean isTopOfHierarchy = center.isTopOfHierarchy();
    center.getCustomerAccount().handleChangeInMeetingSchedule(workingDays, holidays, isTopOfHierarchy);
    accountBO.handleChangeInMeetingSchedule(workingDays, holidays, isTopOfHierarchy);
    savingsBO.handleChangeInMeetingSchedule(workingDays, holidays, isTopOfHierarchy);
    StaticHibernateUtil.flushSession();
}
Also used : CustomerService(org.mifos.customers.business.service.CustomerService) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Holiday(org.mifos.application.holiday.business.Holiday) LoanBO(org.mifos.accounts.loan.business.LoanBO) Days(org.joda.time.Days) ArrayList(java.util.ArrayList) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) DateTimeService(org.mifos.framework.util.DateTimeService) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules)

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