fix: Sortierung bevorzugt Matches mit näherem Betrag

Matches die innerhalb von 10% des Transaktionsbetrags liegen
werden jetzt vor Matches mit größerer Abweichung angezeigt.

Bei 523€ Transaktion:
- Multi-Match 529€ (Diff 6€) → wird bevorzugt
- Einzelmatch 60€ (Diff 463€) → kommt danach

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Eduard Wisch 2026-03-05 10:54:43 +01:00
parent f9852f98f6
commit 463e7bdf0d

View file

@ -852,8 +852,22 @@ class BankImportTransaction extends CommonObject
}
}
// Sort by score descending
usort($matches, function($a, $b) {
// Sort by: 1) Amount difference (closer to transaction amount is better), 2) Score
$absAmount = abs($this->amount);
usort($matches, function($a, $b) use ($absAmount) {
$diffA = abs($a['amount'] - $absAmount);
$diffB = abs($b['amount'] - $absAmount);
// If one match is much closer in amount (within 10% of transaction), prefer it
$threshold = $absAmount * 0.10;
if ($diffA < $threshold && $diffB >= $threshold) {
return -1; // A is better (closer amount)
}
if ($diffB < $threshold && $diffA >= $threshold) {
return 1; // B is better (closer amount)
}
// Otherwise sort by score
return $b['match_score'] - $a['match_score'];
});