Files

58 lines
2.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Resources\PreventivoResource\RelationManagers;
use App\Support\ConfigurazioneFormatter;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
class ItemsRelationManager extends RelationManager
{
protected static string $relationship = 'items';
protected static ?string $title = 'Prodotti configurati';
protected static ?string $modelLabel = 'prodotto';
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('nome_modello')
->columns([
Tables\Columns\ImageColumn::make('immagine_path')
->label('Anteprima')
->disk('public')
->height(60)
->square(),
Tables\Columns\TextColumn::make('nome_modello')
->label('Modello')
->description(fn (Model $record) => trim(($record->sistema ? ucfirst($record->sistema) : '').' '.($record->type ?? ''))),
Tables\Columns\TextColumn::make('dimensioni')
->label('Dimensioni')
->state(fn (Model $record) => $record->larghezza && $record->altezza
? "{$record->larghezza} × {$record->altezza} cm" : '—'),
Tables\Columns\TextColumn::make('quantita')->label('Q.tà'),
Tables\Columns\TextColumn::make('prezzo_unitario')->label('Prezzo un.')->money('EUR'),
Tables\Columns\TextColumn::make('prezzo_totale')->label('Totale')->money('EUR'),
])
->actions([
Tables\Actions\ViewAction::make()
->infolist(fn ($infolist) => $infolist->schema([
\Filament\Infolists\Components\ImageEntry::make('immagine_path')
->label('Anteprima')
->disk('public')
->height(220),
\Filament\Infolists\Components\KeyValueEntry::make('configurazione_display')
->label('Configurazione selezionata')
->state(fn (Model $record) => collect(ConfigurazioneFormatter::toRows($record->payload))
->mapWithKeys(fn ($row) => [$row['label'] => $row['value']])
->all())
->columnSpanFull(),
])),
])
->paginated(false);
}
}