68 lines
1.9 KiB
PHP
Executable File
68 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Filament\Pages\Gescon;
|
|
|
|
use App\Models\Stabile;
|
|
use App\Models\User;
|
|
use App\Services\GesconImport\EssentialImportService;
|
|
use App\Support\StabileContext;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Checkbox;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Pages\Page;
|
|
use Filament\Notifications\Notification;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class StabileScheda extends Page
|
|
{
|
|
protected static ?string $title = 'Scheda stabile';
|
|
|
|
protected static ?string $slug = 'anagrafica/stabili/{record}';
|
|
|
|
protected static bool $shouldRegisterNavigation = false;
|
|
|
|
protected string $view = 'filament.pages.gescon.stabile-scheda';
|
|
|
|
public Stabile $stabile;
|
|
|
|
public function mount(int|string $record): void
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User) {
|
|
abort(403);
|
|
}
|
|
|
|
if (! $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore'])) {
|
|
abort(403);
|
|
}
|
|
|
|
$this->stabile = Stabile::query()->with(['rubrica', 'amministratore'])->findOrFail((int) $record);
|
|
|
|
if (! $user->hasAnyRole(['super-admin', 'admin'])) {
|
|
$activeStabile = StabileContext::getActiveStabile($user);
|
|
$adminId = (int) ($activeStabile?->amministratore_id ?: 0);
|
|
if ($adminId <= 0 || (int) $this->stabile->amministratore_id !== $adminId) {
|
|
abort(404);
|
|
}
|
|
}
|
|
|
|
// Imposta questo stabile come attivo per garantire che le pagine "Stabile" puntino ai dati giusti.
|
|
StabileContext::setActiveStabileId($user, (int) $this->stabile->id);
|
|
}
|
|
|
|
protected function getBackUrl(): string
|
|
{
|
|
$back = request()->query('back');
|
|
if (is_string($back) && trim($back) !== '') {
|
|
return $back;
|
|
}
|
|
|
|
return StabiliArchivio::getUrl(panel: 'admin-filament');
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [];
|
|
}
|
|
}
|