From c31e88f07cc3c1af68a44634da18f07df4d785fa Mon Sep 17 00:00:00 2001 From: AJ Date: Sun, 19 Oct 2025 01:03:26 -0400 Subject: [PATCH] =?UTF-8?q?Receipts:=20highlight=20exact=20amount=20matche?= =?UTF-8?q?s=20in=20green,=20close=20(=C2=B110%)=20in=20yellow;=20update?= =?UTF-8?q?=20legend=20and=20scroll=20target=20preference?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MoneyMap/Pages/Receipts.cshtml | 5 +++-- MoneyMap/Pages/Receipts.cshtml.cs | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/MoneyMap/Pages/Receipts.cshtml b/MoneyMap/Pages/Receipts.cshtml index 41e9e6a..64921b6 100644 --- a/MoneyMap/Pages/Receipts.cshtml +++ b/MoneyMap/Pages/Receipts.cshtml @@ -334,11 +334,11 @@ @{ - var firstMatchId = matches.FirstOrDefault(t => t.IsAmountMatch)?.Id; + var firstMatchId = matches.FirstOrDefault(t => t.IsExactAmount)?.Id ?? matches.FirstOrDefault(t => t.IsCloseAmount)?.Id; } @foreach (var txn in matches) { - var rowClass = txn.IsAmountMatch ? "table-success" : ""; + var rowClass = txn.IsExactAmount ? "table-success" : (txn.IsCloseAmount ? "table-warning" : ""); var isFirstMatch = txn.Id == firstMatchId; { - var transactionAmount = Math.Abs(t.Amount); + var transactionAmount = Math.Round(Math.Abs(t.Amount), 2); return transactionAmount >= minAmount && transactionAmount <= maxAmount; }) .ToList(); @@ -355,16 +355,18 @@ namespace MoneyMap.Pages Amount = t.Amount, MerchantName = t.Merchant?.Name, PaymentMethod = t.PaymentMethodLabel, - IsAmountMatch = false + IsExactAmount = false, + IsCloseAmount = false }; - // Check if amount matches within tighter tolerance for highlighting (±2%) + // Amount matching flags if (receipt.Total.HasValue) { - var receiptTotal = Math.Abs(receipt.Total.Value); - var transactionAmount = Math.Abs(t.Amount); - var tightTolerance = receiptTotal * 0.02m; // 2% for green highlighting - option.IsAmountMatch = Math.Abs(transactionAmount - receiptTotal) <= tightTolerance; + var receiptTotal = Math.Round(Math.Abs(receipt.Total.Value), 2); + var transactionAmount = Math.Round(Math.Abs(t.Amount), 2); + option.IsExactAmount = transactionAmount == receiptTotal; + var tolerance = receiptTotal * 0.10m; + option.IsCloseAmount = !option.IsExactAmount && Math.Abs(transactionAmount - receiptTotal) <= tolerance; } return option; @@ -424,8 +426,12 @@ namespace MoneyMap.Pages public decimal Amount { get; set; } public string? MerchantName { get; set; } public string PaymentMethod { get; set; } = ""; - public bool IsAmountMatch { get; set; } + public bool IsExactAmount { get; set; } + public bool IsCloseAmount { get; set; } } } } + + +