Die Generelle Funktionsweise besteht darin, zuerst die Daten aus der Tabellenkalkulation auf das interne Rechnungsformat in JSON abzubilden, und daraus im nächsten Schritt eine XML-E-Rechnung oder eine hybrid PDF/XML-Datei aus den JSON-Daten zu erzeugen. Es ist aber auch möglich, den Mapping-Schritt zu überspringen und die Rechnung direkt aus den JSON-Daten zu erzeugen.
Bevor begonnen werden kann, müssen die folgenden Voraussetzungen vorliegen:
contrib/templates/default-invoice.ods
.contrib/mappings/default-invoice.yaml
.E-Invoice-EU verwendet LibreOffice im Headless-Modus, um PDFs aus Tabellenkalkulations-Daten zu erzeugen. Wird dieses Feature nicht genutzt, muss LibreOffice nicht installiert sein. Alternativ kann immer eine PDF-Datei aus anderen Quellen zur Verfügung gestellt werden, statt sie aus der Tabellenkalkulation zu erzeugen.
Der API-Endpunkt für diese Funktion ist /api/invoice/create/:FORMAT
.
Ab Version 1.4.3 gilt der Endpunkt /invoice/transform-and-create
als veraltet. Er wird in der nächsten Version 2.x.x der Software entfernt. Der einzig notwendige Schritt ist /invoice/transform-and-create
mit /invoice/create
zu ersetzen. Die Parameter bleiben die gleichen.
In its most simple form, you can create an e-invoice from spreadsheet data like this:
curl -X POST http://localhost:3000/api/invoice/create/UBL \
-F spreadsheet=@contrib/templates/default-invoice.ods \
-F mapping=@contrib/mappings/default-invoice.yaml
http --form POST http://localhost:3000/api/invoice/create/UBL \
spreadsheet@contrib/templates/default-invoice.ods \
mapping@contrib/mappings/default-invoice.yaml
Das Format ist ein Pfad-Parameter, der nach dem Endpunkt-Pfad api/invoice/create
angegeben wird, in diesem Fall UBL
. Groß- und Kleinschreibung spielt bei der Angabe des Formats keine Rolle.
The invoice data (parameter spreadsheet
) is read from the spreadsheet file
contrib/templates/default-invoice.ods
. That spreadsheet data is then
mapped (parameter mapping
) with the mapping definition
contrib/mappings/default-invoice.yaml
.
It is possible to attach files with additional information. This works both for pure XML formats and for hybrid Factur-X/ZUGFeRD e-invoices. The example creates a Factur-X Extended invoice with three attachments:
curl -X POST \
http://localhost:3000/api/invoice/create/UBL \
-F lang=de \
-F spreadsheet=@contrib/templates/default-invoice.ods \
-F mapping=@contrib/mappings/default-invoice.yaml \
-F embedPDF=1 \
-F pdf=@invoice.pdf \
-F pdfID=1234567890 \
-F pdfDescription="Invoice as PDF." \
-F "attachment=@time-sheet.ods;type=application/vnd.oasis.opendocument.spreadsheet" \
-F "attachmentID=abc-123-xyz" \
-F attachmentDescription="Detailed description of hours spent." \
-F attachment=@payment-terms.pdf \
-F attachmentDescription="Our payment terms"
http --form POST http://localhost:3000/api/invoice/create/UBL \
lang=de \
spreadsheet@contrib/templates/default-invoice.ods \
mapping@contrib/mappings/default-invoice.yaml \
embedPDF=1 \
pdf@invoice.pdf \
pdfID=1234567890 \
pdfDescription="Invoice as PDF." \
attachment@time-sheet.ods\;type=application/vnd.oasis.opendocument.spreadsheet \
attachmentID=abc-123-xyz \
attachmentDescription="Detailed description of hours spent." \
attachment@payment-terms.pdf \
attachmentDescription="Our payment terms"
Die Bedeutungen der einzelnen URL-Parameter sind:
lang
: This is used to determine the language for some canned texts.spreadsheet
: The spreadsheet with the invoice data.mapping
: The mapping definition for the invoice data.embedPDF
: Embed a PDF version of the e-invoice in the XML; ignored for Factur-X/ZUGFeRD.pdf
: The PDF version of the e-invoice. If embedding a PDF was requested but the parameter pdf
is missing, the PDF is generated from the spreadsheet file (parameter spreadsheet
).pdfID
: The attachment id of the embedded PDF, defaults to the filename.pdfDescription
: An optional description of that attachment.attachment
: Optionally, an additional file to be embedded.attachmentID
: Optionally, the id of the attachment, defaults to the filename.attachmentDescription
: An optional description of the attachment.The last group of parameters attachment
, attachmentID
is used twice for
two additional attachments. The last attachment does not have an ID.
If the PDF is not provided with the parameter pdf
, it is generated from
the spreadsheet file (parameter spreadsheet
). In that case you must
ensure that the LibreOffice executable is found. The software tries to guess
the correct location. If that fails, it must be either in your
$PATH
or you have configured its
location.
Jeder Anhang an die E-Rechnung kann eine optionale ID und eine optionale Beschreibung erhalten. Der Service „sieht” allerdings nur 3 Listen der URL-Parameter attachment
, attachmentID
und attachmentDescription
, selbst wenn sie pro Anhang gruppiert wurden.
Wird der Paramter Attachment
viermal, attachmentID
zweimal und attachmentDescription
dreimal angegeben, ganz gleich in welcher Reihenfolge, werden die folgenden Anhänge eingebettet:
Attachment | Filename | ID | Description |
---|---|---|---|
Attachment #1 | attachment #1 |
attachmentID #1 |
attachmentDescription #1 |
Attachment #2 | attachment #2 |
attachmentID #2 |
attachmentDescription #2 |
Attachment #3 | attachment #3 |
- | attachmentDescription #3 |
Attachment #4 | attachment #4 |
- | - |
Normalerweise wird man diesen Komplikationen aus dem Wege gehen wollen und entweder für jeden Anhang eine ID und/oder Beschreibung übergeben oder für keinen.
Die Erzeugung von Factur-X/ZUGFeRD unterscheidet sich eigentlich nur darin, dass die Ausgabe binär ist, und deshalb in eine Datei umgeleitet werden sollte.
curl -X POST http://localhost:3000/api/invoice/create/Factur-X-Extended \
-F spreadsheet=@contrib/templates/default-invoice.ods \
-F mapping=@contrib/mappings/default-invoice.yaml \
--output e-invoice.pdf
http --form POST http://localhost:3000/api/invoice/create/Factur-X-Extended \
spreadsheet@contrib/templates/default-invoice.ods \
mapping@contrib/mappings/default-invoice.yaml \
--output e-invoice.pdf
This would create a Factur-X/ZUGFeRD e-invoice with the profile Extended.
You must also keep in mind that the hybrid Factur-X/ZUGFeRD format requires
a PDF version of the input. You must either specify it yourself with the
parameter pdf
or LibreOffice
must be available so that it can be generated
from the spreadsheet file spreadsheet
.
Depending on what shell you are using, redirecting standard output messes up the generated PDF. More precisely, it converts all newline characters (`LF`) to `CRLF` which corrupts the binary file. It also encodes it as UTF-16-LE, a 2-byte character encoding, which is again wrong for binary files. You can avoid that by using the option `-o` resp. `--output`. See https://github.com/gflohr/e-invoice-eu/issues/96#issuecomment-2708171823 for more information!
You can bypass the mapping step and generate
the invoice directly from JSON. All you have to do is to omit the parameter
mapping
.
Beispiel:
curl -X POST http://localhost:3000/api/invoice/create/UBL \
-F invoice=@contrib/data/default-invoice.json
http --form POST http://localhost:3000/api/invoice/create/UBL \
invoice@contrib/data/default-invoice.json
In diesem Fall wird ein Peppol-UBL-Rechnung erzeugt.
Dieser Endpunkt erlaubt exakt die gleichen URL-Parameter wie der Endpunkt für die Erzeugung von Rechnungen aus Tabellen-Daten, bis auf den Parameter mapping
der hier keinen Sinn ergibt.
Mit dem API-Endpunkt /api/mapping/transform/:FORMAT
lassen sich Rechnungsdaten im internen Format aus einer Tabellendatei erzeugen. Das ergibt vermutlich nur für Informationszwecke Sinn, weil JSON kein erlaubtes Format für E-Rechnungen ist.
Beispiel:
curl -X POST http://localhost:3000/api/mapping/transform/UBL \
-F spreadsheet=@contrib/templates/default-invoice.ods \
-F mapping=@contrib/mappings/default-invoice.yaml
http --form POST http://localhost:3000/api/mapping/transform/UBL \
spreadsheet@contrib/templates/default-invoice.ods \
mapping@contrib/mappings/default-invoice.yaml
Dieser Endpunkt erlaubt nur zwei Parameter:
spreadsheet
: The spreadsheet with the invoice spreadsheet.mapping
: The mapping definition for the invoice data.Dieser Endpunkt bildet Daten aus einer Tabellendatei in das [interne Format](/e-invoice-eu/de/docs/details/internes-format/) ab, was eigentlich unabhängig vom Ausgabeformat sein sollte. Das Format muss dennoch angegeben werden, weil die Transformierung auch die Customization-ID im Feld `/ubl:Invoice/cbc:customizationID` einfügt. Wird die Customization-ID mit der Tabelle übergeben, kann ein beliebiges Format angegeben werden, weil eine explizit angegebene Customization-ID nie überschrieben wird.