diff --git a/project/ProjectTourAgency/Forms/FormAddMoney.cs b/project/ProjectTourAgency/Forms/FormAddMoney.cs index 918074d..bd1382e 100644 --- a/project/ProjectTourAgency/Forms/FormAddMoney.cs +++ b/project/ProjectTourAgency/Forms/FormAddMoney.cs @@ -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) diff --git a/project/ProjectTourAgency/Reports/ChartReport.cs b/project/ProjectTourAgency/Reports/ChartReport.cs index f4c881e..1b890cc 100644 --- a/project/ProjectTourAgency/Reports/ChartReport.cs +++ b/project/ProjectTourAgency/Reports/ChartReport.cs @@ -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(); } diff --git a/project/ProjectTourAgency/Reports/TableReportcs.cs b/project/ProjectTourAgency/Reports/TableReportcs.cs index 97d1788..5200dd1 100644 --- a/project/ProjectTourAgency/Reports/TableReportcs.cs +++ b/project/ProjectTourAgency/Reports/TableReportcs.cs @@ -45,7 +45,6 @@ namespace ProjectTourAgency.Reports private List 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() { 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(); } + } }