61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Amministratore;
|
|
use App\Models\Stabile;
|
|
use App\Services\FattureElettroniche\CassettoFiscaleDownloadService;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class RunCassettoFiscaleDownload implements ShouldQueue
|
|
{
|
|
use Dispatchable;
|
|
use InteractsWithQueue;
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
public function __construct(
|
|
public int $amministratoreId,
|
|
public int $stabileId,
|
|
public string $dalYmd,
|
|
public string $alYmd,
|
|
public bool $metadati,
|
|
public int $userId,
|
|
/** @var array<string,mixed> */
|
|
public array $opts = [],
|
|
) {
|
|
}
|
|
|
|
public function handle(CassettoFiscaleDownloadService $svc): void
|
|
{
|
|
/** @var Amministratore|null $amministratore */
|
|
$amministratore = Amministratore::query()->find($this->amministratoreId);
|
|
/** @var Stabile|null $stabile */
|
|
$stabile = Stabile::query()->with('amministratore', 'rubrica')->find($this->stabileId);
|
|
|
|
if (! $amministratore || ! $stabile) {
|
|
return;
|
|
}
|
|
|
|
$dal = \DateTimeImmutable::createFromFormat('Y-m-d', $this->dalYmd) ?: null;
|
|
$al = \DateTimeImmutable::createFromFormat('Y-m-d', $this->alYmd) ?: null;
|
|
if (! $dal || ! $al) {
|
|
return;
|
|
}
|
|
|
|
$svc->downloadAndImport(
|
|
$amministratore,
|
|
$stabile,
|
|
$dal,
|
|
$al,
|
|
$this->metadati,
|
|
$this->userId,
|
|
$this->opts,
|
|
);
|
|
}
|
|
}
|