51 lines
1.8 KiB
PHP
Executable File
51 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Services\GesconImport\EssentialImportService;
|
|
use App\Models\Amministratore;
|
|
|
|
class GesconEssentialImport extends Command
|
|
{
|
|
protected $signature = 'gescon:essential-import {--stabile=} {--amministratore-id=} {--path=} {--dry} {--force-months} {--only=}';
|
|
protected $description = 'Import rapido: stabili -> gestioni -> banche (archivi essenziali)';
|
|
|
|
public function handle(): int
|
|
{
|
|
$legacy = (string)$this->option('stabile');
|
|
if (!$legacy) {
|
|
$this->error('Specificare --stabile=0000');
|
|
return self::FAILURE;
|
|
}
|
|
$ammId = $this->option('amministratore-id');
|
|
$amm = $ammId ? Amministratore::find($ammId) : Amministratore::first();
|
|
if (!$amm) {
|
|
$this->error('Amministratore non trovato');
|
|
return self::FAILURE;
|
|
}
|
|
$svc = new EssentialImportService();
|
|
$opts = [
|
|
'path' => $this->option('path') ?: null,
|
|
'dry' => (bool)$this->option('dry'),
|
|
'force_months' => (bool)$this->option('force-months'),
|
|
];
|
|
$only = $this->option('only');
|
|
$results = [];
|
|
if ($only === 'stabili') {
|
|
$results[] = $svc->importStabileCore($amm, $legacy, $opts);
|
|
} elseif ($only === 'gestioni') {
|
|
$results[] = $svc->importGestioni($amm, $legacy, $opts);
|
|
} elseif ($only === 'banche') {
|
|
$results[] = $svc->importBanche($amm, $legacy, $opts);
|
|
} else {
|
|
$results = $svc->runAll($amm, $legacy, $opts);
|
|
}
|
|
$this->info('Import essenziale completato.');
|
|
foreach ($results as $r) {
|
|
$this->line(($r['step'] ?? '?') . ': ' . json_encode($r));
|
|
}
|
|
return self::SUCCESS;
|
|
}
|
|
}
|