Fix FinTS transaction deduplication
This commit is contained in:
@@ -14,6 +14,54 @@ export type FintsStatementTransaction = {
|
||||
customerReference?: string;
|
||||
};
|
||||
|
||||
const FINTS_EXTERNAL_REF_PLACEHOLDERS = new Set([
|
||||
"0",
|
||||
"00",
|
||||
"000",
|
||||
"0000",
|
||||
"00000",
|
||||
"000000",
|
||||
"0000000",
|
||||
"00000000",
|
||||
"000000000",
|
||||
"0000000000",
|
||||
"KEINE",
|
||||
"N/A",
|
||||
"NA",
|
||||
"NONE",
|
||||
"NONREF",
|
||||
"NOREF",
|
||||
"NOTPROVIDED",
|
||||
"NULL",
|
||||
"UNBEKANNT",
|
||||
]);
|
||||
|
||||
function normalizeFinTsExternalRefValue(value?: string): string | undefined {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed) return undefined;
|
||||
|
||||
const compact = trimmed.replace(/[\s_-]+/g, "").toUpperCase();
|
||||
if (
|
||||
!compact ||
|
||||
FINTS_EXTERNAL_REF_PLACEHOLDERS.has(compact) ||
|
||||
/^POS\d+$/.test(compact)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
export function normalizeFinTsExternalRef(
|
||||
bankReference?: string,
|
||||
customerReference?: string,
|
||||
): string | undefined {
|
||||
return (
|
||||
normalizeFinTsExternalRefValue(bankReference) ??
|
||||
normalizeFinTsExternalRefValue(customerReference)
|
||||
);
|
||||
}
|
||||
|
||||
export function formatFinTsDate(date: Date): string {
|
||||
const y = date.getFullYear();
|
||||
const m = String(date.getMonth() + 1).padStart(2, "0");
|
||||
@@ -55,7 +103,7 @@ export function mapFinTsTransaction(
|
||||
vorgang,
|
||||
isPending: false,
|
||||
rawText: rawText || undefined,
|
||||
externalRef: tx.bankReference || tx.customerReference || undefined,
|
||||
externalRef: normalizeFinTsExternalRef(tx.bankReference, tx.customerReference),
|
||||
categoryName,
|
||||
assignedMonth,
|
||||
effectiveMonth,
|
||||
|
||||
Reference in New Issue
Block a user