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

//1. onForm Open - to check in table comp_acct_det, if accountID hs trnsctn, then disabled combobox and updateable = NO.
//2. onForm Open - to check in comp_acct_setup, if updateable = NO, then disabled combobox

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

	public function index()
	{   		
			
	}
	
	public function generalSetup() {
		$this->load->model('systemgeneral/systemgeneral_model');
		if($this->input->post('mysubmit')){
//		echo var_dump($this->input->post());
			//index 0 = acctCode, 1=updateable, 2=ID
			$post = $this->input->post();
//			echo var_dump($post);
			//save record
			$i=0;
			foreach ($post as $key => $val) {
				//omit first 2 array
//				echo '<br>key='.$key.' val='.$val;
//			echo var_dump($val);
				if ($i > 1 && $i < sizeof($post) -1) 
					$this->systemgeneral_model->updateAccountCode1($key,$val);
				$i++;
			}
	
		} //end submit
			$this->lang->load("systemgeneral",$this->session->userdata('language'));
			$this->load->library('layouts');
			$this->load->helper('form');
			$this->load->model('systemgeneral/systemgeneral_model');
			$dataum = $this->systemgeneral_model->sysgetall_bycompanyID();
			echo $this->db->last_query();
//			if (!$dataum){
//			}
			$data['generalsetup'] = $dataum;
//			echo $this->db->last_query();
//			var_dump($dataum);
//			echo $this->db->last_query();
			$data['sysgen'] = '';
			$this->load->model('Chartofaccount');
			$data['chartAccounts'] = $this->Chartofaccount->chartofaccount_byAcctCode();
//			echo $this->db->last_query();
			$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
			->add_includes('js/validationengine/jquery.validationEngine.js');
			$this->layouts->view('sysgen/genList', array('latest' => 'sidebar/latest'),$data);
		}


}