ZeRechnung
Language: English

Examples

Examples, step by step

Each example is a complete Go program that runs as it is. It creates a real e-invoice, checks it against the rules of the country, then reads it back. The tests of the repository run every program and check that it prints what this page shows.

Example 1

A Cork distillery invoices a Dublin pub

Factur-XEN 16931Irish VAT 23%

Inishcarra Distillers, on the banks of the Lee west of Cork, sends an order up to the Brazen Lantern, a pub on Camden Street in Dublin: single pot still whiskey, a sherry-finished single malt, a cask strength bottling and a few bottles of poitín. The distillery's accounts package already prints the invoice as a PDF; ZeRechnung adds the XML and the Factur-X metadata, and checks the invoice against EN 16931 before writing anything.

Spirits carry the standard rate of Irish VAT, 23%, and the prices already include the Alcohol Products Tax paid when the bottles left the bonded warehouse.

  1. Read the invoice PDF

    The starting point is the PDF your software already produces. Ideally a PDF/A-3, but any PDF will do: ZeRechnung does not change its bytes, it adds the attachment with an incremental update.

    Go
    pdf, err := os.ReadFile("invoice.pdf")
    if err != nil {
    	log.Fatal(err)
    }
  2. Describe the seller and the buyer

    Both parties are VAT-registered, so their Irish VAT numbers go on the invoice (BT-31, BT-48). The distillery adds its company registration number, as Irish companies print it on their business documents (BT-33). An Irish address ends with its Eircode, the postcode.

    Go
    distillery := invoice.Party{
    	Name:        "Inishcarra Distillers Ltd",
    	Description: "Registered in Ireland No. 612345",
    	VATID:       "IE3254871E",
    	Address: invoice.Address{Line1: "Mill Road", City: "Inishcarra", PostCode: "P31 X2F7",
    		CountrySubdivision: "Co. Cork", CountryCode: "IE"},
    }
    pub := invoice.Party{
    	Name:  "Brazen Lantern Taverns Ltd",
    	VATID: "IE9471263R",
    	Address: invoice.Address{Line1: "14 Camden Street Lower", City: "Dublin 2",
    		PostCode: "D02 YX48", CountryCode: "IE"},
    }
  3. Add the order details and payment terms

    The pub's order number goes in BT-13, the note tells the buyer that the excise duty is paid, and the payment instructions give the IBAN of the distillery for a SEPA credit transfer.

    Go
    d := invoice.MustDecimal
    inv := &invoice.Invoice{
    	Profile:                invoice.ProfileEN16931,
    	Number:                 "INV-26-0571",
    	TypeCode:               invoice.TypeCommercialInvoice,
    	IssueDate:              invoice.NewDate(2026, time.November, 20),
    	Currency:               "EUR",
    	PurchaseOrderReference: "BL-2026-118",
    	Seller:                 distillery,
    	Buyer:                  pub,
    	DeliveryDate:           invoice.NewDate(2026, time.November, 18),
    	Notes: []invoice.Note{
    		{Content: "Alcohol Products Tax paid and included in the prices."},
    	},
    	PaymentMeans: []invoice.PaymentMeans{{
    		TypeCode: invoice.PaymentSEPACreditTransfer, PayeeIBAN: "IE29AIBK93115212345678",
    	}},
    	PaymentTerms: []invoice.PaymentTerms{{
    		Description: "Payment within 30 days by bank transfer.",
    		DueDate:     invoice.NewDate(2026, time.December, 20),
    	}},
    }
  4. List the bottles

    Each line has a quantity, a unit (UN/ECE code: H87 for a piece, C62 for one unit), a net price and its VAT rate. The delivery is charged at the same 23% as the spirits.

    Go
    inv.Lines = []invoice.Line{{
    	ID: "1", Item: invoice.Item{Name: "Single Pot Still Irish Whiskey, 12 Year Old, 70 cl"},
    	Quantity: d("24"), UnitCode: "H87", NetPrice: d("46.50"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "2", Item: invoice.Item{Name: "Single Malt, Oloroso Sherry Cask Finish, 70 cl"},
    	Quantity: d("12"), UnitCode: "H87", NetPrice: d("58.00"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "3", Item: invoice.Item{Name: "Single Pot Still, Cask Strength, 70 cl"},
    	Quantity: d("6"), UnitCode: "H87", NetPrice: d("79.00"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "4", Item: invoice.Item{Name: "Irish Poitín, 70 cl"},
    	Quantity: d("12"), UnitCode: "H87", NetPrice: d("32.00"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "5", Item: invoice.Item{Name: "Delivery to Dublin"},
    	Quantity: d("1"), UnitCode: "C62", NetPrice: d("45.00"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }}
  5. Create the Factur-X invoice

    Calculate works out the line amounts, the totals and the VAT breakdown with exact decimals. With the default options, the invoice is then checked against the XML schema, the EN 16931 business rules and the Factur-X schematron of its profile. An invalid invoice is refused: Create returns the findings and writes nothing.

    Go
    out, err := zerechnung.Create(pdf, inv, &zerechnung.CreateOptions{
    	Calculate: true,
    	Validate:  &validate.Options{},
    })
    if err != nil {
    	log.Fatal(err)
    }
    if err := os.WriteFile("INV-26-0571.pdf", out, 0o644); err != nil {
    	log.Fatal(err)
    }
  6. Read back and check the result

    The PDF reads like any invoice you receive. Check validates the PDF container, the XMP metadata and the XML, with the same rules.

    Go
    back, att, err := zerechnung.Read(out)
    if err != nil {
    	log.Fatal(err)
    }
    fmt.Println(att.Filename, "·", att.Metadata.ConformanceLevel)
    for _, vat := range back.VATBreakdown {
    	fmt.Printf("VAT %s%% on €%s: €%s\n", vat.Rate, vat.TaxableAmount, vat.TaxAmount)
    }
    t := back.Totals
    fmt.Printf("Total excl. VAT: €%s · incl. VAT: €%s\n", t.TaxBasisTotal, t.GrandTotal)
    
    report, _, err := zerechnung.Check(out, nil)
    if err != nil {
    	log.Fatal(err)
    }
    fmt.Println("Errors:", len(report.Errors()))

What the program prints

go run .
factur-x.xml · EN 16931
VAT 23% on €2715.00: €624.45
Total excl. VAT: €2715.00 · incl. VAT: €3339.45
Errors: 0
The whole program
main.go
package main

import (
	"fmt"
	"log"
	"os"
	"time"

	"github.com/ritoon/zerechnung"
	"github.com/ritoon/zerechnung/invoice"
	"github.com/ritoon/zerechnung/validate"
)

func main() {
	// Read the invoice PDF
	pdf, err := os.ReadFile("invoice.pdf")
	if err != nil {
		log.Fatal(err)
	}

	// Describe the seller and the buyer
	distillery := invoice.Party{
		Name:        "Inishcarra Distillers Ltd",
		Description: "Registered in Ireland No. 612345",
		VATID:       "IE3254871E",
		Address: invoice.Address{Line1: "Mill Road", City: "Inishcarra", PostCode: "P31 X2F7",
			CountrySubdivision: "Co. Cork", CountryCode: "IE"},
	}
	pub := invoice.Party{
		Name:  "Brazen Lantern Taverns Ltd",
		VATID: "IE9471263R",
		Address: invoice.Address{Line1: "14 Camden Street Lower", City: "Dublin 2",
			PostCode: "D02 YX48", CountryCode: "IE"},
	}

	// Add the order details and payment terms
	d := invoice.MustDecimal
	inv := &invoice.Invoice{
		Profile:                invoice.ProfileEN16931,
		Number:                 "INV-26-0571",
		TypeCode:               invoice.TypeCommercialInvoice,
		IssueDate:              invoice.NewDate(2026, time.November, 20),
		Currency:               "EUR",
		PurchaseOrderReference: "BL-2026-118",
		Seller:                 distillery,
		Buyer:                  pub,
		DeliveryDate:           invoice.NewDate(2026, time.November, 18),
		Notes: []invoice.Note{
			{Content: "Alcohol Products Tax paid and included in the prices."},
		},
		PaymentMeans: []invoice.PaymentMeans{{
			TypeCode: invoice.PaymentSEPACreditTransfer, PayeeIBAN: "IE29AIBK93115212345678",
		}},
		PaymentTerms: []invoice.PaymentTerms{{
			Description: "Payment within 30 days by bank transfer.",
			DueDate:     invoice.NewDate(2026, time.December, 20),
		}},
	}

	// List the bottles
	inv.Lines = []invoice.Line{{
		ID: "1", Item: invoice.Item{Name: "Single Pot Still Irish Whiskey, 12 Year Old, 70 cl"},
		Quantity: d("24"), UnitCode: "H87", NetPrice: d("46.50"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "2", Item: invoice.Item{Name: "Single Malt, Oloroso Sherry Cask Finish, 70 cl"},
		Quantity: d("12"), UnitCode: "H87", NetPrice: d("58.00"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "3", Item: invoice.Item{Name: "Single Pot Still, Cask Strength, 70 cl"},
		Quantity: d("6"), UnitCode: "H87", NetPrice: d("79.00"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "4", Item: invoice.Item{Name: "Irish Poitín, 70 cl"},
		Quantity: d("12"), UnitCode: "H87", NetPrice: d("32.00"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "5", Item: invoice.Item{Name: "Delivery to Dublin"},
		Quantity: d("1"), UnitCode: "C62", NetPrice: d("45.00"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}}

	// Create the Factur-X invoice
	out, err := zerechnung.Create(pdf, inv, &zerechnung.CreateOptions{
		Calculate: true,
		Validate:  &validate.Options{},
	})
	if err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("INV-26-0571.pdf", out, 0o644); err != nil {
		log.Fatal(err)
	}

	// Read back and check the result
	back, att, err := zerechnung.Read(out)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(att.Filename, "·", att.Metadata.ConformanceLevel)
	for _, vat := range back.VATBreakdown {
		fmt.Printf("VAT %s%% on €%s: €%s\n", vat.Rate, vat.TaxableAmount, vat.TaxAmount)
	}
	t := back.Totals
	fmt.Printf("Total excl. VAT: €%s · incl. VAT: €%s\n", t.TaxBasisTotal, t.GrandTotal)

	report, _, err := zerechnung.Check(out, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Errors:", len(report.Errors()))
}

Run it from a clone of the repository:

Shell
git clone https://github.com/ritoon/zerechnung
cd zerechnung/site/examples/en-1-distillery
go run .

This example on GitHub

Example 2

A Kilkenny hurley maker invoices a public body over Peppol

Peppol BIS Billing 3.0UBLEN 16931Irish VAT 23%

Nore Valley Hurleys turns ash planks into hurleys in a workshop outside Kilkenny. This autumn it equipped the schools of the Nore and Barrow Education and Training Board for the hurling and camogie season: senior and junior hurleys, a few hundred sliotars, and the repair of sticks cracked during the first weeks of training.

An education and training board is a contracting authority, and like other Irish public bodies it receives EN 16931 e-invoices, many of them through the Peppol network. ZeRechnung writes the invoice in UBL following Peppol BIS Billing 3.0, and checks it against the Peppol rules before it is handed to an access point.

  1. Describe the supplier and the board

    On Peppol, each party has an electronic address (BT-34, BT-49): its participant identifier on the network. Here both use the scheme 9935, an Irish VAT number; the board has one too.

    Go
    hurleys := invoice.Party{
    	Name:  "Nore Valley Hurleys Ltd",
    	VATID: "IE7046192G",
    	Address: invoice.Address{Line1: "Unit 4, Bennettsbridge Road", City: "Kilkenny",
    		PostCode: "R95 FX62", CountryCode: "IE"},
    	ElectronicAddress: invoice.Identifier{ID: "IE7046192G", Scheme: invoice.SchemeIEVAT},
    }
    board := invoice.Party{
    	Name:  "Nore and Barrow Education and Training Board",
    	VATID: "IE4180736U",
    	Address: invoice.Address{Line1: "Barrow House, Ormonde Road", City: "Kilkenny",
    		PostCode: "R95 A39T", CountryCode: "IE"},
    	ElectronicAddress: invoice.Identifier{ID: "IE4180736U", Scheme: invoice.SchemeIEVAT},
    }
  2. Add the Peppol references

    The Peppol profile sets the specification identifier (BT-24), and BT-23 names the Peppol billing process. Peppol requires a buyer reference or an order reference: the board's purchase order number goes in BT-13, and the reference of the ordering department in BT-10.

    Go
    d := invoice.MustDecimal
    inv := &invoice.Invoice{
    	Profile:                invoice.ProfilePeppol,
    	BusinessProcess:        invoice.ProcessPeppolBilling,
    	Number:                 "NVH-2026-0214",
    	TypeCode:               invoice.TypeCommercialInvoice,
    	IssueDate:              invoice.NewDate(2026, time.November, 16),
    	Currency:               "EUR",
    	BuyerReference:         "SCHOOLS-SPORT",
    	PurchaseOrderReference: "PO-2026-04417",
    	Seller:                 hurleys,
    	Buyer:                  board,
    	DeliveryDate:           invoice.NewDate(2026, time.November, 9),
    	PaymentMeans: []invoice.PaymentMeans{{
    		TypeCode: invoice.PaymentSEPACreditTransfer, PayeeIBAN: "IE29AIBK93115212345678",
    	}},
    	PaymentTerms: []invoice.PaymentTerms{{
    		Description: "Payment within 30 days of receipt of invoice.",
    		DueDate:     invoice.NewDate(2026, time.December, 16),
    	}},
    }
  3. List the hurleys, the sliotars and the repairs

    Sports equipment carries the standard rate of 23%, and so does the repair service. H87 is the UN/ECE code for a piece, C62 for one unit.

    Go
    inv.Lines = []invoice.Line{{
    	ID: "1", Item: invoice.Item{Name: "Ash hurley, handcrafted, sizes 30 to 36"},
    	Quantity: d("40"), UnitCode: "H87", NetPrice: d("38.00"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "2", Item: invoice.Item{Name: "Junior ash hurley, sizes 18 to 28"},
    	Quantity: d("60"), UnitCode: "H87", NetPrice: d("27.50"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "3", Item: invoice.Item{Name: "Sliotar, leather, match grade"},
    	Quantity: d("200"), UnitCode: "H87", NetPrice: d("6.50"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "4", Item: invoice.Item{Name: "Hurley repair: splice and metal band"},
    	Quantity: d("25"), UnitCode: "H87", NetPrice: d("8.00"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }, {
    	ID: "5", Item: invoice.Item{Name: "Delivery to the board's schools"},
    	Quantity: d("1"), UnitCode: "C62", NetPrice: d("60.00"),
    	VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
    }}
  4. Write the UBL invoice

    Calculate works out the line amounts, the totals and the VAT breakdown with exact decimals. ubl.Marshal writes a UBL 2.1 Invoice.

    Go
    inv.Calculate()
    xml, err := ubl.Marshal(inv, nil)
    if err != nil {
    	log.Fatal(err)
    }
  5. Validate with the Peppol rules

    The Peppol rules apply on their own to an invoice that declares Peppol in BT-24; naming them makes the check explicit. They come on top of the UBL 2.1 schema and the EN 16931 rules, and check, among others, the electronic addresses, the references and the code lists.

    Go
    report := validate.XML(xml, &validate.Options{Rules: validate.Default | validate.Peppol})
    if !report.Valid() {
    	log.Fatal(report)
    }
  6. Read the invoice back

    ubl.Parse reads the UBL document into the same model, as the board's finance system would.

    Go
    back, err := ubl.Parse(xml)
    if err != nil {
    	log.Fatal(err)
    }
    fmt.Println(back.Profile, "·", back.Number)
    to := back.Buyer.ElectronicAddress
    fmt.Println("To:", back.Buyer.Name, "·", to.Scheme+":"+to.ID)
    fmt.Println("Order:", back.PurchaseOrderReference)
    vat := back.VATBreakdown[0]
    fmt.Printf("VAT %s%% on €%s: €%s\n", vat.Rate, vat.TaxableAmount, vat.TaxAmount)
    fmt.Printf("Amount due: €%s\n", back.Totals.DuePayable)
    fmt.Println("Findings:", len(report.Findings))

What the program prints

go run .
PEPPOL · NVH-2026-0214
To: Nore and Barrow Education and Training Board · 9935:IE4180736U
Order: PO-2026-04417
VAT 23% on €4730.00: €1087.90
Amount due: €5817.90
Findings: 0
The whole program
main.go
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/ritoon/zerechnung/invoice"
	"github.com/ritoon/zerechnung/ubl"
	"github.com/ritoon/zerechnung/validate"
)

func main() {
	// Describe the supplier and the board
	hurleys := invoice.Party{
		Name:  "Nore Valley Hurleys Ltd",
		VATID: "IE7046192G",
		Address: invoice.Address{Line1: "Unit 4, Bennettsbridge Road", City: "Kilkenny",
			PostCode: "R95 FX62", CountryCode: "IE"},
		ElectronicAddress: invoice.Identifier{ID: "IE7046192G", Scheme: invoice.SchemeIEVAT},
	}
	board := invoice.Party{
		Name:  "Nore and Barrow Education and Training Board",
		VATID: "IE4180736U",
		Address: invoice.Address{Line1: "Barrow House, Ormonde Road", City: "Kilkenny",
			PostCode: "R95 A39T", CountryCode: "IE"},
		ElectronicAddress: invoice.Identifier{ID: "IE4180736U", Scheme: invoice.SchemeIEVAT},
	}

	// Add the Peppol references
	d := invoice.MustDecimal
	inv := &invoice.Invoice{
		Profile:                invoice.ProfilePeppol,
		BusinessProcess:        invoice.ProcessPeppolBilling,
		Number:                 "NVH-2026-0214",
		TypeCode:               invoice.TypeCommercialInvoice,
		IssueDate:              invoice.NewDate(2026, time.November, 16),
		Currency:               "EUR",
		BuyerReference:         "SCHOOLS-SPORT",
		PurchaseOrderReference: "PO-2026-04417",
		Seller:                 hurleys,
		Buyer:                  board,
		DeliveryDate:           invoice.NewDate(2026, time.November, 9),
		PaymentMeans: []invoice.PaymentMeans{{
			TypeCode: invoice.PaymentSEPACreditTransfer, PayeeIBAN: "IE29AIBK93115212345678",
		}},
		PaymentTerms: []invoice.PaymentTerms{{
			Description: "Payment within 30 days of receipt of invoice.",
			DueDate:     invoice.NewDate(2026, time.December, 16),
		}},
	}

	// List the hurleys, the sliotars and the repairs
	inv.Lines = []invoice.Line{{
		ID: "1", Item: invoice.Item{Name: "Ash hurley, handcrafted, sizes 30 to 36"},
		Quantity: d("40"), UnitCode: "H87", NetPrice: d("38.00"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "2", Item: invoice.Item{Name: "Junior ash hurley, sizes 18 to 28"},
		Quantity: d("60"), UnitCode: "H87", NetPrice: d("27.50"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "3", Item: invoice.Item{Name: "Sliotar, leather, match grade"},
		Quantity: d("200"), UnitCode: "H87", NetPrice: d("6.50"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "4", Item: invoice.Item{Name: "Hurley repair: splice and metal band"},
		Quantity: d("25"), UnitCode: "H87", NetPrice: d("8.00"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}, {
		ID: "5", Item: invoice.Item{Name: "Delivery to the board's schools"},
		Quantity: d("1"), UnitCode: "C62", NetPrice: d("60.00"),
		VATCategoryCode: invoice.VATStandard, VATRate: d("23"),
	}}

	// Write the UBL invoice
	inv.Calculate()
	xml, err := ubl.Marshal(inv, nil)
	if err != nil {
		log.Fatal(err)
	}

	// Validate with the Peppol rules
	report := validate.XML(xml, &validate.Options{Rules: validate.Default | validate.Peppol})
	if !report.Valid() {
		log.Fatal(report)
	}

	// Read the invoice back
	back, err := ubl.Parse(xml)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(back.Profile, "·", back.Number)
	to := back.Buyer.ElectronicAddress
	fmt.Println("To:", back.Buyer.Name, "·", to.Scheme+":"+to.ID)
	fmt.Println("Order:", back.PurchaseOrderReference)
	vat := back.VATBreakdown[0]
	fmt.Printf("VAT %s%% on €%s: €%s\n", vat.Rate, vat.TaxableAmount, vat.TaxAmount)
	fmt.Printf("Amount due: €%s\n", back.Totals.DuePayable)
	fmt.Println("Findings:", len(report.Findings))
}

Run it from a clone of the repository:

Shell
git clone https://github.com/ritoon/zerechnung
cd zerechnung/site/examples/en-2-hurleys
go run .

This example on GitHub

Example 3

A Kerry creamery ships butter and cheddar to Germany

CIIEN 16931intra-Community supplyVAT 0%

Slieve Mish Co-operative Creamery churns butter and makes cheddar from the milk of grass-fed herds on the Dingle Peninsula. A refrigerated trailer leaves Castlemaine for the central warehouse of Frischmarkt Hanse, a supermarket chain in northern Germany, with salted and unsalted butter and two cheddars.

A supply of goods to a VAT-registered business in another member state is an intra-Community supply: no Irish VAT is charged, and the invoice says why. The chain's purchase ledger reads EN 16931 invoices in CII, the XML syntax of ZUGFeRD that XRechnung also accepts, so ZeRechnung writes the invoice as CII XML and checks the rules that apply to such a supply.

  1. Describe the creamery, the chain and the warehouse

    An intra-Community supply needs the VAT numbers of both parties (BT-31, BT-48): the German one shows that the buyer is a business registered for VAT in another member state. The goods go to the chain's warehouse in Bremen, the deliver-to address (BG-15), whose country is mandatory for such a supply.

    Go
    creamery := invoice.Party{
    	Name:  "Slieve Mish Co-operative Creamery Ltd",
    	VATID: "IE5218437A",
    	Address: invoice.Address{Line1: "Creamery Road", City: "Castlemaine", PostCode: "V93 K2P6",
    		CountrySubdivision: "Co. Kerry", CountryCode: "IE"},
    }
    chain := invoice.Party{
    	Name:  "Frischmarkt Hanse GmbH & Co. KG",
    	VATID: "DE136902056",
    	Address: invoice.Address{Line1: "Am Sandtorkai 40", City: "Hamburg", PostCode: "20457",
    		CountryCode: "DE"},
    }
    warehouse := &invoice.Party{
    	Name: "Frischmarkt Hanse, Zentrallager Bremen",
    	Address: invoice.Address{Line1: "Industriestraße 12", City: "Bremen", PostCode: "28199",
    		CountryCode: "DE"},
    }
  2. State the VAT exemption

    The VAT category is K, intra-Community supply, at 0%. The breakdown carries the reason for the exemption as a VATEX code and as text (BT-121, BT-120); Calculate keeps them when it fills in the amounts. The delivery date (BT-72) tells in which period the supply took place.

    Go
    d := invoice.MustDecimal
    inv := &invoice.Invoice{
    	Profile:                invoice.ProfileEN16931,
    	Number:                 "SMC-EX-26-0388",
    	TypeCode:               invoice.TypeCommercialInvoice,
    	IssueDate:              invoice.NewDate(2026, time.November, 19),
    	Currency:               "EUR",
    	PurchaseOrderReference: "4500987123",
    	Seller:                 creamery,
    	Buyer:                  chain,
    	ShipTo:                 warehouse,
    	DeliveryDate:           invoice.NewDate(2026, time.November, 17),
    	VATBreakdown: []invoice.VATBreakdown{{
    		CategoryCode:        invoice.VATIntraCommunity,
    		Rate:                d("0"),
    		ExemptionReasonCode: invoice.VATEXIntraCommunity,
    		ExemptionReason:     "Intra-Community supply, Article 138 of the VAT Directive",
    	}},
    	PaymentMeans: []invoice.PaymentMeans{{
    		TypeCode: invoice.PaymentSEPACreditTransfer, PayeeIBAN: "IE29AIBK93115212345678",
    	}},
    	PaymentTerms: []invoice.PaymentTerms{{
    		Description: "Payment within 45 days by SEPA credit transfer.",
    		DueDate:     invoice.NewDate(2027, time.January, 3),
    	}},
    }
  3. List the butter and the cheese

    Every line carries the category K and the rate 0%. Butter is invoiced by the 250 g pack (H87, a piece), the block cheddar by the kilogram (KGM).

    Go
    inv.Lines = []invoice.Line{{
    	ID: "1", Item: invoice.Item{Name: "Salted creamery butter, 250 g"},
    	Quantity: d("9600"), UnitCode: "H87", NetPrice: d("1.95"),
    	VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
    }, {
    	ID: "2", Item: invoice.Item{Name: "Unsalted creamery butter, 250 g"},
    	Quantity: d("2400"), UnitCode: "H87", NetPrice: d("1.95"),
    	VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
    }, {
    	ID: "3", Item: invoice.Item{Name: "Mature white cheddar, 2.5 kg block"},
    	Quantity: d("500"), UnitCode: "KGM", NetPrice: d("7.40"),
    	VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
    }, {
    	ID: "4", Item: invoice.Item{Name: "Vintage red cheddar, 200 g"},
    	Quantity: d("3000"), UnitCode: "H87", NetPrice: d("2.10"),
    	VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
    }}
  4. Add the haulage as a charge

    The refrigerated transport to Bremen is a document level charge (BG-21) with the reason code FC, freight. It is part of the same supply, with the same category K.

    Go
    inv.AllowancesCharges = []invoice.AllowanceCharge{{
    	Charge: true, Reason: "Refrigerated haulage to Bremen", ReasonCode: "FC",
    	Amount: d("1450.00"), VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
    }}
  5. Write and validate the CII invoice

    Calculate works out the line amounts, the totals and the VAT breakdown. cii.Marshal writes the invoice at the EN 16931 profile; validate.XML checks the CII schema and the EN 16931 rules, among them the BR-IC rules of the intra-Community supply: both VAT numbers, the deliver-to country, the delivery date, the exemption reason, no VAT amount.

    Go
    inv.Calculate()
    xml, err := cii.Marshal(inv, nil)
    if err != nil {
    	log.Fatal(err)
    }
    report := validate.XML(xml, nil)
    if !report.Valid() {
    	log.Fatal(report)
    }
  6. Read the invoice back

    cii.Parse reads the XML into the same model, as the chain's system would.

    Go
    back, err := cii.Parse(xml)
    if err != nil {
    	log.Fatal(err)
    }
    vat := back.VATBreakdown[0]
    fmt.Printf("VAT %s %s%% on €%s: €%s\n", vat.CategoryCode, vat.Rate, vat.TaxableAmount, vat.TaxAmount)
    fmt.Println("Exemption:", vat.ExemptionReasonCode, "·", vat.ExemptionReason)
    fmt.Println("Deliver to:", back.ShipTo.Address.City+",", back.ShipTo.Address.CountryCode)
    t := back.Totals
    fmt.Printf("Lines: €%s · charges: €%s\n", t.LineTotal, t.ChargeTotal)
    fmt.Printf("Amount due: €%s\n", t.DuePayable)
    fmt.Println("Errors:", len(report.Errors()))

What the program prints

go run .
VAT K 0% on €34850.00: €0.00
Exemption: VATEX-EU-IC · Intra-Community supply, Article 138 of the VAT Directive
Deliver to: Bremen, DE
Lines: €33400.00 · charges: €1450.00
Amount due: €34850.00
Errors: 0
The whole program
main.go
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/ritoon/zerechnung/cii"
	"github.com/ritoon/zerechnung/invoice"
	"github.com/ritoon/zerechnung/validate"
)

func main() {
	// Describe the creamery, the chain and the warehouse
	creamery := invoice.Party{
		Name:  "Slieve Mish Co-operative Creamery Ltd",
		VATID: "IE5218437A",
		Address: invoice.Address{Line1: "Creamery Road", City: "Castlemaine", PostCode: "V93 K2P6",
			CountrySubdivision: "Co. Kerry", CountryCode: "IE"},
	}
	chain := invoice.Party{
		Name:  "Frischmarkt Hanse GmbH & Co. KG",
		VATID: "DE136902056",
		Address: invoice.Address{Line1: "Am Sandtorkai 40", City: "Hamburg", PostCode: "20457",
			CountryCode: "DE"},
	}
	warehouse := &invoice.Party{
		Name: "Frischmarkt Hanse, Zentrallager Bremen",
		Address: invoice.Address{Line1: "Industriestraße 12", City: "Bremen", PostCode: "28199",
			CountryCode: "DE"},
	}

	// State the VAT exemption
	d := invoice.MustDecimal
	inv := &invoice.Invoice{
		Profile:                invoice.ProfileEN16931,
		Number:                 "SMC-EX-26-0388",
		TypeCode:               invoice.TypeCommercialInvoice,
		IssueDate:              invoice.NewDate(2026, time.November, 19),
		Currency:               "EUR",
		PurchaseOrderReference: "4500987123",
		Seller:                 creamery,
		Buyer:                  chain,
		ShipTo:                 warehouse,
		DeliveryDate:           invoice.NewDate(2026, time.November, 17),
		VATBreakdown: []invoice.VATBreakdown{{
			CategoryCode:        invoice.VATIntraCommunity,
			Rate:                d("0"),
			ExemptionReasonCode: invoice.VATEXIntraCommunity,
			ExemptionReason:     "Intra-Community supply, Article 138 of the VAT Directive",
		}},
		PaymentMeans: []invoice.PaymentMeans{{
			TypeCode: invoice.PaymentSEPACreditTransfer, PayeeIBAN: "IE29AIBK93115212345678",
		}},
		PaymentTerms: []invoice.PaymentTerms{{
			Description: "Payment within 45 days by SEPA credit transfer.",
			DueDate:     invoice.NewDate(2027, time.January, 3),
		}},
	}

	// List the butter and the cheese
	inv.Lines = []invoice.Line{{
		ID: "1", Item: invoice.Item{Name: "Salted creamery butter, 250 g"},
		Quantity: d("9600"), UnitCode: "H87", NetPrice: d("1.95"),
		VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
	}, {
		ID: "2", Item: invoice.Item{Name: "Unsalted creamery butter, 250 g"},
		Quantity: d("2400"), UnitCode: "H87", NetPrice: d("1.95"),
		VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
	}, {
		ID: "3", Item: invoice.Item{Name: "Mature white cheddar, 2.5 kg block"},
		Quantity: d("500"), UnitCode: "KGM", NetPrice: d("7.40"),
		VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
	}, {
		ID: "4", Item: invoice.Item{Name: "Vintage red cheddar, 200 g"},
		Quantity: d("3000"), UnitCode: "H87", NetPrice: d("2.10"),
		VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
	}}

	// Add the haulage as a charge
	inv.AllowancesCharges = []invoice.AllowanceCharge{{
		Charge: true, Reason: "Refrigerated haulage to Bremen", ReasonCode: "FC",
		Amount: d("1450.00"), VATCategoryCode: invoice.VATIntraCommunity, VATRate: d("0"),
	}}

	// Write and validate the CII invoice
	inv.Calculate()
	xml, err := cii.Marshal(inv, nil)
	if err != nil {
		log.Fatal(err)
	}
	report := validate.XML(xml, nil)
	if !report.Valid() {
		log.Fatal(report)
	}

	// Read the invoice back
	back, err := cii.Parse(xml)
	if err != nil {
		log.Fatal(err)
	}
	vat := back.VATBreakdown[0]
	fmt.Printf("VAT %s %s%% on €%s: €%s\n", vat.CategoryCode, vat.Rate, vat.TaxableAmount, vat.TaxAmount)
	fmt.Println("Exemption:", vat.ExemptionReasonCode, "·", vat.ExemptionReason)
	fmt.Println("Deliver to:", back.ShipTo.Address.City+",", back.ShipTo.Address.CountryCode)
	t := back.Totals
	fmt.Printf("Lines: €%s · charges: €%s\n", t.LineTotal, t.ChargeTotal)
	fmt.Printf("Amount due: €%s\n", t.DuePayable)
	fmt.Println("Errors:", len(report.Errors()))
}

Run it from a clone of the repository:

Shell
git clone https://github.com/ritoon/zerechnung
cd zerechnung/site/examples/en-3-creamery
go run .

This example on GitHub

More examples, for every feature of the package: Full examples in the README · API reference