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

class setup extends CI_Controller {

	public function __construct(){
		parent::__construct();
		/*$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('1', 'reports');
		if(!$query){
			echo '<script>alert("Not authorised..");
				window.location.replace("'.base_url().'Error");
				</script>';
		}*/
		$this->load->library('layouts');
    $this->load->model('general_model');
		$this->load->model('company/company_info_model');
		//$this->load->model('menu');
	}

	public function index()
	{
//		var_dump($this->session->userdata('logged_in'));
	}

	/**
	* REVIEW
	* METHOD FOR SETUP REVIEW ITEMS
	* @author : Farouq Zakwan (12/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- remove load 'layouts' library because already loaded in __construct
	*									- change view path from 'setup_review' to 'setup/setup_review'
	*/
	public function review($value='') {			
		//list all project
		$data['ps'] = $this->general_model->get_all('project','ID');
		//list all project review 
		$data['rs'] = $this->general_model->get_byFilter('_ref_review',array(),$filter=array('projectID'=>$value),$join=array(),$order=array());
		//list all method
		$data['method'] = $this->general_model->get_all('_ref_method');

		$Pchoose = $this->general_model->get_byFilter('project',$select=array('ID','title'),$filter=array('ID' => $value),$join=array(),$order=array());
		$data['Pchoose'] = ($Pchoose)?$Pchoose[0]->title:'Pilih projek';
		$data['Pid'] = ($Pchoose)?$Pchoose[0]->ID:null;

		$this->layouts->view('setup/setup_review',array(),$data);
	}

	/**
	* ADDREVIEWITEM
	* METHOD TO ADD NEW REVIEW ITEM
	* @author : Farouq Zakwan (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*/	
	public function addReviewItem($value='') {
		$title = $this->input->post('a');
		$itemNo = $this->input->post('b');
		$rule = $this->input->post('c');
		$parentID = $this->input->post('d');
		$method = $this->input->post('e');

		$data = array(
			'parentID' => $parentID,
			'projectID' => $title,
			'methodID' => $method,
			'code' => $itemNo,
			'text' => $rule,
		);
	
		$this->general_model->insert('_ref_review',$data);	
	}

	/**
	* EDITREVIEW
	* METHOD TO EDIT REVIEW ITEM
	* @author : Farouq Zakwan (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*/	
	public function editReview($value='') {
			$id = $this->input->post('a');
			$code = $this->input->post('b');
			$title = $this->input->post('c');

			$data = array( 	'code' => $code, 'text' => $title );
			
			$this->general_model->update('_ref_review', $data, array('ID'=>$id));
	}

	/**
	* DELETEREVIEW
	* METHOD TO DELETE REVIEW ITEM
	* @author : Farouq Zakwan (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- remove load 'layouts' library because already loaded in __construct
	*/	
	public function deleteReview($value='') {
		$data['ps'] = $this->general_model->get_all('project','ID');
		$Pchoose = $this->general_model->get_byFilter('project',$select=array('ID','title'),$filter=array('ID' => $value),$join=array(),$order=array());
		$data['Pchoose'] = ($Pchoose)?$Pchoose[0]->title:'Pilih projek';
		$data['Pid'] = ($Pchoose)?$Pchoose[0]->ID:null;

		$textValue = $this->input->post('a');
		$code = $this->input->post('b');
		$idProject = $this->input->post('c');

		$this->db->delete('_ref_review',array('ID' => $code));

		return;
	}

	/**
	* REVIEWTABLE
	* METHOD TO DISPLAY REVIEW ITEMS BY PROJECT
	* @author : Farouq Zakwan (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- remove load 'layouts' library because already loaded in __construct
	* @note : METHOD OBSOLETED (18/08/2016 - Farouq Zakwan)
	*/	
	public function reviewTable($value='') {
		return;
		$id = $this->input->post();
		$data['rs'] = $this->general_model->get_byFilter('_ref_review',array(),$filter=array('projectID'=>$id),$join=array(),$order=array());
		$this->load->view('setupReview/tabledata');
	}

	/**
	* ADDPROJECT
	* METHOD TO ADD A NEW PROJECT
	* @author : Farouq Zakwan (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- remove load 'layouts' library because already loaded in __construct
	*/	
	public function addProject($value='') {
			$title = $this->input->post('a');
			$data = array( 'title' => $title );

			$this->general_model->insert('project',$data);		
	}
	/**
	* GETREVIEWLIST
	* AJAX TO GET PARENT DROPDOWN 
	* @author : Farouq Zakwan (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- remove load 'layouts' library because already loaded in __construct
	*/
	public function getReviewList($value='')
	{
		$methodID = $this->input->post('a');
		$projectID = $this->input->post('b');

		$this->load->model('general_model');

		$data = $this->general_model->get_byFilter($tname='_ref_review',$select=array('ID','text'),$filter=array('methodID'=>$methodID,'projectID'=>$projectID,'is_delete' => 0),$join=array(),$order=array('projectID','code'));

		print json_encode(array("status"=>"success","message"=>$data));
	}

	/**
	* SUBREVIEW
	* METHOD FOR SETUP SUB-REVIEW ITEMS
	* @author : Abu Aiman (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- remove load 'layouts' library because already loaded in __construct
	*									- change view path from 'review_detail_setup' to 'setup/review_detail_setup'
	*								 Abu Aiman (22/08/2016)
	*								 Abu Aiman (29/08/2016)
	*/	
	public function subreview( $ID = 0 ){
		$this->lang->load("kelayakan", $this->session->userdata('language'));
		$rsSemak = $this->general_model->get_byFilter($tname='_ref_review',$select=array('parentID','code','text'),$filter=array('ID'=>$ID),$join=array(),$order=array('ID')) ;
		$data['semak'] = ($rsSemak)?'Item '.$rsSemak[0]->parentID.''.$rsSemak[0]->code.' : '.$rsSemak[0]->text:'Klik sini untuk pilih senarai semak';
		$data['rs'] = $this->general_model->get_byFilter($tname='_ref_review_detail',$select=array('*'),$filter=array('reviewID'=>$ID,'is_delete'=>0),$join=array(),$order=array('ID')) ;
		$data['attachment'] = $this->general_model->get_byFilter($tname='review_attachment',$select=array('*'),$filter=array('reviewID'=>$ID),$join=array(),$order=array('ID')) ;
		$data['rsSemak'] = $this->general_model->get_all($tname='_ref_review',$orderBy='ID');
		//$data['ID'] = $ID;
		$this->layouts->view('setup/review_detail_setup',array(),$data);
	}	


	/**
	* DELETESUBREVIEW
	* METHOD FOR DELETE SUB-REVIEW ITEM
	* @author : Abu Aiman (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- change method name from "delete" to "deletesubreview"
	*								 Abu Aiman (22/08/2016)
	*/	
	public function deletesubreview() //delete row of _ref_review_detail by abu
	{
		$data = array(
					'ID'=> $this->input->post('a'),
					'is_delete'=> $this->input->post('b')
					);
		$result = $this->general_model->update($tname='_ref_review_detail',$data,array('ID'=>$this->input->post('a')));
		$id = ($result)? $this->db->insert_ID() : 0;
		$rs = $this->general_model->get_byFilter($tname='_ref_review_detail',$select=array('*'),$filter=array('ID'=>$id,'is_delete'=>0),$join=array(),$order=array('ID')) ;				
		echo json_encode($rs[0]);		
		//echo ($result) ? "SUCCESS" : "FAIL";
		$this->layouts->view('setup/review_detail_setup',array(),$data);
	}
		

	/**
	* INSERTSUBREVIEW
	* METHOD FOR INSERT SUB-REVIEW ITEM
	* @author : Abu Aiman (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*									- change method name from "insert" to "insertsubreview"
	*								 Abu Aiman (22/08/2016)
	*/	
	public function insertsubreview() {
		$data = array(
					//'ID'=> $this->input->post('a'),
					'reviewID'=> $this->input->post('b'),
					'text'=> $this->input->post('c')
					);
		$result = $this->general_model->insert($tname='_ref_review_detail',$data);
		// DAPATKAN DATA BARU BASED ON ID BARU GENERATE
		$id = ($result)? $this->db->insert_ID() : 0;
		$rs = $this->general_model->get_byFilter($tname='_ref_review_detail',$select=array('*'),$filter=array('ID'=>$id,'is_delete'=>0),$join=array(),$order=array('ID')) ;				
		echo json_encode($rs[0]);				
	}
	
		

	/**
	* UPDATEROW
	* METHOD FOR UPDATE SUB-REVIEW ITEM
	* @author : Abu Aiman (18/08/2016)
	* @last-update : Zul Zolkaffly (19/08/2016)
	*									- Copy method from orig author to actual controller
	*									- remove load 'general_model' model because already loaded in __construct
	*								 Abu Aiman (22/08/2016)
	*/	
	public function updateRow() {
		$data = array(
					'ID'=> $this->input->post('a'),
					'reviewID'=> $this->input->post('b'),
					'text'=> $this->input->post('c')
					);
		$this->general_model->update($tname='_ref_review_detail',$data,array('ID'=>$this->input->post('a')));
		//echo ($result)? "SUCCESS" : "FAIL";							
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	* NOTE: Zul Zolkaffly (19/08/2016) - Don't think the methods below are applicable
	*/

	function unformat($amt) {
    return str_replace(array(' ', ','), '', $amt);
   }

	public function companySetup(){

		$this->lang->load("companyInfo",$this->session->userdata('language'));

		$ID = element('compID', $this->session->userdata('logged_in'));

		if($this->input->post('mysubmit')){

			$this->load->model('Gallery_company');
			$image_name = $this->Gallery_company->do_upload($ID);

			$companyinfo = array(
				'companyName'	=> $this->input->post('companyName'),
				'line1'		=> $this->input->post('line1'),
				'line2'		=> $this->input->post('line2'),
				'line3'		=> $this->input->post('line3'),
				'city'		=> $this->input->post('city'),
				'companyPostCode'		=> $this->input->post('companyPostCode'),
				'companyStateID'		=> $this->input->post('stateID'),
				'countryID'		=> $this->input->post('countryID'),
				'parlimenID'		=> $this->input->post('parlimenID'),
				'phoneNo'	=> $this->input->post('phoneNo'),
				'faxNo'	=> $this->input->post('faxNo'),
				'email'		=> $this->input->post('email'),
				'incorporateDate'    => date("Y-m-d", strtotime($this->input->post('incorporateDate'))),
				'businessTypeID'    => $this->input->post('businessTypeID'),
				'businessIndustryID'    => $this->input->post('industryID'),
				'currencyID'		=> 1,
				'uploadLogo'    => $image_name,
				'updatedBy'		=> element('userid', $this->session->userdata('logged_in')),
			);


			$this->load->model('company/Company_info_model');
			$update_companyID = $this->Company_info_model->company_edit($companyinfo, $ID);
			
			$update_companyID2 = $this->Company_info_model->company_editMaster($companyinfo, $ID);

			if($update_companyID){

				echo '<script>alert("Update Success..");
					window.location = "companySetup";
					</script>';
			}else{
				echo '<script>alert("Update Failed.");
				history.go(-1);</script>';
			}

		}
		else{
			$this->load->model('company/company_info_model');

			$data['comID'] = $ID;

			$data['company'] = $this->company_info_model->company_ByID();
			if (!$data['company']) {
				echo '<script>alert("company info not exist. Please contact the system admin");</script>';
				return false;
			}

			$this->load->model('Country');
			$data['country'] = $this->Country->country_all();

			$this->load->model('State');
			$data['state'] = $this->State->state_region('458');
			
			$data['parlimen'] = $this->State->getParlimen_byID($data['company'][0]->companyStateID);

			$data['businessIndustry'] = $this->company_info_model->getBusinessIndustry();
			
			$data['businessType'] = $this->company_info_model->getBusinessType();

			$this->lang->load("companyInfo",$this->session->userdata('language'));
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('setup/companyEdit', array('Menu'=>'layouts/menu'), $data);
		}
	}

	public function getState()
	{
		$region = $this->input->post('region');
    	$this->load->model('State');
    	$data['statelist']=$this->State->state_region($region);
    	print json_encode(array("status"=>"success", "message"=>$data['statelist']));
	}


	public function getParlimen()
	{
		$stateID = $this->input->post('stateID');
    	$this->load->model('State');
    	$parlimen = $this->State->getParlimen_byID($stateID);
    	print json_encode(array("status"=>"success", "message"=>$parlimen));
	}


	public function getBusinessType()
	{
		$industryID = $this->input->post('industryID');
    	$this->load->model('company/company_info_model');
    	$businessType = $this->company_info_model->getBusinessType_ByIndustryID($industryID);
    	print json_encode(array("status"=>"success", "message"=>$businessType));
	}

	public function saveCompany(){
		$this->lang->load("companyInfo",$this->session->userdata('language'));

		$ID = $this->uri->segment(3);

		if($ID){
			$fad = $ID;
		}
		else{
			$fad = NULL;
		}

        if($this->input->post('mysubmit')){

			$companyinfo = array(
				'companyName'	=> $this->input->post('companyName'),
				'line1'		=> $this->input->post('line1'),
				'line2'		=> $this->input->post('line2'),
				'line3'		=> $this->input->post('line3'),
				'city'		=> $this->input->post('city'),
				'companyPostCode'		=> $this->input->post('companyPostCode'),
				'companyStateID'		=> $this->input->post('stateID'),
				'countryID'		=> $this->input->post('countryID'),
				'phoneNo'	=> $this->input->post('phoneNo'),
				'faxNo'	=> $this->input->post('faxNo'),
				'email'		=> $this->input->post('email'),
				'businessTypeID'    => $this->input->post('businessTypeID'),
				'uploadLogo'		=> $this->input->post('userfile'),
				'currencyID'		=> 1,
				'createdBy'		=> element('userid', $this->session->userdata('logged_in')),
				'createdTS'		=> $this->input->post('order_time')
			);

			$this->load->model('company/company_info_model');

			$new_companyID = $this->company_info_model->companyInsert($companyinfo);

			if($new_companyID){
				$this->load->model('gallery_company');
				// $this->gallery_company->do_upload($new_companyID);

				echo '<script>alert("Sava Success..");
					window.location = "'.base_url().'admin/company";
					</script>';

		 	}

		}
		else{

			$this->load->model('company/company_info_model');
			$data['company'] = $this->company_info_model->company_ByID();

			$data['comID'] = $fad;

			$this->load->model('Country');
			$data['country'] = $this->Country->country_all();

			$this->load->model('State');
			$data['state'] = $this->State->state_region('458');

			$data['businessType'] = $this->company_info_model->getBusinessType();

			$this->lang->load("companyInfo",$this->session->userdata('language'));
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('setup/companySetup', array('Menu'=>'layouts/menu'), $data);

		}

	}


	public function editCompany(){
		$this->lang->load("companyInfo",$this->session->userdata('language'));


		$this->load->model('company/company_info_model');

		$ID = $this->company_info_model->companymaster_id($this->uri->segment(3));

		if($this->input->post('mysubmit')){

			$cid = $this->input->post("ID");
			$this->load->model('Gallery_company');
			$image_name = $this->Gallery_company->do_upload($cid);
			// var_dump($image_name);
			// exit();

			$companyinfo = array(
				// 'ID'		    => $ID,
				'companyName'	=> $this->input->post('companyName'),
				'line1'		=> $this->input->post('line1'),
				'line2'		=> $this->input->post('line2'),
				'line3'		=> $this->input->post('line3'),
				'city'		=> $this->input->post('city'),
				'companyPostCode'		=> $this->input->post('companyPostCode'),
				'companyStateID'		=> $this->input->post('stateID'),
				'countryID'		=> $this->input->post('countryID'),
				'phoneNo'	=> $this->input->post('phoneNo'),
				'faxNo'	=> $this->input->post('faxNo'),
				'email'		=> $this->input->post('email'),
				'businessTypeID'    => $this->input->post('businessTypeID'),
				'currencyID'		=> 1,
				'uploadLogo'    =>  $image_name,
				'updatedBy'		=> element('userid', $this->session->userdata('logged_in')),
			);


			$this->load->model('company/Company_info_model');
			$update_companyID = $this->Company_info_model->company_edit($companyinfo, $cid);


			if($update_companyID){

				echo '<script>alert("Update Success..");
					window.location = "'.base_url().'admin/company";
					</script>';
			}else{
				echo '<script>alert("Update Failed.");
				history.go(-1);</script>';
			}

		}
		else{
			$this->load->model('company/company_info_model');

			$data['comID'] = $ID;

			//var_dump($data['comID'] );


			$data['company'] = $this->company_info_model->companyById($this->uri->segment(3));

			//var_dump($data['company']);
			// exit();

			$this->load->model('Country');
			$data['country'] = $this->Country->country_all();

			$this->load->model('State');
			$data['state'] = $this->State->state_region('458');

			$data['businessType'] = $this->company_info_model->getBusinessType();

			$this->lang->load("companyInfo",$this->session->userdata('language'));
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('setup/companyEdit', array('Menu'=>'layouts/menu'), $data);
		}


	}

	public function userEditCompany(){
		$this->lang->load("companyInfo",$this->session->userdata('language'));


		$this->load->model('company/company_info_model');

		//$ID = $this->company_info_model->companymaster_id($this->uri->segment(3));
		$ID =  element('compID', $this->session->userdata('logged_in'));
		if($this->input->post('mysubmit')){

			//$cid = $this->input->post("ID");
			$cid = element('compID', $this->session->userdata('logged_in'));
			$this->load->model('Gallery_company');
			$image_name = $this->Gallery_company->do_upload($cid);

			$companyinfo = array(
				// 'ID'		    => $ID,
				'companyName'	=> $this->input->post('companyName'),
				'line1'		=> $this->input->post('line1'),
				'line2'		=> $this->input->post('line2'),
				'line3'		=> $this->input->post('line3'),
				'city'		=> $this->input->post('city'),
				'companyPostCode'		=> $this->input->post('companyPostCode'),
				'companyStateID'		=> $this->input->post('stateID'),
				'countryID'		=> $this->input->post('countryID'),
				'phoneNo'	=> $this->input->post('phoneNo'),
				'faxNo'	=> $this->input->post('faxNo'),
				'email'		=> $this->input->post('email'),
				'businessTypeID'    => $this->input->post('businessTypeID'),
				'currencyID'		=> 1,
				'uploadLogo'    =>  $image_name,
				'updatedBy'		=> element('userid', $this->session->userdata('logged_in')),
			);


			$this->load->model('company/Company_info_model');
			$update_companyID = $this->Company_info_model->company_edit($companyinfo, $cid);


			if($update_companyID){

				echo '<script>alert("Update Success..");
					window.location = "'.base_url().'home";
					</script>';
			}else{
				echo '<script>alert("Update Failed.");
				history.go(-1);</script>';
			}

		}
		else{
			$this->load->model('company/company_info_model');

			$data['comID'] = $ID;

// var_dump($data['comID'] );
// exit();

			//$data['company'] = $this->company_info_model->companyById($this->uri->segment(3));
			$data['company'] = $this->company_info_model->companyById($ID);
			// var_dump($data['company']);
			// exit();

			$this->load->model('Country');
			$data['country'] = $this->Country->country_all();

			$this->load->model('State');
			$data['state'] = $this->State->state_region('458');

			$data['businessType'] = $this->company_info_model->getBusinessType();

			$this->lang->load("companyInfo",$this->session->userdata('language'));
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('setup/companyEdit', array('Menu'=>'layouts/menu'), $data);
		}


	}


	public function loanSetup(){

		$this->load->model('loan/loan_model');
		$data['datatbls'] = $this->loan_model->chartOfAcctLoan_all();

		$this->lang->load("loan",$this->session->userdata('language'));
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('setup/loanSetup', array('Menu'=>'layouts/menu'), $data);
	}

	public function saveLoan(){

		$ID = $this->input->post('ID');
		$acctName = $this->input->post('acctName');
		$openingBalanceCr = $this->input->post('openingBalanceCr');
		$createdTS = $this->input->post('createdTS');
		$is_delete = $this->input->post('is_delete');

		$datainsert = array(
			'acctName' => $acctName,
			'openingBalanceCr' => $this->unformat($openingBalanceCr),
			'createdTS' => date("Y-m-d H:i:s", strtotime($createdTS)),
			'is_delete' => $is_delete,
		);

		$this->load->model('loan/loan_model');
		$query = $this->loan_model->updateLoan("comp_chart_of_acct", $datainsert, $ID);


		if($query){
			print json_encode(array("status"=>"success", "message"=>$datainsert));
		}else{
			print json_encode(array("status"=>"failed", "message"=>$this->lang->line('failed')));
		}
	}

	public function assetSetup(){

		$this->load->model('asset/asset_model');
		$companyID = $ID = element('compID', $this->session->userdata('logged_in'));
		$this->db->query('insert into comp_chart_of_acct (companyID, acctGroupID,acctCode, acctName) select '.$companyID.', acctGroupID,acctCode, acctName from _ref_chart_of_acct where acctCode not in (select acctCode from comp_chart_of_acct where companyID = '.$companyID.')');
//	echo $this->db->last_query(); 
		$data['datatbls'] = $this->asset_model->chartOfAcctLoan_all();

		$this->lang->load("asset",$this->session->userdata('language'));
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('setup/assetSetup', array('Menu'=>'layouts/menu'), $data);
	}

	public function saveAsset(){

		$ID = $this->input->post('ID');
		$acctName = $this->input->post('acctName');
		$openingBalanceDr = $this->input->post('openingBalanceDr');
		$createdTS = $this->input->post('createdTS');
		$is_delete = $this->input->post('is_delete');

		$datainsert = array(
			'acctName' => $acctName,
			'openingBalanceDr' => $openingBalanceDr,
			'createdTS' => date("Y-m-d H:i:s", strtotime($createdTS)),
			'is_delete' => $is_delete,
		);

		$this->load->model('asset/asset_model');
		$query = $this->asset_model->updateAsset("comp_chart_of_acct", $datainsert, $ID);


		if($query){
			print json_encode(array("status"=>"success", "message"=>$datainsert));
		}else{
			print json_encode(array("status"=>"failed", "message"=>$this->lang->line('failed')));
		}
	}

	public function expensesSetup(){

		$this->load->model('expenses/expenses_model');
		$data['datatbls'] = $this->expenses_model->chartOfAcctLoan_all();

		$this->lang->load("expenses",$this->session->userdata('language'));
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('setup/expensesSetup', array('Menu'=>'layouts/menu'), $data);
	}

	public function saveExpenses(){

		$ID = $this->input->post('ID');
		$is_delete = $this->input->post('is_delete');

		$datainsert = array(
			'is_delete' => $is_delete,
		);

		$this->load->model('expenses/expenses_model');
		$query = $this->expenses_model->updateExpenses("comp_chart_of_acct", $datainsert, $ID);


		if($query){
			print json_encode(array("status"=>"success", "message"=>$datainsert));
		}else{
			print json_encode(array("status"=>"failed", "message"=>$this->lang->line('failed')));
		}
	}

	public function search() {
        /* $id = $this->input->post('search_text');
          $length = strlen($id);
          $searchdata = substr($id, 1, $length);

          var_dump($searchdata);

          switch ($id[0]) {
          case 'M':
          $this->load->model('SysMenu');
          $query = $this->SysMenu->menuMaster_menu($searchdata);
          echo '<script>window.location.replace("' . base_url() . '' . $query[0]->urls . '")</script>';
          break;
          }
         * */
        $this->load->library('layouts');
        $this->load->model('menu');

        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
        $searchdata = $this->input->post('search_text');
        $data["searchKey"] = $searchdata;
        $data["searchResult"] = $this->menu->doResearch($searchdata);


        $this->layouts->view('layouts/searchpage', '', $data);
    }
	
	
	public function updateCompany(){
		
		$businessIndustry = $this->input->post('businessIndustry');
		$businessType = $this->input->post('businessType');
		$incorporateDate = $this->input->post('incorporateDate');
		
		$ID = element('compID', $this->session->userdata('logged_in'));
		
		$data = array(
					'businessIndustryID' => $businessIndustry,
					'businessTypeID' => $businessType,
					'incorporateDate' => date('Y-m-d', strtotime($incorporateDate))
				);
		
		$update_companyID = $this->company_info_model->company_edit($data, $ID);
			
		$update_companyID2 = $this->company_info_model->company_editMaster($data, $ID);
		
		$this->session->set_userdata('industryType', $this->input->post('businessIndustry'));
		$this->session->set_userdata('businessType', $this->input->post('businessType'));
		$this->session->set_userdata('incorporateDate', $this->input->post('incorporateDate'));
		
		if($update_companyID){
			print json_encode(array("status"=>"success"));
		}else{
			print json_encode(array("status"=>"failed"));
		}
		
	}


}


/* End of file gltransaction.php */
/* Location: ./application/controller/gltransaction.php */
