@fleetbase/fleetops-engine 0.3.7 → 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/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/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/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 +27 -12
- 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/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 +4 -3
|
@@ -105,8 +105,8 @@ class TrackingStatusController extends Controller
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// if no code set create a code from the status
|
|
108
|
-
if (empty($
|
|
109
|
-
$input['code'] = TrackingStatus::prepareCode($input
|
|
108
|
+
if (empty($trackingStatus->code)) {
|
|
109
|
+
$input['code'] = TrackingStatus::prepareCode(data_get($input, 'status', $trackingStatus->status));
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
// update the trackingStatus
|
|
@@ -24,13 +24,18 @@ class VehicleController extends Controller
|
|
|
24
24
|
public function create(CreateVehicleRequest $request)
|
|
25
25
|
{
|
|
26
26
|
// get request input
|
|
27
|
-
$input = $request->only(['status', 'make', 'model', 'year', 'trim', 'type', 'plate_number', 'vin', 'meta', 'location', 'altitude', 'heading', 'speed']);
|
|
27
|
+
$input = $request->only(['status', 'make', 'model', 'year', 'trim', 'type', 'plate_number', 'vin', 'meta', 'online', 'location', 'altitude', 'heading', 'speed']);
|
|
28
28
|
// make sure company is set
|
|
29
29
|
$input['company_uuid'] = session('company');
|
|
30
30
|
|
|
31
31
|
// create instance of vehicle model
|
|
32
32
|
$vehicle = new Vehicle();
|
|
33
33
|
|
|
34
|
+
// set default online
|
|
35
|
+
if (!isset($input['online'])) {
|
|
36
|
+
$input['online'] = 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
// vendor assignment
|
|
35
40
|
if ($request->has('vendor')) {
|
|
36
41
|
$input['vendor_uuid'] = Utils::getUuid('vendors', [
|
|
@@ -39,6 +44,11 @@ class VehicleController extends Controller
|
|
|
39
44
|
]);
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
// latitude / longitude
|
|
48
|
+
if ($request->has(['latitude', 'longitude'])) {
|
|
49
|
+
$input['location'] = Utils::getPointFromCoordinates($request->only(['latitude', 'longitude']));
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
// apply user input to vehicle
|
|
43
53
|
$vehicle = $vehicle->fill($input);
|
|
44
54
|
|
|
@@ -90,7 +100,7 @@ class VehicleController extends Controller
|
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
// get request input
|
|
93
|
-
$input = $request->only(['status', 'make', 'model', 'year', 'trim', 'type', 'plate_number', 'vin', 'meta', 'location', 'altitude', 'heading', 'speed']);
|
|
103
|
+
$input = $request->only(['status', 'make', 'model', 'year', 'trim', 'type', 'plate_number', 'vin', 'meta', 'location', 'online', 'altitude', 'heading', 'speed']);
|
|
94
104
|
|
|
95
105
|
// vendor assignment
|
|
96
106
|
if ($request->has('vendor')) {
|
|
@@ -100,6 +110,16 @@ class VehicleController extends Controller
|
|
|
100
110
|
]);
|
|
101
111
|
}
|
|
102
112
|
|
|
113
|
+
// set default online
|
|
114
|
+
if (!isset($input['online'])) {
|
|
115
|
+
$input['online'] = 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// latitude / longitude
|
|
119
|
+
if ($request->has(['latitude', 'longitude'])) {
|
|
120
|
+
$input['location'] = Utils::getPointFromCoordinates($request->only(['latitude', 'longitude']));
|
|
121
|
+
}
|
|
122
|
+
|
|
103
123
|
// update the vehicle w/ user input
|
|
104
124
|
$vehicle->fill($input);
|
|
105
125
|
|
|
@@ -9,6 +9,7 @@ use Fleetbase\FleetOps\Http\Resources\v1\Zone as ZoneResource;
|
|
|
9
9
|
use Fleetbase\FleetOps\Models\Zone;
|
|
10
10
|
use Fleetbase\FleetOps\Support\Utils;
|
|
11
11
|
use Fleetbase\Http\Controllers\Controller;
|
|
12
|
+
use Grimzy\LaravelMysqlSpatial\Types\Point;
|
|
12
13
|
use Illuminate\Http\Request;
|
|
13
14
|
|
|
14
15
|
class ZoneController extends Controller
|
|
@@ -23,7 +24,10 @@ class ZoneController extends Controller
|
|
|
23
24
|
public function create(CreateZoneRequest $request)
|
|
24
25
|
{
|
|
25
26
|
// get request input
|
|
26
|
-
$input = $request->only(['name', '
|
|
27
|
+
$input = $request->only(['name', 'border', 'status', 'description', 'color', 'stroke_color']);
|
|
28
|
+
|
|
29
|
+
// get radius for creating zone border - default to 500 meters
|
|
30
|
+
$radius = $request->input('radius', 500);
|
|
27
31
|
|
|
28
32
|
// make sure company is set
|
|
29
33
|
$input['company_uuid'] = session('company');
|
|
@@ -36,10 +40,37 @@ class ZoneController extends Controller
|
|
|
36
40
|
]);
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
// if latitude and longitude is provided
|
|
44
|
+
if ($request->has(['latitude', 'longitude'])) {
|
|
45
|
+
// create a polygon given the radius
|
|
46
|
+
$latitude = $request->input('latitude');
|
|
47
|
+
$longitude = $request->input('longitude');
|
|
48
|
+
$point = new Point($latitude, $longitude);
|
|
49
|
+
|
|
50
|
+
if ($point instanceof Point) {
|
|
51
|
+
$input['border'] = Zone::createPolygonFromPoint($point, $radius);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// if a location is provided
|
|
56
|
+
if ($request->has('location')) {
|
|
57
|
+
$location = $request->input('location');
|
|
58
|
+
$point = Utils::getPointFromMixed($location);
|
|
59
|
+
|
|
60
|
+
if ($point instanceof Point) {
|
|
61
|
+
$input['border'] = Zone::createPolygonFromPoint($point, $radius);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @todo if missing location, latitude, longitude and border
|
|
67
|
+
* then create a zone from the center of the service area provided
|
|
68
|
+
*/
|
|
69
|
+
|
|
39
70
|
// create the zone
|
|
40
71
|
$zone = Zone::create($input);
|
|
41
72
|
|
|
42
|
-
// response the
|
|
73
|
+
// response the zone resource
|
|
43
74
|
return new ZoneResource($zone);
|
|
44
75
|
}
|
|
45
76
|
|
|
@@ -66,7 +97,10 @@ class ZoneController extends Controller
|
|
|
66
97
|
}
|
|
67
98
|
|
|
68
99
|
// get request input
|
|
69
|
-
$input = $request->only(['name', '
|
|
100
|
+
$input = $request->only(['name', 'border', 'status', 'description', 'color', 'stroke_color']);
|
|
101
|
+
|
|
102
|
+
// get radius for creating zone border - default to 500 meters
|
|
103
|
+
$radius = $request->input('radius', 500);
|
|
70
104
|
|
|
71
105
|
// service area assignment
|
|
72
106
|
if ($request->has('service_area')) {
|
|
@@ -76,6 +110,28 @@ class ZoneController extends Controller
|
|
|
76
110
|
]);
|
|
77
111
|
}
|
|
78
112
|
|
|
113
|
+
// if latitude and longitude is provided
|
|
114
|
+
if ($request->has(['latitude', 'longitude'])) {
|
|
115
|
+
// create a polygon given the radius
|
|
116
|
+
$latitude = $request->input('latitude');
|
|
117
|
+
$longitude = $request->input('longitude');
|
|
118
|
+
$point = new Point($latitude, $longitude);
|
|
119
|
+
|
|
120
|
+
if ($point instanceof Point) {
|
|
121
|
+
$input['border'] = Zone::createPolygonFromPoint($point, $radius);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// if a location is provided
|
|
126
|
+
if ($request->has('location')) {
|
|
127
|
+
$location = $request->input('location');
|
|
128
|
+
$point = Utils::getPointFromMixed($location);
|
|
129
|
+
|
|
130
|
+
if ($point instanceof Point) {
|
|
131
|
+
$input['border'] = Zone::createPolygonFromPoint($point, $radius);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
79
135
|
// update the zone
|
|
80
136
|
$zone->update($input);
|
|
81
137
|
|
|
@@ -62,6 +62,16 @@ class OrderController extends FleetOpsController
|
|
|
62
62
|
|
|
63
63
|
$input['integrated_vendor_order'] = $integratedVendorOrder;
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
// if no type is set its default to default
|
|
67
|
+
if (!isset($input['type'])) {
|
|
68
|
+
$input['type'] = 'default';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// if no status is set its default to `created`
|
|
72
|
+
if (!isset($input['status'])) {
|
|
73
|
+
$input['status'] = 'created';
|
|
74
|
+
}
|
|
65
75
|
},
|
|
66
76
|
function (&$request, Order &$order, &$requestInput) {
|
|
67
77
|
$input = $request->input('order');
|
|
@@ -101,7 +111,7 @@ class OrderController extends FleetOpsController
|
|
|
101
111
|
$order->purchaseServiceQuote($serviceQuote);
|
|
102
112
|
|
|
103
113
|
// dispatch if flagged true
|
|
104
|
-
$order->
|
|
114
|
+
$order->firstDispatchWithActivity();
|
|
105
115
|
|
|
106
116
|
// load tracking number
|
|
107
117
|
$order->load(['trackingNumber']);
|
|
@@ -11,6 +11,16 @@ class TrackingStatusFilter extends Filter
|
|
|
11
11
|
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
public function trackingNumber(string $trackingNumber)
|
|
15
|
+
{
|
|
16
|
+
$this->builder->whereHas('trackingNumber', function ($query) use ($trackingNumber) {
|
|
17
|
+
$query->where(function ($query) use ($trackingNumber) {
|
|
18
|
+
$query->where('public_id', $trackingNumber);
|
|
19
|
+
$query->orWhere('uuid', $trackingNumber);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
public function order(string $order)
|
|
15
25
|
{
|
|
16
26
|
$this->builder->whereHas(
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Http\Requests;
|
|
4
4
|
|
|
5
|
-
use Fleetbase\FleetOps\Support\Utils;
|
|
6
5
|
use Fleetbase\Http\Requests\FleetbaseRequest;
|
|
7
6
|
|
|
8
7
|
class CancelOrderRequest extends FleetbaseRequest
|
|
@@ -14,7 +13,7 @@ class CancelOrderRequest extends FleetbaseRequest
|
|
|
14
13
|
*/
|
|
15
14
|
public function authorize()
|
|
16
15
|
{
|
|
17
|
-
return
|
|
16
|
+
return request()->session()->has('api_credential');
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Http\Requests;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\Http\Requests\FleetbaseRequest;
|
|
6
|
+
use Illuminate\Validation\Rules\RequiredIf;
|
|
6
7
|
|
|
7
8
|
class CreateContactRequest extends FleetbaseRequest
|
|
8
9
|
{
|
|
@@ -24,10 +25,10 @@ class CreateContactRequest extends FleetbaseRequest
|
|
|
24
25
|
public function rules()
|
|
25
26
|
{
|
|
26
27
|
return [
|
|
27
|
-
'name' => 'required',
|
|
28
|
-
'type' => '
|
|
29
|
-
'email' => 'nullable
|
|
30
|
-
'phone' => 'nullable',
|
|
28
|
+
'name' => ['required'],
|
|
29
|
+
'type' => [new RequiredIf($this->isMethod('POST'))],
|
|
30
|
+
'email' => ['nullable', 'email'],
|
|
31
|
+
'phone' => ['nullable'],
|
|
31
32
|
];
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -28,17 +28,19 @@ class CreateDriverRequest extends FleetbaseRequest
|
|
|
28
28
|
$isCreating = $this->isMethod('POST');
|
|
29
29
|
|
|
30
30
|
return [
|
|
31
|
-
'name'
|
|
32
|
-
'email'
|
|
33
|
-
'phone'
|
|
34
|
-
'password'
|
|
35
|
-
'country'
|
|
36
|
-
'city'
|
|
37
|
-
'vehicle'
|
|
38
|
-
'status'
|
|
39
|
-
'vendor'
|
|
40
|
-
'job'
|
|
41
|
-
'location'
|
|
31
|
+
'name' => [Rule::requiredIf($isCreating)],
|
|
32
|
+
'email' => [Rule::requiredIf($isCreating), Rule::when($this->filled('email'), ['email']), Rule::when($isCreating, [Rule::unique('users')->whereNull('deleted_at')])],
|
|
33
|
+
'phone' => [Rule::requiredIf($isCreating), Rule::when($isCreating, [Rule::unique('users')->whereNull('deleted_at')])],
|
|
34
|
+
'password' => 'nullable|string',
|
|
35
|
+
'country' => 'nullable|size:2',
|
|
36
|
+
'city' => 'nullable|string',
|
|
37
|
+
'vehicle' => 'nullable|string|starts_with:vehicle_|exists:drivers,public_id',
|
|
38
|
+
'status' => 'nullable|string|in:active,inactive',
|
|
39
|
+
'vendor' => 'nullable|exists:vendors,public_id',
|
|
40
|
+
'job' => 'nullable|exists:orders,public_id',
|
|
41
|
+
'location' => ['nullable', new ResolvablePoint()],
|
|
42
|
+
'latitude' => ['nullable', 'required_with:longitude'],
|
|
43
|
+
'longitude' => ['nullable', 'required_with:latitude'],
|
|
42
44
|
];
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -27,16 +27,19 @@ class CreateEntityRequest extends FleetbaseRequest
|
|
|
27
27
|
return [
|
|
28
28
|
'name' => [Rule::requiredIf($this->isMethod('POST'))],
|
|
29
29
|
'type' => [Rule::requiredIf($this->isMethod('POST'))],
|
|
30
|
-
'
|
|
30
|
+
'destination' => ['nullable', Rule::exists('places', 'public_id')->whereNull('deleted_at')],
|
|
31
|
+
'waypoint' => ['nullable', Rule::exists('places', 'public_id')->whereNull('deleted_at')],
|
|
32
|
+
'payload' => ['nullable', Rule::exists('payloads', 'public_id')->whereNull('deleted_at'), 'required_with:destination,waypoint'],
|
|
33
|
+
'email' => ['nullable', 'email'],
|
|
31
34
|
'weight' => 'nullable',
|
|
32
35
|
'weight_unit' => [Rule::requiredIf($this->has('weight')), 'in:g,oz,lb,kg'],
|
|
33
36
|
'length' => 'nullable',
|
|
34
37
|
'width' => 'nullable',
|
|
35
38
|
'height' => 'nullable',
|
|
36
39
|
'dimensions_unit' => [Rule::requiredIf($this->has(['length', 'width', 'height'])), 'in:cm,in,ft,mm,m,yd'],
|
|
37
|
-
'declared_value' => 'nullable',
|
|
38
|
-
'price' => 'nullable',
|
|
39
|
-
'sales_price' => 'nullable',
|
|
40
|
+
'declared_value' => ['nullable', 'numeric'],
|
|
41
|
+
'price' => ['nullable', 'numeric'],
|
|
42
|
+
'sales_price' => ['nullable', 'numeric'],
|
|
40
43
|
'currency' => [Rule::requiredIf($this->has(['declared_value', 'price', 'sales_price'])), 'size:3'],
|
|
41
44
|
];
|
|
42
45
|
}
|
|
@@ -26,11 +26,11 @@ class CreateOrderRequest extends FleetbaseRequest
|
|
|
26
26
|
{
|
|
27
27
|
$validations = [
|
|
28
28
|
'adhoc' => 'in:true,false,1,0',
|
|
29
|
-
'dispatch' => 'boolean',
|
|
29
|
+
'dispatch' => ['nullable', 'boolean'],
|
|
30
30
|
'adhoc_distance' => 'numeric',
|
|
31
31
|
'pod_required' => 'in:true,false,1,0',
|
|
32
32
|
'pod_method' => 'in:' . config('api.pod_methods'),
|
|
33
|
-
'scheduled_at' => 'date',
|
|
33
|
+
'scheduled_at' => ['nullable', 'date'],
|
|
34
34
|
'driver' => 'nullable|exists:drivers,public_id',
|
|
35
35
|
'service_quote' => 'nullable|exists:service_quotes,public_id',
|
|
36
36
|
'purchase_rate' => 'nullable|exists:purchase_rates,public_id',
|
|
@@ -28,7 +28,7 @@ class CreatePayloadRequest extends FleetbaseRequest
|
|
|
28
28
|
'entities' => 'array',
|
|
29
29
|
'waypoints' => 'array',
|
|
30
30
|
'return' => 'nullable',
|
|
31
|
-
'type' => '
|
|
31
|
+
'type' => [Rule::requiredIf($this->isMethod('POST'))],
|
|
32
32
|
'cod_currency' => [Rule::requiredIf($this->has(['cod_amount'])), 'size:3'],
|
|
33
33
|
'cod_payment_method' => [Rule::requiredIf($this->has(['cod_amount'])), 'in:card,check,cash,bank_transfer'],
|
|
34
34
|
];
|
|
@@ -29,14 +29,56 @@ class CreatePlaceRequest extends FleetbaseRequest
|
|
|
29
29
|
public function rules()
|
|
30
30
|
{
|
|
31
31
|
return [
|
|
32
|
-
'name' => [
|
|
33
|
-
|
|
32
|
+
'name' => [
|
|
33
|
+
Rule::requiredIf(function () {
|
|
34
|
+
$isCreating = $this->isMethod('POST');
|
|
35
|
+
$hasCoordiantes = $this->filled('latitude') && $this->filled('longitude');
|
|
36
|
+
$hasLocation = $this->filled('location');
|
|
37
|
+
$hasStreet = $this->filled('street1');
|
|
38
|
+
|
|
39
|
+
// if creating then it's required
|
|
40
|
+
if ($isCreating) {
|
|
41
|
+
// if either has coordinated or location then it's not required
|
|
42
|
+
if ($hasCoordiantes || $hasLocation) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// if street1 provided then it's not required
|
|
47
|
+
if ($hasStreet) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return false;
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
'street1' => [
|
|
58
|
+
Rule::requiredIf(function () {
|
|
59
|
+
$isCreating = $this->isMethod('POST');
|
|
60
|
+
$hasCoordiantes = $this->filled('latitude') && $this->filled('longitude');
|
|
61
|
+
$hasLocation = $this->filled('location');
|
|
62
|
+
|
|
63
|
+
// if creating then it's required
|
|
64
|
+
if ($isCreating) {
|
|
65
|
+
// if either has coordinated or location then it's not required
|
|
66
|
+
if ($hasCoordiantes || $hasLocation) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return false;
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
34
76
|
'customer' => ['nullable', new ExistsInAny(['vendors', 'contacts'], 'public_id')],
|
|
35
77
|
'contact' => ['nullable', new ExistsInAny(['vendors', 'contacts'], 'public_id')],
|
|
36
78
|
'vendor' => 'nullable|exists:vendors,public_id',
|
|
37
79
|
'location' => ['nullable', new ResolvablePoint()],
|
|
38
|
-
'latitude' => 'nullable',
|
|
39
|
-
'longitude' => 'nullable',
|
|
80
|
+
'latitude' => ['nullable', 'required_with:longitude'],
|
|
81
|
+
'longitude' => ['nullable', 'required_with:latitude'],
|
|
40
82
|
];
|
|
41
83
|
}
|
|
42
84
|
}
|
|
@@ -4,6 +4,7 @@ namespace Fleetbase\FleetOps\Http\Requests;
|
|
|
4
4
|
|
|
5
5
|
use Fleetbase\Http\Requests\FleetbaseRequest;
|
|
6
6
|
use Fleetbase\Rules\ExistsInAny;
|
|
7
|
+
use Illuminate\Validation\Rule;
|
|
7
8
|
|
|
8
9
|
class CreatePurchaseRateRequest extends FleetbaseRequest
|
|
9
10
|
{
|
|
@@ -25,8 +26,8 @@ class CreatePurchaseRateRequest extends FleetbaseRequest
|
|
|
25
26
|
public function rules()
|
|
26
27
|
{
|
|
27
28
|
return [
|
|
28
|
-
'service_quote' => 'required
|
|
29
|
-
'order' => 'nullable
|
|
29
|
+
'service_quote' => ['required', Rule::exists('service_quotes', 'public_id')->whereNull('deleted_at')],
|
|
30
|
+
'order' => ['nullable', Rule::exists('orders', 'public_id')->whereNull('deleted_at')],
|
|
30
31
|
'customer' => ['nullable', new ExistsInAny(['vendors', 'contacts'], 'public_id')],
|
|
31
32
|
];
|
|
32
33
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Http\Requests;
|
|
4
4
|
|
|
5
|
+
use Fleetbase\FleetOps\Rules\ResolvablePoint;
|
|
5
6
|
use Fleetbase\Http\Requests\FleetbaseRequest;
|
|
6
7
|
use Illuminate\Validation\Rule;
|
|
7
8
|
|
|
@@ -14,9 +15,7 @@ class CreateServiceAreaRequest extends FleetbaseRequest
|
|
|
14
15
|
*/
|
|
15
16
|
public function authorize()
|
|
16
17
|
{
|
|
17
|
-
return request()
|
|
18
|
-
->session()
|
|
19
|
-
->has('api_credential');
|
|
18
|
+
return request()->session()->has('api_credential');
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
/**
|
|
@@ -28,8 +27,29 @@ class CreateServiceAreaRequest extends FleetbaseRequest
|
|
|
28
27
|
{
|
|
29
28
|
return [
|
|
30
29
|
'name' => [Rule::requiredIf($this->isMethod('POST')), 'string'],
|
|
31
|
-
'country' => '
|
|
30
|
+
'country' => [Rule::requiredIf($this->isMethod('POST')), 'string'],
|
|
32
31
|
'status' => 'in:active,inactive',
|
|
32
|
+
'border' => ['nullable', Rule::requiredIf(function () {
|
|
33
|
+
$isCreating = $this->isMethod('POST');
|
|
34
|
+
$hasCoordiantes = $this->filled('latitude') && $this->filled('longitude');
|
|
35
|
+
$hasLocation = $this->filled('location');
|
|
36
|
+
|
|
37
|
+
// if creating then it's required
|
|
38
|
+
if ($isCreating) {
|
|
39
|
+
// if either has coordinated or location then it's not required
|
|
40
|
+
if ($hasCoordiantes || $hasLocation) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return false;
|
|
48
|
+
})],
|
|
49
|
+
'parent' => ['nullable', 'exists:service_areas,public_id'],
|
|
50
|
+
'location' => ['nullable', new ResolvablePoint()],
|
|
51
|
+
'latitude' => ['nullable', 'required_with:longitude'],
|
|
52
|
+
'longitude' => ['nullable', 'required_with:latitude'],
|
|
33
53
|
];
|
|
34
54
|
}
|
|
35
55
|
}
|
|
@@ -29,28 +29,29 @@ class CreateServiceRateRequest extends FleetbaseRequest
|
|
|
29
29
|
return [
|
|
30
30
|
'service_name' => [Rule::requiredIf($this->isMethod('POST')), 'string'],
|
|
31
31
|
'service_type' => [Rule::requiredIf($this->isMethod('POST')), 'string'],
|
|
32
|
-
'service_area' => '
|
|
33
|
-
'zone' => '
|
|
34
|
-
'rate_calculation_method' => '
|
|
35
|
-
'currency' => 'required
|
|
36
|
-
'base_fee' => '
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'meter_fees
|
|
40
|
-
'meter_fees.*.
|
|
41
|
-
'
|
|
42
|
-
'
|
|
32
|
+
'service_area' => [Rule::exists('service_areas', 'public_id')->whereNull('deleted_at')],
|
|
33
|
+
'zone' => [Rule::exists('zones', 'public_id')->whereNull('deleted_at')],
|
|
34
|
+
'rate_calculation_method' => [Rule::requiredIf($this->isMethod('POST')), 'string', 'in:fixed_meter,per_meter,per_drop,algo'],
|
|
35
|
+
'currency' => ['required', 'size:3'],
|
|
36
|
+
'base_fee' => ['numeric'],
|
|
37
|
+
'per_meter_unit' => ['required_if:rate_calculation_method,per_meter', 'string', 'in:km,m'],
|
|
38
|
+
'per_meter_flat_rate_fee' => ['required_if:rate_calculation_method,per_meter', 'numeric'],
|
|
39
|
+
'meter_fees' => ['required_if:rate_calculation_method,fixed_meter', 'array'],
|
|
40
|
+
'meter_fees.*.distance' => ['numeric'],
|
|
41
|
+
'meter_fees.*.fee' => ['numeric'],
|
|
42
|
+
'algorithm' => ['required_if:rate_calculation_method,algo', new ComputableAlgo(), 'string'],
|
|
43
|
+
'has_cod_fee' => ['boolean'],
|
|
43
44
|
'cod_calculation_method' => [Rule::requiredIf(Utils::isTrue($this->input(['has_cod_fee']))), 'in:percentage,flat'],
|
|
44
|
-
'cod_flat_fee' => [Rule::requiredIf($this->input(
|
|
45
|
-
'cod_percent' => [Rule::requiredIf($this->input(
|
|
46
|
-
'has_peak_hours_fee' => 'boolean',
|
|
47
|
-
'peak_hours_calculation_method' => [Rule::requiredIf(Utils::isTrue($this->input(
|
|
48
|
-
'peak_hours_flat_fee' => [Rule::requiredIf($this->input(
|
|
49
|
-
'peak_hours_percent' => [Rule::requiredIf($this->input(
|
|
50
|
-
'peak_hours_start' => [Rule::requiredIf(Utils::isTrue($this->input(
|
|
51
|
-
'peak_hours_end' => [Rule::requiredIf(Utils::isTrue($this->input(
|
|
52
|
-
'duration_terms' => 'string',
|
|
53
|
-
'estimated_days' => '
|
|
45
|
+
'cod_flat_fee' => [Rule::requiredIf($this->input('cod_calculation_method') === 'flat'), 'numeric'],
|
|
46
|
+
'cod_percent' => [Rule::requiredIf($this->input('cod_calculation_method') === 'percentage'), 'integer'],
|
|
47
|
+
'has_peak_hours_fee' => ['boolean'],
|
|
48
|
+
'peak_hours_calculation_method' => [Rule::requiredIf(Utils::isTrue($this->input('has_peak_hours'))), 'in:percentage,flat'],
|
|
49
|
+
'peak_hours_flat_fee' => [Rule::requiredIf($this->input('peak_hours_calculation_method') === 'flat'), 'numeric'],
|
|
50
|
+
'peak_hours_percent' => [Rule::requiredIf($this->input('peak_hours_calculation_method') === 'percentage'), 'integer'],
|
|
51
|
+
'peak_hours_start' => [Rule::requiredIf(Utils::isTrue($this->input('has_peak_hours'))), 'date_format:H:i'],
|
|
52
|
+
'peak_hours_end' => [Rule::requiredIf(Utils::isTrue($this->input('has_peak_hours'))), 'date_format:H:i'],
|
|
53
|
+
'duration_terms' => ['string'],
|
|
54
|
+
'estimated_days' => ['integer'],
|
|
54
55
|
];
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -30,14 +30,15 @@ class CreateTrackingStatusRequest extends FleetbaseRequest
|
|
|
30
30
|
{
|
|
31
31
|
$validations = [
|
|
32
32
|
'tracking_number' => array_filter([
|
|
33
|
-
'
|
|
33
|
+
Rule::requiredIf($this->isMethod('POST')),
|
|
34
34
|
$this->isMethod('POST') ? Rule::exists('tracking_numbers', 'public_id') : null,
|
|
35
35
|
$this->isMethod('POST') ? static::uniqueStatus($this) : null,
|
|
36
36
|
]),
|
|
37
|
-
'location' => [new ResolvablePoint()],
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
37
|
+
'location' => [Rule::requiredIf($this->isMethod('POST')), new ResolvablePoint()],
|
|
38
|
+
'country' => ['nullable', 'string', 'size:2'],
|
|
39
|
+
'code' => [Rule::requiredIf($this->isMethod('POST')), 'string', 'min:3'],
|
|
40
|
+
'status' => [Rule::requiredIf($this->isMethod('POST')), 'string', 'min:3'],
|
|
41
|
+
'details' => [Rule::requiredIf($this->isMethod('POST')), 'string', 'min:3'],
|
|
41
42
|
];
|
|
42
43
|
|
|
43
44
|
if ($this->isMethod('POST') && $this->missing('tracking_number') && $this->has('order')) {
|
|
@@ -50,10 +51,10 @@ class CreateTrackingStatusRequest extends FleetbaseRequest
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
if ($this->missing(['latitude', 'longitude'])) {
|
|
53
|
-
$validations['location'] = ['
|
|
54
|
+
$validations['location'] = [Rule::requiredIf($this->isMethod('POST')), new ResolvablePoint()];
|
|
54
55
|
} elseif ($this->missing('location')) {
|
|
55
|
-
$validations['latitude'] = '
|
|
56
|
-
$validations['longitude'] = '
|
|
56
|
+
$validations['latitude'] = [Rule::requiredIf($this->isMethod('POST'))];
|
|
57
|
+
$validations['longitude'] = [Rule::requiredIf($this->isMethod('POST'))];
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
return $validations;
|
|
@@ -25,10 +25,12 @@ class CreateVehicleRequest extends FleetbaseRequest
|
|
|
25
25
|
public function rules()
|
|
26
26
|
{
|
|
27
27
|
return [
|
|
28
|
-
'status'
|
|
29
|
-
'vendor'
|
|
30
|
-
'driver'
|
|
31
|
-
'location'
|
|
28
|
+
'status' => 'nullable|in:operational,maintenance,decommissioned',
|
|
29
|
+
'vendor' => 'nullable|exists:vendors,public_id',
|
|
30
|
+
'driver' => 'nullable|exists:drivers,public_id',
|
|
31
|
+
'location' => ['nullable', new ResolvablePoint()],
|
|
32
|
+
'latitude' => ['nullable', 'required_with:longitude'],
|
|
33
|
+
'longitude' => ['nullable', 'required_with:latitude'],
|
|
32
34
|
];
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\FleetOps\Http\Requests;
|
|
4
4
|
|
|
5
|
+
use Fleetbase\FleetOps\Rules\ResolvablePoint;
|
|
5
6
|
use Fleetbase\Http\Requests\FleetbaseRequest;
|
|
6
7
|
use Illuminate\Validation\Rule;
|
|
7
8
|
|
|
@@ -25,11 +26,29 @@ class CreateZoneRequest extends FleetbaseRequest
|
|
|
25
26
|
public function rules()
|
|
26
27
|
{
|
|
27
28
|
return [
|
|
28
|
-
'name'
|
|
29
|
-
|
|
30
|
-
'
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
'name' => [Rule::requiredIf($this->isMethod('POST')), 'string'],
|
|
30
|
+
'service_area' => [Rule::requiredIf($this->isMethod('POST')), 'exists:service_areas,public_id'],
|
|
31
|
+
'border' => ['nullable', Rule::requiredIf(function () {
|
|
32
|
+
$isCreating = $this->isMethod('POST');
|
|
33
|
+
$hasCoordiantes = $this->filled('latitude') && $this->filled('longitude');
|
|
34
|
+
$hasLocation = $this->filled('location');
|
|
35
|
+
|
|
36
|
+
// if creating then it's required
|
|
37
|
+
if ($isCreating) {
|
|
38
|
+
// if either has coordinated or location then it's not required
|
|
39
|
+
if ($hasCoordiantes || $hasLocation) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
})],
|
|
48
|
+
'location' => ['nullable', new ResolvablePoint()],
|
|
49
|
+
'latitude' => ['nullable', 'required_with:longitude'],
|
|
50
|
+
'longitude' => ['nullable', 'required_with:latitude'],
|
|
51
|
+
'status' => ['nullable', 'in:active,inactive'],
|
|
33
52
|
];
|
|
34
53
|
}
|
|
35
54
|
}
|