Сдано

This commit is contained in:
Tonb73 2024-12-13 10:05:54 +03:00
parent a1a7cad61f
commit b9a375ab27
3 changed files with 25 additions and 19 deletions

View File

@ -20,9 +20,9 @@ namespace ProjectTourAgency.Forms
InitializeComponent();
_addMoneyRepository = addMoneyRepository ??
throw new ArgumentNullException(nameof(addMoneyRepository));
comboBoxClientId.DataSource = clientRepository.ReadClients();
comboBoxClientId.DisplayMember = "Name";
comboBoxClientId.ValueMember = "Id";
comboBoxClientId.DataSource = addMoneyRepository.ReadAddMoneys();
comboBoxClientId.DisplayMember = "ClientName";
comboBoxClientId.ValueMember = "ClientId";
}
private void buttonSave_Click(object sender, EventArgs e)

View File

@ -28,7 +28,7 @@ internal class ChartReport
{
new PdfBuilder(filePath)
.AddHeader("Операции пополнения")
.AddPieChart("Пополнения счетов клиентов", GetData(dateTime))
.AddPieChart($"Пополнения счетов клиентов за {dateTime.ToString("d MMMM yyyy")}", GetData(dateTime))
.Build();
return true;
@ -44,7 +44,7 @@ internal class ChartReport
{
return _addMoneyRepository
.ReadAddMoneys(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
.GroupBy(x => x.ClientId, (key, group) => new { Id = key, Count = group.Count() })
.GroupBy(x => x.ClientName, (key, group) => new { Id = key, Count = group.Count() })
.Select(x => (x.Id.ToString(), (double)x.Count))
.ToList();
}

View File

@ -45,7 +45,6 @@ namespace ProjectTourAgency.Reports
private List<string[]> GetData(int tourId, DateTime startDate, DateTime endDate)
{
var tourData = _tourRepository.ReadTours(startDate, endDate, tourId)
.SelectMany(x => x.ClientTours
.Select(y => new {
@ -56,10 +55,8 @@ namespace ProjectTourAgency.Reports
CountOut = (int?)y.Cost
}));
var clientId = tourData.Select(x =>x.ClientId).Distinct().ToList();
var clientId = tourData.Select(x => x.ClientId).Distinct().ToList();
var addMoneyData = _addMoneyRepository.ReadAddMoneys(startDate, endDate)
.Where(x => clientId.Contains(x.ClientId))
.Select(x => new {
@ -70,24 +67,33 @@ namespace ProjectTourAgency.Reports
CountOut = (int?)null
});
// Объединяем данные и группируем по клиенту и дате
var data = tourData
.Union(addMoneyData)
.GroupBy(x => new { x.ClientId, x.ClientName, x.Date })
.Select(g => new {
ClientName = g.Key.ClientName,
Date = g.Key.Date,
CountIn = g.Sum(x => x.CountIn ?? 0),
CountOut = g.Sum(x => x.CountOut ?? 0)
})
.OrderBy(x => x.Date);
return new List<string[]>() { item }
.Union(data.Select(x => new string[] {
x.ClientName.ToString(),
x.Date.ToString(),
x.CountIn?.ToString() ?? "NO",
x.CountOut?.ToString() ?? "NO"}))
x.ClientName,
x.Date.ToString("dd.MM.yyyy"), // Форматируем дату
x.CountIn == 0 ? "NO" : x.CountIn.ToString(),
x.CountOut == 0 ? "NO" : x.CountOut.ToString()
}))
.Union(new[] { new string[] {
"Всего",
"",
data.Sum(x => x.CountIn ?? 0) == 0 ? "NO" : data.Sum(x => x.CountIn ?? 0).ToString(),
data.Sum(x => x.CountOut ?? 0) == 0 ? "NO" : data.Sum(x => x.CountOut ?? 0).ToString()
}})
"Всего",
"",
data.Sum(x => x.CountIn) == 0 ? "NO" : data.Sum(x => x.CountIn).ToString(),
data.Sum(x => x.CountOut) == 0 ? "NO" : data.Sum(x => x.CountOut).ToString()
}})
.ToList();
}
}
}