Class AbstractEinvoice() Professional

Abstract base class for EN 16931 electronic invoices.

Description

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.

Constructors
:new()
Initializes a new invoice object.
Methods
:acceptsBuyerCountry()
Checks whether a buyer country is valid for the scenario.
:addAllowance()
Adds a document-level allowance (BG-20).
:addCharge()
Adds a document-level charge (BG-21).
:addLineItem()
Adds an invoice line (BG-25).
:addNote()
Adds a free-text note (BG-1).
:addRecipient()
Adds a buyer, deliver-to or payee party (BG-7/BG-10/BG-13).
:getAllowanceCharges()
Returns the document-level allowances and charges (BG-20/BG-21).
:getBillingPeriod()
Returns the invoicing period (BG-14).
:getBuyer()
Returns the buyer (BG-7).
:getBuyerReference()
Returns the buyer reference (BT-10).
:getContractReference()
Returns the contract reference (BT-12).
:getCurrency()
Returns the invoice currency (BT-5).
:getDeliveryDate()
Returns the actual delivery date (BT-72).
:getIssueDate()
Returns the issue date (BT-2).
:getLastWarnings()
Returns the warnings of the last serialization.
:getLines()
Returns the invoice lines (BG-25).
:getNotes()
Returns the free-text notes (BG-1).
:getNumber()
Returns the invoice number (BT-1).
:getOrderReference()
Returns the purchase order reference (BT-13).
:getPayee()
Returns the payee (BG-10).
:getPaymentMeans()
Returns the payment means (BG-16).
:getPaymentTerms()
Returns the payment terms (BT-9/BT-20).
:getPrecedingInvoice()
Returns the preceding invoice reference (BG-3).
:getPrepaidAmount()
Returns the prepaid amoun (BT-113)t.
:getProfile()
Returns the country profile used for the invoice.
:getScenario()
Returns the scenario of the invoice.
:getSellerCountry()
Returns the country code of the seller.
:getSeller()
Returns the seller (BG-4).
:getShipTo()
Returns the deliver-to party (BG-13).
:getTypeCode()
Returns the invoice type code (BT-2).
:requireEuSeller()
Reports an error if the seller is not located in the EU.
:resolveVatCategory()
Resolves the VAT category and rate of an invoice line.
:setBillingPeriod()
Sets the invoicing period (BG-14).
:setBuyerReference()
Sets the buyer reference (BT-10).
:setContractReference()
Sets the contract reference (BT-12).
:setCurrency()
Sets the invoice currency (BT-5).
:setDeliveryDate()
Sets the actual delivery date (BT-27).
:setIssueDate()
Sets the issue date (BT-2).
:setNumber()
Sets the invoice number (BT-1).
:setOrderReference()
Sets the purchase order reference (BT-13).
:setPaymentMeans()
Sets the payment means (BG-16).
:setPaymentTerms()
Sets the payment terms (BT-9/BT-20).
:setPrecedingInvoice()
Sets the preceding invoice reference (BG-3).
:setPrepaidAmount()
Sets the prepaid amount (BT-113).
:setProfile()
Sets the country profile for the invoice.
:setSeller()
Sets the seller (BG-4).
:setTypeCode()
Sets the invoice type code (BT-3).
:toModel()
Builds the calculated invoice model.
:toXRechnung()
Creates an XRechnung XML document.
:toZugferd()
Creates a ZUGFeRD XML document.
:validateScenario()
Validates the scenario-specific rules.
:validate()
Validates the invoice.
Examples
Build, validate and serialize an invoice
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 

Feedback

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.