48 lines
1.5 KiB
PHP
Executable File
48 lines
1.5 KiB
PHP
Executable File
<?php
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\IstatIndiceMensile;
|
|
use Illuminate\Console\Command;
|
|
|
|
class IstatSetIndiceCommand extends Command
|
|
{
|
|
protected $signature = 'istat:set-indice
|
|
{anno : Anno indice}
|
|
{mese : Mese indice (1-12)}
|
|
{indice : Valore indice}
|
|
{--series=FOI : Codice serie ISTAT}
|
|
{--source=manuale : Fonte}';
|
|
|
|
protected $description = 'Inserisce/aggiorna manualmente un indice ISTAT mensile';
|
|
|
|
public function handle(): int
|
|
{
|
|
$anno = (int) $this->argument('anno');
|
|
$mese = (int) $this->argument('mese');
|
|
$indice = (float) $this->argument('indice');
|
|
$series = strtoupper((string) $this->option('series'));
|
|
$source = (string) $this->option('source');
|
|
|
|
if ($anno < 1900 || $anno > 2300 || $mese < 1 || $mese > 12 || $indice <= 0) {
|
|
$this->error('Parametri non validi: verifica anno/mese/indice.');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
IstatIndiceMensile::query()->updateOrCreate(
|
|
[
|
|
'codice_serie' => $series,
|
|
'anno' => $anno,
|
|
'mese' => $mese,
|
|
],
|
|
[
|
|
'indice' => $indice,
|
|
'fonte' => $source,
|
|
'sincronizzato_il' => now(),
|
|
]
|
|
);
|
|
|
|
$this->info("Indice ISTAT salvato: {$series} {$anno}-" . str_pad((string) $mese, 2, '0', STR_PAD_LEFT) . " = {$indice}");
|
|
return self::SUCCESS;
|
|
}
|
|
}
|