# Rule: Balance Sheet (how to generate it correctly)

The balance sheet is a snapshot at a date: **Assets = Liabilities + Equity.**

## Building it from the ledger
1. Take all accounts with `AccountTypes.IsBalanceSheet = 1`, as-of the date (`trp_valuedate <= @date`).
2. Classify by `AccountTypes.BalanceSheetGroup`: groups starting with **"Assets"** are assets; groups starting with **"Lib"** (Liabilities & Equity) are liabilities/equity. (Note the data's spelling: "Libailities & Equity…".)
3. **Signs:** assets are debit-natured → balance = SUM(debit) − SUM(credit), shown positive. Liabilities & equity are credit-natured → flip the sign so they show positive.

## CRITICAL: carry the period result into equity
A balance sheet built from balance-sheet accounts alone **will NOT balance**, because the year's profit still sits in the P&L (Income/Expense) accounts and is only moved to retained earnings at **year-end close**.
- Compute **Net result = Income − Expenses** (the P&L accounts, `IsBalanceSheet = 0`) up to the same date.
- **Add that Net result to Equity.** Then Assets = Liabilities + Equity + Net result.
- Verified: the "imbalance" of the BS-only sum equals the P&L net profit exactly (e.g. ~773.7M LBP in 2021).

Use the **`balance_sheet`** tool — it does all of this and returns a `balance_check` (should be ~0; a tiny residual is the books' known rounding difference).

## This company's data
Mostly **Current Assets** (AR + Cash + Banks + Inventory) vs **Current Liabilities** (AP); capital/equity accounts exist but carry little/no balance, so equity is essentially the accumulated net result.
