diff --git a/src/pages/Categorias.tsx b/src/pages/Categorias.tsx index 100c068..8de5a58 100644 --- a/src/pages/Categorias.tsx +++ b/src/pages/Categorias.tsx @@ -6,6 +6,14 @@ import { getCategorySummary } from '@/services/transacaoService'; import { CategorySummary } from '@/types/financialTypes'; import { useToast } from "@/components/ui/use-toast"; import { Progress } from "@/components/ui/progress"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow +} from "@/components/ui/table"; const CategoriasPage = () => { const [categories, setCategories] = useState([]); @@ -41,6 +49,8 @@ const CategoriasPage = () => { currency: 'BRL', }).format(value); }; + + const totalGastos = categories.reduce((total, category) => total + category.valor, 0); return ( @@ -70,36 +80,78 @@ const CategoriasPage = () => { ) : ( -
- {categories.map((category) => ( - - - - - {category.categoria} - - - -
- {formatCurrency(category.valor)} -
-
- -
- {(category.percentage * 100).toFixed(1)}% do total de despesas + <> +
+ {categories.map((category) => ( + + + + + {category.categoria} + + + +
+ {formatCurrency(category.valor)}
-
- - - ))} -
+
+ +
+ {(category.percentage * 100).toFixed(1)}% do total de despesas +
+
+ + + ))} +
+ + + + Resumo de Categorias + + + + + + Categoria + Valor + Percentual + + + + {categories.map((category) => ( + + + + {category.categoria} + + {formatCurrency(category.valor)} + {(category.percentage * 100).toFixed(1)}% + + ))} + + Total + {formatCurrency(totalGastos)} + 100% + + +
+
+
+ )}
diff --git a/src/services/transacaoService.ts b/src/services/transacaoService.ts index ec4e5e6..89fec29 100644 --- a/src/services/transacaoService.ts +++ b/src/services/transacaoService.ts @@ -25,7 +25,7 @@ export async function getTransacoes(): Promise { quando: item.quando || new Date().toISOString(), detalhes: item.detalhes || '', estabelecimento: item.estabelecimento || '', - tipo: item.tipo || 'saida', + tipo: item.tipo || 'despesa', categoria: item.categoria || 'Outros' })); } @@ -79,10 +79,11 @@ export async function getCategorySummary() { const categorias: Record = {}; data.forEach(item => { if (item.categoria && item.valor) { - if (!categorias[item.categoria]) { - categorias[item.categoria] = 0; + const categoriaKey = item.categoria || 'Outros'; + if (!categorias[categoriaKey]) { + categorias[categoriaKey] = 0; } - categorias[item.categoria] += Math.abs(item.valor); + categorias[categoriaKey] += Math.abs(item.valor); } }); diff --git a/src/types/financialTypes.ts b/src/types/financialTypes.ts index 69f8f94..7d5af6a 100644 --- a/src/types/financialTypes.ts +++ b/src/types/financialTypes.ts @@ -7,7 +7,7 @@ export interface Transaction { quando: string; detalhes: string; estabelecimento: string; - tipo: 'entrada' | 'saida'; + tipo: string; categoria: string; }