File: /home/cafsindia/ntc_cafsinfotech_in_bk/application/controllers/Maintenance_labour_work_order.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Base_controller.php");
class Maintenance_labour_work_order extends Base_controller{
public function __construct(){
parent::__construct('maintenance_labour_work_order');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$this->collect_base_info();
}
// LOAD PAGE WITH TABLE DATA
public function index(){
$this->db->select('prime_service_type_id,service_type');
$this->db->from('service_type');
$this->db->where('cw_service_type.trans_status', 1);
$service_type_rslt = $this->db->get()->result();
foreach($service_type_rslt as $rlst){
$prime_service_type_id = $rlst->prime_service_type_id;
$service_type = $rlst->service_type;
$service_type_list[$prime_service_type_id] = $service_type;
}
$data['service_type_list'] = $service_type_list;
$this->db->select('prime_service_category_id,service_category');
$this->db->from('service_category');
$this->db->where('cw_service_category.trans_status', 1);
$service_category_rslt = $this->db->get()->result();
foreach($service_category_rslt as $rlst){
$prime_service_category_id = $rlst->prime_service_category_id;
$service_category = $rlst->service_category;
$service_category_list[$prime_service_category_id] = $service_category;
}
$data['service_category_list'] = $service_category_list;
$data['table_headers']= $this->xss_clean(get_work_order_headers());
$this->load->view("$this->control_name/manage",$data);
}
//LOAD MODEL PAGE VIEW WITH DATA
public function view($prime_maintenance_job_schedule_id=-1){
$labour_info = json_decode($this->get_labour_info($prime_maintenance_job_schedule_id));
$data['labour_details_list'] = $labour_info->labour_table;
$data['labour_details'] = $prime_maintenance_job_schedule_id;
$this->load->view("$this->control_name/form",$data);
}
//LOAD PAGE TABLE VIEW WITH DATA BASED ON SEARCH FILTERS
public function search(){
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$start_date = str_replace("/","-",$this->input->get('start_date'));
$end_date = str_replace("/","-",$this->input->get('end_date'));
$from_date = date('Y-m-d',strtotime($start_date));
$to_date = date('Y-m-d',strtotime($end_date));
$filters = $this->input->get('filters');
$this->db->select('maintenance_job_schedule.prime_maintenance_job_schedule_id,prime_fault_id,job_card_number,cw_service_type.service_type,vehicle_master.register_no,vehicle_no,date,driver,km');
$this->db->from('maintenance_job_schedule');
$this->db->join('vehicle_master', 'vehicle_master.prime_vehicle_master_id = maintenance_job_schedule.vehicle_no','LEFT');
$this->db->join('service_type', 'service_type.prime_service_type_id = maintenance_job_schedule.service_type','inner');
$this->db->join('labour_details', 'labour_details.prime_maintenance_job_schedule_id = maintenance_job_schedule.prime_maintenance_job_schedule_id','inner');
if($search){
$this->db->group_start();
$this->db->like('prime_fault_id',$search);
$this->db->or_like('cw_service_type.service_type',$search);
$this->db->or_like('driver',$search);
$this->db->or_like('km',$search);
$this->db->or_like('vehicle_no',$search);
if(strpos($search, '-') !== false){
$this->db->or_like('date', date('Y-m-d',strtotime($search)));
}
$this->db->group_end();
}
if(((int)$this->logged_role != 1) and ((int)$this->logged_role != 2)){
$check_info = array($this->logged_id);
$this->db->group_start();
$this->db->where_in('cw_labour_details.assign_labour',$check_info);
$this->db->group_end();
}
$this->db->group_start();
if($filters[0] > 0){
$this->db->where_in('maintenance_job_schedule.service_type', $filters);
}
$filters_sts = array();
foreach($service_category as $key=>$value){
if($value){ $filters_sts[] = $value; }
}
$this->db->where('DATE_FORMAT(date, "%Y-%m-%d") BETWEEN '. $this->db->escape($from_date).' AND '.$this->db->escape($to_date));
$this->db->group_end();
$this->db->group_by('maintenance_job_schedule.prime_maintenance_job_schedule_id');
$this->db->order_by($sort,$order);
$receiving_data = $this->db->get();
$receiving_rslt = $receiving_data->result();
$num_rows = $receiving_data->num_rows();
$datarows = array();
foreach($receiving_rslt as $receiving){
$datarows[] = get_work_order_datarows($receiving,$this);
}
echo json_encode(array('total'=>$num_rows,'rows'=>$datarows));
}
public function get_labour_info($prime_maintenance_job_schedule_id = -1){
if((int)$this->input->post('prime_maintenance_job_schedule_id') > 0){
$prime_maintenance_job_schedule_id = (int)$this->input->post('prime_maintenance_job_schedule_id');
}
$tble_line = "";
if($this->job_schedule_exists($prime_maintenance_job_schedule_id,TRUE)){
$this->db->select('prime_labour_details_id,maintenance_faults.fault_name ,cw_labour_details.fault_name as fault_id,assign_labour,cw_labour_details.completed_delivery_date,cw_labour_details.hours,cw_labour_details.status');
$this->db->from('labour_details');
$this->db->join('maintenance_faults', 'maintenance_faults.prime_maintenance_faults_id = cw_labour_details.fault_name','inner');
$this->db->where('cw_labour_details.prime_maintenance_job_schedule_id', $prime_maintenance_job_schedule_id);
$this->db->where('cw_labour_details.trans_status', 1);
if(((int)$this->logged_role != 1) and ((int)$this->logged_role != 2)){
$check_info = array($this->logged_id);
$this->db->group_start();
$this->db->where_in('cw_labour_details.assign_labour',$check_info);
$this->db->group_end();
}
$labour_info = $this->db->get()->result();
foreach($labour_info as $fault_rlst){
$prime_labour_details_id = $fault_rlst->prime_labour_details_id;
$fault_name = $fault_rlst->fault_name;
$completed_delivery_date = $fault_rlst->completed_delivery_date;
$status = $fault_rlst->status;
$hours = $fault_rlst->hours;
$status_list = array("" => '--select--',1 => "on process",2 => "completed",3 => "incomplted");
$Status = form_dropdown(array('name' => "status_$prime_labour_details_id",'id' => "status_$prime_labour_details_id",'class' => 'form-control input-sm select2','onchange' => "update_info($prime_labour_details_id)"), $status_list,$status);
if($completed_delivery_date){
$completed_delivery_date = date('d-m-Y',strtotime($completed_delivery_date));
if($completed_delivery_date === "01-01-1970"){ $completed_delivery_date = date("d-m-Y"); }
}
if($hours){
$hours = date('HH:mm:ss',strtotime($hours));
if($hours === "00:00:00"){ $hours = date("HH:mm:ss"); }
}
$hours_data = form_input(array( 'name' => "hours_$prime_labour_details_id", 'id' => "hours_$prime_labour_details_id", 'class' => 'form-control input-sm time' ,'value' => $hours));
$completed_delivery_date = form_input(array( 'name' => "completed_delivery_date_$prime_labour_details_id", 'id' => "completed_delivery_date_$prime_labour_details_id", 'class' => 'form-control input-sm datepicker' ,'value' => $completed_delivery_date));
$tble_line .= " <tr>
<td style='width:60%'>$fault_name</td>
<td style='width:10%'>$hours_data</td>
<td style='width:20%'>$Status</td>
<td style='width:10%'>$completed_delivery_date</td>
</tr>";
}
}
if($tble_line === ""){
$tble_line = "<tr><td colspan='4'>No Data Found</td></tr>";
}
$table_data = " <h4 class='m-t-0 header-title'><b>Labours Information List</b></h4>
<table class='table table-striped table-bordered' id='labours_info_table'>
<thead>
<tr>
<th><input type='hidden' id='prime_maintenance_job_schedule_id' value='$prime_maintenance_job_schedule_id'></input>Fault Name</th>
<th>Hours</th>
<th>Status</th>
<th>Completed Date</th>
</tr>
</thead>
<tbody>
$tble_line
</tbody>
</table>";
return json_encode(array("success" => TRUE,'labour_table' => $table_data));
}
//UPDATE LABOUR INFO
public function update_info(){
$prime_maintenance_job_schedule_id = $this->input->post('prime_maintenance_job_schedule_id');
$prime_labour_details_id = $this->input->post('prime_labour_details_id');
if((int)$this->input->post('status')){
$update_data['status'] = $this->input->post('status');
}else{
$update_data['status'] = 0;
}
$update_data['completed_delivery_date'] = date('Y-m-d',strtotime($this->input->post('completed_delivery_date')));
$update_data['hours'] = date('H:i:s',strtotime($this->input->post('hours')));
$update_data['trans_updated_by'] = $this->session->userdata('logged_id');
$update_data['trans_updated_date'] = date("Y-m-d H:i:s");
$this->db->where('prime_labour_details_id',$prime_labour_details_id);
if($this->db->update('cw_labour_details',$update_data)){
$this->check_status($prime_maintenance_job_schedule_id);
echo json_encode(array("success" => TRUE,'message' => 'Updated successfully'));
}else{
echo json_encode(array("success" => False,'message' => "Please Try Again"));
}
}
//CHECKING COMPLETE STATUS AND UPDATE IN DATABASE
public function check_status($prime_maintenance_job_schedule_id){
$this->db->select('status');
$this->db->from('cw_labour_details');
$this->db->where('cw_labour_details.prime_maintenance_job_schedule_id',$prime_maintenance_job_schedule_id);
$this->db->where('cw_labour_details.trans_status',1);
$labour_details = $this->db->get()->result();
$check_count = 0;
foreach($labour_details as $lb_rlst){
$status = $lb_rlst->status;
if((int)$status != 2){
$check_count++;
}
}
$this->db->select('prime_fault_id,vehicle_no');
$this->db->from('cw_maintenance_job_schedule');
$this->db->where('cw_maintenance_job_schedule.prime_maintenance_job_schedule_id',$prime_maintenance_job_schedule_id);
$job_info = $this->db->get()->result();
$prime_fault_id = $job_info[0]->prime_fault_id;
$vehicle_no = $job_info[0]->vehicle_no;
if((int)$check_count === 0){
if((int)$prime_fault_id > 0){
$update_fault_info['fault_status'] = 3;
$update_fault_info['trans_updated_by'] = $this->session->userdata('logged_id');
$update_fault_info['trans_updated_date'] = date("Y-m-d H:i:s");
$this->db->where('prime_maintenance_fault_report_id',$prime_fault_id);
$this->db->where('ntc_vehicle',$vehicle_no);
$this->db->update('cw_maintenance_fault_report',$update_fault_info);
}
$update_job_info['job_status'] = 3;
$update_job_info['trans_updated_by'] = $this->session->userdata('logged_id');
$update_job_info['trans_updated_date'] = date("Y-m-d H:i:s");
$this->db->where('cw_maintenance_job_schedule.prime_maintenance_job_schedule_id',$prime_maintenance_job_schedule_id);
$this->db->update('cw_maintenance_job_schedule',$update_job_info);
}else{
if((int)$prime_fault_id > 0){
$update_fault_info['fault_status'] = 2;
$update_fault_info['trans_updated_by'] = $this->session->userdata('logged_id');
$update_fault_info['trans_updated_date'] = date("Y-m-d H:i:s");
$this->db->where('prime_maintenance_fault_report_id',$prime_fault_id);
$this->db->where('ntc_vehicle',$vehicle_no);
$this->db->update('cw_maintenance_fault_report',$update_fault_info);
}
$update_job_info['job_status'] = 2;
$update_job_info['trans_updated_by'] = $this->session->userdata('logged_id');
$update_job_info['trans_updated_date'] = date("Y-m-d H:i:s");
$this->db->where('cw_maintenance_job_schedule.prime_maintenance_job_schedule_id',$prime_maintenance_job_schedule_id);
$this->db->update('cw_maintenance_job_schedule',$update_job_info);
}
}
//JOB SCHEDULE INFO EXIST
public function job_schedule_exists($prime_maintenance_job_schedule_id){
$this->db->from('maintenance_job_schedule');
$this->db->where('prime_maintenance_job_schedule_id', $prime_maintenance_job_schedule_id);
$this->db->where('trans_status', 1);
return ($this->db->get()->num_rows() == 1);
}
}
?>