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

147 lines
5.7 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\EDocument;
2024-03-20 12:54:18 +01:00
use App\Utils\Ninja;
use App\Models\Quote;
2024-03-10 16:02:15 +01:00
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\PurchaseOrder;
use Illuminate\Bus\Queueable;
2024-03-20 12:54:18 +01:00
use Illuminate\Support\Facades\App;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
2024-08-01 08:32:35 +02:00
use App\Services\EDocument\Standards\Peppol;
2024-03-20 12:54:18 +01:00
use horstoeko\zugferd\ZugferdDocumentBuilder;
2024-08-01 08:32:35 +02:00
use App\Services\EDocument\Standards\FatturaPA;
use App\Services\EDocument\Standards\RoEInvoice;
2024-03-20 12:54:18 +01:00
use App\Services\EDocument\Standards\OrderXDocument;
use App\Services\EDocument\Standards\FacturaEInvoice;
use App\Services\EDocument\Standards\ZugferdEDokument;
class CreateEDocument implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public $deleteWhenMissingModels = true;
public function __construct(private object $document, private bool $returnObject = false)
{
}
/**
* Execute the job.
*
* @return string|ZugferdDocumentBuilder
*/
public function handle(): string|ZugferdDocumentBuilder
{
/* Forget the singleton*/
App::forgetInstance('translator');
/* Init a new copy of the translator*/
$t = app('translator');
/* Set the locale*/
2024-03-13 10:34:36 +01:00
$settings_entity = ($this->document instanceof PurchaseOrder) ? $this->document->vendor : $this->document->client;
2024-03-20 12:54:18 +01:00
App::setLocale($settings_entity->locale());
/* Set customized translations _NOW_ */
2024-06-14 09:09:44 +02:00
if($this->document->client ?? false) {
2024-05-10 13:32:14 +02:00
$t->replace(Ninja::transformTranslations($this->document->client->getMergedSettings()));
2024-06-14 09:09:44 +02:00
}
$e_document_type = strlen($settings_entity->getSetting('e_invoice_type')) > 2 ? $settings_entity->getSetting('e_invoice_type') : "XInvoice_3_0";
$e_quote_type = strlen($settings_entity->getSetting('e_quote_type')) > 2 ? $settings_entity->getSetting('e_quote_type') : "OrderX_Extended";
2024-06-14 09:09:44 +02:00
if ($this->document instanceof Invoice) {
switch ($e_document_type) {
2024-08-01 08:32:35 +02:00
case "PEPPOL":
return (new Peppol($this->document))->toXml();
2024-04-07 23:26:18 +02:00
case "FACT1":
return (new RoEInvoice($this->document))->generateXml();
2024-04-10 14:07:03 +02:00
case "FatturaPA":
return (new FatturaPA($this->document))->run();
case "EN16931":
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":
2024-03-10 16:02:15 +01:00
$zugferd = (new ZugferdEDokument($this->document))->run();
2024-03-10 16:02:15 +01:00
return $this->returnObject ? $zugferd->xdocument : $zugferd->getXml();
case "Facturae_3.2":
case "Facturae_3.2.1":
case "Facturae_3.2.2":
2024-03-10 16:02:15 +01:00
return (new FacturaEInvoice($this->document, str_replace("Facturae_", "", $e_document_type)))->run();
default:
2024-03-10 16:02:15 +01:00
$zugferd = (new ZugferdEDokument($this->document))->run();
return $this->returnObject ? $zugferd : $zugferd->getXml();
}
2024-06-14 09:09:44 +02:00
} elseif ($this->document instanceof Quote) {
switch ($e_quote_type) {
2024-03-11 15:20:02 +01:00
case "OrderX_Basic":
case "OrderX_Comfort":
case "OrderX_Extended":
$orderx = (new OrderXDocument($this->document))->run();
return $this->returnObject ? $orderx->orderxdocument : $orderx->getXml();
default:
2024-03-11 15:20:02 +01:00
$orderx = (new OrderXDocument($this->document))->run();
return $this->returnObject ? $orderx->orderxdocument : $orderx->getXml();
}
2024-06-14 09:09:44 +02:00
} elseif ($this->document instanceof PurchaseOrder) {
switch ($e_quote_type) {
2024-03-11 15:20:02 +01:00
case "OrderX_Basic":
case "OrderX_Comfort":
case "OrderX_Extended":
$orderx = (new OrderXDocument($this->document))->run();
return $this->returnObject ? $orderx->orderxdocument : $orderx->getXml();
2024-03-10 16:02:15 +01:00
default:
2024-03-11 15:20:02 +01:00
$orderx = (new OrderXDocument($this->document))->run();
return $this->returnObject ? $orderx->orderxdocument : $orderx->getXml();
2024-03-10 16:02:15 +01:00
}
2024-06-14 09:09:44 +02:00
} elseif ($this->document instanceof Credit) {
2024-03-10 16:02:15 +01:00
switch ($e_document_type) {
case "EN16931":
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":
2024-03-10 16:02:15 +01:00
$zugferd = (new ZugferdEDokument($this->document))->run();
return $this->returnObject ? $zugferd->xdocument : $zugferd->getXml();
default:
2024-03-10 16:02:15 +01:00
$zugferd = (new ZugferdEDokument($this->document))->run();
return $this->returnObject ? $zugferd : $zugferd->getXml();
}
2024-06-14 09:09:44 +02:00
} else {
return "";
}
}
}