From e1a01cab91f11ded07e5ffc9c74ea1905763e6ba Mon Sep 17 00:00:00 2001 From: marcoitaloesp-ai Date: Tue, 16 Dec 2025 20:13:32 +0000 Subject: [PATCH] =?UTF-8?q?v1.43.21=20-=20FIX=20CR=C3=8DTICO:=20Inst=C3=A2?= =?UTF-8?q?ncias=20de=20recorr=C3=AAncias=20vencidas=20na=20proje=C3=A7?= =?UTF-8?q?=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 10 +++++++ VERSION | 2 +- .../Http/Controllers/Api/ReportController.php | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b49656..92cb2f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ O formato segue [Keep a Changelog](https://keepachangelog.com/pt-BR/). Este projeto adota [Versionamento Semântico](https://semver.org/pt-BR/). +## [1.43.21] - 2025-12-16 + +### Fixed +- **Projeção de Saldo - Instâncias de Recorrências Vencidas** + - FIX CRÍTICO: Projeção agora inclui instâncias de recorrências pendentes vencidas + - Exemplo: "Aluguel" (1003,59€, vencida há 15 dias) e "Compra Bizum Asenergy" (94,22€, vencida há 29 dias) + - Query adicional para `recurring_instances` com `status='pending'` e `due_date < hoje` + - Separa receitas e despesas vencidas corretamente + - Valores agora aparecem em `overdue.income` e `overdue.expense` + ## [1.43.20] - 2025-12-16 ### Fixed diff --git a/VERSION b/VERSION index a07ddf0..15a0f2a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.43.20 +1.43.21 diff --git a/backend/app/Http/Controllers/Api/ReportController.php b/backend/app/Http/Controllers/Api/ReportController.php index cbfbfd0..41bedc1 100644 --- a/backend/app/Http/Controllers/Api/ReportController.php +++ b/backend/app/Http/Controllers/Api/ReportController.php @@ -966,6 +966,32 @@ public function projection(Request $request) $overdueExpense += $this->convertToPrimaryCurrency($rec['amount'], $rec['currency']); } + // Instâncias de recorrências pendentes vencidas + $overdueRecurringInstances = DB::select(" + SELECT + ri.planned_amount as amount, + rt.type, + COALESCE(a.currency, 'EUR') as currency + FROM recurring_instances ri + JOIN recurring_templates rt ON ri.recurring_template_id = rt.id + LEFT JOIN accounts a ON rt.account_id = a.id + WHERE ri.user_id = ? + AND ri.status = 'pending' + AND ri.due_date < ? + AND ri.deleted_at IS NULL + ", [$this->userId, $today]); + + foreach ($overdueRecurringInstances as $row) { + $amount = abs($row->amount); + $converted = $this->convertToPrimaryCurrency($amount, $row->currency); + + if ($row->type === 'credit') { + $overdueIncome += $converted; + } else { + $overdueExpense += $converted; + } + } + // ========================================================================= // 6. TRANSAÇÕES PENDENTES ATÉ O FIM DO MÊS (planned_date entre hoje e fim do mês) // =========================================================================