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

class Admin extends CI_Controller {  
     public function __construct() {
        parent::__construct();  
        date_default_timezone_set('Asia/Kolkata');
         $this->load->database();
         $this->load->model('Login_model');
         $this->load->helper('email');
         $this->load->model('Common_model');
     
//               $ip = $this->input->ip_address();

// $sql = "SELECT ip_adr FROM  allowed_ip where status = '0' and  ip_adr = '$ip' ";	
	
//         $rs = $this->Login_model->Execute($sql, array())->result_array();


//         if(empty($rs)){
            
//             echo '<div style= "text-align:center;background-color:red;color:white; margin-top:30px;"><h1>Your are not allowed to access this website.Please Contact Administration.</h1></div>';
            
            
//             die;
//         }
              
    }
    
    public function dashboard(){
    if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
        $qry="SELECT(SELECT COUNT(id) FROM tbl_driver) AS total_driver,
        (SELECT COUNT(id) FROM tbl_driver WHERE status=1) AS total_activedriver,
        (SELECT COUNT(id) FROM tbl_driver WHERE status=0) AS total_inactivedriver,
        (SELECT COUNT(id) FROM tbl_driver WHERE status=1 AND is_online=1) AS total_onlinedriver,
        (SELECT COUNT(id) FROM tbl_user WHERE status=1) AS total_users,
        (SELECT COUNT(id) FROM tbl_user WHERE status=0) AS total_inactiveusers,
        (SELECT COUNT(id) FROM tbl_booking) AS total_booking,
        (SELECT COUNT(v.id) 
         FROM tbl_booking v
         INNER JOIN tbl_driver d ON d.id = v.driver_id
         INNER JOIN tbl_vehicle tv ON tv.driver_id = v.driver_id
         INNER JOIN tbl_vehicletype t ON t.id = v.type_id
         WHERE v.ride_status = '0'
        ) AS total_pending_booking,
        
        (SELECT COUNT(v.id) 
         FROM tbl_booking v
         INNER JOIN tbl_driver d ON d.id = v.driver_id
         INNER JOIN tbl_vehicle tv ON tv.driver_id = v.driver_id
         INNER JOIN tbl_vehicletype t ON t.id = v.type_id
         WHERE v.ride_status = '1'
        ) AS total_start_booking,
        
        (SELECT COUNT(v.id) 
         FROM tbl_booking v
         INNER JOIN tbl_driver d ON d.id = v.driver_id
         INNER JOIN tbl_vehicle tv ON tv.driver_id = v.driver_id
         INNER JOIN tbl_vehicletype t ON t.id = v.type_id
         WHERE v.ride_status = '2'
        ) AS total_complete_booking,
        
        (SELECT COUNT(v.id) 
         FROM tbl_booking v
         INNER JOIN tbl_driver d ON d.id = v.driver_id
         INNER JOIN tbl_vehicle tv ON tv.driver_id = v.driver_id
         INNER JOIN tbl_vehicletype t ON t.id = v.type_id
         WHERE v.ride_status = '3'
        ) AS total_reject_booking,
        
        (SELECT SUM(final_grandtotal) FROM tbl_booking WHERE payment_status=1 ) AS total_revenue,
        (SELECT SUM(total_fare) FROM tbl_booking WHERE paymenttype='COD' AND payment_status=1 ) AS total_cod_collection,
        (SELECT SUM(total_fare) FROM tbl_booking WHERE paymenttype='wallet' AND payment_status=1 ) AS total_wallet_collection,
        (SELECT SUM(total_fare) FROM tbl_booking WHERE paymenttype='online' AND payment_status=1 ) AS total_online_collection,
        (SELECT COUNT(id) FROM tbl_booking WHERE is_cancle=1) AS total_cancle_booking,
        (SELECT COUNT(id) FROM tbl_booking WHERE ride_status=0 AND DATE_FORMAT(entry_date,'%Y-%m-%d')='".date('Y-m-d')."') AS today_pending_booking,
        (SELECT COUNT(id) FROM tbl_booking WHERE DATE_FORMAT(entry_date,'%Y-%m-%d')='".date('Y-m-d')."') AS today_total_booking,
        (SELECT COUNT(id) FROM tbl_booking WHERE ride_status=2 AND is_cancle=0 AND DATE_FORMAT(entry_date,'%Y-%m-%d')='".date('Y-m-d')."') AS today_complete_booking,
        (SELECT IFNULL(SUM(total_fare),0) FROM tbl_booking WHERE ride_status=2 AND paymenttype='COD' AND payment_status=1 AND DATE_FORMAT(entry_date,'%Y-%m-%d')='".date('Y-m-d')."') AS today_farecodcollection,
        (SELECT IFNULL(SUM(total_wait_charge),0) FROM tbl_booking WHERE ride_status=2 AND post_paymenttype='COD' AND post_payment_status=1 AND DATE_FORMAT(entry_date,'%Y-%m-%d')='".date('Y-m-d')."') AS today_waitchargecodcollection,
        (SELECT IFNULL(SUM(total_fare+total_wait_charge),0) FROM tbl_booking WHERE ride_status=2 AND DATE_FORMAT(entry_date,'%Y-%m-%d')='".date('Y-m-d')."') AS today_total_collection";
        
        $data=$this->db->query($qry)->row_array();
        
        $this->load->view('header');
        $this->load->view('admin/dashboard',array('data'=>$data));
        $this->load->view('footer');
    }
    }
      
      
      public function cod_status($st =''){
          
      
           
           if($st == 0){
               
              $f = array(					
					    
    					'status' => 1,
    				);
    				
    				
           }else{
               $f = array(					
					   
    					'status' => 0,
    				);
           }
           
           $this->Login_model->Update('tbl_cod_sts',$f , array('id'=>1));
           
       
          
          
          redirect(base_url() . 'Admin/setting');
          
          
      }
    
    
    public function setting(){
        
    if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    
    $this->load->view('header');
    $this->load->view('admin/setting_new');
    $this->load->view('footer');
    }
    }
    
    
    
    
    
    
    
    
     public function user_list(){
    if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/user_list');
    $this->load->view('footer');
        }
    }
    
    
    
    
    
    
  
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function user_bookinghistory($id=''){
        if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
           
        $qry="SELECT v.*,md.*,dr.driver_name,tv.number,dr.id as driver_id,dr.driver_profile_pic  
                FROM tbl_booking v
              INNER JOIN  tbl_user md ON md.id=v.user_id
              INNER JOIN tbl_vehicle tv ON tv.driver_id = v.driver_id
              LEFT JOIN tbl_driver dr ON v.driver_id = dr.id
              WHERE v.user_id = $id";
        $data['result']=$this->db->query($qry)->result_array();
        $data['id']=$id;
        
    $this->load->view('header');
    $this->load->view('admin/user_history',$data);
    $this->load->view('footer');
        }
        
    }
    
    public function update_location($id=''){
        if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/update_location');
    $this->load->view('footer');
        }
        
    }
    
    public function rentalkm()
    {
       if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
        } else {
        $this->load->view('header');
        $this->load->view('admin/rental');
        $this->load->view('footer');
        } 
    }
    
    public function find_driver()
    {
        if ($this->session->userdata('admin_login_id') == "" ) {
              redirect('Base/login/');
        } else {
            $id=$_POST['driver_id'];
            
            $qry="SELECT driver_name,id FROM tbl_driver WHERE driver_id = '$id' ";
            
            $result=$this->db->query($qry)->row_array();
    
            if ($result) {
               echo json_encode([
                    'driver_name' => $result['driver_name'],
                    'id' => $result['id']
                ]);

            } else {
                echo json_encode(['driver_name' => null]);
            }
        
            }
        
    }
    
    public function update_driver_location()
    {
        if ($this->session->userdata('admin_login_id') == "") {
            redirect('Base/login/');
        }

        if (
            empty($_POST['id']) ||
            empty($_POST['driver_id']) ||
            empty($_POST['curr_lat']) ||
            empty($_POST['curr_long'])
        ) {
            $this->session->set_flashdata('error', 'Kindly fill all the required fields');
            redirect(base_url('Admin/update_location'));
        } else {
            $curr_lat = $this->security->xss_clean($this->input->post('curr_lat'));
            $curr_long = $this->security->xss_clean($this->input->post('curr_long'));
    
            $data = [
                'curr_lat' => $curr_lat,
                'curr_long' => $curr_long,
            ];
    
            $id = $this->input->post('id'); // Sanitize input using CodeIgniter's input class
            if (!empty($id)) {
                $this->db->where('id', $id);
                $update = $this->db->update('tbl_driver_currentLocation', $data);
    
                if ($update) {
                    $this->session->set_flashdata('message_name', 'Location updated successfully');
                } else {
                    $this->session->set_flashdata('error', 'Failed to update location');
                }
            } else {
                $this->session->set_flashdata('error', 'Invalid driver ID');
            }
    
            redirect(base_url('Admin/update_location'));
        }
}

    public function update_rental_kmlist()
    {
        if ($this->session->userdata('admin_login_id') == "") {
            redirect('Base/login/');
        }

        if (
            empty($_POST['id']) ||
            empty($_POST['km']) ||
            empty($_POST['hrs'])
           
        ) {
            $this->session->set_flashdata('error', 'Kindly fill all the required fields');
            redirect(base_url('Admin/rentalkm'));
        } else {
            $km = $this->security->xss_clean($this->input->post('km'));
            $hrs = $this->security->xss_clean($this->input->post('hrs'));
    
            $data = [
                'km' => $km,
                'hrs' => $hrs,
            ];
    
            $id = $this->input->post('id'); // Sanitize input using CodeIgniter's input class
            if (!empty($id)) {
                $this->db->where('id', $id);
                $update = $this->db->update('tbl_rental_km_hrs', $data);
    
                if ($update) {
                    $this->session->set_flashdata('message_name', 'Rental km and hrs updated successfully');
                } else {
                    $this->session->set_flashdata('error', 'Failed to update');
                }
            } else {
                $this->session->set_flashdata('error', 'Invalid driver ID');
            }
    
            redirect(base_url('Admin/rentalkm'));
        }
}

    public function add_driver_location()
    {
        if ($this->session->userdata('admin_login_id') == "") {
            redirect('Base/login/');
        }

        if (
            empty($_POST['driver_id']) ||
            empty($_POST['curr_lat']) ||
            empty($_POST['curr_long'])
        ) {
            $this->session->set_flashdata('error', 'Kindly fill all the required fields');
            redirect(base_url('Admin/update_location'));
        } else {
            $driver_id = $this->security->xss_clean($this->input->post('driver_id'));
            $curr_lat = $this->security->xss_clean($this->input->post('curr_lat'));
            $curr_long = $this->security->xss_clean($this->input->post('curr_long'));
    
            $data = [
                'driver_id'=>$driver_id,
                'curr_lat' => $curr_lat,
                'curr_long' => $curr_long,
            ];
    
            
            if (!empty($data)) {
                
                $this->db->insert('tbl_driver_currentLocation', $data);
                $insert_id = $this->db->insert_id();
    
                if ($insert_id) {
                    $this->session->set_flashdata('message_name', 'Location Added successfully');
                } else {
                    $this->session->set_flashdata('error', 'Failed to update location');
                }
            } else {
                $this->session->set_flashdata('error', 'Invalid driver ID');
            }
    
            redirect(base_url('Admin/update_location'));
        }
}

    public function add_rental_kmhrs()
    {
        if ($this->session->userdata('admin_login_id') == "") {
            redirect('Base/login/');
        }

        if (
            empty($_POST['km']) ||
            empty($_POST['hours']) 
            
        ) {
            $this->session->set_flashdata('error', 'Kindly fill all the required fields');
            redirect(base_url('Admin/rentalkm'));
        } else {
            $km = $this->security->xss_clean($this->input->post('km'));
            $hours = $this->security->xss_clean($this->input->post('hours'));
    
            $data = [
                'km'=>$km,
                'hrs' => $hours,
            ];
    
            
            if (!empty($data)) {
                
                $this->db->insert('tbl_rental_km_hrs', $data);
                $insert_id = $this->db->insert_id();
    
                if ($insert_id) {
                    $this->session->set_flashdata('message_name', 'Rental Km and Hrs Added successfully');
                } else {
                    $this->session->set_flashdata('error', 'Failed to Add');
                }
            } else {
                $this->session->set_flashdata('error', 'Invalid driver ID');
            }
    
            redirect(base_url('Admin/rentalkm'));
        }
}



public function conven_charge(){
    if(empty($_POST['charge'])){
        
        
        $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
         
        redirect(base_url() . 'Admin/setting');
        
    }else{
        
         $charge = $this->security->xss_clean($this->input->post('charge'));
         
          $ch_id = $this->security->xss_clean($this->input->post('ch_id'));
           $status = $this->security->xss_clean($this->input->post('status'));
        if(!empty($ch_id)){
            
            	$f = array(					
					    'amt' => $charge,
    					'status' => $status,
    				);
    				
    				$this->Login_model->Update('tbl_conv_charge',$f , array('id'=>$ch_id));
            
            $this->session->set_flashdata('message_name',' Charges Updated successfully');
            
        }else{
            	$f = array(					
					    'amt' => $charge,
    					'status' => 0,
    				);
    				
    				$this->Login_model->insert('tbl_conv_charge',$f);
        
        	$this->session->set_flashdata('message_name','Charges added successfully');
        }
        
        
    }
     redirect(base_url() . 'Admin/setting');
}

public function update_conven_charge(){
    if(empty($_POST['ch_id'])){
        
        $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
        redirect(base_url() . 'Admin/setting');
        
    }else{
        
         $charge = $this->security->xss_clean($this->input->post('charge'));
          $ch_id = $this->security->xss_clean($this->input->post('ch_id'));
           
        if(!empty($ch_id)){
            
            	$f = array(					
					    'amt' => isset($charge)?$charge:0,
    					'status' => '0',
    				);
    				
    				$this->Login_model->Update('tbl_conv_charge',$f , array('id'=>$ch_id));
            
            $this->session->set_flashdata('message_name',' Charges Updated successfully');
            
        }
    }
     redirect(base_url() . 'Admin/setting');
}



    public function add_cabfare(){
 
  if(empty($_POST['wait_charge']) && empty($_POST['night_fare_sts']) && empty($_POST['wait_charge']) && empty($_POST['wait_limit']) && empty($_POST['capacity']) && empty($_POST['km_charge']) && empty($_POST['veh_type']) ){
          
          $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
         
        redirect(base_url() . 'Admin/add_fare');
       }else{
           
           
           
            $night_fare = $this->security->xss_clean($this->input->post('night_fare'));
	$end_time = $this->security->xss_clean($this->input->post('end_time'));
	$strt_time = $this->security->xss_clean($this->input->post('strt_time'));
	$night_fare_sts = $this->security->xss_clean($this->input->post('night_fare_sts'));
	$sch_ride = $this->security->xss_clean($this->input->post('sch_ride'));
	$wait_charge = $this->security->xss_clean($this->input->post('wait_charge'));
	$wait_limit = $this->security->xss_clean($this->input->post('wait_limit'));
	$capacity = $this->security->xss_clean($this->input->post('capacity'));
	$km_charge = $this->security->xss_clean($this->input->post('km_charge'));
	$veh_type = $this->security->xss_clean($this->input->post('veh_type'));

           if(!empty($_POST['status'])){
                       $sts = $_POST['status']; 
                        
                    }else{
                        $sts = 0 ;
                    }
                    
           	$f = array(					
					    'vehicle_type' => $veh_type,
    					'per_km' => $km_charge,
    					'capacity' => $capacity ,
    					'wait_time_limit' => $wait_limit,
    					'wait_charge' => $wait_charge,
						'sch_fare' => $sch_ride,
    					'night_fare_status' => $night_fare_sts,
    					'nightfare_strt_time' => $strt_time,
    					'nightfare_end_time' => $end_time,
    					'nightfare_charge' => $night_fare,
    					'status' => $sts,
    				);
                    
                    	
                    
		

			    
			    
    				
    				if(!empty($_POST['auto_id'])){
    				    
    				    $ide = $_POST['auto_id'] ;
    				    
                       	$this->db->Where('id',$ide);
					$this->db->update('tbl_fare',$f);
	$this->session->set_flashdata('message_name','Fare Charges Updated successfully');
                        redirect(base_url() . 'Admin/fare_manage');
                        
                    }else{
                        
                        $sql = $this->Login_model->Select('tbl_fare', '*', array('vehicle_type'=>$veh_type));
  
			if (empty($sql)) {
               
                       	$this->Login_model->insert('tbl_fare',$f); 
                       		$this->session->set_flashdata('message_name','Fare Charges added successfully');
                       		
			}else{
			    
			      $this->session->set_flashdata('error', 'Fare Charges already exist for this vehicle type');
			}
                    }
    				
    				
    			
			    
			    
			    
			    
			
           
           
           
           
       }
 
 
 
 redirect(base_url() . 'Admin/add_fare');
    }
    
    public function add_data_table_theme()
    {
            if(empty($_POST['font_family']) && empty($_POST['font_size']) && empty($_POST['heading_color']) && 
                empty($_POST['divider_thickness']) && empty($_POST['heading_row_color']))           
            {
                    $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
                    redirect(base_url() . 'Admin/data_table_theme');
            }
            else
            {
                    $font_family = $this->security->xss_clean($this->input->post('font_family'));
                	$font_size = $this->security->xss_clean($this->input->post('font_size'));
                	$heading_color = $this->security->xss_clean($this->input->post('heading_color'));
                	$divider_thickness = $this->security->xss_clean($this->input->post('divider_thickness'));
                	$heading_row_color = $this->security->xss_clean($this->input->post('heading_row_color'));
                    
               	        $f = array(					
    					    'font_family' => $font_family,
        					'font_size' => $font_size,
        					'heading_color' => $heading_color ,
        					'divider_thickness' => $divider_thickness,
        					'heading_row_color' => $heading_row_color,
        				);
			    
    				
    				if(!empty($_POST['auto_id']))
    				{
    				    $ide = $_POST['auto_id'];
                       	$this->db->Where('id',$ide);
    					$this->db->update('data_table_theme',$f);
    	                 $this->session->set_flashdata('message_name','Data table theme Updated successfully');
                        redirect(base_url() . 'Admin/data_table_theme');
                    }
                    else
                    {
                         $this->session->set_flashdata('error', 'Data table theme not Updated successfully');
			
                    }
           
           
        }
            redirect(base_url() . 'Admin/data_table_theme');
    }
    
    public function add_text_theme()
    {
        echo "working";
        die;
            if(empty($_POST['section_name']) && empty($_POST['font_family']) && empty($_POST['font_weight']) && 
                empty($_POST['font_size']) && empty($_POST['text_theme_color']))           
            {
                    $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
                    redirect(base_url() . 'Admin/text_theme');
            }
            else
            {
                    $section_name = $this->security->xss_clean($this->input->post('section_name'));
                	$font_family = $this->security->xss_clean($this->input->post('font_family'));
                	$font_weight = $this->security->xss_clean($this->input->post('font_weight'));
                	$font_size = $this->security->xss_clean($this->input->post('font_size'));
                	$text_theme_color = $this->security->xss_clean($this->input->post('text_theme_color'));
                    
               	        $f = array(					
    					    'section_name' => $section_name,
        					'font_family' => $font_family,
        					'font_weight' => $font_weight ,
        					'font_size' => $font_size,
        					'text_theme_color' => $text_theme_color,
        				);
			    
			    echo "working";
			    die;
    				
    				if(!empty($_POST['auto_id']))
    				{
    				    $ide = $_POST['auto_id'];
                       	$this->db->Where('id',$ide);
    					$this->db->update('text_theme',$f);
    	                 $this->session->set_flashdata('message_name','Text theme Updated successfully');
                        redirect(base_url() . 'Admin/text_theme');
                    }
                    else
                    {
                         $this->session->set_flashdata('error', 'Text theme not Updated successfully');
			
                    }
           
           
        }
            redirect(base_url() . 'Admin/text_theme');
    }
    
    public function add_gradient()
    {
            if(empty($_POST['start_color']) && empty($_POST['center_color']) && empty($_POST['end_color']))           
            {
                    $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
                    redirect(base_url() . 'Admin/gradient');
            }
            else
            {
                    $start_color = $this->security->xss_clean($this->input->post('start_color'));
                	$center_color = $this->security->xss_clean($this->input->post('center_color'));
                	$end_color = $this->security->xss_clean($this->input->post('end_color'));
                    
               	        $f = array(					
    					    'start_color' => $start_color,
        					'center_color' => $center_color,
        					'end_color' => $end_color ,
        				);
			    
    				
    				if(!empty($_POST['auto_id']))
    				{
    				    $ide = $_POST['auto_id'];
                       	$this->db->Where('id',$ide);
    					$this->db->update('gradient',$f);
    	                 $this->session->set_flashdata('message_name','gradient Updated successfully');
                        redirect(base_url() . 'Admin/gradient');
                    }
                    else
                    {
                         $this->session->set_flashdata('error', 'gradient not Updated successfully');
			
                    }
           
           
        }
            redirect(base_url() . 'Admin/gradient');
    }
    
    public function add_icon_theme()
    {
        if(empty($_POST['icon_theme_color']))           
        {
                $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
                redirect(base_url() . 'Admin/icon_theme');
        }
        else
        {
                $icon_theme_color = $this->security->xss_clean($this->input->post('icon_theme_color'));
                
           	        $f = array(					
					    'icon_theme_color' => $icon_theme_color,
    					
    				);
		    
				
				if(!empty($_POST['auto_id']))
				{
				    $ide = $_POST['auto_id'];
                   	$this->db->Where('id',$ide);
					$this->db->update('icon_theme',$f);
	                 $this->session->set_flashdata('message_name','Icon theme Updated successfully');
                    redirect(base_url() . 'Admin/icon_theme');
                }
                else
                {
                     $this->session->set_flashdata('error', 'Icon theme not Updated successfully');
		
                }
       
       
    }
        redirect(base_url() . 'Admin/icon_theme');
    }
    
    public function add_app_bar_theme()
    {
            if(empty($_POST['background_color']) && empty($_POST['elevation']) && empty($_POST['shadow_color'])
             && empty($_POST['border_radius_bottom_left'])  && empty($_POST['border_radius_bottom_right']) )           
            {
                    $this->session->set_flashdata('error', 'Kindly Fill all the required Filled');
                    redirect(base_url() . 'Admin/app_bar_theme');
            }
            else
            {
                    $background_color = $this->security->xss_clean($this->input->post('background_color'));
                	$elevation = $this->security->xss_clean($this->input->post('elevation'));
                	$shadow_color = $this->security->xss_clean($this->input->post('shadow_color'));
                    $border_radius_bottom_left = $this->security->xss_clean($this->input->post('border_radius_bottom_left'));
                    $border_radius_bottom_right = $this->security->xss_clean($this->input->post('border_radius_bottom_right'));
                    
               	        $f = array(					
    					    'background_color' => $background_color,
        					'elevation' => $elevation,
        					'shadow_color' => $shadow_color ,
        					'border_radius_bottom_left' => $border_radius_bottom_left,
        					'border_radius_bottom_right' => $border_radius_bottom_right,
        				);
			    
    				
    				if(!empty($_POST['auto_id']))
    				{
    				    $ide = $_POST['auto_id'];
                       	$this->db->Where('id',$ide);
    					$this->db->update('app_bar_theme',$f);
    	                 $this->session->set_flashdata('message_name','App bar theme Updated successfully');
                        redirect(base_url() . 'Admin/app_bar_theme');
                    }
                    else
                    {
                         $this->session->set_flashdata('error', 'App bar theme not Updated successfully');
			
                    }
           
           
        }
            redirect(base_url() . 'Admin/app_bar_theme');
    }
    
    

    public function driver_list(){
    if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/driver_list');
    $this->load->view('footer');
        }
    }


      public function active_driver_list(){
    if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
        
         $makelist = $this->Login_model->select_column_where(['*'],'tbl_vehiclemake',['status' => 1]);
             $driverlist = $this->Login_model->select_column_where(['*'],'tbl_driver',['status' => 1]);
             $typelist = $this->Login_model->select_column_where(['*'],'tbl_vehicletype',['status' => 1]);
             $data=array(
                'makelist'=>$makelist,
                'driverlist'=>$driverlist,
                'typelist'=>$typelist
            );
    $this->load->view('header');
    $this->load->view('admin/active_derver_list',$data);
    $this->load->view('footer');
        }
    }
   public function view()
   {
       $id=$_POST['id'];
    	if($id)
    	{
    	   $qry="SELECT v.*,mk.name as make_name,md.model_name,d.driver_name,d.driver_type,d.driver_id AS driverid,GROUP_CONCAT(t.name) AS type
           FROM tbl_vehicle v
           INNER JOIN tbl_vehiclemodel md ON md.id=v.model_id
           INNER JOIN tbl_vehiclemake mk ON mk.id=v.make_id
           INNER JOIN tbl_driver d ON d.id=v.driver_id
           INNER JOIN tbl_map_vehicletype mv ON mv.vehicle_id=v.id
           INNER JOIN tbl_vehicletype t ON t.id=mv.type_id WHERE v.id = $id";
           $row=$this->db->query($qry)->row_array();
           
           
           if(!empty($row))
           {
               ?>
            
               <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
				    <table id="tblsizewiserate" class="table table-striped table-bordered jambo_table bulk_action" style="width:100%;margin-bottom:20px;">
    					<tbody>
    						<tr>
    							<th style="width:15%">Driver Name</th>
    							<td style="width:30%"><?php echo $row['driver_type']."-".$row['driver_name']." (".$row['driverid'].")"?></td>
    							<th style="width:15%">Vehicle Make</th>
    							<td style="width:30%"><?php echo $row['make_name']?></td>
    						</tr>
    						<tr>
    							<th style="width:15%">Vehicle Model</th>
    							<td style="width:30%"><?php echo $row['model_name']?></td>
    							<th style="width:15%">Vehicle Type</th>
    							<td style="width:30%"><?php echo $row['type']?></td>
    						</tr>
    						<tr>
    							<th style="width:15%">Handicap Accessibility Available</th>
    							<td style="width:30%"><?php echo $row['handicap']?></td>
    							<th style="width:15%">Child Seat Accessibility Available </th>
    							<td style="width:30%"><?php echo $row['childseat']?></td>
    						</tr>
    						<tr>
    							<th style="width:15%">Vehicle Number</th>
    							<td style="width:30%"><?php echo $row['number']?></td>
    							<th style="width:15%">vehicle_color </th>
    							<td style="width:30%"><?php echo $row['color']?></td>
    						</tr>
    						<tr>
    							<th style="width:15%">Vehicle Year</th>
    							<td style="width:30%"><?php echo $row['year']?></td>
    							<th style="width:15%">Insurance </th>
    							<td style="width:30%">
    							    
    							   
                                <?php if (!empty($row['insurance_image'])): ?>
                                    <a href="<?php echo base_url() . $row['insurance_image']; ?>" target="_blank">
                                        <img src="<?php echo base_url() . $row['insurance_image']; ?>" width="80px" height="80px">
                                    </a>
                                <?php else: ?>
                                    <span>Image Not Available</span>
                                <?php endif; ?>
    							    
    							    <!--<a href="<?//php echo base_url().$row['insurance_image'] ?>" -->
    							    <!--target="_blank"><img src="<?//php echo base_url().$row['insurance_image'] ?>" -->
    							    <!--width="80px" height="80px"></a>-->
    							    
    							    
    							 </td>
    						</tr>
    						<tr>
    							<th style="width:15%">Vehicle Status</th>
    							<td style="width:30%"><?php 
    							
    							if($row['status']==1)
    							{
    							    echo "Active";
    							}
    							else
    							{
    							    echo "inactive";
    							}
    							?></td>
    							<th style="width:15%">Insurance </th>
    							<td style="width:30%"><?php echo $row['insurance_status']?></td>
    						</tr>
    					</tbody>
					</table>
				</div>
               <?php
           }
           else
           {
               echo "Data not found";
           }
    	}
   }
   
   public function user_view()
   {
       $id=$_POST['id'];
    	if($id)
    	{
    	    
    	    $qry="SELECT * FROM tbl_user WHERE id=$id";
    	   
           $row=$this->db->query($qry)->row_array();
           
           if(!empty($row))
           {
               ?>
            
               <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
				    <table id="tblsizewiserate" class="table table-striped table-bordered jambo_table bulk_action" style="width:100%;margin-bottom:20px;">
    					<tbody>
                            <tr>
                                <th style="width:15%">User Name</th>
                                <td style="width:30%"><?php echo !empty($row['f_name']) ? $row['f_name'] : 'NA'; ?></td>
                                <th style="width:15%">User ID</th>
                                <td style="width:30%"><?php echo !empty($row['user_id']) ? $row['user_id'] : 'NA'; ?></td>
                            </tr>
                            <tr>
                                <th style="width:15%">Mobile No</th>
                                <td style="width:30%"><?php echo !empty($row['mobile_no']) ? $row['mobile_no'] : 'NA'; ?></td>
                                <th style="width:15%">Email Id</th>
                                <td style="width:30%"><?php echo !empty($row['email_id']) ? $row['email_id'] : 'NA'; ?></td>
                            </tr>
                            <tr>
                                <th style="width:15%">Pincode</th>
                                <td style="width:30%"><?php echo !empty($row['pincode']) ? $row['pincode'] : 'NA'; ?></td>
                                <th style="width:15%">Address</th>
                                <td style="width:30%"><?php echo !empty($row['address']) ? $row['address'] : 'NA'; ?></td>
                            </tr>
                            <tr>
                                <th style="width:15%">Wallet</th>
                                <td style="width:30%"><?php echo $row['wallet_amount']; ?></td>
                            </tr>
                            <tr>
                                <th style="width:15%">Status</th>
                                <td style="width:30%">
                                    <?php 
                                    if (!empty($row['status']) && $row['status'] == 1) {
                                        echo "Active";
                                    } else {
                                        echo "Inactive";
                                    }
                                    ?>
                                </td>
                            </tr>
                        </tbody>

    					
					</table>
				</div>
               <?php
           }
           else
           {
               echo "Data not found";
           }
    	}
   }
   
   
   public function update_driverlocation()
   {
       $id=$_POST['id'];
    	if($id)
    	{
    	    
    	    //$qry="SELECT * FROM tbl_driver_currentLocation WHERE id=$id";
    	    
    	    $qry="SELECT v.*,dr.driver_name,dr.driver_id As driverid  
                FROM tbl_driver_currentLocation v
                    INNER JOIN  tbl_driver dr ON dr.id=v.driver_id
                   WHERE  v.id =$id ";
    	   
             $value=$this->db->query($qry)->row();
           
           if(!empty($value))
           {
               ?>
              
            
               <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                   
                   <form method="POST" action="<?php echo base_url();?>Admin/update_driver_location" class="form" enctype="multipart/form-data">
                     <label for="file-img" class="form-label fs-6">Driver Name <span class="text-danger"> *</span></label>
                    <input type="text"  class="form-control" name="driver_name" value="<?php echo $value->driver_name; ?>" readonly required="">
                    
                    <label for="file-img" class="form-label fs-6">Driver Id <span class="text-danger"> *</span></label>
                    <input type="text"  class="form-control" name="driver_id" value="<?php echo $value->driverid; ?>" readonly required="">
                    
                    <label for="file-img" class="form-label fs-6">Current lat <span class="text-danger"> *</span></label>
                    <input type="text"  class="form-control" name="curr_lat" value="<?php echo $value->curr_lat; ?>" required="">
                    
                    <label for="file-img" class="form-label fs-6">Current Long <span class="text-danger"> *</span></label>
                    <input type="text"  class="form-control" name="curr_long" value="<?php echo $value->curr_long; ?>" required="">
    
                    
                    
                    
                    <input type="hidden"  name="id" value="<?php echo $value->id; ?>">
                    
                    <div class="py-2 text-end">
                        <button type="submit"  class="btn btn-primary">Update</button>
                      </div>
                </form>
				    
				</div>
               <?php
           }
           else
           {
               echo "Data not found";
           }
    	}
   }
   
    public function update_rentalkmlist()
   {
       $id=$_POST['id'];
    	if($id)
    	{
    	    
    	    $qry="SELECT * FROM tbl_rental_km_hrs 
                   WHERE  tbl_rental_km_hrs.id =$id ";
    	   
             $value=$this->db->query($qry)->row();
           
           if(!empty($value))
           {
               ?>
              
            
               <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                   
                   <form method="POST" action="<?php echo base_url();?>Admin/update_rental_kmlist" class="form" enctype="multipart/form-data">
                     <label for="file-img" class="form-label fs-6">km <span class="text-danger"> *</span></label>
                    <input type="number"  class="form-control" name="km" value="<?php echo $value->km; ?>">
                    
                    <label for="file-img" class="form-label fs-6">Hrs <span class="text-danger"> *</span></label>
                    <input type="number"  class="form-control" name="hrs" value="<?php echo $value->hrs; ?>">
                    
                    <input type="hidden"  name="id" value="<?php echo $value->id; ?>">
                    
                    <div class="py-2 text-end">
                        <button type="submit"  class="btn btn-primary">Update</button>
                      </div>
                </form>
				    
				</div>
               <?php
           }
           else
           {
               echo "Data not found";
           }
    	}
   }
   
   
   public function vehicle_list(){
        if ($this->session->userdata('admin_login_id') == "" ) {
              redirect('Base/login/');
        } else {
        $this->load->view('header');
        $this->load->view('admin/vehicle_list');
        $this->load->view('footer');
            }
    }
    
    
    public function add_fare(){
        if ($this->session->userdata('admin_login_id') == "" ) {
              redirect('Base/login/');
        } else {
        $this->load->view('header');
        $this->load->view('admin/add_fare');
        $this->load->view('footer');
            }
    }
    
    
    
    
    
   public function add_driver(){
        if ($this->session->userdata('admin_login_id') == "" ) {
              redirect('Base/login/');
        } else {
        $this->load->view('header');
        $this->load->view('admin/add_driver');
        $this->load->view('footer');
            }
    }
     
     
      public function cod_Summary(){
        if ($this->session->userdata('admin_login_id') == "" ) {
              redirect('Base/login/');
        } else {
        $this->load->view('header');
        $this->load->view('admin/cod_collection');
        $this->load->view('footer');
            }
    }
    
    public function cod_Collected($id=''){
     
     if(!empty($id)){
     
         $f = array (
                
                 'status' => 1 ,
                 'clt_date' =>  date('Y-m-d H:i:s') 
                 
                 );
                 $this->session->set_flashdata('message_name', 'Amount has been collected');
                 
        $this->Login_model->Update( "tbl_cod_collection" , $f, array('id'=> $id ));
      
       redirect('Admin/cod_Summary');
       
     }
     
        
    }
    
    
       
    public function all_delivery_cod_summary()
    {
  
        $draw=$_POST['draw'];
       
        $startdate='';
        
        
        $enddate='';
        if($_POST['daterange'])
        {
            $ex=explode(" - ",$_POST['daterange']);
            if(!empty($ex))
            {
                $fromdate=$ex[0];
                $todate=$ex[1];
            
                $date = str_replace('/', '-', $fromdate);
                $startdate=date('Y-m-d', strtotime($date));
                
        
                $date1 = str_replace('/', '-', $todate);
                $enddate=date('Y-m-d', strtotime($date1));
            }
        }
        
        
        
        $datefilter_qry="";
        if($startdate && $enddate)
        {
            $datefilter_qry="and  STR_TO_DATE(tbl_cod_collection.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
        }
        
        
        $extra_qry='';
        if($_POST['searchvalue'])
        {
            $searchValue=trim($_POST['searchvalue']); 
            
            $search_qry="and  (tbl_cod_collection.book_id LIKE '%$searchValue%'  OR tbl_cod_collection.cod_amt LIKE '%$searchValue%' OR tbl_driver.driver_id LIKE '%$searchValue%' OR tbl_driver.driver_name LIKE '%$searchValue%')";
        }else{
            $search_qry=""; 
        }
        
      if($_POST['sts_fltr']){
           
          
          
          if($_POST['sts_fltr'] == '2'){
              
              $sts_flt = "and tbl_cod_collection.status = 0 " ;
          }else if($_POST['sts_fltr'] == '1'){
              $sts_flt = " and tbl_cod_collection.status = 1 " ;
              
          }else{
              $sts_flt='';
          }
          
      }else{
           
          $sts_flt = '';
      }
      
     
     $sql = "SELECT tbl_cod_collection.*,tbl_driver.driver_id AS user_id ,tbl_driver.driver_name AS user_name FROM  tbl_cod_collection INNER JOIN  tbl_driver ON  tbl_cod_collection.driver_id = tbl_driver.id where cod_amt > 0  $sts_flt  $datefilter_qry $search_qry order by tbl_cod_collection.id desc ";
    
      
      
        
        $limit="LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];

        $totalRecords =$this->db->query($sql)->num_rows();
        
        $result=$this->db->query($sql.$limit)->result_array();

        if(!empty($result))
        {
            $i=0;
            $minus_length=0;
            if($_REQUEST['start'] > 0)
            {
                $minus_length=$_REQUEST['start'];
            }
            $index=$totalRecords-$minus_length;
            foreach($result as $row)
            {
                if($row['status'] == 0) {
                   
                    $label = '<span class="badge rounded-pill bg-warning">pending</span>' ;
                      $act = '<a class="btn btn-info btn-sm text-white" role="button" href="' . base_url() . 'Admin/cod_Collected/' . $row['id'] .'"> Collect Amount</a>';

                }
                
                if($row['status'] == 1 ) {
                   
                    $label = '<span class="badge rounded-pill bg-success">Collected</span>' ;
                $act = '<a class="text-success" href="#">Amount Collected</a>';
                    
                }
                    
                    
                    
                    
                $response['list'][$i]['id']=$index;
                
                $response['list'][$i]['dl_date']=date("d-m-Y h:i:s a", strtotime(trim($row['created_at'])));
               
                $response['list'][$i]['book_id']=$row['book_id'];
                $response['list'][$i]['user_id']=$row['user_id'];
                  $response['list'][$i]['d_name']=$row['user_name'];
                $response['list'][$i]['status']=$label;               
                
                $response['list'][$i]['amount']="<b>".'Rs. '.number_format($row['cod_amt'],2)."</b>";
                $response['list'][$i]['act']=$act;    
                    
                $i++;
                $index--;
            }
        }
        else
        {
            $response['list']=[];
        }
        
        
        $json_data = array(
        "draw"            => intval( $_REQUEST['draw'] ),   
        "recordsTotal"    => intval($totalRecords ),  
        "recordsFiltered" => intval($totalRecords),
        "data"            => $response['list']   // total data array
        );
        
        echo json_encode($json_data);
    }
    
     
     public function manage_booking(){
          if ($this->session->userdata('admin_login_id') == "" ) {
              redirect('Base/login/');
        } else {
         $this->load->view('header');
        $this->load->view('admin/manage_booking');
        $this->load->view('footer');
         
        }
         
     }
    
    
    
    
   public function driver_view()
   {
       $id=$_POST['id'];
    	if($id)
    	{
    	   $qry="SELECT v.*,mk.name as make_name,md.model_name,d.driver_name,d.driver_type,d.email,d.mobile_no,d.password,d.address,d.driving_license_image,d.driver_profile_pic,d.state,d.city,d.driver_id AS driverid,GROUP_CONCAT(t.name) AS type
           FROM tbl_vehicle v
           INNER JOIN tbl_vehiclemodel md ON md.id=v.model_id
           INNER JOIN tbl_vehiclemake mk ON mk.id=v.make_id
           INNER JOIN tbl_driver d ON d.id=v.driver_id
           INNER JOIN tbl_map_vehicletype mv ON mv.vehicle_id=v.id
           INNER JOIN tbl_vehicletype t ON t.id=mv.type_id WHERE v.id = $id";
           $row=$this->db->query($qry)->row_array();
           
          $driverid= $row['driverid']; 
          $qry1="SELECT id FROM tbl_driver WHERE driver_id='$driverid' ";
          $rs=$this->db->query($qry1)->row_array();
          
          $id=$rs['id'];
          
          $qry2="SELECT * FROM tbl_booking WHERE driver_id='$id' ";
          
          $res=$this->db->query($qry2)->result();
          
          $totalbooking=count($res);
           
           
           
           
           if(!empty($row))
           {
               ?>
            
               <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
				    <table id="tblsizewiserate" class="table table-striped table-bordered jambo_table bulk_action" style="width:100%;margin-bottom:20px;">
				                <h3 style="color:red">Total Booking-<?php echo $totalbooking;?></h3>
    						   
    					<tbody>
    						<tr>
    							<th style="width:15%">Driver Name</th>
    							<td style="width:30%"><?php echo $row['driver_type']."-".$row['driver_name']." (".$row['driverid'].")"?></td>
    							<th style="width:15%">Driver Mobile No</th>
    					     	<td style="width:30%"><?php echo $row['mobile_no']?></td>
    						<th style="width:15%">Driver Email</th>
    					     	<td style="width:30%"><?php echo $row['email']?></td>
    							
    						</tr>
    						    						<tr>
    						    	<th style="width:15%">Driver Address</th>
    							<td style="width:30%"><?php echo $row['address']?></td>
    							<th style="width:15%">Vehicle State</th>
    							<td style="width:30%"><?php echo $row['state']?></td>
    							<th style="width:15%">Vehicle city</th>
    							<td style="width:30%"><?php echo $row['city']?></td>
    						</tr>
    						 						<tr>
    						    	<th style="width:15%">Driver Password</th>
    							<td style="width:30%"><?php echo $row['password']?></td>
    							
    							<th style="width:15%">Driver Photo </th>
    							
    							<td style="width:30%">
                                    <?php if (!empty($row['driver_profile_pic'])): ?>
                                        <a href="<?= base_url($row['driver_profile_pic']) ?>" target="_blank">
                                            <img src="<?= base_url($row['driver_profile_pic']) ?>" width="80px" height="80px">
                                        </a>
                                    <?php else: ?>
                                        <span>Image Not Available</span>
                                    <?php endif; ?>
                                </td>

    							
    							<!--<td style="width:30%"><a href="<?//php echo base_url().$row['driver_profile_pic'] ?>" 
    							target="_blank"><img src="<?//php echo base_url().$row['driver_profile_pic'] ?>" width="80px" height="80px"></a></td>-->
    					 
    							<th style="width:15%">Driver Licence </th>
    							
    							<td style="width:30%">
                                    <?php if (!empty($row['driving_license_image'])): ?>
                                        <a href="<?= base_url($row['driving_license_image']) ?>" target="_blank">
                                            <img src="<?= base_url($row['driving_license_image']) ?>" width="80px" height="80px">
                                        </a>
                                    <?php else: ?>
                                        <span>Image Not Available</span>
                                    <?php endif; ?>
                                </td>
    							
    							
    							<!--<td style="width:30%"><a href="<?//php echo base_url().$row['driving_license_image'] ?>" 
    							target="_blank"><img src="<?//php echo base_url().$row['driving_license_image'] ?>" width="80px" height="80px"></a></td>-->
    					 
    						</tr>
    						<tr>
    						    	<th style="width:15%">Vehicle Make</th>
    							<td style="width:30%"><?php echo $row['make_name']?></td>
    							<th style="width:15%">Vehicle Model</th>
    							<td style="width:30%"><?php echo $row['model_name']?></td>
    							<th style="width:15%">Vehicle Type</th>
    							<td style="width:30%"><?php echo $row['type']?></td>
    							
    						</tr>
    					
    						<tr>
    						    <th style="width:15%">vehicle_color </th>
    							<td style="width:30%"><?php echo $row['color']?></td>
    							<th style="width:15%">Vehicle Year</th>
    							<td style="width:30%"><?php echo $row['year']?></td>
    							<th style="width:15%">Insurance </th>
    							
    							<td style="width:30%">
                                    <?php if (!empty($row['insurance_image'])): ?>
                                        <a href="<?= base_url($row['insurance_image']) ?>" target="_blank">
                                            <img src="<?= base_url($row['insurance_image']) ?>" width="80px" height="80px">
                                        </a>
                                    <?php else: ?>
                                        <span>Image Not Available</span>
                                    <?php endif; ?>
                                </td>
    							
    							
    							<!--<td style="width:30%"><a href="<?//php echo base_url().$row['insurance_image'] ?>" -->
    							<!--target="_blank"><img src="<?//php echo base_url().$row['insurance_image'] ?>" -->
    							<!--width="80px" height="80px"></a></td>-->
    					 
    					 	</tr>
    						<tr>
    						    	<th style="width:15%">Vehicle Number</th>
    							<td style="width:30%"><?php echo $row['number']?></td>
    							<th style="width:15%">Vehicle Status</th>
    							<td style="width:30%"><?php 
    							
    							if($row['status']==1)
    							{
    							    echo "Active";
    							}
    							else
    							{
    							    echo "inactive";
    							}
    							?></td>
    							<th style="width:15%">Insurance </th>
    							<td style="width:30%"><?php echo $row['insurance_status']?></td>
    						</tr>
    					</tbody>
					</table>
				</div>
               <?php
           }
           else
           {
               echo "Data not found";
           }
    	}
   }
    
    
    public function list()
   {
       
          $draw=$_POST['draw'];       
          $fltstatus=$_POST['fltstatus'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(v.entry_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);    
           
              
              $search_qry=" WHERE (tmp.book_id LIKE '%$searchValue%' OR tmp.driverid LIKE '%$searchValue%' 
              OR tmp.driver_name LIKE '%$searchValue%' OR tmp.type LIKE '%$searchValue%' OR tmp.number LIKE '%$searchValue%'
              OR tmp.paymenttype LIKE '%$searchValue%'
              )"; 
           
          }
          
          $sql = "SELECT tmp.* FROM ( SELECT v.*,d.driver_name, tv.number,d.driver_id AS driverid,GROUP_CONCAT(t.name) AS type
          FROM tbl_booking v
          INNER JOIN tbl_driver d ON d.id=v.driver_id
          INNER JOIN tbl_vehicle tv ON tv.driver_id = v.driver_id
          INNER JOIN tbl_vehicletype t ON t.id=v.type_id
          WHERE v.ride_status LIKE '$fltstatus' $datefilter_qry GROUP BY v.id ) AS tmp $search_qry ORDER BY tmp.id DESC";
        
        //  $sql =  "SELECT tbl_booking.* , tbl_driver.*  FROM tbl_booking INNER JOIN tbl_driver ON tbl_driver.id = tbl_booking.driver_id where tbl_driver.status = 1 ORDER BY tbl_booking.id DESC ";

            
            // echo $sql;
            // die;
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {     
                 
                 
                 if($r->ride_status==0){
                      
                       $sts = '<span class="text-warning">Pending</span>';
                  }else if($r->ride_status==1){
                      $sts = '<span class="text-info">start</span>';
                  }else if($r->ride_status== 2){
                       $sts = '<span class="text-success">Completed</span>';
                  }else if($r->ride_status==3){
                       $sts = '<span class="text-danger">Cancel</span>';
                  }
               
                $response['list'][$i]['i']=$index;
                $response['list'][$i]['driver_name']=$r->driver_name;
                $response['list'][$i]['driver_id']=$r->driverid;
                 $response['list'][$i]['book']=$r->book_id;
                $response['list'][$i]['type']=$r->type;
                $response['list'][$i]['dist']=$r->user_journey_distance;
                 $response['list'][$i]['fare']=$r->total_fare;
                  $response['list'][$i]['drop']=$r->drop_address;
                   $response['list'][$i]['pick']=$r->pickup_address;
                $response['list'][$i]['number']=$r->number;
                $response['list'][$i]['entry_date']=date("d-m-Y h:i:s a", strtotime(trim($r->entry_date)));  
                $response['list'][$i]['status']=$sts;
                
                $collect_cash='';
                $collect_total_cash=0;
                if($r->ride_status==2)
                {
                    if($r->post_paymenttype == 'COD')
                    {   
                       $collect_total_cash=round($r->total_fare+$r->total_wait_charge,2);
                       $collect_cash='<a href="javascript:void(0);" class="delete" data-toggle="tooltip" title="Collect cash" onclick="collectcash('.$r->id.')" aria-hidden="true" style="color:green;font-size:27px">
    						 <i class="fa fa-check-square" aria-hidden="true"></i></a>';     
                    }
                    else if($r->post_paymenttype == 'COD' && $r->post_paymenttype != 'COD')
                    {
                        $collect_total_cash=round($r->total_wait_charge,2);
                    }
                }
               
                $response['list'][$i]['collect_total_cash']=$collect_total_cash;
                $response['list'][$i]['payment_type']=$r->paymenttype;
                
                $action='<a href="javascript:void(0);" class="delete" data-toggle="tooltip" title="View Details" 
                onclick="view_detail('.$r->id.')" aria-hidden="true" style="color:#0e2b05ed;font-size:27px">
						 <i class="fa fa-eye" aria-hidden="true"></i></a>'.$collect_cash;
								
						
                $response['list'][$i]['action']=$action;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
   } 
    
    
    public function user_bookinglist()
   {
       
          $draw=$_POST['draw'];       
          $fltstatus=$_POST['fltstatus'];
          $startdate='';
          $enddate='';
          
          $id=$_POST['id'];
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(v.entry_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);    
           
              
              $search_qry=" AND (v.book_id LIKE '%$searchValue%' OR dr.driver_id LIKE '%$searchValue%' 
              OR dr.driver_name LIKE '%$searchValue%'OR tv.number LIKE '%$searchValue%' 
              )"; 
           
          }
          
          
          $sql="SELECT v.*,md.*,dr.driver_name,tv.number,dr.driver_id,dr.driver_profile_pic  
                FROM tbl_booking v
              INNER JOIN  tbl_user md ON md.id=v.user_id
              INNER JOIN tbl_vehicle tv ON tv.driver_id = v.driver_id
              LEFT JOIN tbl_driver dr ON v.driver_id = dr.id
              WHERE v.user_id = '$id' $datefilter_qry $search_qry ";
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
            
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {     
                 
                 
                 if($r->ride_status==0){
                      
                       $sts = '<span class="text-warning">Pending</span>';
                  }else if($r->ride_status==1){
                      $sts = '<span class="text-info">start</span>';
                  }else if($r->ride_status== 2){
                       $sts = '<span class="text-success">Completed</span>';
                  }else if($r->ride_status==3){
                       $sts = '<span class="text-danger">Cancel</span>';
                  }
               
                $response['list'][$i]['i']=$index;
                $response['list'][$i]['driver_name']=$r->driver_name;
                $response['list'][$i]['driver_id']=$r->driver_id;
                 $response['list'][$i]['book']=$r->book_id;
                $response['list'][$i]['dist']=$r->user_journey_distance;
                $response['list'][$i]['fare']=$r->total_fare;
                $response['list'][$i]['drop']=$r->drop_address;
                $response['list'][$i]['pick']=$r->pickup_address;
                $response['list'][$i]['entry_date']=date("d-m-Y h:i:s a", strtotime(trim($r->entry_date)));  
                $response['list'][$i]['status']=$sts;
                
                $collect_cash='';
                $collect_total_cash=0;
                if($r->ride_status==2)
                {
                    if($r->post_paymenttype == 'COD')
                    {   
                       $collect_total_cash=round($r->total_fare+$r->total_wait_charge,2);
                       $collect_cash='<a href="javascript:void(0);" class="delete" data-toggle="tooltip" title="Collect cash" onclick="collectcash('.$r->id.')" aria-hidden="true" style="color:green;font-size:27px">
    						 <i class="fa fa-check-square" aria-hidden="true"></i></a>';     
                    }
                    else if($r->post_paymenttype == 'COD' && $r->post_paymenttype != 'COD')
                    {
                        $collect_total_cash=round($r->total_wait_charge,2);
                    }
                }
               
                $response['list'][$i]['collect_total_cash']=$collect_total_cash;
                
                $action='<a href="javascript:void(0);" class="delete" data-toggle="tooltip" title="View Details" 
                onclick="view_detail('.$r->id.')" aria-hidden="true" style="color:#0e2b05ed;font-size:27px">
						 <i class="fa fa-eye" aria-hidden="true"></i></a>'.$collect_cash;
								
						
                // $response['list'][$i]['action']=$action;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
   }
    
    
    
    public function fare_manage(){
        
         if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/fare_manage');
    $this->load->view('footer');
        }
        
        
        
    }
    
    
    
    public function data_table_theme(){
        
         if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/data_table_theme');
    $this->load->view('footer');
        }
        
        
        
    }
    
    
    public function gradient(){
        
         if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/gradient');
    $this->load->view('footer');
        }
        
        
        
    }
    
    public function app_bar_theme(){
        
         if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/app_bar_theme');
    $this->load->view('footer');
        }
        
        
        
    }
    
    public function icon_theme(){
        
         if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/icon_theme');
    $this->load->view('footer');
        }
        
        
        
    }
    
    public function text_theme(){
        
         if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/text_theme');
    $this->load->view('footer');
        }
        
        
        
    }
    
    
    
    public function get_gradient()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" WHERE STR_TO_DATE(gradient.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" WHERE (gradient.start_color = '$searchValue')";    
           
          }

          if($data_type=='all')
          {
             $sql =   " SELECT * FROM gradient $datefilter_qry $search_qry ORDER BY id DESC ";
          }
          
          
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              { 
               
                $button = '<a href="#" class="btn btn-secondary" role="button"   onclick="edit_fare('.$r->id.')">Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at)));  
                $response['list'][$i]['start_color']= !empty($r->start_color)?$r->start_color:'NA';  
                $response['list'][$i]['center_color']= !empty($r->center_color)?$r->center_color:'NA'; 
                $response['list'][$i]['end_color']= !empty($r->end_color)?$r->end_color:'NA'; 
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    
    public function get_data_table_theme()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" WHERE STR_TO_DATE(data_table_theme.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" WHERE (data_table_theme.font_family = '$searchValue')";    
           
          }

          if($data_type=='all')
          {
             $sql =   " SELECT * FROM data_table_theme $datefilter_qry $search_qry ORDER BY id DESC ";
          }
          
          
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              { 
               
                $button = '<a href="#" class="btn btn-secondary" role="button"   onclick="edit_fare('.$r->id.')">Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at)));  
                $response['list'][$i]['font_family']= !empty($r->font_family)?$r->font_family:'NA';  
                $response['list'][$i]['font_size']= !empty($r->font_size)?$r->font_size:'NA'; 
                $response['list'][$i]['heading_color']= !empty($r->heading_color)?$r->heading_color:'NA'; 
                $response['list'][$i]['divider_thickness']= !empty($r->divider_thickness)?$r->divider_thickness:'NA'; 
                $response['list'][$i]['heading_row_color']= !empty($r->heading_row_color)?$r->heading_row_color:'NA'; 
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    public function get_app_bar_theme()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" WHERE STR_TO_DATE(app_bar_theme.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" WHERE (app_bar_theme.background_color = '$searchValue')";    
           
          }

          if($data_type=='all')
          {
             $sql =   " SELECT * FROM app_bar_theme $datefilter_qry $search_qry ORDER BY id DESC ";
          }
          
          
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              { 
               
                $button = '<a href="#" class="btn btn-secondary" role="button"   onclick="edit_fare('.$r->id.')">Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at)));  
                $response['list'][$i]['background_color']= !empty($r->background_color)?$r->background_color:'NA';  
                $response['list'][$i]['elevation']= !empty($r->elevation)?$r->elevation:'NA'; 
                $response['list'][$i]['shadow_color']= !empty($r->shadow_color)?$r->shadow_color:'NA'; 
                $response['list'][$i]['border_radius_bottom_left']= !empty($r->border_radius_bottom_left)?$r->border_radius_bottom_left:'NA'; 
                $response['list'][$i]['border_radius_bottom_right']= !empty($r->border_radius_bottom_right)?$r->border_radius_bottom_right:'NA'; 
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    public function get_icontheme()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" WHERE STR_TO_DATE( icon_theme.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" WHERE ( icon_theme.icon_theme_color = '$searchValue')";    
           
          }

          if($data_type=='all')
          {
             $sql =   " SELECT * FROM icon_theme $datefilter_qry $search_qry ORDER BY id DESC ";
          }
          
          
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              { 
               
                $button = '<a href="#" class="btn btn-secondary" role="button"   onclick="edit_fare('.$r->id.')">Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at)));  
                $response['list'][$i]['icon_theme_color']= !empty($r->icon_theme_color)?$r->icon_theme_color:'NA';  
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    public function get_text_theme()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" WHERE STR_TO_DATE(text_theme.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" WHERE (text_theme.font_family = '$searchValue')";    
           
          }

          if($data_type=='all')
          {
             $sql =   " SELECT * FROM text_theme $datefilter_qry $search_qry ORDER BY id DESC ";
          }
          
          
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              { 
               
                $button = '<a href="#" class="btn btn-secondary" role="button"   onclick="edit_fare('.$r->id.')">Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at)));  
                $response['list'][$i]['font_family']= !empty($r->font_family)?$r->font_family:'NA';  
                $response['list'][$i]['font_weight']= !empty($r->font_weight)?$r->font_weight:'NA'; 
                $response['list'][$i]['font_size']= !empty($r->font_size)?$r->font_size:'NA'; 
                $response['list'][$i]['text_theme_color']= !empty($r->text_theme_color)?$r->text_theme_color:'NA'; 
                $response['list'][$i]['section_name']= !empty($r->section_name)?$r->section_name:'NA'; 
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    
    
    
  public function get_driverlist()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" WHERE STR_TO_DATE(tbl_driver.created_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" and (tbl_driver.name = '$searchValue')";    
           
          }

          if($data_type=='all')
          {
           
            $sql = "SELECT * FROM tbl_driver  where status = 0 OR status = 2  $datefilter_qry $search_qry ORDER BY tbl_driver.id DESC";
     
          }
          
          
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {         
                  
                  if($r->status==1){
                      
                       $sts = '<span class="text-success">Active</span>';
                  }
                   else if($r->status==2){
                      
                       $sts = '<span class="text-danger">Rejected</span>';
                  }
                  else{
                      $sts = '<span class="text-warning">Pending</span>';
                  }
               
                $status = '<i class="fa-solid fa-eye rounded-pill fs-6 me-1" role="button"  data-bs-toggle="modal" data-bs-target="#staticview' . $r->id . '"></i>';

                $button = '<a href="#" class="btn btn-secondary" role="button"  onclick="edit_driver('.$r->id.')"        >Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_date)));  
                $response['list'][$i]['name']= !empty($r->driver_name)?$r->driver_name:'NA';  
                $response['list'][$i]['driver_id']= !empty($r->driver_id)?$r->driver_id:'NA'; 
                $response['list'][$i]['gendr']= !empty($r->gender)?$r->gender:'NA'; 
                $response['list'][$i]['email']= !empty($r->email)?$r->email:'NA'; 
                $response['list'][$i]['mob']= !empty($r->mobile_no)?$r->mobile_no:'NA'; 
                $response['list'][$i]['v_no']= !empty($r->driver_name)?$r->driver_name:'NA'; 
                  $response['list'][$i]['add']= !empty($r->address)?$r->address:'NA'; 
                $response['list'][$i]['sts']=$sts;
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    
    public function update_pendriver(){
        
        $name = $_POST['first_name'] ;
        $email = $_POST['email'] ;
        $sts = $_POST['status'] ;
        $state = $_POST['state'] ;
        $pin = $_POST['pin_code'] ;
        $city = $_POST['city'] ;
        $add = $_POST['address'] ;
        $mobile = $_POST['mobile_number'] ;
        $pass=  $_POST['password'] ;
        $id =  $_POST['edit_id'] ;
        	$image =$_FILES['driver_photo']['name'];
        	
        	
        	
        
        	$result_row=$this->Login_model->select_column_where(['*'],'tbl_driver',['id'=>$id]);
					
					$result=$result_row[0];
					$img_name =$result['driver_profile_pic'];
        
        	$time=time();
        	
        	if($image)
					{
        		unlink($result['driver_profile_pic']);
						$ext = pathinfo($_FILES['driver_photo']['name'], PATHINFO_EXTENSION);
    					$img_name='uploads/images/DriverProfile/img_'.$time.".".$ext;
        	$this->my_upload->upload($_FILES['driver_photo']);
        	if ( $this->my_upload->uploaded == true  ) 
    					{
    						$this->my_upload->allowed         		= array('image/*');
    						$this->my_upload->file_new_name_body    = 'img_'.$time;
    						//$this->my_upload->image_convert 		= 'jpg';
    						$this->my_upload->jpeg_quality 			= 100;	
    						$this->my_upload->image_resize          = true;
    						$this->my_upload->image_ratio_fill   = true;
    						$this->my_upload->image_x               = 270;
    						$this->my_upload->image_y         		= 168;
    
    					
    						$this->my_upload->process('uploads/images/DriverProfile/');
    						if ( $this->my_upload->processed == true ) 
    						{
    							$this->my_upload->clean();  
    						} 
    						
    					}
					}
					
					
        		$data = array(
					"driver_name" => $name,
					"driver_profile_pic"=>$img_name,
					"status"=>$sts,
					"pin_code"=>$pin,
					"address"=>$add,
					"password"=>$pass,
					"mobile_no"=>$mobile,
					"email"=>$email,
					"state"=>$state,
					"city"=>$city,
				
				    );
				    
				  
					$this->db->Where('id',$id);
					$this->db->update('tbl_driver',$data);

					$this->session->set_flashdata('message_name','Data updated successfully');    
					redirect('Admin/driver_list');
        
        
    }
    
     public function edit_driver_data()
   {
        header("Access-Control-Allow-Origin: *");
    	header("Content-Type: application/json; charset=UTF-8");
    	$status=0;
    	$message='Invalid Request';
    	
    	$id=$_POST['id'];
    	if($id)
    	{
    		 $result = $this->Login_model->select_column_where(['*'],
            'tbl_driver',['id' => $id]);
    		
    		if(!empty($result))
    		{
    		    $response['id']=$result[0]['id'];
    		    
    		    $response['name']=$result[0]['driver_name'];
    		    $response['email']=$result[0]['email'];
    		    $response['mob']=$result[0]['mobile_no'];
    		    $response['pass']=$result[0]['password'];
    		    $response['add']=$result[0]['address'];
    		     $response['gen']=$result[0]['gender'];
    		    $response['city']=$result[0]['city'];
    		    $response['state']=$result[0]['state'];
    		    $response['pin']=$result[0]['pin_code'];
    		    $response['profile']=$result[0]['driver_profile_pic'];
    		      $response['sts']=$result[0]['status'];
    		}
    		
    		
    		$status=1;
    		$message='success';
    			
    		
    	}
    	$response['status']=$status;
    	$response['message']=$message;
    	echo json_encode($response);
   }
   
    public function edit_fare_data()
   {
        header("Access-Control-Allow-Origin: *");
    	header("Content-Type: application/json; charset=UTF-8");
    	$status=0;
    	$message='Invalid Request';
    	
    	$id=$_POST['id'];
    	if($id)
    	{
    		 $result = $this->Login_model->select_column_where(['*'],
            'tbl_fare',['id' => $id]);
    		
    		if(!empty($result))
    		{
    		    $response['id']=$result[0]['id'];
    		    
    		    $response['status']=$result[0]['status'];
    		    $response['nightfare_charge']=$result[0]['nightfare_charge'];
    		    $response['end_time']=$result[0]['nightfare_end_time'];
    		    $response['strt_time']=$result[0]['nightfare_strt_time'];
    		    $response['night_fare_status']=$result[0]['night_fare_status'];
    		     $response['sch_fare']=$result[0]['sch_fare'];
    		    $response['wait_charge']=$result[0]['wait_charge'];
    		    $response['wait_time_limit']=$result[0]['wait_time_limit'];
    		    $response['capacity']=$result[0]['capacity'];
    		    $response['per_km']=$result[0]['per_km'];
    		      $response['vehicle_type']=$result[0]['vehicle_type'];
    		}
    		
    		
    		$status=1;
    		$message='success';
    			
    		
    	}
    	$response['status']=$status;
    	$response['message']=$message;
    	echo json_encode($response);
   }
   
   public function edit_data_table_theme()
   {
        header("Access-Control-Allow-Origin: *");
    	header("Content-Type: application/json; charset=UTF-8");
    	$status=0;
    	$message='Invalid Request';
    	
    	$id=$_POST['id'];
    	if($id)
    	{
    		 $result = $this->Login_model->select_column_where(['*'],
            'data_table_theme',['id' => $id]);
    		
    		if(!empty($result))
    		{
    		    $response['id']=$result[0]['id'];
    		    $response['font_family']=$result[0]['font_family'];
    		    $response['font_size']=$result[0]['font_size'];
    		    $response['heading_color']=$result[0]['heading_color'];
    		    $response['divider_thickness']=$result[0]['divider_thickness'];
    		    $response['heading_row_color']=$result[0]['heading_row_color'];
    		}
    		
    		
    		$status=1;
    		$message='success';
    			
    		
    	}
    	$response['status']=$status;
    	$response['message']=$message;
    	echo json_encode($response);
   }
   
   public function edit_text_theme()
   {
        header("Access-Control-Allow-Origin: *");
    	header("Content-Type: application/json; charset=UTF-8");
    	$status=0;
    	$message='Invalid Request';
    	
    	$id=$_POST['id'];
    	if($id)
    	{
    		 $result = $this->Login_model->select_column_where(['*'],
            'text_theme',['id' => $id]);
    		
    		if(!empty($result))
    		{
    		    $response['id']=$result[0]['id'];
    		    $response['section_name']=$result[0]['section_name'];
    		    $response['font_family']=$result[0]['font_family'];
    		    $response['font_weight']=$result[0]['font_weight'];
    		    $response['font_size']=$result[0]['font_size'];
    		    $response['text_theme_color']=$result[0]['text_theme_color'];
    		}
    		
    		
    		$status=1;
    		$message='success';
    			
    		
    	}
    	$response['status']=$status;
    	$response['message']=$message;
    	echo json_encode($response);
   }
   
   public function edit_app_bar_theme()
   {
        header("Access-Control-Allow-Origin: *");
    	header("Content-Type: application/json; charset=UTF-8");
    	$status=0;
    	$message='Invalid Request';
    	
    	$id=$_POST['id'];
    	if($id)
    	{
    		 $result = $this->Login_model->select_column_where(['*'],
            'app_bar_theme',['id' => $id]);
    		
    		if(!empty($result))
    		{
    		    $response['id']=$result[0]['id'];
    		    $response['background_color']=$result[0]['background_color'];
    		    $response['elevation']=$result[0]['elevation'];
    		    $response['shadow_color']=$result[0]['shadow_color'];
    		    $response['border_radius_bottom_left']=$result[0]['border_radius_bottom_left'];
    		    $response['border_radius_bottom_right']=$result[0]['border_radius_bottom_right'];
    		}
    		
    		
    		$status=1;
    		$message='success';
    			
    		
    	}
    	$response['status']=$status;
    	$response['message']=$message;
    	echo json_encode($response);
   }
   
   
   public function edit_gradient()
   {
        header("Access-Control-Allow-Origin: *");
    	header("Content-Type: application/json; charset=UTF-8");
    	$status=0;
    	$message='Invalid Request';
    	
    	$id=$_POST['id'];
    	if($id)
    	{
    		 $result = $this->Login_model->select_column_where(['*'],
            'gradient',['id' => $id]);
    		
    		if(!empty($result))
    		{
    		    $response['id']=$result[0]['id'];
    		    $response['start_color']=$result[0]['start_color'];
    		    $response['center_color']=$result[0]['center_color'];
    		    $response['end_color']=$result[0]['end_color'];
    		}
    		
    		
    		$status=1;
    		$message='success';
    			
    		
    	}
    	$response['status']=$status;
    	$response['message']=$message;
    	echo json_encode($response);
   }
   
   public function edit_icon_theme()
   {
        header("Access-Control-Allow-Origin: *");
    	header("Content-Type: application/json; charset=UTF-8");
    	$status=0;
    	$message='Invalid Request';
    	
    	$id=$_POST['id'];
    	if($id)
    	{
    		 $result = $this->Login_model->select_column_where(['*'],
            'icon_theme',['id' => $id]);
    		
    		if(!empty($result))
    		{
    		    $response['id']=$result[0]['id'];
    		    $response['icon_theme_color']=$result[0]['icon_theme_color'];
    		}
    		
    		
    		$status=1;
    		$message='success';
    			
    		
    	}
    	$response['status']=$status;
    	$response['message']=$message;
    	echo json_encode($response);
   }
    
    
    public function get_activedriverlist()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" and STR_TO_DATE(tbl_driver.created_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" and (tbl_driver.name = '$searchValue')";    
           
          }

          if($data_type=='all')
          {
           
           
          $sql =  "SELECT tbl_vehicle.* , tbl_driver.* ,tbl_vehiclemake.name as comp_name  FROM tbl_vehicle INNER JOIN tbl_driver ON tbl_driver.id = tbl_vehicle.driver_id INNER JOIN tbl_vehiclemake ON tbl_vehiclemake.id = tbl_vehicle.make_id where tbl_driver.status = 1 ORDER BY tbl_driver.id DESC ";

            
          }
          
          
           
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {         
                  
                  if($r->status==1){
                      
                       $sts = '<span class="text-success">Active</span>';
                  }else{
                      $sts = '<span class="text-warning">Pending</span>';
                  }
               
                $status = '<i class="fa-solid fa-eye rounded-pill fs-6 me-1" role="button"  data-bs-toggle="modal" data-bs-target="#staticview' . $r->id . '"></i>';

                $button = '<a href="#" class="btn btn-secondary" role="button" data-bs-toggle="modal" data-bs-target="#staticBackdrop' . $r->id . '">Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_date)));  
                $response['list'][$i]['name']= !empty($r->driver_name)?$r->driver_name:'NA';  
                $response['list'][$i]['driver_id']= !empty($r->driver_id)?$r->driver_id:'NA'; 
                $response['list'][$i]['gendr']= !empty($r->gender)?$r->gender:'NA'; 
                $response['list'][$i]['email']= !empty($r->email)?$r->email:'NA'; 
                $response['list'][$i]['mob']= !empty($r->mobile_no)?$r->mobile_no:'NA'; 
                $response['list'][$i]['v_no']= !empty($r->number)?$r->number:'NA'; 
                  $response['list'][$i]['add']= !empty($r->address)?$r->address:'NA'; 
                   $response['list'][$i]['cpmy']= !empty($r->comp_name)?$r->comp_name:'NA';
                $response['list'][$i]['sts']=$sts;
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    
    
    public function get_farelist()
    {  
       
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(tbl_fare.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" and (tbl_vehicletype.name = '$searchValue' OR tbl_fare.per_km LIKE '%$searchValue%' 
              OR tbl_fare.capacity LIKE '%$searchValue%' )";    
           
          }

          if($data_type=='all')
          {
     
                $sql =   " SELECT tbl_fare.*, tbl_vehicletype.name as vehicle_name
                FROM tbl_fare
                INNER JOIN tbl_vehicletype ON tbl_fare.vehicle_type = tbl_vehicletype.id 
                where tbl_fare.id != 0  $datefilter_qry $search_qry ORDER BY tbl_fare.id DESC";
     
          }
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {         
                  
                  if($r->night_fare_status==1){
                      
                       $sts = '<span class="text-success">Active</span>';
                  }else{
                      $sts = '<span class="text-warning">Pending</span>';
                  }
               
                if($r->status==0){
                      
                       $status = '<span class="text-success">Active</span>';
                  }else{
                      $status = '<span class="text-warning">Pending</span>';
                  }
                  
                  
                  $more_info = '<div class="dropdown">
                    <a class="dropdown-toggle" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false" href="#">
                        <i class="fa fa-plus" aria-hidden="true"></i>
                    </a>
                    <ul class="dropdown-menu py-0" aria-labelledby="dropdownMenuButton1">
                        <table class="table table-bordered mb-0" style="font-size: 12px;">
                            <thead>
                                <tr>
                                    <th>Nightfare Start Time</th>
                                    <th>Nightfare End Time</th>
                                    <th>Nightfare Charge</th>
                                </tr>
                            </thead>
                            <tbody>';
                        
                    if ($r->night_fare_status == 1) {
                        $more_info .= '<tr>
                                            <td>' . (!empty($r->nightfare_strt_time) ? $r->nightfare_strt_time : 'NA') . '</td>
                                            <td>' . (!empty($r->nightfare_end_time) ? $r->nightfare_end_time : 'NA') . '</td>
                                            <td>' . (!empty($r->nightfare_charge) ? $r->nightfare_charge : 'NA') . '</td>
                                       </tr>';
                    } else {
                        $more_info .= '<tr>
                                          <td colspan="3">No Data</td>
                                       </tr>';
                    }
                    
                    $more_info .= '</tbody>
                                    </table>
                                    </ul>
                                  </div>';

                  
                  
                  
               
                $button = '<a href="#" class="btn btn-secondary" role="button"   onclick="edit_fare('.$r->id.')">Edit</a>';

                $response['list'][$i]['i']=$index;
                $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at)));  
                $response['list'][$i]['veh_type']= !empty($r->vehicle_name)?$r->vehicle_name:'NA';  
                $response['list'][$i]['per_km']= !empty($r->per_km)?$r->per_km:'NA'; 
                $response['list'][$i]['cap']= !empty($r->capacity)?$r->capacity:'NA'; 
                $response['list'][$i]['wait_limit']= !empty($r->wait_time_limit)?$r->wait_time_limit:'NA'; 
                $response['list'][$i]['wait_Charge']= !empty($r->wait_time_limit)?$r->wait_time_limit:'NA'; 
                $response['list'][$i]['sch_fare']= !empty($r->sch_fare)?$r->sch_fare:'NA'; 
                  $response['list'][$i]['night_status']= !empty($r->night_fare_status)?$r->night_fare_status:'NA'; 
                  $response['list'][$i]['info']= $more_info; 
              $response['list'][$i]['status']= $status; 
              
                $response['list'][$i]['act']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
      public function registration_driver_old(){
        
       if(empty($_POST['file_1']) && empty($_POST['mobile_number']) && empty($_POST['driver_photo']) && empty($_POST['first_name']) && empty($_POST['email']) && empty($_POST['password']) && empty($_POST['c']) && empty($_POST['pin_code']) ){
           
                
          $this->session->set_flashdata('message_name', 'Kindly Fill all the required Filled');
         
        redirect(base_url() . 'Admin/add_driver');
       }else{
           
           $name = $this->security->xss_clean($this->input->post('first_name'));
	$email = $this->security->xss_clean($this->input->post('email'));
	$pass = $this->security->xss_clean($this->input->post('password'));
	$contact = $this->security->xss_clean($this->input->post('mobile_number'));
	$address = $this->security->xss_clean($this->input->post('address'));
	$pin = $this->security->xss_clean($this->input->post('pin_code'));
	$city = $this->security->xss_clean($this->input->post('city'));
	$state = $this->security->xss_clean($this->input->post('state'));
	$lst_name = $this->security->xss_clean($this->input->post('last_name'));
		$driving_license_status = $this->security->xss_clean($this->input->post('driving_license_status'));
	$gender = $this->security->xss_clean($this->input->post('gender'));
           
        $expired_date= $this->security->xss_clean($this->input->post('expired_date_1'));   
         			
  		
$sql = $this->Login_model->Select('tbl_driver', '*', array('mobile_no' => $contact , 'email' => $email));
  
			if (empty($sql)) {
			       
			$time=time();
					
					$ext = pathinfo($_FILES['driver_file']['name'], PATHINFO_EXTENSION);
					$img_name='uploads/images/Licence/img_'.$time.".".$ext;
					
					$this->my_upload->upload($_FILES['driver_file']);
					
					if ( $this->my_upload->uploaded == true  ) 
					{
						$this->my_upload->allowed         		= array('image/*');
						$this->my_upload->file_new_name_body    = 'img_'.$time;
						//$this->my_upload->image_convert 		= 'jpg';
						$this->my_upload->jpeg_quality 			= 100;	
						$this->my_upload->image_resize          = true;
						$this->my_upload->image_ratio_fill   = true;
						$this->my_upload->image_x               = 270;
						$this->my_upload->image_y         		= 168;

						
						$this->my_upload->process('uploads/images/Licence/');
						if ( $this->my_upload->processed == true ) 
						{
							$this->my_upload->clean();  
						} 
						
					}
					
					
						$ext = pathinfo($_FILES['driver_photo']['name'], PATHINFO_EXTENSION);
					$profile_img='uploads/images/DriverProfile/img_'.$time.".".$ext;
					
					$this->my_upload->upload($_FILES['driver_photo']);
					
					if ( $this->my_upload->uploaded == true  ) 
					{
						$this->my_upload->allowed         		= array('image/*');
						$this->my_upload->file_new_name_body    = 'img_'.$time;
						//$this->my_upload->image_convert 		= 'jpg';
						$this->my_upload->jpeg_quality 			= 100;	
						$this->my_upload->image_resize          = true;
						$this->my_upload->image_ratio_fill   = true;
						$this->my_upload->image_x               = 270;
						$this->my_upload->image_y         		= 168;

						
						$this->my_upload->process('uploads/images/DriverProfile/');
						if ( $this->my_upload->processed == true ) 
						{
							$this->my_upload->clean();  
						} 
						
					}
					
					
					
					
					
					
					
					
					
					
					
	
			     $random_number = mt_rand(100, 999);
                   
                        $ud=$name.$random_number."-Drv";
                        
			$f = array(					
					    'driver_name' => $name.''.$lst_name,
    					'email' => $email,
    					'driver_id' => $ud ,

    					'mobile_no' => $contact,
    					'password' => $pass,
						'gender' => $gender,
    					'address' => $address,
    					'pin_code' => $pin,
    					'city' => $city,
    					'state' => $state,
    					'expire_date' => $expired_date,
    					'driving_license_status' => $driving_license_status,
    					'driving_license_image' => $img_name,
    					'driver_profile_pic' => $profile_img,
    			       	'status'=> 0
    					
    				);
    				
    				$this->Login_model->insert('tbl_driver',$f);

					$this->session->set_flashdata('message_name','Data inserted successfully');
			    
			     
			}else{
			     $this->session->set_flashdata('error', 'Driver is already exist with this mobile number and email');
         
       
			}  
           
   
            redirect(base_url() . 'Admin/add_driver');
           
           
       } 
        
  
    }
    
    
      public function registration_driver(){
        
       if(empty($_POST['file_1']) && empty($_POST['mobile_number']) && empty($_POST['driver_photo']) && empty($_POST['first_name']) && empty($_POST['email']) && empty($_POST['password']) && empty($_POST['c']) && empty($_POST['pin_code']) ){
           
                
          $this->session->set_flashdata('message_name', 'Kindly Fill all the required Filled');
         
        redirect(base_url() . 'Admin/add_driver');
       }else{
           
           $name = $this->security->xss_clean($this->input->post('first_name'));
	$email = $this->security->xss_clean($this->input->post('email'));
	$pass = $this->security->xss_clean($this->input->post('password'));
	$contact = $this->security->xss_clean($this->input->post('mobile_number'));
	$address = $this->security->xss_clean($this->input->post('address'));
	$pin = $this->security->xss_clean($this->input->post('pin_code'));
	$city = $this->security->xss_clean($this->input->post('city'));
	$state = $this->security->xss_clean($this->input->post('state'));
	$lst_name = $this->security->xss_clean($this->input->post('last_name'));
		$driving_license_status = $this->security->xss_clean($this->input->post('driving_license_status'));
	$gender = $this->security->xss_clean($this->input->post('gender'));
           
        $expired_date= $this->security->xss_clean($this->input->post('expired_date_1'));   
         			
  		
$sql = $this->Login_model->Select('tbl_driver', '*', array('mobile_no' => $contact , 'email' => $email));
  
			if (empty($sql)) {
			       
			        $time = time();
                    $upload_dir = 'uploads/images/Licence/';
                    $imageName = 'img_' . $time;
                    $file_ext = pathinfo($_FILES['driver_file']['name'], PATHINFO_EXTENSION);
                    $final_image = '';
                    
                    $this->my_upload->upload($_FILES['driver_file']);
                    
                    if ($this->my_upload->uploaded) {
                        $this->my_upload->allowed = array('image/*');
                        $this->my_upload->file_new_name_body = $imageName;
                        $this->my_upload->jpeg_quality = 100;
                        $this->my_upload->image_resize = true;
                        $this->my_upload->image_ratio_fill = true;
                        $this->my_upload->image_x = 270;
                        $this->my_upload->image_y = 168;
                    
                        $this->my_upload->process($upload_dir);
                    
                        if ($this->my_upload->processed) {
                            $uploaded_file_path = $upload_dir . $this->my_upload->file_dst_name;
                            $file_ext = pathinfo($uploaded_file_path, PATHINFO_EXTENSION);
                    
                            // Convert to WebP if necessary
                            if (strtolower($file_ext) != 'webp') {
                                $output_path = $upload_dir . $imageName . '.webp';
                                
                                if (convert_to_webp_image($uploaded_file_path, $output_path)) {
                                    // Remove the original file after conversion
                                    unlink($uploaded_file_path);
                                    $final_image = $output_path;
                                } else {
                                    // If conversion fails, keep the original file
                                    $final_image = $uploaded_file_path;
                                }
                            } else {
                                // If the uploaded file is already a WebP image
                                $final_image = $uploaded_file_path;
                            }
                    
                            // Clean up the upload object
                            $this->my_upload->clean();
                        }
                    }
				
			
					
					$profileupload_dir = 'uploads/images/DriverProfile/';
                    $profile_imageName = 'img_' . $time;
                    $file_ext = pathinfo($_FILES['driver_photo']['name'], PATHINFO_EXTENSION);
                    $profile_img = '';
					
					$this->my_upload->upload($_FILES['driver_photo']);
					
					if ( $this->my_upload->uploaded == true  ) 
					{
						$this->my_upload->allowed         		= array('image/*');
						$this->my_upload->file_new_name_body    = 'img_'.$time;
						//$this->my_upload->image_convert 		= 'jpg';
						$this->my_upload->jpeg_quality 			= 100;	
						$this->my_upload->image_resize          = true;
						$this->my_upload->image_ratio_fill   = true;
						$this->my_upload->image_x               = 270;
						$this->my_upload->image_y         		= 168;

						
						$this->my_upload->process($profileupload_dir);
                    
                        if ($this->my_upload->processed) {
                            $uploaded_file_path = $profileupload_dir . $this->my_upload->file_dst_name;
                            $file_ext = pathinfo($uploaded_file_path, PATHINFO_EXTENSION);
                          
                            if (strtolower($file_ext) != 'webp') {
                                $output_path = $profileupload_dir . $profile_imageName . '.webp';
                                
                                if (convert_to_webp_image($uploaded_file_path, $output_path)) {
                                    
                                    unlink($uploaded_file_path);
                                    $profile_img = $output_path;
                                } else {
                                   
                                    $profile_img = $uploaded_file_path;
                                }
                            } else {
                               
                                $profile_img = $uploaded_file_path;
                            }
                    
                            
                            $this->my_upload->clean();
                        }
                    } 
					
	
			     $random_number = mt_rand(100, 999);
                   
                        $ud=$name.$random_number."-Drv";
                        
			$f = array(					
					    'driver_name' => $name.''.$lst_name,
    					'email' => $email,
    					'driver_id' => $ud ,

    					'mobile_no' => $contact,
    					'password' => $pass,
						'gender' => $gender,
    					'address' => $address,
    					'pin_code' => $pin,
    					'city' => $city,
    					'state' => $state,
    					'expire_date' => $expired_date,
    					'driving_license_status' => $driving_license_status,
    					'driving_license_image' => $final_image,
    					'driver_profile_pic' => $profile_img,
    			       	'status'=> 0
    					
    				);
    				
    				$this->Login_model->insert('tbl_driver',$f);

					$this->session->set_flashdata('message_name','Data inserted successfully');
			    
			     
			}else{
			     $this->session->set_flashdata('error', 'Driver is already exist with this mobile number and email');
         
       
			}  
           
   
            redirect(base_url() . 'Admin/driver_list');
           
           
       } 
        
  
    }
    
    
    public function get_userlist()
    {  
       
        // Rows display per page
          $draw=$_POST['draw'];
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';          
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(tbl_user.created_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry=''; 
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" AND (tbl_user.user_id LIKE '%$searchValue%'  OR tbl_user.f_name LIKE '%$searchValue%'
              OR tbl_user.mobile_no = '$searchValue' OR tbl_user.email_id = '$searchValue' 
              OR tbl_user.pincode = '$searchValue' OR tbl_user.address = '$searchValue' )";
              
              
            
          }

          if($data_type=='all')
          {            

            $sql = "SELECT * FROM tbl_user WHERE  status !='' $datefilter_qry $search_qry $extra_qry ORDER BY id DESC";
     
          }
       
          
            // echo $sql;
            // die;
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
        
          
            //   echo "<pre>";
            //   print_r($result);
            //   die;
  
  
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {            
               
               
                  $action='<a href="javascript:void(0);" class="delete" data-toggle="tooltip" title="View Details" 
                                onclick="view_detail('.$r->id.')" aria-hidden="true" style="color:#0e2b05ed;font-size:27px">
                    		 <i class="fa fa-eye" aria-hidden="true"></i></a>';
                    		 
                $button = '<a href="' . base_url('Admin/user_bookinghistory/' . $r->id) . '" class="delete" data-toggle="tooltip" title="Booking Details" 
                            aria-hidden="true" style="color:blue; font-size:27px" target="_blank">
                            <i class="fa fa-plus" aria-hidden="true"></i>
                          </a>';


                        
                   
                    $name = $r->f_name;
                    // $address = $r->address .' '. $r->city;
               
                    $response['list'][$i]['i']=$index;
                    $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_date)));  
                     $response['list'][$i]['user_id']= !empty($r->user_id)?$r->user_id:'NA';
                    $response['list'][$i]['name']= !empty($name)?$name:'NA';
                    // $response['list'][$i]['gender']= !empty($r->gender)?$r->gender:'NA';
                    $response['list'][$i]['mobile_no']=!empty($r->mobile_no)?$r->mobile_no:'NA';                   
                    $response['list'][$i]['email_id']=!empty($r->email_id)? $r->email_id : 'NA'; 
                    $response['list'][$i]['address']=!empty($r->address)? $r->address : 'NA'; 
                    $response['list'][$i]['action']=$action.$button; 
                    
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
    
    }
    
    
    
    
     public function get_userlist_data() {
    $page = $this->input->get('page') ?? 1;
    $limit = 10;
    $offset = ($page - 1) * $limit;
    $search = $this->input->get('search'); 

    $total_rows = $this->Common_model->count_all($search); 
    $userlist = $this->Common_model->get_paginated($limit, $offset, $search); 

    $html_list = $this->load->view('admin/user_cardrow', ['userlist' => $userlist], TRUE);

    $this->load->library('pagination');
    $config = [
        'base_url' => site_url('Admin/get_userlist_data'),
        'total_rows' => $total_rows,
        'per_page' => $limit,
        'use_page_numbers' => TRUE,
        'page_query_string' => TRUE,
        'query_string_segment' => 'page',
        'reuse_query_string' => TRUE,
        'full_tag_open' => '<ul class="pagination justify-content-center">',
        'full_tag_close' => '</ul>',
        'attributes' => ['class' => 'page-link', 'data-ci-pagination-page' => ''],
        'first_link' => 'First',
        'last_link' => 'Last',
        'next_link' => 'Next',
        'prev_link' => 'Prev',
    ];
    $this->pagination->initialize($config);
    $pagination_links = $this->pagination->create_links();

    echo json_encode([
        'delivery_list_html' => $html_list,
        'pagination_html' => $pagination_links,
        'total_deliveryboy' => $total_rows
    ]);
}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function get_driver_location()
    {  
       
        // Rows display per page
          $draw=$_POST['draw'];
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';          
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(v.entry_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" AND (v.curr_lat LIKE '%$searchValue%'  
              OR v.curr_long LIKE '%$searchValue%'
              OR v.driver_id LIKE '%$searchValue%'  OR dr.driver_name LIKE '%$searchValue%' )";
          }

          if($data_type=='all')
          { 
            
            $sql="SELECT v.*,dr.driver_name,dr.driver_id As driverid  
                FROM tbl_driver_currentLocation v
                    INNER JOIN  tbl_driver dr ON dr.id=v.driver_id
                   WHERE  v.id !='' $datefilter_qry $search_qry $extra_qry 
                    ORDER BY id DESC";
          }
       
          
            // echo $sql;
            // die;
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
        
          
            //   echo "<pre>";
            //   print_r($result);
            //   die;
  
  
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {            
               
               
                  $action='<a href="javascript:void(0);" class="delete" data-toggle="tooltip" title="Edit Details" 
                                onclick="view_detail('.$r->id.')" aria-hidden="true" style="color:#0e2b05ed;font-size:27px">
                    		 <i class="fa fa-edit" aria-hidden="true"></i></a>';
                   
               
                    $response['list'][$i]['i']=$index;
                    $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->entry_date))); 
                    $response['list'][$i]['driver_name']=!empty($r->driver_name)? $r->driver_name : 'NA'; 
                    $response['list'][$i]['driver_id']=!empty($r->driverid)? $r->driverid : 'NA'; 
                     $response['list'][$i]['curr_lat']= !empty($r->curr_lat)?$r->curr_lat:'NA';
                    $response['list'][$i]['curr_long']=!empty($r->curr_long)?$r->curr_long:'NA';
                    $response['list'][$i]['action']=$action; 
                    
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
    
    }
    
    
     public function get_rental_list()
    {  
       
        // Rows display per page
          $draw=$_POST['draw'];
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';          
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(tbl_rental_km_hrs.created_at,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" AND (tbl_rental_km_hrs.km LIKE '%$searchValue%'  
              OR tbl_rental_km_hrs.hrs LIKE '%$searchValue%' )";
          }

          if($data_type=='all')
          { 
            
            $sql="SELECT * FROM tbl_rental_km_hrs 
                    WHERE  id !='' $datefilter_qry $search_qry $extra_qry 
                    ORDER BY id DESC";
          }
       
          
            // echo $sql;
            // die;
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
        
          
            //   echo "<pre>";
            //   print_r($result);
            //   die;
  
  
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {            
               
               
                  $action='<a href="javascript:void(0);" class="delete" data-toggle="tooltip" title="Edit Details" 
                                onclick="view_detail('.$r->id.')" aria-hidden="true" style="color:#0e2b05ed;font-size:27px">
                    		 <i class="fa fa-edit" aria-hidden="true"></i></a>';
               
                    $response['list'][$i]['i']=$index;
                    $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at))); 
                    $response['list'][$i]['km']=!empty($r->km)? $r->km	 : 'NA'; 
                    $response['list'][$i]['hrs']=!empty($r->hrs)? $r->hrs : 'NA'; 
                    $response['list'][$i]['action']=$action; 
                    
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
    
    }
    
    
     public function get_locationlist()
    {  
       
        // Rows display per page
          $draw=$_POST['draw'];
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';          
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(tbl_user.created_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" AND (tbl_user.user_id LIKE '%$searchValue%'  OR tbl_user.f_name LIKE '%$searchValue%'
              OR tbl_user.mobile_no = '$searchValue' OR tbl_user.email_id = '$searchValue' 
              OR tbl_user.pincode = '$searchValue' OR tbl_user.address = '$searchValue' )";
              
             
           
          }

          if($data_type=='all')
          {            

            $sql = "SELECT * FROM tbl_user WHERE  status !='' $datefilter_qry $search_qry $extra_qry ORDER BY id DESC";
     
          }
       
          
            // echo $sql;
            // die;
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
        
          
            //   echo "<pre>";
            //   print_r($result);
            //   die;
  
  
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              {            
               
               
                  
                        $button = '';
                   
                    $name = $r->f_name;
                    // $address = $r->address .' '. $r->city;
               
                    $response['list'][$i]['i']=$index;
                    $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_date)));  
                     $response['list'][$i]['user_id']= !empty($r->user_id)?$r->user_id:'NA';
                    $response['list'][$i]['name']= !empty($name)?$name:'NA';
                    // $response['list'][$i]['gender']= !empty($r->gender)?$r->gender:'NA';
                    $response['list'][$i]['mobile_no']=!empty($r->mobile_no)?$r->mobile_no:'NA';                   
                    $response['list'][$i]['email_id']=!empty($r->email_id)? $r->email_id : 'NA'; 
                    $response['list'][$i]['address']=!empty($r->address)? $r->address : 'NA'; 
                    $response['list'][$i]['action']=$button;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
    
    }
    
     
     public function location_list(){
    if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $this->load->view('header');
    $this->load->view('admin/location_list');
    $this->load->view('footer');
        }
    }
    
    
    
 
   public function managecash()
   {
      $draw=$_POST['draw'];       
      $data_type=$_POST['data_type'];
      $startdate='';
      $enddate='';
      
      if($_POST['daterange'])
      {
          $ex=explode(" - ",$_POST['daterange']);
          if(!empty($ex))
          {
              $fromdate=$ex[0];
              $todate=$ex[1];
          
              $date = str_replace('/', '-', $fromdate);
              $startdate=date('Y-m-d', strtotime($date));
              
      
              $date1 = str_replace('/', '-', $todate);
              $enddate=date('Y-m-d', strtotime($date1));
          }
      }
      
      
      $datefilter_qry="";
      if($startdate && $enddate)
      {
        $datefilter_qry=" WHERE STR_TO_DATE(tbl_fare.created_date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
      }          
    
      $search_qry="";      
    
      $extra_qry='';
      if($_POST['searchvalue'])
      {
          $searchValue=trim($_POST['searchvalue']);      
        
          $search_qry=" and (tbl_fare.name = '$searchValue')";    
       
      }

      if($data_type=='all')
      {
       
        $sql = "SELECT * FROM tbl_fare  where status = 0  $datefilter_qry $search_qry ORDER BY tbl_fare.id DESC";
 
      }
      
        $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
        $totalRecords =$this->db->query($sql)->num_rows();
        $result=$this->db->query($sql.$limit)->result();
      
      if(!empty($result))
      {
          $i=0;
          $minus_length=0;
          if($_REQUEST['start'] > 0)
          {
              $minus_length=$_REQUEST['start'];
          }
          $index=$totalRecords-$minus_length;
          
          foreach($result as $r)
          {         
              
              if($r->night_fare_status==1){
                  
                   $sts = '<span class="text-success">Active</span>';
              }else{
                  $sts = '<span class="text-warning">Pending</span>';
              }
           
            $status = '<i class="fa-solid fa-eye rounded-pill fs-6 me-1" role="button"  data-bs-toggle="modal" data-bs-target="#staticview' . $r->id . '"></i>';

            $button = '<a href="#" class="btn btn-secondary" role="button" data-bs-toggle="modal" data-bs-target="#staticBackdrop' . $r->id . '">Edit</a>';

            $response['list'][$i]['i']=$index;
            $response['list'][$i]['date']=date("d-m-Y h:i:s a", strtotime(trim($r->created_at)));  
            $response['list'][$i]['veh_type']= !empty($r->vehicle_type)?$r->vehicle_type:'NA';  
            $response['list'][$i]['per_km']= !empty($r->per_km)?$r->per_km:'NA'; 
            $response['list'][$i]['cap']= !empty($r->capacity)?$r->capacity:'NA'; 
            $response['list'][$i]['wait_limit']= !empty($r->wait_time_limit)?$r->wait_time_limit:'NA'; 
            $response['list'][$i]['wait_Charge']= !empty($r->wait_time_limit)?$r->wait_time_limit:'NA'; 
            $response['list'][$i]['sch_fare']= !empty($r->sch_fare)?$r->sch_fare:'NA'; 
              $response['list'][$i]['night_status']= !empty($r->night_fare_status)?$r->night_fare_status:'NA'; 
          
            $response['list'][$i]['act']=$button;
            
              $i++;
              $index--;
          }
      }
      else
      {
          $response['list']=[];
      }
      
      
      $json_data = array(
      "draw"            => intval( $_REQUEST['draw'] ),   
      "recordsTotal"    => intval($totalRecords ),  
      "recordsFiltered" => intval($totalRecords),
      "data"            => $response['list']   // total data array
      );
      
      echo json_encode($json_data);
      
        

   }
   
   public function collectcash()
   {
       $id=$_POST['id'];
       
       if($id)
       {
           $this->db->update('tbl_booking',array('is_cash_collect',1));
       }
   }
   
   
          public function check_phone(){
   $phone = $this->input->post('phone');
 
    $is_registeredE = $this->Login_model->is_registered1($phone);
   // print_r($is_registeredE);
            echo $is_registeredE ;
          }
          
           
          public function check_deliemail(){
   $email_id = $this->input->post('email_id');
 
    $is_registeredE = $this->Login_model->emailcheckdeliv($email_id);
   
            echo $is_registeredE ;
          }
          
          
          
public function privacy()
{   
     if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    $dd=$this->db->query("select * from privacy where id= 1 ")->row_array();
    $data['privacy_data']=$dd;
   $this->load->view('header');
    $this->load->view('privacy',$data);
     $this->load->view('footer');
    }
}

public function editSave_privacy()
{
  
        extract($_POST);
        // print_r($_POST);exit;
        $x= 1;

        $insert_array=array
        (
        'privacy'=>$privacy, 
        'created_date'=>date('Y-m-d') 
        );
    
        $this->db->where('id',$x);
        $this->db->update('privacy',$insert_array);
        $this->session->set_flashdata('message_name','Save successfully.');
        redirect("Admin/privacy");


}





public function terms()
{
     if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    
    $dd=$this->db->query("select * from terms_condition where id= 1 ")->row_array();
    $data['terms_data']=$dd;
     $this->load->view('header');
    $this->load->view('terms',$data);
    $this->load->view('footer');
    }
}

public function editSave_terms()

{
    extract($_POST);
    // print_r($_POST);exit;
    $x= 1;
    $insert_array=array
    (
    'terms_data'=>$terms, 
    'created_date'=>date('Y-m-d') 
    );

    $this->db->where('id',$x);
    $this->db->update('terms_condition',$insert_array);
    $this->session->set_flashdata('message_name','Save successfully.');
    redirect("Admin/terms");


}



public function help()
{
     if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
    
    $dd=$this->db->query("select * from help where id= 1 ")->row_array();
    $data['help_data']=$dd;
     $this->load->view('header');
    $this->load->view('help',$data);
    $this->load->view('footer');
    }
}

public function editSave_help()

{
    extract($_POST);
    // print_r($_POST);exit;
    $x= 1;
    $insert_array=array
    (
    'help_data'=>$help, 
    'created_date'=>date('Y-m-d') 
    );

    $this->db->where('id',$x);
    $this->db->update('help',$insert_array);
    $this->session->set_flashdata('message_name','Save successfully.');
    redirect("Admin/help");


}


public function change_pass()
{
     if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
    } else {
        $id=$this->session->userdata('admin_login_id');
    // print_r($id);exit;
    $dd=$this->db->query("select * from tbl_admin where admin_id='$id'")->row_array();
    $data['admin_data']=$dd;
     $this->load->view('header');
    $this->load->view('change_password',$data);
    $this->load->view('footer');
    }
}

    public function change_password(){
    
    $admin_login_id=$this->session->userdata('admin_login_id');
    $data=array('password'=>$_POST['password']);
    $this->Login_model->update_data('tbl_admin','admin_id',$admin_login_id,$data);
    $this->session->set_flashdata('message_name', 'Update Your Password Successfull..! ');
    $this->session->sess_destroy();
     redirect('Base/login/');
    }
    
    
    public function Add_main_banner()
    {
        if(empty($_POST['status']))
        {
                $this->session->set_flashdata('message_name', 'Can Not submit Empty fields');
                redirect('Admin/main_banner');
        }
        else
        {
    
           $service = array(
               'banner_name'=>$this->input->post('banner_name'),
               'date'=> $this->input->post('date'),
               'link'=> $this->input->post('link'),
               'status'=>  $this->input->post('status'),
               'created_by'=>$this->session->userdata('admin_login_id'),
                'created_by_type'=>'Admin',
               );
            $this->db->insert('main_banner',$service);
     
            $id= $this->db->insert_id(); 
        }
        if(!empty($_FILES['appbanner_image']['name']))
        {
                    
            $appimageName = 'appmain_banner'.time();
          
            $fil = $_FILES["appbanner_image"]['name'] ;
            $ext= pathinfo($fil, PATHINFO_EXTENSION);
            if($ext=='webp')
            {
                $config['allowed_types'] = '*';
            }
            else
            {
               $config['allowed_types'] = 'jpg|jpeg|png';
           
            }
          
            $config['upload_path']   = './media/main_banner/';
            $config['max_size']      = 10000;
             $config['file_name']     = $appimageName;
    
            $this->load->library('upload', $config);
            // $this->load->library('upload');
            $this->upload->initialize($config);
             if ($this->upload->do_upload('appbanner_image')) {
                // File uploaded successfully
                $data = $this->upload->data();
                //   $temporarys = explode(".",$_FILES['appbanner_image']['name']);
                  $this->resizeImage_app_banner($appimageName);
                  
                $filePath = $config['upload_path'] . $data['file_name'];
                $fileExt = $data['file_ext'];
                
                // Check if the uploaded file is already in WebP format
                if ($fileExt == '.webp') {
                $final_image = $filePath;
                } else {
                    $output_path = $config['upload_path'] . $appimageName . '.webp';
                    if (convert_jpg_to_webp($filePath, $output_path)) {
                        unlink($filePath);
                        $final_image = $output_path;
                    } else {
                        $final_image = $filePath; // Use original image if conversion fails
                    }
                    
                    
                } 
                   
                $datas = array('appbanner_image'=>  $final_image );
                
                
                $this->Login_model->update_data('main_banner','id',$id,$datas);
        
            
        
            } else {
                 $this->session->set_flashdata('error', 'Not Upload banner');
            }
       }
        $this->session->set_flashdata('suceess', 'Main Banner Added Successfully');
        redirect('Admin/main_banner');
    }
     
    
    public function update_main_banner(){
         $id = $this->input->post('id');
         
        if(!empty($_FILES['appbanner_image']['name']))
        {
            
            $fil = $_FILES["appbanner_image"]['name'] ;
            $ext= pathinfo($fil, PATHINFO_EXTENSION);
            if($ext=='webp')
            {
                $config['allowed_types'] = '*';
            }
            else
            {
               $config['allowed_types'] = 'jpg|jpeg|png';
           
            }
            
            
            $appimageName = 'appmain_banner'.time();
            $config['upload_path']   = './media/main_banner/';
            // $config['max_size']      = 10000;
            $config['file_name']     = $appimageName;

            $this->load->library('upload', $config);
            // $this->load->library('upload');
            $this->upload->initialize($config);
             if ($this->upload->do_upload('appbanner_image')) 
             {
                    // File uploaded successfully
                    $dataa = $this->upload->data();
                    $this->resizeImage_app_banner($appimageName);
                    
                    $filePath = $config['upload_path'] . $dataa['file_name'];
                    $fileExt = $dataa['file_ext'];
                    
                    // Check if the uploaded file is already in WebP format
                    if ($fileExt == '.webp') {
                    $final_image = $filePath;
                    } else {
                        $output_path = $config['upload_path'] . $appimageName . '.webp';
                        if (convert_jpg_to_webp($filePath, $output_path)) {
                            unlink($filePath);
                            $final_image = $output_path;
                        } else {
                            $final_image = $filePath; // Use original image if conversion fails
                        }
                        
                        
                    } 
                    
                    $datas = array('appbanner_image'=>  $final_image );
                    $this->Login_model->update_data('main_banner','id',$id,$datas);
        
            
        
            }
            else
            {            
                $this->session->set_flashdata('error', 'Not Upload banner');
                
            }
        }
        else
        {
                     $data = array('banner_name'=> $this->input->post('banner_name'),
                      'date'=> $this->input->post('date'),
                      'appbanner_image'=>$this->input->post('old_appimage'),
                        'link'=> $this->input->post('link'),
                        'status'=>  $this->input->post('status')
                      
                    );
        

        $res  =  $this->Login_model->update_data('main_banner','id',$id,$data);
         redirect('Admin/main_banner');
        }
        
   
      
  
            
      $this->session->set_flashdata('suceess', 'Main Banner Added Successfully');
         
        redirect(base_url() . 'Admin/main_banner');  
        
     
}

 private function resizeImage_app_banner($filename) {
      $config['image_library']  = 'gd2';
      $config['source_image']   = './media/main_banner/' . $filename;
      // $config['maintain_ratio'] = TRUE;
      $config['maintain_ratio'] = FALSE;
      $config['width']          = 540;
      $config['height']         = 313;

      $this->load->library('image_lib', $config);
      $this->image_lib->resize();
  }


private function resizeImage_mainbn_banner($filename) {
  $config['image_library']  = 'gd2';
  $config['source_image']   = './media/main_banner/' . $filename;
  // $config['maintain_ratio'] = TRUE;
  $config['maintain_ratio'] = FALSE;
  $config['width']          = 1920;
  $config['height']         = 845;

  $this->load->library('image_lib', $config);
  $this->image_lib->resize();
}
   
         
    public function main_banner_delete()
      {
        $id = $_GET['id'];
        $img = $_GET['img'];
        unlink("media/main_banner/".$img);
       
        $this->Login_model->delete_data('grocery_main_banner','id',$id);
       
        redirect('Admin/main_banner');
      }
    
    public function main_banner()
    {
        
        if ($this->session->userdata('admin_login_id') == "" ) {
          redirect('Base/login/');
            } else {
            $user = $this->session->userdata('admin_login_id');
           $data['banner'] = $this->Login_model->get_main_banner($user);
            $this->load->view('header');
            $this->load->view('admin/main_banner',$data);
            $this->load->view('footer');
            }
        
        
    }
    
    public function get_mainbannerlist()
    {  
        $user = $this->session->userdata('admin_login_id');
          $draw=$_POST['draw'];       
          $data_type=$_POST['data_type'];
          $startdate='';
          $enddate='';
          
          if($_POST['daterange'])
          {
              $ex=explode(" - ",$_POST['daterange']);
              if(!empty($ex))
              {
                  $fromdate=$ex[0];
                  $todate=$ex[1];
              
                  $date = str_replace('/', '-', $fromdate);
                  $startdate=date('Y-m-d', strtotime($date));
                  
          
                  $date1 = str_replace('/', '-', $todate);
                  $enddate=date('Y-m-d', strtotime($date1));
              }
          }
          
          
          $datefilter_qry="";
          if($startdate && $enddate)
          {
            $datefilter_qry=" AND STR_TO_DATE(main_banner.date,'%Y-%m-%d') BETWEEN '$startdate' AND '$enddate'";
          }          
        
          $search_qry="";      
        
          $extra_qry='';
          if($_POST['searchvalue'])
          {
              $searchValue=trim($_POST['searchvalue']);      
            
              $search_qry=" AND ( main_banner.banner_name = '$searchValue' OR main_banner.status = '$searchValue' )";    
           
          }

          if($data_type=='all')
          {
           
            $sql="SELECT * FROM  main_banner WHERE created_by='$user' $datefilter_qry $search_qry  ORDER BY date DESC ";

          }
          
          
          
            $limit=" LIMIT ".$_REQUEST['start']." ,".$_REQUEST['length'];
            $totalRecords =$this->db->query($sql)->num_rows();
            $result=$this->db->query($sql.$limit)->result();
          
        
  
          if(!empty($result))
          {
              $i=0;
              $minus_length=0;
              if($_REQUEST['start'] > 0)
              {
                  $minus_length=$_REQUEST['start'];
              }
              $index=$totalRecords-$minus_length;
              
              foreach($result as $r)
              { 
           
            
            
                $edit = '<i class="fa fa-edit" rounded-pill" role="button" data-payid="' . $r->id . '"></i>';
                
                $view = '<i class="fa fa-eye" rounded-pill" role="button" data-payid="' . $r->id . '"></i>';
                
                
            //   if(count($result) > 1){
            //             $button = '<a style="color:white;" href="' . base_url('Admin/Pages/main_banner_delete?id=' . $r->id.'&img=' . $r->banner_image) . '" onclick="return confirm(\'Do You Really Want to Delete\')"> 
            //     <i role="button" class="fa-regular fa-trash-can text-danger"></i></a>';
            //           }else{
            //               $button ='';
            //           }
               
                //  $webimg='<img src="' . base_url() . $r->banner_image. '" height="50rem">';
                
                 $appimg='<img src="' . base_url() . $r->appbanner_image. '" height="50rem">';
                 
                if($r->status=='Active'){
                   $st ='<p class="badge rounded-pill bg-success  py-1">'.$r->status.'</p>';
                }else{
                   $st='<p class=" badge rounded-pill bg-warning py-1">'.$r->status.'</p>';
                } 

                $response['list'][$i]['i']=$index;
                //  $response['list'][$i]['webbanner']=$webimg; 
                 $response['list'][$i]['appbanner']=$appimg; 
                $response['list'][$i]['banner_name']= !empty($r->banner_name)?$r->banner_name:'NA';  
                $response['list'][$i]['date']=date("d-m-Y", strtotime(trim($r->date)));  
               
                $response['list'][$i]['status']=$st;                      
                $response['list'][$i]['action']=$view .$edit;
                
                  $i++;
                  $index--;
              }
          }
          else
          {
              $response['list']=[];
          }
          
          
          $json_data = array(
          "draw"            => intval( $_REQUEST['draw'] ),   
          "recordsTotal"    => intval($totalRecords ),  
          "recordsFiltered" => intval($totalRecords),
          "data"            => $response['list']   // total data array
          );
          
          echo json_encode($json_data);
      
        

    }
    
    public function get_editdata()
    {
        if ($this->session->userdata('admin_login_id') == "" ) {
             redirect('Base/login/');
        } else {
        $id = $_POST['id'];
        
        $sql = "SELECT * FROM main_banner WHERE id=$id ";
        
        $value = $this->db->query($sql)->row();
        
        ?>
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="d-flex gap-4">
                        <h5 class="modal-title">Update Main Banner</h5>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    
                    
                <form method="POST" action="<?php echo base_url();?>Admin/update_main_banner" class="form" enctype="multipart/form-data">
                     <label for="file-img" class="form-label fs-6">Banner Name <span class="text-danger"> *</span></label>
                    <input type="text"  class="form-control" name="banner_name" value="<?php echo $value->banner_name; ?>" required="">
                     
                     <label for="file-img" class="form-label fs-6">URL for redirect <span class="text-danger"> *</span></label>
                    <input type="text"  class="form-control" name="link" value="<?php echo $value->link; ?>" required="">
                       
                    <label for="file-img" class="form-label fs-6">Upload APP Banner image <span class="text-danger"> *</span></label>           
    
                    <input type="file"  class="form-control" name="appbanner_image" onchange="validateappImage(this)">
                     <input type="hidden"  name="old_appimage" value="<?php echo $value->appbanner_image; ?>">
                    <span class="text-danger">Image size 540 x 313, 44 KB</span><br>
                    
                    <input type="hidden"  name="id" value="<?php echo $value->id; ?>">
                    <label for="sub-name" class="form-label fs-6 mt-2"> Date <span class="text-danger"> *</span></label>
                    <input type="date" placeholder="Enter Date" class="form-control" name="date" value="<?php echo $value->date; ?>" required="">
                    <label for="subject" class="form-label fs-6 mt-2"> Banner Status <span class="text-danger"> *</span></label>
                    <select id="clases" class="form-control" name="status">
                       
                        <option value="Active" <?php if($value->status=='Active'){ echo 'selected'; } ?>>Active</option>
                        <option value="InActive" <?php if($value->status=='InActive'){ echo 'selected'; } ?>>InActive</option>
                    </select>
                    <div class="py-2 text-end">
                        <button type="submit"  class="btn btn-primary">Upload</button>
                      </div>
                </form>
                    
                </div>
            </div>
        </div>
         
        <?php
        
        
        }
    }
    
    
   
    
    
    
    
    public function view_bannerdata()
    {
        if ($this->session->userdata('admin_login_id') == "" ) {
             redirect('Base/login/');
        } else {
        $id = $_POST['id'];
        
        $sql = "SELECT * FROM main_banner WHERE id=$id ";
        
        $value = $this->db->query($sql)->row();
        
        ?>
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="d-flex gap-4">
                        <h5 class="modal-title">View Main Banner</h5>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                
                
                <div class="modal-body p-0">
                     <div class="bg-white">
                            
                              <div class="row  p-3">
                                 <div class="col-lg-6 shadow p-2">
                                    <div class="d-flex gap-3">
                                       <span class="fw-bold">Banner Name :</span>
                                       <span class="text-danger" id="list-color
                                          "> <?=$value->banner_name;?> </span>
                                    </div>
                                   
                                    <div class="d-flex gap-3">
                                       <span class="fw-bold"> Date :</span>
                                       <span class="text-danger" id="list-color
                                          "> <?=date("d-m-Y g:i a", strtotime($value->created));?> </span>
                                    </div>
                                    <div class="d-flex gap-3">
                                       <span class="fw-bold">status:</span>
                                       <span class="text-danger" id="list-color
                                          "> <?=$value->status;?> </span>
                                    </div>
                                 </div>
                                 <div class="col-lg-12  p-2">
                               <div class="d-flex gap-3 ">
                                       <span class="fw-bold">URL for redirect :</span>
                                       <span class="text-danger" id="list-color
                                          "> <?=$value->link?> </span>
                                    </div> 
                                    
                                    </div> 
                              </div>
                              
                                 
                           </div>
                    </div>
                
                
            </div>
        </div>
         
        <?php
        
        
        }
    }
    
    
    
           
    
}