413
Ledger & statements
General ledger
Trial balance: the balance of every account. Debits must equal credits.
| Code | Account | Type | Total debits | Total credits | Debit balance | Credit balance |
|---|---|---|---|---|---|---|
| 1000 | Petty cash | ASSET | 70,000.00 | 36,872.20 | 33,127.80 | |
| 1010 | Bank - KBank current account | ASSET | 13,025,481.73 | 9,128,025.48 | 3,897,456.25 | |
| 1020 | Bank - SCB savings account | ASSET | 1,110,137.60 | 0.00 | 1,110,137.60 | |
| 1100 | Accounts receivable | ASSET | 12,050,643.86 | 10,046,415.47 | 2,004,228.39 | |
| 1150 | Input VAT | ASSET | 157,153.50 | 0.00 | 157,153.50 | |
| 1160 | Withholding tax prepaid | ASSET | 137,005.30 | 0.00 | 137,005.30 | |
| 1500 | Office equipment | ASSET | 300,000.00 | 0.00 | 300,000.00 | |
| 1510 | Computer equipment | ASSET | 660,000.00 | 0.00 | 660,000.00 | |
| 1590 | Accumulated depreciation | ASSET | 0.00 | 252,200.00 | 252,200.00 | |
| 2000 | Accounts payable | LIABILITY | 2,972,093.44 | 3,060,154.44 | 88,061.00 | |
| 2100 | Output VAT | LIABILITY | 3,115.00 | 458,563.70 | 455,448.70 | |
| 2150 | Withholding tax payable | LIABILITY | 0.00 | 61,518.70 | 61,518.70 | |
| 2500 | Long-term bank loan | LIABILITY | 200,000.00 | 1,000,000.00 | 800,000.00 | |
| 3000 | Share capital | EQUITY | 0.00 | 2,000,000.00 | 2,000,000.00 | |
| 3100 | Retained earnings | EQUITY | 0.00 | 750,000.00 | 750,000.00 | |
| 4000 | Software sales | REVENUE | 0.00 | 6,080,563.86 | 6,080,563.86 | |
| 4100 | Consulting services | REVENUE | 0.00 | 4,417,401.98 | 4,417,401.98 | |
| 4200 | Training income | REVENUE | 0.00 | 1,796,483.72 | 1,796,483.72 | |
| 4800 | Interest income | REVENUE | 0.00 | 10,240.00 | 10,240.00 | |
| 4850 | Foreign exchange gain | REVENUE | 0.00 | 45,028.29 | 45,028.29 | |
| 4900 | Sales returns and allowances | REVENUE | 44,500.00 | 0.00 | 44,500.00 | |
| 5000 | Cost of services | EXPENSE | 200,983.25 | 0.00 | 200,983.25 | |
| 5100 | Salaries and wages | EXPENSE | 5,313,000.00 | 0.00 | 5,313,000.00 | |
| 5110 | Social security contributions | EXPENSE | 157,500.00 | 0.00 | 157,500.00 | |
| 5200 | Office rent | EXPENSE | 850,000.00 | 0.00 | 850,000.00 | |
| 5300 | Utilities | EXPENSE | 170,670.00 | 0.00 | 170,670.00 | |
| 5400 | Marketing and advertising | EXPENSE | 836,550.00 | 0.00 | 836,550.00 | |
| 5500 | Travel | EXPENSE | 126,480.00 | 0.00 | 126,480.00 | |
| 5600 | Office supplies | EXPENSE | 34,460.00 | 0.00 | 34,460.00 | |
| 5700 | Software subscriptions | EXPENSE | 427,565.79 | 0.00 | 427,565.79 | |
| 5800 | Professional fees | EXPENSE | 90,000.00 | 0.00 | 90,000.00 | |
| 5850 | Depreciation | EXPENSE | 132,200.00 | 0.00 | 132,200.00 | |
| 5900 | Bank charges | EXPENSE | 4,766.00 | 0.00 | 4,766.00 | |
| 5950 | Foreign exchange loss | EXPENSE | 32,662.37 | 0.00 | 32,662.37 | |
| 5960 | Interest expense | EXPENSE | 36,500.00 | 0.00 | 36,500.00 | |
| Total | 16,756,946.25 | 16,756,946.25 | ||||
How this works - feature 413 Chart of accounts, trial balance, journals and account ledgers.
Concepts
- Double entry: every entry has debits = credits; JournalService.post refuses anything else.
- CHECK constraint: a line is either a debit or a credit, never negative.
- Trial balance: if total debits = total credits the books are in balance.
- Ledger running balance: SUM(...) OVER (ORDER BY ... ROWS UNBOUNDED PRECEDING).
- Document numbers come from one MERGE ... OUTPUT statement (NumberingService).
Read the code
service/JournalServiceservice/JournalDraftservice/ReportService#trialBalanceservice/NumberingService
SQL behind this page
SELECT a.id, a.code, a.name, a.type,
COALESCE(SUM(l.debit), 0) AS debit,
COALESCE(SUM(l.credit), 0) AS credit
FROM account a
LEFT JOIN v_ledger l ON l.account_id = a.id AND l.entry_date <= :asOf
GROUP BY a.id, a.code, a.name, a.type
ORDER BY a.code
-- account ledger
SELECT entry_id, entry_no, entry_date, entry_description, source_type, source_ref, memo, debit, credit,
SUM(natural_amount) OVER (ORDER BY entry_date, entry_id, line_id
ROWS UNBOUNDED PRECEDING) AS running
FROM v_ledger
WHERE account_id = :accountId AND entry_date BETWEEN :from AND :to
ORDER BY entry_date, entry_id, line_id