2024-03-26 18:10:51 +04:00
|
|
|
|
using FlowerShopBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using FlowerShopBusinessLogic.OfficePackage;
|
|
|
|
|
using FlowerShopContracts.BindingModels;
|
|
|
|
|
using FlowerShopContracts.BusinessLogicsContracts;
|
|
|
|
|
using FlowerShopContracts.SearchModels;
|
|
|
|
|
using FlowerShopContracts.StoragesContracts;
|
|
|
|
|
using FlowerShopContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FlowerShopBusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
|
|
|
|
private readonly IFlowerStorage _flowerStorage;
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
2024-04-04 11:38:58 +04:00
|
|
|
|
private readonly IShopStorage _shopStorage;
|
|
|
|
|
|
2024-03-26 18:10:51 +04:00
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
|
public ReportLogic(IFlowerStorage flowerStorage, IComponentStorage
|
2024-04-04 11:38:58 +04:00
|
|
|
|
componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
|
2024-03-26 18:10:51 +04:00
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
|
|
|
|
|
AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
|
|
|
|
_flowerStorage = flowerStorage;
|
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
2024-04-04 11:38:58 +04:00
|
|
|
|
_shopStorage = shopStorage;
|
|
|
|
|
|
2024-03-26 18:10:51 +04:00
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ReportFlowerComponentViewModel> GetFlowerComponent()
|
|
|
|
|
{
|
|
|
|
|
var flowers = _flowerStorage.GetFullList();
|
|
|
|
|
var list = new List<ReportFlowerComponentViewModel>();
|
2024-03-26 22:55:11 +04:00
|
|
|
|
foreach (var flower in flowers)
|
2024-03-26 18:10:51 +04:00
|
|
|
|
{
|
|
|
|
|
var record = new ReportFlowerComponentViewModel
|
|
|
|
|
{
|
2024-03-26 22:55:11 +04:00
|
|
|
|
FlowerName = flower.FlowerName,
|
|
|
|
|
Components = new List<Tuple<string, int>>(),
|
2024-03-26 18:10:51 +04:00
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
2024-03-26 22:55:11 +04:00
|
|
|
|
foreach (var component in flower.FlowerComponents)
|
2024-03-26 18:10:51 +04:00
|
|
|
|
{
|
2024-03-26 22:55:11 +04:00
|
|
|
|
record.Components.Add(new Tuple<string,
|
|
|
|
|
int>(component.Value.Item1.ComponentName, component.Value.Item2));
|
|
|
|
|
record.TotalCount +=
|
|
|
|
|
component.Value.Item2;
|
2024-03-26 18:10:51 +04:00
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
FlowerName = x.FlowerName,
|
2024-03-26 20:53:44 +04:00
|
|
|
|
OrderStatus = x.Status.ToString(),
|
2024-03-26 18:10:51 +04:00
|
|
|
|
Sum = x.Sum
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент в файл-Word
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveComponentsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-03-26 22:55:11 +04:00
|
|
|
|
Title = "Список цветов",
|
|
|
|
|
Flowers = _flowerStorage.GetFullList()
|
2024-03-26 18:10:51 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveFlowerComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-03-26 22:55:11 +04:00
|
|
|
|
Title = "Список компонентов",
|
2024-03-26 18:10:51 +04:00
|
|
|
|
FlowerComponents = GetFlowerComponent()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <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)
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-04 11:38:58 +04:00
|
|
|
|
|
|
|
|
|
public List<ReportShopFlowerViewModel> GetShopsFlowers()
|
|
|
|
|
{
|
|
|
|
|
var shops = _shopStorage.GetFullList();
|
|
|
|
|
var list = new List<ReportShopFlowerViewModel>();
|
|
|
|
|
foreach (var shop in shops)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportShopFlowerViewModel
|
|
|
|
|
{
|
|
|
|
|
ShopName = shop.ShopName,
|
|
|
|
|
Flowers = new List<Tuple<string, int>>(),
|
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
|
|
|
|
foreach (var flower in shop.ShopFlowers)
|
|
|
|
|
{
|
|
|
|
|
record.Flowers.Add(new Tuple<string, int>(flower.Value.Item1.FlowerName, flower.Value.Item2));
|
|
|
|
|
record.TotalCount +=
|
|
|
|
|
flower.Value.Item2;
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
public List<ReportDateOrdersViewModel> GetDatesOrders()
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
DateOfOrders = x.Key,
|
|
|
|
|
Count = x.Count(),
|
|
|
|
|
Sum = x.Sum(y => y.Sum)
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
public void SaveDatesOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateReportDateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Заказы по датам",
|
|
|
|
|
DateOrders = GetDatesOrders()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public void SaveShopsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var tmp = _shopStorage.GetFullList();
|
|
|
|
|
_saveToWord.CreateTableDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список магазинов",
|
|
|
|
|
Shops = _shopStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public void SaveShopsFlowersToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateShopReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Загруженность магазинов",
|
|
|
|
|
ShopFlowers = GetShopsFlowers()
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-26 18:10:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|