Search in sources :

Example 11 with ScheduledEvent

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

the class AccountBO method getNextMeetingDate.

public Date getNextMeetingDate() {
    AccountActionDateEntity nextAccountAction = getDetailsOfNextInstallment();
    if (nextAccountAction != null) {
        return nextAccountAction.getActionDate();
    }
    // calculate the next date based on the customer's meeting object
    CustomerMeetingEntity customerMeeting = customer.getCustomerMeeting();
    if (customerMeeting != null) {
        ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customerMeeting.getMeeting());
        DateTime nextMeetingDate = scheduledEvent.nearestMatchingDateBeginningAt(new LocalDate().toDateTimeAtStartOfDay());
        return new java.sql.Date(nextMeetingDate.toDate().getTime());
    }
    return new java.sql.Date(DateUtils.getCurrentDateWithoutTimeStamp().getTime());
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) CustomerMeetingEntity(org.mifos.customers.business.CustomerMeetingEntity) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Example 12 with ScheduledEvent

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

the class AccountBO method getFeeDates.

public final List<Date> getFeeDates(final MeetingBO feeMeetingFrequency, final List<InstallmentDate> installmentDates, final boolean adjustForHolidays) {
    MeetingBO customerMeeting = getCustomer().getCustomerMeetingValue();
    List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
    HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
    List<Holiday> holidays;
    if (adjustForHolidays) {
        holidays = holidayDao.findAllHolidaysThisYearAndNext(getOffice().getOfficeId());
    } else {
        holidays = new ArrayList<Holiday>();
    }
    DateTime startFromMeetingDate = new DateTime(installmentDates.get(0).getInstallmentDueDate());
    DateTime repaymentEndDatetime = new DateTime(installmentDates.get(installmentDates.size() - 1).getInstallmentDueDate());
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customerMeeting, feeMeetingFrequency);
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
    List<DateTime> feeScheduleDates = dateGeneration.generateScheduledDatesThrough(startFromMeetingDate, repaymentEndDatetime, scheduledEvent, true);
    List<Date> feeSchedulesAsJavaDates = new ArrayList<Date>();
    for (DateTime feeSchedule : feeScheduleDates) {
        feeSchedulesAsJavaDates.add(feeSchedule.toDate());
    }
    return feeSchedulesAsJavaDates;
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) 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 13 with ScheduledEvent

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

the class MeetingBOIntegrationTest method verifyFirstDateForWeekForGivenStartDateAndWeekDay.

/**
     * Asserts that meeting.getFirstDateForWeek(startDate) returns a date matching the expected date.
     *
     * A dummy meeting is created with the given weekDay, and then the resulting date from
     * meeting.getFirstDateForWeek(startDate) is asserted to be the expected date
     *
     */
private void verifyFirstDateForWeekForGivenStartDateAndWeekDay(final WeekDay weekDay, final Date startDate, final Date expectedDate) throws MeetingException {
    // Assert getFirstDateForWeek works as expected for meeting with given
    // weekDay
    MeetingBO meeting = createWeeklyMeeting(weekDay, ONE, new Date());
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
    DateTime nearestDate = scheduledEvent.nearestMatchingDateBeginningAt(new DateTime(startDate));
    Assert.assertTrue(nearestDate.toDate().compareTo(expectedDate) == 0);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 14 with ScheduledEvent

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForTwoFeesBothAccountAndFeesAreScheduledEveryWeekShouldGetOneFeeInstallmentPerAccountEventPerFee.

/**********************************
     * Tests verify merging fees when two or more fees are attached to the account
     *
     * TODO: KRP: Remove the assumption of order that fee installments appear in the created list.
     **********************************/
@Test
public void createMergedFeeInstallmentsForTwoFeesBothAccountAndFeesAreScheduledEveryWeekShouldGetOneFeeInstallmentPerAccountEventPerFee() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(1).weeks().build();
    FeeBO feeBO1 = createWeeklyFeeBO(1);
    FeeBO feeBO2 = createWeeklyFeeBO(1);
    AccountFeesEntity accountFeesEntity1 = createAccountFeesEntity(feeBO1, 10.0);
    AccountFeesEntity accountFeesEntity2 = createAccountFeesEntity(feeBO2, 13.0);
    List<AccountFeesEntity> accountFees = Arrays.asList(new AccountFeesEntity[] { accountFeesEntity1, accountFeesEntity2 });
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallments(masterEvent, accountFees, 3);
    assertThat(feeInstallments.size(), is(6));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(1), 2, 10.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(2), 3, 10.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(3), 1, 13.0, feeBO2);
    assertFeeInstallment(feeInstallments.get(4), 2, 13.0, feeBO2);
    assertFeeInstallment(feeInstallments.get(5), 3, 13.0, feeBO2);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 15 with ScheduledEvent

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEveryOtherWeekFeeScheduledEveryWeekt.

@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEveryOtherWeekFeeScheduledEveryWeekt() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(2).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(1);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(masterEvent, accountFeesEntity, 4);
    assertThat(feeInstallments.size(), is(4));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 2, 20.0, feeBO);
    assertFeeInstallment(feeInstallments.get(2), 3, 20.0, feeBO);
    assertFeeInstallment(feeInstallments.get(3), 4, 20.0, feeBO);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Aggregations

ScheduledEvent (org.mifos.schedule.ScheduledEvent)38 DateTime (org.joda.time.DateTime)23 LocalDate (org.joda.time.LocalDate)16 ArrayList (java.util.ArrayList)14 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)13 Test (org.junit.Test)12 FeeInstallment (org.mifos.accounts.util.helpers.FeeInstallment)12 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)12 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)12 Date (java.util.Date)11 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)11 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)10 FeeBO (org.mifos.accounts.fees.business.FeeBO)9 ScheduledEventBuilder (org.mifos.domain.builders.ScheduledEventBuilder)9 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)7 InterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent)6 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)5 Days (org.joda.time.Days)4 Holiday (org.mifos.application.holiday.business.Holiday)4