84 lines
3.0 KiB
PHP
84 lines
3.0 KiB
PHP
@php
|
|
/** @var \Illuminate\Support\Collection<int, \App\Models\Stabile> $stabili */
|
|
/** @var \App\Models\Stabile|null $stabileAttivo */
|
|
$activeId = $stabileAttivo?->id;
|
|
|
|
$stabileHasRiscaldamento = static function (?\App\Models\Stabile $stabile): bool {
|
|
if (! $stabile) {
|
|
return false;
|
|
}
|
|
|
|
if ((bool) ($stabile->riscaldamento_centralizzato ?? false)) {
|
|
return true;
|
|
}
|
|
|
|
$rateRiscaldamento = $stabile->rate_riscaldamento_mesi ?? [];
|
|
if (is_string($rateRiscaldamento)) {
|
|
$rateRiscaldamento = json_decode($rateRiscaldamento, true);
|
|
}
|
|
if (is_array($rateRiscaldamento) && $rateRiscaldamento !== []) {
|
|
return true;
|
|
}
|
|
|
|
$config = $stabile->configurazione_avanzata ?? [];
|
|
if (is_string($config)) {
|
|
$config = json_decode($config, true);
|
|
}
|
|
if (is_array($config) && array_key_exists('mostra_riscaldamento', $config) && $config['mostra_riscaldamento']) {
|
|
return true;
|
|
}
|
|
|
|
return \Illuminate\Support\Facades\DB::table('gestioni_contabili')
|
|
->where('stabile_id', $stabile->id)
|
|
->where('tipo_gestione', 'riscaldamento')
|
|
->exists();
|
|
};
|
|
|
|
$stabileLabel = static function (?\App\Models\Stabile $stabile): string {
|
|
if (! $stabile) {
|
|
return '';
|
|
}
|
|
|
|
$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));
|
|
};
|
|
@endphp
|
|
|
|
<div class="flex items-center gap-3">
|
|
@if($stabileAttivo)
|
|
<div class="hidden md:flex flex-col leading-tight">
|
|
<div class="text-xs text-gray-500">Stabile attivo</div>
|
|
<div class="text-sm font-medium">
|
|
{{ $stabileLabel($stabileAttivo) }} — {{ $stabileAttivo->denominazione }}
|
|
</div>
|
|
<div class="text-xs text-gray-500">
|
|
Ordinari: {{ ($stabileAttivo->numero_rate_ordinarie ?? 0) > 0 ? 'Sì' : 'No' }} ·
|
|
Riscaldamento: {{ $stabileHasRiscaldamento($stabileAttivo) ? 'Sì' : 'No' }}
|
|
</div>
|
|
</div>
|
|
@endif
|
|
|
|
@if($stabili->count() > 1)
|
|
<form method="POST" action="{{ route('admin-filament.stabile-attivo') }}" class="flex items-center">
|
|
@csrf
|
|
<select
|
|
name="stabile_id"
|
|
class="fi-input block w-full min-w-[220px]"
|
|
onchange="this.form.submit()"
|
|
>
|
|
@foreach($stabili as $stabile)
|
|
<option value="{{ $stabile->id }}" @selected($activeId === $stabile->id)>
|
|
{{ $stabileLabel($stabile) }} — {{ $stabile->denominazione }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</form>
|
|
@endif
|
|
</div>
|