2024-04-08 21:48:15 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ConfectioneryBusinessLogic.OfficePackage;
|
|
|
|
|
using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
|
|
|
using ConfectioneryContracts.SearchModels;
|
|
|
|
|
using ConfectioneryContracts.StoragesContracts;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ConfectioneryBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
2024-04-09 15:45:07 +04:00
|
|
|
|
private readonly IPastryStorage _pastryStorage;
|
2024-04-08 21:48:15 +04:00
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
2024-04-09 15:45:07 +04:00
|
|
|
|
public ReportLogic(IPastryStorage pastryStorage, IComponentStorage
|
2024-04-08 21:48:15 +04:00
|
|
|
|
componentStorage, IOrderStorage orderStorage,
|
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
|
|
|
|
|
AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
2024-04-09 15:45:07 +04:00
|
|
|
|
_pastryStorage = pastryStorage;
|
2024-04-08 21:48:15 +04:00
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-04-09 15:45:07 +04:00
|
|
|
|
public List<ReportPastryComponentViewModel> GetPastryComponent()
|
2024-04-08 21:48:15 +04:00
|
|
|
|
{
|
2024-04-09 15:45:07 +04:00
|
|
|
|
var pastries = _pastryStorage.GetFullList();
|
2024-04-20 15:51:24 +04:00
|
|
|
|
|
2024-04-08 21:48:15 +04:00
|
|
|
|
var list = new List<ReportPastryComponentViewModel>();
|
2024-04-20 15:51:24 +04:00
|
|
|
|
|
|
|
|
|
foreach (var pastry in pastries)
|
2024-04-08 21:48:15 +04:00
|
|
|
|
{
|
|
|
|
|
var record = new ReportPastryComponentViewModel
|
|
|
|
|
{
|
2024-04-20 15:51:24 +04:00
|
|
|
|
PastryName = pastry.PastryName,
|
|
|
|
|
Components = new List<(string Component, int Count)>(),
|
|
|
|
|
TotalCount = 0,
|
2024-04-08 21:48:15 +04:00
|
|
|
|
};
|
2024-04-20 15:51:24 +04:00
|
|
|
|
foreach (var component in pastry.PastryComponents)
|
2024-04-08 21:48:15 +04:00
|
|
|
|
{
|
2024-04-20 15:51:24 +04:00
|
|
|
|
record.Components.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
|
|
|
|
record.TotalCount += component.Value.Item2;
|
2024-04-08 21:48:15 +04:00
|
|
|
|
}
|
2024-04-20 15:51:24 +04:00
|
|
|
|
|
2024-04-08 21:48:15 +04:00
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
2024-04-20 15:51:24 +04:00
|
|
|
|
|
2024-04-08 21:48:15 +04:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка заказов за определенный период
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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,
|
|
|
|
|
PastryName = x.PastryName,
|
2024-04-20 15:51:24 +04:00
|
|
|
|
OrderStatus = x.Status.ToString(),
|
2024-04-08 21:48:15 +04:00
|
|
|
|
Sum = x.Sum
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент в файл-Word
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
2024-04-09 15:45:07 +04:00
|
|
|
|
public void SavePastriesToWordFile(ReportBindingModel model)
|
2024-04-08 21:48:15 +04:00
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-04-20 15:51:24 +04:00
|
|
|
|
Title = "Список выпечки",
|
|
|
|
|
Pastries = _pastryStorage.GetFullList()
|
2024-04-08 21:48:15 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
2024-04-09 15:45:07 +04:00
|
|
|
|
public void SavePastryComponentToExcelFile(ReportBindingModel model)
|
2024-04-08 21:48:15 +04:00
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-04-20 16:17:34 +04:00
|
|
|
|
Title = "Список выпечки ",
|
2024-04-09 15:45:07 +04:00
|
|
|
|
PastryComponents = GetPastryComponent()
|
2024-04-08 21:48:15 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение заказов в файл-Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
|
|
|
|
Orders = GetOrders(model)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|