# Advanced Booking Calendar Implementation
## Overview
This implementation provides a comprehensive calendar system for managing three different types of bookings:
1. **Spots** - Beach chairs, tables, umbrellas (hourly/daily bookings)
2. **Rentals** - Rooms, cars, yachts, equipment (flexible duration)
3. **Services** - Spa treatments, activities, guided tours (appointment-based)
## Features Implemented
### 1. Dynamic Venue Selection
- Dropdown selector showing all venues for the current company/workspace
- Displays venue name, location, and booking type
- Automatic resource loading based on selected venue's booking type
### 2. Multi-Type Resource Management
#### Spots Booking
- **Resources**: VenueSpots (beach chairs, tables, etc.)
- **Capacity**: Adults + Children tracking
- **Pricing**: Per day/hour
- **Additional**: Spot objects (umbrellas, loungers) can be attached
#### Rentals Booking
- **Resources**: RentalUnits (rooms, cars, yachts, equipment)
- **Capacity**: People capacity
- **Pricing**: Hourly, Daily, Weekly, Monthly options
- **Additional**: Security deposit, license requirements, maintenance tracking
#### Services Booking
- **Resources**: VenueServiceProviders (therapists, instructors, guides)
- **Services**: Multiple services per provider
- **Scheduling**: Specific appointment times
- **Capacity**: Participant limits per service
### 3. Advanced Filtering System
- Filter by resource (specific spot/rental/provider)
- Filter by status (pending, confirmed, checked_in, etc.)
- Filter by payment status
- Date range filtering
- Customer name search
- Real-time stats update on filter application
### 4. Calendar Views
- **Month View**: Overview of all bookings
- **Week View**: Detailed weekly schedule
- **Day View**: Hour-by-hour breakdown
- Navigation controls (previous/next month, go to today)
### 5. Booking Management
#### Create Booking
- Select resource from available list
- Set check-in/check-out dates and times
- Type-specific fields:
- **Spots**: Adults, Children count
- **Rentals**: Duration type selection
- **Services**: Service selection, participants
- Special requests field
- Status and payment status selection
#### Edit Booking
- Load existing booking data
- Update any booking details
- Maintain booking history
#### Booking Actions
- **Download PDF**: Generate professional booking confirmation
- **Send Email**: Email confirmation with PDF attachment
- **View Details**: Full booking information display
### 6. Statistics Dashboard
- Total bookings for selected period
- Breakdown by status (pending, confirmed, checked_in, completed, cancelled)
- Revenue tracking (paid bookings only)
- Real-time updates based on filters
### 7. Email & PDF Confirmations
#### PDF Features
- Professional layout with venue branding
- Complete booking details
- Customer information
- Pricing breakdown
- QR code support (optional)
- Terms and conditions
#### Email Features
- HTML email template
- Booking summary
- PDF attachment
- Call-to-action buttons
- Contact information
## Files Created/Modified
### New Files
1. `app/Filament/Widgets/BookingCalendarWidget.php` - Main calendar widget
2. `resources/views/filament/widgets/booking-calendar-widget.blade.php` - Widget view
3. `app/Mail/BookingConfirmationMail.php` - Email mailable class
4. `resources/views/emails/booking-confirmation.blade.php` - Email template
5. `resources/views/pdf/booking-confirmation.blade.php` - PDF template
6. `database/migrations/2025_10_13_120000_add_booking_type_to_venues_table.php` - Migration
### Modified Files
1. `app/Filament/Pages/CalendarPage.php` - Updated to use new widget
2. `app/Models/Booking.php` - Added relationships for all booking types
3. `app/Models/Venue.php` - Already had booking_type support
## Database Schema
### Required Tables
- `venues` - Added `booking_type` enum field
- `bookings` - Main booking table
- `booking_venue_spots` - Pivot for spots bookings
- `booking_room` - Pivot for rental bookings
- `booking_venue_service` - Pivot for service bookings
### Migration to Run
```bash
php artisan migrate
```
## Usage Guide
### For Venue Managers
#### Creating a Booking
1. Navigate to **Bookings > Calendar**
2. Select a venue from the dropdown
3. Click on a resource or "New Booking" button
4. Fill in booking details (dates, guests, etc.)
5. Add special requests if needed
6. Set status and payment status
7. Click "Create Booking"
#### Managing Bookings
- Click on any event in the calendar to view/edit
- Use filters to find specific bookings
- Download PDF confirmations for customers
- Send email confirmations directly
#### Viewing Availability
- Resources are color-coded
- Click on a resource to see available time slots
- Calendar shows all bookings for selected venue
### For Developers
#### Extending the Calendar
The widget is designed to be extensible:
```php
// Add custom resource types
protected function loadCustomResources()
{
return CustomResource::where('venue_id', $this->selectedVenue)
->get()
->map(function ($resource) {
return [
'id' => $resource->id,
'title' => $resource->name,
'type' => 'custom',
'capacity' => $resource->capacity,
'color' => $this->randomColor(),
'metadata' => [...],
];
})->toArray();
}
```
#### Customizing PDF Template
Edit `resources/views/pdf/booking-confirmation.blade.php` to match your branding.
#### Customizing Email Template
Edit `resources/views/emails/booking-confirmation.blade.php` for email styling.
## Integration with Web Booking Form
The calendar system integrates with the existing web booking form (`venue.blade.php`):
- Same conditional logic for booking types
- Shared models and relationships
- Consistent pricing calculations
- Unified availability checking
## Advanced Features
### Availability Checking
The system checks resource availability before allowing bookings:
- Prevents double-booking
- Shows available time slots
- Validates capacity limits
### Price Calculation
Automatic price calculation based on:
- Duration (hours/days/weeks/months)
- Resource pricing
- Number of guests/participants
- Additional services/objects
### Notifications
Real-time notifications for:
- Booking creation/updates
- Email sending status
- Validation errors
- Success confirmations
## Future Enhancements
### Planned Features
1. **Drag & Drop**: Move bookings between resources
2. **Recurring Bookings**: Set up repeating reservations
3. **Conflict Resolution**: Smart suggestions for alternative times
4. **Mobile Optimization**: Touch-friendly calendar interface
5. **Payment Integration**: Direct payment processing
6. **SMS Notifications**: Text message confirmations
7. **Calendar Sync**: Export to Google Calendar, iCal
8. **Waitlist Management**: Queue system for fully booked resources
### Integration Points
- **Payment Gateway**: Stripe, PayPal integration ready
- **SMS Service**: Twilio integration prepared
- **Analytics**: Booking patterns and revenue reports
- **CRM**: Customer relationship management
## Troubleshooting
### Common Issues
**Issue**: Resources not loading
- **Solution**: Ensure venue has `booking_type` set correctly
- **Check**: Verify resources exist for the selected venue
**Issue**: PDF not generating
- **Solution**: Install DomPDF: `composer require barryvdh/laravel-dompdf`
- **Check**: Ensure storage directory is writable
**Issue**: Emails not sending
- **Solution**: Configure mail settings in `.env`
- **Check**: Test mail configuration with `php artisan tinker`
**Issue**: Calendar events not showing
- **Solution**: Check date filters and venue selection
- **Check**: Verify bookings exist in database
## Performance Optimization
### Recommended Practices
1. **Eager Loading**: Widget already uses `with()` for relationships
2. **Caching**: Consider caching venue and resource lists
3. **Pagination**: For large datasets, implement pagination
4. **Indexing**: Ensure database indexes on `venue_id`, `check_in`, `check_out`
### Database Indexes
```sql
CREATE INDEX idx_bookings_venue_dates ON bookings(venue_id, check_in, check_out);
CREATE INDEX idx_bookings_status ON bookings(status, payment_status);
```
## Security Considerations
### Implemented
- ✅ User authentication required
- ✅ Company/workspace scoping
- ✅ Input validation
- ✅ SQL injection prevention (Eloquent ORM)
- ✅ CSRF protection (Livewire)
### Recommended
- Add role-based permissions (Filament Shield)
- Implement booking ownership checks
- Add rate limiting for booking creation
- Log all booking modifications
## Support & Documentation
### Related Documentation
- [Filament Widgets](https://filamentphp.com/docs/widgets)
- [Livewire Documentation](https://livewire.laravel.com/docs)
- [Laravel Mail](https://laravel.com/docs/mail)
- [DomPDF](https://github.com/barryvdh/laravel-dompdf)
### Contact
For issues or questions, refer to the main project documentation or contact the development team.
---
**Version**: 1.0.0
**Last Updated**: October 13, 2025
**Author**: Zapazime Development Team