> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gobl.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Saudi Arabia ZATCA

Key: `sa-zatca-v1`

Module: [github.com/invopop/gobl.sa.zatca](https://github.com/invopop/gobl.sa.zatca)

Support for the Saudi Arabia ZATCA (Zakat, Tax and Customs Authority) e-invoicing
requirements based on UBL 2.1 with EN 16931 as an intermediate layer and KSA-specific
extensions (BR-KSA-\* rules).

ZATCA e-invoicing covers both standard tax invoices (B2B/B2G) sent for clearance
and simplified tax invoices (B2C) sent for reporting through the FATOORA platform.

This addon extends EN 16931 with Saudi-specific fields and validations including
invoice type transactions, address requirements, and supply date handling.

## Sources

* [ZATCA E-Invoicing Developer Portal](https://zatca.gov.sa/en/E-Invoicing/SystemsDevelopers/Pages/E-Invoice-specifications.aspx)

## Scenarios

Scenarios attach notes and extensions to a document when its filters match.
[Read more about scenarios](https://docs.gobl.org/overview/scenarios.md).

> [accordion] bill/invoice
>
> | Type | Output |
> | - | - |
> | `standard` | `{  "ext": {    "untdid-document-type": "388"  }}` |

## Extensions

### ZATCA Invoice Transaction Type

Code used to describe the ZATCA invoice transaction type and flags (KSA-2).
The code is a 7-character string where positions 1-2 indicate the main type
(01 = Standard Tax Invoice, 02 = Simplified Tax Invoice) and positions 3-7
are binary flags for third-party, nominal, export, summary, and self-billed
transactions respectively.

> [accordion] sa-zatca-invoice-type
>
> Pattern: `^0[12][01]{5}$`
>
> | Code | Name |
> | - | - |
> | `0100000` | Standard Tax Invoice |
> | `0100001` | Standard Tax Invoice — Self-billed |
> | `0100010` | Standard Tax Invoice — Summary |
> | `0100011` | Standard Tax Invoice — Summary, Self-billed |
> | `0100100` | Standard Tax Invoice — Export |
> | `0100110` | Standard Tax Invoice — Export, Summary |
> | `0101000` | Standard Tax Invoice — Nominal |
> | `0101001` | Standard Tax Invoice — Nominal, Self-billed |
> | `0101010` | Standard Tax Invoice — Nominal, Summary |
> | `0101011` | Standard Tax Invoice — Nominal, Summary, Self-billed |
> | `0101100` | Standard Tax Invoice — Nominal, Export |
> | `0101110` | Standard Tax Invoice — Nominal, Export, Summary |
> | `0110000` | Standard Tax Invoice — Third-party |
> | `0110001` | Standard Tax Invoice — Third-party, Self-billed |
> | `0110010` | Standard Tax Invoice — Third-party, Summary |
> | `0110011` | Standard Tax Invoice — Third-party, Summary, Self-billed |
> | `0110100` | Standard Tax Invoice — Third-party, Export |
> | `0110110` | Standard Tax Invoice — Third-party, Export, Summary |
> | `0111000` | Standard Tax Invoice — Third-party, Nominal |
> | `0111001` | Standard Tax Invoice — Third-party, Nominal, Self-billed |
> | `0111010` | Standard Tax Invoice — Third-party, Nominal, Summary |
> | `0111011` | Standard Tax Invoice — Third-party, Nominal, Summary, Self-billed |
> | `0111100` | Standard Tax Invoice — Third-party, Nominal, Export |
> | `0111110` | Standard Tax Invoice — Third-party, Nominal, Export, Summary |
> | `0200000` | Simplified Tax Invoice |
> | `0200010` | Simplified Tax Invoice — Summary |
> | `0201000` | Simplified Tax Invoice — Nominal |
> | `0201010` | Simplified Tax Invoice — Nominal, Summary |
> | `0210000` | Simplified Tax Invoice — Third-party |
> | `0210010` | Simplified Tax Invoice — Third-party, Summary |
> | `0211000` | Simplified Tax Invoice — Third-party, Nominal |
> | `0211010` | Simplified Tax Invoice — Third-party, Nominal, Summary |

## Validation Rules

Validation rules check each struct against a set of assertions and report any
failures with a unique code and message.
[Read more about validation](https://docs.gobl.org/overview/validation.md).

> [accordion] bill.Invoice
>
> | Field | Test | Validation Code / Message |
> | - | - | - |
> | Invoice | <ul><li>Can convert to \[SAR]</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-34` Invoice currency must be SAR or include an exchange rate to convert to SAR |
> | `issue_time` Calculated | <ul><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-01` Invoice issue time must be present (BR-KSA-70) |
> | `tax` | <ul><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-02` Invoice tax must be present |
> | `tax.ext` | <ul><li>Ext require \[untdid-document-type]</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-03` Invoice tax untdid-document-type extension is required |
> | `tax.ext` | <ul><li>Ext require \[sa-zatca-invoice-type]</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-04` Invoice tax sa-zatca-invoice-type extension is required |
> | `tax.ext` | <ul><li>Ext 'untdid-document-type' in \[388, 386, 383, 381]</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-05` Invoice tax untdid-document-type extension must be a valid ZATCA type (388, 386, 383, 381) (BR-KSA-05) |
> | `tax.ext` | <ul><li>Ext 'sa-zatca-invoice-type' in \[0100000, 0100001, 0100010, 0100011, 0100100, 0100110, 0101000, 0101001, 0101010, 0101011, 0101100, 0101110, 0110000, 0110001, 0110010, 0110011, 0110100, 0110110, 0111000, 0111001, 0111010, 0111011, 0111100, 0111110, 0200000, 0200010, 0201000, 0201010, 0210000, 0210010, 0211000, 0211010]</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-06` Invoice tax sa-zatca-invoice-type extension must be valid (BR-KSA-06) |
> | `preceding` | <ul><li>Invoice type in \[credit-note, debit-note]</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-07` Credit and debit notes must have a billing reference |
> | `preceding[*].code` | <ul><li>Invoice type in \[credit-note, debit-note]</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-08` Credit or debit note billing reference must have an identifier (BR-KSA-56) |
> | `preceding[*].reason` | <ul><li>Invoice type in \[credit-note, debit-note]</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-09` Credit and debit notes must contain the reason for issuance (BR-KSA-17) |
> | `payment` | <ul><li>Invoice type in \[credit-note, debit-note]</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-10` Credit or debit notes must have payment details |
> | `payment.instructions` | <ul><li>Invoice type in \[credit-note, debit-note]</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-11` Credit or debit notes must have payment instructions |
> | `payment.instructions.key` | <ul><li>Invoice type in \[credit-note, debit-note]</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-12` Credit or debit note payment instructions must have a key (BR-KSA-17) |
> | `customer` | <ul><li>Standard tax invoice</li><li>Invoice customer must have a tax id code or a valid identification (TIN/CRN/MOM/MLS/700/SAG/NAT/GCC/IQA/PAS/OTH) for standard invoices (BR-KSA-14), (BR-KSA-81)</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-16` Invoice customer must have a valid identification scheme for standard invoices |
> | `customer.addresses[*].street` | <ul><li>Standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-13` Invoice customer address must have a street name for standard tax invoices (BR-KSA-10) |
> | `customer.addresses[*].locality` | <ul><li>Standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-14` Invoice customer address must have a city name for standard tax invoices (BR-KSA-10) |
> | `customer.addresses[*].country` | <ul><li>Standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-15` Invoice customer address must have a country code for standard tax invoices (BR-KSA-10) |
> | `lines[*].taxes` | <ul><li>Standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-17` Invoice line taxes are required for standard tax invoices (BR-KSA-52) |
> | `delivery` | <ul><li>Standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-18` Invoice delivery must be present for standard tax invoices |
> | `delivery.date` | <ul><li>Standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-19` Invoice delivery must have a supply date for standard tax invoices (BR-KSA-15) |
> | `customer.tax_id` | <ul><li>Export invoice</li><li>Empty</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-20` Invoice customer must not have a tax id for export invoices (BR-KSA-46) |
> | `delivery` | <ul><li>Invoice is simplified and summary</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-21` Invoice delivery must be present for simplified and summary invoices |
> | `delivery.period` | <ul><li>Invoice is simplified and summary</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-22` Invoice supply must have a delivery period for simplified and summary invoices |
> | `delivery.period.start` | <ul><li>Invoice is simplified and summary</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-23` Invoice delivery start date must be present for simplified and summary invoices (BR-KSA-72) |
> | `delivery.period.end` | <ul><li>Invoice is simplified and summary</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-24` Invoice delivery end date must be present for simplified and summary invoices (BR-KSA-72) |
> | `customer.identities` | <ul><li>Has EDU or HEA tax exemption</li><li>Has a type in \[NAT]</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-25` Invoice customer must have a national ID (NAT) when tax exemption is VATEX-SA-EDU or VATEX-SA-HEA (BR-KSA-49) |
> | `customer` | <ul><li>Simplified and (EDU or HEA exemptions), or invoice is simplified and summary, or standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-26` Invoice customer must be present for standard tax invoices, simplified summary invoices, and simplified invoices with EDU or HEA exemptions |
> | `customer.name` | <ul><li>Simplified and (EDU or HEA exemptions), or invoice is simplified and summary, or standard tax invoice</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-27` Invoice customer must be present for standard tax invoices, simplified summary invoices, and simplified invoices with EDU or HEA exemptions (BR-KSA-71), (BR-KSA-25), (BR-KSA-42) |
> | `supplier.tax_id` | <ul><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-28` Invoice supplier must have a tax id (BR-KSA-39) |
> | `supplier.tax_id.code` | <ul><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-29` Invoice supplier must have a tax id code (BR-KSA-39) |
> | `supplier.identities` | <ul><li>Identity must be one of: CRN/MOM/MLS/700/SAG/OTH</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-30` Invoice supplier must have a valid identity (CRN/MOM/MLS/700/SAG/OTH) (BR-KSA-08) |
> | `customer.tax_id` | <ul><li>Invoice is self-billed</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-31` Invoice customer must have a tax id when self-billed (BR-KSA-39) |
> | `customer.tax_id.code` | <ul><li>Invoice is self-billed</li><li>Present</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-32` Invoice customer must have a tax id code when self-billed (BR-KSA-39) |
> | `customer.identities` | <ul><li>Invoice is self-billed</li><li>Identity must be one of: CRN/MOM/MLS/700/SAG/OTH</li></ul> | `GOBL-SA-ZATCA-BILL-INVOICE-33` Invoice customer must have a valid identity for self-billed invoices (CRN/MOM/MLS/700/SAG/OTH) (BR-KSA-08) |

> [accordion] bill.Line
>
> | Field | Test | Validation Code / Message |
> | - | - | - |
> | `charges` | <ul><li>Length exactly 0</li></ul> | `GOBL-SA-ZATCA-BILL-LINE-01` Invoice line charges are not allowed (BR-KSA-EN16931-06) |

> [accordion] org.Address
>
> | Field | Test | Validation Code / Message |
> | - | - | - |
> | `country` | <ul><li>Present</li></ul> | `GOBL-SA-ZATCA-ORG-ADDRESS-01` Address must have a country code |
> | `street` | <ul><li>Country code is SA</li><li>Present</li></ul> | `GOBL-SA-ZATCA-ORG-ADDRESS-02` Invoice addresses in SA must have a street name (BR-KSA-09), (BR-KSA-63) |
> | `num` | <ul><li>Country code is SA</li><li>Present</li><li>Matches `^\d{4}$`</li></ul> | `GOBL-SA-ZATCA-ORG-ADDRESS-03` Invoice addresses in SA must have a 4 digits building number (BR-KSA-09), (BR-KSA-63), (BR-KSA-37) |
> | `code` | <ul><li>Country code is SA</li><li>Present</li><li>Matches `^\d{5}$`</li></ul> | `GOBL-SA-ZATCA-ORG-ADDRESS-04` Invoice addresses in SA must have a 5 digits postal code (BR-KSA-09), (BR-KSA-63) (BR-KSA-67), (BR-KSA-66) |
> | `locality` | <ul><li>Country code is SA</li><li>Present</li></ul> | `GOBL-SA-ZATCA-ORG-ADDRESS-05` Invoice addresses in SA must have a city name (BR-KSA-09), (BR-KSA-63) |
> | `street_extra` | <ul><li>Country code is SA</li><li>Present</li></ul> | `GOBL-SA-ZATCA-ORG-ADDRESS-06` Invoice addresses in SA must have a district name (BR-KSA-09), (BR-KSA-63) |

> [accordion] tax.Combo
>
> | Field | Test | Validation Code / Message |
> | - | - | - |
> | `ext` | <ul><li>Valid SA VAT exemption code</li></ul> | `GOBL-SA-ZATCA-TAX-COMBO-01` Invoice line tax cef-vatex extension code must be present and valid for Z/E/O categories, and must not be set for Standard (BR-KSA-CL-04) |
> | `ext` | <ul><li>Ext 'untdid-tax-category' in \[S, Z, E, O]</li></ul> | `GOBL-SA-ZATCA-TAX-COMBO-02` Invoice line tax untdid-tax-category extension code must contain one of the values (S, Z, E, O) (BR-KSA-18) |
> | `cat` | <ul><li>One of \[VAT]</li></ul> | `GOBL-SA-ZATCA-TAX-COMBO-03` Tax schema id must be 'VAT' (BR-KSA-54) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.