Venue Objects Booking Fix

📄 General
← Back to Documentation
# Venue Objects Booking Fix ## Problem User was getting "No Items Selected" error even when venue objects were selected with quantity > 0. ## Root Cause The JavaScript validation was only checking for `rooms[` and `services[` input names, but venue objects use `venue_objects[` as the input name prefix. ## Solution Implemented ### 1. Updated JavaScript Validation **File**: `resources/views/web/partials/booking-form-rentals.blade.php` **Before**: ```javascript const hasRooms = Array.from(formData.entries()).some(([key, value]) => key.startsWith('rooms[') && parseInt(value) > 0 ); const hasServices = Array.from(formData.entries()).some(([key, value]) => key.startsWith('services[') && parseInt(value) > 0 ); if (!hasRooms && !hasServices) { // Show error } ``` **After**: ```javascript const hasVenueObjects = Array.from(formData.entries()).some(([key, value]) => key.startsWith('venue_objects[') && parseInt(value) > 0 ); const hasRooms = Array.from(formData.entries()).some(([key, value]) => key.startsWith('rooms[') && parseInt(value) > 0 ); const hasServices = Array.from(formData.entries()).some(([key, value]) => key.startsWith('services[') && parseInt(value) > 0 ); if (!hasVenueObjects && !hasRooms && !hasServices) { // Show error } ``` ### 2. Added Venue Objects Validation Rules **File**: `app/Http/Controllers/BookingController.php` Added to rentals validation rules: ```php 'venue_objects' => 'nullable|array', 'venue_objects.*' => 'nullable|integer|min:0', ``` ### 3. Added Venue Objects Processing **File**: `app/Http/Controllers/BookingController.php` Added processing logic to calculate pricing and save venue objects: ```php // Process venue objects (rental units) if (!empty($validated['venue_objects'])) { foreach ($validated['venue_objects'] as $objectId => $quantity) { if ($quantity > 0) { $venueObject = \App\Models\VenueObject::find($objectId); if ($venueObject) { $nights = $this->calculateNights($validated['check_in'], $validated['check_out']); $pricePerNight = $venueObject->price ?? 0; $objectSubtotal = $pricePerNight * $quantity * $nights; $venueObjectsData[$objectId] = [ 'quantity' => $quantity, 'price_per_night' => $pricePerNight, 'nights' => $nights, 'subtotal' => $objectSubtotal, ]; $subtotal += $objectSubtotal; } } } } ``` ### 4. Added Database Insertion for Venue Objects **File**: `app/Http/Controllers/BookingController.php` Added logic to save venue objects to `booking_venue_object` table: ```php // Attach venue objects to booking if (!empty($venueObjectsData)) { foreach ($venueObjectsData as $objectId => $data) { DB::table('booking_venue_object')->insert([ 'booking_id' => $booking->id, 'venue_object_id' => $objectId, 'count' => $data['quantity'] ?? 1, 'price' => $data['subtotal'] ?? ($data['price_per_night'] * $data['nights']), 'nights' => $data['nights'] ?? 1, 'created_at' => now(), 'updated_at' => now(), ]); } } ``` ## Form Input Names The form uses these input name patterns: - **Venue Objects**: `venue_objects[{id}]` - For rental units (cars, rooms, bungalows, etc.) - **Rooms**: `rooms[{id}]` - For traditional room types (if used) - **Services**: `services[{id}]` - For additional services - **Packages**: `packages[{id}]` - For service packages ## Testing To test the fix: 1. Go to a venue with rental units (venue objects) 2. Select check-in and check-out dates 3. Increase quantity for at least one venue object 4. Click "Proceed to Booking" 5. Form should submit successfully 6. Check browser console for: `🚀 Form submitting...` and `📋 Form Data: {...}` 7. Verify `venue_objects[X]: "1"` appears in the form data 8. Booking should be created and redirect to confirmation page ## Expected Behavior 1. **With venue objects selected**: Form submits, booking created 2. **With rooms selected**: Form submits, booking created 3. **With services selected**: Form submits, booking created 4. **With nothing selected**: Error message shown 5. **Without dates**: Error message shown ## Files Modified 1. `resources/views/web/partials/booking-form-rentals.blade.php` - Updated validation 2. `app/Http/Controllers/BookingController.php` - Added venue_objects support 3. `VENUE_OBJECTS_BOOKING_FIX.md` - This documentation ## Database Schema The `booking_venue_object` table is used for both rooms and venue objects: ```sql CREATE TABLE booking_venue_object ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, booking_id BIGINT UNSIGNED NOT NULL, venue_object_id BIGINT UNSIGNED NOT NULL, count INT NOT NULL DEFAULT 1, price DECIMAL(10,2) NOT NULL, nights INT NOT NULL DEFAULT 1, created_at TIMESTAMP NULL, updated_at TIMESTAMP NULL, FOREIGN KEY (booking_id) REFERENCES bookings(id) ON DELETE CASCADE, FOREIGN KEY (venue_object_id) REFERENCES venue_objects(id) ON DELETE CASCADE ); ``` ## Success Indicators ✅ JavaScript validation passes for venue objects ✅ Backend validation accepts venue_objects array ✅ Venue objects are processed and priced correctly ✅ Venue objects are saved to database ✅ Booking total includes venue object prices ✅ User is redirected to confirmation page ## Troubleshooting If bookings still don't work: 1. Check browser console for form data 2. Check Laravel logs: `tail -f storage/logs/laravel.log` 3. Verify venue objects have prices set 4. Verify dates are selected 5. Verify user is logged in 6. Verify user has a client record