1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Jobs/Invoice/CreateEInvoice.php

87 lines
2.5 KiB
PHP
Raw Normal View History

2023-03-12 12:13:59 +01:00
<?php
2023-04-21 07:44:44 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
2023-03-12 12:13:59 +01:00
namespace App\Jobs\Invoice;
use App\Models\Invoice;
2023-10-26 04:57:44 +02:00
use App\Services\Invoice\EInvoice\FacturaEInvoice;
use App\Services\Invoice\EInvoice\ZugferdEInvoice;
use App\Utils\Ninja;
2023-08-14 10:22:54 +02:00
use horstoeko\zugferd\ZugferdDocumentBuilder;
2023-03-12 12:58:48 +01:00
use Illuminate\Bus\Queueable;
2023-03-12 12:46:10 +01:00
use Illuminate\Contracts\Queue\ShouldQueue;
2023-03-12 12:58:48 +01:00
use Illuminate\Foundation\Bus\Dispatchable;
2023-10-26 04:57:44 +02:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
2023-03-12 12:13:59 +01:00
2023-04-21 07:44:11 +02:00
class CreateEInvoice implements ShouldQueue
2023-03-12 12:13:59 +01:00
{
2024-01-14 05:05:00 +01:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
2023-03-12 12:58:48 +01:00
2023-04-19 08:51:01 +02:00
public $deleteWhenMissingModels = true;
2023-08-14 10:22:54 +02:00
public function __construct(private Invoice $invoice, private bool $returnObject = false)
2023-03-12 12:13:59 +01:00
{
}
/**
* Execute the job.
*
* @return string|ZugferdDocumentBuilder
2023-03-12 12:13:59 +01:00
*/
2023-08-14 10:22:54 +02:00
public function handle(): string|ZugferdDocumentBuilder
2023-03-12 12:13:59 +01:00
{
2023-04-21 07:44:11 +02:00
/* Forget the singleton*/
App::forgetInstance('translator');
2023-04-21 07:18:17 +02:00
2023-04-21 07:44:11 +02:00
/* Init a new copy of the translator*/
$t = app('translator');
/* Set the locale*/
App::setLocale($this->invoice->client->locale());
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->invoice->client->getMergedSettings()));
2023-04-21 07:44:11 +02:00
$e_invoice_type = $this->invoice->client->getSetting('e_invoice_type');
2023-04-21 07:44:11 +02:00
switch ($e_invoice_type) {
case "EN16931":
2023-11-27 18:19:52 +01:00
case "XInvoice_3_0":
case "XInvoice_2_3":
case "XInvoice_2_2":
case "XInvoice_2_1":
case "XInvoice_2_0":
case "XInvoice_1_0":
case "XInvoice-Extended":
case "XInvoice-BasicWL":
case "XInvoice-Basic":
2023-08-16 11:55:35 +02:00
$zugferd = (new ZugferdEInvoice($this->invoice))->run();
return $this->returnObject ? $zugferd->xrechnung : $zugferd->getXml();
2023-04-21 07:44:11 +02:00
case "Facturae_3.2":
case "Facturae_3.2.1":
case "Facturae_3.2.2":
return (new FacturaEInvoice($this->invoice, str_replace("Facturae_", "", $e_invoice_type)))->run();
2023-04-20 23:54:35 +02:00
default:
2024-01-14 05:05:00 +01:00
2023-08-16 11:55:35 +02:00
$zugferd = (new ZugferdEInvoice($this->invoice))->run();
return $this->returnObject ? $zugferd : $zugferd->getXml();
2023-04-17 11:55:38 +02:00
}
2023-04-21 07:44:11 +02:00
}
}