- Implemented session storage management for the last configuration choices made by the user. - Added functionality to prompt users when changing models to retain their previous selections. - Introduced methods to apply previous choices to the newly loaded model, including finishes, handles, glass types, and options. - Enhanced user experience by ensuring selections are automatically applied where applicable.
127 lines
5.3 KiB
PHP
127 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\VetroResource\Pages;
|
|
use App\Filament\Support\CampiConfiguratore;
|
|
use App\Models\Vetro;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Forms\Get;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Validation\Rules\Unique;
|
|
|
|
class VetroResource extends Resource
|
|
{
|
|
protected static ?string $model = Vetro::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-square-2-stack';
|
|
|
|
protected static ?string $slug = 'vetri';
|
|
|
|
protected static ?string $navigationGroup = 'Configuratore';
|
|
|
|
protected static ?string $navigationLabel = 'Vetri e riempimenti';
|
|
|
|
protected static ?string $modelLabel = 'vetro';
|
|
|
|
protected static ?string $pluralModelLabel = 'vetri';
|
|
|
|
protected static ?int $navigationSort = 21;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Forms\Components\Section::make()
|
|
->columns(2)
|
|
->schema([
|
|
CampiConfiguratore::sistema(),
|
|
Forms\Components\TextInput::make('codice')
|
|
->label('Codice')
|
|
->helperText('Identificativo inviato dal configuratore (es. V3).')
|
|
->required()
|
|
->maxLength(50)
|
|
->unique(
|
|
ignoreRecord: true,
|
|
modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('sistema_id', $get('sistema_id')),
|
|
),
|
|
Forms\Components\TextInput::make('descrizione')->label('Descrizione')->required()->maxLength(255)->columnSpanFull(),
|
|
Forms\Components\Toggle::make('predefinito')->label('Predefinito')->helperText('Selezionato all\'apertura del configuratore.')->inline(false),
|
|
Forms\Components\Toggle::make('attivo')->label('Attivo')->default(true)->inline(false),
|
|
]),
|
|
Forms\Components\Section::make('Prezzo')
|
|
->description('Variazione = somma per lastra di max(area, minimo fatturabile) x maggiorazione. Le lastre sono calcolate dalla regola vetro del modello.')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\TextInput::make('maggiorazione_mq')
|
|
->label('Maggiorazione')
|
|
->helperText('Negativa per una decurtazione (es. infisso senza vetro).')
|
|
->numeric()
|
|
->step(0.01)
|
|
->prefix('€')
|
|
->suffix('/m²')
|
|
->default(0)
|
|
->required(),
|
|
Forms\Components\TextInput::make('minimo_mq')
|
|
->label('Minimo fatturabile per lastra')
|
|
->numeric()
|
|
->minValue(0)
|
|
->step(0.001)
|
|
->suffix('m²')
|
|
->default(0)
|
|
->required(),
|
|
]),
|
|
Forms\Components\Section::make('Immagini')
|
|
->columns(2)
|
|
->schema([
|
|
CampiConfiguratore::immagine('anteprima', 'Icona nel menu', 'vetri'),
|
|
CampiConfiguratore::immagine('popup', 'Immagine informativa (popup)', 'vetri'),
|
|
]),
|
|
CampiConfiguratore::aspetto3d('vetri', opacita: true),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('ordine')
|
|
->reorderable('ordine')
|
|
->columns([
|
|
Tables\Columns\ImageColumn::make('anteprima')->label('Icona')->disk('public')->height(40),
|
|
Tables\Columns\TextColumn::make('codice')->label('Codice')->searchable(),
|
|
Tables\Columns\TextColumn::make('descrizione')->label('Descrizione')->searchable()->wrap(),
|
|
Tables\Columns\TextColumn::make('maggiorazione_mq')
|
|
->label('Maggiorazione')
|
|
->formatStateUsing(fn ($state) => '€ '.number_format((float) $state, 2, ',', '.').'/m²')
|
|
->color(fn ($state) => $state < 0 ? 'danger' : null)
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('minimo_mq')
|
|
->label('Minimo')
|
|
->formatStateUsing(fn ($state) => number_format((float) $state, 2, ',', '.').' m²'),
|
|
Tables\Columns\IconColumn::make('predefinito')->label('Predefinito')->boolean(),
|
|
Tables\Columns\ToggleColumn::make('attivo')->label('Attivo'),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('sistema')->label('Sistema')->relationship('sistema', 'nome'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make()->iconButton(),
|
|
Tables\Actions\DeleteAction::make()->iconButton(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ManageVetri::route('/'),
|
|
];
|
|
}
|
|
}
|