107 lines
4.1 KiB
C#
107 lines
4.1 KiB
C#
using DinerContracts.BindingModels;
|
||
using DinerContracts.BusinessLogicsContracts;
|
||
using DinerContracts.SearchModels;
|
||
using DinerContracts.StoragesContracts;
|
||
using DinerContracts.ViewModels;
|
||
using DineryBusinessLogic.OfficePackage;
|
||
using DineryBusinessLogic.OfficePackage.HelperModels;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace DineryBusinessLogic.BusinessLogic
|
||
{
|
||
public class ReportLogic : IReportLogic
|
||
{
|
||
private readonly IFoodStorage _componentStorage;
|
||
private readonly ISnackStorage _productStorage;
|
||
private readonly IOrderStorage _orderStorage;
|
||
private readonly AbstractSaveToExcel _saveToExcel;
|
||
private readonly AbstractSaveToWord _saveToWord;
|
||
private readonly AbstractSaveToPdf _saveToPdf;
|
||
|
||
public ReportLogic(IFoodStorage componentStorage, ISnackStorage productStorage, IOrderStorage orderStorage,
|
||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||
{
|
||
_componentStorage = componentStorage;
|
||
_productStorage = productStorage;
|
||
_orderStorage = orderStorage;
|
||
_saveToExcel = saveToExcel;
|
||
_saveToWord = saveToWord;
|
||
_saveToPdf = saveToPdf;
|
||
}
|
||
// Получение списка заказов за определенный период
|
||
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
||
{
|
||
return _orderStorage.GetFilteredList(new OrderSearchModel {
|
||
DateFrom = model.DateFrom,
|
||
DateTo = model.DateTo
|
||
}).Select(x => new ReportOrdersViewModel
|
||
{
|
||
ID = x.ID,
|
||
DateCreate = x.DateCreate,
|
||
ProductName = x.ProductName,
|
||
Sum = x.Sum,
|
||
})
|
||
.ToList();
|
||
}
|
||
// Получение списка компонент с указанием, в каких изделиях используются
|
||
public List<ReportSnackFoodsViewModel> GetProductComponent()
|
||
{
|
||
var components = _componentStorage.GetFullList();
|
||
var products = _productStorage.GetFullList();
|
||
var list = new List<ReportSnackFoodsViewModel>();
|
||
foreach (var component in components) {
|
||
var record = new ReportSnackFoodsViewModel
|
||
{
|
||
ComponentName = component.ComponentName,
|
||
Products = new List<(string, int)>(),
|
||
TotalCount = 0
|
||
};
|
||
foreach (var product in products) {
|
||
if (product.ProductComponents.ContainsKey(component.ID)) {
|
||
record.Products.Add(new(product.ProductName, product.ProductComponents[component.ID].Item2));
|
||
record.TotalCount += product.ProductComponents[component.ID].Item2;
|
||
}
|
||
}
|
||
list.Add(record);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
public void SaveComponentsToWorldFile(ReportBindingModel model)
|
||
{
|
||
_saveToWord.CreateDoc(new WordInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список еды",
|
||
Components = _componentStorage.GetFullList()
|
||
});
|
||
}
|
||
|
||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||
{
|
||
_saveToPdf.CreateDoc(new PdfInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список заказов",
|
||
DateFrom = model.DateFrom!.Value,
|
||
DateTo = model.DateTo!.Value,
|
||
Orders = GetOrders(model)
|
||
});
|
||
}
|
||
|
||
public void SaveProductComponentToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveToExcel.CreateReport(new ExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список еды",
|
||
ProductComponents = GetProductComponent()
|
||
});
|
||
}
|
||
}
|
||
}
|