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

class Cvao_ctrl extends user_icd_index {
 
	
	public function __construct(){
		parent::__construct();   
		$data = array();
		$this->load->model('admin_model');
		$this->load->model('icd_model');		
	}
	
	/*----------------- load container_verification_approve_list page -----------------*/
	public function container_verification_approve_list(){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/cvao/container_verification_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');			
		$data['sdata']['igedl_list'] 		= $this->icd_model->get_icd_igedl_details_list('','','','1','1','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 container_verification_approve_form page -----------------*/
	public function container_verification_approve_form($igedl_id){		
		$data['sdata'] 					= array();
		$data['subview'] 				= 'icd/cvao/container_verification_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']['igedl_data'] 	= $this->icd_model->get_icd_igedl_details_list('',$igedl_id,'','1','1','1','1','1','1','1','1','1','1','1','1','','0');
		// echo $this->db->last_query();return;
		
		$data['sdata']['ivcl_list'] 	= $this->icd_model->get_icdl_ivcl_details_list('',$igedl_id,'','1');
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- update_container_verification_approve_details -----------------*/
	public function update_c_verify_approve_details($igedl_id){		
		$this->form_validation->set_rules('igedl_tansad_no', 'TANSAD No', 'trim|required');

		
		if ($this->form_validation->run() === FALSE) {
			$e_msg = ''; 			
			$e_msg .= form_error('igedl_tansad_no'); 	
			$this->session->set_flashdata('tos_error', $e_msg);
			redirect('icd/cvao_ctrl/container_verification_approve_list');	return;			
			
		}	
		$data['igedl_details']['igedl_tansad_no'] 			= $this->input->post('igedl_tansad_no');
		$data['igedl_details']['igedl_cvao_id'] 			= $this->user['i_user_id'];
		$data['igedl_details']['igedl_cvao_status'] 		= '1';
		$data['igedl_details']['igedl_cvao_date'] 			= date("Y-m-d"); 
		
		if(isset($_POST['f_upadate'])){
			$data['igedl_details']['igedl_fnl_cvao_id'] 			= $this->user['i_user_id'];
			$data['igedl_details']['igedl_fnl_cvao_status'] 		= '1';
			$data['igedl_details']['igedl_fnl_cvao_date'] 			= date("Y-m-d");
		}
		$edit_igedl 			= $this->admin_model->update_data('icd_gate_entry_details_list','igedl_id',$igedl_id,$data['igedl_details']);
		

		$icdl_id 						= $this->input->post('icdl_id');   
		$icdl_extra_field 				= $this->input->post('icdl_extra_field');   
		$cro_rem_c_no 					= 0;

		foreach($icdl_id as $icdl_key=>$icdl_row){		
			$data['icdl_details']['icdl_extra_field'] 	=  $icdl_extra_field[$icdl_key];	

			$edit_icdl 									= $this->admin_model->update_data('icd_container_details_list','icdl_id',$icdl_row,$data['icdl_details']);	
			$cro_rem_c_no								= $cro_rem_c_no+1;	
		}
		$data['igedl']['igedl_cro_re_c_no'] 			= $cro_rem_c_no; 
		
		$edit_igedl 			= $this->admin_model->update_data('icd_gate_entry_details_list','igedl_id',$igedl_id,$data['igedl']);


				
		if($edit_igedl!='0'){
			$this->session->set_flashdata('tos_success', 'Details Approved');
			redirect('icd/cvao_ctrl/container_verification_approve_list');
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/cvao_ctrl/container_verification_approve_list');
		}			
				
	}
	

	
}
