@fleetbase/fleetops-engine 0.4.19 → 0.4.21
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 +1 -1
- package/addon/components/activity-form-panel.js +2 -2
- package/addon/components/activity-logic-builder.js +1 -1
- package/addon/components/admin/navigator-app.hbs +77 -1
- package/addon/components/admin/navigator-app.js +65 -12
- package/addon/components/contact-form-panel.js +2 -2
- package/addon/components/contact-panel.js +2 -2
- package/addon/components/custom-field-form-panel.js +2 -2
- package/addon/components/driver-form-panel.js +2 -2
- package/addon/components/driver-panel.js +2 -2
- package/addon/components/edit-order-route-panel.js +2 -2
- package/addon/components/fleet-form-panel.js +2 -2
- package/addon/components/fleet-panel/driver-listing.js +1 -1
- package/addon/components/fleet-panel/vehicle-listing.js +1 -1
- package/addon/components/fleet-panel.js +2 -2
- package/addon/components/fuel-report-form-panel.js +2 -2
- package/addon/components/fuel-report-panel.js +2 -2
- package/addon/components/issue-form-panel.js +2 -2
- package/addon/components/issue-panel.js +2 -2
- package/addon/components/live-map-drawer.js +2 -2
- 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-overlay.js +1 -1
- package/addon/components/order-config-manager.js +2 -2
- package/addon/components/place-form-panel.js +2 -2
- package/addon/components/place-panel.js +2 -2
- package/addon/components/vehicle-form-panel.js +2 -2
- package/addon/components/vehicle-panel.js +2 -2
- package/addon/components/vendor-form-panel/create-form.js +1 -1
- package/addon/components/vendor-form-panel.js +2 -2
- package/addon/components/vendor-panel.js +2 -2
- package/composer.json +2 -2
- package/extension.json +1 -1
- package/package.json +2 -2
- package/server/config/fleetops.php +19 -0
- package/server/src/Console/Commands/DispatchAdhocOrders.php +44 -30
- package/server/src/Console/Commands/DispatchOrders.php +27 -21
- package/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php +96 -0
- package/server/src/Console/Commands/TrackOrderDistanceAndTime.php +30 -15
- package/server/src/Http/Controllers/Api/v1/DriverController.php +0 -1
- package/server/src/Http/Controllers/Api/v1/OrderController.php +49 -2
- package/server/src/Http/Controllers/Internal/v1/SettingController.php +20 -0
- package/server/src/Http/Filter/ContactFilter.php +5 -0
- package/server/src/Http/Filter/DriverFilter.php +5 -0
- package/server/src/Http/Filter/EntityFilter.php +18 -0
- package/server/src/Http/Filter/FleetFilter.php +5 -0
- package/server/src/Http/Filter/FuelReportFilter.php +5 -0
- package/server/src/Http/Filter/IssueFilter.php +5 -0
- package/server/src/Http/Filter/OrderConfigFilter.php +5 -0
- package/server/src/Http/Filter/OrderFilter.php +5 -0
- package/server/src/Http/Filter/PayloadFilter.php +18 -0
- package/server/src/Http/Filter/PlaceFilter.php +5 -0
- package/server/src/Http/Filter/PurchaseRateFilter.php +18 -0
- package/server/src/Http/Filter/ServiceAreaFilter.php +5 -0
- package/server/src/Http/Filter/ServiceQuoteFilter.php +5 -0
- package/server/src/Http/Filter/ServiceRateFilter.php +5 -0
- package/server/src/Http/Filter/TrackingNumberFilter.php +18 -0
- package/server/src/Http/Filter/TrackingStatusFilter.php +5 -0
- package/server/src/Http/Filter/VehicleFilter.php +5 -0
- package/server/src/Http/Filter/VendorFilter.php +5 -0
- package/server/src/Http/Filter/ZoneFilter.php +5 -0
- package/server/src/Http/Resources/v1/Order.php +1 -0
- package/server/src/Models/Driver.php +1 -1
- package/server/src/Models/Order.php +2 -4
- package/server/src/Providers/FleetOpsServiceProvider.php +4 -3
- package/server/src/Support/Algo.php +0 -24
- package/server/src/Support/DistanceMatrix.php +9 -1
- package/server/src/Support/OSRM.php +7 -0
- package/server/src/Support/Utils.php +216 -169
- package/server/src/routes.php +3 -3
- package/translations/en-us.yaml +3 -0
- package/addon/utils/apply-context-component-arguments.js +0 -33
- package/addon/utils/context-component-callback.js +0 -16
- package/app/utils/apply-context-component-arguments.js +0 -1
- package/app/utils/context-component-callback.js +0 -1
|
@@ -7,6 +7,7 @@ use Fleetbase\FleetOps\Models\Order;
|
|
|
7
7
|
use Fleetbase\FleetOps\Support\Utils;
|
|
8
8
|
use Fleetbase\LaravelMysqlSpatial\Types\Point;
|
|
9
9
|
use Illuminate\Console\Command;
|
|
10
|
+
use Illuminate\Database\Eloquent\Collection;
|
|
10
11
|
use Illuminate\Support\Carbon;
|
|
11
12
|
|
|
12
13
|
class DispatchAdhocOrders extends Command
|
|
@@ -28,52 +29,56 @@ class DispatchAdhocOrders extends Command
|
|
|
28
29
|
/**
|
|
29
30
|
* Execute the console command.
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @return int
|
|
32
|
+
* Processes and dispatches ad-hoc orders based on their scheduled dispatch time and driver availability.
|
|
33
|
+
* Orders without an assigned driver and that have surpassed the dispatch time threshold are considered for dispatch.
|
|
34
|
+
* The command supports sandbox and testing modes for different operational environments.
|
|
36
35
|
*/
|
|
37
|
-
public function handle()
|
|
36
|
+
public function handle(): void
|
|
38
37
|
{
|
|
39
|
-
// Set UTC as default timezone
|
|
40
38
|
date_default_timezone_set('UTC');
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
$sandboxMode = Utils::castBoolean($this->option('sandbox'));
|
|
41
|
+
$this->info('Running in ' . ($sandboxMode ? 'sandbox' : 'production') . ' mode.');
|
|
42
|
+
|
|
43
43
|
$orders = $this->getDispatchableOrders();
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
$this->alert('Found (' . $orders->count() . ') Orders to be Dispatched -- Current Time: ' . Carbon::now()->toDateTimeString());
|
|
45
|
+
$this->alert($orders->count() . ' orders found for ad-hoc dispatch. Current Time: ' . Carbon::now()->toDateTimeString());
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
$pickup = $order->getPickupLocation();
|
|
52
|
-
$distance = $order->getAdhocPingDistance();
|
|
47
|
+
foreach ($orders as $order) {
|
|
48
|
+
$pickup = $order->getPickupLocation();
|
|
49
|
+
$distance = $order->getAdhocPingDistance();
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
if (!Utils::isPoint($pickup)) {
|
|
52
|
+
$this->error('Invalid pickup location for order ' . $order->public_id);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
$drivers = $this->getNearbyDriversForOrder($order, $pickup, $distance);
|
|
56
|
+
$drivers = $this->getNearbyDriversForOrder($order, $pickup, $distance);
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
$this->alert('Found (' . $drivers->count() . ') driver within ' . $distance . ' meters of the pickup location for order ' . $order->public_id);
|
|
58
|
+
$this->line('Checking order ' . $order->public_id . ' for nearby drivers within ' . $distance . ' meters.');
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
if ($drivers->count()) {
|
|
61
|
+
$order->dispatch(true);
|
|
62
|
+
$this->info('Order ' . $order->public_id . ' dispatched successfully to ' . $drivers->count() . ' nearby drivers.');
|
|
63
|
+
foreach ($drivers as $driver) {
|
|
64
|
+
$this->info('Pinging driver ' . $driver->name . ' (' . $driver->public_id . ') ...');
|
|
68
65
|
}
|
|
66
|
+
} else {
|
|
67
|
+
$this->warn('No available drivers found for order ' . $order->public_id);
|
|
69
68
|
}
|
|
70
|
-
|
|
69
|
+
}
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
/**
|
|
74
|
-
* Fetches dispatchable orders based on certain criteria.
|
|
73
|
+
* Fetches ad-hoc dispatchable orders based on certain criteria.
|
|
74
|
+
*
|
|
75
|
+
* Retrieves orders that are marked as ad-hoc and have not been dispatched yet. The orders
|
|
76
|
+
* are filtered by their scheduled dispatch time, order status, and whether a driver has been
|
|
77
|
+
* assigned to them. The method also applies filters based on sandbox mode.
|
|
78
|
+
*
|
|
79
|
+
* @return Collection returns a collection of orders that meet the criteria
|
|
75
80
|
*/
|
|
76
|
-
public function getDispatchableOrders():
|
|
81
|
+
public function getDispatchableOrders(): Collection
|
|
77
82
|
{
|
|
78
83
|
$sandbox = Utils::castBoolean($this->option('sandbox'));
|
|
79
84
|
$interval = 4;
|
|
@@ -100,8 +105,17 @@ class DispatchAdhocOrders extends Command
|
|
|
100
105
|
|
|
101
106
|
/**
|
|
102
107
|
* Fetches nearby drivers for a given order based on the pickup location and distance.
|
|
108
|
+
*
|
|
109
|
+
* Retrieves drivers who are within a specified distance from the pickup location of the order.
|
|
110
|
+
* The method supports a testing mode to simulate driver availability.
|
|
111
|
+
*
|
|
112
|
+
* @param Order $order the order for which drivers are being sought
|
|
113
|
+
* @param Point $pickup the geographic point representing the pickup location
|
|
114
|
+
* @param int $distance the maximum distance (in meters) within which drivers should be located
|
|
115
|
+
*
|
|
116
|
+
* @return Collection returns a collection of nearby drivers
|
|
103
117
|
*/
|
|
104
|
-
public function getNearbyDriversForOrder(Order $order, Point $pickup, int $distance):
|
|
118
|
+
public function getNearbyDriversForOrder(Order $order, Point $pickup, int $distance): Collection
|
|
105
119
|
{
|
|
106
120
|
$testing = Utils::castBoolean($this->option('testing'));
|
|
107
121
|
|
|
@@ -14,7 +14,7 @@ class DispatchOrders extends Command
|
|
|
14
14
|
*
|
|
15
15
|
* @var string
|
|
16
16
|
*/
|
|
17
|
-
protected $signature = 'fleetops:dispatch-orders {--sandbox=false}';
|
|
17
|
+
protected $signature = 'fleetops:dispatch-orders {--sandbox=false : Whether to use the sandbox database for testing purposes.}';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* The console command description.
|
|
@@ -26,41 +26,47 @@ class DispatchOrders extends Command
|
|
|
26
26
|
/**
|
|
27
27
|
* Execute the console command.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
29
|
+
* Processes and dispatches orders that are scheduled for today. Orders are
|
|
30
|
+
* filtered based on their dispatch status, scheduled time, and other criteria.
|
|
31
|
+
* The command allows for a sandbox mode for testing.
|
|
30
32
|
*/
|
|
31
|
-
public function handle()
|
|
33
|
+
public function handle(): void
|
|
32
34
|
{
|
|
33
35
|
// Set UTC as default timezone
|
|
34
36
|
date_default_timezone_set('UTC');
|
|
35
37
|
|
|
38
|
+
$sandboxMode = Utils::castBoolean($this->option('sandbox'));
|
|
39
|
+
$this->info('Running in ' . ($sandboxMode ? 'sandbox' : 'production') . ' mode.');
|
|
40
|
+
|
|
36
41
|
// Get all scheduled dispatchable orders
|
|
37
|
-
$orders = $this->getScheduledOrders();
|
|
42
|
+
$orders = $this->getScheduledOrders($sandboxMode);
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
$this->alert('Found (' . $orders->count() . ') Orders Scheduled for Dispatched -- Current Time: ' . Carbon::now()->toDateTimeString());
|
|
44
|
+
$this->alert('Found ' . $orders->count() . ' orders scheduled for dispatch. Current Time: ' . Carbon::now()->toDateTimeString());
|
|
41
45
|
|
|
42
46
|
// Dispatch each order
|
|
43
|
-
$orders
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} else {
|
|
50
|
-
$this->warn('Order ' . $order->public_id . ' will be dispatched today today AT ' . $order->scheduled_at);
|
|
51
|
-
}
|
|
47
|
+
foreach ($orders as $order) {
|
|
48
|
+
if ($order->shouldDispatch()) {
|
|
49
|
+
$order->dispatch();
|
|
50
|
+
$this->info('Order ' . $order->public_id . ' dispatched successfully (' . $order->scheduled_at . ').');
|
|
51
|
+
} else {
|
|
52
|
+
$this->warn('Order ' . $order->public_id . ' is not ready for dispatch (' . $order->scheduled_at . ').');
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
}
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
|
-
* Fetches scheduled dispatchable orders
|
|
58
|
+
* Fetches scheduled dispatchable orders.
|
|
59
|
+
*
|
|
60
|
+
* Retrieves orders that are scheduled for today and have not yet been dispatched.
|
|
61
|
+
* Filters orders based on dispatch status, order status, and scheduled date.
|
|
62
|
+
*
|
|
63
|
+
* @param bool $sandboxMode whether to use the sandbox database
|
|
64
|
+
*
|
|
65
|
+
* @return \Illuminate\Database\Eloquent\Collection returns a collection of orders that meet the criteria
|
|
58
66
|
*/
|
|
59
|
-
|
|
67
|
+
protected function getScheduledOrders(bool $sandboxMode): \Illuminate\Database\Eloquent\Collection
|
|
60
68
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return Order::on($sandbox ? 'sandbox' : 'mysql')
|
|
69
|
+
return Order::on($sandboxMode ? 'sandbox' : 'mysql')
|
|
64
70
|
->withoutGlobalScopes()
|
|
65
71
|
->where('dispatched', 0)
|
|
66
72
|
->whereIn('status', ['pending', 'created'])
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Console\Commands;
|
|
4
|
+
|
|
5
|
+
use Illuminate\Console\Command;
|
|
6
|
+
use Illuminate\Support\Str;
|
|
7
|
+
|
|
8
|
+
class FixInvalidPolymorphicRelationTypeNamespaces extends Command
|
|
9
|
+
{
|
|
10
|
+
/**
|
|
11
|
+
* The name and signature of the console command.
|
|
12
|
+
*
|
|
13
|
+
* @var string
|
|
14
|
+
*/
|
|
15
|
+
protected $signature = 'fleetops:fix-invalid-polymorphic-relation-type-namespaces';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The console command description.
|
|
19
|
+
*
|
|
20
|
+
* @var string
|
|
21
|
+
*/
|
|
22
|
+
protected $description = 'Fixes invalid namespaces in polymorphic relations across multiple models';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Handle the console command execution.
|
|
26
|
+
*
|
|
27
|
+
* Iterates over a predefined list of models and their respective polymorphic columns,
|
|
28
|
+
* calling a method to fix invalid namespace references in these polymorphic relations.
|
|
29
|
+
* This allows correction across multiple models in a single command execution.
|
|
30
|
+
*
|
|
31
|
+
* @return void
|
|
32
|
+
*/
|
|
33
|
+
public function handle()
|
|
34
|
+
{
|
|
35
|
+
$models = [
|
|
36
|
+
['model' => \Fleetbase\FleetOps\Models\Order::class, 'columns' => ['customer_type', 'facilitator_type']],
|
|
37
|
+
['model' => \Fleetbase\FleetOps\Models\Place::class, 'columns' => ['owner_type']],
|
|
38
|
+
['model' => \Fleetbase\FleetOps\Models\Entity::class, 'columns' => ['customer_type']],
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
foreach ($models as $modelConfig) {
|
|
42
|
+
$this->fixModelRelations($modelConfig['model'], $modelConfig['columns']);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Fixes invalid namespace references in polymorphic relations for a specific model.
|
|
48
|
+
*
|
|
49
|
+
* Given a model class and an array of its polymorphic relation columns, this method
|
|
50
|
+
* iterates through each record of the model, correcting any invalid namespaces in
|
|
51
|
+
* these columns. It outputs information about the process, including the number of
|
|
52
|
+
* records updated. This function is designed to be reusable for different models.
|
|
53
|
+
*
|
|
54
|
+
* @param string $modelClass the class name of the model to be processed
|
|
55
|
+
* @param array $columns an array of column names that have polymorphic relations
|
|
56
|
+
*/
|
|
57
|
+
protected function fixModelRelations(string $modelClass, array $columns): void
|
|
58
|
+
{
|
|
59
|
+
$modelInstance = new $modelClass();
|
|
60
|
+
$modelName = class_basename($modelInstance);
|
|
61
|
+
|
|
62
|
+
$this->info("Processing $modelName...");
|
|
63
|
+
|
|
64
|
+
$records = $modelInstance::query();
|
|
65
|
+
foreach ($columns as $column) {
|
|
66
|
+
$records->orWhereNotNull($column);
|
|
67
|
+
}
|
|
68
|
+
$records = $records->get();
|
|
69
|
+
$updatedCount = 0;
|
|
70
|
+
$this->alert('Checking ' . $records->count() . ' ' . Str::plural($modelName, $records->count()) . ' for invalid polymorphic relation type namespaces.');
|
|
71
|
+
|
|
72
|
+
foreach ($records as $record) {
|
|
73
|
+
foreach ($columns as $column) {
|
|
74
|
+
if (isset($record->$column)) {
|
|
75
|
+
$original = $record->$column;
|
|
76
|
+
$normalizedOriginal = ltrim($original, '\\');
|
|
77
|
+
|
|
78
|
+
if (Str::startsWith($normalizedOriginal, 'Fleetbase\Models')) {
|
|
79
|
+
$newNamespace = Str::replaceFirst('Fleetbase\Models', 'Fleetbase\FleetOps\Models', $normalizedOriginal);
|
|
80
|
+
$record->$column = $newNamespace;
|
|
81
|
+
$updatedCount++;
|
|
82
|
+
|
|
83
|
+
$this->info("{$modelName} ID {$record->id}: Corrected namespace from '$original' to '$newNamespace'.");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if ($record->isDirty()) {
|
|
89
|
+
$record->save();
|
|
90
|
+
$this->info("Saved changes for $modelName ID {$record->public_id}.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
$this->info("Finished processing $modelName. Total updated records: $updatedCount.");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -13,7 +13,7 @@ class TrackOrderDistanceAndTime extends Command
|
|
|
13
13
|
*
|
|
14
14
|
* @var string
|
|
15
15
|
*/
|
|
16
|
-
protected $signature = 'fleetops:update-estimations';
|
|
16
|
+
protected $signature = 'fleetops:update-estimations {--provider : The distance and time calculation provider (calculate, google, or osrm)}';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* The console command description.
|
|
@@ -32,31 +32,46 @@ class TrackOrderDistanceAndTime extends Command
|
|
|
32
32
|
// Set UTC as default timezone
|
|
33
33
|
date_default_timezone_set('UTC');
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
$
|
|
35
|
+
// Determine the provider
|
|
36
|
+
$provider = $this->option('provider') ?? config('fleetops.distance_matrix.provider');
|
|
37
|
+
$this->info("Using '{$provider}' as the provider for calculations.");
|
|
37
38
|
|
|
38
|
-
//
|
|
39
|
-
$
|
|
39
|
+
// Get all active/ready orders
|
|
40
|
+
$orders = $this->getActiveOrders();
|
|
40
41
|
|
|
41
|
-
// Notify Current Time and # of Orders
|
|
42
|
-
$this->alert('Found
|
|
42
|
+
// Notify Current Time and # of Orders
|
|
43
|
+
$this->alert('Found ' . $orders->count() . ' orders to update tracking estimations. Current Time: ' . Carbon::now()->toDateTimeString());
|
|
43
44
|
|
|
44
45
|
// Update for each order
|
|
45
|
-
$
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
$updated = 0;
|
|
47
|
+
foreach ($orders as $order) {
|
|
48
|
+
try {
|
|
49
|
+
// Update order distance and time estimations based on the provider
|
|
50
|
+
$order->setDistanceAndTime(['provider' => $provider]);
|
|
51
|
+
$updated++;
|
|
52
|
+
$this->info("Order ID {$order->id} - Distance & Time estimations updated.");
|
|
53
|
+
} catch (\Exception $e) {
|
|
54
|
+
$this->error("Failed to update Order ID {$order->id} - Error: " . $e->getMessage());
|
|
48
55
|
}
|
|
49
|
-
|
|
56
|
+
}
|
|
50
57
|
|
|
51
|
-
//
|
|
52
|
-
$this->info(
|
|
58
|
+
// Summary info
|
|
59
|
+
$this->info("Updated $updated/" . $orders->count() . " orders' Distance & Time Estimations.");
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
/**
|
|
56
63
|
* Fetches active orders.
|
|
64
|
+
*
|
|
65
|
+
* @return \Illuminate\Database\Eloquent\Collection
|
|
57
66
|
*/
|
|
58
|
-
|
|
67
|
+
protected function getActiveOrders()
|
|
59
68
|
{
|
|
60
|
-
return Order::whereNotIn('status', ['completed', 'canceled'])
|
|
69
|
+
return Order::whereNotIn('status', ['completed', 'canceled'])
|
|
70
|
+
->whereNull('deleted_at')
|
|
71
|
+
->whereNotNull('company_uuid')
|
|
72
|
+
->whereHas('payload')
|
|
73
|
+
->with(['payload', 'payload.waypoints', 'payload.pickup', 'payload.dropoff'])
|
|
74
|
+
->withoutGlobalScopes()
|
|
75
|
+
->get();
|
|
61
76
|
}
|
|
62
77
|
}
|
|
@@ -11,7 +11,6 @@ use Fleetbase\FleetOps\Http\Resources\v1\Driver as DriverResource;
|
|
|
11
11
|
use Fleetbase\FleetOps\Jobs\SimulateDrivingRoute;
|
|
12
12
|
use Fleetbase\FleetOps\Models\Driver;
|
|
13
13
|
use Fleetbase\FleetOps\Models\Order;
|
|
14
|
-
use Fleetbase\FleetOps\Support\Flow;
|
|
15
14
|
use Fleetbase\FleetOps\Support\OSRM;
|
|
16
15
|
use Fleetbase\FleetOps\Support\Utils;
|
|
17
16
|
use Fleetbase\Http\Controllers\Controller;
|
|
@@ -25,6 +25,7 @@ use Fleetbase\FleetOps\Support\Utils;
|
|
|
25
25
|
use Fleetbase\Http\Controllers\Controller;
|
|
26
26
|
use Fleetbase\Models\Company;
|
|
27
27
|
use Fleetbase\Models\File;
|
|
28
|
+
use Fleetbase\Models\Setting;
|
|
28
29
|
use Fleetbase\Support\Auth;
|
|
29
30
|
use Illuminate\Http\Request;
|
|
30
31
|
use Illuminate\Support\Carbon;
|
|
@@ -433,8 +434,6 @@ class OrderController extends Controller
|
|
|
433
434
|
public function query(Request $request)
|
|
434
435
|
{
|
|
435
436
|
$results = Order::queryWithRequest($request, function (&$query, $request) {
|
|
436
|
-
$query->where('company_uuid', session('company'));
|
|
437
|
-
|
|
438
437
|
if ($request->has('payload')) {
|
|
439
438
|
$query->whereHas('payload', function ($q) use ($request) {
|
|
440
439
|
$q->where('public_id', $request->input('payload'));
|
|
@@ -1364,4 +1363,52 @@ class OrderController extends Controller
|
|
|
1364
1363
|
|
|
1365
1364
|
return new ProofResource($proof);
|
|
1366
1365
|
}
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* Retrieves editable fields for a specific order entity based on its configuration.
|
|
1369
|
+
*
|
|
1370
|
+
* This function looks up an order by its ID and retrieves configurable editable fields
|
|
1371
|
+
* associated with it, as defined in the settings. If the order is not found, it returns
|
|
1372
|
+
* a 404 response with an error message. Otherwise, it returns the editable fields for
|
|
1373
|
+
* the order entity.
|
|
1374
|
+
*
|
|
1375
|
+
* @param string $id the unique identifier of the order
|
|
1376
|
+
* @param Request $request the incoming request instance
|
|
1377
|
+
*
|
|
1378
|
+
* @return \Illuminate\Http\JsonResponse returns a JSON response containing either an error message
|
|
1379
|
+
* or the editable fields for the order entity
|
|
1380
|
+
*
|
|
1381
|
+
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException thrown if the order with the given ID cannot be found
|
|
1382
|
+
*/
|
|
1383
|
+
public function getEditableEntityFields(string $id, Request $request)
|
|
1384
|
+
{
|
|
1385
|
+
try {
|
|
1386
|
+
$order = Order::findRecordOrFail($id);
|
|
1387
|
+
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $exception) {
|
|
1388
|
+
return response()->json(
|
|
1389
|
+
[
|
|
1390
|
+
'error' => 'Order resource not found.',
|
|
1391
|
+
],
|
|
1392
|
+
404
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// Define settings as array
|
|
1397
|
+
$entityEditingSettings = [];
|
|
1398
|
+
|
|
1399
|
+
// get the order config id
|
|
1400
|
+
$orderConfigId = data_get($order, 'order_config_uuid');
|
|
1401
|
+
|
|
1402
|
+
// Get entity editing settings
|
|
1403
|
+
$savedEntityEditingSettings = Setting::where('key', 'fleet-ops.entity-editing-settings')->value('value');
|
|
1404
|
+
|
|
1405
|
+
if ($orderConfigId && $savedEntityEditingSettings) {
|
|
1406
|
+
$resolvedEntityEditingSettings = data_get($savedEntityEditingSettings, $orderConfigId, []);
|
|
1407
|
+
if ($resolvedEntityEditingSettings) {
|
|
1408
|
+
$entityEditingSettings = data_get($resolvedEntityEditingSettings, 'editable_entity_fields', []);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
return response()->json($entityEditingSettings);
|
|
1413
|
+
}
|
|
1367
1414
|
}
|
|
@@ -47,4 +47,24 @@ class SettingController extends Controller
|
|
|
47
47
|
|
|
48
48
|
return response()->json(['visibilitySettings' => $visibilitySettings]);
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
public function saveEntityEditingSettings(Request $request)
|
|
52
|
+
{
|
|
53
|
+
$entityEditingSettings = $request->input('entityEditingSettings', []);
|
|
54
|
+
$isEntityFieldsEditable = $request->boolean('isEntityFieldsEditable');
|
|
55
|
+
|
|
56
|
+
// Save entity editing settings
|
|
57
|
+
Setting::configure('fleet-ops.entity-editing-settings', $entityEditingSettings);
|
|
58
|
+
Setting::configure('fleet-ops.entity-fields-editable', $isEntityFieldsEditable);
|
|
59
|
+
|
|
60
|
+
return response()->json(['entityEditingSettings' => $entityEditingSettings, 'isEntityFieldsEditable' => $isEntityFieldsEditable]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public function getEntityEditingSettings()
|
|
64
|
+
{
|
|
65
|
+
$entityEditingSettings = Setting::where('key', 'fleet-ops.entity-editing-settings')->value('value');
|
|
66
|
+
$isEntityFieldsEditable = Setting::where('key', 'fleet-ops.entity-fields-editable')->value('value');
|
|
67
|
+
|
|
68
|
+
return response()->json(['entityEditingSettings' => $entityEditingSettings, 'isEntityFieldsEditable' => $isEntityFieldsEditable]);
|
|
69
|
+
}
|
|
50
70
|
}
|
|
@@ -22,6 +22,11 @@ class ContactFilter extends Filter
|
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
public function queryForPublic()
|
|
26
|
+
{
|
|
27
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
public function query(?string $searchQuery)
|
|
26
31
|
{
|
|
27
32
|
$this->builder->search($searchQuery);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Http\Filter;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Http\Filter\Filter;
|
|
6
|
+
|
|
7
|
+
class EntityFilter extends Filter
|
|
8
|
+
{
|
|
9
|
+
public function queryForInternal()
|
|
10
|
+
{
|
|
11
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public function queryForPublic()
|
|
15
|
+
{
|
|
16
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -12,6 +12,11 @@ class FleetFilter extends Filter
|
|
|
12
12
|
$this->builder->where('company_uuid', $this->session->get('company'))->with(['serviceArea', 'zone']);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
public function queryForPublic()
|
|
16
|
+
{
|
|
17
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
public function query(?string $searchQuery)
|
|
16
21
|
{
|
|
17
22
|
$this->builder->where(function ($query) use ($searchQuery) {
|
|
@@ -13,6 +13,11 @@ class FuelReportFilter extends Filter
|
|
|
13
13
|
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
public function queryForPublic()
|
|
17
|
+
{
|
|
18
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
public function query(?string $searchQuery)
|
|
17
22
|
{
|
|
18
23
|
$this->builder->search($searchQuery);
|
|
@@ -13,6 +13,11 @@ class IssueFilter extends Filter
|
|
|
13
13
|
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
public function queryForPublic()
|
|
17
|
+
{
|
|
18
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
public function query(?string $searchQuery)
|
|
17
22
|
{
|
|
18
23
|
$this->builder->search($searchQuery);
|
|
@@ -36,6 +36,11 @@ class OrderFilter extends Filter
|
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
public function queryForPublic()
|
|
40
|
+
{
|
|
41
|
+
$this->builder->where('company_uuid', $this->session->get('company'))->whereHas('trackingNumber')->whereHas('payload');
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
public function unassigned(bool $unassigned)
|
|
40
45
|
{
|
|
41
46
|
if ($unassigned) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Http\Filter;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Http\Filter\Filter;
|
|
6
|
+
|
|
7
|
+
class PayloadFilter extends Filter
|
|
8
|
+
{
|
|
9
|
+
public function queryForInternal()
|
|
10
|
+
{
|
|
11
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public function queryForPublic()
|
|
15
|
+
{
|
|
16
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -15,6 +15,11 @@ class PlaceFilter extends Filter
|
|
|
15
15
|
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
public function queryForPublic()
|
|
19
|
+
{
|
|
20
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
public function query(?string $searchQuery)
|
|
19
24
|
{
|
|
20
25
|
$this->builder->search($searchQuery);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Http\Filter;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\Http\Filter\Filter;
|
|
6
|
+
|
|
7
|
+
class PurchaseRateFilter extends Filter
|
|
8
|
+
{
|
|
9
|
+
public function queryForInternal()
|
|
10
|
+
{
|
|
11
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public function queryForPublic()
|
|
15
|
+
{
|
|
16
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -11,6 +11,11 @@ class ServiceRateFilter extends Filter
|
|
|
11
11
|
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
public function queryForPublic()
|
|
15
|
+
{
|
|
16
|
+
$this->builder->where('company_uuid', $this->session->get('company'));
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
public function serviceArea(?string $serviceArea)
|
|
15
20
|
{
|
|
16
21
|
$this->builder->whereHas(
|