HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /var/www/html/pmw24/app/application/models/customer/Mbooking.php
<?php
class Mbooking extends CI_Model {
	var $table = 'booking_request';
    var $column_order = array('br.created_ts','br.service_date','br.status','c.car_no','s.service_name','br.job_note'); //set column field database for datatable orderable
    var $column_search = array('br.created_ts','br.service_date','br.status','c.car_no','s.service_name','br.job_note'); //set column field database for datatable searchable just firstname , lastname , address are searchable
    var $order = array('br.booking_request_id' => 'desc'); // default order 

    public function __construct() {
        parent::__construct();
        $this->customer=$this->session->userdata('customer_data');	
    }
	private function _get_datatables_query(){
        
        $this->db->select('date_format(br.created_ts,"%d/%m/%Y %H:%i:%s") as created_ts,date_format(br.service_date,"%d/%m/%Y") as service_date,br.status,c.car_no,GROUP_CONCAT(s.service_name SEPARATOR ",") as service_name,br.job_note');
        $this->db->from('booking_request br');
        $this->db->join('booking_request_services brs','brs.booking_request_id = br.booking_request_id','inner');
        $this->db->join('car c','c.car_id = br.car_id','inner');
        $this->db->join('service s','s.service_id = brs.service_id','inner');
		$this->db->where('br.created_by',$this->customer['customer_id']);
		$this->db->group_by('br.booking_request_id');
        $i = 0;
        foreach ($this->column_search as $item){ // loop column 
			//echo $_POST['search']['value'];exit;
            if($_POST['search']['value']){ // if datatable send POST for search                 
                if($i===0){ // first loop
                    $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
                    $this->db->like($item, $_POST['search']['value']);
                }
                else{
                    $this->db->or_like($item, $_POST['search']['value']);
                }
                if(count($this->column_search) - 1 == $i) //last loop
                $this->db->group_end(); //close bracket
            }
            $i++;
        }
         
        if(isset($_POST['order'])){ // here order processing
            $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
        }else if(isset($this->order)){
            $order = $this->order;
            $this->db->order_by(key($order), $order[key($order)]);
        }
    }
	
	public function get_datatables(){   
        $this->_get_datatables_query();
        if($_POST['length'] != -1)
        $this->db->limit($_POST['length'], $_POST['start']);
        $query = $this->db->get();
       //echo $this->db->last_query();die;
        return $query->result();
    }
	
	public function count_filtered(){
        $this->_get_datatables_query();
        $query = $this->db->get();
        return $query->num_rows();
    }
	
	public function count_all(){
        $this->db->from($this->table);
        $this->db->where('booking_request.created_by',$this->customer['customer_id']);      
        return $this->db->count_all_results();
    }

    public function get_details($car_id){
		$this->db->select('car.*,IF(silver_service=1,"Yes","NO") silver_service,DATE_FORMAT(car.compliance_date, "%d/%m/%Y") compliance_date,DATE_FORMAT(car.registration_expiry_date, "%d/%m/%Y") registration_expiry_date,DATE_FORMAT(car.registration_due_month, "%d/%m/%Y") registration_due_month,DATE_FORMAT(car.dob, "%d/%m/%Y") dob');
        $this->db->from($this->table);		
        $this->db->where('car_id',$car_id);
        $query=$this->db->get();
        return $query->row_array();
    }
	
	public function update($condition,$data){
		$this->db->where($condition);
		$this->db->update($this->table,$data);
		return 1;
	}
	
	public function get_parent_category(){
		$this->db->select('*');
        $this->db->from($this->table); 	
        $this->db->where('parent_id=0');
        $query=$this->db->get();
        return $query->result_array();
	}
	
	public function get_sub_category($category_id){		
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where('parent_id',$category_id);		
        $query=$this->db->get();
        return $query->result_array();
    }
	
	public function add($data){
        $this->db->insert($this->table,$data);
        return $this->db->insert_id();
    }
	
	public function get_category($category_id){	
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where('category_id',$category_id);		
        $query=$this->db->get();
        return $query->row_array();
	}
	
	public function check_category_exsits($category_name,$parent_id){
		$this->db->select('*');
        $this->db->from($this->table);
        $this->db->where('parent_id',$parent_id);		
		 $this->db->where('category_name',$category_name);	
        $query=$this->db->get();
		if($query->result())
		{
			return 1;
		}else{
			return 0;
		}
	}
	
	public function delete($condition){
        $this->db->delete($this->table,$condition);
        return 1;
    }
	
	public function active($condition,$data){
        $this->db->where($condition);
        $this->db->update($this->table,$data);
        return 1;
    }
	
	 public function getRow($table,$condition){
        $this->db->where($condition);
        $query=$this->db->get($table);
        return $query->row_array();
    } 
    
    public function getDetails($table,$condition){
        $this->db->where($condition);
        $query=$this->db->get($table);
        return $query->result_array();
    }
    
    public function set_active_inactive_car($car_id){
            $query="UPDATE car SET status =(CASE WHEN status = 1 THEN 0 ELSE 1 END) WHERE car_id='".$car_id."'";
            $run_query= $this->db->query($query);
            return ($run_query)?true:false;
    }

    public function getServices($job_id){
		$this->db->from("job_services");		
		$this->db->join('service','service.service_id=job_services.service_id');	
		$this->db->where('job_id',$job_id);		
		$query=$this->db->get();
        return $query->result_array();
		
    }
    
    public function getRowA($table,$condition){
        $this->db->where($condition);
		$this->db->order_by('assign_job_id', 'DESC');
		$this->db->limit(1);
        $query=$this->db->get($table);
        return $query->row_array();
    }
}
?>