Skip to content

nbrain_mena

Invoice encoding, regional tax helpers and identifier checks

nbrain_mena · Invoice encoding, regional tax helpers and identifier checks

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102490nbrain_menanbrain_mena1.0.0FEATMITPLpgSQL

PostgreSQL · 13, 14, 15, 16, 17

Usage

Sources:

nbrain_mena 1.0.0 provides SQL and PL/pgSQL helpers for invoice-field encoding, selected tax calculations and identifier checks. Upstream lists PostgreSQL 13–17. Its control and versioned SQL install a normal extension; managed-provider availability is not established by that source claim.

Enable and Call

Install the control and SQL files on the server, then create the extension with an appropriately privileged role. The control is relocatable but not marked trusted. PL/pgSQL must be available; no shared library, preload or restart is needed.

CREATE EXTENSION nbrain_mena;
SELECT nbrain_is_valid_saudi_vat('300123456789003');
SELECT * FROM nbrain_calculate_mena_vat('BH', 200.000);
SELECT nbrain_is_valid_arab_iban('SA0380000000608010167519');

Functions and Limits

nbrain_zatca_tlv_qr encodes five invoice fields as UTF-8 TLV and returns single-line Base64, not a rendered QR image. It checks the Saudi VAT-number shape and rejects fields longer than 255 bytes. It does not verify the timestamp’s meaning or implement a complete electronic-invoicing protocol.

nbrain_calculate_mena_vat returns rate_pct, decimals, net_out, vat_out and gross_out. Its rates and country list are hard-coded in the reviewed SQL; unsupported country codes raise an error. Check applicable rates and rounding rules independently before business use.

nbrain_is_valid_saudi_vat, nbrain_is_valid_uae_trn, nbrain_is_valid_egypt_rin and nbrain_is_valid_morocco_ice check string patterns, not registration status. nbrain_is_valid_arab_iban checks formatting and MOD-97, with explicit lengths for ten country prefixes; it does not restrict all other prefixes or confirm an account exists.

Functions are declared strict, so null inputs return null. The source provides an initial installation script, with no version-to-version upgrade script. Review future SQL migrations and dependent application behavior before upgrading.

Table reader