<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Icsetting extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('4', 'setup');
		if(!$query){
			echo '<script>alert("Not authorised..");
				window.location.replace("'.base_url().'Error");
				</script>';
		}
		$this->load->library('layouts');
		$this->load->model('menu');
	}

// Unit Of Measure

	public function unitmeasurelist(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('INVUM');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->model('Sysum');
		$this->lang->load("um",$this->session->userdata('language'));
		$data['datatbls'] = $this->Sysum->sysum_all();
		$data['headertbl'] = $this->session->userdata('menuactive');
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ic/setups/unitmeasure', array('latest' => 'sidebar/latest'), $data);
	}
	public function umGetList(){
		$this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('INVUM');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->model('Sysum');
		$data['umlist'] = $this->Sysum->sysum_all();
		print_r($data['datatbls']);
	}
	public function um_save(){
			$this->load->model('Sysum');
			$fldid = $this->input->post('fldid');
			$fieldname = $this->input->post('fieldname');
			$value = $this->input->post('content');
			$data = array($fieldname=>$value);
		  	$query = $this->Sysum->sysum_save($fldid, $data);
			if($query){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	
	public function um_insert(){
			$this->load->model('Sysum');
			$code = $this->input->post('code');
			$desc = $this->input->post('desc');
			$data = array(
				'companyID' => element('compID', $this->session->userdata('logged_in')),
				'code' => $code,
				'desc' => $desc
				);
		  	$query = $this->Sysum->sysum_insert($data);
			if($query){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	
	public function um_delete(){
			$this->load->model('Sysum');
			$fldid = $this->input->post('fldid');
		  	$delete_menu = $this->Sysum->sysum_delete($fldid);
			if($delete_menu){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	
// Unit Measure Conversion
	public function umconversion(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('PURUOMLS');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->lang->load("um",$this->session->userdata('language'));
	  if($this->input->post('mysubmit')){
		$this->load->model('Sysumconv');	
		  if($this->input->post('fldid')==NULL){
			  $newdata = array(
			  	'companyID' => element('compID', $this->session->userdata('logged_in')),
			  	'itemID'		=> $this->input->post('itemID'),
			  	'from_um'		=> $this->input->post('from_um'), 
			  	'to_um'		=> $this->input->post('to_um'), 
			  	'unitm'		=> $this->input->post('unitm'), 
			  	'factor'		=> $this->input->post('factor'), 
		  		'create_by'		=> element('userid', $this->session->userdata('logged_in')), 
		  	);
		  	$insert_data = $this->Sysumconv->sysumconv_insert($newdata);
			if($insert_data){
				echo '<script>alert("Insert Data Success..");
				window.location.replace("umconversionlist");
				</script>';
			}else{
				echo '<script>alert("Insert Data Failed.");
				history.go(-1);</script>';
			}
		  }else{
			$fldid = $this->input->post('fldid');
		  	$update = array(
			  	'fldid'		=> $this->input->post('fldid'),
				'companyID' => element('compID', $this->session->userdata('logged_in')),
				'itemID'		=> $this->input->post('itemID'), 
			  	'from_um'		=> $this->input->post('from_um'), 
			  	'to_um'		=> $this->input->post('to_um'), 
			  	'unitm'		=> $this->input->post('unitm'), 
			  	'factor'		=> $this->input->post('factor'), 
			  	'modified_dt'		=> $this->input->post('order_time'), 
		  		'modified_by'		=> element('userid', $this->session->userdata('logged_in')), 
		 	);
		  	$update_data = $this->Sysumconv->sysumconv_edit($update, $fldid);
			if($update_data){
				echo '<script>alert("Update Success..");
					window.location.replace("suppliers_list");
					</script>';
			}else{
				echo '<script>alert("Update Failed.");
				history.go(-1);</script>';
			}
		  }
	  }else{
		  $id = $this->uri->segment(3);
		  $this->load->model('Sysum');
		//  $this->load->model('items'); model for item exist already !!!
                 // $data['itemname'] = $this->items->itemname_all();
                  
                  $this->load->model('item/itemSetup_model');
                  $data['itemname'] = $this->itemSetup_model->get_all();
        
		  $this->lang->load("um",$this->session->userdata('language'));
		  $data['unitmeasure'] = $this->Sysum->sysum_all();
		  
		  $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
		  	->add_includes('js/validationengine/jquery.validationEngine.js')
			->add_includes('js/uniform/jquery.uniform.min.js');
		  $this->layouts->view('ic/setups/umconversion', array('latest' => 'sidebar/latest'), $data);
	  }
	}
	
	public function checkUMConvert()
	{
		$this->load->model('Sysumconv');
	
		$where = array(
			'itemID'=>$this->input->post('itemID'),
			'from_um'=>$this->input->post('fromUM'),
			'to_um'=>$this->input->post('toUM')
			);
		$query = $this->Sysumconv->sysumconv_checkNameFromTo($where);
		if($query){
			print json_encode(array(
				"status"=>"success", 
				"message1"=>$query , 
				));
		}else{
			print json_encode(array("status"=>"false", "message2"=>''));
		}
	}

	public function umconversionlist(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('PURUOMLS');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
			$this->load->model('Sysum');
			$data['datatblsum'] = $this->Sysum->sysum_all();
			$this->load->model('Sysumconv');
		    $this->lang->load("um",$this->session->userdata('language'));
			$data['datatbls'] = $this->Sysumconv->sysumconv_all();
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('purchasesetting/umconversionlist', array('latest' => 'sidebar/latest'), $data);
	}

	public function umconv_save(){
			$this->load->model('Sysumconv');
			$fldid = $this->input->post('fldid');
			$fieldname = $this->input->post('fieldname');
			$value = $this->input->post('content');
			$data = array($fieldname=>$value);
		  	$query = $this->Sysumconv->sysumconv_save($fldid, $data);
			if($query){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	
	public function umconv_insert(){
			$this->load->model('Sysumconv');
			$from_um = $this->input->post('from_um');
			$to_um = $this->input->post('to_um');
			$unitm = $this->input->post('unitm');
			$factor = $this->input->post('factor');
			$data = array(
				'from_um' => $from_um,
				'to_um' => $to_um,
				'unit' => $unit,
				'factor' => $factor
				);
		  	$query = $this->Sysumconv->sysumconv_insert($data);
			if($query){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	
	public function umconv_delete(){
			$this->load->model('Sysumconv');
			$fldid = $this->input->post('fldid');
		  	$delete_menu = $this->Sysumconv->sysumconv_delete($fldid);
			if($delete_menu){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	
// Item Master

	public function itemList() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ITEMSET');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->lang->load("item",$this->session->userdata('language'));
		$this->load->model('item/itemSetup_model');
		$listData['datatbls'] = $this->itemSetup_model->get_all();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ic/setups/item_list', array('latest' => 'sidebar/latest'), $listData);
	}
	
	public function item_id(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('INEDITEM');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']: $this->uri->segment(3);
		$this->lang->load("item",$this->session->userdata('language'));
		$this->load->model('master/masterCode_model');
		$data['rowStatus'] = $this->masterCode_model->get_all(array('masterID'=>1));

        $this->load->model('item/ItemSetup_model');
        $data['itemCategory'] = $this->ItemSetup_model->get_all_category();

		$data['itemType'] = $this->masterCode_model->get_all(array('masterID'=>9)); //default list all item_type
		$this->load->model('Sysum');
		$data['rowUnitOfMeasure'] = $this->Sysum->sysum_all();
//		$data['rowUnitOfMeasure'] = $this->masterCode_model->get_all(array('masterID'=>12)); //default list all unit of measure
		$this->load->model('chartofaccount');
		$data['rowIncome'] = $this->chartofaccount->chartofaccount_all();
		$data['rowCogs'] = $this->chartofaccount->chartofaccount_all();
		$data['rowInventories'] = $this->chartofaccount->chartofaccount_all();
		$this->load->model('taxmaster');
		$data['rowOutputTax'] = $this->taxmaster->taxmaster_saleOutput();
		$data['rowInputTax'] = $this->taxmaster->taxmaster_purchaseInput();
		$this->load->model('item/itemSetup_model');
		$rs=$this->itemSetup_model->get_byID($ID);
		$data['rs']=$rs[0];
		$data['ID']=$ID;
		$data['companyID']=element('compID', $this->session->userdata('logged_in')) ; 
		$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
			->add_includes('js/validationengine/jquery.validationEngine.js');
		$this->layouts->view('ic/setups/itemForm', array('latest' => 'sidebar/latest'), $data); //send empty $data as new record
	
	}
	
	public function itemNew() {
//		$this->lang->load("namafile",$this->session->userdata('language'));
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('INNWITEM');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->lang->load("item",$this->session->userdata('language'));
		$this->load->model('master/masterCode_model');
		$this->load->model('taxmaster');
		$data['rowStatus'] = $this->masterCode_model->get_all(array('masterID'=>1));

        $this->load->model('item/ItemSetup_model');
        $data['itemCategory'] = $this->ItemSetup_model->get_all_category();

        $data['itemType'] = $this->masterCode_model->get_all(array('masterID'=>9)); //default list all item_type
		$this->load->model('Sysum');
		$data['rowUnitOfMeasure'] = $this->Sysum->sysum_all();

//		$data['rowUnitOfMeasure'] = $this->masterCode_model->get_all(array('masterID'=>12)); //default list all unit of measure
		$this->load->model('company/companyControlAcctSetup_model');
		$data['defaultIncomeID'] = $this->companyControlAcctSetup_model->get_byCode('saleacct'); //$accountCode income
		$data['defaultCogsID'] = $this->companyControlAcctSetup_model->get_byCode('cogs'); //$accountCode cogs
		$data['defaultInventoriesID'] = $this->companyControlAcctSetup_model->get_byCode('invAcct'); //$accountCode inventories
//		$data['defaultInputTaxID'] = $this->companyControlAcctSetup_model->get_byCode('gstInputTax'); //$accountCode input Tax
		$data['defaultInputTaxID'] = $this->taxmaster->taxmaster_by_code('TX');
		//echo '<br>'.$this->db->last_query().' / '.$data['defaultInputTaxID']; 
//		$data['defaultOutputTaxID'] = $this->companyControlAcctSetup_model->get_byCode('gstOutTax'); //$accountCode output tax
		$data['defaultOutputTaxID'] = $this->taxmaster->taxmaster_by_code('SR');
//		echo '<br>'.$this->db->last_query().' / '.$data['defaultOutputTaxID']; 
		$this->load->model('chartofaccount');
		$data['rowIncome'] = $this->chartofaccount->chartofaccount_all();
		$data['rowCogs'] = $this->chartofaccount->chartofaccount_all();
		$data['rowInventories'] = $this->chartofaccount->chartofaccount_all(); 
		$data['rowOutputTax'] = $this->taxmaster->taxmaster_saleOutput();
//				echo '<br>'.$this->db->last_query();
		$data['rowInputTax'] = $this->taxmaster->taxmaster_purchaseInput();
//				echo '<br>'.$this->db->last_query();
		
		$data['ID']=0;
//		var_dump($data); exit();
		$data['companyID']=element('compID', $this->session->userdata('logged_in')) ;  
		$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
			->add_includes('js/validationengine/jquery.validationEngine.js')
			->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ic/setups/itemForm', array('latest' => 'sidebar/latest'), $data); //send empty $data as new record
	}
	public function itemSave() { //save record
			$this->load->model('Gallery');
			$this->load->model('item/itemSetup_model');
			$ID = $this->input->post('ID');
			$companyID =  element('compID', $this->session->userdata('logged_in')) ;
			$dataupdate = array (
				'companyID' => $companyID, 
				'itemCode' => $this->input->post('itemCode'),
				'name' => $this->input->post('name'),
				'description' => $this->input->post('itemDescription'),
				'itemCategoryID' => $this->input->post('item_category'),
				'itemTypeID' => $this->input->post('item_type'),
				'unitOfMeasureID' => $this->input->post('unitOfMeasure'),
				'editDescription' => $this->input->post(''),
				'itemStatusID' => $this->input->post('itemStatus'),
				'reorderLevel' => $this->input->post('reorderLevel'),
				'incomeID' => $this->input->post('income'),
				'cogsID' => $this->input->post('cogs'),
				'inventoriesID' => $this->input->post('inventories'),
				'inputTaxID' => $this->input->post('inputTax'),
				'outputTaxID' => $this->input->post('ouputTax'),
				'supplierID' => 0,
			);

            if ($ID=='' || $ID==0){
			  	$query = $this->itemSetup_model->insert($dataupdate);
				if($query){
					$this->Gallery->do_upload($query,'');
					echo '<script>alert("Save Success..");
						window.location.replace("itemList");
						</script>';
				}else{
					return FALSE;
				}
			}else{
				$query = $this->itemSetup_model->update_byID2($ID, $dataupdate);
				if($query){
					$this->Gallery->do_upload($ID,$query);
					echo '<script>alert("Save Success..");
						window.location.replace("itemList");
						</script>';
				}else{
					return FALSE;
				}
			}
	}
	
	public function getItemList()
	{
		$itemCategoryID = $this->input->post('region');
    	$this->load->model('master/masterCode_model');
    	$data['statelist']=$this->State->state_region($region);
    	print json_encode(array("status"=>"success", "message"=>$data['statelist']));
	}
	
// Item Details
	public function ItemDetails(){
		$this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ItemDetR');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$item = $this->uri->segment(3);
		$this->lang->load("itemDetails",$this->session->userdata('language'));
		$this->load->model('Items');
		$this->load->model('ItemDetails');
		if($item){
			$query = $this->Items->Items_ID($item);
			$data['header'] = $query[0];
			$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
			 	->add_includes('js/validationengine/jquery.validationEngine.js')
		  	 	->add_includes('js/datatables/jquery.dataTables.min.js');
			$data['datatbls'] = $this->ItemDetails->ItemOnHand_itemID($item);
			$this->layouts->view('ic/setups/itemDetails', array('latest' => 'sidebar/latest'), $data);
		}else{
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$data['datatbls'] = $this->ItemDetails->ItemOnHand();
			$this->layouts->view('ic/setups/itemDetailsList', array('latest' => 'sidebar/latest'), $data);
		}
	}
	
	//Item detail print
	public function itemDetail_print($mode = false){
		$this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ItemDetR');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$item = $this->uri->segment(3);
		$this->lang->load("itemDetails",$this->session->userdata('language'));
		$this->load->model('Items');
		$this->load->model('ItemDetails');
		if($item){
			$query = $this->Items->Items_ID($item);
			$data['header'] = $query[0];
			$data['datatbls'] = $this->ItemDetails->ItemOnHand_itemID($item);
			
			//Report printing
			$headerData['rptTitle'] = $this->lang->line('titlelist');
			/*$headerData['rightContent'] = array("From: ".date('d-m-Y', strtotime($startDate))." To: ".date('d-m-Y', strtotime($endDate)));*/
			//$headerData['leftContent'] = array("Left : value", "Left: value");

			//   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));

			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("itemCode"), 
										$this->lang->line("itemName"), 
										$this->lang->line("location"),
										$this->lang->line("um"),
										$this->lang->line("qthOH")
									); 
			$bodyData['selectFields'] = array("itemCode", 
										"name", 
										"descCode",
										"umCode",
										"quantityOnHand"
									);
			$bodyData ['tdAmount'] = array("quantityOnHand");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = $this->lang->line('titlelist');

			if(!$mode){
				//print
				$this->load->view('layouts/report/header', $headerData);
				$this->load->view('layouts/report/body', $bodyData);
				$this->load->view('layouts/report/footer','');
			}else{
				//download excell
				$this->load->helper('excel');
				excel($headerData,array($bodyData),$footerData);
			}
		}else{
			$data['datatbls'] = $this->ItemDetails->ItemOnHand();
			//Report printing
			$headerData['rptTitle'] = $this->lang->line('titlelist');
			/*$headerData['rightContent'] = array("From: ".date('d-m-Y', strtotime($startDate))." To: ".date('d-m-Y', strtotime($endDate)));*/
			//$headerData['leftContent'] = array("Left : value", "Left: value");

			//   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));

			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("itemCode"), 
										$this->lang->line("itemName"), 
										$this->lang->line("location"),
										$this->lang->line("um"),
										$this->lang->line("qthOH")
									); 
			$bodyData['selectFields'] = array("itemCode", 
										"name", 
										"descCode",
										"umCode",
										"quantityOnHand"
									);
			$bodyData ['tdAmount'] = array("quantityOnHand");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = $this->lang->line('titlelist');

			if(!$mode){
				//print
				$this->load->view('layouts/report/header', $headerData);
				$this->load->view('layouts/report/body', $bodyData);
				$this->load->view('layouts/report/footer','');
			}else{
				//download excell
				$this->load->helper('excel');
				excel($headerData,array($bodyData),$footerData);
			}
		}
	}
	
// Item Category
	public function itemCategoryList() {
			$this->load->model('UseraccessDetails');
        	$query = $this->UseraccessDetails->UseraccessDetails_id_code('ITEMCAT');
        	if (!$query) {
            	echo '<script>alert("Not authorised..");
					window.location.replace("' . base_url() . 'Error");
					</script>';
        	}
			$this->lang->load("itemCategory",$this->session->userdata('language'));
			$this->load->model('item/ItemSetup_model');
			$listData['title'] = $this->lang->line('titleCategory');
			//$filter['masterID']=8; //masterID=8 for itemCategory
			$listData['datatbls'] = $this->ItemSetup_model->getCategoryAll(); 
			$listData['New']='../icsetting/itemCategory/';
			$listData['Action']='Update';
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('item/itemCategList', array('latest' => 'sidebar/latest'), $listData);
	}
        
        public function delete_itemCateg() {
            $this->load->model('item/ItemSetup_model');
           $re =  $this->ItemSetup_model->updateItemCateg(array ("is_delete"=>1), $this->input->post('ID'));
           if ($re){
               echo "success";
           }else{
               echo "fail";
           }
        }
		
		public function itemdelete() {
            $this->load->model('item/ItemSetup_model');
           $re =  $this->ItemSetup_model->updateItem(array ("is_delete"=>1), $this->input->post('ID'));
           if ($re){
               echo "success";
           }else{
               echo "fail";
           }
        }

// Item Type	
	public function itemTypeList() {
			$this->load->model('UseraccessDetails');
        	$query = $this->UseraccessDetails->UseraccessDetails_id_code('ITEMTYP');
        	if (!$query) {
            	echo '<script>alert("Not authorised..");
					window.location.replace("' . base_url() . 'Error");
					</script>';
        	}
			$this->lang->load("masterCode",$this->session->userdata('language'));
			$this->load->helper('menu');
			$this->load->model('master/masterCode_model');
			$filter['masterID']=9; //masterID=9 for itemType
			//$listData = $this->masterCode_model->get_all($filter); 
			$listData['datatbls'] = $this->masterCode_model->get_all($filter);
			$listData['New'] = null;
			$listData['Action'] = null;
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('ic/setups/masterCodeList', array('latest' => 'sidebar/latest'), $listData);

			//echo json_encode(array("status"=>"success", "message"=>$listData));


	}
        
        public function itemcategory(){
		if($this->input->post('submit')){
			$this->load->model('item/itemSetup_model');
			if($this->input->post('masterCodeSetupID')==NULL){
				$newRow = array( 
						'code'		=> $this->input->post('code'),
						'name'		=> $this->input->post('name'),
						'shortName'		=> $this->input->post('shortName'),
						'description'		=> $this->input->post('description'),
                                                'companyID'=>  element('compID', $this->session->userdata('logged_in')),
						'orderNo'		=> $this->input->post('orderNo'),
		  				'createdBy'		=> element('userid', $this->session->userdata('logged_in')), 
		  				'createdTS'		=> $this->input->post('order_time') 
		  			);
					
		  			$res= $this->itemSetup_model->insertNewCateg($newRow);
					if($res){
						echo '<script>alert("Insert Data Success..");
						window.location.replace("itemCategoryList");
						</script>';
					}else{
						echo '<script>alert("Insert Data Failed.");
						history.go(-1);</script>';
					}
		 	}else{
					$ID = $this->input->post('masterCodeSetupID');
		  			$data = array(
						'code'		=> $this->input->post('code'),
						'name'		=> $this->input->post('name'),
						'shortName'		=> $this->input->post('shortName'),
						'description'		=> $this->input->post('description'),
                                                'companyID'=>  element('compID', $this->session->userdata('logged_in')),
						'orderNo'		=> $this->input->post('orderNo'),
		  				'updateBy'		=> element('role', $this->session->userdata('logged_in')), 
		  			);
					//$this->load->model(company/Company_info_model);
					$this->load->model('item/itemSetup_model');
		  			$update = $this->itemSetup_model->updateItemCateg($data, $ID);
					if($update){
						echo '<script>alert("Update Success..");
						window.location.replace("itemCategoryList");
						</script>';
					}
					else{
						echo '<script>alert("Update Failed.");
						history.go(-1);</script>';
					}
		  		}
	  		} 
			else 
			{     
				$id = isset($_REQUEST['id'])?$_REQUEST['id']:'';
				$data['masterID'] =  $this->uri->segment(3);
				$this->load->library('layouts');
				$this->load->model('item/ItemSetup_model');
				if($id){
					$dataum = $this->ItemSetup_model->getCategoryById($id);
                                        if ($dataum)
					$data['mcmaster'] = $dataum[0];
                                        else 
                                            $data['mcmaster'] = NULL;
				//echo $this->db->last_query();
				}else{
					$data['mcmaster'] = NULL;
				}
                                $this->lang->load("itemCategory",$this->session->userdata('language'));
				$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
					->add_includes('js/validationengine/jquery.validationEngine.js')
					->add_includes('js/datatables/jquery.dataTables.min.js');
					
					$this->layouts->view('item/itemcategory', array('latest' => 'sidebar/latest'), $data);
				
			}
	}
}
/* End of file icsetting.php */
/* Location: ./application/controller/icsetting.php */
