diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs index 120ecc8..2d37f47 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -13,16 +13,18 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly IRepairStorage _RepairStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage, + public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage, IShopStorage ShopStorage, AbstractSaveToExcel SaveToExcel, AbstractSaveToWord SaveToWord, AbstractSaveToPdf SaveToPdf) { _RepairStorage = RepairStorage; _componentStorage = ComponentStorage; _orderStorage = OrderStorage; + _shopStorage = ShopStorage; _saveToExcel = SaveToExcel; _saveToWord = SaveToWord; @@ -41,6 +43,26 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics .ToList(); } + public List GetShops() + { + return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel + { + ShopName = x.ShopName, + Repairs = x.ShopRepairs.Select(x => (x.Value.Item1.RepairName, x.Value.Item2)).ToList(), + TotalCount = x.ShopRepairs.Select(x => x.Value.Item2).Sum() + }).ToList(); + } + + public List GetGroupedOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupedOrdersViewModel + { + Date = x.Key, + OrdersCount = x.Count(), + OrdersSum = x.Select(y => y.Sum).Sum() + }).ToList(); + } + public List GetOrders(ReportBindingModel Model) { return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = Model.DateFrom, DateTo = Model.DateTo }) @@ -77,7 +99,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public void SaveOrdersToPdfFile(ReportBindingModel Model) { - _saveToPdf.CreateDoc(new PdfInfo + _saveToPdf.CreateDoc(new PdfOrdersInfo { FileName = Model.FileName, Title = "Список заказов", @@ -86,5 +108,35 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics Orders = GetOrders(Model) }); } + + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsDoc(new WordShopsInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopPizzasReport(new ExcelShopsInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopRepairs = GetShops() + }); + } + + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo + { + FileName = model.FileName, + Title = "Список заказов, объединенных по датам", + GroupedOrders = GetGroupedOrders() + }); + } } } diff --git a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 86fd1a0..94b2490 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { - public void CreateDoc(PdfInfo Info) + public void CreateDoc(PdfOrdersInfo Info) { CreatePdf(Info); CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); @@ -33,8 +33,35 @@ namespace AutoWorkshopBusinessLogic.OfficePackage SavePdf(Info); } - - protected abstract void CreatePdf(PdfInfo Info); + + public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo Info) + { + CreatePdf(Info); + CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "4cm", "3cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Кол-во", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var groupedOrder in Info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {Info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + SavePdf(Info); + } + + protected abstract void CreatePdf(IDocumentInfo Info); protected abstract void CreateParagraph(PdfParagraph Paragraph); @@ -42,6 +69,6 @@ namespace AutoWorkshopBusinessLogic.OfficePackage protected abstract void CreateRow(PdfRowParameters RowParameters); - protected abstract void SavePdf(PdfInfo Info); + protected abstract void SavePdf(IDocumentInfo Info); } } diff --git a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs similarity index 90% rename from AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs rename to AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs index 1df40e0..ee25fd5 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/HelperModels/PdfOrdersInfo.cs @@ -2,7 +2,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels { - public class PdfInfo + public class PdfOrdersInfo : IDocumentInfo { public string FileName { get; set; } = string.Empty; diff --git a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 0ee1ec4..b1ed115 100644 --- a/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/AutoWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -33,7 +33,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements Style.Font.Bold = true; } - protected override void CreatePdf(PdfInfo Info) + protected override void CreatePdf(IDocumentInfo Info) { _document = new Document(); DefineStyles(_document); @@ -94,7 +94,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements } } - protected override void SavePdf(PdfInfo Info) + protected override void SavePdf(IDocumentInfo Info) { var Renderer = new PdfDocumentRenderer(true) {