Skip to content

Developer notes

  1. Number and date: Invoices & Credit Notes (Tygh\Addons\KvInvoiceBuilder\Issuer::issueInvoice() when the order has no invoice yet) or the add-on’s own series (kv_einv_counters, counter row locked with SELECT ... FOR UPDATE, retried on deadlocks; a rolled back transaction never consumes a number).
  2. Model: Model\Builder::invoice() reads fn_get_order_info() and builds the EN 16931 semantic model (array): seller (seller data with company fallback), buyer (billing address, profile fields, EU VAT Number Validation row), delivery (shipping address, first shipment date or the issue date), lines, allowances and charges, payment instructions. Model\Calculator::finish() adds the VAT breakdown per category and rate (tax = taxable amount × rate, rounded to 2 decimals) and the totals; the difference to the charged order total becomes a rounding amount (BT-114) or, above 1.00, a prepaid amount (gift certificates).
  3. Freeze + check: the model is stored as JSON in kv_einv_documents.data; Validator::all() stores the check per format in checks.
  4. Files on demand: Formats::render($model, $format) adapts the model to the format (electronic addresses, contact point) and writes it: Format\Ubl (Peppol BIS 3.0 / XRechnung UBL, Invoice and CreditNote), Format\Cii (XRechnung CII / Factur-X), Pdf\FacturX (PDF/A-3b with factur-x.xml, AFRelationship Alternative).

Order lines are matched to taxes through order.taxes[tax_id].applies: P_<item_id> (tax per unit price) or items.P[<item_id>] (tax on the subtotal); shipping through S_<group>_<shipping_id> / items.S, the payment surcharge through PS_* / items.PS. Rates of several taxes on one line are added up (with a warning); fixed-amount taxes are left out (warning). Prices that include tax are turned into net amounts with the stored tax of the line, or by the rate when the tax was calculated on the subtotal. Order discounts are split over the VAT groups in proportion to their gross value.

Plain PHP, no library: Pdf\Document writes PDF 1.7 objects with Type0 / CIDFontType2 fonts (Identity-H, ToUnicode), XMP metadata (pdfaid part 3, conformance B, the Factur-X extension schema), an sRGB output intent with an ICC profile generated by Pdf\Icc, and the embedded file. Pdf\TrueType reads the bundled Noto Sans fonts (SIL Open Font License, resources/fonts/OFL.txt, Latin, Greek and Cyrillic) and embeds only the glyphs used. Pdf\Layout draws the A4 page; labels are language variables kv_eu_e_invoicing.pdf_*.

Built in (1.1.0): Peppol\Provider\Recommand and Peppol\Provider\B2brouter, both implementing Peppol\ProviderInterface (test, send, status, lookup, inbox, fetch, ack) over Peppol\Http (cURL). The connection of a seller lives in kv_einv_peppol_accounts; Peppol\Accounts::provider($company_id) returns its driver. Hook kv_eu_e_invoicing_peppol_provider($company_id, $row, &$driver) replaces or adds a driver per seller (any ProviderInterface), which gives it sending, tracking, retries and receiving.

Routing (Peppol\Transports::route()): the seller’s own connection first; otherwise a third-party driver from the settings. Test or proxy overrides (config.local.php): KV_EINV_RECOMMAND_URL, KV_EINV_B2BROUTER_URL, KV_EINV_DIRECTORY_URL; hosts whose PHP has no CA bundle can define KV_EINV_CA_FILE.

Third-party drivers of 1.0 keep working: a driver is any class implementing Tygh\Addons\KvEuEInvoicing\Peppol\TransportInterface, registered from your own add-on:

func.php
// init.php of your add-on
fn_register_hooks('kv_eu_e_invoicing_peppol_transports');
function fn_my_addon_kv_eu_e_invoicing_peppol_transports(&$transports)
{
$transports['my_ap'] = new \Tygh\Addons\MyAddon\AccessPoint();
}
class AccessPoint implements \Tygh\Addons\KvEuEInvoicing\Peppol\TransportInterface
{
public function getName() { return 'My access point'; }
public function isConfigured() { return (bool) $this->apiKey(); }
public function send($xml, array $document)
{
// $xml: Peppol BIS Billing 3.0 UBL Invoice or CreditNote
// $document: doc_id, doc_type (I|C), number, order_id, company_id, seller_id, buyer, buyer_vat,
// data (the EN 16931 model; data.buyer.endpoint / endpoint_scheme = receiver)
// POST it to your access point here.
return ['ok' => true, 'message_id' => 'AP-12345', 'error' => ''];
}
}

The driver then appears in Third-party Peppol driver. Sending is refused while the license is not valid or the Peppol check of the document has errors. Third-party drivers have no delivery tracking or automatic retries.

Peppol state of a document: peppol_status (Q queued, S sent, D delivered, E error with retry, F failed), peppol_provider, peppol_doc_ref (provider document), peppol_ref (message id), peppol_recipient, peppol_error, peppol_at, peppol_attempts, peppol_next_at, peppol_delivered_at. Queue run: Peppol\Sender::run() (cron URL index.php?dispatch=kv_eu_e_invoicing.cron&key=..., console admin.php --dispatch=kv_eu_e_invoicing.cron, function fn_kv_eu_e_invoicing_peppol_run()). Incoming: Peppol\Inbox::poll($company_id), Peppol\Inbox::store(...), Peppol\Reader::read($xml) (UBL / CII summary).

Hook Arguments Use
kv_eu_e_invoicing_peppol_transports &$transports (id => TransportInterface) Register third-party Peppol drivers
kv_eu_e_invoicing_peppol_provider $company_id, $row, &$driver (ProviderInterface or null) Replace or add the provider driver of a seller connection
use Tygh\Addons\KvEuEInvoicing\Documents;
use Tygh\Addons\KvEuEInvoicing\Issuer;
use Tygh\Addons\KvEuEInvoicing\Output;
$doc = Documents::invoiceForOrder($order_id); // or Issuer::issueInvoice($order_id, 'manual')['doc']
$file = Output::file($doc, 'xrechnung_cii'); // facturx | xrechnung_cii | xrechnung_ubl | peppol
// $file = ['content' => ..., 'filename' => 'INV-2026-00042-xrechnung-cii.xml', 'mime' => 'application/xml']
Table Contents
kv_einv_documents doc_id, doc_type (I/C), order_id, company_id, seller_id, number, issue_date, issued_at, invoice_id (credit note → invoice), ib_doc_id (Invoices & Credit Notes document), source, source_key (unique, idempotency: inv:<order>, cn:<invoice> first full credit, cnp:<invoice>:<form token> partial, cnr:<invoice>:<n> rest), series_key + seq_no (own numbers), currency, total (amount due), with_vat, tax_total, buyer, buyer_vat, buyer_ref, email, user_id, status (check of the document’s own format), checks (JSON), peppol_status / ref / error / at, format (2.0: the document’s own format), country (2.0: module BE/DE/FR or empty), data (JSON model; version 2 adds country, process_code, vat_point_code, note subjects, line nature, credit_selection), order_deleted
kv_einv_counters series_key (`I
kv_einv_sellers company_id (0 = store / marketplace, storefront, vendor) + seller data fields
kv_einv_maps map_type (tax, payment), map_key (tax_id, payment_id), value (category / means code), extra (exemption text)
kv_einv_products product_id, unit_code, nature (2.0: G goods, S services, ‘’ default)
kv_einv_peppol_accounts company_id (seller), provider, environment, account_ref, api_key / api_secret (AES-256-GCM, key from crypt_key), participant, auto_send, receive, status, info (JSON), last_check, last_error, last_poll, last_poll_error
kv_einv_inbound inbound_id, company_id, provider + provider_ref (unique), kind (I/C/U), syntax, number, issue_date, due_date, currency, net_total, tax_total, total, supplier, supplier_vat, sender_id, receiver_id, status (N new, D processed), note, received_at, xml, summary (JSON)
kv_einv_archive (2.0) archive_id, doc_id, company_id, seller_id, format, event (issue, rebuild, peppol, mail, manual), filename, mime, size, sha256, prev_hash, chain_hash (SHA-256 of `prev
kv_einv_peppol_log log_id, doc_id, inbound_id, company_id, action (attempt, send, status, retry, queue, lookup, test, poll, receive), ok, message, ref, user_id, created_at (kept 400 days)

Documents are never deleted while the add-on is installed. When an order is deleted, its documents are kept and flagged order_deleted.

2.0: country modules, schema check, archive, credits (classes)

Section titled “2.0: country modules, schema check, archive, credits (classes)”
Class Role
Countries Module per seller country (module()), model enrichment after the totals (enrich(): buyer BT-47 from the VAT ID, France BT-23 / BT-8 / notes), format by country (format()), country rules (rules(), called by Validator::check()), readiness rows (readiness()).
Ids SIREN / SIRET (Luhn), KBO/BCE (mod 97), Leitweg-ID (ISO/IEC 7064 MOD 97-10), legal() = registration number + ICD scheme of a country.
Schema XML Schema check with PHP dom/libxml against resources/xsd/ubl21 and resources/xsd/cii-d16b (official, unchanged, see SOURCE.txt); rule id XSD. Validator::all($model, [$format]) runs it for the given formats.
Archive freeze(), latest(), forDoc(), find(), verify(), export(). Output::file() returns the newest copy of a format when it is not older than the document’s updated_at; Output::render() always renders.
Credits remaining($invoice) from the current state (invoice minus every credit note), selection($invoice, $request) for Model\Builder::credit().
Report build($doc) (all checks again incl. XSD), json().

Notes: model notes[] entries are strings or {subject, text}; UBL writes #CODE#text, CII IncludedNote/SubjectCode. Peppol files join several notes into one (PEPPOL-EN16931-R002). BT-8 is written as DueDateTypeCode 5 (CII) and InvoicePeriod/DescriptionCode 3 (UBL).

Tests: tests/v2/cases.php (store-free; files for tooling/einvoice-validate), tests/v2/store.php (in a booted store, real orders), tests/upgrade/fixture.php (kv qa upgrade, 1.x → 2.0 data step).

Namespace Tygh\Addons\KvEuEInvoicing\National:

Class Role
Driver Base of a driver: applies(), build(), rules(), xsd(), check() (rules + schema of the written file). Pure, no database.
Pl\Ksef EN 16931 model -> neutral model of the KSeF engine; Pl\Fa3, Pl\Api, Pl\Crypto, Pl\Xml, Pl\ApiException are the audited engine of the add-on KSeF e-Invoicing for Poland (kv_ksef 1.0.4), copied with the namespace changed and the certificate (XAdES) login removed.
Hr\Eracun UBL of the add-on + the Croatian parts (CustomizationID, ProfileID, IssueTime, OIB endpoints 9934, SellerContact operator, KPD per line, VAT marks). KPD list: resources/hr/kpd2025.txt (from the official codelist).
Gr\MyData, Gr\Client InvoicesDoc v2.0.2; SendInvoices, RequestTransmittedDocs.
Dr\Ecf, Dr\Signer, Dr\Client e-CF 31/32/34 + RFCE; XMLDSig (enveloped, inclusive C14N, RSA-SHA256, whitespace not preserved); seed/token, reception, result, RFCE, track IDs. Namespace Dr because do is a PHP keyword.
Registry, Accounts, Store, Service, Sequences, Transmit, Sender, Tester, View Drivers by country / format, sealed credentials per seller, rows and states, check + state, e-NCF ranges, one transmission step per authority, queue run (cron with Peppol), connection test, page data.

Tables: ?:kv_einv_national (one row per document and driver: state, national number, remote reference / id, attempts, next try, findings, extra JSON) and ?:kv_einv_national_accounts (per seller and driver: environment, user, sealed secret / certificate, options JSON, auto send). Column ?:kv_einv_products.kpd. All kept on uninstall (retention).

Idempotency: the row is marked “ambiguous” and the exact bytes archived before a creating request; a marked row is looked up first on the next run. Rows are processed under GET_LOCK('kv_einv_nat_<id>'). Accepted rows are final.

Development mocks: $config['kv_einv_national_base_gr'] / _do / _pl in config.local.php (only http(s)://127.0.0.1 or localhost accepted). Tests: tests/v21/national.php (store-free, every file schema-checked), tests/v21/hr-schematron.py (official Croatian validator via Saxon), tests/v21/store.php (real orders, in-process mocks), tests/v21/patch-xsd.py (derives the two libxml2-compatible DGII schemas from the official files, sha256-checked).

Sources (retrieved 24 November 2026; sha256 prefix of the file used)

Section titled “Sources (retrieved 24 November 2026; sha256 prefix of the file used)”
Country Document sha256
Greece AADE “myDATA REST API ERP” v2.0.2 (September 2026), sections 4.1-4.2, 5.1-5.8, 6.1-6.2, 8.1-8.13 409c5acdd5219930
Greece myDATA XSD v2.0.2 zip (InvoicesDoc-v2.0.2.xsd 686769176906d2eb) feaf90afc57150c8
Greece syndiasmoi_xaraktirismwn_v2.0.2 (classification combinations) e541a87e9b2f8f32
Dominican Republic DGII “Descripción Técnica Servicios DGII” (29/05/2026) 85a601ffe4af67ad
Dominican Republic DGII “Formato Comprobante Fiscal Electrónico (e-CF) V1.0” (30/10/2025) c811c91a9e6a61a6
Dominican Republic DGII “Firmado de e-CF” (22/11/2023) bb32bb04c170ac3e
Dominican Republic XSD e-CF 31-34 v1.0, RFCE 32 v1.0, Semilla v1.0 (e-CF 31 6f2909a93d84919518d2) see tests/v21/patch-xsd.py
Croatia Porezna uprava “Specifikacija osnovne uporabe eRačuna s proširenjima” (12.03.2026) fe4600c79ff097b3
Croatia Validator HR-CIUS-EXT-EN16931-UBL.sch (13.03.2026) / UBL 2.1 eRačun XSD (15.04.2026) / examples (12.12.2025) d6250b00b1cd385c / 549ced211d2b463d / 4ee27e233b8f803e
Poland FA(3) 1-0E XSD and KSeF API 2.0 as in kv_ksef 1.0.4 (CIRFMF/ksef-api, api-test.ksef.mf.gov.pl/docs/v2) resources/xsd/ksef/SOURCE
France DGFiP Spécifications externes v3.2, annexe 7 v1.9 (G1.31, G1.41, G1.47, scheme 0225) as in the France E-Invoicing add-on

PHP: change_order_status (create e-invoices, own credit notes, pick up Invoices & Credit Notes credit notes), mailer_send_pre (attachment), delete_order, update_product_post / delete_product_post (unit), delete_company (seller data), rma_update_details_post (credit notes of returns), kv_invoice_builder_document_issued (Invoices & Credit Notes 1.0.1+: e-credit note at once for every credit note issued there). All exist with the same arguments in 4.17.2 and 4.21.2. The add-on priority is 1100, so Invoices & Credit Notes (1000) has issued its number first in shared hooks.

Templates: admin orders:tabs_extra (post), orders:details_tools (post), products:update_product_amount (post), index:styles; storefront orders:details_tools (post), index:styles. Context menu: orders (Print documents → e-Invoices (ZIP)).

Nothing is printed on cacheable storefront pages. Customer links are on the session-bound order page; downloads are sent with Cache-Control: private, no-store.

Add-on Integration
Invoices & Credit Notes Numbers, dates and credit notes (read through its public classes; when it is not active, own numbering). Its per-vendor numbering makes vendors the sellers (Multi-Vendor, automatic mode).
EU VAT Number Validation Buyer VAT ID and reverse-charge decision from kv_vat_orders; store VAT number as the seller VAT fallback.
Sell by Weight & Length Measured quantity (extra.kv_fq.qty / 10000) and unit (kg → KGM, m → MTR, l → LTR …).
app/addons/kv_eu_e_invoicing/
addon.xml, init.php, func.php
controllers/backend/kv_eu_e_invoicing.php list, document page, downloads, ZIP, issue, rebuild, credit, send, seller data, mapping
controllers/backend/orders.post.php order page tab
controllers/backend/products.post.php unit field data
controllers/frontend/kv_eu_e_invoicing.php customer download, Peppol cron URL
controllers/frontend/orders.post.php customer order page links
resources/fonts/ Noto Sans Regular/Bold (subset) + OFL.txt
resources/xsd/ OASIS UBL 2.1 + UN/CEFACT CII D16B schemas (2.0) + SOURCE.txt
schemas/ context_menu, menu, permissions, settings
Tygh/Addons/KvEuEInvoicing/
Config, Codes, Lang, Sellers, Maps, Buyer, InvoiceBuilder, Series, Documents, Issuer, Validator, Formats, Output,
Countries, Ids, Schema, Archive, Credits, Report (2.0),
Access, Hooks, View, Model/{Builder,Calculator}, Format/{Xml,Ubl,Cii}, Pdf/{Document,TrueType,Icc,Layout,FacturX},
Secret, Peppol/{TransportInterface,Transports,ProviderInterface,Http,Accounts,Sender,Inbox,Reader,Directory,Log},
Peppol/Provider/{Recommand,B2brouter}, License/*, Upgrade/Synchronizer
design/backend/templates/addons/kv_eu_e_invoicing/ views, components, hooks, settings, license
design/backend/css/addons/kv_eu_e_invoicing/styles.less
design/backend/media/images/addons/kv_eu_e_invoicing/icon.png
var/themes_repository/responsive/templates/addons/kv_eu_e_invoicing/hooks
var/themes_repository/responsive/css/addons/kv_eu_e_invoicing/styles.less
var/langs/en/addons/kv_eu_e_invoicing.po

The license client is Tygh\Addons\KvEuEInvoicing\License\Client (isActive()); the gate is Config::canIssue() (enabled and licensed). Gated: creating, rebuilding and crediting documents (incl. partial credit notes), e-mail attachments, Peppol sending, retries and fetching incoming e-invoices. Not gated: lists, document pages, downloads (admin, vendor, customer), the archive (list, download, export, integrity check), validation reports, stored incoming e-invoices.