public function deleteVehicleBooking(Request $request)
 {
     $user = $request->session()->get('user');
     if (is_null($user)) {
         return false;
     }
     if ($request['id'] != null) {
         $deleteVehicleBookings = vehicleBookingModel::where('id', '=', $request['id'])->delete();
     }
     print json_encode(array(1));
 }
Esempio n. 2
0
 public function bookVehicles(Request $request)
 {
     $user = $request->session()->get('user');
     if (is_null($user)) {
         return redirect()->action('MainController@index');
     } else {
         if ($user[0]->type == 'tenant') {
             // /var_dump($request['date10']);
             // $numDays = $fromDate->diff($toDate)->format("%a");
             // $numhours = $fromDate->diff($toDate)->format("%h");
             //	var_dump($request['vehicleid']);
             if (isset($request['vehicleid']) && !empty($request['vehicleid'])) {
                 $vehicleid = $request['vehicleid'];
             }
             if (isset($request['date10']) && !empty($request['date10'])) {
                 $fromDate = new \DateTime($request['date10']);
             }
             if (isset($request['date11']) && !empty($request['date11'])) {
                 $toDate = new \DateTime($request['date11']);
             }
             if (isset($request['lattitude']) && !empty($request['lattitude'])) {
                 $lattitude = $request['lattitude'];
             }
             if (isset($request['longitude']) && !empty($request['longitude'])) {
                 $longitude = $request['longitude'];
             }
             $CheckvehicleAvail = vehicleBookingModel::where('vehicleid', '=', $vehicleid)->where('todate', '>=', $fromDate)->where('fromdate', '<=', $toDate)->get();
             $checkTravel = DB::table('tbltravel')->join('tblbooking', 'tbltravel.bookingID', '=', 'tblbooking.id')->where('tbltravel.vehicleID', '=', $vehicleid)->where('tblbooking.checkin', '>=', $fromDate)->where('tblbooking.checkOut', '<=', $toDate)->select('tblbooking.*')->get();
             $arrmsg = array();
             if (isset($CheckvehicleAvail) && count($CheckvehicleAvail) > 0 || isset($checkTravel) && count($checkTravel) > 0) {
                 $arrmsg['status'] = -1;
                 $arrmsg['msg'] = "This vehicle is not available for the specified date";
             } else {
                 $vehicle = vehicleModel::where('id', '=', $vehicleid)->get();
                 $numDays = $fromDate->diff($toDate)->format("%r%a");
                 $numHour1 = $numDays * 24;
                 $numhours = $fromDate->diff($toDate)->format("%r%h");
                 $totalHours = $numHour1 + $numhours;
                 if ($totalHours >= 2) {
                     $vehiclePrice = $vehicle[0]->price;
                     $price = $totalHours * $vehiclePrice;
                     $vehicleBooking = new vehicleBookingModel();
                     $vehicleBooking->tenantid = $user[0]->id;
                     $vehicleBooking->vehicleid = $vehicleid;
                     $vehicleBooking->fromdate = $fromDate;
                     $vehicleBooking->todate = $toDate;
                     $vehicleBooking->price = $price;
                     if (!is_null($request['lattitude'])) {
                         $vehicleBooking->pickuplat = $lattitude;
                     }
                     if (!is_null($request['longitude'])) {
                         $vehicleBooking->pickuplong = $longitude;
                     }
                     $vehicleBooking->save();
                     $arrmsg['status'] = 1;
                     $arrmsg['msg'] = "Vehicle booking successful";
                 } else {
                     $arrmsg['status'] = -1;
                     $arrmsg['msg'] = "Minimum Booking timespan is 2 hours";
                 }
             }
             return json_encode($arrmsg);
         } else {
             return response()->view('pages.404', ['user' => $user], 404);
         }
     }
 }