@fleetbase/fleetops-engine 0.4.0 → 0.4.2

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 (207) 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 +8 -4
  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 +6 -2
  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 +8 -3
  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 +7 -2
  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 +127 -30
  162. package/addon/controllers/operations/orders/index/view.js +57 -20
  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 +1 -12
  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/application.js +5 -2
  169. package/addon/routes/management/places/index.js +1 -1
  170. package/addon/routes/operations/orders/index/view.js +2 -14
  171. package/addon/services/driver-actions.js +9 -8
  172. package/addon/services/vehicle-actions.js +2 -1
  173. package/addon/styles/fleetops-engine.css +6 -0
  174. package/addon/templates/management/contacts/index.hbs +6 -6
  175. package/addon/templates/management/drivers/index.hbs +6 -6
  176. package/addon/templates/management/fleets/index.hbs +6 -6
  177. package/addon/templates/management/fuel-reports/index.hbs +7 -7
  178. package/addon/templates/management/index.hbs +17 -17
  179. package/addon/templates/management/issues/index.hbs +6 -6
  180. package/addon/templates/management/places/index.hbs +6 -6
  181. package/addon/templates/management/vehicles/index.hbs +6 -6
  182. package/addon/templates/management/vendors/index.hbs +6 -6
  183. package/addon/templates/operations/orders/index/config/types.hbs +3 -3
  184. package/addon/templates/operations/orders/index/config.hbs +3 -4
  185. package/addon/templates/operations/orders/index/new.hbs +73 -73
  186. package/addon/templates/operations/orders/index/view.hbs +147 -53
  187. package/addon/templates/operations/orders/index.hbs +13 -13
  188. package/addon/templates/operations/scheduler/index.hbs +3 -3
  189. package/addon/templates/operations/service-rates/index/new.hbs +79 -81
  190. package/addon/templates/operations/service-rates/index.hbs +6 -6
  191. package/composer.json +2 -2
  192. package/extension.json +1 -1
  193. package/package.json +4 -2
  194. package/server/resources/views/labels/default.php +40 -18
  195. package/server/resources/views/labels/waypoint-label.php +126 -0
  196. package/server/src/Http/Controllers/Api/v1/DriverController.php +4 -1
  197. package/server/src/Http/Controllers/Api/v1/OrderController.php +1 -1
  198. package/server/src/Http/Resources/v1/Entity.php +2 -2
  199. package/server/src/Http/Resources/v1/Payload.php +11 -30
  200. package/server/src/Http/Resources/v1/Place.php +3 -3
  201. package/server/src/Http/Resources/v1/Waypoint.php +101 -0
  202. package/server/src/Models/Entity.php +1 -1
  203. package/server/src/Models/Payload.php +39 -0
  204. package/server/src/Models/Place.php +5 -2
  205. package/server/src/Models/Proof.php +1 -1
  206. package/server/src/Models/Waypoint.php +15 -3
  207. package/translations/en-us.yaml +1343 -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>
@@ -422,7 +422,10 @@ class DriverController extends Controller
422
422
  return 'Your ' . data_get($company, 'name', config('app.name')) . ' verification code is ' . $verification->code;
423
423
  });
424
424
  } catch (\Throwable $e) {
425
- return response()->apiError($e->getMessage());
425
+ if (app()->bound('sentry')) {
426
+ app('sentry')->captureException($e);
427
+ }
428
+ return response()->apiError('Unable to send SMS Verification code.');
426
429
  }
427
430
 
428
431
  return response()->json(['status' => 'OK']);
@@ -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 {
@@ -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
+ }
@@ -247,7 +247,7 @@ class Entity extends Model
247
247
  */
248
248
  public function getPhotoUrlAttribute()
249
249
  {
250
- return data_get($this, 'photo.s3url', 'https://s3.ap-southeast-1.amazonaws.com/flb-assets/static/parcels/medium.png');
250
+ return data_get($this, 'photo.url', 'https://s3.ap-southeast-1.amazonaws.com/flb-assets/static/parcels/medium.png');
251
251
  }
252
252
 
253
253
  /**
@@ -216,6 +216,14 @@ class Payload extends Model
216
216
  }
217
217
  }
218
218
 
219
+ // Validate destination actually exists
220
+ if (isset($attributes['destination_uuid']) && Place::where('uuid', $attributes['destination_uuid'])->doesntExist()) {
221
+ $validDestination = $this->_findCorrectDestinationForEntity($attributes);
222
+ if ($validDestination) {
223
+ $attributes['destination_uuid'] = $validDestination->uuid;
224
+ }
225
+ }
226
+
219
227
  $entity = new Entity($attributes);
220
228
  $this->entities()->save($entity);
221
229
  }
@@ -249,6 +257,14 @@ class Payload extends Model
249
257
  }
250
258
  }
251
259
 
260
+ // Validate destination actually exists
261
+ if (isset($attributes['destination_uuid']) && Place::where('uuid', $attributes['destination_uuid'])->doesntExist()) {
262
+ $validDestination = $this->_findCorrectDestinationForEntity($attributes);
263
+ if ($validDestination) {
264
+ $attributes['destination_uuid'] = $validDestination->uuid;
265
+ }
266
+ }
267
+
252
268
  Entity::insertGetUuid($attributes, $this);
253
269
  }
254
270
 
@@ -334,7 +350,9 @@ class Payload extends Model
334
350
  if (Str::isUuid($placeUuid) && isset($attributes['uuid']) && $placeUuid !== $attributes['uuid']) {
335
351
  $place = Place::where('uuid', $placeUuid)->first();
336
352
 
353
+ // set the original destination uuid in meta
337
354
  if ($place instanceof Place) {
355
+ $place->updateMeta('_console_destination_uuid', $attributes['uuid']);
338
356
  $place->updateMeta('search_uuid', $attributes['uuid']);
339
357
  }
340
358
  }
@@ -399,6 +417,18 @@ class Payload extends Model
399
417
  return $this->refresh()->load(['waypoints']);
400
418
  }
401
419
 
420
+ public function _findCorrectDestinationForEntity($entityAttributes = []): ?Place
421
+ {
422
+ $destinationId = Utils::get($entityAttributes, 'destination_uuid');
423
+
424
+ $destination = Place::where('meta->search_uuid', $destinationId)->first();
425
+ if (!$destination) {
426
+ $destination = Place::where('meta->_console_destination_uuid', $destinationId)->first();
427
+ }
428
+
429
+ return $destination;
430
+ }
431
+
402
432
  /**
403
433
  * Get the payload pickup point or the first waypoint.
404
434
  *
@@ -783,6 +813,15 @@ class Payload extends Model
783
813
  }
784
814
  }
785
815
 
816
+ // Validate destination actually exists
817
+ if (isset($attributes['destination_uuid']) && Place::where('uuid', $attributes['destination_uuid'])->doesntExist()) {
818
+ $destination = $this->_findCorrectDestinationForEntity($attributes);
819
+
820
+ if ($destination instanceof Place) {
821
+ return $destination;
822
+ }
823
+ }
824
+
786
825
  return null;
787
826
  }
788
827
  }
@@ -447,9 +447,12 @@ class Place extends Model
447
447
  return static::createFromCoordinates($place, $attributes, $saveInstance);
448
448
  }
449
449
 
450
+ // Get uuid if set
451
+ $uuid = data_get($place, 'uuid');
452
+
450
453
  // If $place has a valid uuid and a matching Place object exists, return the uuid
451
- if (isset($place['uuid']) && Str::isUuid($place['uuid']) && Place::where('uuid', $place['uuid'])->exists()) {
452
- return $place['uuid'];
454
+ if (Str::isUuid($uuid) && $place = Place::where('uuid', $uuid)->first()) {
455
+ return $place;
453
456
  }
454
457
 
455
458
  // Otherwise, create a new Place object with the given attributes
@@ -81,7 +81,7 @@ class Proof extends Model
81
81
  */
82
82
  public function getFileUrlAttribute()
83
83
  {
84
- return $this->fromCache('file.s3url', null);
84
+ return $this->fromCache('file.url', null);
85
85
  }
86
86
 
87
87
  /**
@@ -83,16 +83,28 @@ class Waypoint extends Model
83
83
  return $this->pdfLabel()->stream();
84
84
  }
85
85
 
86
+ /**
87
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
88
+ */
89
+ public function entities()
90
+ {
91
+ return $this->hasMany(Entity::class, 'destination_uuid', 'place_uuid')->where('payload_uuid', $this->payload_uuid);
92
+ }
93
+
86
94
  /**
87
95
  * The html for the shipment label.
88
96
  */
89
97
  public function label()
90
98
  {
91
- $this->load(['trackingNumber', 'company', 'place']);
99
+ $this->load(['trackingNumber', 'company', 'place', 'entities']);
100
+
101
+ // $entities = Entity::where(['payload_uuid' => $this->payload_uuid, 'destination_uuid' => $this->place_uuid])->get();
102
+ // dd($entities, );
92
103
 
93
- return view('labels/default', [
94
- 'order' => $this,
104
+ return view('fleetops::labels/waypoint-label', [
105
+ 'waypoint' => $this,
95
106
  'dropoff' => $this->place,
107
+ 'entities' => $this->entities()->get(),
96
108
  'trackingNumber' => $this->trackingNumber,
97
109
  'company' => $this->company,
98
110
  ])->render();