Search in sources :

Example 31 with ScheduledEvent

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeBothAccountAndFeeAreScheduledEveryWeekShouldGetOneFeeInstallmentPerAccountEvent.

@Test
public void createMergedFeeInstallmentsForOneFeeBothAccountAndFeeAreScheduledEveryWeekShouldGetOneFeeInstallmentPerAccountEvent() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(1).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(1);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(masterEvent, accountFeesEntity, 3);
    assertThat(feeInstallments.size(), is(3));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 2, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(2), 3, 10.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)

Example 32 with ScheduledEvent

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

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEveryWeekFeeScheduledEveryOtherWeekShouldGetOneFeeInstallmentPerEveryOtherAccountEvent.

@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEveryWeekFeeScheduledEveryOtherWeekShouldGetOneFeeInstallmentPerEveryOtherAccountEvent() {
    ScheduledEvent accountEvent = new ScheduledEventBuilder().every(1).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(2);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(accountEvent, accountFeesEntity, 4);
    assertThat(feeInstallments.size(), is(2));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 3, 10.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)

Example 33 with ScheduledEvent

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

the class LoanBO method regenerateFutureInstallments.

/**
     * regenerate installments starting from nextInstallmentId
     */
@Override
protected void regenerateFutureInstallments(final AccountActionDateEntity nextInstallment, final List<Days> workingDays, final List<Holiday> holidays) throws AccountException {
    int numberOfInstallmentsToGenerate = getLastInstallmentId();
    MeetingBO meeting = buildLoanMeeting(customer.getCustomerMeeting().getMeeting(), getLoanMeeting(), getLoanMeeting().getMeetingStartDate());
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
    LocalDate currentDate = new LocalDate();
    LocalDate thisIntervalStartDate = meeting.startDateForMeetingInterval(currentDate);
    LocalDate nextMatchingDate = new LocalDate(scheduledEvent.nextEventDateAfter(thisIntervalStartDate.toDateTimeAtStartOfDay()));
    DateTime futureIntervalStartDate = meeting.startDateForMeetingInterval(nextMatchingDate).toDateTimeAtStartOfDay();
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
    List<DateTime> meetingDates = dateGeneration.generateScheduledDates(numberOfInstallmentsToGenerate, futureIntervalStartDate, scheduledEvent, false);
    updateSchedule(nextInstallment.getInstallmentId(), meetingDates);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 34 with ScheduledEvent

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

the class CustomerAccountBO method createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer.

/**
     * Create an initial meeting schedule with fees attached, if any.
     *
     * <p>PostConditions:</p>
     *
     * <ul>
     * <li> <code>numberOfMeetingDatesToGenerateOnCreation</code> {@link CustomerScheduleEntity}s are created
     *      starting with <code>customerMeeting</code>'s start date, scheduled according to <code>customerMeeting</code>'s
     *      frequency and recurrence, and subject to rules for scheduling around on working days and around holidays. See
     *      {@link HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration} for scheduling rules.</li>
     * <li> One-time upfront fees are attached to the first meeting.</li>
     * <li> Periodic fees are attached to the first meeting and subsequent meetings that match the fee's frequency
     *      and recurrence</li>
     * <li> The <code>lastAppliedDate</code> for each fee is set to the date of the latest meeting to which the fee
     *      is attached
     * </ul>
     */
public void createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(CustomerBO customer, List<AccountFeesEntity> accountFees, MeetingBO customerMeeting, CalendarEvent applicableCalendarEvents, DateTime scheduleGenerationStartingFrom) {
    final ScheduledEvent customerMeetingEvent = new RecurringScheduledEventFactoryImpl().createScheduledEventFrom(customerMeeting);
    DateTime beginningFrom = scheduleGenerationStartingFrom;
    // synch up generated schedule for center/group/client or group/client hierarchy
    CustomerBO upmostParent = upmostParentOf(customer);
    if (upmostParent != null) {
        LocalDate parentCustomerActiviationDate = new LocalDate(upmostParent.getCustomerActivationDate());
        LocalDate childCustomerActiviationDate = new LocalDate(customer.getCustomerActivationDate());
        LocalDate validCustomerMeetingMatch = null;
        if (customerMeetingEvent instanceof DailyScheduledEvent) {
            validCustomerMeetingMatch = new LocalDate(parentCustomerActiviationDate.toDateMidnight().toDateTime());
        } else {
            validCustomerMeetingMatch = new LocalDate(customerMeetingEvent.nearestMatchNotTakingIntoAccountScheduleFrequency(parentCustomerActiviationDate.toDateMidnight().toDateTime()));
        }
        while (childCustomerActiviationDate.isAfter(validCustomerMeetingMatch)) {
            validCustomerMeetingMatch = new LocalDate(customerMeetingEvent.rollFrowardDateByFrequency(validCustomerMeetingMatch.toDateMidnight().toDateTime()));
        }
        beginningFrom = validCustomerMeetingMatch.toDateMidnight().toDateTime();
    }
    DateTime meetingStartDate = new DateTime(customer.getCustomerMeetingValue().getMeetingStartDate());
    if (beginningFrom.isBefore(meetingStartDate)) {
        beginningFrom = meetingStartDate;
    }
    createInitialSetOfCustomerScheduleEntities(customer, beginningFrom, applicableCalendarEvents, customerMeetingEvent);
    applyFeesToInitialSetOfInstallments(new ArrayList<AccountFeesEntity>(accountFees), customerMeetingEvent);
}
Also used : DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) RecurringScheduledEventFactoryImpl(org.mifos.clientportfolio.newloan.domain.RecurringScheduledEventFactoryImpl) DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 35 with ScheduledEvent

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

the class CustomerAccountBO method applyPeriodicFee.

/*
     * Package-level visibility for testing
     */
void applyPeriodicFee(final FeeBO fee, final Money charge, final List<AccountActionDateEntity> dueInstallments) throws AccountException {
    AccountFeesEntity accountFee = getAccountFee(fee, charge.getAmountDoubleValue());
    accountFee.setAccountFeeAmount(charge);
    List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
    for (AccountActionDateEntity accountActionDateEntity : dueInstallments) {
        installmentDates.add(new InstallmentDate(accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate()));
    }
    //        List<FeeInstallment> feeInstallmentList = mergeFeeInstallments(handlePeriodic(accountFee, installmentDates));
    ScheduledEvent loanScheduledEvent = ScheduledEventFactory.createScheduledEventFrom(this.getMeetingForAccount());
    List<FeeInstallment> feeInstallmentList = FeeInstallment.createMergedFeeInstallmentsForOneFeeStartingWith(loanScheduledEvent, accountFee, dueInstallments.size(), dueInstallments.get(0).getInstallmentId());
    // MIFOS-3701: we want to display only fee charge, not the totalFeeAmountApplied
    applyFeeToInstallments(feeInstallmentList, dueInstallments);
    updateCustomerActivity(fee.getFeeId(), charge, fee.getFeeName() + AccountConstants.APPLIED);
    accountFee.setFeeStatus(FeeStatus.ACTIVE);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) DailyScheduledEvent(org.mifos.schedule.internal.DailyScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate)

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