2024-04-17 20:25:41 +04:00
|
|
|
|
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,
|
2024-04-18 18:01:18 +04:00
|
|
|
|
DateTo = model.DateTo
|
2024-04-17 20:25:41 +04:00
|
|
|
|
}).Select(x => new ReportOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
ID = x.ID,
|
|
|
|
|
DateCreate = x.DateCreate,
|
|
|
|
|
ProductName = x.ProductName,
|
|
|
|
|
Sum = x.Sum,
|
2024-04-19 11:14:33 +04:00
|
|
|
|
OrderStatus = x.Status.ToString(),
|
2024-04-17 20:25:41 +04:00
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
public List<ReportSnackFoodsViewModel> GetProductComponent()
|
|
|
|
|
{
|
|
|
|
|
var components = _componentStorage.GetFullList();
|
|
|
|
|
var products = _productStorage.GetFullList();
|
|
|
|
|
var list = new List<ReportSnackFoodsViewModel>();
|
2024-04-19 11:14:33 +04:00
|
|
|
|
foreach (var pr in products) {
|
2024-04-17 20:25:41 +04:00
|
|
|
|
var record = new ReportSnackFoodsViewModel
|
|
|
|
|
{
|
2024-04-19 11:14:33 +04:00
|
|
|
|
ProductName = pr.ProductName,
|
|
|
|
|
Components = new(),
|
2024-04-17 20:25:41 +04:00
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
2024-04-19 11:14:33 +04:00
|
|
|
|
foreach (var cp in components) {
|
|
|
|
|
if (pr.ProductComponents.ContainsKey(cp.ID)) {
|
|
|
|
|
record.Components.Add(new(cp.ComponentName, pr.ProductComponents[cp.ID].Item2));
|
|
|
|
|
record.TotalCount += pr.ProductComponents[cp.ID].Item2;
|
2024-04-17 20:25:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveComponentsToWorldFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список еды",
|
2024-04-19 11:14:33 +04:00
|
|
|
|
Products = _productStorage.GetFullList(),
|
2024-04-17 20:25:41 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
2024-04-18 18:01:18 +04:00
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
2024-04-17 20:25:41 +04:00
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-04-18 18:01:18 +04:00
|
|
|
|
Title = "Список заказов",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
|
|
|
|
Orders = GetOrders(model)
|
2024-04-17 20:25:41 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveProductComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
2024-04-18 18:01:18 +04:00
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
2024-04-17 20:25:41 +04:00
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-04-18 18:01:18 +04:00
|
|
|
|
Title = "Список еды",
|
|
|
|
|
ProductComponents = GetProductComponent()
|
2024-04-17 20:25:41 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|