1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Jobs/EDocument/ImportEDocument.php

70 lines
1.7 KiB
PHP
Raw Normal View History

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
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);
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) {
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
}
}