File: //home/cafsindia/allyindian_com/sbltt/application/controllers/Hsn.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Hsn extends Secure_Controller
{
public function __construct()
{
parent::__construct('hsn');
$this->load->model('Hsn_model');
}
public function index()
{
if(!$this->Appconfig->isAppvalid())
{
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_hsn_headers());
$this->load->view('hsn/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');
$hsn=$this->Hsn_model->search($search,$limit,$offset,$sort,$order);
$TotalRows=$this->Hsn_model->get_found_rows($search);
$DataRows=array();
foreach ($hsn->result() as $person)
{
$DataRows[]=get_hsn_datarows($person,$this);
}
$DataRows=$this->xss_clean($DataRows);
echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
}
public function view($hsn_id=-1)
{
$info=$this->Hsn_model->get_info($hsn_id);
foreach (get_object_vars($info) as $property => $value)
{
$info->$property = $this->xss_clean($value);
}
$data['hsn']=$info;
$this->load->view("hsn/form",$data);
}
/*
Inserts/updates a hsn
*/
public function save($hsn_id = -1)
{
$hsn_data = array(
'hsn_id' => $this->input->post('hsn_id'),
'hsn_name' => $this->input->post('hsn_name'),
'igst' => $this->input->post('igst'),
'sgst' => $this->input->post('sgst'),
'cgst' => $this->input->post('cgst'),
'cess' => $this->input->post('cess'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d h:i:s"),
);
if($this->Hsn_model->save_hsn($hsn_data, $hsn_id)){
$hsn_data = $this->xss_clean($hsn_data);
//New hsn
if($hsn_id == -1)
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('hsn_successful_adding').' '.
$hsn_data['hsn_name'], 'id' => $hsn_data['hsn_id']));
}else {
//Existing hsns
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('hsn_successful_updating').' '.
$hsn_data['hsn_name'], 'id' => $hsn_id));
}
}else{
//failure
$hsn_data = $this->xss_clean($hsn_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('hsn_error_adding_updating').' '.
$hsn_data['hsn_name'], 'id' => -1));
}
}
public function get_row($hsn_ids)
{
$hsn_infos = $this->Hsn_model->get_multiple_info($hsn_ids);
$result = array();
foreach($hsn_infos as $item_info)
{
$result[$item_info->hsn_id] = $this->xss_clean(get_item_data_row($item_info, $this));
}
echo json_encode($result);
}
/*
This deletes hsns from the hsns table
*/
public function delete(){
$hsn_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->Hsn_model->delete_list($hsn_to_delete))
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('hsn_successful_deleted').' '.
count($hsn_to_delete).' '.$this->lang->line('hsn_one_or_multiple')));
}
else
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('hsn_cannot_be_deleted')));
}
}
}
?>