@fleetbase/fleetops-engine 0.4.16 → 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/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 +46 -26
- 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/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 +6 -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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Flow;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
+
use Illuminate\Support\Str;
|
|
7
|
+
|
|
8
|
+
class Condition extends FlowResource
|
|
9
|
+
{
|
|
10
|
+
/**
|
|
11
|
+
* Evaluate the condition against an order.
|
|
12
|
+
*
|
|
13
|
+
* @param Order $order the order to evaluate the condition against
|
|
14
|
+
*
|
|
15
|
+
* @return bool the result of the condition evaluation
|
|
16
|
+
*
|
|
17
|
+
* @throws \Exception if the operator is unknown
|
|
18
|
+
*/
|
|
19
|
+
public function eval(Order $order)
|
|
20
|
+
{
|
|
21
|
+
$field = $this->field;
|
|
22
|
+
$operator = $this->operator;
|
|
23
|
+
$value = $this->value;
|
|
24
|
+
$actualValue = strtolower($order->resolveDynamicValue($field));
|
|
25
|
+
|
|
26
|
+
// if value is string convert to lowercase
|
|
27
|
+
if (is_string($value)) {
|
|
28
|
+
$value = strtolower($value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch ($operator) {
|
|
32
|
+
case 'exists':
|
|
33
|
+
return isset($actualValue);
|
|
34
|
+
|
|
35
|
+
case 'in':
|
|
36
|
+
case 'has':
|
|
37
|
+
return is_array($actualValue) && in_array($actualValue, $value);
|
|
38
|
+
|
|
39
|
+
case 'notIn':
|
|
40
|
+
case 'doesntHave':
|
|
41
|
+
return is_array($actualValue) && !in_array($actualValue, $value);
|
|
42
|
+
|
|
43
|
+
case 'contains':
|
|
44
|
+
return is_string($value) && is_string($actualValue) && Str::contains($value, $actualValue);
|
|
45
|
+
|
|
46
|
+
case 'beginsWith':
|
|
47
|
+
return is_string($value) && is_string($actualValue) && Str::startsWith($value, $actualValue);
|
|
48
|
+
|
|
49
|
+
case 'endsWith':
|
|
50
|
+
return is_string($value) && is_string($actualValue) && Str::endsWith($value, $actualValue);
|
|
51
|
+
|
|
52
|
+
case 'equal':
|
|
53
|
+
return $actualValue == $value;
|
|
54
|
+
|
|
55
|
+
case 'and':
|
|
56
|
+
return $actualValue && $value;
|
|
57
|
+
|
|
58
|
+
case 'or':
|
|
59
|
+
return $actualValue || $value;
|
|
60
|
+
|
|
61
|
+
case 'not':
|
|
62
|
+
return !$actualValue;
|
|
63
|
+
|
|
64
|
+
case 'notEqual':
|
|
65
|
+
return $actualValue != $value;
|
|
66
|
+
|
|
67
|
+
case 'greaterThan':
|
|
68
|
+
return $actualValue > $value;
|
|
69
|
+
|
|
70
|
+
case 'greaterThanOrEqual':
|
|
71
|
+
return $actualValue >= $value;
|
|
72
|
+
|
|
73
|
+
case 'lessThan':
|
|
74
|
+
return $actualValue < $value;
|
|
75
|
+
|
|
76
|
+
case 'lessThanOrEqual':
|
|
77
|
+
return $actualValue <= $value;
|
|
78
|
+
|
|
79
|
+
// ... and so on for the other operators
|
|
80
|
+
default:
|
|
81
|
+
throw new \Exception("Unknown operator: {$operator}");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Flow;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
7
|
+
use Illuminate\Support\Str;
|
|
8
|
+
|
|
9
|
+
class Event
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* The name of the event.
|
|
13
|
+
*/
|
|
14
|
+
public string $name;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The order associated with the event, if any.
|
|
18
|
+
*
|
|
19
|
+
* @var ?Order
|
|
20
|
+
*/
|
|
21
|
+
public ?Order $order = null;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Constructs a new Event instance.
|
|
25
|
+
*
|
|
26
|
+
* @param string $name the name of the event
|
|
27
|
+
* @param ?Order $order the associated order, if any
|
|
28
|
+
*/
|
|
29
|
+
public function __construct(string $name, ?Order $order = null)
|
|
30
|
+
{
|
|
31
|
+
$this->name = $name;
|
|
32
|
+
$this->order = $order;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Sets the order for the event.
|
|
37
|
+
*
|
|
38
|
+
* @param Order $order the order to associate with this event
|
|
39
|
+
*/
|
|
40
|
+
public function setOrder(Order $order)
|
|
41
|
+
{
|
|
42
|
+
$this->order = $order;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Triggers the event, optionally setting the order if not already set.
|
|
47
|
+
*
|
|
48
|
+
* Resolves the event class based on the event name and fires it using Laravel's event system.
|
|
49
|
+
* If the order is not set in the event, and an Order object is provided, it sets the order before firing.
|
|
50
|
+
*
|
|
51
|
+
* @param ?Order $order optional order to associate with the event
|
|
52
|
+
*/
|
|
53
|
+
public function fire(?Order $order = null)
|
|
54
|
+
{
|
|
55
|
+
if (!$this->order && $order instanceof Order) {
|
|
56
|
+
$this->setOrder($order);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
$eventClass = $this->resolve();
|
|
60
|
+
if ($eventClass) {
|
|
61
|
+
event(new $eventClass($this->order));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Resolves the class name of the event based on the event name.
|
|
67
|
+
*
|
|
68
|
+
* Tries to locate the class in predefined namespaces and returns the fully qualified name if found.
|
|
69
|
+
*
|
|
70
|
+
* @return string|null the resolved class name or null if not found
|
|
71
|
+
*/
|
|
72
|
+
public function resolve()
|
|
73
|
+
{
|
|
74
|
+
$eventClassName = Str::studly(preg_replace('/[^a-zA-Z0-9]/', ' ', $this->name));
|
|
75
|
+
$eventClasses = [
|
|
76
|
+
'\\Fleetbase\\FleetOps\Events\\' . $eventClassName,
|
|
77
|
+
'\\Fleetbase\\Events\\' . $eventClassName,
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
foreach ($eventClasses as $eventClass) {
|
|
81
|
+
if (Utils::classExists($eventClass)) {
|
|
82
|
+
return $eventClass;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Flow;
|
|
4
|
+
|
|
5
|
+
class Flow extends FlowResource implements \IteratorAggregate
|
|
6
|
+
{
|
|
7
|
+
/**
|
|
8
|
+
* Returns an iterator for the flow.
|
|
9
|
+
*
|
|
10
|
+
* @return \Traversable an iterator for the flow's activities
|
|
11
|
+
*/
|
|
12
|
+
public function getIterator(): \Traversable
|
|
13
|
+
{
|
|
14
|
+
foreach ($this->attributes['activities'] as $activityAttributes) {
|
|
15
|
+
yield new Activity($activityAttributes, $this->serialize());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retrieve the activity for a given code.
|
|
21
|
+
*
|
|
22
|
+
* @param string $code the unique code identifier for the activity
|
|
23
|
+
*
|
|
24
|
+
* @return Activity|null the Activity object if found, or null otherwise
|
|
25
|
+
*/
|
|
26
|
+
public function getActivity(string $code): ?Activity
|
|
27
|
+
{
|
|
28
|
+
if (isset($this->{$code})) {
|
|
29
|
+
return new Activity($this->{$code}, $this->serialize());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Determines if a given object is an instance of Activity.
|
|
37
|
+
*
|
|
38
|
+
* This static method is used to check if a provided object is an
|
|
39
|
+
* instance of the Activity class. This can be useful in contexts where
|
|
40
|
+
* there is a need to verify the type of a given resource or object.
|
|
41
|
+
*
|
|
42
|
+
* @param mixed $activity the object to check
|
|
43
|
+
*
|
|
44
|
+
* @return bool returns true if the provided object is an instance of Activity, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
public static function isActivity($activity)
|
|
47
|
+
{
|
|
48
|
+
return $activity instanceof Activity;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Flow;
|
|
4
|
+
|
|
5
|
+
use Illuminate\Support\Str;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base class for flow resources which can serialize to JSON.
|
|
9
|
+
*/
|
|
10
|
+
class FlowResource implements \JsonSerializable
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* The array of attributes for the flow resource.
|
|
14
|
+
*/
|
|
15
|
+
public array $attributes = [];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create a new flow resource instance.
|
|
19
|
+
*
|
|
20
|
+
* @param array $attributes attributes to set upon construction
|
|
21
|
+
*/
|
|
22
|
+
public function __construct(array $attributes = [])
|
|
23
|
+
{
|
|
24
|
+
$this->attributes = $attributes;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Magic method to retrieve the value of a property.
|
|
29
|
+
* If a getter method exists for the property, it will be used; otherwise, it will access the property directly.
|
|
30
|
+
*
|
|
31
|
+
* @param string $name the name of the property to access
|
|
32
|
+
*
|
|
33
|
+
* @return mixed the value of the property
|
|
34
|
+
*/
|
|
35
|
+
public function __get($name)
|
|
36
|
+
{
|
|
37
|
+
// if has special attribute `get_Attribute()` call first
|
|
38
|
+
$mutatorMethod = 'get' . Str::studly($name) . 'Attribute';
|
|
39
|
+
if (method_exists($this, $mutatorMethod)) {
|
|
40
|
+
return $this->{$mutatorMethod}();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (array_key_exists($name, $this->attributes)) {
|
|
44
|
+
return $this->attributes[$name];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return $this->{$name};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Magic method to check if a property is set.
|
|
52
|
+
* This will return true if the property exists and is not null.
|
|
53
|
+
*
|
|
54
|
+
* @param string $name the name of the property to check
|
|
55
|
+
*
|
|
56
|
+
* @return bool true if the property is set, false otherwise
|
|
57
|
+
*/
|
|
58
|
+
public function __isset($name)
|
|
59
|
+
{
|
|
60
|
+
if (array_key_exists($name, $this->attributes)) {
|
|
61
|
+
return isset($this->attributes[$name]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return isset($this->{$name});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get the value of a given key from the attributes.
|
|
69
|
+
* If the key does not exist, the default value will be returned.
|
|
70
|
+
*
|
|
71
|
+
* @param string $key the key to retrieve
|
|
72
|
+
* @param mixed $defaultValue the default value to return if the key does not exist
|
|
73
|
+
*
|
|
74
|
+
* @return mixed the value from the attributes or the default value
|
|
75
|
+
*/
|
|
76
|
+
public function get($key, $defaultValue = null)
|
|
77
|
+
{
|
|
78
|
+
if (array_key_exists($key, $this->attributes)) {
|
|
79
|
+
return $this->attributes[$key];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (isset($this->{$key})) {
|
|
83
|
+
return $this->{$key};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return data_get($this, $key, $defaultValue);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set a given attribute on the resource.
|
|
91
|
+
*
|
|
92
|
+
* @param string $key the key of the attribute to set
|
|
93
|
+
* @param mixed $value the value to set for the attribute
|
|
94
|
+
*
|
|
95
|
+
* @return self returns instance of FlowResource for chaining
|
|
96
|
+
*/
|
|
97
|
+
public function set(string $key, $value): self
|
|
98
|
+
{
|
|
99
|
+
$this->attributes[$key] = $value;
|
|
100
|
+
|
|
101
|
+
return $this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Serialize the attributes to an array.
|
|
106
|
+
*
|
|
107
|
+
* @return array the array representation of the attributes
|
|
108
|
+
*/
|
|
109
|
+
public function serialize(): array
|
|
110
|
+
{
|
|
111
|
+
return $this->attributes;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Convert the object into an array.
|
|
116
|
+
*
|
|
117
|
+
* @return array the array representation of the object
|
|
118
|
+
*/
|
|
119
|
+
public function toArray(): array
|
|
120
|
+
{
|
|
121
|
+
return $this->serialize();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Convert the object into a JSON string.
|
|
126
|
+
*
|
|
127
|
+
* @return string the JSON representation of the object
|
|
128
|
+
*/
|
|
129
|
+
public function toJson()
|
|
130
|
+
{
|
|
131
|
+
return json_encode($this->serialize());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Specify data which should be serialized to JSON.
|
|
136
|
+
*
|
|
137
|
+
* @return mixed data which can be serialized by json_encode, which is a value of any type other than a resource
|
|
138
|
+
*/
|
|
139
|
+
public function jsonSerialize()
|
|
140
|
+
{
|
|
141
|
+
return $this->toArray();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -2,6 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Flow;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
+
|
|
7
|
+
class Logic extends FlowResource
|
|
6
8
|
{
|
|
9
|
+
/**
|
|
10
|
+
* Accessor method to retrieve the 'conditions' attribute.
|
|
11
|
+
*
|
|
12
|
+
* This method maps each condition in the 'conditions' attribute to a new Condition object.
|
|
13
|
+
* It utilizes the array_map function to apply this transformation, ensuring each entry
|
|
14
|
+
* in the conditions array is converted to a Condition object.
|
|
15
|
+
*
|
|
16
|
+
* @return array an array of Condition objects derived from the 'conditions' attribute
|
|
17
|
+
*/
|
|
18
|
+
public function getConditionsAttribute(): array
|
|
19
|
+
{
|
|
20
|
+
return array_map(
|
|
21
|
+
function ($condition) {
|
|
22
|
+
return new Condition($condition);
|
|
23
|
+
},
|
|
24
|
+
$this->get('conditions', [])
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Evaluates the logic conditions against an order.
|
|
30
|
+
*
|
|
31
|
+
* @param Order $order the order to evaluate the logic against
|
|
32
|
+
*
|
|
33
|
+
* @return bool whether the logic passes based on the order's attributes
|
|
34
|
+
*
|
|
35
|
+
* @throws \Exception if the logic type is unknown
|
|
36
|
+
*/
|
|
37
|
+
public function passes(Order $order)
|
|
38
|
+
{
|
|
39
|
+
$logicType = $this->type;
|
|
40
|
+
$conditions = collect($this->conditions);
|
|
41
|
+
|
|
42
|
+
switch ($logicType) {
|
|
43
|
+
case 'and':
|
|
44
|
+
// All conditions must be true
|
|
45
|
+
return $conditions->every(fn ($condition) => $condition->eval($order));
|
|
46
|
+
|
|
47
|
+
case 'or':
|
|
48
|
+
// At least one condition must be true
|
|
49
|
+
return $conditions->contains(fn ($condition) => $condition->eval($order));
|
|
50
|
+
|
|
51
|
+
case 'not':
|
|
52
|
+
// None of the conditions must be true
|
|
53
|
+
return !$conditions->contains(fn ($condition) => $condition->eval($order));
|
|
54
|
+
|
|
55
|
+
case 'if':
|
|
56
|
+
// 'if' type logic can have multiple conditions; all must be true
|
|
57
|
+
return $conditions->every(fn ($condition) => $condition->eval($order));
|
|
58
|
+
|
|
59
|
+
default:
|
|
60
|
+
throw new \Exception("Unknown logic type: {$logicType}");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
7
63
|
}
|
|
@@ -527,7 +527,7 @@ class DriverController extends Controller
|
|
|
527
527
|
}
|
|
528
528
|
|
|
529
529
|
// Get the user account company
|
|
530
|
-
$company =
|
|
530
|
+
$company = Auth::getCompanySessionForUser($user);
|
|
531
531
|
if (!$company) {
|
|
532
532
|
return response()->apiError('No company found for this driver.');
|
|
533
533
|
}
|
|
@@ -752,7 +752,7 @@ class DriverController extends Controller
|
|
|
752
752
|
|
|
753
753
|
// If unable to find company from driver profile, fallback to session flow
|
|
754
754
|
if (!$company) {
|
|
755
|
-
$company =
|
|
755
|
+
$company = Auth::getCompanySessionForUser($user);
|
|
756
756
|
}
|
|
757
757
|
|
|
758
758
|
return $company;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Http\Controllers\Api\v1;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Http\Requests\CreateIssueRequest;
|
|
6
|
+
use Fleetbase\FleetOps\Http\Requests\UpdateIssueRequest;
|
|
7
|
+
use Fleetbase\FleetOps\Http\Resources\v1\Issue as DeletedIssue;
|
|
8
|
+
use Fleetbase\FleetOps\Http\Resources\v1\Issue as IssueResource;
|
|
9
|
+
use Fleetbase\FleetOps\Models\Driver;
|
|
10
|
+
use Fleetbase\FleetOps\Models\Issue;
|
|
11
|
+
use Fleetbase\Http\Controllers\Controller;
|
|
12
|
+
use Illuminate\Http\Request;
|
|
13
|
+
|
|
14
|
+
class IssueController extends Controller
|
|
15
|
+
{
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new Fleetbase Issue resource.
|
|
18
|
+
*
|
|
19
|
+
* @param \Fleetbase\Http\Requests\CreateIssueRequest $request
|
|
20
|
+
*
|
|
21
|
+
* @return \Fleetbase\Http\Resources\Entity
|
|
22
|
+
*/
|
|
23
|
+
public function createRecord(CreateIssueRequest $request)
|
|
24
|
+
{
|
|
25
|
+
// get request input
|
|
26
|
+
$input = $request->only([
|
|
27
|
+
'driver',
|
|
28
|
+
'location',
|
|
29
|
+
'category',
|
|
30
|
+
'type',
|
|
31
|
+
'report',
|
|
32
|
+
'priority',
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
// Find driver who is reporting
|
|
36
|
+
try {
|
|
37
|
+
$driver = Driver::findRecordOrFail($request->input('driver'));
|
|
38
|
+
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) {
|
|
39
|
+
return response()->json(
|
|
40
|
+
[
|
|
41
|
+
'error' => 'Driver reporting issue not found.',
|
|
42
|
+
],
|
|
43
|
+
404
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// get the user uuid
|
|
48
|
+
$input['driver_uuid'] = $driver->uuid;
|
|
49
|
+
$input['reported_by_uuid'] = $driver->user_uuid;
|
|
50
|
+
$input['vehicle_uuid'] = $driver->vehicle_uuid;
|
|
51
|
+
|
|
52
|
+
// create the entity
|
|
53
|
+
$entity = Issue::create($input);
|
|
54
|
+
|
|
55
|
+
// response the driver resource
|
|
56
|
+
return new IssueResource($entity);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Updates new Fleetbase Issue resource.
|
|
61
|
+
*
|
|
62
|
+
* @param string $id
|
|
63
|
+
* @param \Fleetbase\Http\Requests\UpdateIssueRequest $request
|
|
64
|
+
*
|
|
65
|
+
* @return \Fleetbase\Http\Resources\Issue
|
|
66
|
+
*/
|
|
67
|
+
public function updateRecord($id, UpdateIssueRequest $request)
|
|
68
|
+
{
|
|
69
|
+
// find for the issue
|
|
70
|
+
try {
|
|
71
|
+
$issue = Issue::findRecordOrFail($id);
|
|
72
|
+
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) {
|
|
73
|
+
return response()->json(
|
|
74
|
+
[
|
|
75
|
+
'error' => 'Issue resource not found.',
|
|
76
|
+
],
|
|
77
|
+
404
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
$input = $request->only([
|
|
82
|
+
'category',
|
|
83
|
+
'type',
|
|
84
|
+
'report',
|
|
85
|
+
'priority',
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
// update the issue
|
|
89
|
+
$issue->update($input);
|
|
90
|
+
|
|
91
|
+
// response the issue resource
|
|
92
|
+
return new IssueResource($issue);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Query for Fleetbase Issue resources.
|
|
97
|
+
*
|
|
98
|
+
* @return \Fleetbase\Http\Resources\FleetCollection
|
|
99
|
+
*/
|
|
100
|
+
public function queryRecord(Request $request)
|
|
101
|
+
{
|
|
102
|
+
$results = Issue::queryWithRequest($request);
|
|
103
|
+
|
|
104
|
+
return IssueResource::collection($results);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Deletes a Fleetbase Issue resources.
|
|
109
|
+
*
|
|
110
|
+
* @return \Fleetbase\Http\Resources\FleetCollection
|
|
111
|
+
*/
|
|
112
|
+
public function deleteRecord($id)
|
|
113
|
+
{
|
|
114
|
+
// find for the driver
|
|
115
|
+
try {
|
|
116
|
+
$issue = Issue::findRecordOrFail($id);
|
|
117
|
+
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) {
|
|
118
|
+
return response()->json(
|
|
119
|
+
[
|
|
120
|
+
'error' => 'Issue resource not found.',
|
|
121
|
+
],
|
|
122
|
+
404
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// delete the issue
|
|
127
|
+
$issue->delete();
|
|
128
|
+
|
|
129
|
+
// response the issue resource
|
|
130
|
+
return new DeletedIssue($issue);
|
|
131
|
+
}
|
|
132
|
+
}
|