47 lines
1.7 KiB
PHP
47 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Stabile;
|
|
use App\Services\Contabilita\ContabilitaSyncService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class GesconSyncContabilitaStabileCommand extends Command
|
|
{
|
|
protected $signature = 'gescon:sync-contabilita-stabile
|
|
{stabile : Codice stabile legacy (es. 0013) o ID interno}
|
|
{--anno= : Anno gestione specifico da importare (es. 2026)}
|
|
{--all-years : Sincronizza tutte le annualità storiche presenti}
|
|
{--dry-run : Simula senza scrivere su database}';
|
|
|
|
protected $description = 'Importa e sincronizza la contabilità completa per uno stabile da archivio legacy (Fornitori, Operazioni, Rate, Incassi, Dett_tab e Bilanci).';
|
|
|
|
public function handle(ContabilitaSyncService $service): int
|
|
{
|
|
$stabileInput = (string) $this->argument('stabile');
|
|
$anno = $this->option('anno') ? (int) $this->option('anno') : null;
|
|
$allYears = (bool) $this->option('all-years');
|
|
$dryRun = (bool) $this->option('dry-run');
|
|
|
|
$this->info("🏛️ Avvio sincronizzazione contabile completa per stabile: {$stabileInput}...");
|
|
|
|
$res = $service->syncStabile(
|
|
stabileInput: $stabileInput,
|
|
targetYear: $anno,
|
|
allYears: $allYears,
|
|
dryRun: $dryRun,
|
|
log: function (string $msg) {
|
|
$this->line($msg);
|
|
}
|
|
);
|
|
|
|
if (! empty($res['success'])) {
|
|
$this->info("✅ Sincronizzazione contabile completata con successo!");
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$this->error("❌ Errore durante la sincronizzazione: " . ($res['error'] ?? 'Sconosciuto'));
|
|
return self::FAILURE;
|
|
}
|
|
}
|