Documentation
¶
Overview ¶
Package einvoice provides the domain model for German E-Invoices (E-Rechnung) compliant with EN 16931.
The Invoice type is the entry point. Serialize it to XRechnung 3.0 / CII XML with the cii package, and embed that XML into a PDF/A-3 (ZUGFeRD / Factur-X) with the zugferd package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllowanceCharge ¶ added in v0.2.0
type AllowanceCharge struct {
Amount decimal.Decimal
IsCharge bool // false = allowance (reduces total), true = charge (adds)
TaxCategory TaxCategory
TaxRate decimal.Decimal
Reason string
}
AllowanceCharge is a document-level allowance (discount) or charge (BG-20 / BG-21). Its TaxCategory and TaxRate must match the goods they apply to so the amount lands in the right VAT breakdown group. Reason is required by XRechnung.
type Invoice ¶
type Invoice struct {
Number string
IssueDate time.Time
DueDate time.Time
DeliveryDate time.Time // BT-72 Leistungs-/Lieferdatum (UStG mandatory)
// DeliveryCountryCode is the deliver-to country (BT-80). Mandatory for
// intra-community supply (category K); defaults to the buyer's country.
DeliveryCountryCode string
Currency string
Note string
BuyerReference string
Seller Party
Buyer Party
Payment Payment
LineItems []LineItem
AllowanceCharges []AllowanceCharge // document-level allowances/charges (BG-20/21)
}
Example ¶
package main
import (
"fmt"
einvoice "github.com/dotwavehq/go-einvoice"
"github.com/dotwavehq/go-einvoice/cii"
"github.com/shopspring/decimal"
)
func main() {
inv := &einvoice.Invoice{
Number: "RE-2025-1001",
Currency: "EUR",
Seller: einvoice.Party{Name: "Seller GmbH", CountryCode: "DE", VATID: "DE123456789"},
Buyer: einvoice.Party{Name: "Buyer AG", CountryCode: "DE"},
LineItems: []einvoice.LineItem{{
Description: "Consulting",
Quantity: decimal.NewFromInt(10),
UnitCode: "HUR",
UnitPrice: decimal.RequireFromString("100.00"),
TaxCategory: einvoice.CategoryStandard,
TaxRate: decimal.NewFromInt(19),
}},
}
xmlBytes, err := cii.NewSerializer().Serialize(inv)
if err != nil {
panic(err)
}
fmt.Println(len(xmlBytes) > 0)
}
Output: true
type InvoiceSerializer ¶
InvoiceSerializer defines the contract for converting the domain model into a spec format.
type LineItem ¶
type LineItem struct {
Description string
Quantity decimal.Decimal
UnitCode string
UnitPrice decimal.Decimal
// TaxCategory is the EN 16931 VAT category (BT-151). Empty defaults to
// Standard ("S"). For Differenzbesteuerung (§25a UStG) use CategoryExempt
// with TaxRate 0 and ExemptionCode VATExSecondHandGoods.
TaxCategory TaxCategory
TaxRate decimal.Decimal
// ExemptionCode (BT-121) and ExemptionReason (BT-120) are required for
// non-standard categories (E, AE, K). If ExemptionReason is empty, the
// default German text for a known ExemptionCode is used.
ExemptionCode VATExCode
ExemptionReason string
}
type Party ¶
type Party struct {
Name string
Street string
City string
PostalCode string
CountryCode string
VATID string
Contact *Contact
// ElectronicAddress is the party's electronic address (BT-34 seller / BT-49
// buyer), mandatory in XRechnung. ElectronicAddressScheme is its EAS code
// (e.g. "EM" email, "9930" German VAT, "0204" Leitweg-ID); defaults to "EM".
// If ElectronicAddress is empty, Contact.Email is used as an "EM" fallback.
ElectronicAddress string
ElectronicAddressScheme string
}
type TaxCategory ¶ added in v0.2.0
type TaxCategory string
TaxCategory is an EN 16931 / UNTDID 5305 VAT category code (BT-118 / BT-151).
const ( CategoryStandard TaxCategory = "S" // Standard rate (19% / 7%) CategoryZero TaxCategory = "Z" // Zero rated goods CategoryExempt TaxCategory = "E" // Exempt from VAT (incl. §25a margin scheme) CategoryReverseCharge TaxCategory = "AE" // VAT reverse charge (§13b UStG) CategoryIntraCommunity TaxCategory = "K" // Intra-community supply CategoryExport TaxCategory = "G" // Free export item, tax not charged CategoryOutOfScope TaxCategory = "O" // Services outside scope of tax )
type VATExCode ¶ added in v0.2.0
type VATExCode string
VATExCode is an EN 16931 VAT exemption reason code (BT-121), from the CEF VATEX code list. Codes F/I/J cover the German Differenzbesteuerung variants.
const ( VATExSecondHandGoods VATExCode = "VATEX-EU-F" // Gebrauchtgegenstände (e.g. used cars) VATExWorksOfArt VATExCode = "VATEX-EU-I" // Kunstgegenstände VATExCollectors VATExCode = "VATEX-EU-J" // Sammlungsstücke und Antiquitäten VATExReverseCharge VATExCode = "VATEX-EU-AE" // Steuerschuldnerschaft des Leistungsempfängers VATExIntraCommunity VATExCode = "VATEX-EU-IC" // Innergemeinschaftliche Lieferung )
func (VATExCode) DefaultReason ¶ added in v0.2.0
DefaultReason returns the standard German exemption text (BT-120) mandated for a known VATEX code, or "" if the code is unknown.