2023-03-01 16:42:58 +04:00
|
|
|
|
using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using ConfectioneryBusinessLogic.OfficePackage;
|
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
|
|
|
using ConfectioneryContracts.SearchModels;
|
|
|
|
|
using ConfectioneryContracts.StoragesContract;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace ConfectioneryBusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
2023-03-01 20:38:56 +04:00
|
|
|
|
private readonly IPastryStorage _pastryStorage;
|
2023-03-01 16:42:58 +04:00
|
|
|
|
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
|
2023-03-02 02:49:25 +04:00
|
|
|
|
private readonly IShopStorage _shopStorage;
|
2023-03-08 16:05:07 +04:00
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
2023-03-02 02:49:25 +04:00
|
|
|
|
|
2023-03-01 16:42:58 +04:00
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
|
|
2023-03-08 16:05:07 +04:00
|
|
|
|
public ReportLogic(IPastryStorage PastryStorage, IOrderStorage orderStorage, IShopStorage shopStorage, IComponentStorage componentStorage,
|
2023-03-01 16:42:58 +04:00
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
2023-03-08 16:05:07 +04:00
|
|
|
|
_componentStorage = componentStorage;
|
2023-03-01 20:38:56 +04:00
|
|
|
|
_pastryStorage = PastryStorage;
|
2023-03-01 16:42:58 +04:00
|
|
|
|
_orderStorage = orderStorage;
|
2023-03-02 02:49:25 +04:00
|
|
|
|
_shopStorage = shopStorage;
|
2023-03-01 16:42:58 +04:00
|
|
|
|
|
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-03-02 03:15:42 +04:00
|
|
|
|
/// Получение списка магазинов с изделиями
|
2023-03-01 16:42:58 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-03-02 03:15:42 +04:00
|
|
|
|
public List<ReportShopPastrytViewModel> GetShopPastries()
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-02 03:15:42 +04:00
|
|
|
|
var shops = _shopStorage.GetFullList();
|
2023-03-01 16:42:58 +04:00
|
|
|
|
|
2023-03-01 20:55:46 +04:00
|
|
|
|
var pastries = _pastryStorage.GetFullList();
|
2023-03-01 16:42:58 +04:00
|
|
|
|
|
2023-03-02 03:15:42 +04:00
|
|
|
|
var list = new List<ReportShopPastrytViewModel>();
|
2023-03-01 16:42:58 +04:00
|
|
|
|
|
2023-03-02 03:15:42 +04:00
|
|
|
|
foreach (var shop in shops)
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-02 03:15:42 +04:00
|
|
|
|
var record = new ReportShopPastrytViewModel
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-02 03:15:42 +04:00
|
|
|
|
ShopName = shop.Name,
|
|
|
|
|
Pastries = new List<Tuple<string, int>>(),
|
2023-03-01 16:42:58 +04:00
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
2023-03-02 03:15:42 +04:00
|
|
|
|
foreach (var pastry in pastries)
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-02 03:15:42 +04:00
|
|
|
|
if (shop.Pastries.ContainsKey(pastry.Id))
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-02 03:15:42 +04:00
|
|
|
|
record.Pastries.Add(new(pastry.PastryName, shop.Pastries[pastry.Id].Item2));
|
|
|
|
|
record.TotalCount += shop.Pastries[pastry.Id].Item2;
|
2023-03-01 16:42:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-02 03:15:42 +04:00
|
|
|
|
record.Workload = record.TotalCount / (double)shop.MaxCountPastries;
|
2023-03-01 16:42:58 +04:00
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 16:05:07 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ReportPastryComponentViewModel> GetPastryComponent()
|
|
|
|
|
{
|
|
|
|
|
var components = _componentStorage.GetFullList();
|
|
|
|
|
|
|
|
|
|
var pastries = _pastryStorage.GetFullList();
|
|
|
|
|
|
|
|
|
|
var list = new List<ReportPastryComponentViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var pastry in pastries)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportPastryComponentViewModel
|
|
|
|
|
{
|
|
|
|
|
PastryName = pastry.PastryName,
|
|
|
|
|
Components = new List<Tuple<string, int>>(),
|
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
|
|
|
|
foreach (var component in components)
|
|
|
|
|
{
|
|
|
|
|
if (pastry.PastryComponents.ContainsKey(component.Id))
|
|
|
|
|
{
|
|
|
|
|
record.Components.Add(new(component.ComponentName, pastry.PastryComponents[component.Id].Item2));
|
|
|
|
|
record.TotalCount += pastry.PastryComponents[component.Id].Item2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 16:42:58 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка заказов за определенный период
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
2023-03-08 16:05:07 +04:00
|
|
|
|
{
|
|
|
|
|
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
|
|
|
|
|
.Select(x => new ReportOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
DateCreate = x.DateCreate,
|
|
|
|
|
PastryName = x.PastryName,
|
|
|
|
|
OrderStatus = Convert.ToString(x.Status) ?? string.Empty,
|
|
|
|
|
Sum = x.Sum
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка заказов за определенный период
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ReportGroupOrdersViewModel> GetGroupOrders(ReportBindingModel model)
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-02 04:28:14 +04:00
|
|
|
|
return _orderStorage.GetFullList()
|
|
|
|
|
.GroupBy(x => x.DateCreate.Date)
|
2023-03-08 16:05:07 +04:00
|
|
|
|
.Select(x => new ReportGroupOrdersViewModel
|
2023-03-02 04:28:14 +04:00
|
|
|
|
{
|
|
|
|
|
Date = x.Key,
|
|
|
|
|
Count = x.Count(),
|
|
|
|
|
Sum = x.Sum(y => y.Sum)
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2023-03-01 16:42:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-03-02 02:49:25 +04:00
|
|
|
|
/// Сохранение магазинов в файл-Word
|
2023-03-01 16:42:58 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
2023-03-08 16:05:07 +04:00
|
|
|
|
public void SaveShopsTableToWordFile(ReportBindingModel model)
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-08 16:05:07 +04:00
|
|
|
|
_saveToWord.CreateDocTable(new WordInfoTable
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2023-03-02 02:49:25 +04:00
|
|
|
|
Title = "Список магазинов",
|
|
|
|
|
Shops = _shopStorage.GetFullList()
|
2023-03-01 16:42:58 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 16:05:07 +04:00
|
|
|
|
public void SavePastriesToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список изделий",
|
|
|
|
|
Pastries = _pastryStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-01 16:42:58 +04:00
|
|
|
|
/// <summary>
|
2023-03-02 03:15:42 +04:00
|
|
|
|
/// Сохранение магазинов с указаеним продуктов в файл-Excel
|
2023-03-01 16:42:58 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
2023-03-02 03:15:42 +04:00
|
|
|
|
public void SaveShopPastryToExcelFile(ReportBindingModel model)
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
2023-03-08 16:05:07 +04:00
|
|
|
|
_saveToExcel.CreateReportShop(new ExcelInfo
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2023-03-02 03:15:42 +04:00
|
|
|
|
Title = "Список магазинов",
|
|
|
|
|
ShopPastries = GetShopPastries()
|
2023-03-01 16:42:58 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 16:05:07 +04:00
|
|
|
|
public void SavePastryComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReportPastry(new ExcelInfoPastry
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список изделий по компонентам",
|
|
|
|
|
PastryComponents = GetPastryComponent(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 16:42:58 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение заказов в файл-Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
2023-03-08 16:05:07 +04:00
|
|
|
|
public void SaveGroupOrdersToPdfFile(ReportBindingModel model)
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
2023-03-08 16:05:07 +04:00
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список сгруппированных заказов по датам",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
|
|
|
|
Orders = GetGroupOrders(model)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение заказов в файл-Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDocOrders(new PdfInfoOrders
|
2023-03-01 16:42:58 +04:00
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
2023-03-08 16:05:07 +04:00
|
|
|
|
Orders = GetOrders(model),
|
2023-03-01 16:42:58 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-08 16:05:07 +04:00
|
|
|
|
|
2023-03-01 16:42:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|