Receipts: highlight exact amount matches in green, close (±10%) in yellow; update legend and scroll target preference
This commit is contained in:
@@ -334,11 +334,11 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@{
|
||||
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;
|
||||
<tr class="@rowClass"
|
||||
id="@(isFirstMatch ? $"firstMatch{r.Id}" : "")"
|
||||
@@ -434,3 +434,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ namespace MoneyMap.Pages
|
||||
// Filter by amount (±10% tolerance) if receipt has a total
|
||||
if (receipt.Total.HasValue)
|
||||
{
|
||||
var receiptTotal = Math.Abs(receipt.Total.Value);
|
||||
var receiptTotal = Math.Round(Math.Abs(receipt.Total.Value), 2);
|
||||
var tolerance = receiptTotal * 0.10m; // 10% tolerance
|
||||
var minAmount = receiptTotal - tolerance;
|
||||
var maxAmount = receiptTotal + tolerance;
|
||||
@@ -338,7 +338,7 @@ namespace MoneyMap.Pages
|
||||
candidates = candidates
|
||||
.Where(t =>
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user