The previous invoice hash (PIH) and the document chain
Each document carries the hash of the one before it from the same device, so documents form a chain in which any deletion or change shows.
The controls require the issuing unit to put a hash on each document together with the hash of the previous one. If a document is deleted, the next hash no longer matches anything; if one is altered, its hash changes and the chain breaks after it.
The first document of a device's chain carries a fixed value from the standard: the base64 of the hexadecimal hash of "0". Note that this value is base64 of 64 characters of text, whereas later documents' hashes are base64 of 32 bytes.
Rejected documents are part of the chain: the platform records their hashes, so the next document points to them. Documents need not be submitted in the order they were issued, as long as each points to the one issued immediately before it.
In JooDax
BuiltEach unit keeps the last document's hash and writes it into the next inside the same transaction, starting from the genesis value, which matches the standard exactly. A unit test checks that the second document carries the first one's hash.
crates/jdx-einvoice-sa/src/unit.rs
Questions and answers
If document 2 is rejected and resent after document 3, which does it point to?
The resent document points to document 3, and document 3 still points to the rejected document 2, per the technical guidelines' example.
Related pages
- KSA-13 Previous invoice hash (PIH)
- KSA-16 Invoice counter value (ICV)
- BR-KSA-26 · The previous invoice hash must be a base64 SHA-256 computed the standard's way.
- BR-KSA-61 · Every document must contain the previous invoice hash.
Related concepts
- The invoice hash: how it is computedA SHA-256 fingerprint of the document after removing the stamp and QR blocks and canonicalizing it, written in base64; the stamp and the chain rest on it.
- The invoice counter (ICV)A number that goes up by one with every document a device issues, never reset or reused, so any gap in the chain shows.
E-invoicing in Saudi Arabia (FATOORA)
Sources
- الضوابط والمتطلبات والمواصفات الفنية والقواعد الإجرائية اللازمة لتنفيذ أحكام لائحة الفوترة الإلكترونية (قرار المحافظ رقم 62738 وتاريخ 1443/11/23هـ) (vfile dated 20230519 (decision 62738)) — ZATCA
- Electronic Invoice XML Implementation Standard to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
- Security Features Implementation Standards to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
- E-invoicing Detailed Technical Guidelines (vVersion 2) — ZATCA
Checked on: 4 November 2026. What concerns JooDax is taken from the programs’ own code.