fix(unita-immobiliare): resolve payment management years dynamically from payload.anno_incasso and data_pag (task-d095b0e23b)

This commit is contained in:
michele 2026-08-29 01:01:54 +02:00
parent 3c0df5cea4
commit ce12386c8e

View File

@ -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,