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 = TTnew('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 (isset($raw_schedule_shifts) and 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 = TTnew('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 = TTnew('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) { $department_schedule_shift = Sort::multiSort($department_schedule_shift, 'last_name'); $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift; } } } } //Debug::Arr($this->schedule_shifts, 'Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10); $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; }
function scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format) { if (isset($column_widths['day'])) { $this->pdf->SetFont($this->config['other']['default_font'], 'B', $this->_pdf_fontSize(8)); if ($format != 'pdf_schedule' and $format != 'pdf_schedule_print') { $this->pdf->Cell($column_widths['label'], 4, TTi18n::getText('Employee'), 1, 0, 'C', 0, NULL, 1); } $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day); foreach ($calendar_header as $header_name) { $this->pdf->Cell($column_widths['day'], $this->_pdf_scaleSize(4), $header_name, 1, 0, 'C', 0, NULL, 1); } $this->pdf->SetFont($this->config['other']['default_font'], '', $this->_pdf_fontSize(8)); $this->pdf->Ln(); return TRUE; } return FALSE; }