public function saveReservationDetails($check_in, $check_out, $no_of_nights, $customer_id)
 {
     //predefined check in and check out times
     $arr_dep_time = DB::table('HOTEL_INFO')->select('check_in', 'check_out')->first();
     $check_in_time = $arr_dep_time->check_in;
     $check_out_time = $arr_dep_time->check_out;
     //create a carbon timestamp instance merging the dates and time
     $check_in_datetime = Carbon::createFromTimestamp(strtotime($check_in . $check_in_time));
     $check_out_datetime = Carbon::createFromTimestamp(strtotime($check_out . $check_out_time));
     //creates a instance of the ROOM_RESERVATION model
     $reservation = new ROOM_RESERVATION();
     //store the details
     $reservation->check_in = $check_in_datetime;
     $reservation->check_out = $check_out_datetime;
     $reservation->adults = session('adults');
     $reservation->children = session('kids');
     $reservation->num_of_rooms = session('rooms');
     $reservation->num_of_nights = $no_of_nights;
     $reservation->total_amount = session('total_payable');
     $reservation->cus_id = $customer_id;
     $reservation->status = config('constants.RES_PENDING');
     if (Session::has('promo_code')) {
         $reservation->promo_code = session('promo_code');
     }
     $reservation->save();
     //get the last added reservation id
     $res_id = $reservation->room_reservation_id;
     return $res_id;
 }
 /**
  * checkout reservation information
  * @param Request $request
  */
 public function checkout(Request $request)
 {
     $id = $request->input('id');
     $rsb = ROOM_RESERVATION_BLOCK::where("room_reservation_id", $id);
     foreach ($rsb as $r) {
         $room = ROOM::find($r->room_id);
         $room->status = 'AVAILABLE';
         $room->save();
     }
     $rs = ROOM_RESERVATION::find($id);
     $rs->status = "CHECKED OUT";
     $rs->save();
 }
 /**
  * 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 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";
 }