75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Contabilita;
|
|
|
|
use App\Filament\Pages\Condomini\CruscottoStabile;
|
|
use App\Filament\Pages\Gescon\StabiliArchivio;
|
|
use App\Models\Stabile;
|
|
use App\Models\User;
|
|
use App\Support\StabileContext;
|
|
use BackedEnum;
|
|
use Filament\Pages\Page;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use UnitEnum;
|
|
|
|
class GestioneStraordinaria extends Page
|
|
{
|
|
protected static ?string $navigationLabel = 'Straordinaria';
|
|
|
|
protected static ?string $title = 'Gestione straordinaria';
|
|
|
|
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-wrench-screwdriver';
|
|
|
|
protected static UnitEnum|string|null $navigationGroup = 'Contabilità';
|
|
|
|
protected static ?int $navigationSort = 12;
|
|
|
|
protected static ?string $slug = 'contabilita/gestione-straordinaria';
|
|
|
|
protected string $view = 'filament.pages.contabilita.gestione-straordinaria';
|
|
|
|
public ?Stabile $stabileAttivo = null;
|
|
|
|
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.gestioni');
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User) {
|
|
return;
|
|
}
|
|
|
|
$activeId = StabileContext::resolveActiveStabileId($user);
|
|
if (! $activeId) {
|
|
$this->stabileAttivo = null;
|
|
return;
|
|
}
|
|
|
|
$this->stabileAttivo = StabileContext::accessibleStabili($user)
|
|
->firstWhere('id', $activeId);
|
|
}
|
|
|
|
public static function getCruscottoUrl(): string
|
|
{
|
|
return CruscottoStabile::getUrl(panel: 'admin-filament');
|
|
}
|
|
|
|
public static function getSelezionaStabileUrl(): string
|
|
{
|
|
return StabiliArchivio::getUrl(panel: 'admin-filament');
|
|
}
|
|
}
|