public function createReport()
 {
     $to = Input::get('to');
     $from = Input::get('from');
     if ($from == null || $to == null) {
         $todayFrom = date('Y-m-d', strtotime('-30 day')) . ' 00:00:00';
         $todayTo = date('Y-m-d') . ' 23:59:59';
     } else {
         $todayFrom = $from . ' 00:00:00';
         $todayTo = $to . ' 23:59:59';
     }
     $results = [];
     try {
         $trips = DailyTrips::where('departure_date_time', '>', $todayFrom)->where('departure_date_time', '<', $todayTo)->orderBy('departure_date_time')->get();
         $totalTripCount = count($trips);
         $totalTripCost = 0;
         $totalTripDistance = 0;
         $totalTripTime = 0;
         foreach ($trips as $trip) {
             $totalTripCost += $trip->trip_cost;
             $totalTripDistance += $trip->arrival_km - $trip->departure_km;
             $totalTripTime += strtotime($trip->arrival_date_time) - strtotime($trip->departure_date_time);
         }
         $totalTripTime = date('H:i:s', $totalTripTime);
         $totalFuel = FuelFillUp::where('date_and_time', '>', $todayFrom)->where('date_and_time', '<', $todayTo)->orderBy('date_and_time')->get();
         $totalFuelCost = 0;
         $totalFuelAmount = 0;
         foreach ($totalFuel as $Fuel) {
             $totalFuelCost += $Fuel->cost;
             $totalFuelAmount += $Fuel->amount;
         }
         $totalPayments = 0;
         $totalOther = 0;
         $payments = Payment::where('created_at', '>', $todayFrom)->where('created_at', '<', $todayTo)->orderBy('created_at')->get();
         foreach ($payments as $payment) {
             $totalPayments += $payment->amount;
             $totalOther += $payment->other;
         }
         $report = ['totalTripCounts' => $totalTripCount, 'totalTripCost' => $totalTripCost, 'totalTripkm' => $totalTripDistance, 'totalTripTime' => $totalTripTime, 'totalFuelCost' => round($totalFuelCost, 2), 'totalFuelAmount' => round($totalFuelAmount, 2), 'totalPayments' => $totalPayments, 'totalOther' => $totalOther];
         array_push($results, $report);
         /*
         $queries = DB::getQueryLog();
         $last_query = end($queries);
         */
     } catch (Exception $ex) {
         \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1));
     }
     //\Log::info(__METHOD__.' | =====> $results : '.print_r($results,1 ));
     return json_encode($results);
 }
 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;
 }