Statement import: read ING's Af Bij column for the direction of each amount
ING Netherlands exports every amount as positive and says Af (out) or Bij (in) in its own column. Without this, spending and income all came in as income. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b532bb8dd8
commit
fc0bf0a566
2 files changed
+18
-2
No files matched your search
@@ -5,7 +5,8 @@ export type Row = { date: string; amount: number; name: string; key: string; cat
|
||||
export type Table = { header: string[]; rows: string[][] };
|
||||
export type DateOrder = "dmy" | "mdy" | "ymd";
|
||||
// Column indexes; -1 = not used. A single signed amount, or separate debit (out) and credit (in) columns.
|
||||
export type Mapping = { date: number; name: number; amount: number; debit: number; credit: number; order: DateOrder; outPositive: boolean; category?: number };
|
||||
// sign: a column that says which way the money went, for banks whose amount is always positive (ING's "Af Bij").
|
||||
export type Mapping = { date: number; name: number; amount: number; debit: number; credit: number; order: DateOrder; outPositive: boolean; category?: number; sign?: number };
|
||||
export type Parsed = { kind: "csv"; table: Table; mapping: Mapping } | { kind: "ofx" | "qif"; rows: Row[] };
|
||||
|
||||
const MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
||||
@@ -143,7 +144,8 @@ export function guessMapping(t: Table, locale: string): Mapping {
|
||||
const debit = amount >= 0 ? -1 : find(h, [/withdrawal/, /debit/, /money out/, /paid out/, /^dr$/, /\bout\b/]);
|
||||
const credit = amount >= 0 ? -1 : find(h, [/deposit/, /credit/, /money in/, /paid in/, /^cr$/, /\bin\b/]);
|
||||
const category = find(h, [/^category$/, /categor/]);
|
||||
return { date, name, amount, debit, credit, order: dateOrder(date >= 0 ? col(date) : [], locale), outPositive: false, category };
|
||||
const sign = amount < 0 ? -1 : find(h, [/^af ?[/-]? ?bij$/, /^(debit|credit) ?[/-]? ?(credit|debit)$/, /^d ?[/-]? ?c$/, /^soll ?[/-]? ?haben$/]);
|
||||
return { date, name, amount, debit, credit, order: dateOrder(date >= 0 ? col(date) : [], locale), outPositive: false, category, ...(sign >= 0 && { sign }) };
|
||||
}
|
||||
|
||||
// Stable dedupe keys: the same date, amount and name gets 1, 2, 3... in file order, so re-importing adds nothing.
|
||||
@@ -167,6 +169,10 @@ export function applyMapping(t: Table, m: Mapping, locale: string): { rows: Row[
|
||||
const a = parseAmount(r[m.amount] ?? "", locale);
|
||||
// Most banks export money out as negative; the app stores it as positive.
|
||||
if (a !== null) amount = m.outPositive ? a : -a;
|
||||
// A direction column wins over the sign: "Af"/"Debit" is money out, "Bij"/"Credit" is money in.
|
||||
const way = (m.sign ?? -1) >= 0 ? (r[m.sign!] ?? "").trim().toLowerCase() : "";
|
||||
if (a !== null && /^(af|debit|d|dr|s|soll)$/.test(way)) amount = Math.abs(a);
|
||||
else if (a !== null && /^(bij|credit|c|cr|h|haben)$/.test(way)) amount = -Math.abs(a);
|
||||
} else {
|
||||
const dr = m.debit >= 0 ? parseAmount(r[m.debit] ?? "", locale) : null;
|
||||
const cr = m.credit >= 0 ? parseAmount(r[m.credit] ?? "", locale) : null;
|
||||
|
||||
Reference in new issue
Block a user