netgescon-day0/resources/views/filament/pages/contabilita/registro-ra.blade.php

323 lines
23 KiB
PHP

@php
$activeTab = $this->viewTab ?? 'ra';
$years = $this->availableFiscalYears ?? [];
$selectedYear = $this->fiscalYear;
$f24 = $this->f24MonthlySummary ?? ['rows' => [], 'totale_versato' => 0, 'totale_da_versare' => 0];
$f24Details = $this->f24DetailRows ?? [];
$f24DetailsFiltered = $this->filteredF24DetailRows ?? [];
$selectedF24Model = $this->selectedF24Model;
$cu = $this->cuSummary ?? ['rows' => [], 'totale_ra' => 0];
$cuDetails = $this->filteredCuDetailRows ?? [];
@endphp
<x-filament-panels::page>
<div class="mx-auto max-w-7xl space-y-4">
<div class="flex flex-wrap gap-2">
<x-filament::button size="sm" :color="$activeTab === 'ra' ? 'primary' : 'gray'" wire:click="setViewTab('ra')">Registro RA</x-filament::button>
<x-filament::button size="sm" :color="$activeTab === 'f24' ? 'primary' : 'gray'" wire:click="setViewTab('f24')">Modelli F24</x-filament::button>
<x-filament::button size="sm" :color="$activeTab === 'cu' ? 'primary' : 'gray'" wire:click="setViewTab('cu')">Certificazioni Uniche</x-filament::button>
</div>
<div class="rounded-lg border bg-white px-3 py-2">
<div class="flex flex-wrap items-center gap-3 text-xs">
<label class="text-gray-600">Anno fiscale</label>
<select wire:model.live="fiscalYear" class="rounded border-gray-300 text-xs">
@foreach($years as $yearValue => $yearLabel)
<option value="{{ $yearValue }}">{{ $yearLabel }}</option>
@endforeach
</select>
<span class="text-gray-500">Visualizzazione annuale con consultazione anni arretrati.</span>
</div>
</div>
@if($activeTab === 'ra')
<div class="rounded-lg border bg-white p-2">
{{ $this->table }}
</div>
@endif
@if($activeTab === 'f24')
<div class="flex flex-wrap gap-2">
<x-filament::button size="sm" :color="($this->f24SubTab ?? 'riepilogo') === 'riepilogo' ? 'primary' : 'gray'" wire:click="setF24SubTab('riepilogo')">Riepilogo F24 per mese / tributo</x-filament::button>
<x-filament::button size="sm" :color="($this->f24SubTab ?? 'riepilogo') === 'dettaglio' ? 'primary' : 'gray'" wire:click="setF24SubTab('dettaglio')">Dettaglio tributi versati / da versare</x-filament::button>
</div>
@if(($this->f24SubTab ?? 'riepilogo') === 'riepilogo')
<div class="rounded-lg border bg-white">
<div class="border-b bg-gray-50 px-3 py-2 text-xs font-semibold text-gray-700">Riepilogo F24 per mese / tributo</div>
<div class="border-b bg-white px-3 py-2 text-xs text-gray-600">
Versato: {{ number_format((float)($f24['totale_versato'] ?? 0), 2, ',', '.') }}
· Da versare: {{ number_format((float)($f24['totale_da_versare'] ?? 0), 2, ',', '.') }}
</div>
@if(!empty($f24['rows']))
<div class="overflow-x-auto">
<table class="min-w-full text-xs">
<thead class="bg-white">
<tr>
<th class="px-3 py-2 text-left">Mese</th>
<th class="px-3 py-2 text-left">Tributo</th>
<th class="px-3 py-2 text-right">Versato </th>
<th class="px-3 py-2 text-right">Da versare </th>
<th class="px-3 py-2 text-right">Righe</th>
<th class="px-3 py-2 text-right">Rif. F24</th>
</tr>
</thead>
<tbody>
@php
$groupedByMonth = collect($f24['rows'] ?? [])->groupBy('mese');
@endphp
@foreach($groupedByMonth as $mese => $monthRows)
@foreach($monthRows as $row)
<tr class="border-t">
<td class="px-3 py-2">{{ \Carbon\Carbon::createFromFormat('Y-m', $row['mese'])->format('m/Y') }}</td>
<td class="px-3 py-2">{{ $row['tributo'] }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['versato'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['da_versare'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ (int) ($row['righe'] ?? 0) }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ (int) ($row['f24_compilati'] ?? 0) }}</td>
</tr>
@endforeach
<tr class="border-t bg-gray-50 font-semibold text-gray-700">
<td class="px-3 py-2">Subtotale {{ \Carbon\Carbon::createFromFormat('Y-m', $mese)->format('m/Y') }}</td>
<td class="px-3 py-2">Totale mese</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float) $monthRows->sum('versato'), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float) $monthRows->sum('da_versare'), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ (int) $monthRows->sum('righe') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ (int) $monthRows->sum('f24_compilati') }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="px-3 py-3 text-xs text-gray-500">Nessun dato F24 disponibile.</div>
@endif
</div>
@endif
@if(($this->f24SubTab ?? 'riepilogo') === 'dettaglio')
<div class="rounded-lg border bg-white">
<div class="border-b bg-gray-50 px-3 py-2 text-xs font-semibold text-gray-700">Dettaglio tributi versati / da versare (data + istituto addebito)</div>
<div class="border-b bg-white px-3 py-2 text-xs">
<div class="flex flex-wrap items-center gap-3">
<label class="text-gray-600">Filtro stato</label>
<select wire:model.live="f24DetailFilterState" class="rounded border-gray-300 text-xs">
<option value="tutti">Tutti</option>
<option value="versato">Solo versato</option>
<option value="da_versare">Solo da versare</option>
<option value="ritardo">Solo in ritardo</option>
</select>
<span class="text-gray-500">Sanzione (8906) e interessi (1991) sono esposti come tributi separati nel modello F24.</span>
</div>
</div>
@if(!empty($f24DetailsFiltered))
<div class="overflow-x-auto">
<table class="min-w-full text-xs">
<thead class="bg-white">
<tr>
<th class="px-3 py-2 text-left">Fornitore</th>
<th class="px-3 py-2 text-left">Fattura</th>
<th class="px-3 py-2 text-left">Tributo</th>
<th class="px-3 py-2 text-right">RA </th>
<th class="px-3 py-2 text-left">Pagata</th>
<th class="px-3 py-2 text-left">Scadenza RA</th>
<th class="px-3 py-2 text-left">Versata</th>
<th class="px-3 py-2 text-left">Istituto</th>
<th class="px-3 py-2 text-right">Sanzioni </th>
<th class="px-3 py-2 text-right">Interessi </th>
<th class="px-3 py-2 text-right">Totale F24 </th>
<th class="px-3 py-2 text-left">Stato</th>
<th class="px-3 py-2 text-left">Azioni</th>
</tr>
</thead>
<tbody>
@foreach($f24DetailsFiltered as $row)
<tr class="border-t">
<td class="px-3 py-2">{{ $row['fornitore'] ?? '—' }}</td>
<td class="px-3 py-2">{{ $row['numero_documento'] ?? '—' }}</td>
<td class="px-3 py-2">{{ $row['tributo'] ?? '1040' }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['importo_ra'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2">{{ !empty($row['data_pagamento']) ? \Carbon\Carbon::parse($row['data_pagamento'])->format('d/m/Y') : '—' }}</td>
<td class="px-3 py-2">{{ !empty($row['scadenza_versamento']) ? \Carbon\Carbon::parse($row['scadenza_versamento'])->format('d/m/Y') : '—' }}</td>
<td class="px-3 py-2">{{ !empty($row['data_versamento']) ? \Carbon\Carbon::parse($row['data_versamento'])->format('d/m/Y') : '—' }}</td>
<td class="px-3 py-2">
<div>{{ $row['istituto_banca'] ?? '—' }}</div>
@if(!empty($row['addebito_descrizione']))
<div class="text-[10px] text-gray-500">{{ $row['addebito_descrizione'] }}</div>
@endif
</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['sanzioni'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['interessi'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['totale_f24'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2">
@if(!empty($row['versata']))
@if(!empty($row['in_ritardo']))
<span class="text-amber-700">Versata in ritardo</span>
@else
<span class="text-emerald-700">Versata</span>
@endif
@else
<span class="text-amber-700">Da versare</span>
@endif
</td>
<td class="px-3 py-2">
<x-filament::button size="xs" color="gray" wire:click="setSelectedF24Fattura({{ (int)($row['fattura_id'] ?? 0) }})">Vedi modello F24</x-filament::button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="px-3 py-3 text-xs text-gray-500">Nessun dettaglio tributi disponibile per l'anno fiscale selezionato.</div>
@endif
</div>
@if(!empty($selectedF24Model))
<div class="rounded-lg border bg-white">
<div class="border-b bg-gray-50 px-3 py-2 text-xs font-semibold text-gray-700">Modello F24 compilato (simulazione)</div>
<div class="grid gap-3 p-3 text-xs md:grid-cols-2">
<div>
<div><span class="font-semibold">Fornitore:</span> {{ $selectedF24Model['fornitore'] ?? '' }}</div>
<div><span class="font-semibold">Fattura:</span> {{ $selectedF24Model['numero_documento'] ?? '' }}</div>
<div><span class="font-semibold">Data versamento:</span> {{ !empty($selectedF24Model['data_versamento']) ? \Carbon\Carbon::parse($selectedF24Model['data_versamento'])->format('d/m/Y') : '' }}</div>
<div><span class="font-semibold">Istituto:</span> {{ $selectedF24Model['istituto_banca'] ?? '' }}</div>
<div><span class="font-semibold">ABI/CAB:</span> {{ $selectedF24Model['istituto_abi'] ?: '' }} / {{ $selectedF24Model['istituto_cab'] ?: '' }}</div>
</div>
<div>
<div class="font-semibold text-gray-700">Sezione Erario</div>
<div>Cod. {{ $selectedF24Model['tributo'] ?? '1040' }}: € {{ number_format((float)($selectedF24Model['importo_ra'] ?? 0), 2, ',', '.') }}</div>
<div>Cod. {{ $selectedF24Model['tributo_sanzione'] ?? '8906' }}: € {{ number_format((float)($selectedF24Model['sanzioni'] ?? 0), 2, ',', '.') }}</div>
<div>Cod. {{ $selectedF24Model['tributo_interessi'] ?? '1991' }}: € {{ number_format((float)($selectedF24Model['interessi'] ?? 0), 2, ',', '.') }}</div>
<div class="mt-1 font-semibold">Totale delega: € {{ number_format((float)($selectedF24Model['totale_f24'] ?? 0), 2, ',', '.') }}</div>
<div class="text-[10px] text-gray-500">Giorni ritardo: {{ (int)($selectedF24Model['giorni_ritardo'] ?? 0) }} · Sanzione: {{ number_format((float)($selectedF24Model['sanzione_percentuale'] ?? 0), 2, ',', '.') }}% · Tasso legale: {{ number_format((float)($selectedF24Model['tasso_legale'] ?? 0), 2, ',', '.') }}%</div>
</div>
</div>
</div>
@endif
@endif
@endif
@if($activeTab === 'cu')
<div class="flex flex-wrap gap-2">
<x-filament::button size="sm" :color="($this->cuSubTab ?? 'riepilogo') === 'riepilogo' ? 'primary' : 'gray'" wire:click="setCuSubTab('riepilogo')">Riepilogo CU per fornitore</x-filament::button>
<x-filament::button size="sm" :color="($this->cuSubTab ?? 'riepilogo') === 'dettaglio' ? 'primary' : 'gray'" wire:click="setCuSubTab('dettaglio')">Dettaglio CU fornitore</x-filament::button>
</div>
@if(($this->cuSubTab ?? 'riepilogo') === 'riepilogo')
<div class="rounded-lg border bg-white">
<div class="border-b bg-gray-50 px-3 py-2 text-xs font-semibold text-gray-700">Riepilogo CU per anno / fornitore</div>
<div class="border-b bg-white px-3 py-2 text-xs text-gray-600">
Totale RA monitorate: € {{ number_format((float)($cu['totale_ra'] ?? 0), 2, ',', '.') }}
</div>
@if(!empty($cu['rows']))
<div class="overflow-x-auto">
<table class="min-w-full text-xs">
<thead class="bg-white">
<tr>
<th class="px-3 py-2 text-left">Anno fiscale</th>
<th class="px-3 py-2 text-left">Fornitore</th>
<th class="px-3 py-2 text-right">Totale RA €</th>
<th class="px-3 py-2 text-right">RA versata €</th>
<th class="px-3 py-2 text-right">RA da versare €</th>
<th class="px-3 py-2 text-right">Righe</th>
<th class="px-3 py-2 text-left">Stato CU</th>
<th class="px-3 py-2 text-left">Comunicazione</th>
<th class="px-3 py-2 text-left">Azioni</th>
</tr>
</thead>
<tbody>
@foreach(($cu['rows'] ?? []) as $row)
<tr class="border-t">
<td class="px-3 py-2">{{ $row['anno'] }}</td>
<td class="px-3 py-2">{{ $row['fornitore'] }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['totale_ra'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['totale_versata'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['totale_da_versare'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ (int) ($row['righe'] ?? 0) }}</td>
<td class="px-3 py-2">
@if(!empty($row['inclusa_cu']))
<span class="text-emerald-700">Inclusa</span>
@else
<span class="text-amber-700">Da includere</span>
@endif
</td>
<td class="px-3 py-2">
@if(!empty($row['comunicata']))
<span class="text-emerald-700">Inviata</span>
@if(!empty($row['ultima_comunicazione']))
<span class="text-[10px] text-gray-500"> · {{ \Carbon\Carbon::parse($row['ultima_comunicazione'])->format('d/m/Y') }}</span>
@endif
@else
<span class="text-amber-700">Da inviare</span>
@endif
</td>
<td class="px-3 py-2">
<x-filament::button size="xs" color="gray" wire:click="setSelectedCuFornitore({{ (int)($row['fornitore_id'] ?? 0) }})">Vedi dettaglio</x-filament::button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="px-3 py-3 text-xs text-gray-500">Nessun dato CU disponibile.</div>
@endif
</div>
@endif
@if(($this->cuSubTab ?? 'riepilogo') === 'dettaglio')
<div class="rounded-lg border bg-white">
<div class="border-b bg-gray-50 px-3 py-2 text-xs font-semibold text-gray-700">Dettaglio fatture pagate e RA per anno fiscale</div>
@if(!empty($this->selectedCuFornitoreId))
<div class="border-b bg-white px-3 py-2 text-xs text-gray-600">Filtro attivo sul fornitore selezionato nel riepilogo.</div>
@endif
@if(!empty($cuDetails))
<div class="overflow-x-auto">
<table class="min-w-full text-xs">
<thead class="bg-white">
<tr>
<th class="px-3 py-2 text-left">Fornitore</th>
<th class="px-3 py-2 text-left">Fattura</th>
<th class="px-3 py-2 text-left">Data doc.</th>
<th class="px-3 py-2 text-left">Pagata</th>
<th class="px-3 py-2 text-left">Vers. RA</th>
<th class="px-3 py-2 text-left">Tributo</th>
<th class="px-3 py-2 text-right">RA €</th>
<th class="px-3 py-2 text-left">CU</th>
</tr>
</thead>
<tbody>
@foreach($cuDetails as $row)
<tr class="border-t">
<td class="px-3 py-2">{{ $row['fornitore'] ?? '' }}</td>
<td class="px-3 py-2">{{ $row['numero_documento'] ?? '' }}</td>
<td class="px-3 py-2">{{ !empty($row['data_documento']) ? \Carbon\Carbon::parse($row['data_documento'])->format('d/m/Y') : '' }}</td>
<td class="px-3 py-2">{{ !empty($row['data_pagamento']) ? \Carbon\Carbon::parse($row['data_pagamento'])->format('d/m/Y') : '' }}</td>
<td class="px-3 py-2">{{ !empty($row['data_versamento']) ? \Carbon\Carbon::parse($row['data_versamento'])->format('d/m/Y') : '' }}</td>
<td class="px-3 py-2">{{ $row['tributo'] ?? '1040' }}</td>
<td class="px-3 py-2 text-right tabular-nums">{{ number_format((float)($row['importo_ra'] ?? 0), 2, ',', '.') }}</td>
<td class="px-3 py-2">
@if(!empty($row['inclusa_cu']))
<span class="text-emerald-700">Inclusa</span>
@else
<span class="text-amber-700">Da includere</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="px-3 py-3 text-xs text-gray-500">Nessun dettaglio CU disponibile per l'anno fiscale selezionato.</div>
@endif
</div>
@endif
@endif
</div>
</x-filament-panels::page>