diff --git a/composer.json b/composer.json index cde0d9f2..723932ad 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/fleetops-api", - "version": "0.4.21", + "version": "0.4.22", "description": "Fleet & Transport Management Extension for Fleetbase", "keywords": [ "fleetbase-extension", diff --git a/extension.json b/extension.json index 4f9734d3..b0204c29 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "Fleet-Ops", - "version": "0.4.21", + "version": "0.4.22", "description": "Fleet & Transport Management Extension for Fleetbase", "repository": "https://github.com/fleetbase/fleetops", "license": "MIT", diff --git a/package.json b/package.json index 044c0c1e..1bbc27f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/fleetops-engine", - "version": "0.4.21", + "version": "0.4.22", "description": "Fleet & Transport Management Extension for Fleetbase", "fleetbase": { "route": "fleet-ops" diff --git a/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php b/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php index 05557a16..3289db9c 100644 --- a/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php +++ b/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php @@ -36,6 +36,7 @@ public function handle() ['model' => \Fleetbase\FleetOps\Models\Order::class, 'columns' => ['customer_type', 'facilitator_type']], ['model' => \Fleetbase\FleetOps\Models\Place::class, 'columns' => ['owner_type']], ['model' => \Fleetbase\FleetOps\Models\Entity::class, 'columns' => ['customer_type']], + ['model' => \Fleetbase\FleetOps\Models\PurchaseRate::class, 'columns' => ['customer_type']], ]; foreach ($models as $modelConfig) { diff --git a/server/src/Console/Commands/TrackOrderDistanceAndTime.php b/server/src/Console/Commands/TrackOrderDistanceAndTime.php index 2212baf0..c6523033 100644 --- a/server/src/Console/Commands/TrackOrderDistanceAndTime.php +++ b/server/src/Console/Commands/TrackOrderDistanceAndTime.php @@ -33,7 +33,10 @@ public function handle() date_default_timezone_set('UTC'); // Determine the provider - $provider = $this->option('provider') ?? config('fleetops.distance_matrix.provider'); + $provider = $this->option('provider'); + if (!$provider) { + $provider = config('fleetops.distance_matrix.provider'); + } $this->info("Using '{$provider}' as the provider for calculations."); // Get all active/ready orders @@ -60,15 +63,30 @@ public function handle() } /** - * Fetches active orders. + * Retrieves active orders that meet specific criteria. + * + * This method returns a collection of active orders with the following conditions: + * - Not in 'completed' or 'canceled' status. + * - Not marked as deleted (`deleted_at` is null). + * - Associated with a company (`company_uuid` is not null). + * - The order process has started (`started` is not null). + * - Contains a payload (`payload` relationship exists). + * - Created within the past month. * - * @return \Illuminate\Database\Eloquent\Collection + * The result includes related payload data, waypoints, and information about pickup and dropoff points. + * Global scopes are not applied to this query. + * + * @return \Illuminate\Database\Eloquent\Collection collection of relevant Order objects */ protected function getActiveOrders() { + $oneMonthAgo = Carbon::now()->subMonth(); + return Order::whereNotIn('status', ['completed', 'canceled']) ->whereNull('deleted_at') ->whereNotNull('company_uuid') + ->whereNotNull('started') + ->where('created_at', '>=', $oneMonthAgo) ->whereHas('payload') ->with(['payload', 'payload.waypoints', 'payload.pickup', 'payload.dropoff']) ->withoutGlobalScopes() diff --git a/server/src/Models/Place.php b/server/src/Models/Place.php index 93660e20..e2b56b9c 100644 --- a/server/src/Models/Place.php +++ b/server/src/Models/Place.php @@ -3,6 +3,7 @@ namespace Fleetbase\FleetOps\Models; use Fleetbase\Casts\Json; +use Fleetbase\Casts\PolymorphicType; use Fleetbase\FleetOps\Casts\Point; use Fleetbase\FleetOps\Support\Geocoding; use Fleetbase\FleetOps\Support\Utils; @@ -114,8 +115,9 @@ class Place extends Model * @var array */ protected $casts = [ - 'meta' => Json::class, - 'location' => Point::class, + 'meta' => Json::class, + 'location' => Point::class, + 'owner_type' => PolymorphicType::class, ]; /** diff --git a/server/src/Models/PurchaseRate.php b/server/src/Models/PurchaseRate.php index bbfc38f1..6caf7ba3 100644 --- a/server/src/Models/PurchaseRate.php +++ b/server/src/Models/PurchaseRate.php @@ -3,6 +3,7 @@ namespace Fleetbase\FleetOps\Models; use Fleetbase\Casts\Json; +use Fleetbase\Casts\PolymorphicType; use Fleetbase\FleetOps\Support\Utils; use Fleetbase\Models\Model; use Fleetbase\Traits\HasApiModelBehavior; @@ -57,7 +58,8 @@ class PurchaseRate extends Model * @var array */ protected $casts = [ - 'meta' => Json::class, + 'meta' => Json::class, + 'customer_type' => PolymorphicType::class, ]; /**