Only show last month's overflow
This commit is contained in:
@ -30,14 +30,27 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
||||
WHERE categories.id = t_hist.category_id AND t_hist.date < @to_date
|
||||
), 0)
|
||||
)::decimal(12,2) as available,
|
||||
(
|
||||
COALESCE((
|
||||
( COALESCE((
|
||||
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||
WHERE categories.id = a_hist.category_id AND a_hist.date < @from_date
|
||||
), 0)+COALESCE((
|
||||
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||
WHERE categories.id = t_hist.category_id AND t_hist.date < @from_date
|
||||
), 0)
|
||||
), 0)-CASE WHEN (COALESCE((
|
||||
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||
WHERE categories.id = a_hist.category_id AND a_hist.date < @prev_from_date
|
||||
), 0)+COALESCE((
|
||||
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||
WHERE categories.id = t_hist.category_id AND t_hist.date < @prev_from_date
|
||||
), 0)) < 0 THEN (COALESCE((
|
||||
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||
WHERE categories.id = a_hist.category_id AND a_hist.date < @prev_from_date
|
||||
), 0)+COALESCE((
|
||||
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||
WHERE categories.id = t_hist.category_id AND t_hist.date < @prev_from_date
|
||||
), 0)) ELSE 0 END
|
||||
|
||||
|
||||
)::decimal(12,2) as available_last_month,
|
||||
COALESCE((
|
||||
SELECT SUM(t_this.amount) FROM transactions t_this
|
||||
|
Reference in New Issue
Block a user