@fleetbase/fleetops-engine 0.3.9 → 0.4.1

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 (209) hide show
  1. package/addon/components/admin/navigator-app.hbs +3 -3
  2. package/addon/components/admin/visibility-controls.hbs +4 -4
  3. package/addon/components/cell/driver-name.hbs +1 -1
  4. package/addon/components/contact-form-panel.hbs +15 -15
  5. package/addon/components/contact-form-panel.js +5 -1
  6. package/addon/components/contact-panel/details.hbs +7 -7
  7. package/addon/components/contact-panel.hbs +2 -2
  8. package/addon/components/display-place.hbs +2 -2
  9. package/addon/components/driver-card.hbs +1 -1
  10. package/addon/components/driver-form-panel.hbs +36 -29
  11. package/addon/components/driver-form-panel.js +5 -1
  12. package/addon/components/driver-panel/details.hbs +10 -10
  13. package/addon/components/driver-panel.hbs +5 -5
  14. package/addon/components/fleet-driver-listing.hbs +5 -5
  15. package/addon/components/fleet-form-panel.hbs +16 -16
  16. package/addon/components/fleet-form-panel.js +5 -1
  17. package/addon/components/fleet-panel/details.hbs +7 -7
  18. package/addon/components/fleet-panel/driver-listing.hbs +5 -5
  19. package/addon/components/fleet-panel/driver-listing.js +6 -0
  20. package/addon/components/fleet-panel/vehicle-listing.hbs +5 -5
  21. package/addon/components/fleet-panel/vehicle-listing.js +6 -0
  22. package/addon/components/fleet-vehicle-listing.hbs +5 -5
  23. package/addon/components/fuel-report-form-panel.hbs +16 -16
  24. package/addon/components/fuel-report-form-panel.js +5 -1
  25. package/addon/components/fuel-report-panel/details.hbs +11 -11
  26. package/addon/components/fuel-report-panel.hbs +3 -3
  27. package/addon/components/global-search.hbs +1 -1
  28. package/addon/components/horizontal-route.hbs +1 -1
  29. package/addon/components/integrated-order-details.hbs +13 -13
  30. package/addon/components/issue-form-panel.hbs +25 -25
  31. package/addon/components/issue-form-panel.js +6 -1
  32. package/addon/components/issue-panel/details.hbs +11 -11
  33. package/addon/components/issue-panel.hbs +3 -3
  34. package/addon/components/layout/fleet-ops-sidebar.hbs +2 -2
  35. package/addon/components/layout/fleet-ops-sidebar.js +28 -12
  36. package/addon/components/live-map-drawer/driver-listing.hbs +1 -1
  37. package/addon/components/live-map-drawer/driver-listing.js +16 -10
  38. package/addon/components/live-map-drawer/place-listing.hbs +1 -1
  39. package/addon/components/live-map-drawer/place-listing.js +12 -7
  40. package/addon/components/live-map-drawer/vehicle-listing.hbs +1 -1
  41. package/addon/components/live-map-drawer/vehicle-listing.js +15 -9
  42. package/addon/components/live-map.hbs +10 -92
  43. package/addon/components/live-map.js +29 -24
  44. package/addon/components/map-container/toolbar/visibility-control-panel.hbs +9 -9
  45. package/addon/components/map-container/toolbar/zones-panel.hbs +10 -10
  46. package/addon/components/map-container/toolbar.hbs +6 -6
  47. package/addon/components/modals/assign-driver.hbs +2 -2
  48. package/addon/components/modals/clone-config-form.hbs +2 -2
  49. package/addon/components/modals/contact-details.hbs +6 -6
  50. package/addon/components/modals/contact-form.hbs +11 -11
  51. package/addon/components/modals/driver-assign-order.hbs +2 -2
  52. package/addon/components/modals/driver-assign-vehicle.hbs +2 -2
  53. package/addon/components/modals/driver-assign-vendor.hbs +2 -2
  54. package/addon/components/modals/driver-details.hbs +14 -14
  55. package/addon/components/modals/driver-form.hbs +18 -18
  56. package/addon/components/modals/edit-meta-form.hbs +2 -2
  57. package/addon/components/modals/entity-form.hbs +16 -16
  58. package/addon/components/modals/entity-meta-field-prompt.hbs +1 -1
  59. package/addon/components/modals/fleet-details.hbs +6 -6
  60. package/addon/components/modals/fleet-form.hbs +8 -8
  61. package/addon/components/modals/fuel-report-details.hbs +9 -9
  62. package/addon/components/modals/fuel-report-form.hbs +8 -8
  63. package/addon/components/modals/group-details.hbs +4 -4
  64. package/addon/components/modals/group-form.hbs +6 -6
  65. package/addon/components/modals/install-prompt.hbs +2 -3
  66. package/addon/components/modals/issue-details.hbs +8 -8
  67. package/addon/components/modals/issue-from.hbs +21 -21
  68. package/addon/components/modals/map-field-form.hbs +2 -2
  69. package/addon/components/modals/map-field-group-form.hbs +1 -1
  70. package/addon/components/modals/map-layer-form.hbs +10 -10
  71. package/addon/components/modals/meta-field-form.hbs +2 -2
  72. package/addon/components/modals/meta-field-group-form.hbs +1 -1
  73. package/addon/components/modals/new-order-config.hbs +4 -4
  74. package/addon/components/modals/order-assign-driver.hbs +2 -2
  75. package/addon/components/modals/order-config-new-status.hbs +1 -1
  76. package/addon/components/modals/order-event.hbs +2 -2
  77. package/addon/components/modals/order-form.hbs +8 -8
  78. package/addon/components/modals/order-import.hbs +8 -8
  79. package/addon/components/modals/order-label.hbs +1 -1
  80. package/addon/components/modals/order-new-activity.hbs +10 -10
  81. package/addon/components/modals/order-route-form.hbs +17 -17
  82. package/addon/components/modals/place-assign-vendor.hbs +2 -2
  83. package/addon/components/modals/place-details.hbs +13 -13
  84. package/addon/components/modals/place-form.hbs +15 -15
  85. package/addon/components/modals/policy-form.hbs +5 -5
  86. package/addon/components/modals/role-form.hbs +3 -3
  87. package/addon/components/modals/select-payment-method.hbs +1 -1
  88. package/addon/components/modals/service-area-form.hbs +8 -8
  89. package/addon/components/modals/set-password.hbs +3 -3
  90. package/addon/components/modals/uninstall-prompt.hbs +2 -3
  91. package/addon/components/modals/user-form.hbs +9 -9
  92. package/addon/components/modals/vehicle-details.hbs +41 -41
  93. package/addon/components/modals/vehicle-form.hbs +73 -73
  94. package/addon/components/modals/vendor-details.hbs +10 -10
  95. package/addon/components/modals/vendor-form.hbs +36 -36
  96. package/addon/components/modals/view-service-area.hbs +1 -1
  97. package/addon/components/modals/zone-form.hbs +6 -6
  98. package/addon/components/order/header.hbs +11 -11
  99. package/addon/components/order/place-card.hbs +2 -2
  100. package/addon/components/order/schedule-card.hbs +6 -6
  101. package/addon/components/order/schedule-card.js +11 -7
  102. package/addon/components/order-config/activity-flow-editor.hbs +14 -14
  103. package/addon/components/order-config/activity-flow-editor.js +11 -11
  104. package/addon/components/order-config/details-editor.hbs +9 -9
  105. package/addon/components/order-config/entities-editor.hbs +13 -13
  106. package/addon/components/order-config/entities-editor.js +2 -2
  107. package/addon/components/order-config/fields-editor.hbs +14 -14
  108. package/addon/components/order-config/fields-editor.js +13 -12
  109. package/addon/components/order-config.hbs +9 -9
  110. package/addon/components/order-config.js +12 -11
  111. package/addon/components/order-list-overlay.hbs +14 -14
  112. package/addon/components/place-form-panel.hbs +18 -18
  113. package/addon/components/place-form-panel.js +6 -1
  114. package/addon/components/place-panel/details.hbs +10 -10
  115. package/addon/components/place-panel.hbs +2 -2
  116. package/addon/components/route-list.hbs +2 -2
  117. package/addon/components/settings-window.hbs +5 -5
  118. package/addon/components/settings-window.js +2 -1
  119. package/addon/components/vehicle-form-panel.hbs +27 -27
  120. package/addon/components/vehicle-form-panel.js +7 -2
  121. package/addon/components/vehicle-panel/details.hbs +7 -7
  122. package/addon/components/vehicle-panel.hbs +4 -4
  123. package/addon/components/vendor-form-panel/create-form.hbs +34 -33
  124. package/addon/components/vendor-form-panel/create-form.js +6 -2
  125. package/addon/components/vendor-form-panel/edit-form.hbs +27 -27
  126. package/addon/components/vendor-form-panel/edit-form.js +1 -0
  127. package/addon/components/vendor-form-panel.hbs +6 -6
  128. package/addon/components/vendor-form-panel.js +6 -1
  129. package/addon/components/vendor-panel/details.hbs +10 -10
  130. package/addon/components/vendor-panel.hbs +3 -3
  131. package/addon/components/widget/fleet-ops-quickstart.hbs +2 -2
  132. package/addon/components/widget/fleet-ops-quickstart.js +1 -0
  133. package/addon/components/widget/key-metrics.hbs +12 -12
  134. package/addon/components/widget/live-order-map.hbs +4 -4
  135. package/addon/components/widget/recent-orders.hbs +4 -4
  136. package/addon/components/widget/transactions.hbs +4 -4
  137. package/addon/controllers/management/contacts/index/edit.js +10 -3
  138. package/addon/controllers/management/contacts/index/new.js +7 -0
  139. package/addon/controllers/management/contacts/index.js +23 -16
  140. package/addon/controllers/management/drivers/index/edit.js +10 -3
  141. package/addon/controllers/management/drivers/index/new.js +7 -0
  142. package/addon/controllers/management/drivers/index.js +33 -19
  143. package/addon/controllers/management/fleets/index/edit.js +10 -3
  144. package/addon/controllers/management/fleets/index/new.js +7 -0
  145. package/addon/controllers/management/fleets/index.js +24 -17
  146. package/addon/controllers/management/fuel-reports/index/edit.js +10 -3
  147. package/addon/controllers/management/fuel-reports/index/new.js +7 -0
  148. package/addon/controllers/management/fuel-reports/index.js +20 -13
  149. package/addon/controllers/management/issues/index/edit.js +10 -3
  150. package/addon/controllers/management/issues/index/new.js +8 -0
  151. package/addon/controllers/management/issues/index.js +22 -15
  152. package/addon/controllers/management/places/index/edit.js +10 -3
  153. package/addon/controllers/management/places/index/new.js +7 -0
  154. package/addon/controllers/management/places/index.js +27 -20
  155. package/addon/controllers/management/vehicles/index/edit.js +10 -3
  156. package/addon/controllers/management/vehicles/index/new.js +7 -0
  157. package/addon/controllers/management/vehicles/index.js +22 -15
  158. package/addon/controllers/management/vendors/index/edit.js +10 -3
  159. package/addon/controllers/management/vendors/index/new.js +7 -0
  160. package/addon/controllers/management/vendors/index.js +23 -16
  161. package/addon/controllers/operations/orders/index/new.js +110 -25
  162. package/addon/controllers/operations/orders/index/view.js +40 -16
  163. package/addon/controllers/operations/orders/index.js +34 -27
  164. package/addon/controllers/operations/scheduler/index.js +3 -2
  165. package/addon/controllers/operations/service-rates/index/edit.js +9 -1
  166. package/addon/controllers/operations/service-rates/index/new.js +9 -1
  167. package/addon/controllers/operations/service-rates/index.js +16 -9
  168. package/addon/routes/management/places/index.js +1 -1
  169. package/addon/routes/operations/orders/index/view.js +2 -14
  170. package/addon/services/driver-actions.js +9 -8
  171. package/addon/services/vehicle-actions.js +2 -1
  172. package/addon/templates/management/contacts/index.hbs +6 -6
  173. package/addon/templates/management/drivers/index.hbs +6 -6
  174. package/addon/templates/management/fleets/index.hbs +6 -6
  175. package/addon/templates/management/fuel-reports/index.hbs +7 -7
  176. package/addon/templates/management/index.hbs +17 -17
  177. package/addon/templates/management/issues/index.hbs +6 -6
  178. package/addon/templates/management/places/index.hbs +6 -6
  179. package/addon/templates/management/vehicles/index.hbs +6 -6
  180. package/addon/templates/management/vendors/index.hbs +6 -6
  181. package/addon/templates/operations/orders/index/config/types.hbs +3 -3
  182. package/addon/templates/operations/orders/index/config.hbs +3 -4
  183. package/addon/templates/operations/orders/index/new.hbs +72 -72
  184. package/addon/templates/operations/orders/index/view.hbs +147 -53
  185. package/addon/templates/operations/orders/index.hbs +13 -13
  186. package/addon/templates/operations/scheduler/index.hbs +3 -3
  187. package/addon/templates/operations/service-rates/index/new.hbs +79 -81
  188. package/addon/templates/operations/service-rates/index.hbs +6 -6
  189. package/composer.json +2 -2
  190. package/extension.json +1 -1
  191. package/package.json +3 -1
  192. package/server/resources/views/labels/default.php +40 -18
  193. package/server/resources/views/labels/waypoint-label.php +126 -0
  194. package/server/src/Console/Commands/FixDriverCompanies.php +65 -0
  195. package/server/src/Exceptions/IntegratedVendorException.php +11 -12
  196. package/server/src/Http/Controllers/Api/v1/DriverController.php +41 -32
  197. package/server/src/Http/Controllers/Api/v1/OrderController.php +1 -1
  198. package/server/src/Http/Controllers/Internal/v1/DriverController.php +17 -1
  199. package/server/src/Http/Resources/v1/Driver.php +1 -1
  200. package/server/src/Http/Resources/v1/Entity.php +2 -2
  201. package/server/src/Http/Resources/v1/Payload.php +11 -30
  202. package/server/src/Http/Resources/v1/Place.php +3 -3
  203. package/server/src/Http/Resources/v1/Waypoint.php +101 -0
  204. package/server/src/Models/Payload.php +39 -0
  205. package/server/src/Models/Place.php +5 -2
  206. package/server/src/Models/Waypoint.php +15 -3
  207. package/server/src/Providers/FleetOpsServiceProvider.php +1 -0
  208. package/server/src/Support/Flow.php +19 -2
  209. package/translations/en-us.yaml +1341 -3
@@ -0,0 +1,126 @@
1
+ <?php
2
+ use Fleetbase\Support\Utils;
3
+ ?>
4
+
5
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+ <html xmlns="http://www.w3.org/1999/xhtml">
7
+
8
+ <head>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
10
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
11
+ <title><?= $company->name ?? ($waypoint->internal_id ?? $waypoint->public_id) ?> Waypoint Label</title>
12
+ </head>
13
+
14
+ <style>
15
+ .group:after {
16
+ content: "";
17
+ display: table;
18
+ clear: both;
19
+ }
20
+
21
+ .places--display-address {
22
+ display: block;
23
+ }
24
+
25
+ .places--display-address .line {
26
+ display: block;
27
+ }
28
+
29
+ .places--display-address .line:first-child {
30
+ display: block;
31
+ font-weight: 600;
32
+ }
33
+
34
+ .places--display-address .line .segment {
35
+ display: inline-block;
36
+ margin-right: 3px;
37
+ }
38
+
39
+ .places--display-address .line .segment:not(:last-child):after {
40
+ content: ", ";
41
+ }
42
+ </style>
43
+
44
+ <body bgcolor="#f7f7f7">
45
+ <div style="width: 420px; border: 2px #414141 solid; margin: auto;">
46
+ <div class="group" style="border-bottom: 1px #414141 solid; overflow: hidden;">
47
+ <div style="float: left; width: 130px; height: 120px; border-right: 1px #414141 solid; text-align: center; padding: 10px; box-sizing: border-box;">
48
+ <img src="data:image/png;base64,<?= Utils::notEmpty($trackingNumber) ? $trackingNumber->qr_code : $order->trackingNumber->qr_code ?>" style="width: 100%; height: 100%; object-fit: cover;">
49
+ </div>
50
+ <div style="margin-top: 10px;">
51
+ <span style="padding-left: 10px; font-size: 18px; font-weight: bold;"><?= strtoupper($company->name) ?></span>
52
+ </div>
53
+ </div>
54
+
55
+ <?php if ($dropoff) { ?>
56
+ <div class="group">
57
+ <div style="padding: 15px;" class="group" style="border-bottom: 1px #414141 solid; padding: 15px;">
58
+ <div style="float: left; display: inline-block; margin-right: 15px; font-weight: bold;">
59
+ ADDRESS:
60
+ </div>
61
+ <div class="places--display-address" style="float: left; display: inline-block">
62
+ <div class="line"><strong><?= $dropoff->name ?></strong></div>
63
+ <div class="line"><?= $dropoff->street1 ?></div>
64
+ <?php if (!empty($dropoff->street2)) { ?>
65
+ <div class="line"><?= $dropoff->street2 ?></div>
66
+ <?php } ?>
67
+ <div class="line">
68
+ <?php if (!empty($dropoff->neighborhood)) { ?>
69
+ <span class="segment"><?= $dropoff->neighborhood ?></span>
70
+ <?php } ?>
71
+ <?php if (!empty($dropoff->district)) { ?>
72
+ <span class="segment"><?= $dropoff->district ?></span>
73
+ <?php } ?>
74
+ </div>
75
+ <div class="line">
76
+ <?php if (!empty($dropoff->postal_code)) { ?>
77
+ <span class="segment"><?= $dropoff->postal_code ?></span>
78
+ <?php } ?>
79
+ <?php if (!empty($dropoff->city)) { ?>
80
+ <span class="segment"><?= $dropoff->city ?></span>
81
+ <?php } ?>
82
+ <?php if (!empty($dropoff->province)) { ?>
83
+ <span class="segment"><?= $dropoff->province ?></span>
84
+ <?php } ?>
85
+ <?php if (!empty($dropoff->country)) { ?>
86
+ <span class="segment"><?= $dropoff->country ?></span>
87
+ <?php } ?>
88
+ </div>
89
+ <?php if (!empty($dropoff->phone_number)) { ?>
90
+ <div class="line"><?= $dropoff->phone_number ?></div>
91
+ <?php } ?>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ <?php } ?>
96
+ <?php if ($entities) { ?>
97
+ <div class="group">
98
+ <div style="padding: 15px;" class="group" style="border-bottom: 1px #414141 solid; padding: 15px;">
99
+ <div style="float: left; display: inline-block; margin-right: 15px">
100
+ <?php foreach ($entities as $entity) { ?>
101
+ <div class="line">
102
+ <strong>
103
+ <?php
104
+ if (data_get($entity, 'name')) {
105
+ echo strtoupper(data_get($entity, 'name') . ' - ' . data_get($entity, 'internal_id', ''));
106
+ } else {
107
+ echo strtoupper('ITEM - ' . data_get($entity, 'internal_id', ''));
108
+ }
109
+ ?>
110
+ </strong>
111
+ </div>
112
+ <?php } ?>
113
+ </div>
114
+ </div>
115
+ </div>
116
+ <?php } ?>
117
+ <div class="group">
118
+ <div style="text-align: center; padding: 15px 0px; border-top: 1px #414141 solid;">
119
+ <img src="data:image/png;base64,<?= isset($trackingNumber) ? $trackingNumber->barcode : $order->trackingNumber->barcode ?>" style="height: 90px; margin-top: 10px;">
120
+ <div><?= strtoupper(isset($trackingNumber) ? $trackingNumber->tracking_number : $order->trackingNumber->tracking_number) ?></div>
121
+ </div>
122
+ </div>
123
+ </div>
124
+ </body>
125
+
126
+ </html>
@@ -0,0 +1,65 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\FleetOps\Console\Commands;
4
+
5
+ use Fleetbase\FleetOps\Models\Driver;
6
+ use Fleetbase\Models\Company;
7
+ use Fleetbase\Models\CompanyUser;
8
+ use Illuminate\Console\Command;
9
+
10
+ class FixDriverCompanies extends Command
11
+ {
12
+ /**
13
+ * The name and signature of the console command.
14
+ *
15
+ * @var string
16
+ */
17
+ protected $signature = 'fleetops:fix-driver-companies';
18
+
19
+ /**
20
+ * The console command description.
21
+ *
22
+ * @var string
23
+ */
24
+ protected $description = 'This is a command which checks driver\'s users to make sure they are assigned to company, if not it assigns the user to the drivers company';
25
+
26
+ /**
27
+ * Execute the console command.
28
+ *
29
+ * This method is responsible for the main logic of the command.
30
+ * It fetches dispatchable orders, notifies about the current time and number of orders,
31
+ * and then dispatches each order if there are nearby drivers.
32
+ *
33
+ * @return int
34
+ */
35
+ public function handle()
36
+ {
37
+ $drivers = Driver::whereHas('user', function ($query) {
38
+ $query->whereNull('company_uuid');
39
+ $query->withTrashed();
40
+ })->with(['user'])->get();
41
+
42
+ // Fix these drivers
43
+ foreach ($drivers as $driver) {
44
+ $user = $driver->user;
45
+ if ($user) {
46
+ $this->line('Found user ' . $user->name . ' (' . $user->email . ') which has no company assigned');
47
+ // Get company from driver profile
48
+ $company = Company::where('uuid', $driver->company_uuid)->first();
49
+ if ($company) {
50
+ $user->assignCompany($company);
51
+
52
+ // create company user
53
+ CompanyUser::create([
54
+ 'user_uuid' => $user->uuid,
55
+ 'company_uuid' => $company->uuid,
56
+ 'status' => 'active',
57
+ ]);
58
+
59
+ // Inform
60
+ $this->line('User ' . $user->email . ' was assigned to company: ' . $company->name);
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
@@ -7,32 +7,30 @@ use Illuminate\Contracts\Support\Responsable;
7
7
  use Illuminate\Http\JsonResponse;
8
8
 
9
9
  /**
10
- * Class IntegratedVendorException
10
+ * Class IntegratedVendorException.
11
11
  *
12
12
  * Custom exception class for IntegratedVendor-related exceptions.
13
- *
14
- * @package Fleetbase\FleetOps\Exceptions
15
13
  */
16
14
  class IntegratedVendorException extends \Exception implements Responsable
17
15
  {
18
16
  /**
19
- * @var IntegratedVendor|null The IntegratedVendor instance associated with the exception.
17
+ * @var IntegratedVendor|null the IntegratedVendor instance associated with the exception
20
18
  */
21
19
  public ?IntegratedVendor $integratedVendor;
22
20
 
23
21
  /**
24
- * @var string The trigger method that caused the exception.
22
+ * @var string the trigger method that caused the exception
25
23
  */
26
24
  public string $triggerMethod;
27
25
 
28
26
  /**
29
27
  * IntegratedVendorException constructor.
30
28
  *
31
- * @param string $message The exception message.
32
- * @param IntegratedVendor|null $integratedVendor The IntegratedVendor instance associated with the exception.
33
- * @param string|null $triggerMethod The trigger method that caused the exception.
34
- * @param int $code The exception code.
35
- * @param \Throwable|null $previous The previous throwable used for the exception chaining.
29
+ * @param string $message the exception message
30
+ * @param IntegratedVendor|null $integratedVendor the IntegratedVendor instance associated with the exception
31
+ * @param string|null $triggerMethod the trigger method that caused the exception
32
+ * @param int $code the exception code
33
+ * @param \Throwable|null $previous the previous throwable used for the exception chaining
36
34
  */
37
35
  public function __construct(string $message = '', IntegratedVendor $integratedVendor = null, string $triggerMethod = null, int $code = 400, \Throwable $previous = null)
38
36
  {
@@ -45,6 +43,7 @@ class IntegratedVendorException extends \Exception implements Responsable
45
43
  * Get the response representing the exception.
46
44
  *
47
45
  * @param \Illuminate\Http\Request $request
46
+ *
48
47
  * @return \Illuminate\Http\JsonResponse
49
48
  */
50
49
  public function toResponse($request)
@@ -53,8 +52,8 @@ class IntegratedVendorException extends \Exception implements Responsable
53
52
 
54
53
  return new JsonResponse(
55
54
  [
56
- 'errors' => [$errorMessage],
57
- 'integratedVendorId' => data_get($this->integratedVendor, 'uuid')
55
+ 'errors' => [$errorMessage],
56
+ 'integratedVendorId' => data_get($this->integratedVendor, 'uuid'),
58
57
  ],
59
58
  400
60
59
  );
@@ -360,32 +360,31 @@ class DriverController extends Controller
360
360
  {
361
361
  $identity = $request->input('identity');
362
362
  $password = $request->input('password');
363
- $attrs = $request->input(['name', 'phone', 'email']);
363
+ // $attrs = $request->input(['name', 'phone', 'email']);
364
364
 
365
- $user = User::where('email', $identity)->orWhere('phone', static::phone($identity))->first();
365
+ // Get driver attempting to authenticate via phone
366
+ $user = User::where(
367
+ function ($query) use ($identity) {
368
+ $query->where('phone', static::phone($identity));
369
+ $query->owWhere('email', $identity);
370
+ }
371
+ )->whereHas('driver')->first();
366
372
 
373
+ // Check password to authenticate driver
367
374
  if (!Hash::check($password, $user->password)) {
368
375
  return response()->apiError('Authentication failed using password provided.', 401);
369
376
  }
370
377
 
371
- // Get the company session for the user
372
- $company = Flow::getCompanySessionForUser($user);
378
+ // Get the user's company for this driver profile
379
+ $company = $this->_getDriverCompanyFromUser($user);
373
380
 
374
381
  // Get driver record
375
- $driver = Driver::firstOrCreate(
376
- [
377
- 'user_uuid' => $user->uuid,
378
- 'company_uuid' => $company->uuid,
379
- ],
382
+ $driver = Driver::where(
380
383
  [
381
384
  'user_uuid' => $user->uuid,
382
385
  'company_uuid' => $company->uuid,
383
- 'name' => data_get($attrs, 'name', $user->name),
384
- 'phone' => data_get($attrs, 'phone', $user->phone),
385
- 'email' => data_get($attrs, 'email', $user->email),
386
- 'location' => new Point(0, 0),
387
386
  ]
388
- );
387
+ )->first();
389
388
 
390
389
  // generate auth token
391
390
  try {
@@ -409,19 +408,18 @@ class DriverController extends Controller
409
408
  $phone = static::phone();
410
409
 
411
410
  // check if user exists
412
- $user = User::where('phone', $phone)->whereNull('deleted_at')->withoutGlobalScopes()->first();
413
-
411
+ $user = User::where('phone', $phone)->whereHas('driver')->whereNull('deleted_at')->withoutGlobalScopes()->first();
414
412
  if (!$user) {
415
413
  return response()->apiError('No driver with this phone # found.');
416
414
  }
417
415
 
418
- // get the current company session
419
- $company = Flow::getCompanySessionForUser($user);
416
+ // Get the user's company for this driver profile
417
+ $company = $this->_getDriverCompanyFromUser($user);
420
418
 
421
419
  // generate verification token
422
420
  try {
423
421
  VerificationCode::generateSmsVerificationFor($user, 'driver_login', function ($verification) use ($company) {
424
- return "Your {$company->name} verification code is {$verification->code}";
422
+ return 'Your ' . data_get($company, 'name', config('app.name')) . ' verification code is ' . $verification->code;
425
423
  });
426
424
  } catch (\Throwable $e) {
427
425
  return response()->apiError($e->getMessage());
@@ -458,29 +456,20 @@ class DriverController extends Controller
458
456
 
459
457
  // find and verify code
460
458
  $verificationCode = VerificationCode::where(['subject_uuid' => $user->uuid, 'code' => $code, 'for' => $for])->exists();
461
-
462
459
  if (!$verificationCode && $code !== config('fleetops.navigator.bypass_verification_code')) {
463
460
  return response()->apiError('Invalid verification code!');
464
461
  }
465
462
 
466
- // get the current company session
467
- $company = Flow::getCompanySessionForUser($user);
463
+ // Get the user's company for this driver profile
464
+ $company = $this->_getDriverCompanyFromUser($user);
468
465
 
469
466
  // get driver record
470
- $driver = Driver::firstOrCreate(
471
- [
472
- 'user_uuid' => $user->uuid,
473
- 'company_uuid' => $company->uuid,
474
- ],
467
+ $driver = Driver::where(
475
468
  [
476
469
  'user_uuid' => $user->uuid,
477
470
  'company_uuid' => $company->uuid,
478
- 'name' => data_get($attrs, 'name', $user->name),
479
- 'phone' => data_get($attrs, 'phone', $user->phone),
480
- 'email' => data_get($attrs, 'email', $user->email),
481
- 'location' => new Point(0, 0),
482
471
  ]
483
- );
472
+ )->first();
484
473
 
485
474
  // generate auth token
486
475
  try {
@@ -707,4 +696,24 @@ class DriverController extends Controller
707
696
 
708
697
  return response()->json($route);
709
698
  }
699
+
700
+ private function _getDriverCompanyFromUser(User $user): ?Company
701
+ {
702
+ // company defaults to null
703
+ $company = null;
704
+
705
+ // Load the driver profile to get the company
706
+ $driverProfile = Driver::where('user_uuid', $user->uuid)->first();
707
+ if ($driverProfile) {
708
+ // get company from driver profile
709
+ $company = Company::where('uuid', $driverProfile->company_uuid)->first();
710
+ }
711
+
712
+ // If unable to find company from driver profile, fallback to session flow
713
+ if (!$company) {
714
+ $company = Flow::getCompanySessionForUser($user);
715
+ }
716
+
717
+ return $company;
718
+ }
710
719
  }
@@ -1114,7 +1114,7 @@ class OrderController extends Controller
1114
1114
  {
1115
1115
  $code = $request->input('code');
1116
1116
  $data = $request->input('data', []);
1117
- $rawData = $request->input('raw_data', []);
1117
+ $rawData = $request->input('raw_data');
1118
1118
  $type = $subjectId ? strtok($subjectId, '_') : null;
1119
1119
 
1120
1120
  try {
@@ -13,10 +13,12 @@ use Fleetbase\FleetOps\Models\Driver;
13
13
  use Fleetbase\FleetOps\Models\Order;
14
14
  use Fleetbase\FleetOps\Support\Utils;
15
15
  use Fleetbase\Http\Requests\ExportRequest;
16
+ use Fleetbase\Models\CompanyUser;
16
17
  use Fleetbase\Models\Invite;
17
18
  use Fleetbase\Models\User;
18
19
  use Fleetbase\Models\VerificationCode;
19
20
  use Fleetbase\Notifications\UserInvited;
21
+ use Fleetbase\Support\Auth;
20
22
  use Grimzy\LaravelMysqlSpatial\Types\Point;
21
23
  use Illuminate\Http\Request;
22
24
  use Illuminate\Support\Facades\DB;
@@ -155,11 +157,25 @@ class DriverController extends FleetOpsController
155
157
  $userInput['password'] = Str::random(14);
156
158
  }
157
159
 
158
- $userInput['company_uuid'] = session('company');
160
+ // Get current session company
161
+ $company = Auth::getCompany();
162
+ $userInput['company_uuid'] = $company ? $company->uuid : session('company');
159
163
 
160
164
  // Create user account
161
165
  $user = User::create($userInput);
162
166
 
167
+ // Assign user to company
168
+ if ($company) {
169
+ $user->assignCompany($company);
170
+
171
+ // create company user
172
+ CompanyUser::create([
173
+ 'user_uuid' => $user->uuid,
174
+ 'company_uuid' => $company->uuid,
175
+ 'status' => 'active',
176
+ ]);
177
+ }
178
+
163
179
  // Set user type as driver
164
180
  $user->setUserType('driver');
165
181
 
@@ -42,7 +42,7 @@ class Driver extends FleetbaseResource
42
42
  'jobs' => $this->whenLoaded('jobs', CurrentJob::collection($this->jobs()->without(['driverAssigned'])->get())),
43
43
  'vendor' => $this->whenLoaded('vendor', new Vendor($this->vendor)),
44
44
  'fleets' => $this->whenLoaded('fleets', Fleet::collection($this->fleets()->without('drivers')->get())),
45
- 'location' => data_get($this, 'location', new Point(0, 0)),
45
+ 'location' => $this->wasRecentlyCreated ? new Point(0, 0) : data_get($this, 'location', new Point(0, 0)),
46
46
  'heading' => (int) data_get($this, 'heading', 0),
47
47
  'altitude' => (int) data_get($this, 'altitude', 0),
48
48
  'speed' => (int) data_get($this, 'speed', 0),
@@ -31,8 +31,8 @@ class Entity extends FleetbaseResource
31
31
  'internal_id' => $this->internal_id,
32
32
  'name' => $this->name,
33
33
  'type' => $this->type,
34
- 'payload' => $this->when(Http::isPublicRequest(), data_get($this, 'payload.public_id'), null),
35
- 'destination' => $this->when(Http::isPublicRequest(), data_get($this, 'destination.public_id'), null),
34
+ 'payload' => $this->when(Http::isPublicRequest(), data_get($this, 'payload.public_id')),
35
+ 'destination' => $this->when(Http::isPublicRequest(), data_get($this, 'destination.public_id')),
36
36
  'customer' => $this->setCustomerType(Resolve::resourceForMorph($this->customer_type, $this->customer_uuid)),
37
37
  'supplier' => $this->whenLoaded('supplier', $this->supplier),
38
38
  'tracking_number' => new TrackingNumber($this->trackingNumber),
@@ -2,7 +2,6 @@
2
2
 
3
3
  namespace Fleetbase\FleetOps\Http\Resources\v1;
4
4
 
5
- use Fleetbase\FleetOps\Models\Waypoint;
6
5
  use Fleetbase\Http\Resources\FleetbaseResource;
7
6
  use Fleetbase\Support\Http;
8
7
 
@@ -25,12 +24,12 @@ class Payload extends FleetbaseResource
25
24
  'pickup_uuid' => $this->when(Http::isInternalRequest(), $this->pickup_uuid),
26
25
  'dropoff_uuid' => $this->when(Http::isInternalRequest(), $this->dropoff_uuid),
27
26
  'return_uuid' => $this->when(Http::isInternalRequest(), $this->return_uuid),
28
- 'current_waypoint' => $this->when(!Http::isInternalRequest() && $this->currentWaypoint, data_get($this, 'currentWaypoint.public_id'), null),
27
+ 'current_waypoint' => $this->when(!Http::isInternalRequest() && $this->currentWaypoint, data_get($this, 'currentWaypoint.public_id')),
29
28
  'pickup' => new Place($this->pickup),
30
29
  'dropoff' => new Place($this->dropoff),
31
30
  'return' => new Place($this->return),
32
- 'waypoints' => $this->waypoints($this->waypoints),
33
- 'entities' => Entity::collection($this->entities ?? []),
31
+ 'waypoints' => Waypoint::collection($this->getWaypoints()),
32
+ 'entities' => Entity::collection($this->entities),
34
33
  'cod_amount' => $this->cod_amount ?? null,
35
34
  'cod_currency' => $this->cod_currency ?? null,
36
35
  'cod_payment_method' => $this->cod_payment_method ?? null,
@@ -40,6 +39,14 @@ class Payload extends FleetbaseResource
40
39
  ];
41
40
  }
42
41
 
42
+ private function getWaypoints(): ?\Illuminate\Support\Collection
43
+ {
44
+ return $this->waypoints->map(function ($waypoint) {
45
+ $waypoint->payload_uuid = $this->uuid;
46
+ return $waypoint;
47
+ });
48
+ }
49
+
43
50
  /**
44
51
  * Transform the resource into an webhook payload.
45
52
  *
@@ -62,30 +69,4 @@ class Payload extends FleetbaseResource
62
69
  'created_at' => $this->created_at,
63
70
  ];
64
71
  }
65
-
66
- /**
67
- * Returns the correct pickup resource if applicable.
68
- *
69
- * @param \Illuminate\Support\Collection $waypoints
70
- *
71
- * @return Illuminate\Http\Resources\Json\JsonResource|null
72
- */
73
- public function waypoints($waypoints)
74
- {
75
- if (empty($waypoints)) {
76
- return [];
77
- }
78
-
79
- $waypoints = $waypoints->map(
80
- function ($place) {
81
- $waypoint = Waypoint::where(['payload_uuid' => $this->uuid, 'place_uuid' => $place->uuid])->without(['place'])->with(['trackingNumber'])->first();
82
- $place->tracking_number = new TrackingNumber($waypoint->trackingNumber);
83
- $place->order = $waypoint->order;
84
-
85
- return $place;
86
- }
87
- )->sortBy('order');
88
-
89
- return Place::collection($waypoints ?? []);
90
- }
91
72
  }
@@ -23,7 +23,7 @@ class Place extends FleetbaseResource
23
23
  'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
24
24
  'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
25
25
  'name' => $this->name,
26
- 'location' => $this->location ?? new Point(0, 0),
26
+ 'location' => data_get($this, 'location', new Point(0, 0)),
27
27
  'address' => $this->address,
28
28
  'address_html' => $this->when(Http::isInternalRequest(), $this->address_html),
29
29
  'street1' => $this->street1 ?? null,
@@ -40,8 +40,8 @@ class Place extends FleetbaseResource
40
40
  'phone' => $this->phone ?? null,
41
41
  'owner' => $this->when(!Http::isInternalRequest(), Resolve::resourceForMorph($this->owner_type, $this->owner_uuid)),
42
42
  'tracking_number' => $this->whenLoaded('trackingNumber', $this->trackingNumber),
43
- 'type' => $this->type ?? null,
44
- 'meta' => $this->meta ?? [],
43
+ 'type' => $this->type,
44
+ 'meta' => data_get($this, 'meta', []),
45
45
  'updated_at' => $this->updated_at,
46
46
  'created_at' => $this->created_at,
47
47
  ];
@@ -0,0 +1,101 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\FleetOps\Http\Resources\v1;
4
+
5
+ use Fleetbase\FleetOps\Models\Waypoint as WaypointModel;
6
+ use Fleetbase\Http\Resources\FleetbaseResource;
7
+ use Fleetbase\Support\Http;
8
+ use Fleetbase\Support\Resolve;
9
+ use Grimzy\LaravelMysqlSpatial\Types\Point;
10
+
11
+ class Waypoint extends FleetbaseResource
12
+ {
13
+ /**
14
+ * Transform the resource into an array.
15
+ *
16
+ * @param \Illuminate\Http\Request $request
17
+ *
18
+ * @return array
19
+ */
20
+ public function toArray($request)
21
+ {
22
+ $waypoint = $this->getWaypoint();
23
+
24
+ return [
25
+ 'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
26
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
27
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
28
+ 'waypoint_public_id' => $this->when(Http::isInternalRequest(), $waypoint->public_id),
29
+ 'order' => $waypoint->order,
30
+ 'tracking' => $waypoint->tracking,
31
+ 'status' => $waypoint->status,
32
+ 'status_code' => $waypoint->status_code,
33
+ 'name' => $this->name,
34
+ 'location' => data_get($this, 'location', new Point(0, 0)),
35
+ 'address' => $this->address,
36
+ 'address_html' => $this->when(Http::isInternalRequest(), $this->address_html),
37
+ 'street1' => $this->street1 ?? null,
38
+ 'street2' => $this->street2 ?? null,
39
+ 'city' => $this->city ?? null,
40
+ 'province' => $this->province ?? null,
41
+ 'postal_code' => $this->postal_code ?? null,
42
+ 'neighborhood' => $this->neighborhood ?? null,
43
+ 'district' => $this->district ?? null,
44
+ 'building' => $this->building ?? null,
45
+ 'security_access_code' => $this->security_access_code ?? null,
46
+ 'country' => $this->country ?? null,
47
+ 'country_name' => $this->when(Http::isInternalRequest(), $this->country_name),
48
+ 'phone' => $this->phone ?? null,
49
+ 'owner' => $this->when(!Http::isInternalRequest(), Resolve::resourceForMorph($this->owner_type, $this->owner_uuid)),
50
+ 'tracking_number' => $this->whenLoaded('trackingNumber', $waypoint->trackingNumber),
51
+ 'type' => $this->type,
52
+ 'meta' => data_get($this, 'meta', []),
53
+ 'updated_at' => $this->updated_at,
54
+ 'created_at' => $this->created_at,
55
+ ];
56
+ }
57
+
58
+ /**
59
+ * Finds the waypoint got a payload and place
60
+ *
61
+ * @return WaypointModel|null
62
+ */
63
+ private function getWaypoint(): ?WaypointModel
64
+ {
65
+ return WaypointModel::where(['payload_uuid' => $this->payload_uuid, 'place_uuid' => $this->uuid])->without(['place'])->with(['trackingNumber'])->first();
66
+ }
67
+
68
+ /**
69
+ * Transform the resource into an webhook payload.
70
+ *
71
+ * @return array
72
+ */
73
+ public function toWebhookPayload()
74
+ {
75
+ return [
76
+ 'id' => $this->public_id,
77
+ 'internal_id' => $this->internal_id,
78
+ 'name' => $this->name,
79
+ 'type' => data_get($this, 'type'),
80
+ 'destination' => $this->destination ? $this->destination->public_id : null,
81
+ 'customer' => Resolve::resourceForMorph($this->customer_type, $this->customer_uuid),
82
+ 'tracking_number' => new TrackingNumber($this->trackingNumber),
83
+ 'description' => data_get($this, 'description'),
84
+ 'photo_url' => data_get($this, 'photo_url'),
85
+ 'length' => data_get($this, 'length'),
86
+ 'width' => data_get($this, 'width'),
87
+ 'height' => data_get($this, 'height'),
88
+ 'dimensions_unit' => data_get($this, 'dimensions_unit'),
89
+ 'weight' => data_get($this, 'weight'),
90
+ 'weight_unit' => data_get($this, 'weight_unit'),
91
+ 'declared_value' => data_get($this, 'declared_value'),
92
+ 'price' => data_get($this, 'price'),
93
+ 'sale_price' => data_get($this, 'sale_price'),
94
+ 'sku' => data_get($this, 'sku'),
95
+ 'currency' => data_get($this, 'currency'),
96
+ 'meta' => $this->meta ?? [],
97
+ 'updated_at' => $this->updated_at,
98
+ 'created_at' => $this->created_at,
99
+ ];
100
+ }
101
+ }