public function saveEditedTrip()
 {
     $tripId = Input::get('trip_id');
     $edited_customer_name = Input::get('edited_customer_name');
     $edited_customer_email = Input::get('edited_customer_email');
     $edited_customer_phone = Input::get('edited_customer_phone');
     $edited_start_km = Input::get('edited_start_km');
     $edited_end_km = Input::get('edited_end_km');
     $edited_start_time = Input::get('edited_start_time');
     $edited_end_time = Input::get('edited_end_time');
     $edited_departure_address = Input::get('edited_departure_address');
     $edited_destination_address = Input::get('edited_destination_address');
     try {
         $originalTrip = DailyTrips::find($tripId);
         $originalTrip->customer_name = $edited_customer_name;
         $originalTrip->customer_email = $edited_customer_email;
         $originalTrip->customer_phone = $edited_customer_phone;
         $originalTrip->departure_km = $edited_start_km;
         $originalTrip->arrival_km = $edited_end_km;
         $originalTrip->departure_date_time = $edited_start_time;
         $originalTrip->arrival_date_time = $edited_end_time;
         $originalTrip->departure_address = $edited_departure_address;
         $originalTrip->arrival_address = $edited_destination_address;
         $originalTrip->edit_req = null;
         $originalTrip->save();
         DailyTripsRevision::where('trip_id', '=', $tripId)->first()->delete();
         $result = array('success' => true);
     } catch (Exception $ex) {
         \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1));
         $result = array('success' => false);
     }
     return $result;
 }
 public function requestRevision()
 {
     $tripId = Input::get('trip_id');
     $carName = Input::get('car');
     $clientName = Input::get('client');
     $customerName = Input::get('customer_name');
     $customerEmail = Input::get('customer_email');
     $customerPhone = Input::get('customer_phone');
     $departureKm = Input::get('start_km');
     $arrivalKm = Input::get('end_km');
     $departureDateTime = Input::get('start_time');
     $arrivalDateTime = Input::get('end_time');
     $departureAddress = Input::get('departure_address');
     $arrivalAddress = Input::get('destination_address');
     $car = Cars::where('name', '=', substr($carName, 0, 3))->first();
     if ($car instanceof Cars) {
         $carId = $car->id;
     } else {
         $carId = '';
     }
     $client = Client::where('name', '=', $clientName)->first();
     if ($client instanceof Client) {
         $clientId = $client->id;
     } else {
         $clientId = '';
     }
     try {
         $myTrip = DailyTrips::find($tripId);
         $myTrip->edit_req = 1;
         $myTrip->save();
         $myTripRevison = new DailyTripsRevision();
         $myTripRevison->trip_id = $tripId;
         $myTripRevison->user_id = Session::get('user_id');
         $myTripRevison->car_id = $carId;
         $myTripRevison->client_id = $clientId;
         $myTripRevison->customer_name = $customerName;
         $myTripRevison->customer_email = $customerEmail;
         $myTripRevison->customer_phone = $customerPhone;
         $myTripRevison->departure_km = $departureKm;
         $myTripRevison->departure_date_time = $departureDateTime;
         $myTripRevison->arrival_km = $arrivalKm;
         $myTripRevison->arrival_date_time = $arrivalDateTime;
         $myTripRevison->departure_address = $departureAddress;
         $myTripRevison->arrival_address = $arrivalAddress;
         $myTripRevison->save();
         $results = array('success' => true, 'message' => 'revision requested');
     } catch (Exception $ex) {
         \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1));
         $results = array('success' => false, 'message' => 'an error occurred');
     }
     return $results;
 }