Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`/
Expand Down
56 changes: 38 additions & 18 deletions src/main/java/de/codebarista/gallop/cii/CIIXMLEInvoiceWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand All @@ -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()));
}
Expand Down
85 changes: 78 additions & 7 deletions src/main/java/de/codebarista/gallop/model/Invoice.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,31 @@ public class Invoice {
private String currency;

/**
* BuyerReference (BT-10)<br>
* Usually a "Leitweg-ID"
* Buyer reference (BT-10)
* <p>
* 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)
* <p>
* 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).
* <p>
* 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)
* <p>
* 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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/codebarista/gallop/BuildInvoiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/de/codebarista/gallop/ScenarioHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1049",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1086",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1014",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1074",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1081",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "58",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1012",
"leitwegId": "N/A",
"buyerReference": "N/A",
"currency": "EUR",
"paymentInstructions": {
"meansType": "10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1014",
"leitwegId": "N/A",
"buyerReference": "N/A",
"businessProcessType": "B1",
"currency": "EUR",
"paymentInstructions": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"documentTypeCode": "380",
"documentId": "1013",
"leitwegId": "N/A",
"buyerReference": "N/A",
"businessProcessType": "B1",
"currency": "EUR",
"paymentInstructions": {
Expand Down
Loading
Loading