Skip to content

Documentation / @facturometro/einvoice / createInvoice

Function: createInvoice() ​

createInvoice(input): Invoice

Defined in: packages/core/src/create/index.ts:83

Creates a canonical invoice from what the caller knows about it.

Applies the Peppol customization and profile identifiers, the VAT tax schemes, the fixed values of the syntax and the document currency, then computes every amount that is missing: the net amount of each line, the VAT breakdown by category and rate, and the document totals of BR-CO-10 to BR-CO-16.

A VAT breakdown line says one thing a line's classifiedTaxCategory cannot: why a category is exempt (BT-120 taxExemptionReasonCode and BT-121 taxExemptionReason, which BR-E-10, BR-AE-10, BR-O-10 and BR-Z-10 ask for). State it by shaping that one taxSubtotal and leaving its amounts out; the builder computes them and adds a breakdown line for every other category the document uses, so nothing is lost by shaping one:

ts
taxTotal: [
  {
    taxSubtotal: [
      {
        taxCategory: {
          id: 'E',
          percent: 0,
          taxExemptionReasonCode: 'VATEX-EU-O',
          taxExemptionReason: 'Not subject to VAT',
        },
      },
    ],
  },
];

The result is not validated: it is a document of the right shape, and @facturometro/validator is what says whether it is a legal one.

Parameters ​

input ​

InvoiceInput

The invoice, without the amounts that follow from its lines.

Returns ​

Invoice

The canonical invoice.

Throws ​

When a number the caller wrote is not finite.

Throws ​

When a line states a price base quantity (BT-149) of zero.

Throws ​

When an allowance or charge of the document or of a line states no amount and not both a multiplierFactorNumeric and a baseAmount to compute it from, or when a tax total other than the first states no taxAmount, or one of its tax subtotals no taxableAmount or taxAmount: the builder computes only the first tax total (the VAT total in the document currency, BT-110).

Example ​

ts
import { createInvoice } from '@facturometro/core';

const invoice = createInvoice({
  id: 'INV-1',
  issueDate: '2026-09-10',
  invoiceTypeCode: '380',
  documentCurrencyCode: 'EUR',
  accountingSupplierParty: supplier,
  accountingCustomerParty: customer,
  invoiceLine: [
    {
      id: '1',
      invoicedQuantity: { value: 10, unitCode: 'C62' },
      item: { name: 'Widget', classifiedTaxCategory: { id: 'S', percent: 25 } },
      price: { priceAmount: 41 },
    },
  ],
});

invoice.invoiceLine[0].lineExtensionAmount; // { value: '410.00', currencyId: 'EUR' }
invoice.legalMonetaryTotal.payableAmount; // { value: '512.50', currencyId: 'EUR' }

MIT licensed. Specification artefacts belong to OpenPEPPOL, CEN and OASIS.