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 CII D16B element order, derived from the authorities' own instances.
//!
//! **Generated by `cargo xtask codegen`. Do not edit.**
//!
//! Derived from **170** published `CrossIndustryInvoice` documents under
//! `spec/` — CEN unit tests, KoSIT mutation instances, OpenPeppol examples —
//! covering 38 parent elements.
//!
//! CII D16B 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])] = &[
    (
        "AdditionalReferencedDocument",
        &[
            "IssuerAssignedID",
            "URIID",
            "TypeCode",
            "Name",
            "AttachmentBinaryObject",
            "ReferenceTypeCode",
        ],
    ),
    (
        "ApplicableHeaderTradeAgreement",
        &[
            "BuyerReference",
            "SellerTradeParty",
            "BuyerTradeParty",
            "SellerTaxRepresentativeTradeParty",
            "SellerOrderReferencedDocument",
            "BuyerOrderReferencedDocument",
            "ContractReferencedDocument",
            "AdditionalReferencedDocument",
            "SpecifiedProcuringProject",
        ],
    ),
    (
        "ApplicableHeaderTradeDelivery",
        &[
            "ShipToTradeParty",
            "ActualDeliverySupplyChainEvent",
            "DespatchAdviceReferencedDocument",
            "ReceivingAdviceReferencedDocument",
        ],
    ),
    (
        "ApplicableHeaderTradeSettlement",
        &[
            "CreditorReferenceID",
            "PaymentReference",
            "TaxCurrencyCode",
            "InvoiceCurrencyCode",
            "PayeeTradeParty",
            "SpecifiedTradeSettlementPaymentMeans",
            "ApplicableTradeTax",
            "BillingSpecifiedPeriod",
            "SpecifiedTradeAllowanceCharge",
            "SpecifiedTradePaymentTerms",
            "SpecifiedTradeSettlementHeaderMonetarySummation",
            "InvoiceReferencedDocument",
            "ReceivableSpecifiedTradeAccountingAccount",
        ],
    ),
    ("ApplicableProductCharacteristic", &["Description", "Value"]),
    (
        "ApplicableTradeSettlementFinancialCard",
        &["ID", "CardholderName"],
    ),
    (
        "ApplicableTradeTax",
        &[
            "CalculatedAmount",
            "TypeCode",
            "ExemptionReason",
            "BasisAmount",
            "CategoryCode",
            "ExemptionReasonCode",
            "DueDateTypeCode",
            "TaxPointDate",
            "RateApplicablePercent",
        ],
    ),
    (
        "AppliedTradeAllowanceCharge",
        &["ChargeIndicator", "ActualAmount"],
    ),
    (
        "AssociatedDocumentLineDocument",
        &["LineID", "IncludedNote", "ParentLineID"],
    ),
    ("BillingSpecifiedPeriod", &["StartDateTime", "EndDateTime"]),
    (
        "BuyerOrderReferencedDocument",
        &["IssuerAssignedID", "LineID"],
    ),
    (
        "BuyerTradeParty",
        &[
            "GlobalID",
            "ID",
            "Name",
            "SpecifiedLegalOrganization",
            "DefinedTradeContact",
            "PostalTradeAddress",
            "URIUniversalCommunication",
            "SpecifiedTaxRegistration",
        ],
    ),
    (
        "CategoryTradeTax",
        &["TypeCode", "CategoryCode", "RateApplicablePercent"],
    ),
    (
        "CrossIndustryInvoice",
        &[
            "ExchangedDocumentContext",
            "ExchangedDocument",
            "SupplyChainTradeTransaction",
        ],
    ),
    (
        "DefinedTradeContact",
        &[
            "PersonName",
            "DepartmentName",
            "TelephoneUniversalCommunication",
            "EmailURIUniversalCommunication",
        ],
    ),
    (
        "ExchangedDocument",
        &["ID", "TypeCode", "IssueDateTime", "IncludedNote"],
    ),
    (
        "ExchangedDocumentContext",
        &[
            "BusinessProcessSpecifiedDocumentContextParameter",
            "GuidelineSpecifiedDocumentContextParameter",
        ],
    ),
    (
        "GrossPriceProductTradePrice",
        &[
            "ChargeAmount",
            "BasisQuantity",
            "AppliedTradeAllowanceCharge",
        ],
    ),
    ("IncludedNote", &["Content", "SubjectCode"]),
    (
        "IncludedSupplyChainTradeLineItem",
        &[
            "AssociatedDocumentLineDocument",
            "SpecifiedTradeProduct",
            "SpecifiedLineTradeAgreement",
            "SpecifiedLineTradeDelivery",
            "SpecifiedLineTradeSettlement",
        ],
    ),
    (
        "InvoiceReferencedDocument",
        &["IssuerAssignedID", "FormattedIssueDateTime"],
    ),
    (
        "NetPriceProductTradePrice",
        &["ChargeAmount", "BasisQuantity"],
    ),
    (
        "PayeePartyCreditorFinancialAccount",
        &["IBANID", "AccountName"],
    ),
    (
        "PayeeTradeParty",
        &["GlobalID", "ID", "Name", "SpecifiedLegalOrganization"],
    ),
    (
        "PostalTradeAddress",
        &[
            "PostcodeCode",
            "LineOne",
            "LineTwo",
            "LineThree",
            "CityName",
            "CountryID",
            "CountrySubDivisionName",
        ],
    ),
    (
        "SellerTaxRepresentativeTradeParty",
        &["Name", "PostalTradeAddress", "SpecifiedTaxRegistration"],
    ),
    (
        "SellerTradeParty",
        &[
            "GlobalID",
            "ID",
            "Name",
            "Description",
            "SpecifiedLegalOrganization",
            "DefinedTradeContact",
            "PostalTradeAddress",
            "URIUniversalCommunication",
            "SpecifiedTaxRegistration",
        ],
    ),
    (
        "ShipToTradeParty",
        &["GlobalID", "ID", "Name", "PostalTradeAddress"],
    ),
    ("SpecifiedLegalOrganization", &["ID", "TradingBusinessName"]),
    (
        "SpecifiedLineTradeAgreement",
        &[
            "BuyerOrderReferencedDocument",
            "GrossPriceProductTradePrice",
            "NetPriceProductTradePrice",
        ],
    ),
    (
        "SpecifiedLineTradeSettlement",
        &[
            "ApplicableTradeTax",
            "BillingSpecifiedPeriod",
            "SpecifiedTradeAllowanceCharge",
            "SpecifiedTradeSettlementLineMonetarySummation",
            "AdditionalReferencedDocument",
            "ReceivableSpecifiedTradeAccountingAccount",
        ],
    ),
    ("SpecifiedProcuringProject", &["ID", "Name"]),
    (
        "SpecifiedTradeAllowanceCharge",
        &[
            "ChargeIndicator",
            "CalculationPercent",
            "BasisAmount",
            "ActualAmount",
            "ReasonCode",
            "Reason",
            "CategoryTradeTax",
        ],
    ),
    (
        "SpecifiedTradePaymentTerms",
        &["Description", "DueDateDateTime", "DirectDebitMandateID"],
    ),
    (
        "SpecifiedTradeProduct",
        &[
            "GlobalID",
            "SellerAssignedID",
            "BuyerAssignedID",
            "Name",
            "Description",
            "ApplicableProductCharacteristic",
            "DesignatedProductClassification",
            "OriginTradeCountry",
        ],
    ),
    (
        "SpecifiedTradeSettlementHeaderMonetarySummation",
        &[
            "LineTotalAmount",
            "ChargeTotalAmount",
            "AllowanceTotalAmount",
            "TaxBasisTotalAmount",
            "TaxTotalAmount",
            "RoundingAmount",
            "GrandTotalAmount",
            "TotalPrepaidAmount",
            "DuePayableAmount",
        ],
    ),
    (
        "SpecifiedTradeSettlementPaymentMeans",
        &[
            "TypeCode",
            "Information",
            "ApplicableTradeSettlementFinancialCard",
            "PayerPartyDebtorFinancialAccount",
            "PayerSpecifiedDebtorFinancialInstitution",
            "PayeePartyCreditorFinancialAccount",
            "PayeeSpecifiedCreditorFinancialInstitution",
        ],
    ),
    (
        "SupplyChainTradeTransaction",
        &[
            "IncludedSupplyChainTradeLineItem",
            "ApplicableHeaderTradeAgreement",
            "ApplicableHeaderTradeDelivery",
            "ApplicableHeaderTradeSettlement",
        ],
    ),
];

/// 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)
}