@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.
- package/.php-cs-fixer.php +2 -0
- package/addon/components/activity-event-selector.hbs +35 -0
- package/addon/components/activity-event-selector.js +85 -0
- package/addon/components/activity-form-panel.hbs +23 -0
- package/addon/components/activity-form-panel.js +90 -0
- package/addon/components/activity-logic-builder.hbs +80 -0
- package/addon/components/activity-logic-builder.js +260 -0
- package/addon/components/contact-form-panel.hbs +1 -1
- package/addon/components/contact-panel.hbs +1 -1
- package/addon/components/custom-entity-form-panel.hbs +43 -0
- package/addon/components/custom-entity-form-panel.js +129 -0
- package/addon/components/custom-field-form-panel/options-input.hbs +12 -0
- package/addon/components/custom-field-form-panel/options-input.js +139 -0
- package/addon/components/custom-field-form-panel.hbs +77 -0
- package/addon/components/custom-field-form-panel.js +144 -0
- package/addon/components/custom-field.hbs +63 -41
- package/addon/components/custom-field.js +123 -25
- package/addon/components/driver-form-panel.hbs +1 -1
- package/addon/components/driver-panel.hbs +1 -1
- package/addon/components/edit-order-route-panel.hbs +1 -1
- package/addon/components/fleet-form-panel.hbs +1 -1
- package/addon/components/fleet-panel.hbs +1 -1
- package/addon/components/fuel-report-form-panel.hbs +1 -1
- package/addon/components/fuel-report-panel.hbs +1 -1
- package/addon/components/issue-form-panel.hbs +1 -1
- package/addon/components/issue-panel.hbs +1 -1
- package/addon/components/joint-graph.hbs +1 -0
- package/addon/components/joint-graph.js +103 -0
- package/addon/components/layout/fleet-ops-sidebar.hbs +3 -3
- package/addon/components/layout/fleet-ops-sidebar.js +1 -0
- package/addon/components/live-map.js +71 -28
- package/addon/components/modals/new-custom-field-group.hbs +5 -0
- package/addon/components/modals/new-order-config.hbs +3 -3
- package/addon/components/modals/order-new-activity.hbs +1 -1
- package/addon/components/order-config-manager/activity-flow.hbs +11 -0
- package/addon/components/order-config-manager/activity-flow.js +964 -0
- package/addon/components/order-config-manager/custom-fields.hbs +50 -0
- package/addon/components/order-config-manager/custom-fields.js +276 -0
- package/addon/components/order-config-manager/details.hbs +23 -0
- package/addon/components/order-config-manager/details.js +97 -0
- package/addon/components/order-config-manager/entities.hbs +54 -0
- package/addon/components/order-config-manager/entities.js +227 -0
- package/addon/components/order-config-manager-overlay.hbs +26 -0
- package/addon/components/order-config-manager-overlay.js +60 -0
- package/addon/components/order-config-manager.hbs +15 -0
- package/addon/components/order-config-manager.js +285 -0
- package/addon/components/order-flow.hbs +1 -0
- package/addon/components/order-flow.js +3 -0
- package/addon/components/place-form-panel.hbs +1 -1
- package/addon/components/place-panel.hbs +1 -1
- package/addon/components/vehicle-form-panel.hbs +1 -1
- package/addon/components/vehicle-panel.hbs +1 -1
- package/addon/components/vendor-form-panel.hbs +1 -1
- package/addon/components/vendor-panel.hbs +1 -1
- package/addon/controllers/application.js +5 -1
- package/addon/controllers/operations/order-config.js +42 -0
- package/addon/controllers/operations/orders/index/new.js +125 -21
- package/addon/controllers/operations/orders/index/view.js +87 -4
- package/addon/controllers/operations/orders/index.js +2 -2
- package/addon/engine.js +10 -1
- package/addon/initializers/load-jointjs.js +16 -0
- package/addon/routes/application.js +1 -1
- package/addon/routes/operations/order-config.js +28 -0
- package/addon/routes/operations/orders/index/new.js +2 -3
- package/addon/routes/operations/orders/index/view.js +1 -1
- package/addon/routes.js +1 -0
- package/addon/services/context-panel.js +65 -3
- package/addon/styles/fleetops-engine.css +268 -0
- package/addon/templates/application.hbs +1 -1
- package/addon/templates/operations/order-config.hbs +55 -0
- package/addon/templates/operations/orders/index/new.hbs +98 -339
- package/addon/templates/operations/orders/index/view.hbs +36 -96
- package/addon/templates/operations/orders/index.hbs +0 -1
- package/addon/utils/apply-context-component-arguments.js +4 -2
- package/addon/utils/create-custom-entity.js +22 -0
- package/addon/utils/create-flow-activity.js +31 -0
- package/addon/utils/get-custom-field-type-map.js +34 -0
- package/app/components/activity-event-selector.js +1 -0
- package/app/components/activity-form-panel.js +1 -0
- package/app/components/activity-logic-builder.js +1 -0
- package/app/components/custom-entity-form-panel.js +1 -0
- package/app/components/custom-field-form-panel/options-input.js +1 -0
- package/app/components/custom-field-form-panel.js +1 -0
- package/app/components/joint-graph.js +1 -0
- package/app/components/modals/new-custom-field-group.js +1 -0
- package/app/components/order-config-manager/activity-flow.js +1 -0
- package/app/components/order-config-manager/custom-fields.js +1 -0
- package/app/components/order-config-manager/details.js +1 -0
- package/app/components/order-config-manager/entities.js +1 -0
- package/app/components/order-config-manager-overlay.js +1 -0
- package/app/components/order-config-manager.js +1 -0
- package/app/components/order-flow.js +1 -0
- package/app/controllers/operations/order-config.js +1 -0
- package/app/routes/operations/order-config.js +1 -0
- package/app/templates/operations/order-config.js +1 -0
- package/app/utils/create-custom-entity.js +1 -0
- package/app/utils/create-flow-activity.js +1 -0
- package/app/utils/get-custom-field-type-map.js +1 -0
- package/composer.json +4 -3
- package/config/environment.js +1 -0
- package/extension.json +1 -1
- package/index.js +20 -0
- package/package.json +7 -5
- package/server/migrations/2023_04_27_053456_create_contacts_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_drivers_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_entities_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_fleet_drivers_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_fleets_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_fuel_reports_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_integrated_vendors_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_issues_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_orders_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_payloads_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_places_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_positions_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_proofs_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_purchase_rates_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_routes_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_service_areas_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_service_quote_items_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_service_quotes_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_service_rate_fees_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_service_rate_parcel_fees_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_service_rates_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_tracking_numbers_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_tracking_statuses_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_vehicles_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_vendors_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_waypoints_table.php +1 -2
- package/server/migrations/2023_04_27_053456_create_zones_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_companies_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_contacts_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_drivers_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_entities_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleet_drivers_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleets_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fuel_reports_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_integrated_vendors_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_issues_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_orders_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_payloads_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_places_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_positions_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_proofs_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_purchase_rates_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_routes_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_areas_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quote_items_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quotes_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_fees_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_parcel_fees_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rates_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_numbers_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_statuses_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vehicles_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vendors_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_waypoints_table.php +1 -2
- package/server/migrations/2023_04_27_053459_add_foreign_keys_to_zones_table.php +1 -2
- package/server/migrations/2023_09_14_074512_update_vehicles_table.php +1 -2
- package/server/migrations/2023_09_14_074619_create_vehicle_devices_table.php +35 -36
- package/server/migrations/2023_09_26_071205_add_online_column_to_vehicles_table.php +1 -2
- package/server/migrations/2023_09_26_083957_create_fleet_vehicles_table.php +1 -2
- package/server/migrations/2023_09_27_023757_add_column_to_fleets_table.php +1 -2
- package/server/migrations/2023_10_05_074811_update_vehicle.php +1 -2
- package/server/migrations/2023_10_25_093014_create_vehicle_device_events_table.php +1 -2
- package/server/migrations/2023_11_03_072503_refactor_issues_table_columns.php +1 -2
- package/server/migrations/2023_11_06_040645_refactor_fuel_reports_table.php +1 -2
- package/server/migrations/2023_11_09_041807_add_status_column_to_fuel_reports_table.php +1 -2
- package/server/migrations/2023_11_15_062814_add_comments_column_and_resolved_at_column_to_vehicle_device_events_table.php +1 -2
- package/server/migrations/2023_11_17_053001_add_category_uuid_to_entities_table.php +1 -2
- package/server/migrations/2023_11_28_074244_add_supplier_uuid_column_to_entities_table.php +1 -2
- package/server/migrations/2023_12_14_100209_add_meta_column_on_driver_table copy.php +1 -2
- package/server/migrations/2024_02_18_100209_add_avatar_url_columns_table.php +3 -4
- package/server/migrations/2024_02_27_093648_create_order_configs_table.php +43 -0
- package/server/migrations/2024_03_07_075508_add_order_config_uuid_column_to_orders_table.php +28 -0
- package/server/seeders/OrderConfigSeeder.php +151 -0
- package/server/src/Casts/OrderConfigEntities.php +53 -0
- package/server/src/Console/Commands/FixLegacyOrderConfigs.php +66 -0
- package/server/src/Events/DriverLocationChanged.php +1 -1
- package/server/src/Events/DriverSimulatedLocationChanged.php +1 -1
- package/server/src/Expansions/UserExpansion.php +4 -4
- package/server/src/Flow/Activity.php +232 -6
- package/server/src/Flow/Condition.php +84 -0
- package/server/src/Flow/Event.php +88 -0
- package/server/src/Flow/Flow.php +50 -0
- package/server/src/Flow/FlowResource.php +143 -0
- package/server/src/Flow/Logic.php +57 -1
- package/server/src/Http/Controllers/Api/v1/DriverController.php +2 -2
- package/server/src/Http/Controllers/Api/v1/IssueController.php +132 -0
- package/server/src/Http/Controllers/Api/v1/OrderController.php +130 -57
- package/server/src/Http/Controllers/Api/v1/OrganizationController.php +27 -0
- package/server/src/Http/Controllers/Api/v1/PlaceController.php +2 -3
- package/server/src/Http/Controllers/Controller.php +9 -0
- package/server/src/Http/Controllers/FleetOpsController.php +7 -0
- package/server/src/Http/Controllers/Internal/v1/OrderConfigController.php +5 -259
- package/server/src/Http/Controllers/Internal/v1/OrderController.php +56 -35
- package/server/src/Http/Controllers/Internal/v1/SettingController.php +20 -0
- package/server/src/Http/Filter/OrderConfigFilter.php +13 -0
- package/server/src/Http/Requests/CreateIssueRequest.php +19 -0
- package/server/src/Http/Requests/UpdateIssueRequest.php +7 -0
- package/server/src/Http/Resources/v1/Order.php +3 -0
- package/server/src/Http/Resources/v1/Payload.php +1 -1
- package/server/src/Listeners/HandleOrderCanceled.php +8 -4
- package/server/src/Listeners/HandleOrderDispatched.php +14 -12
- package/server/src/Models/Order.php +527 -31
- package/server/src/Models/OrderConfig.php +419 -0
- package/server/src/Models/Payload.php +8 -7
- package/server/src/Notifications/OrderAssigned.php +1 -1
- package/server/src/Notifications/OrderCanceled.php +1 -1
- package/server/src/Notifications/OrderDispatchFailed.php +1 -1
- package/server/src/Notifications/OrderDispatched.php +1 -1
- package/server/src/Notifications/OrderPing.php +1 -1
- package/server/src/Providers/FleetOpsServiceProvider.php +3 -1
- package/server/src/Providers/NotificationServiceProvider.php +2 -1
- package/server/src/Support/Utils.php +17 -0
- package/server/src/Traits/HasTrackingNumber.php +9 -9
- package/server/src/routes.php +19 -11
- package/translations/en-us.yaml +137 -0
- package/server/src/Flow/Config.php +0 -7
- package/server/src/Support/Flow.php +0 -653
|
@@ -1,653 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
namespace Fleetbase\FleetOps\Support;
|
|
4
|
-
|
|
5
|
-
use Fleetbase\FleetOps\Models\Driver;
|
|
6
|
-
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
-
use Fleetbase\FleetOps\Models\Waypoint;
|
|
8
|
-
use Fleetbase\Models\Company;
|
|
9
|
-
use Fleetbase\Models\CompanyUser;
|
|
10
|
-
use Fleetbase\Models\Extension;
|
|
11
|
-
use Fleetbase\Models\ExtensionInstall;
|
|
12
|
-
use Fleetbase\Models\User;
|
|
13
|
-
use Illuminate\Support\Arr;
|
|
14
|
-
use Illuminate\Support\Collection;
|
|
15
|
-
use Illuminate\Support\Str;
|
|
16
|
-
use Laravel\Sanctum\PersonalAccessToken;
|
|
17
|
-
|
|
18
|
-
class Flow
|
|
19
|
-
{
|
|
20
|
-
/**
|
|
21
|
-
* Returns all the order type configurations for the current users session.
|
|
22
|
-
*/
|
|
23
|
-
public static function queryOrderConfigurations($queryCallback = null): ?Collection
|
|
24
|
-
{
|
|
25
|
-
$installedExtensions = [];
|
|
26
|
-
|
|
27
|
-
// get all installed order configs
|
|
28
|
-
$installed = ExtensionInstall::where('company_uuid', session('company'))->whereHas('extension', function ($query) use ($queryCallback) {
|
|
29
|
-
$query->where('meta_type', 'order_config');
|
|
30
|
-
if (is_callable($queryCallback)) {
|
|
31
|
-
$queryCallback($query);
|
|
32
|
-
}
|
|
33
|
-
})->with('extension')->get();
|
|
34
|
-
|
|
35
|
-
// morph installed into extensions
|
|
36
|
-
foreach ($installed as $install) {
|
|
37
|
-
$installedExtensions[] = $install->asExtension();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// get authored extension installs
|
|
41
|
-
$authoredQuery = Extension::where(['author_uuid' => session('company'), 'meta_type' => 'order_config', 'status' => 'private']);
|
|
42
|
-
|
|
43
|
-
if (is_callable($queryCallback)) {
|
|
44
|
-
$queryCallback($authoredQuery);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
$authored = $authoredQuery->get();
|
|
48
|
-
|
|
49
|
-
// create array of configs
|
|
50
|
-
/** @var Collection $configs */
|
|
51
|
-
$configs = collect([...$installedExtensions, ...$authored]);
|
|
52
|
-
|
|
53
|
-
// if no installed configs always place default config
|
|
54
|
-
if ($configs->isEmpty()) {
|
|
55
|
-
$configs = $configs->merge(Flow::getAllDefaultOrderConfigs());
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return $configs;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Returns all the order type configurations for the current users session.
|
|
63
|
-
*/
|
|
64
|
-
public static function getOrderConfigsForSession(): ?Collection
|
|
65
|
-
{
|
|
66
|
-
$installedExtensions = [];
|
|
67
|
-
|
|
68
|
-
// get all installed order configs
|
|
69
|
-
$installed = ExtensionInstall::where('company_uuid', session('company'))->whereHas('extension', function ($query) {
|
|
70
|
-
$query->where('meta_type', 'order_config');
|
|
71
|
-
})->with('extension')->get();
|
|
72
|
-
|
|
73
|
-
// morph installed into extensions
|
|
74
|
-
foreach ($installed as $install) {
|
|
75
|
-
$installedExtensions[] = $install->asExtension();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// get authored extension installs
|
|
79
|
-
$authored = Extension::where(['author_uuid' => session('company'), 'meta_type' => 'order_config', 'status' => 'private'])->get();
|
|
80
|
-
|
|
81
|
-
// create array of configs
|
|
82
|
-
/** @var Collection $configs */
|
|
83
|
-
$configs = collect([...$installedExtensions, ...$authored]);
|
|
84
|
-
|
|
85
|
-
// if no installed configs always place default config
|
|
86
|
-
if ($configs->isEmpty()) {
|
|
87
|
-
$configs = $configs->merge(Flow::getAllDefaultOrderConfigs());
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return $configs;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Returns all the order type configurations for the current users session.
|
|
95
|
-
*/
|
|
96
|
-
public static function getOrderConfigs(Order $order): Collection
|
|
97
|
-
{
|
|
98
|
-
$installedExtensions = [];
|
|
99
|
-
|
|
100
|
-
// get all installed order configs
|
|
101
|
-
$installed = ExtensionInstall::where('company_uuid', $order->company_uuid)->whereHas('extension', function ($query) {
|
|
102
|
-
$query->where('meta_type', 'order_config');
|
|
103
|
-
})->with('extension')->get();
|
|
104
|
-
|
|
105
|
-
// morph installed into extensions
|
|
106
|
-
foreach ($installed as $install) {
|
|
107
|
-
$installedExtensions[] = $install->asExtension();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// get authored extension installs
|
|
111
|
-
$authored = Extension::where(['author_uuid' => $order->company_uuid, 'meta_type' => 'order_config', 'status' => 'private'])->get();
|
|
112
|
-
|
|
113
|
-
// create array of configs
|
|
114
|
-
/** @var Collection $configs */
|
|
115
|
-
$configs = collect([...$installedExtensions, ...$authored]);
|
|
116
|
-
|
|
117
|
-
// if no installed configs always place default config
|
|
118
|
-
if ($configs->isEmpty()) {
|
|
119
|
-
$configs = $configs->merge(Flow::getAllDefaultOrderConfigs());
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return $configs;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Returns a order type configuration by key.
|
|
127
|
-
*/
|
|
128
|
-
public static function getOrderConfig(Order $order): ?Extension
|
|
129
|
-
{
|
|
130
|
-
if ($order->type === 'default' || empty($order->type)) {
|
|
131
|
-
if (empty($order->type)) {
|
|
132
|
-
$order->update(['type' => 'default']);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return static::getDefaultOrderConfig();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
$configs = static::getOrderConfigs($order);
|
|
139
|
-
|
|
140
|
-
return $configs->firstWhere('key', $order->type);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Returns a order type configuration by key.
|
|
145
|
-
*
|
|
146
|
-
* @return array
|
|
147
|
-
*/
|
|
148
|
-
public static function getOrderConfigFlow(Order $order)
|
|
149
|
-
{
|
|
150
|
-
if ($order->type === 'default' || empty($order->type)) {
|
|
151
|
-
if (empty($order->type)) {
|
|
152
|
-
$order->update(['type' => 'default']);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
$config = static::getDefaultOrderConfig();
|
|
156
|
-
|
|
157
|
-
if ($config) {
|
|
158
|
-
return data_get($config, 'meta.flow');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
$configs = static::getOrderConfigs($order);
|
|
165
|
-
$config = $configs->firstWhere('key', $order->type);
|
|
166
|
-
|
|
167
|
-
if ($config) {
|
|
168
|
-
return data_get($config, 'meta.flow');
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Returns a order type configuration by key.
|
|
176
|
-
*/
|
|
177
|
-
public static function getOrderFlow(Order $order): ?array
|
|
178
|
-
{
|
|
179
|
-
$config = static::getOrderConfig($order);
|
|
180
|
-
$vars = static::getOrderFlowVars($order);
|
|
181
|
-
$code = strtolower(data_get($order, 'status'));
|
|
182
|
-
$status = data_get($config, 'meta.flow.' . $code . '.events');
|
|
183
|
-
|
|
184
|
-
$flow = static::bindVariablesToFlow($status, $vars);
|
|
185
|
-
$flow = static::bindPodFlagsToFlow($config, $flow, $order);
|
|
186
|
-
$flow = static::executeLogicStack($flow, $order);
|
|
187
|
-
|
|
188
|
-
return $flow;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Get an order activity from an order configuration provided by the index.
|
|
193
|
-
*/
|
|
194
|
-
public static function getActivity(Order $order, $index): ?array
|
|
195
|
-
{
|
|
196
|
-
$flow = static::getOrderConfigFlow($order);
|
|
197
|
-
|
|
198
|
-
return $flow[$index] ?? null;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Get an order activity from an order configuration provided by the index.
|
|
203
|
-
*/
|
|
204
|
-
public static function getActivityByIndex(Order $order, int $index): ?array
|
|
205
|
-
{
|
|
206
|
-
$flow = array_values(static::getOrderConfigFlow($order));
|
|
207
|
-
$config = $flow[$index] ?? null;
|
|
208
|
-
|
|
209
|
-
return Arr::first(data_get($config, 'events', []));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Get an order activity from an order configuration provided by the index.
|
|
214
|
-
*/
|
|
215
|
-
public static function getAfterNextActivity(Order $order): ?array
|
|
216
|
-
{
|
|
217
|
-
$current = strtolower($order->status);
|
|
218
|
-
$flow = static::getOrderConfigFlow($order);
|
|
219
|
-
$keys = array_keys($flow);
|
|
220
|
-
$activities = array_values($flow);
|
|
221
|
-
$index = array_search($current, $keys) + 1;
|
|
222
|
-
$config = $activities[$index] ?? null;
|
|
223
|
-
|
|
224
|
-
return Arr::first(data_get($config, 'events', []));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Get the next sequential activity from an order configuration.
|
|
229
|
-
*/
|
|
230
|
-
public static function getNextActivity(Order $order): ?array
|
|
231
|
-
{
|
|
232
|
-
$flow = static::getOrderFlow($order);
|
|
233
|
-
|
|
234
|
-
return Arr::first($flow);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Returns a order type configuration by key.
|
|
239
|
-
*
|
|
240
|
-
* @param bool $force - If this method should always return dispatch activity
|
|
241
|
-
*/
|
|
242
|
-
public static function getDispatchActivity(Order $order, bool $force = true): ?array
|
|
243
|
-
{
|
|
244
|
-
$flow = static::getOrderFlow($order);
|
|
245
|
-
|
|
246
|
-
if ($force === true) {
|
|
247
|
-
return [
|
|
248
|
-
'status' => 'Order dispatched',
|
|
249
|
-
'details' => 'Order has been dispatched',
|
|
250
|
-
'code' => 'dispatched',
|
|
251
|
-
];
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return collect($flow)->first(function ($activity) {
|
|
255
|
-
return isset($activity['code']) && $activity['code'] === 'dispatched';
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Returns a order flow status for the waypoint only.
|
|
261
|
-
*/
|
|
262
|
-
public static function getOrderWaypointFlow(Order $order, ?Waypoint $waypoint = null): ?array
|
|
263
|
-
{
|
|
264
|
-
if ($waypoint === null) {
|
|
265
|
-
/** @var \Fleetbase\Models\Waypoint $waypoint */
|
|
266
|
-
$waypoint = $order->payload->waypointMarkers->first(function ($marker) use ($order) {
|
|
267
|
-
return $marker->place_uuid === $order->payload->current_waypoint_uuid;
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
$config = static::getOrderConfig($order);
|
|
272
|
-
$vars = static::getOrderFlowVars($order, $waypoint);
|
|
273
|
-
$code = strtolower($waypoint->status_code);
|
|
274
|
-
|
|
275
|
-
// if code is completed return empty array
|
|
276
|
-
if ($code === 'completed' || $code === 'canceled') {
|
|
277
|
-
return [];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
$status = data_get($config, 'meta.flow.waypoint|' . $code . '.events');
|
|
281
|
-
|
|
282
|
-
if (!$status) {
|
|
283
|
-
return static::getOrderFlow($order);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
$flow = static::bindVariablesToFlow($status, $vars);
|
|
287
|
-
$flow = static::bindPodFlagsToFlow($config, $flow, $order);
|
|
288
|
-
$flow = static::executeLogicStack($flow, $order);
|
|
289
|
-
|
|
290
|
-
return $flow;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Returns a order flow status for the waypoint only.
|
|
295
|
-
*/
|
|
296
|
-
public static function getOrderFlowVars(Order $order, ?Waypoint $currentWaypoint = null): ?array
|
|
297
|
-
{
|
|
298
|
-
$vars = [];
|
|
299
|
-
$allWaypoints = data_get($order, 'payload.waypoints', collect());
|
|
300
|
-
|
|
301
|
-
// set order vars
|
|
302
|
-
$vars['order'] = ['public_id' => $order->public_id, 'internal_id' => $order->internal_id, 'tracking_number' => $order->tracking, 'meta' => $order->meta];
|
|
303
|
-
|
|
304
|
-
// set pickup
|
|
305
|
-
if (!empty(data_get($order, 'payload.pickup'))) {
|
|
306
|
-
$vars['order']['pickup'] = $order->payload->pickup->toArray();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// set dropoff
|
|
310
|
-
if (!empty(data_get($order, 'payload.dropoff'))) {
|
|
311
|
-
$vars['order']['dropoff'] = $order->payload->dropoff->toArray();
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// set return
|
|
315
|
-
if (!empty(data_get($order, 'payload.return'))) {
|
|
316
|
-
$vars['order']['return'] = $order->payload->return->toArray();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if ($currentWaypoint) {
|
|
320
|
-
$currentWaypointIndex = static::findWaypointIndex($currentWaypoint, $allWaypoints);
|
|
321
|
-
|
|
322
|
-
// set waypoint vars
|
|
323
|
-
$vars['waypoint'] = $currentWaypoint->place->toArray();
|
|
324
|
-
// set waypoint index vars
|
|
325
|
-
$vars['waypoint']['index'] = $currentWaypointIndex;
|
|
326
|
-
$vars['waypoint']['ordinalIndex'] = Utils::ordinalNumber($currentWaypointIndex);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// // storefront order add store or network about
|
|
330
|
-
// should patch with hook system
|
|
331
|
-
// storefront extension should register hook to add $vars
|
|
332
|
-
// Hook::register('\Fleetbase\FleetOps\Support\Flow@getOrderFlowVars', addStorefrontVars);
|
|
333
|
-
// here we will run Hook::run(__CLASS__ . '@' . __METHOD__);
|
|
334
|
-
// if ($order->type === 'storefront' && $order->hasMeta('storefront_id')) {
|
|
335
|
-
// $storefront = Storefront::findAbout($order->getMeta('storefront_id'));
|
|
336
|
-
|
|
337
|
-
// if ($storefront) {
|
|
338
|
-
// $vars['storefront'] = $storefront->toArray();
|
|
339
|
-
// }
|
|
340
|
-
// }
|
|
341
|
-
|
|
342
|
-
return $vars;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
public static function orderConfigRequiresPod(Order $order)
|
|
346
|
-
{
|
|
347
|
-
$config = static::getOrderConfig($order);
|
|
348
|
-
|
|
349
|
-
if ($order->type === 'storefront') {
|
|
350
|
-
return $order->isMeta('require_pod');
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
return (bool) data_get($config, 'meta.require_pod');
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
public static function bindPodFlagsToFlow($config, array $flows = [], ?Order $order)
|
|
357
|
-
{
|
|
358
|
-
$podRequired = (bool) data_get($config, 'meta.require_pod', $order->pod_required);
|
|
359
|
-
$podMethod = data_get($config, 'meta.pod_method', $order->pod_method);
|
|
360
|
-
|
|
361
|
-
if ($order->type === 'storefront') {
|
|
362
|
-
$podRequired = $order->getMeta('require_pod');
|
|
363
|
-
$podMethod = $order->getMeta('pod_method');
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if ($order->pod_required === true) {
|
|
367
|
-
$podRequired = true;
|
|
368
|
-
$podMethod = $order->pod_method ?? 'scan';
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if ($podRequired && !$podMethod) {
|
|
372
|
-
$podMethod = 'scan';
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
foreach ($flows as $index => $status) {
|
|
376
|
-
if (isset($status['code']) && $status['code'] === 'completed') {
|
|
377
|
-
$status['require_pod'] = $podRequired;
|
|
378
|
-
$status['pod_method'] = $podMethod;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
$flows[$index] = $status;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return $flows;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
public static function bindVariablesToFlow(?array $flows, array $vars = [])
|
|
388
|
-
{
|
|
389
|
-
if (is_null($flows)) {
|
|
390
|
-
return [];
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
if (!is_array($flows)) {
|
|
394
|
-
return $flows;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
foreach ($flows as $index => $status) {
|
|
398
|
-
if (!is_array($status)) {
|
|
399
|
-
continue;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
foreach ($status as $key => $value) {
|
|
403
|
-
if (!is_string($value)) {
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
$status[$key] = Utils::bindVariablesToString($value, $vars);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
$flows[$index] = $status;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return $flows;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
public static function executeLogicStack(array $flows, Order $order)
|
|
417
|
-
{
|
|
418
|
-
$passingFlows = [];
|
|
419
|
-
$noLogicFlows = [];
|
|
420
|
-
|
|
421
|
-
foreach ($flows as $status) {
|
|
422
|
-
if (isset($status['if']) && count($status['if'])) {
|
|
423
|
-
foreach ($status['if'] as $logic) {
|
|
424
|
-
list($prop, $operator, $rightSideValue) = $logic;
|
|
425
|
-
|
|
426
|
-
$leftSideValue = data_get($order, $prop);
|
|
427
|
-
$passed = false;
|
|
428
|
-
|
|
429
|
-
if ($operator === '=') {
|
|
430
|
-
$passed = $leftSideValue === $rightSideValue;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if ($operator === '!=') {
|
|
434
|
-
$passed = $leftSideValue !== $rightSideValue;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
if ($operator === '$') {
|
|
438
|
-
$passed = Str::contains($rightSideValue, $leftSideValue);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if ($operator === '>') {
|
|
442
|
-
$passed = $leftSideValue > $rightSideValue;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if ($operator === '<') {
|
|
446
|
-
$passed = $leftSideValue < $rightSideValue;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if ($passed) {
|
|
450
|
-
$passingFlows[] = $status;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
} else {
|
|
454
|
-
$noLogicFlows[] = $status;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
if (!$passingFlows) {
|
|
459
|
-
return $noLogicFlows;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
return $passingFlows;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
public static function findWaypointIndex(Waypoint $waypoint, Collection $waypoints): ?int
|
|
466
|
-
{
|
|
467
|
-
$waypointIndex = $waypoints->search(function ($wp) use ($waypoint) {
|
|
468
|
-
return $wp->uuid === $waypoint->place_uuid;
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
return $waypointIndex + 1;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
public static function getInstalledOrderConfigs()
|
|
475
|
-
{
|
|
476
|
-
$configs = Extension::where('meta_type', 'order_config')
|
|
477
|
-
->whereHas('type', function ($q) {
|
|
478
|
-
$q->where('key', 'config');
|
|
479
|
-
})->whereHas('installs', function ($q) {
|
|
480
|
-
$q->where('company_uuid', session('company'));
|
|
481
|
-
})->get();
|
|
482
|
-
|
|
483
|
-
return $configs;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
public static function getAuthoredOrderConfigs()
|
|
487
|
-
{
|
|
488
|
-
$configs = Extension::where('meta_type', 'order_config')
|
|
489
|
-
->whereHas('type', function ($q) {
|
|
490
|
-
$q->where('key', 'config');
|
|
491
|
-
})->where('author_uuid', session('company'))->get();
|
|
492
|
-
|
|
493
|
-
return $configs;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
public static function getInstalledOrderConfigsCount()
|
|
497
|
-
{
|
|
498
|
-
$count = Extension::where('meta_type', 'order_config')
|
|
499
|
-
->whereHas('type', function ($q) {
|
|
500
|
-
$q->where('key', 'config');
|
|
501
|
-
})->whereHas('installs', function ($q) {
|
|
502
|
-
$q->where('company_uuid', session('company'));
|
|
503
|
-
})->count();
|
|
504
|
-
|
|
505
|
-
return $count;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
public static function getAuthoredOrderConfigsCount()
|
|
509
|
-
{
|
|
510
|
-
$count = Extension::where('meta_type', 'order_config')
|
|
511
|
-
->whereHas('type', function ($q) {
|
|
512
|
-
$q->where('key', 'config');
|
|
513
|
-
})->where('author_uuid', session('company'))->count();
|
|
514
|
-
|
|
515
|
-
return $count;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
public static function hasInstalledOrAuthoredOrderConfigs()
|
|
519
|
-
{
|
|
520
|
-
$installed = static::getInstalledOrderConfigsCount();
|
|
521
|
-
$authored = static::getAuthoredOrderConfigsCount();
|
|
522
|
-
|
|
523
|
-
return ($installed + $authored) > 0;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
public static function getDriverFromToken()
|
|
527
|
-
{
|
|
528
|
-
$token = request()->header('Driver-Token');
|
|
529
|
-
|
|
530
|
-
if ($token) {
|
|
531
|
-
$accessToken = PersonalAccessToken::findToken($token);
|
|
532
|
-
|
|
533
|
-
if ($accessToken && Str::isUuid($accessToken->name)) {
|
|
534
|
-
$driver = Driver::where('uuid', $accessToken->name)->first();
|
|
535
|
-
|
|
536
|
-
if ($driver) {
|
|
537
|
-
return $driver;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
if ($accessToken) {
|
|
542
|
-
return Driver::where('user_uuid', $accessToken->tokenable->uuid)->first();
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
public static function getCompanySession()
|
|
550
|
-
{
|
|
551
|
-
return Company::currentSession();
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
public static function getCompanySessionForUser(User $user): ?Company
|
|
555
|
-
{
|
|
556
|
-
if (Str::isUuid($user->company_uuid)) {
|
|
557
|
-
$company = Company::where('uuid', $user->company_uuid)->first();
|
|
558
|
-
if ($company) {
|
|
559
|
-
return $company;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// fallback to get user's first company
|
|
564
|
-
$userCompany = CompanyUser::where('user_uuid', $user->uuid)->first();
|
|
565
|
-
if ($userCompany) {
|
|
566
|
-
$company = Company::where('uuid', $userCompany->company_uuid)->first();
|
|
567
|
-
if ($company) {
|
|
568
|
-
return $company;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
public static function getDefaultOrderFlow()
|
|
576
|
-
{
|
|
577
|
-
return config('api.types.order.0.meta.flow');
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
public static function getDefaultOrderConfig(): Extension
|
|
581
|
-
{
|
|
582
|
-
$name = 'Default';
|
|
583
|
-
$description = 'Operational flow for standard A to B transport.';
|
|
584
|
-
$company = static::getCompanySession();
|
|
585
|
-
|
|
586
|
-
return new Extension([
|
|
587
|
-
'id' => -1,
|
|
588
|
-
'uuid' => Str::uuid(),
|
|
589
|
-
'author_uuid' => $company->uuid,
|
|
590
|
-
'name' => $name,
|
|
591
|
-
'description' => $description,
|
|
592
|
-
'display_name' => $name,
|
|
593
|
-
'key' => Str::slug($name),
|
|
594
|
-
'namespace' => Extension::createNamespace($company->slug, 'order-config', $name),
|
|
595
|
-
'version' => '0.0.1',
|
|
596
|
-
'core_service' => 0,
|
|
597
|
-
'meta' => ['flow' => static::getDefaultOrderFlow()],
|
|
598
|
-
'meta_type' => 'order_config',
|
|
599
|
-
'config' => [],
|
|
600
|
-
'status' => 'private',
|
|
601
|
-
]);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
public static function getAllDefaultOrderConfigs(): Collection
|
|
605
|
-
{
|
|
606
|
-
/** @var Collection $extensions */
|
|
607
|
-
$extensions = collect();
|
|
608
|
-
$company = static::getCompanySession();
|
|
609
|
-
$orderConfigs = config('api.types.order', []);
|
|
610
|
-
$thirdPartyOrderConfigs = Utils::fromFleetbaseExtensions('order-config');
|
|
611
|
-
|
|
612
|
-
// make sure order configs is array
|
|
613
|
-
if (!is_array($orderConfigs)) {
|
|
614
|
-
$orderConfigs = [];
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
if (!empty($thirdPartyOrderConfigs)) {
|
|
618
|
-
foreach ($thirdPartyOrderConfigs as $orderConfigProvider) {
|
|
619
|
-
$resolvedOrderConfigProvider = app($orderConfigProvider);
|
|
620
|
-
|
|
621
|
-
if (is_object($resolvedOrderConfigProvider) && method_exists($resolvedOrderConfigProvider, 'get')) {
|
|
622
|
-
$orderConfigs = array_merge($orderConfigs, $resolvedOrderConfigProvider->get());
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// convert order configs to local extensions
|
|
628
|
-
foreach ($orderConfigs as $index => $orderConfig) {
|
|
629
|
-
$extensions->push(
|
|
630
|
-
new Extension(
|
|
631
|
-
[
|
|
632
|
-
'id' => $index,
|
|
633
|
-
'uuid' => Str::uuid(),
|
|
634
|
-
'author_uuid' => $company->uuid,
|
|
635
|
-
'name' => data_get($orderConfig, 'name'),
|
|
636
|
-
'description' => data_get($orderConfig, 'description'),
|
|
637
|
-
'display_name' => data_get($orderConfig, 'name'),
|
|
638
|
-
'key' => data_get($orderConfig, 'key'),
|
|
639
|
-
'namespace' => Extension::createNamespace($company->slug, 'order-config', data_get($orderConfig, 'name')),
|
|
640
|
-
'version' => '0.0.1',
|
|
641
|
-
'core_service' => 0,
|
|
642
|
-
'meta' => data_get($orderConfig, 'meta'),
|
|
643
|
-
'meta_type' => 'order_config',
|
|
644
|
-
'config' => [],
|
|
645
|
-
'status' => 'private',
|
|
646
|
-
]
|
|
647
|
-
)
|
|
648
|
-
);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
return $extensions;
|
|
652
|
-
}
|
|
653
|
-
}
|