Order Lifecycle
Service orders follow a structured workflow with seven distinct statuses:Received
Initial status when order is created
Diagnostic
Equipment is being analyzed
Repairing
Active repair in progress
Quote
Awaiting customer approval
Ready
Repair complete, ready for pickup
Delivered
Returned to customer
Not Repaired
Could not be repaired
Status Transitions
Orders can be updated manually or automatically based on billing events:- Quote document → Sets linked orders to
quotestatus - Invoice document → Sets linked orders to
readystatus
app/Services/BillingService.php:193-214
Creating Service Orders
Basic Order Creation
Orders require a customer, equipment, and optional symptom description:Validation Rules
Fromapp/Http/Requests/StoreOrderRequest.php:16-28:
| Field | Type | Rules |
|---|---|---|
customer_id | integer | Required, must exist |
equipment_id | integer | Required, must exist |
technician | string | Optional, max 255 chars |
technician_user_id | integer | Optional for admin assignment |
symptoms | string | 5-600 chars, required if AI requested |
request_ai_diagnosis | boolean | Triggers AI analysis |
estimated_cost | numeric | Optional, min 0 |
Technician Assignment
- Worker Role
- Admin Role
- Developer Role
When a worker creates an order, they are automatically assigned as the technician:
app/Services/OrderCreationService.php:154-183
AI Diagnostic Integration
Requesting AI Diagnosis
When creating an order withrequest_ai_diagnosis enabled, the system:
- Validates plan eligibility - Only
enterpriseanddeveloper_testplans have access - Checks monthly quotas - Ensures query and token limits aren’t exceeded
- Estimates token usage before sending request
- Analyzes equipment and symptoms via AiDiagnosticService
- Validates actual usage after response
- Stores results in order fields
AI Response Data
Successful diagnostics populate these order fields:One-Time Diagnostic Rule
Each order can only use AI diagnostics once:app/Services/OrderCreationService.php:54-59
Cost Estimation
The AI diagnostic service provides three cost components:Labor Cost
Labor Cost
Base cost for repair work, varies by symptom complexity:
- Power issues: 850.00
- Mechanical issues: 700.00
- Fluid leaks: 600.00
- Default: 450.00
Parts Cost
Parts Cost
Calculated per suggested part:Each identified part adds 320.00 to the estimate.
Total Estimate
Total Estimate
Sum of labor and parts when replacement is required:
app/Services/AiDiagnosticService.php:7-69
Business Rules
Cross-Company Restrictions
Customer and equipment must belong to the same company:Authorization
Non-developer users can only create orders within their own company:Search and Filtering
Orders can be searched by multiple criteria:app/Http/Controllers/Worker/OrderController.php:53-64
Relations
Service orders maintain relationships with:- Company - The business managing the repair
- Customer - Equipment owner
- Equipment - Device being serviced
- Billing Items - Invoice/quote line items
- AI Usages - Diagnostic usage history
app/Models/Order.php:50-73