feat(accounting): configurable revenue posting engine (account determination)
Replaces the hardcoded AccountCodes::creditAccountForPaymentType() match
statement with a versioned, effective-dated mapping that finance controls
from /accounting/revenue-mapping.
Every collected amount can now be split across multiple GL accounts by flat
amount, percentage, or remainder, with VAT handled as its own layer and
deferred revenue amortised over the service period.
What the live DB showed, and this addresses:
- 4,256,399.96 EGP across 129 transactions posted to a single catch-all
account (410515 إيرادات متنوعه) — waiver, separation, death, foreign
membership, early settlement and four payment types that had no rule in
the code at all and silently fell through to `default`.
- 240,582 EGP of divorce fees posted to 410302 «محل 1», a shop rental account.
- 120301 العملاء and 230804 جاري مصلحة الضرائب are header accounts, and
JournalService rejects posting to headers — so every AR and VAT entry has
been failing silently. accounts_receivable holds 0 rows against 970,592.67
EGP of unpaid instalments.
Model follows SAP account determination / Dynamics posting profiles, adapted
to Egyptian VAT law 67/2016 and EAS 48 revenue recognition:
- revenue_streams catalogue of every chargeable thing
- revenue_tax_profiles rate + inclusive/exclusive + treatment
- revenue_posting_rules versioned, effective-dated, scopeable
- revenue_posting_rule_lines the split components
- revenue_posting_log which rule version produced which entry
- revenue_recognition_schedules deferred revenue amortisation
Allocation order is fixed and deterministic: tax extraction, then fixed
amounts, then percentages, then a mandatory remainder line that absorbs
rounding residue so the entry always balances.
Tax is a separate layer rather than a split because inclusive and exclusive
pricing are not the same number: 14% of a tax-inclusive 1140 is 140 on
revenue of 1000, not 159.60. Deferral is separate for the same reason — it
is a split across periods, not accounts.
Adds two postable accounts the chart was missing: 120301004 أعضاء النادي
(مدينون) and 12041106 ضريبة القيمة المضافة — مدخلات.
Seeded rules reproduce current posting behaviour exactly, so this deploy
moves no reported number. Streams landing in a catch-all are flagged for
review rather than silently re-pointed — repointing them moves real revenue
between accounts and is finance's decision.
Unconfigured streams fall through to the legacy path unchanged.
Co-Authored-By:
Claude Opus 5 (1M context) <noreply@anthropic.com>
Showing
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Please register or sign in to comment