feat: mapeamento automatico de categoria na importacao de planilhas

This commit is contained in:
Yuri Argolo
2026-06-13 15:54:27 -03:00
committed by Felipe Coutinho
parent 2fd6e3c323
commit 558197e870
3 changed files with 19 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ export type ImportedTransaction = {
amount: number; // positivo = receita, negativo = despesa
description: string; // MEMO ou NAME
transactionType: "income" | "expense";
categoryRaw?: string | null;
};
export type ImportStatement = {

View File

@@ -99,6 +99,7 @@ export async function parseXls(buffer: ArrayBuffer): Promise<ImportStatement> {
const typeRaw =
values[4] != null ? String(values[4]).toLowerCase().trim() : "";
const transactionType = typeRaw === "receita" ? "income" : "expense";
const categoryRaw = values[5] != null ? String(values[5]).trim() : null;
if (!date || !description || amount === null || amount <= 0) return;
@@ -108,6 +109,7 @@ export async function parseXls(buffer: ArrayBuffer): Promise<ImportStatement> {
amount,
description,
transactionType,
categoryRaw,
});
});
@@ -132,16 +134,17 @@ export async function generateXlsTemplate(): Promise<ArrayBuffer> {
const ws = workbook.addWorksheet("Lançamentos");
ws.addRows([
["Data", "Descrição", "Valor", "Tipo"],
["01/03/2026", "Ingressos São Januário", 160, "despesa"],
["01/03/2026", "Salário", 3000.0, "receita"],
["01/03/2026", "Posto do Vasco da Gama", 89.9, "despesa"],
["Data", "Descrição", "Valor", "Tipo", "Categoria"],
["01/03/2026", "Ingressos São Januário", 160, "despesa", "Lazer"],
["01/03/2026", "Salário", 3000.0, "receita", "Salário"],
["01/03/2026", "Posto do Vasco da Gama", 89.9, "despesa", "Transporte"],
]);
ws.getColumn(1).width = 14;
ws.getColumn(2).width = 32;
ws.getColumn(3).width = 12;
ws.getColumn(4).width = 10;
ws.getColumn(5).width = 24;
// Dropdown para coluna Tipo (D2:D100)
for (let i = 2; i <= 100; i++) {