Rest Budget in Grafana
This commit is contained in:
121
firefly_grafana/dashboard.sql
Normal file
121
firefly_grafana/dashboard.sql
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
SELECT
|
||||||
|
t.id
|
||||||
|
, a.id AS account_id
|
||||||
|
, a.name AS account_name
|
||||||
|
, aty.type
|
||||||
|
, t.amount
|
||||||
|
, tj.description AS tj_descr
|
||||||
|
, tj.date
|
||||||
|
, c.name AS category_name
|
||||||
|
FROM firefly.transactions AS t
|
||||||
|
INNER JOIN firefly.transaction_journals AS tj
|
||||||
|
ON t.transaction_journal_id = tj.id
|
||||||
|
LEFT JOIN firefly.category_transaction_journal as ctj
|
||||||
|
ON tj.id = ctj.transaction_journal_id
|
||||||
|
LEFT JOIN firefly.categories AS c
|
||||||
|
ON c.id = ctj.category_id
|
||||||
|
LEFT JOIN firefly.accounts AS a
|
||||||
|
ON t.account_id = a.id
|
||||||
|
LEFT JOIN firefly.account_types AS aty
|
||||||
|
ON a.account_type_id = aty.id
|
||||||
|
WHERE TRUE
|
||||||
|
AND tj.DATE BETWEEN '2025-11-28' AND '2025-11-28'
|
||||||
|
AND a.id = 1
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Total Expanses of the month
|
||||||
|
*/
|
||||||
|
SELECT
|
||||||
|
SUM(t.amount)
|
||||||
|
FROM firefly.transactions AS t
|
||||||
|
INNER JOIN firefly.transaction_journals AS tj
|
||||||
|
ON t.transaction_journal_id = tj.id
|
||||||
|
LEFT JOIN firefly.category_transaction_journal as ctj
|
||||||
|
ON tj.id = ctj.transaction_journal_id
|
||||||
|
LEFT JOIN firefly.categories AS c
|
||||||
|
ON c.id = ctj.category_id
|
||||||
|
LEFT JOIN firefly.accounts AS a
|
||||||
|
ON t.account_id = a.id
|
||||||
|
LEFT JOIN firefly.account_types AS aty
|
||||||
|
ON a.account_type_id = aty.id
|
||||||
|
WHERE TRUE
|
||||||
|
AND tj.DATE BETWEEN ${__from:date:iso} AND ${__to:date:iso}
|
||||||
|
AND a.id = 1
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Barchart with Budget
|
||||||
|
*/
|
||||||
|
SELECT
|
||||||
|
c.name AS category_name
|
||||||
|
, 500 AS budget
|
||||||
|
, ABS(SUM(t.amount)) AS current_status
|
||||||
|
FROM firefly.transactions AS t
|
||||||
|
INNER JOIN firefly.transaction_journals AS tj
|
||||||
|
ON t.transaction_journal_id = tj.id
|
||||||
|
LEFT JOIN firefly.category_transaction_journal as ctj
|
||||||
|
ON tj.id = ctj.transaction_journal_id
|
||||||
|
LEFT JOIN firefly.categories AS c
|
||||||
|
ON c.id = ctj.category_id
|
||||||
|
LEFT JOIN firefly.accounts AS a
|
||||||
|
ON t.account_id = a.id
|
||||||
|
LEFT JOIN firefly.account_types AS aty
|
||||||
|
ON a.account_type_id = aty.id
|
||||||
|
WHERE TRUE
|
||||||
|
AND tj.DATE BETWEEN "${__from:date:iso}" AND "${__to:date:iso}"
|
||||||
|
AND a.id = 1
|
||||||
|
GROUP BY 1,2
|
||||||
|
ORDER BY 3 ASC
|
||||||
|
LIMIT 10
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Barchart with Budget difference stacked
|
||||||
|
*/
|
||||||
|
WITH calc_budget AS (
|
||||||
|
SELECT
|
||||||
|
c.name AS category_name
|
||||||
|
, ABS(SUM(t.amount)) AS current_status
|
||||||
|
, CASE
|
||||||
|
WHEN c.name = 'Lebensmittel' THEN ${budget_lebensmittel}
|
||||||
|
WHEN c.name = 'Unterhaltung: Ausgehen' THEN ${budget_unterhaltung_ausgehen}
|
||||||
|
WHEN c.name = 'Sonstiges' THEN ${budget_sonstiges}
|
||||||
|
WHEN c.name = 'Online Einkäufe' THEN ${budget_online_einkaeufe}
|
||||||
|
WHEN c.name = 'Wohnen: Möbel' THEN ${budget_wohnen_moebel}
|
||||||
|
WHEN c.name = 'Drogerie' THEN ${budget_drogerie}
|
||||||
|
ELSE 0
|
||||||
|
END AS budget
|
||||||
|
FROM firefly.transactions AS t
|
||||||
|
INNER JOIN firefly.transaction_journals AS tj
|
||||||
|
ON t.transaction_journal_id = tj.id
|
||||||
|
LEFT JOIN firefly.category_transaction_journal as ctj
|
||||||
|
ON tj.id = ctj.transaction_journal_id
|
||||||
|
LEFT JOIN firefly.categories AS c
|
||||||
|
ON c.id = ctj.category_id
|
||||||
|
LEFT JOIN firefly.accounts AS a
|
||||||
|
ON t.account_id = a.id
|
||||||
|
LEFT JOIN firefly.account_types AS aty
|
||||||
|
ON a.account_type_id = aty.id
|
||||||
|
WHERE TRUE
|
||||||
|
AND tj.DATE BETWEEN "${__from:date:iso}" AND "${__to:date:iso}"
|
||||||
|
AND a.id = 1
|
||||||
|
AND c.name != "Monatliche Einzahlung"
|
||||||
|
GROUP BY 1,3
|
||||||
|
ORDER BY 2 DESC
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
category_name
|
||||||
|
, current_status
|
||||||
|
, CASE
|
||||||
|
WHEN budget - current_status > 0 THEN budget - current_status
|
||||||
|
ELSE 0
|
||||||
|
END AS rest_budget
|
||||||
|
FROM calc_budget
|
||||||
|
WHERE TRUE
|
||||||
|
AND budget > 0
|
||||||
|
;
|
||||||
86
firefly_grafana/desc_table.txt
Normal file
86
firefly_grafana/desc_table.txt
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
DESC firefly.category_transaction_journal;
|
||||||
|
|
||||||
|
|
||||||
|
0:"id"
|
||||||
|
1:"category_id"
|
||||||
|
2:"transaction_journal_id"
|
||||||
|
|
||||||
|
firefly.transaction_journals
|
||||||
|
|
||||||
|
0:Array[20]
|
||||||
|
0:"id"
|
||||||
|
1:"created_at"
|
||||||
|
2:"updated_at"
|
||||||
|
3:"deleted_at"
|
||||||
|
4:"user_id"
|
||||||
|
5:"user_group_id"
|
||||||
|
6:"transaction_type_id"
|
||||||
|
7:"transaction_group_id"
|
||||||
|
8:"bill_id"
|
||||||
|
9:"transaction_currency_id"
|
||||||
|
10:"description"
|
||||||
|
11:"date"
|
||||||
|
12:"date_tz"
|
||||||
|
13:"interest_date"
|
||||||
|
14:"book_date"
|
||||||
|
15:"process_date"
|
||||||
|
16:"order"
|
||||||
|
17:"tag_count"
|
||||||
|
18:"encrypted"
|
||||||
|
19:"completed"
|
||||||
|
|
||||||
|
DESC firefly.transactions;
|
||||||
|
|
||||||
|
values:Array[6]
|
||||||
|
0:Array[18]
|
||||||
|
0:"id"
|
||||||
|
1:"created_at"
|
||||||
|
2:"updated_at"
|
||||||
|
3:"deleted_at"
|
||||||
|
4:"reconciled"
|
||||||
|
5:"account_id"
|
||||||
|
6:"transaction_journal_id"
|
||||||
|
7:"description"
|
||||||
|
8:"transaction_currency_id"
|
||||||
|
9:"amount"
|
||||||
|
10:"balance_before"
|
||||||
|
11:"balance_after"
|
||||||
|
12:"balance_dirty"
|
||||||
|
13:"foreign_amount"
|
||||||
|
14:"foreign_currency_id"
|
||||||
|
15:"identifier"
|
||||||
|
16:"native_amount"
|
||||||
|
17:"native_foreign_amount"
|
||||||
|
|
||||||
|
firefly.categories
|
||||||
|
|
||||||
|
values:Array[6]
|
||||||
|
0:Array[8]
|
||||||
|
0:"id"
|
||||||
|
1:"created_at"
|
||||||
|
2:"updated_at"
|
||||||
|
3:"deleted_at"
|
||||||
|
4:"user_id"
|
||||||
|
5:"user_group_id"
|
||||||
|
6:"name"
|
||||||
|
7:"encrypted"
|
||||||
|
|
||||||
|
|
||||||
|
firefly.accounts
|
||||||
|
|
||||||
|
values:Array[6]
|
||||||
|
0:Array[14]
|
||||||
|
0:"id"
|
||||||
|
1:"created_at"
|
||||||
|
2:"updated_at"
|
||||||
|
3:"deleted_at"
|
||||||
|
4:"user_id"
|
||||||
|
5:"user_group_id"
|
||||||
|
6:"account_type_id"
|
||||||
|
7:"name"
|
||||||
|
8:"virtual_balance"
|
||||||
|
9:"iban"
|
||||||
|
10:"active"
|
||||||
|
11:"encrypted"
|
||||||
|
12:"order"
|
||||||
|
13:"native_virtual_balance"
|
||||||
Reference in New Issue
Block a user