ZUGFeRD / mustangproject

Open Source Java e-Invoicing library, validator and tool (Factur-X/ZUGFeRD, UNCEFACT/CII XRechnung)
http://www.mustangproject.org
Apache License 2.0
234 stars 132 forks source link

Add Field for "Invoiced Object Identifier" (BT-18) in Invoice.java to Align with XRechnung Requirements #536

Open fktrdui opened 3 weeks ago

fktrdui commented 3 weeks ago

The Invoice.java class currently lacks a field for storing the "Invoiced Object Identifier" (BT-18), which is required at the entire-invoice level in XRechnung. This identifier is essential for referencing objects related to the entire invoice, similar to the way Item.java stores "Invoice Line Object Identifier" (BT-128).

BT18

BT128

Mustang has the specification of mapping BT-18 to XML as follows: (https://github.com/ZUGFeRD/mustangproject/blob/master/library/src/main/resources/stylesheets/cii-xr.xsl) <xsl:apply-templates mode="BT-18" select="./rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:AdditionalReferencedDocument/ram:IssuerAssignedID[following-sibling::ram:TypeCode='130']"/>

In the current setup: Item.java includes field (referencedDocuments) to store ReferencedDocument objects, allowing it to handle "Invoice Line Object Identifier" (BT-128).

However, Invoice.java has no corresponding field to hold ReferencedDocument instances for BT-18 at the invoice level.

Suggested Solution: To align with XRechnung requirements, add an ArrayList field in Invoice.java to store BT-18 references. This new field would ensure consistency across classes, allowing Invoice.java to manage invoice-wide object identifiers similarly to how Item.java handles line-specific identifiers.

public class Invoice {

    // New field for storing Invoiced Object Identifier (BT-18)
    protected ArrayList<ReferencedDocument> invoiceReferencedDocuments = null;

    // Getter for BT-18
    public ArrayList<ReferencedDocument> getInvoiceReferencedDocuments() {
        return invoiceReferencedDocuments;
    }

    // Setter for BT-18
    public void setInvoiceReferencedDocuments(ArrayList<ReferencedDocument> invoiceReferencedDocuments) {
        this.invoiceReferencedDocuments = invoiceReferencedDocuments;
    }

    // Method to add a single ReferencedDocument for BT-18
    public void addInvoiceReferencedDocument(ReferencedDocument doc) {
        if (invoiceReferencedDocuments == null) {
            invoiceReferencedDocuments = new ArrayList<>();
        }
        invoiceReferencedDocuments.add(doc);
    }
}

Suggested XML Output Update: With the proposed changes, Invoice.java should generate XML for ./rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:AdditionalReferencedDocument as follows:


if (trans.getInvoiceReferencedDocuments() != null) {
    for (final IReferencedDocument currentReferencedDocument : trans.getReferencedDocuments()) {
        xml += "<ram:AdditionalReferencedDocument>" +
               "<ram:IssuerAssignedID>" + XMLTools.encodeXML(currentReferencedDocument.getIssuerAssignedID()) + "</ram:IssuerAssignedID>" +
               "<ram:TypeCode>" + XMLTools.encodeXML(currentReferencedDocument.getTypeCode()) + "</ram:TypeCode>" +
               "<ram:ReferenceTypeCode>" + XMLTools.encodeXML(currentReferencedDocument.getReferenceTypeCode()) + "</ram:ReferenceTypeCode>" +
               "</ram:AdditionalReferencedDocument>";
    }
}
johamb commented 3 days ago

+1 This would also enable adding "Tender or lot reference" (BT-17).