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

class Unloading_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_entry_list_for_unloading(){	
		if($this->user['panel_type']=='2' && in_array("2", $this->u_roles)){								
			$data['sdata'] 				= array();
			$data['subview'] 			= 'unloading_o/vehicle_entry_list_for_unloading';
			$data['active_cls'] 		= 'unloadaa_cls';		
			$data['sdata']['lul_list'] 			= $this->loading_model->get_loading_list('Unloading','','','1','0');		
			$this->load->view('common/sidepanel',$data);
		}else{
			redirect('login_ctrl/logout');
		}
	}
	

	/*----------------- load vehicle slip entry page ----------------*/
	public function vehicle_slip_entry_of_unloading($lul_id){	
		if($this->user['panel_type']=='2' && in_array("2", $this->u_roles)){						
			$data['sdata'] 						= array();
			$data['subview'] 					= 'unloading_o/vehicle_slip_entry_of_unloading';
			$data['active_cls'] 				= 'unloadaa_cls';				
			$data['sdata']['lul_data'] 			= $this->loading_model->get_loading_list('Unloading',$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);
		}else{
			redirect('login_ctrl/logout');
		}
	}
	
	
	/*----------------- submit W/Bridge Ticket No  -----------------*/
	public function submit_vehicle_slip_of_unloading($lul_id= false){		
		if(($this->user['panel_type']!='2') && (!in_array("2", $this->u_roles))){
			redirect('login_ctrl/logout');
		}
			
		$data['lul_details']['lul_lo_id'] 					= $this->user['i_user_id'];
		$data['lul_details']['lul_lo_date_time'] 			= date("Y-m-d h:i a");
		$data['lul_details']['lul_W_Bridge_Ticket_No'] 		= $this->input->post('lul_W_Bridge_Ticket_No');
		$data['lul_details']['lul_w_bridge_gross'] 			= $this->input->post('lul_w_bridge_gross');
		$data['lul_details']['lul_w_bridge_tare'] 			= $this->input->post('lul_w_bridge_tare');
		$data['lul_details']['lul_w_bridge_net'] 			= $this->input->post('lul_w_bridge_net');
		$data['lul_details']['lul_return_status'] 			= '1';
		
		$edit_lul = $this->admin_model->update_data('loading_unloading_list','lul_id',$lul_id,$data['lul_details']);

		
			
		if($edit_lul==1){
			$this->session->set_flashdata('tos_success', 'Vehicle slip submitted.');
			redirect('print_ctrl/print_unload_o_view_loading/'.$lul_id);
		}else {
			$this->session->set_flashdata('tos_error', 'Try again !...');
			redirect('unloading_o_ctrl/vehicle_entry_list_for_unloading');
		}			
			
	}

	/*----------------- Vehicle Return Selection Window(After Loading) -----------------*/
	public function vehicle_return_selection_list_unloading(){	
		if($this->user['panel_type']=='2' && in_array("2", $this->u_roles)){						
			$data['sdata'] 				= array();
			$data['subview'] 			= 'unloading_o/vehicle_return_selection_list_unloading';
			$data['active_cls'] 		= 'unloadaa_cls';		
			$data['sdata']['lul_list'] 			= $this->loading_model->get_loading_list('Unloading','','','1','','','','1');	
			// echo $this->db->last_query();return;	
			$this->load->view('common/sidepanel',$data);
		}else{
			redirect('login_ctrl/logout');
		}
	}

	/*----------------- load vehicle slip authorizing page ----------------*/
	public function vehicle_slip_return_form_unloading($lul_id){
		if($this->user['panel_type']=='2' && in_array("2", $this->u_roles)){						
			$data['sdata'] 						= array();
			$data['subview'] 					= 'unloading_o/vehicle_slip_return_form_unloading';
			$data['active_cls'] 				= 'unloadaa_cls';				
			$data['sdata']['lul_data'] 			= $this->loading_model->get_loading_list('Unloading',$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);
		}else{
			redirect('login_ctrl/logout');
		}
	}
	

	/*----------------- submit_vehicle_slip_return_form -----------------*/
	public function submit_vehicle_slip_return_form_unloading($lul_id= false){	
		if(($this->user['panel_type']!='2') && (!in_array("2", $this->u_roles))){
			redirect('login_ctrl/logout');
		}
			
		$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');

		$this->form_validation->set_rules('lul_w_bridge_tare', 'Tare', 'trim|required');
		$this->form_validation->set_rules('lul_w_bridge_net', 'Net', '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');  				  
			$e_msg .= form_error('lul_w_bridge_tare');  				  
			$e_msg .= form_error('lul_w_bridge_net');  				  
			$this->session->set_flashdata('tos_error', $e_msg);
			redirect('unloading_o_ctrl/vehicle_slip_return_form_unloading/'.$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_w_bridge_tare'] 	= $this->input->post('lul_w_bridge_tare');
		$data['lul_details']['lul_w_bridge_net'] 	= $this->input->post('lul_w_bridge_net');
		$data['lul_details']['lul_return_status'] 	= '2';
		$data['lul_details']['lul_loading_date'] 	= date('Y-m-d');
			
			
			
		$edit_lul = $this->admin_model->update_data('loading_unloading_list','lul_id',$lul_id,$data['lul_details']);
	
		if($edit_lul==1){
			$this->session->set_flashdata('tos_success', 'Loading vehicle slip authorized details updated.');
			redirect('unloading_o_ctrl/vehicle_return_selection_list_unloading');
		}else {
			$this->session->set_flashdata('tos_error', 'Try again !...');
			redirect('unloading_o_ctrl/vehicle_return_selection_list_unloading');
		}			
				
	}

	

	
}
