Przejdź do głównej zawartości

Pass 400: fuzzy

PoleWartosc
namefuzzy
order400
confidence80%

Pass laczy dwa kryteria:

  1. Rozmyte dopasowanie nazwy: fuzzball.ratio(invoice.sellerName, tx.senderName) >= 80
  2. Dokladna kwota: |tx.amount| === invoice.grossAmount

Oba warunki musza byc spelnione jednoczesnie.

fuzzball implementuje algorytm oparty na odleglosci Levenshteina. Funkcja ratio() zwraca wynik 0-100, gdzie 100 oznacza identyczne ciagi.

import { ratio } from 'fuzzball'
ratio('TECHSOLUTIONS SP Z OO', 'TECHSOLUTIONS SP. Z O.O.') // 85
ratio('FIRMA ABC', 'FIRMA ABC SP Z OO') // 67
ratio('JAN KOWALSKI', 'KOWALSKI JAN') // 74

Prog FUZZY_THRESHOLD = 80 zostal dobrany eksperymentalnie — lapie typowe roznice w pisowni nazw firm, jednoczesnie unikajac falszywych dopasowan.

import { ratio } from 'fuzzball'
const FUZZY_THRESHOLD = 80
const fuzzyPass: ReconciliationPass = {
name: 'fuzzy',
order: 400,
async run(context: MatchingContext): Promise<MatchResult[]> {
const results: MatchResult[] = []
const usedTxIds = new Set<string>()
for (const invoice of context.invoices) {
if (!invoice.sellerName) continue
for (const tx of context.transactions) {
if (usedTxIds.has(tx.id)) continue
if (Math.abs(tx.amount) !== invoice.grossAmount) continue
const txName = tx.senderName ?? tx.recipientName
if (!txName) continue
const score = ratio(invoice.sellerName, txName)
if (score >= FUZZY_THRESHOLD) {
results.push({
invoiceId: invoice.id,
transactionId: tx.id,
confidence: 80,
reasons: [
`Fuzzy name match: "${invoice.sellerName}" ~ "${txName}" (score: ${score})`,
`Exact amount match: ${Math.abs(tx.amount)} grosze`,
],
})
usedTxIds.add(tx.id)
break
}
}
}
return results
},
}
const invoice = {
id: 'inv-001',
invoiceNumber: 'FV/2026/03/077',
sellerNIP: '5213456784',
sellerName: 'TECHSOLUTIONS SP Z OO',
grossAmount: 369000, // 3 690,00 PLN
issueDate: '2026-03-01',
}
const transaction = {
id: 'tx-001',
date: '2026-03-14',
amount: -369000,
description: 'Zaplata za uslugi IT',
senderName: 'TECHSOLUTIONS SP. Z O.O.',
}
// fuzzball.ratio("TECHSOLUTIONS SP Z OO", "TECHSOLUTIONS SP. Z O.O.") = 85
// 85 >= 80 -> match!
// confidence: 80
SytuacjaFakturaPrzelew
Skrot formy prawnejSP Z OOSP. Z O.O.
Brak polskich znakowLODZKALODZKA
Dodatkowy suffixFIRMA ABCFIRMA ABC S.A.