File: /home/cafsindia/crm_cafsindia_com/application/controllers/Goal_sheet.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Goal_sheet extends Secure_Controller{
public function __construct(){
parent::__construct('goal_sheet');
$this->load->model('Goal_sheet_model');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers']=$this->xss_clean(goal_sheet_table_headers());
$this->load->view('goal_sheet/manage',$data);
}
public function view($goal_id=-1){
$info = $this->Goal_sheet_model->get_info($goal_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['goal_info'] = $info;
$role_info[""] = "---- Select Role ----";
foreach($this->Goal_sheet_model->get_role()->result_array() as $row){
$role_info[$this->xss_clean($row['role_id'])] = $this->xss_clean($row['role_name']);
}
$data['role_info'] = $role_info;
$category_info[""] = "---- Select Category ----";
foreach($this->Goal_sheet_model->get_category() as $row){
$category_info[$this->xss_clean($row->cat_id)] = $this->xss_clean($row->cat_name);
}
$data['category_info'] = $category_info;
$employee_list[""] = "---- Select Employee ----";
foreach($this->Goal_sheet_model->get_employee_list("","") as $row){
$employee_list[$this->xss_clean($row->emp_id)] = $this->xss_clean($row->name);
}
$data['employee_list'] = $employee_list;
$this->load->view("goal_sheet/form",$data);
}
public function save($goal_id= -1){
$goal_data =array(
'emp_id' => $this->input->post('emp_list'),
'role' => $this->input->post('role'),
'category'=> $this->input->post('category'),
'from_date' => date('Y-m-d',strtotime($this->input->post('from_date'))),
'to_date' => date('Y-m-d',strtotime($this->input->post('to_date'))),
'wfp' => $this->input->post('wfp'),
'nop' => $this->input->post('nop'),
'sip' => $this->input->post('sip'),
'premium' => $this->input->post('premium'),
'met' => $this->input->post('met'),
'attrition' => $this->input->post('attrition'),
'conversion_ratio' => $this->input->post('conversion_ratio'),
'renewal_persistency'=> $this->input->post('renewal_persistency'),
'other_campaign' => $this->input->post('other_campaign'),
);
if($goal_id === -1){
$goal_data['created_by'] = $this->session->userdata('emp_id');
$goal_data['created_date'] = date('Y-m-d h:i:s');
}else{
$goal_data['updated_by'] = $this->session->userdata('emp_id');
$goal_data['updated_date'] = date('Y-m-d h:i:s');
}
if($this->Goal_sheet_model->save_goal($goal_data,$goal_id)){
if($goal_id == -1){
echo json_encode(array('success' => 'TRUE', 'message' => "Goal Sheet Added".' '. $goal_data['goal_id'], 'id' => $goal_id));
}else{
echo json_encode(array('success' => 'TRUE', 'message' => "Goal Sheet Updated".' '. $goal_data['goal_id'], 'id' => $goal_id));
}
}
}
public function get_employee_list(){
$role = $_REQUEST['role'];
$category = $_REQUEST['category'];
$employee_list = $this->Goal_sheet_model->get_employee_list($role,$category);
echo json_encode(array('status' =>"SUCCESS",'employee_list' => $employee_list));
}
public function search(){
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$filters = array('start_date' => $this->input->get('start_date'),
'end_date' => $this->input->get('end_date'),
'Admin' => FALSE,
'Manager' => FALSE,
'CRM' => FALSE,
'Area_Manager' => FALSE,
'RM' => FALSE,
'Team_Leader' => FALSE,
'Executive' => FALSE,
'RM_Manager' => FALSE,
'RE_Manager' => FALSE);
$filledup = array_fill_keys($this->input->get('filters'), TRUE);
$filters = array_merge($filters, $filledup);
$goal = $this->Goal_sheet_model->search($search, $filters, $limit, $offset, $sort, $order);
$total_rows = $this->Goal_sheet_model->get_found_rows($search);
$data_row=array();
foreach($goal->result() as $goal_info) {
$data_row[] = goal_sheet_table_data($goal_info,$this);
}
$data_row=$this->xss_clean($data_row);
echo json_encode(array('total'=>$total_rows,'rows'=>$data_row));
}
public function get_row($goal_ids){
$goal_info = $this->Goal_sheet_model->get_multiple_info($goal_ids);
$result = array();
foreach($goal_info as $ItemInfo){
$result[$ItemInfo->goal_id] = $this->xss_clean(get_item_data_row($ItemInfo, $this));
}
echo json_encode($result);
}
public function delete(){
$goal_delete = $this->xss_clean($this->input->post('ids'));
if($this->Goal_sheet_model->delete_list($goal_delete)){
echo json_encode(array('success' => TRUE, 'message' => "Goal Sheet Deleted".' '.
count($goal_delete).' '."Goals"));
}else{
echo json_encode(array('success' => FALSE, 'message' =>"Goal Sheet Unable Deleted"));
}
}
}
?>