@fleetbase/fleetops-engine 0.4.16 → 0.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) 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 +106 -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 +298 -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 +43 -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/config/api.php +3 -650
  105. package/server/migrations/2023_04_27_053456_create_contacts_table.php +1 -2
  106. package/server/migrations/2023_04_27_053456_create_drivers_table.php +1 -2
  107. package/server/migrations/2023_04_27_053456_create_entities_table.php +1 -2
  108. package/server/migrations/2023_04_27_053456_create_fleet_drivers_table.php +1 -2
  109. package/server/migrations/2023_04_27_053456_create_fleets_table.php +1 -2
  110. package/server/migrations/2023_04_27_053456_create_fuel_reports_table.php +1 -2
  111. package/server/migrations/2023_04_27_053456_create_integrated_vendors_table.php +1 -2
  112. package/server/migrations/2023_04_27_053456_create_issues_table.php +1 -2
  113. package/server/migrations/2023_04_27_053456_create_orders_table.php +1 -2
  114. package/server/migrations/2023_04_27_053456_create_payloads_table.php +1 -2
  115. package/server/migrations/2023_04_27_053456_create_places_table.php +1 -2
  116. package/server/migrations/2023_04_27_053456_create_positions_table.php +1 -2
  117. package/server/migrations/2023_04_27_053456_create_proofs_table.php +1 -2
  118. package/server/migrations/2023_04_27_053456_create_purchase_rates_table.php +1 -2
  119. package/server/migrations/2023_04_27_053456_create_routes_table.php +1 -2
  120. package/server/migrations/2023_04_27_053456_create_service_areas_table.php +1 -2
  121. package/server/migrations/2023_04_27_053456_create_service_quote_items_table.php +1 -2
  122. package/server/migrations/2023_04_27_053456_create_service_quotes_table.php +1 -2
  123. package/server/migrations/2023_04_27_053456_create_service_rate_fees_table.php +1 -2
  124. package/server/migrations/2023_04_27_053456_create_service_rate_parcel_fees_table.php +1 -2
  125. package/server/migrations/2023_04_27_053456_create_service_rates_table.php +1 -2
  126. package/server/migrations/2023_04_27_053456_create_tracking_numbers_table.php +1 -2
  127. package/server/migrations/2023_04_27_053456_create_tracking_statuses_table.php +1 -2
  128. package/server/migrations/2023_04_27_053456_create_vehicles_table.php +1 -2
  129. package/server/migrations/2023_04_27_053456_create_vendors_table.php +1 -2
  130. package/server/migrations/2023_04_27_053456_create_waypoints_table.php +1 -2
  131. package/server/migrations/2023_04_27_053456_create_zones_table.php +1 -2
  132. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_companies_table.php +1 -2
  133. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_contacts_table.php +1 -2
  134. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_drivers_table.php +1 -2
  135. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_entities_table.php +1 -2
  136. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleet_drivers_table.php +1 -2
  137. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleets_table.php +1 -2
  138. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fuel_reports_table.php +1 -2
  139. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_integrated_vendors_table.php +1 -2
  140. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_issues_table.php +1 -2
  141. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_orders_table.php +1 -2
  142. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_payloads_table.php +1 -2
  143. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_places_table.php +1 -2
  144. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_positions_table.php +1 -2
  145. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_proofs_table.php +1 -2
  146. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_purchase_rates_table.php +1 -2
  147. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_routes_table.php +1 -2
  148. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_areas_table.php +1 -2
  149. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quote_items_table.php +1 -2
  150. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quotes_table.php +1 -2
  151. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_fees_table.php +1 -2
  152. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_parcel_fees_table.php +1 -2
  153. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rates_table.php +1 -2
  154. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_numbers_table.php +1 -2
  155. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_statuses_table.php +1 -2
  156. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vehicles_table.php +1 -2
  157. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vendors_table.php +1 -2
  158. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_waypoints_table.php +1 -2
  159. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_zones_table.php +1 -2
  160. package/server/migrations/2023_09_14_074512_update_vehicles_table.php +1 -2
  161. package/server/migrations/2023_09_14_074619_create_vehicle_devices_table.php +35 -36
  162. package/server/migrations/2023_09_26_071205_add_online_column_to_vehicles_table.php +1 -2
  163. package/server/migrations/2023_09_26_083957_create_fleet_vehicles_table.php +1 -2
  164. package/server/migrations/2023_09_27_023757_add_column_to_fleets_table.php +1 -2
  165. package/server/migrations/2023_10_05_074811_update_vehicle.php +1 -2
  166. package/server/migrations/2023_10_25_093014_create_vehicle_device_events_table.php +1 -2
  167. package/server/migrations/2023_11_03_072503_refactor_issues_table_columns.php +1 -2
  168. package/server/migrations/2023_11_06_040645_refactor_fuel_reports_table.php +1 -2
  169. package/server/migrations/2023_11_09_041807_add_status_column_to_fuel_reports_table.php +1 -2
  170. package/server/migrations/2023_11_15_062814_add_comments_column_and_resolved_at_column_to_vehicle_device_events_table.php +1 -2
  171. package/server/migrations/2023_11_17_053001_add_category_uuid_to_entities_table.php +1 -2
  172. package/server/migrations/2023_11_28_074244_add_supplier_uuid_column_to_entities_table.php +1 -2
  173. package/server/migrations/2023_12_14_100209_add_meta_column_on_driver_table copy.php +1 -2
  174. package/server/migrations/2024_02_18_100209_add_avatar_url_columns_table.php +3 -4
  175. package/server/migrations/2024_02_27_093648_create_order_configs_table.php +43 -0
  176. package/server/migrations/2024_03_07_075508_add_order_config_uuid_column_to_orders_table.php +28 -0
  177. package/server/migrations/2024_03_12_033527_add_public_id_column_to_order_configs_table.php +34 -0
  178. package/server/seeders/OrderConfigSeeder.php +23 -0
  179. package/server/src/Casts/OrderConfigEntities.php +53 -0
  180. package/server/src/Console/Commands/FixLegacyOrderConfigs.php +66 -0
  181. package/server/src/Events/DriverLocationChanged.php +1 -1
  182. package/server/src/Events/DriverSimulatedLocationChanged.php +1 -1
  183. package/server/src/Flow/Activity.php +232 -6
  184. package/server/src/Flow/Condition.php +84 -0
  185. package/server/src/Flow/Event.php +88 -0
  186. package/server/src/Flow/Flow.php +50 -0
  187. package/server/src/Flow/FlowResource.php +143 -0
  188. package/server/src/Flow/Logic.php +57 -1
  189. package/server/src/Http/Controllers/Api/v1/DriverController.php +2 -2
  190. package/server/src/Http/Controllers/Api/v1/IssueController.php +132 -0
  191. package/server/src/Http/Controllers/Api/v1/OrderController.php +152 -57
  192. package/server/src/Http/Controllers/Api/v1/OrganizationController.php +27 -0
  193. package/server/src/Http/Controllers/Api/v1/PlaceController.php +2 -3
  194. package/server/src/Http/Controllers/Controller.php +9 -0
  195. package/server/src/Http/Controllers/FleetOpsController.php +7 -0
  196. package/server/src/Http/Controllers/Internal/v1/OrderConfigController.php +40 -233
  197. package/server/src/Http/Controllers/Internal/v1/OrderController.php +58 -28
  198. package/server/src/Http/Controllers/Internal/v1/SettingController.php +20 -0
  199. package/server/src/Http/Filter/OrderConfigFilter.php +13 -0
  200. package/server/src/Http/Requests/CreateIssueRequest.php +19 -0
  201. package/server/src/Http/Requests/Internal/CreateOrderConfigRequest.php +40 -0
  202. package/server/src/Http/Requests/Internal/CreateOrderRequest.php +66 -0
  203. package/server/src/Http/Requests/Internal/DeleteOrderConfigRequest.php +0 -0
  204. package/server/src/Http/Requests/UpdateIssueRequest.php +7 -0
  205. package/server/src/Http/Resources/v1/Order.php +3 -0
  206. package/server/src/Listeners/HandleOrderCanceled.php +8 -4
  207. package/server/src/Listeners/HandleOrderDispatched.php +14 -12
  208. package/server/src/Models/Order.php +527 -31
  209. package/server/src/Models/OrderConfig.php +467 -0
  210. package/server/src/Models/Payload.php +6 -7
  211. package/server/src/Notifications/OrderAssigned.php +1 -1
  212. package/server/src/Notifications/OrderCanceled.php +1 -1
  213. package/server/src/Notifications/OrderDispatchFailed.php +1 -1
  214. package/server/src/Notifications/OrderDispatched.php +1 -1
  215. package/server/src/Notifications/OrderPing.php +1 -1
  216. package/server/src/Observers/CompanyObserver.php +20 -0
  217. package/server/src/Providers/FleetOpsServiceProvider.php +4 -1
  218. package/server/src/Providers/NotificationServiceProvider.php +2 -1
  219. package/server/src/Support/FleetOps.php +137 -0
  220. package/server/src/Support/Utils.php +17 -0
  221. package/server/src/Traits/HasTrackingNumber.php +9 -9
  222. package/server/src/routes.php +19 -11
  223. package/translations/en-us.yaml +137 -0
  224. package/server/src/Flow/Config.php +0 -7
  225. package/server/src/Support/Flow.php +0 -653
@@ -9,10 +9,12 @@ use Fleetbase\FleetOps\Events\OrderCanceled;
9
9
  use Fleetbase\FleetOps\Events\OrderCompleted;
10
10
  use Fleetbase\FleetOps\Events\OrderDispatched;
11
11
  use Fleetbase\FleetOps\Events\OrderDriverAssigned;
12
- use Fleetbase\FleetOps\Support\Flow;
12
+ use Fleetbase\FleetOps\Flow\Activity;
13
13
  use Fleetbase\FleetOps\Support\Utils;
14
14
  use Fleetbase\FleetOps\Traits\HasTrackingNumber;
15
15
  use Fleetbase\LaravelMysqlSpatial\Types\Point;
16
+ use Fleetbase\Models\CustomField;
17
+ use Fleetbase\Models\CustomFieldValue;
16
18
  use Fleetbase\Models\Model;
17
19
  use Fleetbase\Models\Transaction;
18
20
  use Fleetbase\Traits\HasApiModelBehavior;
@@ -84,6 +86,7 @@ class Order extends Model
84
86
  'company_uuid',
85
87
  'session_uuid',
86
88
  'payload_uuid',
89
+ 'order_config_uuid',
87
90
  'transaction_uuid',
88
91
  'purchase_rate_uuid',
89
92
  'tracking_number_uuid',
@@ -239,6 +242,14 @@ class Order extends Model
239
242
  ])->render();
240
243
  }
241
244
 
245
+ /**
246
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
247
+ */
248
+ public function orderConfig()
249
+ {
250
+ return $this->belongsTo(OrderConfig::class)->withTrashed();
251
+ }
252
+
242
253
  /**
243
254
  * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
244
255
  */
@@ -271,14 +282,6 @@ class Order extends Model
271
282
  return $this->belongsTo(\Fleetbase\Models\Company::class);
272
283
  }
273
284
 
274
- /**
275
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
276
- */
277
- public function orderConfig()
278
- {
279
- return $this->hasOne(\Fleetbase\Models\Extension::class, 'key', 'type')->where('type', 'order_config');
280
- }
281
-
282
285
  /**
283
286
  * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
284
287
  */
@@ -332,7 +335,15 @@ class Order extends Model
332
335
  */
333
336
  public function customFields()
334
337
  {
335
- return $this->hasMany(\Fleetbase\Models\CustomField::class, 'subject_uuid')->orderBy('order');
338
+ return $this->hasMany(CustomField::class, 'subject_uuid')->orderBy('order');
339
+ }
340
+
341
+ /**
342
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
343
+ */
344
+ public function customFieldValues()
345
+ {
346
+ return $this->hasMany(CustomFieldValue::class, 'subject_uuid');
336
347
  }
337
348
 
338
349
  /**
@@ -599,36 +610,76 @@ class Order extends Model
599
610
  $this->attributes['status'] = is_string($status) ? Str::snake($status) : 'created';
600
611
  }
601
612
 
613
+ /**
614
+ * Checks if a driver is assigned to the order.
615
+ *
616
+ * @return bool returns true if a driver is assigned, false otherwise
617
+ */
602
618
  public function getHasDriverAssignedAttribute()
603
619
  {
604
620
  return (bool) $this->driver_assigned_uuid;
605
621
  }
606
622
 
623
+ /**
624
+ * Determines if the order is ready for dispatch.
625
+ * An order is ready for dispatch if it has a driver assigned or if it is marked as adhoc.
626
+ *
627
+ * @return bool returns true if the order is ready for dispatch, false otherwise
628
+ */
607
629
  public function getIsReadyForDispatchAttribute()
608
630
  {
609
631
  return $this->hasDrvierAssigned || $this->adhoc;
610
632
  }
611
633
 
634
+ /**
635
+ * Checks if the order is scheduled.
636
+ * Determines if a valid scheduled date and time is set for the order.
637
+ *
638
+ * @return bool returns true if the order is scheduled, false otherwise
639
+ */
612
640
  public function getIsScheduledAttribute(): bool
613
641
  {
614
642
  return !empty($this->scheduled_at) && Carbon::parse($this->scheduled_at)->isValid();
615
643
  }
616
644
 
645
+ /**
646
+ * Determines if the order is assigned to a driver but not yet dispatched.
647
+ *
648
+ * @return bool returns true if the order is assigned to a driver but not dispatched, false otherwise
649
+ */
617
650
  public function getIsAssignedNotDispatchedAttribute(): bool
618
651
  {
619
652
  return !empty($this->driver_assigned_uuid) && $this->dispatched_at === null;
620
653
  }
621
654
 
655
+ /**
656
+ * Checks if the order has not been dispatched.
657
+ *
658
+ * @return bool returns true if the order has not been dispatched, false otherwise
659
+ */
622
660
  public function getIsNotDispatchedAttribute(): bool
623
661
  {
624
662
  return $this->dispatched_at === null;
625
663
  }
626
664
 
665
+ /**
666
+ * Indicates whether the order is from an integrated vendor.
667
+ *
668
+ * @return bool returns true if the order is from an integrated vendor, false otherwise
669
+ */
627
670
  public function getIsIntegratedVendorOrderAttribute()
628
671
  {
629
672
  return $this->isIntegratedVendorOrder();
630
673
  }
631
674
 
675
+ /**
676
+ * Associates a given payload with the order.
677
+ * Sets the payload_uuid and updates the payload relationship for the order.
678
+ *
679
+ * @param Payload|null $payload the Payload instance to associate with the order
680
+ *
681
+ * @return Order the Order instance for method chaining
682
+ */
632
683
  public function setPayload(?Payload $payload): Order
633
684
  {
634
685
  $this->payload_uuid = $payload->uuid;
@@ -638,6 +689,15 @@ class Order extends Model
638
689
  return $this;
639
690
  }
640
691
 
692
+ /**
693
+ * Creates a new payload for the order with the provided attributes.
694
+ * Optionally sets the newly created payload as the payload of the order.
695
+ *
696
+ * @param array|null $attributes the attributes for creating the payload
697
+ * @param bool $setPayload whether to set the newly created payload as the order's payload
698
+ *
699
+ * @return Payload the newly created Payload instance
700
+ */
641
701
  public function createPayload(?array $attributes = [], bool $setPayload = true): Payload
642
702
  {
643
703
  // set payload type if not set
@@ -678,6 +738,15 @@ class Order extends Model
678
738
  return $payload;
679
739
  }
680
740
 
741
+ /**
742
+ * Inserts a new payload for the order into the database with the provided attributes.
743
+ * Optionally sets the inserted payload as the payload of the order.
744
+ *
745
+ * @param array|null $attributes the attributes for inserting the payload
746
+ * @param bool $setPayload whether to set the inserted payload as the order's payload
747
+ *
748
+ * @return Payload the inserted Payload instance
749
+ */
681
750
  public function insertPayload(?array $attributes = [], bool $setPayload = true): Payload
682
751
  {
683
752
  // set payload type if not set
@@ -737,6 +806,12 @@ class Order extends Model
737
806
  return $payload;
738
807
  }
739
808
 
809
+ /**
810
+ * Retrieves the payload associated with the order.
811
+ * If the payload is not already loaded, it loads the payload relationship.
812
+ *
813
+ * @return Payload|null the Payload model associated with the order
814
+ */
740
815
  public function getPayload()
741
816
  {
742
817
  if ($this->payload) {
@@ -748,6 +823,15 @@ class Order extends Model
748
823
  return $this->payload;
749
824
  }
750
825
 
826
+ /**
827
+ * Sets or updates the route for the order.
828
+ * If a Route instance is provided, it sets the order_uuid and saves the Route.
829
+ * Otherwise, it creates a new Route with the provided attributes.
830
+ *
831
+ * @param array|Route|null $attributes attributes for the route or a Route instance
832
+ *
833
+ * @return self the Order instance for method chaining
834
+ */
751
835
  public function setRoute(?array $attributes = [])
752
836
  {
753
837
  if (!$attributes) {
@@ -777,6 +861,12 @@ class Order extends Model
777
861
  return $this;
778
862
  }
779
863
 
864
+ /**
865
+ * Retrieves the current destination location for the order.
866
+ * It prioritizes dropoff location, then waypoints, and defaults to a zero-point if none are set.
867
+ *
868
+ * @return Point the current destination location as a Point instance
869
+ */
780
870
  public function getCurrentDestinationLocation()
781
871
  {
782
872
  if ($this->payload && $this->payload->dropoff) {
@@ -794,6 +884,12 @@ class Order extends Model
794
884
  return new Point(0, 0);
795
885
  }
796
886
 
887
+ /**
888
+ * Retrieves the last known location for the order.
889
+ * It checks the driver assigned location, then the pickup location, followed by waypoints.
890
+ *
891
+ * @return Point the last known location as a Point instance
892
+ */
797
893
  public function getLastLocation()
798
894
  {
799
895
  if ($this->driverAssigned && $this->driverAssigned->location) {
@@ -815,6 +911,15 @@ class Order extends Model
815
911
  return new Point(0, 0);
816
912
  }
817
913
 
914
+ /**
915
+ * Purchases a service quote for the order and creates a purchase rate.
916
+ * The purchase rate details are saved to the order.
917
+ *
918
+ * @param string $serviceQuoteId the UUID of the service quote
919
+ * @param array $meta additional metadata for the purchase
920
+ *
921
+ * @return bool returns true if the purchase rate is successfully saved
922
+ */
818
923
  public function purchaseQuote(string $serviceQuoteId, $meta = [])
819
924
  {
820
925
  // $serviceQuote = ServiceQuote::where('uuid', $serviceQuoteId)->first();
@@ -834,6 +939,15 @@ class Order extends Model
834
939
  return $this->save();
835
940
  }
836
941
 
942
+ /**
943
+ * Purchases a service quote for the order, or creates a transaction without a service quote if none is provided.
944
+ * The function handles different types of service quote identifiers and creates a purchase rate accordingly.
945
+ *
946
+ * @param mixed $serviceQuote the service quote or its identifier
947
+ * @param array $meta additional metadata for the purchase
948
+ *
949
+ * @return self|bool the Order instance for method chaining, or false on failure
950
+ */
837
951
  public function purchaseServiceQuote($serviceQuote, $meta = [])
838
952
  {
839
953
  if (!$serviceQuote) {
@@ -870,6 +984,12 @@ class Order extends Model
870
984
  return false;
871
985
  }
872
986
 
987
+ /**
988
+ * Creates a transaction for the order without a service quote.
989
+ * This method is used when an order is made without selecting a specific service quote.
990
+ *
991
+ * @return Transaction|null the created Transaction model or null on failure
992
+ */
873
993
  public function createOrderTransactionWithoutServiceQuote(): ?Transaction
874
994
  {
875
995
  $transaction = null;
@@ -898,6 +1018,13 @@ class Order extends Model
898
1018
  return $transaction;
899
1019
  }
900
1020
 
1021
+ /**
1022
+ * Determines if the order should be dispatched based on the scheduled time and a precision interval.
1023
+ *
1024
+ * @param int $precision the number of minutes before and after the scheduled time to consider for dispatching
1025
+ *
1026
+ * @return bool returns true if the order should be dispatched, false otherwise
1027
+ */
901
1028
  public function shouldDispatch($precision = 1)
902
1029
  {
903
1030
  $min = Carbon::now()->subMinutes($precision);
@@ -906,6 +1033,14 @@ class Order extends Model
906
1033
  return !$this->dispatched && Carbon::fromString($this->scheduled_at)->between($min, $max);
907
1034
  }
908
1035
 
1036
+ /**
1037
+ * Dispatches the order.
1038
+ * Sets the dispatched flag and dispatched_at timestamp. Optionally saves the order and flushes attribute cache.
1039
+ *
1040
+ * @param bool $save whether to save the order after dispatching
1041
+ *
1042
+ * @return mixed the result of the OrderDispatched event
1043
+ */
909
1044
  public function dispatch($save = true)
910
1045
  {
911
1046
  $this->dispatched = true;
@@ -919,10 +1054,16 @@ class Order extends Model
919
1054
  return event(new OrderDispatched($this));
920
1055
  }
921
1056
 
1057
+ /**
1058
+ * Inserts a dispatch activity into the order.
1059
+ * Retrieves and applies a dispatch activity specific to the order.
1060
+ *
1061
+ * @return Order the updated Order instance
1062
+ */
922
1063
  public function insertDispatchActivity(): Order
923
1064
  {
924
1065
  // get dispatch activity if any and apply to order
925
- $dispatchActivity = Flow::getDispatchActivity($this);
1066
+ $dispatchActivity = $this->config()->getDispatchActivity();
926
1067
 
927
1068
  if ($dispatchActivity) {
928
1069
  $this->updateActivity($dispatchActivity);
@@ -931,6 +1072,12 @@ class Order extends Model
931
1072
  return $this;
932
1073
  }
933
1074
 
1075
+ /**
1076
+ * Dispatches the order and inserts a dispatch activity.
1077
+ * Combines the functionalities of dispatching the order and inserting a dispatch activity.
1078
+ *
1079
+ * @return Order the updated Order instance
1080
+ */
934
1081
  public function dispatchWithActivity(): Order
935
1082
  {
936
1083
  $this->dispatch();
@@ -939,6 +1086,12 @@ class Order extends Model
939
1086
  return $this;
940
1087
  }
941
1088
 
1089
+ /**
1090
+ * Dispatches the order only if it hasn't been dispatched yet.
1091
+ * A check is performed before dispatching the order.
1092
+ *
1093
+ * @return Order the updated Order instance
1094
+ */
942
1095
  public function firstDispatch(): Order
943
1096
  {
944
1097
  if ($this->dispatched) {
@@ -948,6 +1101,12 @@ class Order extends Model
948
1101
  return $this;
949
1102
  }
950
1103
 
1104
+ /**
1105
+ * Dispatches the order with activity only if it hasn't been dispatched yet.
1106
+ * A check is performed before dispatching the order and inserting the dispatch activity.
1107
+ *
1108
+ * @return Order the updated Order instance
1109
+ */
951
1110
  public function firstDispatchWithActivity(): Order
952
1111
  {
953
1112
  if ($this->dispatched) {
@@ -957,6 +1116,12 @@ class Order extends Model
957
1116
  return $this;
958
1117
  }
959
1118
 
1119
+ /**
1120
+ * Cancels the order.
1121
+ * Sets the order status to 'canceled' and handles cancellation for integrated vendor orders.
1122
+ *
1123
+ * @return mixed the result of the OrderCanceled event
1124
+ */
960
1125
  public function cancel()
961
1126
  {
962
1127
  $this->status = 'canceled';
@@ -972,6 +1137,12 @@ class Order extends Model
972
1137
  return event(new OrderCanceled($this));
973
1138
  }
974
1139
 
1140
+ /**
1141
+ * Notifies that a driver has been assigned to the order.
1142
+ * Triggers an event when a driver is assigned to the order.
1143
+ *
1144
+ * @return mixed the result of the OrderDriverAssigned event, if a driver is assigned
1145
+ */
975
1146
  public function notifyDriverAssigned()
976
1147
  {
977
1148
  if ($this->driver_assigned_uuid) {
@@ -979,33 +1150,97 @@ class Order extends Model
979
1150
  }
980
1151
  }
981
1152
 
982
- public function updateActivity(?array $activity = null, $proof = null): Order
1153
+ /**
1154
+ * Updates the activity of the order.
1155
+ * Updates the order status and inserts a new activity based on the provided activity details.
1156
+ *
1157
+ * @param Activity $activity the activity details to be updated
1158
+ * @param mixed $proof additional proof or details for the activity update
1159
+ *
1160
+ * @return Order the updated Order instance
1161
+ */
1162
+ public function updateActivity(?Activity $activity = null, $proof = null): Order
983
1163
  {
984
- $status = data_get($activity, 'status');
985
- $details = data_get($activity, 'details', '');
986
- $code = data_get($activity, 'code', 'dispatched');
1164
+ if (!Utils::isActivity($activity)) {
1165
+ return $this;
1166
+ }
1167
+
1168
+ // Get location
987
1169
  $location = $this->getLastLocation();
988
1170
 
989
- // insert dispatch activity
990
- $this->insertActivity($status, $details, $location, $code, $proof);
1171
+ // Insert dispatch activity
1172
+ $this->insertActivity($activity, $location, $proof);
991
1173
 
992
- // update status using code
993
- $this->setStatus($code, true);
1174
+ // Update status using code
1175
+ $this->setStatus($activity->get('code'), true);
1176
+
1177
+ // Fire activity events
1178
+ $activity->fireEvents($this);
994
1179
 
995
1180
  return $this;
996
1181
  }
997
1182
 
1183
+ /**
1184
+ * Notifies that the order has been completed.
1185
+ * Triggers an event indicating the completion of the order.
1186
+ *
1187
+ * @return mixed the result of the OrderCompleted event
1188
+ */
998
1189
  public function notifyCompleted()
999
1190
  {
1000
1191
  return event(new OrderCompleted($this));
1001
1192
  }
1002
1193
 
1194
+ /**
1195
+ * Completes the order and updates its activities.
1196
+ *
1197
+ * This method is responsible for marking the order as completed. It achieves this by
1198
+ * creating a new 'completed' Activity instance and updating the order's status and activities
1199
+ * accordingly. Additionally, this method triggers a notification to indicate that the order
1200
+ * has been completed. Optionally, proof or additional details can be provided to accompany
1201
+ * the activity update.
1202
+ *
1203
+ * The process involves the following steps:
1204
+ * 1. Creating a new Activity instance with the 'completed' code and relevant details.
1205
+ * 2. Notifying that the order has been completed via `notifyCompleted`.
1206
+ * 3. Updating the order's activity with the new 'completed' activity through `updateActivity`.
1207
+ *
1208
+ * @param Proof|null $proof Optional. Additional proof or details for the activity update.
1209
+ *
1210
+ * @return Order the order instance with updated activities, reflecting the completion status
1211
+ */
1212
+ public function complete(?Proof $proof = null): self
1213
+ {
1214
+ $this->notifyCompleted();
1215
+
1216
+ $doesntHaveCompletedActivity = TrackingStatus::where(['tracking_number_uuid' => $this->tracking_number_uuid, 'code' => 'COMPLETED'])->doesntExist();
1217
+ if ($doesntHaveCompletedActivity) {
1218
+ $activity = $this->config()->getCompletedActivity();
1219
+
1220
+ return $this->updateActivity($activity, $proof);
1221
+ }
1222
+
1223
+ return $this;
1224
+ }
1225
+
1226
+ /**
1227
+ * Sets the customer for the order.
1228
+ * Updates the customer_uuid and customer_type attributes based on the provided model.
1229
+ *
1230
+ * @param Model $model the customer model to set for the order
1231
+ */
1003
1232
  public function setCustomer($model)
1004
1233
  {
1005
1234
  $this->customer_uuid = $model->uuid;
1006
- $this->customer_type = Utils::getModelClassName($model);
1235
+ $this->customer_type = Utils::getMutationType($model);
1007
1236
  }
1008
1237
 
1238
+ /**
1239
+ * Sets the customer type attribute for the order.
1240
+ * Transforms and sets the customer type attribute based on specific string handling rules.
1241
+ *
1242
+ * @param string $type the customer type to be set
1243
+ */
1009
1244
  public function setCustomerTypeAttribute($type)
1010
1245
  {
1011
1246
  if (is_string($type)) {
@@ -1023,6 +1258,12 @@ class Order extends Model
1023
1258
  }
1024
1259
  }
1025
1260
 
1261
+ /**
1262
+ * Sets the facilitator type attribute for the order.
1263
+ * Transforms and sets the facilitator type attribute based on specific string handling rules.
1264
+ *
1265
+ * @param string $type the facilitator type to be set
1266
+ */
1026
1267
  public function setFacilitatorTypeAttribute($type)
1027
1268
  {
1028
1269
  if (is_string($type)) {
@@ -1040,6 +1281,12 @@ class Order extends Model
1040
1281
  }
1041
1282
  }
1042
1283
 
1284
+ /**
1285
+ * Sets the pickup location of the payload to the driver's current location.
1286
+ * Optionally forces the update or sets the location based on specific order conditions.
1287
+ *
1288
+ * @param bool $force whether to force the update of the pickup location
1289
+ */
1043
1290
  public function setDriverLocationAsPickup($force = false)
1044
1291
  {
1045
1292
  if ($force === true) {
@@ -1061,11 +1308,24 @@ class Order extends Model
1061
1308
  }
1062
1309
  }
1063
1310
 
1311
+ /**
1312
+ * Determines if the pickup location is set to be from the driver's current location.
1313
+ *
1314
+ * @return bool returns true if the pickup location should be the driver's current location, false otherwise
1315
+ */
1064
1316
  public function isPickupIsFromDriverLocation()
1065
1317
  {
1066
1318
  return $this->payload instanceof Payload && $this->payload->hasMeta('pickup_is_driver_location');
1067
1319
  }
1068
1320
 
1321
+ /**
1322
+ * Updates the status of the order.
1323
+ * Allows updating multiple statuses or a specific status based on a code or the order's flow.
1324
+ *
1325
+ * @param string|array|null $code the status code(s) to update the order status to
1326
+ *
1327
+ * @return bool returns true if the status is successfully updated, false otherwise
1328
+ */
1069
1329
  public function updateStatus($code = null)
1070
1330
  {
1071
1331
  // update multiple status codes
@@ -1075,7 +1335,7 @@ class Order extends Model
1075
1335
  });
1076
1336
  }
1077
1337
 
1078
- $flow = Flow::getOrderFlow($this);
1338
+ $flow = $this->config()->nextActivity();
1079
1339
  $activity = null;
1080
1340
 
1081
1341
  if (count($flow) === 1 && $code === null) {
@@ -1083,33 +1343,38 @@ class Order extends Model
1083
1343
  }
1084
1344
 
1085
1345
  if ($code) {
1086
- $activity = collect($flow)->firstWhere('code', $code);
1346
+ $activity = $flow->firstWhere('code', $code);
1087
1347
  }
1088
1348
 
1089
- if (!$activity) {
1349
+ if (!Utils::isActivity($activity)) {
1090
1350
  return false;
1091
1351
  }
1092
1352
 
1093
- $isDispatchActivity = is_array($activity) && $activity['code'] === 'dispatched';
1353
+ $isDispatchActivity = Utils::isActivity($activity) && $activity->is('dispatched');
1094
1354
  $isReadyForDispatch = $this->isReadyForDispatch;
1095
1355
 
1096
1356
  if ($isDispatchActivity && $isReadyForDispatch) {
1097
1357
  $this->dispatch(true);
1098
1358
  }
1099
1359
 
1100
- // edge case if not dispatched but code is dispatched/dispatch
1101
- if (!$this->dispatched && Str::startsWith($code, 'dispatch')) {
1102
- $this->dispatch(true);
1103
- }
1104
-
1105
1360
  $location = $this->getLastLocation();
1106
1361
 
1107
- $this->setStatus($activity['code']);
1108
- $this->insertActivity($activity['status'], $activity['details'], $location, $activity['code']);
1362
+ $this->setStatus($activity->code);
1363
+ $this->insertActivity($activity, $location);
1364
+
1365
+ // fire events if any
1366
+ $activity->fireEvents($this);
1109
1367
 
1110
1368
  return true;
1111
1369
  }
1112
1370
 
1371
+ /**
1372
+ * Checks if the specified driver is assigned to the order.
1373
+ *
1374
+ * @param mixed $driver the driver instance, UUID, or public ID to check against
1375
+ *
1376
+ * @return bool returns true if the specified driver is assigned to the order, false otherwise
1377
+ */
1113
1378
  public function isDriver($driver)
1114
1379
  {
1115
1380
  if ($driver instanceof Driver) {
@@ -1123,6 +1388,16 @@ class Order extends Model
1123
1388
  return $driver === $this->driverAssigned;
1124
1389
  }
1125
1390
 
1391
+ /**
1392
+ * Assigns a driver to the order.
1393
+ * Sets the driver_assigned_uuid and updates the related relationships.
1394
+ * Optionally notifies about the driver assignment.
1395
+ *
1396
+ * @param mixed $driver the driver instance or identifier to assign
1397
+ * @param bool $silent whether to suppress the notification of the driver assignment
1398
+ *
1399
+ * @return Order the updated Order instance
1400
+ */
1126
1401
  public function assignDriver($driver, $silent = false)
1127
1402
  {
1128
1403
  if ($driver instanceof Driver) {
@@ -1155,6 +1430,12 @@ class Order extends Model
1155
1430
  return $this;
1156
1431
  }
1157
1432
 
1433
+ /**
1434
+ * Retrieves the current origin position for the order.
1435
+ * The origin is either the driver's current location or the payload's pickup/current waypoint.
1436
+ *
1437
+ * @return Point|null the current origin position as a Point instance, or null if not set
1438
+ */
1158
1439
  public function getCurrentOriginPosition()
1159
1440
  {
1160
1441
  if ($this->hasDriverAssigned) {
@@ -1179,6 +1460,12 @@ class Order extends Model
1179
1460
  return $origin ? $origin->location : null;
1180
1461
  }
1181
1462
 
1463
+ /**
1464
+ * Retrieves the destination position for the order.
1465
+ * The destination is either the payload's dropoff or the last waypoint.
1466
+ *
1467
+ * @return Point|null the destination position as a Point instance, or null if not set
1468
+ */
1182
1469
  public function getDestinationPosition()
1183
1470
  {
1184
1471
  $destination = null;
@@ -1190,6 +1477,12 @@ class Order extends Model
1190
1477
  return $destination ? $destination->location : null;
1191
1478
  }
1192
1479
 
1480
+ /**
1481
+ * Sets the preliminary distance and time for the order.
1482
+ * Uses a utility method to calculate the distance and time between the current origin and destination positions.
1483
+ *
1484
+ * @return Order the updated Order instance
1485
+ */
1193
1486
  public function setPreliminaryDistanceAndTime()
1194
1487
  {
1195
1488
  $origin = $this->getCurrentOriginPosition();
@@ -1206,6 +1499,12 @@ class Order extends Model
1206
1499
  return $this;
1207
1500
  }
1208
1501
 
1502
+ /**
1503
+ * Sets the accurate distance and time for the order based on driving distance.
1504
+ * Uses a utility method to calculate the driving distance and time between the current origin and destination positions.
1505
+ *
1506
+ * @return Order the updated Order instance
1507
+ */
1209
1508
  public function setDistanceAndTime(): Order
1210
1509
  {
1211
1510
  $origin = $this->getCurrentOriginPosition();
@@ -1222,13 +1521,210 @@ class Order extends Model
1222
1521
  return $this;
1223
1522
  }
1224
1523
 
1524
+ /**
1525
+ * Determines if the order is from an integrated vendor.
1526
+ *
1527
+ * @return bool returns true if the order is from an integrated vendor, false otherwise
1528
+ */
1225
1529
  public function isIntegratedVendorOrder()
1226
1530
  {
1227
1531
  return $this->facilitator_is_integrated_vendor === true;
1228
1532
  }
1229
1533
 
1534
+ /**
1535
+ * Retrieves the adhoc ping distance for the order.
1536
+ * Defaults to a specified value or a configuration setting.
1537
+ *
1538
+ * @return int the adhoc ping distance in meters
1539
+ */
1230
1540
  public function getAdhocPingDistance(): int
1231
1541
  {
1232
1542
  return (int) Utils::get($this, 'adhoc_distance', Utils::get($this, 'company.options.fleetops.adhoc_distance', 6000));
1233
1543
  }
1544
+
1545
+ /**
1546
+ * Retrieves a custom field by its key.
1547
+ *
1548
+ * This method searches for a custom field where the name or label matches the given key.
1549
+ *
1550
+ * @param string $key the key used to search for the custom field
1551
+ *
1552
+ * @return CustomField|null the found CustomField object or null if not found
1553
+ */
1554
+ public function getCustomField(string $key): ?CustomField
1555
+ {
1556
+ $name = Str::slug($key);
1557
+ $label = Str::title($key);
1558
+
1559
+ return $this->customFields()->where('name', $name)->orWhere('label', $label)->first();
1560
+ }
1561
+
1562
+ /**
1563
+ * Retrieves the custom field value for the specified custom field.
1564
+ *
1565
+ * @param CustomField $customField the custom field to retrieve the value for
1566
+ *
1567
+ * @return CustomFieldValue|null the custom field value, or null if not found
1568
+ */
1569
+ public function getCustomFieldValue(CustomField $customField): ?CustomFieldValue
1570
+ {
1571
+ $customFieldValue = $this->customFieldValues()->where('custom_field_uuid', $customField->uuid)->first();
1572
+ if ($customFieldValue) {
1573
+ return $customFieldValue;
1574
+ }
1575
+
1576
+ return null;
1577
+ }
1578
+
1579
+ /**
1580
+ * Retrieves the value of a custom field by its key.
1581
+ *
1582
+ * @param string $key the key of the custom field
1583
+ *
1584
+ * @return mixed|null the value of the custom field, or null if not found
1585
+ */
1586
+ public function getCustomFieldValueByKey(string $key)
1587
+ {
1588
+ $customField = $this->getCustomField($key);
1589
+ if ($customField) {
1590
+ $customFieldValue = $this->getCustomFieldValue($customField);
1591
+ if ($customFieldValue) {
1592
+ return $customFieldValue->value;
1593
+ }
1594
+ }
1595
+
1596
+ return null;
1597
+ }
1598
+
1599
+ /**
1600
+ * Checks if a custom field exists.
1601
+ *
1602
+ * @param string $key the key of the custom field
1603
+ */
1604
+ public function isCustomField(string $key): bool
1605
+ {
1606
+ $name = Str::slug($key);
1607
+ $label = Str::title($key);
1608
+
1609
+ return $this->customFields()->where('name', $name)->orWhere('label', $label)->exists();
1610
+ }
1611
+
1612
+ /**
1613
+ * Retrieves all custom field values associated with the order.
1614
+ *
1615
+ * @return array an array of custom field values
1616
+ */
1617
+ public function getCustomFieldValues(): array
1618
+ {
1619
+ $customFields = [];
1620
+ foreach ($this->customFieldValues as $customFieldValue) {
1621
+ $key = Str::snake(strtolower($customFieldValue->custom_field_label));
1622
+ if ($key) {
1623
+ $customFields[$key] = $customFieldValue->value;
1624
+ }
1625
+ }
1626
+
1627
+ return $customFields;
1628
+ }
1629
+
1630
+ /**
1631
+ * Retrieves the OrderConfig associated with this order.
1632
+ *
1633
+ * This function first attempts to load the 'orderConfig' relationship.
1634
+ * If 'orderConfig' is already loaded and is an instance of OrderConfig,
1635
+ * it returns this instance. If not, and if the 'order_config_uuid' is
1636
+ * a valid UUID, it attempts to retrieve the OrderConfig by this UUID,
1637
+ * including any trashed instances. If none of these conditions are met,
1638
+ * it returns null.
1639
+ *
1640
+ * @return OrderConfig|null the OrderConfig associated with this order, or null if not found
1641
+ *
1642
+ * @throws \Exception type of exceptions this function might throw, if any
1643
+ */
1644
+ public function config(): OrderConfig
1645
+ {
1646
+ $this->load(['orderConfig']);
1647
+
1648
+ if ($this->orderConfig instanceof OrderConfig) {
1649
+ $this->orderConfig->setOrderContext($this);
1650
+
1651
+ return $this->orderConfig;
1652
+ }
1653
+
1654
+ if (Str::isUuid($this->order_config_uuid)) {
1655
+ $orderConfig = OrderConfig::where('uuid', $this->order_config_uuid)->withTrashed()->first();
1656
+ $orderConfig->setOrderContext($this);
1657
+
1658
+ return $orderConfig;
1659
+ }
1660
+
1661
+ return null;
1662
+ }
1663
+
1664
+ /**
1665
+ * Retrieves the flow configuration from the order config.
1666
+ *
1667
+ * This method accesses the order config and returns its 'flow' property.
1668
+ * The flow property is expected to be an array that outlines the sequence or
1669
+ * structure of activities or steps in the order process. If the flow property
1670
+ * is not an array or is not set, an empty array is returned.
1671
+ *
1672
+ * @return array the flow configuration array from the order config, or an empty array if not set or not an array
1673
+ */
1674
+ public function getConfigFlow(): array
1675
+ {
1676
+ $orderConfig = $this->config();
1677
+ if (is_array($orderConfig->flow)) {
1678
+ return $orderConfig->flow;
1679
+ }
1680
+
1681
+ return [];
1682
+ }
1683
+
1684
+ /**
1685
+ * Resolves a given value which can be a static value or a dynamic property name.
1686
+ *
1687
+ * This method attempts to resolve the dynamic property first, if not found it returns the given value.
1688
+ *
1689
+ * @return mixed the resolved value, or the input value if the resolution finds nothing
1690
+ */
1691
+ public function resolveDynamicProperty(string $property)
1692
+ {
1693
+ $snakedProperty = Str::snake($property);
1694
+
1695
+ // check if existing property
1696
+ if ($this->{$snakedProperty}) {
1697
+ return $this->{$snakedProperty};
1698
+ }
1699
+
1700
+ // Check if custom field property
1701
+ if ($this->isCustomField($property)) {
1702
+ return $this->getCustomFieldValueByKey($property);
1703
+ }
1704
+
1705
+ // Check if meta attribute
1706
+ if ($this->hasMeta($property)) {
1707
+ return $this->getMeta($property);
1708
+ }
1709
+
1710
+ return data_get($this, $property);
1711
+ }
1712
+
1713
+ /**
1714
+ * Resolves the value of a dynamic property.
1715
+ *
1716
+ * This method attempts to resolve the property from the object, then as a custom field, and finally as a meta attribute.
1717
+ * If none of these are found, it returns the value using the `data_get` helper function.
1718
+ *
1719
+ * @return mixed the resolved value of the property, or the original property if not found
1720
+ */
1721
+ public function resolveDynamicValue(string $value)
1722
+ {
1723
+ $resolved = $this->resolveDynamicProperty($value);
1724
+ if ($resolved) {
1725
+ return $resolved;
1726
+ }
1727
+
1728
+ return $value;
1729
+ }
1234
1730
  }