Non-Peppol EN 16931 invoices
Not every EN 16931 invoice travels over Peppol. The customization id (BT-24) decides which rules validate() runs by default, and you can register your own composition for any id.
A plain EN 16931 invoice
With the CEN id, or any id that does not start with the Peppol one (and is not the CIUS-ES-FACE id), only the EN 16931 rules run, so you get no Peppol-specific errors:
const cenInvoice = createInvoice({
...baseInvoice,
customizationId: 'urn:cen.eu:en16931:2017',
});
const cenRules = validate(cenInvoice).ruleset.ids; // ['en16931']: no Peppol rulesSpanish public administrations (FACe)
Invoices sent to Spanish public administrations through FACe follow CIUS-ES-FACE 1.0.0 and declare its id, CIUS_ES_FACE_CUSTOMIZATION_ID. For that id, validate() runs EN 16931 and esFaceRuleset (ES-FACE-R*), and no Peppol rules:
const faceInvoice = createInvoice({
...baseInvoice,
customizationId: CIUS_ES_FACE_CUSTOMIZATION_ID,
// The DIR3 codes of the accounting (01), managing (02) and executing (03) offices
buyerReference: '01|EA4503152|02|EA3000128|03|E14921301|',
});
const faceRules = validate(faceInvoice).ruleset.ids; // ['en16931', 'es-face']The CIUS adds these rules:
- Type code. The invoice type code (BT-3) is
380or384. A correction is a corrected invoice (384), so a UBL credit note does not pass. - Attachments and preceding invoices. Attachments are PDF or HTML, and an invoice has at most one preceding invoice reference (BG-3).
- DIR3 units. The buyer reference (BT-10) is mandatory. It lists the DIR3 units of the accounting office (
01), the managing office (02) and the executing office (03), each asID|CODE|, in any order. Units with roles04to09may follow. The contracting unit, or FACe's directory, gives the codes. - Lengths. Text fields respect the FacturaE lengths of the CIUS's value-domain table, such as 20 characters for the invoice number (BT-1) and 80 for the seller name (BT-27).
- Decimals. Percentages, VAT rates, prices and the price base quantity have at most eight decimals. Amounts keep EN 16931's two decimals (
BR-DEC-*): a CIUS can only restrict EN 16931, and FACe asks for two decimals too.
FACe's own sample invoices leave out the closing | of the last DIR3 unit, which ES-FACE-R007 reports. To accept them, add esFaceLenientRuleset. It disables that one rule and nothing else:
// FACe's own sample invoices leave out the closing `|` of the last unit
const sample = createInvoice({
...faceInvoice,
buyerReference: '03|E14921301|02|EA3000128|01|EA4503152',
});
const strictIssues = validate(sample).issues.map((issue) => issue.id); // ['ES-FACE-R007']
const lenientOk = validate(sample, {
ruleset: [en16931Ruleset, esFaceRuleset, esFaceLenientRuleset],
}).ok; // trueRegister a composition for another CIUS
const EXAMPLE_CIUS = 'urn:cen.eu:en16931:2017#compliant#urn:example.org:cius:1.0';
const exampleCius = defineRuleset({
id: 'example-cius',
version: '1.0.0',
requires: [en16931Ruleset],
rules: [
rule.custom('EX-R-001', {
severity: 'fatal',
message: 'The buyer reference (BT-10) is mandatory in this CIUS.',
bt: ['BT-10'],
at: 'document',
test: (document, ctx) => ctx.normSpace(document.buyerReference) !== '',
}),
],
});
registerRuleset({ customizationId: EXAMPLE_CIUS, ruleset: [en16931Ruleset, exampleCius] });
const ciusInvoice = createInvoice({ ...baseInvoice, customizationId: EXAMPLE_CIUS });
const ciusRules = validate(ciusInvoice).ruleset.ids; // ['en16931', 'example-cius']A registration applies to the exact id, or to every id that starts with it when you pass matchPrefix: true. You can register the CEN id itself too. See Rulesets and extensions for writing the ruleset.
Add the Danish rules
National rules are opt-in
The official Peppol validator applies national rules by the supplier's country; this library does not. Add dkRuleset to validate the way it does for Danish suppliers.
const danishRules = validate(createInvoice(baseInvoice), {
ruleset: [en16931Ruleset, peppolRuleset, dkRuleset],
}).ruleset.ids; // ['en16931', 'peppol', 'dk']: the DK rules apply to Danish suppliers onlyThe Danish rules are the only national rules in this release; CIUS-ES-FACE is a CIUS, not a national rule pack.