feat(analytics): replace budget page with spending analytics + split-adjusted amounts

- Rename 'Budget' → 'Analytics' in sidebar
- Rewrite /budget page: summary cards, recharts bar charts (monthly trend + category breakdown), 6-month trend table
- Fix analytics API to count only user's share for split transactions (CASE WHEN ts.share_percent IS NOT NULL THEN amount * share_percent / 100 ELSE amount END)
- Install recharts
This commit is contained in:
2026-03-08 17:58:33 +11:00
parent 1e79ada6d8
commit 30a7857d13
5 changed files with 646 additions and 272 deletions
+7 -1
View File
@@ -25,10 +25,16 @@ export async function GET(req: NextRequest) {
`SELECT
TO_CHAR(DATE_TRUNC('month', t.transaction_date::date), 'YYYY-MM') as month,
COALESCE(o.category_override, t.category) as category,
SUM(t.amount)::numeric(12,2) as total_spent,
SUM(
CASE
WHEN ts.share_percent IS NOT NULL THEN t.amount * ts.share_percent / 100
ELSE t.amount
END
)::numeric(12,2) as total_spent,
COUNT(*)::int as transaction_count
FROM transactions t
LEFT JOIN transaction_overrides o ON o.transaction_id = t.id
LEFT JOIN transaction_splits ts ON ts.transaction_id = t.id AND ts.participant_id = $1
JOIN statements s ON s.id = t.statement_id
WHERE s.owner_id = $1
AND t.transaction_type = 'debit'