Dashboard: Show revenue data for keypad (#5317)

* POS: Display fixes

* Dashboard: Fix Top Items component

* Dashboard: Fix App Sales component

* Dashboard: Show revenue data for keypad

Closes #5303.
This commit is contained in:
d11n 2023-09-14 02:26:47 +02:00 committed by GitHub
parent 73a4ac599c
commit 492512f527
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 27 deletions

View file

@ -1,27 +1,24 @@
if (!window.appSales) {
window.appSales =
{
dataLoaded: function (model) {
const id = "AppSales-" + model.id;
window.appSales = {
dataLoaded (model) {
const id = `AppSales-${model.id}`;
const appId = model.id;
const period = model.period;
const baseUrl = model.url;
const baseUrl = model.dataUrl;
const data = model;
const render = (data, period) => {
const series = data.series.map(s => s.salesCount);
const labels = data.series.map((s, i) => period === model.period ? s.label : (i % 5 === 0 ? s.label : ''));
const labels = data.series.map((s, i) => period === 'Month' ? (i % 5 === 0 ? s.label : '') : s.label);
const min = Math.min(...series);
const max = Math.max(...series);
const low = min === max ? 0 : Math.max(min - ((max - min) / 5), 0);
document.querySelectorAll(`#${id} .sales-count`).innerText = data.salesCount;
new Chartist.Bar(`#${id} .ct-chart`, {
labels,
series: [series]
}, {
low,
low
});
};

View file

@ -27,8 +27,8 @@
const response = await fetch(url);
if (response.ok) {
document.getElementById(`AppTopItems-${appId}`).outerHTML = await response.text();
const data = document.querySelector(`#AppSales-${appId} template`);
if (data) window.appSales.dataLoaded(JSON.parse(data.innerHTML));
const data = document.querySelector(`#AppTopItems-${appId} template`);
if (data) window.appTopItems.dataLoaded(JSON.parse(data.innerHTML));
}
})();
</script>

View file

@ -1,8 +1,7 @@
if (!window.appTopItems) {
window.appTopItems =
{
dataLoaded: function (model) {
const id = "AppTopItems-" + model.id;
window.appTopItems = {
dataLoaded (model) {
const id = `AppTopItems-${model.id}`;
const series = model.salesCount;
new Chartist.Bar(`#${id} .ct-chart`, { series }, {
distributeSeries: true,

View file

@ -40,7 +40,7 @@ namespace BTCPayServer.Plugins.PointOfSale
Static,
[Display(Name = "Product list with cart")]
Cart,
[Display(Name = "Keypad only")]
[Display(Name = "Keypad")]
Light,
[Display(Name = "Print display")]
Print
@ -87,7 +87,7 @@ namespace BTCPayServer.Plugins.PointOfSale
public Task<IEnumerable<ItemStats>> GetItemStats(AppData appData, InvoiceEntity[] paidInvoices)
{
var settings = appData.GetSettings<PointOfSaleSettings>();
var items = AppService.Parse( settings.Template);
var items = AppService.Parse(settings.Template);
var itemCount = paidInvoices
.Where(entity => entity.Currency.Equals(settings.Currency, StringComparison.OrdinalIgnoreCase) && (
// The POS data is present for the cart view, where multiple items can be bought

View file

@ -160,12 +160,10 @@ namespace BTCPayServer.Services.Apps
{
return (res, e) =>
{
if (e.Metadata.PosData != null)
// flatten single items from POS data
var data = e.Metadata.PosData?.ToObject<PosAppData>();
if (data is { Cart.Length: > 0 })
{
// flatten single items from POS data
var data = e.Metadata.PosData.ToObject<PosAppData>();
if (data is not { Cart.Length: > 0 })
return res;
foreach (var lineItem in data.Cart)
{
var item = items.FirstOrDefault(p => p.Id == lineItem.Id);
@ -184,10 +182,10 @@ namespace BTCPayServer.Services.Apps
}
}
else
{;
{
res.Add(new InvoiceStatsItem
{
ItemCode = e.Metadata.ItemCode,
ItemCode = e.Metadata.ItemCode ?? typeof(PosViewType).DisplayName(PosViewType.Light.ToString()),
FiatPrice = e.PaidAmount.Net,
Date = e.InvoiceTime.Date
});

View file

@ -70,7 +70,7 @@
{
<img class="card-img-top" src="@item.Image" alt="@item.Title" asp-append-version="true">
}
<div class="card-body p-3 d-flex flex-column gap-2">
<div class="card-body p-3 d-flex flex-column gap-2 mb-auto">
<h5 class="card-title m-0">@Safe.Raw(item.Title)</h5>
<div class="d-flex gap-2 align-items-center">
@if (item.PriceType == ViewPointOfSaleViewModel.ItemPriceType.Topup || item.Price == 0)

View file

@ -41,7 +41,7 @@
{
<img class="card-img-top" src="@item.Image" alt="@Safe.Raw(item.Title)" asp-append-version="true">
}
<div class="card-body p-3 d-flex flex-column gap-2">
<div class="card-body p-3 d-flex flex-column gap-2 mb-auto">
<h5 class="card-title m-0">@Safe.Raw(item.Title)</h5>
<div class="d-flex gap-2 align-items-center">
@if (item.PriceType == ViewPointOfSaleViewModel.ItemPriceType.Topup || item.Price == 0)

View file

@ -56,5 +56,4 @@
.posItem .card .card-img-top {
max-height: 210px;
object-fit: scale-down;
margin-bottom: auto;
}