@fleetbase/fleetops-engine 0.6.16 → 0.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/addon/components/layout/fleet-ops-sidebar.hbs +25 -0
  2. package/addon/templates/virtual.hbs +3 -3
  3. package/composer.json +3 -2
  4. package/extension.json +1 -1
  5. package/package.json +1 -1
  6. package/server/migrations/2025_08_11_170800_add_company_index_to_routes_table.php +21 -0
  7. package/server/migrations/2025_08_28_054920_create_warranties_table.php +56 -0
  8. package/server/migrations/2025_08_28_054921_create_telematics_table.php +60 -0
  9. package/server/migrations/2025_08_28_054922_create_assets_table.php +94 -0
  10. package/server/migrations/2025_08_28_054925_create_devices_table.php +190 -0
  11. package/server/migrations/2025_08_28_054926_create_device_events_table.php +99 -0
  12. package/server/migrations/2025_08_28_054926_create_sensors_table.php +62 -0
  13. package/server/migrations/2025_08_28_054927_create_parts_table.php +73 -0
  14. package/server/migrations/2025_08_28_054929_create_equipments_table.php +58 -0
  15. package/server/migrations/2025_08_28_054930_create_work_orders_table.php +85 -0
  16. package/server/migrations/2025_08_28_054931_create_maintenances_table.php +79 -0
  17. package/server/migrations/2025_08_28_082002_update_vehicles_table_telematics.php +60 -0
  18. package/server/src/Http/Controllers/Api/v1/OrderController.php +19 -1
  19. package/server/src/Http/Controllers/Internal/v1/OrderController.php +31 -8
  20. package/server/src/Http/Resources/v1/Order.php +111 -60
  21. package/server/src/Models/Asset.php +548 -0
  22. package/server/src/Models/Contact.php +2 -0
  23. package/server/src/Models/Device.php +435 -0
  24. package/server/src/Models/DeviceEvent.php +501 -0
  25. package/server/src/Models/Driver.php +2 -0
  26. package/server/src/Models/Entity.php +27 -50
  27. package/server/src/Models/Equipment.php +483 -0
  28. package/server/src/Models/Fleet.php +2 -0
  29. package/server/src/Models/FuelReport.php +2 -0
  30. package/server/src/Models/Issue.php +2 -0
  31. package/server/src/Models/Maintenance.php +549 -0
  32. package/server/src/Models/Order.php +32 -112
  33. package/server/src/Models/OrderConfig.php +8 -0
  34. package/server/src/Models/Part.php +502 -0
  35. package/server/src/Models/Payload.php +101 -20
  36. package/server/src/Models/Place.php +10 -4
  37. package/server/src/Models/Sensor.php +510 -0
  38. package/server/src/Models/ServiceArea.php +1 -1
  39. package/server/src/Models/Telematic.php +336 -0
  40. package/server/src/Models/Vehicle.php +45 -1
  41. package/server/src/Models/VehicleDevice.php +1 -1
  42. package/server/src/Models/Vendor.php +2 -0
  43. package/server/src/Models/Warranty.php +413 -0
  44. package/server/src/Models/Waypoint.php +2 -0
  45. package/server/src/Models/WorkOrder.php +532 -0
  46. package/server/src/Support/Utils.php +5 -0
  47. package/server/src/Traits/HasTrackingNumber.php +64 -10
  48. package/server/src/Traits/Maintainable.php +307 -0
  49. package/server/src/Traits/PayloadAccessors.php +126 -0
@@ -15,68 +15,119 @@ class Order extends FleetbaseResource
15
15
  * Transform the resource into an array.
16
16
  *
17
17
  * @param \Illuminate\Http\Request $request
18
- *
19
- * @return array
20
18
  */
21
- public function toArray($request)
19
+ public function toArray($request): array
22
20
  {
23
- return [
24
- 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
25
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
26
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
27
- 'internal_id' => $this->internal_id,
28
- 'company_uuid' => $this->when(Http::isInternalRequest(), $this->company_uuid),
29
- 'transaction_uuid' => $this->when(Http::isInternalRequest(), $this->transaction_uuid),
30
- 'customer_uuid' => $this->when(Http::isInternalRequest(), $this->customer_uuid),
31
- 'customer_type' => $this->when(Http::isInternalRequest(), $this->customer_type),
32
- 'facilitator_uuid' => $this->when(Http::isInternalRequest(), $this->facilitator_uuid),
33
- 'facilitator_type' => $this->when(Http::isInternalRequest(), $this->facilitator_type),
34
- 'payload_uuid' => $this->when(Http::isInternalRequest(), $this->payload_uuid),
35
- 'route_uuid' => $this->when(Http::isInternalRequest(), $this->route_uuid),
36
- 'purchase_rate_uuid' => $this->when(Http::isInternalRequest(), $this->purchase_rate_uuid),
37
- 'tracking_number_uuid' => $this->when(Http::isInternalRequest(), $this->tracking_number_uuid),
38
- 'driver_assigned_uuid' => $this->when(Http::isInternalRequest(), $this->driver_assigned_uuid),
39
- 'vehicle_assigned_uuid' => $this->when(Http::isInternalRequest(), $this->vehicle_assigned_uuid),
40
- 'service_quote_uuid' => $this->when(Http::isInternalRequest(), $this->service_quote_uuid),
41
- 'has_driver_assigned' => $this->when(Http::isInternalRequest(), $this->has_driver_assigned),
42
- 'is_scheduled' => $this->when(Http::isInternalRequest(), $this->is_scheduled),
43
- 'order_config_uuid' => $this->when(Http::isInternalRequest(), $this->order_config_uuid),
44
- 'order_config' => $this->when(Http::isInternalRequest(), $this->whenLoaded('orderConfig', fn () => $this->orderConfig), data_get($this->orderConfig, 'public_id')),
45
- 'custom_field_values' => $this->when(Http::isInternalRequest(), $this->customFieldValues),
46
- 'customer' => $this->setCustomerType(Resolve::resourceForMorph($this->customer_type, $this->customer_uuid)),
47
- 'payload' => new Payload($this->payload),
48
- 'facilitator' => $this->setFacilitatorType(Resolve::resourceForMorph($this->facilitator_type, $this->facilitator_uuid)),
49
- 'driver_assigned' => new Driver($this->driverAssigned()->without(['jobs', 'currentJob'])->first()),
50
- 'vehicle_assigned' => new Vehicle($this->vehicleAssigned()->without(['fleets', 'vendor'])->first()),
51
- 'tracking_number' => new TrackingNumber($this->trackingNumber),
52
- 'tracking_statuses' => $this->whenLoaded('trackingStatuses', fn () => TrackingStatus::collection($this->trackingStatuses)),
53
- 'tracking' => $this->when(Http::isInternalRequest(), $this->trackingNumber ? $this->trackingNumber->tracking_number : null),
54
- 'barcode' => $this->when(Http::isInternalRequest(), $this->trackingNumber ? $this->trackingNumber->barcode : null),
55
- 'qr_code' => $this->when(Http::isInternalRequest(), $this->trackingNumber ? $this->trackingNumber->qr_code : null),
56
- 'comments' => $this->when(Http::isInternalRequest(), Comment::collection($this->comments)),
57
- 'files' => $this->when(Http::isInternalRequest(), $this->files, File::collection($this->files)),
58
- 'purchase_rate' => new PurchaseRate($this->purchaseRate),
59
- 'notes' => $this->notes,
60
- ...$this->getCustomFieldValues(),
61
- 'custom_fields' => $this->when(Http::isPublicRequest(), fn () => $this->getCustomFieldKeys()),
62
- 'type' => $this->type,
63
- 'status' => $this->status,
64
- 'pod_method' => $this->pod_method,
65
- 'pod_required' => (bool) data_get($this, 'pod_required', false),
66
- 'dispatched' => (bool) data_get($this, 'dispatched', false),
67
- 'adhoc' => (bool) data_get($this, 'adhoc', false),
68
- 'adhoc_distance' => (int) $this->getAdhocDistance(),
69
- 'distance' => (int) $this->distance,
70
- 'time' => (int) $this->time,
71
- 'tracker_data' => $this->when($request->has('with_tracker_data') || !empty($this->resource->tracker_data), fn () => $this->resource->tracker_data ?? $this->resource->tracker()->toArray()),
72
- 'eta' => $this->when($request->has('with_eta') || !empty($this->resource->eta), fn () => $this->resource->eta ?? $this->resource->tracker()->eta()),
73
- 'meta' => data_get($this, 'meta', Utils::createObject()),
74
- 'dispatched_at' => $this->dispatched_at,
75
- 'started_at' => $this->started_at,
76
- 'scheduled_at' => $this->scheduled_at,
77
- 'updated_at' => $this->updated_at,
78
- 'created_at' => $this->created_at,
79
- ];
21
+ $isInternal = Http::isInternalRequest();
22
+ $isPublic = Http::isPublicRequest();
23
+
24
+ // Precompute expensive bits safely
25
+ $orderConfigPublicId = data_get($this->orderConfig, 'public_id');
26
+
27
+ // Driver / vehicle relations (prevent eager noise)
28
+ $driverAssignedModel = $this->driverAssigned()->without(['jobs', 'currentJob'])->first();
29
+ $vehicleAssignedModel = $this->vehicleAssigned()->without(['fleets', 'vendor'])->first();
30
+
31
+ // Tracker helpers (avoid calling ->tracker() twice)
32
+ $withTrackerData = $request->has('with_tracker_data') || !empty($this->resource->tracker_data);
33
+ $withEta = $request->has('with_eta') || !empty($this->resource->eta);
34
+ $tracker = ($withTrackerData || $withEta) ? $this->resource->tracker() : null;
35
+
36
+ return $this->withCustomFields([
37
+ // IDs
38
+ 'id' => $this->when($isInternal, $this->id, $this->public_id),
39
+ 'uuid' => $this->when($isInternal, $this->uuid),
40
+ 'public_id' => $this->when($isInternal, $this->public_id),
41
+ 'internal_id' => $this->internal_id,
42
+
43
+ // FKs (internal only)
44
+ 'company_uuid' => $this->when($isInternal, $this->company_uuid),
45
+ 'transaction_uuid' => $this->when($isInternal, $this->transaction_uuid),
46
+ 'customer_uuid' => $this->when($isInternal, $this->customer_uuid),
47
+ 'customer_type' => $this->when($isInternal, $this->customer_type),
48
+ 'facilitator_uuid' => $this->when($isInternal, $this->facilitator_uuid),
49
+ 'facilitator_type' => $this->when($isInternal, $this->facilitator_type),
50
+ 'payload_uuid' => $this->when($isInternal, $this->payload_uuid),
51
+ 'route_uuid' => $this->when($isInternal, $this->route_uuid),
52
+ 'purchase_rate_uuid' => $this->when($isInternal, $this->purchase_rate_uuid),
53
+ 'tracking_number_uuid' => $this->when($isInternal, $this->tracking_number_uuid),
54
+ 'driver_assigned_uuid' => $this->when($isInternal, $this->driver_assigned_uuid),
55
+ 'vehicle_assigned_uuid'=> $this->when($isInternal, $this->vehicle_assigned_uuid),
56
+ 'service_quote_uuid' => $this->when($isInternal, $this->service_quote_uuid),
57
+ 'has_driver_assigned' => $this->when($isInternal, $this->has_driver_assigned),
58
+ 'is_scheduled' => $this->when($isInternal, $this->is_scheduled),
59
+
60
+ // Order config: internal gets the relation; public gets the public_id (or null)
61
+ 'order_config_uuid' => $this->when($isInternal, $this->order_config_uuid),
62
+ 'order_config' => $this->when(
63
+ $isInternal,
64
+ $this->whenLoaded('orderConfig', function () {
65
+ return $this->orderConfig;
66
+ }),
67
+ $orderConfigPublicId
68
+ ),
69
+
70
+ // Custom field values (internal only) the relation collection is fine for internal,
71
+ // public callers will not see this key at all
72
+ 'custom_field_values' => $this->when($isInternal, $this->customFieldValues),
73
+
74
+ // Morph resources
75
+ 'customer' => $this->setCustomerType(Resolve::resourceForMorph($this->customer_type, $this->customer_uuid)),
76
+ 'payload' => new Payload($this->payload),
77
+ 'facilitator' => $this->setFacilitatorType(Resolve::resourceForMorph($this->facilitator_type, $this->facilitator_uuid)),
78
+
79
+ // Assigned entities
80
+ 'driver_assigned' => new Driver($driverAssignedModel),
81
+ 'vehicle_assigned' => new Vehicle($vehicleAssignedModel),
82
+
83
+ // Tracking
84
+ 'tracking_number' => new TrackingNumber($this->trackingNumber),
85
+ 'tracking_statuses' => $this->whenLoaded('trackingStatuses', function () {
86
+ return TrackingStatus::collection($this->trackingStatuses);
87
+ }),
88
+ 'tracking' => $this->when($isInternal, $this->trackingNumber ? $this->trackingNumber->tracking_number : null),
89
+ 'barcode' => $this->when($isInternal, $this->trackingNumber ? $this->trackingNumber->barcode : null),
90
+ 'qr_code' => $this->when($isInternal, $this->trackingNumber ? $this->trackingNumber->qr_code : null),
91
+
92
+ // Comments & files (internal gets raw; public gets resource collections)
93
+ 'comments' => $this->when($isInternal, Comment::collection($this->comments)),
94
+ 'files' => $this->when($isInternal, $this->files, File::collection($this->files)),
95
+
96
+ // Pricing / notes
97
+ 'purchase_rate' => new PurchaseRate($this->purchaseRate),
98
+ 'notes' => $this->notes,
99
+
100
+ // Expose only keys list publicly
101
+ 'custom_fields' => $this->when($isPublic, function () {
102
+ return $this->getCustomFieldKeys();
103
+ }),
104
+
105
+ // Basic attrs
106
+ 'type' => $this->type,
107
+ 'status' => $this->status,
108
+ 'pod_method' => $this->pod_method,
109
+ 'pod_required' => (bool) data_get($this, 'pod_required', false),
110
+ 'dispatched' => (bool) data_get($this, 'dispatched', false),
111
+ 'adhoc' => (bool) data_get($this, 'adhoc', false),
112
+ 'adhoc_distance' => (int) $this->getAdhocDistance(),
113
+ 'distance' => (int) $this->distance,
114
+ 'time' => (int) $this->time,
115
+
116
+ // Tracker derived data (computed only when requested/present)
117
+ 'tracker_data' => $this->when($withTrackerData, function () use ($tracker) {
118
+ return $this->resource->tracker_data ?? ($tracker ? $tracker->toArray() : null);
119
+ }),
120
+ 'eta' => $this->when($withEta, function () use ($tracker) {
121
+ return $this->resource->eta ?? ($tracker ? $tracker->eta() : null);
122
+ }),
123
+
124
+ 'meta' => data_get($this, 'meta', Utils::createObject()),
125
+ 'dispatched_at' => $this->dispatched_at,
126
+ 'started_at' => $this->started_at,
127
+ 'scheduled_at' => $this->scheduled_at,
128
+ 'updated_at' => $this->updated_at,
129
+ 'created_at' => $this->created_at,
130
+ ]);
80
131
  }
81
132
 
82
133
  /**