Skip to content

Commit

Permalink
Payments Report: Add POS data columns
Browse files Browse the repository at this point in the history
Extends the payments report data with subtotal, tip and discount amounts. This works for keypad and cart sales. Closes btcpayserver#5290.
  • Loading branch information
dennisreimann committed Dec 29, 2023
1 parent c7eef01 commit 199bc22
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions BTCPayServer/Services/Reporting/PaymentsReportProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ ViewDefinition CreateViewDefinition()
new ("LightningAddress", "string"),
new ("Currency", "string"),
new ("CurrencyAmount", "amount"),
new ("Rate", "amount")
new ("Rate", "amount"),
new ("Subtotal", "amount"),
new ("Discount", "amount"),
new ("Tip", "amount")
},
Charts =
{
Expand Down Expand Up @@ -163,7 +166,7 @@ public override async Task Query(QueryContext queryContext, CancellationToken ca
values.Add(paymentType.CryptoCode);

var cryptoAmount = paymentData.GetValue();

var currency = invoiceBlob.Currency ?? "USD";
var divisibility = 8;
if (_btcPayNetworkProvider.TryGetNetwork<BTCPayNetwork>(paymentType.CryptoCode, out var network))
{
Expand All @@ -180,15 +183,22 @@ public override async Task Query(QueryContext queryContext, CancellationToken ca
values.Add(invoiceBlob.Currency);
if (invoiceBlob.Rates.TryGetValue(paymentType.CryptoCode, out var rate))
{
values.Add(DisplayFormatter.ToFormattedAmount(rate * cryptoAmount, invoiceBlob.Currency ?? "USD")); // Currency amount
values.Add(DisplayFormatter.ToFormattedAmount(rate, invoiceBlob.Currency ?? "USD"));
values.Add(DisplayFormatter.ToFormattedAmount(rate * cryptoAmount, currency)); // Currency amount
values.Add(DisplayFormatter.ToFormattedAmount(rate, currency));
}
else
{
values.Add(null);
values.Add(null);
}

var subtotal = invoiceBlob.Metadata.PosData.Value<decimal?>("subTotal");
values.Add(subtotal.HasValue ? DisplayFormatter.ToFormattedAmount(subtotal.Value, currency) : null);
var discount = invoiceBlob.Metadata.PosData.Value<decimal?>("discountAmount");
values.Add(discount.HasValue ? DisplayFormatter.ToFormattedAmount(discount.Value, currency) : null);
var tip = invoiceBlob.Metadata.PosData.Value<decimal?>("tip");
values.Add(tip.HasValue ? DisplayFormatter.ToFormattedAmount(tip.Value, currency) : null);

queryContext.Data.Add(values);
}
}
Expand Down

0 comments on commit 199bc22

Please sign in to comment.