diff --git a/README.md b/README.md
index 8c33e3d..59e720b 100644
--- a/README.md
+++ b/README.md
@@ -98,7 +98,7 @@ public class InvoiceGenerator {
Invoice invoice = Invoice.create()
.documentTypeCode(InvoiceType.COMMERCIAL_INVOICE.getValue()) // Define invoice type
.documentId("INV-2025-1001") // Unique invoice identifier
- .leitwegId("N/A") // Buyer reference (BT-10)
+ .buyerReference("N/A") // Buyer reference (BT-10)
.currency("EUR") // Currency used for the invoice
// Payment details including method and terms
@@ -202,9 +202,13 @@ public class InvoiceGenerator {
- UNRELEASED: Optional elements are only written when they have a value: the seller contact (BG-6) and each of its
details, and the seller/buyer electronic address (BT-34/BT-49). The electronic address is now written with its
scheme (`SellerOrBuyer.electronicAddressScheme`, falling back to `EM`) instead of always `EM`. **Behavior change:**
- `BuyerReference` (BT-10) is only written if `Invoice.leitwegId` is set; Gallop no longer
+ `BuyerReference` (BT-10) is only written if `Invoice.buyerReference` is set; Gallop no longer
writes `N/A` without it. XRechnung requires BT-10 (BR-DE-15), so set e.g. `N/A` yourself if there is no
- reference. Includes the changes of 3.1.0.
+ reference. Add purchase order reference (`Invoice.buyerOrderReference`, BT-13) and VAT point date code
+ (`Invoice.vatPointDateCode`, BT-8, written as `ram:DueDateTypeCode` in every VAT breakdown, e.g. `5` for VAT on
+ debits). `Invoice.leitwegId` was renamed to `buyerReference` (BT-10); `leitwegId(...)`/`getLeitwegId()` are
+ deprecated. **Fix:** the VAT exemption reason code (BT-121) is now written after `ram:CategoryCode` as required by
+ the CII schema; before, invoices with BT-121 were schema-invalid. Includes the changes of 3.1.0.
- 3.1.0: Add the fields required by the French rules for Factur-X: invoice
note subject code (`InvoiceNote.subjectCode`, BT-21), business process type (`Invoice.businessProcessType`,
BT-23, overrides the format's default) and seller/buyer identifier with scheme (`SellerOrBuyer.identifier`/
diff --git a/src/main/java/de/codebarista/gallop/cii/CIIXMLEInvoiceWriter.java b/src/main/java/de/codebarista/gallop/cii/CIIXMLEInvoiceWriter.java
index 45770e6..396262e 100644
--- a/src/main/java/de/codebarista/gallop/cii/CIIXMLEInvoiceWriter.java
+++ b/src/main/java/de/codebarista/gallop/cii/CIIXMLEInvoiceWriter.java
@@ -184,7 +184,7 @@ private static Element createTradeLineItem(Item lineItem, XmlDocumentBuilder bui
Element specifiedSettlement = builder.createElement(NS_RAM, "SpecifiedLineTradeSettlement");
tradeLineItem.appendChild(specifiedSettlement);
if (lineItem.getVat() != null) {
- specifiedSettlement.appendChild(createTax(builder, lineItem.getVat()));
+ specifiedSettlement.appendChild(createTax(builder, lineItem.getVat(), null));
}
if (lineItem.getItemTotalNetAmount() != null) {
Element taxSummation = builder.createElement(NS_RAM, "SpecifiedTradeSettlementLineMonetarySummation");
@@ -199,9 +199,9 @@ private static Element createTradeLineItem(Item lineItem, XmlDocumentBuilder bui
private Element createTradeHeader(XmlDocumentBuilder builder) {
Element tradeHeader = builder.createElement(NS_RAM, "ApplicableHeaderTradeAgreement");
- if (GallopUtils.isNotNullOrBlank(invoice.getLeitwegId())) {
- Element buyerRef = builder.createElement(NS_RAM, "BuyerReference");
- buyerRef.setTextContent(invoice.getLeitwegId());
+ if (GallopUtils.isNotNullOrBlank(invoice.getBuyerReference())) {
+ Element buyerRef = builder.createElement(NS_RAM, "BuyerReference"); // BT-10
+ buyerRef.setTextContent(invoice.getBuyerReference());
tradeHeader.appendChild(buyerRef);
}
@@ -276,17 +276,26 @@ private Element createTradeHeader(XmlDocumentBuilder builder) {
}
}
- if (GallopUtils.isNotNullOrBlank(invoice.getSalesOrderReference())) {
- Element sellerRefDoc = builder.createElement(NS_RAM, "SellerOrderReferencedDocument");
- tradeHeader.appendChild(sellerRefDoc);
- Element issuerId = builder.createElement(NS_RAM, "IssuerAssignedID");
- issuerId.setTextContent(invoice.getSalesOrderReference());
- sellerRefDoc.appendChild(issuerId);
+ if (GallopUtils.isNotNullOrBlank(invoice.getSalesOrderReference())) { // BT-14
+ tradeHeader.appendChild(createReferencedDocument(
+ builder, "SellerOrderReferencedDocument", invoice.getSalesOrderReference()));
+ }
+ if (GallopUtils.isNotNullOrBlank(invoice.getBuyerOrderReference())) { // BT-13
+ tradeHeader.appendChild(createReferencedDocument(
+ builder, "BuyerOrderReferencedDocument", invoice.getBuyerOrderReference()));
}
return tradeHeader;
}
+ private static Element createReferencedDocument(XmlDocumentBuilder builder, String elementName, String id) {
+ Element referencedDocument = builder.createElement(NS_RAM, elementName);
+ Element issuerId = builder.createElement(NS_RAM, "IssuerAssignedID");
+ issuerId.setTextContent(id);
+ referencedDocument.appendChild(issuerId);
+ return referencedDocument;
+ }
+
private Element createTradeDelivery(XmlDocumentBuilder builder) {
Element tradeDelivery = builder.createElement(NS_RAM, "ApplicableHeaderTradeDelivery");
DeliveryInformation deliveryInfo = invoice.getDeliveryInfo();
@@ -339,7 +348,7 @@ private Element createTradeSettlement(XmlDocumentBuilder builder) {
}
}
for (Vat totalVat : invoice.getVatTotals()) {
- tradeSettlement.appendChild(createTax(builder, totalVat));
+ tradeSettlement.appendChild(createTax(builder, totalVat, invoice.getVatPointDateCode()));
}
for (Allowance allowance : invoice.getAllowances()) {
tradeSettlement.appendChild(createAllowance(builder, allowance));
@@ -635,7 +644,13 @@ private static Element createAddress(XmlDocumentBuilder builder, PostalAddress a
return tradeAddress;
}
- private static Element createTax(XmlDocumentBuilder builder, Vat vat) {
+ /**
+ * Writes a VAT breakdown (BG-23) or the line VAT information (BG-30).
+ *
+ * @param vatPointDateCode the VAT point date code (BT-8), only for the VAT breakdown on document level;
+ * {@code null} for invoice lines
+ */
+ private static Element createTax(XmlDocumentBuilder builder, Vat vat, String vatPointDateCode) {
Element tradeTax = builder.createElement(NS_RAM, "ApplicableTradeTax");
if (vat != null) {
if (vat.getTaxAmount() != null) {
@@ -649,19 +664,24 @@ private static Element createTax(XmlDocumentBuilder builder, Vat vat) {
exemptionReasonText.setTextContent(vat.getVatExemptionReasonText());
tradeTax.appendChild(exemptionReasonText);
}
- if (GallopUtils.isNotNullOrBlank(vat.getVatExemptionReasonCode())) {
- Element exemptionReasonCode = builder.createElement(NS_RAM, "ExemptionReasonCode"); // BT-121
- exemptionReasonCode.setTextContent(vat.getVatExemptionReasonCode());
- tradeTax.appendChild(exemptionReasonCode);
- }
if (vat.getTaxableAmount() != null) {
- Element basis = builder.createElement(NS_RAM, "BasisAmount");
+ Element basis = builder.createElement(NS_RAM, "BasisAmount"); // BT-116
basis.setTextContent(vat.getTaxableAmount().toString());
tradeTax.appendChild(basis);
}
if (vat.getCategory() != null) {
tradeTax.appendChild(createCategoryCode(builder, vat.getCategory().getCategoryCode()));
}
+ if (GallopUtils.isNotNullOrBlank(vat.getVatExemptionReasonCode())) {
+ Element exemptionReasonCode = builder.createElement(NS_RAM, "ExemptionReasonCode"); // BT-121
+ exemptionReasonCode.setTextContent(vat.getVatExemptionReasonCode());
+ tradeTax.appendChild(exemptionReasonCode);
+ }
+ if (GallopUtils.isNotNullOrBlank(vatPointDateCode)) {
+ Element dueDateTypeCode = builder.createElement(NS_RAM, "DueDateTypeCode"); // BT-8
+ dueDateTypeCode.setTextContent(vatPointDateCode);
+ tradeTax.appendChild(dueDateTypeCode);
+ }
if (vat.getRate() != null) {
tradeTax.appendChild(createRate(builder, vat.getRate().toString()));
}
diff --git a/src/main/java/de/codebarista/gallop/model/Invoice.java b/src/main/java/de/codebarista/gallop/model/Invoice.java
index a17aa73..572d792 100644
--- a/src/main/java/de/codebarista/gallop/model/Invoice.java
+++ b/src/main/java/de/codebarista/gallop/model/Invoice.java
@@ -32,10 +32,31 @@ public class Invoice {
private String currency;
/**
- * BuyerReference (BT-10)
- * Usually a "Leitweg-ID"
+ * Buyer reference (BT-10)
+ *
+ * An identifier assigned by the buyer used for internal routing purposes, e.g. the German "Leitweg-ID" or + * the French service code (code service) of Chorus Pro. + */ + private String buyerReference; + + /** + * Value added tax point date code (BT-8) + *
+ * The code of the date when the VAT becomes accountable for the seller and the buyer. Code list UNTDID 2475 + * in CII: {@code 5} (invoice date), {@code 29} (delivery date), {@code 72} (paid to date). + *
+ * It is written in every VAT breakdown (BG-23). According to BR-CO-3 it must not be used together with the + * VAT point date (BT-7). + */ + private String vatPointDateCode; + + /** + * Purchase order reference (BT-13) + *
+ * An identifier of a referenced purchase order, issued by the buyer. For the French public sector this is
+ * e.g. the commitment number (numéro d'engagement).
*/
- private String leitwegId;
+ private String buyerOrderReference;
/**
* Business process type (BT-23)
@@ -197,10 +218,36 @@ public Invoice currency(String currency) {
}
/**
- * Sets the {@link #leitwegId}
+ * Sets the {@link #buyerReference}
*/
+ public Invoice buyerReference(String buyerReference) {
+ this.buyerReference = buyerReference;
+ return this;
+ }
+
+ /**
+ * Sets the {@link #buyerReference}
+ *
+ * @deprecated use {@link #buyerReference(String)} instead
+ */
+ @Deprecated
public Invoice leitwegId(String leitwegId) {
- this.leitwegId = leitwegId;
+ return buyerReference(leitwegId);
+ }
+
+ /**
+ * Sets the {@link #vatPointDateCode}
+ */
+ public Invoice vatPointDateCode(String vatPointDateCode) {
+ this.vatPointDateCode = vatPointDateCode;
+ return this;
+ }
+
+ /**
+ * Sets the {@link #buyerOrderReference}
+ */
+ public Invoice buyerOrderReference(String buyerOrderReference) {
+ this.buyerOrderReference = buyerOrderReference;
return this;
}
@@ -491,10 +538,34 @@ public String getCurrency() {
}
/**
- * Gets the {@link #leitwegId}.
+ * Gets the {@link #buyerReference}.
*/
+ public String getBuyerReference() {
+ return buyerReference;
+ }
+
+ /**
+ * Gets the {@link #buyerReference}.
+ *
+ * @deprecated use {@link #getBuyerReference()} instead
+ */
+ @Deprecated
public String getLeitwegId() {
- return leitwegId;
+ return getBuyerReference();
+ }
+
+ /**
+ * Gets the {@link #vatPointDateCode}.
+ */
+ public String getVatPointDateCode() {
+ return vatPointDateCode;
+ }
+
+ /**
+ * Gets the {@link #buyerOrderReference}.
+ */
+ public String getBuyerOrderReference() {
+ return buyerOrderReference;
}
/**
diff --git a/src/test/java/de/codebarista/gallop/BuildInvoiceTest.java b/src/test/java/de/codebarista/gallop/BuildInvoiceTest.java
index bec1014..5a32420 100644
--- a/src/test/java/de/codebarista/gallop/BuildInvoiceTest.java
+++ b/src/test/java/de/codebarista/gallop/BuildInvoiceTest.java
@@ -31,7 +31,7 @@ public void buildInvoice() {
Invoice invoice = Invoice.create()
.documentTypeCode(InvoiceType.COMMERCIAL_INVOICE.getValue()) // Define invoice type
.documentId("INV-2025-1001") // Unique invoice identifier
- .leitwegId("N/A") // Buyer reference (BT-10)
+ .buyerReference("N/A") // Buyer reference (BT-10) e.g. German "Leitweg-ID" or French "code service"
.currency("EUR") // Currency used for the invoice
// Payment details including method and terms
diff --git a/src/test/java/de/codebarista/gallop/ScenarioHelper.java b/src/test/java/de/codebarista/gallop/ScenarioHelper.java
index 8b0659c..89cdd39 100644
--- a/src/test/java/de/codebarista/gallop/ScenarioHelper.java
+++ b/src/test/java/de/codebarista/gallop/ScenarioHelper.java
@@ -37,6 +37,7 @@ public ScenarioFormats(String scenario, EInvoiceFormat... formats) {
new ScenarioFormats("order_with_discount_code_and_shipping_costs_with_multiple_taxes", XRECHNUNG, EN16931_CORE),
new ScenarioFormats("order_with_french_b2c_billing_note_without_buyer_identifiers", EN16931_CORE),
new ScenarioFormats("order_with_french_mandatory_notes_and_billing_mode", EN16931_CORE),
+ new ScenarioFormats("order_with_french_purchase_order_and_vat_on_debits", EN16931_CORE),
new ScenarioFormats("order_with_legal_registration_identifiers", XRECHNUNG, EN16931_CORE),
new ScenarioFormats("order_with_leitweg_id_partial_seller_contact_and_buyer_address_scheme", XRECHNUNG, EN16931_CORE),
new ScenarioFormats("order_with_payment_in_advance", XRECHNUNG, EN16931_CORE),
@@ -48,6 +49,7 @@ public ScenarioFormats(String scenario, EInvoiceFormat... formats) {
new ScenarioFormats("order_with_seller_and_buyer_identifiers", XRECHNUNG, EN16931_CORE),
new ScenarioFormats("order_with_shipping_costs_with_multiple_taxes", XRECHNUNG, EN16931_CORE),
new ScenarioFormats("order_with_tax_free_product", XRECHNUNG, EN16931_CORE),
+ new ScenarioFormats("order_with_vat_exemption_reason_code", XRECHNUNG, EN16931_CORE),
new ScenarioFormats("order_without_vatid", XRECHNUNG, EN16931_CORE)
);
diff --git a/src/test/resources/invoice/order_with_allowance/invoice.json b/src/test/resources/invoice/order_with_allowance/invoice.json
index 0508cae..9d4e6ba 100644
--- a/src/test/resources/invoice/order_with_allowance/invoice.json
+++ b/src/test/resources/invoice/order_with_allowance/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1049",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
diff --git a/src/test/resources/invoice/order_with_already_paid_amount/invoice.json b/src/test/resources/invoice/order_with_already_paid_amount/invoice.json
index c2f615c..6cab9b1 100644
--- a/src/test/resources/invoice/order_with_already_paid_amount/invoice.json
+++ b/src/test/resources/invoice/order_with_already_paid_amount/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
diff --git a/src/test/resources/invoice/order_with_belgian_tax_rates_and_document_comment/invoice.json b/src/test/resources/invoice/order_with_belgian_tax_rates_and_document_comment/invoice.json
index 86aa618..6b300ac 100644
--- a/src/test/resources/invoice/order_with_belgian_tax_rates_and_document_comment/invoice.json
+++ b/src/test/resources/invoice/order_with_belgian_tax_rates_and_document_comment/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1086",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
diff --git a/src/test/resources/invoice/order_with_cash_payment/invoice.json b/src/test/resources/invoice/order_with_cash_payment/invoice.json
index 7368ef8..b458e5e 100644
--- a/src/test/resources/invoice/order_with_cash_payment/invoice.json
+++ b/src/test/resources/invoice/order_with_cash_payment/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
diff --git a/src/test/resources/invoice/order_with_credit_and_surcharge/invoice.json b/src/test/resources/invoice/order_with_credit_and_surcharge/invoice.json
index d95456e..0ef6653 100644
--- a/src/test/resources/invoice/order_with_credit_and_surcharge/invoice.json
+++ b/src/test/resources/invoice/order_with_credit_and_surcharge/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1014",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
diff --git a/src/test/resources/invoice/order_with_custom_line_item_type/invoice.json b/src/test/resources/invoice/order_with_custom_line_item_type/invoice.json
index eac8035..6f4ab4e 100644
--- a/src/test/resources/invoice/order_with_custom_line_item_type/invoice.json
+++ b/src/test/resources/invoice/order_with_custom_line_item_type/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1074",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
diff --git a/src/test/resources/invoice/order_with_customer_vatid/invoice.json b/src/test/resources/invoice/order_with_customer_vatid/invoice.json
index e2c3338..a41acc6 100644
--- a/src/test/resources/invoice/order_with_customer_vatid/invoice.json
+++ b/src/test/resources/invoice/order_with_customer_vatid/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
diff --git a/src/test/resources/invoice/order_with_different_billing_and_shipping_address/invoice.json b/src/test/resources/invoice/order_with_different_billing_and_shipping_address/invoice.json
index fe99198..7685679 100644
--- a/src/test/resources/invoice/order_with_different_billing_and_shipping_address/invoice.json
+++ b/src/test/resources/invoice/order_with_different_billing_and_shipping_address/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1081",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
diff --git a/src/test/resources/invoice/order_with_discount_code_and_shipping_costs_with_multiple_taxes/invoice.json b/src/test/resources/invoice/order_with_discount_code_and_shipping_costs_with_multiple_taxes/invoice.json
index 60c2359..cd840aa 100644
--- a/src/test/resources/invoice/order_with_discount_code_and_shipping_costs_with_multiple_taxes/invoice.json
+++ b/src/test/resources/invoice/order_with_discount_code_and_shipping_costs_with_multiple_taxes/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
diff --git a/src/test/resources/invoice/order_with_french_b2c_billing_note_without_buyer_identifiers/invoice.json b/src/test/resources/invoice/order_with_french_b2c_billing_note_without_buyer_identifiers/invoice.json
index 5db7c89..8ca8025 100644
--- a/src/test/resources/invoice/order_with_french_b2c_billing_note_without_buyer_identifiers/invoice.json
+++ b/src/test/resources/invoice/order_with_french_b2c_billing_note_without_buyer_identifiers/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1014",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"businessProcessType": "B1",
"currency": "EUR",
"paymentInstructions": {
diff --git a/src/test/resources/invoice/order_with_french_mandatory_notes_and_billing_mode/invoice.json b/src/test/resources/invoice/order_with_french_mandatory_notes_and_billing_mode/invoice.json
index a19a0a7..fb41b36 100644
--- a/src/test/resources/invoice/order_with_french_mandatory_notes_and_billing_mode/invoice.json
+++ b/src/test/resources/invoice/order_with_french_mandatory_notes_and_billing_mode/invoice.json
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1013",
- "leitwegId": "N/A",
+ "buyerReference": "N/A",
"businessProcessType": "B1",
"currency": "EUR",
"paymentInstructions": {
diff --git a/src/test/resources/invoice/order_with_french_purchase_order_and_vat_on_debits/en16931-core.xml b/src/test/resources/invoice/order_with_french_purchase_order_and_vat_on_debits/en16931-core.xml
new file mode 100644
index 0000000..755b6fe
--- /dev/null
+++ b/src/test/resources/invoice/order_with_french_purchase_order_and_vat_on_debits/en16931-core.xml
@@ -0,0 +1,173 @@
+
+