File: //home/cafsindia/allyindian_com/sbltt/application/controllers/Driver.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class driver extends Secure_Controller{
public function __construct(){
parent::__construct('driver');
$this->load->model('Sms_model');
$this->load->model('Driver_model');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_driver_headers());
$this->load->view('driver/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'));
$operation=$this->Driver_model->search($search,$filters,$limit,$offset,$sort,$order);
$TotalRows=$this->Driver_model->get_found_rows($search,$filters);
$DataRows=array();
foreach ($operation->result() as $person) {
$DataRows[]=get_driver_datarows($person,$this);
}
//$DataRows=$this->xss_clean($DataRows);
echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
}
public function view($operation_id){
$data['booking_info'] = $this->Driver_model->view_data($operation_id);
$booking = $data['booking_info'];
$op_vehicle_id = $booking->op_vehicle_id;
$data['suspence_list'] = $this->Driver_model->suspence_list($operation_id,$op_vehicle_id);
$data['diesel_list'] = $this->Driver_model->diesel_list($operation_id,$op_vehicle_id);
$data['starting_km'] = $this->Driver_model->get_start_km($operation_id,$op_vehicle_id);
$this->load->view("driver/form",$data);
}
public function trip_status($operation_id){
$data['booking_info'] = $this->Driver_model->view_data($operation_id);
$booking = $data['booking_info'];
$op_vehicle_id = $booking->op_vehicle_id;
$data['maintenance_list'] = $this->Driver_model->maintenance_list($operation_id,$op_vehicle_id );
$this->load->view("driver/trip_status",$data);
}
public function update_trip(){
$op_line_id = $this->input->post('op_line_id');
$start_op_id = $this->input->post('start_op_id');
$trip_data = array(
'trip_start_km' => $this->input->post('trip_start_km'),
'driver_chk_list' => $this->input->post('driver_chk_list'),
'driver_remark' => $this->input->post('driver_remark'),
'driver_sts' => '2',
);
$this->Driver_model->update_trip($trip_data, $op_line_id,$start_op_id);
$this->Sms_model->send_traking_url($op_line_id);
echo json_encode(array('success' => TRUE, 'message' => "Updated to trip information"));
}
public function update_trip_end(){
$op_line_id = $this->input->post('end_op_line_id');
$trip_data = array(
'trip_end_km' => $this->input->post('trip_end_km'),
'red_alert' => $this->input->post('red_alert'),
'driver_sts' => '3',
);
$update_trip = $this->Driver_model->update_trip($trip_data, $op_line_id);
if($update_trip){
$trip_end_info = $this->Driver_model->trip_end_info($op_line_id);
if($trip_end_info){
$customer_name = $trip_end_info->customer_name;
$tour_no = $trip_end_info->tour_no;
$phone_number = $trip_end_info->phone_number;
$trip_start_km = (int)$trip_end_info->trip_start_km;
$trip_end_km = (int)$trip_end_info->trip_end_km;
$total_km = $trip_end_km - $trip_start_km;
$sms_content = "Greetings from SBLT,$customer_name Trip completed for $customer_name Order#$tour_no. Your trip total KM $total_km";
$sms_data = array(
'for_id' => $op_line_id,
'to_mobile' => $phone_number,
'sms_txt' => $sms_content,
'sent_from' => "total_km",
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d h:i:s"),
);
$this->Sms_model->save_sms($sms_data);
$this->Sms_model->trigger_sms($phone_number,$sms_content);
}
}
echo json_encode(array('success' => TRUE, 'message' => "Updated to trip information"));
}
public function get_suspence(){
$suspence_id = $this->input->post('suspence_id');
$sus_data = $this->Driver_model->get_suspence($suspence_id);
echo json_encode(array('success' => TRUE, 'sus_data' => $sus_data));
}
public function save_suspence($suspence_id){
$suspence_id = $this->input->post('suspence_id');
$suspence_op_id = $this->input->post('suspence_op_id');
$suspence_vch_id = $this->input->post('suspence_vch_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->Driver_model->save_suspence($suspence_data, $suspence_id);
$suspence_list = $this->Driver_model->suspence_list($suspence_op_id,$suspence_vch_id);
$suspence_amount = $this->Driver_model->get_suspence_amount($suspence_op_id,$suspence_vch_id);
echo json_encode(array('success' => TRUE, 'suspence_list' => $suspence_list, 'amount' => $suspence_amount));
}
public function get_diesel(){
$diesel_id = $this->input->post('diesel_id');
$diesel_data = $this->Driver_model->get_diesel($diesel_id);
echo json_encode(array('success' => TRUE, 'diesel_data' => $diesel_data));
}
public function save_diesel($diesel_id){
$diesel_id = $this->input->post('diesel_id');
$diesel_op_id = $this->input->post('diesel_op_id');
$diesel_vch_id = $this->input->post('diesel_vch_id');
$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'),
'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->Driver_model->save_diesel($diesel_data, $diesel_id);
$diesel_list = $this->Driver_model->diesel_list($diesel_op_id,$diesel_vch_id);
$diesel_amount = $this->Driver_model->get_diesel_amount($diesel_op_id,$diesel_vch_id);
echo json_encode(array('success' => TRUE, 'diesel_list' => $diesel_list, 'amount' => $diesel_amount));
}
public function save_feed_back(){
$feed_data = array(
'feed_op_id' => $this->input->post('feed_op_id'),
'feed_op_line_id' => $this->input->post('feed_op_line_id'),
'feed_vch_id' => $this->input->post('feed_vch_id'),
'vch_quality' => $this->input->post('vch_quality'),
'vch_media' => $this->input->post('vch_media'),
'vch_seat' => $this->input->post('vch_seat'),
'driving_skill' => $this->input->post('driving_skill'),
'driver_behaviour' => $this->input->post('driver_behaviour'),
'sightseeing' => $this->input->post('sightseeing'),
'remarks' => $this->input->post('remarks'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d h:i:s"),
);
$this->Driver_model->save_feed_back($feed_data);
echo json_encode(array('success' => TRUE, 'message' => "Thanks for your valuable feedback"));
}
public function get_maintenance(){
$maintenance_id = $this->input->post('maintenance_id');
$maintenance_data = $this->Driver_model->get_maintenance($maintenance_id);
echo json_encode(array('success' => TRUE, 'maintenance_data' => $maintenance_data));
}
public function save_maintenance(){
$maintenance_id = $this->input->post('maintenance_id');
$maintenance_op_id = $this->input->post('maintenance_op_id');
$maintenance_vch_id = $this->input->post('maintenance_vch_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->Driver_model->save_maintenance($maintenance_data,$maintenance_op_id);
$maintenance_list = $this->Driver_model->maintenance_list($maintenance_op_id,$maintenance_vch_id);
echo json_encode(array('success' => TRUE, 'maintenance_list' => $maintenance_list));
}
}
?>