FIX v1.43.8 - Corrigido agrupamento de subcategorias
A query padrão agora agrupa por categoria pai usando COALESCE(c.parent_id, c.id), somando as transações de todas as subcategorias. Antes: Transações em subcategorias (Supermercado, Restaurantes) não apareciam Agora: Alimentação mostra total de Supermercado + Restaurantes + todas subcategorias
This commit is contained in:
parent
7b9345dc80
commit
bdfcc8f60b
@ -23,8 +23,9 @@ Este projeto adota [Versionamento Semântico](https://semver.org/pt-BR/).
|
||||
### Changed
|
||||
- **Backend - API /reports/by-category**
|
||||
- Novo parâmetro `parent_id` para filtrar subcategorias
|
||||
- Query padrão agora mostra apenas categorias pai (`parent_id IS NULL`)
|
||||
- Query padrão agrupa por categoria pai, somando transações de todas as subcategorias
|
||||
- Query com `parent_id` filtra subcategorias da categoria especificada
|
||||
- **FIX**: Transações em subcategorias agora aparecem corretamente agrupadas na categoria pai
|
||||
|
||||
## [1.43.7] - 2025-12-16
|
||||
|
||||
|
||||
@ -198,25 +198,25 @@ public function byCategory(Request $request)
|
||||
ORDER BY total DESC
|
||||
", [$this->userId, $startDate, $endDate, $type]);
|
||||
} else {
|
||||
// Sin agrupar: solo categorías padre (sin parent_id)
|
||||
// Vista padrão: agrupar por categoria pai (soma transações de subcategorias)
|
||||
$data = DB::select("
|
||||
SELECT
|
||||
c.id as category_id,
|
||||
c.name as category_name,
|
||||
c.icon,
|
||||
c.color,
|
||||
COALESCE(c.parent_id, c.id) as category_id,
|
||||
COALESCE(cp.name, c.name) as category_name,
|
||||
COALESCE(cp.icon, c.icon) as icon,
|
||||
COALESCE(cp.color, c.color) as color,
|
||||
COALESCE(a.currency, 'EUR') as currency,
|
||||
SUM(ABS(t.amount)) as total
|
||||
FROM transactions t
|
||||
LEFT JOIN categories c ON t.category_id = c.id
|
||||
LEFT JOIN categories cp ON c.parent_id = cp.id
|
||||
LEFT JOIN accounts a ON t.account_id = a.id
|
||||
WHERE t.user_id = ?
|
||||
AND t.effective_date BETWEEN ? AND ?
|
||||
AND t.type = ?
|
||||
AND c.parent_id IS NULL
|
||||
AND t.deleted_at IS NULL
|
||||
AND {$this->excludeTransfers()}
|
||||
GROUP BY c.id, c.name, c.icon, c.color, COALESCE(a.currency, 'EUR')
|
||||
GROUP BY COALESCE(c.parent_id, c.id), COALESCE(cp.name, c.name), COALESCE(cp.icon, c.icon), COALESCE(cp.color, c.color), COALESCE(a.currency, 'EUR')
|
||||
ORDER BY total DESC
|
||||
", [$this->userId, $startDate, $endDate, $type]);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user