public function index($assignment_id)
 {
     $this->load->model('miniant/diagnostic_tree_model');
     require_capability('servicequotes:writesqs');
     $technician_id = parent::get_technician_id($assignment_id);
     $is_technician = user_has_role($this->session->userdata('user_id'), 'Technician');
     $this->assignment = $this->assignment_model->get($assignment_id);
     if (empty($this->assignment)) {
         add_message('This job is no longer on record.', 'warning');
         redirect(base_url());
     }
     $order = (object) $this->order_model->get_values($this->assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'required_parts', 'param' => $this->assignment->id, 'module' => 'miniant'));
     if ($technician_id == $order->senior_technician_id) {
         $units = $this->assignment_model->get_units($assignment_id);
     } else {
         $units = $this->assignment_model->get_units($assignment_id, $technician_id);
     }
     $diagnostic_estimate_tree = $this->diagnostic_tree_model->get_estimate_tree($assignment_id);
     $estimated_time = $this->diagnostic_tree_model->get_estimate_time($diagnostic_estimate_tree);
     // We no longer ask the technician to estimate the labour, it is done entirely by the system based on diagnostic rules
     $this->diagnostic_model->edit($this->assignment->diagnostic_id, array('estimated_time' => $estimated_time));
     // Create SQ if none for this job/unit yet
     $sq = $this->servicequote_model->get(array('order_id' => $order->id, 'diagnostic_id' => $this->assignment->diagnostic_id), true);
     if (empty($sq->id)) {
         $sq_id = $this->servicequote_model->create_from_diagnostic($this->assignment->diagnostic_id);
     } else {
         $sq_id = $sq->id;
     }
     // Replace required_parts (loaded from step_parts table) with actual parts (from parts table)
     foreach ($units as $key => $unit) {
         $units[$key]->assignment = (object) $this->assignment_model->get_values($units[$key]->assignment_id);
         $units[$key]->diagnostic = (object) $this->diagnostic_model->get_values($units[$key]->assignment->diagnostic_id);
         // Only provide the SQ ID if this stage has been completed
         if ($this->assignment_model->has_statuses($units[$key]->assignment_id, array('REQUIRED PARTS RECORDED'))) {
             $units[$key]->required_parts = $this->diagnostic_model->get_required_parts($units[$key]->assignment->diagnostic_id, $sq_id);
         } else {
             $units[$key]->required_parts = $this->diagnostic_model->get_required_parts($units[$key]->assignment->diagnostic_id);
         }
         foreach ($units[$key]->required_parts as $part_key => $part) {
             form_element::$default_data["part_model_number[{$part->id}]"] = $part->part_number;
         }
     }
     $parts_title_options = array('title' => '', 'help' => 'Record the parts required this SQ', 'icons' => array());
     $info_title_options = array('title' => 'Unit info', 'help' => 'Information', 'icons' => array());
     $this->load_stage_view(array('units' => $units, 'parts_title_options' => $parts_title_options, 'info_title_options' => $info_title_options, 'diagnostic_id' => $this->assignment->diagnostic_id, 'is_technician' => $is_technician, 'sq_id' => $sq_id));
 }
 public function index($assignment_id)
 {
     $this->assignment = $this->assignment_model->get_values($assignment_id);
     if (empty($this->assignment)) {
         add_message('This job is no longer on record.', 'warning');
         redirect(base_url());
     }
     $order = (object) $this->order_model->get_values($this->assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'unit_serial', 'param' => $assignment_id, 'module' => 'miniant'));
     $technician_id = parent::get_technician_id($assignment_id);
     $is_technician = user_has_role($this->session->userdata('user_id'), 'Technician');
     parent::update_time($order->id);
     $order_technician = $this->order_technician_model->get(array('order_id' => $order->id, 'technician_id' => $technician_id), true);
     if ($is_technician) {
         trigger_event('start', 'order_technician', $order_technician->id, false, 'miniant');
     }
     $next_page_url = $this->workflow_manager->get_next_url();
     $order_technician = $this->order_technician_model->get(array('order_id' => $order->id, 'technician_id' => $technician_id), true);
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     $this->load_stage_view(array('units' => $units));
 }