diff --git a/app/Jobs/EDocument/CreateEDocument.php b/app/Jobs/EDocument/CreateEDocument.php new file mode 100644 index 0000000000..07e967c0b3 --- /dev/null +++ b/app/Jobs/EDocument/CreateEDocument.php @@ -0,0 +1,130 @@ +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 ""; + } + } +} diff --git a/app/Jobs/EInvoice/CreateEInvoice.php b/app/Jobs/EInvoice/CreateEInvoice.php deleted file mode 100644 index 204bb9e036..0000000000 --- a/app/Jobs/EInvoice/CreateEInvoice.php +++ /dev/null @@ -1,87 +0,0 @@ -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(); - - } - - } -} diff --git a/app/Livewire/PdfSlot.php b/app/Livewire/PdfSlot.php index b81d5d9d3e..81ad1fab61 100644 --- a/app/Livewire/PdfSlot.php +++ b/app/Livewire/PdfSlot.php @@ -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']; diff --git a/app/Services/EInvoicing/Standards/FacturaEInvoice.php b/app/Services/EDocument/Standards/FacturaEInvoice.php similarity index 100% rename from app/Services/EInvoicing/Standards/FacturaEInvoice.php rename to app/Services/EDocument/Standards/FacturaEInvoice.php diff --git a/app/Services/EInvoicing/Standards/FatturaPA.php b/app/Services/EDocument/Standards/FatturaPA.php similarity index 100% rename from app/Services/EInvoicing/Standards/FatturaPA.php rename to app/Services/EDocument/Standards/FatturaPA.php diff --git a/app/Services/EInvoicing/Standards/RoEInvoice.php b/app/Services/EDocument/Standards/RoEInvoice.php similarity index 100% rename from app/Services/EInvoicing/Standards/RoEInvoice.php rename to app/Services/EDocument/Standards/RoEInvoice.php diff --git a/app/Services/EInvoicing/Standards/ZugferdEInvoice.php b/app/Services/EDocument/Standards/ZugferdEDokument.php similarity index 99% rename from app/Services/EInvoicing/Standards/ZugferdEInvoice.php rename to app/Services/EDocument/Standards/ZugferdEDokument.php index c08cbe7d1f..ce295c74d3 100644 --- a/app/Services/EInvoicing/Standards/ZugferdEInvoice.php +++ b/app/Services/EDocument/Standards/ZugferdEDokument.php @@ -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; diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 5d13c90c47..c6adb7457b 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -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) diff --git a/app/Services/Pdf/PdfService.php b/app/Services/Pdf/PdfService.php index 81162798c0..4a579db80c 100644 --- a/app/Services/Pdf/PdfService.php +++ b/app/Services/Pdf/PdfService.php @@ -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(); diff --git a/tests/Unit/EInvoiceTest.php b/tests/Unit/EInvoiceTest.php index 4b8977dc50..08c8edf34c 100644 --- a/tests/Unit/EInvoiceTest.php +++ b/tests/Unit/EInvoiceTest.php @@ -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);