function getSchedule($filter_data, $start_week_day = 0, $group_schedule = FALSE) { global $current_user, $current_user_prefs; //Individual is one schedule per employee, or all on one schedule. if (!is_array($filter_data)) { return FALSE; } $current_epoch = time(); //Debug::Text('Start Date: '. TTDate::getDate('DATE', $start_date) .' End Date: '. TTDate::getDate('DATE', $end_date) , __FILE__, __LINE__, __METHOD__,10); Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $filter_data['start_date']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $filter_data['end_date']) . ' Start Week Day: ' . $start_week_day, __FILE__, __LINE__, __METHOD__, 10); $pdf = new TTPDF('L', 'pt', 'Letter'); $left_margin = 20; $top_margin = 20; $pdf->setMargins($left_margin, $top_margin); $pdf->SetAutoPageBreak(TRUE, 30); //$pdf->SetAutoPageBreak(FALSE); $pdf->SetFont('freesans', '', 10); $border = 0; $adjust_x = 0; $adjust_y = 0; if ($group_schedule == FALSE) { $valid_schedules = 0; $sf = new ScheduleFactory(); $tmp_schedule_shifts = $sf->getScheduleArray($filter_data); //Re-arrange array by user_id->date if (is_array($tmp_schedule_shifts)) { foreach ($tmp_schedule_shifts as $day_epoch => $day_schedule_shifts) { foreach ($day_schedule_shifts as $day_schedule_shift) { $raw_schedule_shifts[$day_schedule_shift['user_id']][$day_epoch][] = $day_schedule_shift; } } } unset($tmp_schedule_shifts); //Debug::Arr($raw_schedule_shifts, 'Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10); if (is_array($raw_schedule_shifts)) { foreach ($raw_schedule_shifts as $user_id => $day_schedule_shifts) { foreach ($day_schedule_shifts as $day_epoch => $day_schedule_shifts) { foreach ($day_schedule_shifts as $day_schedule_shift) { //Debug::Arr($day_schedule_shift, 'aDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10); $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift; if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) { $schedule_shift_totals[$day_epoch]['total_shifts']++; } else { $schedule_shift_totals[$day_epoch]['total_shifts'] = 1; } //$week_of_year = TTDate::getWeek( strtotime($day_epoch) ); $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day); if (!isset($schedule_shift_totals[$day_epoch]['labels'])) { $schedule_shift_totals[$day_epoch]['labels'] = 0; } if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) { $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE; $schedule_shift_totals[$day_epoch]['labels']++; } if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) { $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE; $schedule_shift_totals[$day_epoch]['labels']++; } if (!isset($max_week_data[$week_of_year]['shift'])) { Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10); $max_week_data[$week_of_year]['shift'] = 1; $max_week_data[$week_of_year]['labels'] = 0; } if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) { Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10); $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts']; $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels']; } //Debug::Arr($schedule_shift_totals, ' Schedule Shift Totals: ', __FILE__, __LINE__, __METHOD__,10); //Debug::Arr($max_week_data, ' zMaxWeekData: ', __FILE__, __LINE__, __METHOD__,10); } } if (isset($tmp_schedule_shifts)) { //Sort Branches/Departments first foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) { ksort($day_tmp_schedule_shift); $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift; foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) { ksort($tmp_schedule_shifts[$day_epoch][$branch]); } } //Sort each department by start time. foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) { foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) { foreach ($department_schedule_shifts as $department => $department_schedule_shift) { $department_schedule_shift = Sort::multiSort($department_schedule_shift, 'start_time'); $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift; } } } } unset($day_tmp_schedule_shift, $department_schedule_shifts, $department_schedule_shift, $tmp_schedule_shifts, $branch, $department); $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day); //var_dump($calendar_array); if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) { continue; //Skip to next user. } $ulf = new UserListFactory(); $ulf->getByIdAndCompanyId($user_id, $current_user->getCompany()); if ($ulf->getRecordCount() != 1) { continue; } else { $user_obj = $ulf->getCurrent(); $pdf->AddPage(); $pdf->setXY(670, $top_margin); $pdf->SetFont('freesans', '', 10); $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R'); $pdf->setXY($left_margin, $top_margin); $pdf->SetFont('freesans', 'B', 25); $pdf->Cell(0, 25, $user_obj->getFullName() . ' - ' . TTi18n::getText('Schedule'), $border, 0, 'C'); $pdf->Ln(); } $pdf->SetFont('freesans', 'B', 16); $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C'); //$pdf->Ln(); $pdf->Ln(); $pdf->Ln(); $pdf->SetFont('freesans', '', 8); $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7); $cell_height = 100; $i = 0; $total_days = count($calendar_array) - 1; $boader = 1; foreach ($calendar_array as $calendar) { if ($i == 0) { //Calendar Header $pdf->SetFont('freesans', 'B', 8); $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day); foreach ($calendar_header as $header_name) { $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C'); } $pdf->Ln(); unset($calendar_header, $header_name); } $month_name = NULL; if ($i == 0 or $calendar['isNewMonth'] == TRUE) { $month_name = $calendar['month_name']; } if ($i > 0 and $i % 7 == 0) { $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day); unset($week_date_stamps); } $pdf->SetFont('freesans', 'B', 8); $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L'); $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R'); $week_date_stamps[] = $calendar['date_stamp']; $i++; } $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE); $valid_schedules++; unset($this->schedule_shifts, $calendar_array, $week_date_stamps, $max_week_data, $day_epoch, $day_schedule_shifts, $day_schedule_shift, $schedule_shift_totals); } } unset($raw_schedule_shifts); } else { $valid_schedules = 1; $sf = new ScheduleFactory(); $raw_schedule_shifts = $sf->getScheduleArray($filter_data); if (is_array($raw_schedule_shifts)) { foreach ($raw_schedule_shifts as $day_epoch => $day_schedule_shifts) { foreach ($day_schedule_shifts as $day_schedule_shift) { //Debug::Arr($day_schedule_shift, 'bDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10); $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift; if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) { $schedule_shift_totals[$day_epoch]['total_shifts']++; } else { $schedule_shift_totals[$day_epoch]['total_shifts'] = 1; } //$week_of_year = TTDate::getWeek( strtotime($day_epoch) ); $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day); Debug::text(' Date: ' . TTDate::getDate('DATE', strtotime($day_epoch)) . ' Week: ' . $week_of_year . ' TMP: ' . TTDate::getWeek(strtotime('20070721'), $start_week_day), __FILE__, __LINE__, __METHOD__, 10); if (!isset($schedule_shift_totals[$day_epoch]['labels'])) { $schedule_shift_totals[$day_epoch]['labels'] = 0; } if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) { $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE; $schedule_shift_totals[$day_epoch]['labels']++; } if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) { $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE; $schedule_shift_totals[$day_epoch]['labels']++; } if (!isset($max_week_data[$week_of_year]['shift'])) { Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10); $max_week_data[$week_of_year]['shift'] = 1; $max_week_data[$week_of_year]['labels'] = 0; } if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) { Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10); $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts']; $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels']; } } } } //print_r($tmp_schedule_shifts); //print_r($max_week_data); if (isset($tmp_schedule_shifts)) { //Sort Branches/Departments first foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) { ksort($day_tmp_schedule_shift); $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift; foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) { ksort($tmp_schedule_shifts[$day_epoch][$branch]); } } //Sort each department by start time. foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) { foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) { foreach ($department_schedule_shifts as $department => $department_schedule_shift) { $sort = new arr_multisort(); $sort->setArray($department_schedule_shift); $sort->addColumn('start_time', 1); $department_schedule_shift = $sort->Sort(); unset($sort); $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift; } } } } //print_r($this->schedule_shifts); $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day); //var_dump($calendar_array); if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) { return FALSE; } $pdf->AddPage(); $pdf->setXY(670, $top_margin); $pdf->SetFont('freesans', '', 10); $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R'); $pdf->setXY($left_margin, $top_margin); $pdf->SetFont('freesans', 'B', 25); $pdf->Cell(0, 25, 'Employee Schedule', $border, 0, 'C'); $pdf->Ln(); $pdf->SetFont('freesans', 'B', 10); $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C'); $pdf->Ln(); $pdf->Ln(); $pdf->SetFont('freesans', '', 8); $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7); $cell_height = 100; $i = 0; $total_days = count($calendar_array) - 1; $boader = 1; foreach ($calendar_array as $calendar) { if ($i == 0) { //Calendar Header $pdf->SetFont('freesans', 'B', 8); $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day); foreach ($calendar_header as $header_name) { $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C'); } $pdf->Ln(); unset($calendar_header, $header_name); } $month_name = NULL; if ($i == 0 or $calendar['isNewMonth'] == TRUE) { $month_name = $calendar['month_name']; } if ($i > 0 and $i % 7 == 0) { $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day); unset($week_date_stamps); } $pdf->SetFont('freesans', 'B', 8); $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L'); $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R'); $week_date_stamps[] = $calendar['date_stamp']; $i++; } $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE); } if ($valid_schedules > 0) { $output = $pdf->Output('', 'S'); return $output; } return FALSE; }
case 'view_schedule': default: $user_ids = array(); if ($filter_data['start_date'] != '' and $filter_data['show_days'] != '') { $start_date = $filter_data['start_date'] = TTDate::getBeginDayEpoch(TTDate::parseDateTime($filter_data['start_date'])); $end_date = $filter_data['end_date'] = TTDate::getEndDayEpoch($start_date + $filter_data['show_days'] * (86400 - 3601)); } else { $start_date = $filter_data['start_date'] = TTDate::getBeginWeekEpoch(TTDate::getTime(), $current_user_prefs->getStartWeekDay()); $end_date = $filter_data['end_date'] = TTDate::getEndDayEpoch($start_date + $filter_data['show_days'] * (86400 - 3601)); } Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); $i = 0; $min_hour = 0; $max_hour = 0; $sf = new ScheduleFactory(); $raw_schedule_shifts = $sf->getScheduleArray($filter_data); if (is_array($raw_schedule_shifts)) { foreach ($raw_schedule_shifts as $day_epoch => $day_schedule_shifts) { foreach ($day_schedule_shifts as $day_schedule_shift) { //$day_schedule_shift['is_owner'] = $permission->isOwner( $u_obj->getCreatedBy(), $u_obj->getId() ); //$day_schedule_shift['is_child'] = $permission->isChild( $u_obj->getId(), $permission_children_ids ); $day_schedule_shift['is_owner'] = $permission->isOwner($day_schedule_shift['user_created_by'], $day_schedule_shift['user_id']); $day_schedule_shift['is_child'] = $permission->isChild($day_schedule_shift['user_id'], $permission_children_ids); $day_schedule_shift['span_day'] = FALSE; $day_schedule_shift['span_day_split'] = TRUE; //var_dump($day_schedule_shift); $tmp_start_hour = TTDate::getHour($day_schedule_shift['start_time']); $tmp_end_hour = TTDate::getHour($day_schedule_shift['end_time']); if ($tmp_end_hour < $tmp_start_hour) { $tmp_end_hour = 24; }
$user_id = $filter_user_id; } else { $user_id = $current_user->getId(); } } else { $user_id = $current_user->getId(); } if ($filter_start_date == '' or $filter_end_date == '') { $start_date = $filter_start_date = TTDate::getBeginWeekEpoch(TTDate::getTime() - 86400, $current_user_prefs->getStartWeekDay()); $end_date = $filter_end_date = TTDate::getEndWeekEpoch(TTDate::getTime() + 86400 * 28, $current_user_prefs->getStartWeekDay()); } //$start_date = $filter_start_date = TTDate::getBeginWeekEpoch( $start_date, 'mon'); //$end_date = $filter_end_date = TTDate::getEndWeekEpoch( $end_date, 'mon' ); Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10); $sf = new ScheduleFactory(); $default_schedule_shifts = $sf->getScheduleArray($user_id, $start_date, $end_date); //var_dump($default_schedule_shifts); $calendar_array = TTDate::getCalendarArray($start_date, $end_date, $current_user_prefs->getStartWeekDay()); $smarty->assign_by_ref('calendar_array', $calendar_array); //$smarty->assign_by_ref('pay_period_locked_rows', $pay_period_locked_rows); $ulf = new UserListFactory(); $user_obj = $ulf->getById($user_id)->getCurrent(); /* $holiday = new Holiday(); $holiday->GetByCountryAndProvince($user_obj->getCountry(), $user_obj->getProvince() ); */ $hlf = new HolidayListFactory(); $holiday_array = $hlf->getArrayByPolicyGroupUserId($user_id, $start_date, $end_date); //var_dump($holiday_array); $smarty->assign_by_ref('holidays', $holiday_array); $smarty->assign_by_ref('filter_start_date', $filter_start_date);