141 lines
5.8 KiB
PHP
Executable File
141 lines
5.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Filament\Pages\SuperAdmin;
|
|
|
|
use App\Models\FeRitenutaPrevidenziale;
|
|
use App\Models\FeTributoF24;
|
|
use App\Models\User;
|
|
use BackedEnum;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Pages\Page;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use UnitEnum;
|
|
|
|
class CodiciTributiF24 extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static ?string $navigationLabel = 'Codici tributo (F24)';
|
|
|
|
protected static ?string $title = 'Codici tributo F24';
|
|
|
|
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-document-text';
|
|
|
|
protected static UnitEnum|string|null $navigationGroup = 'Super Admin';
|
|
|
|
protected static ?int $navigationSort = 21;
|
|
|
|
protected static ?string $slug = 'superadmin/codici-tributi-f24';
|
|
|
|
protected string $view = 'filament.pages.gescon.table';
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = Auth::user();
|
|
|
|
return $user instanceof User
|
|
&& $user->hasAnyRole(['super-admin', 'admin'])
|
|
&& Schema::hasTable('fe_tributi_f24')
|
|
&& Schema::hasTable('fe_ritenute_previdenziali');
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->mountInteractsWithTable();
|
|
}
|
|
|
|
protected function getTableQuery(): Builder
|
|
{
|
|
return FeTributoF24::query();
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->striped()
|
|
->defaultSort('codice')
|
|
->columns([
|
|
TextColumn::make('codice')->label('Codice')->searchable()->sortable(),
|
|
TextColumn::make('descrizione')->label('Descrizione')->searchable()->sortable(),
|
|
TextColumn::make('ritenuta_previdenziale_codice')->label('RT..')->toggleable(),
|
|
IconColumn::make('attivo')->label('Attivo')->boolean()->sortable(),
|
|
TextColumn::make('updated_at')->label('Aggiornato')->dateTime('d/m/Y H:i')->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->headerActions([
|
|
Action::make('create')
|
|
->label('Nuovo')
|
|
->icon('heroicon-o-plus')
|
|
->form([
|
|
TextInput::make('codice')->label('Codice')->required()->maxLength(10),
|
|
TextInput::make('descrizione')->label('Descrizione')->required()->maxLength(255),
|
|
Select::make('ritenuta_previdenziale_codice')
|
|
->label('Ritenuta previdenziale (RT..)')
|
|
->options(fn() => FeRitenutaPrevidenziale::query()
|
|
->where('attivo', true)
|
|
->orderBy('codice')
|
|
->pluck('codice', 'codice')
|
|
->all())
|
|
->searchable()
|
|
->nullable(),
|
|
Toggle::make('attivo')->label('Attivo')->default(true),
|
|
])
|
|
->action(function (array $data): void {
|
|
FeTributoF24::query()->create([
|
|
'codice' => trim((string) ($data['codice'] ?? '')),
|
|
'descrizione' => (string) ($data['descrizione'] ?? ''),
|
|
'ritenuta_previdenziale_codice' => $data['ritenuta_previdenziale_codice'] ?? null,
|
|
'attivo' => (bool) ($data['attivo'] ?? true),
|
|
]);
|
|
}),
|
|
])
|
|
->actions([
|
|
Action::make('edit')
|
|
->label('Modifica')
|
|
->icon('heroicon-o-pencil-square')
|
|
->form([
|
|
TextInput::make('descrizione')->label('Descrizione')->required()->maxLength(255),
|
|
Select::make('ritenuta_previdenziale_codice')
|
|
->label('Ritenuta previdenziale (RT..)')
|
|
->options(fn() => FeRitenutaPrevidenziale::query()
|
|
->where('attivo', true)
|
|
->orderBy('codice')
|
|
->pluck('codice', 'codice')
|
|
->all())
|
|
->searchable()
|
|
->nullable(),
|
|
Toggle::make('attivo')->label('Attivo')->default(true),
|
|
])
|
|
->fillForm(fn(FeTributoF24 $record): array => [
|
|
'descrizione' => $record->descrizione,
|
|
'ritenuta_previdenziale_codice' => $record->ritenuta_previdenziale_codice,
|
|
'attivo' => (bool) $record->attivo,
|
|
])
|
|
->action(function (FeTributoF24 $record, array $data): void {
|
|
$record->fill([
|
|
'descrizione' => (string) ($data['descrizione'] ?? ''),
|
|
'ritenuta_previdenziale_codice' => $data['ritenuta_previdenziale_codice'] ?? null,
|
|
'attivo' => (bool) ($data['attivo'] ?? true),
|
|
]);
|
|
$record->save();
|
|
}),
|
|
|
|
Action::make('delete')
|
|
->label('Elimina')
|
|
->icon('heroicon-o-trash')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->action(fn(FeTributoF24 $record) => $record->delete()),
|
|
]);
|
|
}
|
|
}
|