Skip to content

URD: Expenses

ModuleCORE-12Versionv0.4
StatusIn-progressDate2026-05-30

1. Purpose

Define the user-facing requirements for Expenses — the merchant's books. The module must track money across accounts (cash, bank, QR, mobile-POS), record every movement as a balanced double-entry voucher, classify income and expense by category, and create most postings automatically in response to sales, purchases, and stock movements so owners do not record routine money flows by hand.

2. Scope

IncludedExcluded
Money accounts / wallets (Cash, Bank, QR, Mobile-POS)Payment-gateway processing (Payment module)
Internal control accounts (Inventory, Cost of Goods Sold)Tax invoice issuance (Invoice module)
Vouchers: receipt, payment, transfer, adjustmentStock quantity & costing math (Inventory module)
Ledger lines (debit / credit) per voucherBudget tracking, P&L, cash-flow forecast (future)
Income / expense categories (seeded + custom)Recurring / scheduled expenses (future)
Auto posting from sale payment, PO receipt, stock movementReceipt-image capture / OCR (future)
Voucher void by balanced reversalMulti-currency conversion (single currency per voucher)

3. Definitions

TermDefinition
Account (wallet)A place money lives — a cash drawer, bank account, QR acceptance account, or mobile-POS terminal. Holds a running balance.
Internal control accountA non-cash bookkeeping account (Inventory, Cost of Goods Sold) the system maintains automatically; not user money.
VoucherOne bookkeeping document recording a money event: a receipt (money in), payment (money out), transfer (between accounts), or adjustment.
Ledger lineOne debit or credit row inside a voucher. A voucher always balances: total debits equal total credits where both sides apply.
CategoryThe income/expense classification on a movement (e.g. Sale, Purchase, Rent).
Default accountThe account a given type of automatic posting routes to by default — one per type per merchant.
VoidCancelling an issued voucher by posting an equal-and-opposite reversal, preserving the original for audit.

4. Conceptual Model

Conceptual only — the full schema, enums, and invariants live in the finance developer domain model.

5. Functional Requirements

One table per functional area. Priority = MoSCoW (Must / Should / Could / Won't). Area codes line up with the test-case IDs.

5.1 Accounts (WAL)

IDPRequirement
URD-WAL-001MHold accounts of types Cash, Bank, QR, and Mobile-POS, each owned by one merchant
URD-WAL-002MMaintain a default account per type per merchant for routing automatic postings
URD-WAL-003MAuto-create each merchant's default and internal control accounts when the merchant is created
URD-WAL-004MTrack each account's running current balance as vouchers post
URD-WAL-005SAllow account currency (default VND)
URD-WAL-006SRestrict account visibility to merchants the user is granted (admins see all)

5.2 Vouchers & posting (VCH)

IDPRequirement
URD-VCH-001MRecord money events as vouchers of type receipt, payment, transfer, or adjustment
URD-VCH-002MEvery voucher is balanced — debits equal credits where both sides apply
URD-VCH-003MAuto-issue a receipt voucher when a sale payment succeeds, classified as Sale
URD-VCH-004MAuto-issue a payment voucher to the vendor when a purchase order is received
URD-VCH-005MAuto-post cost of goods sold and stock adjustments to internal control accounts on stock movement
URD-VCH-006MAutomatic postings are idempotent — a repeated event never double-posts
URD-VCH-007MLink each voucher to its source document (sale order, purchase order, stock movement, manual)
URD-VCH-008SNumber each issued voucher per merchant, per type, per month
URD-VCH-009SSupport a manual lifecycle: draft → issue, and delete a draft before issue
URD-VCH-010STransfer money between two accounts as a single balanced transfer voucher
URD-VCH-011SVoid an issued voucher via a balanced reversal; the original is preserved
URD-VCH-012CAttribute a voucher to a POS shift session for shift cash movements

5.3 Ledger lines (TXN)

IDPRequirement
URD-TXN-001MEach voucher posts debit/credit ledger lines against accounts
URD-TXN-002MA line carries the account it affects, an optional category, an amount, and balance-before/after snapshot
URD-TXN-003MLines share the voucher's currency
URD-TXN-004SA line may reference its source document for traceability

5.4 Categories (CAT)

IDPRequirement
URD-CAT-001MProvide 14 seeded system categories spanning income and expense
URD-CAT-002MCategories are typed income or expense
URD-CAT-003MApply a system category automatically to auto-generated vouchers (e.g. Sale, Purchase)
URD-CAT-004SMerchants may add custom categories, nested under a parent

6. Acceptance Criteria

AC-VCH-01: Auto receipt on paid sale
GivenWhenThen
A sale order is paidThe payment-succeeded event arrivesA receipt voucher is issued, classified as Sale, linked to the sale order
The receiving account's balance goes up by the amount
The same event arrives againProcessed a second timeNo second voucher is created (idempotent)
AC-VCH-02: Auto payment on purchase-order receipt
GivenWhenThen
A purchase order is receivedThe PO-received event arrivesA payment voucher is issued to the vendor, linked to the purchase order
Inventory value is positiveThe voucher balances a stock asset leg against the cash leg(s)
AC-WAL-01: Default & control accounts on new merchant
GivenWhenThen
A merchant is createdThe merchant event is reconciledThe merchant's default accounts are seeded
Internal Inventory and Cost-of-Goods-Sold control accounts exist
AC-VCH-03: Transfer between accounts
GivenWhenThen
Two accounts of the merchantOwner transfers an amount A → BOne transfer voucher posts a debit and a credit of equal value
Account A goes down and Account B goes up by the same amount
AC-VCH-04: Void by reversal
GivenWhenThen
An issued voucherOwner voids itA balanced reversal voucher is posted; the original is preserved
Affected account balances return to their pre-voucher state

7. Constraints & Non-Goals

Constraints

IDConstraint
C-01Every voucher must balance (debits equal credits where both sides apply)
C-02Exactly one default account per type per merchant
C-03Automatic postings must be idempotent under repeated events
C-04All ledger lines in a voucher share the voucher's currency (single-currency; default VND)
C-05The 14 seeded system categories are not merchant-owned
C-06Records use soft-delete; issued vouchers are never hard-deleted — they are voided
C-07Internal control accounts must exist before cost-of-goods postings

Non-Goals

  • Budget tracking and variance
  • Recurring / scheduled expense automation
  • Profit & loss statement and cash-flow forecasting
  • Receipt-image capture / OCR
  • Multi-currency conversion within a single voucher

8. Version History

DateAuthorDescriptionVer
2026-02-26P. Do — Product OwnerInitial user storiesv0.1
2026-04-16P. Do — Product OwnerWallets, transactions, categories scopev0.3
2026-05-30Docs migrationRestructured to verified double-entry voucher model (accounts / vouchers / ledger lines / categories); corrected account types and transaction modelv0.4

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.