Invoices PRO can produce e-invoices by the European standard EN 16931: a ZUGFeRD / Factur-X PDF with the machine-readable XML inside, or an XRechnung XML file. You add the XML part to an ordinary invoice template, and the plugin attaches it to every PDF made from that template.
- How it works
- Download a ready template
- Add the template to Redmine
- Fill in your company data
- Buyer data from contact fields
- Leitweg-ID and buyer reference
- Get the PDF and the XML
- Write your own XML invoice
- Units of measure
- Partial payments
- Discounts
- Check your e-invoice
- Limitations
- Related articles
Available in Invoices PRO since version 4.4.1. The Light version has no custom templates and makes plain PDFs only.
How it works
An invoice template is a Liquid document with two parts:
- the printed part: HTML, the same as in any custom template;
- the XML invoice: the XML written between
{% xml_invoice %}and{% endxml_invoice %}. It is not printed.
When a template has an XML invoice:
- every PDF made from it (Download as PDF, the public link, the email attachment, Reports) becomes a hybrid PDF: a PDF/A-3B file with the XML attached as
factur-x.xml; - the Preview page shows a Download XML button that saves the XML alone. Use it for XRechnung, which public buyers in Germany expect as a separate XML file.
A template without the block makes a plain PDF, as before.
Download a ready template
Two templates are ready to use. Both are CII (UN/CEFACT Cross Industry Invoice) XML, checked with the veraPDF (PDF/A-3b) and Mediaatelier (XSD, EN 16931 and XRechnung rules) validators.
| Template | Standard | Use it for | |
|---|---|---|---|
| Factur-X (EN 16931) | ZUGFeRD 2 / Factur-X, profile EN 16931 | B2B invoices in Germany, France and the EU: one PDF a person reads and software imports | Download |
| XRechnung 3.0 (CII) | XRechnung 3.0 | Invoices to German public authorities (with a Leitweg-ID) and B2B buyers who ask for XRechnung | Download |
Output of the Factur-X template for a sample invoice: factur-x-example.pdf (hybrid PDF) and factur-x-example.xml (the XML inside it); of the XRechnung template: xrechnung-example.xml.
Add the template to Redmine
You need to be an administrator, or have the Manage invoices permission to add a template to one project (Project settings, tab Invoice templates).
To add the template:
- Open the downloaded
.liquidfile in a text editor and copy all of its text. - Select Administration, then Invoices, then the Invoice templates tab.
- Click New invoice template.
- Enter a Name, for example Factur-X (EN 16931). The name is shown on the Download XML button.
- Leave Active on. Turn on Default to use this template for every invoice that has no template of its own.
- Paste the text into the Invoice template field and click Create.

The template is used for an invoice when it is the default template (the Default checkbox, or Invoice template in Administration, then Invoices, then General; see How to set default invoice template), or, with Per invoice templates turned on in the same tab, when it is chosen in the invoice form.
Fill in your company data
The template reads the seller from the Company profile settings (Administration, then Invoices, then Company profile; a project can override them in its settings):
- Company name: the seller name;
- Representative: the contact person (XRechnung);
- Company info and Bill info: one
Key: valueper line, with these keys:
Street: Musterstraße 1 Postcode: 10115 City: Berlin Country: DE VAT ID: DE123456789 Phone: +49 30 1234567 Email: billing@example.com IBAN: DE89 3704 0044 0532 0130 00
Phone and Email are used by XRechnung only. Spaces in the IBAN are removed. The XML ignores lines with other keys or without a key.
A key that is missing from the settings falls back to the value written in the template. These defaults are the assign lines at the top of the block; replace the sample values with yours if you prefer to keep the data in the template:
{% xml_invoice %}
{% assign seller_name = account.company | default: 'Your Company GmbH' %}
{% assign seller_street = 'Musterstraße 1' %}
{% assign seller_postcode = '10115' %}
{% assign seller_city = 'Berlin' %}
{% assign seller_country = 'DE' %}
{% assign seller_vat_id = 'DE123456789' %}
{% assign seller_iban = 'DE89370400440532013000' %}
The buyer comes from the invoice Client: the company name (or the contact name), the address and, for XRechnung, the primary email. For XRechnung the client must have a postcode, a city and an email.
Buyer data from contact fields
The buyer is the invoice Client, available in the template as invoice.contact. Its email is contact.primary_email (contact.email is empty in templates). Custom fields of the contact are read with the custom_field filter and the exact field name:
{% assign buyer = invoice.contact %}
{% assign buyer_vat_id = buyer | custom_field: 'VAT ID' %}
{% assign buyer_reg_id = buyer | custom_field: 'Registration ID' %}
{% assign buyer_email = buyer.primary_email %}
Use the values inside the buyer block of the XML. The element order of ram:BuyerTradeParty matters:
<ram:BuyerTradeParty>
<ram:Name>{{ buyer_name | xml_escape }}</ram:Name>
{% if buyer_reg_id != blank %}<ram:SpecifiedLegalOrganization><ram:ID>{{ buyer_reg_id | xml_escape }}</ram:ID></ram:SpecifiedLegalOrganization>{% endif %}
<ram:PostalTradeAddress>...</ram:PostalTradeAddress>
{% if buyer_email != blank %}<ram:URIUniversalCommunication><ram:URIID schemeID="EM">{{ buyer_email | xml_escape }}</ram:URIID></ram:URIUniversalCommunication>{% endif %}
{% if buyer_vat_id != blank %}<ram:SpecifiedTaxRegistration><ram:ID schemeID="VA">{{ buyer_vat_id | xml_escape }}</ram:ID></ram:SpecifiedTaxRegistration>{% endif %}
</ram:BuyerTradeParty>
This covers the buyer legal registration ID (BT-47), the buyer email for receiving the invoice (BT-49) and the buyer VAT ID (BT-48). Add the fields to Administration, then Custom fields, then Contacts. Add the schemeID attribute to the registration ID when your buyer requires it.
Leitweg-ID and buyer reference
Both templates put the invoice Order number into the buyer reference (BuyerReference). For an invoice to a German public authority, enter its Leitweg-ID (for example 04011000-12345-03) in Order number. When Order number is empty, the invoice number is used.
Get the PDF and the XML
When the invoice has a template, the invoice page shows the PDF button and, if the template has an XML invoice, the XML button, before Edit and Copy.
To get the e-invoice:
- Open the invoice.
- Click PDF for the hybrid PDF, or XML for the XML alone.
The files are named after the invoice: invoice-NUMBER.pdf and invoice-NUMBER.xml.
Both files are also available on the Preview page (..., then Preview): Download as PDF and Download XML (template name).


To get the XML of several templates at once, select ..., then Reports, pick the templates and click Preview: there is one Download XML button per template with an XML invoice.
The PDF sent with Send and the PDF behind the Public link are hybrid PDFs too.
Write your own XML invoice
You can change the downloaded templates or write the block into your existing template. The printed part stays as it is; add the block at the end:
{% xml_invoice %}
<?xml version="1.0" encoding="UTF-8"?>
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" ...>
<rsm:ExchangedDocument>
<ram:ID>{{ invoice.number | xml_escape }}</ram:ID>
<ram:TypeCode>380</ram:TypeCode>
<ram:IssueDateTime><udt:DateTimeString format="102">{{ invoice.invoice_date | date: '%Y%m%d' }}</udt:DateTimeString></ram:IssueDateTime>
</rsm:ExchangedDocument>
...
{% for line in invoice.lines %}
<ram:IncludedSupplyChainTradeLineItem>
<ram:SpecifiedTradeProduct><ram:Name>{{ line.description | xml_escape }}</ram:Name></ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement><ram:NetPriceProductTradePrice><ram:ChargeAmount>{{ line.price | round: 2 }}</ram:ChargeAmount></ram:NetPriceProductTradePrice></ram:SpecifiedLineTradeAgreement>
...
</ram:IncludedSupplyChainTradeLineItem>
{% endfor %}
...
</rsm:CrossIndustryInvoice>
{% endxml_invoice %}
Rules for the block:
- Pass every text value through the
xml_escapefilter. It escapes ampersands, angle brackets and quotes and removes characters XML does not allow; a company name like Smith & Sons breaks the XML without it. - Write amounts with
| round: 2and dates with| date: '%Y%m%d'(format102). - Taxes by rate are in
invoice.tax_groups:group[0]is the rate,group[1]the tax amount,group[2]the base. - All template variables work inside the block.
The XML must be well-formed. If it is not, the PDF and the XML are not created and Redmine shows Failed to generate the invoice PDF. See the server log for details. The server log names the line of the error.
XRechnung differs from the Factur-X template by the guideline ID urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0, the business process ID, the seller contact (name, phone, email) and the electronic addresses of the seller and the buyer. Compare the two downloaded files to see every change.
Units of measure
The invoice line has no unit field. To bill hours, days or kilometres, add a custom field Unit to invoice lines (Administration, then Custom fields, then Invoice lines, list format with values such as hour, day) and map it to a UN/ECE unit code in the line block:
{% assign unit = line | custom_field: 'Unit' %}
{% case unit %}
{% when 'hour' %}{% assign unit_code = 'HUR' %}
{% when 'day' %}{% assign unit_code = 'DAY' %}
{% when 'km' %}{% assign unit_code = 'KMT' %}
{% when 'lump sum' %}{% assign unit_code = 'LS' %}
{% else %}{% assign unit_code = 'C62' %}
{% endcase %}
<ram:BilledQuantity unitCode="{{ unit_code }}">{{ line.quantity }}</ram:BilledQuantity>
| Unit | Code |
|---|---|
| Piece | C62 |
| Hour | HUR |
| Day | DAY |
| Kilometre | KMT |
| Lump sum | LS |
Partial payments
The templates write the paid amount into TotalPrepaidAmount and the rest into DuePayableAmount, so the totals pass the check Amount due = Grand total - Paid amount (BR-CO-16) for partially paid invoices:
<ram:GrandTotalAmount>{{ invoice.amount | round: 2 }}</ram:GrandTotalAmount>
<ram:TotalPrepaidAmount>{{ invoice.balance | round: 2 }}</ram:TotalPrepaidAmount>
<ram:DuePayableAmount>{{ invoice.remaining_balance | round: 2 }}</ram:DuePayableAmount>
If you downloaded a template earlier, add the TotalPrepaidAmount line to it.
Discounts
A discount of the whole invoice is a document-level allowance. The line totals are written before the discount, the allowance is the difference to the net amount (invoice.subtotal, which already has the discount), and the tax basis is the net amount. Put the allowance after the ApplicableTradeTax blocks and the total in the summation:
{% assign lines_total = 0 %}
{% for line in invoice.lines %}{% assign lines_total = lines_total | plus: line.total %}{% endfor %}
{% assign allowance = lines_total | minus: invoice.subtotal %}
{% if allowance > 0 %}
<ram:SpecifiedTradeAllowanceCharge>
<ram:ChargeIndicator><udt:Indicator>false</udt:Indicator></ram:ChargeIndicator>
<ram:ActualAmount>{{ allowance | round: 2 }}</ram:ActualAmount>
<ram:Reason>Discount</ram:Reason>
<ram:CategoryTradeTax><ram:TypeCode>VAT</ram:TypeCode><ram:CategoryCode>S</ram:CategoryCode><ram:RateApplicablePercent>19</ram:RateApplicablePercent></ram:CategoryTradeTax>
</ram:SpecifiedTradeAllowanceCharge>
{% endif %}
<ram:LineTotalAmount>{{ lines_total | round: 2 }}</ram:LineTotalAmount>
{% if allowance > 0 %}<ram:AllowanceTotalAmount>{{ allowance | round: 2 }}</ram:AllowanceTotalAmount>{% endif %}
<ram:TaxBasisTotalAmount>{{ invoice.subtotal | round: 2 }}</ram:TaxBasisTotalAmount>
The example is for the discount that is applied before tax. Use the tax rate of your invoice in RateApplicablePercent. With several tax rates write one allowance per rate. Check the result in a validator before you send it.
Check your e-invoice
Before you send the first e-invoice made with a changed template, check one:
- the XML or the hybrid PDF in the Mediaatelier e-invoice validator (runs in the browser, nothing is uploaded) or the official KoSIT validator for XRechnung;
- the hybrid PDF in veraPDF with the profile PDF/A-3b Basic.
Limitations
- Tax categories: a line with tax gets category
S(standard rate), a line with 0% getsZ(zero rated). Exempt (E), reverse charge (AE) and intra-community (K) supplies need an exemption reason and are not covered by the templates. - The templates use the unit code
C62(piece) for every line. See Units of measure below to change it. - The hybrid PDF is marked as Factur-X profile EN 16931, also when the XML inside is XRechnung. Send XRechnung as the XML file.
- The PDF is made by
wkhtmltopdf(version 0.12.6 was checked). After you upgradewkhtmltopdf, check one hybrid PDF in veraPDF again.