application/modules/hr/models/Emp_model.php
//use for datatable with live filtering
use for datatable with live filtering
use for datatable with live filtering
private function _get_datatables_query()
	{
        if($this->input->post('f_empcode_f'))
        {
            $this->db->where('emp_master.empcode', $this->input->post('f_empcode_f'));
        }
        if($this->input->post('f_dept_f'))
        {
            $this->db->where('emp_master.departement', $this->input->post('f_dept_f'));
        }
        if($this->input->post('filter_position'))
        {
            $this->db->where('emp_master.position', $this->input->post('filter_position'));
        }
        if($this->input->post('f_emptype_f'))
        {
            $this->db->where('emp_master.employeetype', $this->input->post('f_emptype_f'));
        }
        if($this->input->post('filter_start') != '' && $this->input->post('filter_end') != '' || $this->input->post('filter_start') != null)
        {
        $this->db->where('emp_master.companybegin BETWEEN "'.$this->input->post('filter_start').'" AND "'.$this->input->post('filter_end').'"');
        }
        $this->db->select('emp_master.*,master_position.position_desc, a.position_desc as position_id');
        $this->db->from($this->table);
        $this->db->join('master_position','emp_master.employeetype = master_position.id_position','left');
        $this->db->join('master_position AS a','emp_master.position = a.id_position','left');
        $this->db->where('emp_master.is_deleted = "0" and empcode not in (SELECT empcode FROM hr_termination) and site_id = 2001');
		$i = 0;
		foreach ($this->column_search as $item) 
		{
			if($_POST['search']['value']) 
			{
				if($i===0) 
				{
					$this->db->group_start(); 
					$this->db->like($item, $_POST['search']['value']);
				}
				else
				{
					$this->db->or_like($item, $_POST['search']['value']);
				}
				if(count($this->column_search) - 1 == $i) 
					$this->db->group_end(); 
			}
			$i++;
		}
		if(isset($_POST['order'])) 
		{
			$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)]);
		}
	}
private function _get_datatables_query ( ) { if ( $ this -> input -> post ( 'f_empcode_f' ) ) { $ this -> db -> where ( 'emp_master.empcode' , $ this -> input -> post ( 'f_empcode_f' ) ) ; } if ( $ this -> input -> post ( 'f_dept_f' ) ) { $ this -> db -> where ( 'emp_master.departement' , $ this -> input -> post ( 'f_dept_f' ) ) ; } if ( $ this -> input -> post ( 'filter_position' ) ) { $ this -> db -> where ( 'emp_master.position' , $ this -> input -> post ( 'filter_position' ) ) ; } if ( $ this -> input -> post ( 'f_emptype_f' ) ) { $ this -> db -> where ( 'emp_master.employeetype' , $ this -> input -> post ( 'f_emptype_f' ) ) ; } if ( $ this -> input -> post ( 'filter_start' ) != '' && $ this -> input -> post ( 'filter_end' ) != '' || $ this -> input -> post ( 'filter_start' ) != null ) { $ this -> db -> where ( 'emp_master.companybegin BETWEEN "' . $ this -> input -> post ( 'filter_start' ) . '" AND "' . $ this -> input -> post ( 'filter_end' ) . '"' ) ; } $ this -> db -> select ( 'emp_master.*,master_position.position_desc, a.position_desc as position_id' ) ; $ this -> db -> from ( $ this -> table ) ; $ this -> db -> join ( 'master_position' , 'emp_master.employeetype = master_position.id_position' , 'left' ) ; $ this -> db -> join ( 'master_position AS a' , 'emp_master.position = a.id_position' , 'left' ) ; $ this -> db -> where ( 'emp_master.is_deleted = "0" and empcode not in (SELECT empcode FROM hr_termination) and site_id = 2001' ) ; $ i = 0 ; foreach ( $ this -> column_search as $ item ) { if ( $ _POST [ 'search' ] [ 'value' ] ) { if ( $ i === 0 ) { $ this -> db -> group_start ( ) ; $ this -> db -> like ( $ item , $ _POST [ 'search' ] [ 'value' ] ) ; } else { $ this -> db -> or_like ( $ item , $ _POST [ 'search' ] [ 'value' ] ) ; } if ( count ( $ this -> column_search ) - 1 == $ i ) $ this -> db -> group_end ( ) ; } $ i ++ ; } if ( isset ( $ _POST [ 'order' ] ) ) { $ 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 ) ] ) ; } }
use for datatable with live filtering
use for datatable with live filtering
//add custom filter here //$this->db->where('created_at BETWEEN "'. date('Y-m-d', strtotime($from)). '" and "'. date('Y-m-d', strtotime($to)).'"'); /*if($this->input->post('filter_emp_status'))
        {
            $this->db->like('address', $this->input->post('address'));
        }*/ // loop column  // if datatable send POST for search // first loop // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND. //last loop //close bracket // here order processing