<?php	if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Refill_track extends CI_Controller {

	function __construct()	{
		parent::__construct();
	}

	function index()	{	
		$this->list_refill_track();
	}

	function list_refill_track() {

		admin_auth();

	  $tracking_number = check_injections_filter($this->input->post('refill_tracking_number'));
	   
	  $condition[] = array('where','tracking_number',$tracking_number);

	   $select=array(
                              'table_name'=>TABLE_TRACKING_DETAILS,
                              'table_fields'=>'tracking_number',
                               'condition'=>$condition,
                               'limit'=>'',
                               //'order_by_field'=>'a.branch_salable_geography_id',
                               //'group_by_field'=>'a.customer_name',
                               'offset'=>''
                              );
	   $track_check['track_check'] = $this->master_model->select_data($select);       
       if(!empty($track_check['track_check'])&& is_array($track_check['track_check'])){

		$this->page_data['page_title']="History of ".$tracking_number;
		$this->page_data['bredcrum']=array(
			 							'Refill Tracking'=>'#',
										//'Company Branch'=>'#',
										'History of Tracking Number'=>'#',
										);

		$condition[] = array('join',TABLE_COMPANY_BRANCH.' as b','b.company_branch_id = a.company_branch_id','inner');

		$condition[] = array('join',TABLE_CUSTOMER.' as c','c.customer_id = a.customer_id','inner');

        $condition[] = array('join',TABLE_DISPENSER_SALES.' as d','d.dispenser_sales_id = a.dispenser_sales_id','inner');

        $condition[] = array('join',TABLE_DISPENSER_REFILL_DETAILS.' as e','e.dispenser_refill_details_id = a.dispenser_refill_details_id','inner');

         $condition[] = array('join',TABLE_PRODUCT.' as f','f.product_id = d.product_id','inner');
		$condition[] = array('where','a.tracking_number',$tracking_number);

        $selected_array=array(
                              'table_name'=>TABLE_TRACKING_DETAILS.' as a',
                              'table_fields'=>'a.tracking_details_id,a.tracking_number,c.customer_name, b.company_branch_name, f.product_name, f.dispenser_name, d.created_on, a.next_refill_date, a.is_returned',
                               'condition'=>$condition,
                               'limit'=>'',
                               //'order_by_field'=>'a.branch_salable_geography_id',
                               //'group_by_field'=>'a.customer_name',
                               'offset'=>''
                              );
        $refill_history['refill_history'] = $this->master_model->select_data($selected_array);
       if(!empty($refill_history['refill_history'])&& is_array($refill_history['refill_history'])){
							
				  $this->page_data['refill_history'] = $refill_history['refill_history'];
		 	
  	    } 

			$this->load->view('gc/refill_tracking_list.php',$this->page_data);
      }	
      else{

      	$this->session->set_flashdata('msg','Invalid Tracking Number');
      	redirect('gc/refill_track/manage_refill_track');
      }
    
	
	}
	
	// function view_refill_track() {
	// 	$this->_page_data['page_title']="View Company Branch";
	// 	$this->_page_data['bredcrum']=array(
	// 									'Masters'=>'#',
	// 									'Company Branch'=>'#',
	// 									'List Company Branch'=>site_url('gc/company_branch/list_company_branch'),
	// 									'View Company Branch'=>'#',
	// 									);
	// 	$this->load->view('gc/refill_tracking_view.php',$this->_page_data);
	// }
	
	function manage_refill_track() {
		admin_auth();
		if($purpose=='')
			$purpose='Search';
		
		$this->_page_data['purpose']=$purpose;
		$this->_page_data['page_title']=$purpose." Tracking ";
		$this->_page_data['bredcrum']=array(
										'Refill Tracking'=>'#',
									    //'Company Branch'=>'#',
										//'List Company Branch'=>site_url('gc/company_branch/list_gc_type'),
										$purpose.'Tracking '=>'#',
										);
		$this->load->view('gc/refill_tracking.php',$this->_page_data);
	}
	
}