Pass 400: fuzzy
Parametry
Dział zatytułowany „Parametry”| Pole | Wartosc |
|---|---|
| name | fuzzy |
| order | 400 |
| confidence | 80% |
Strategia
Dział zatytułowany „Strategia”Pass laczy dwa kryteria:
- Rozmyte dopasowanie nazwy:
fuzzball.ratio(invoice.sellerName, tx.senderName) >= 80 - Dokladna kwota:
|tx.amount| === invoice.grossAmount
Oba warunki musza byc spelnione jednoczesnie.
Biblioteka fuzzball
Dział zatytułowany „Biblioteka fuzzball”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.') // 85ratio('FIRMA ABC', 'FIRMA ABC SP Z OO') // 67ratio('JAN KOWALSKI', 'KOWALSKI JAN') // 74Prog FUZZY_THRESHOLD = 80 zostal dobrany eksperymentalnie — lapie typowe roznice w pisowni nazw firm, jednoczesnie unikajac falszywych dopasowan.
Kod zrodlowy
Dział zatytułowany „Kod zrodlowy”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 },}Przyklad
Dział zatytułowany „Przyklad”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: 80Kiedy przydatne
Dział zatytułowany „Kiedy przydatne”| Sytuacja | Faktura | Przelew |
|---|---|---|
| Skrot formy prawnej | SP Z OO | SP. Z O.O. |
| Brak polskich znakow | LODZKA | LODZKA |
| Dodatkowy suffix | FIRMA ABC | FIRMA ABC S.A. |