mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-08 21:33:59 +02:00
SQL: Add account_balances view
This commit is contained in:
parent
8ae6dfb604
commit
48bfde333a
1 changed files with 11 additions and 0 deletions
11
brmbar3/SQL
11
brmbar3/SQL
|
@ -79,3 +79,14 @@ CREATE TABLE transaction_splits (
|
||||||
|
|
||||||
memo TEXT
|
memo TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- List balances of accounts computed based on transactions
|
||||||
|
-- Note that currency information is currently not supplied; inventory items
|
||||||
|
-- have balances in stock amounts.
|
||||||
|
CREATE VIEW account_balances AS
|
||||||
|
SELECT ts.account AS id, accounts.name AS name, accounts.acctype AS acctype,
|
||||||
|
-SUM(CASE WHEN ts.side = 'credit' THEN -ts.amount ELSE ts.amount END) AS crbalance
|
||||||
|
FROM transaction_splits AS ts
|
||||||
|
LEFT JOIN accounts ON accounts.id = ts.account
|
||||||
|
GROUP BY ts.account, accounts.name, accounts.acctype
|
||||||
|
ORDER BY crbalance ASC;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue