using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using VeterinaryClinicBusinessLogic.OfficePackage; using VeterinaryClinicBusinessLogic.OfficePackage.HelperModels; using VeterinaryClinicContracts.BindingModels; using VeterinaryClinicContracts.BusinessLogicsContracts; using VeterinaryClinicContracts.SearchModels; using VeterinaryClinicContracts.StorageContracts; using VeterinaryClinicContracts.ViewModels; namespace VeterinaryClinicBusinessLogic.BusinessLogics { public class ReportLogic : IReportLogic { private readonly IPrintedStorage _printedStorage; private readonly IOrderStorage _orderStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(IPrintedStorage printedStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _printedStorage = printedStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } public List GetPrintedComponent() { var printeds = _printedStorage.GetFullList(); var list = new List(); foreach (var printed in printeds) { var record = new ReportPrintedComponentViewModel { PrintedName = printed.PrintedName, Components = new List<(string, int)>(), TotalCount = 0 }; foreach (var component in printed.PrintedComponents) { record.Components.Add(new(component.Value.Item1.ComponentName, component.Value.Item2)); record.TotalCount += component.Value.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, PrintedName = x.PrintedName, Sum = x.Sum, OrderStatus = x.Status.ToString() }) .ToList(); } public void SavePrintedsToWordFile(ReportBindingModel model) { _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, Title = "Список изделий", Printeds = _printedStorage.GetFullList() }); } public void SavePrintedComponentToExcelFile(ReportBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, Title = "Список изделий", PrintedComponents = GetPrintedComponent() }); } public void SaveOrdersToPdfFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { FileName = model.FileName, Title = "Список заказов", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, Orders = GetOrders(model), }); } } }