File: /home/cafsindia/crm_cafsindia_com/application/controllers/Incentives.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Incentives extends Secure_Controller
{
public function __construct()
{
parent::__construct('incentives');
$this->load->model('Incentive_model');
}
public function index()
{
if(!$this->Appconfig->isAppvalid())
{
redirect('config');
}
$data['table_headers']=$this->xss_clean(incentives_table_headers());
$this->load->view('incentives/manage',$data);
}
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');
$incentives=$this->Incentive_model->search($search,$limit,$offset,$sort,$order);
$total_rows=$this->Incentive_model->get_found_rows($search);
$data_rows=array();
foreach($incentives->result() as $incentive)
{
$data_rows[]=incentives_table_data($incentive,$this);
}
$data_rows=$this->xss_clean($data_rows);
echo json_encode(array('total'=>$total_rows,'rows'=>$data_rows));
}
public function view($incentive_id=-1){
$info=$this->Incentive_model->GetInfo($incentive_id);
foreach (get_object_vars($info) as $property => $value)
{
$info->$property = $this->xss_clean($value);
}
$data['incentive_info']=$info;
$role_info[""] = "---- Select Role ----";
foreach($this->Incentive_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->Incentive_model->get_category()->result_array() as $row){
$category_info[$this->xss_clean($row['cat_id'])] = $this->xss_clean($row['cat_name']);
}
$data['category_info'] = $category_info;
$grade_info[""] = "---- Select Grade ----";
foreach($this->Incentive_model->get_grade()->result_array() as $row){
$grade_info[$this->xss_clean($row['grade_id'])] = $this->xss_clean($row['grade']);
}
$data['grade_info'] = $grade_info;
$this->load->view("incentives/form",$data);
}
public function save($incentive_id= -1)
{
$incentiveData=array(
'from_date' =>date("Y-m-d",strtotime($this->input->post('from_date'))),
'to_date' =>date("Y-m-d",strtotime($this->input->post('to_date'))),
'category' =>$this->input->post('category'),
'role' =>$this->input->post('role'),
'grade' =>$this->input->post('grade'),
'type' =>$this->input->post('type'),
'slab_one_start' =>$this->input->post('slab_one_start'),
'slab_one_end' =>$this->input->post('slab_one_end'),
'slab_one_per' =>$this->input->post('slab_one_per'),
'slab_two_start' =>$this->input->post('slab_two_start'),
'slab_two_end' =>$this->input->post('slab_two_end'),
'slab_two_per' =>$this->input->post('slab_two_per'),
'slab_three_start' =>$this->input->post('slab_three_start'),
'slab_three_end' =>$this->input->post('slab_three_end'),
'slab_three_per' =>$this->input->post('slab_three_per'),
'slab_four' =>$this->input->post('slab_four'),
'slab_four_per' =>$this->input->post('slab_four_per'),
'met' =>$this->input->post('met'),
'value' =>$this->input->post('value'),
'nop' =>$this->input->post('nop'),
'avg_premium' =>$this->input->post('avg_premium'),
'productivity' =>$this->input->post('productivity'),
'percentage' =>$this->input->post('percentage'),
'convertion_ratio' =>$this->input->post('convertion_ratio'),
'credit' =>$this->input->post('credit'),
'created_date' =>date('Y-m-d h:i:s'),
'created_by' =>$this->session->userdata('emp_id'),
);
if($this->Incentive_model->save_incentive($incentiveData,$incentive_id)){
if($incentive_id == -1){
echo json_encode(array('success' => 'TRUE', 'message' => "Incentive Added Successfully".' '. $incentiveData['incentive_id'], 'id' => $incentive_id));
}else{
echo json_encode(array('success' => 'TRUE', 'message' => "Incentive Updated Successfully".' '. $incentiveData['incentive_id'], 'id' => $incentive_id));
}
}else{
$incentiveData=$this->xss_clean($incentiveData);
echo json_encode(array('success' => FALSE, 'message' => 'This Grade already Exist'.' '.
$incentiveData['grade'], 'id' => -1));
}
}
public function get_row($incentive_ids)
{
$incentive_info = $this->Incentive_model->get_multiple_info($incentive_ids);
$result = array();
foreach($incentive_info as $ItemInfo)
{
$result[$ItemInfo->incentive_id] = $this->xss_clean(get_item_data_row($ItemInfo, $this));
}
echo json_encode($result);
}
public function delete()
{
$incentive_delete=$this->xss_clean($this->input->post('ids'));
if($this->Incentive_model->delete_list($incentive_delete))
{
echo json_encode(array('success' => TRUE, 'message' => "Incentive Successfully Deleted".' '.
count($incentive_delete).' '."Grades"));
}
else
{
echo json_encode(array('success' => FALSE, 'message' =>"Incentive Cannot Deleted"));
}
}
}
?>