PIbd-22 Pyzhov E.A. LabWork03 #3
@ -1,6 +1,4 @@
|
||||
using ITServiceManager.Entities;
|
||||
using ITServiceManager.Repositories;
|
||||
using ITServiceManager.Repositories.Implementations;
|
||||
using ITServiceManager.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ITServiceManager.Reports;
|
||||
@ -35,43 +33,25 @@ public class ChartReport
|
||||
}
|
||||
}
|
||||
|
||||
//private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
//{
|
||||
// return _orderRepository
|
||||
// .ReadOrders() // Получаем все заказы
|
||||
// .Where(order => order.Date.Date == dateTime.Date) // Фильтруем по дате заказа
|
||||
// .SelectMany(order => order.OrderService) // Разворачиваем список услуг в заказах
|
||||
// .GroupBy(service => service.ServiceId, (key, group) => new { ServiceId = key, Count = group.Sum(service => service.Quantity) }) // Группируем по ID услуги и суммируем количество
|
||||
// .Select(group =>
|
||||
// {
|
||||
// var service = _serviceRepository.ReadServiceById(group.ServiceId); // Получаем информацию о услуге по ID
|
||||
// return (service.ServiceType.ToString(), (double)group.Count); // Возвращаем название услуги и ее количество
|
||||
// })
|
||||
// .ToList();
|
||||
//}
|
||||
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
// Получаем заказы за указанную дату
|
||||
var orders = _orderRepository
|
||||
.ReadOrders()
|
||||
.Where(order => order.Date.Date == dateTime.Date) // Фильтруем заказы по дате
|
||||
.Where(order => order.Date.Date == dateTime.Date)
|
||||
.ToList();
|
||||
|
||||
// Группируем заказы по CompanyId и вычисляем общую сумму затрат
|
||||
var groupedOrders = orders
|
||||
.GroupBy(order => order.CompanyId)
|
||||
.Select(group => new
|
||||
{
|
||||
CompanyId = group.Key,
|
||||
TotalSpent = group.Sum(order => (double)order.Price) // Суммируем стоимость заказов
|
||||
TotalSpent = group.Sum(order => (double)order.Price)
|
||||
});
|
||||
|
||||
// Получаем названия компаний и формируем данные для диаграммы
|
||||
return groupedOrders
|
||||
.Select(group =>
|
||||
{
|
||||
var company = _companyRepository.ReadCompanyById(group.CompanyId); // Получаем информацию о компании
|
||||
var company = _companyRepository.ReadCompanyById(group.CompanyId);
|
||||
return (Caption: company.Name, Value: group.TotalSpent);
|
||||
})
|
||||
.ToList();
|
||||
|
@ -30,7 +30,7 @@ public class DocReport
|
||||
}
|
||||
if (includeServices)
|
||||
{
|
||||
builder.AddParagraph("Услуги").AddTable([2400, 2400], GetServices());
|
||||
builder.AddParagraph("Услуги").AddTable([2400, 2400, 2400], GetServices());
|
||||
}
|
||||
if (includeEmployees)
|
||||
{
|
||||
@ -69,10 +69,10 @@ public class DocReport
|
||||
private List<string[]> GetServices()
|
||||
{
|
||||
return [
|
||||
["Тип услуги", "Описание"],
|
||||
["Название услуги", "Тип услуги", "Описание"],
|
||||
.. _serviceRepository
|
||||
.ReadServices()
|
||||
.Select(x => new string[] { x.ServiceType.ToString(), x.Description }),
|
||||
.Select(x => new string[] {x.ServiceName, x.ServiceType.ToString(), x.Description }),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
|
||||
using ITServiceManager.Entities;
|
||||
using ITServiceManager.Repositories;
|
||||
using ITServiceManager.Repositories.Implementations;
|
||||
using ITServiceManager.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ITServiceManager.Reports;
|
||||
|
Loading…
x
Reference in New Issue
Block a user