118 lines
3.6 KiB
PHP
Executable File
118 lines
3.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Filament\Pages\Condomini;
|
|
|
|
use App\Filament\Pages\Condomini\PalazzineInterni;
|
|
use App\Models\Palazzina;
|
|
use App\Models\User;
|
|
use App\Support\StabileContext;
|
|
use BackedEnum;
|
|
use Filament\Actions\Action;
|
|
use Filament\Pages\Page;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextInputColumn;
|
|
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 PalazzineArchivio extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static ?string $navigationLabel = 'Palazzine';
|
|
|
|
protected static ?string $title = 'Palazzine';
|
|
|
|
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-building-office-2';
|
|
|
|
protected static UnitEnum|string|null $navigationGroup = 'Stabile';
|
|
|
|
protected static ?int $navigationSort = 30;
|
|
|
|
protected static ?string $slug = 'condomini/palazzine';
|
|
|
|
protected string $view = 'filament.pages.gescon.table';
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = Auth::user();
|
|
return $user instanceof User
|
|
&& $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore']);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->mountInteractsWithTable();
|
|
}
|
|
|
|
protected function getTableQuery(): Builder
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User) {
|
|
return Palazzina::query()->whereRaw('1 = 0');
|
|
}
|
|
|
|
$activeStabileId = StabileContext::resolveActiveStabileId($user);
|
|
if (! $activeStabileId) {
|
|
return Palazzina::query()->whereRaw('1 = 0');
|
|
}
|
|
|
|
return Palazzina::query()
|
|
->where('stabile_id', $activeStabileId)
|
|
->withCount('unitaImmobiliari')
|
|
->orderBy('codice_palazzina');
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->striped()
|
|
->columns([
|
|
TextColumn::make('codice_palazzina')
|
|
->label('Codice')
|
|
->sortable()
|
|
->searchable(),
|
|
|
|
TextColumn::make('denominazione')
|
|
->label('Denominazione')
|
|
->searchable()
|
|
->wrap(),
|
|
|
|
TextInputColumn::make('numero_scale')
|
|
->label('Scale')
|
|
->type('number')
|
|
->inputMode('numeric')
|
|
->rules(['nullable', 'integer', 'min:0'])
|
|
->sortable()
|
|
->toggleable(),
|
|
|
|
TextInputColumn::make('numero_piani_fuori_terra')
|
|
->label('Piani')
|
|
->type('number')
|
|
->inputMode('numeric')
|
|
->rules(['nullable', 'integer', 'min:0'])
|
|
->sortable()
|
|
->toggleable(),
|
|
|
|
TextColumn::make('unita_immobiliari_count')
|
|
->label('Unità')
|
|
->sortable()
|
|
->toggleable(),
|
|
|
|
IconColumn::make('attiva')
|
|
->label('Attiva')
|
|
->boolean(),
|
|
])
|
|
->actions([
|
|
Action::make('interni')
|
|
->label('Interni')
|
|
->icon('heroicon-o-rectangle-group')
|
|
->url(fn(Palazzina $record) => PalazzineInterni::getUrl(panel: 'admin-filament') . '?palazzina_id=' . (int) $record->id . '&back=' . urlencode((string) request()->getRequestUri())),
|
|
]);
|
|
}
|
|
}
|