Files
core/src/Shipping/Filament/Resources/ManifestResource.php
T

80 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace Modules\Core\Shipping\Filament\Resources;
use Filament\Actions\ViewAction;
use Filament\Resources\Resource;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Lunar\Shipping\Facades\Shipping;
use Modules\Core\Shipping\Contracts\SupportsManifestBatching;
use Modules\Core\Shipping\Filament\Resources\ManifestResource\Pages\ListManifests;
use Modules\Core\Shipping\Filament\Resources\ManifestResource\Pages\ViewManifest;
use Modules\Core\Shipping\Filament\Resources\ManifestResource\RelationManagers\ShipmentsRelationManager;
use Modules\Core\Shipping\Models\Manifest;
/**
* Issued manifests — Modules\Core\Shipping\Models\Manifest is the only
* record of "which shipments were on manifest X, and when" this codebase
* keeps; ACS's own ACS_Issue_Pickup_List call returns nothing beyond a
* reference number, so there is nothing to re-fetch from the carrier
* later (see that model's own docblock). Complements
* Modules\Core\Shipping\Filament\Resources\ShipmentResource, which only
* ever shows shipments NOT YET on a manifest.
*/
class ManifestResource extends Resource
{
protected static ?string $model = Manifest::class;
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-clipboard-document-list';
protected static string | \UnitEnum | null $navigationGroup = 'Sales';
protected static ?string $navigationLabel = 'Issued Manifests';
/**
* Only carriers that batch into manifests (ACS) produce any — with none
* registered the menu entry would lead to an empty screen, so it's
* hidden (the page itself, and any past manifests, stay reachable).
*/
public static function shouldRegisterNavigation(): bool
{
return collect(Shipping::getSupportedDrivers())->keys()
->contains(fn (string $carrier) => ShipmentResource::fulfillmentService($carrier) instanceof SupportsManifestBatching);
}
protected static ?string $modelLabel = 'Manifest';
protected static ?int $navigationSort = 101;
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('carrier')->badge(),
TextColumn::make('reference')->label('Reference')->copyable(),
TextColumn::make('shipment_count')->label('Shipments'),
TextColumn::make('issued_at')->label('Issued')->dateTime(),
])
->recordActions([
ViewAction::make(),
])
->defaultSort('issued_at', 'desc');
}
public static function getRelations(): array
{
return [
ShipmentsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => ListManifests::route('/'),
'view' => ViewManifest::route('/{record}'),
];
}
}