en16931-formats 0.2.0

European e-invoicing formats on top of the EN 16931 semantic model: UBL 2.1 and UN/CEFACT CII in both directions, the XRechnung CIUS, and ZUGFeRD / Factur-X hybrid PDFs. Every business rule is delegated to `en16931`.
Documentation
//! The UBL 2.1 element order, derived from the authorities' own instances.
//!
//! **Generated by `cargo xtask codegen`. Do not edit.**
//!
//! Derived from **320** published `Invoice` / `CreditNote` documents under
//! `spec/` — CEN unit tests, KoSIT mutation instances, OpenPeppol examples —
//! covering 36 parent elements.
//!
//! UBL 2.1 content models are XSD `sequence`s: a document carrying the right
//! elements in the wrong order is invalid, and **no Schematron rule reports
//! it**, because ordering is the schema's job and this crate ships no schema.
//!
//! For each parent, the child order is the topological sort of the pairwise
//! precedences observed across all of them, taking the **majority** direction
//! where instances disagree — and they do, because much of that corpus is
//! deliberately invalid. `cargo xtask codegen` exits non-zero rather than
//! emitting a table it could not derive cleanly, so a cycle or a tied pair
//! fails the build instead of becoming a guess written to disk.
//!
//! [`mod@super::write`] does not consult this table directly — the shared serialiser
//! sorts by it, so the writer emits in whatever order reads best and cannot
//! produce a misordered document at all.

/// `(parent, children in sequence order)` for every element observed with more
/// than one distinct child. Sorted by parent, for binary search.
pub static ORDER: &[(&str, &[&str])] = &[
    (
        "AdditionalDocumentReference",
        &[
            "ID",
            "DocumentDescription",
            "Attachment",
            "DocumentTypeCode",
        ],
    ),
    ("AdditionalItemProperty", &["Name", "Value"]),
    (
        "Address",
        &[
            "StreetName",
            "AdditionalStreetName",
            "CityName",
            "PostalZone",
            "CountrySubentity",
            "AddressLine",
            "Country",
        ],
    ),
    (
        "AllowanceCharge",
        &[
            "ChargeIndicator",
            "AllowanceChargeReasonCode",
            "AllowanceChargeReason",
            "MultiplierFactorNumeric",
            "Amount",
            "BaseAmount",
            "TaxCategory",
        ],
    ),
    (
        "Attachment",
        &["EmbeddedDocumentBinaryObject", "ExternalReference"],
    ),
    (
        "CardAccount",
        &["PrimaryAccountNumberID", "NetworkID", "HolderName"],
    ),
    ("ClassifiedTaxCategory", &["ID", "Percent", "TaxScheme"]),
    ("Contact", &["Name", "Telephone", "ElectronicMail"]),
    (
        "CreditNote",
        &[
            "UBLVersionID",
            "CustomizationID",
            "ProfileID",
            "ID",
            "IssueDate",
            "TaxPointDate",
            "CreditNoteTypeCode",
            "Note",
            "DocumentCurrencyCode",
            "TaxCurrencyCode",
            "AccountingCost",
            "BuyerReference",
            "InvoicePeriod",
            "OrderReference",
            "BillingReference",
            "DespatchDocumentReference",
            "ReceiptDocumentReference",
            "ContractDocumentReference",
            "AdditionalDocumentReference",
            "OriginatorDocumentReference",
            "AccountingSupplierParty",
            "AccountingCustomerParty",
            "PayeeParty",
            "TaxRepresentativeParty",
            "Delivery",
            "PaymentMeans",
            "PaymentTerms",
            "AllowanceCharge",
            "TaxTotal",
            "LegalMonetaryTotal",
            "CreditNoteLine",
        ],
    ),
    (
        "CreditNoteLine",
        &[
            "ID",
            "Note",
            "CreditedQuantity",
            "LineExtensionAmount",
            "AccountingCost",
            "InvoicePeriod",
            "OrderLineReference",
            "DocumentReference",
            "AllowanceCharge",
            "Item",
            "Price",
        ],
    ),
    (
        "Delivery",
        &["ActualDeliveryDate", "DeliveryLocation", "DeliveryParty"],
    ),
    ("DeliveryLocation", &["ID", "Address"]),
    ("DocumentReference", &["ID", "DocumentTypeCode"]),
    (
        "Invoice",
        &[
            "UBLExtensions",
            "UBLVersionID",
            "CustomizationID",
            "ProfileID",
            "ID",
            "IssueDate",
            "DueDate",
            "InvoiceTypeCode",
            "Note",
            "TaxPointDate",
            "DocumentCurrencyCode",
            "TaxCurrencyCode",
            "AccountingCost",
            "BuyerReference",
            "InvoicePeriod",
            "OrderReference",
            "BillingReference",
            "DespatchDocumentReference",
            "ReceiptDocumentReference",
            "OriginatorDocumentReference",
            "ContractDocumentReference",
            "AdditionalDocumentReference",
            "ProjectReference",
            "AccountingSupplierParty",
            "AccountingCustomerParty",
            "PayeeParty",
            "TaxRepresentativeParty",
            "Delivery",
            "PaymentMeans",
            "PaymentTerms",
            "PrepaidPayment",
            "AllowanceCharge",
            "TaxTotal",
            "LegalMonetaryTotal",
            "InvoiceLine",
        ],
    ),
    ("InvoiceDocumentReference", &["ID", "IssueDate"]),
    (
        "InvoiceLine",
        &[
            "ID",
            "Note",
            "InvoicedQuantity",
            "LineExtensionAmount",
            "AccountingCost",
            "InvoicePeriod",
            "OrderLineReference",
            "DocumentReference",
            "AllowanceCharge",
            "Item",
            "Price",
            "SubInvoiceLine",
        ],
    ),
    (
        "InvoicePeriod",
        &["StartDate", "EndDate", "DescriptionCode"],
    ),
    (
        "Item",
        &[
            "Description",
            "Name",
            "BuyersItemIdentification",
            "SellersItemIdentification",
            "StandardItemIdentification",
            "OriginCountry",
            "CommodityClassification",
            "ClassifiedTaxCategory",
            "AdditionalItemProperty",
        ],
    ),
    (
        "LegalMonetaryTotal",
        &[
            "LineExtensionAmount",
            "TaxExclusiveAmount",
            "TaxInclusiveAmount",
            "AllowanceTotalAmount",
            "ChargeTotalAmount",
            "PrepaidAmount",
            "PayableRoundingAmount",
            "PayableAmount",
        ],
    ),
    ("OrderLineReference", &["LineID", "OrderReference"]),
    ("OrderReference", &["ID", "SalesOrderID"]),
    (
        "Party",
        &[
            "EndpointID",
            "PartyIdentification",
            "PartyName",
            "PostalAddress",
            "PartyTaxScheme",
            "PartyLegalEntity",
            "Contact",
        ],
    ),
    (
        "PartyLegalEntity",
        &["RegistrationName", "CompanyID", "CompanyLegalForm"],
    ),
    ("PartyTaxScheme", &["CompanyID", "TaxScheme"]),
    (
        "PayeeFinancialAccount",
        &["ID", "Name", "FinancialInstitutionBranch"],
    ),
    (
        "PayeeParty",
        &["PartyIdentification", "PartyName", "PartyLegalEntity"],
    ),
    ("PaymentMandate", &["ID", "PayerFinancialAccount"]),
    (
        "PaymentMeans",
        &[
            "PaymentMeansCode",
            "PaymentID",
            "CardAccount",
            "PayeeFinancialAccount",
            "CreditAccount",
            "PaymentMandate",
        ],
    ),
    (
        "PostalAddress",
        &[
            "StreetName",
            "AdditionalStreetName",
            "CityName",
            "PostalZone",
            "CountrySubentity",
            "AddressLine",
            "Country",
        ],
    ),
    ("PrepaidPayment", &["ID", "PaidAmount", "InstructionID"]),
    ("Price", &["PriceAmount", "BaseQuantity", "AllowanceCharge"]),
    (
        "SubInvoiceLine",
        &[
            "ID",
            "InvoicedQuantity",
            "LineExtensionAmount",
            "Item",
            "Price",
            "SubInvoiceLine",
        ],
    ),
    (
        "TaxCategory",
        &[
            "ID",
            "Percent",
            "TaxExemptionReasonCode",
            "TaxExemptionReason",
            "TaxScheme",
        ],
    ),
    (
        "TaxRepresentativeParty",
        &["PartyName", "PostalAddress", "PartyTaxScheme"],
    ),
    (
        "TaxSubtotal",
        &["TaxableAmount", "TaxAmount", "TaxCategory"],
    ),
    ("TaxTotal", &["TaxAmount", "TaxSubtotal"]),
];

/// The canonical child order for a parent element, if one was observed.
#[must_use]
pub fn children_of(parent: &str) -> Option<&'static [&'static str]> {
    ORDER
        .binary_search_by_key(&parent, |(p, _)| *p)
        .ok()
        .map(|i| ORDER[i].1)
}

/// The position of `child` within `parent`'s sequence.
#[must_use]
pub fn index_of(parent: &str, child: &str) -> Option<usize> {
    children_of(parent)?.iter().position(|c| *c == child)
}