use of org.mifos.schedule.ScheduledDateGeneration in project head by mifos.
the class SavingsBO method generateAccountActivationDetails.
public static SavingsAccountActivationDetail generateAccountActivationDetails(CustomerBO customer, SavingsOfferingBO savingsProduct, Money recommendedOrMandatoryAmount, AccountState savingsAccountState, CalendarEvent calendarEvents, LocalDate activationDate) {
List<AccountActionDateEntity> scheduledPayments = new ArrayList<AccountActionDateEntity>();
LocalDate nextInterestPostingDate = new LocalDate();
if (savingsAccountState.isActiveSavingsAccountState()) {
ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
List<DateTime> depositDates = dateGeneration.generateScheduledDates(10, activationDate.toDateTimeAtStartOfDay(), scheduledEvent, false);
short installmentNumber = 0;
for (DateTime date : depositDates) {
java.sql.Date depositDueDate = new java.sql.Date(date.toDate().getTime());
AccountActionDateEntity scheduledSavingsDeposit = new SavingsScheduleEntity(customer, installmentNumber++, depositDueDate, PaymentStatus.UNPAID, recommendedOrMandatoryAmount, savingsProduct.getCurrency());
scheduledPayments.add(scheduledSavingsDeposit);
}
InterestScheduledEvent interestPostingEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(savingsProduct.getFreqOfPostIntcalc().getMeeting());
nextInterestPostingDate = interestPostingEvent.nextMatchingDateAfter(new LocalDate(startOfFiscalYear()), activationDate);
}
return new SavingsAccountActivationDetail(activationDate, nextInterestPostingDate, scheduledPayments);
}
use of org.mifos.schedule.ScheduledDateGeneration in project head by mifos.
the class SavingsBO method regenerateFutureInstallments.
@Override
protected void regenerateFutureInstallments(final AccountActionDateEntity nextInstallment, final List<Days> workingDays, final List<Holiday> holidays) throws AccountException {
MeetingBO customerMeeting = getCustomer().getCustomerMeetingValue();
ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customerMeeting);
LocalDate currentDate = new LocalDate();
LocalDate thisIntervalStartDate = customerMeeting.startDateForMeetingInterval(currentDate);
LocalDate nextMatchingDate = new LocalDate(scheduledEvent.nextEventDateAfter(thisIntervalStartDate.toDateTimeAtStartOfDay()));
DateTime futureIntervalStartDate = customerMeeting.startDateForMeetingInterval(nextMatchingDate).toDateTimeAtStartOfDay();
ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
int numberOfInstallmentsToGenerate = getLastInstallmentId();
List<DateTime> meetingDates = dateGeneration.generateScheduledDates(numberOfInstallmentsToGenerate, futureIntervalStartDate, scheduledEvent, false);
if (getCustomer().getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || getCustomer().getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
updateSchedule(nextInstallment.getInstallmentId(), meetingDates);
} else {
List<CustomerBO> children;
try {
children = getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.OTHER_THAN_CLOSED);
} catch (CustomerException ce) {
throw new AccountException(ce);
}
updateSavingsSchedule(nextInstallment.getInstallmentId(), meetingDates, children);
}
}
use of org.mifos.schedule.ScheduledDateGeneration in project head by mifos.
the class TestObjectFactory method getMeetingDatesThroughTo.
public static List<Date> getMeetingDatesThroughTo(short officeId, final MeetingBO meeting, Date endDate) {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> upcomingHolidays = ApplicationContextProvider.getBean(HolidayDao.class).findAllHolidaysThisYearAndNext(officeId);
ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
DateTime meetingStartDate = new DateTime(meeting.getMeetingStartDate());
DateTime endDateTime = new DateTime(endDate);
ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, upcomingHolidays);
List<DateTime> allDates = dateGeneration.generateScheduledDatesThrough(meetingStartDate, endDateTime, scheduledEvent, false);
List<Date> dates = new ArrayList<Date>();
for (DateTime dateTime : allDates) {
dates.add(dateTime.toDate());
}
return dates;
}
use of org.mifos.schedule.ScheduledDateGeneration in project head by mifos.
the class TestObjectFactory method getMeetingDates.
public static List<Date> getMeetingDates(short officeId, final MeetingBO meeting, final int occurrences) {
List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
List<Holiday> upcomingHolidays = ApplicationContextProvider.getBean(HolidayDao.class).findAllHolidaysThisYearAndNext(officeId);
ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting);
DateTime meetingStartDate = new DateTime(meeting.getMeetingStartDate());
ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, upcomingHolidays);
List<DateTime> allDates = dateGeneration.generateScheduledDates(occurrences, meetingStartDate, scheduledEvent, false);
List<Date> dates = new ArrayList<Date>();
for (DateTime dateTime : allDates) {
dates.add(dateTime.toDate());
}
return dates;
}
use of org.mifos.schedule.ScheduledDateGeneration 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;
}
Aggregations