<?php



class Loading_model extends CI_Model{	

	public function __construct(){
		//database loading
		$this->load->database();
	}
	
	 
	
	public function get_loading_list($lul_type,$lul_id='',$lul_a_o_id='',$lul_leo_status='',$lul_lo_id='',$lul_d_o_id='',$lul_print_status='',$lul_return_status='',$lul_avso_id=''){
		$this->db->select('loading_unloading_list.*,customer_list.*,transporter_list.*,commodity_list.*,users_list.*,authorize_tb.ul_name AS authorize_name,authorize_tb.ul_id AS authorize_id')
				->from('loading_unloading_list')
				->join('customer_list','customer_list.cl_id=loading_unloading_list.lul_cl_id')
				->join('transporter_list','transporter_list.tl_id=loading_unloading_list.lul_tl_id')
				->join('commodity_list','commodity_list.com_id=loading_unloading_list.lul_com_id')
				->join('users_list','users_list.ul_id=loading_unloading_list.lul_e_o_id')				
				->join('users_list authorize_tb', 'loading_unloading_list.lul_a_o_id = authorize_tb.ul_id', 'left');
		if($lul_type!=''){
			$this->db->where('lul_type',$lul_type);
		}
		if($lul_print_status!=''){
			$this->db->where('lul_print_status',$lul_print_status);
		}
		if($lul_a_o_id!=''){
			$this->db->where('lul_a_o_id',$lul_a_o_id);
		}
		if($lul_leo_status!=''){
			$this->db->where('lul_a_o_id !=','0');
			$this->db->where('lul_leo_status',$lul_leo_status);
		}	
		if($lul_return_status!=''){
			$this->db->where('lul_return_status',$lul_return_status);	
		}


		if($lul_avso_id!=''){
			if($lul_avso_id=='0'){
				$this->db->where('lul_avso_id','0');
			}else if($lul_avso_id=='1'){
				$this->db->where('lul_avso_id !=','0');			
			}
		}

		if($lul_lo_id!=''){
			if($lul_lo_id=='0'){
				$this->db->where('lul_lo_id','0');
			}else if($lul_lo_id=='1'){
				$this->db->where('lul_lo_id !=','0');			
				$this->db->where('lul_avso_id','0');			
			}else{
				$this->db->where('lul_lo_id',$lul_lo_id);			
			}
		}

		if($lul_d_o_id!=''){
			if($lul_d_o_id=='0'){
				$this->db->where('lul_lo_id !=','0');				
				$this->db->where('lul_d_o_id','0');
			}else{
				$this->db->where('lul_d_o_id',$lul_d_o_id);			
			}
		}
		$this->db->where('lul_reject','0');
		if($lul_id!=''){
			$this->db->where('lul_id',$lul_id);
			$query=$this->db->get();
			return $query->row_array();
		}				
		else{		
			$query=$this->db->get();
			return $query->result_array();
		}		
	}

	public function get_loading_or_unloading_meterial_list($lul_id='',$luml_id='',$lul_print_status=''){
		$this->db->select('*')
				->from('loading_unloading_meterial_list')
				->join('loading_unloading_list','loading_unloading_list.lul_id=loading_unloading_meterial_list.luml_lul_id')
				->join('commodity_list','commodity_list.com_id=loading_unloading_list.lul_com_id')
				->join('meterial_list','meterial_list.ml_id=loading_unloading_meterial_list.luml_ml_id')
				->join('units_list','units_list.unl_id=loading_unloading_meterial_list.luml_unl_id')
				;
		if($lul_print_status!=''){
			$this->db->where('lul_print_status',$lul_print_status);
		}
		if($lul_id!=''){
			$this->db->where('lul_id',$lul_id);
		}
		if($luml_id!=''){
			$this->db->where('luml_id',$luml_id);
			$query=$this->db->get();
			return $query->row_array();
		}				
		else{		
			$query=$this->db->get();
			return $query->result_array();
		}		
	}

	public function get_reports_loading($re_type,$lul_type="",$cl_id="",$com_id="",$ml_id="",$tl_id="",$token="",$w_b_token="",$f_date="",$t_date=""){
		$this->db->select('lul_id,lul_date as Entry_Date,lul_loading_date as Loading_Date,lul_exit_date as Exit_Date,lul_token_no as SLIP_NUMBER,lul_W_Bridge_Ticket_No as w_bridge_no,lul_ton as Packing_In_Kg,lul_truck_no as Truck_No,com_name as commodity_name,lul_ton as As_Per_D_N_Ton,lul_w_bridge_net as As_Per_W_Bridge,lul_leo_id as DF,lul_no_of_bag as BAGS,lul_leo_id as Remarkes,tl_name as Transporter_Name,lul_d_no as Party_DO_NO,cl_name as cust_Name,lul_trailer_no as trailer_no,lul_desti_reciecve_from_place as desti_rec_place,cl_code as cust_code,lul_kgs as qty_kgs,lul_w_bridge_gross as gross_weight,lul_w_bridge_tare as tare_weight,lul_w_bridge_net as net_weight,lul_no_of_bag as no_bags,lul_type as remarks,lul_type as type,lul_destination as desti_place,users_list.ul_name AS entered_by,authorize_tb.ul_name AS authorize_by,loading_by_tb.ul_name AS loading_by,despatch_by_tb.ul_name AS despatch_by,lul_load_by,lul_l_name,lul_bag_loaded,lul_bag_short,lul_kgs,lul_e_o_date_time,lul_a_o_date_time,lul_leo_date_time,lul_lo_date_time,lul_avso_date_time,lul_d_o_date_time');
		if($ml_id!=''){
			$this->db->select('ml_name as meterial_name ');
		}
		$this->db->from('loading_unloading_list') ;
		if($ml_id!=''){
			$this->db->join('loading_unloading_meterial_list','loading_unloading_meterial_list.luml_lul_id=loading_unloading_list.lul_id')
					->join('meterial_list','meterial_list.ml_id=loading_unloading_meterial_list.luml_ml_id');
		}
		$this->db->join('customer_list','customer_list.cl_id=loading_unloading_list.lul_cl_id')
				->join('transporter_list','transporter_list.tl_id=loading_unloading_list.lul_tl_id')
				->join('commodity_list','commodity_list.com_id=loading_unloading_list.lul_com_id')
				->join('users_list','users_list.ul_id=loading_unloading_list.lul_e_o_id')				
				->join('users_list authorize_tb', 'loading_unloading_list.lul_a_o_id = authorize_tb.ul_id', 'left')
				->join('users_list loading_by_tb', 'loading_unloading_list.lul_lo_id = loading_by_tb.ul_id', 'left')
				->join('users_list despatch_by_tb', 'loading_unloading_list.lul_d_o_id = despatch_by_tb.ul_id', 'left');
		if($lul_type!=''){
			$this->db->where('lul_type',$lul_type);
		}
		if($cl_id!=''){
			$this->db->where('cl_id',$cl_id);
		}
		if($com_id!=''){
			$this->db->where('com_id',$com_id);
		}
		if($ml_id!=''){
			$this->db->where('ml_id',$ml_id);	
		}
		if($tl_id!=''){
			$this->db->where('tl_id',$tl_id);	
		}
		if($token!=''){
			$this->db->where('lul_token_no',$token);	
		} 
		if($w_b_token!=''){
			$this->db->where('lul_W_Bridge_Ticket_No',$w_b_token);	
		} 
		if($f_date!=''){
			$this->db->where('lul_date >=',$f_date);	
			 $this->db->where('lul_date <=',$t_date);	
		}

		// if($f_date!='' && $t_date!=''){
		// 	$this->db->where('lul_date >=',$f_date);	
		// 	$this->db->where('lul_date <=',$t_date);	
		// }else if($f_date!='' && $t_date==''){	
		// 	$this->db->where('lul_date',$f_date);	
		// }

		
		if($re_type=='10'){
			$query=$this->db->get();
			return $query->result_array();
		}else if($re_type=='11'){
			$query=$this->db->get();
			// return $query;
			return $query->result_array();
			
		}

		// $query=$this->db->get();
		// return $query;
		// return $query->result_array();
	}


	public function get_search_loading_list($lul_id='',$lul_token_no=''){
		$this->db->select('*,,authorize_tb.ul_name AS authorize_name,authorize_tb.ul_id AS authorize_id')
				->from('loading_unloading_list') 	
				->join('customer_list','customer_list.cl_id=loading_unloading_list.lul_cl_id')
				->join('transporter_list','transporter_list.tl_id=loading_unloading_list.lul_tl_id')
				->join('commodity_list','commodity_list.com_id=loading_unloading_list.lul_com_id')
				->join('users_list','users_list.ul_id=loading_unloading_list.lul_e_o_id')

				->join('users_list authorize_tb', 'loading_unloading_list.lul_a_o_id = authorize_tb.ul_id', 'left')
				->join('users_list loading_by_tb', 'loading_unloading_list.lul_lo_id = loading_by_tb.ul_id', 'left')
				->join('users_list despatch_by_tb', 'loading_unloading_list.lul_d_o_id = despatch_by_tb.ul_id', 'left');
		
		if($lul_token_no!=''){
			$this->db->where('lul_token_no',$lul_token_no);	
			$query=$this->db->get();
			return $query->row_array();
		}else{
			// $this->db->where('lul_id',$lul_id);			
			$query=$this->db->get();
			return $query->result_array();
		}

	}




	
	
	





	

	


	





}	

?>