Beispiel #1
0
 private function getQueryAvailableVehicles(Request $request)
 {
     $initialised = false;
     $query = '';
     //Search by id
     if ($request['id'] != null) {
         $query = travelModel::where('id', '=', $request['id']);
         $initialised = true;
     }
     //Search by checkin
     if ($request['vehicleid'] != null && $initialised) {
         $query->where('vehicleID', '=', $request['vehicleid']);
     } else {
         if (!$initialised && isset($request['vehicleid'])) {
             $query = travelModel::where('vehicleID', '=', $request['vehicleid']);
             $initialised = true;
         }
     }
     //limit query
     if ($request['limit'] != null && $query != '') {
         $query->take($request['limit']);
     }
     if ($initialised) {
         $vehicles = $query->get();
     } else {
         $vehicles = vehicleModel::get();
     }
     //Check if greater than today
     $errorMessage = "";
     $checkIn = new \DateTime($request['checkin']);
     $checkOut = new \DateTime($request['checkout']);
     $dispatch = $request['dispatch'];
     $error = false;
     foreach ($vehicles as $vehicle) {
         $checkInVehicle = new \DateTime($vehicle->pickUpTime1);
         $checkOutVehicle = new \DateTime($vehicle->pickUpTime2);
         $checkInVehicle1h = new \DateTime($vehicle->pickUpTime1);
         $checkOutVehicle1h = new \DateTime($vehicle->pickUpTime2);
         $checkInVehicle1h->add(new \DateInterval('PT1H'));
         $checkOutVehicle1h->add(new \DateInterval('PT1H'));
         $dispatchvehicle = $request['dispach'];
         if ($checkIn >= $checkInVehicle && $checkIn <= $checkInVehicle1h) {
             //Conflict in check in
             $errorMessage = "A conflict in checkin time";
             $error = true;
         } elseif ($dispatch == 'true' && $checkOut >= $checkInVehicle && $checkOut <= $checkInVehicle1h) {
             // Conflict in return journey
             $errorMessage = "A conflict in checkout time";
             $error = true;
         } elseif ($dispatchvehicle && $checkIn >= $checkOutVehicle && $checkIn <= $checkOutVehicle1h) {
             // Conflict in return journey
             $errorMessage = "A conflict in checkin time";
             $error = true;
         } elseif ($dispatchvehicle && $dispatch && $checkOut >= $checkOutVehicle && $checkOut <= $checkOutVehicle1h) {
             // Conflict in return journey
             $errorMessage = "A conflict in checkout time";
             $error = true;
         } else {
             $errorMessage = "No conflict in checkout time";
         }
     }
     return array('status' => $error, 'msg' => $errorMessage);
 }