en16931 0.1.1 copy "en16931: ^0.1.1" to clipboard
en16931: ^0.1.1 copied to clipboard

The European electronic invoice, EN 16931, as Dart objects. Builds and checks the semantic model the UBL and CII syntaxes both carry, with no XML and no network of its own.

example/example.dart

// ignore_for_file: avoid_print

import 'package:decimal/decimal.dart';
import 'package:en16931/en16931.dart';

/// Builds one invoice: two lines at two different VAT rates and a discount on
/// the whole invoice. The breakdown and the totals are worked out from the
/// lines, and the result is checked against the 223 rules of the standard.
void main() {
  final invoice = Invoice.fromLines(
    number: '2026-0042',
    issueDate: DateTime(2026, 9, 13),
    dueDate: DateTime(2026, 10, 13),
    buyerReference: 'PO-77812',
    seller: const Seller(
      name: 'COMAPPS SRL',
      tradingName: 'ComApps',
      vatIdentifier: 'BE0123456789',
      electronicAddress:
          Identifier('0123456789', scheme: Scheme.belgianEnterprise),
      address: Address(
        line1: 'Rue Example 1',
        city: 'Bruxelles',
        postalCode: '1000',
        country: 'BE',
      ),
      contact: Contact(name: 'Billing', email: 'billing@example.be'),
    ),
    buyer: const Buyer(
      name: 'Client SA',
      vatIdentifier: 'BE0987654321',
      electronicAddress:
          Identifier('0987654321', scheme: Scheme.belgianEnterprise),
      address: Address(
        line1: 'Avenue Example 2',
        city: 'Namur',
        postalCode: '5000',
        country: 'BE',
      ),
    ),
    lines: [
      InvoiceLine.of(
        id: '1',
        item: const Item(
          name: 'Consulting',
          description: 'Integration work, September 2026',
          sellerIdentifier: 'SRV-CONS',
        ),
        quantity: 8,
        unitPrice: 150.00,
        vatRate: 21,
        unit: UnitCode.hour,
        period: DatePeriod(
          start: CalendarDate(2026, 9, 1),
          end: CalendarDate(2026, 9, 30),
        ),
      ),
      InvoiceLine.of(
        id: '2',
        item: const Item(
          name: 'Printed manual',
          standardIdentifier: Identifier('5412345678901', scheme: Scheme.gtin),
        ),
        quantity: 4,
        unitPrice: 15.00,
        vatRate: 6,
        unit: UnitCode.piece,
      ),
    ],
    allowancesAndCharges: [
      DocumentAllowanceCharge(
        kind: AllowanceOrCharge.allowance,
        amount: Decimal.parse('50.00'),
        vatCategory: VatCategory.standardRate,
        vatRate: Decimal.parse('21'),
        reason: 'Loyalty discount',
        reasonCode: '95',
      ),
    ],
    paymentTerms: 'Payable within 30 days.',
    paymentInstructions: const PaymentInstructions(
      means: PaymentMeansCode.sepaCreditTransfer,
      remittanceInformation: '+++090/9337/55493+++',
      creditTransfers: [
        CreditTransferAccount(
          'BE68539007547034',
          name: 'COMAPPS SRL',
          providerBic: 'GEBABEBB',
        ),
      ],
    ),
  );

  print('Invoice ${invoice.number} of ${invoice.issueDate}');
  print('  ${invoice.seller.name} to ${invoice.buyer.name}');
  for (final line in invoice.lines) {
    print(
      '  line ${line.id}: ${line.item.name}, '
      '${line.quantity} ${line.unit} at ${line.price.netPrice} '
      '= ${line.netAmount} (VAT ${line.vatRate}%)',
    );
  }
  for (final vat in invoice.vatBreakdown) {
    print(
      '  VAT ${vat.rate}% on ${vat.taxableAmount} '
      '= ${vat.taxAmount} (${vat.category})',
    );
  }
  print(
    '  due ${invoice.totals.amountDueForPayment} ${invoice.currency} '
    'by ${invoice.dueDate}',
  );

  final violations = validate(invoice);
  print(violations.isEmpty ? '  checks out' : '  ${violations.length} to fix');
  for (final violation in violations) {
    print('  $violation');
  }
}
0
likes
160
points
--
downloads

Documentation

API reference

Publisher

verified publishercomapps.be

The European electronic invoice, EN 16931, as Dart objects. Builds and checks the semantic model the UBL and CII syntaxes both carry, with no XML and no network of its own.

Homepage
Repository (GitHub)
View/report issues

Topics

#einvoicing #en16931 #peppol #invoice #vat

License

MIT (license)

Dependencies

decimal

More

Packages that depend on en16931