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/Operation.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class operation  extends Secure_Controller{
 
	public function __construct(){
		parent::__construct('operation');
		$this->load->model('Sms_model');
		$this->load->model('Operation_model');
	}
	
	public function index(){
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
		$data['table_headers']=$this->xss_clean(get_operation_headers());
		$this->load->view('operation/manage',$data);
	}
	
	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('start_date' => $this->input->get('start_date'),'end_date' => $this->input->get('end_date'),'Follow_Up' => FALSE,'Confirm' => FALSE,'Cancelled' => FALSE,'Completed' => FALSE,'On_progress' => FALSE);			
		$filledup = array_fill_keys($this->input->get('filters'), TRUE);
		$filters = array_merge($filters, $filledup);
		
		$operation=$this->Operation_model->search($search,$filters,$limit,$offset,$sort,$order);

		$TotalRows=$this->Operation_model->get_found_rows($search,$filters);
		$DataRows=array();

		foreach ($operation->result() as $person) 
		{	
			$DataRows[]=get_operation_datarows($person,$this);
		}
		$DataRows=$this->xss_clean($DataRows);
		echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
	}

	public function view($operation_id=-1){
		$booking_info = $this->Operation_model->view_data($operation_id);
		// UDY PATCH WORK FOR BOOKING ID MISSING - START
		$this->db->from('operation');
		$this->db->where('operation_id',$operation_id);
		$operation = $this->db->get()->row();
		$booking_id = $operation->booking_id;
		$booking_info->booking_id = $booking_id;
		$data['booking_info'] = $booking_info;
		// UDY PATCH WORK FOR BOOKING ID MISSING - END
		
		$booking     = $data['booking_info'];
		$vehicle_ids = explode(",",$booking->preferred_vehicle);
		$type        = $booking->vehicle_type;
		$trip        = $booking->trip_type;
		
		$data['preferred_list'] = $this->Operation_model->preferred_vehicle_list($vehicle_ids);
		
		$vehicle_type[""] = "--Select Vehicle Type--";
		foreach($this->Operation_model->get_vehicle_type()->result_array() as $row){
		    $vehicle_type[$this->xss_clean($row['veh_type_id'])] = $this->xss_clean($row['veh_type']." - ".$row['veh_category']);
		}		
		$data['vehicle_type'] = $vehicle_type;		
		
		$vehicle_list[""] = "--Select Vehicle--";
		$vehicle = $this->Operation_model->get_vehicle($type);		
		foreach($vehicle as $row){
		    $vehicle_list[$this->xss_clean($row->vehicle_id)] = $this->xss_clean($row->vehicle_no);
		}
		$data['vehicle_list'] = $vehicle_list;
		
		$driver_list[""] = "--Select Driver--";	
		$driver_list['0'] = "Others";
		foreach($this->Operation_model->get_driver() as $row){
		    $driver_list[$this->xss_clean($row->id)] = $this->xss_clean($row->first_name);
		}		
		$data['driver_list'] = $driver_list;
		
		$cleaner_list[""] = "--Select Cleaner--";	
		$cleaner_list['0'] = "Others";
		foreach($this->Operation_model->get_cleaner() as $row){
		    $cleaner_list[$this->xss_clean($row->id)] = $this->xss_clean($row->first_name);
		}		
		$data['cleaner_list'] = $cleaner_list;
		
		$op_line_list = $this->Operation_model->get_op_line_list($operation_id);
		$data['op_line_list'] = $op_line_list;
		
		$suspence_vech[""] = "--Select Vehicle--";	
		foreach($op_line_list as $row){
		    $suspence_vech[$this->xss_clean($row->op_vehicle_id)] = $this->xss_clean($row->vehicle_no);
		}
		$data['suspence_vech']         = $suspence_vech;
		$data['suspence_list']         = $this->Operation_model->suspence_list($operation_id);
		$data['suspence_subtotal']     = $this->Operation_model->suspence_subtotal($operation_id);
		$data['diesel_list']           = $this->Operation_model->diesel_list($operation_id);
		$data['diesel_subtotal']       = $this->Operation_model->diesel_subtotal($operation_id);
		$data['maintenance_list']      = $this->Operation_model->maintenance_list($operation_id);
		$data['driver_suspence_list']  = $this->Operation_model->driver_suspence_list($operation_id);
		$data['feedback_list']         = $this->Operation_model->feedback_list($operation_id);
		$data['trip_summary']          = $this->Operation_model->trip_summary($operation_id);
		$this->load->view("operation/form",$data);
	}
		/*
	public function get_vehicle_list(){
		$vehicle_type = $this->input->post('vehicle_type');		
		$vehicle_list  = $this->Operation_model->get_vehicle($vehicle_type);
		echo json_encode(array('success' => TRUE, 'vehicle_list' => $vehicle_list));
	}	*/	
	public function get_vehicle_list(){		
		$vehicle_type = $this->input->post('vehicle_type');
		$vehicle_list  = $this->Operation_model->get_vehicle($vehicle_type);
		echo json_encode(array('success' => TRUE, 'vehicle_list' => $vehicle_list));	
	}
	
	public function update_sts(){
		$mode          = $this->input->post('mode');		
		$operation_id  = $this->input->post('operation_id');		
		$booking_id    = $this->input->post('booking_id');
		$mobile        = $this->input->post('mobile');
		$update_sts  = $this->Operation_model->update_sts($mode,$operation_id,$booking_id);
		if($mode === "CHK"){
			if($mobile){
				$this->Sms_model->send_sms($booking_id,$mobile,"trip_completed");
			}
		}
		//echo json_encode(array('success' => TRUE, 'update_sts' => $update_sts));
	}
	
	public function remove_op_line(){
		$op_line_id    = $this->input->post('op_line_id');	
		$update_sts  = $this->Operation_model->remove_op_line($op_line_id);		
		//echo json_encode(array('success' => TRUE, 'update_sts' => $update_sts));
	}
	public function check_driver_expiry($driver_id){
		$driver_id = $this->input->post('driver_id');
		
		$driver_info = $this->Operation_model->get_driver_info($driver_id);
		$license_expiry   = date("Y-m-d", strtotime($driver_info->license_expiry));
		$first_name       = $driver_info->first_name;
		$phone_number     = $driver_info->phone_number;
		
		$vehicle_data = array();		
		$dl_sts  = $this->check_expiry($license_expiry);
		$vehicle_data[] = array('name' => 'Driving License','date'=>$license_expiry,'sts'=>$dl_sts,'driver_id'=>$driver_id,'first_name'=>$first_name,'phone_number'=>$phone_number);
		
		echo json_encode(array('success' => TRUE, 'vehicle_data' => $vehicle_data));
	}
	
	public function get_op_line(){
		$op_line_id = $this->input->post('op_line_id');
		$op_line = $this->Operation_model->get_op_line($op_line_id);
		echo json_encode(array('success' => TRUE, 'op_line' => $op_line));
	}
	
	public function get_cleaner_info(){
		$cleaner_id = $this->input->post('cleaner_id');
		$cleaner_info = $this->Operation_model->get_driver_info($cleaner_id);
		$first_name       = $cleaner_info->first_name;
		$phone_number     = $cleaner_info->phone_number;
		echo json_encode(array('success' => TRUE, 'cleaner_id'=>$cleaner_id,'first_name'=>$first_name,'phone_number'=>$phone_number));
	}
	
	public function get_vehicle_infromation($vehicle_id){
		$vehicle_id = $this->input->post('vehicle_id');	
		
		$tax_info = $this->Operation_model->get_vehicle_tax($vehicle_id);		
		$doc_to = "";
		if($tax_info){
			$doc_to = $tax_info->doc_to;
		}		
		$tp_info = $this->Operation_model->get_vehicle_tp($vehicle_id);		
		$tp_doc_to = "";
		if($tp_info){
			$tp_doc_to = $tp_info->doc_to;
		}
		
		$vehicle_info   = $this->Operation_model->get_vehicle_infromation($vehicle_id);
		$owned_by        = $vehicle_info->owned_by;
		$fc_date        = $vehicle_info->fc_date;
		$permit_date    = $vehicle_info->permit_date;
		$insur_date     = $vehicle_info->insur_date;
		$pollution_date = $vehicle_info->pollution_date;
		$driver_name    = $vehicle_info->driver_name;
		$license_expiry = date("Y-m-d", strtotime($vehicle_info->license_expiry));
		$driver_info = $this->Operation_model->get_driver_info($driver_name);
		$first_name   = $driver_info->first_name;
		$phone_number = $driver_info->phone_number;
		
		$vehicle_data = array();
		$fc_sts  = $this->check_expiry($fc_date);
		$vehicle_data[] = array('owned_by'=>$owned_by,'name' => 'FC','date'=>$fc_date,'sts'=>$fc_sts);
		
		$permit_sts  = $this->check_expiry($permit_date);
		$vehicle_data[] = array('owned_by'=>$owned_by,'name' => 'Permit','date'=>$permit_date,'sts'=>$permit_sts);
		
		$insur_sts  = $this->check_expiry($insur_date);
		$vehicle_data[] = array('owned_by'=>$owned_by,'name' => 'Insurance','date'=>$insur_date,'sts'=>$insur_sts);
		
		$pollution_sts  = $this->check_expiry($pollution_date);
		$vehicle_data[] = array('owned_by'=>$owned_by,'name' => 'Pollution','date'=>$pollution_date,'sts'=>$pollution_sts);
		
		$tax_sts  = $this->check_expiry($doc_to);
		$vehicle_data[] = array('owned_by'=>$owned_by,'name' => 'TAX','date'=>$doc_to,'sts'=>$tax_sts);
		
		$tp_sts  = $this->check_expiry($tp_doc_to);
		$vehicle_data[] = array('owned_by'=>$owned_by,'name' => 'TP','date'=>$tp_doc_to,'sts'=>$tp_sts);
		
		$dl_sts  = $this->check_expiry($license_expiry);
		$vehicle_data[] = array('owned_by'=>$owned_by,'name' => 'Driving License','date'=>$license_expiry,'sts'=>$dl_sts,'driver_id'=>$driver_name,'first_name'=>$first_name,'phone_number'=>$phone_number);
		
		echo json_encode(array('success' => TRUE, 'vehicle_data' => $vehicle_data));
	}
	public function check_expiry($expiry){
		$today  = strtotime(date("Y-m-d"));
		$expiry = strtotime($expiry);
		$sts = "Valid";
		if($today > $expiry){
			$sts = "Expired";
		}
		return $sts;
	}
	public function date_difference($from_date,$to_date){
		$from_date = date("Y-m-d", strtotime($from_date));
		$to_date   = date("Y-m-d", strtotime($to_date));
		
		$diff = abs(strtotime($to_date) - strtotime($from_date));
		$years = floor($diff / (365*60*60*24));
		$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
		$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
		//$days = $days +1;
		return $days;
	}
	public function print_tp($op_line_id){
		$data['trip_info'] = $this->Operation_model->get_trip_info($op_line_id);
		$data['tax_info']  = $this->Operation_model->get_tax_info($op_line_id);
		$this->load->view('operation/print_tp',$data);
	}
	public function print_trip_sheet($op_line_id){
		$data['trip_info'] = $this->Operation_model->get_trip_info($op_line_id);
	
		$getcust    = $data['trip_info']; 				
		$vehicle    = $getcust->vehicle_type;
		$trip       = $getcust->trip_type;
		$km         = $getcust->avg_km;
		
		if($km === ""){ 
			$km = 0; 
		}
		
		$data['tariff'] = $this->Operation_model->get_tariff_amt($trip,$vehicle,$km);
		
		$this->load->view('operation/print_trip_sheet',$data);
	}
	
	public function check_avilability(){
		$trip_type    = $this->input->post('trip_type');
		$vehicle_type = $this->input->post('vehicle_type');
		$from_date    = date("Y-m-d", strtotime($this->input->post('from_date')));
		$to_date      = date("Y-m-d", strtotime($this->input->post('to_date')));
		$get_cout 	  = $this->input->post('get_cout');
		
		$start    = (new DateTime($from_date))->modify('first day of this month');
		$end      = (new DateTime($to_date))->modify('first day of next month');
		$interval = DateInterval::createFromDateString('1 month');
		$period   = new DatePeriod($start, $interval, $end);
		$table    = "";		
		foreach ($period as $dt) {
			$year_month    =  $dt->format("Y-m");
			$vehicle_list = $this->Operation_model->get_vehicle_live($vehicle_type);
			
			foreach ($vehicle_list as $vehicle){
				$vehicle_id    = $vehicle->vehicle_id;
				$vehicle_no    = $vehicle->vehicle_no;
				$type          = $vehicle->vehicle_type;
				
				$txt_month    = date("F Y", strtotime("$year_month-01"));
				$booked_list  = $this->Operation_model->get_booking_chart($year_month,$vehicle_id,$type);				
				$demand_month = $this->Operation_model->get_demand_date($year_month);
				
				$year_month_rslt = explode('-', $year_month);
				$year  = $year_month_rslt[0];
				$month = $year_month_rslt[1];
				
				$tot_days     = cal_days_in_month(CAL_GREGORIAN,$month,$year);
				$th_line    = "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;'>Vehicle Number</th>";
				$th_line    .= "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;'>Mode</th>";
				for($i = 1; $i <= $tot_days; $i++){
					$getday = strtotime("$year_month-$i");
					$day    = date('D', $getday);			
					$col    = "day_".$i;
					$demand_days = $demand_month->$col;
					
					$crl = "";
					if(($day === "Sat") || ($day === "Sun")){
						$crl = "background-color:#FFCF00;";
					}
					if($demand_days === "1"){
						$crl = "background-color:#4dd9f9;";
					}
					$th_line .= "<th style='padding:4px;text-align:center;border:1px solid #CCCCCC;$crl'>$day <br/>$i</th>";			
				}
				$th_line = "<tr>$th_line</tr>";
				
				$td_line    .= "<td rowspan='2' style='padding:8px 0px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;'>$vehicle_no</td>";
				foreach ($booked_list as $booked_list){
					$mode = $booked_list->mode;
					$mode_name = ucfirst(strtolower($mode));
					$td_line    .= "<td style='padding:8px 0px;text-align:center;border:1px solid #CCCCCC;'>$mode_name</td>";
					for($i = 1; $i <= $tot_days; $i++){
						$col        = "day_".$i;
						$to_booked = $booked_list->$col;
						$crl   = "";
						if($to_booked === "1"){
							if($mode === "SALES"){
								$crl = "background-color:#E4E051;";
							}else{
								$crl = "background-color:#43D854;";
							}
						}
						$td_line .= "<td style='padding:4px;text-align:center;border:1px solid #CCCCCC;$crl'></td>";
					}
					$td_line = "<tr>$td_line</tr>";
				}
			}
			$table .="<div style='font-weight: bold; color: #d84f57; margin-top: 4px;text-align: center; font-size: 10px;'>$txt_month</div>
					  <table class='table table-hover table-striped table-bordered' style='font-size:9px !important;margin-top:4px;margin-bottom: 4px;'>
						$th_line
						$td_line
					  </table>";
			$td_line = "";
			if($get_cout === "1"){
				$avilability_count =  $this->avilability_count($from_date,$to_date,$type);
			}
		}
		$avilability_chart = "<span style='padding:0px 8px;background-color:#FFCF00;'></span> &nbsp; Saturday and Sunday
						  <span style='padding:0px 8px;background-color:#4dd9f9;'></span> &nbsp; Demand Date
						  <span style='padding:0px 8px;background-color:#E4E051;'></span> &nbsp; Sales Assigned
						  <span style='padding:0px 8px;background-color:#43D854;'></span> &nbsp; Operation Confirmed
						  $table";
		
		if($get_cout === "1"){
			echo "<div style='font-weight: bold; color: #d84f57; margin-top: 4px;text-align: center; font-size: 11px;padding-right:15px;text-align:right;'>$avilability_count</div>$avilability_chart";
		}else{
			echo "$avilability_chart";
		}
	}
	public function avilability_count($from_date,$to_date,$vehicle_type){
		$from     = strtotime($from_date);
		$to       = strtotime($to_date);
		$chkdate  = explode('-', $from_date);
		$premonth = $chkdate[1];
		$chk_qry  = "";
		$chk_qry1 = "";
		for($i=$from; $i<=$to; $i+=86400) {
			$bet_date = date("Y-m-d", $i);
			$between       = explode('-', $bet_date);
			$between_year  = $between[0];
			$between_month = $between[1];
			$between_date  = $between[2];
			$between_date  = ltrim($between_date, '0');
			$col    = "day_".$between_date;
			if($premonth === $between_month){
				$month_one = $between_year."-".$between_month;
				$chk_qry  .= " $col = '0' and";
			}else{
				$month_two = $between_year."-".$between_month;
				$chk_qry1 .= " $col = '0' and";
			}
		}
		$avilability = "";
		if($chk_qry !== ""){
			$chk_qry = rtrim($chk_qry, 'and');
			$month_one_qry   = $this->db->query("select * from sblt_booking_chart where chart_month = '$month_one' and mode = 'OPERATION' and chart_vehicle_type = '$vehicle_type' and $chk_qry");
			$month_one_count = $month_one_qry->num_rows();
			$txt_month    = date("F Y", strtotime("$month_one-01"));
			$avilability .= "$month_one_count Vehicle available for selected date<br/>";
			
		}				
		if($chk_qry1 !== ""){
			$chk_qry1 = rtrim($chk_qry1, 'and');
			$month_two_qry   = $this->db->query("select * from sblt_booking_chart where chart_month = '$month_two' and mode = 'OPERATION' and chart_vehicle_type = '$vehicle_type' and $chk_qry");
			$month_two_count = $month_two_qry->num_rows();
			$txt_month    = date("F Y", strtotime("$month_two-01"));
			$avilability .= "$month_two_count Vehicle available for selected date<br/>";
		}
		return $avilability;
	}
	public function save($op_line_id){
		$operation_id = $this->input->post('operation_id');
		$op_line_data = array(
			'operation_id'         => $this->input->post('operation_id'),
			'op_vehicle_type'      => $this->input->post('vehicle_type'),
			'op_vehicle_id'        => $this->input->post('vehicle_id'),
			'op_driver_id'         => $this->input->post('driver_id'),
			'op_driver_name'       => $this->input->post('driver_name'),
			'op_driver_number'     => $this->input->post('driver_number'),
			'op_suspence_amt'      => $this->input->post('suspence_amt'),
			'second_driver_id'     => $this->input->post('second_driver_id'),
			'second_driver_name'   => $this->input->post('second_driver_name'),
			'second_driver_number' => $this->input->post('second_driver_number'),
			'cleaner_id'           => $this->input->post('cleaner_id'),
			'cleaner_name'         => $this->input->post('cleaner_name'),
			'cleaner_number'       => $this->input->post('cleaner_number'),
			'driver_sts'	       => '1',
			'op_chk_list'          => $this->input->post('chk_list'),
			'remarks'              => $this->input->post('remarks'),
			'tp_info'              => $this->input->post('tp_info'),
			'cust_rout_info'       => $this->input->post('cust_rout_info'),
			'created_by'           => $this->session->userdata('emp_id'),
			'created_date'         => date("Y-m-d H:i:s"),
		);
		$op_line_id = $this->Operation_model->save_op_line($op_line_data, $op_line_id);
		// SEND SMS
		$op_line_info = $this->Operation_model->get_trip_info($op_line_id);
		$mobile       = $op_line_info->phone_number;		
		if($mobile){
			$this->Sms_model->send_sms($op_line_id,$mobile,"operation_confirm");
		}
		$primary_driver = $op_line_info->op_driver_number;
		if($primary_driver){
			$this->Sms_model->send_sms($op_line_id,$primary_driver,"driver_duty");
		}
		$second_driver  = $op_line_info->second_driver_number;
		if($second_driver){
			$this->Sms_model->send_sms($op_line_id,$second_driver,"driver_duty");
		}
		
		$op_line_list = $this->Operation_model->get_op_line_list($operation_id);
		echo json_encode(array('success' => TRUE, 'op_line' => $op_line_list));
	}
	public function save_driver_suspence(){
		$driver_suspence_id    = $this->input->post('driver_suspence_id');
		$driver_suspence_op_id = $this->input->post('driver_suspence_op_id');
		$driver_suspence_data = array(
			'driver_suspence_date'   => date("Y-m-d", strtotime($this->input->post('driver_suspence_date'))),
			'driver_suspence_vch_id' => $this->input->post('driver_suspence_vch_id'),
			'driver_suspence_amount'   => $this->input->post('driver_suspence_amount'),
			'driver_suspence_op_id'   => $this->input->post('driver_suspence_op_id'),
			'created_by'      => $this->session->userdata('emp_id'),
			'created_date'    => date("Y-m-d H:i:s"),
		);
		$this->Operation_model->save_driver_suspence($driver_suspence_data, $driver_suspence_id);
		$driver_suspence_list     = $this->Operation_model->driver_suspence_list($driver_suspence_op_id);
		echo json_encode(array('success' => TRUE, 'driver_suspence_list' => $driver_suspence_list));
		/*
		
		$suspence_list     = $this->Operation_model->suspence_list($suspence_op_id);
		$suspence_subtotal = $this->Operation_model->suspence_subtotal($suspence_op_id);
		$suspence_amount   = $this->Operation_model->get_suspence_amount($suspence_op_id);
		echo json_encode(array('success' => TRUE, 'suspence_list' => $suspence_list, 'amount' => $suspence_amount, 'suspence_subtotal' => $suspence_subtotal));
		*/
	}
	public function get_driver_suspence(){
		$driver_suspence_id = $this->input->post('driver_suspence_id');
		$driver_suspence    = $this->Operation_model->get_driver_suspence($driver_suspence_id);
		echo json_encode(array('success' => TRUE, 'driver_suspence' => $driver_suspence));
	}
	public function save_suspence($suspence_id){
		$suspence_id       = $this->input->post('suspence_id');
		$suspence_op_id    = $this->input->post('suspence_op_id');
		$suspence_book_id  = $this->input->post('suspence_book_id');
		$suspence_data = array(
			'suspence_date'   => date("Y-m-d", strtotime($this->input->post('suspence_date'))),
			'suspence_vch_id' => $this->input->post('suspence_vch_id'),
			'suspence_info'   => $this->input->post('suspence_info'),
			'suspence_amt'    => $this->input->post('suspence_amount'),
			'suspence_op_id'  => $this->input->post('suspence_op_id'),
			'created_by'      => $this->session->userdata('emp_id'),
			'created_date'    => date("Y-m-d H:i:s"),
		);
		$this->Operation_model->save_suspence($suspence_data, $suspence_id,$suspence_book_id);
		$suspence_list     = $this->Operation_model->suspence_list($suspence_op_id);
		$suspence_subtotal = $this->Operation_model->suspence_subtotal($suspence_op_id);
		$suspence_amount   = $this->Operation_model->get_suspence_amount($suspence_op_id);
		echo json_encode(array('success' => TRUE, 'suspence_list' => $suspence_list, 'amount' => $suspence_amount, 'suspence_subtotal' => $suspence_subtotal));
	}
	public function get_suspence(){
		$suspence_id = $this->input->post('suspence_id');
		$sus_data    = $this->Operation_model->get_suspence($suspence_id);
		echo json_encode(array('success' => TRUE, 'sus_data' => $sus_data));
	}
	public function save_diesel($diesel_id){
		$diesel_id    = $this->input->post('diesel_id');
		$diesel_op_id = $this->input->post('diesel_op_id');
		$end_km    = $this->input->post('end_km');
		$start_km  = $this->input->post('start_km');
		$quantity  = $this->input->post('diesel_quantity');
		
		$actual_km = (int)$end_km - (int)$start_km;
		$avg_km = $actual_km  / $quantity;
		
		$diesel_data = array(
			'diesel_date'      => date("Y-m-d", strtotime($this->input->post('diesel_date'))),
			'diesel_vch_id'    => $this->input->post('diesel_vch_id'),
			'start_km'         => $this->input->post('start_km'),
			'end_km'           => $this->input->post('end_km'),
			'diesel_quantity'  => $this->input->post('diesel_quantity'),
			'diesel_amt'       => $this->input->post('diesel_amt'),
			'actual_km'        => $actual_km,
			'avg_km'           => $avg_km,
			'diesel_op_id'     => $this->input->post('diesel_op_id'),
			'created_by'       => $this->session->userdata('emp_id'),
			'created_date'     => date("Y-m-d H:i:s"),
		);
		$this->Operation_model->save_diesel($diesel_data, $diesel_id);
		$diesel_list      = $this->Operation_model->diesel_list($diesel_op_id);
		$diesel_subtotal  = $this->Operation_model->diesel_subtotal($diesel_op_id);
		$diesel_amount    = $this->Operation_model->get_diesel_amount($diesel_op_id);
		echo json_encode(array('success' => TRUE, 'diesel_list' => $diesel_list, 'amount' => $diesel_amount, 'diesel_subtotal' => $diesel_subtotal));
	}
	public function get_diesel(){
		$diesel_id = $this->input->post('diesel_id');
		$diesel_data = $this->Operation_model->get_diesel($diesel_id);
		echo json_encode(array('success' => TRUE, 'diesel_data' => $diesel_data));
	}
	public function save_maintenance($diesel_id){
		$maintenance_id    = $this->input->post('maintenance_id');
		$maintenance_op_id = $this->input->post('maintenance_op_id');
		$maintenance_data = array(
			'maintenance_date' => date("Y-m-d", strtotime($this->input->post('maintenance_date'))),
			'vehicle_id'       => $this->input->post('maintenance_vch_id'),
			'op_id'            => $this->input->post('maintenance_op_id'),
			'maintenance_type' => $this->input->post('maintenance_type'),
			'service_remarks'  => $this->input->post('service_remarks'),
			'created_by'       => $this->session->userdata('emp_id'),
			'created_date'     => date("Y-m-d H:i:s"),
		);
		$this->Operation_model->save_maintenance($maintenance_data,$maintenance_op_id);
		$maintenance_list = $this->Operation_model->maintenance_list($maintenance_op_id);
		echo json_encode(array('success' => TRUE, 'maintenance_list' => $maintenance_list));
	}
	public function save_extra_km(){
		$op_id = $this->input->post('extra_op_id');
		$extra_data  = array(
			'extra_vch_id'     => $this->input->post('extra_vch_id'),
			'hire_charges'     => $this->input->post('hire_charges'),
			'trip_start_km'    => $this->input->post('trip_start_km'),
			'trip_end_km'      => $this->input->post('trip_end_km'),
			'op_extra_km'      => $this->input->post('op_extra_km'),
			'op_extra_pre_km'  => $this->input->post('op_extra_pre_km'),
			'op_extra_amt'     => $this->input->post('op_extra_amt'),
			'extra_avg_km'     => $this->input->post('extra_avg_km'),
			'extra_op_id'      => $this->input->post('extra_op_id'),
			'extra_booking_id' => $this->input->post('extra_booking_id'),
		);
		
		$this->Operation_model->save_extra_km($extra_data);
		$op_line_list = $this->Operation_model->get_op_line_list($op_id);
		echo json_encode(array('success' => TRUE,'op_line_list' => $op_line_list));
	}
	public function get_maintenance(){
		$maintenance_id = $this->input->post('maintenance_id');
		$maintenance_data = $this->Operation_model->get_maintenance($maintenance_id);
		echo json_encode(array('success' => TRUE, 'maintenance_data' => $maintenance_data));
	}
	
	public function get_row($operation_ids){
		$operation_infos = $this->Operation_model->get_multiple_info($operation_ids);
		$result = array();
		foreach($operation_infos as $item_info){
			$result[$item_info->operation_id] = $this->xss_clean(get_item_data_row($item_info, $this));
		}
		echo json_encode($result);
	}
	
	public function delete(){
		$operation_to_delete = $this->xss_clean($this->input->post('ids'));
		if($this->Operation_model->delete_list($operation_to_delete)){
			echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('operation_successful_deleted').' '. count($operation_to_delete).' '.$this->lang->line('operation_one_or_multiple')));
		}else{
			echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('operation_cannot_be_deleted')));
		}
	}
}
?>