114 lines
3.2 KiB
PHP
Executable File
114 lines
3.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Filament\Pages\Contabilita;
|
|
|
|
use App\Filament\Pages\Stampe\PreventivoLettera;
|
|
use App\Models\Preventivo;
|
|
use App\Models\User;
|
|
use App\Support\StabileContext;
|
|
use BackedEnum;
|
|
use Filament\Actions\Action;
|
|
use Filament\Pages\Page;
|
|
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 UnitEnum;
|
|
|
|
class PreventiviArchivio extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static ?string $navigationLabel = 'Preventivi';
|
|
|
|
protected static ?string $title = 'Preventivi';
|
|
|
|
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-document-text';
|
|
|
|
protected static UnitEnum|string|null $navigationGroup = 'Contabilità';
|
|
|
|
protected static ?int $navigationSort = 5;
|
|
|
|
protected static ?string $slug = 'contabilita/preventivi';
|
|
|
|
protected string $view = 'filament.pages.gescon.table';
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = Auth::user();
|
|
|
|
if (! $user instanceof User) {
|
|
return false;
|
|
}
|
|
|
|
if ($user->hasAnyRole(['super-admin', 'admin'])) {
|
|
return true;
|
|
}
|
|
|
|
return $user->can('contabilita.preventivi');
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->mountInteractsWithTable();
|
|
}
|
|
|
|
protected function getTableQuery(): Builder
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User) {
|
|
return Preventivo::query()->whereRaw('1 = 0');
|
|
}
|
|
|
|
$activeStabileId = StabileContext::resolveActiveStabileId($user);
|
|
if (! $activeStabileId) {
|
|
return Preventivo::query()->whereRaw('1 = 0');
|
|
}
|
|
|
|
return Preventivo::query()
|
|
->where('stabile_id', $activeStabileId)
|
|
->with('stabile')
|
|
->orderByDesc('anno_gestione')
|
|
->orderByDesc('created_at');
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->striped()
|
|
->columns([
|
|
TextColumn::make('anno_gestione')
|
|
->label('Anno')
|
|
->sortable(),
|
|
|
|
TextColumn::make('tipo_gestione')
|
|
->label('Gestione')
|
|
->badge()
|
|
->sortable(),
|
|
|
|
TextColumn::make('descrizione')
|
|
->label('Descrizione')
|
|
->wrap()
|
|
->searchable(),
|
|
|
|
TextColumn::make('stato')
|
|
->label('Stato')
|
|
->badge()
|
|
->sortable(),
|
|
|
|
TextColumn::make('importo_totale')
|
|
->label('Totale')
|
|
->alignEnd()
|
|
->formatStateUsing(fn($state) => '€ ' . number_format((float) $state, 2, ',', '.')),
|
|
])
|
|
->actions([
|
|
Action::make('lettera')
|
|
->label('Lettera')
|
|
->icon('heroicon-o-printer')
|
|
->url(fn(Preventivo $record) => PreventivoLettera::getUrl(['record' => $record->id], panel: 'admin-filament'), shouldOpenInNewTab: true),
|
|
]);
|
|
}
|
|
}
|