1. Home
  2. UAE E-Invoicing Hub
  3. Custom ERP & Integration

Custom ERP & Integration

Designing the Database for E-Invoicing: What to Store and How

Your ERP already has an invoices table. E-invoicing needs more: snapshots, acknowledgements and evidence that never change after the fact.

SZ
Sahil ZainiCRM & ERP Development
·2026-11-24·3 min read
Updated 24 Nov 2026 · checked against MoF Guidelines v2.0

An e-invoicing data model separates the mutable commercial record from the immutable compliance record. Store a snapshot of parties and lines as they were at issuance, the generated XML and its hash, each submission attempt and acknowledgement with raw payloads, the derived status, and pointers to archived artefacts. Enforce immutability on submitted documents at the database level and model credit notes as new documents referencing the original.

Key facts at a glance

  • Separate commercial tables (editable) from compliance tables (append-only).
  • Store the XML and SHA-256 per document version.
  • One row per acknowledgement, never overwrite status history.
  • Snapshot party data at issuance; master data changes later must not alter past documents.
  • Index by TIN, document number, issue date, status for reconciliation queries.

Core tables

TableKey columnsNotes
einvoice_documentid, tenant_tin, number, type_code (380/381), issue_date, currency, references_document_id, status, xml_hashOne row per issued document; immutable after submission
einvoice_party_snapshotdocument_id, role (seller/buyer), tin, trn, legal_name, address_json, countryFrozen copy of master data at issuance
einvoice_linedocument_id, line_no, description, qty, unit_code, unit_price, line_net, vat_category, vat_rate, reason_codeAs generated; totals derived
einvoice_allowance_chargedocument_id, line_no (nullable), is_charge, amount, base, percent, reason, vat_category, vat_rateLine-level when line_no set
einvoice_vat_breakdowndocument_id, category, rate, taxable_amount, vat_amount, reason_codeOne per category/rate
einvoice_xmldocument_id, version, xml_blob_or_pointer, sha256, generated_at, ruleset_versionKeep every version submitted
einvoice_submissiondocument_id, attempt_no, provider_code, provider_ref, sent_at, http_status, request_hashOne per attempt
einvoice_ackdocument_id, kind (provider_accepted/rejected/delivered/reported/mlr), received_at, payload_jsonAppend-only

Immutability

Once a document has a provider_accepted acknowledgement, updates and deletes on its rows should be impossible, not merely discouraged. Use database triggers that raise on UPDATE/DELETE when the status is submitted, or move submitted rows into partitions with no write grants for the application role. Corrections create new documents of type 381 with references_document_id set.

Derived status and reporting

Compute the document's current state from the acknowledgement history rather than storing it as the only truth; keep a denormalised status column for indexing but rebuild it from einvoice_ack nightly to catch drift. Reconciliation views join documents, breakdowns and the latest acknowledgement per kind to produce period totals by VAT category that can be compared to the provider's report and to the VAT return.

Multi-entity and retention

Carry tenant_tin on every compliance table so queries, exports and access control are per legal entity. Partition by issue year to make retention management and archival straightforward, and store large XML blobs in object storage with the pointer and hash in the database rather than in the row itself.

Where Zaini Developers fits in

This schema is close to what FORMA uses in production. We adapt it to your ERP's existing tables so the compliance record is complete without duplicating your commercial data.

Book a free consultation →

Frequently asked questions

Should I store the XML in the database or in files?

Store the hash and metadata in the database and the XML in versioned object storage; small deployments can keep both in the database.

How do I handle a document rejected by the provider?

Keep the rejected version in einvoice_xml, record the rejection acknowledgement, fix the source and generate a new version under the same document number if the number was never accepted.

Do I need to snapshot the buyer's address?

Yes. If the customer moves next year, last year's documents must still show the address used at the time.

What about inbound invoices?

Mirror the structure with a direction flag; inbound documents also need acknowledgements, matching status and archive pointers.

This guide explains published UAE rules in plain language and is not tax or legal advice; confirm your own position with a registered tax adviser. Zaini Developers is not an Accredited Service Provider (ASP); we build and connect systems that transmit through MoF-accredited ASPs. Product names belong to their owners.
Free E-Invoicing Readiness CheckAnswer 8 quick questions and get your score and action plan.
Check my readiness

Let's build together

Need your system e-invoicing ready?
We build and connect it.

We build e-invoicing-ready ERP, CRM and POS systems and connect existing software to UAE e-invoicing.

Chat on WhatsApp