public function insertPackage(Request $request) { $user = $request->session()->get('user'); $categories = roomCategory::all(); $buildings = buildingModel::where('landlordID', '=', $user[0]->ID)->get(); return view('pages.insertPackage', array('user' => $user, 'buildings' => $buildings, 'categories' => $categories)); }
public function rentRoomVehicles(Request $request) { $user = $request->session()->get('user'); if (is_null($user)) { return redirect()->action('MainController@index'); } else { if ($user[0]->type == 'tenant') { //Gets building categories $buildingCategories = buildingCategory::all(); // $buildings = buildingModel::where('landlordID', '=', $user[0]->ID)->get(); //return view('pages.landlordAddBuilding', array('categories' => $categories,'user' => $user, 'buildings' => $buildings)); //Gets buildings $buildings = buildingModel::where('created_at', '!=', '')->orderBy('created_at', 'DESC')->get(); $buildingFacAr = array(); foreach ($buildings as $building) { //$buildingFacilities = buildingFacilityModel::where('buildingid', '=', $building->id)->get(); $buildingFacilities = buildingFacilityModel::where('buildingid', '=', $building->id)->get(); array_push($buildingFacAr, $buildingFacilities); } $Facilities = facilityModel::all(); //return view('pages.landlordbuildings', array('user' => $user, 'buildings' => $buildings)); return view('pages.bestDeals', array('user' => $user, 'Facilities' => $Facilities, 'buildings' => $buildings, 'buildingCategories' => $buildingCategories, 'buildingFacilities' => $buildingFacAr)); } else { return response()->view('pages.404', ['user' => $user], 404); } } }
public function viewPackage(Request $request) { $user = $request->session()->get('user'); //Gets buildings $buildings = buildingModel::where('landlordID', '=', $user[0]->ID)->get(); //Gets packages of building $packages = packageModel::where('buildingid', '=', $buildings[0]->id)->get(); //var_dump($packages[0]->id); return view('pages.landlordpackages', array('user' => $user, 'packages' => $packages, 'buildings' => $buildings)); }
public function rentRoomVehicles(Request $request) { $user = $request->session()->get('user'); //Gets building categories // $categories = buildingCategory::all(); // $buildings = buildingModel::where('landlordID', '=', $user[0]->ID)->get(); //return view('pages.landlordAddBuilding', array('categories' => $categories,'user' => $user, 'buildings' => $buildings)); //Gets buildings $buildings = buildingModel::where('created_at', '!=', '')->orderBy('created_at', 'DESC')->get(); //return view('pages.landlordbuildings', array('user' => $user, 'buildings' => $buildings)); return view('pages.bestDeals', array('user' => $user, 'buildings' => $buildings)); }
public function index(Request $request) { $user = $request->session()->get('user'); $blockedUsers = UserLandlord::where('userStatus', '=', 1)->get(); $building = buildingModel::orderBy('created_at', 'DESC')->paginate(3); foreach ($blockedUsers as $blockedUser) { $blocked = $blockedUser['id']; } if (!empty($blocked)) { $buildings = buildingModel::where('landlordID', '=', $blocked)->get(); } else { $buildings = ""; } return view('pages.index', array('user' => $user, 'buildings' => $buildings, 'building' => $building)); }
public function getAdvancedSearch(Request $request) { $error = False; if (isset($request['buildingName'])) { $buildingName = $request['buildingName']; } else { $buildingName = False; $error = True; } if ($error == False) { if (isset($request['buildingLocation'])) { $buildingLocation = $request['buildingLocation']; } else { $buildingLocation = False; } if (isset($request['buildingCat']) && $request['buildingCat'] != -1) { $buildingCat = $request['buildingCat']; } else { $buildingCat = False; } if (isset($request['buildingFacility']) && $request['buildingFacility'] != -1) { $buildingFacility = $request['buildingFacility']; // var_dump($request['buildingFacility']); } else { $buildingFacility = False; } if (isset($request['checkIn']) && $request['checkIn'] != -1) { $checkIn = $request['checkIn']; // var_dump($request['buildingFacility']); } else { $checkIn = False; } if (isset($request['checkOut']) && $request['checkOut'] != -1) { $checkOut = $request['checkOut']; // var_dump($request['buildingFacility']); } else { $checkOut = False; } $buildings = buildingModel::where('buildingName', 'Like', $buildingName . '%')->Where(function ($query) use($buildingLocation, $buildingCat, $buildingFacility) { if ($buildingLocation) { $query->where('buildingLocation', 'like', $buildingLocation . '%'); } if ($buildingCat) { $query->where('buildingCatID', 'like', $buildingCat . '%'); } })->get(); /** $buildingBooked = DB::table('tblbooking') ->join('tblbuilding', 'tblbooking.buildingID', '=', 'tblbuilding.id') ->join('tblbuildingcat', 'tblbuildingcat.id', '=', 'tblbuilding.buildingCatID') ->where('tblbooking.checkin','<=', $checkIn ) ->where('tblbooking.checkOut','>=', $checkOut) ->where('tblbuildingcat.buildingCatName','!=', 'Appartment') ->where('tblbuildingcat.buildingCatName','!=', 'Hotel') ->select('tblbuilding.*') ->get(); $rooms = roomModel::all(); $roomsBooked = DB::table('tblroombooking') ->join('tblbooking', 'tblroombooking.bookingid', '=', 'tblbooking.id') ->join('tblbuilding', 'tblbooking.buildingID', '=', 'tblbuilding.id') ->join('tblbuildingcat', 'tblbuildingcat.id', '=', 'tblbuilding.buildingCatID') ->join('tblroom', 'tblroom.buildingid', '=', 'tblbuilding.id') ->where('tblbooking.checkin','<=', $checkIn ) ->where('tblbooking.checkOut','>=', $checkOut) ->where('tblbuildingcat.buildingCatName','!=', 'Bungalow') ->where('tblbuildingcat.buildingCatName','!=', 'House') ->where('tblbuildingcat.buildingCatName','!=', 'Villa') ->where('tblbuildingcat.buildingCatName','!=', 'Penthouse') ->select('tblroom.*') ->get(); // var_dump($roomsBooked);die; //$vehicleTrav = array_diff($vehicles, $vehicleOccupiedTravel); // var_dump($vehicleOccupiedBooking); //$vehicleBook = array_diff($vehicles, $vehicleOccupiedBooking); $buildings = $this->removeFromArray($buildings, $buildingBooked); $rooms = $this->removeFromArray($rooms, $roomsBooked); //$vehicles = $this->removeFromArray($vehicles, $vehicleOccupiedBooking); //var_dump($buildings); var_dump($building);die; //var_dump($request['buildingCat']); //var_dump($buildings); **/ return json_encode($buildings); } }
private function getQueryVehicles(Request $request) { $initialised = false; $query = ''; //Search by id if ($request['id'] != null) { $query = vehicleModel::where('id', '=', $request['id']); $initialised = true; } //Search by landlord if ($request['vehicleOwnerID'] != null && $initialised) { $query->where('vehicleOwnerID', '=', $request['vehicleOwnerID']); } else { if (!$initialised) { $query = vehicleModel::where('vehicleOwnerID', '=', $request['vehicleOwnerID']); $initialised = true; } } //Search by buildingcategory if ($request['category'] != null && $initialised) { $query->where('category', '=', $request['category']); } else { if (!$initialised) { $query = vehicleModel::where('vehicleCatID', '=', $request['category']); $initialised = true; } } //Search by desc if ($request['name'] != null && $initialised) { $query->where('name', 'LIKE', "%" . $request['name'] . "%"); } else { if (!$initialised) { $query = vehicleModel::where('name', 'LIKE', "%" . $request['name'] . "%"); $initialised = true; } } //Search by buildingcategory if ($request['numOfSeats'] != null && $initialised) { $query->where('numOfSeats', 'LIKE', "%" . $request['numOfSeats'] . "%"); } else { if (!$initialised) { $query = buildingModel::where('numOfSeats', 'LIKE', "%" . $request['numOfSeats'] . "%"); $initialised = true; } } //limit query if ($request['limit'] != null && $query != '') { $query->take($request['limit']); } $vehicles = $query->get(); return $vehicles; }
public function insertPackage(Request $request) { $user = $request->session()->get('user'); if (is_null($user)) { return redirect()->action('MainController@index'); } elseif ($user[0]->type == 'Landlord') { $categories = roomCategory::all(); $buildings = buildingModel::where('landlordID', '=', $user[0]->id)->get(); return view('pages.insertPackage', array('user' => $user, 'buildings' => $buildings, 'categories' => $categories)); } else { return response()->view('pages.404', ['user' => $user], 404); } }
public function getbuildingCat(Request $request) { $error = false; if (isset($request['building'])) { $buildingid = $request['building']; } else { $error = true; $buildingid = false; } $building = buildingModel::where('id', '=', $buildingid)->get(); $buildingCatName = $building[0]->category->buildingCatName; json_encode($buildingCatName); }
public function update(Request $request) { //$categories = buildingCategory::all(); if (isset($request['buildingid']) && !empty($request['buildingid'])) { $buildingid = $request['buildingid']; } if (isset($request['buildingdesc']) && !empty($request['buildingdesc'])) { $buildingdesc = $request['buildingdesc']; } if (isset($request['buildingLocation']) && !empty($request['buildingLocation'])) { $buildingLocation = $request['buildingLocation']; } // Retrieve use session $user = $request->session()->get('user'); //Save building for user $building = buildingModel::find($buildingid); $building->buildingLocation = $buildingLocation; $building->desc = $buildingdesc; $building->save(); Session::flash('success', 'Building successfully updated'); print json_encode(array(1)); }
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; }