netgescon-day0/resources/views/filament/pages/contabilita/estratto-conto-soggetto.blade.php

310 lines
20 KiB
PHP

<x-filament-panels::page>
<div class="mx-auto max-w-7xl space-y-4">
@if(! $soggetto)
<div class="rounded-xl border border-dashed border-gray-200 bg-white p-6 text-center text-gray-500">Soggetto non trovato.</div>
@php return; @endphp
@endif
@php
$nome = trim((string) ($soggetto->ragione_sociale ?? ''));
if ($nome === '') {
$nome = trim((string) ($soggetto->nome ?? '') . ' ' . (string) ($soggetto->cognome ?? ''));
}
if ($nome === '') {
$nome = 'Soggetto #' . (int) $soggetto->id;
}
@endphp
@php
$persona = $soggetto->persona ?? null;
$tel1 = trim((string) ($persona->telefono_principale ?? $soggetto->telefono ?? ''));
$tel2 = trim((string) ($persona->telefono_secondario ?? ''));
$whatsapp = trim((string) ($persona->whatsapp ?? ''));
$email = trim((string) ($persona->email_principale ?? $soggetto->email ?? ''));
$pec = trim((string) ($persona->email_pec ?? ''));
$selectedUnitLabel = '—';
if (!empty($unitaId) && !empty($unitaList)) {
foreach ($unitaList as $uu) {
if ((int) ($uu['id'] ?? 0) === (int) $unitaId) {
$selectedUnitLabel = (string) ($uu['label'] ?? '—');
break;
}
}
}
$baseQuery = [
'vista' => $vista ?? 'unita',
'unita_id' => $unitaId,
'q' => $qUnita ?? '',
'scadenza' => !empty($showScadenza) ? 1 : 0,
];
@endphp
<x-filament::section class="p-4!">
<div class="flex flex-wrap items-start justify-between gap-4">
<div class="space-y-1">
<div class="text-lg font-semibold text-gray-900">Estratto conto</div>
<div class="text-sm text-gray-700">{{ $nome }}</div>
<div class="text-xs text-gray-500">CF: {{ $soggetto->codice_fiscale ?? '—' }}</div>
<div class="mt-2 text-xs text-gray-700">
<div class="font-medium text-gray-900">Unità</div>
<div>{{ $selectedUnitLabel }}</div>
</div>
</div>
<div class="space-y-2">
<div class="flex flex-wrap items-center justify-end gap-2">
<form method="GET" class="flex flex-wrap items-center gap-2">
<input type="hidden" name="vista" value="{{ $vista ?? 'unita' }}" />
<input type="hidden" name="unita_id" value="{{ $unitaId }}" />
<input type="hidden" name="scadenza" value="{{ !empty($showScadenza) ? 1 : 0 }}" />
<div class="fi-input-wrp">
<input class="fi-input block w-56" type="text" name="q" value="{{ $qUnita ?? '' }}" placeholder="Cerca unità (codice/int.)" />
</div>
<x-filament::button type="submit" color="gray">Cerca</x-filament::button>
</form>
<div class="flex items-center gap-2">
<a class="fi-btn fi-btn-color-gray fi-btn-size-sm" href="{{ request()->fullUrlWithQuery(array_merge($baseQuery, ['vista' => 'unita'])) }}">Vista Unità</a>
<a class="fi-btn fi-btn-color-gray fi-btn-size-sm" href="{{ request()->fullUrlWithQuery(array_merge($baseQuery, ['vista' => 'soggetto'])) }}">Vista Soggetto</a>
</div>
<div class="flex items-center gap-2">
@if(!empty($prevUnitaId))
<a class="fi-btn fi-btn-color-gray fi-btn-size-sm" href="{{ request()->fullUrlWithQuery(array_merge($baseQuery, ['vista' => 'unita', 'unita_id' => $prevUnitaId])) }}">&larr;</a>
@else
<span class="fi-btn fi-btn-color-gray fi-btn-size-sm opacity-40">&larr;</span>
@endif
@if(!empty($nextUnitaId))
<a class="fi-btn fi-btn-color-gray fi-btn-size-sm" href="{{ request()->fullUrlWithQuery(array_merge($baseQuery, ['vista' => 'unita', 'unita_id' => $nextUnitaId])) }}">&rarr;</a>
@else
<span class="fi-btn fi-btn-color-gray fi-btn-size-sm opacity-40">&rarr;</span>
@endif
</div>
</div>
<div class="flex flex-wrap items-start justify-end gap-4">
<div class="grid gap-2 sm:grid-cols-3">
<div class="rounded-lg border bg-gray-50 p-3">
<div class="text-xs text-gray-500">Addebito (vista)</div>
@php
$t = ($vista ?? 'unita') === 'unita' ? ($totaliUnita ?? []) : ($totali ?? []);
@endphp
<div class="text-sm font-semibold text-gray-900">{{ number_format((float) ($t['addebitato'] ?? 0), 2, ',', '.') }} </div>
</div>
<div class="rounded-lg border bg-gray-50 p-3">
<div class="text-xs text-gray-500">Pagato (vista)</div>
<div class="text-sm font-semibold text-gray-900">{{ number_format((float) ($t['pagato'] ?? 0), 2, ',', '.') }} </div>
</div>
<div class="rounded-lg border bg-gray-50 p-3">
<div class="text-xs text-gray-500">Residuo (vista)</div>
<div class="text-sm font-semibold text-gray-900">{{ number_format((float) ($t['residuo'] ?? 0), 2, ',', '.') }} </div>
</div>
</div>
<div class="space-y-1 text-xs text-gray-700">
<div class="font-medium text-gray-900">Contatti</div>
<div class="flex flex-wrap gap-x-3 gap-y-1">
@if($tel1 !== '')
<a class="fi-link" href="tel:{{ preg_replace('/\s+/', '', $tel1) }}">Tel: {{ $tel1 }}</a>
@endif
@if($tel2 !== '')
<a class="fi-link" href="tel:{{ preg_replace('/\s+/', '', $tel2) }}">Tel2: {{ $tel2 }}</a>
@endif
@if($whatsapp !== '')
<a class="fi-link" href="tel:{{ preg_replace('/\s+/', '', $whatsapp) }}">WhatsApp: {{ $whatsapp }}</a>
@endif
@if($email !== '')
<a class="fi-link" href="mailto:{{ $email }}">Email: {{ $email }}</a>
@endif
@if($pec !== '')
<a class="fi-link" href="mailto:{{ $pec }}">PEC: {{ $pec }}</a>
@endif
@if($tel1 === '' && $tel2 === '' && $whatsapp === '' && $email === '' && $pec === '')
<span class="text-gray-500"></span>
@endif
</div>
@if(!empty($recordCondominoId) || !empty($recordInquilinoId))
<div class="pt-1">
<span class="text-gray-500">Passa a:</span>
@if(!empty($recordCondominoId))
<a class="fi-link" href="{{ \App\Filament\Pages\Contabilita\EstrattoContoSoggetto::getUrl(['record' => $recordCondominoId], panel: 'admin-filament') }}?{{ http_build_query(array_merge($baseQuery, ['vista' => 'unita', 'unita_id' => $unitaId])) }}">Condomino</a>
@endif
@if(!empty($recordInquilinoId))
<a class="fi-link" href="{{ \App\Filament\Pages\Contabilita\EstrattoContoSoggetto::getUrl(['record' => $recordInquilinoId], panel: 'admin-filament') }}?{{ http_build_query(array_merge($baseQuery, ['vista' => 'unita', 'unita_id' => $unitaId])) }}">Inquilino</a>
@endif
</div>
@endif
</div>
</div>
<div class="text-xs text-gray-600">
<a class="fi-link" href="{{ request()->fullUrlWithQuery(array_merge($baseQuery, ['scadenza' => empty($showScadenza) ? 1 : 0])) }}">
{{ empty($showScadenza) ? 'Mostra scadenza' : 'Nascondi scadenza' }}
</a>
</div>
</div>
</div>
</x-filament::section>
<x-filament::section>
<x-slot name="heading">Rate emesse</x-slot>
<x-slot name="description">Raggruppate per gestione, in ordine dalla più vecchia</x-slot>
@if(empty($groups))
<div class="text-sm text-gray-500">Nessuna rata trovata.</div>
@else
<div class="space-y-4">
@foreach($groups as $g)
<div class="rounded-xl border bg-white">
<div class="flex flex-wrap items-center justify-between gap-3 border-b bg-gray-50 px-4 py-3">
<div class="text-sm font-semibold text-gray-900">{{ $g['label'] ?? 'Gestione' }}</div>
<div class="text-xs text-gray-700">
Totale gestione: <span class="font-semibold">{{ number_format((float) data_get($g, 'totali.dovuto', 0), 2, ',', '.') }} </span>
· Pagato: <span class="font-semibold">{{ number_format((float) data_get($g, 'totali.pagato', 0), 2, ',', '.') }} </span>
· Residuo: <span class="font-semibold">{{ number_format((float) data_get($g, 'totali.residuo', 0), 2, ',', '.') }} </span>
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full text-sm">
<thead>
<tr class="text-gray-500 border-b">
<th class="text-left py-2 px-4">Emissione</th>
@if(!empty($showScadenza))
<th class="text-left py-2 pr-4">Scadenza</th>
@endif
<th class="text-left py-2 pr-4">Avviso</th>
<th class="text-left py-2 pr-4">Em.</th>
<th class="text-left py-2 pr-4">Descrizione</th>
<th class="text-right py-2 pr-4">Dovuto</th>
<th class="text-right py-2 pr-4">Data pag.</th>
<th class="text-right py-2 pr-4">Pagato</th>
<th class="text-right py-2 pr-4">Residuo</th>
</tr>
</thead>
<tbody class="divide-y">
@foreach(($g['rows'] ?? []) as $r)
@php
$scad = $r['data_scadenza'] ?? null;
$emTitle = $scad ? ('Scadenza: ' . $scad) : '';
$suffixUnita = (($vista ?? 'unita') === 'soggetto' && !empty($r['unita_short']))
? (' (' . $r['unita_short'] . ')')
: '';
@endphp
<tr>
<td class="py-2 px-4 text-gray-900" title="{{ $emTitle }}">{{ $r['data_emissione'] ?? '—' }}</td>
@if(!empty($showScadenza))
<td class="py-2 pr-4 text-gray-700">{{ $r['data_scadenza'] ?? '—' }}</td>
@endif
<td class="py-2 pr-4 text-gray-900">{{ !empty($r['avviso']) ? $r['avviso'] : '—' }}</td>
<td class="py-2 pr-4 text-gray-700">{{ $r['n_emissione'] ?? '—' }}</td>
<td class="py-2 pr-4 text-gray-900">
<div>{{ $r['descrizione'] ?? '—' }}</div>
@if($suffixUnita !== '')
<div class="text-xs text-gray-500">{{ $suffixUnita }}</div>
@endif
</td>
<td class="py-2 pr-4 text-right text-gray-900">{{ number_format((float) ($r['dovuto'] ?? 0), 2, ',', '.') }} </td>
<td class="py-2 pr-4 text-right text-gray-700">{{ $r['data_pagamento'] ?? '—' }}</td>
<td class="py-2 pr-4 text-right text-gray-900">{{ number_format((float) ($r['pagato'] ?? 0), 2, ',', '.') }} </td>
<td class="py-2 pr-4 text-right text-gray-900">{{ number_format((float) ($r['residuo'] ?? 0), 2, ',', '.') }} </td>
</tr>
@endforeach
<tr class="bg-gray-50 font-semibold">
<td class="py-2 px-4 text-gray-900" colspan="{{ !empty($showScadenza) ? 5 : 4 }}">Totale gestione</td>
<td class="py-2 pr-4 text-right text-gray-900">{{ number_format((float) data_get($g, 'totali.dovuto', 0), 2, ',', '.') }} </td>
<td class="py-2 pr-4"></td>
<td class="py-2 pr-4 text-right text-gray-900">{{ number_format((float) data_get($g, 'totali.pagato', 0), 2, ',', '.') }} </td>
<td class="py-2 pr-4 text-right text-gray-900">{{ number_format((float) data_get($g, 'totali.residuo', 0), 2, ',', '.') }} </td>
</tr>
</tbody>
</table>
</div>
</div>
@endforeach
@php
$t = ($vista ?? 'unita') === 'unita' ? ($totaliUnita ?? []) : ($totali ?? []);
@endphp
<div class="text-sm text-gray-700">
<span class="font-semibold">Totale generale (vista):</span>
Dovuto {{ number_format((float) ($t['addebitato'] ?? 0), 2, ',', '.') }} ·
Pagato {{ number_format((float) ($t['pagato'] ?? 0), 2, ',', '.') }} ·
Residuo {{ number_format((float) ($t['residuo'] ?? 0), 2, ',', '.') }}
</div>
</div>
@endif
</x-filament::section>
<x-filament::section>
<x-slot name="heading">Incassi</x-slot>
<x-slot name="description">Pagamenti ricevuti (collegati via codifica legacy: tipo C/I + cod_cond)</x-slot>
@if(empty($incassi))
<div class="text-sm text-gray-500">Nessun incasso collegato (oppure non ancora importato).</div>
@else
<div class="overflow-x-auto">
<table class="min-w-full text-sm">
<thead>
<tr class="text-gray-500 border-b">
<th class="text-left py-2 pr-3">Anno</th>
<th class="text-left py-2 pr-3">Tipo</th>
<th class="text-left py-2 pr-3">cod_cond</th>
<th class="text-right py-2 pr-3">Data</th>
<th class="text-right py-2 pr-3">Ricevuta</th>
<th class="text-right py-2 pr-3">Importo</th>
<th class="text-left py-2 pr-3">Cassa/Banca</th>
<th class="text-left py-2 pr-3">Stato</th>
<th class="text-left py-2 pr-0">Descrizione</th>
</tr>
</thead>
<tbody class="divide-y">
@foreach($incassi as $i)
@php
$sem = (string) ($i['semaforo'] ?? '');
$semClass = 'text-gray-700';
if ($sem === 'OK') {
$semClass = 'text-emerald-700';
} elseif ($sem === 'MATCH') {
$semClass = 'text-amber-700';
}
$data = $i['dt_empag'] ?? $i['data_pagamento'] ?? '—';
@endphp
<tr>
<td class="py-2 pr-3 text-gray-900">{{ $i['anno'] ?? '—' }}</td>
<td class="py-2 pr-3 text-gray-900">{{ $i['tipo'] ?? '—' }}</td>
<td class="py-2 pr-3 text-gray-700">{{ $i['cod_cond'] ?? '—' }}</td>
<td class="py-2 pr-3 text-right text-gray-700">{{ $data }}</td>
<td class="py-2 pr-3 text-right text-gray-700">{{ $i['n_ricevuta'] ?? '—' }}</td>
<td class="py-2 pr-3 text-right text-gray-900">{{ number_format((float) ($i['importo'] ?? 0), 2, ',', '.') }} </td>
<td class="py-2 pr-3 text-gray-700">
@if(!empty($i['conto_url']))
<a class="fi-link" href="{{ $i['conto_url'] }}">Conto #{{ $i['conto_id'] }}</a>
@else
{{ !empty($i['cod_cassa']) ? $i['cod_cassa'] : '—' }}
@endif
</td>
<td class="py-2 pr-3">
<div class="text-sm font-semibold {{ $semClass }}">{{ $sem !== '' ? $sem : '—' }}</div>
@if(!empty($i['stato_riconciliazione']))
<div class="text-xs text-gray-500">{{ $i['stato_riconciliazione'] }}</div>
@elseif(!is_null($i['confidenza_match']))
<div class="text-xs text-gray-500">conf: {{ number_format((float) $i['confidenza_match'], 2, ',', '.') }}</div>
@endif
</td>
<td class="py-2 pr-0 text-gray-700">{{ $i['descrizione'] ?? '' }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</x-filament::section>
</div>
</x-filament-panels::page>