/** * 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 provide the details of past reservation of the customer. * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function myPastReservation(Request $request) { $inputs = $request::all(); $customer_id = $inputs['customer_id']; $date = Carbon::now(); $past_reservations = ROOM_RESERVATION::where('cus_id', '=', $customer_id)->where('check_out', '<', $date)->get(); return response()->json(['res_id' => count($past_reservations), 'data' => $past_reservations]); }
/** * This function is to update the reservation upon rejecting the reservation. * * @param Request $request * @return string */ public function updateRejectReservation(Request $request) { $inputs = $request->all(); $reservation_id = $inputs['room_reservation_id']; $reject_reason = $inputs['reason']; ROOM_RESERVATION::where('room_reservation_id', '=', $reservation_id)->update(['status' => 'REJECTED']); //calls to a self class function to the reservation details when providing the reservation id. $mail_reservation_details = $this->getReservationDetails($reservation_id); //send reservation rejection mail to the customer upon rejecting the reservation. $this->sendRejectReservationMail($mail_reservation_details, $reject_reason); return "Success"; }