← Projects

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.

A document’s pathThe invoice on the Emitere page, run through Registru without writing anything. The app is in Romanian.

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

  • ✓implicitalways
  • ·cota-declarataline.tax_code != ""
  • ·servicii-fara-stocline.kind == "service"
  • ·agentie-comisionline.revenue_code == "AGENCY"
  • ·export-fara-tvaparty.country != "MD" && line.kind != "service"
  • ·asigurari-scutitestartswith(line.product_ref, "ASG-")
  • ·client-mare-cont-separatparty.segment == "key" && total > 10000000

terms · terms0 days

  • ✓termen-implicitalways
  • ✓persoana-fizicaparty.is_company == 0
  • ·contract-cadruhas(party.contract)

payment · payment242

  • ✓plata-implicitalways
  • ·numerarmethod == "cash"
  • ·portofelmethod == "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"})
      end

712 144,00521 (144,00)

analyticssezon=extrasezondurata=lungcanal=webdestinatii=Turcia

Pure data: the lines, not written yet.

accountexplanationdebitcredit
611Venituri din vînzăriAntalya, 7 nopți–18.000,00
711Costul vînzărilorcost13.200,00–
217Mărfuristoc–13.200,00
5344Datorii privind taxa pe valoarea adăugatăTVA S20–3.600,00
712Cheltuieli de distribuirecomision-agent: comision agent 3% pe TUR-ANT144,00–
521Datorii comerciale curentecomision-agent: datorie comision agent–144,00
221Creanțe comercialecreanță, scadent 2026-10-2721.600,00–
total34.944,0034.944,00

It checks everything before a single line exists.

accountexplanationdebitcredit
611Venituri din vînzăriAntalya, 7 nopți–18.000,00
711Costul vînzărilorcost13.200,00–
217Mărfuristoc–13.200,00
5344Datorii privind taxa pe valoarea adăugatăTVA S20–3.600,00
712Cheltuieli de distribuirecomision-agent: comision agent 3% pe TUR-ANT144,00–
521Datorii comerciale curentecomision-agent: datorie comision agent–144,00
221Creanțe comercialecreanță, scadent 2026-10-2721.600,00–
total34.944,0034.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.

accountexplanationdebitcredit
611Venituri din vînzăriAntalya, 7 nopți–18.000,00
711Costul vînzărilorcost13.200,00–
217Mărfuristoc–13.200,00
5344Datorii privind taxa pe valoarea adăugatăTVA S20–3.600,00
712Cheltuieli de distribuirecomision-agent: comision agent 3% pe TUR-ANT144,00–
521Datorii comerciale curentecomision-agent: datorie comision agent–144,00
221Creanțe comercialecreanță, scadent 2026-10-2721.600,00–
total34.944,0034.944,00

✓ It passes every check: 0 violations.

Triggers in the schema: no UPDATE, no DELETE. A mistake is reversed, and the trace stays.

Registru, the Emitere page: the proposal for the invoice, its totals equal and its checks passed
Registru, the Emitere page: the proposal for the invoice, its totals equal and its checks passed

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
The dashboard: 180 movements, the sum of balances 0.00 and the invariants, all checked

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.

The Rules page: the posting and payment sets, with their conditionsThe Scripts page: the installed Lua scripts and the test bench

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.

The financial statements: the balance sheetThe VAT returnRegisters: the trial balanceThe accounting journalPayroll: the pay sheet and the time sheet

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:

  1. the balance sheet didn’t balance during the year: the result so far was missing until closing
  2. two tax accounts mixed up: the one from salaries and the non-residents’ one
  3. the VAT check counted income tax on salaries, so it lit up on every payroll
The year’s trial balance
123Mijloace fixe240.000,00
1237Mijloace fixe primite în leasing financiar360.000,00
124Amortizarea mijloacelor fixe(60.000,00)
1247Amortizarea mijloacelor fixe primite în leasing financiar(120.000,00)
211Materiale36.000,00
2131Obiecte de mică valoare și scurtă durată în stoc3.000,00
2132Obiecte de mică valoare și scurtă durată în exploatare5.000,00
214Uzura obiectelor de mică valoare și scurtă durată(5.000,00)
2161Produse finite34.800,03
218Ajustări pentru deprecierea stocurilor(25.200,03)
221Creanțe comerciale42.000,00
2261Creanțe ale titularilor de avans840,00
231Creanțe privind veniturile din utilizarea de către terți a activelor entității14.178,08
241Casa47.000,00
242Conturi curente în monedă națională1.138.450,00
251Investiții financiare curente în părți neafiliate200.000,00
311Capital social(1.000.000,00)
4213Datorii privind leasingul financiar(240.000,00)
521Datorii comerciale curente(553.200,00)
531Datorii față de personal privind retribuirea muncii(317.879,04)
5331Datorii față de bugetul asigurărilor sociale de stat(59.033,71)
5332Datorii față de fondurile asigurării obligatorii de asistență medicală(22.649,14)
5342Datorii privind impozitul pe venit din salariu(19.128,96)
5343Datorii privind impozitul pe venit reținut la sursa de plată(3.000,00)
5344Datorii privind taxa pe valoarea adăugată(40.440,00)
537Finanțări și încasări cu destinație specială curente(56.000,00)
611Venituri din vînzări(420.000,00)
613Venituri din dobînzile aferente împrumuturilor acordate(14.178,08)
616Venituri aferente mijloacelor cu destinație specială(24.000,00)
711Costul vînzărilor318.199,97
7116Costuri aferente contractelor de leasing operațional și financiar (arendă, locațiune)33.550,00
713Cheltuieli administrative457.490,85
714Alte cheltuieli din activitatea operațională25.200,03
716Cheltuieli aferente mijloacelor cu destinație specială24.000,00
811Activități de bază–
821Costuri 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)