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:
parent
f9852f98f6
commit
463e7bdf0d
1 changed files with 16 additions and 2 deletions
|
|
@ -852,8 +852,22 @@ class BankImportTransaction extends CommonObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by score descending
|
// Sort by: 1) Amount difference (closer to transaction amount is better), 2) Score
|
||||||
usort($matches, function($a, $b) {
|
$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'];
|
return $b['match_score'] - $a['match_score'];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue