46 lines
1.5 KiB
C#

using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Publication.Reports;
public class ChartReport
{
/*private readonly IOrderRepository _invoiceRepository;
private readonly ILogger<ChartReport> _logger;
public ChartReport(IInvoiceRepository invoiceRepository, ILogger<ChartReport> logger)
{
_invoiceRepository = invoiceRepository ?? throw new ArgumentNullException(nameof(invoiceRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateChart(string filePath, DateTime dateTime)
{
try
{
new PdfBuilder(filePath)
.AddHeader("Сумма покупки каждого клиента")
.AddPieChart("Клиенты", GetData(dateTime))
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<(string Caption, double Value)> GetData(DateTime dateTime)
{
return _invoiceRepository
.ReadInvoices()
.Where(x => x.DateInvoice.Date == dateTime.Date)
.GroupBy(x => x.ClientID, (key, group) => new { ID = key, Count = group.Sum(y => y.SellingPrice) })
.Select(x => (x.ID.ToString(), (double)x.Count))
.ToList();
}*/
}