1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Jobs/Invoice/CreateEInvoice.php

83 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;
2023-04-21 07:44:11 +02:00
use App\Utils\Ninja;
2023-03-12 12:13:59 +01:00
use App\Models\Invoice;
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-04-21 07:44:11 +02:00
use Illuminate\Support\Facades\App;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
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-04-21 07:44:11 +02:00
use App\Services\Invoice\EInvoice\FacturaEInvoice;
use App\Services\Invoice\EInvoice\ZugferdEInvoice;
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
{
2023-03-12 12:58:48 +01:00
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
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":
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:
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
}
}