예제 #1
0
 public function deleteBooking(Request $request)
 {
     if ($request['id'] != null) {
         $deleteBookings = bookingModel::where('id', '=', $request['id'])->delete();
     }
     print json_encode(array(1));
 }
예제 #2
0
 public function landlordDeleteTenantBooking(Request $request)
 {
     $user = $request->session()->get('user');
     if (is_null($user)) {
         return false;
     } elseif ($user[0]->type == 'Landlord') {
         if ($request['id'] != null) {
             $deleteBookings = bookingModel::where('id', '=', $request['id'])->delete();
             $deletePackageModel = bookingPackageModel::where("booking_id", "=", $request['id'])->delete();
             $travelModel = travelModel::where("bookingID", '=', $request['id'])->delete();
             roomBookingModel::where("bookingId", "=", $request['id'])->delete();
         }
         print json_encode(array(1));
     } else {
         return response()->view('pages.404', ['user' => $user], 404);
     }
 }
예제 #3
0
 public function register(Request $request)
 {
     $error = false;
     $status = array('success' => 0, 'msg' => 'Error occured');
     $user = $request->session()->get('user');
     if (isset($request['package']) && !empty($request['package'])) {
         $packageObj = $request['package'];
         $package = packageModel::find($request['package']);
     } else {
         $error = true;
     }
     if (isset($request['numAdult']) && !empty($request['numAdult'])) {
         $adultsObj = $request['numAdult'];
     } else {
         if ($package->building->category->buildingCatName == 'House' || $package->building->category->buildingCatName == 'Bungalow') {
         } else {
             $error = true;
         }
     }
     if (isset($request['numChild']) && !empty($request['numChild'])) {
         $childrenObj = $request['numChild'];
     }
     if (isset($request['start']) && !empty($request['start'])) {
         $date10Obj = $request['start'];
     } else {
         $error = true;
     }
     if (isset($request['end']) && !empty($request['end'])) {
         $date11Obj = $request['end'];
     } else {
         $error = true;
     }
     $bookings = bookingModel::where('tenantID', "=", $user[0]->ID)->where('checkin', '>=', $date10Obj)->where('checkout', '<=', $date11Obj)->get();
     //Save booking for user
     if (!$error) {
         if (sizeof($bookings) > 0) {
             $status['msg'] = "Booking conflict has been detected for the period " . $date10Obj . " - " . $date11Obj;
         } else {
             $booking = new bookingModel();
             $booking->checkin = $date10Obj;
             $booking->checkOut = $date11Obj;
             $booking->tenantID = $user[0]->ID;
             $booking->packageId = $packageObj;
             //Get package
             $price = 0;
             $buildingtype = $package->building->category;
             if (!is_null($buildingtype->buildingCatName) && ($buildingtype->buildingCatName == 'Hotel' || $buildingtype->buildingCatName == 'Appartment')) {
                 $price = $booking->getPrice($package, $booking);
             } else {
                 if (!is_null($buildingtype->buildingCatName) && ($buildingtype->buildingCatName == 'Bungalow' || $buildingtype->buildingCatName == 'Villa' || $buildingtype->buildingCatName == 'Penthouse' || $buildingtype->buildingCatName == 'House')) {
                     $price = $booking->getPrice($package, $booking);
                 }
             }
             $booking->price = $price;
             $booking->save();
             $status['success'] = 1;
             $status['msg'] = "Booking successfully registered";
         }
     } else {
         $status['msg'] = "Error in field validation";
     }
     return $status;
 }
예제 #4
0
 public function register(Request $request)
 {
     $user = $request->session()->get('user');
     if (is_null($user)) {
         return false;
     }
     $error = false;
     $status = array('success' => 0, 'msg' => 'Error occured');
     $user = $request->session()->get('user');
     $building = buildingModel::where("id", '=', $request['buildingId'])->first();
     $buildingCat = buildingCategory::where('id', '=', $building->buildingCatID)->get();
     if (isset($request['date10']) && !empty($request['date10'])) {
         $date10Obj = $request['date10'];
     } else {
         $error = true;
     }
     if (isset($request['date11']) && !empty($request['date11'])) {
         $date11Obj = $request['date11'];
     } else {
         $error = true;
     }
     if (isset($request['packages']) && !empty($request['packages'])) {
         //$packageObj = $request['package'];
         //$package = packageModel::find ($request['package']);
         if ($buildingCat[0]->buildingCatName == "Hotel" || $buildingCat[0]->buildingCatName == "Appartment") {
             $bookings = bookingModel::where('tenantID', "=", $user[0]->id)->where('checkin', '>=', $date10Obj)->where('checkout', '<=', $date11Obj)->get();
             if (sizeof($bookings) > 0) {
                 $status['msg'] = "Booking conflict has been detected for the period " . $date10Obj . " - " . $date11Obj;
                 return $status;
             } else {
                 //Check if all rooms available in this package
                 $buildingId = $request['buildingId'];
                 $error = false;
                 $roomPackage = array();
                 foreach ($request['packages'] as $packaged) {
                     if (isset($packaged['package'])) {
                         $idpackage = $packaged['package'];
                         $child = $packaged['child'];
                         $adult = $packaged['adult'];
                         $roomsNum = $packaged['room'];
                         $package = packageModel::find($idpackage);
                         //var_dump($packaged->id);
                         $rooms = DB::table('tblroom')->select(DB::raw('*'))->where('buildingid', '=', $buildingId)->where('roomCatID', '=', $package->roomCategoryID)->get();
                         $roomsub = DB::table('tblroombooking')->join('tblroom', 'tblroombooking.roomId', '=', 'tblroom.id')->join('tblbooking', 'tblroombooking.bookingId', '=', 'tblbooking.id')->where('tblroom.roomCatID', '=', $package->roomCategoryID)->where('tblroom.buildingID', '=', $buildingId)->where('tblbooking.checkin', '>=', $date10Obj)->where('tblbooking.checkOut', '<=', $date11Obj)->select('tblroom.*')->get();
                         if (!empty($rooms) && !empty($roomsub)) {
                             $roomsAvailable = array_diff($rooms, $roomsub);
                         } else {
                             if (!empty($rooms)) {
                                 $roomsAvailable = $rooms;
                             } else {
                                 if (!empty($roomsub)) {
                                     $roomsAvailable = array();
                                 } else {
                                     $roomsAvailable = array();
                                 }
                             }
                         }
                         if (isset($roomsNum) && $roomsNum > 0 && $roomsNum <= count($roomsAvailable)) {
                             $roomPackage[$idpackage] = $roomsAvailable;
                             //success
                         } else {
                             if ($roomsNum == 0 && $roomsNum > count($roomsAvailable)) {
                                 $error = true;
                                 $status['msg'] = "No selected room ";
                             } else {
                                 if ($roomsNum > 0 && $roomsNum > count($roomsAvailable)) {
                                     $error = true;
                                     $status['msg'] = "Not enough rooms for the period " . $date10Obj . " - " . $date11Obj . "  for package" . $package->packageName;
                                 } else {
                                     $error = true;
                                     $status['msg'] = "Error ";
                                 }
                             }
                         }
                     }
                 }
                 //iF ALL ROOMS AVAILABLE AND NO ERROR INSERT INTO BOOKING
                 //INSERT INTO ROOMBOOKING
                 if (!$error) {
                     $booking = new bookingModel();
                     $booking->checkin = $date10Obj;
                     $booking->checkOut = $date11Obj;
                     $booking->tenantID = $user[0]->id;
                     $booking->buildingID = $request['buildingId'];
                     $booking->save();
                     $price = 0;
                     foreach ($request['packages'] as $packaged) {
                         if (isset($packaged['package'])) {
                             $idpackage = $packaged['package'];
                             $child = $packaged['child'];
                             $adult = $packaged['adult'];
                             $roomsNum = $packaged['room'];
                             $roomPackage[$idpackage];
                             $package = packageModel::find($idpackage);
                             //insert into booking package
                             $bookingpackage = new bookingPackageModel();
                             $bookingpackage->booking_id = $booking->id;
                             $bookingpackage->package_id = $idpackage;
                             $bookingpackage->save();
                             //insert into roombooking
                             $availablerooms = $roomPackage[$idpackage];
                             for ($i = 0; $i < $roomsNum; $i++) {
                                 $roomBookingModel = new roomBookingModel();
                                 $roomBookingModel->roomId = $availablerooms[$i]->id;
                                 $roomBookingModel->bookingId = $booking->id;
                                 $roomBookingModel->save();
                             }
                             $priceArr = $booking->getPrice($package, $booking);
                             $price += (double) $priceArr['days'] * ($priceArr['child'] * $child + $adult * $priceArr['adult']);
                         }
                     }
                     $booking->price = $price;
                     $booking->save();
                     $status['success'] = 1;
                     $status['msg'] = "Booking successfully registered";
                     if (count($request['block-vehicle']) > 0) {
                         foreach ($request['block-vehicle'] as $blockVehicle) {
                             if (isset($blockVehicle)) {
                                 $vehicle = $blockVehicle['vehicle'];
                                 $travelModel = new travelModel();
                                 $travelModel->bookingID = $booking->id;
                                 $travelModel->vehicleID = $vehicle;
                                 $travelModel->dispach = $blockVehicle['dispatch'];
                                 $travelModel->pickUpTime1 = $booking->checkin;
                                 $travelModel->pickUpLocation1 = $user[0]->Address;
                                 $travelModel->pickUpDestination1 = $booking->building->buildingLocation;
                                 if ($travelModel->dispach == 'true') {
                                     $travelModel->pickUpTime2 = $booking->checkOut;
                                     $travelModel->pickUpLocation2 = $booking->building->buildingLocation;
                                     $travelModel->pickUpDestination2 = $user[0]->Address;
                                 }
                                 $travelModel->save();
                             }
                         }
                     }
                 }
             }
         } else {
             $bookings = bookingModel::where('tenantID', '=', $user[0]->id)->where('checkin', '>=', $date10Obj)->where('checkout', '<=', $date11Obj)->get();
             if (!$error) {
                 if (sizeof($bookings) > 0) {
                     $status['msg'] = "Booking conflict has been detected for the period " . $date10Obj . " - " . $date11Obj;
                 } else {
                     $booking = new bookingModel();
                     $booking->checkin = $date10Obj;
                     $booking->checkOut = $date11Obj;
                     $booking->tenantID = $user[0]->id;
                     $booking->buildingID = $request['buildingId'];
                     $booking->save();
                     $price = 0;
                     foreach ($request['packages'] as $packaged) {
                         if (isset($packaged['package'])) {
                             //Access array packaged key pacakges, ie:number of selected packages
                             $idpackage = $packaged['package'];
                             $child = $packaged['child'];
                             $adult = $packaged['adult'];
                             $package = packageModel::find($idpackage);
                             $price += $booking->getPrice($package, $booking);
                             //Add to booking
                             $bookingpackage = new bookingPackageModel();
                             $bookingpackage->booking_id = $booking->id;
                             $bookingpackage->package_id = $idpackage;
                             $bookingpackage->save();
                         }
                     }
                     //update price in booking
                     $booking->price = $price;
                     $booking->save();
                     $status['success'] = 1;
                     $status['msg'] = "Booking successfully registered";
                     if (!empty($request['block-vehicle'])) {
                         foreach ($request['block-vehicle'] as $blockVehicle) {
                             if (isset($blockVehicle)) {
                                 $vehicle = $blockVehicle['vehicle'];
                                 $travelModel = new travelModel();
                                 $travelModel->bookingID = $booking->id;
                                 $travelModel->vehicleID = $vehicle;
                                 $travelModel->dispach = $blockVehicle['dispatch'];
                                 $travelModel->pickUpTime1 = $booking->checkin;
                                 $travelModel->pickUpLocation1 = $user[0]->Address;
                                 $travelModel->pickUpDestination1 = $booking->building->buildingLocation;
                                 if ($travelModel->dispach == 'true') {
                                     $travelModel->pickUpTime2 = $booking->checkOut;
                                     $travelModel->pickUpLocation2 = $booking->building->buildingLocation;
                                     $travelModel->pickUpDestination2 = $user[0]->Address;
                                 }
                                 $travelModel->save();
                             }
                         }
                     }
                 }
             }
         }
     }
     return $status;
 }
예제 #5
0
 public function delete(Request $request)
 {
     $user = $request->session()->get('user');
     if (is_null($user)) {
         return false;
     }
     if ($request['id'] != null) {
         $buildings = buildingModel::where('id', '=', $request['id'])->delete();
         // delete facilities
         $buildingFacilities = buildingFacilityModel::where("buildingid", "=", $request['id'])->delete();
         //delete room
         //delete room facilities
         //delete room booking
         $rooms = roomModel::where("buildingID", "=", $request['id'])->get();
         foreach ($rooms as $room) {
             roomFacilityModel::where("roomid", "=", $room->id)->delete();
             roomBookingModel::where("roomid", "=", $room->id)->delete();
             $room->delete();
         }
         //delete packages
         $packages = packageModel::where("buildingid", "=", $request['id'])->delete();
         //delete booking
         //delete travel
         $bookings = bookingModel::where("buildingID", "=", $request['id'])->get();
         foreach ($bookings as $booking) {
             bookingPackageModel::where("booking_id", "=", $booking->id)->delete();
             travelModel::where("bookingID", "=", $booking->id)->delete();
             $booking->delete();
         }
     }
     print json_encode(array());
 }
예제 #6
0
 public function deleteBooking(Request $request)
 {
     $user = $request->session()->get('user');
     if (is_null($user)) {
         return false;
     }
     if ($request['id'] != null) {
         $deleteBookings = bookingModel::where('id', '=', $request['id'])->delete();
         $deletePackageModel = bookingPackageModel::where("booking_id", "=", $request['id'])->delete();
         $travelModel = travelModel::where("bookingID", '=', $request['id'])->delete();
         roomBookingModel::where("bookingId", "=", $request['id'])->delete();
         //return redirect()->action('tenantController@myBookings');
     }
     print json_encode(array(1));
 }