47 lines
2.0 KiB
PHP
47 lines
2.0 KiB
PHP
<?php
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\Catalog\ContabilitaMysqlSerialImportService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class ImportNcomSerialsCommand extends Command
|
|
{
|
|
protected $signature = 'fornitore:import-mysql-serials
|
|
{--supplier=NCOMSRL : Codice fornitore in contabilità MySQL (es. NCOMSRL)}
|
|
{--fornitore-id= : ID del fornitore locale in NetGescon}
|
|
{--dry-run : Esegue la scansione senza persistere modifiche}';
|
|
|
|
protected $description = 'Importa prodotti, codici articolo, prezzi e seriali (RMA) dalla contabilità MySQL esterna.';
|
|
|
|
public function handle(ContabilitaMysqlSerialImportService $importer): int
|
|
{
|
|
$supplier = (string) $this->option('supplier');
|
|
$fornitoreId = $this->option('fornitore-id') ? (int) $this->option('fornitore-id') : null;
|
|
$dryRun = (bool) $this->option('dry-run');
|
|
|
|
$this->info("Inizio importazione seriali e prodotti per '{$supplier}' da contabilità MySQL...");
|
|
|
|
try {
|
|
$stats = $importer->importForSupplier($supplier, $fornitoreId, $dryRun);
|
|
|
|
$this->table(['Metrica', 'Valore'], [
|
|
['Codice Fornitore', $stats['supplier_code']],
|
|
['ID Fornitore Locale', $stats['fornitore_id']],
|
|
['Fatture Trovate', $stats['invoices_count']],
|
|
['Righe Documento Elaborate', $stats['lines_processed']],
|
|
['Prodotti Creati', $stats['products_created']],
|
|
['Codici Articolo / Identifier Creati', $stats['identifiers_created']],
|
|
['Seriali Nuovi Inseriti', $stats['serials_created']],
|
|
['Seriali Aggiornati', $stats['serials_updated']],
|
|
['Modalità Dry-Run', $stats['dry_run'] ? 'Sì' : 'No'],
|
|
]);
|
|
|
|
$this->info("Importazione completata con successo!");
|
|
return self::SUCCESS;
|
|
} catch (\Throwable $e) {
|
|
$this->error("Errore durante l'importazione: " . $e->getMessage());
|
|
return self::FAILURE;
|
|
}
|
|
}
|
|
}
|