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 showMyTrips()
 {
     $userId = Session::get('user_id');
     $to = Input::get('to');
     $from = Input::get('from');
     if ($from == null || $to == null) {
         $today = LocationController::getTime();
         $todayFrom = $today['date'] . ' 00:00:00';
         $todayTo = $today['date'] . ' 23:59:59';
     } else {
         $todayFrom = $from . ' 00:00:00';
         $todayTo = $to . ' 23:59:59';
     }
     try {
         $myTrips = DailyTrips::where('user_id', '=', $userId)->where('departure_date_time', '>', $todayFrom)->where('departure_date_time', '<', $todayTo)->orderBy('departure_date_time', 'desc')->get()->toArray();
         $carId = Session::get('car_id');
         $car = Cars::find($carId);
         if ($myTrips == null) {
             $myTrips = array('my_trips' => 'no trips have been recorded for you.');
         }
         $results = array('success' => true, 'my_trips' => $myTrips, 'car' => $car);
     } catch (Exception $ex) {
         \Log::error(__METHOD__ . ' | error :' . print_r($ex, 1));
         $results = array('success' => false, 'message' => 'an error occurred');
     }
     return $results;
 }