/** * This function provides the view of the rooms page with details * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function roomsView() { //this calls the clear session function in order to clear the session $this->clearSession(); $room_types = ROOM_TYPE::get(); $total_rooms_have = config('constants.CHK_ZERO'); $total_rooms = HotelInfo::value('selectable_no_of_rooms'); $kids_can = HotelInfo::value('no_of_kids'); $adults_can = HotelInfo::value('no_of_adults'); foreach ($room_types as $room_type) { $total_rooms_have += DB::table('ROOMS')->where('room_type_id', '=', $room_type->room_type_id)->count(); } //check if the room count exceed the available rooms if ($total_rooms > $total_rooms_have) { $total_rooms = $total_rooms_have; } return view('Website.Room_Packages', ["room_types" => $room_types, 'total_rooms' => $total_rooms, 'kids_can' => $kids_can, 'adults_can' => $adults_can]); }
public function getAvailableRoomTypeCount($check_in, $check_out, $reason, $res_id) { //an array to keep the count of rooms per room_type that are booked during the requested period $booked_room_type_count = $this->getBookedRoomTypeCount($check_in, $check_out, $reason, $res_id); //an array to keep the available room count of the room types for the requested period $room_type_available = array(); //to give an error message to the customer if the requested number of rooms are g $total_rooms_available = config('constants.CHK_ZERO'); $room_types = ROOM_TYPE::get(); //room type count will be taken from the rooms table but for now take it from the room_type table foreach ($room_types as $room_type) { $room_type_room_count = DB::table('ROOMS')->where('room_type_id', '=', $room_type->room_type_id)->count(); $available_rooms = $room_type_room_count - $booked_room_type_count[$room_type->room_type_id]; //check whether available rooms are negative if ($available_rooms >= config('constants.CHK_ZERO')) { $room_type_available[$room_type->room_type_id] = $available_rooms; } else { $room_type_available[$room_type->room_type_id] = config('constants.CHK_ZERO'); } $total_rooms_available += $available_rooms; } return ["room_type_available" => $room_type_available, "total_rooms_available" => $total_rooms_available]; }
/** * This function check the room availability for admin part * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function checkRoomAvailability(Request $request) { $input = $request->all(); $reservation_id = $input['reservation_id']; $reservation_details = ROOM_RESERVATION::where('room_reservation_id', '=', $reservation_id)->first(); $check_in = $reservation_details->check_in; $check_out = $reservation_details->check_out; $room_types = ROOM_TYPE::all(); //calls to a function which is in the RoomAvailabilityController which return the room availability details. $room_results = app('App\\Http\\Controllers\\RoomAvailabilityController')->getAvailableRoomTypeCount($check_in, $check_out, "CHK", $reservation_id); $room_type_available = $room_results['room_type_available']; return response()->json(["room_type_available" => $room_type_available, "room_types" => $room_types]); }