@fleetbase/fleetops-engine 0.3.4 → 0.3.6

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 (166) hide show
  1. package/README.md +4 -4
  2. package/addon/components/admin/navigator-app.hbs +5 -0
  3. package/addon/components/admin/navigator-app.js +27 -0
  4. package/addon/components/driver-form-panel.js +13 -19
  5. package/addon/components/fleet-listing-panel.hbs +2 -2
  6. package/addon/components/layout/fleet-ops-sidebar/fleet-listing.hbs +1 -0
  7. package/addon/components/layout/fleet-ops-sidebar/fleet-listing.js +3 -0
  8. package/addon/components/layout/fleet-ops-sidebar.hbs +4 -4
  9. package/addon/components/layout/fleet-ops-sidebar.js +2 -0
  10. package/addon/components/leaflet-draw-control.js +2 -3
  11. package/addon/components/live-map.js +7 -4
  12. package/addon/components/modals/driver-assign-order.hbs +2 -2
  13. package/addon/components/modals/order-import.hbs +5 -5
  14. package/addon/components/modals/order-new-activity.hbs +1 -1
  15. package/addon/components/order-config/entities-editor.js +3 -5
  16. package/addon/components/route-list.hbs +2 -2
  17. package/addon/components/vendor-form-panel.js +1 -1
  18. package/addon/controllers/application.js +2 -2
  19. package/addon/controllers/base-controller.js +31 -0
  20. package/addon/controllers/management/contacts/index/details.js +2 -2
  21. package/addon/controllers/management/contacts/index/edit.js +2 -2
  22. package/addon/controllers/management/contacts/index/new.js +2 -2
  23. package/addon/controllers/management/contacts/index.js +9 -2
  24. package/addon/controllers/management/drivers/index/details.js +2 -2
  25. package/addon/controllers/management/drivers/index/edit.js +28 -2
  26. package/addon/controllers/management/drivers/index/new.js +2 -2
  27. package/addon/controllers/management/drivers/index.js +18 -24
  28. package/addon/controllers/management/fleets/index/details.js +2 -2
  29. package/addon/controllers/management/fleets/index/edit.js +2 -2
  30. package/addon/controllers/management/fleets/index/new.js +2 -2
  31. package/addon/controllers/management/fleets/index.js +16 -9
  32. package/addon/controllers/management/fuel-reports/index/details.js +2 -2
  33. package/addon/controllers/management/fuel-reports/index/edit.js +2 -2
  34. package/addon/controllers/management/fuel-reports/index/new.js +2 -2
  35. package/addon/controllers/management/fuel-reports/index.js +9 -2
  36. package/addon/controllers/management/issues/index/details.js +2 -2
  37. package/addon/controllers/management/issues/index/edit.js +2 -2
  38. package/addon/controllers/management/issues/index/new.js +2 -2
  39. package/addon/controllers/management/issues/index.js +9 -9
  40. package/addon/controllers/management/places/index/details.js +2 -2
  41. package/addon/controllers/management/places/index/edit.js +2 -2
  42. package/addon/controllers/management/places/index/new.js +2 -2
  43. package/addon/controllers/management/places/index.js +8 -2
  44. package/addon/controllers/management/vehicles/index/details.js +2 -2
  45. package/addon/controllers/management/vehicles/index/edit.js +2 -2
  46. package/addon/controllers/management/vehicles/index/new.js +2 -2
  47. package/addon/controllers/management/vehicles/index.js +24 -32
  48. package/addon/controllers/management/vendors/index/details.js +2 -2
  49. package/addon/controllers/management/vendors/index/edit.js +2 -2
  50. package/addon/controllers/management/vendors/index/new.js +2 -2
  51. package/addon/controllers/management/vendors/index.js +9 -8
  52. package/addon/controllers/management.js +2 -2
  53. package/addon/controllers/operations/orders/index/config/types.js +2 -2
  54. package/addon/controllers/operations/orders/index/config.js +2 -2
  55. package/addon/controllers/operations/orders/index/new.js +64 -44
  56. package/addon/controllers/operations/orders/index/view.js +11 -4
  57. package/addon/controllers/operations/orders/index.js +2 -2
  58. package/addon/controllers/operations/scheduler/index.js +2 -2
  59. package/addon/controllers/operations/service-rates/index/edit.js +12 -18
  60. package/addon/controllers/operations/service-rates/index/new.js +16 -22
  61. package/addon/controllers/operations/service-rates/index.js +9 -2
  62. package/addon/engine.js +6 -0
  63. package/addon/helpers/waypoint-label.js +6 -1
  64. package/addon/routes/application.js +4 -15
  65. package/addon/routes/management/contacts/index.js +9 -5
  66. package/addon/routes/management/drivers/index.js +7 -3
  67. package/addon/routes/management/fleets/index.js +9 -5
  68. package/addon/routes/management/fuel-reports/index.js +9 -5
  69. package/addon/routes/management/issues/index.js +9 -5
  70. package/addon/routes/management/places/index.js +9 -5
  71. package/addon/routes/management/vehicles/index/details.js +2 -2
  72. package/addon/routes/management/vehicles/index.js +11 -2
  73. package/addon/routes/management/vendors/index.js +9 -6
  74. package/addon/routes/operations/orders/index/view.js +6 -2
  75. package/addon/routes/operations/orders/index.js +7 -1
  76. package/addon/routes/operations/orders.js +0 -1
  77. package/addon/routes/operations/service-rates/index.js +9 -27
  78. package/addon/routes/operations/service-rates.js +1 -8
  79. package/addon/styles/fleetops-engine.css +14 -7
  80. package/addon/templates/management/contacts/index.hbs +1 -0
  81. package/addon/templates/management/drivers/index.hbs +2 -1
  82. package/addon/templates/management/fleets/index.hbs +23 -3
  83. package/addon/templates/management/fuel-reports/index.hbs +1 -0
  84. package/addon/templates/management/issues/index.hbs +22 -2
  85. package/addon/templates/management/places/index.hbs +9 -1
  86. package/addon/templates/management/vehicles/index.hbs +22 -2
  87. package/addon/templates/management/vendors/index.hbs +22 -2
  88. package/addon/templates/operations/orders/index/new.hbs +7 -7
  89. package/addon/templates/operations/orders/index/view.hbs +17 -16
  90. package/addon/templates/operations/service-rates/index.hbs +11 -3
  91. package/addon/utils/waypoint-label.js +3 -0
  92. package/app/components/layout/fleet-ops-sidebar/fleet-listing.js +1 -0
  93. package/app/controllers/{operations/zones/index.js → base-controller.js} +1 -1
  94. package/app/utils/waypoint-label.js +1 -0
  95. package/composer.json +1 -1
  96. package/config/environment.js +11 -1
  97. package/extension.json +1 -1
  98. package/index.js +1 -0
  99. package/package.json +47 -41
  100. package/server/migrations/2023_04_27_053456_create_contacts_table.php +2 -2
  101. package/server/migrations/2023_04_27_053456_create_drivers_table.php +5 -5
  102. package/server/migrations/2023_04_27_053456_create_entities_table.php +5 -5
  103. package/server/migrations/2023_04_27_053456_create_fleet_drivers_table.php +2 -2
  104. package/server/migrations/2023_04_27_053456_create_fleets_table.php +3 -3
  105. package/server/migrations/2023_04_27_053456_create_fuel_reports_table.php +3 -3
  106. package/server/migrations/2023_04_27_053456_create_issues_table.php +4 -4
  107. package/server/migrations/2023_04_27_053456_create_orders_table.php +8 -8
  108. package/server/migrations/2023_04_27_053456_create_payloads_table.php +5 -5
  109. package/server/migrations/2023_04_27_053456_create_places_table.php +1 -1
  110. package/server/migrations/2023_04_27_053456_create_purchase_rates_table.php +4 -4
  111. package/server/migrations/2023_04_27_053456_create_service_areas_table.php +2 -2
  112. package/server/migrations/2023_04_27_053456_create_service_quote_items_table.php +1 -1
  113. package/server/migrations/2023_04_27_053456_create_service_quotes_table.php +3 -3
  114. package/server/migrations/2023_04_27_053456_create_service_rate_fees_table.php +1 -1
  115. package/server/migrations/2023_04_27_053456_create_service_rate_parcel_fees_table.php +1 -1
  116. package/server/migrations/2023_04_27_053456_create_service_rates_table.php +3 -3
  117. package/server/migrations/2023_04_27_053456_create_tracking_numbers_table.php +3 -3
  118. package/server/migrations/2023_04_27_053456_create_tracking_statuses_table.php +2 -2
  119. package/server/migrations/2023_04_27_053456_create_vehicles_table.php +3 -3
  120. package/server/migrations/2023_04_27_053456_create_vendors_table.php +5 -5
  121. package/server/migrations/2023_04_27_053456_create_waypoints_table.php +4 -4
  122. package/server/migrations/2023_04_27_053456_create_zones_table.php +2 -2
  123. package/server/migrations/2023_11_17_053001_add_category_uuid_to_entities_table.php +33 -0
  124. package/server/migrations/2023_11_28_074244_add_supplier_uuid_column_to_entities_table.php +33 -0
  125. package/server/migrations/2023_12_14_100209_add_meta_column_on_driver_table.php +30 -0
  126. package/server/src/Http/Controllers/Api/v1/DriverController.php +7 -4
  127. package/server/src/Http/Controllers/Api/v1/EntityController.php +2 -0
  128. package/server/src/Http/Controllers/Api/v1/OrderController.php +118 -42
  129. package/server/src/Http/Controllers/Api/v1/PayloadController.php +41 -43
  130. package/server/src/Http/Controllers/Api/v1/TrackingStatusController.php +43 -2
  131. package/server/src/Http/Controllers/Internal/v1/DriverController.php +0 -1
  132. package/server/src/Http/Controllers/Internal/v1/MorphController.php +48 -16
  133. package/server/src/Http/Controllers/Internal/v1/NavigatorController.php +41 -0
  134. package/server/src/Http/Controllers/Internal/v1/OrderController.php +3 -2
  135. package/server/src/Http/Controllers/Internal/v1/PlaceController.php +2 -2
  136. package/server/src/Http/Requests/CreateDriverRequest.php +2 -0
  137. package/server/src/Http/Requests/CreateOrderRequest.php +18 -4
  138. package/server/src/Http/Requests/CreatePayloadRequest.php +23 -7
  139. package/server/src/Http/Requests/CreatePlaceRequest.php +9 -5
  140. package/server/src/Http/Requests/CreateTrackingStatusRequest.php +69 -12
  141. package/server/src/Http/Requests/CreateVehicleRequest.php +5 -3
  142. package/server/src/Http/Resources/v1/Entity.php +3 -0
  143. package/server/src/Http/Resources/v1/Fleet.php +19 -17
  144. package/server/src/Http/Resources/v1/Order.php +3 -2
  145. package/server/src/Models/Driver.php +21 -2
  146. package/server/src/Models/Entity.php +18 -23
  147. package/server/src/Models/Order.php +2 -2
  148. package/server/src/Models/Payload.php +27 -9
  149. package/server/src/Models/Place.php +28 -5
  150. package/server/src/Models/TrackingStatus.php +9 -3
  151. package/server/src/Models/Vehicle.php +4 -2
  152. package/server/src/Models/VehicleDevice.php +28 -0
  153. package/server/src/Models/VehicleDeviceEvent.php +1 -1
  154. package/server/src/Models/Vendor.php +16 -0
  155. package/server/src/Observers/DriverObserver.php +1 -1
  156. package/server/src/routes.php +8 -0
  157. package/tsconfig.declarations.json +10 -0
  158. package/addon/components/file-icon.js +0 -1
  159. package/addon/controllers/operations/zones/index.js +0 -475
  160. package/addon/routes/operations/dispatch.js +0 -3
  161. package/addon/routes/operations/zones/index.js +0 -25
  162. package/addon/routes/operations/zones.js +0 -7
  163. package/addon/templates/operations/dispatch.hbs +0 -1
  164. package/addon/templates/operations/zones/index.hbs +0 -72
  165. package/addon/templates/operations/zones.hbs +0 -1
  166. package/app/components/file-icon.js +0 -1
@@ -0,0 +1,41 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\FleetOps\Http\Controllers\Internal\v1;
4
+
5
+ use Fleetbase\Http\Controllers\Controller;
6
+ use Fleetbase\Models\ApiCredential;
7
+ use Fleetbase\Models\User;
8
+
9
+ class NavigatorController extends Controller
10
+ {
11
+ public function linkApp()
12
+ {
13
+ $adminUser = User::where('type', 'admin')->first();
14
+
15
+ if ($adminUser->company) {
16
+ $apiCredential = ApiCredential::firstOrCreate(
17
+ [
18
+ 'user_uuid' => $adminUser->uuid,
19
+ 'company_uuid' => $adminUser->company_uuid,
20
+ 'name' => 'NavigationAppLinker',
21
+ ],
22
+ [
23
+ 'user_uuid' => $adminUser->uuid,
24
+ 'company_uuid' => $adminUser->company->uuid,
25
+ 'name' => 'NavigationAppLinker',
26
+ ]
27
+ );
28
+
29
+ return redirect()->away('flbnavigator://configure?key=' . $apiCredential->key . '&host=' . url()->secure('/'));
30
+ }
31
+
32
+ return response()->error('Organization for linking not found.');
33
+ }
34
+
35
+ public function getLinkAppUrl()
36
+ {
37
+ return response()->json([
38
+ 'linkUrl' => url('int/v1/fleet-ops/navigator/link-app'),
39
+ ]);
40
+ }
41
+ }
@@ -129,6 +129,7 @@ class OrderController extends FleetOpsController
129
129
  public function importFromFiles(Request $request)
130
130
  {
131
131
  $info = Utils::lookupIp();
132
+ $disk = $request->input('disk', config('filesystems.default'));
132
133
  $files = $request->input('files');
133
134
  $files = File::whereIn('uuid', $files)->get();
134
135
  $country = $request->input('country', Utils::or($info, ['country_name', 'region'], 'Singapore'));
@@ -143,7 +144,7 @@ class OrderController extends FleetOpsController
143
144
  }
144
145
 
145
146
  try {
146
- $data = Excel::toArray(new OrdersImport(), $file->path, 's3');
147
+ $data = Excel::toArray(new OrdersImport(), $file->path, $disk);
147
148
  } catch (\Exception $e) {
148
149
  return response()->error('Invalid file, unable to proccess.');
149
150
  }
@@ -177,7 +178,7 @@ class OrderController extends FleetOpsController
177
178
  $entity = new Entity(['name' => $itemName]);
178
179
  $entity->setAttribute('destination_uuid', $place->uuid);
179
180
  $entity->setAttribute('_import_id', $importId);
180
- $entity->setMetas($place->getMeta());
181
+ $entity->setMeta($place->getMeta());
181
182
  $entities[] = $entity;
182
183
  }
183
184
  }
@@ -76,7 +76,7 @@ class PlaceController extends FleetOpsController
76
76
  }
77
77
  }
78
78
 
79
- return response()->json($results);
79
+ return response()->json($results)->withHeaders(['Cache-Control' => 'no-cache']);
80
80
  }
81
81
 
82
82
  /**
@@ -113,7 +113,7 @@ class PlaceController extends FleetOpsController
113
113
  }
114
114
  }
115
115
 
116
- return response()->json($results);
116
+ return response()->json($results)->withHeaders(['Cache-Control' => 'no-cache']);
117
117
  }
118
118
 
119
119
  /**
@@ -2,6 +2,7 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Http\Requests;
4
4
 
5
+ use Fleetbase\FleetOps\Rules\ResolvablePoint;
5
6
  use Fleetbase\Http\Requests\FleetbaseRequest;
6
7
  use Illuminate\Validation\Rule;
7
8
 
@@ -37,6 +38,7 @@ class CreateDriverRequest extends FleetbaseRequest
37
38
  'status' => 'nullable|string|in:active,inactive',
38
39
  'vendor' => 'nullable|exists:vendors,public_id',
39
40
  'job' => 'nullable|exists:orders,public_id',
41
+ 'location' => ['nullable', new ResolvablePoint()],
40
42
  ];
41
43
  }
42
44
 
@@ -46,8 +46,16 @@ class CreateOrderRequest extends FleetbaseRequest
46
46
 
47
47
  if ($this->isArray('payload')) {
48
48
  $validations['payload'] = 'required';
49
- $validations['payload.pickup'] = 'required';
50
- $validations['payload.dropoff'] = 'required';
49
+
50
+ if ($this->missing('payload.waypoints')) {
51
+ $validations['payload.pickup'] = 'required';
52
+ $validations['payload.dropoff'] = 'required';
53
+ }
54
+
55
+ if ($this->missing(['payload.pickup', 'payload.dropoff'])) {
56
+ $validations['payload.waypoints'] = 'required|array|min:2';
57
+ }
58
+
51
59
  $validations['payload.return'] = 'nullable';
52
60
  }
53
61
 
@@ -57,8 +65,14 @@ class CreateOrderRequest extends FleetbaseRequest
57
65
  }
58
66
 
59
67
  if ($this->missing('payload') && $this->isMethod('POST')) {
60
- $validations['pickup'] = 'required';
61
- $validations['dropoff'] = 'required';
68
+ if ($this->missing('waypoints')) {
69
+ $validations['pickup'] = 'required';
70
+ $validations['dropoff'] = 'required';
71
+ }
72
+
73
+ if ($this->missing(['pickup', 'dropoff'])) {
74
+ $validations['waypoints'] = 'required|array|min:2';
75
+ }
62
76
  }
63
77
 
64
78
  return $validations;
@@ -25,13 +25,29 @@ class CreatePayloadRequest extends FleetbaseRequest
25
25
  public function rules()
26
26
  {
27
27
  return [
28
- 'pickup' => 'required',
29
- 'dropoff' => 'required',
30
- 'return' => 'nullable',
31
- 'waypoints' => 'nullable|array',
32
- 'type' => 'required',
33
- 'cod_currency' => [Rule::requiredIf($this->has(['cod_amount'])), 'size:3'],
34
- 'cod_payment_method' => [Rule::requiredIf($this->has(['cod_amount'])), 'in:card,check,cash,bank_transfer'],
28
+ 'entities' => 'array',
29
+ 'waypoints' => 'array',
30
+ 'return' => 'nullable',
31
+ 'type' => 'required',
32
+ 'cod_currency' => [Rule::requiredIf($this->has(['cod_amount'])), 'size:3'],
33
+ 'cod_payment_method' => [Rule::requiredIf($this->has(['cod_amount'])), 'in:card,check,cash,bank_transfer'],
35
34
  ];
35
+
36
+ if ($this->missing('waypoints')) {
37
+ $validations['pickup'] = 'required';
38
+ $validations['dropoff'] = 'required';
39
+ }
40
+
41
+ if ($this->isString('pickup')) {
42
+ $validations['pickup'] = 'required|exists:places,public_id';
43
+ }
44
+
45
+ if ($this->isString('dropoff')) {
46
+ $validations['dropoff'] = 'required|exists:places,public_id';
47
+ }
48
+
49
+ if ($this->missing(['pickup', 'dropoff'])) {
50
+ $validations['waypoints'] = 'required|array|min:2';
51
+ }
36
52
  }
37
53
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Http\Requests;
4
4
 
5
+ use Fleetbase\FleetOps\Rules\ResolvablePoint;
5
6
  use Fleetbase\Http\Requests\FleetbaseRequest;
6
7
  use Fleetbase\Rules\ExistsInAny;
7
8
  use Illuminate\Validation\Rule;
@@ -28,11 +29,14 @@ class CreatePlaceRequest extends FleetbaseRequest
28
29
  public function rules()
29
30
  {
30
31
  return [
31
- 'name' => [Rule::requiredIf($this->isMethod('POST'))],
32
- 'street1' => [Rule::requiredIf($this->isMethod('POST'))],
33
- 'customer' => ['nullable', new ExistsInAny(['vendors', 'contacts'], 'public_id')],
34
- 'contact' => ['nullable', new ExistsInAny(['vendors', 'contacts'], 'public_id')],
35
- 'vendor' => 'nullable|exists:vendors,public_id',
32
+ 'name' => [Rule::requiredIf($this->isMethod('POST'))],
33
+ 'street1' => [Rule::requiredIf($this->isMethod('POST'))],
34
+ 'customer' => ['nullable', new ExistsInAny(['vendors', 'contacts'], 'public_id')],
35
+ 'contact' => ['nullable', new ExistsInAny(['vendors', 'contacts'], 'public_id')],
36
+ 'vendor' => 'nullable|exists:vendors,public_id',
37
+ 'location' => ['nullable', new ResolvablePoint()],
38
+ 'latitude' => 'nullable',
39
+ 'longitude' => 'nullable',
36
40
  ];
37
41
  }
38
42
  }
@@ -2,7 +2,11 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Http\Requests;
4
4
 
5
+ use Fleetbase\FleetOps\Models\Order;
6
+ use Fleetbase\FleetOps\Models\TrackingNumber;
7
+ use Fleetbase\FleetOps\Rules\ResolvablePoint;
5
8
  use Fleetbase\Http\Requests\FleetbaseRequest;
9
+ use Illuminate\Support\Str;
6
10
  use Illuminate\Validation\Rule;
7
11
 
8
12
  class CreateTrackingStatusRequest extends FleetbaseRequest
@@ -24,19 +28,72 @@ class CreateTrackingStatusRequest extends FleetbaseRequest
24
28
  */
25
29
  public function rules()
26
30
  {
27
- return [
28
- 'tracking_number' => [
31
+ $validations = [
32
+ 'tracking_number' => array_filter([
29
33
  'required',
30
- Rule::exists('tracking_numbers')->where(function ($query) {
31
- $query->where('public_id', $this->input('tracking_number'));
32
- $query->whereDoesntHave('status', function ($q) {
33
- $q->where('code', $this->input('code'));
34
- });
35
- }),
36
- ],
37
- 'status' => 'required|string',
38
- 'details' => 'required|string',
39
- 'code' => 'required|string',
34
+ $this->isMethod('POST') ? Rule::exists('tracking_numbers', 'public_id') : null,
35
+ $this->isMethod('POST') ? static::uniqueStatus($this) : null,
36
+ ]),
37
+ 'location' => [new ResolvablePoint()],
38
+ 'code' => 'nullable|string|min:3',
39
+ 'status' => ['required', 'string', 'min:3'],
40
+ 'details' => 'nullable|string',
40
41
  ];
42
+
43
+ if ($this->isMethod('POST') && $this->missing('tracking_number') && $this->has('order')) {
44
+ $validations['tracking_number'] = 'nullable';
45
+ $validations['order'] = [
46
+ 'required',
47
+ Rule::exists('orders', 'public_id'),
48
+ static::uniqueStatus($this),
49
+ ];
50
+ }
51
+
52
+ if ($this->missing(['latitude', 'longitude'])) {
53
+ $validations['location'] = ['required', new ResolvablePoint()];
54
+ } elseif ($this->missing('location')) {
55
+ $validations['latitude'] = 'required';
56
+ $validations['longitude'] = 'required';
57
+ }
58
+
59
+ return $validations;
60
+ }
61
+
62
+ /**
63
+ * Custom rule to ensure status is unique for an order or tracking number.
64
+ *
65
+ * @return \Closure
66
+ */
67
+ private static function uniqueStatus($request)
68
+ {
69
+ return function ($attribute, $value, $fail) use ($request) {
70
+ $trackingNumber = $request->input('tracking_number');
71
+ $orderId = $request->input('order');
72
+ $status = $request->input('status');
73
+ $exists = false;
74
+
75
+ // if duplicate status enabled skip
76
+ if ($request->boolean('duplicate')) {
77
+ return;
78
+ }
79
+
80
+ if ($trackingNumber) {
81
+ $exists = TrackingNumber::where('public_id', $trackingNumber)->whereHas('statuses', function ($query) use ($status) {
82
+ $query->where('status', $status);
83
+ $query->orWhere('status', Str::title($status));
84
+ })->exists();
85
+ } elseif ($orderId) {
86
+ $exists = Order::where('public_id', $orderId)->whereHas('trackingNumber', function ($query) use ($status) {
87
+ $query->whereHas('statuses', function ($query) use ($status) {
88
+ $query->where('status', $status);
89
+ $query->orWhere('status', Str::title($status));
90
+ });
91
+ })->exists();
92
+ }
93
+
94
+ if ($exists) {
95
+ $fail('The status "' . Str::title($status) . '" has already been applied to the order.');
96
+ }
97
+ };
41
98
  }
42
99
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Http\Requests;
4
4
 
5
+ use Fleetbase\FleetOps\Rules\ResolvablePoint;
5
6
  use Fleetbase\Http\Requests\FleetbaseRequest;
6
7
 
7
8
  class CreateVehicleRequest extends FleetbaseRequest
@@ -24,9 +25,10 @@ class CreateVehicleRequest extends FleetbaseRequest
24
25
  public function rules()
25
26
  {
26
27
  return [
27
- 'status' => 'nullable|in:operational,maintenance,decommissioned',
28
- 'vendor' => 'nullable|exists:vendors,public_id',
29
- 'driver' => 'nullable|exists:drivers,public_id',
28
+ 'status' => 'nullable|in:operational,maintenance,decommissioned',
29
+ 'vendor' => 'nullable|exists:vendors,public_id',
30
+ 'driver' => 'nullable|exists:drivers,public_id',
31
+ 'location' => ['nullable', new ResolvablePoint()],
30
32
  ];
31
33
  }
32
34
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Http\Resources\v1;
4
4
 
5
+ use Fleetbase\FleetOps\Support\Utils;
5
6
  use Fleetbase\Http\Resources\FleetbaseResource;
6
7
  use Fleetbase\Support\Http;
7
8
  use Fleetbase\Support\Resolve;
@@ -24,11 +25,13 @@ class Entity extends FleetbaseResource
24
25
  'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
25
26
  'customer_uuid' => $this->when(Http::isInternalRequest(), $this->customer_uuid),
26
27
  'customer_type' => $this->when(Http::isInternalRequest(), $this->customer_type),
28
+ 'supplier_uuid' => $this->when(Http::isInternalRequest(), $this->supplier_uuid),
27
29
  'internal_id' => $this->internal_id,
28
30
  'name' => $this->name,
29
31
  'type' => $this->type ?? null,
30
32
  'destination' => $this->when(Http::isPublicRequest(), data_get($this, 'destination.public_id'), null),
31
33
  'customer' => $this->setCustomerType(Resolve::resourceForMorph($this->customer_type, $this->customer_uuid)),
34
+ 'supplier' => $this->whenLoaded('supplier', $this->supplier),
32
35
  'tracking_number' => new TrackingNumber($this->trackingNumber),
33
36
  'description' => $this->description ?? null,
34
37
  'photo_url' => $this->photo_url ?? null,
@@ -17,23 +17,25 @@ class Fleet extends FleetbaseResource
17
17
  public function toArray($request)
18
18
  {
19
19
  return [
20
- 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
21
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
- 'name' => $this->name,
24
- 'task' => $this->task ?? null,
25
- 'status' => $this->status ?? null,
26
- 'drivers_count' => $this->when(Http::isInternalRequest(), $this->drivers_count),
27
- 'drivers_online_count' => $this->when(Http::isInternalRequest(), $this->drivers_online_count),
28
- 'service_area' => $this->whenLoaded('serviceArea', new ServiceArea($this->serviceArea)),
29
- 'zone' => $this->whenLoaded('zone', new Zone($this->zone)),
30
- 'vendor' => $this->whenLoaded('vendor', new Vendor($this->vendor)),
31
- 'parent_fleet' => $this->whenLoaded('parentFleet', new ParentFleet($this->parentFleet)),
32
- 'subfleets' => $this->whenLoaded('subFleets', SubFleet::collection($this->subFleets)),
33
- 'drivers' => $this->whenLoaded('drivers', Driver::collection($this->drivers()->without(['driverAssigned'])->with(Http::isInternalRequest() ? ['jobs'] : [])->get())),
34
- 'vehicles' => $this->whenLoaded('vehicles', Vehicle::collection($this->vehicles)),
35
- 'updated_at' => $this->updated_at,
36
- 'created_at' => $this->created_at,
20
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
21
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
22
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
23
+ 'name' => $this->name,
24
+ 'task' => $this->task ?? null,
25
+ 'status' => $this->status ?? null,
26
+ 'drivers_count' => $this->when(Http::isInternalRequest(), $this->drivers_count),
27
+ 'drivers_online_count' => $this->when(Http::isInternalRequest(), $this->drivers_online_count),
28
+ 'vehicles_count' => $this->when(Http::isInternalRequest(), $this->vehicles_count),
29
+ 'vehicles_online_count' => $this->when(Http::isInternalRequest(), $this->vehicles_online_count),
30
+ 'service_area' => $this->whenLoaded('serviceArea', new ServiceArea($this->serviceArea)),
31
+ 'zone' => $this->whenLoaded('zone', new Zone($this->zone)),
32
+ 'vendor' => $this->whenLoaded('vendor', new Vendor($this->vendor)),
33
+ 'parent_fleet' => $this->whenLoaded('parentFleet', new ParentFleet($this->parentFleet)),
34
+ 'subfleets' => $this->whenLoaded('subFleets', SubFleet::collection($this->subFleets)),
35
+ 'drivers' => $this->whenLoaded('drivers', Driver::collection($this->drivers()->without(['driverAssigned'])->with(Http::isInternalRequest() ? ['jobs'] : [])->get())),
36
+ 'vehicles' => $this->whenLoaded('vehicles', Vehicle::collection($this->vehicles)),
37
+ 'updated_at' => $this->updated_at,
38
+ 'created_at' => $this->created_at,
37
39
  ];
38
40
  }
39
41
 
@@ -48,12 +48,13 @@ class Order extends FleetbaseResource
48
48
  'type' => $this->type,
49
49
  'status' => $this->status,
50
50
  'pod_method' => $this->pod_method,
51
- 'pod_required' => $this->pod_required ?? false,
51
+ 'pod_required' => (bool) data_get($this, 'pod_required', false),
52
+ 'dispatched' => (bool) data_get($this, 'dispatched', false),
52
53
  'adhoc' => $this->adhoc,
53
54
  'adhoc_distance' => (int) $this->getAdhocDistance(),
54
55
  'distance' => (int) $this->distance,
55
56
  'time' => (int) $this->time,
56
- 'meta' => $this->meta ?? [],
57
+ 'meta' => data_get($this, 'meta', []),
57
58
  'dispatched_at' => $this->dispatched_at,
58
59
  'started_at' => $this->started_at,
59
60
  'scheduled_at' => $this->scheduled_at,
@@ -18,10 +18,12 @@ use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
18
18
  use Illuminate\Broadcasting\Channel;
19
19
  use Illuminate\Notifications\Notifiable;
20
20
  use Illuminate\Support\Facades\DB;
21
+ use Illuminate\Support\Str;
21
22
  use Spatie\Activitylog\Traits\CausesActivity;
22
23
  use Spatie\Activitylog\Traits\LogsActivity;
23
24
  use Spatie\Sluggable\HasSlug;
24
25
  use Spatie\Sluggable\SlugOptions;
26
+ use WebSocket\Message\Ping;
25
27
 
26
28
  class Driver extends Model
27
29
  {
@@ -86,6 +88,7 @@ class Driver extends Model
86
88
  'online',
87
89
  'slug',
88
90
  'status',
91
+ 'meta,',
89
92
  ];
90
93
 
91
94
  /**
@@ -108,8 +111,9 @@ class Driver extends Model
108
111
  * @var array
109
112
  */
110
113
  protected $casts = [
111
- 'location' => Point::class,
112
- 'online' => 'boolean',
114
+ 'location' => Point::class,
115
+ 'online' => 'boolean',
116
+ 'meta' => Json::class,
113
117
  ];
114
118
 
115
119
  /**
@@ -546,4 +550,19 @@ class Driver extends Model
546
550
 
547
551
  return $position;
548
552
  }
553
+
554
+ /**
555
+ * Get the user relationship from the driver.
556
+ */
557
+ public function getUser(): ?\Fleetbase\Models\User
558
+ {
559
+ // get user
560
+ $user = $this->load(['user'])->user;
561
+
562
+ if (empty($user) && Str::isUuid($this->user_uuid)) {
563
+ $user = \Fleetbase\Models\User::where('uuid', $this->user_uuid)->first();
564
+ }
565
+
566
+ return $user;
567
+ }
549
568
  }
@@ -68,6 +68,7 @@ class Entity extends Model
68
68
  'customer_type',
69
69
  'tracking_number_uuid',
70
70
  'destination_uuid',
71
+ 'supplier_uuid',
71
72
  'photo_uuid',
72
73
  '_import_id',
73
74
  'internal_id',
@@ -160,9 +161,7 @@ class Entity extends Model
160
161
  }
161
162
 
162
163
  /**
163
- * Photo of entity belongs to.
164
- *
165
- * @var Model
164
+ * @var \Illuminate\Database\Eloquent\Relations\BelongsTo
166
165
  */
167
166
  public function photo()
168
167
  {
@@ -170,9 +169,7 @@ class Entity extends Model
170
169
  }
171
170
 
172
171
  /**
173
- * Files assosciated with entity.
174
- *
175
- * @var Model
172
+ * @var \Illuminate\Database\Eloquent\Relations\HasMany
176
173
  */
177
174
  public function files()
178
175
  {
@@ -180,7 +177,7 @@ class Entity extends Model
180
177
  }
181
178
 
182
179
  /**
183
- * The proofs for this order.
180
+ * @var \Illuminate\Database\Eloquent\Relations\HasMany
184
181
  */
185
182
  public function proofs()
186
183
  {
@@ -188,9 +185,7 @@ class Entity extends Model
188
185
  }
189
186
 
190
187
  /**
191
- * The entity destination.
192
- *
193
- * @var Model
188
+ * @var \Illuminate\Database\Eloquent\Relations\BelongsTo
194
189
  */
195
190
  public function destination()
196
191
  {
@@ -198,9 +193,7 @@ class Entity extends Model
198
193
  }
199
194
 
200
195
  /**
201
- * Payload entity belongs to.
202
- *
203
- * @var Model
196
+ * @var \Illuminate\Database\Eloquent\Relations\BelongsTo
204
197
  */
205
198
  public function payload()
206
199
  {
@@ -208,9 +201,15 @@ class Entity extends Model
208
201
  }
209
202
 
210
203
  /**
211
- * Driver assigned to order.
212
- *
213
- * @var Model
204
+ * @var \Illuminate\Database\Eloquent\Relations\BelongsTo
205
+ */
206
+ public function supplier()
207
+ {
208
+ return $this->belongsTo(Vendor::class, 'supplier_uuid', 'uuid');
209
+ }
210
+
211
+ /**
212
+ * @var \Illuminate\Database\Eloquent\Relations\BelongsTo
214
213
  */
215
214
  public function driver()
216
215
  {
@@ -218,9 +217,7 @@ class Entity extends Model
218
217
  }
219
218
 
220
219
  /**
221
- * The company who manages this order.
222
- *
223
- * @var Model
220
+ * @var \Illuminate\Database\Eloquent\Relations\BelongsTo
224
221
  */
225
222
  public function company()
226
223
  {
@@ -228,7 +225,7 @@ class Entity extends Model
228
225
  }
229
226
 
230
227
  /**
231
- * The tracking number assosicated to the entity.
228
+ * @var \Illuminate\Database\Eloquent\Relations\BelongsTo
232
229
  */
233
230
  public function trackingNumber()
234
231
  {
@@ -236,9 +233,7 @@ class Entity extends Model
236
233
  }
237
234
 
238
235
  /**
239
- * The customer of this order.
240
- *
241
- * @var Model
236
+ * @var \Illuminate\Database\Eloquent\Relations\MorphTo
242
237
  */
243
238
  public function customer()
244
239
  {
@@ -975,7 +975,7 @@ class Order extends Model
975
975
  $this->load('driverAssigned');
976
976
 
977
977
  if ($this->driverAssigned instanceof Driver) {
978
- $this->payload->setPickup($this->driverAssigned->location, true);
978
+ $this->payload->setPickup($this->driverAssigned->location, ['save' => true]);
979
979
  }
980
980
  }
981
981
 
@@ -985,7 +985,7 @@ class Order extends Model
985
985
  $this->load('driverAssigned');
986
986
 
987
987
  if ($this->driverAssigned instanceof Driver) {
988
- $this->payload->setPickup($this->driverAssigned->location, true);
988
+ $this->payload->setPickup($this->driverAssigned->location, ['save' => true]);
989
989
  }
990
990
  }
991
991
  }