accounting for a company in Moldova
Accounting, with rules as data.
The official chart of accounts, the four financial statements, seven tax returns and e-Factura. Rules pick the accounts, Lua scripts work out the rest, and the database refuses anything that would break the ledger.
The shop says what happened, not what to post.
- InvoiceIssued
- F-2026-4688 · 2026-10-27
- client
- Ana Cebotari C3
- TUR-ANT
- Antalya, 7 nopți, Turcia
- pcs
- 2 × 9.000,00
- cost
- 6.600,00
- nights
- 7
- channel
- web
The reference is UNIQUE: the same event never gets in twice.
UNIQUE(ref) = F-2026-4688
Sent a second time, it wouldn’t be posted again: a UNIQUE constraint in the database stops it, not the code.
They pick the accounts, the VAT rate and the terms, in order of priority: the most specific has the last word.
posting · accounts611 · 711 · 217 · S20 · VZ
- ✓implicit
always - ·cota-declarata
line.tax_code != "" - ·servicii-fara-stoc
line.kind == "service" - ·agentie-comision
line.revenue_code == "AGENCY" - ·export-fara-tva
party.country != "MD" && line.kind != "service" - ·asigurari-scutite
startswith(line.product_ref, "ASG-") - ·client-mare-cont-separat
party.segment == "key" && total > 10000000
terms · terms0 days
- ✓termen-implicit
always - ✓persoana-fizica
party.is_company == 0 - ·contract-cadru
has(party.contract)
payment · payment242
- ✓plata-implicit
always - ·numerar
method == "cash" - ·portofel
method == "wallet"
Lua, in a cage: 200,000 instructions, no more.
function compute_lines(doc, resolved)
-- 3% din marja pe pachetele de peste 4 nopti, cu TVA din configuratie
local out = {}
local t = ctx.tax(resolved.tax_code or "S20")
for _, l in ipairs(doc.lines) do
if (l.nights or 0) > 4 and (l.unit_cost or 0) > 0 then
local margin = (l.unit_net - l.unit_cost) * l.qty
local fee = pct(margin, 3)
if fee > 0 then
table.insert(out, Line{account="712", debit=fee, party=doc.party.ref,
note="comision agent 3% pe " .. l.product_ref})
table.insert(out, Line{account="521", credit=fee, party=doc.party.ref,
note="datorie comision agent"})
end712 144,00521 (144,00)
analyticssezon=extrasezondurata=lungcanal=webdestinatii=Turcia
Pure data: the lines, not written yet.
| account | explanation | debit | credit |
|---|---|---|---|
| 611 | Venituri din vînzăriAntalya, 7 nopți | – | 18.000,00 |
| 711 | Costul vînzărilorcost | 13.200,00 | – |
| 217 | Mărfuristoc | – | 13.200,00 |
| 5344 | Datorii privind taxa pe valoarea adăugatăTVA S20 | – | 3.600,00 |
| 712 | Cheltuieli de distribuirecomision-agent: comision agent 3% pe TUR-ANT | 144,00 | – |
| 521 | Datorii comerciale curentecomision-agent: datorie comision agent | – | 144,00 |
| 221 | Creanțe comercialecreanță, scadent 2026-10-27 | 21.600,00 | – |
| total | 34.944,00 | 34.944,00 |
It checks everything before a single line exists.
| account | explanation | debit | credit |
|---|---|---|---|
| 611 | Venituri din vînzăriAntalya, 7 nopți | – | 18.000,00 |
| 711 | Costul vînzărilorcost | 13.200,00 | – |
| 217 | Mărfuristoc | – | 13.200,00 |
| 5344 | Datorii privind taxa pe valoarea adăugatăTVA S20 | – | 3.600,00 |
| 712 | Cheltuieli de distribuirecomision-agent: comision agent 3% pe TUR-ANT | 144,00 | – |
| 521 | Datorii comerciale curentecomision-agent: datorie comision agent | – | 144,00 |
| 221 | Creanțe comercialecreanță, scadent 2026-10-27 | 21.600,00 | – |
| total | 34.944,00 | 34.944,00 |
The write boundary: up to here, it’s only data.
✓ It passes every check: 0 violations.
fingerprint rules@8da30e961b6a + scripts@3144141fd2a7
read from the host comision-agent: tax(S20)
Only now would it be written, and a written line never changes.
| account | explanation | debit | credit |
|---|---|---|---|
| 611 | Venituri din vînzăriAntalya, 7 nopți | – | 18.000,00 |
| 711 | Costul vînzărilorcost | 13.200,00 | – |
| 217 | Mărfuristoc | – | 13.200,00 |
| 5344 | Datorii privind taxa pe valoarea adăugatăTVA S20 | – | 3.600,00 |
| 712 | Cheltuieli de distribuirecomision-agent: comision agent 3% pe TUR-ANT | 144,00 | – |
| 521 | Datorii comerciale curentecomision-agent: datorie comision agent | – | 144,00 |
| 221 | Creanțe comercialecreanță, scadent 2026-10-27 | 21.600,00 | – |
| total | 34.944,00 | 34.944,00 |
✓ It passes every check: 0 violations.
Triggers in the schema: no UPDATE, no DELETE. A mistake is reversed, and the trace stays.

Nr. 01
The database keeps the books, not the code.
What must not happen is written into the schema, as triggers and constraints. The application’s code can’t get around them, not even by mistake.
- posted lines can’t be changed or deleted, only reconciled
- a posted movement isn’t taken back with an UPDATE
- closed periods refuse any movement
- events are idempotent through a UNIQUE constraint
- cash accounts can’t go negative
- an account in a currency only takes lines in that currency
- money is INTEGER, in bani: not one REAL column in the whole system

Nr. 02
Rules are data. Scripts live in a cage.
Rules are written in its own language, deliberately without loops, or in CEL, and they’re versioned. What rules can’t do, scripts work out, in Lua or in Python, each in its own cage. Every movement remembers the rules’ version, the scripts’ fingerprint and everything they read from the host.


Nr. 03
The way the law asks for them.
The general chart of accounts, all 476 of them, from the Ministry of Finance’s order. The financial statements with the rows and codes of the national standards’ forms, the tax returns on the official forms, e-Factura in the required structure. Everything shown is derived from movements; nothing is stored twice.





Nr. 04
A whole year, in the same book.
A furniture factory, from 1 January to 31 December: made-to-order production with overheads, leasing, payroll with a sick leave, a grant, a deposit, a payment to a non-resident and the closing adjustments. Ten modules, written one after another, finally put together. The test found three bugs that no other test had seen:
- the balance sheet didn’t balance during the year: the result so far was missing until closing
- two tax accounts mixed up: the one from salaries and the non-residents’ one
- the VAT check counted income tax on salaries, so it lit up on every payroll
| 123 | Mijloace fixe | 240.000,00 |
| 1237 | Mijloace fixe primite în leasing financiar | 360.000,00 |
| 124 | Amortizarea mijloacelor fixe | (60.000,00) |
| 1247 | Amortizarea mijloacelor fixe primite în leasing financiar | (120.000,00) |
| 211 | Materiale | 36.000,00 |
| 2131 | Obiecte de mică valoare și scurtă durată în stoc | 3.000,00 |
| 2132 | Obiecte de mică valoare și scurtă durată în exploatare | 5.000,00 |
| 214 | Uzura obiectelor de mică valoare și scurtă durată | (5.000,00) |
| 2161 | Produse finite | 34.800,03 |
| 218 | Ajustări pentru deprecierea stocurilor | (25.200,03) |
| 221 | Creanțe comerciale | 42.000,00 |
| 2261 | Creanțe ale titularilor de avans | 840,00 |
| 231 | Creanțe privind veniturile din utilizarea de către terți a activelor entității | 14.178,08 |
| 241 | Casa | 47.000,00 |
| 242 | Conturi curente în monedă națională | 1.138.450,00 |
| 251 | Investiții financiare curente în părți neafiliate | 200.000,00 |
| 311 | Capital social | (1.000.000,00) |
| 4213 | Datorii privind leasingul financiar | (240.000,00) |
| 521 | Datorii comerciale curente | (553.200,00) |
| 531 | Datorii față de personal privind retribuirea muncii | (317.879,04) |
| 5331 | Datorii față de bugetul asigurărilor sociale de stat | (59.033,71) |
| 5332 | Datorii față de fondurile asigurării obligatorii de asistență medicală | (22.649,14) |
| 5342 | Datorii privind impozitul pe venit din salariu | (19.128,96) |
| 5343 | Datorii privind impozitul pe venit reținut la sursa de plată | (3.000,00) |
| 5344 | Datorii privind taxa pe valoarea adăugată | (40.440,00) |
| 537 | Finanțări și încasări cu destinație specială curente | (56.000,00) |
| 611 | Venituri din vînzări | (420.000,00) |
| 613 | Venituri din dobînzile aferente împrumuturilor acordate | (14.178,08) |
| 616 | Venituri aferente mijloacelor cu destinație specială | (24.000,00) |
| 711 | Costul vînzărilor | 318.199,97 |
| 7116 | Costuri aferente contractelor de leasing operațional și financiar (arendă, locațiune) | 33.550,00 |
| 713 | Cheltuieli administrative | 457.490,85 |
| 714 | Alte cheltuieli din activitatea operațională | 25.200,03 |
| 716 | Cheltuieli aferente mijloacelor cu destinație specială | 24.000,00 |
| 811 | Activități de bază | – |
| 821 | Costuri indirecte de producție | – |
sum of balances0,00
Mobilier Nord SRL, the year test’s company. The balances as run.py --no-serve prints them.
- 933 tests
- 78 commits in five days, 4–8 September
- 476 accounts, all from the official chart
- 28 ms a year’s general ledger, 30,000 rows (351 ms before)