/** * populateSeedData * * This is a static function to create TimePeriods. * * @static * @return array Array of TimePeriods created */ public static function populateSeedData() { //Simulate settings to create 2 forward and 2 backward timeperiods $settings = array(); $settings['timeperiod_start_date'] = date("Y") . "-01-01"; $settings['timeperiod_interval'] = TimePeriod::ANNUAL_TYPE; $settings['timeperiod_leaf_interval'] = TimePeriod::QUARTER_TYPE; $settings['timeperiod_shown_backward'] = 2; $settings['timeperiod_shown_forward'] = 2; $timePeriod = TimePeriod::getByType(TimePeriod::ANNUAL_TYPE); $timePeriod->rebuildForecastingTimePeriods(array(), $settings); $ids = TimePeriod::get_not_fiscal_timeperiods_dom(); $timeperiods = array(); foreach ($ids as $id => $name) { $timeperiods[$id] = TimePeriod::getBean($id); } return $timeperiods; }
/** * Determines the end date to hold to the contract of this being a TimePeriod * * @param $startDate String of the TimePeriod start_date in db format */ public function determineEndDate($start_date) { $timedate = TimeDate::getInstance(); $startDate = $timedate->fromDbDate($start_date); $startDateDay = $startDate->format('j'); //Flag if the start date's day is the last day of the month if (!empty($this->parent_id)) { $parentTimePeriod = TimePeriod::getBean($this->parent_id); $parentStartDate = $timedate->fromDbDate($parentTimePeriod->start_date); $isStartDateDayLastDayOfMonth = $parentStartDate->format('j') == $parentStartDate->format('t'); } else { $isStartDateDayLastDayOfMonth = $startDateDay == $startDate->format('t'); } $endDate = $startDate->modify($this->next_date_modifier); $endDateDay = $endDate->format('j'); //Handle special cases where start date day is towards the last days of the month if ($startDateDay > 28 && $endDateDay < 4) { $endDate->modify("-{$endDateDay} day"); } else { if ($isStartDateDayLastDayOfMonth) { $endDate->setDate($endDate->format('Y'), $endDate->format('n'), $endDate->format('t')); } } $endDate->modify('-1 day'); return $endDate; }