File: /var/www/html/pmw24/app/application/controllers/admin/Servicehistory.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Servicehistory extends MY_Controller {
public function __construct() {
parent::__construct();
$this->redirect_guest();
$this->admin=$this->session->userdata('admin');
$this->load->model('admin/mservicehistory');
$this->load->dbutil();
$this->load->helper('file');
$this->load->helper('download');
}
public function index() {
$this->_load_list_view();
}
private function _load_list_view() {
$condition = array();
$data['cars'] = $this->mservicehistory->getRows('car',$condition,'car_no','asc');
$data['content'] = 'admin/servicehistory/list';
$this->load->view('admin/layouts/index', $data);
}
public function all_content_list(){
$start_date = explode("/",$_POST['start_date']);
$start_date = $start_date[2].'-'.$start_date[1].'-'.$start_date[0] ;
$end_date = explode("/",$_POST['end_date']);
$end_date = $end_date[2].'-'.$end_date[1].'-'.$end_date[0] ;
//$end_date = date("Y-m-d", strtotime($_POST['end_date']));
//$end_date = date("Y-m-d", strtotime($_POST['end_date']));
$car_id = $_POST['car_id'];
$list = $this->mservicehistory->get_datatables($start_date,$end_date,$car_id);
$data = array();
$no = $_POST['start'];
$i=1;
if($no>1)
{
$i=$i*$no+1;
}
foreach ($list as $person) {
$no++;
$row = array();
$row[] =$no;
$row[] = $person->car_no;
$row[] = date("d-m-Y", strtotime($person->service_date));
$row[] = '<a class="cstm_view" id="view" style="padding-left:5px" href="javascript:void(0)" title="'.$person->job_id.'" car_id="'.$person->car_id.'"><i class="glyphicon glyphicon-eye-open"></i></a>';
$data[] = $row;
$i++;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->mservicehistory->count_all($start_date,$end_date,$car_id),
"recordsFiltered" => $this->mservicehistory->count_filtered($start_date,$end_date,$car_id),
"data" => $data,
);
echo json_encode($output);
}
public function all_content_list_csv(){
//$start_date = $_POST['start_date'];
$start_date = date("Y-m-d", strtotime($_POST['start_date']));
//$end_date = $_POST['end_date'];
$end_date = explode("/",$_POST['end_date']);
$end_date = $end_date[2].'-'.$end_date[1].'-'.$end_date[0] ;
$car_id = $_POST['car_id'];
$filename= 'service_history_report'.time().'.csv';
/* $this->db->select('*');
$query = $this->db->get('car');*/
$this->db->select('car.car_no,job_service_date.service_date');
$this->db->from('job_service_date');
$this->db->join('car', 'car.car_id = job_service_date.car_id', 'left');
$this->db->join('job', 'job_service_date.job_id = job.job_id', 'left');
$this->db->where("job_service_date.service_date>=",$start_date);
$this->db->where("job_service_date.service_date<=",$end_date);
$this->db->where("job_service_date.car_id",$car_id);
$this->db->where("job.job_status",2);
$query = $this->db->get();
// echo $query = $this->db->last_query(); die;
@query_to_csv($query,TRUE,$filename);
echo $filename;
}
public function all_details(){
$job_id = $this->input->post('job_id');
$car_id = $this->input->post('car_id');
$services = $this->mservicehistory->get_details($job_id);
foreach($services as $key=>$service)
{
//$condition = array("service_id"=>$service['service_id']);
//$task = $this->mservicehistory->getRows('task',$condition);
$task=$this->mservicehistory->selected_task_list_for_particular_service($job_id,$service['service_id']);
$services[$key]['task'] = $task;
}
$result['services'] = $services;
$car_condition = array("car_id"=>$car_id);
$car = $this->mservicehistory->getRow('car',$car_condition);
$result['job_details']=$this->mservicehistory->get_job_details($job_id);
$result['job_image_details']=$this->mservicehistory->getRows('job_images',array('job_id'=>$job_id));
$result['car'] = $car;
echo json_encode($result);
}
}