mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-06 18:41:12 +01:00
* Add dashboard and chart basics * More widgets * Make widgets responsive * Layout dashboard * Prepare ExplorerClient * Switch to Chartist * Dynamic data for store numbers and recent transactions tiles * Dynamic data for recent invoices tile * Improvements * Plug NBXPlorer DB * Properly filter by code * Reorder cheat mode button * AJAX update for graph data * Fix create invoice button * Retry connection on transient issues * App Top Items stats * Design updates * App Sales stats * Add points for weekly histogram, set last point to current balance Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Data;
|
|
using BTCPayServer.Services.Invoices;
|
|
using BTCPayServer.Services.Rates;
|
|
using BTCPayServer.Services.Stores;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BTCPayServer.Components.StoreRecentInvoices;
|
|
|
|
public class StoreRecentInvoices : ViewComponent
|
|
{
|
|
private readonly StoreRepository _storeRepo;
|
|
private readonly InvoiceRepository _invoiceRepo;
|
|
private readonly CurrencyNameTable _currencyNameTable;
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
|
private readonly ApplicationDbContextFactory _dbContextFactory;
|
|
|
|
public StoreRecentInvoices(
|
|
StoreRepository storeRepo,
|
|
InvoiceRepository invoiceRepo,
|
|
CurrencyNameTable currencyNameTable,
|
|
UserManager<ApplicationUser> userManager,
|
|
ApplicationDbContextFactory dbContextFactory)
|
|
{
|
|
_storeRepo = storeRepo;
|
|
_invoiceRepo = invoiceRepo;
|
|
_userManager = userManager;
|
|
_currencyNameTable = currencyNameTable;
|
|
_dbContextFactory = dbContextFactory;
|
|
}
|
|
|
|
public async Task<IViewComponentResult> InvokeAsync(StoreData store)
|
|
{
|
|
var userId = _userManager.GetUserId(UserClaimsPrincipal);
|
|
var invoiceEntities = await _invoiceRepo.GetInvoices(new InvoiceQuery
|
|
{
|
|
UserId = userId,
|
|
StoreId = new [] { store.Id },
|
|
Take = 5
|
|
});
|
|
var invoices = new List<StoreRecentInvoiceViewModel>();
|
|
foreach (var invoice in invoiceEntities)
|
|
{
|
|
var state = invoice.GetInvoiceState();
|
|
invoices.Add(new StoreRecentInvoiceViewModel
|
|
{
|
|
Date = invoice.InvoiceTime,
|
|
Status = state,
|
|
InvoiceId = invoice.Id,
|
|
OrderId = invoice.Metadata.OrderId ?? string.Empty,
|
|
AmountCurrency = _currencyNameTable.DisplayFormatCurrency(invoice.Price, invoice.Currency),
|
|
});
|
|
}
|
|
var vm = new StoreRecentInvoicesViewModel
|
|
{
|
|
Store = store,
|
|
Invoices = invoices
|
|
};
|
|
|
|
return View(vm);
|
|
}
|
|
}
|