mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 22:24:31 -04:00
rewrite EDocument service structure
This commit is contained in:
parent
b13e54f49b
commit
e586455be3
@ -129,7 +129,6 @@ class Kernel extends ConsoleKernel
|
|||||||
|
|
||||||
$schedule->command('queue:restart')->everyFiveMinutes()->withoutOverlapping();
|
$schedule->command('queue:restart')->everyFiveMinutes()->withoutOverlapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace App\Jobs\EDocument;
|
namespace App\Jobs\EDocument;
|
||||||
|
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Services\EDocument\Imports\ZugferdEDocument;
|
use App\Services\EDocument\Imports\ParseEDocument;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
@ -28,13 +28,10 @@ class ImportEDocument implements ShouldQueue
|
|||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
public $deleteWhenMissingModels = true;
|
public $deleteWhenMissingModels = true;
|
||||||
private string $file_name;
|
|
||||||
private readonly string $file_content;
|
|
||||||
|
|
||||||
public function __construct(string $file_content, string $file_name)
|
public function __construct(private readonly string $file_content, private string $file_name)
|
||||||
{
|
{
|
||||||
$this->file_content = $file_content;
|
|
||||||
$this->file_name = $file_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,20 +42,6 @@ class ImportEDocument implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(): Expense
|
public function handle(): Expense
|
||||||
{
|
{
|
||||||
if (str_contains($this->file_name, ".xml")){
|
return (new ParseEDocument($this->file_content, $this->file_name))->run();
|
||||||
switch (true) {
|
|
||||||
case stristr($this->file_content, "urn:cen.eu:en16931:2017"):
|
|
||||||
case stristr($this->file_content, "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"):
|
|
||||||
case stristr($this->file_content, "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.1"):
|
|
||||||
case stristr($this->file_content, "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.0"):
|
|
||||||
return (new ZugferdEDocument($this->file_content, $this->file_name))->run();
|
|
||||||
default:
|
|
||||||
throw new Exception("E-Invoice standard not supported");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Exception("File type not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
app/Services/EDocument/Imports/ParseEDocument.php
Normal file
52
app/Services/EDocument/Imports/ParseEDocument.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?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\Services\EDocument\Imports;
|
||||||
|
|
||||||
|
use App\Models\Expense;
|
||||||
|
use App\Services\AbstractService;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class ParseEDocument extends AbstractService
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function __construct(private string $file_content, private string $file_name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the service.
|
||||||
|
*
|
||||||
|
* @return Expense
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function run(): Expense
|
||||||
|
{
|
||||||
|
if (str_contains($this->file_name, ".xml")) {
|
||||||
|
switch (true) {
|
||||||
|
case stristr($this->file_content, "urn:cen.eu:en16931:2017"):
|
||||||
|
case stristr($this->file_content, "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"):
|
||||||
|
case stristr($this->file_content, "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.1"):
|
||||||
|
case stristr($this->file_content, "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_2.0"):
|
||||||
|
return (new ZugferdEDocument($this->file_content, $this->file_name))->run();
|
||||||
|
default:
|
||||||
|
throw new Exception("E-Invoice standard not supported");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception("File type not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user