@fleetbase/fleetops-engine 0.3.7 → 0.3.9

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 (113) hide show
  1. package/addon/components/contact-form-panel.hbs +4 -1
  2. package/addon/components/contact-panel.hbs +1 -1
  3. package/addon/components/driver-form-panel.hbs +5 -12
  4. package/addon/components/driver-panel.hbs +4 -1
  5. package/addon/components/fleet-form-panel.hbs +4 -1
  6. package/addon/components/fleet-listing-panel.hbs +2 -2
  7. package/addon/components/fleet-panel.hbs +1 -1
  8. package/addon/components/fuel-report-form-panel.hbs +4 -1
  9. package/addon/components/fuel-report-panel.hbs +4 -1
  10. package/addon/components/issue-form-panel.hbs +4 -1
  11. package/addon/components/issue-panel.hbs +4 -1
  12. package/addon/components/layout/fleet-ops-sidebar/driver-listing.hbs +5 -0
  13. package/addon/components/layout/fleet-ops-sidebar/driver-listing.js +122 -0
  14. package/addon/components/layout/fleet-ops-sidebar/fleet-listing.hbs +5 -1
  15. package/addon/components/layout/fleet-ops-sidebar/fleet-listing.js +118 -1
  16. package/addon/components/layout/fleet-ops-sidebar.hbs +5 -1
  17. package/addon/components/layout/fleet-ops-sidebar.js +4 -2
  18. package/addon/components/live-map.hbs +90 -9
  19. package/addon/components/live-map.js +28 -11
  20. package/addon/components/map-container/toolbar/zones-panel.js +16 -13
  21. package/addon/components/place-form-panel.hbs +4 -1
  22. package/addon/components/place-panel.hbs +4 -1
  23. package/addon/components/settings-window.hbs +1 -1
  24. package/addon/components/vehicle-form-panel.hbs +4 -1
  25. package/addon/components/vehicle-panel.hbs +4 -1
  26. package/addon/components/vendor-form-panel.hbs +4 -1
  27. package/addon/components/vendor-panel.hbs +4 -1
  28. package/addon/controllers/management/drivers/index.js +10 -90
  29. package/addon/controllers/management/vehicles/index.js +11 -21
  30. package/addon/controllers/operations/orders/index/new.js +5 -5
  31. package/addon/controllers/operations/orders/index/view.js +9 -13
  32. package/addon/helpers/format-point.js +5 -2
  33. package/addon/helpers/point-to-coordinates.js +6 -2
  34. package/addon/services/context-panel.js +23 -18
  35. package/addon/services/driver-actions.js +107 -0
  36. package/addon/services/vehicle-actions.js +42 -0
  37. package/addon/styles/fleetops-engine.css +27 -0
  38. package/addon/templates/operations/orders/index/new.hbs +3 -3
  39. package/addon/templates/operations/service-rates/index/new.hbs +1 -1
  40. package/addon/utils/fly-to-leaflet-layer.js +7 -0
  41. package/app/components/layout/fleet-ops-sidebar/driver-listing.js +1 -0
  42. package/app/services/driver-actions.js +1 -0
  43. package/app/services/vehicle-actions.js +1 -0
  44. package/composer.json +2 -2
  45. package/extension.json +1 -1
  46. package/package.json +4 -4
  47. package/server/src/Casts/MultiPolygon.php +14 -3
  48. package/server/src/Casts/Point.php +12 -2
  49. package/server/src/Casts/Polygon.php +19 -4
  50. package/server/src/Exceptions/IntegratedVendorException.php +45 -1
  51. package/server/src/Http/Controllers/Api/v1/DriverController.php +29 -14
  52. package/server/src/Http/Controllers/Api/v1/EntityController.php +36 -1
  53. package/server/src/Http/Controllers/Api/v1/LabelController.php +2 -2
  54. package/server/src/Http/Controllers/Api/v1/OrderController.php +139 -59
  55. package/server/src/Http/Controllers/Api/v1/PayloadController.php +20 -12
  56. package/server/src/Http/Controllers/Api/v1/PlaceController.php +25 -3
  57. package/server/src/Http/Controllers/Api/v1/PurchaseRateController.php +1 -1
  58. package/server/src/Http/Controllers/Api/v1/ServiceAreaController.php +71 -3
  59. package/server/src/Http/Controllers/Api/v1/ServiceQuoteController.php +1 -1
  60. package/server/src/Http/Controllers/Api/v1/ServiceRateController.php +3 -2
  61. package/server/src/Http/Controllers/Api/v1/TrackingNumberController.php +2 -2
  62. package/server/src/Http/Controllers/Api/v1/TrackingStatusController.php +2 -2
  63. package/server/src/Http/Controllers/Api/v1/VehicleController.php +22 -2
  64. package/server/src/Http/Controllers/Api/v1/ZoneController.php +59 -3
  65. package/server/src/Http/Controllers/Internal/v1/DriverController.php +25 -4
  66. package/server/src/Http/Controllers/Internal/v1/LiveController.php +3 -10
  67. package/server/src/Http/Controllers/Internal/v1/NavigatorController.php +1 -1
  68. package/server/src/Http/Controllers/Internal/v1/OrderController.php +11 -1
  69. package/server/src/Http/Filter/TrackingStatusFilter.php +10 -0
  70. package/server/src/Http/Requests/CancelOrderRequest.php +1 -2
  71. package/server/src/Http/Requests/CreateContactRequest.php +5 -4
  72. package/server/src/Http/Requests/CreateDriverRequest.php +13 -11
  73. package/server/src/Http/Requests/CreateEntityRequest.php +7 -4
  74. package/server/src/Http/Requests/CreateOrderRequest.php +2 -2
  75. package/server/src/Http/Requests/CreatePayloadRequest.php +1 -1
  76. package/server/src/Http/Requests/CreatePlaceRequest.php +46 -4
  77. package/server/src/Http/Requests/CreatePurchaseRateRequest.php +3 -2
  78. package/server/src/Http/Requests/CreateServiceAreaRequest.php +24 -4
  79. package/server/src/Http/Requests/CreateServiceRateRequest.php +22 -21
  80. package/server/src/Http/Requests/CreateTrackingStatusRequest.php +9 -8
  81. package/server/src/Http/Requests/CreateVehicleRequest.php +6 -4
  82. package/server/src/Http/Requests/CreateZoneRequest.php +24 -5
  83. package/server/src/Http/Requests/QueryServiceQuotesRequest.php +11 -10
  84. package/server/src/Http/Requests/ScheduleOrderRequest.php +32 -0
  85. package/server/src/Http/Requests/UpdateContactRequest.php +0 -13
  86. package/server/src/Http/Requests/UpdateServiceAreaRequest.php +1 -23
  87. package/server/src/Http/Requests/UpdateServiceQuoteRequest.php +1 -23
  88. package/server/src/Http/Requests/UpdateServiceRateRequest.php +1 -23
  89. package/server/src/Http/Requests/UpdateTrackingStatusRequest.php +1 -26
  90. package/server/src/Http/Resources/v1/DeletedResource.php +2 -9
  91. package/server/src/Http/Resources/v1/Entity.php +47 -44
  92. package/server/src/Http/Resources/v1/Order.php +1 -1
  93. package/server/src/Http/Resources/v1/ServiceArea.php +2 -2
  94. package/server/src/Http/Resources/v1/Vehicle.php +1 -3
  95. package/server/src/Http/Resources/v1/Zone.php +2 -4
  96. package/server/src/Models/Entity.php +99 -3
  97. package/server/src/Models/Order.php +75 -7
  98. package/server/src/Models/Payload.php +104 -33
  99. package/server/src/Models/Place.php +56 -17
  100. package/server/src/Models/ServiceArea.php +285 -18
  101. package/server/src/Models/ServiceRate.php +10 -6
  102. package/server/src/Models/TrackingNumber.php +18 -24
  103. package/server/src/Models/TrackingStatus.php +2 -6
  104. package/server/src/Models/Vehicle.php +2 -2
  105. package/server/src/Models/Waypoint.php +0 -10
  106. package/server/src/Models/Zone.php +132 -5
  107. package/server/src/Support/Flow.php +17 -3
  108. package/server/src/Support/Utils.php +143 -9
  109. package/server/src/routes.php +4 -3
  110. package/addon/helpers/extract-coordinates.js +0 -6
  111. package/addon/utils/extract-coordinates.js +0 -1
  112. package/app/helpers/extract-coordinates.js +0 -1
  113. package/app/utils/extract-coordinates.js +0 -1
@@ -19,36 +19,39 @@ class Entity extends FleetbaseResource
19
19
  public function toArray($request)
20
20
  {
21
21
  return [
22
- 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
23
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
24
- 'photo_uuid' => $this->when(Http::isInternalRequest(), $this->photo_uuid),
25
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
26
- 'customer_uuid' => $this->when(Http::isInternalRequest(), $this->customer_uuid),
27
- 'customer_type' => $this->when(Http::isInternalRequest(), $this->customer_type),
28
- 'supplier_uuid' => $this->when(Http::isInternalRequest(), $this->supplier_uuid),
29
- 'internal_id' => $this->internal_id,
30
- 'name' => $this->name,
31
- 'type' => $this->type ?? null,
32
- 'destination' => $this->when(Http::isPublicRequest(), data_get($this, 'destination.public_id'), null),
33
- 'customer' => $this->setCustomerType(Resolve::resourceForMorph($this->customer_type, $this->customer_uuid)),
34
- 'supplier' => $this->whenLoaded('supplier', $this->supplier),
35
- 'tracking_number' => new TrackingNumber($this->trackingNumber),
36
- 'description' => $this->description ?? null,
37
- 'photo_url' => $this->photo_url ?? null,
38
- 'length' => $this->length ?? null,
39
- 'width' => $this->width ?? null,
40
- 'height' => $this->height ?? null,
41
- 'dimensions_unit' => $this->dimensions_unit ?? null,
42
- 'weight' => $this->weight ?? null,
43
- 'weight_unit' => $this->weight_unit ?? null,
44
- 'declared_value' => $this->declared_value ?? null,
45
- 'price' => $this->price ?? null,
46
- 'sale_price' => $this->sale_price ?? null,
47
- 'sku' => $this->sku ?? null,
48
- 'currency' => $this->currency ?? null,
49
- 'meta' => $this->meta ?? [],
50
- 'updated_at' => $this->updated_at,
51
- 'created_at' => $this->created_at,
22
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
23
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
24
+ 'photo_uuid' => $this->when(Http::isInternalRequest(), $this->photo_uuid),
25
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
26
+ 'customer_uuid' => $this->when(Http::isInternalRequest(), $this->customer_uuid),
27
+ 'customer_type' => $this->when(Http::isInternalRequest(), $this->customer_type),
28
+ 'supplier_uuid' => $this->when(Http::isInternalRequest(), $this->supplier_uuid),
29
+ 'destination_uuid' => $this->when(Http::isInternalRequest(), $this->destination_uuid),
30
+ 'payload_uuid' => $this->when(Http::isInternalRequest(), $this->payload_uuid),
31
+ 'internal_id' => $this->internal_id,
32
+ 'name' => $this->name,
33
+ 'type' => $this->type,
34
+ 'payload' => $this->when(Http::isPublicRequest(), data_get($this, 'payload.public_id'), null),
35
+ 'destination' => $this->when(Http::isPublicRequest(), data_get($this, 'destination.public_id'), null),
36
+ 'customer' => $this->setCustomerType(Resolve::resourceForMorph($this->customer_type, $this->customer_uuid)),
37
+ 'supplier' => $this->whenLoaded('supplier', $this->supplier),
38
+ 'tracking_number' => new TrackingNumber($this->trackingNumber),
39
+ 'description' => data_get($this, 'description'),
40
+ 'photo_url' => data_get($this, 'photo_url'),
41
+ 'length' => data_get($this, 'length'),
42
+ 'width' => data_get($this, 'width'),
43
+ 'height' => data_get($this, 'height'),
44
+ 'dimensions_unit' => data_get($this, 'dimensions_unit'),
45
+ 'weight' => data_get($this, 'weight'),
46
+ 'weight_unit' => data_get($this, 'weight_unit'),
47
+ 'declared_value' => data_get($this, 'declared_value'),
48
+ 'price' => data_get($this, 'price'),
49
+ 'sale_price' => data_get($this, 'sale_price'),
50
+ 'sku' => data_get($this, 'sku'),
51
+ 'currency' => data_get($this, 'currency'),
52
+ 'meta' => data_get($this, 'meta', []),
53
+ 'updated_at' => $this->updated_at,
54
+ 'created_at' => $this->created_at,
52
55
  ];
53
56
  }
54
57
 
@@ -82,23 +85,23 @@ class Entity extends FleetbaseResource
82
85
  'id' => $this->public_id,
83
86
  'internal_id' => $this->internal_id,
84
87
  'name' => $this->name,
85
- 'type' => $this->type ?? null,
88
+ 'type' => data_get($this, 'type'),
86
89
  'destination' => $this->destination ? $this->destination->public_id : null,
87
90
  'customer' => Resolve::resourceForMorph($this->customer_type, $this->customer_uuid),
88
91
  'tracking_number' => new TrackingNumber($this->trackingNumber),
89
- 'description' => $this->description ?? null,
90
- 'photo_url' => $this->photo_url ?? null,
91
- 'length' => $this->length ?? null,
92
- 'width' => $this->width ?? null,
93
- 'height' => $this->height ?? null,
94
- 'dimensions_unit' => $this->dimensions_unit ?? null,
95
- 'weight' => $this->weight ?? null,
96
- 'weight_unit' => $this->weight_unit ?? null,
97
- 'declared_value' => $this->declared_value ?? null,
98
- 'price' => $this->price ?? null,
99
- 'sale_price' => $this->sale_price ?? null,
100
- 'sku' => $this->sku ?? null,
101
- 'currency' => $this->currency ?? null,
92
+ 'description' => data_get($this, 'description'),
93
+ 'photo_url' => data_get($this, 'photo_url'),
94
+ 'length' => data_get($this, 'length'),
95
+ 'width' => data_get($this, 'width'),
96
+ 'height' => data_get($this, 'height'),
97
+ 'dimensions_unit' => data_get($this, 'dimensions_unit'),
98
+ 'weight' => data_get($this, 'weight'),
99
+ 'weight_unit' => data_get($this, 'weight_unit'),
100
+ 'declared_value' => data_get($this, 'declared_value'),
101
+ 'price' => data_get($this, 'price'),
102
+ 'sale_price' => data_get($this, 'sale_price'),
103
+ 'sku' => data_get($this, 'sku'),
104
+ 'currency' => data_get($this, 'currency'),
102
105
  'meta' => $this->meta ?? [],
103
106
  'updated_at' => $this->updated_at,
104
107
  'created_at' => $this->created_at,
@@ -50,7 +50,7 @@ class Order extends FleetbaseResource
50
50
  'pod_method' => $this->pod_method,
51
51
  'pod_required' => (bool) data_get($this, 'pod_required', false),
52
52
  'dispatched' => (bool) data_get($this, 'dispatched', false),
53
- 'adhoc' => $this->adhoc,
53
+ 'adhoc' => (bool) data_get($this, 'adhoc', false),
54
54
  'adhoc_distance' => (int) $this->getAdhocDistance(),
55
55
  'distance' => (int) $this->distance,
56
56
  'time' => (int) $this->time,
@@ -22,7 +22,7 @@ class ServiceArea extends FleetbaseResource
22
22
  'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
23
  'name' => $this->name,
24
24
  'type' => $this->type,
25
- 'location' => $this->location,
25
+ 'center' => $this->location,
26
26
  'border' => $this->border,
27
27
  'zones' => $this->whenLoaded('zones', Zone::collection($this->zones)),
28
28
  'status' => $this->status,
@@ -42,7 +42,7 @@ class ServiceArea extends FleetbaseResource
42
42
  'id' => $this->public_id,
43
43
  'name' => $this->name,
44
44
  'type' => $this->type,
45
- 'location' => $this->location,
45
+ 'center' => $this->location,
46
46
  'border' => $this->border,
47
47
  'status' => $this->status,
48
48
  'updated_at' => $this->updated_at,
@@ -22,7 +22,6 @@ class Vehicle extends FleetbaseResource
22
22
  'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
23
23
  'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
24
24
  'photo_uuid' => $this->when(Http::isInternalRequest(), $this->photo_uuid),
25
- 'internal_id' => $this->internal_id,
26
25
  'name' => $this->display_name,
27
26
  'display_name' => $this->when(Http::isInternalRequest(), $this->display_name),
28
27
  'vin' => $this->vin ?? null,
@@ -59,9 +58,8 @@ class Vehicle extends FleetbaseResource
59
58
  {
60
59
  return [
61
60
  'id' => $this->public_id,
62
- 'internal_id' => $this->internal_id,
63
61
  'name' => $this->name,
64
- 'vin' => $this->vin ?? null,
62
+ 'vin' => $this->vin,
65
63
  'driver' => $this->whenLoaded('driver', new Driver($this->driver)),
66
64
  'photo_url' => $this->photoUrl,
67
65
  'avatar_url' => $this->avatar_url,
@@ -2,10 +2,8 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Http\Resources\v1;
4
4
 
5
- use Fleetbase\FleetOps\Support\Utils;
6
5
  use Fleetbase\Http\Resources\FleetbaseResource;
7
6
  use Fleetbase\Support\Http;
8
- use Grimzy\LaravelMysqlSpatial\Types\Polygon;
9
7
 
10
8
  class Zone extends FleetbaseResource
11
9
  {
@@ -24,7 +22,7 @@ class Zone extends FleetbaseResource
24
22
  'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
25
23
  'name' => $this->name,
26
24
  'description' => $this->description,
27
- 'coordinates' => $this->when($this->border instanceof Polygon, Utils::getCoordinatesFromPolygon($this->border), []),
25
+ 'center' => $this->location,
28
26
  'border' => $this->border,
29
27
  'color' => $this->color,
30
28
  'stroke_color' => $this->stroke_color,
@@ -45,7 +43,7 @@ class Zone extends FleetbaseResource
45
43
  'id' => $this->public_id,
46
44
  'name' => $this->name,
47
45
  'description' => $this->description,
48
- 'coordinates' => data_get($this->border, 'coordinates', []),
46
+ 'center' => $this->location,
49
47
  'border' => $this->border,
50
48
  'color' => $this->color,
51
49
  'stroke_color' => $this->stroke_color,
@@ -197,7 +197,7 @@ class Entity extends Model
197
197
  */
198
198
  public function payload()
199
199
  {
200
- return $this->belongsTo(Payload::class);
200
+ return $this->belongsTo(Payload::class)->without(['entities']);
201
201
  }
202
202
 
203
203
  /**
@@ -273,7 +273,7 @@ class Entity extends Model
273
273
  /**
274
274
  * The length the entity belongs to.
275
275
  *
276
- * @var PhpUnitsOfMeasure\PhysicalQuantity\Length
276
+ * @var \PhpUnitsOfMeasure\PhysicalQuantity\Length
277
277
  */
278
278
  public function getLengthUnitAttribute()
279
279
  {
@@ -283,7 +283,7 @@ class Entity extends Model
283
283
  /**
284
284
  * The width the entity belongs to.
285
285
  *
286
- * @var PhpUnitsOfMeasure\PhysicalQuantity\Length
286
+ * @var \PhpUnitsOfMeasure\PhysicalQuantity\Length
287
287
  */
288
288
  public function getWidthUnitAttribute()
289
289
  {
@@ -350,6 +350,72 @@ class Entity extends Model
350
350
  return data_get($this, 'trackingNumber.last_status');
351
351
  }
352
352
 
353
+ public function setDestination($destinationKey, Payload $payload, bool $save = true): Entity
354
+ {
355
+ // if waypoint index provided
356
+ if (is_numeric($destinationKey)) {
357
+ $waypoint = $payload->waypoints->values()->get($destinationKey);
358
+
359
+ if ($waypoint) {
360
+ $this->destination_uuid = $waypoint->uuid;
361
+ }
362
+ }
363
+
364
+ // if explicitly set to pickup
365
+ if ($destinationKey === 'pickup' && $payload->pickup) {
366
+ $this->destination_uuid = $payload->pickup->uuid;
367
+ }
368
+
369
+ // if explicitly set to dropoff
370
+ if ($destinationKey === 'dropoff' && $payload->dropoff) {
371
+ $this->destination_uuid = $payload->dropoff->uuid;
372
+ }
373
+
374
+ // if waypoint public_id
375
+ if (Utils::isPublicId($destinationKey)) {
376
+ $waypoint = $payload->waypoints->firstWhere('public_id', $destinationKey);
377
+
378
+ // if no waypoint found from public_id check pickup/dropoff
379
+ if (!$waypoint) {
380
+ $waypoint = collect([$this->pickup, $this->dropoff])->firstWhere('public_id', $destinationKey);
381
+ }
382
+
383
+ if ($waypoint) {
384
+ $this->destination_uuid = $waypoint->uuid;
385
+ }
386
+ }
387
+
388
+ // if waypoint uuid
389
+ if (Str::isUuid($destinationKey)) {
390
+ $waypoint = $payload->waypoints->firstWhere('uuid', $destinationKey);
391
+
392
+ // if no waypoint found from uuid check pickup/dropoff
393
+ if (!$waypoint) {
394
+ $waypoint = collect([$payload->pickup, $payload->dropoff])->firstWhere('uuid', $destinationKey);
395
+ }
396
+
397
+ if ($waypoint) {
398
+ $this->destination_uuid = $waypoint->uuid;
399
+ }
400
+ }
401
+
402
+ // confirm destination_uuid is indeed a place record
403
+ if (isset($attributes['destination_uuid']) && Place::where('uuid', $attributes['destination_uuid'])->doesntExist()) {
404
+ // search waypoints for search_uuid if any
405
+ $destination = Place::where('meta->search_uuid', $attributes['destination_uuid'])->first();
406
+
407
+ if ($destination instanceof Place) {
408
+ $this->destination_uuid = $destination->uuid;
409
+ }
410
+ }
411
+
412
+ if ($save) {
413
+ $this->save();
414
+ }
415
+
416
+ return $this;
417
+ }
418
+
353
419
  public static function insertGetUuid($values = [], Payload $payload = null)
354
420
  {
355
421
  if (is_array($values) && isset($values['uuid'])) {
@@ -408,4 +474,34 @@ class Entity extends Model
408
474
  $this->customer_uuid = $model->uuid;
409
475
  $this->customer_type = Utils::getMutationType($model);
410
476
  }
477
+
478
+ public function getPayload(): ?Payload
479
+ {
480
+ $this->load('payload');
481
+
482
+ if ($this->payload instanceof Payload) {
483
+ return $this->payload;
484
+ }
485
+
486
+ if (Str::isUuid($this->payload_uuid)) {
487
+ return Payload::where('uuid', $this->payload_uuid)->first();
488
+ }
489
+
490
+ return null;
491
+ }
492
+
493
+ public function getTrashedPayload(): ?Payload
494
+ {
495
+ $payload = $this->payload()->withoutGlobalScopes()->first();
496
+
497
+ if ($payload instanceof Payload) {
498
+ return $payload;
499
+ }
500
+
501
+ if (Str::isUuid($this->payload_uuid)) {
502
+ return Payload::where('uuid', $this->payload_uuid)->withoutGlobalScopes()->first();
503
+ }
504
+
505
+ return null;
506
+ }
411
507
  }
@@ -604,12 +604,12 @@ class Order extends Model
604
604
 
605
605
  public function getIsAssignedNotDispatchedAttribute(): bool
606
606
  {
607
- return !empty($this->driver_assigned_uuid) && !$this->dispatched_at;
607
+ return !empty($this->driver_assigned_uuid) && $this->dispatched_at === null;
608
608
  }
609
609
 
610
610
  public function getIsNotDispatchedAttribute(): bool
611
611
  {
612
- return !$this->dispatched_at;
612
+ return $this->dispatched_at === null;
613
613
  }
614
614
 
615
615
  public function getIsIntegratedVendorOrderAttribute()
@@ -894,7 +894,7 @@ class Order extends Model
894
894
  return !$this->dispatched && Carbon::fromString($this->scheduled_at)->between($min, $max);
895
895
  }
896
896
 
897
- public function dispatch($save = false)
897
+ public function dispatch($save = true)
898
898
  {
899
899
  $this->dispatched = true;
900
900
  $this->dispatched_at = now();
@@ -907,11 +907,42 @@ class Order extends Model
907
907
  return event(new OrderDispatched($this));
908
908
  }
909
909
 
910
- public function firstDispatch()
910
+ public function insertDispatchActivity(): Order
911
+ {
912
+ // get dispatch activity if any and apply to order
913
+ $dispatchActivity = Flow::getDispatchActivity($this);
914
+
915
+ if ($dispatchActivity) {
916
+ $this->updateActivity($dispatchActivity);
917
+ }
918
+
919
+ return $this;
920
+ }
921
+
922
+ public function dispatchWithActivity(): Order
923
+ {
924
+ $this->dispatch();
925
+ $this->insertDispatchActivity();
926
+
927
+ return $this;
928
+ }
929
+
930
+ public function firstDispatch(): Order
911
931
  {
912
932
  if ($this->dispatched) {
913
933
  $this->dispatch();
914
934
  }
935
+
936
+ return $this;
937
+ }
938
+
939
+ public function firstDispatchWithActivity(): Order
940
+ {
941
+ if ($this->dispatched) {
942
+ $this->dispatchWithActivity();
943
+ }
944
+
945
+ return $this;
915
946
  }
916
947
 
917
948
  public function cancel()
@@ -936,6 +967,22 @@ class Order extends Model
936
967
  }
937
968
  }
938
969
 
970
+ public function updateActivity(array $activity = null, $proof = null): Order
971
+ {
972
+ $status = data_get($activity, 'status');
973
+ $details = data_get($activity, 'details', '');
974
+ $code = data_get($activity, 'code', 'dispatched');
975
+ $location = $this->getLastLocation();
976
+
977
+ // insert dispatch activity
978
+ $this->insertActivity($status, $details, $location, $code, $proof);
979
+
980
+ // update status using code
981
+ $this->setStatus($code, true);
982
+
983
+ return $this;
984
+ }
985
+
939
986
  public function notifyCompleted()
940
987
  {
941
988
  return event(new OrderCompleted($this));
@@ -950,7 +997,13 @@ class Order extends Model
950
997
  public function setCustomerTypeAttribute($type)
951
998
  {
952
999
  if (is_string($type)) {
953
- if ($type === 'customer' || $type === 'vendor' || !Str::startsWith($type, 'fleet-ops')) {
1000
+ $isNotNamespace = !Str::contains($type, '\\');
1001
+ $doesNotStartWithFleetOps = !Str::startsWith($type, 'fleet-ops');
1002
+ $isValidType = $type === 'customer' || $type === 'vendor';
1003
+
1004
+ // preprend fleet-ops IF not a namespace and does not start with fleet-ops
1005
+ // this is for handling ember style registry spacing
1006
+ if ($isNotNamespace && $doesNotStartWithFleetOps && $isValidType) {
954
1007
  $type = 'fleet-ops:' . $type;
955
1008
  }
956
1009
 
@@ -961,7 +1014,13 @@ class Order extends Model
961
1014
  public function setFacilitatorTypeAttribute($type)
962
1015
  {
963
1016
  if (is_string($type)) {
964
- if ($type === 'customer' || $type === 'vendor' || !Str::startsWith($type, 'fleet-ops')) {
1017
+ $isNotNamespace = !Str::contains($type, '\\');
1018
+ $doesNotStartWithFleetOps = !Str::startsWith($type, 'fleet-ops');
1019
+ $isValidType = $type === 'customer' || $type === 'vendor';
1020
+
1021
+ // preprend fleet-ops IF not a namespace and does not start with fleet-ops
1022
+ // this is for handling ember style registry spacing
1023
+ if ($isNotNamespace && $doesNotStartWithFleetOps && $isValidType) {
965
1024
  $type = 'fleet-ops:' . $type;
966
1025
  }
967
1026
 
@@ -1087,7 +1146,16 @@ class Order extends Model
1087
1146
  public function getCurrentOriginPosition()
1088
1147
  {
1089
1148
  if ($this->hasDriverAssigned) {
1090
- return $this->driverAssigned->location;
1149
+ $this->load(['driverAssigned']);
1150
+ $driverAssigned = $this->driverAssigned;
1151
+
1152
+ if (!$driverAssigned) {
1153
+ $driverAssigned = Driver::where('uuid', $this->driver_assigned_uuid)->first();
1154
+ }
1155
+
1156
+ if ($driverAssigned instanceof Driver) {
1157
+ return $driverAssigned->location;
1158
+ }
1091
1159
  }
1092
1160
 
1093
1161
  $origin = null;