added History view
This commit is contained in:
parent
3a5d70d889
commit
acad2118c5
38
schema.sql
38
schema.sql
@ -258,3 +258,41 @@ CREATE VIEW ReconstructedBankStatement AS
|
|||||||
WHERE targetCredit IS NULL -- exclude internal transfers
|
WHERE targetCredit IS NULL -- exclude internal transfers
|
||||||
ORDER BY date ASC
|
ORDER BY date ASC
|
||||||
;
|
;
|
||||||
|
|
||||||
|
-- History view: All incoming, outgoing payments and internal transfers
|
||||||
|
CREATE VIEW History AS
|
||||||
|
SELECT c.date AS date,
|
||||||
|
c.purpose AS purpose,
|
||||||
|
account,
|
||||||
|
c.value AS credit,
|
||||||
|
NULL AS debit,
|
||||||
|
NULL AS contra,
|
||||||
|
NULL AS billId
|
||||||
|
FROM Credit AS c
|
||||||
|
LEFT OUTER JOIN Debit AS d ON c.ID=d.targetCredit
|
||||||
|
GROUP BY c.ID
|
||||||
|
HAVING count(d.billId) == 0 -- exclude internal transfers
|
||||||
|
UNION -- internal transfers with account as source
|
||||||
|
SELECT DATE(timestamp) AS date,
|
||||||
|
d.purpose AS purpose,
|
||||||
|
d.debtor AS account,
|
||||||
|
NULL AS credit,
|
||||||
|
t.amount AS debit,
|
||||||
|
c.account AS contra,
|
||||||
|
d.billId AS billId
|
||||||
|
FROM Transfer t
|
||||||
|
LEFT JOIN Credit AS c ON c.Id = t.fromCredit
|
||||||
|
LEFT JOIN Debit AS d ON d.billId = t.billId
|
||||||
|
UNION -- internal transfers with account as target
|
||||||
|
SELECT DATE(timestamp) AS date,
|
||||||
|
d.purpose AS purpose,
|
||||||
|
c.account AS account,
|
||||||
|
t.amount AS credit,
|
||||||
|
NULL AS debit,
|
||||||
|
d.debtor AS contra,
|
||||||
|
d.billId AS billId
|
||||||
|
FROM Transfer t
|
||||||
|
LEFT JOIN Debit AS d ON d.billId = t.billId
|
||||||
|
LEFT JOIN Credit AS c ON c.Id = t.fromCredit
|
||||||
|
ORDER BY date ASC
|
||||||
|
;
|
||||||
|
@ -9,9 +9,9 @@ john: 0 +0 0
|
|||||||
Club: 0 +0 -16250
|
Club: 0 +0 -16250
|
||||||
alex: 7200 +16250 0
|
alex: 7200 +16250 0
|
||||||
# Some updates and deletes that could, unless denied, destroy consistency ...
|
# Some updates and deletes that could, unless denied, destroy consistency ...
|
||||||
Error: near line 300: paid is set and adjusted automatically according to added Transfer records
|
Error: near line 338: paid is set and adjusted automatically according to added Transfer records
|
||||||
Error: near line 301: Debt is involved in transfers to revoke at first
|
Error: near line 339: Debt is involved in transfers to revoke at first
|
||||||
Error: near line 302: FOREIGN KEY constraint failed
|
Error: near line 340: FOREIGN KEY constraint failed
|
||||||
# After revoking transactions, you are free to change or delete debts and credits ...
|
# After revoking transactions, you are free to change or delete debts and credits ...
|
||||||
Club: 7200 +0 0
|
Club: 7200 +0 0
|
||||||
alex: 0 +0 0
|
alex: 0 +0 0
|
||||||
|
Loading…
Reference in New Issue
Block a user