use of org.mifos.schedule.internal.DailyScheduledEvent in project head by mifos.
the class AnyScheduledEventLoanInstallmentGenerator method generate.
@Override
public List<InstallmentDate> generate(LocalDate actualDisbursementDate, int numberOfInstallments, GraceType graceType, int gracePeriodDuration, Short officeId) {
List<InstallmentDate> installmentDates = new ArrayList<InstallmentDate>();
if (numberOfInstallments > 0) {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> holidays = new ArrayList<Holiday>();
LocalDate startFromMeetingDate = null;
if (scheduledEvent instanceof DailyScheduledEvent) {
startFromMeetingDate = actualDisbursementDate.plusDays(scheduledEvent.getEvery());
} else {
startFromMeetingDate = actualDisbursementDate.plusDays(1);
}
holidays = holidayDao.findAllHolidaysFromDateAndNext(officeId, startFromMeetingDate.toString());
int occurrences = numberOfInstallments;
if (graceType == GraceType.GRACEONALLREPAYMENTS) {
occurrences += gracePeriodDuration;
}
ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
List<Date> dueDates = new ArrayList<Date>();
List<DateTime> installmentDateTimes = dateGeneration.generateScheduledDates(occurrences, startFromMeetingDate.toDateMidnight().toDateTime(), scheduledEvent, false);
for (DateTime installmentDate : installmentDateTimes) {
dueDates.add(installmentDate.toDate());
}
installmentDates = createInstallmentDates(dueDates);
if (graceType == GraceType.GRACEONALLREPAYMENTS) {
removeInstallmentsNeedNotPay(gracePeriodDuration, installmentDates);
}
}
return installmentDates;
}
use of org.mifos.schedule.internal.DailyScheduledEvent 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);
}
Aggregations