# MAYA OS ENTERPRISE — ACCOUNTING & GENERAL LEDGER ARCHITECTURE

## 1. Single Source of Truth Double-Entry Engine

Every financial module (Treasury, Procurement, AR/Debtors, AP/Creditors, Fleet, Inventory, Loans, Payroll, Opening Balances) posts strictly through the central `accounting` Voucher & `LedgerEntry` engine. No shadow ledgers or duplicated vendor/customer masters exist.

- **Balanced Invariant**: Posted vouchers must satisfy $\sum \text{Debit} = \sum \text{Credit}$ up to exact Decimal precision (`Decimal("0.01")` quantized currency amounts), enforced inside `transaction.atomic()` blocks with `SELECT ... FOR UPDATE` locks on fiscal periods and sequence counters under MySQL `READ-COMMITTED`.
- **Workflow States**: `DRAFT` -> `SUBMITTED` -> `APPROVED` -> `POSTED` (immutable ledger lines; corrections require a compensating reversal or credit/debit note, never silent mutation).
- **Fiscal Year & Period Locking**: Nepal BS fiscal years (`Shrawan` to `Ashadh`) divide into 12 `FiscalPeriod` records (`is_closed`). Posting into a closed period is blocked at service and database-lock level.

## 2. Subledger Control Accounts & Dimensions

- **Control Accounts**: `1100 Accounts Receivable`, `2010 Accounts Payable`, `Employee Imprest Receivable`, bank/cash GL links stay reconciled against party subledgers (`party_hub`), `BankAccount.gl_account`, and `CashAccount.gl_account`.
- **Dimensions**: `project`, `worksite`, `cost_center`, `fleet_vehicle`, `employee`, and `party` tags propagate onto `LedgerEntry` lines for real-time project profitability and cost-center reporting.

## 3. Opening Balance Cutover & Lock

Opening balances (`/api/accounting/opening-balances/`) support multi-line trial balance import, Party AP/AR subledger tie-out, Bank unpresented cheque / deposit-in-transit cutover, Inventory valuation seed, and formal Opening Balance Lock once `Assets = Liabilities + Equity`.

