From 463e7bdf0d6d63125e93a3d169ecf0341b0633ba Mon Sep 17 00:00:00 2001 From: data Date: Thu, 5 Mar 2026 10:54:43 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20Sortierung=20bevorzugt=20Matches=20mit?= =?UTF-8?q?=20n=C3=A4herem=20Betrag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- class/banktransaction.class.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/class/banktransaction.class.php b/class/banktransaction.class.php index a5814ac..96305a4 100755 --- a/class/banktransaction.class.php +++ b/class/banktransaction.class.php @@ -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']; });