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 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]); }