@fleetbase/fleetops-engine 0.4.15 → 0.4.17

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 (220) hide show
  1. package/.php-cs-fixer.php +2 -0
  2. package/addon/components/activity-event-selector.hbs +35 -0
  3. package/addon/components/activity-event-selector.js +85 -0
  4. package/addon/components/activity-form-panel.hbs +23 -0
  5. package/addon/components/activity-form-panel.js +90 -0
  6. package/addon/components/activity-logic-builder.hbs +80 -0
  7. package/addon/components/activity-logic-builder.js +260 -0
  8. package/addon/components/contact-form-panel.hbs +1 -1
  9. package/addon/components/contact-panel.hbs +1 -1
  10. package/addon/components/custom-entity-form-panel.hbs +43 -0
  11. package/addon/components/custom-entity-form-panel.js +129 -0
  12. package/addon/components/custom-field-form-panel/options-input.hbs +12 -0
  13. package/addon/components/custom-field-form-panel/options-input.js +139 -0
  14. package/addon/components/custom-field-form-panel.hbs +77 -0
  15. package/addon/components/custom-field-form-panel.js +144 -0
  16. package/addon/components/custom-field.hbs +63 -41
  17. package/addon/components/custom-field.js +123 -25
  18. package/addon/components/driver-form-panel.hbs +1 -1
  19. package/addon/components/driver-panel.hbs +1 -1
  20. package/addon/components/edit-order-route-panel.hbs +1 -1
  21. package/addon/components/fleet-form-panel.hbs +1 -1
  22. package/addon/components/fleet-panel.hbs +1 -1
  23. package/addon/components/fuel-report-form-panel.hbs +1 -1
  24. package/addon/components/fuel-report-panel.hbs +1 -1
  25. package/addon/components/issue-form-panel.hbs +1 -1
  26. package/addon/components/issue-panel.hbs +1 -1
  27. package/addon/components/joint-graph.hbs +1 -0
  28. package/addon/components/joint-graph.js +103 -0
  29. package/addon/components/layout/fleet-ops-sidebar.hbs +3 -3
  30. package/addon/components/layout/fleet-ops-sidebar.js +1 -0
  31. package/addon/components/live-map.js +71 -28
  32. package/addon/components/modals/new-custom-field-group.hbs +5 -0
  33. package/addon/components/modals/new-order-config.hbs +3 -3
  34. package/addon/components/modals/order-new-activity.hbs +1 -1
  35. package/addon/components/order-config-manager/activity-flow.hbs +11 -0
  36. package/addon/components/order-config-manager/activity-flow.js +964 -0
  37. package/addon/components/order-config-manager/custom-fields.hbs +50 -0
  38. package/addon/components/order-config-manager/custom-fields.js +276 -0
  39. package/addon/components/order-config-manager/details.hbs +23 -0
  40. package/addon/components/order-config-manager/details.js +97 -0
  41. package/addon/components/order-config-manager/entities.hbs +54 -0
  42. package/addon/components/order-config-manager/entities.js +227 -0
  43. package/addon/components/order-config-manager-overlay.hbs +26 -0
  44. package/addon/components/order-config-manager-overlay.js +60 -0
  45. package/addon/components/order-config-manager.hbs +15 -0
  46. package/addon/components/order-config-manager.js +285 -0
  47. package/addon/components/order-flow.hbs +1 -0
  48. package/addon/components/order-flow.js +3 -0
  49. package/addon/components/place-form-panel.hbs +1 -1
  50. package/addon/components/place-panel.hbs +1 -1
  51. package/addon/components/vehicle-form-panel.hbs +1 -1
  52. package/addon/components/vehicle-panel.hbs +1 -1
  53. package/addon/components/vendor-form-panel.hbs +1 -1
  54. package/addon/components/vendor-panel.hbs +1 -1
  55. package/addon/controllers/application.js +5 -1
  56. package/addon/controllers/operations/order-config.js +42 -0
  57. package/addon/controllers/operations/orders/index/new.js +125 -21
  58. package/addon/controllers/operations/orders/index/view.js +87 -4
  59. package/addon/controllers/operations/orders/index.js +2 -2
  60. package/addon/engine.js +10 -1
  61. package/addon/initializers/load-jointjs.js +16 -0
  62. package/addon/routes/application.js +1 -1
  63. package/addon/routes/operations/order-config.js +28 -0
  64. package/addon/routes/operations/orders/index/new.js +2 -3
  65. package/addon/routes/operations/orders/index/view.js +1 -1
  66. package/addon/routes.js +1 -0
  67. package/addon/services/context-panel.js +65 -3
  68. package/addon/styles/fleetops-engine.css +268 -0
  69. package/addon/templates/application.hbs +1 -1
  70. package/addon/templates/operations/order-config.hbs +55 -0
  71. package/addon/templates/operations/orders/index/new.hbs +98 -339
  72. package/addon/templates/operations/orders/index/view.hbs +36 -96
  73. package/addon/templates/operations/orders/index.hbs +0 -1
  74. package/addon/utils/apply-context-component-arguments.js +4 -2
  75. package/addon/utils/create-custom-entity.js +22 -0
  76. package/addon/utils/create-flow-activity.js +31 -0
  77. package/addon/utils/get-custom-field-type-map.js +34 -0
  78. package/app/components/activity-event-selector.js +1 -0
  79. package/app/components/activity-form-panel.js +1 -0
  80. package/app/components/activity-logic-builder.js +1 -0
  81. package/app/components/custom-entity-form-panel.js +1 -0
  82. package/app/components/custom-field-form-panel/options-input.js +1 -0
  83. package/app/components/custom-field-form-panel.js +1 -0
  84. package/app/components/joint-graph.js +1 -0
  85. package/app/components/modals/new-custom-field-group.js +1 -0
  86. package/app/components/order-config-manager/activity-flow.js +1 -0
  87. package/app/components/order-config-manager/custom-fields.js +1 -0
  88. package/app/components/order-config-manager/details.js +1 -0
  89. package/app/components/order-config-manager/entities.js +1 -0
  90. package/app/components/order-config-manager-overlay.js +1 -0
  91. package/app/components/order-config-manager.js +1 -0
  92. package/app/components/order-flow.js +1 -0
  93. package/app/controllers/operations/order-config.js +1 -0
  94. package/app/routes/operations/order-config.js +1 -0
  95. package/app/templates/operations/order-config.js +1 -0
  96. package/app/utils/create-custom-entity.js +1 -0
  97. package/app/utils/create-flow-activity.js +1 -0
  98. package/app/utils/get-custom-field-type-map.js +1 -0
  99. package/composer.json +4 -3
  100. package/config/environment.js +1 -0
  101. package/extension.json +1 -1
  102. package/index.js +20 -0
  103. package/package.json +7 -5
  104. package/server/migrations/2023_04_27_053456_create_contacts_table.php +1 -2
  105. package/server/migrations/2023_04_27_053456_create_drivers_table.php +1 -2
  106. package/server/migrations/2023_04_27_053456_create_entities_table.php +1 -2
  107. package/server/migrations/2023_04_27_053456_create_fleet_drivers_table.php +1 -2
  108. package/server/migrations/2023_04_27_053456_create_fleets_table.php +1 -2
  109. package/server/migrations/2023_04_27_053456_create_fuel_reports_table.php +1 -2
  110. package/server/migrations/2023_04_27_053456_create_integrated_vendors_table.php +1 -2
  111. package/server/migrations/2023_04_27_053456_create_issues_table.php +1 -2
  112. package/server/migrations/2023_04_27_053456_create_orders_table.php +1 -2
  113. package/server/migrations/2023_04_27_053456_create_payloads_table.php +1 -2
  114. package/server/migrations/2023_04_27_053456_create_places_table.php +1 -2
  115. package/server/migrations/2023_04_27_053456_create_positions_table.php +1 -2
  116. package/server/migrations/2023_04_27_053456_create_proofs_table.php +1 -2
  117. package/server/migrations/2023_04_27_053456_create_purchase_rates_table.php +1 -2
  118. package/server/migrations/2023_04_27_053456_create_routes_table.php +1 -2
  119. package/server/migrations/2023_04_27_053456_create_service_areas_table.php +1 -2
  120. package/server/migrations/2023_04_27_053456_create_service_quote_items_table.php +1 -2
  121. package/server/migrations/2023_04_27_053456_create_service_quotes_table.php +1 -2
  122. package/server/migrations/2023_04_27_053456_create_service_rate_fees_table.php +1 -2
  123. package/server/migrations/2023_04_27_053456_create_service_rate_parcel_fees_table.php +1 -2
  124. package/server/migrations/2023_04_27_053456_create_service_rates_table.php +1 -2
  125. package/server/migrations/2023_04_27_053456_create_tracking_numbers_table.php +1 -2
  126. package/server/migrations/2023_04_27_053456_create_tracking_statuses_table.php +1 -2
  127. package/server/migrations/2023_04_27_053456_create_vehicles_table.php +1 -2
  128. package/server/migrations/2023_04_27_053456_create_vendors_table.php +1 -2
  129. package/server/migrations/2023_04_27_053456_create_waypoints_table.php +1 -2
  130. package/server/migrations/2023_04_27_053456_create_zones_table.php +1 -2
  131. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_companies_table.php +1 -2
  132. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_contacts_table.php +1 -2
  133. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_drivers_table.php +1 -2
  134. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_entities_table.php +1 -2
  135. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleet_drivers_table.php +1 -2
  136. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleets_table.php +1 -2
  137. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fuel_reports_table.php +1 -2
  138. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_integrated_vendors_table.php +1 -2
  139. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_issues_table.php +1 -2
  140. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_orders_table.php +1 -2
  141. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_payloads_table.php +1 -2
  142. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_places_table.php +1 -2
  143. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_positions_table.php +1 -2
  144. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_proofs_table.php +1 -2
  145. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_purchase_rates_table.php +1 -2
  146. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_routes_table.php +1 -2
  147. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_areas_table.php +1 -2
  148. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quote_items_table.php +1 -2
  149. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quotes_table.php +1 -2
  150. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_fees_table.php +1 -2
  151. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_parcel_fees_table.php +1 -2
  152. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rates_table.php +1 -2
  153. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_numbers_table.php +1 -2
  154. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_statuses_table.php +1 -2
  155. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vehicles_table.php +1 -2
  156. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vendors_table.php +1 -2
  157. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_waypoints_table.php +1 -2
  158. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_zones_table.php +1 -2
  159. package/server/migrations/2023_09_14_074512_update_vehicles_table.php +1 -2
  160. package/server/migrations/2023_09_14_074619_create_vehicle_devices_table.php +35 -36
  161. package/server/migrations/2023_09_26_071205_add_online_column_to_vehicles_table.php +1 -2
  162. package/server/migrations/2023_09_26_083957_create_fleet_vehicles_table.php +1 -2
  163. package/server/migrations/2023_09_27_023757_add_column_to_fleets_table.php +1 -2
  164. package/server/migrations/2023_10_05_074811_update_vehicle.php +1 -2
  165. package/server/migrations/2023_10_25_093014_create_vehicle_device_events_table.php +1 -2
  166. package/server/migrations/2023_11_03_072503_refactor_issues_table_columns.php +1 -2
  167. package/server/migrations/2023_11_06_040645_refactor_fuel_reports_table.php +1 -2
  168. package/server/migrations/2023_11_09_041807_add_status_column_to_fuel_reports_table.php +1 -2
  169. package/server/migrations/2023_11_15_062814_add_comments_column_and_resolved_at_column_to_vehicle_device_events_table.php +1 -2
  170. package/server/migrations/2023_11_17_053001_add_category_uuid_to_entities_table.php +1 -2
  171. package/server/migrations/2023_11_28_074244_add_supplier_uuid_column_to_entities_table.php +1 -2
  172. package/server/migrations/2023_12_14_100209_add_meta_column_on_driver_table copy.php +1 -2
  173. package/server/migrations/2024_02_18_100209_add_avatar_url_columns_table.php +3 -4
  174. package/server/migrations/2024_02_27_093648_create_order_configs_table.php +43 -0
  175. package/server/migrations/2024_03_07_075508_add_order_config_uuid_column_to_orders_table.php +28 -0
  176. package/server/seeders/OrderConfigSeeder.php +151 -0
  177. package/server/src/Casts/OrderConfigEntities.php +53 -0
  178. package/server/src/Console/Commands/FixLegacyOrderConfigs.php +66 -0
  179. package/server/src/Events/DriverLocationChanged.php +1 -1
  180. package/server/src/Events/DriverSimulatedLocationChanged.php +1 -1
  181. package/server/src/Expansions/UserExpansion.php +4 -4
  182. package/server/src/Flow/Activity.php +232 -6
  183. package/server/src/Flow/Condition.php +84 -0
  184. package/server/src/Flow/Event.php +88 -0
  185. package/server/src/Flow/Flow.php +50 -0
  186. package/server/src/Flow/FlowResource.php +143 -0
  187. package/server/src/Flow/Logic.php +57 -1
  188. package/server/src/Http/Controllers/Api/v1/DriverController.php +2 -2
  189. package/server/src/Http/Controllers/Api/v1/IssueController.php +132 -0
  190. package/server/src/Http/Controllers/Api/v1/OrderController.php +130 -57
  191. package/server/src/Http/Controllers/Api/v1/OrganizationController.php +27 -0
  192. package/server/src/Http/Controllers/Api/v1/PlaceController.php +2 -3
  193. package/server/src/Http/Controllers/Controller.php +9 -0
  194. package/server/src/Http/Controllers/FleetOpsController.php +7 -0
  195. package/server/src/Http/Controllers/Internal/v1/OrderConfigController.php +5 -259
  196. package/server/src/Http/Controllers/Internal/v1/OrderController.php +56 -35
  197. package/server/src/Http/Controllers/Internal/v1/SettingController.php +20 -0
  198. package/server/src/Http/Filter/OrderConfigFilter.php +13 -0
  199. package/server/src/Http/Requests/CreateIssueRequest.php +19 -0
  200. package/server/src/Http/Requests/UpdateIssueRequest.php +7 -0
  201. package/server/src/Http/Resources/v1/Order.php +3 -0
  202. package/server/src/Http/Resources/v1/Payload.php +1 -1
  203. package/server/src/Listeners/HandleOrderCanceled.php +8 -4
  204. package/server/src/Listeners/HandleOrderDispatched.php +14 -12
  205. package/server/src/Models/Order.php +527 -31
  206. package/server/src/Models/OrderConfig.php +419 -0
  207. package/server/src/Models/Payload.php +8 -7
  208. package/server/src/Notifications/OrderAssigned.php +1 -1
  209. package/server/src/Notifications/OrderCanceled.php +1 -1
  210. package/server/src/Notifications/OrderDispatchFailed.php +1 -1
  211. package/server/src/Notifications/OrderDispatched.php +1 -1
  212. package/server/src/Notifications/OrderPing.php +1 -1
  213. package/server/src/Providers/FleetOpsServiceProvider.php +3 -1
  214. package/server/src/Providers/NotificationServiceProvider.php +2 -1
  215. package/server/src/Support/Utils.php +17 -0
  216. package/server/src/Traits/HasTrackingNumber.php +9 -9
  217. package/server/src/routes.php +19 -11
  218. package/translations/en-us.yaml +137 -0
  219. package/server/src/Flow/Config.php +0 -7
  220. package/server/src/Support/Flow.php +0 -653
@@ -0,0 +1,419 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\FleetOps\Models;
4
+
5
+ use Fleetbase\Casts\Json;
6
+ use Fleetbase\FleetOps\Casts\OrderConfigEntities;
7
+ use Fleetbase\FleetOps\Flow\Activity;
8
+ use Fleetbase\Models\Model;
9
+ use Fleetbase\Support\Auth;
10
+ use Fleetbase\Traits\HasApiModelBehavior;
11
+ use Fleetbase\Traits\HasMetaAttributes;
12
+ use Fleetbase\Traits\HasUuid;
13
+ use Fleetbase\Traits\Searchable;
14
+ use Illuminate\Support\Collection;
15
+ use Illuminate\Support\Str;
16
+
17
+ class OrderConfig extends Model
18
+ {
19
+ use HasUuid;
20
+ use Searchable;
21
+ use HasMetaAttributes;
22
+ use HasApiModelBehavior;
23
+
24
+ /**
25
+ * The database table used by the model.
26
+ *
27
+ * @var string
28
+ */
29
+ protected $table = 'order_configs';
30
+
31
+ /**
32
+ * These attributes that can be queried.
33
+ *
34
+ * @var array
35
+ */
36
+ protected $searchableColumns = ['name'];
37
+
38
+ /**
39
+ * The attributes that are mass assignable.
40
+ *
41
+ * @var array
42
+ */
43
+ protected $fillable = [
44
+ 'company_uuid',
45
+ 'author_uuid',
46
+ 'category_uuid',
47
+ 'icon_uuid',
48
+ 'name',
49
+ 'namespace',
50
+ 'description',
51
+ 'key',
52
+ 'status',
53
+ 'version',
54
+ 'core_service',
55
+ 'tags',
56
+ 'flow',
57
+ 'entities',
58
+ 'meta',
59
+ ];
60
+
61
+ /**
62
+ * The attributes that should be cast to native types.
63
+ *
64
+ * @var array
65
+ */
66
+ protected $casts = [
67
+ 'tags' => Json::class,
68
+ 'flow' => Json::class,
69
+ 'entities' => OrderConfigEntities::class,
70
+ 'meta' => Json::class,
71
+ ];
72
+
73
+ /**
74
+ * Dynamic attributes that are appended to object.
75
+ *
76
+ * @var array
77
+ */
78
+ protected $appends = ['type'];
79
+
80
+ /**
81
+ * The attributes excluded from the model's JSON form.
82
+ *
83
+ * @var array
84
+ */
85
+ protected $hidden = [];
86
+
87
+ /**
88
+ * The current order in context to this config.
89
+ *
90
+ * @var Order
91
+ */
92
+ protected $orderContext;
93
+
94
+ /**
95
+ * Bootstraps the model and its events.
96
+ *
97
+ * This method overrides the default Eloquent model boot method
98
+ * to add a custom 'creating' event listener. This listener is used
99
+ * to set default values when a new model instance is being created.
100
+ *
101
+ * @return void
102
+ */
103
+ protected static function boot()
104
+ {
105
+ parent::boot();
106
+
107
+ static::creating(function ($model) {
108
+ $model->namespace = empty($model->namespace) ? static::createNamespace($model->name) : $model->namespace;
109
+ $model->version = '0.0.1';
110
+ $model->status = 'private';
111
+ $model->key = Str::slug($model->name);
112
+ });
113
+ }
114
+
115
+ /**
116
+ * Creates a namespaced string based on the provided name.
117
+ *
118
+ * This method generates a namespaced string using the company's name
119
+ * retrieved from the authenticated user's company, followed by a fixed
120
+ * segment ':order-config:', and the provided name. This is used to
121
+ * create a unique namespace for each model instance.
122
+ *
123
+ * @param string $name the name to be included in the namespace
124
+ *
125
+ * @return string the generated namespaced string
126
+ */
127
+ public static function createNamespace(string $name): string
128
+ {
129
+ $company = Auth::getCompany();
130
+
131
+ return Str::slug($company->name) . ':order-config:' . Str::slug($name);
132
+ }
133
+
134
+ /**
135
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
136
+ */
137
+ public function company()
138
+ {
139
+ return $this->belongsTo(Order::class);
140
+ }
141
+
142
+ /**
143
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
144
+ */
145
+ public function author()
146
+ {
147
+ return $this->belongsTo(\Fleetbase\Models\User::class);
148
+ }
149
+
150
+ /**
151
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
152
+ */
153
+ public function category()
154
+ {
155
+ return $this->belongsTo(\Fleetbase\Models\Category::class);
156
+ }
157
+
158
+ /**
159
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
160
+ */
161
+ public function icon()
162
+ {
163
+ return $this->belongsTo(\Fleetbase\Models\File::class);
164
+ }
165
+
166
+ /**
167
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
168
+ */
169
+ public function customFields()
170
+ {
171
+ return $this->belongsTo(\Fleetbase\Models\CustomField::class);
172
+ }
173
+
174
+ /**
175
+ * Accessor method for getting the type attribute of the order config.
176
+ *
177
+ * @return string the type of the order config
178
+ */
179
+ public function getTypeAttribute()
180
+ {
181
+ return 'order-config';
182
+ }
183
+
184
+ /**
185
+ * Sets the order context for the current order config.
186
+ *
187
+ * @param Order $order the order to set as the context
188
+ *
189
+ * @return self returns the instance for chaining
190
+ */
191
+ public function setOrderContext(Order $order): self
192
+ {
193
+ $this->orderContext = $order;
194
+
195
+ return $this;
196
+ }
197
+
198
+ /**
199
+ * Retrieves the current order context, setting it if not already set.
200
+ *
201
+ * @param Order|null $order the order to use as context if no current context is set
202
+ *
203
+ * @return Order|null the current order context
204
+ *
205
+ * @throws \Exception if no order context is found and none is provided
206
+ */
207
+ public function getOrderContext(?Order $order = null): ?Order
208
+ {
209
+ if (!$this->orderContext && $order instanceof Order) {
210
+ $this->setOrderContext($order);
211
+
212
+ return $order;
213
+ }
214
+
215
+ if (!$this->orderContext) {
216
+ throw new \Exception('No order context found to run order config.');
217
+ }
218
+
219
+ return $this->orderContext;
220
+ }
221
+
222
+ /**
223
+ * Retrieves all activities defined in the order config's flow.
224
+ *
225
+ * @return Collection a collection of Activity objects
226
+ */
227
+ public function activities(): Collection
228
+ {
229
+ $activities = collect();
230
+ foreach ($this->flow as $activity) {
231
+ $activities->push(new Activity($activity, $this->flow));
232
+ }
233
+
234
+ return $activities;
235
+ }
236
+
237
+ /**
238
+ * Retrieves the 'created' activity from the flow.
239
+ *
240
+ * @return Activity|null the created Activity object or null if not found
241
+ */
242
+ public function getCreatedActivity(): ?Activity
243
+ {
244
+ return $this->activities()->firstWhere('code', 'created');
245
+ }
246
+
247
+ /**
248
+ * Retrieves the 'dispatched' activity from the flow.
249
+ *
250
+ * @return Activity|null the dispatched Activity object or null if not found
251
+ */
252
+ public function getDispatchActivity(): ?Activity
253
+ {
254
+ return $this->activities()->firstWhere('code', 'dispatched');
255
+ }
256
+
257
+ /**
258
+ * Determines the current activity based on the order's status.
259
+ *
260
+ * @param Order|null $order the order to evaluate
261
+ *
262
+ * @return Activity|null the current Activity object or null if not found
263
+ */
264
+ public function currentActivity(?Order $order = null): ?Activity
265
+ {
266
+ $order = $this->getOrderContext($order);
267
+
268
+ return $this->activities()->firstWhere('code', $order->status);
269
+ }
270
+
271
+ /**
272
+ * Determines the next set of activities based on the current activity.
273
+ *
274
+ * @param Order|null $order the order to evaluate
275
+ *
276
+ * @return Collection a collection of the next activities
277
+ */
278
+ public function nextActivity(?Order $order = null): Collection
279
+ {
280
+ $order = $this->getOrderContext($order);
281
+ $currentActivity = $this->currentActivity($order);
282
+ if ($currentActivity) {
283
+ return $currentActivity->getNext($order);
284
+ }
285
+
286
+ return collect();
287
+ }
288
+
289
+ /**
290
+ * Retrieves the first activity in the next set of activities.
291
+ *
292
+ * @param Order|null $order the order to evaluate
293
+ *
294
+ * @return Activity|null the first Activity object in the next set or null if not found
295
+ */
296
+ public function nextFirstActivity(?Order $order = null): ?Activity
297
+ {
298
+ $next = collect();
299
+ $order = $this->getOrderContext($order);
300
+ $currentActivity = $this->currentActivity($order);
301
+ if ($currentActivity) {
302
+ $next = $currentActivity->getNext($order);
303
+ }
304
+
305
+ return $next->first();
306
+ }
307
+
308
+ /**
309
+ * Retrieves the activity that follows after the next activity.
310
+ *
311
+ * @param Order|null $order the order to evaluate
312
+ *
313
+ * @return Activity|null the Activity object that follows after the next or null if not found
314
+ */
315
+ public function afterNextActivity(?Order $order = null): ?Activity
316
+ {
317
+ $afterNext = collect();
318
+ $order = $this->getOrderContext($order);
319
+ $nextActivity = $this->nextFirstActivity($order);
320
+ if ($nextActivity) {
321
+ $afterNext = $nextActivity->getNext($order);
322
+ }
323
+
324
+ return $afterNext->first();
325
+ }
326
+
327
+ /**
328
+ * Retrieves the previous activities based on the current activity.
329
+ *
330
+ * @param Order|null $order the order to evaluate
331
+ *
332
+ * @return Collection a collection of previous activities
333
+ */
334
+ public function previousActivity(?Order $order = null): Collection
335
+ {
336
+ $order = $this->getOrderContext($order);
337
+ $currentActivity = $this->currentActivity($order);
338
+ if ($currentActivity) {
339
+ return $currentActivity->getPrevious($order);
340
+ }
341
+
342
+ return collect();
343
+ }
344
+
345
+ /**
346
+ * Creates an Activity instance representing a canceled order.
347
+ *
348
+ * This method constructs an Activity object with specific attributes
349
+ * like key, code, status, and details, indicating that the order has been canceled.
350
+ * It utilizes the flow associated with the OrderConfig for this purpose.
351
+ *
352
+ * @return Activity a new Activity instance representing a canceled order
353
+ */
354
+ public function getCanceledActivity()
355
+ {
356
+ $canceledActivity = $this->activities()->firstWhere('code', 'canceled');
357
+ if ($canceledActivity) {
358
+ return $canceledActivity;
359
+ }
360
+
361
+ return new Activity([
362
+ 'key' => 'order_canceled',
363
+ 'code' => 'canceled',
364
+ 'status' => 'Order canceled',
365
+ 'details' => 'Order was canceled',
366
+ 'complete' => false,
367
+ ], $this->flow);
368
+ }
369
+
370
+ /**
371
+ * Creates an Activity instance representing a completed order.
372
+ *
373
+ * This method constructs an Activity object with specific attributes
374
+ * such as key, code, status, and details, indicating that the order has been completed.
375
+ * It leverages the flow associated with the OrderConfig to construct this Activity.
376
+ *
377
+ * @return Activity a new Activity instance representing a completed order
378
+ */
379
+ public function getCompletedActivity()
380
+ {
381
+ $completedActivity = $this->activities()->firstWhere('code', 'completed');
382
+ if ($completedActivity) {
383
+ return $completedActivity;
384
+ }
385
+
386
+ return new Activity([
387
+ 'key' => 'order_completed',
388
+ 'code' => 'completed',
389
+ 'status' => 'Order completed',
390
+ 'details' => 'Order was completed',
391
+ 'complete' => true,
392
+ ], $this->flow);
393
+ }
394
+
395
+ /**
396
+ * Creates an Activity instance representing a started order.
397
+ *
398
+ * This method constructs an Activity object with specific attributes
399
+ * such as key, code, status, and details, indicating that the order has been started.
400
+ * It leverages the flow associated with the OrderConfig to construct this Activity.
401
+ *
402
+ * @return Activity a new Activity instance representing a started order
403
+ */
404
+ public function getStartedActivity()
405
+ {
406
+ $startedActivity = $this->activities()->firstWhere('code', 'started');
407
+ if ($startedActivity) {
408
+ return $startedActivity;
409
+ }
410
+
411
+ return new Activity([
412
+ 'key' => 'order_started',
413
+ 'code' => 'started',
414
+ 'status' => 'Order started',
415
+ 'details' => 'Order has started',
416
+ 'complete' => false,
417
+ ], $this->flow);
418
+ }
419
+ }
@@ -3,6 +3,7 @@
3
3
  namespace Fleetbase\FleetOps\Models;
4
4
 
5
5
  use Fleetbase\Casts\Json;
6
+ use Fleetbase\FleetOps\Flow\Activity;
6
7
  use Fleetbase\FleetOps\Support\Utils;
7
8
  use Fleetbase\Http\Resources\Internal\v1\Payload as PayloadResource;
8
9
  use Fleetbase\LaravelMysqlSpatial\Types\Point;
@@ -578,6 +579,7 @@ class Payload extends Model
578
579
  }
579
580
 
580
581
  $this->load('order');
582
+
581
583
  return $this->order;
582
584
  }
583
585
 
@@ -585,6 +587,7 @@ class Payload extends Model
585
587
  {
586
588
  Waypoint::where('payload_uuid', $this->uuid)->delete();
587
589
  $this->setRelation('waypoints', collect());
590
+
588
591
  return $this;
589
592
  }
590
593
 
@@ -699,12 +702,11 @@ class Payload extends Model
699
702
  /**
700
703
  * Set the first waypoint and update activity.
701
704
  *
702
- * @param array $activity
703
705
  * @param Point $location
704
706
  *
705
707
  * @return void
706
708
  */
707
- public function setFirstWaypoint($activity = null, $location = null)
709
+ public function setFirstWaypoint(?Activity $activity = null, $location = null)
708
710
  {
709
711
  $destination = null;
710
712
 
@@ -728,27 +730,26 @@ class Payload extends Model
728
730
  /**
729
731
  * Update the current waypoint activity and it's entities.
730
732
  *
731
- * @param array $activity
732
733
  * @param Point $location
733
734
  * @param \Fleetbase\Models\Proof|string|null $proof resolvable proof of delivery/activity
734
735
  *
735
736
  * @return $this
736
737
  */
737
- public function updateWaypointActivity($activity = null, $location = null, $proof = null)
738
+ public function updateWaypointActivity(?Activity $activity = null, $location = null, $proof = null)
738
739
  {
739
- if ($this->isMultipleDropOrder && is_array($activity) && $location) {
740
+ if ($this->isMultipleDropOrder && Utils::isActivity($activity) && $location) {
740
741
  // update activity for the current waypoint
741
742
  $currentWaypoint = $this->waypointMarkers->firstWhere('place_uuid', $this->current_waypoint_uuid);
742
743
 
743
744
  if ($currentWaypoint) {
744
- $currentWaypoint->insertActivity($activity['status'], $activity['details'], $location, $activity['code'], $proof);
745
+ $currentWaypoint->insertActivity($activity, $location, $proof);
745
746
  }
746
747
 
747
748
  // update activity for all entities for this destination/waypoint
748
749
  $entities = $this->entities->where('destination_uuid', $this->current_waypoint_uuid);
749
750
 
750
751
  foreach ($entities as $entity) {
751
- $entity->insertActivity($activity['status'], $activity['details'], $location, $activity['code'], $proof);
752
+ $entity->insertActivity($activity, $location, $proof);
752
753
  }
753
754
  }
754
755
 
@@ -65,7 +65,7 @@ class OrderAssigned extends Notification implements ShouldQueue
65
65
  /**
66
66
  * Get the channels the event should broadcast on.
67
67
  *
68
- * @return \Illuminate\Broadcasting\Channel|array
68
+ * @return Channel|array
69
69
  */
70
70
  public function broadcastOn()
71
71
  {
@@ -65,7 +65,7 @@ class OrderCanceled extends Notification implements ShouldQueue
65
65
  /**
66
66
  * Get the channels the event should broadcast on.
67
67
  *
68
- * @return \Illuminate\Broadcasting\Channel|array
68
+ * @return Channel|array
69
69
  */
70
70
  public function broadcastOn()
71
71
  {
@@ -59,7 +59,7 @@ class OrderDispatchFailed extends Notification implements ShouldQueue
59
59
  /**
60
60
  * Get the channels the event should broadcast on.
61
61
  *
62
- * @return \Illuminate\Broadcasting\Channel|array
62
+ * @return Channel|array
63
63
  */
64
64
  public function broadcastOn()
65
65
  {
@@ -77,7 +77,7 @@ class OrderDispatched extends Notification implements ShouldQueue
77
77
  /**
78
78
  * Get the channels the event should broadcast on.
79
79
  *
80
- * @return \Illuminate\Broadcasting\Channel|array
80
+ * @return Channel|array
81
81
  */
82
82
  public function broadcastOn()
83
83
  {
@@ -82,7 +82,7 @@ class OrderPing extends Notification implements ShouldQueue
82
82
  /**
83
83
  * Get the channels the event should broadcast on.
84
84
  *
85
- * @return \Illuminate\Broadcasting\Channel|array
85
+ * @return Channel|array
86
86
  */
87
87
  public function broadcastOn()
88
88
  {
@@ -6,8 +6,9 @@ use Brick\Geo\Engine\GeometryEngineRegistry;
6
6
  use Brick\Geo\Engine\GEOSEngine;
7
7
  use Fleetbase\Providers\CoreServiceProvider;
8
8
  use Fleetbase\Support\NotificationRegistry;
9
+ use Fleetbase\Support\Utils;
9
10
 
10
- if (!class_exists(CoreServiceProvider::class)) {
11
+ if (!Utils::classExists(CoreServiceProvider::class)) {
11
12
  throw new \Exception('FleetOps cannot be loaded without `fleetbase/core-api` installed!');
12
13
  }
13
14
 
@@ -45,6 +46,7 @@ class FleetOpsServiceProvider extends CoreServiceProvider
45
46
  \Fleetbase\FleetOps\Console\Commands\DispatchOrders::class,
46
47
  \Fleetbase\FleetOps\Console\Commands\TrackOrderDistanceAndTime::class,
47
48
  \Fleetbase\FleetOps\Console\Commands\FixDriverCompanies::class,
49
+ \Fleetbase\FleetOps\Console\Commands\FixLegacyOrderConfigs::class,
48
50
  ];
49
51
 
50
52
  /**
@@ -4,8 +4,9 @@ namespace Fleetbase\FleetOps\Providers;
4
4
 
5
5
  use Fleetbase\Providers\CoreServiceProvider;
6
6
  use Fleetbase\Support\NotificationRegistry;
7
+ use Fleetbase\Support\Utils;
7
8
 
8
- if (!class_exists(CoreServiceProvider::class)) {
9
+ if (!Utils::classExists(CoreServiceProvider::class)) {
9
10
  throw new \Exception('FleetOps cannot be loaded without `fleetbase/core-api` installed!');
10
11
  }
11
12
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Support;
4
4
 
5
+ use Fleetbase\FleetOps\Flow\Activity;
5
6
  use Fleetbase\Support\Utils as FleetbaseUtils;
6
7
  use Illuminate\Support\Arr;
7
8
  use Illuminate\Support\Facades\DB;
@@ -1276,4 +1277,20 @@ class Utils extends FleetbaseUtils
1276
1277
 
1277
1278
  return $theta_deg;
1278
1279
  }
1280
+
1281
+ /**
1282
+ * Determines if a given object is an instance of Activity.
1283
+ *
1284
+ * This static method is used to check if a provided object is an
1285
+ * instance of the Activity class. This can be useful in contexts where
1286
+ * there is a need to verify the type of a given resource or object.
1287
+ *
1288
+ * @param mixed $activity the object to check
1289
+ *
1290
+ * @return bool returns true if the provided object is an instance of Activity, false otherwise
1291
+ */
1292
+ public static function isActivity($activity)
1293
+ {
1294
+ return $activity && $activity instanceof Activity && !empty($activity->code);
1295
+ }
1279
1296
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Traits;
4
4
 
5
+ use Fleetbase\FleetOps\Flow\Activity;
5
6
  use Fleetbase\FleetOps\Models\Proof;
6
7
  use Fleetbase\FleetOps\Models\TrackingNumber;
7
8
  use Fleetbase\FleetOps\Models\TrackingStatus;
@@ -47,16 +48,16 @@ trait HasTrackingNumber
47
48
  /**
48
49
  * Creates activity for this resource tracking number.
49
50
  *
50
- * @param string $status the short status update
51
- * @param string $details the detailed update
52
51
  * @param array|Point $location the location of the update, can be either [lat, lng] or a \Fleetbase\LaravelMysqlSpatial\Types\Point instance
53
- * @param string $code the onew word status code
54
52
  * @param \Fleetbase\Models\Proof|string|null $proof resolvable proof of delivery/activity
55
53
  *
56
54
  * @return \Fleetbase\Models\TrackingStatus
57
55
  */
58
- public function createActivity(string $status, string $details = '', $location = [], string $code = '', $proof = null): TrackingStatus
56
+ public function createActivity(Activity $activity, $location = [], $proof = null): TrackingStatus
59
57
  {
58
+ $status = $activity->get('status');
59
+ $details = $activity->get('details');
60
+ $code = $activity->get('code');
60
61
  $proof = static::resolveProof($proof);
61
62
  $activity = TrackingStatus::create([
62
63
  'company_uuid' => data_get($this, 'company_uuid', session('company')),
@@ -82,14 +83,14 @@ trait HasTrackingNumber
82
83
  /**
83
84
  * Inserts activity for this resource tracking number.
84
85
  *
85
- * @param string $status the short status update
86
- * @param string $details the detailed update
87
86
  * @param array|Point $location the location of the update, can be either [lat, lng] or a \Fleetbase\LaravelMysqlSpatial\Types\Point instance
88
87
  * @param \Fleetbase\Models\Proof|string|null $proof resolvable proof of delivery/activity
89
- * @param string $code the onew word status code
90
88
  */
91
- public function insertActivity(string $status, string $details = '', $location = [], string $code = '', $proof = null): string
89
+ public function insertActivity(Activity $activity, $location = [], $proof = null): string
92
90
  {
91
+ $status = $activity->get('status');
92
+ $details = $activity->get('details');
93
+ $code = $activity->get('code');
93
94
  $proof = static::resolveProof($proof);
94
95
  $activityId = TrackingStatus::insertGetUuid([
95
96
  'company_uuid' => data_get($this, 'company_uuid', session('company')),
@@ -158,7 +159,6 @@ trait HasTrackingNumber
158
159
  $this->status = $status;
159
160
 
160
161
  if ($andSave) {
161
- // static::where('uuid', $this->uuid)->update(['status' => $status]);
162
162
  $this->save();
163
163
  }
164
164