1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Rename some files, added additional checks for more file types in CreateEDocument.php

This commit is contained in:
Lars Kusch 2024-03-10 08:13:34 +01:00
parent 8fe73e9be9
commit 99d6ac5a70
10 changed files with 140 additions and 97 deletions

View File

@ -0,0 +1,130 @@
<?php
/**
* 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
*/
namespace App\Jobs\EDocument;
use App\Models\Invoice;
use App\Models\PurchaseOrder;
use App\Models\Quote;
use App\Services\EInvoicing\Standards\FacturaEInvoice;
use App\Services\EInvoicing\Standards\ZugferdEDokument;
use App\Utils\Ninja;
use horstoeko\zugferd\ZugferdDocumentBuilder;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
use function App\Jobs\Invoice\app;
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*/
App::setLocale($this->document->client->locale());
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->document->client->getMergedSettings()));
$e_document_type = $this->document->client->getSetting('e_invoice_type');
if ($this->document instanceof Invoice){
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":
$zugferd = (new ZugferdEDokument($this->invoice))->run();
return $this->returnObject ? $zugferd->xrechnung : $zugferd->getXml();
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();
default:
$zugferd = (new ZugferdEDokument($this->invoice))->run();
return $this->returnObject ? $zugferd : $zugferd->getXml();
}
}
elseif ($this->document instanceof Quote){
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":
$zugferd = (new ZugferdEDokument($this->invoice))->run();
return $this->returnObject ? $zugferd->xrechnung : $zugferd->getXml();
default:
$zugferd = (new ZugferdEDokument($this->invoice))->run();
return $this->returnObject ? $zugferd : $zugferd->getXml();
}
}
elseif ($this->document instanceof PurchaseOrder){
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":
$zugferd = (new ZugferdEDokument($this->invoice))->run();
return $this->returnObject ? $zugferd->xrechnung : $zugferd->getXml();
default:
$zugferd = (new ZugferdEDokument($this->invoice))->run();
return $this->returnObject ? $zugferd : $zugferd->getXml();
}
}
else{
return "";
}
}
}

View File

@ -1,87 +0,0 @@
<?php
/**
* 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
*/
namespace App\Jobs\EInvoice;
use App\Models\Invoice;
use App\Services\EInvoicing\Standards\FacturaEInvoice;
use App\Services\EInvoicing\Standards\ZugferdEInvoice;
use App\Utils\Ninja;
use horstoeko\zugferd\ZugferdDocumentBuilder;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
use function App\Jobs\Invoice\app;
class CreateEInvoice implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public $deleteWhenMissingModels = true;
public function __construct(private Invoice $invoice, 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*/
App::setLocale($this->invoice->client->locale());
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->invoice->client->getMergedSettings()));
$e_invoice_type = $this->invoice->client->getSetting('e_invoice_type');
switch ($e_invoice_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":
$zugferd = (new ZugferdEInvoice($this->invoice))->run();
return $this->returnObject ? $zugferd->xrechnung : $zugferd->getXml();
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();
default:
$zugferd = (new ZugferdEInvoice($this->invoice))->run();
return $this->returnObject ? $zugferd : $zugferd->getXml();
}
}
}

View File

@ -12,7 +12,7 @@
namespace App\Livewire;
use App\Jobs\EInvoice\CreateEInvoice;
use App\Jobs\EDocument\CreateEDocument;
use App\Libraries\MultiDB;
use App\Models\CreditInvitation;
use App\Models\InvoiceInvitation;
@ -113,7 +113,7 @@ class PdfSlot extends Component
$file_name = $this->entity->numberFormatter().'.xml';
$file = (new CreateEInvoice($this->entity))->handle();
$file = (new CreateEDocument($this->entity))->handle();
$headers = ['Content-Type' => 'application/xml'];

View File

@ -18,7 +18,7 @@ use horstoeko\zugferd\codelists\ZugferdDutyTaxFeeCategories;
use horstoeko\zugferd\ZugferdDocumentBuilder;
use horstoeko\zugferd\ZugferdProfiles;
class ZugferdEInvoice extends AbstractService
class ZugferdEDokument extends AbstractService
{
public ZugferdDocumentBuilder $xrechnung;

View File

@ -12,7 +12,7 @@
namespace App\Services\Invoice;
use App\Events\Invoice\InvoiceWasArchived;
use App\Jobs\EInvoice\CreateEInvoice;
use App\Jobs\EDocument\CreateEDocument;
use App\Jobs\Entity\CreateRawPdf;
use App\Jobs\Inventory\AdjustProductInventory;
use App\Libraries\Currency\Conversion\CurrencyApi;
@ -201,7 +201,7 @@ class InvoiceService
public function getEInvoice($contact = null)
{
return (new CreateEInvoice($this->invoice))->handle();
return (new CreateEDocument($this->invoice))->handle();
}
public function sendEmail($contact = null)

View File

@ -11,7 +11,7 @@
namespace App\Services\Pdf;
use App\Jobs\EInvoice\CreateEInvoice;
use App\Jobs\EDocument\CreateEDocument;
use App\Models\Company;
use App\Models\CreditInvitation;
use App\Models\Invoice;
@ -216,7 +216,7 @@ class PdfService
{
try {
$e_rechnung = (new CreateEInvoice($this->config->entity, true))->handle();
$e_rechnung = (new CreateEDocument($this->config->entity, true))->handle();
$pdfBuilder = new ZugferdDocumentPdfBuilder($e_rechnung, $pdf);
$pdfBuilder->generateDocument();

View File

@ -9,7 +9,7 @@
* @license https://www.elastic.co/licensing/elastic-license
*/
use App\Jobs\EInvoice\CreateEInvoice;
use App\Jobs\EDocument\CreateEDocument;
use App\Jobs\Entity\CreateRawPdf;
use horstoeko\zugferd\ZugferdDocumentReader;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -41,7 +41,7 @@ class EInvoiceTest extends TestCase
$this->company->e_invoice_type = "EN16931";
$this->invoice->client->routing_id = 'DE123456789';
$this->invoice->client->save();
$e_invoice = (new CreateEInvoice($this->invoice))->handle();
$e_invoice = (new CreateEDocument($this->invoice))->handle();
$this->assertIsString($e_invoice);
}
@ -54,7 +54,7 @@ class EInvoiceTest extends TestCase
$this->invoice->client->routing_id = 'DE123456789';
$this->invoice->client->save();
$e_invoice = (new CreateEInvoice($this->invoice))->handle();
$e_invoice = (new CreateEDocument($this->invoice))->handle();
$document = ZugferdDocumentReader::readAndGuessFromContent($e_invoice);
$document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest);
$this->assertEquals($this->invoice->number, $documentno);