2024-06-12 16:14:24 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\EDocument;
|
|
|
|
|
|
|
|
use App\Models\Expense;
|
2024-06-22 15:02:53 +02:00
|
|
|
use App\Services\EDocument\Imports\ParseEDocument;
|
2024-06-22 18:52:25 +02:00
|
|
|
use App\Utils\TempFile;
|
2024-06-12 16:14:24 +02:00
|
|
|
use Exception;
|
2024-08-18 23:42:49 +02:00
|
|
|
use App\Models\Company;
|
2024-06-12 16:14:24 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2024-08-18 23:42:49 +02:00
|
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
|
|
use App\Services\EDocument\Imports\ZugferdEDocument;
|
2024-06-12 16:14:24 +02:00
|
|
|
|
|
|
|
class ImportEDocument implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable;
|
|
|
|
use InteractsWithQueue;
|
|
|
|
use Queueable;
|
|
|
|
use SerializesModels;
|
|
|
|
|
2024-08-18 23:42:49 +02:00
|
|
|
public $tries = 1;
|
2024-06-12 16:14:24 +02:00
|
|
|
|
2024-08-28 07:02:43 +02:00
|
|
|
public function __construct(private readonly string $file_content, private string $file_name, private string $file_mime_type, private Company $company)
|
2024-06-12 16:14:24 +02:00
|
|
|
{
|
2024-06-22 15:02:53 +02:00
|
|
|
|
2024-06-12 16:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return Expense
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function handle(): Expense
|
|
|
|
{
|
2024-06-22 18:52:25 +02:00
|
|
|
|
|
|
|
$file = TempFile::UploadedFileFromRaw($this->file_content, $this->file_name, $this->file_mime_type);
|
|
|
|
|
2024-08-28 07:02:43 +02:00
|
|
|
return (new ParseEDocument($file, $this->company))->run();
|
2024-06-22 18:52:25 +02:00
|
|
|
|
2024-06-12 16:14:24 +02:00
|
|
|
}
|
2024-08-18 23:42:49 +02:00
|
|
|
|
|
|
|
public function middleware()
|
|
|
|
{
|
|
|
|
return [new WithoutOverlapping($this->company->company_key)];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function failed($exception = null)
|
|
|
|
{
|
|
|
|
if ($exception) {
|
2024-08-28 07:02:43 +02:00
|
|
|
nlog("EXCEPTION:: ImportEDocument:: " . $exception->getMessage());
|
2024-06-12 16:14:24 +02:00
|
|
|
}
|
|
|
|
|
2024-08-18 23:42:49 +02:00
|
|
|
config(['queue.failed.driver' => null]);
|
2024-06-12 16:14:24 +02:00
|
|
|
}
|
|
|
|
}
|