Skip to content

Commit

Permalink
Do not include templates in expense grouping listings and sum
Browse files Browse the repository at this point in the history
  • Loading branch information
thaapasa committed Mar 10, 2024
1 parent 6e2effd commit d31bbb7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/server/data/grouping/GroupingDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ const EXPENSE_SUM_SUBSELECT = /*sql*/ `
SELECT SUM(CASE e.type WHEN 'expense' THEN sum WHEN 'income' THEN -sum ELSE 0 END)
FROM expenses e
LEFT JOIN categories cat ON (cat.id = e.category_id)
WHERE e.grouping_id = data.id
OR (
e.grouping_id IS NULL
AND (cat.id = ANY(data.categories) OR cat.parent_id = ANY(data.categories))
AND (data."startDate" IS NULL OR e.date >= data."startDate")
AND (data."endDate" IS NULL OR e.date <= data."endDate")
AND (data."onlyOwn" IS FALSE OR e.user_id = $/userId/)
WHERE e.template IS FALSE
AND (e.grouping_id = data.id
OR (
e.grouping_id IS NULL
AND (cat.id = ANY(data.categories) OR cat.parent_id = ANY(data.categories))
AND (data."startDate" IS NULL OR e.date >= data."startDate")
AND (data."endDate" IS NULL OR e.date <= data."endDate")
AND (data."onlyOwn" IS FALSE OR e.user_id = $/userId/)
)
)
`;

Expand All @@ -42,6 +44,7 @@ const EXPENSE_JOIN_TO_GROUPING = /*sql*/ `
(e.grouping_id IS NULL AND eg.id = $/groupingId/)
OR (e.grouping_id = $/groupingId/)
)
AND e.template IS FALSE
`;

export async function getExpenseGroupingsForUser(
Expand Down

0 comments on commit d31bbb7

Please sign in to comment.