@fleetbase/fleetops-engine 0.3.6 → 0.3.8
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/admin/navigator-app.hbs +6 -3
- package/addon/components/layout/fleet-ops-sidebar/fleet-listing.hbs +5 -1
- package/addon/components/layout/fleet-ops-sidebar/fleet-listing.js +98 -1
- package/addon/components/layout/fleet-ops-sidebar.hbs +5 -1
- package/addon/components/layout/fleet-ops-sidebar.js +1 -0
- package/addon/controllers/management/drivers/index/edit.js +0 -26
- package/addon/engine.js +4 -4
- package/addon/styles/fleetops-engine.css +17 -0
- package/addon/templates/operations/service-rates/index/new.hbs +1 -1
- package/composer.json +2 -2
- package/extension.json +1 -1
- package/package.json +1 -1
- package/server/config/fleetops.php +4 -1
- package/server/src/Casts/MultiPolygon.php +14 -3
- package/server/src/Casts/Point.php +12 -2
- package/server/src/Casts/Polygon.php +19 -4
- package/server/src/Http/Controllers/Api/v1/DriverController.php +34 -18
- package/server/src/Http/Controllers/Api/v1/EntityController.php +36 -1
- package/server/src/Http/Controllers/Api/v1/LabelController.php +2 -2
- package/server/src/Http/Controllers/Api/v1/OrderController.php +139 -59
- package/server/src/Http/Controllers/Api/v1/PayloadController.php +20 -12
- package/server/src/Http/Controllers/Api/v1/PlaceController.php +25 -3
- package/server/src/Http/Controllers/Api/v1/PurchaseRateController.php +1 -1
- package/server/src/Http/Controllers/Api/v1/ServiceAreaController.php +71 -3
- package/server/src/Http/Controllers/Api/v1/ServiceQuoteController.php +1 -1
- package/server/src/Http/Controllers/Api/v1/ServiceRateController.php +3 -2
- package/server/src/Http/Controllers/Api/v1/TrackingNumberController.php +2 -2
- package/server/src/Http/Controllers/Api/v1/TrackingStatusController.php +2 -2
- package/server/src/Http/Controllers/Api/v1/VehicleController.php +22 -2
- package/server/src/Http/Controllers/Api/v1/ZoneController.php +59 -3
- package/server/src/Http/Controllers/Internal/v1/DriverController.php +148 -0
- package/server/src/Http/Controllers/Internal/v1/NavigatorController.php +38 -0
- package/server/src/Http/Controllers/Internal/v1/OrderController.php +11 -1
- package/server/src/Http/Filter/TrackingStatusFilter.php +10 -0
- package/server/src/Http/Requests/CancelOrderRequest.php +1 -2
- package/server/src/Http/Requests/CreateContactRequest.php +5 -4
- package/server/src/Http/Requests/CreateDriverRequest.php +13 -11
- package/server/src/Http/Requests/CreateEntityRequest.php +7 -4
- package/server/src/Http/Requests/CreateOrderRequest.php +2 -2
- package/server/src/Http/Requests/CreatePayloadRequest.php +1 -1
- package/server/src/Http/Requests/CreatePlaceRequest.php +46 -4
- package/server/src/Http/Requests/CreatePurchaseRateRequest.php +3 -2
- package/server/src/Http/Requests/CreateServiceAreaRequest.php +24 -4
- package/server/src/Http/Requests/CreateServiceRateRequest.php +22 -21
- package/server/src/Http/Requests/CreateTrackingStatusRequest.php +9 -8
- package/server/src/Http/Requests/CreateVehicleRequest.php +6 -4
- package/server/src/Http/Requests/CreateZoneRequest.php +24 -5
- package/server/src/Http/Requests/QueryServiceQuotesRequest.php +11 -10
- package/server/src/Http/Requests/ScheduleOrderRequest.php +32 -0
- package/server/src/Http/Requests/UpdateContactRequest.php +0 -13
- package/server/src/Http/Requests/UpdateServiceAreaRequest.php +1 -23
- package/server/src/Http/Requests/UpdateServiceQuoteRequest.php +1 -23
- package/server/src/Http/Requests/UpdateServiceRateRequest.php +1 -23
- package/server/src/Http/Requests/UpdateTrackingStatusRequest.php +1 -26
- package/server/src/Http/Resources/v1/DeletedResource.php +2 -9
- package/server/src/Http/Resources/v1/Entity.php +47 -44
- package/server/src/Http/Resources/v1/Order.php +1 -1
- package/server/src/Http/Resources/v1/ServiceArea.php +2 -2
- package/server/src/Http/Resources/v1/Vehicle.php +1 -3
- package/server/src/Http/Resources/v1/Zone.php +2 -4
- package/server/src/Models/Entity.php +99 -3
- package/server/src/Models/Order.php +75 -7
- package/server/src/Models/Payload.php +104 -33
- package/server/src/Models/Place.php +56 -17
- package/server/src/Models/ServiceArea.php +285 -18
- package/server/src/Models/ServiceRate.php +10 -6
- package/server/src/Models/TrackingNumber.php +18 -24
- package/server/src/Models/TrackingStatus.php +2 -6
- package/server/src/Models/Vehicle.php +2 -2
- package/server/src/Models/Waypoint.php +0 -10
- package/server/src/Models/Zone.php +132 -5
- package/server/src/Support/Flow.php +17 -3
- package/server/src/Support/Utils.php +143 -9
- package/server/src/routes.php +58 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Models;
|
|
4
4
|
|
|
5
|
-
use Fleetbase\FleetOps\Casts\MultiPolygon;
|
|
5
|
+
use Fleetbase\FleetOps\Casts\MultiPolygon as MultiPolygonCast;
|
|
6
6
|
use Fleetbase\FleetOps\Support\Utils;
|
|
7
7
|
use Fleetbase\Models\Model;
|
|
8
8
|
use Fleetbase\Traits\HasApiModelBehavior;
|
|
@@ -11,7 +11,16 @@ use Fleetbase\Traits\HasUuid;
|
|
|
11
11
|
use Fleetbase\Traits\SendsWebhooks;
|
|
12
12
|
use Fleetbase\Traits\TracksApiCredential;
|
|
13
13
|
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
|
|
14
|
+
use Grimzy\LaravelMysqlSpatial\Types\LineString;
|
|
15
|
+
use Grimzy\LaravelMysqlSpatial\Types\MultiPolygon;
|
|
16
|
+
use Grimzy\LaravelMysqlSpatial\Types\Point;
|
|
17
|
+
use Grimzy\LaravelMysqlSpatial\Types\Polygon;
|
|
18
|
+
use Illuminate\Support\Arr;
|
|
14
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @var \Grimzy\LaravelMysqlSpatial\Types\Point $location
|
|
22
|
+
* @var \Grimzy\LaravelMysqlSpatial\Types\MultiPolygon $border
|
|
23
|
+
*/
|
|
15
24
|
class ServiceArea extends Model
|
|
16
25
|
{
|
|
17
26
|
use HasUuid;
|
|
@@ -83,7 +92,7 @@ class ServiceArea extends Model
|
|
|
83
92
|
* @var array
|
|
84
93
|
*/
|
|
85
94
|
protected $casts = [
|
|
86
|
-
'border' =>
|
|
95
|
+
'border' => MultiPolygonCast::class,
|
|
87
96
|
];
|
|
88
97
|
|
|
89
98
|
/**
|
|
@@ -119,39 +128,297 @@ class ServiceArea extends Model
|
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
/**
|
|
122
|
-
* Creates a
|
|
131
|
+
* Creates a polygon from a given point and radius.
|
|
123
132
|
*
|
|
124
|
-
* @
|
|
133
|
+
* @param \Grimzy\LaravelMysqlSpatial\Types\Point $point the central point from which to create the polygon
|
|
134
|
+
* @param int $meters The radius in meters for the polygon. Default is 500 meters.
|
|
135
|
+
*
|
|
136
|
+
* @return \Grimzy\LaravelMysqlSpatial\Types\Polygon returns a Polygon object
|
|
137
|
+
*/
|
|
138
|
+
public static function createPolygonFromPoint(Point $point, int $meters = 500): Polygon
|
|
139
|
+
{
|
|
140
|
+
$coordinates = array_map(
|
|
141
|
+
function ($coord) {
|
|
142
|
+
return new Point(...$coord);
|
|
143
|
+
},
|
|
144
|
+
Utils::coordsToCircle($point->getLat(), $point->getLng(), $meters)
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return new Polygon([new LineString($coordinates)]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Creates a multi-polygon from a given point and radius.
|
|
152
|
+
*
|
|
153
|
+
* @param \Grimzy\LaravelMysqlSpatial\Types\Point $point the central point from which to create the multi-polygon
|
|
154
|
+
* @param int $meters The radius in meters for the multi-polygon. Default is 500 meters.
|
|
155
|
+
*
|
|
156
|
+
* @return \Grimzy\LaravelMysqlSpatial\Types\MultiPolygon returns a MultiPolygon object
|
|
157
|
+
*/
|
|
158
|
+
public static function createMultiPolygonFromPoint(Point $point, int $meters = 500): MultiPolygon
|
|
159
|
+
{
|
|
160
|
+
$coordinates = Utils::coordsToCircle($point->getLat(), $point->getLng(), $meters);
|
|
161
|
+
|
|
162
|
+
// first and last positions should be equivalent
|
|
163
|
+
if (Arr::first($coordinates) !== Arr::last($coordinates)) {
|
|
164
|
+
$coordinates[] = Arr::first($coordinates);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// conver the coordinate pairs to points
|
|
168
|
+
$coordinates = array_map(
|
|
169
|
+
function ($coord) {
|
|
170
|
+
return new Point(...$coord);
|
|
171
|
+
},
|
|
172
|
+
$coordinates
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
$polygon = new Polygon([new LineString($coordinates)]);
|
|
176
|
+
|
|
177
|
+
return new MultiPolygon([$polygon]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Retrieves the location attribute as a point.
|
|
182
|
+
*
|
|
183
|
+
* @return \Grimzy\LaravelMysqlSpatial\Types\Point returns the centroid of the border as a Point object
|
|
184
|
+
*/
|
|
185
|
+
public function getLocationAttribute(): Point
|
|
186
|
+
{
|
|
187
|
+
$centroid = $this->getCentroid();
|
|
188
|
+
|
|
189
|
+
return new Point($centroid->x(), $centroid->y());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Retrieves the latitude component of the location attribute.
|
|
194
|
+
*
|
|
195
|
+
* @return float returns the latitude value
|
|
196
|
+
*/
|
|
197
|
+
public function getLatitudeAttribute(): float
|
|
198
|
+
{
|
|
199
|
+
return $this->location->getLat();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Retrieves the longitude component of the location attribute.
|
|
204
|
+
*
|
|
205
|
+
* @return float returns the longitude value
|
|
125
206
|
*/
|
|
126
|
-
public function
|
|
207
|
+
public function getLongitudeAttribute(): float
|
|
127
208
|
{
|
|
128
|
-
return
|
|
209
|
+
return $this->location->getLng();
|
|
129
210
|
}
|
|
130
211
|
|
|
131
212
|
/**
|
|
132
|
-
*
|
|
213
|
+
* Creates a polygon from the center point of the current object.
|
|
133
214
|
*
|
|
134
|
-
* @param int $
|
|
135
|
-
* @param int $longitude
|
|
215
|
+
* @param int $meters The radius in meters for the polygon. Default is 500 meters.
|
|
136
216
|
*
|
|
137
|
-
* @return
|
|
217
|
+
* @return \League\Geotools\Polygon\Polygon returns a Polygon object
|
|
138
218
|
*/
|
|
139
|
-
public function
|
|
219
|
+
public function createPolygonFromCenter(int $meters = 500): \League\Geotools\Polygon\Polygon
|
|
140
220
|
{
|
|
141
|
-
|
|
221
|
+
$coordinates = Utils::coordsToCircle($this->latitude, $this->longitude, $meters);
|
|
222
|
+
|
|
223
|
+
return new \League\Geotools\Polygon\Polygon($coordinates);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Converts the border attribute to a MultiPolygon object.
|
|
228
|
+
*
|
|
229
|
+
* @return \League\Geotools\Polygon\MultiPolygon returns a MultiPolygon object representing the border
|
|
230
|
+
*/
|
|
231
|
+
public function asMultiPolygon(): \League\Geotools\Polygon\MultiPolygon
|
|
232
|
+
{
|
|
233
|
+
$polygons = [];
|
|
234
|
+
|
|
235
|
+
if (is_iterable($this->border)) {
|
|
236
|
+
foreach ($this->border as $polygon) {
|
|
237
|
+
$coordinates = [];
|
|
238
|
+
foreach ($polygon as $lineString) {
|
|
239
|
+
foreach ($lineString as $point) {
|
|
240
|
+
$coordinates[] = [$point->getLat(), $point->getLng()];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (count($coordinates)) {
|
|
245
|
+
$polygons[] = new \League\Geotools\Polygon\Polygon($coordinates);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (empty($polygons)) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return new \League\Geotools\Polygon\MultiPolygon($polygons);
|
|
142
255
|
}
|
|
143
256
|
|
|
144
257
|
/**
|
|
145
|
-
*
|
|
258
|
+
* Converts the border's coordinates to an array of \Brick\Geo\Point objects.
|
|
146
259
|
*
|
|
147
|
-
* @
|
|
260
|
+
* @return \Brick\Geo\Point[] an array of \Brick\Geo\Point objects representing the coordinates
|
|
261
|
+
*/
|
|
262
|
+
public function toGeosCoordinates(): array
|
|
263
|
+
{
|
|
264
|
+
$coordinates = [];
|
|
265
|
+
|
|
266
|
+
if (is_iterable($this->border)) {
|
|
267
|
+
foreach ($this->border as $polygon) {
|
|
268
|
+
foreach ($polygon as $lineString) {
|
|
269
|
+
foreach ($lineString as $point) {
|
|
270
|
+
$coordinates[] = \Brick\Geo\Point::fromText('POINT (' . $point->getLat() . ' ' . $point->getLng() . ')');
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return $coordinates;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Converts the border's coordinates to an array of \Brick\Geo\LineString objects.
|
|
148
281
|
*
|
|
149
|
-
* @return
|
|
282
|
+
* @return \Brick\Geo\LineString[] an array of \Brick\Geo\LineString objects
|
|
150
283
|
*/
|
|
151
|
-
public function
|
|
284
|
+
public function toGeosLineStrings(): array
|
|
152
285
|
{
|
|
153
|
-
|
|
154
|
-
|
|
286
|
+
$lineStrings = [];
|
|
287
|
+
if (is_iterable($this->border)) {
|
|
288
|
+
foreach ($this->border as $polygon) {
|
|
289
|
+
$points = [];
|
|
290
|
+
|
|
291
|
+
foreach ($polygon as $lineString) {
|
|
292
|
+
foreach ($lineString as $point) {
|
|
293
|
+
$points[] = \Brick\Geo\Point::fromText('POINT (' . $point->getLat() . ' ' . $point->getLng() . ')');
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if ($points) {
|
|
298
|
+
$lineStrings[] = \Brick\Geo\LineString::of(...$points);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return $lineStrings;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Converts the first LineString from the border into a \Brick\Geo\Polygon.
|
|
308
|
+
*
|
|
309
|
+
* @return \Brick\Geo\Polygon a \Brick\Geo\Polygon object created from the first line string of the border
|
|
310
|
+
*/
|
|
311
|
+
public function toGeosPolygon(): ?\Brick\Geo\Polygon
|
|
312
|
+
{
|
|
313
|
+
$lineString = Arr::first($this->toGeosLineStrings());
|
|
314
|
+
|
|
315
|
+
if (empty($lineString)) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return \Brick\Geo\Polygon::of($lineString);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Converts the border's coordinates to a \Brick\Geo\MultiPolygon object.
|
|
324
|
+
*
|
|
325
|
+
* @return \Brick\Geo\MultiPolygon a \Brick\Geo\MultiPolygon object representing the border
|
|
326
|
+
*/
|
|
327
|
+
public function toGeosMultiPolygon(): ?\Brick\Geo\MultiPolygon
|
|
328
|
+
{
|
|
329
|
+
$polygons = [];
|
|
330
|
+
|
|
331
|
+
if (is_iterable($this->border)) {
|
|
332
|
+
foreach ($this->border as $polygon) {
|
|
333
|
+
$points = [];
|
|
334
|
+
|
|
335
|
+
foreach ($polygon as $lineString) {
|
|
336
|
+
foreach ($lineString as $point) {
|
|
337
|
+
$points[] = \Brick\Geo\Point::fromText('POINT (' . $point->getLat() . ' ' . $point->getLng() . ')');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
$lineString = \Brick\Geo\LineString::of(...$points);
|
|
342
|
+
$polygons[] = \Brick\Geo\Polygon::of($lineString);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (empty($polygons)) {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return \Brick\Geo\MultiPolygon::of(...$polygons);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Calculates the centroid of the border as a \Brick\Geo\Point.
|
|
355
|
+
*
|
|
356
|
+
* @return \Brick\Geo\Point the centroid of the border as a \Brick\Geo\Point object
|
|
357
|
+
*/
|
|
358
|
+
public function getCentroid(): \Brick\Geo\Point
|
|
359
|
+
{
|
|
360
|
+
$geometryEngine = new \Brick\Geo\Engine\GEOSEngine();
|
|
361
|
+
$borderAsMultiPolygon = $this->toGeosMultiPolygon();
|
|
362
|
+
|
|
363
|
+
if ($borderAsMultiPolygon instanceof \Brick\Geo\Geometry) {
|
|
364
|
+
return $geometryEngine->centroid($borderAsMultiPolygon);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return \Brick\Geo\Point::fromText('POINT (0 0)');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Converts the border attribute to a Polygon object.
|
|
372
|
+
*
|
|
373
|
+
* @return \League\Geotools\Polygon\Polygon returns the first Polygon object from the border
|
|
374
|
+
*/
|
|
375
|
+
public function asPolygon(): ?\League\Geotools\Polygon\Polygon
|
|
376
|
+
{
|
|
377
|
+
$polygons = [];
|
|
378
|
+
|
|
379
|
+
if (is_iterable($this->border)) {
|
|
380
|
+
foreach ($this->border as $polygon) {
|
|
381
|
+
$coordinates = [];
|
|
382
|
+
foreach ($polygon as $point) {
|
|
383
|
+
$coordinates[] = [$point->getLat(), $point->getLng()];
|
|
384
|
+
}
|
|
385
|
+
$polygons[] = new \League\Geotools\Polygon\Polygon($coordinates);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return Arr::first($polygons);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Checks if a given point is included within the border.
|
|
394
|
+
*
|
|
395
|
+
* @param Point $point the point to check
|
|
396
|
+
*
|
|
397
|
+
* @return bool returns true if the point is inside the polygon, false otherwise
|
|
398
|
+
*/
|
|
399
|
+
public function includesPoint(Point $point): bool
|
|
400
|
+
{
|
|
401
|
+
$latitude = $point->getLat();
|
|
402
|
+
$longitude = $point->getLng();
|
|
403
|
+
$coordinate = new \League\Geotools\Coordinate\Coordinate([$latitude, $longitude]);
|
|
404
|
+
|
|
405
|
+
return $this->asPolygon()->pointInPolygon($coordinate);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Checks if a set of points are all included within the border.
|
|
410
|
+
*
|
|
411
|
+
* @param array $coordinates an array of coordinates to check
|
|
412
|
+
*
|
|
413
|
+
* @return bool returns true if all points are inside the polygon, false otherwise
|
|
414
|
+
*/
|
|
415
|
+
public function includesPoints(array $coordinates = []): bool
|
|
416
|
+
{
|
|
417
|
+
foreach ($coordinates as $coord) {
|
|
418
|
+
$point = Utils::getPointFromMixed($coord);
|
|
419
|
+
$includesPoint = $this->includesPoint($point);
|
|
420
|
+
|
|
421
|
+
if (!$includesPoint) {
|
|
155
422
|
return false;
|
|
156
423
|
}
|
|
157
424
|
}
|
|
@@ -81,10 +81,10 @@ class ServiceRate extends Model
|
|
|
81
81
|
* @var array
|
|
82
82
|
*/
|
|
83
83
|
protected $casts = [
|
|
84
|
-
'base_fee' => Money::class
|
|
85
|
-
'per_meter_flat_rate_fee' => Money::class
|
|
86
|
-
'cod_flat_fee' => Money::class
|
|
87
|
-
'peak_hours_flat_fee' => Money::class
|
|
84
|
+
'base_fee' => Money::class,
|
|
85
|
+
'per_meter_flat_rate_fee' => Money::class,
|
|
86
|
+
'cod_flat_fee' => Money::class,
|
|
87
|
+
'peak_hours_flat_fee' => Money::class,
|
|
88
88
|
];
|
|
89
89
|
|
|
90
90
|
/**
|
|
@@ -461,7 +461,11 @@ class ServiceRate extends Model
|
|
|
461
461
|
$serviceRates = $serviceRatesQuery->get();
|
|
462
462
|
|
|
463
463
|
$waypoints = collect($places)->map(function ($place) {
|
|
464
|
-
|
|
464
|
+
$place = Place::createFromMixed($place);
|
|
465
|
+
|
|
466
|
+
if ($place instanceof Place) {
|
|
467
|
+
return $place->getLocationAsPoint();
|
|
468
|
+
}
|
|
465
469
|
});
|
|
466
470
|
|
|
467
471
|
foreach ($serviceRates as $serviceRate) {
|
|
@@ -726,7 +730,7 @@ class ServiceRate extends Model
|
|
|
726
730
|
]);
|
|
727
731
|
|
|
728
732
|
// Prepare all waypoints and origin and destination
|
|
729
|
-
$waypoints = $payload->getAllStops()
|
|
733
|
+
$waypoints = $payload->getAllStops();
|
|
730
734
|
$origin = $waypoints->first();
|
|
731
735
|
$destinations = $waypoints->skip(1)->toArray();
|
|
732
736
|
|
|
@@ -88,7 +88,9 @@ class TrackingNumber extends Model
|
|
|
88
88
|
*/
|
|
89
89
|
public function getLastStatusAttribute()
|
|
90
90
|
{
|
|
91
|
-
|
|
91
|
+
$this->load('status');
|
|
92
|
+
|
|
93
|
+
return data_get($this, 'status.status');
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
/**
|
|
@@ -96,7 +98,9 @@ class TrackingNumber extends Model
|
|
|
96
98
|
*/
|
|
97
99
|
public function getLastStatusCodeAttribute()
|
|
98
100
|
{
|
|
99
|
-
|
|
101
|
+
$this->load('status');
|
|
102
|
+
|
|
103
|
+
return data_get($this, 'status.code');
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
/**
|
|
@@ -104,13 +108,13 @@ class TrackingNumber extends Model
|
|
|
104
108
|
*/
|
|
105
109
|
public function getLastStatusUpdatedAtAttribute()
|
|
106
110
|
{
|
|
107
|
-
|
|
111
|
+
$this->load('status');
|
|
112
|
+
|
|
113
|
+
return data_get($this, 'status.created_at');
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* @var Model
|
|
117
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
114
118
|
*/
|
|
115
119
|
public function status()
|
|
116
120
|
{
|
|
@@ -118,9 +122,7 @@ class TrackingNumber extends Model
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* @var Model
|
|
125
|
+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
124
126
|
*/
|
|
125
127
|
public function statuses()
|
|
126
128
|
{
|
|
@@ -128,9 +130,7 @@ class TrackingNumber extends Model
|
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @var Model
|
|
133
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
134
134
|
*/
|
|
135
135
|
public function order()
|
|
136
136
|
{
|
|
@@ -138,9 +138,7 @@ class TrackingNumber extends Model
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @var Model
|
|
141
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
144
142
|
*/
|
|
145
143
|
public function entity()
|
|
146
144
|
{
|
|
@@ -148,9 +146,7 @@ class TrackingNumber extends Model
|
|
|
148
146
|
}
|
|
149
147
|
|
|
150
148
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @var Model
|
|
149
|
+
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
154
150
|
*/
|
|
155
151
|
public function owner()
|
|
156
152
|
{
|
|
@@ -158,9 +154,7 @@ class TrackingNumber extends Model
|
|
|
158
154
|
}
|
|
159
155
|
|
|
160
156
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @var Model
|
|
157
|
+
* @return string
|
|
164
158
|
*/
|
|
165
159
|
public function getTypeAttribute()
|
|
166
160
|
{
|
|
@@ -170,9 +164,9 @@ class TrackingNumber extends Model
|
|
|
170
164
|
/**
|
|
171
165
|
* Generates a fleetbase tracking number.
|
|
172
166
|
*
|
|
173
|
-
* @var
|
|
167
|
+
* @var string
|
|
174
168
|
*/
|
|
175
|
-
public static function generateTrackingNumber($region = 'SG', $length = 10)
|
|
169
|
+
public static function generateTrackingNumber($region = 'SG', $length = 10): string
|
|
176
170
|
{
|
|
177
171
|
$company = \Fleetbase\Models\Company::where('uuid', session('company'))->withoutGlobalScopes()->first();
|
|
178
172
|
$companyName = $company ? strtoupper(substr($company->name, 0, 3)) : null;
|
|
@@ -188,7 +182,7 @@ class TrackingNumber extends Model
|
|
|
188
182
|
/**
|
|
189
183
|
* Generates a unique fleetbase tracking number.
|
|
190
184
|
*
|
|
191
|
-
* @var
|
|
185
|
+
* @var string
|
|
192
186
|
*/
|
|
193
187
|
public static function generateNumber($region = 'SG', $length = 10)
|
|
194
188
|
{
|
|
@@ -110,9 +110,7 @@ class TrackingStatus extends Model
|
|
|
110
110
|
protected $hidden = [];
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @var Model
|
|
113
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
116
114
|
*/
|
|
117
115
|
public function trackingNumber()
|
|
118
116
|
{
|
|
@@ -120,9 +118,7 @@ class TrackingStatus extends Model
|
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* @var Model
|
|
121
|
+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
126
122
|
*/
|
|
127
123
|
public function proof()
|
|
128
124
|
{
|
|
@@ -49,7 +49,7 @@ class Vehicle extends Model
|
|
|
49
49
|
*
|
|
50
50
|
* @var array
|
|
51
51
|
*/
|
|
52
|
-
protected $searchableColumns = ['make', 'model', 'year', 'plate_number', '
|
|
52
|
+
protected $searchableColumns = ['make', 'model', 'year', 'plate_number', 'vin', 'public_id'];
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Attributes that is filterable on this model.
|
|
@@ -233,7 +233,7 @@ class Vehicle extends Model
|
|
|
233
233
|
$nameSegments = [];
|
|
234
234
|
|
|
235
235
|
// Populate the nameSegments array with the values of the attributes
|
|
236
|
-
$keys = ['year', 'make', 'model', 'trim', 'plate_number'
|
|
236
|
+
$keys = ['year', 'make', 'model', 'trim', 'plate_number'];
|
|
237
237
|
foreach ($keys as $key) {
|
|
238
238
|
if (!empty($this->{$key})) {
|
|
239
239
|
$nameSegments[] = $this->{$key};
|
|
@@ -146,16 +146,6 @@ class Waypoint extends Model
|
|
|
146
146
|
return $this->belongsTo(\Fleetbase\Models\Company::class);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
/**
|
|
150
|
-
* Waypoint has completed instance.
|
|
151
|
-
*
|
|
152
|
-
* @var Model
|
|
153
|
-
*/
|
|
154
|
-
public function completed()
|
|
155
|
-
{
|
|
156
|
-
return $this->hasOne(WaypointCompleted::class, 'place_uuid', 'place_uuid')->where('payload_uuid', $this->payload_uuid);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
149
|
/**
|
|
160
150
|
* The tracking number for waypoint.
|
|
161
151
|
*/
|