@fleetbase/fleetops-engine 0.6.8 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/components/activity-event-selector.js +4 -0
- package/addon/components/admin/navigator-app.js +1 -1
- package/addon/components/custom-field-form-panel.js +1 -1
- package/addon/components/display-place.hbs +27 -3
- package/addon/components/driver-onboard-settings.js +1 -1
- package/addon/components/driver-panel/orders.js +1 -1
- package/addon/components/edit-order-route-panel.js +1 -1
- package/addon/components/entity-field-editing-settings.js +1 -1
- package/addon/components/fleet-driver-listing.js +1 -2
- package/addon/components/fleet-panel/driver-listing.js +1 -2
- package/addon/components/fleet-panel/vehicle-listing.js +1 -2
- package/addon/components/fleet-vehicle-listing.js +1 -2
- package/addon/components/layout/fleet-ops-sidebar/driver-listing.js +1 -1
- package/addon/components/layout/fleet-ops-sidebar/fleet-listing.js +1 -1
- package/addon/components/live-map.js +1 -1
- package/addon/components/map-container/toolbar/zones-panel.js +1 -1
- package/addon/components/order-config-manager/activity-flow.js +1 -1
- package/addon/components/order-config-manager/custom-fields.js +1 -1
- package/addon/components/order-config-manager/entities.js +1 -1
- package/addon/components/order-config-manager.js +1 -1
- package/addon/components/route-list.hbs +3 -3
- package/addon/components/vendor-panel/drivers.js +1 -2
- package/addon/components/widget/fleet-ops-key-metrics.js +1 -1
- package/addon/controllers/management/contacts/index.js +1 -2
- package/addon/controllers/management/drivers/index.js +1 -2
- package/addon/controllers/management/fleets/index.js +1 -2
- package/addon/controllers/management/fuel-reports/index.js +1 -2
- package/addon/controllers/management/issues/index.js +1 -2
- package/addon/controllers/management/vehicles/index.js +1 -2
- package/addon/controllers/management/vendors/index.js +1 -2
- package/addon/controllers/operations/orders/index/new.js +40 -48
- package/addon/controllers/operations/orders/index/view.js +1 -1
- package/addon/controllers/operations/orders/index.js +1 -6
- package/addon/controllers/operations/service-rates/index.js +1 -2
- package/addon/routes/operations/orders/index/view.js +18 -1
- package/addon/services/movement-tracker.js +1 -1
- package/addon/services/order-creation.js +1 -1
- package/addon/styles/fleetops-engine.css +7 -0
- package/addon/templates/operations/orders/index/new.hbs +2 -2
- package/addon/templates/operations/orders/index/view.hbs +5 -1
- package/addon/templates/operations/orders/index.hbs +6 -1
- package/addon/templates/settings/notifications.hbs +9 -1
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +2 -3
- package/server/src/Console/Commands/TrackOrderDistanceAndTime.php +2 -2
- package/server/src/Events/OrderCanceled.php +6 -0
- package/server/src/Events/OrderCompleted.php +6 -0
- package/server/src/Events/OrderDispatched.php +6 -0
- package/server/src/Events/OrderFailed.php +6 -0
- package/server/src/Events/WaypointActivityChanged.php +119 -0
- package/server/src/Events/WaypointCompleted.php +119 -0
- package/server/src/Flow/Activity.php +28 -10
- package/server/src/Flow/Event.php +26 -2
- package/server/src/Http/Controllers/Api/v1/DriverController.php +19 -2
- package/server/src/Http/Controllers/Api/v1/OrderController.php +274 -164
- package/server/src/Http/Controllers/Internal/v1/OrderController.php +15 -8
- package/server/src/Http/Filter/OrderFilter.php +4 -4
- package/server/src/Http/Resources/v1/Payload.php +1 -1
- package/server/src/Listeners/HandleOrderCanceled.php +0 -10
- package/server/src/Listeners/NotifyOrderEvent.php +4 -4
- package/server/src/Models/OrderConfig.php +50 -35
- package/server/src/Models/Payload.php +26 -7
- package/server/src/Models/Waypoint.php +10 -0
- package/server/src/Notifications/OrderAssigned.php +3 -5
- package/server/src/Notifications/OrderCanceled.php +32 -12
- package/server/src/Notifications/OrderCompleted.php +31 -11
- package/server/src/Notifications/OrderDispatchFailed.php +3 -5
- package/server/src/Notifications/OrderDispatched.php +31 -11
- package/server/src/Notifications/OrderFailed.php +32 -12
- package/server/src/Notifications/OrderPing.php +2 -6
- package/server/src/Notifications/OrderSplit.php +1 -1
- package/server/src/Notifications/WaypointCompleted.php +157 -0
|
@@ -340,8 +340,8 @@ class OrderFilter extends Filter
|
|
|
340
340
|
{
|
|
341
341
|
$ids = Utils::arrayFrom($ids);
|
|
342
342
|
$firstId = Arr::first($ids);
|
|
343
|
-
|
|
344
|
-
|
|
343
|
+
if ($firstId) {
|
|
344
|
+
$this->builder->where(function ($query) use ($ids, $firstId) {
|
|
345
345
|
if (Utils::isPublicId($firstId)) {
|
|
346
346
|
return $query->whereIn('public_id', $ids);
|
|
347
347
|
}
|
|
@@ -354,8 +354,8 @@ class OrderFilter extends Filter
|
|
|
354
354
|
$query->orWhereHas('trackingNumber', function ($query) use ($ids) {
|
|
355
355
|
$query->whereIn('tracking_number', $ids);
|
|
356
356
|
});
|
|
357
|
-
}
|
|
358
|
-
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
public function createdAt($createdAt)
|
|
@@ -29,7 +29,7 @@ class Payload extends FleetbaseResource
|
|
|
29
29
|
'pickup_uuid' => $this->when(Http::isInternalRequest(), $this->pickup_uuid),
|
|
30
30
|
'dropoff_uuid' => $this->when(Http::isInternalRequest(), $this->dropoff_uuid),
|
|
31
31
|
'return_uuid' => $this->when(Http::isInternalRequest(), $this->return_uuid),
|
|
32
|
-
'current_waypoint' => $this->when(
|
|
32
|
+
'current_waypoint' => $this->when(Http::isPublicRequest() && $this->currentWaypoint, data_get($this, 'currentWaypoint.public_id')),
|
|
33
33
|
'pickup' => $this->getPlace($this->pickup),
|
|
34
34
|
'dropoff' => $this->getPlace($this->dropoff),
|
|
35
35
|
'return' => new Place($this->return),
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Listeners;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Events\OrderCanceled;
|
|
6
|
-
use Fleetbase\FleetOps\Flow\Activity;
|
|
7
6
|
use Fleetbase\FleetOps\Models\Driver;
|
|
8
7
|
use Fleetbase\FleetOps\Notifications\OrderCanceled as OrderCanceledNotification;
|
|
9
8
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
@@ -24,15 +23,6 @@ class HandleOrderCanceled implements ShouldQueue
|
|
|
24
23
|
{
|
|
25
24
|
/** @var \Fleetbase\FleetOps\Models\Order $order */
|
|
26
25
|
$order = $event->getModelRecord();
|
|
27
|
-
$location = $order->getLastLocation();
|
|
28
|
-
|
|
29
|
-
// Create order cancel activity
|
|
30
|
-
$activity = $order->config()->getCanceledActivity();
|
|
31
|
-
|
|
32
|
-
// Update order activity
|
|
33
|
-
$order->setStatus($activity->status);
|
|
34
|
-
$order->createActivity($activity, $location);
|
|
35
|
-
|
|
36
26
|
if ($order->isIntegratedVendorOrder()) {
|
|
37
27
|
$order->facilitator->provider()->callback('onCanceled', $order);
|
|
38
28
|
}
|
|
@@ -32,15 +32,15 @@ class NotifyOrderEvent implements ShouldQueue
|
|
|
32
32
|
// Send a notification for order events
|
|
33
33
|
if ($event instanceof \Fleetbase\FleetOps\Events\OrderCanceled) {
|
|
34
34
|
$reason = $event->activity ? $event->activity->get('details') : '';
|
|
35
|
-
NotificationRegistry::notify(OrderCanceled::class, $order);
|
|
35
|
+
NotificationRegistry::notify(OrderCanceled::class, $order, $reason, $event->waypoint);
|
|
36
36
|
}
|
|
37
37
|
if ($event instanceof \Fleetbase\FleetOps\Events\OrderCompleted) {
|
|
38
|
-
NotificationRegistry::notify(OrderCompleted::class, $order);
|
|
38
|
+
NotificationRegistry::notify(OrderCompleted::class, $order, $event->waypoint);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if ($event instanceof \Fleetbase\FleetOps\Events\OrderFailed) {
|
|
42
42
|
$reason = $event->activity ? $event->activity->get('details') : '';
|
|
43
|
-
NotificationRegistry::notify(OrderFailed::class, $order, $reason);
|
|
43
|
+
NotificationRegistry::notify(OrderFailed::class, $order, $reason, $event->waypoint);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if ($event instanceof \Fleetbase\FleetOps\Events\OrderDispatchFailed) {
|
|
@@ -48,7 +48,7 @@ class NotifyOrderEvent implements ShouldQueue
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
if ($event instanceof \Fleetbase\FleetOps\Events\OrderDispatched) {
|
|
51
|
-
NotificationRegistry::notify(OrderDispatched::class, $order);
|
|
51
|
+
NotificationRegistry::notify(OrderDispatched::class, $order, $event->waypoint);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if ($event instanceof \Fleetbase\FleetOps\Events\OrderDriverAssigned) {
|
|
@@ -209,18 +209,25 @@ class OrderConfig extends Model
|
|
|
209
209
|
/**
|
|
210
210
|
* Retrieves the current order context, setting it if not already set.
|
|
211
211
|
*
|
|
212
|
-
* @param Order|null $order the order to use as context if no current context is set
|
|
213
|
-
*
|
|
214
212
|
* @return Order|null the current order context
|
|
215
213
|
*
|
|
216
214
|
* @throws \Exception if no order context is found and none is provided
|
|
217
215
|
*/
|
|
218
|
-
public function getOrderContext(
|
|
216
|
+
public function getOrderContext(Order|Waypoint|null $context = null): ?Order
|
|
219
217
|
{
|
|
220
|
-
if (!$this->orderContext && $
|
|
221
|
-
$this->setOrderContext($
|
|
218
|
+
if (!$this->orderContext && $context instanceof Order) {
|
|
219
|
+
$this->setOrderContext($context);
|
|
220
|
+
|
|
221
|
+
return $context;
|
|
222
|
+
}
|
|
222
223
|
|
|
223
|
-
|
|
224
|
+
if (!$this->orderContext && $context instanceof Waypoint) {
|
|
225
|
+
$order = Order::where('payload_uuid', $context->payload_uuid)->first();
|
|
226
|
+
if ($order) {
|
|
227
|
+
$this->setOrderContext($order);
|
|
228
|
+
|
|
229
|
+
return $order;
|
|
230
|
+
}
|
|
224
231
|
}
|
|
225
232
|
|
|
226
233
|
if (!$this->orderContext) {
|
|
@@ -268,30 +275,35 @@ class OrderConfig extends Model
|
|
|
268
275
|
/**
|
|
269
276
|
* Determines the current activity based on the order's status.
|
|
270
277
|
*
|
|
271
|
-
* @param Order|null $order the order to evaluate
|
|
272
|
-
*
|
|
273
278
|
* @return Activity|null the current Activity object or null if not found
|
|
274
279
|
*/
|
|
275
|
-
public function currentActivity(
|
|
280
|
+
public function currentActivity(Order|Waypoint|null $context = null): ?Activity
|
|
276
281
|
{
|
|
277
|
-
$
|
|
282
|
+
if ($context === null) {
|
|
283
|
+
$context = $this->getOrderContext($context);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if ($context instanceof Waypoint) {
|
|
287
|
+
return $this->activities()->firstWhere('code', strtolower($context->status_code));
|
|
288
|
+
}
|
|
278
289
|
|
|
279
|
-
return $this->activities()->firstWhere('code', $
|
|
290
|
+
return $this->activities()->firstWhere('code', $context->status);
|
|
280
291
|
}
|
|
281
292
|
|
|
282
293
|
/**
|
|
283
294
|
* Determines the next set of activities based on the current activity.
|
|
284
295
|
*
|
|
285
|
-
* @param Order|null $order the order to evaluate
|
|
286
|
-
*
|
|
287
296
|
* @return Collection a collection of the next activities
|
|
288
297
|
*/
|
|
289
|
-
public function nextActivity(
|
|
298
|
+
public function nextActivity(Order|Waypoint|null $context = null): Collection
|
|
290
299
|
{
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
if ($context === null) {
|
|
301
|
+
$context = $this->getOrderContext($context);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
$currentActivity = $this->currentActivity($context);
|
|
293
305
|
if ($currentActivity) {
|
|
294
|
-
return $currentActivity->getNext($
|
|
306
|
+
return $currentActivity->getNext($context);
|
|
295
307
|
}
|
|
296
308
|
|
|
297
309
|
return collect();
|
|
@@ -300,17 +312,18 @@ class OrderConfig extends Model
|
|
|
300
312
|
/**
|
|
301
313
|
* Retrieves the first activity in the next set of activities.
|
|
302
314
|
*
|
|
303
|
-
* @param Order|null $order the order to evaluate
|
|
304
|
-
*
|
|
305
315
|
* @return Activity|null the first Activity object in the next set or null if not found
|
|
306
316
|
*/
|
|
307
|
-
public function nextFirstActivity(
|
|
317
|
+
public function nextFirstActivity(Order|Waypoint|null $context = null): ?Activity
|
|
308
318
|
{
|
|
319
|
+
if ($context === null) {
|
|
320
|
+
$context = $this->getOrderContext($context);
|
|
321
|
+
}
|
|
322
|
+
|
|
309
323
|
$next = collect();
|
|
310
|
-
$
|
|
311
|
-
$currentActivity = $this->currentActivity($order);
|
|
324
|
+
$currentActivity = $this->currentActivity($context);
|
|
312
325
|
if ($currentActivity) {
|
|
313
|
-
$next = $currentActivity->getNext($
|
|
326
|
+
$next = $currentActivity->getNext($context);
|
|
314
327
|
}
|
|
315
328
|
|
|
316
329
|
return $next->first();
|
|
@@ -319,17 +332,18 @@ class OrderConfig extends Model
|
|
|
319
332
|
/**
|
|
320
333
|
* Retrieves the activity that follows after the next activity.
|
|
321
334
|
*
|
|
322
|
-
* @param Order|null $order the order to evaluate
|
|
323
|
-
*
|
|
324
335
|
* @return Activity|null the Activity object that follows after the next or null if not found
|
|
325
336
|
*/
|
|
326
|
-
public function afterNextActivity(
|
|
337
|
+
public function afterNextActivity(Order|Waypoint|null $context = null): ?Activity
|
|
327
338
|
{
|
|
339
|
+
if ($context === null) {
|
|
340
|
+
$context = $this->getOrderContext($context);
|
|
341
|
+
}
|
|
342
|
+
|
|
328
343
|
$afterNext = collect();
|
|
329
|
-
$
|
|
330
|
-
$nextActivity = $this->nextFirstActivity($order);
|
|
344
|
+
$nextActivity = $this->nextFirstActivity($context);
|
|
331
345
|
if ($nextActivity) {
|
|
332
|
-
$afterNext = $nextActivity->getNext($
|
|
346
|
+
$afterNext = $nextActivity->getNext($context);
|
|
333
347
|
}
|
|
334
348
|
|
|
335
349
|
return $afterNext->first();
|
|
@@ -338,16 +352,17 @@ class OrderConfig extends Model
|
|
|
338
352
|
/**
|
|
339
353
|
* Retrieves the previous activities based on the current activity.
|
|
340
354
|
*
|
|
341
|
-
* @param Order|null $order the order to evaluate
|
|
342
|
-
*
|
|
343
355
|
* @return Collection a collection of previous activities
|
|
344
356
|
*/
|
|
345
|
-
public function previousActivity(
|
|
357
|
+
public function previousActivity(Order|Waypoint|null $context = null): Collection
|
|
346
358
|
{
|
|
347
|
-
|
|
348
|
-
|
|
359
|
+
if ($context === null) {
|
|
360
|
+
$context = $this->getOrderContext($context);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
$currentActivity = $this->currentActivity($context);
|
|
349
364
|
if ($currentActivity) {
|
|
350
|
-
return $currentActivity->getPrevious($
|
|
365
|
+
return $currentActivity->getPrevious($context);
|
|
351
366
|
}
|
|
352
367
|
|
|
353
368
|
return collect();
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Models;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\Casts\Json;
|
|
6
|
+
use Fleetbase\FleetOps\Events\WaypointActivityChanged;
|
|
7
|
+
use Fleetbase\FleetOps\Events\WaypointCompleted;
|
|
6
8
|
use Fleetbase\FleetOps\Flow\Activity;
|
|
7
9
|
use Fleetbase\FleetOps\Http\Resources\v1\Payload as PayloadResource;
|
|
8
10
|
use Fleetbase\FleetOps\Support\Utils;
|
|
@@ -282,10 +284,13 @@ class Payload extends Model
|
|
|
282
284
|
return $this;
|
|
283
285
|
}
|
|
284
286
|
|
|
285
|
-
public function setCurrentWaypoint(Place $destination, bool $save = true): Payload
|
|
287
|
+
public function setCurrentWaypoint(Place|Waypoint $destination, bool $save = true): Payload
|
|
286
288
|
{
|
|
287
|
-
$
|
|
289
|
+
if ($destination instanceof Waypoint) {
|
|
290
|
+
$destination = $destination->getPlace();
|
|
291
|
+
}
|
|
288
292
|
|
|
293
|
+
$this->current_waypoint_uuid = $destination->uuid;
|
|
289
294
|
if ($save) {
|
|
290
295
|
DB::table($this->getTable())->where('uuid', $this->uuid)->update(['current_waypoint_uuid' => $destination->uuid]);
|
|
291
296
|
}
|
|
@@ -772,7 +777,7 @@ class Payload extends Model
|
|
|
772
777
|
$currentWaypoint = $this->waypointMarkers->firstWhere('place_uuid', $this->current_waypoint_uuid);
|
|
773
778
|
if ($currentWaypoint) {
|
|
774
779
|
$currentWaypoint->insertActivity($activity, $location, $proof);
|
|
775
|
-
$activity->fireEvents($this->order);
|
|
780
|
+
$activity->fireEvents($this->order, $currentWaypoint);
|
|
776
781
|
}
|
|
777
782
|
|
|
778
783
|
// update activity for all entities for this destination/waypoint
|
|
@@ -780,6 +785,13 @@ class Payload extends Model
|
|
|
780
785
|
foreach ($entities as $entity) {
|
|
781
786
|
$entity->insertActivity($activity, $location, $proof);
|
|
782
787
|
}
|
|
788
|
+
|
|
789
|
+
// if this activity completes the waypoint notify waypoint customer
|
|
790
|
+
if ($activity && $activity->complete()) {
|
|
791
|
+
event(new WaypointCompleted($currentWaypoint, $activity));
|
|
792
|
+
} else {
|
|
793
|
+
event(new WaypointActivityChanged($currentWaypoint, $activity));
|
|
794
|
+
}
|
|
783
795
|
}
|
|
784
796
|
|
|
785
797
|
return $this;
|
|
@@ -792,16 +804,23 @@ class Payload extends Model
|
|
|
792
804
|
*/
|
|
793
805
|
public function setNextWaypointDestination()
|
|
794
806
|
{
|
|
795
|
-
$nextWaypoint = $this->waypointMarkers->
|
|
807
|
+
$nextWaypoint = $this->waypointMarkers->first(function ($waypoint) {
|
|
796
808
|
return !$waypoint->complete && $waypoint->place_uuid !== $this->current_waypoint_uuid;
|
|
797
|
-
})
|
|
809
|
+
});
|
|
798
810
|
|
|
799
811
|
if (!$nextWaypoint || $this->current_waypoint_uuid === $nextWaypoint->place_uuid) {
|
|
800
812
|
return $this;
|
|
801
813
|
}
|
|
802
814
|
|
|
803
|
-
|
|
804
|
-
$
|
|
815
|
+
// if next waypoint is waypoint get the place record
|
|
816
|
+
$destination = $nextWaypoint;
|
|
817
|
+
if ($nextWaypoint instanceof Waypoint) {
|
|
818
|
+
$destination = $nextWaypoint->getPlace();
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// Always set the destination using a place model
|
|
822
|
+
$this->setCurrentWaypoint($destination);
|
|
823
|
+
$this->setRelation('currentWaypoint', $destination);
|
|
805
824
|
|
|
806
825
|
return $this;
|
|
807
826
|
}
|
|
@@ -224,4 +224,14 @@ class Waypoint extends Model
|
|
|
224
224
|
|
|
225
225
|
return $result ? $uuid : false;
|
|
226
226
|
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Get this waypoint place record.
|
|
230
|
+
*/
|
|
231
|
+
public function getPlace(): ?Place
|
|
232
|
+
{
|
|
233
|
+
$this->loadMissing('place');
|
|
234
|
+
|
|
235
|
+
return $this->place ?? Place::where('uuid', $this->place_uuid)->first();
|
|
236
|
+
}
|
|
227
237
|
}
|
|
@@ -21,7 +21,7 @@ class OrderAssigned extends Notification implements ShouldQueue
|
|
|
21
21
|
/**
|
|
22
22
|
* The order instance this notification is for.
|
|
23
23
|
*
|
|
24
|
-
* @var
|
|
24
|
+
* @var Order
|
|
25
25
|
*/
|
|
26
26
|
public $order;
|
|
27
27
|
|
|
@@ -106,12 +106,10 @@ class OrderAssigned extends Notification implements ShouldQueue
|
|
|
106
106
|
$order = new OrderResource($this->order);
|
|
107
107
|
|
|
108
108
|
return [
|
|
109
|
+
'event' => 'order.assigned_notification',
|
|
109
110
|
'title' => $this->title,
|
|
110
111
|
'body' => $this->message,
|
|
111
|
-
'data' =>
|
|
112
|
-
...$this->data,
|
|
113
|
-
'order' => $order->toWebhookPayload(),
|
|
114
|
-
],
|
|
112
|
+
'data' => $this->data,
|
|
115
113
|
];
|
|
116
114
|
}
|
|
117
115
|
|
|
@@ -4,6 +4,7 @@ namespace Fleetbase\FleetOps\Notifications;
|
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Http\Resources\v1\Order as OrderResource;
|
|
6
6
|
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
+
use Fleetbase\FleetOps\Models\Waypoint;
|
|
7
8
|
use Fleetbase\FleetOps\Support\Utils;
|
|
8
9
|
use Fleetbase\Support\PushNotification;
|
|
9
10
|
use Illuminate\Broadcasting\Channel;
|
|
@@ -21,10 +22,17 @@ class OrderCanceled extends Notification implements ShouldQueue
|
|
|
21
22
|
/**
|
|
22
23
|
* The order instance this notification is for.
|
|
23
24
|
*
|
|
24
|
-
* @var
|
|
25
|
+
* @var Order
|
|
25
26
|
*/
|
|
26
27
|
public $order;
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The waypoint instance this notification is for.
|
|
31
|
+
*
|
|
32
|
+
* @var Waypoint
|
|
33
|
+
*/
|
|
34
|
+
public $waypoint;
|
|
35
|
+
|
|
28
36
|
/**
|
|
29
37
|
* Notification name.
|
|
30
38
|
*/
|
|
@@ -65,13 +73,14 @@ class OrderCanceled extends Notification implements ShouldQueue
|
|
|
65
73
|
*
|
|
66
74
|
* @return void
|
|
67
75
|
*/
|
|
68
|
-
public function __construct(Order $order, string $reason = '')
|
|
76
|
+
public function __construct(Order $order, string $reason = '', ?Waypoint $waypoint = null)
|
|
69
77
|
{
|
|
70
|
-
$this->order
|
|
71
|
-
$this->
|
|
72
|
-
$this->
|
|
73
|
-
$this->
|
|
74
|
-
$this->
|
|
78
|
+
$this->order = $order;
|
|
79
|
+
$this->waypoint = $waypoint;
|
|
80
|
+
$this->reason = $reason;
|
|
81
|
+
$this->title = 'Order ' . $this->getTrackingNumber() . ' was canceled';
|
|
82
|
+
$this->message = 'Order ' . $this->getTrackingNumber() . ' has been canceled.';
|
|
83
|
+
$this->data = ['id' => $this->order->public_id, 'type' => 'order_canceled'];
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
/**
|
|
@@ -110,12 +119,10 @@ class OrderCanceled extends Notification implements ShouldQueue
|
|
|
110
119
|
$order = new OrderResource($this->order);
|
|
111
120
|
|
|
112
121
|
return [
|
|
122
|
+
'event' => 'order.canceled_notification',
|
|
113
123
|
'title' => $this->title,
|
|
114
124
|
'body' => $this->message . ' ' . $this->reason,
|
|
115
|
-
'data' =>
|
|
116
|
-
...$this->data,
|
|
117
|
-
'order' => $order->toWebhookPayload(),
|
|
118
|
-
],
|
|
125
|
+
'data' => $this->data,
|
|
119
126
|
];
|
|
120
127
|
}
|
|
121
128
|
|
|
@@ -131,7 +138,7 @@ class OrderCanceled extends Notification implements ShouldQueue
|
|
|
131
138
|
->line($this->message)
|
|
132
139
|
->line($this->reason)
|
|
133
140
|
->line('No further action is necessary.')
|
|
134
|
-
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->
|
|
141
|
+
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->getTrackingNumber()]));
|
|
135
142
|
}
|
|
136
143
|
|
|
137
144
|
/**
|
|
@@ -153,4 +160,17 @@ class OrderCanceled extends Notification implements ShouldQueue
|
|
|
153
160
|
{
|
|
154
161
|
return PushNotification::createApnMessage($this->title, $this->message, $this->data, 'view_order');
|
|
155
162
|
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get the tracking number which should be used for this event.
|
|
166
|
+
* In the case that the order has a currentWaypoint attached use its tracking number otherwise use the orders.
|
|
167
|
+
*/
|
|
168
|
+
private function getTrackingNumber(): ?string
|
|
169
|
+
{
|
|
170
|
+
if ($this->waypoint instanceof Waypoint) {
|
|
171
|
+
return $this->waypoint->tracking;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return $this->order->tracking;
|
|
175
|
+
}
|
|
156
176
|
}
|
|
@@ -4,6 +4,7 @@ namespace Fleetbase\FleetOps\Notifications;
|
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Http\Resources\v1\Order as OrderResource;
|
|
6
6
|
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
+
use Fleetbase\FleetOps\Models\Waypoint;
|
|
7
8
|
use Fleetbase\FleetOps\Support\Utils;
|
|
8
9
|
use Fleetbase\Support\PushNotification;
|
|
9
10
|
use Illuminate\Broadcasting\Channel;
|
|
@@ -21,10 +22,17 @@ class OrderCompleted extends Notification implements ShouldQueue
|
|
|
21
22
|
/**
|
|
22
23
|
* The order instance this notification is for.
|
|
23
24
|
*
|
|
24
|
-
* @var
|
|
25
|
+
* @var Order
|
|
25
26
|
*/
|
|
26
27
|
public $order;
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The waypoint instance this notification is for.
|
|
31
|
+
*
|
|
32
|
+
* @var Waypoint
|
|
33
|
+
*/
|
|
34
|
+
public $waypoint;
|
|
35
|
+
|
|
28
36
|
/**
|
|
29
37
|
* Notification name.
|
|
30
38
|
*/
|
|
@@ -60,12 +68,13 @@ class OrderCompleted extends Notification implements ShouldQueue
|
|
|
60
68
|
*
|
|
61
69
|
* @return void
|
|
62
70
|
*/
|
|
63
|
-
public function __construct(Order $order)
|
|
71
|
+
public function __construct(Order $order, ?Waypoint $waypoint = null)
|
|
64
72
|
{
|
|
65
|
-
$this->order
|
|
66
|
-
$this->
|
|
67
|
-
$this->
|
|
68
|
-
$this->
|
|
73
|
+
$this->order = $order;
|
|
74
|
+
$this->waypoint = $waypoint;
|
|
75
|
+
$this->title = 'Order ' . $this->getTrackingNumber() . ' has been completed.';
|
|
76
|
+
$this->message = 'Order ' . $this->getTrackingNumber() . ' has been completed by agent.';
|
|
77
|
+
$this->data = ['id' => $this->order->public_id, 'type' => 'order_completed'];
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
/**
|
|
@@ -104,12 +113,10 @@ class OrderCompleted extends Notification implements ShouldQueue
|
|
|
104
113
|
$order = new OrderResource($this->order);
|
|
105
114
|
|
|
106
115
|
return [
|
|
116
|
+
'event' => 'order.completed_notification',
|
|
107
117
|
'title' => $this->title,
|
|
108
118
|
'body' => $this->message,
|
|
109
|
-
'data' =>
|
|
110
|
-
...$this->data,
|
|
111
|
-
'order' => $order->toWebhookPayload(),
|
|
112
|
-
],
|
|
119
|
+
'data' => $this->data,
|
|
113
120
|
];
|
|
114
121
|
}
|
|
115
122
|
|
|
@@ -124,7 +131,7 @@ class OrderCompleted extends Notification implements ShouldQueue
|
|
|
124
131
|
->subject($this->title)
|
|
125
132
|
->line($this->message)
|
|
126
133
|
->line('No further action is necessary.')
|
|
127
|
-
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->
|
|
134
|
+
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->getTrackingNumber()]));
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
/**
|
|
@@ -146,4 +153,17 @@ class OrderCompleted extends Notification implements ShouldQueue
|
|
|
146
153
|
{
|
|
147
154
|
return PushNotification::createApnMessage($this->title, $this->message, $this->data, 'view_order');
|
|
148
155
|
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get the tracking number which should be used for this event.
|
|
159
|
+
* In the case that the order has a currentWaypoint attached use its tracking number otherwise use the orders.
|
|
160
|
+
*/
|
|
161
|
+
private function getTrackingNumber(): ?string
|
|
162
|
+
{
|
|
163
|
+
if ($this->waypoint instanceof Waypoint) {
|
|
164
|
+
return $this->waypoint->tracking;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return $this->order->tracking;
|
|
168
|
+
}
|
|
149
169
|
}
|
|
@@ -19,7 +19,7 @@ class OrderDispatchFailed extends Notification implements ShouldQueue
|
|
|
19
19
|
/**
|
|
20
20
|
* The order instance this notification is for.
|
|
21
21
|
*
|
|
22
|
-
* @var
|
|
22
|
+
* @var Order
|
|
23
23
|
*/
|
|
24
24
|
public $order;
|
|
25
25
|
|
|
@@ -110,12 +110,10 @@ class OrderDispatchFailed extends Notification implements ShouldQueue
|
|
|
110
110
|
$order = new OrderResource($this->order);
|
|
111
111
|
|
|
112
112
|
return [
|
|
113
|
+
'event' => 'order.assigned_failed_notification',
|
|
113
114
|
'title' => $this->title,
|
|
114
115
|
'body' => $this->message,
|
|
115
|
-
'data' =>
|
|
116
|
-
...$this->data,
|
|
117
|
-
'order' => $order->toWebhookPayload(),
|
|
118
|
-
],
|
|
116
|
+
'data' => $this->data,
|
|
119
117
|
];
|
|
120
118
|
}
|
|
121
119
|
|
|
@@ -5,6 +5,7 @@ namespace Fleetbase\FleetOps\Notifications;
|
|
|
5
5
|
use Fleetbase\Events\ResourceLifecycleEvent;
|
|
6
6
|
use Fleetbase\FleetOps\Http\Resources\v1\Order as OrderResource;
|
|
7
7
|
use Fleetbase\FleetOps\Models\Order;
|
|
8
|
+
use Fleetbase\FleetOps\Models\Waypoint;
|
|
8
9
|
use Fleetbase\FleetOps\Support\Utils;
|
|
9
10
|
use Fleetbase\Support\PushNotification;
|
|
10
11
|
use Illuminate\Broadcasting\Channel;
|
|
@@ -23,10 +24,17 @@ class OrderDispatched extends Notification implements ShouldQueue
|
|
|
23
24
|
/**
|
|
24
25
|
* The order instance this notification is for.
|
|
25
26
|
*
|
|
26
|
-
* @var
|
|
27
|
+
* @var Order
|
|
27
28
|
*/
|
|
28
29
|
public $order;
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* The waypoint instance this notification is for.
|
|
33
|
+
*
|
|
34
|
+
* @var Waypoint
|
|
35
|
+
*/
|
|
36
|
+
public $waypoint;
|
|
37
|
+
|
|
30
38
|
/**
|
|
31
39
|
* Notification name.
|
|
32
40
|
*/
|
|
@@ -62,12 +70,13 @@ class OrderDispatched extends Notification implements ShouldQueue
|
|
|
62
70
|
*
|
|
63
71
|
* @return void
|
|
64
72
|
*/
|
|
65
|
-
public function __construct(Order $order)
|
|
73
|
+
public function __construct(Order $order, ?Waypoint $waypoint = null)
|
|
66
74
|
{
|
|
67
|
-
$this->order
|
|
68
|
-
$this->
|
|
69
|
-
$this->
|
|
70
|
-
$this->
|
|
75
|
+
$this->order = $order;
|
|
76
|
+
$this->waypoint = $waypoint;
|
|
77
|
+
$this->title = 'Order ' . $this->getTrackingNumber() . ' has been dispatched!';
|
|
78
|
+
$this->message = 'An order has just been dispatched to you and is ready to be started.';
|
|
79
|
+
$this->data = ['id' => $this->order->public_id, 'type' => 'order_dispatched'];
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
/**
|
|
@@ -118,12 +127,10 @@ class OrderDispatched extends Notification implements ShouldQueue
|
|
|
118
127
|
$order = new OrderResource($this->order);
|
|
119
128
|
|
|
120
129
|
return [
|
|
130
|
+
'event' => 'order.dispatched_notification',
|
|
121
131
|
'title' => $this->title,
|
|
122
132
|
'body' => $this->message,
|
|
123
|
-
'data' =>
|
|
124
|
-
...$this->data,
|
|
125
|
-
'order' => $order->toWebhookPayload(),
|
|
126
|
-
],
|
|
133
|
+
'data' => $this->data,
|
|
127
134
|
];
|
|
128
135
|
}
|
|
129
136
|
|
|
@@ -169,7 +176,7 @@ class OrderDispatched extends Notification implements ShouldQueue
|
|
|
169
176
|
return (new MailMessage())
|
|
170
177
|
->subject($this->title)
|
|
171
178
|
->line($this->message)
|
|
172
|
-
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->
|
|
179
|
+
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->getTrackingNumber()]));
|
|
173
180
|
}
|
|
174
181
|
|
|
175
182
|
/**
|
|
@@ -191,4 +198,17 @@ class OrderDispatched extends Notification implements ShouldQueue
|
|
|
191
198
|
{
|
|
192
199
|
return PushNotification::createApnMessage($this->title, $this->message, $this->data, 'view_order');
|
|
193
200
|
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Get the tracking number which should be used for this event.
|
|
204
|
+
* In the case that the order has a currentWaypoint attached use its tracking number otherwise use the orders.
|
|
205
|
+
*/
|
|
206
|
+
private function getTrackingNumber(): ?string
|
|
207
|
+
{
|
|
208
|
+
if ($this->waypoint instanceof Waypoint) {
|
|
209
|
+
return $this->waypoint->tracking;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return $this->order->tracking;
|
|
213
|
+
}
|
|
194
214
|
}
|