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

class Avso_o_ctrl extends user_index {
 
	
	public function __construct(){ 
		parent::__construct();
		$data = array();
		$this->load->model('admin_model');	
		$this->load->model('loading_model');	
	}
	
	/*----------------- load loading vehicle  entry list page -----------------*/
	public function vehicle_slip_authorize_window(){	
		$data['sdata'] 				= array();
		$data['subview'] 			= 'avso/vehicle_slip_authorize_window';
		$data['active_cls'] 		= 'loadaa_lcs';		
		$data['sdata']['lul_list'] 			= $this->loading_model->get_loading_list('Loading','','','1','','','','','0');
		// echo $this->db->last_query();return;	
		$this->load->view('common/sidepanel',$data);
	}
	

	/*----------------- load vehicle slip authorizing page ----------------*/
	public function vehicle_slip_authorizing($lul_id){	
		$data['sdata'] 						= array();
		$data['subview'] 					= 'avso/vehicle_slip_authorizing';
		$data['active_cls'] 				= 'loadaa_lcs';				
		$data['sdata']['lul_data'] 			= $this->loading_model->get_loading_list('Loading',$lul_id);
		$data['sdata']['luml_data'] 		= $this->loading_model->get_loading_or_unloading_meterial_list($lul_id);	
		// echo $this->db->last_query();return;
		$this->load->view('common/sidepanel',$data);
	}
	
	
	/*----------------- submit_vehicle_slip_authorizing -----------------*/
	public function submit_vehicle_slip_authorizing($lul_id= false){		
		$this->form_validation->set_rules('lul_load_by', 'Load By', 'trim|required');
		$this->form_validation->set_rules('lul_l_name', 'Name', 'trim|required');
		$this->form_validation->set_rules('lul_bag_loaded', 'Bags Loaded', 'trim|required');
		$this->form_validation->set_rules('lul_bag_short', 'Bags(Short)', 'trim|required');
		$this->form_validation->set_rules('lul_kgs', 'KGS', 'trim|required');
		
		if ($this->form_validation->run() === FALSE) {
			$e_msg = '';
			$e_msg .= form_error('lul_load_by');  				  
			$e_msg .= form_error('lul_l_name');  				  
			$e_msg .= form_error('lul_bag_loaded');  				  
			$e_msg .= form_error('lul_bag_short');  				  
			$e_msg .= form_error('lul_kgs');  				  
			$this->session->set_flashdata('tos_error', $e_msg);
			redirect('avso_o_ctrl/vehicle_slip_authorizing/'.$lul_id);				
			
		}	
				
		$data['lul_details']['lul_load_by'] 		= $this->input->post('lul_load_by');
		$data['lul_details']['lul_l_name'] 			= $this->input->post('lul_l_name');
		$data['lul_details']['lul_bag_loaded'] 		= $this->input->post('lul_bag_loaded');
		$data['lul_details']['lul_bag_short'] 		= $this->input->post('lul_bag_short');
		$data['lul_details']['lul_kgs'] 			= $this->input->post('lul_kgs');		
		$data['lul_details']['lul_avso_id'] 		= $this->user['i_user_id'];
		$data['lul_details']['lul_avso_date_time'] 	= date("Y-m-d h:i a");
		
		$edit_lul = $this->admin_model->update_data('loading_unloading_list','lul_id',$lul_id,$data['lul_details']);

			
		if($edit_lul!=false){
			$this->session->set_flashdata('tos_success', 'Loading vehicle slip authorized details updated.');
			redirect('print_ctrl/print_avso_view_loading/'.$lul_id);
		}else {
			$this->session->set_flashdata('tos_error', 'Try again !...');
			redirect('avso_o_ctrl/vehicle_slip_authorize_window');
		}			
			
	}

	
	 

	
}
