101 lines
4.7 KiB
PHP
101 lines
4.7 KiB
PHP
@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);
|
|
@endphp
|
|
|
|
<div class="flex min-w-0 flex-1 flex-wrap items-end gap-2 ps-3">
|
|
<div class="flex min-w-0 flex-wrap items-end gap-2">
|
|
<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-2 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>
|
|
|
|
<form method="POST" action="{{ route('admin-filament.gestione-attiva') }}" class="min-w-[11rem]">
|
|
@csrf
|
|
<label class="mb-1 block text-[11px] font-semibold uppercase tracking-wide text-gray-500">Gestione</label>
|
|
<select name="gestione" onchange="this.form.submit()" class="w-full rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-medium text-gray-800 shadow-sm focus:border-amber-400 focus:outline-none">
|
|
@foreach($gestioni as $gestioneKey => $gestioneLabel)
|
|
@continue($gestioneKey === 'riscaldamento' && ! $haRiscaldamento)
|
|
<option value="{{ $gestioneKey }}" @selected($gestioneKey === $gestioneAttiva)>{{ $gestioneLabel }}</option>
|
|
@endforeach
|
|
</select>
|
|
</form>
|
|
|
|
<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-2 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>
|
|
|
|
<span class="inline-flex items-center rounded-full border border-gray-200 bg-white px-2.5 py-2 text-xs font-medium text-gray-800">
|
|
Risc: {{ $haRiscaldamento ? 'SI' : 'NO' }}
|
|
</span>
|
|
</div>
|
|
|
|
<livewire:filament.topbar-live-call />
|
|
|
|
<button
|
|
type="button"
|
|
class="fi-icon-btn fi-color-gray"
|
|
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>
|