Class AbstractEinvoice() Professional
Abstract base class for EN 16931 electronic invoices.
The AbstractEinvoice class implements the data model and the calculation engine shared by all electronic invoices that conform to the European standard EN 16931. It provides the builder methods, the calculation and validation logic, and the serialization into the XRechnung and ZUGFeRD formats.
The invoice data is assigned through fluent builder methods such as :setSeller(), :addRecipient(), :addLineItem(), :setPaymentMeans() and :setPaymentTerms(). Each of these methods returns the invoice object, so calls can be chained.
The method :toModel() resolves the VAT category and rate of each invoice line, builds the VAT breakdown and calculates the invoice totals. The method :validate() checks the invoice against the EU content rules, the EN 16931 rules, the rules of the active scenario and the national rules of the seller's country profile.
The methods :toXRechnung() and :toZugferd() produce the final XML document.
The AbstractEinvoice class cannot be instantiated directly. Instead, one of the following scenario subclasses must be used. The scenario is always determined from the point of view of the seller:
DomesticEinvoice - The buyer is located in the same country as the seller. The seller must be located in the EU.
IntraEuEinvoice - The buyer is located in another EU member state. The seller must be located in the EU.
ExportEinvoice - The buyer is located outside the EU. The seller must be located in the EU.
ManualEinvoice - The VAT category and rate are specified explicitly for each line. The seller can be located in any country.
Alternatively, the methods EinvFactory():createInvoice() and EinvFactory():createManualInvoice() can be used. These methods select and create the appropriate scenario subclass automatically.
All country-specific VAT information, such as VAT rates, mandatory legal statements and national checks, is provided by the EinvoiceCountryProfile() object of the seller's country. The profile is looked up automatically through the EinvoiceProfileRegistry() class.
LOCAL oInvoice, oResult, cXml
oInvoice := EinvFactory():createInvoice( oSeller, oBuyer, "INV-2024-00011", Date() )
oInvoice:addLineItem( EinvoiceLineItem():new():setName("Widget"):setQuantity(2):setPrice(9.5) )
oResult := oInvoice:validate()
IF oResult:Valid
cXml := oInvoice:toXRechnung()
ENDIF
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.