# Rule: Aged Receivables & Payables (collections / what's owed)

- **Receivables** = what customers owe you = debit balances on **Client** accounts (class 411). **Payables** = what you owe suppliers = credit balances on **Supplier** accounts (class 401).
- Use the **`aged_receivables`** and **`aged_payables`** tools. They do **FIFO open-item aging**: payments are applied to the oldest invoices first, and whatever is still open is bucketed by age — **0-30 / 31-60 / 61-90 / 90+ days** — from the as-of date.
- **as_of** defaults to the latest transaction date in the books (so aging is meaningful, not "everything is 90+ years old").
- Buckets are in **LBP**; each debtor/creditor also shows its **net USD** balance.

## DSO (Days Sales Outstanding)
- DSO = Receivables ÷ sales-per-day = how many days, on average, it takes to get paid. Lower is better; a **rising DSO over consecutive periods is an early cash-flow warning**.
- `aged_receivables` returns `dso_days` computed over the sales window up to as_of.

## Invoice-level open items (added 2026-11-09, from the UNO VB classes)
- UNO records which receipt paid which invoice in **`InvoicePayments`** (`Paid`, `totalhtpaid`, `vatpaid`, cash/card/cheque split). **`open_invoices`** = UNO's "Outstanding Invoices" screen: per invoice remaining = total − allocated payments − returns referencing it, remaining HT/VAT, due date (invoice date + PayTermsDays), overdue flag, cash vs credit customer (credit limit 0 = cash customer, UNO rule); `side=payable` for supplier bills. Materiality like UNO: LBP > 10,000 / USD > 1.
- Prefer `open_invoices` when the company allocates payments (LPHARM, Ghazi); on a company with almost no allocations (Golden Pharm: 17 rows) it says so — use the GL aging instead.
- Related: `invoice_payments` (how an invoice was settled), `receipt_allocations` (receipts not applied to any invoice), `payment_schedule` (instalments, where used), `party_balances` (every customer/supplier with balance, last invoice/receipt, contact, salesman), `credit_limit_check`, `salesman_customers` (portfolio mapping UNO uses for "outstanding by salesman").

## What to flag to the owner
- **90+ bucket** = likely bad/at-risk debt → chase or provision.
- **AP > AR** = trade working-capital squeeze.
- **Concentration**: one customer = large share of AR (collection risk) or one supplier = large share of AP (dependency/negotiation leverage).
- Note: FIFO "open" total can differ slightly from the net account balance when a party has prepayments/advances (carried, not aged).
