diff --git a/app/Console/Commands/GesconImportStabiliBankNotesCommand.php b/app/Console/Commands/GesconImportStabiliBankNotesCommand.php index 06c2f58..35129d5 100644 --- a/app/Console/Commands/GesconImportStabiliBankNotesCommand.php +++ b/app/Console/Commands/GesconImportStabiliBankNotesCommand.php @@ -63,6 +63,7 @@ public function handle(): int if (count($data) === count($header)) { $row = array_combine($header, $data); $codLegacy = sprintf('%04d', (int) ($row['cod_stabile'] ?? 0)); + $cfLegacy = trim((string) ($row['codice_fisc'] ?? '')); $den = trim((string) ($row['denominazione'] ?? '')); $note1 = trim((string) ($row['note1'] ?? '')); $note2 = trim((string) ($row['Note'] ?? '')); @@ -83,16 +84,56 @@ public function handle(): int $numCcp2 = trim((string) ($row['num_ccp_2'] ?? '')); $ibanPosta2 = trim((string) ($row['IBAN_Posta_2'] ?? '')); - $stabile = Stabile::query() - ->where('codice_stabile', $codLegacy) - ->orWhere('cod_stabile', $codLegacy) - ->orWhere('codice_stabile', ltrim($codLegacy, '0')) - ->first(); + $stabile = null; + if ($cfLegacy !== '') { + $stabile = Stabile::query()->where('codice_fiscale', $cfLegacy)->first(); + } + if (! $stabile) { + $stabile = Stabile::query() + ->where('codice_stabile', $codLegacy) + ->orWhere('cod_stabile', $codLegacy) + ->orWhere('codice_stabile', ltrim($codLegacy, '0')) + ->first(); + } if ($stabile) { $noteFull = array_filter([$note1, $note2]); $noteStr = implode("\n", $noteFull); + // Leggi anagr_casse dal file generale_stabile.mdb dello stabile se presente + $casseAnagr = []; + $stabileDirCandidates = [ + "/mnt/gescon-archives/gescon/{$codLegacy}/generale_stabile.mdb", + "/mnt/gescon-archives/gescon/" . sprintf('%04d', (int)$stabile->codice_stabile) . "/generale_stabile.mdb", + ]; + foreach ($stabileDirCandidates as $gsMdb) { + if (file_exists($gsMdb) && is_readable($gsMdb)) { + $pCasse = new \Symfony\Component\Process\Process(['mdb-export', $gsMdb, 'anagr_casse']); + $pCasse->run(); + if ($pCasse->isSuccessful() && $pCasse->getOutput()) { + $cStream = fopen('php://memory', 'r+'); + fwrite($cStream, $pCasse->getOutput()); + rewind($cStream); + $cHeader = fgetcsv($cStream); + if ($cHeader) { + while (($cData = fgetcsv($cStream)) !== false) { + if (count($cData) === count($cHeader)) { + $cRow = array_combine($cHeader, $cData); + $casseAnagr[] = [ + 'id_cassa' => (int) ($cRow['Id_cassa'] ?? 0), + 'codice' => trim((string) ($cRow['Codice'] ?? '')), + 'descrizione' => trim((string) ($cRow['Descrizione'] ?? '')), + 'saldo_iniziale_euro'=> (float) ($cRow['Saldo_iniziale_EURO'] ?? 0), + ]; + } + } + } + fclose($cStream); + } + break; + } + } + $bancherieAdv = [ 'banca_1' => [ 'banca' => $banca1, @@ -116,6 +157,7 @@ public function handle(): int 'num_ccp' => $numCcp2, 'iban' => $ibanPosta2, ], + 'anagr_casse' => $casseAnagr, ]; $existingAdv = is_array($stabile->configurazione_avanzata) ? $stabile->configurazione_avanzata : []; @@ -123,21 +165,21 @@ public function handle(): int $stabile->update([ 'note' => $noteStr ?: $stabile->note, - 'banca_principale' => $banca1 ?: $stabile->banca_principale, - 'iban_principale' => $ibanBanca1 ?: $stabile->iban_principale, + 'banca_principale' => $banca1 ?: ($ibanPosta1 ? 'Poste Italiane' : $stabile->banca_principale), + 'iban_principale' => $ibanBanca1 ?: ($ibanPosta1 ?: $stabile->iban_principale), 'banca_secondaria' => $banca2 ?: $stabile->banca_secondaria, 'iban_secondario' => ($ibanBanca2 ?: $ibanPosta1) ?: $stabile->iban_secondario, 'configurazione_avanzata'=> $mergedAdv, ]); $updated++; - $this->line(" ✓ Stabile {$codLegacy} ({$den}): Note e Conti Correnti aggiornati."); + $this->line(" ✓ Stabile {$stabile->codice_stabile} ({$den}): Note, IBAN e " . count($casseAnagr) . " Casse (CCB/CCP/CON) sincronizzate."); } } } fclose($stream); - $this->info("Completata sincronizzazione conti correnti per {$updated} stabili!"); + $this->info("Completata sincronizzazione conti correnti e tabelle anagr_casse per {$updated} stabili!"); return self::SUCCESS; } } diff --git a/resources/views/filament/pages/super-admin/amministratori.blade.php b/resources/views/filament/pages/super-admin/amministratori.blade.php index 3c87288..bfd9086 100644 --- a/resources/views/filament/pages/super-admin/amministratori.blade.php +++ b/resources/views/filament/pages/super-admin/amministratori.blade.php @@ -219,9 +219,12 @@ class="inline-flex items-center gap-1 rounded-lg bg-amber-500 px-4 py-2 text-xs

Stabili condominiali gestiti ed archivio ditte accreditati riservati per lo studio.

- {{-- TABELLA STABILI CONDOMINIALI GESTITI --}} + {{-- TABELLA STABILI CONDOMINIALI GESTITI DYNAMICAMENTE --}} + @php + $stabiliReal = \App\Models\Stabile::query()->orderBy('codice_stabile')->get(); + @endphp
-

🏢 Stabili Condominiali Gestiti dallo Studio (12 Stabili):

+

🏢 Stabili Condominiali Gestiti dallo Studio ({{ count($stabiliReal) }} Stabili):

@@ -230,27 +233,41 @@ class="inline-flex items-center gap-1 rounded-lg bg-amber-500 px-4 py-2 text-xs + - - - - - - - - - - - - - - - - - - + @foreach($stabiliReal as $st) + @php + $adv = is_array($st->configurazione_avanzata) ? $st->configurazione_avanzata : []; + $casse = $adv['conti_correnti']['anagr_casse'] ?? []; + @endphp + + + + + + + + @endforeach
DENOMINAZIONE STABILE CODICE FISCALE BANCA PRINCIPALE & IBANCASSE (anagr_casse)
0010CATONE 34 - GERMANICO 85 - GRACCHI 3280123456789ISTITUTO SAN PAOLO: IT26Z0306905077100000013753
0013OTTAVIANO 105 - GIULIO CESARE 17180987654321ISTITUTO SAN PAOLO: IT26Z0306905077100000013753
0016GERMANICO 9697112233445BANCA DEL FUCINO: IT48W0312403203000000233378
{{ $st->codice_stabile }}{{ $st->denominazione }}{{ $st->codice_fiscale ?: '-' }} + @if($st->iban_principale) + {{ $st->banca_principale ?: 'Banca' }}: {{ $st->iban_principale }} + @else + Nessun IBAN registrato + @endif + + @if(!empty($casse)) +
+ @foreach($casse as $c) + + {{ $c['codice'] }} + + @endforeach +
+ @else + - + @endif +