v1.43.10 - FIX: Drill-down incluindo categoria pai nas subcategorias

This commit is contained in:
marcoitaloesp-ai 2025-12-16 16:40:21 +00:00 committed by GitHub
parent bb06ca8fae
commit 30d58c375c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 6 deletions

View File

@ -5,6 +5,25 @@ O formato segue [Keep a Changelog](https://keepachangelog.com/pt-BR/).
Este projeto adota [Versionamento Semântico](https://semver.org/pt-BR/).
## [1.43.10] - 2025-12-16
### Fixed
- **Relatórios - Drill-down de Categorias e Centros de Custo**
- **FIX CRÍTICO**: Ao clicar em uma categoria/centro pai, a soma das subcategorias não batia com o total
- Problema: Query do nível 3 filtrava apenas `c.parent_id = ?`, excluindo transações da categoria pai
- Exemplo: "Vaper/Tabaco" mostrava 784,68€ (correto), mas subcategorias somavam 297,33€
- Causa: 487,35€ estavam na própria categoria pai, não nas subcategorias
- Solução: Query agora usa `(c.id = ? OR c.parent_id = ?)` para incluir categoria pai e subcategorias
- Aplicado em:
* `/api/reports/by-category` (parâmetro `parent_id`)
* `/api/reports/by-cost-center` (parâmetros `cost_center_id` + `category_id`)
- Agora mostra corretamente:
* Categoria pai: 487,35€
* Subcategoria 1: 240,45€
* Subcategoria 2: 44,20€
* Subcategoria 3: 12,68€
* **Total: 784,68€** ✅
## [1.43.9] - 2025-12-16
### Added

View File

@ -1 +1 @@
1.43.9
1.43.10

View File

@ -168,12 +168,12 @@ public function byCategory(Request $request)
WHERE t.user_id = ?
AND t.effective_date BETWEEN ? AND ?
AND t.type = ?
AND c.parent_id = ?
AND (c.id = ? OR c.parent_id = ?)
AND t.deleted_at IS NULL
AND {$this->excludeTransfers()}
GROUP BY c.id, c.name, c.icon, c.color, COALESCE(a.currency, 'EUR')
ORDER BY total DESC
", [$this->userId, $startDate, $endDate, $type, $parentId]);
", [$this->userId, $startDate, $endDate, $type, $parentId, $parentId]);
}
// Si se quiere agrupar por categoría padre, obtenemos el nombre del padre
else if ($groupByParent) {
@ -286,14 +286,14 @@ public function byCostCenter(Request $request)
WHERE t.user_id = ?
AND t.effective_date BETWEEN ? AND ?
AND " . ($costCenterId == 0 ? "t.cost_center_id IS NULL" : "t.cost_center_id = ?") . "
AND c.parent_id = ?
AND (c.id = ? OR c.parent_id = ?)
AND t.deleted_at IS NULL
AND {$this->excludeTransfers()}
GROUP BY c.id, c.name, c.icon, c.color, COALESCE(a.currency, 'EUR')
ORDER BY expense DESC
", $costCenterId == 0
? [$this->userId, $startDate, $endDate, $categoryId]
: [$this->userId, $startDate, $endDate, $costCenterId, $categoryId]
? [$this->userId, $startDate, $endDate, $categoryId, $categoryId]
: [$this->userId, $startDate, $endDate, $costCenterId, $categoryId, $categoryId]
);
}
// Nível 2: Categorias pai de um centro de custo específico