/**
  * This function check the hall availability according to the requested date.
  * This response to  a ajax call from the view.
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 function checkHallAvailability(Request $request)
 {
     //delete the session if already a hall is added for a reservation
     if (Session::has('hall_selected')) {
         $request->session()->forget('hall_selected');
     }
     $inputs = $request->all();
     $event_date = $inputs['event_date'];
     $time_slot = $inputs['timeSlot'];
     $request->session()->put('event_date', $event_date);
     $request->session()->put('timeSlot', $time_slot);
     //define an array to store the availability of the halls
     $hall_status = array();
     $halls = HALL::get();
     $total_halls = 0;
     //for each halls check whether they are already reserved in a reservation
     foreach ($halls as $hall) {
         $row_count = HALL_RESERVATION::where('hall_id', '=', $hall->hall_id)->where('reserve_date', '=', $event_date)->where('time_slot', '=', $time_slot)->count();
         //if the row count is zero means that is not reserved
         if ($row_count == 0) {
             $total_halls += 1;
             $hall_status[$hall->hall_id] = "Available";
         } else {
             $hall_status[$hall->hall_id] = "Not Available";
         }
     }
     return response()->json(['hall_status' => $hall_status, 'hall_ids' => $halls, 'edate' => $event_date, 'timeSlot' => $time_slot, 'total_halls' => $total_halls]);
 }
 /**
  * This function is used to update the reservation upon rejecting the reservation.
  *
  * @param Request $request
  * @return string
  */
 public function updateRejectHallReservation(Request $request)
 {
     $inputs = $request->all();
     $reservation_id = $inputs['hall_reservation_id'];
     $reject_reason = $inputs['reason'];
     HALL_RESERVATION::where('hall_reservation_id', '=', $reservation_id)->update(['status' => 'REJECTED']);
     //calls to a self class function to get the hall reservation details.
     $mail_reservation_details = $this->getHallReservationDetails($reservation_id);
     //calls to a self class function to send an email to customer upon rejection.
     $this->sendRejectHallReservationMail($mail_reservation_details, $reject_reason);
     return "ok";
 }
 /**
  * This function provide the past reservation that are made by the customer.
  * It responds to a ajax call from the view My Reservations
  *
  * @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 = HALL_RESERVATION::where('cus_id', '=', $customer_id)->where('reserve_date', '<', $date)->join('HALLS', 'HALLS.hall_id', '=', 'HALL_RESERVATION.hall_id')->get();
     return response()->json(['res_id' => count($past_reservations), 'data' => $past_reservations]);
 }