/** * This function is used to get the booked roomtype count for a period * * @param $check_in * @param $check_out * @return array */ public function getBookedRoomTypeCount($check_in, $check_out, $reason, $res_id) { $room_types = ROOM_TYPE::get(); //an array to keep the count of rooms per room_type that are booked during the requested period $booked_room_type_count = array(); //initially assign zero to each booked room type count foreach ($room_types as $room_type) { $booked_room_type_count[$room_type->room_type_id] = config('constants.CHK_ZERO'); } if ($reason == "NEW") { //query the reservations that are that have check in or check out dates between the requested date period $reservations = ROOM_RESERVATION::where('check_in', '<=', $check_out)->where('check_out', '>=', $check_in)->orwhereIn('remarks', ['tendative', 'confirmed'])->select('room_reservation_id')->distinct()->get(); } else { $reservations = ROOM_RESERVATION::where('check_in', '<=', $check_out)->where('check_out', '>=', $check_in)->where('room_reservation_id', '!=', $res_id)->orwhereIn('remarks', ['tendative', 'confirmed'])->select('room_reservation_id')->distinct()->get(); } //for each reservation within that period get the room types booked and their total room count foreach ($reservations as $reservation) { foreach ($room_types as $room_type) { $room_type_booked = RES_RMTYPE_CNT_RATE::where('room_reservation_id', '=', $reservation->room_reservation_id)->where('room_type_id', '=', $room_type->room_type_id)->value('count'); //increment the room type count as per the entries in the RES_RMTYPE_CNT_RATE for a reservation $booked_room_type_count[$room_type->room_type_id] += $room_type_booked; } } return $booked_room_type_count; }
/** * This function used to get the reservation,customer and room type details * when a valid reservation id is provided. * * @param $reservation_id * @return array */ public function getReservationDetails($reservation_id) { $reservation_details = ROOM_RESERVATION::where('room_reservation_id', '=', $reservation_id)->first(); $customer_details = Customer::where('cus_id', '=', $reservation_details->cus_id)->first(); $room_types = RES_RMTYPE_CNT_RATE::where('room_reservation_id', '=', $reservation_id)->rightJoin('ROOM_TYPES', 'RES_RMTYPE_CNT_RATE.room_type_id', '=', 'ROOM_TYPES.room_type_id')->select('RES_RMTYPE_CNT_RATE.room_type_id', 'RES_RMTYPE_CNT_RATE.count', 'ROOM_TYPES.type_name')->get(); return ["reservation_details" => $reservation_details, "customer_details" => $customer_details, "room_types" => $room_types]; }