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:
MangaValkandClaude Opus 5.5 committed 2026-11-19 16:40:42 +01:00
1 parent 0232766260
commit 33a8a237ea
4 files changed
+42 -3

No files matched your search

+16
View File
@@ -156,3 +156,19 @@ console.log("statement ok");
`, "nl-NL");
assert.deepEqual(brief(c.rows), [["2026-11-14", 42.17, "Albert Heijn 1234"], ["2026-11-13", -2500, "Werkgever BV"], ["2026-11-12", 13.99, "Netflix"]]);
}
// ABN AMRO TXT/TAB download: no header, tab separated, signed amounts, coded descriptions.
{
const c = csv([
"123456789\tEUR\t20261114\t2000,00\t1957,83\t20261114\t-42,17\tBEA, Apple Pay ALBERT HEIJN 1234,PAS123 NR:ABC123, 14.11.26/18:02 AMSTERDAM",
"123456789\tEUR\t20261113\t-500,00\t2000,00\t20261113\t2500,00\t/TRTP/SEPA OVERBOEKING/IBAN/NL00RABO0123456789/BIC/RABONL2U/NAME/Werkgever BV/REMI/Salaris november/EREF/NOTPROVIDED",
"123456789\tEUR\t20261112\t-486,01\t-500,00\t20261112\t-13,99\tSEPA Incasso algemeen doorlopend Incassant: NL00ZZZ000000000000 Naam: Netflix International B.V. Machtiging: 123 Omschrijving: Netflix",
"123456789\tEUR\t20261111\t-436,01\t-486,01\t20261111\t-50,00\tGEA NR:XX123 11.11.26/10.15 ABN AMRO BANK NV,PAS123",
].join("\n") + "\n", "nl-NL");
assert.deepEqual(brief(c.rows), [
["2026-11-14", 42.17, "ALBERT HEIJN 1234"],
["2026-11-13", -2500, "Werkgever BV"],
["2026-11-12", 13.99, "Netflix International B.V."],
["2026-11-11", 50, "ABN AMRO BANK NV"],
]);
}
+23 -1
View File
@@ -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() : "";