using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels; using PrecastConcretePlantBusinessLogic.OfficePackage; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; namespace PrecastConcretePlantBusinessLogic.BusinessLogics { public class ReportLogic : IReportLogic { private readonly IComponentStorage _componentStorage; private readonly IReinforcedStorage _reinforcedStorage; private readonly IOrderStorage _orderStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(IReinforcedStorage reinforcedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _reinforcedStorage = reinforcedStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } /// /// Получение списка компонент с указанием, в каких изделиях используются /// /// public List GetReinforcedComponent() { var components = _componentStorage.GetFullList(); var reinforceds = _reinforcedStorage.GetFullList(); var list = new List(); foreach (var reinforced in reinforceds) { var record = new ReportReinforcedComponentViewModel { ReinforcedName = reinforced.ReinforcedName, Components = new List<(string, int)>(), TotalCount = 0 }; foreach (var condition in components) { if (reinforced.ReinforcedComponents.ContainsKey(condition.Id)) { record.Components.Add(new(condition.ComponentName, reinforced.ReinforcedComponents[condition.Id].Item2)); record.TotalCount += reinforced.ReinforcedComponents[condition.Id].Item2; } } list.Add(record); } return list; } /// /// Получение списка заказов за определенный период /// /// /// public List GetOrders(ReportBindingModel model) { return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }) .Select(x => new ReportOrdersViewModel { Id = x.Id, DateCreate = x.DateCreate, ReinforcedName = x.ReinforcedName, OrderStatus = x.Status.ToString(), Sum = x.Sum }) .ToList(); } /// /// Сохранение компонент в файл-Word /// /// public void SaveReinforcedsToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, Title = "Список изделий", Reinforceds = _reinforcedStorage.GetFullList() }); } /// /// Сохранение компонент с указаеним продуктов в файл-Excel /// /// public void SaveReinforcedComponentToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, Title = "Список изделий", ReinforcedComponents = GetReinforcedComponent() }); } /// /// Сохранение заказов в файл-Pdf /// /// public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { FileName = model.FileName, Title = "Список заказов", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, Orders = GetOrders(model) }); } } }