File: /home/cafsindia/crm_cafsindia_com/application/models/Goal_sheet_model.php
<?php
class Goal_sheet_model extends CI_Model{
public function get_role() {
$this->db->from('role');
$this->db->order_by('role_name', 'asc');
return $this->db->get();
}
public function get_category(){
$role_id = $this->session->userdata('emp_role');
$category = $this->session->userdata('emp_category');
$this->db->from('category');
return $this->db->get()->result();
}
public function get_employee_list($role,$category){
$this->db->select('employees.id as emp_id,people.first_name as name');
$this->db->from('employees');
$this->db->join('people', 'people.person_id = employees.person_id');
if($role !== ""){
$this->db->where('employees.role',$role);
}
if($category !== ""){
$this->db->where('employees.category',$category);
}
return $this->db->get()->result();
}
public function save_goal($goal_data,$goal_id){
if($goal_id === -1){
$this->db->insert('goal_sheet',$goal_data);
$goal_data['goal_id']=$this->db->insert_id();
return true;
}else{
$this->db->where('goal_id',$goal_id);
return $this->db->update('goal_sheet',$goal_data);
}
}
public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = '', $order = 'asc'){
$start_date = $filters['start_date'];
$end_date = $filters['end_date'];
$this->db->from('goal_sheet');
$this->db->join('employees', 'employees.id = goal_sheet.emp_id');
$this->db->join('people', 'people.person_id = employees.person_id');
$this->db->join('role', 'role.role_id = goal_sheet.role');
$this->db->join('category', 'category.cat_id = goal_sheet.category');
$this->db->where('goal_sheet.deleted',0);
$this->db->group_start();
$this->db->like('people.first_name',$search);
$this->db->or_like('category.cat_name',$search);
$this->db->or_like('role.role_name',$search);
if(strpos($search, '-') !== false){
$this->db->or_like('goal_sheet.from_date', date('Y-m-d',strtotime($search)));
$this->db->or_like('goal_sheet.to_date', date('Y-m-d',strtotime($search)));
}
$this->db->group_end();
$role = array();
if($filters['Admin'] != FALSE){
$role[] = 1;
}
if($filters['Manager'] != FALSE){
$role[] = 2;
}
if($filters['CRM'] != FALSE){
$role[] = 3;
}
if($filters['Area_Manager'] != FALSE){
$role[] = 4;
}
if($filters['RM'] != FALSE){
$role[] = 5;
}
if($filters['Team_Leader'] != FALSE){
$role[] = 6;
}
if($filters['Executive'] != FALSE){
$role[] = 8;
}
if($filters['RM_Manager'] != FALSE){
$role[] = 9;
}
if($filters['RE_Manager'] != FALSE){
$role[] = 10;
}
if(!empty($role)) {
$this->db->where_in('goal_sheet.role', $role);
}
$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->order_by('goal_id',$order);
if($rows>0){
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
//echo $this->db->last_query();
}
public function get_found_rows($search){
$this->db->from('goal_sheet');
$this->db->where('deleted',0);
return $this->db->get()->num_rows();
}
public function get_info($goal_id){
$this->db->from('goal_sheet');
$this->db->where('goal_id',$goal_id);
$goal_info = $this->db->get();
if($goal_info->num_rows() === 1){
return $goal_info->row();
}else{
foreach ($this->db->list_fields('goal_sheet') as $field){
$goal_Obj->field= '';
}
return $goal_Obj;
}
}
public function get_multiple_info($goal_ids){
$this->db->from('goal_sheet');
$this->db->where_in('goal_id', $goal_ids);
return $this->db->get()->result_array();
}
public function delete_list($goal_delete){
$this->db->where_in('goal_id',$goal_delete);
return $this->db->update('goal_sheet',array('deleted'=>1,'deleted_by'=>$this->session->userdata('emp_id'),'deleted_date'=>date('Y-m-d h:i:s')));
}
}
?>