From 30d58c375c6e7133be95d2549d9b8edfac303080 Mon Sep 17 00:00:00 2001 From: marcoitaloesp-ai Date: Tue, 16 Dec 2025 16:40:21 +0000 Subject: [PATCH] v1.43.10 - FIX: Drill-down incluindo categoria pai nas subcategorias --- CHANGELOG.md | 19 +++++++++++++++++++ VERSION | 2 +- .../Http/Controllers/Api/ReportController.php | 10 +++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f806fa..e6a4200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/VERSION b/VERSION index 53b7a1c..b073f13 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.43.9 +1.43.10 diff --git a/backend/app/Http/Controllers/Api/ReportController.php b/backend/app/Http/Controllers/Api/ReportController.php index b4437c9..ef8e067 100644 --- a/backend/app/Http/Controllers/Api/ReportController.php +++ b/backend/app/Http/Controllers/Api/ReportController.php @@ -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