@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.
Files changed (218) hide show
  1. package/.php-cs-fixer.php +2 -0
  2. package/addon/components/activity-event-selector.hbs +35 -0
  3. package/addon/components/activity-event-selector.js +85 -0
  4. package/addon/components/activity-form-panel.hbs +23 -0
  5. package/addon/components/activity-form-panel.js +90 -0
  6. package/addon/components/activity-logic-builder.hbs +80 -0
  7. package/addon/components/activity-logic-builder.js +260 -0
  8. package/addon/components/contact-form-panel.hbs +1 -1
  9. package/addon/components/contact-panel.hbs +1 -1
  10. package/addon/components/custom-entity-form-panel.hbs +43 -0
  11. package/addon/components/custom-entity-form-panel.js +129 -0
  12. package/addon/components/custom-field-form-panel/options-input.hbs +12 -0
  13. package/addon/components/custom-field-form-panel/options-input.js +139 -0
  14. package/addon/components/custom-field-form-panel.hbs +77 -0
  15. package/addon/components/custom-field-form-panel.js +144 -0
  16. package/addon/components/custom-field.hbs +63 -41
  17. package/addon/components/custom-field.js +123 -25
  18. package/addon/components/driver-form-panel.hbs +1 -1
  19. package/addon/components/driver-panel.hbs +1 -1
  20. package/addon/components/edit-order-route-panel.hbs +1 -1
  21. package/addon/components/fleet-form-panel.hbs +1 -1
  22. package/addon/components/fleet-panel.hbs +1 -1
  23. package/addon/components/fuel-report-form-panel.hbs +1 -1
  24. package/addon/components/fuel-report-panel.hbs +1 -1
  25. package/addon/components/issue-form-panel.hbs +1 -1
  26. package/addon/components/issue-panel.hbs +1 -1
  27. package/addon/components/joint-graph.hbs +1 -0
  28. package/addon/components/joint-graph.js +103 -0
  29. package/addon/components/layout/fleet-ops-sidebar.hbs +3 -3
  30. package/addon/components/layout/fleet-ops-sidebar.js +1 -0
  31. package/addon/components/live-map.js +71 -28
  32. package/addon/components/modals/new-custom-field-group.hbs +5 -0
  33. package/addon/components/modals/new-order-config.hbs +3 -3
  34. package/addon/components/modals/order-new-activity.hbs +1 -1
  35. package/addon/components/order-config-manager/activity-flow.hbs +11 -0
  36. package/addon/components/order-config-manager/activity-flow.js +964 -0
  37. package/addon/components/order-config-manager/custom-fields.hbs +50 -0
  38. package/addon/components/order-config-manager/custom-fields.js +276 -0
  39. package/addon/components/order-config-manager/details.hbs +23 -0
  40. package/addon/components/order-config-manager/details.js +97 -0
  41. package/addon/components/order-config-manager/entities.hbs +54 -0
  42. package/addon/components/order-config-manager/entities.js +227 -0
  43. package/addon/components/order-config-manager-overlay.hbs +26 -0
  44. package/addon/components/order-config-manager-overlay.js +60 -0
  45. package/addon/components/order-config-manager.hbs +15 -0
  46. package/addon/components/order-config-manager.js +285 -0
  47. package/addon/components/order-flow.hbs +1 -0
  48. package/addon/components/order-flow.js +3 -0
  49. package/addon/components/place-form-panel.hbs +1 -1
  50. package/addon/components/place-panel.hbs +1 -1
  51. package/addon/components/vehicle-form-panel.hbs +1 -1
  52. package/addon/components/vehicle-panel.hbs +1 -1
  53. package/addon/components/vendor-form-panel.hbs +1 -1
  54. package/addon/components/vendor-panel.hbs +1 -1
  55. package/addon/controllers/application.js +5 -1
  56. package/addon/controllers/operations/order-config.js +42 -0
  57. package/addon/controllers/operations/orders/index/new.js +125 -21
  58. package/addon/controllers/operations/orders/index/view.js +87 -4
  59. package/addon/controllers/operations/orders/index.js +2 -2
  60. package/addon/engine.js +10 -1
  61. package/addon/initializers/load-jointjs.js +16 -0
  62. package/addon/routes/application.js +1 -1
  63. package/addon/routes/operations/order-config.js +28 -0
  64. package/addon/routes/operations/orders/index/new.js +2 -3
  65. package/addon/routes/operations/orders/index/view.js +1 -1
  66. package/addon/routes.js +1 -0
  67. package/addon/services/context-panel.js +65 -3
  68. package/addon/styles/fleetops-engine.css +268 -0
  69. package/addon/templates/application.hbs +1 -1
  70. package/addon/templates/operations/order-config.hbs +55 -0
  71. package/addon/templates/operations/orders/index/new.hbs +98 -339
  72. package/addon/templates/operations/orders/index/view.hbs +36 -96
  73. package/addon/templates/operations/orders/index.hbs +0 -1
  74. package/addon/utils/apply-context-component-arguments.js +4 -2
  75. package/addon/utils/create-custom-entity.js +22 -0
  76. package/addon/utils/create-flow-activity.js +31 -0
  77. package/addon/utils/get-custom-field-type-map.js +34 -0
  78. package/app/components/activity-event-selector.js +1 -0
  79. package/app/components/activity-form-panel.js +1 -0
  80. package/app/components/activity-logic-builder.js +1 -0
  81. package/app/components/custom-entity-form-panel.js +1 -0
  82. package/app/components/custom-field-form-panel/options-input.js +1 -0
  83. package/app/components/custom-field-form-panel.js +1 -0
  84. package/app/components/joint-graph.js +1 -0
  85. package/app/components/modals/new-custom-field-group.js +1 -0
  86. package/app/components/order-config-manager/activity-flow.js +1 -0
  87. package/app/components/order-config-manager/custom-fields.js +1 -0
  88. package/app/components/order-config-manager/details.js +1 -0
  89. package/app/components/order-config-manager/entities.js +1 -0
  90. package/app/components/order-config-manager-overlay.js +1 -0
  91. package/app/components/order-config-manager.js +1 -0
  92. package/app/components/order-flow.js +1 -0
  93. package/app/controllers/operations/order-config.js +1 -0
  94. package/app/routes/operations/order-config.js +1 -0
  95. package/app/templates/operations/order-config.js +1 -0
  96. package/app/utils/create-custom-entity.js +1 -0
  97. package/app/utils/create-flow-activity.js +1 -0
  98. package/app/utils/get-custom-field-type-map.js +1 -0
  99. package/composer.json +4 -3
  100. package/config/environment.js +1 -0
  101. package/extension.json +1 -1
  102. package/index.js +20 -0
  103. package/package.json +7 -5
  104. package/server/migrations/2023_04_27_053456_create_contacts_table.php +1 -2
  105. package/server/migrations/2023_04_27_053456_create_drivers_table.php +1 -2
  106. package/server/migrations/2023_04_27_053456_create_entities_table.php +1 -2
  107. package/server/migrations/2023_04_27_053456_create_fleet_drivers_table.php +1 -2
  108. package/server/migrations/2023_04_27_053456_create_fleets_table.php +1 -2
  109. package/server/migrations/2023_04_27_053456_create_fuel_reports_table.php +1 -2
  110. package/server/migrations/2023_04_27_053456_create_integrated_vendors_table.php +1 -2
  111. package/server/migrations/2023_04_27_053456_create_issues_table.php +1 -2
  112. package/server/migrations/2023_04_27_053456_create_orders_table.php +1 -2
  113. package/server/migrations/2023_04_27_053456_create_payloads_table.php +1 -2
  114. package/server/migrations/2023_04_27_053456_create_places_table.php +1 -2
  115. package/server/migrations/2023_04_27_053456_create_positions_table.php +1 -2
  116. package/server/migrations/2023_04_27_053456_create_proofs_table.php +1 -2
  117. package/server/migrations/2023_04_27_053456_create_purchase_rates_table.php +1 -2
  118. package/server/migrations/2023_04_27_053456_create_routes_table.php +1 -2
  119. package/server/migrations/2023_04_27_053456_create_service_areas_table.php +1 -2
  120. package/server/migrations/2023_04_27_053456_create_service_quote_items_table.php +1 -2
  121. package/server/migrations/2023_04_27_053456_create_service_quotes_table.php +1 -2
  122. package/server/migrations/2023_04_27_053456_create_service_rate_fees_table.php +1 -2
  123. package/server/migrations/2023_04_27_053456_create_service_rate_parcel_fees_table.php +1 -2
  124. package/server/migrations/2023_04_27_053456_create_service_rates_table.php +1 -2
  125. package/server/migrations/2023_04_27_053456_create_tracking_numbers_table.php +1 -2
  126. package/server/migrations/2023_04_27_053456_create_tracking_statuses_table.php +1 -2
  127. package/server/migrations/2023_04_27_053456_create_vehicles_table.php +1 -2
  128. package/server/migrations/2023_04_27_053456_create_vendors_table.php +1 -2
  129. package/server/migrations/2023_04_27_053456_create_waypoints_table.php +1 -2
  130. package/server/migrations/2023_04_27_053456_create_zones_table.php +1 -2
  131. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_companies_table.php +1 -2
  132. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_contacts_table.php +1 -2
  133. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_drivers_table.php +1 -2
  134. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_entities_table.php +1 -2
  135. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleet_drivers_table.php +1 -2
  136. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fleets_table.php +1 -2
  137. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_fuel_reports_table.php +1 -2
  138. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_integrated_vendors_table.php +1 -2
  139. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_issues_table.php +1 -2
  140. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_orders_table.php +1 -2
  141. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_payloads_table.php +1 -2
  142. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_places_table.php +1 -2
  143. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_positions_table.php +1 -2
  144. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_proofs_table.php +1 -2
  145. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_purchase_rates_table.php +1 -2
  146. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_routes_table.php +1 -2
  147. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_areas_table.php +1 -2
  148. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quote_items_table.php +1 -2
  149. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_quotes_table.php +1 -2
  150. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_fees_table.php +1 -2
  151. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rate_parcel_fees_table.php +1 -2
  152. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_service_rates_table.php +1 -2
  153. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_numbers_table.php +1 -2
  154. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_tracking_statuses_table.php +1 -2
  155. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vehicles_table.php +1 -2
  156. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_vendors_table.php +1 -2
  157. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_waypoints_table.php +1 -2
  158. package/server/migrations/2023_04_27_053459_add_foreign_keys_to_zones_table.php +1 -2
  159. package/server/migrations/2023_09_14_074512_update_vehicles_table.php +1 -2
  160. package/server/migrations/2023_09_14_074619_create_vehicle_devices_table.php +35 -36
  161. package/server/migrations/2023_09_26_071205_add_online_column_to_vehicles_table.php +1 -2
  162. package/server/migrations/2023_09_26_083957_create_fleet_vehicles_table.php +1 -2
  163. package/server/migrations/2023_09_27_023757_add_column_to_fleets_table.php +1 -2
  164. package/server/migrations/2023_10_05_074811_update_vehicle.php +1 -2
  165. package/server/migrations/2023_10_25_093014_create_vehicle_device_events_table.php +1 -2
  166. package/server/migrations/2023_11_03_072503_refactor_issues_table_columns.php +1 -2
  167. package/server/migrations/2023_11_06_040645_refactor_fuel_reports_table.php +1 -2
  168. package/server/migrations/2023_11_09_041807_add_status_column_to_fuel_reports_table.php +1 -2
  169. package/server/migrations/2023_11_15_062814_add_comments_column_and_resolved_at_column_to_vehicle_device_events_table.php +1 -2
  170. package/server/migrations/2023_11_17_053001_add_category_uuid_to_entities_table.php +1 -2
  171. package/server/migrations/2023_11_28_074244_add_supplier_uuid_column_to_entities_table.php +1 -2
  172. package/server/migrations/2023_12_14_100209_add_meta_column_on_driver_table copy.php +1 -2
  173. package/server/migrations/2024_02_18_100209_add_avatar_url_columns_table.php +3 -4
  174. package/server/migrations/2024_02_27_093648_create_order_configs_table.php +43 -0
  175. package/server/migrations/2024_03_07_075508_add_order_config_uuid_column_to_orders_table.php +28 -0
  176. package/server/seeders/OrderConfigSeeder.php +151 -0
  177. package/server/src/Casts/OrderConfigEntities.php +53 -0
  178. package/server/src/Console/Commands/FixLegacyOrderConfigs.php +66 -0
  179. package/server/src/Events/DriverLocationChanged.php +1 -1
  180. package/server/src/Events/DriverSimulatedLocationChanged.php +1 -1
  181. package/server/src/Flow/Activity.php +232 -6
  182. package/server/src/Flow/Condition.php +84 -0
  183. package/server/src/Flow/Event.php +88 -0
  184. package/server/src/Flow/Flow.php +50 -0
  185. package/server/src/Flow/FlowResource.php +143 -0
  186. package/server/src/Flow/Logic.php +57 -1
  187. package/server/src/Http/Controllers/Api/v1/DriverController.php +2 -2
  188. package/server/src/Http/Controllers/Api/v1/IssueController.php +132 -0
  189. package/server/src/Http/Controllers/Api/v1/OrderController.php +130 -57
  190. package/server/src/Http/Controllers/Api/v1/OrganizationController.php +27 -0
  191. package/server/src/Http/Controllers/Api/v1/PlaceController.php +2 -3
  192. package/server/src/Http/Controllers/Controller.php +9 -0
  193. package/server/src/Http/Controllers/FleetOpsController.php +7 -0
  194. package/server/src/Http/Controllers/Internal/v1/OrderConfigController.php +5 -259
  195. package/server/src/Http/Controllers/Internal/v1/OrderController.php +46 -26
  196. package/server/src/Http/Controllers/Internal/v1/SettingController.php +20 -0
  197. package/server/src/Http/Filter/OrderConfigFilter.php +13 -0
  198. package/server/src/Http/Requests/CreateIssueRequest.php +19 -0
  199. package/server/src/Http/Requests/UpdateIssueRequest.php +7 -0
  200. package/server/src/Http/Resources/v1/Order.php +3 -0
  201. package/server/src/Listeners/HandleOrderCanceled.php +8 -4
  202. package/server/src/Listeners/HandleOrderDispatched.php +14 -12
  203. package/server/src/Models/Order.php +527 -31
  204. package/server/src/Models/OrderConfig.php +419 -0
  205. package/server/src/Models/Payload.php +6 -7
  206. package/server/src/Notifications/OrderAssigned.php +1 -1
  207. package/server/src/Notifications/OrderCanceled.php +1 -1
  208. package/server/src/Notifications/OrderDispatchFailed.php +1 -1
  209. package/server/src/Notifications/OrderDispatched.php +1 -1
  210. package/server/src/Notifications/OrderPing.php +1 -1
  211. package/server/src/Providers/FleetOpsServiceProvider.php +3 -1
  212. package/server/src/Providers/NotificationServiceProvider.php +2 -1
  213. package/server/src/Support/Utils.php +17 -0
  214. package/server/src/Traits/HasTrackingNumber.php +9 -9
  215. package/server/src/routes.php +19 -11
  216. package/translations/en-us.yaml +137 -0
  217. package/server/src/Flow/Config.php +0 -7
  218. package/server/src/Support/Flow.php +0 -653
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
4
4
  use Illuminate\Database\Schema\Blueprint;
5
5
  use Illuminate\Support\Facades\Schema;
6
6
 
7
- return new class extends Migration
8
- {
7
+ return new class() extends Migration {
9
8
  /**
10
9
  * Run the migrations.
11
10
  *
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
4
4
  use Illuminate\Database\Schema\Blueprint;
5
5
  use Illuminate\Support\Facades\Schema;
6
6
 
7
- return new class extends Migration
8
- {
7
+ return new class() extends Migration {
9
8
  /**
10
9
  * Run the migrations.
11
10
  *
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
4
4
  use Illuminate\Database\Schema\Blueprint;
5
5
  use Illuminate\Support\Facades\Schema;
6
6
 
7
- return new class extends Migration
8
- {
7
+ return new class() extends Migration {
9
8
  /**
10
9
  * Run the migrations.
11
10
  *
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
4
4
  use Illuminate\Database\Schema\Blueprint;
5
5
  use Illuminate\Support\Facades\Schema;
6
6
 
7
- return new class extends Migration
8
- {
7
+ return new class() extends Migration {
9
8
  /**
10
9
  * Run the migrations.
11
10
  *
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
4
4
  use Illuminate\Database\Schema\Blueprint;
5
5
  use Illuminate\Support\Facades\Schema;
6
6
 
7
- return new class extends Migration
8
- {
7
+ return new class() extends Migration {
9
8
  /**
10
9
  * Run the migrations.
11
10
  *
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
4
4
  use Illuminate\Database\Schema\Blueprint;
5
5
  use Illuminate\Support\Facades\Schema;
6
6
 
7
- return new class extends Migration
8
- {
7
+ return new class() extends Migration {
9
8
  /**
10
9
  * Run the migrations.
11
10
  *
@@ -36,8 +35,8 @@ return new class extends Migration
36
35
  */
37
36
  public function down()
38
37
  {
39
- // Reverse: Increase size of vehicles avatar url column for signed urls
40
- Schema::table('vehicles', function (Blueprint $table) {
38
+ // Reverse: Increase size of vehicles avatar url column for signed urls
39
+ Schema::table('vehicles', function (Blueprint $table) {
41
40
  $table->string('avatar_url', 300)->change();
42
41
  });
43
42
 
@@ -0,0 +1,43 @@
1
+ <?php
2
+
3
+ use Illuminate\Database\Migrations\Migration;
4
+ use Illuminate\Database\Schema\Blueprint;
5
+ use Illuminate\Support\Facades\Schema;
6
+
7
+ return new class() extends Migration {
8
+ /**
9
+ * Run the migrations.
10
+ */
11
+ public function up(): void
12
+ {
13
+ Schema::create('order_configs', function (Blueprint $table) {
14
+ $table->increments('id');
15
+ $table->uuid('uuid')->nullable()->index();
16
+ $table->foreignUuid('company_uuid')->nullable()->references('uuid')->on('companies')->onUpdate('CASCADE')->onDelete('CASCADE');
17
+ $table->foreignUuid('author_uuid')->nullable()->references('uuid')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE');
18
+ $table->foreignUuid('category_uuid')->nullable()->references('uuid')->on('categories')->onUpdate('CASCADE')->onDelete('CASCADE');
19
+ $table->foreignUuid('icon_uuid')->nullable()->references('uuid')->on('files')->onUpdate('CASCADE')->onDelete('CASCADE');
20
+ $table->string('name')->nullable();
21
+ $table->string('namespace')->nullable();
22
+ $table->mediumText('description')->nullable();
23
+ $table->string('key')->nullable();
24
+ $table->string('status')->nullable();
25
+ $table->string('version')->nullable();
26
+ $table->boolean('core_service')->default(0);
27
+ $table->json('flow')->nullable();
28
+ $table->json('entities')->nullable();
29
+ $table->json('tags')->nullable();
30
+ $table->json('meta')->nullable();
31
+ $table->timestamps();
32
+ $table->softDeletes();
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Reverse the migrations.
38
+ */
39
+ public function down(): void
40
+ {
41
+ Schema::dropIfExists('order_configs');
42
+ }
43
+ };
@@ -0,0 +1,28 @@
1
+ <?php
2
+
3
+ use Illuminate\Database\Migrations\Migration;
4
+ use Illuminate\Database\Schema\Blueprint;
5
+ use Illuminate\Support\Facades\Schema;
6
+
7
+ return new class() extends Migration {
8
+ /**
9
+ * Run the migrations.
10
+ */
11
+ public function up(): void
12
+ {
13
+ Schema::table('orders', function (Blueprint $table) {
14
+ $table->foreignUuid('order_config_uuid')->nullable()->after('updated_by_uuid')->references('uuid')->on('order_configs')->onUpdate('CASCADE')->onDelete('CASCADE');
15
+ });
16
+ }
17
+
18
+ /**
19
+ * Reverse the migrations.
20
+ */
21
+ public function down(): void
22
+ {
23
+ Schema::table('orders', function (Blueprint $table) {
24
+ $table->dropForeign(['order_config_uuid']);
25
+ $table->dropColumn(['order_config_uuid']);
26
+ });
27
+ }
28
+ };
@@ -0,0 +1,151 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\FleetOps\Seeders;
4
+
5
+ use Fleetbase\FleetOps\Models\OrderConfig;
6
+ use Fleetbase\Models\Company;
7
+ use Illuminate\Database\Seeder;
8
+ use Illuminate\Support\Str;
9
+
10
+ class OrderConfigSeeder extends Seeder
11
+ {
12
+ /**
13
+ * Run the database seeds.
14
+ *
15
+ * @return void
16
+ */
17
+ public function run()
18
+ {
19
+ $companies = Company::all();
20
+ foreach ($companies as $company) {
21
+ static::createTransportConfig($company);
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Creates or retrieves an existing transport configuration for a given company.
27
+ *
28
+ * This method attempts to find a transport configuration (`OrderConfig`) for the specified company.
29
+ * If such a configuration exists, it's returned. Otherwise, a new configuration is created with default values,
30
+ * such as the company UUID, key, core service flag, status, version, tags, and predefined workflow steps.
31
+ * These steps include 'created', 'enroute', 'started', 'completed', and 'dispatched', each with specific attributes.
32
+ *
33
+ * @param Company $company the company for which the transport configuration is being created or retrieved
34
+ *
35
+ * @return OrderConfig the transport configuration associated with the specified company
36
+ */
37
+ public static function createTransportConfig(Company $company): OrderConfig
38
+ {
39
+ return OrderConfig::firstOrCreate(
40
+ [
41
+ 'company_uuid' => $company->uuid,
42
+ 'key' => 'transport',
43
+ 'namespace' => 'system:order-config:transport',
44
+ ],
45
+ [
46
+ 'name' => 'Transport',
47
+ 'key' => 'transport',
48
+ 'namespace' => 'system:order-config:transport',
49
+ 'description' => 'Default order configuration for transport',
50
+ 'core_service' => 1,
51
+ 'status' => 'private',
52
+ 'version' => '0.0.1',
53
+ 'tags' => ['transport', 'delivery'],
54
+ 'entities' => [],
55
+ 'meta' => [],
56
+ 'flow' => [
57
+ 'created' => [
58
+ 'key' => 'created',
59
+ 'code' => 'created',
60
+ 'color' => '#1f2937',
61
+ 'logic' => [],
62
+ 'events' => [],
63
+ 'status' => 'Order Created',
64
+ 'actions' => [],
65
+ 'details' => 'New order was created.',
66
+ 'options' => [],
67
+ 'complete' => false,
68
+ 'entities' => [],
69
+ 'sequence' => 0,
70
+ 'activities' => ['dispatched'],
71
+ 'internalId' => Str::uuid(),
72
+ 'pod_method' => 'scan',
73
+ 'require_pod' => false,
74
+ ],
75
+ 'enroute' => [
76
+ 'key' => 'enroute',
77
+ 'code' => 'enroute',
78
+ 'color' => '#1f2937',
79
+ 'logic' => [],
80
+ 'events' => [],
81
+ 'status' => 'Driver Enroute',
82
+ 'actions' => [],
83
+ 'details' => 'Driver is en-route.',
84
+ 'options' => [],
85
+ 'complete' => false,
86
+ 'entities' => [],
87
+ 'sequence' => 0,
88
+ 'activities' => ['completed'],
89
+ 'internalId' => Str::uuid(),
90
+ 'pod_method' => 'scan',
91
+ 'require_pod' => false,
92
+ ],
93
+ 'started' => [
94
+ 'key' => 'started',
95
+ 'code' => 'started',
96
+ 'color' => '#1f2937',
97
+ 'logic' => [],
98
+ 'events' => [],
99
+ 'status' => 'Order Started',
100
+ 'actions' => [],
101
+ 'details' => 'Order has been started',
102
+ 'options' => [],
103
+ 'complete' => false,
104
+ 'entities' => [],
105
+ 'sequence' => 0,
106
+ 'activities' => ['enroute'],
107
+ 'internalId' => Str::uuid(),
108
+ 'pod_method' => 'scan',
109
+ 'require_pod' => false,
110
+ ],
111
+ 'completed' => [
112
+ 'key' => 'completed',
113
+ 'code' => 'completed',
114
+ 'color' => '#1f2937',
115
+ 'logic' => [],
116
+ 'events' => [],
117
+ 'status' => 'Order Completed',
118
+ 'actions' => [],
119
+ 'details' => 'Order has been completed.',
120
+ 'options' => [],
121
+ 'complete' => true,
122
+ 'entities' => [],
123
+ 'sequence' => 0,
124
+ 'activities' => [],
125
+ 'internalId' => Str::uuid(),
126
+ 'pod_method' => 'scan',
127
+ 'require_pod' => false,
128
+ ],
129
+ 'dispatched' => [
130
+ 'key' => 'dispatched',
131
+ 'code' => 'dispatched',
132
+ 'color' => '#1f2937',
133
+ 'logic' => [],
134
+ 'events' => [],
135
+ 'status' => 'Order Dispatched',
136
+ 'actions' => [],
137
+ 'details' => 'Order has been dispatched.',
138
+ 'options' => [],
139
+ 'complete' => false,
140
+ 'entities' => [],
141
+ 'sequence' => 0,
142
+ 'activities' => ['started'],
143
+ 'internalId' => Str::uuid(),
144
+ 'pod_method' => 'scan',
145
+ 'require_pod' => false,
146
+ ],
147
+ ],
148
+ ]
149
+ );
150
+ }
151
+ }
@@ -0,0 +1,53 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\FleetOps\Casts;
4
+
5
+ use Fleetbase\Casts\Json;
6
+ use Fleetbase\Models\File;
7
+ use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
8
+
9
+ class OrderConfigEntities implements CastsAttributes
10
+ {
11
+ /**
12
+ * Cast the given value.
13
+ *
14
+ * @param \Illuminate\Database\Eloquent\Model $model
15
+ * @param string $key
16
+ * @param array $attributes
17
+ *
18
+ * @return array
19
+ */
20
+ public function get($model, $key, $value, $attributes)
21
+ {
22
+ $entities = Json::decode($value);
23
+ if (is_array($entities)) {
24
+ $entities = array_map(function ($entity) {
25
+ if (isset($entity['photo_uuid'])) {
26
+ $file = File::where('uuid', $entity['photo_uuid'])->first();
27
+ if ($file) {
28
+ $entity['photo_url'] = $file->url;
29
+ }
30
+ }
31
+
32
+ return $entity;
33
+ }, $entities);
34
+ }
35
+
36
+ return $entities;
37
+ }
38
+
39
+ /**
40
+ * Prepare the given value for storage.
41
+ *
42
+ * @param \Illuminate\Database\Eloquent\Model $model
43
+ * @param string $key
44
+ * @param array $value
45
+ * @param array $attributes
46
+ *
47
+ * @return string
48
+ */
49
+ public function set($model, $key, $value, $attributes)
50
+ {
51
+ return json_encode($value);
52
+ }
53
+ }
@@ -0,0 +1,66 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\FleetOps\Console\Commands;
4
+
5
+ use Fleetbase\FleetOps\Models\Order;
6
+ use Fleetbase\FleetOps\Models\OrderConfig;
7
+ use Fleetbase\Support\Utils;
8
+ use Illuminate\Console\Command;
9
+ use Illuminate\Support\Facades\Artisan;
10
+
11
+ class FixLegacyOrderConfigs extends Command
12
+ {
13
+ /**
14
+ * The name and signature of the console command.
15
+ *
16
+ * @var string
17
+ */
18
+ protected $signature = 'fleetops:fix-legacy-order-configs';
19
+
20
+ /**
21
+ * The console command description.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $description = 'This is a command which migrates legacy orders to the new order config system.';
26
+
27
+ /**
28
+ * Execute the console command.
29
+ *
30
+ * This method is responsible for the main logic of the command.
31
+ * It fetches dispatchable orders, notifies about the current time and number of orders,
32
+ * and then dispatches each order if there are nearby drivers.
33
+ *
34
+ * @return int
35
+ */
36
+ public function handle()
37
+ {
38
+ if (Utils::classExists('\\Fleetbase\\FleetOps\\Seeders\\OrderConfigSeeder')) {
39
+ $this->info('Starting the database seeding...');
40
+
41
+ Artisan::call('db:seed', [
42
+ '--class' => '\\Fleetbase\\FleetOps\\Seeders\\OrderConfigSeeder',
43
+ ]);
44
+
45
+ $this->info('Database seeding completed.');
46
+ }
47
+
48
+ $orders = Order::whereNull('order_config_uuid')->get();
49
+ $totalOrders = $orders->count();
50
+ $this->info($totalOrders . ' orders found for updating.');
51
+ $progressBar = $this->output->createProgressBar($totalOrders);
52
+ $progressBar->start();
53
+ foreach ($orders as $order) {
54
+ $orderConfig = OrderConfig::where(['company_uuid' => $order->company_uuid, 'namespace' => 'system:order-config:transport'])->first();
55
+ if ($orderConfig) {
56
+ $order->update(['order_config_uuid' => $orderConfig->uuid]);
57
+ }
58
+ // Advance the progress bar by one step
59
+ $progressBar->advance();
60
+ }
61
+
62
+ $progressBar->finish();
63
+ $this->line('');
64
+ $this->info('All orders have been processed.');
65
+ }
66
+ }
@@ -124,7 +124,7 @@ class DriverLocationChanged implements ShouldBroadcast
124
124
  /**
125
125
  * Get the channels the event should broadcast on.
126
126
  *
127
- * @return \Illuminate\Broadcasting\Channel|array
127
+ * @return Channel|array
128
128
  */
129
129
  public function broadcastOn()
130
130
  {
@@ -133,7 +133,7 @@ class DriverSimulatedLocationChanged implements ShouldBroadcast
133
133
  /**
134
134
  * Get the channels the event should broadcast on.
135
135
  *
136
- * @return \Illuminate\Broadcasting\Channel|array
136
+ * @return Channel|array
137
137
  */
138
138
  public function broadcastOn()
139
139
  {
@@ -2,12 +2,238 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Flow;
4
4
 
5
- use Fleetbase\Models\Model;
5
+ use Fleetbase\FleetOps\Models\Order;
6
+ use Fleetbase\FleetOps\Support\Utils;
6
7
 
7
- class Activity
8
+ class Activity extends FlowResource
8
9
  {
9
- protected string $status;
10
- protected string $code;
11
- protected string $details;
12
- protected Model $owner;
10
+ /**
11
+ * The Flow context for the activity.
12
+ */
13
+ public Flow $flow;
14
+
15
+ /**
16
+ * Create a new Activity instance.
17
+ *
18
+ * @param array $attributes initial attributes of the activity
19
+ * @param array $flow the flow configuration for this activity
20
+ */
21
+ public function __construct(array $attributes = [], array $flow = [])
22
+ {
23
+ parent::__construct($attributes);
24
+ $this->flow = new Flow($flow);
25
+ }
26
+
27
+ /**
28
+ * Retrieves the logic attribute of the Activity.
29
+ *
30
+ * @return array an array of Logic instances associated with the Activity
31
+ */
32
+ public function getLogicAttribute(): array
33
+ {
34
+ return array_map(
35
+ function ($logic) {
36
+ return new Logic($logic);
37
+ },
38
+ $this->get('logic', [])
39
+ );
40
+ }
41
+
42
+ /**
43
+ * Retrieves the events attribute of the Activity.
44
+ *
45
+ * @return array an array of Event instances associated with the Activity
46
+ */
47
+ public function getEventsAttribute(): array
48
+ {
49
+ return array_map(
50
+ function ($eventName) {
51
+ return new Event($eventName);
52
+ },
53
+ $this->get('events', [])
54
+ );
55
+ }
56
+
57
+ /**
58
+ * Determines if the Activity passes based on the provided Order.
59
+ *
60
+ * @param Order $order the order to evaluate against the Activity's logic
61
+ *
62
+ * @return bool true if all the logic associated with the Activity passes; False otherwise
63
+ */
64
+ public function passes(Order $order)
65
+ {
66
+ $logicCollection = collect($this->logic);
67
+
68
+ return $logicCollection->every(function ($logic) use ($order) {
69
+ $conditionCollection = collect($logic->conditions);
70
+
71
+ switch ($logic->type) {
72
+ case 'and':
73
+ // All conditions must be true
74
+ return $conditionCollection->every(fn ($condition) => $condition->eval($order));
75
+
76
+ case 'or':
77
+ // At least one condition must be true
78
+ return $conditionCollection->contains(fn ($condition) => $condition->eval($order));
79
+
80
+ case 'not':
81
+ // None of the conditions must be true (assuming 'not' can have multiple conditions)
82
+ return !$conditionCollection->contains(fn ($condition) => $condition->eval($order));
83
+
84
+ case 'if':
85
+ // Only one condition in 'if', and it must be true (typically, 'if' has only one condition)
86
+ return $conditionCollection->first()->eval($order);
87
+
88
+ default:
89
+ // Unrecognized logic type
90
+ throw new \Exception("Unsupported logic type '{$logic->type}' provided.");
91
+ }
92
+ });
93
+ }
94
+
95
+ /**
96
+ * Fires a series of events associated with an order.
97
+ *
98
+ * Iterates over the events array and triggers each event, passing the order as a parameter.
99
+ * This function is typically used to execute a sequence of events as part of a workflow process.
100
+ *
101
+ * @param Order $order the order object to be passed to each event
102
+ */
103
+ public function fireEvents(Order $order)
104
+ {
105
+ foreach ($this->events as $event) {
106
+ $event->fire($order);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Retrieves the child activities of this Activity.
112
+ *
113
+ * @return \Illuminate\Support\Collection a collection of child activities
114
+ */
115
+ public function getChildActivities()
116
+ {
117
+ $children = collect();
118
+ if (is_array($this->activities)) {
119
+ foreach ($this->activities as $childActivityCode) {
120
+ $childActivity = $this->flow->getActivity($childActivityCode);
121
+ if ($childActivity) {
122
+ $children->push($childActivity);
123
+ }
124
+ }
125
+ }
126
+
127
+ return $children;
128
+ }
129
+
130
+ /**
131
+ * Retrieves the children activities of this Activity.
132
+ *
133
+ * This is a shorthand method for `getChildActivities`.
134
+ *
135
+ * @return \Illuminate\Support\Collection the collection of child activities
136
+ */
137
+ public function children()
138
+ {
139
+ return $this->getChildActivities();
140
+ }
141
+
142
+ /**
143
+ * Checks whether this Activity has a child activity with a specified code.
144
+ *
145
+ * @param string $code the unique code identifier for the child activity
146
+ *
147
+ * @return bool true if the child activity is found; otherwise, False
148
+ */
149
+ public function hasChildActivity(string $code)
150
+ {
151
+ return $this->children()->contains(
152
+ function ($activity) use ($code) {
153
+ return $activity->code === $code;
154
+ }
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Determines the next set of activities based on the provided Order.
160
+ *
161
+ * @param Order $order the order to determine the next activities for
162
+ *
163
+ * @return \Illuminate\Support\Collection a collection of the next activities
164
+ */
165
+ public function getNext(Order $order)
166
+ {
167
+ $children = $this->getChildActivities();
168
+ $nextActivities = collect();
169
+
170
+ foreach ($children as $childActivity) {
171
+ if ($childActivity->passes($order)) {
172
+ $nextActivities->push($childActivity);
173
+ }
174
+ }
175
+
176
+ return $nextActivities;
177
+ }
178
+
179
+ /**
180
+ * Retrieves the previous activities of this Activity in the Flow.
181
+ *
182
+ * This method iterates over the flow to find activities that list this Activity as a child.
183
+ *
184
+ * @return \Illuminate\Support\Collection a collection of previous activities
185
+ */
186
+ public function getPrevious()
187
+ {
188
+ $previous = collect();
189
+ foreach ($this->flow as $activity) {
190
+ if ($activity->hasChildActivity($this->code)) {
191
+ $previous->push($activity);
192
+ }
193
+ }
194
+
195
+ return $previous;
196
+ }
197
+
198
+ /**
199
+ * Checks if the activity's code matches a specified code.
200
+ *
201
+ * This method is used to determine if the current activity instance
202
+ * has a specific code, which is useful for identifying the activity.
203
+ *
204
+ * @param string $code the code to compare against the activity's code
205
+ *
206
+ * @return bool returns true if the activity's code matches the specified code, false otherwise
207
+ */
208
+ public function is(string $code)
209
+ {
210
+ return $this->code === $code;
211
+ }
212
+
213
+ /**
214
+ * Determines if the activity is marked as complete.
215
+ *
216
+ * This method checks the 'complete' property of the activity. It's typically used
217
+ * to verify if the activity has been completed as part of the workflow process.
218
+ *
219
+ * @return bool returns true if the activity is marked as complete, false otherwise
220
+ */
221
+ public function complete(): bool
222
+ {
223
+ return Utils::isTrue($this->complete);
224
+ }
225
+
226
+ /**
227
+ * Checks if completing this activity leads to the completion of the order.
228
+ *
229
+ * This method uses the `complete` method to determine if the completion of
230
+ * this activity signifies the completion of the associated order. It is useful
231
+ * for workflows where the finalization of an activity concludes the entire order process.
232
+ *
233
+ * @return bool returns true if completing this activity completes the order, false otherwise
234
+ */
235
+ public function completesOrder(): bool
236
+ {
237
+ return $this->complete();
238
+ }
13
239
  }