From c7089dba989f775afec50b98bb3462bf14ef7b07 Mon Sep 17 00:00:00 2001 From: AJ Date: Sun, 12 Oct 2025 19:17:16 -0400 Subject: [PATCH] =?UTF-8?q?Filter=20transactions=20by=20=C2=B110%=20amount?= =?UTF-8?q?=20tolerance=20for=20receipt=20mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed amount matching from a fixed ±$0.10 tolerance to a percentage-based ±10% tolerance. This dramatically narrows down the transaction list for manual mapping, often to just 1-2 transactions. Changes: - Manual mapping: Filters candidates to ±10% of receipt total - Manual mapping: Green highlighting for very close matches (±2%) - Auto-mapping: Uses same ±10% tolerance for filtering - UI: Updated help text to explain the filtering Example: A $100 receipt will only show transactions between $90-$110, making it much easier to find the correct match. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- MoneyMap/Pages/Receipts.cshtml | 2 +- MoneyMap/Pages/Receipts.cshtml.cs | 22 ++++++++++++++++++++-- MoneyMap/Services/ReceiptAutoMapper.cs | 14 ++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) 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(); }