예제 #1
0
 public function changeRoom(Request $request, $slotId)
 {
     if ($request->session()->has('currentBookingId')) {
         $bookingId = $request->session()->get('currentBookingId');
         //Found Booking ID and Slot Id Both
         //Now Change the booking
         //Get the old slot Id - Update its status to AV
         //Make the status of new slot id as NA
         //Change the slot in the original booking object
         $booking = Booking::where('id', $bookingId)->first();
         $venueRoomSlot = VenueRoomSlot::where('id', $slotId)->first();
         if ($venueRoomSlot->status == "AV") {
             //Change the booking
             $venueRoomSlot->status = "NA";
             $venueRoomSlot->save();
             //Get the old venue slot id and change its status to av
             $oldVenueRoomSlotId = $booking->venue_room_slot_id;
             $oldVenueRoomSlot = VenueRoomSlot::where('id', $oldVenueRoomSlotId)->first();
             if ($oldVenueRoomSlot->status == "NA") {
                 $oldVenueRoomSlot->status = "AV";
                 $oldVenueRoomSlot->save();
                 $booking->venue_room_slot_id = $slotId;
                 $booking->save();
                 return redirect('securitynewbookings');
             }
         }
         dd("NHP");
     }
 }
 public function bookSlot($slot_id)
 {
     if ($slot_id != null) {
         //1. Get user id
         //2. Get venue_slot_id
         //3. Dump all the details as JSON
         //4. Update the details for the particaular slot
         //Update the particular slot status to NA
         $slot = VenueRoomSlot::where('id', $slot_id)->first();
         //Club is only allowed to do two bookings on a day
         //First check for booking count on that day
         //If count >= 2
         //Do not allow to book them the room
         $bookingDate = $slot->date;
         $userId = Auth::user()->id;
         $venueRoomSlotIds = VenueRoomSlot::where('date', $bookingDate)->lists('id');
         //Get all bookings off this user on the date
         //Which are not disapproved
         //When he is trying to book the room
         $bookings = Booking::where('user_id', $userId)->where('disapproved_by', null)->whereIn('venue_room_slot_id', $venueRoomSlotIds)->get();
         if (count($bookings) >= 2) {
             //Bookings Not Allowed
             return "You can not book any more room on " . $bookingDate;
         } else {
             if ($slot->status == 'AV') {
                 $slot->status = 'NA';
                 $slot->save();
             } else {
                 //Redirect to All Booking Page
                 // return Redirect::to('clubbookings');
                 return "Could not book the room";
             }
             $slotId = $slot_id;
             $postData = Input::all();
             $bookingDetails['applicantName'] = $postData['applicantName'];
             $bookingDetails['applicantRegistrationNumber'] = $postData['applicantRegistrationNumber'];
             $bookingDetails['clubName'] = $postData['clubname'];
             $bookingDetails['contact'] = $postData['contact'];
             $bookingDetails['typeoffunction'] = $postData['typeoffunction'];
             $bookingDetails['purpose'] = $postData['purpose'];
             $bookingDetails['equipments'][] = $postData['equipmentcheckbox'];
             $bookingDetails['informationdesk'] = $postData['informationdesk'];
             $bookingDetails['audiovisual'] = $postData['audiovisual'];
             $bookingDetails['eventname'] = $postData['eventname'];
             $bookingDetails['posters'] = $postData['posters'];
             $bookingDetails['displayboard'] = $postData['displayboard'];
             $bookingDetails['banners'] = $postData['banners'];
             $booking = new Booking();
             $booking->venue_room_slot_id = $slotId;
             $booking->user_id = $userId;
             $booking->details = json_encode($bookingDetails);
             $booking->save();
             //Redirect to All Booking Page
             return Redirect::to('clubbookings');
             //            return "";
         }
     }
 }