From 59aad5652753dba1216820407bf992a0ac3813dc Mon Sep 17 00:00:00 2001 From: Petek1234 <149153720+Petek1234@users.noreply.github.com> Date: Wed, 4 Dec 2024 22:00:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=203=20=D0=B3=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GasStation/GasStation/Entities/FuelSale.cs | 12 ++ .../GasStation/Entities/SuppliersFuel.cs | 2 +- .../GasStation/Entities/TempFuelFuelSale.cs | 17 +++ .../GasStation/FormGasStation.Designer.cs | 12 +- GasStation/GasStation/FormGasStation.cs | 13 ++ GasStation/GasStation/Forms/FormFuelSale.cs | 3 +- .../Forms/FormSupplierFuel.Designer.cs | 12 +- .../GasStation/Forms/FormSupplierFuel.resx | 6 + ...uppliersFuelDistributionReport.Designer.cs | 108 ++++++++++++++++ .../FormSuppliersFuelDistributionReport.cs | 69 ++++++++++ .../FormSuppliersFuelDistributionReport.resx | 120 ++++++++++++++++++ GasStation/GasStation/GasStation.csproj | 1 + GasStation/GasStation/Reports/ChartReport.cs | 54 ++++++++ GasStation/GasStation/Reports/PdfBuilder.cs | 77 +++++++++++ GasStation/GasStation/Reports/TableReport.cs | 43 +++---- .../Implementations/FuelSalesRepository.cs | 9 +- 16 files changed, 520 insertions(+), 38 deletions(-) create mode 100644 GasStation/GasStation/Entities/TempFuelFuelSale.cs create mode 100644 GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.Designer.cs create mode 100644 GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.cs create mode 100644 GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.resx create mode 100644 GasStation/GasStation/Reports/ChartReport.cs create mode 100644 GasStation/GasStation/Reports/PdfBuilder.cs diff --git a/GasStation/GasStation/Entities/FuelSale.cs b/GasStation/GasStation/Entities/FuelSale.cs index fc44dbb..92e7f71 100644 --- a/GasStation/GasStation/Entities/FuelSale.cs +++ b/GasStation/GasStation/Entities/FuelSale.cs @@ -34,4 +34,16 @@ public class FuelSale FuelFuelSale = fuelFuelSale }; } + + public static FuelSale CreateElement(TempFuelFuelSale tempFuelFuelSale, IEnumerable fuelFuelSale) + { + return new FuelSale + { + Id = tempFuelFuelSale.Id, + CashierId = tempFuelFuelSale.CashierId, + SaleDate = tempFuelFuelSale.SaleDate, + TotalPrice = tempFuelFuelSale.TotalPrice, + FuelFuelSale = fuelFuelSale + }; + } } diff --git a/GasStation/GasStation/Entities/SuppliersFuel.cs b/GasStation/GasStation/Entities/SuppliersFuel.cs index aae2c25..0026d59 100644 --- a/GasStation/GasStation/Entities/SuppliersFuel.cs +++ b/GasStation/GasStation/Entities/SuppliersFuel.cs @@ -12,7 +12,7 @@ public class SuppliersFuel public int Id { get; private set; } public int SuppliersId { get; private set; } - + public DateTime Date { get; private set; } public IEnumerable SuppliersFuelFuel { get; private set; } = []; diff --git a/GasStation/GasStation/Entities/TempFuelFuelSale.cs b/GasStation/GasStation/Entities/TempFuelFuelSale.cs new file mode 100644 index 0000000..f9e9cea --- /dev/null +++ b/GasStation/GasStation/Entities/TempFuelFuelSale.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasStation.Entities; + +public class TempFuelFuelSale +{ + public int Id { get; private set; } + public int CashierId { get; private set; } + public DateTime SaleDate { get; private set; } + public int TotalPrice { get; private set; } + public int FuelId { get; private set; } + public int Quantity { get; private set; } +} diff --git a/GasStation/GasStation/FormGasStation.Designer.cs b/GasStation/GasStation/FormGasStation.Designer.cs index cb51417..77002aa 100644 --- a/GasStation/GasStation/FormGasStation.Designer.cs +++ b/GasStation/GasStation/FormGasStation.Designer.cs @@ -39,6 +39,7 @@ отчётыToolStripMenuItem = new ToolStripMenuItem(); DirectoryReportToolStripMenuItem = new ToolStripMenuItem(); FuelReportToolStripMenuItem = new ToolStripMenuItem(); + ToolStripFuelDistribution = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -102,7 +103,7 @@ // // отчётыToolStripMenuItem // - отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, FuelReportToolStripMenuItem }); + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, FuelReportToolStripMenuItem, ToolStripFuelDistribution }); отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; отчётыToolStripMenuItem.Size = new Size(62, 20); отчётыToolStripMenuItem.Text = "Отчёты"; @@ -123,6 +124,14 @@ FuelReportToolStripMenuItem.Text = "Движение топлива"; FuelReportToolStripMenuItem.Click += FuelReportToolStripMenuItem_Click; // + // ToolStripFuelDistribution + // + ToolStripFuelDistribution.Name = "ToolStripFuelDistribution"; + ToolStripFuelDistribution.ShortcutKeys = Keys.Control | Keys.P; + ToolStripFuelDistribution.Size = new Size(311, 22); + ToolStripFuelDistribution.Text = "Распределение поставок топлива"; + ToolStripFuelDistribution.Click += ToolStripFuelDistribution_Click; + // // FormGasStation // AutoScaleDimensions = new SizeF(7F, 15F); @@ -154,5 +163,6 @@ private ToolStripMenuItem ToolStripMenuItemSuppliersFuel; private ToolStripMenuItem DirectoryReportToolStripMenuItem; private ToolStripMenuItem FuelReportToolStripMenuItem; + private ToolStripMenuItem ToolStripFuelDistribution; } } \ No newline at end of file diff --git a/GasStation/GasStation/FormGasStation.cs b/GasStation/GasStation/FormGasStation.cs index d925ffc..9c3be2a 100644 --- a/GasStation/GasStation/FormGasStation.cs +++ b/GasStation/GasStation/FormGasStation.cs @@ -103,4 +103,17 @@ public partial class FormGasStation : Form MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void ToolStripFuelDistribution_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } \ No newline at end of file diff --git a/GasStation/GasStation/Forms/FormFuelSale.cs b/GasStation/GasStation/Forms/FormFuelSale.cs index 3e2440f..ccde5dd 100644 --- a/GasStation/GasStation/Forms/FormFuelSale.cs +++ b/GasStation/GasStation/Forms/FormFuelSale.cs @@ -68,6 +68,7 @@ public partial class FormFuelSale : Form Convert.ToInt32(row.Cells["ColumnFuel"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value), 0)); } - return list; + return list.GroupBy(x => x.FuelId, x => x.Quantity, (id, counts) => + FuelFuelSale.CreateFuelFuelSale(0, id, counts.Sum(), 0)).ToList(); } } diff --git a/GasStation/GasStation/Forms/FormSupplierFuel.Designer.cs b/GasStation/GasStation/Forms/FormSupplierFuel.Designer.cs index 34a4877..e69ec50 100644 --- a/GasStation/GasStation/Forms/FormSupplierFuel.Designer.cs +++ b/GasStation/GasStation/Forms/FormSupplierFuel.Designer.cs @@ -78,7 +78,7 @@ // ButtonSave // ButtonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonSave.Location = new Point(13, 370); + ButtonSave.Location = new Point(12, 365); ButtonSave.Name = "ButtonSave"; ButtonSave.Size = new Size(117, 22); ButtonSave.TabIndex = 5; @@ -89,7 +89,7 @@ // ButtonCancel // ButtonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - ButtonCancel.Location = new Point(210, 370); + ButtonCancel.Location = new Point(211, 365); ButtonCancel.Name = "ButtonCancel"; ButtonCancel.Size = new Size(117, 22); ButtonCancel.TabIndex = 6; @@ -99,11 +99,10 @@ // // groupBox // - groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; groupBox.Controls.Add(dataGridView); - groupBox.Location = new Point(12, 89); + groupBox.Location = new Point(13, 89); groupBox.Name = "groupBox"; - groupBox.Size = new Size(318, 272); + groupBox.Size = new Size(318, 271); groupBox.TabIndex = 7; groupBox.TabStop = false; groupBox.Text = "Топливо"; @@ -120,9 +119,8 @@ dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.RowHeadersVisible = false; - dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(312, 250); + dataGridView.Size = new Size(312, 249); dataGridView.TabIndex = 0; // // ColumnFuel diff --git a/GasStation/GasStation/Forms/FormSupplierFuel.resx b/GasStation/GasStation/Forms/FormSupplierFuel.resx index a5f58c2..a1982ad 100644 --- a/GasStation/GasStation/Forms/FormSupplierFuel.resx +++ b/GasStation/GasStation/Forms/FormSupplierFuel.resx @@ -123,4 +123,10 @@ True + + True + + + True + \ No newline at end of file diff --git a/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.Designer.cs b/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.Designer.cs new file mode 100644 index 0000000..139a871 --- /dev/null +++ b/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.Designer.cs @@ -0,0 +1,108 @@ +namespace GasStation.Forms +{ + partial class FormSuppliersFuelDistributionReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ButtonFile = new Button(); + labelFileName = new Label(); + dateTimePicker = new DateTimePicker(); + label1 = new Label(); + ButtonBuild = new Button(); + SuspendLayout(); + // + // ButtonFile + // + ButtonFile.Location = new Point(12, 22); + ButtonFile.Name = "ButtonFile"; + ButtonFile.Size = new Size(75, 23); + ButtonFile.TabIndex = 0; + ButtonFile.Text = "Выбрать"; + ButtonFile.UseVisualStyleBackColor = true; + ButtonFile.Click += ButtonFile_Click; + // + // labelFileName + // + labelFileName.AutoSize = true; + labelFileName.Location = new Point(93, 26); + labelFileName.Name = "labelFileName"; + labelFileName.Size = new Size(38, 15); + labelFileName.TabIndex = 1; + labelFileName.Text = "Файл"; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(71, 65); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(151, 23); + dateTimePicker.TabIndex = 2; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 71); + label1.Name = "label1"; + label1.Size = new Size(36, 15); + label1.TabIndex = 3; + label1.Text = "Дата:"; + // + // ButtonBuild + // + ButtonBuild.Location = new Point(12, 101); + ButtonBuild.Name = "ButtonBuild"; + ButtonBuild.Size = new Size(210, 27); + ButtonBuild.TabIndex = 4; + ButtonBuild.Text = "Сформировать"; + ButtonBuild.UseVisualStyleBackColor = true; + ButtonBuild.Click += ButtonBuild_Click; + // + // FormSuppliersFuelDistributionReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(236, 154); + Controls.Add(ButtonBuild); + Controls.Add(label1); + Controls.Add(dateTimePicker); + Controls.Add(labelFileName); + Controls.Add(ButtonFile); + Name = "FormSuppliersFuelDistributionReport"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormSuppliersFuelDistributionReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button ButtonFile; + private Label labelFileName; + private DateTimePicker dateTimePicker; + private Label label1; + private Button ButtonBuild; + } +} \ No newline at end of file diff --git a/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.cs b/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.cs new file mode 100644 index 0000000..1042d95 --- /dev/null +++ b/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using GasStation.Reports; +using Unity; + +namespace GasStation.Forms; + +public partial class FormSuppliersFuelDistributionReport : Form +{ + private string _fileName = string.Empty; + + private readonly IUnityContainer _container; + + public FormSuppliersFuelDistributionReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void ButtonBuild_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(_fileName)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if + (_container.Resolve().CreateChart(_fileName, dateTimePicker.Value)) + { + MessageBox.Show("Документ сформирован", + "Формирование документа", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", + "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании отчета", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonFile_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Pdf Files | *.pdf" + }; + if (sfd.ShowDialog() == DialogResult.OK) + { + _fileName = sfd.FileName; + labelFileName.Text = Path.GetFileName(_fileName); + } + } +} diff --git a/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.resx b/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/GasStation/GasStation/Forms/FormSuppliersFuelDistributionReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GasStation/GasStation/GasStation.csproj b/GasStation/GasStation/GasStation.csproj index 74f8ea0..05aee82 100644 --- a/GasStation/GasStation/GasStation.csproj +++ b/GasStation/GasStation/GasStation.csproj @@ -26,6 +26,7 @@ + diff --git a/GasStation/GasStation/Reports/ChartReport.cs b/GasStation/GasStation/Reports/ChartReport.cs new file mode 100644 index 0000000..a688fbd --- /dev/null +++ b/GasStation/GasStation/Reports/ChartReport.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GasStation.Repositories; +using Microsoft.Extensions.Logging; + +namespace GasStation.Reports; + +internal class ChartReport +{ + private readonly ISuppliersFuelRepository _suppliersFuelRepository; + private readonly IFuelRepository _fuelRepository; + private readonly ILogger _logger; + + public ChartReport(ISuppliersFuelRepository suppliersFuelRepository, IFuelRepository fuelRepository, ILogger logger) + { + _suppliersFuelRepository = suppliersFuelRepository ?? throw new ArgumentNullException(nameof(suppliersFuelRepository)); + _fuelRepository = fuelRepository ?? throw new ArgumentNullException(nameof(fuelRepository)); + _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) + { + var fuelNames = _fuelRepository.ReadFuels() + .ToDictionary(f => f.Id, f => f.Type); + + return _suppliersFuelRepository + .ReadSuppliersFuels() + .Where(x => x.Date.Date == dateTime.Date) + .SelectMany(x => x.SuppliersFuelFuel) + .GroupBy(x => x.FuelId) + .Select(g => (Caption: fuelNames[g.Key].ToString(), Value: (double)g.Sum(x => x.Quantity))) + .ToList(); + } +} diff --git a/GasStation/GasStation/Reports/PdfBuilder.cs b/GasStation/GasStation/Reports/PdfBuilder.cs new file mode 100644 index 0000000..25a19bd --- /dev/null +++ b/GasStation/GasStation/Reports/PdfBuilder.cs @@ -0,0 +1,77 @@ +using System.Text; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; + +namespace GasStation.Reports; + +internal class PdfBuilder +{ + private readonly string _filePath; + private readonly Document _document; + + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + chart.TopArea.AddParagraph(title); + chart.XAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + chart.TopArea.AddLegend(); + _document.LastSection.Add(chart); + return this; + } + + public void Build() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + + private void DefineStyles() + { + var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal"); + headerStyle.Font.Bold = true; + headerStyle.Font.Size = 14; + } +} diff --git a/GasStation/GasStation/Reports/TableReport.cs b/GasStation/GasStation/Reports/TableReport.cs index e421320..79b710c 100644 --- a/GasStation/GasStation/Reports/TableReport.cs +++ b/GasStation/GasStation/Reports/TableReport.cs @@ -31,7 +31,7 @@ internal class TableReport new ExcelBuilder(filePath) .AddHeader("Сводка по движению топлива", 0, 3) .AddParagraph("за период", 0) - .AddTable([ 10, 15, 15], GetData(fuelId, startDate, endDate)) + .AddTable([10, 15, 15], GetData(fuelId, startDate, endDate)) .Build(); return true; } @@ -42,38 +42,31 @@ internal class TableReport } } + + private List GetData(int fuelId, DateTime startDate, DateTime endDate) { - var data = _suppliersFuelRepository - .ReadSuppliersFuels() - .Where(x => x.Date >= startDate && x.Date <= endDate && x.SuppliersFuelFuel.Any(y => y.FuelId == fuelId)) - .Select(x => new { x.Date, CountIn = x.SuppliersFuelFuel.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity, CountOut = (int?)null }) - .Union( - _fuelSalesRepository + var suppliersData = _suppliersFuelRepository + .ReadSuppliersFuels() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.SuppliersFuelFuel.Any(y => y.FuelId == fuelId)) + .Select(x => new { Date = x.Date, CountIn = x.SuppliersFuelFuel.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity, CountOut = (int?)null }); + + var salesData = _fuelSalesRepository .ReadFuelSale() .Where(x => x.SaleDate >= startDate && x.SaleDate <= endDate && x.FuelFuelSale.Any(y => y.FuelId == fuelId)) - .Select(x => new { Date = x.SaleDate, CountIn = (int?)null, CountOut = x.FuelFuelSale.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity }) - ) - .OrderBy(x => x.Date); + .Select(x => new { Date = x.SaleDate, CountIn = (int?)null, CountOut = x.FuelFuelSale.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity }); - var groupedData = data + var combinedData = suppliersData.Union(salesData) .GroupBy(x => x.Date) - .Select(g => new - { - Date = g.Key, - TotalIn = g.Sum(x => x.CountIn), - TotalOut = g.Sum(x => x.CountOut) - }) + .Select(g => new { Date = g.Key, CountIn = g.Sum(x => x.CountIn ?? 0), CountOut = g.Sum(x => x.CountOut ?? 0) }) .OrderBy(x => x.Date); - return - new List() { item } - .Union(groupedData - .Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.TotalIn.ToString()!, x.TotalOut.ToString()! })) + return new List() { item } .Union( - new[] { new string[] { "Всего", groupedData.Sum(x => x.TotalIn).ToString()!, groupedData.Sum(x => x.TotalOut).ToString()! } } - ) + combinedData + .Select(x => new string[] { x.Date.ToString(), x.CountIn.ToString(), x.CountOut.ToString() })) + .Union( + new List() { new string[] { "Всего", combinedData.Sum(x => x.CountIn).ToString(), combinedData.Sum(x => x.CountOut).ToString() } }) .ToList(); } - -} +} \ No newline at end of file diff --git a/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs b/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs index bb081cf..818693c 100644 --- a/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs +++ b/GasStation/GasStation/Repositories/Implementations/FuelSalesRepository.cs @@ -9,6 +9,7 @@ using GasStation.Entities; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; +using ProjectGasStation.Entities; namespace GasStation.Repositories.Implementations; @@ -97,11 +98,13 @@ public class FuelSalesRepository : IFuelSalesRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM FuelSale"; - var fuelSales = connection.Query(querySelect); + var querySelect = @"SELECT fs.*, ffs.FuelId, ffs.Quantity FROM FuelSale fs + INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id"; + var fuelSales = connection.Query(querySelect); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuelSales)); - return fuelSales; + return fuelSales.GroupBy(x => x.Id, y => y, (key, value) => FuelSale.CreateElement(value.First(), + value.Select(z => FuelFuelSale.CreateFuelFuelSale(0, z.FuelId, z.Quantity,0)))).ToList(); } catch (Exception ex) {