Fix: Dashboard pie chart missing categories
Corrected the category filtering in the dashboard pie chart to include 'despesas' and 'serviços'.
This commit is contained in:
parent
b1e48398c2
commit
1d1135cbe4
@ -164,18 +164,29 @@ export async function getCategorySummary(tipo: string = 'despesa'): Promise<Cate
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`📋 [getCategorySummary] Dados recebidos:`, data.map(d => ({ categoria: d.categoria, valor: d.valor, tipo: d.tipo })));
|
||||||
|
|
||||||
// Group by category and sum values
|
// Group by category and sum values
|
||||||
const categoryMap: { [key: string]: number } = {};
|
const categoryMap: { [key: string]: number } = {};
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
data.forEach((transaction) => {
|
data.forEach((transaction) => {
|
||||||
const categoria = transaction.categoria || 'Outros';
|
// Usar a categoria exata ou 'Outros' se for null/undefined/vazia
|
||||||
|
const categoria = transaction.categoria && transaction.categoria.trim() !== ''
|
||||||
|
? transaction.categoria.trim()
|
||||||
|
: 'Outros';
|
||||||
|
|
||||||
const valor = Math.abs(Number(transaction.valor || 0));
|
const valor = Math.abs(Number(transaction.valor || 0));
|
||||||
|
|
||||||
|
console.log(`📋 [getCategorySummary] Processando: categoria='${categoria}', valor=${valor}`);
|
||||||
|
|
||||||
categoryMap[categoria] = (categoryMap[categoria] || 0) + valor;
|
categoryMap[categoria] = (categoryMap[categoria] || 0) + valor;
|
||||||
total += valor;
|
total += valor;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`📋 [getCategorySummary] Mapeamento final de categorias:`, categoryMap);
|
||||||
|
console.log(`📋 [getCategorySummary] Total geral: ${total}`);
|
||||||
|
|
||||||
// Enhanced color palette with more distinct colors - avoiding white/light colors
|
// Enhanced color palette with more distinct colors - avoiding white/light colors
|
||||||
const colors = [
|
const colors = [
|
||||||
'#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7',
|
'#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7',
|
||||||
@ -196,7 +207,7 @@ export async function getCategorySummary(tipo: string = 'despesa'): Promise<Cate
|
|||||||
}))
|
}))
|
||||||
.sort((a, b) => b.valor - a.valor);
|
.sort((a, b) => b.valor - a.valor);
|
||||||
|
|
||||||
console.log(`📋 [getCategorySummary] ${categoryArray.length} categorias processadas`);
|
console.log(`📋 [getCategorySummary] ${categoryArray.length} categorias processadas:`, categoryArray);
|
||||||
return categoryArray;
|
return categoryArray;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('💥 [getCategorySummary] Erro geral:', error);
|
console.error('💥 [getCategorySummary] Erro geral:', error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user