diff --git a/MoneyMap/Pages/Receipts.cshtml b/MoneyMap/Pages/Receipts.cshtml
index 72f140d..0581eec 100644
--- a/MoneyMap/Pages/Receipts.cshtml
+++ b/MoneyMap/Pages/Receipts.cshtml
@@ -314,7 +314,7 @@
{
Showing recent transactions without receipts.
}
- Rows highlighted in green have matching amounts.
+ Rows highlighted in green have matching amounts (within ±2%). Only showing transactions within ±10% of receipt total.
diff --git a/MoneyMap/Pages/Receipts.cshtml.cs b/MoneyMap/Pages/Receipts.cshtml.cs
index f39f76f..211f5dd 100644
--- a/MoneyMap/Pages/Receipts.cshtml.cs
+++ b/MoneyMap/Pages/Receipts.cshtml.cs
@@ -294,6 +294,23 @@ namespace MoneyMap.Pages
.ToList();
}
+ // Filter by amount (±10% tolerance) if receipt has a total
+ if (receipt.Total.HasValue)
+ {
+ var receiptTotal = Math.Abs(receipt.Total.Value);
+ var tolerance = receiptTotal * 0.10m; // 10% tolerance
+ var minAmount = receiptTotal - tolerance;
+ var maxAmount = receiptTotal + tolerance;
+
+ candidates = candidates
+ .Where(t =>
+ {
+ var transactionAmount = Math.Abs(t.Amount);
+ return transactionAmount >= minAmount && transactionAmount <= maxAmount;
+ })
+ .ToList();
+ }
+
// Calculate match scores and mark close amount matches
var options = candidates.Select(t =>
{
@@ -308,12 +325,13 @@ namespace MoneyMap.Pages
IsAmountMatch = false
};
- // Check if amount matches within tolerance
+ // Check if amount matches within tighter tolerance for highlighting (±2%)
if (receipt.Total.HasValue)
{
var receiptTotal = Math.Abs(receipt.Total.Value);
var transactionAmount = Math.Abs(t.Amount);
- option.IsAmountMatch = Math.Abs(transactionAmount - receiptTotal) <= 0.10m;
+ var tightTolerance = receiptTotal * 0.02m; // 2% for green highlighting
+ option.IsAmountMatch = Math.Abs(transactionAmount - receiptTotal) <= tightTolerance;
}
return option;
diff --git a/MoneyMap/Services/ReceiptAutoMapper.cs b/MoneyMap/Services/ReceiptAutoMapper.cs
index ab558b8..883ea44 100644
--- a/MoneyMap/Services/ReceiptAutoMapper.cs
+++ b/MoneyMap/Services/ReceiptAutoMapper.cs
@@ -130,14 +130,20 @@ namespace MoneyMap.Services
// Get candidates
var candidates = await query.ToListAsync();
- // If we have a total amount, filter by amount match
+ // If we have a total amount, filter by amount match (±10% tolerance)
if (receipt.Total.HasValue)
{
- // Allow for slight variations in amount (e.g., due to rounding)
- // Match if transaction amount is within $0.10 of receipt total
var receiptTotal = Math.Abs(receipt.Total.Value);
+ var tolerance = receiptTotal * 0.10m; // 10% tolerance
+ var minAmount = receiptTotal - tolerance;
+ var maxAmount = receiptTotal + tolerance;
+
candidates = candidates
- .Where(t => Math.Abs(Math.Abs(t.Amount) - receiptTotal) <= 0.10m)
+ .Where(t =>
+ {
+ var transactionAmount = Math.Abs(t.Amount);
+ return transactionAmount >= minAmount && transactionAmount <= maxAmount;
+ })
.ToList();
}