94938f24d7
Schema: - tire_sets (client/vehicle, season, size width/profile/diameter, brand/DOT, rims, tread JSON per position + tread_min cache, TPMS + sensor ids, photos) - tire_storage (location, season_label, stored/retrieved, check-in/out, fee) Models: - TireSet (HasMedia): sizeLabel, isStored, currentStorage, auto tread_min - TireStorage: durationDays, isActive Filament (new "Anvelope" nav group): - TireSetResource: specs form + per-position tread + TPMS + photo upload; table with size, season badge, min tread (red < 3mm), storage status - Check-in (location + period + fee → stored) / Check-out (→ retrieved) - StorageRelationManager (stay history); nav badge = sets currently stored Tests (6 new): - sizeLabel formatting; tread_min from positions; check-in active storage; check-out retrieved + duration; multiple stays per set; tenant isolation Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
197 lines
9.5 KiB
PHP
197 lines
9.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources;
|
|
|
|
use App\Filament\Tenant\Resources\TireSetResource\Pages;
|
|
use App\Filament\Tenant\Resources\TireSetResource\RelationManagers;
|
|
use App\Models\Tenant\Client;
|
|
use App\Models\Tenant\TireSet;
|
|
use App\Models\Tenant\Vehicle;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class TireSetResource extends Resource
|
|
{
|
|
protected static ?string $model = TireSet::class;
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-lifebuoy';
|
|
|
|
protected static ?string $navigationLabel = 'Seturi anvelope';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Anvelope';
|
|
|
|
protected static ?string $modelLabel = 'set anvelope';
|
|
|
|
protected static ?string $pluralModelLabel = 'seturi anvelope';
|
|
|
|
protected static ?int $navigationSort = 60;
|
|
|
|
public static function getNavigationBadge(): ?string
|
|
{
|
|
$stored = \App\Models\Tenant\TireStorage::where('status', 'stored')->count();
|
|
return $stored > 0 ? (string) $stored : null;
|
|
}
|
|
|
|
public static function getNavigationBadgeColor(): ?string
|
|
{
|
|
return 'info';
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Schemas\Components\Section::make('Proprietar')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\Select::make('client_id')
|
|
->label('Client')
|
|
->options(fn () => Client::pluck('name', 'id'))
|
|
->searchable()
|
|
->live()
|
|
->required(),
|
|
Forms\Components\Select::make('vehicle_id')
|
|
->label('Auto')
|
|
->options(fn (Get $get) => $get('client_id')
|
|
? Vehicle::where('client_id', $get('client_id'))->get()
|
|
->mapWithKeys(fn ($v) => [$v->id => "{$v->make} {$v->model} {$v->plate}"])->toArray()
|
|
: [])
|
|
->searchable(),
|
|
Forms\Components\TextInput::make('label')->label('Etichetă')->placeholder('ex: Iarnă Michelin'),
|
|
Forms\Components\Select::make('season')->label('Sezon')->options(TireSet::SEASONS)->default('winter')->required(),
|
|
]),
|
|
Schemas\Components\Section::make('Specificații')
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\TextInput::make('width')->label('Lățime')->numeric()->placeholder('205'),
|
|
Forms\Components\TextInput::make('profile')->label('Profil')->numeric()->placeholder('55'),
|
|
Forms\Components\TextInput::make('diameter')->label('Diametru R')->numeric()->placeholder('16'),
|
|
Forms\Components\TextInput::make('brand')->maxLength(64),
|
|
Forms\Components\TextInput::make('model')->maxLength(64),
|
|
Forms\Components\TextInput::make('dot_year')->label('DOT')->maxLength(8)->placeholder('3621'),
|
|
Forms\Components\Toggle::make('has_rims')->label('Cu jante'),
|
|
Forms\Components\Select::make('rim_type')->label('Tip jante')->options(['steel' => 'Tablă', 'alloy' => 'Aliaj']),
|
|
Forms\Components\Select::make('condition')->label('Stare')->options(TireSet::CONDITIONS),
|
|
]),
|
|
Schemas\Components\Section::make('Uzură (mm) per poziție')
|
|
->columns(4)
|
|
->schema([
|
|
Forms\Components\TextInput::make('tread.fl')->label('Față-Stânga')->numeric(),
|
|
Forms\Components\TextInput::make('tread.fr')->label('Față-Dreapta')->numeric(),
|
|
Forms\Components\TextInput::make('tread.rl')->label('Spate-Stânga')->numeric(),
|
|
Forms\Components\TextInput::make('tread.rr')->label('Spate-Dreapta')->numeric(),
|
|
]),
|
|
Schemas\Components\Section::make('TPMS & foto')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\Toggle::make('tpms')->label('Senzori TPMS'),
|
|
Forms\Components\TextInput::make('notes')->label('Observații'),
|
|
\Filament\Forms\Components\SpatieMediaLibraryFileUpload::make('photos')
|
|
->label('Fotografii')
|
|
->collection('photos')
|
|
->multiple()
|
|
->image()
|
|
->maxFiles(8)
|
|
->columnSpanFull(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('client.name')->label('Client')->searchable()->sortable(),
|
|
Tables\Columns\TextColumn::make('label')->label('Etichetă')->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('size')
|
|
->label('Dimensiune')
|
|
->state(fn (TireSet $r) => $r->sizeLabel()),
|
|
Tables\Columns\TextColumn::make('season')
|
|
->label('Sezon')
|
|
->formatStateUsing(fn ($s) => TireSet::SEASONS[$s] ?? $s)
|
|
->badge()
|
|
->colors(['warning' => ['summer'], 'info' => ['winter'], 'gray' => ['allseason']]),
|
|
Tables\Columns\TextColumn::make('tread_min')->label('Uzură min')
|
|
->formatStateUsing(fn ($s) => $s ? $s . ' mm' : '—')
|
|
->color(fn ($s) => $s !== null && (float) $s < 3 ? 'danger' : null)
|
|
->alignRight(),
|
|
Tables\Columns\IconColumn::make('tpms')->label('TPMS')->boolean()->toggleable(),
|
|
Tables\Columns\TextColumn::make('storage_status')
|
|
->label('Depozit')
|
|
->state(fn (TireSet $r) => $r->isStored() ? ($r->currentStorage()?->location ?? 'da') : '—')
|
|
->badge()
|
|
->color(fn ($state) => $state === '—' ? 'gray' : 'success'),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('season')->options(TireSet::SEASONS),
|
|
Tables\Filters\Filter::make('stored')
|
|
->label('În depozit')
|
|
->query(fn ($q) => $q->whereHas('storage', fn ($s) => $s->where('status', 'stored'))),
|
|
])
|
|
->actions([
|
|
Actions\Action::make('check_in')
|
|
->label('Check-in depozit')
|
|
->icon('heroicon-m-arrow-down-on-square')
|
|
->color('success')
|
|
->visible(fn (TireSet $r) => ! $r->isStored())
|
|
->schema([
|
|
Forms\Components\TextInput::make('location')->label('Locație (raft)')->required()->placeholder('A1-03'),
|
|
Forms\Components\TextInput::make('season_label')->label('Perioadă')->placeholder('Iarnă 2025-2026'),
|
|
Forms\Components\TextInput::make('fee')->label('Taxă depozitare')->numeric()->default(0),
|
|
])
|
|
->action(function (TireSet $r, array $data) {
|
|
\App\Models\Tenant\TireStorage::create([
|
|
'tire_set_id' => $r->id,
|
|
'location' => $data['location'],
|
|
'season_label' => $data['season_label'] ?? null,
|
|
'fee' => (float) ($data['fee'] ?? 0),
|
|
'status' => 'stored',
|
|
'checked_in_at' => now(),
|
|
]);
|
|
\Filament\Notifications\Notification::make()->title('Set primit în depozit')->success()->send();
|
|
}),
|
|
Actions\Action::make('check_out')
|
|
->label('Eliberează')
|
|
->icon('heroicon-m-arrow-up-on-square')
|
|
->color('warning')
|
|
->visible(fn (TireSet $r) => $r->isStored())
|
|
->requiresConfirmation()
|
|
->modalDescription('Marchează setul ca ridicat de client.')
|
|
->action(function (TireSet $r) {
|
|
$storage = $r->currentStorage();
|
|
if ($storage) {
|
|
$storage->update(['status' => 'retrieved', 'checked_out_at' => now()]);
|
|
}
|
|
\Filament\Notifications\Notification::make()->title('Set eliberat din depozit')->success()->send();
|
|
}),
|
|
Actions\EditAction::make(),
|
|
Actions\DeleteAction::make(),
|
|
])
|
|
->emptyStateHeading('Niciun set de anvelope')
|
|
->emptyStateDescription('Înregistrează seturile de anvelope ale clienților și gestionează depozitarea sezonieră (tire hotel). Urmărește uzura, TPMS și locația în depozit.')
|
|
->emptyStateIcon('heroicon-o-lifebuoy')
|
|
->defaultSort('created_at', 'desc');
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\StorageRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListTireSets::route('/'),
|
|
'create' => Pages\CreateTireSet::route('/create'),
|
|
'edit' => Pages\EditTireSet::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|