48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
|
using Microsoft.Extensions.Logging;
|
|||
|
using ProjectFamilyBudget.Entities;
|
|||
|
using ProjectFamilyBudget.Repositories;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ProjectFamilyBudget.Reports;
|
|||
|
|
|||
|
public class ChartReport
|
|||
|
{
|
|||
|
private readonly IPeopleExpense _peopleExpense;
|
|||
|
private readonly ILogger<ChartReport> _logger;
|
|||
|
|
|||
|
public ChartReport(IPeopleExpense peopleExpense,, ILogger<ChartReport> logger)
|
|||
|
{
|
|||
|
_peopleExpense = peopleExpense ?? throw new ArgumentNullException(nameof(peopleExpense));
|
|||
|
_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 _peopleExpense
|
|||
|
.ReadPeopleExpense()
|
|||
|
.Where(x => x.DataReciept.Date == dateTime.Date)
|
|||
|
.GroupBy(x => x.PeopleId, (key, group) => new { Id = key, Count = group.Sum(x =>})
|
|||
|
.Select(x => (x.Id.ToString(), (double)x.Count))
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
}
|