|
| 1 | +# Core Scheduling Module |
| 2 | + |
| 3 | +This module provides a polymorphic, reusable scheduling system for the Fleetbase platform. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Polymorphic Architecture**: Schedule any entity type (drivers, vehicles, stores, warehouses, etc.) |
| 8 | +- **Flexible Schedule Items**: Assign items to any assignee with any resource |
| 9 | +- **Availability Management**: Track availability windows for any entity |
| 10 | +- **Constraint System**: Pluggable constraint validation framework |
| 11 | +- **Event-Driven**: Comprehensive event system for extensibility |
| 12 | +- **Activity Logging**: All scheduling activities logged via Spatie Activity Log |
| 13 | + |
| 14 | +## Database Tables |
| 15 | + |
| 16 | +1. **schedules** - Master schedule records |
| 17 | +2. **schedule_items** - Individual scheduled items/slots |
| 18 | +3. **schedule_templates** - Reusable schedule patterns |
| 19 | +4. **schedule_availability** - Availability tracking |
| 20 | +5. **schedule_constraints** - Configurable scheduling rules |
| 21 | + |
| 22 | +## Models |
| 23 | + |
| 24 | +- `Schedule` - Main schedule model with polymorphic subject |
| 25 | +- `ScheduleItem` - Schedule item with polymorphic assignee and resource |
| 26 | +- `ScheduleTemplate` - Reusable template patterns |
| 27 | +- `ScheduleAvailability` - Availability windows |
| 28 | +- `ScheduleConstraint` - Constraint definitions |
| 29 | + |
| 30 | +## Services |
| 31 | + |
| 32 | +- `ScheduleService` - Core scheduling operations |
| 33 | +- `AvailabilityService` - Availability management |
| 34 | +- `ConstraintService` - Pluggable constraint validation |
| 35 | + |
| 36 | +## Events |
| 37 | + |
| 38 | +- `ScheduleCreated` |
| 39 | +- `ScheduleUpdated` |
| 40 | +- `ScheduleDeleted` |
| 41 | +- `ScheduleItemCreated` |
| 42 | +- `ScheduleItemUpdated` |
| 43 | +- `ScheduleItemDeleted` |
| 44 | +- `ScheduleItemAssigned` |
| 45 | +- `ScheduleConstraintViolated` |
| 46 | + |
| 47 | +## API Endpoints |
| 48 | + |
| 49 | +All endpoints are available under `/int/v1/` prefix: |
| 50 | + |
| 51 | +- `/schedules` - Schedule CRUD operations |
| 52 | +- `/schedule-items` - Schedule item CRUD operations |
| 53 | +- `/schedule-templates` - Template CRUD operations |
| 54 | +- `/schedule-availability` - Availability CRUD operations |
| 55 | +- `/schedule-constraints` - Constraint CRUD operations |
| 56 | + |
| 57 | +## Extension Integration |
| 58 | + |
| 59 | +Extensions can integrate with the scheduling module by: |
| 60 | + |
| 61 | +1. **Registering Constraints**: Use `ConstraintService::register()` to add domain-specific constraints |
| 62 | +2. **Listening to Events**: Subscribe to scheduling events to trigger extension-specific workflows |
| 63 | +3. **Using the Meta Field**: Store extension-specific data in the `meta` JSON field |
| 64 | + |
| 65 | +### Example: FleetOps HOS Constraint |
| 66 | + |
| 67 | +```php |
| 68 | +// In FleetOps ServiceProvider |
| 69 | +public function boot() |
| 70 | +{ |
| 71 | + $constraintService = app(\Fleetbase\Services\Scheduling\ConstraintService::class); |
| 72 | + $constraintService->register('driver', \Fleetbase\FleetOps\Constraints\HOSConstraint::class); |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +## Usage Examples |
| 77 | + |
| 78 | +### Creating a Schedule |
| 79 | + |
| 80 | +```php |
| 81 | +$schedule = Schedule::create([ |
| 82 | + 'company_uuid' => $company->uuid, |
| 83 | + 'subject_type' => 'fleet', |
| 84 | + 'subject_uuid' => $fleet->uuid, |
| 85 | + 'name' => 'Weekly Driver Schedule', |
| 86 | + 'start_date' => '2025-11-15', |
| 87 | + 'end_date' => '2025-11-22', |
| 88 | + 'timezone' => 'America/New_York', |
| 89 | + 'status' => 'active', |
| 90 | +]); |
| 91 | +``` |
| 92 | + |
| 93 | +### Creating a Schedule Item |
| 94 | + |
| 95 | +```php |
| 96 | +$item = ScheduleItem::create([ |
| 97 | + 'schedule_uuid' => $schedule->uuid, |
| 98 | + 'assignee_type' => 'driver', |
| 99 | + 'assignee_uuid' => $driver->uuid, |
| 100 | + 'resource_type' => 'vehicle', |
| 101 | + 'resource_uuid' => $vehicle->uuid, |
| 102 | + 'start_at' => '2025-11-15 08:00:00', |
| 103 | + 'end_at' => '2025-11-15 17:00:00', |
| 104 | + 'status' => 'confirmed', |
| 105 | +]); |
| 106 | +``` |
| 107 | + |
| 108 | +### Setting Availability |
| 109 | + |
| 110 | +```php |
| 111 | +$availability = ScheduleAvailability::create([ |
| 112 | + 'subject_type' => 'driver', |
| 113 | + 'subject_uuid' => $driver->uuid, |
| 114 | + 'start_at' => '2025-11-20 00:00:00', |
| 115 | + 'end_at' => '2025-11-22 23:59:59', |
| 116 | + 'is_available' => false, |
| 117 | + 'reason' => 'vacation', |
| 118 | +]); |
| 119 | +``` |
| 120 | + |
| 121 | +## Future Enhancements |
| 122 | + |
| 123 | +- Optimization algorithms for automatic schedule generation |
| 124 | +- RRULE processing for recurring patterns |
| 125 | +- Conflict detection and resolution |
| 126 | +- Capacity planning and load balancing |
| 127 | +- Multi-timezone support improvements |
0 commit comments