File: //home/cafsindia/crm_cafsindia_com/application/models/Target_model.php
<?php
class Target_model extends CI_Model{
public function get_emp($emp_id){
$this->db->select('employees.id as emp_id,first_name,role,category');
$this->db->from('employees');
$this->db->join('people', 'employees.person_id = people.person_id');
if($emp_id){
$this->db->where('reporting',$emp_id);
}
$this->db->where('employees.deleted',0);
return $this->db->get()->result_array();
}
public function save_target($target_data,$target_id){
//print_r($target_data); die;
if($target_id === -1){
if(!$this->emp_exist($target_data['emp_id'],$target_data['from_date'])){
$this->db->insert('target',$target_data);
$target_data['target_id']=$this->db->insert_id();
return true;
}else{
return false;
}
}else{
$this->db->where('target_id',$target_id);
return $this->db->update('target',$target_data);
}
}
//Added By SAT 01 Aug 2018
public function get_employee_data($emp_id){
$this->db->select('role,category');
$this->db->from('employees');
$this->db->join('people', 'employees.person_id = people.person_id');
$this->db->where('id',$emp_id);
$this->db->where('employees.deleted',0);
return $this->db->get()->result_array();
}
public function emp_exist($emp_id,$from_date){
$this->db->from('target');
$this->db->where('emp_id',$emp_id);
$this->db->where('DATE_FORMAT(from_date, "%Y-%m")=',date('Y-m',strtotime($from_date)));
$this->db->where('deleted',0);
return $this->db->get()->num_rows();
//echo $this->db->last_query();
}
public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = '', $order = 'asc'){
$emp_id = $this->session->userdata('emp_id');
$start_date = $filters['start_date'];
$end_date = $filters['end_date'];
$this->db->select('*,role_name,cat_name,first_name');
$this->db->from('target');
$this->db->join('employees', 'employees.id = target.emp_id');
$this->db->join('role', 'role.role_id = target.role');
$this->db->join('category', 'category.cat_id = target.category');
$this->db->join('people', 'people.person_id = target.emp_id');
$this->db->group_start();
$this->db->like('first_name',$search);
$this->db->or_like('premium',$search);
$this->db->or_like('met',$search);
$this->db->or_like('nop',$search);
$this->db->or_like('sip',$search);
if(strpos($search, '-') !== false){
$this->db->or_like('from_date', date('Y-m-d',strtotime($search)));
$this->db->or_like('to_date', date('Y-m-d',strtotime($search)));
}
$this->db->group_end();
$this->db->group_start();
$this->db->where('DATE_FORMAT(from_date, "%Y-%m-%d") BETWEEN '. $this->db->escape($start_date).' AND '.$this->db->escape($end_date))->or_where('DATE_FORMAT(to_date, "%Y-%m-%d") BETWEEN '. $this->db->escape($start_date).' AND '.$this->db->escape($end_date));
$this->db->group_end();
$this->db->where('target.deleted',0);
$this->db->where('target.tl_id',$emp_id);
$this->db->order_by('target_id',$order);
if($rows > 0){
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
public function get_info($target_id){
$this->db->from('target');
$this->db->where('target_id',$target_id);
$target_info = $this->db->get();
if($target_info->num_rows() === 1){
return $target_info->row();
}else{
foreach ($this->db->list_fields('target') as $field){
$target_Obj->field= '';
}
return $target_Obj;
}
}
public function get_found_rows($search, $filters){
return $this->search($search, $filters)->num_rows();
}
public function get_multiple_info($target_ids){
$this->db->from('target');
$this->db->where_in('target_id', $target_ids);
return $this->db->get()->result_array();
}
public function delete_list($target_delete){
$this->db->where_in('target_id',$target_delete);
return $this->db->update('target',array('deleted'=>1,'deleted_by'=>$this->session->userdata('emp_id'),'deleted_date'=>date('Y-m-d h:i:s')));
}
}
?>