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

class Iao_ctrl extends user_icd_index {
 
	
	public function __construct(){
		parent::__construct();  
		$data = array();
		$this->load->model('admin_model');
		$this->load->model('icd_model');		
	}
	
	/*----------------- load gate1_entry_authorization_list page -----------------*/
	public function gate1_entry_authorization_list(){		
		$data['sdata'] 						= array();
		$data['subview'] 					= 'icd/iao/gate1_entry_authorization_list';		
		$data['active_cls'] 				= 'conedl_cls';	
		$data['url_list'] 					= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');		
		$data['sdata']['igedl_list'] 		= $this->icd_model->get_icd_igedl_details_list('','','','1','1','1','0');
		// echo $this->db->last_query();return;		

		$this->load->view('icd/common/icd_sidepanel',$data);  
	}
 
	/*----------------- load gate1_entry_authorization_form page -----------------*/
	public function gate1_entry_authorization_form($igedl_id){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/iao/gate1_entry_authorization_form';		
		$data['active_cls'] 	= 'dash';			 
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');			
	
		$data['sdata']['igedl_data'] 				= $this->icd_model->get_icd_igedl_details_list('',$igedl_id,'','1','1','1','0');
		$data['sdata']['iidl_list'] 				= $this->icd_model->get_icdl_iidl_details_list('',$igedl_id,'','1');
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- authorize_gate1_entry_details -----------------*/
	public function authorize_gate1_entry_details($igedl_id){		
		$data['igedl_details']['igedl_iao_id'] 		= $this->user['i_user_id'];
		$data['igedl_details']['igedl_iao_status'] 	= '1';
		$data['igedl_details']['igedl_iao_date'] 	= date("Y-m-d");
		
		$edit_igedl 			= $this->admin_model->update_data('icd_gate_entry_details_list','igedl_id',$igedl_id,$data['igedl_details']);	
				
		if($edit_igedl!='0'){
			$this->session->set_flashdata('tos_success', 'Details updated');
			redirect('icd/iao_ctrl/gate1_entry_authorization_list');		
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/iao_ctrl/gate1_entry_authorization_list');
		}		
	}
	

	/*----------------- load icd_out_gate_pass_authorization_print_out_list page -----------------*/
	public function icd_out_gate_pass_authorization_print_out_list(){		
		$data['sdata'] 						= array();
		$data['subview'] 					= 'icd/iao/icd_out_gate_pass_authorization_print_out_list';		
		$data['active_cls'] 				= 'conedl_cls';	
		$data['url_list'] 					= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');			
		$data['sdata']['igedl_list'] 		= $this->icd_model->get_icd_igedl_details_list('','','','1','1','1','1','1','1','1','1','0');			
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}
	 
	/*----------------- load icd_out_gate_pass_authorization_print_out_form page -----------------*/
	public function icd_out_gate_pass_authorization_print_out_form($igedl_id){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/iao/icd_out_gate_pass_authorization_print_out_form';		
		$data['active_cls'] 	= 'dash';			
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');					

		$data['sdata']['igedl_data'] 				= $this->icd_model->get_icd_igedl_details_list('',$igedl_id,'','1','1','1','1','1','1','1','1','0');
		$data['sdata']['iidl_list'] 				= $this->icd_model->get_icdl_iidl_details_list('',$igedl_id,'','1');
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}
	
	/*----------------- update_out_gate_pass_autho_print_out_details -----------------*/
	public function update_out_gate_pass_autho_print_out_details($igedl_id){
				
		$data['igedl_details']['igedl_iao_print_out_id'] 			= $this->user['i_user_id'];
		$data['igedl_details']['igedl_iao_print_out_status'] 		= '1';
		$data['igedl_details']['igedl_iao_print_out_date'] 		= date("Y-m-d");
		
		$edit_igedl 			= $this->admin_model->update_data('icd_gate_entry_details_list','igedl_id',$igedl_id,$data['igedl_details']);	
				
		if($edit_igedl!='0'){
			$this->session->set_flashdata('tos_success', 'Details updated');
			redirect('icd/icd_print_out_ctrl/out_gate_pass_icd_authorization_print_out/'.$igedl_id);		
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/iao_ctrl/icd_out_gate_pass_authorization_print_out_list');
		}		
	}

	/*----------------- load icd_container_out_approve_list page -----------------*/
	public function icd_container_out_approve_list(){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/iao/icd_container_out_approve_list';		
		$data['active_cls'] 	= 'conedl_cls';	
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');			
		if(isset($_POST['token_no_val'])){ 
			$token_no = $this->input->post('token_no_val');
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','',$token_no,'1','Local-Container&Material','1','1','1','1','1','0');
		}else if(!isset($_POST['token_no_val'])){		
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','','','1','Local-Container&Material','1','1','1','1','1','0');
		}
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- load icd_container_out_approve_form page -----------------*/
	public function icd_container_out_approve_form($igedl_id,$igetl_id){		
		$data['sdata'] 					= array();
		$data['subview'] 				= 'icd/iao/icd_container_out_approve_form';		
		$data['active_cls'] 			= 'dash';			
		$data['url_list'] 				= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');					
		$data['sdata']['agl_list'] 		= $this->admin_model->get_result_array('agent_list');	
		$data['sdata']['igetl_data'] 		= $this->icd_model->get_icdl_igetl_details_list('',$igedl_id,$igetl_id,'','1','Local-Container&Material','1','1','1','1','1','0');	

		$data['sdata']['itncl_list'] 	= $this->icd_model->get_icdl_itncl_details_list('',$igetl_id,'','1','','1');
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- update_icd_container_out_approve_details -----------------*/
	public function update_icd_container_out_approve_details($igetl_id){		
		
		$data['igetl_details']['igetl_icoa_iao_id'] 		= $this->user['i_user_id'];
		$data['igetl_details']['igetl_icoa_iao_status'] 	= '1';
		$data['igetl_details']['igetl_icoa_iao_date'] 	= date("Y-m-d");
		
		$edit_igetl 			= $this->admin_model->update_data('icd_gate_entry_token_list','igetl_id',$igetl_id,$data['igetl_details']);

		
				
		if($edit_igetl!='0'){
			$this->session->set_flashdata('tos_success', 'Details updated');
			redirect('icd/iao_ctrl/icd_container_out_approve_list');
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/iao_ctrl/icd_container_out_approve_list');
		}			
				
	}

	/*-----------load icd_out_local_extra_or_lcl_material_authorize_list page  -----------*/
	public function icd_out_local_extra_or_lcl_material_authorize_list(){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/iao/icd_out_local_extra_or_lcl_material_authorize_list';		
		$data['active_cls'] 	= 'conedl_cls';	
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');	
		if(isset($_POST['token_no_val'])){ 
			$token_no = $this->input->post('token_no_val');
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','',$token_no,'1','Local-LCL/Extra Material','1','1','1','1','','','','','','','','1','0');
		}else if(!isset($_POST['token_no_val'])){		
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','','','1','Local-LCL/Extra Material','1','1','1','1','','','','','','','','1','0');
		}		
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*---------- load icd_out_local_extra_or_lcl_material_authorize_form page  ----------*/
	public function icd_out_local_extra_or_lcl_material_authorize_form($igedl_id,$igetl_id){		
		$data['sdata'] 					= array();
		$data['subview'] 				= 'icd/iao/icd_out_local_extra_or_lcl_material_authorize_form';		
		$data['active_cls'] 			= 'dash';			
		$data['url_list'] 				= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');		
			
		$data['sdata']['agl_list'] 		= $this->admin_model->get_result_array('agent_list');	
		$data['sdata']['igetl_data'] 		= $this->icd_model->get_icdl_igetl_details_list('',$igedl_id,$igetl_id,'','1','Local-LCL/Extra Material','1','1','1','1','','','','','','','','1','0');				
		$data['sdata']['itncl_list'] 	= $this->icd_model->get_icdl_itncl_details_list('',$igetl_id,'','1','','1');
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*---------- update update_icd_out_localextraorlclmaterial_authorize_details details ----------*/
	public function update_icd_out_localextraorlclmaterial_authorize_details($igetl_id){		
		
			
		$data['igetl_details']['igetl_iolelmg_iao_id'] 		= $this->user['i_user_id'];
		$data['igetl_details']['igetl_iolelmg_iao_status'] 	= '1';
		$data['igetl_details']['igetl_iolelmg_iao_date'] 	= date("Y-m-d");
		
		$edit_igetl 			= $this->admin_model->update_data('icd_gate_entry_token_list','igetl_id',$igetl_id,$data['igetl_details']);
			
		if($edit_igetl!='0'){
			$this->session->set_flashdata('tos_success', 'Details updated');	
			redirect('icd/iao_ctrl/icd_out_local_extra_or_lcl_material_authorize_list');				
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/iao_ctrl/icd_out_local_extra_or_lcl_material_authorize_list');
		}			
				
	}

	/*--load icd_gpofvo_loacl_extra_lcl_authorize_list (gpofvo - gate pass of vehicle out) page  --*/
	public function icd_gpofvo_loacl_extra_lcl_authorize_list(){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/iao/icd_gpofvo_loacl_extra_lcl_authorize_list';		
		$data['active_cls'] 	= 'conedl_cls';	
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');			
		if(isset($_POST['token_no_val'])){ 
			$token_no = $this->input->post('token_no_val');
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','',$token_no,'1','Local-LCL/Extra Material','1','1','1','1','','','','','','','','1','1','1','1','1','1','0');
		}else if(!isset($_POST['token_no_val'])){		
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','','','1','Local-LCL/Extra Material','1','1','1','1','','','','','','','','1','1','1','1','1','1','0');
		}
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*-- load icd_gpofvo_loacl_extra_lcl_authorize_form (gpofvo - gate pass of vehicle out) page  --*/
	public function icd_gpofvo_loacl_extra_lcl_authorize_form($igedl_id,$igetl_id){		
		$data['sdata'] 					= array();
		$data['subview'] 				= 'icd/iao/icd_gpofvo_loacl_extra_lcl_authorize_form';		
		$data['active_cls'] 			= 'dash';			
		$data['url_list'] 				= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');		
			
		$data['sdata']['igetl_data'] 		= $this->icd_model->get_icdl_igetl_details_list('',$igedl_id,$igetl_id,'','1','Local-LCL/Extra Material','1','1','1','1','','','','','','','','1','1','1','1','1','1','0');		
		// echo $this->db->last_query();return;
		
		$data['sdata']['itncl_list'] 	= $this->icd_model->get_icdl_itncl_details_list('',$igetl_id,'','1','','1');
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*-- update_icd_gpofvo_loacl_extra_lcl_authorize_details (gpofvo - gate pass of vehicle out) --*/
	public function update_icd_gpofvo_loacl_extra_lcl_authorize_details($igetl_id){		
		$data['igetl_details'] = array(); 

		foreach($_POST as $post_key=>$post_rows){
			$data['igetl_details'][$post_key] 		= $this->input->post($post_key);			
		} 
		$data['igetl_details']['igetl_igpvolel_iao_id'] 		= $this->user['i_user_id'];
		$data['igetl_details']['igetl_igpvolel_iao_status'] 	= '1';
		$data['igetl_details']['igetl_igpvolel_iao_date'] 		= date("Y-m-d");
		
		$edit_igetl 			= $this->admin_model->update_data('icd_gate_entry_token_list','igetl_id',$igetl_id,$data['igetl_details']);
				
		if($edit_igetl!='0'){ 
			$this->session->set_flashdata('tos_success', 'Details updated');	
			redirect('icd/icd_print_out_ctrl/icd_gpofvo_loacl_extra_lcl_authorize_print_out/'.$igetl_id);					
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/iao_ctrl/icd_gpofvo_loacl_extra_lcl_authorize_list');
		}			
				
	}

	/*---------- update icd_out_vehicle_transit_empty_aproove_list details ----------*/
	public function icd_out_vehicle_transit_empty_aproove_list(){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/iao/icd_out_vehicle_transit_empty_aproove_list';		
		$data['active_cls'] 	= 'conedl_cls';	
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');			
		if(isset($_POST['token_no_val'])){ 
			$token_no = $this->input->post('token_no_val');
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','',$token_no,'1','Local-Empty Container','1','1','1','1','','','','','','','','','','','','','','','1','1','1','0');
		}else if(!isset($_POST['token_no_val'])){		
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','','','1','Local-Empty Container','1','1','1','1','','','','','','','','','','','','','','','1','1','1','0');
		}
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*---------- load icd_out_vehicle_transit_empty_aproove_form  page  ----------*/
	public function icd_out_vehicle_transit_empty_aproove_form($igetl_id){		
		$data['sdata'] 					= array();
		$data['subview'] 				= 'icd/iao/icd_out_vehicle_transit_empty_aproove_form';		
		$data['active_cls'] 			= 'dash';			
		$data['url_list'] 				= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');		
			
		$data['sdata']['igetl_data'] 		= $this->icd_model->get_icdl_igetl_details_list('','',$igetl_id,'','1','Local-Empty Container','1','1','1','1','','','','','','','','','','','','','','','1','1','1','0');			
		$data['sdata']['itncl_list'] 	= $this->icd_model->get_icdl_itncl_details_list('',$igetl_id,'','1','','1');
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*---------- update update_icd_out_vehicle_transit_empty_aproove_details details ----------*/
	public function update_icd_out_vehicle_transit_empty_aproove_details($igetl_id){		
		$data['igetl'] = array();

		foreach($_POST as $post_key=>$post_rows){
			$data['igetl'][$post_key] 		= $this->input->post($post_key);			
		}

		$data['igetl']['igetl_iovgete_aproove_iao_id'] 		= $this->user['i_user_id'];
		$data['igetl']['igetl_iovgete_aproove_iao_status'] 	= '1';
		$data['igetl']['igetl_iovgete_aproove_iao_date'] 	= date("Y-m-d");
		
		$edit_igetl 			= $this->admin_model->update_data('icd_gate_entry_token_list','igetl_id',$igetl_id,$data['igetl']);
				
		if($edit_igetl!='0'){
			$this->session->set_flashdata('tos_success', 'Details updated');	
			redirect('icd/icd_print_out_ctrl/icd_out_vehicle_transit_empty_aproove_print_out/'.$igetl_id);
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/iao_ctrl/icd_out_vehicle_transit_empty_aproove_list');
		}			
				
	}

	/*---------- update icd_out_transit_material_authorize_list details ----------*/
	public function icd_out_transit_material_authorize_list(){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/iao/icd_out_transit_material_authorize_list';		
		$data['active_cls'] 	= 'conedl_cls';	
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');			
		if(isset($_POST['token_no_val'])){ 
			$token_no = $this->input->post('token_no_val');
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','',$token_no,'2','Transit-Material','1','1','1','1','','','','','','','','','','','','','','','','','','','','','','1','0');
		}else if(!isset($_POST['token_no_val'])){		
			$data['sdata']['igetl_list'] 		= $this->icd_model->get_icdl_igetl_details_list('','','','','2','Transit-Material','1','1','1','1','','','','','','','','','','','','','','','','','','','','','','1','0');
		}
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*---------- load icd_out_transit_material_authorize_form  page  ----------*/
	public function icd_out_transit_material_authorize_form($igetl_id){		
		$data['sdata'] 					= array();
		$data['subview'] 				= 'icd/iao/icd_out_transit_material_authorize_form';		
		$data['active_cls'] 			= 'dash';			
		$data['url_list'] 				= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');	
		
		$data['sdata']['igetl_data'] 		= $this->icd_model->get_icdl_igetl_details_list('','',$igetl_id,'','2','Transit-Material','1','1','1','1','','','','','','','','','','','','','','','','','','','','','','1','0');			
		
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}
	
	/*----------------- add insert_transit_material_details  details -----------------*/
	public function insert_transit_material_details($igetl_id,$idl_id){		
		$data['igetl']['igetl_otm_iao_id'] 			= $this->user['i_user_id'];
		$data['igetl']['igetl_otm_iao_status'] 		= '1';
		$data['igetl']['igetl_otm_iao_date'] 			= date("Y-m-d");
		
		$edit_igetl 			= $this->admin_model->update_data('icd_gate_entry_token_list','igetl_id',$igetl_id,$data['igetl']);	


		$itml_goods_desc 			= $this->input->post('itml_goods_desc');
		$itml_uom 					= $this->input->post('itml_uom');
		$itml_packing_type 			= $this->input->post('itml_packing_type');
		$itml_qty 					= $this->input->post('itml_qty');
		$itml_remarks 				= $this->input->post('itml_remarks');
		
		foreach($itml_goods_desc as $icdl_key=>$icdl_row){				
			$data['itml_details']['itml_idl_id'] 		=  $idl_id;	
			$data['itml_details']['itml_igetl_id'] 		=  $igetl_id;			
			$data['itml_details']['itml_goods_desc'] 	=  $icdl_row;
			$data['itml_details']['itml_uom'] 			=  $itml_uom[$icdl_key];
			$data['itml_details']['itml_packing_type'] 	=  $itml_packing_type[$icdl_key];
			$data['itml_details']['itml_qty'] 			=  $itml_qty[$icdl_key];
			$data['itml_details']['itml_remarks'] 		=  $itml_remarks[$icdl_key];

			$add_itml 									= $this->admin_model->insert_item('icd_transit_material_list',$data['itml_details']);	
		}
				
		if($edit_igetl!='0'){
			$this->session->set_flashdata('tos_success', 'Material details added');
			redirect('icd/iao_ctrl/icd_out_transit_material_authorize_list');
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/iao_ctrl/icd_out_transit_material_authorize_list');
		}			
				
	}




}
