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

class Reports_ctrl extends user_index {
 
	
	public function __construct(){ 
		parent::__construct();
		$data = array();
		$this->load->model('admin_model');
		$this->load->model('loading_model');	
			
	}
	
	/*----------------- load users list page -----------------*/
	public function reports_list(){	
		$data['sdata'] 					= array();
		$data['subview'] 				= 'reports/reports_list';
		$data['active_cls'] 			= 'reprr_cls';		
		$data['sdata']['cl_list'] 		= $this->admin_model->get_result_array('customer_list');				
		$data['sdata']['com_list'] 		= $this->admin_model->get_result_array('commodity_list');				
		$data['sdata']['tl_list'] 		= $this->admin_model->get_result_array('transporter_list');	
		$data['sdata']['ml_list'] 		= $this->admin_model->get_meterial_list();				
		$data['sdata']['tab_active_cls'] 			= 'repp_cu_tab_cls';
		$this->load->view('common/sidepanel',$data);
	}
	

	/*----------------- load add users details page ----------------*/
	public function get_reports(){	

		$view_type_val 					= $this->input->post('view_type_val');
		$s_type 						= $this->input->post('s_type');
		$cl_id 							= $this->input->post('cl_id');
		$com_id 						= $this->input->post('com_id');
		$ml_id 							= $this->input->post('ml_id');
		$tl_id 							= $this->input->post('tl_id');
		$token 							= $this->input->post('token');
		$f_date 						= $this->input->post('f_date');
		$t_date 						= $this->input->post('t_date');

		$data['sdata']['view_type_val']	= $this->input->post('view_type_val');
		$data['sdata']['s_type']		= $this->input->post('s_type');
		$data['sdata']['cl_id']			= $this->input->post('cl_id');
		$data['sdata']['com_id']		= $this->input->post('com_id');
		$data['sdata']['ml_id']			= $this->input->post('ml_id');
		$data['sdata']['tl_id']			= $this->input->post('tl_id');
		$data['sdata']['token']			= $this->input->post('token');
		$data['sdata']['f_date']		= $this->input->post('f_date');
		$data['sdata']['t_date']		= $this->input->post('t_date');
		
		if($view_type_val=='1'){
			$data['sdata']['tab_active_cls'] 			= 'repp_cu_tab_cls';
		}else if($view_type_val=='2'){
			$data['sdata']['tab_active_cls'] 			= 'repp_tl_tab_cls';
		}else if($view_type_val=='3'){
			$data['sdata']['tab_active_cls'] 			= 'repp_com_tab_cls';
		}else if($view_type_val=='4'){
			$data['sdata']['tab_active_cls'] 			= 'repp_tok_tab_cls';
		}else if($view_type_val=='5'){
			$data['sdata']['tab_active_cls'] 			= 'repp_fd_tab_cls';
		}


		$data['subview'] 				= 'reports/reports_list';
		$data['active_cls'] 			= 'reprr_cls';					
		$data['sdata']['cl_list'] 		= $this->admin_model->get_result_array('customer_list');				
		$data['sdata']['com_list'] 		= $this->admin_model->get_result_array('commodity_list');				
		$data['sdata']['tl_list'] 		= $this->admin_model->get_result_array('transporter_list');	
		$data['sdata']['ml_list'] 		= $this->admin_model->get_meterial_list();	
		$data['sdata']['lul_re_list']	= $this->loading_model->get_reports_loading('10',$s_type,$cl_id,$com_id,$ml_id,$tl_id,$token,$f_date,$t_date);
		// echo $this->db->last_query();return;
		$this->load->view('common/sidepanel',$data);
					
		
		
	}

	/*----------------- load add users details page ----------------*/
	public function get_download_reports(){	
		
		$this->load->dbutil();
		$this->load->helper('file');
		$this->load->helper('download');

		$s_type 		= $this->input->post('s_type');
		$cl_id 			= $this->input->post('cl_id');
		$com_id 		= $this->input->post('com_id');
		$ml_id 			= $this->input->post('ml_id');
		$tl_id 			= $this->input->post('tl_id');
		$token 			= $this->input->post('token');
		$f_date 		= $this->input->post('f_date');
		$t_date 		= $this->input->post('t_date');
		

		$query1 		= $this->loading_model->get_reports_loading('11',$s_type,$cl_id,$com_id,$ml_id,$tl_id,$token,$f_date,$t_date);
		// echo $this->db->last_query();
		// var_dump($query1);return;
		
		$delimiter 		= ",";
		$newline 		= "\r\n";
		$data 			= $this->dbutil->csv_from_result($query1, $delimiter, $newline);
		// var_dump($data);return;	
		$exp_file_name 	= 'reports_'.rand(1, 1000000);
		force_download(''.$exp_file_name.'.csv', $data);
	}
	
	

	
}
