Search in sources :

Example 21 with FiscalCalendarRules

use of org.mifos.config.FiscalCalendarRules in project head by mifos.

the class MifosIntegrationTestCase method enableCustomWorkingDays.

/**
     * see MIFOS-2659 <br><br>
     * This will be disabled automatically at the end of a test case
     *
     */
protected static void enableCustomWorkingDays() {
    savedFiscalCalendarRulesWorkingDays = new FiscalCalendarRules().getWorkingDaysAsString();
    new FiscalCalendarRules().setWorkingDays("MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY");
}
Also used : FiscalCalendarRules(org.mifos.config.FiscalCalendarRules)

Example 22 with FiscalCalendarRules

use of org.mifos.config.FiscalCalendarRules in project head by mifos.

the class SavingsBOIntegrationTest method testGenerateMeetingForNextYear.

@Test
public void testGenerateMeetingForNextYear() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("center1", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    SavingsTestHelper SavingsTestHelper = new SavingsTestHelper();
    SavingsOfferingBO savingsOfferingBO = SavingsTestHelper.createSavingsOffering("dfasdasd1", "sad1");
    savingsOfferingBO.setRecommendedAmntUnit(RecommendedAmountUnit.COMPLETE_GROUP);
    SavingsBO savingsBO = SavingsTestHelper.createSavingsAccount(savingsOfferingBO, group, AccountState.SAVINGS_ACTIVE, TestUtils.makeUser());
    Short LastInstallmentId = savingsBO.getLastInstallmentId();
    AccountActionDateEntity lastYearLastInstallment = savingsBO.getAccountActionDate(LastInstallmentId);
    Integer installmetId = lastYearLastInstallment.getInstallmentId().intValue() + (short) 1;
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    List<Holiday> holidays = new ArrayList<Holiday>();
    savingsBO.generateNextSetOfMeetingDates(workingDays, holidays);
    TestObjectFactory.updateObject(savingsBO);
    TestObjectFactory.updateObject(center);
    TestObjectFactory.updateObject(group);
    TestObjectFactory.updateObject(savingsBO);
    center = (CustomerBO) StaticHibernateUtil.getSessionTL().get(CustomerBO.class, center.getCustomerId());
    group = (CustomerBO) StaticHibernateUtil.getSessionTL().get(CustomerBO.class, group.getCustomerId());
    savingsBO = (SavingsBO) StaticHibernateUtil.getSessionTL().get(SavingsBO.class, savingsBO.getAccountId());
    MeetingBO meetingBO = center.getCustomerMeeting().getMeeting();
    meetingBO.setMeetingStartDate(lastYearLastInstallment.getActionDate());
    List<Date> meetingDates = TestObjectFactory.getMeetingDates(group.getOfficeId(), meetingBO, 10);
    meetingDates.remove(0);
    Date FirstSavingInstallmetDate = savingsBO.getAccountActionDate(installmetId.shortValue()).getActionDate();
    Calendar calendar2 = Calendar.getInstance();
    calendar2.setTime(meetingDates.get(0));
    Calendar calendar3 = Calendar.getInstance();
    calendar3.setTime(FirstSavingInstallmetDate);
    Assert.assertEquals(0, new GregorianCalendar(calendar3.get(Calendar.YEAR), calendar3.get(Calendar.MONTH), calendar3.get(Calendar.DATE), 0, 0, 0).compareTo(new GregorianCalendar(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DATE), 0, 0, 0)));
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Date(java.util.Date) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) SavingsTestHelper(org.mifos.accounts.savings.util.helpers.SavingsTestHelper) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) Test(org.junit.Test)

Example 23 with FiscalCalendarRules

use of org.mifos.config.FiscalCalendarRules in project head by mifos.

the class IndependentOfCustomerMeetingScheduleLoanInstallmentGenerator method getInstallmentDates.

private final List<InstallmentDate> getInstallmentDates(final ScheduledEvent scheduledEvent, LocalDate meetingStartDate, final int noOfInstallments, final int installmentToSkip, Short officeId) {
    List<InstallmentDate> dueInstallmentDates = new ArrayList<InstallmentDate>();
    if (noOfInstallments > 0) {
        List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
        List<Holiday> holidays = new ArrayList<Holiday>();
        DateTime startFromMeetingDate = meetingStartDate.toDateMidnight().toDateTime();
        holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toLocalDate().toString());
        final int occurrences = noOfInstallments + installmentToSkip;
        ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
        List<Date> dueDates = new ArrayList<Date>();
        DateTime startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate;
        // 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 : ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) 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)

Aggregations

FiscalCalendarRules (org.mifos.config.FiscalCalendarRules)23 ArrayList (java.util.ArrayList)14 Holiday (org.mifos.application.holiday.business.Holiday)13 Days (org.joda.time.Days)12 LocalDate (org.joda.time.LocalDate)8 Date (java.util.Date)7 DateTime (org.joda.time.DateTime)7 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)7 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)7 MessageLookup (org.mifos.application.master.MessageLookup)5 WeekDay (org.mifos.application.meeting.util.helpers.WeekDay)5 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)4 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)4 ScheduledEvent (org.mifos.schedule.ScheduledEvent)4 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1