MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/crm_cafsindia_com/application/controllers/Company_code.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Company_code extends Secure_Controller
{
    public function __construct(){
        parent::__construct('Company_code');
        $this->load->model('Company_codes');
    }
	public function index()
	{
		if(!$this->Appconfig->isAppvalid())
		{
			redirect('config');
		}
		$data['table_headers']=$this->xss_clean(get_company_code_table_headers());
		$this->load->view('company_code/manage',$data);
  	}
  	/* 
  	To display or Search the Company Code
  	*/
   	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');
		
		$codes = $this->Company_codes->search($search, $limit, $offset, $sort, $order);
		$total_rows=$this->Company_codes->get_found_rows($search);
		
		$data_rows=array();
		foreach ($codes->result() as $person) {
			# code...
			$data_rows[]=get_code_data_row($person,$this);
		}
		$data_rows=$this->xss_clean($data_rows);
		
		echo json_encode(array('total' => $total_rows,'rows' => $data_rows));
	}

  	//To View Company Codes
	public function view($code_id=-1)
	{
		$info = $this->Company_codes->get_info($code_id);

		foreach(get_object_vars($info) as $property => $value)
		{
			$info->$property = $this->xss_clean($value);
		}
		$data['person_info'] = $info;
	
  		$category_info[""] = "---- Select Category ----";
   		foreach($this->Company_codes->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;
    	$vendor_info[""] = "-----Select Vendor ----";
    	foreach ($this->Company_codes->get_vendor()->result_array() as $row) {
        	$vendor_info[$this->xss_clean($row['vendor_id'])]=$this->xss_clean($row['vendorcompanyname']);
    	}
    	$data['vendor_info']=$vendor_info;
		$this->load->view("company_code/form",$data);
	}
	//On change category Function
	public function category()
	{
		$c=$this->input->post('c');
		$a= $this->Company_codes->get_ven($c);
		echo json_encode($a);
	}
	//To save Company codes
	public function save($company_code_id=-1)
	{
		$code_data=array(
			'category_id'=>$this->input->post('category'),
			'vendorcompanyname'=>$this->input->post('vendor'),
			'company_code'=>$this->input->post('company_code'),			
			'status'=>1,
			
		);
		if($company_code_id === -1){
			$code_data['created_by']   = $this->session->userdata('emp_id');
			$code_data['created_date'] = date('Y-m-d h:i:s');
		}else{
			$code_data['updated_by']   = $this->session->userdata('emp_id');
			$code_data['updated_date'] = date('Y-m-d h:i:s');
		}

		if($this->Company_codes->save_code($code_data,$company_code_id))
		{
			$code_data=$this->xss_clean($code_data);
			// New Company Code
			if($company_code_id === -1)
			{
				echo json_encode(array('success' => 'TRUE', 'message' => $this->lang->line('company_code_successful_adding').' '.
								$code_data['company_code'], 'id' => $code_data['code_id']));
			}
			//Existing Code - Updates Company Code
			else
			{
				echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('company_code_successful_updating').' '.
								$code_data['company_code'], 'id' => $company_code_id));
			
			}	
				
		}
		else	
		{
			$code_data=$this->xss_clean($code_data);
			echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('code_error_adding_updating').' '.
							$code_data['company_code'], 'id' => -1));
		}

	}
	/*
	To Delete Company Codes
	*/
	public function delete()
	{
		$code_to_delete=$this->xss_clean($this->input->post('ids'));
		if($this->Company_codes->delete_list($code_to_delete))
		{
			echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('code_successful_deleted').' '.
							count($code_to_delete).' '.$this->lang->line('code_one_or_multiple')));
		}
		else
		{
			echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('code_cannot_be_deleted')));	
		}
	}
	

	public function get_row($code_ids)
	{
  		$code_info = $this->Company_codes->get_multiple_info($code_ids);

		$result = array();
		foreach($code_info as $item_info)
		{
			$result[$item_info->code_id] = $this->xss_clean(get_item_data_row($item_info, $this));
		}

		echo json_encode($result);
	}

}
?>