Beispiel #1
0
 protected function _build_schedule_for_site($site_row)
 {
     $site_shift_rows = $this->site_shift_model->get_rows(array('site_id' => $site_row->id));
     $work_status_rows = $this->work_status_model->get_rows(array());
     $start_date = datetime_start_month();
     $end_date = datetime_add_days(60, $start_date);
     $current_date = $start_date;
     while ($current_date < $end_date) {
         $day_of_week_name = date('D', strtotime($current_date));
         $used_staff_ids = array();
         $relief_counts = array();
         foreach ($site_shift_rows as $site_shift_row) {
             $this->schedule_model->delete_where(array('start_date' => $current_date, 'site_id' => $site_row->id, 'shift_type' => $site_shift_row->shift_type));
             $staff_rows = $this->staff_assignment_model->get_staff_rows(array('site_id' => $site_row->id, 'shift_type' => $site_shift_row->shift_type, 'assign_type' => 'FullTime'));
             $relief_counts[$site_shift_row->shift_type] = 0;
             for ($count = 0; $count < $site_shift_row->staff_count; $count++) {
                 if (count($staff_rows) > 0) {
                     $staff_row = array_pop($staff_rows);
                     $work_status_row = $this->work_status_model->get_row_from_code('W' . strtoupper(substr($site_shift_row->shift_type, 0, 1)));
                     $off_day_names = explode(",", $staff_row->off_day_names);
                     if (in_array($day_of_week_name, $off_day_names)) {
                         $work_status_row = $this->work_status_model->get_row_from_code('O');
                         $relief_counts[$site_shift_row->shift_type]++;
                     } else {
                         if (rand(0, 100) > 80) {
                             $index = array_rand($work_status_rows, 1);
                             if ($index > 3) {
                                 $work_status_row = $work_status_rows[$index];
                                 $relief_counts[$site_shift_row->shift_type]++;
                             }
                         }
                     }
                     $used_staff_ids[] = $staff_row->staff_id;
                     $data = array('start_date' => $current_date, 'site_id' => $site_row->id, 'staff_id' => $staff_row->staff_id, 'shift_type' => $site_shift_row->shift_type, 'work_status_id' => $work_status_row->id);
                     $this->schedule_model->add_row($data);
                 }
             }
         }
         $work_status_row = $this->work_status_model->get_row_from_code('WD');
         foreach ($relief_counts as $shift_type => $relief_count) {
             if ($relief_count > 0) {
                 $staff_rows = $this->staff_assignment_model->get_staff_rows(array('site_id' => $site_row->id, 'assign_type' => 'Relief'));
                 $staff_indexes = array_rand($staff_rows, $relief_count);
                 if (is_numeric($staff_indexes)) {
                     $staff_indexes = array($staff_indexes);
                 }
                 foreach ($staff_indexes as $staff_index) {
                     $staff_row = $staff_rows[$staff_index];
                     $data = array('start_date' => $current_date, 'site_id' => $site_row->id, 'staff_id' => $staff_row->staff_id, 'shift_type' => $shift_type, 'work_status_id' => $work_status_row->id);
                     $this->schedule_model->add_row($data);
                 }
             }
         }
         $current_date = datetime_add_days(1, $current_date);
     }
 }
Beispiel #2
0
 public function index($row_pos = 0)
 {
     $this->_sort_order = $this->schedule_model->get_sort_order();
     $this->_filter = filter_load('filter', array('start_date' => datetime_start_month(), 'site_id_match' => ''));
     toolbar_process_task($this);
     $this->load->library('pagination');
     $row_pos = intval($row_pos);
     $row_count = $this->schedule_model->get_row_count($this->_filter);
     $config = array('total_rows' => $row_count, 'base_url' => site_url('admin/schedule/index'), 'cur_page' => $row_pos, 'per_page' => 100);
     $this->pagination->initialize($config);
     $rows = $this->schedule_model->get_rows($this->_filter, $this->_sort_order, $row_pos, $this->pagination->per_page);
     $data = array('rows' => $rows, 'site_list' => $this->site_model->get_dropdown_list('Select Site'), 'filter' => $this->_filter, 'sort_order' => $this->_sort_order, 'pagination_links' => $this->pagination->create_links());
     $this->load->view('admin/schedule_list', $data);
 }