Statement import: ABN AMRO's TXT/TAB download
It has no header row, so nothing came in. Recognize its eight columns, and take the other party's name out of ABN's coded text (/NAME/, card payments, Naam:). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0232766260
commit
33a8a237ea
4 files changed
+42
-3
No files matched your search
+23
-1
@@ -133,9 +133,15 @@ const find = (header: string[], tests: RegExp[], skip: RegExp = /$^/) => {
|
||||
return -1;
|
||||
};
|
||||
|
||||
// ABN AMRO's TXT/TAB download has no header: account, currency, date, opening balance, closing balance, value date,
|
||||
// signed amount, description. Two of the other columns are amounts too, so it can't be guessed from the values.
|
||||
const isAbnAmro = (t: Table, col: (i: number) => string[]) =>
|
||||
t.header.length === 8 && t.header[0] === "Column 1" && col(1).every((v) => /^[A-Z]{3}$/.test(v)) && col(2).every((v) => /^\d{8}$/.test(v));
|
||||
|
||||
export function guessMapping(t: Table, locale: string): Mapping {
|
||||
const h = t.header.map((x) => x.toLowerCase().trim());
|
||||
const col = (i: number) => t.rows.slice(0, 50).map((r) => r[i] ?? "");
|
||||
if (isAbnAmro(t, col)) return { date: 2, name: 7, amount: 6, debit: -1, credit: -1, order: "ymd", outPositive: false, category: -1 };
|
||||
let date = find(h, [/^(transaction |txn |posted |posting )?date$/, /date/], /value|process|created/);
|
||||
if (date < 0) date = h.findIndex((_, i) => col(i).filter(looksDate).length > col(i).length / 2);
|
||||
let name = find(h, [/payee/, /counter ?party/, /^name$/, /^details$/, /narration/, /description/, /merchant/, /memo/, /particulars/, /reference/]);
|
||||
@@ -159,6 +165,22 @@ export function withKeys(rows: Omit<Row, "key">[], ids?: (string | undefined)[])
|
||||
});
|
||||
}
|
||||
|
||||
// Dutch banks (ABN AMRO above all) pack the other party's name into coded text. Pull the name out; any other text
|
||||
// stays as the bank wrote it.
|
||||
export function cleanName(raw: string) {
|
||||
const s = raw.replace(/\s+/g, " ").trim();
|
||||
// SEPA transfer or direct debit: /TRTP/SEPA OVERBOEKING/IBAN/.../NAME/Werkgever BV/REMI/...
|
||||
const sepa = s.match(/\/NAME\/([^/]+)/);
|
||||
if (sepa) return sepa[1].trim();
|
||||
// Card payment or cash: "BEA, Apple Pay ALBERT HEIJN 1234,PAS123 NR:..." or "BEA NR:XX 14.11.26/18.02 ALBERT HEIJN,PAS123"
|
||||
const card = s.match(/^(?:BEA|GEA|eCom)\b[,:]?\s*(?:(?:Apple|Google) Pay|Betaalpas)?\s*(.+?),\s*PAS\d+/i);
|
||||
if (card) return card[1].replace(/^NR:\S+\s+\d{2}\.\d{2}\.\d{2}\/\d{2}[.:]\d{2}\s+/, "").trim();
|
||||
// Older SEPA text: "SEPA Incasso ... Naam: Netflix International B.V. Machtiging: ..."
|
||||
const naam = s.match(/\bNaam:\s*(.+?)(?=\s+(?:Machtiging|Omschrijving|IBAN|Kenmerk|BIC|Incassant|Betalingskenm\.?)[:\s]|$)/i);
|
||||
if (naam) return naam[1].trim();
|
||||
return s;
|
||||
}
|
||||
|
||||
export function applyMapping(t: Table, m: Mapping, locale: string): { rows: Row[]; skipped: number } {
|
||||
const out: Omit<Row, "key">[] = [];
|
||||
let skipped = 0;
|
||||
@@ -178,7 +200,7 @@ export function applyMapping(t: Table, m: Mapping, locale: string): { rows: Row[
|
||||
const cr = m.credit >= 0 ? parseAmount(r[m.credit] ?? "", locale) : null;
|
||||
if (dr !== null || cr !== null) amount = Math.abs(dr ?? 0) - Math.abs(cr ?? 0);
|
||||
}
|
||||
const name = (m.name >= 0 ? r[m.name] ?? "" : "").replace(/\s+/g, " ").trim();
|
||||
const name = cleanName(m.name >= 0 ? r[m.name] ?? "" : "");
|
||||
if (!date || amount === null || !amount) skipped++;
|
||||
else {
|
||||
const category = (m.category ?? -1) >= 0 ? (r[m.category!] ?? "").trim() : "";
|
||||
|
||||
Reference in new issue
Block a user