diff --git a/app/Filament/Pages/UnitaImmobiliarePage.php b/app/Filament/Pages/UnitaImmobiliarePage.php index 9934a86..4eb31d0 100755 --- a/app/Filament/Pages/UnitaImmobiliarePage.php +++ b/app/Filament/Pages/UnitaImmobiliarePage.php @@ -682,7 +682,11 @@ public function resolveHumanYearLabel(string $yearCode, string $codStabile): str if (DbSchema::connection('gescon_import')->hasTable('gestioni_annuali')) { $row = DB::connection('gescon_import')->table('gestioni_annuali') ->where('cod_stabile', $codStabile) - ->where('cartella', $yearCode) + ->where(function ($q) use ($yearCode) { + $q->where('cartella', $yearCode) + ->orWhere('anno_ordinario', $yearCode) + ->orWhere('anno_ordinario', (int) $yearCode); + }) ->first(); if ($row) { @@ -893,10 +897,15 @@ public function getEstrattoContoNominativoDettaglioProperty(): array ->get(); foreach ($ecRows as $inc) { - $imp = (float) ($inc->importo ?? 0); - $yearRef = (string) ($inc->legacy_year ?? ''); - $humanYr = $yearRef !== '' ? $this->resolveHumanYearLabel($yearRef, $codStabile) : '—'; - $dtPag = ! empty($inc->data_pag) ? date('d/m/Y', strtotime((string) $inc->data_pag)) : '—'; + $imp = (float) ($inc->importo ?? 0); + $payload = ! empty($inc->payload) ? json_decode((string) $inc->payload, true) : []; + $annoInc = $payload['anno_incasso'] ?? ($inc->anno_incasso ?? ($inc->anno_rif ?? null)); + $dtPagRaw = $inc->data_pag ?? null; + $yearFromDate = ! empty($dtPagRaw) ? date('Y', strtotime((string) $dtPagRaw)) : null; + + $effectiveYear = (string) ($annoInc ?: ($yearFromDate ?: ($inc->legacy_year ?? ''))); + $humanYr = $effectiveYear !== '' ? $this->resolveHumanYearLabel($effectiveYear, $codStabile) : '—'; + $dtPag = ! empty($dtPagRaw) ? date('d/m/Y', strtotime((string) $dtPagRaw)) : '—'; $dettaglioIncassi[] = [ 'data_pagamento' => $dtPag,