2017-01-19 21:44:22 +01:00
|
|
|
-- Log of internal transfers
|
|
|
|
DROP VIEW IF EXISTS History;
|
|
|
|
CREATE VIEW History AS
|
|
|
|
-- internal transfers with account as source
|
|
|
|
SELECT DATE(timestamp) AS date,
|
|
|
|
d.purpose AS purpose,
|
2017-01-29 15:57:34 +01:00
|
|
|
d.category AS category,
|
2017-01-19 21:44:22 +01:00
|
|
|
d.debtor AS account,
|
|
|
|
t.credId AS credId,
|
|
|
|
t.amount AS debit,
|
|
|
|
NULL AS credit,
|
|
|
|
d.targetCredit AS contra,
|
|
|
|
d.billId AS billId,
|
|
|
|
t.note AS note
|
|
|
|
FROM Transfer t
|
|
|
|
LEFT JOIN Debit AS d ON d.billId = t.billId
|
|
|
|
-- internal transfers with account as target
|
|
|
|
UNION
|
|
|
|
SELECT DATE(timestamp) AS date,
|
|
|
|
d.purpose AS purpose,
|
2017-01-29 15:57:34 +01:00
|
|
|
d.category AS category,
|
2017-01-19 21:44:22 +01:00
|
|
|
c.account AS account,
|
|
|
|
d.targetCredit AS credId,
|
|
|
|
NULL AS debit,
|
|
|
|
t.amount AS credit,
|
|
|
|
t.credId AS contra,
|
|
|
|
d.billId AS billId,
|
|
|
|
t.note AS note
|
|
|
|
FROM Transfer t
|
|
|
|
LEFT JOIN Debit AS d ON d.billId = t.billId
|
|
|
|
LEFT JOIN Credit AS c ON c.credId = d.targetCredit
|
|
|
|
ORDER BY date ASC
|
|
|
|
;
|