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

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

	public function index()
	{   		
	}
	
	//--New Bank Setup--\\
	public function BankNew()
	{
	  if($this->input->post('mysubmit')){
		  if($this->input->post('ID')==NULL){
			  $newbank = array(
			  	'ID'		=> $this->input->post('ID'),
				'companyID'		=> element('compID', $this->session->userdata('logged_in')), 
			  	'bankName'		=> $this->input->post('bankName'), 
			  	'bankShortName'		=> $this->input->post('bankShortName'),
				'branch'		=> $this->input->post('branch'),
				'bankAccountNo'		=> $this->input->post('bankAccountNo'), 
				'currentBalance'		=> $this->input->post('currentBalance'),
				'line1'		=> $this->input->post('line1'),
				'line2'		=> $this->input->post('line2'),
				'line3'		=> $this->input->post('line3'),
				'PostCode'		=> $this->input->post('PostCode'),
				'city'		=> $this->input->post('city'),
				'bankStateID'		=> $this->input->post('bankStateID'),
				'bankcountryID'		=> $this->input->post('bankCountryID'),
				'attention'		=> $this->input->post('attention'),
				'phonenumber1'		=> $this->input->post('phonenumber1'),
				'phonenumber2'		=> $this->input->post('phonenumber2'),
				'fax'		=> $this->input->post('fax'),
				'generalNote'		=> $this->input->post('generalNote'),
				'creditLimit'		=> $this->input->post('creditLimit'),
				'creditLimitAlert'		=> $this->input->post('creditLimitAlert'),
				'linkAccountID'		=> $this->input->post('linkAccountID'),
				'createdDate'		=> $this->input->post('createdDate'),
				'currencyID'		=> $this->input->post('currencyID'),
				'email'		=> $this->input->post('email'),

						
		
		  	);
			$this->load->model('bank/bank_model');
		  	$insert_bank = $this->bank_model->bank_insert($newbank);
			if($insert_bank){
				echo '<script>alert("Insert Data Success..");
				window.location.replace("banklist");
				</script>';
			}else{
				echo '<script>alert("Insert Data Failed.");
				history.go(-1);</script>';
			}
		  }
		  else{
			$ID = $this->input->post('ID');
		  	$newbank = array(
				 	'ID'		=> $this->input->post('ID'),
				'companyID'		=> element('compID', $this->session->userdata('logged_in')), 
			  	'bankName'		=> $this->input->post('bankName'), 
			  	'bankShortName'		=> $this->input->post('bankShortName'),
				'branch'		=> $this->input->post('branch'),
				'bankAccountNo'		=> $this->input->post('bankAccountNo'), 
				'currentBalance'		=> $this->input->post('currentBalance'),
				'line1'		=> $this->input->post('line1'),
				'line2'		=> $this->input->post('line2'),
				'line3'		=> $this->input->post('line3'),
				'PostCode'		=> $this->input->post('PostCode'),
				'city'		=> $this->input->post('city'),
				'bankStateID'		=> $this->input->post('bankStateID'),
				'bankcountryID'		=> $this->input->post('bankCountryID'),
				'attention'		=> $this->input->post('attention'),
				'phonenumber1'		=> $this->input->post('phonenumber1'),
				'phonenumber2'		=> $this->input->post('phonenumber2'),
				'fax'		=> $this->input->post('fax'),
				'generalNote'		=> $this->input->post('generalNote'),
				'creditLimit'		=> $this->input->post('creditLimit'),
				'creditLimitAlert'		=> $this->input->post('creditLimitAlert'),
				'linkAccountID'		=> $this->input->post('linkAccountID'),
				'createdDate'		=> $this->input->post('createdDate'),
				'currencyID'		=> $this->input->post('currencyID'),
				'email'		=> $this->input->post('email'),
			
		  	);
			$this->load->model('bank/bank_model');
			$insert_bank = $this->bank_model->bank_edit($newbank, $ID);
			if($insert_bank){
				echo '<script>alert("Update Success..");
					window.location.replace("banklist");
					</script>';
			}else{
				echo '<script>alert("Update Failed.");
				history.go(-1);</script>';
			}
		  }
		   } else {     
		$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']:"";
		$this->lang->load("bank",$this->session->userdata('language'));
		$this->load->model('bank/bank_model');
		$this->load->model('Country');
		$data['country'] = $this->Country->country_all();
		$this->load->model('Currency');
		$data['currency'] = $this->Currency->currency_all();
		$this->load->model('State');
		$this->load->model('master/masterCode_model');
		$filter['masterID']=5;
		$data['gender'] = $this->masterCode_model->get_all($filter);;
		$this->load->model('Chartofaccount');
		$data['chartAccounts'] = $this->Chartofaccount->chartofaccount_all();
		$this->load->model('company/companyControlAcctSetup_model');
		$data['defaultacct'] = $this->companyControlAcctSetup_model->get_byCode('rcvacct');
		
		$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
			->add_includes('js/validationengine/jquery.validationEngine.js');
			
		if($ID >= '0'){
			$dataum = $this->bank_model->bank_id($ID);
			$data['bankmaster'] = $dataum[0];
			$data['state'] = $this->State->state_region($dataum[0]->bankCountryID);
			$this->layouts->view('bank/add_new', array('latest' => 'sidebar/latest'), $data);
		}else{
			$data['state'] = $this->State->state_region('458');
			$data['bankmaster'] = '';
			$this->layouts->view('bank/add_new', array('latest' => 'sidebar/latest'), $data);
		}
						
			}
	}
	public function bank_delete(){
			$this->load->model('bank/bank_model');
		  	$deletebank = array('is_delete' => '1');
			$ID = $this->input->post('ID');
		  	$delete_bank = $this->bank_model->bank_delete($deletebank, $ID);
			if($delete_bank){
				return TRUE;
			}else{
				return FALSE;
			}
	}

	public function bank_edit(){
			$this->load->model('bank/bank_model');
		  	$updatebank = array('is_delete' => '1');
			$ID = $this->input->post('ID');
		  	$updatebank = $this->bank_model->bank_edit($updatebank,$ID);
			if($updatebank){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	public function bankList(){
		$this->load->model('bank/bank_model');
		$data['datatbls'] = $this->bank_model->bank_all();
		$this->lang->load("bank",$this->session->userdata('language'));
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('bank/list', array('latest' => 'sidebar/latest'), $data);
	}
	
	//public function bank_allopt(){
		//$this->load->model('bank/bank_model');
		//$query = $this->bank_model->bank_allopt();
		//header('Content-Type: application/json');
       // echo json_encode($query);		
		//return TRUE;
	//}
	
	 public function rptBank (){
		 
			//$headerData['id'] = $id;
			$this->load->model('company/company_info_model');
            $this->load->model('bank/bank_model');
			$this->load->model('State');
            $this->lang->load("bank",$this->session->userdata('language'));
          
            
             $headerData['rightContentHeader'] = "";
             $headerData['rptTitle'] = "Bank Master List";
             $headerData['rightContent'] = array("As at: ".date("d-m-Y"));
             $headerData['leftContent'] = array("Bank Listing : All");
             
             $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
              
             $bodyData['rptDataDetail'] = $this->bank_model->bank_all();
             $bodyData['tableHeader'] = array("Bank Name", "Branch", "Bank Account No", "Phone Number", "Fax","Email"); 
             $bodyData['selectFields'] = array("bankName", "branch", "bankAccountNo","phoneNumber1","fax", "email");
          
            
            $this->load->view('layouts/report/header', $headerData);
            $this->load->view('layouts/report/body', $bodyData);
            $this->load->view('layouts/report/footer','');
        }
}

	 