public function index($assignment_id)
 {
     $this->assignment = (object) $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);
     $technician_id = $this->session->userdata('user_id');
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => 'repair', 'stage' => 'repair_checklist', 'param' => $assignment_id, 'module' => 'miniant'));
     $unit = (object) $this->unit_model->get_values($this->assignment->unit_id);
     $tasks = $this->repair_task_model->get(array('assignment_id' => $assignment_id));
     $is_required_set = $this->assignment->diagnostic_required === '0' || $this->assignment->diagnostic_required === '1';
     $is_authorised_set = $this->assignment->diagnostic_required === '0' || ($this->assignment->diagnostic_authorised === '0' || $this->assignment->diagnostic_authorised === '1');
     $this->load->library('Dialog');
     $this->dialog->initialise(array('id' => 'dialog'));
     $this->dialog->add_question(array('id' => 'repairs_completed', 'shown' => !$this->order_model->has_statuses($order->id, array('REPAIR TASKS COMPLETED')), 'text' => 'Have you completed all needed repairs on this unit?', 'answers' => array(array('text' => 'Yes', 'ids_to_show' => array('diagnostic_required'), 'ajax_callback' => 'miniant/stages/repair_checklist/set_diagnostic_not_required/' . $this->assignment->id, 'triggers' => array(array('system' => 'order', 'document_id' => $this->assignment->order_id, 'event_name' => 'repair_tasks_completed', 'module' => 'miniant'))))));
     $this->dialog->add_question(array('id' => 'diagnostic_required', 'shown' => !$is_required_set && $this->order_model->has_statuses($order->id, array('REPAIR TASKS COMPLETED')), 'text' => 'Is this unit now functioning properly?', 'answers' => array(array('text' => 'Yes', 'ids_to_show' => array('continue'), 'ajax_callback' => 'miniant/stages/repair_checklist/set_diagnostic_not_required/' . $this->assignment->id), array('text' => 'No', 'ids_to_show' => array('diagnostic_authorised'), 'ajax_callback' => 'miniant/stages/repair_checklist/set_diagnostic_required/' . $this->assignment->id))));
     $this->dialog->add_question(array('id' => 'diagnostic_authorised', 'shown' => $this->order_model->has_statuses($order->id, array('REPAIR TASKS COMPLETED')) && !$is_authorised_set && $this->assignment->diagnostic_required === '1', 'text' => 'Have you been authorised to perform a diagnostic on this unit?', 'answers' => array(array('text' => 'Yes', 'ids_to_show' => array('continue'), 'ajax_callback' => 'miniant/stages/repair_checklist/set_diagnostic_authorised/' . $this->assignment->id), array('text' => 'No', 'ids_to_show' => array('continue'), 'ajax_callback' => 'miniant/stages/repair_checklist/set_diagnostic_not_authorised/' . $this->assignment->id))));
     $this->dialog->add_question(array('id' => 'continue', 'shown' => $this->order_model->has_statuses($order->id, array('REPAIR TASKS COMPLETED')) && $is_required_set && $is_authorised_set, 'text' => ' ', 'answers' => array(array('text' => 'Continue', 'url' => 'miniant/stages/repair_checklist/process/' . $this->assignment->id))));
     $dialog = $this->dialog->output();
     $this->load_stage_view(array('tasks' => $tasks, 'unit' => $unit, 'dialog' => $dialog, 'title' => 'Repair checklist: Unit ' . $unit->id, 'is_senior_technician' => $technician_id == $order->senior_technician_id));
 }
Beispiel #2
0
 public function index($assignment_id, $type = null)
 {
     $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());
     }
     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);
     // Determine if this is pre-job or post-job depending on order statuses
     // This should only be used in last resort, use the extra_param field of the workflow_stages table when possible
     if (is_null($type)) {
         $type = $this->order_model->has_statuses($order->id, array('POST-JOB COMPLETE', 'PRE-JOB SITE PHOTOS UPLOADED'), 'AND') ? 'post-job' : 'pre-job';
     }
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'photos', 'param' => $assignment_id, 'extra_param' => $type, 'module' => 'miniant'));
     $help = $type == 'pre-job' ? 'Take photos of the site before any work is done, then upload them here.' : 'Take photos of the site after all work is completed, then upload them here.';
     $title = ucfirst($type) . ' site photos: ' . $this->order_model->get_reference_id($order->id);
     $this->load_stage_view(array('extra_param' => $type, 'type' => $type, 'dialog' => $this->get_signature_required_dialog($type), 'help' => $help));
 }
 /**
  * A single assignment_id is given, but it may represent a group of units (as an assignment).
  * The reason we pass the $assignment_id instead of the $assignment_id is to highlight the last edited Unit tab on this page
  * The Diagnostic is created on this page
  */
 public function index($assignment_id)
 {
     $this->load->model('miniant/diagnostic_tree_model');
     $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());
     }
     $unit = $this->unit_model->get($this->assignment->unit_id);
     $order = (object) $this->order_model->get_values($this->assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     $technician_id = parent::get_technician_id($assignment_id);
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     $this->db->cache_delete();
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'diagnostic_report', 'param' => $assignment_id, 'module' => 'miniant'));
     $part_types_by_unit_type = array();
     foreach ($units as $key => $unit) {
         $units[$key]->assignment = (object) $this->assignment_model->get_values($unit->assignment_id);
         if ($units[$key]->assignment->no_issues_found) {
             $this->diagnostic_issue_model->delete(array('diagnostic_id' => $units[$key]->assignment->diagnostic_id));
         }
         if (empty($units[$key]->assignment->diagnostic_id)) {
             $diagnostic_id = $this->diagnostic_model->add(array());
             $this->assignment_model->edit($unit->assignment_id, array('diagnostic_id' => $diagnostic_id));
             $units[$key]->diagnostic = (object) $this->diagnostic_model->get_values($diagnostic_id);
         } else {
             $units[$key]->diagnostic = (object) $this->diagnostic_model->get_values($units[$key]->assignment->diagnostic_id);
         }
         $units[$key]->order = (object) $this->order_model->get_values($order->id);
         $units[$key]->diagnostic_issues = $this->diagnostic_issue_model->get(array('diagnostic_id' => $units[$key]->diagnostic->id));
         $units[$key]->dialog = $this->get_diagnostic_report_dialog($units[$key]->diagnostic->id, $order, $technician_id, $this->workflow_manager);
         $units[$key]->no_issues_dialog = $this->get_diagnostic_report_no_issues_dialog($units[$key]->diagnostic->id, $order, $technician_id, $this->workflow_manager);
         if (empty($part_types_by_unit_type[$unit->unit_type_id])) {
             $part_types_by_unit_type[$unit->unit_type_id] = $this->diagnostic_tree_model->get_part_types($unit->unit_type_id, true);
         }
         $part_types_dropdown = array(0 => '-- Select One --');
         foreach ($part_types_by_unit_type[$unit->unit_type_id] as $part_type) {
             $part_types_dropdown[$part_type->id] = $part_type->name;
         }
         $units[$key]->part_types_dropdown = $part_types_dropdown;
         $units[$key]->sq_submitted = $this->assignment_model->has_statuses($unit->assignment_id, array('AWAITING REVIEW'));
     }
     $info_title_options = array('title' => 'Unit info', 'help' => 'Information', 'icons' => array());
     $site_title_options = array('title' => 'Site info', 'help' => 'Site address and name of the site contact', 'icons' => array());
     $diagnostic_title_options = array('title' => 'Diagnosed issues', 'help' => 'Record the issues discovered during diagnosis', 'icons' => array());
     $this->load_stage_view(array('units' => $units, 'info_title_options' => $info_title_options, 'diagnostic_title_options' => $diagnostic_title_options, 'site_title_options' => $site_title_options, 'show_start_diagnostic_message' => $order_type != 'Repair' && !$this->assignment_model->has_statuses($assignment_id, array('ISSUES DIAGNOSED'))));
 }
 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' => 'assignment_details', 'param' => $assignment_id, 'module' => 'miniant'));
     $next_page_url = $this->workflow_manager->get_next_url();
     parent::update_time($order->id);
     $technician_id = parent::get_technician_id($assignment_id);
     $order_technician = $this->order_technician_model->get(array('order_id' => $order->id, 'technician_id' => $technician_id), true);
     $is_technician = user_has_role($this->session->userdata('user_id'), 'Technician');
     $order_technician_id = @$order_technician->id;
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     $notes = $this->message_model->get_with_author_names(array('document_type' => 'order', 'document_id' => $order->id));
     $equipment_type = null;
     $equipment_types = array();
     foreach ($units as $key => $unit) {
         $units[$key]->notes = $this->message_model->get_with_author_names(array('document_type' => 'assignment', 'document_id' => $assignment_id));
         if (is_null($equipment_type)) {
             $equipment_type = $this->unit_model->get_type_string($unit->unit_type_id);
         }
         if (!in_array($unit->unit_type_id, $equipment_types)) {
             $equipment_types[] = $unit->unit_type_id;
         }
     }
     if (count($equipment_types) > 1) {
         $equipment_type = 'Mixed';
     }
     $this->load->library('Dialog');
     $this->dialog->initialise(array('min_interval_between_answers' => 300));
     if ($is_technician) {
         $this->dialog->add_question(array('id' => 'ready_to_travel', 'shown' => !$this->order_technician_model->has_statuses($order_technician_id, array('STARTED TRAVEL')), 'text' => 'Are you ready to travel to the job?', 'answers' => array(array('text' => 'Yes', 'ids_to_show' => array('ready_to_start'), 'triggers' => array(array('system' => 'order_technician', 'document_id' => $order_technician_id, 'event_name' => 'leaving', 'module' => 'miniant'))))));
         $this->dialog->add_question(array('id' => 'continue', 'shown' => $this->order_technician_model->has_statuses($order_technician_id, array('STARTED')), 'text' => 'This job is currently in progress', 'answers' => array(array('text' => 'Continue this job', 'url' => $next_page_url))));
         $question_text = $order_type == 'Installation' ? 'Are you ready to start the installation?' : 'Are you ready to start the diagnostic?';
         $this->dialog->add_question(array('id' => 'ready_to_start', 'shown' => !$this->order_technician_model->has_statuses($order_technician_id, array('STARTED')) && $this->order_technician_model->has_statuses($order_technician_id, array('STARTED TRAVEL')), 'text' => $question_text, 'answers' => array(array('text' => 'Yes', 'triggers' => array(array('system' => 'order_technician', 'document_id' => $order_technician_id, 'event_name' => 'start', 'module' => 'miniant'), array('system' => 'order', 'document_id' => $order->id, 'event_name' => 'start', 'module' => 'miniant')), 'url' => $next_page_url, 'short_interval_js' => '$("#did_you_forget").show();return false;'))));
         $this->dialog->add_question(array('id' => 'did_you_forget', 'shown' => false, 'text' => 'Did you forget to click the "Are you ready to travel" button before you left?', 'answers' => array(array('text' => 'Yes', 'undo' => false, 'ids_to_show' => array('time_estimate')), array('text' => 'No', 'triggers' => array(array('system' => 'order_technician', 'document_id' => $order_technician_id, 'event_name' => 'start', 'module' => 'miniant'), array('system' => 'order', 'document_id' => $order->id, 'event_name' => 'start', 'module' => 'miniant')), 'url' => $next_page_url))));
         $this->dialog->add_question(array('id' => 'time_estimate', 'shown' => false, 'text' => 'Estimate how long it took you to travel', 'answers' => array(array('text' => 'Travel time', 'type' => 'dropdown', 'options' => array(0 => '-- Select One --', 900 => '15 minutes', 1800 => '30 minutes', 2700 => '45 minutes', 3600 => '1 hour', 4500 => '1 hour 15 minutes', 5400 => '1 hour 30 minutes', 6300 => '1 hour 45 minutes', 7200 => '2 hours', 8100 => '2 hours 15 minutes', 9000 => '2 hours 30 minutes', 9900 => '2 hours 45 minutes', 10800 => '3 hours', 11700 => '3 hours 15 minutes', 12600 => '3 hours 30 minutes', 13500 => '3 hours 45 minutes', 14400 => '4 hours', 15300 => '4 hours 15 minutes', 16200 => '4 hours 30 minutes', 17100 => '4 hours 45 minutes', 18000 => '5 hours'), 'ajax_callback' => 'miniant/stages/assignment_details/add_travel_time/' . $assignment_id, 'ajax_position' => 'end', 'ajax_data' => array('assignment_id' => $assignment_id), 'triggers' => array(array('system' => 'order_technician', 'document_id' => $order_technician_id, 'event_name' => 'start', 'module' => 'miniant')), 'url' => $next_page_url))));
     } else {
         $this->dialog->add_question(array('id' => 'review', 'shown' => true, 'text' => ' ', 'answers' => array(array('text' => 'Review this job', 'url' => $next_page_url))));
     }
     $this->load_stage_view(array('units' => $units, 'notes' => $notes, 'dialog' => $this->dialog->output(), 'equipment_type' => $equipment_type));
 }
 public function index($assignment_id)
 {
     require_capability('orders:editunitdetails');
     $this->assignment = (object) $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);
     $technician_id = $this->session->userdata('user_id');
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'location_diagram', 'param' => $assignment_id, 'module' => 'miniant'));
     // Look up if there are existing location diagrams for this job site. If yes, copy the latest one over to this job
     $this->location_diagram_model->copy_if_exists_for_address($order->id, $order->parent_sq_id);
     $this->load_stage_view(array('is_senior_technician' => $technician_id == $order->senior_technician_id, 'is_maintenance' => $order->order_type_id == $this->order_model->get_type_id('Maintenance'), 'is_service' => $order->order_type_id == $this->order_model->get_type_id('Service'), 'module' => 'miniant', 'jstoload' => array('signature_pad')));
 }
 public function index($assignment_id)
 {
     $this->assignment_id = $assignment_id;
     $this->assignment = (object) $this->assignment_model->get_values($this->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);
     $technician_id = $this->session->userdata('user_id');
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => 'installation', 'stage' => 'installation_checklist', 'param' => $assignment_id, 'module' => 'miniant'));
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     foreach ($units as $key => $unit) {
         $installation_tasks = $this->installation_task_model->get(array('unit_id' => $unit->id, 'disabled' => 0));
         $units[$key]->installation_tasks = $installation_tasks;
     }
     $this->load_stage_view(array('units' => $units, 'is_senior_technician' => $technician_id == $order->senior_technician_id, 'supervisor' => false));
 }
 public function index($assignment_id, $type = null)
 {
     require_capability('orders:editunitdetails');
     $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);
     $technician_id = $this->session->userdata('user_id');
     parent::update_time($order->id);
     if (is_null($type)) {
         $type = $this->order_model->has_statuses($order->id, array('POST-JOB COMPLETE', 'PRE-JOB SITE PHOTOS UPLOADED'), 'AND') ? 'post-job' : 'pre-job';
     }
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'unit_photos', 'param' => $assignment_id, 'module' => 'miniant'));
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     $help = 'Upload photos of the unit you are working on only (e.g., Indoor, Outdoor, Thermostat)';
     $title = 'Equipment photos';
     $this->load_stage_view(array('units' => $units));
 }
 public function index($assignment_id)
 {
     $this->assignment = (object) $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);
     $technician_id = $this->session->userdata('user_id');
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => 'maintenance', 'stage' => 'maintenance_checklist', 'param' => $assignment_id, 'module' => 'miniant'));
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     foreach ($units as $key => $unit) {
         $maintenance_task_templates = $this->maintenance_task_template_model->get(array('unit_type_id' => $unit->unit_type_id));
         foreach ($maintenance_task_templates as $key2 => $maintenance_task_template) {
             if ($maintenance_task = $this->maintenance_task_model->get(array('maintenance_task_template_id' => $maintenance_task_template->id, 'assignment_id' => $assignment_id), true)) {
                 $maintenance_task_templates[$key2]->completed_date = $maintenance_task->completed_date;
                 $maintenance_task_templates[$key2]->completed_by = $maintenance_task->completed_by;
             } else {
                 $maintenance_task_templates[$key2]->completed_date = null;
                 $maintenance_task_templates[$key2]->completed_by = null;
             }
         }
         $units[$key]->maintenance_tasks = $maintenance_task_templates;
         $this->load->library('Dialog');
         $this->dialog->initialise(array('id' => 'dialog-' . $unit->assignment_id));
         $this->dialog->add_question(array('id' => 'diagnostic_required_' . $unit->id, 'shown' => is_null($unit->assignment->diagnostic_required) && !$this->assignment_model->has_statuses($unit->assignment_id, array('MAINTENANCE TASKS COMPLETED')), 'text' => 'Is this unit functioning properly?', 'answers' => array(array('text' => 'Yes', 'ids_to_show' => array('continue_' . $unit->id), 'ajax_callback' => 'miniant/stages/maintenance_checklist/set_diagnostic_not_required/' . $unit->assignment_id), array('text' => 'No', 'ids_to_show' => array('can_be_fixed_immediately_' . $unit->id), 'ajax_callback' => 'miniant/stages/maintenance_checklist/set_diagnostic_required/' . $unit->assignment_id))));
         $this->dialog->add_question(array('id' => 'can_be_fixed_immediately_' . $unit->id, 'shown' => empty($unit->assignment->estimated_duration) && $this->assignment->diagnostic_required == 1, 'text' => 'Can you fix the issue within 5 minutes?', 'answers' => array(array('text' => 'Yes', 'ids_to_show' => array('diagnostic_authorised_' . $unit->id), 'ajax_callback' => 'miniant/stages/maintenance_checklist/set_diagnostic_immediate_fix/' . $unit->assignment_id), array('text' => 'No', 'ids_to_show' => array('continue_' . $unit->id), 'ajax_callback' => 'miniant/stages/maintenance_checklist/set_diagnostic_needs_sq/' . $unit->assignment_id))));
         $this->dialog->add_question(array('id' => 'diagnostic_authorised_' . $unit->id, 'shown' => !$this->assignment_model->has_statuses($unit->assignment_id, array('MAINTENANCE TASKS COMPLETED')) && is_null($unit->assignment->diagnostic_authorised) && $unit->assignment->diagnostic_required == 1 && $unit->assignment->estimated_duration == 5, 'text' => 'Have you been authorised to perform a diagnostic on this unit?', 'answers' => array(array('text' => 'Yes', 'ids_to_show' => array('continue_' . $unit->id), 'ajax_callback' => 'miniant/stages/maintenance_checklist/set_diagnostic_authorised/' . $unit->assignment_id), array('text' => 'No', 'ids_to_show' => array('continue_' . $unit->id), 'ajax_callback' => 'miniant/stages/maintenance_checklist/set_diagnostic_not_authorised/' . $unit->assignment_id))));
         $this->dialog->add_question(array('id' => 'continue_' . $unit->id, 'shown' => $this->assignment_model->has_statuses($unit->assignment_id, array('MAINTENANCE TASKS COMPLETED')) && isset($unit->assignment->diagnostic_required) && isset($unit->assignment->diagnostic_authorised) && isset($unit->assignment->estimated_duration), 'text' => ' ', 'answers' => array(array('text' => 'Continue', 'url' => 'miniant/stages/maintenance_checklist/process/' . $unit->assignment_id))));
         $units[$key]->dialog = $this->dialog->output();
     }
     $this->load_stage_view(array('units' => $units, 'is_senior_technician' => $technician_id == $order->senior_technician_id));
 }
 public function index($assignment_id)
 {
     require_capability('orders:editunitdetails');
     if (!($this->assignment = $this->assignment_model->get($assignment_id))) {
         die("The assignment ID {$assignment_id} could not be found!");
     }
     $order = (object) $this->order_model->get_values($this->assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     $technician_id = parent::get_technician_id($assignment_id);
     $is_technician = user_has_role($this->session->userdata('user_id'), 'Technician');
     $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);
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'signature', 'param' => $assignment_id, 'module' => 'miniant'));
     $has_required_diagnostics = false;
     $tenancies = array();
     foreach ($units as $key => $unit) {
         $units[$key]->assignment = (object) $this->assignment_model->get_values($units[$key]->assignment_id);
         $unit_photos = get_photos('assignment', $unit->assignment_id, $unit->id, 'miniant');
         $photos = array();
         $photos['Equipment photos'] = array();
         if (!empty($unit_photos)) {
             foreach ($unit_photos as $photo) {
                 $photos['Equipment photos'][] = $photo;
             }
         }
         if ($order_type != 'Installation') {
             if (!empty($units[$key]->assignment->diagnostic_id)) {
                 $units[$key]->diagnostic = (object) $this->diagnostic_model->get_values($units[$key]->assignment->diagnostic_id);
                 $units[$key]->issues = $this->diagnostic_issue_model->get(array('diagnostic_id' => $units[$key]->diagnostic->id));
                 if (!$units[$key]->diagnostic->bypassed) {
                     $has_required_diagnostics = true;
                 }
             }
             if (!empty($units[$key]->issues) && !$units[$key]->assignment->hide_issue_photos) {
                 foreach ($units[$key]->issues as $diagnostic_issue) {
                     if ($issue_photos = get_photos('diagnostic_issue', null, $diagnostic_issue->id, 'miniant')) {
                         foreach ($issue_photos as $issue_photo) {
                             if (empty($photos["{$diagnostic_issue->issue_type_name} {$diagnostic_issue->part_type_name}"])) {
                                 $photos["{$diagnostic_issue->issue_type_name} {$diagnostic_issue->part_type_name}"] = array();
                             }
                             $photos["{$diagnostic_issue->issue_type_name} {$diagnostic_issue->part_type_name}"][] = $issue_photo;
                         }
                     }
                 }
             }
         }
         $units[$key]->photos = $photos;
         $parts_used = $this->part_model->get(array('assignment_id' => $unit->assignment_id));
         foreach ($parts_used as $key2 => $part_used) {
             if (empty($part_used->part_name)) {
                 $parts_used[$key2]->part_name = $this->part_type_model->get($part_used->part_type_id)->name;
             }
             if (empty($part_used->quantity)) {
                 $part_used->quantity = $part_used->description;
             }
             if (!empty($part_used->servicequote_id) || empty($part_used->quantity)) {
                 unset($parts_used[$key2]);
             }
         }
         $units[$key]->parts_used = $parts_used;
         if (empty($tenancies[$unit->tenancy_id])) {
             $tenancy = $this->tenancy_model->get($unit->tenancy_id);
             $tenancies[$unit->tenancy_id] = array('units' => array(), 'tenancy' => $tenancy, 'signature' => $this->tenancy_model->get_signature_for_order($tenancy->id, $order->id));
         }
         $tenancies[$unit->tenancy_id]['units'][] = $unit;
     }
     $site_photos = array('pre-job' => get_photos('order', 'site-pre-job', $order->id, 'miniant'), 'post-job' => get_photos('order', 'site-post-job', $order->id, 'miniant'));
     $this->load_stage_view(array('units' => $units, 'jstoload' => array('jquery.signaturepad', 'signaturepad/flashcanvas', 'signaturepad/json2'), 'module' => 'miniant', 'csstoload' => array('jquery.signaturepad'), 'tenancies' => $tenancies, 'site_photos' => $site_photos, 'terms' => $this->setting_model->get(array('name' => 'terms'), true)->value, 'is_maintenance' => $order->order_type_id == $this->order_model->get_type_id('Maintenance'), 'is_service' => $order->order_type_id == $this->order_model->get_type_id('Service'), 'is_repair' => $order->order_type_id == $this->order_model->get_type_id('Repair'), 'order_dowd' => $this->dowd_model->get_formatted_order_dowd($order->dowd_id, $order->id), 'time_started' => @$this->order_technician_model->get_status_change_log($order_technician->id, 'STARTED')->creation_date));
 }
 private function get_assignment_info($assignment_id)
 {
     $this->load->model('miniant/order_technician_model');
     $assignment = $this->assignment_model->get($assignment_id);
     if (!is_object($assignment)) {
         debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
         die;
     }
     $unit = (object) $this->unit_model->get_values($assignment->unit_id);
     $order = (object) $this->order_model->get_values($assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     $technician_id = Stage_controller::get_technician_id($assignment_id);
     $order_technician = $this->order_technician_model->get(array('order_id' => $order->id, 'technician_id' => $technician_id), true);
     return compact('assignment', 'order', 'order_type', 'technician_id', 'order_technician', 'unit');
 }
Beispiel #11
0
 public function index($assignment_id)
 {
     $this->assignment_id = $assignment_id;
     $this->assignment = $this->assignment_model->get($this->assignment_id);
     if (empty($this->assignment)) {
         add_message('This job is no longer on record.', 'warning');
         redirect(base_url());
     }
     $diagnostic = $this->diagnostic_model->get($this->assignment->diagnostic_id);
     $order = (object) $this->order_model->get_values($this->assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     $technician_id = parent::get_technician_id($assignment_id);
     $is_technician = user_has_role($this->session->userdata('user_id'), 'Technician');
     $is_senior_technician = $technician_id == $order->senior_technician_id;
     parent::update_time($order->id);
     $is_maintenance = $order->order_type_id == $this->order_model->get_type_id('Maintenance');
     $is_repair = $order->order_type_id == $this->order_model->get_type_id('Repair');
     $is_breakdown = $order->order_type_id == $this->order_model->get_type_id('Breakdown');
     $is_installation = $order->order_type_id == $this->order_model->get_type_id('Installation');
     $is_service = $order->order_type_id == $this->order_model->get_type_id('Service');
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'dowds', 'param' => $assignment_id, 'module' => 'miniant'));
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     foreach ($units as $key => $unit) {
         $sq = $this->servicequote_model->get(array('order_id' => $order->id, 'diagnostic_id' => $unit->assignment->diagnostic_id), true);
         $units[$key]->assignment = (object) $this->assignment_model->get_values($unit->assignment_id);
         $units[$key]->order = (object) $this->order_model->get_values($order->id);
         if (!empty($units[$key]->assignment->diagnostic_id)) {
             $units[$key]->diagnostic = (object) $this->diagnostic_model->get_values($units[$key]->assignment->diagnostic_id);
             $diagnostic_issues = $this->diagnostic_issue_model->get(array('diagnostic_id' => $unit->diagnostic->id));
         }
         if (empty($diagnostic_issues)) {
             form_element::$default_data['dowd_text'] = $this->assignment->dowd_text;
             $diagnostic_issues = array();
         } else {
             foreach ($diagnostic_issues as $key2 => $diagnostic_issue) {
                 if (empty($diagnostic_issue->dowd_id)) {
                     // TODO Improve the automatic selection of a unit DOWD. Must cover all scenarios!
                     if (!$this->assignment_model->has_repairs_approved($unit->assignment->id) && !$this->assignment_model->has_statuses($unit->assignment->id, array('SQ APPROVED'))) {
                         $dowd = $this->dowd_model->get(array('name' => 'ISSUES FOUND - NO ACTION', 'order_type_id' => $order->order_type_id), true);
                     } else {
                         if ($diagnostic_issue->can_be_fixed_now) {
                             // If at least one part must be picked up from supplier, use the supplier DOWD
                             if ($this->assignment_model->requires_parts_from_supplier($unit->assignment_id)) {
                                 $dowd = $this->dowd_model->get(array('name' => 'PARTS REQUIRED - TO BE PICKED UP FROM SUPPLIER', 'order_type_id' => $order->order_type_id), true);
                             } else {
                                 $dowd = $this->dowd_model->get(array('name' => 'PARTS REQUIRED FROM VAN STOCK', 'order_type_id' => $order->order_type_id), true);
                             }
                         } else {
                             $dowd = $this->dowd_model->get(array('name' => 'WAITING ON APPROVAL', 'order_type_id' => $order->order_type_id), true);
                         }
                     }
                     if (empty($dowd)) {
                         add_message("No DOWD found for {$order->order_type} job type, issue {$diagnostic_issue->issue_type_name} {$diagnostic_issue->part_type_name}", 'danger');
                         break;
                     }
                     $diagnostic_issues[$key2]->dowd_id = $dowd->id;
                     form_element::$default_data['dowd_id[' . $diagnostic_issue->id . ']'] = $dowd->id;
                     form_element::$default_data['dowd_text[' . $diagnostic_issue->id . ']'] = $this->dowd_model->get_formatted_description($dowd->id, $diagnostic_issue->id);
                 }
             }
         }
         $units[$key]->diagnostic_issues = $diagnostic_issues;
         $units[$key]->isolated = $this->assignment_model->has_statuses($unit->assignment_id, array("ISOLATED AND TAGGED"));
     }
     $dowds_dropdown = $this->dowd_model->get_dropdown('name', false);
     $dowds_dropdown[null] = null;
     // Prevent a PHP error if no DOWD was found
     $this->load_stage_view(array('units' => $units, 'is_maintenance' => $is_maintenance, 'is_repair' => $is_repair, 'is_breakdown' => $is_breakdown, 'is_installation' => $is_installation, 'is_service' => $is_service, 'is_senior_technician' => $is_senior_technician, 'dowds_dropdown' => $dowds_dropdown, 'is_technician' => $is_technician));
 }
 public function index($assignment_id)
 {
     $this->assignment_id = $assignment_id;
     $this->assignment = $this->assignment_model->get($this->assignment_id);
     if (empty($this->assignment)) {
         add_message('This job is no longer on record.', 'warning');
         redirect(base_url());
     }
     $diagnostic = $this->diagnostic_model->get($this->assignment->diagnostic_id);
     $order = (object) $this->order_model->get_values($this->assignment->order_id);
     $order_type = $this->order_model->get_type_string($order->order_type_id);
     $technician_id = $this->session->userdata('user_id');
     $is_senior_technician = $technician_id == $order->senior_technician_id;
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'order_dowd', 'param' => $assignment_id, 'module' => 'miniant'));
     $dowd = null;
     switch ($order_type) {
         case 'Repair':
             if ($this->assignment->no_issues_found || !$this->assignment_model->has_statuses($this->assignment->id, array('SQ APPROVED'))) {
                 $dowd = $this->dowd_model->get(array('name' => 'REPAIR TASKS COMPLETED - OPERATIONAL', 'order_type_id' => $order->order_type_id), true);
             } else {
                 if ($this->assignment_model->has_statuses($this->assignment->id, array('SQ APPROVED'))) {
                     $dowd = $this->dowd_model->get(array('name' => 'REPAIR TASKS COMPLETED - SQ', 'order_type_id' => $order->order_type_id), true);
                 }
             }
             break;
         case 'Breakdown':
             if ($this->assignment->no_issues_found) {
                 $dowd = $this->dowd_model->get(array('name' => 'NO ISSUES FOUND', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
                 // No repairs done, SQ created and approved WAITING ON APPROVAL
             } else {
                 if (!$this->order_model->has_repairs_approved($order->id) && $this->order_model->has_sq_approved($order->id)) {
                     $dowd = $this->dowd_model->get(array('name' => 'WAITING ON APPROVAL', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
                     // Some repairs done, SQ approved WAITING ON APPROVAL - SOME ISSUES REPAIRED
                 } else {
                     if ($this->order_model->has_repairs_approved($order->id) && $this->order_model->has_sq_approved($order->id)) {
                         $dowd = $this->dowd_model->get(array('name' => 'WAITING ON APPROVAL - SOME ISSUES REPAIRED', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
                         // All repairs done, no SQ ISSUES FOUND AND REPAIRED
                     } else {
                         if ($this->order_model->has_repairs_approved($order->id) && !$this->order_model->has_sq_approved($order->id)) {
                             $dowd = $this->dowd_model->get(array('name' => 'ISSUES FOUND AND REPAIRED', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
                             // Some issues diagnosed, but no repairs done or SQ created NO REPAIRS AUTHORISED
                         } else {
                             if (!$this->order_model->has_repairs_approved($order->id) && !$this->order_model->has_sq_approved($order->id)) {
                                 $dowd = $this->dowd_model->get(array('name' => 'NO REPAIRS AUTHORISED', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
                             }
                         }
                     }
                 }
             }
             break;
         case 'Installation':
             $dowd = $this->dowd_model->get(array('name' => 'UNITS INSTALLED', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
             break;
         case 'Maintenance':
             if ($this->order_model->has_sq_approved($order->id)) {
                 $dowd = $this->dowd_model->get(array('name' => 'MAINTENANCE COMPLETED ISSUES FOUND', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
             } else {
                 $dowd = $this->dowd_model->get(array('name' => 'MAINTENANCE COMPLETED NO ISSUES', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
             }
             break;
         case 'Service':
             if ($this->order_model->has_sq_approved($order->id)) {
                 $dowd = $this->dowd_model->get(array('name' => 'SERVICE COMPLETED ISSUES FOUND', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
             } else {
                 $dowd = $this->dowd_model->get(array('name' => 'SERVICE COMPLETED NO ISSUES', 'order_type_id' => $order->order_type_id, 'granularity' => 'order'), true);
             }
             break;
     }
     $this->db->where(array('order_type_id' => $order->order_type_id, 'granularity' => 'order'));
     $this->load_stage_view(array('is_senior_technician' => $is_senior_technician, 'dowds_dropdown' => $this->dowd_model->get_dropdown('name'), 'dowd' => $dowd));
 }
 public function index($assignment_id)
 {
     // If this stage is completed, redirect to the next uncompleted unit, if any
     if ($assignment = $this->stage_conditions_model->get_next_uncompleted_assignment_for_stage($assignment_id, 'unit_details')) {
         $this->assignment = (object) $this->assignment_model->get_values($assignment->id);
     } else {
         $this->assignment = (object) $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);
     $technician_id = parent::get_technician_id($assignment_id);
     $is_technician = user_has_role($this->session->userdata('user_id'), 'Technician');
     parent::update_time($order->id);
     $this->load->library('Miniant_Workflow_manager', array(), 'workflow_manager');
     $this->workflow_manager->initialise(array('workflow' => $order_type, 'stage' => 'unit_details', 'param' => $assignment_id, 'module' => 'miniant'));
     require_capability('orders:editunitdetails');
     $this->order_time_model->finish_time($order->id, $technician_id);
     $this->order_time_model->add(array('time_start' => time(), 'technician_id' => $technician_id, 'order_id' => $order->id));
     $units = $this->get_units($assignment_id, $technician_id, $order->senior_technician_id);
     if (empty($units)) {
         add_message('There are no units associated with this job!', 'danger');
         redirect(base_url('miniant/stages/assignment_details/index/' . $assignment_id));
     }
     $notes = $this->message_model->get_with_author_names(array('document_type' => 'order', 'document_id' => $order->id));
     foreach ($units as $key => $unit) {
         $unit_data = (array) $unit;
         foreach ($unit_data as $var => $val) {
             if (!is_array($val)) {
                 form_element::$default_data[$var . '_' . $unit->assignment_id] = $val;
             }
         }
         if ($unit->unit_type_id == $this->unit_model->get_type_id('Evaporative A/C')) {
             form_element::$default_data['brand_id_evap_' . $unit->assignment_id] = $unit->brand_id;
         }
         if ($unit->unit_type_id == $this->unit_model->get_type_id('Refrigerated A/C')) {
             form_element::$default_data['brand_id_ref_' . $unit->assignment_id] = $unit->brand_id;
         }
         // Get assignment of parent order
         $units[$key]->diagnostic_assignment = $this->assignment_model->get_diagnostic_assignment($unit->assignment_id);
         $units[$key]->assignment = (object) $this->assignment_model->get_values($units[$key]->assignment_id);
         $units[$key]->notes = $this->message_model->get_with_author_names(array('document_type' => 'assignment', 'document_id' => $unit->assignment_id));
         $units[$key]->details_recorded = $this->unit_model->has_statuses($unit->id, array('UNIT DETAILS RECORDED'));
         if ($order_type == 'Repair') {
             $photos = array();
             if (!empty($units[$key]->diagnostic_assignment->diagnostic_id)) {
                 $units[$key]->parent_diagnostic = (object) $this->diagnostic_model->get_values($units[$key]->diagnostic_assignment->diagnostic_id);
                 $units[$key]->issues = $this->diagnostic_issue_model->get(array('diagnostic_id' => $units[$key]->parent_diagnostic->id));
                 if (!$units[$key]->parent_diagnostic->bypassed) {
                     $has_required_diagnostics = true;
                 }
             }
             if (!empty($units[$key]->issues) && !$units[$key]->diagnostic_assignment->hide_issue_photos) {
                 foreach ($units[$key]->issues as $diagnostic_issue) {
                     if ($issue_photos = get_photos('diagnostic_issue', null, $diagnostic_issue->id, 'miniant')) {
                         foreach ($issue_photos as $issue_photo) {
                             if (empty($photos["{$diagnostic_issue->issue_type_name} {$diagnostic_issue->part_type_name}"])) {
                                 $photos["{$diagnostic_issue->issue_type_name} {$diagnostic_issue->part_type_name}"] = array();
                             }
                             $photos["{$diagnostic_issue->issue_type_name} {$diagnostic_issue->part_type_name}"][] = $issue_photo;
                         }
                     }
                 }
             }
             $units[$key]->photos = $photos;
         }
         /*
          * I don't think we need this dialog at all
          *
         $this->load->library('Dialog');
         $this->dialog->initialise(array());
         
         $this->dialog->add_question(array(
             'id' => 'unit_details_recorded',
             'shown' => !$this->unit_model->has_statuses($unit->id, array('UNIT DETAILS RECORDED')),
             'text' => 'Have the details of this unit been recorded by the senior technician ('.$order->senior_technician_first_name.')?',
             'answers' => array(
                 array(
                     'text' => 'Yes',
                     'ids_to_show' => array('start_diagnostic'),
                 ))
             ));
         
             // $next_page_url = ($order->order_type == 'Installation') ? base_url() . 'orders/technician/installation_checklist/'.$unit->assignment_id : base_url() . 'orders/technician/diagnostic_report/'.$unit->assignment_id;
             $this->dialog->add_question(array(
                 'id' => 'start_diagnostic',
                 'shown' => $this->unit_model->has_statuses($unit->id, array('UNIT DETAILS RECORDED')),
                 'text' => 'Details have been recorded for this unit',
                 'answers' => array(
                     array(
                         'text' => 'Continue',
                         'url' => $this->workflow_manager->get_next_url(),
                     ))
                 ));
         $units[$key]->junior_technician_dialog = $this->dialog->output();
         */
     }
     if ($this->input->post()) {
         foreach ($this->input->post() as $key => $val) {
             form_element::$default_data[$key] = $val;
         }
     }
     $this->load_stage_view(array('units' => $units, 'jstoload' => array('signature_pad'), 'is_senior_technician' => $technician_id == $order->senior_technician_id, 'is_maintenance' => $order_type == 'Maintenance', 'is_technician' => user_has_role($this->session->userdata('user_id'), 'Technician'), 'is_service' => $order_type == 'Service', 'is_repair' => $order_type == 'Repair', 'notes' => $notes));
 }