Skip to content

Commit 20002d1

Browse files
authored
Merge pull request #97 from devmount/fix-invoice-xml-export
Fix XML export of invoices without VAT
2 parents 1125fea + a1297c0 commit 20002d1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

app/Services/InvoiceService.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ public static function generatePdf(Invoice $invoice): string {
310310

311311
/**
312312
* Generate invoice XML (EN16931 conform), save it and return path/filename
313+
* @see https://validator.invoice-portal.de for validation check
313314
*
314315
* @param Invoice $invoice Record to export
315316
* @return string
@@ -430,8 +431,12 @@ public static function generateEn16931Xml(Invoice $invoice): string {
430431
$x->text($invoice->vat);
431432
$x->endElement();
432433
$x->startElement('cac:TaxCategory');
433-
$x->writeElement('cbc:ID', 'S');
434-
$x->writeElement('cbc:Percent', $invoice->vat_rate*100);
434+
// See https://developer.vertexinc.com/einvoicing/docs/en-16931-tax-categories
435+
$x->writeElement('cbc:ID', $invoice->taxable ? 'S' : 'G');
436+
$x->writeElement('cbc:Percent', $invoice->taxable ? $invoice->vat_rate*100 : 0);
437+
if (!$invoice->taxable) {
438+
$x->writeElement('cbc:TaxExemptionReasonCode', 'VATEX-EU-G');
439+
}
435440
$x->startElement('cac:TaxScheme');
436441
$x->writeElement('cbc:ID', 'VAT');
437442
$x->endElement();
@@ -477,8 +482,8 @@ public static function generateEn16931Xml(Invoice $invoice): string {
477482
$x->writeElement('cbc:Description', $position->description);
478483
$x->writeElement('cbc:Name', trans_choice('position', 1, locale: $lang));
479484
$x->startElement('cac:ClassifiedTaxCategory');
480-
$x->writeElement('cbc:ID', 'S');
481-
$x->writeElement('cbc:Percent', $invoice->vat_rate*100);
485+
$x->writeElement('cbc:ID', $invoice->taxable ? 'S' : 'G');
486+
$x->writeElement('cbc:Percent', $invoice->taxable ? $invoice->vat_rate*100 : 0);
482487
$x->startElement('cac:TaxScheme');
483488
$x->writeElement('cbc:ID', 'VAT');
484489
$x->endElement();

0 commit comments

Comments
 (0)