112 lines
5.7 KiB
PHP
Executable File
112 lines
5.7 KiB
PHP
Executable File
@php
|
|
$user = \Illuminate\Support\Facades\Auth::user();
|
|
|
|
$stabileHasRiscaldamento = static function (?\App\Models\Stabile $stabile): bool {
|
|
if (! $stabile) {
|
|
return false;
|
|
}
|
|
|
|
return method_exists($stabile, 'hasOperationalHeating')
|
|
? $stabile->hasOperationalHeating()
|
|
: false;
|
|
};
|
|
|
|
$stabileLabel = static function (?\App\Models\Stabile $stabile): string {
|
|
if (! $stabile) {
|
|
return 'Seleziona stabile';
|
|
}
|
|
|
|
$primary = trim((string) ($stabile->codice_operatore ?: $stabile->codice_stabile));
|
|
$mnemo = trim((string) ($stabile->cod_stabile ?? ''));
|
|
|
|
if ($mnemo !== '' && $primary !== '' && $mnemo !== $primary) {
|
|
return $mnemo . ' · ' . $primary;
|
|
}
|
|
|
|
return $primary !== '' ? $primary : ($mnemo !== '' ? $mnemo : ('#' . (string) $stabile->id));
|
|
};
|
|
|
|
$stabili = collect();
|
|
$stabileAttivo = null;
|
|
|
|
if ($user instanceof \App\Models\User) {
|
|
$stabili = \App\Support\StabileContext::accessibleStabili($user);
|
|
$activeId = \App\Support\StabileContext::resolveActiveStabileId($user);
|
|
$stabileAttivo = $activeId ? $stabili->firstWhere('id', $activeId) : null;
|
|
}
|
|
|
|
$gestioni = \App\Support\GestioneContext::availableGestioni();
|
|
$gestioneAttiva = \App\Support\GestioneContext::resolveActiveGestione($user instanceof \App\Models\User ? $user : null);
|
|
|
|
$annoGestione = \App\Support\AnnoGestioneContext::resolveActiveAnno($user instanceof \App\Models\User ? $user : null);
|
|
$anniGestione = range(max(2000, $annoGestione - 5), min(2100, $annoGestione + 3));
|
|
|
|
$labelGestione = $gestioni[$gestioneAttiva] ?? (string) $gestioneAttiva;
|
|
|
|
$haRiscaldamento = $stabileHasRiscaldamento($stabileAttivo);
|
|
$showOperationalContext = $user instanceof \App\Models\User
|
|
&& $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore']);
|
|
@endphp
|
|
|
|
<div class="flex w-full items-center justify-between gap-4 ps-3">
|
|
@if(session('impersonator_id'))
|
|
<div class="flex items-center gap-2 rounded-lg bg-amber-500 px-3 py-1.5 text-xs font-bold text-white shadow">
|
|
<span>⚠️ Impersonificazione Studio Attiva</span>
|
|
<a href="{{ route('impersonate.leave') }}" class="rounded-md bg-slate-900 px-2.5 py-1 text-[11px] font-bold text-white shadow hover:bg-slate-800 transition">
|
|
↩️ TORNA A SUPER ADMIN
|
|
</a>
|
|
</div>
|
|
@endif
|
|
@if($showOperationalContext)
|
|
<div class="flex items-center gap-3">
|
|
<form method="POST" action="{{ route('admin-filament.stabile-attivo') }}" class="min-w-[15rem]">
|
|
@csrf
|
|
<label class="mb-1 block text-[11px] font-semibold uppercase tracking-wide text-gray-500">Stabile</label>
|
|
<select name="stabile_id" onchange="this.form.submit()" class="w-full rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-xs font-medium text-gray-800 shadow-sm focus:border-amber-400 focus:outline-none">
|
|
@foreach($stabili as $stabile)
|
|
<option value="{{ $stabile->id }}" @selected((int) $stabile->id === (int) ($stabileAttivo?->id ?? 0))>
|
|
{{ $stabileLabel($stabile) }} · {{ $stabile->denominazione }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</form>
|
|
|
|
<span class="inline-flex items-center rounded-full border border-gray-200 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-800">
|
|
Risc: {{ $haRiscaldamento ? 'SI' : 'NO' }}
|
|
</span>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2">
|
|
@if($haRiscaldamento)
|
|
<a href="/admin-filament/condomini/riscaldamento-utenze?stabile_id={{ $stabileAttivo?->id }}" class="inline-flex items-center justify-center rounded-lg bg-sky-50 dark:bg-sky-950/20 border border-sky-200 dark:border-sky-800 px-3 py-1.5 text-xs font-bold text-sky-700 dark:text-sky-300 transition-colors hover:bg-sky-100 dark:hover:bg-sky-950/40" title="Riscaldamento Utenze">
|
|
🔥 RISCALDAMENTO
|
|
</a>
|
|
@endif
|
|
|
|
<a href="/admin-filament/gescon/straordinarie?stabile_id={{ $stabileAttivo?->id }}" class="inline-flex items-center justify-center rounded-lg bg-amber-50 dark:bg-amber-950/20 border border-amber-200 dark:border-amber-800 px-3 py-1.5 text-xs font-bold text-amber-700 dark:text-amber-300 transition-colors hover:bg-amber-100 dark:hover:bg-amber-950/40" title="Spese Straordinarie">
|
|
🛠️ STRAORDINARIE
|
|
</a>
|
|
|
|
<form method="POST" action="{{ route('admin-filament.anno-gestione-attivo') }}" class="min-w-[7rem]">
|
|
@csrf
|
|
<label class="mb-1 block text-[11px] font-semibold uppercase tracking-wide text-gray-500">Anno</label>
|
|
<select name="anno" onchange="this.form.submit()" class="w-full rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-xs font-medium text-gray-800 shadow-sm focus:border-amber-400 focus:outline-none">
|
|
@foreach($anniGestione as $anno)
|
|
<option value="{{ $anno }}" @selected((int) $anno === (int) $annoGestione)>{{ $anno }}</option>
|
|
@endforeach
|
|
</select>
|
|
</form>
|
|
|
|
<button
|
|
type="button"
|
|
class="fi-icon-btn fi-color-gray ml-2"
|
|
x-data="{}"
|
|
x-on:click="$dispatch('open-global-search-results')"
|
|
title="Cerca"
|
|
>
|
|
<x-filament::icon icon="heroicon-o-magnifying-glass" class="h-5 w-5" />
|
|
</button>
|
|
</div>
|
|
@endif
|
|
</div>
|