MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/allyindian_com/sbltt/application/controllers/Vehicle_running_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once("Secure_Controller.php");

class Vehicle_running_report extends Secure_Controller{
	
	public function __construct(){
		parent::__construct('vehicle_running_report');
		$this->load->model('Vehicle_running_model');
	}

	public function index(){
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
		 $data['table_headers'] = $this->xss_clean(get_vehicle_running_report_table_headers());

		 $this->load->view('vehicle_running_report/manage', $data);
	}

	/*
	Returns Supplier table data rows. This will be called with AJAX.
	*/
	public function search(){
		$search = $this->input->get('search');
  		$limit = $this->input->get('limit');
  		$offset = $this->input->get('offset');
  		$sort = $this->input->get('sort');
  		$order = $this->input->get('order');
		$filters = array('crm' => $this->input->get('crm'),
						'crmto' => $this->input->get('crmto'));
		$all_leads = $this->Vehicle_running_model->search($search, $filters, $limit, $offset, $sort, $order);
        $total_rows = $this->Vehicle_running_model->get_found_rows($search, $filters);
        $data_rows = array();
        foreach($all_leads->result() as $leads){
            $data_rows[] = get_transfer_data_row($leads, $this);
        }
        echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
	}	

	/*
	This abstrack_report
	*/
	public function vehicle_report(){
		$filters = array('start_date' => $this->input->post('start_date'), 'end_date' => $this->input->post('end_date'));	
		$result = $this->Vehicle_running_model->vehicle_report($filters);
		echo json_encode(array('success' => TRUE, 'result' => $result));
	}
	
	public function bar_report($start,$end){	
		$start = $_REQUEST['start'];
		$end = $_REQUEST['end'];
		$result = $this->Vehicle_running_model->bar_report($start,$end);
		print json_encode($result, JSON_NUMERIC_CHECK);
	}
	
	public function excel($start_date,$end_date){
		$filters = array('start_date' => $start_date, 'end_date' => $end_date);
		$this->load->library('excel');
		$obj = new Excel();
		
		// Add new sheet
		$objWorkSheet = $obj->createSheet(0); //Setting index when creating
		$obj->setActiveSheetIndex(0);
		
		//Write cells
		$objWorkSheet->setCellValue('A1', 'Vehicle Type')
		->setCellValue('B1', 'Vehicle No')
		->setCellValue('C1', 'Count');

		 // set database value
		$data = $this->Vehicle_running_model->vehicle_report($filters);
		$i=2;
		$follow  = 0;
		$confirm = 0;
		$cancel  = 0;
		foreach ($data as $key => $value){ 
			$veh_type   = $value['veh_type'];
			$vehicle_no = $value['vehicle_no'];
			$tot        = $value['tot'];
		
			$objWorkSheet->setCellValue('A'.$i, $veh_type)
			->setCellValue('B'.$i, $vehicle_no)
			->setCellValue('C'.$i, $tot);
			$i++;
		}
		
		  // Rename sheet
		$objWorkSheet->setTitle("summary");

		 // Add new sheet
		$objWorkSheet = $obj->createSheet(1); //Setting index when creating
		 
		//Write cells
		$objWorkSheet->setCellValue('A1', 'Tour No')
		->setCellValue('B1', 'Customer Name')
		->setCellValue('C1', 'Billing Name')
		->setCellValue('D1', 'Mobile')
		->setCellValue('E1', 'Trip Type')
		->setCellValue('F1', 'Orgin')
		->setCellValue('G1', 'Destination')
		->setCellValue('H1', 'Avg Km')
		->setCellValue('I1', 'From')
		->setCellValue('J1', 'To')
		->setCellValue('K1', 'Trip Days')
		->setCellValue('L1', 'Veh Type')
		->setCellValue('M1', 'Vehicle Count')
		->setCellValue('N1', 'Cust Type')
		->setCellValue('O1', 'Booking Amount')
		->setCellValue('P1', 'Advance')
		->setCellValue('Q1', 'Discount')
		->setCellValue('R1', 'Balance')
		->setCellValue('S1', 'Vehicle No')
		->setCellValue('T1', 'Start KM')
		->setCellValue('U1', 'End KM')
		->setCellValue('V1', 'Total KM')
		->setCellValue('W1', 'Vendor Name')
		->setCellValue('X1', 'Operation Type')
		->setCellValue('Y1', 'TP Info')
		->setCellValue('Z1', 'Driver Name')
		->setCellValue('AA1', 'Driver Mobile#')
		->setCellValue('AB1', 'Suspense Amount')
		->setCellValue('AC1', 'Reffered By')
		->setCellValue('AD1', 'Status');
		
		
		$sale = $this->Vehicle_running_model->excel_report($filters);
		$j=2;
		foreach ($sale as $key => $op_info) { 
			$from_date  	      = date('d-m-Y', strtotime($op_info['from_date']));
			$to_date  		      = date('d-m-Y', strtotime($op_info['to_date']));
			$tour_no     	      = $op_info['tour_no'];
			$name     		      = $op_info['customer_name'];
			$mob      		      = $op_info['phone_number'];
			$cust_sts             = $op_info['cust_sts'];
			$trip_days            = $op_info['trip_days'];
			$bus_count            = $op_info['bus_count'];
			$source               = $op_info['source'];
			$destination          = $op_info['destination'];
			$report_address       = $op_info['report_address'];
			$billing_name         = $op_info['billing_name'];
			$first_name           = $op_info['first_name'];
			$avg_km               = $op_info['avg_km'];
			$trip_type_name       = $op_info['trip_type_name'];
			$veh_type             = $op_info['veh_type'];
			$vehicle_no           = $op_info['vehicle_no'];
			$type                 = $op_info['booking_type_name'];
			$trip_details         = $op_info['trip_details'];
			$operation_sts        = $op_info['operation_sts'];
			$hire_charges         = $op_info['hire_charges'];
			$booking_amount       = $op_info['booking_amount'];
			$advance_amount       = $op_info['advance_amount'];
			$discount_amount      = $op_info['discount_amount'];
			$balance_amount       = $op_info['balance_amount'];
			$extra_km             = $op_info['extra_km'];
			$operation_type       = $op_info['operation_type'];
			$tp_info              = $op_info['tp_info'];
			$op_driver_name       = $op_info['op_driver_name'];
			$op_driver_number     = $op_info['op_driver_number'];
			$op_suspense_amount   = $op_info['op_suspence_amt'];
			$trip_start_km        = $op_info['trip_start_km'];
			$trip_end_km          = $op_info['trip_end_km'];
			$vendor_name          = $op_info['vendor_name'];
			$tot_km               = (int)$trip_end_km  - (int)$trip_start_km;
			
			if($operation_sts === "1"){
				$operation_sts = "Follow Up";
			}else
			if($operation_sts === "2"){
				$operation_sts = "Confirm";
			}else
			if($operation_sts === "3"){
				$operation_sts = "Cancelled";
			}else
			if($operation_sts === "4"){
				$operation_sts = "Completed";
			}else
			if($operation_sts === "5"){
				$operation_sts = "On Progress";
			}
			
			if($operation_type === "1"){
				$operation_type = "Vehicle with driver";
			}else
			if($operation_type === "2"){
				$operation_type = "Only Driver";
			}
			
			$objWorkSheet->setCellValue('A'.$j, $tour_no)
			->setCellValue('B'.$j, $name)
			->setCellValue('C'.$j, $billing_name)
			->setCellValue('D'.$j, $mob)
			->setCellValue('E'.$j, $trip_type_name)
			->setCellValue('F'.$j, $source)
			->setCellValue('G'.$j, $destination)
			->setCellValue('H'.$j, $avg_km)
			->setCellValue('I'.$j, $from_date)
			->setCellValue('J'.$j, $to_date)
			->setCellValue('K'.$j, $trip_days)
			->setCellValue('L'.$j, $veh_type)
			->setCellValue('M'.$j, $bus_count)
			->setCellValue('N'.$j, $type)
			->setCellValue('O'.$j, $booking_amount)
			->setCellValue('P'.$j, $advance_amount)
			->setCellValue('Q'.$j, $discount_amount) 
			->setCellValue('R'.$j, $balance_amount)
			->setCellValue('S'.$j, $vehicle_no)
			->setCellValue('T'.$j, $trip_start_km)
			->setCellValue('U'.$j, $trip_end_km)
			->setCellValue('V'.$j, $tot_km) 
			->setCellValue('W'.$j, $vendor_name)
			->setCellValue('X'.$j, $operation_type) 
			->setCellValue('Y'.$j, $tp_info)
			->setCellValue('Z'.$j, $op_driver_name)
			->setCellValue('AA'.$j, $op_driver_number)
			->setCellValue('AB'.$j, $op_suspense_amount)
			->setCellValue('AC'.$j, $first_name)
			->setCellValue('AD'.$j, $operation_sts);
			
			$j++;
		}
		// Rename sheet
		$objWorkSheet->setTitle("Detailed");
		$date = date("Y-m-d H:i:s");	
		$filename="Vehicle Running report ".date('d-m-Y').".xls"; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
		 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		 //if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($obj, 'Excel5');
		 //force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
		
	}
}
?>