From 14f970f191eb2cab4a4650ace0b5506e97d4fb37 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 17 May 2025 23:51:21 +0000 Subject: [PATCH] Fix: Use transaction type for sign Updated `transacaoService.ts` to determine the sign of the transaction value based on the 'tipo' column instead of 'categoria'. --- src/components/dashboard/TransactionsTable.tsx | 4 ++-- src/services/transacaoService.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/dashboard/TransactionsTable.tsx b/src/components/dashboard/TransactionsTable.tsx index 1342e5b..55a35b1 100644 --- a/src/components/dashboard/TransactionsTable.tsx +++ b/src/components/dashboard/TransactionsTable.tsx @@ -111,10 +111,10 @@ const TransactionsTable = ({ setSearchQuery('')}> Todas - setSearchQuery('entrada')}> + setSearchQuery('receita')}> Receitas - setSearchQuery('saida')}> + setSearchQuery('despesa')}> Despesas diff --git a/src/services/transacaoService.ts b/src/services/transacaoService.ts index e738787..ec4e5e6 100644 --- a/src/services/transacaoService.ts +++ b/src/services/transacaoService.ts @@ -21,11 +21,11 @@ export async function getTransacoes(): Promise { id: item.id.toString(), user: item.user || '', created_at: item.created_at, - valor: item.tipo === 'entrada' ? Math.abs(item.valor || 0) : -Math.abs(item.valor || 0), + valor: item.tipo === 'receita' ? Math.abs(item.valor || 0) : -Math.abs(item.valor || 0), quando: item.quando || new Date().toISOString(), detalhes: item.detalhes || '', estabelecimento: item.estabelecimento || '', - tipo: (item.tipo === 'entrada' || item.tipo === 'saida') ? item.tipo : 'saida', + tipo: item.tipo || 'saida', categoria: item.categoria || 'Outros' })); } @@ -44,11 +44,11 @@ export async function getTransactionSummary() { console.log("Dados para resumo encontrados:", data); const totalReceitas = data - .filter(item => item.tipo === 'entrada') + .filter(item => item.tipo === 'receita') .reduce((sum, item) => sum + Math.abs(item.valor || 0), 0); const totalDespesas = data - .filter(item => item.tipo === 'saida') + .filter(item => item.tipo === 'despesa') .reduce((sum, item) => sum + Math.abs(item.valor || 0), 0); const resultado = { @@ -66,7 +66,7 @@ export async function getCategorySummary() { const { data, error } = await supabase .from('transacoes') .select('categoria, valor, tipo') - .eq('tipo', 'saida'); + .eq('tipo', 'despesa'); if (error) { console.error('Erro ao buscar resumo de categorias:', error); @@ -132,7 +132,7 @@ export async function getMonthlyData() { const mesIndex = data.getMonth(); const nomeMes = nomesMeses[mesIndex]; - if (item.tipo === 'entrada') { + if (item.tipo === 'receita') { meses[nomeMes].receitas += Math.abs(item.valor); } else { meses[nomeMes].despesas += Math.abs(item.valor);