diff --git a/src/routes/settings.import.tsx b/src/routes/settings.import.tsx index cb0af55..68908fb 100644 --- a/src/routes/settings.import.tsx +++ b/src/routes/settings.import.tsx @@ -84,8 +84,25 @@ const toBool = (v: any) => { const toNum = (v: any) => { if (v === "" || v == null) return null; - const n = Number(String(v).replace(/[$,]/g, "")); - return isNaN(n) ? null : n; + if (typeof v === "number") return isNaN(v) ? null : v; + let s = String(v).trim(); + if (!s) return null; + // Accounting negatives: (123.45) → -123.45 + let negative = false; + if (/^\(.*\)$/.test(s)) { + negative = true; + s = s.slice(1, -1); + } + // Strip currency symbols, commas, spaces, and stray non-numeric chars (keep . and -) + s = s.replace(/[$£€¥,\s]/g, ""); + if (s.endsWith("-")) { + // trailing minus (e.g. "100-") + negative = true; + s = s.slice(0, -1); + } + const n = Number(s); + if (isNaN(n)) return null; + return negative ? -n : n; }; const toDate = (v: any): string | null => { @@ -567,9 +584,14 @@ const IMPORTERS: ImporterConfig[] = [ issuedate: "issue_date", date: "issue_date", invoicedate: "issue_date", billdate: "issue_date", duedate: "due_date", status: "status", - subtotal: "subtotal", tax: "tax", total: "total", amount: "total", invoicetotal: "total", grandtotal: "total", - amountpaid: "amount_paid", paid: "amount_paid", paidamount: "amount_paid", - notes: "notes", memo: "notes", description: "notes", + subtotal: "subtotal", subtot: "subtotal", sub: "subtotal", netamount: "subtotal", net: "subtotal", + tax: "tax", taxamount: "tax", salestax: "tax", vat: "tax", gst: "tax", + total: "total", amount: "total", invoicetotal: "total", grandtotal: "total", invoiceamount: "total", + totalamount: "total", totaldue: "total", amountdue: "total", balance: "total", balancedue: "total", + billed: "total", billedamount: "total", feesbilled: "total", chargesbilled: "total", + amountpaid: "amount_paid", paid: "amount_paid", paidamount: "amount_paid", paymentsreceived: "amount_paid", + payments: "amount_paid", feespaid: "amount_paid", totalpaid: "amount_paid", + notes: "notes", memo: "notes", description: "notes", comments: "notes", }, numeric: ["subtotal", "tax", "total", "amount_paid"], dateCols: ["issue_date", "due_date"],