2024-03-25 01:48:14 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TypographyBusinessLogic.OfficePackage;
|
|
|
|
|
using TypographyBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using TypographyContracts.BindingModels;
|
|
|
|
|
using TypographyContracts.BusinessLogicsContracts;
|
|
|
|
|
using TypographyContracts.SearchModels;
|
|
|
|
|
using TypographyContracts.StoragesContracts;
|
|
|
|
|
using TypographyContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace TypographyBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
|
|
|
|
private readonly IPrintedStorage _printedStorage;
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
2024-05-18 03:40:04 +04:00
|
|
|
|
private readonly IShopStorage _shopStorage;
|
2024-03-25 01:48:14 +04:00
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
2024-05-18 03:40:04 +04:00
|
|
|
|
public ReportLogic(IPrintedStorage printedStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
2024-03-25 01:48:14 +04:00
|
|
|
|
{
|
|
|
|
|
_printedStorage = printedStorage;
|
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
2024-05-18 03:40:04 +04:00
|
|
|
|
_shopStorage = shopStorage;
|
2024-03-25 01:48:14 +04:00
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ReportPrintedComponentViewModel> GetPrintedComponents()
|
|
|
|
|
{
|
|
|
|
|
var printeds = _printedStorage.GetFullList();
|
|
|
|
|
var list = new List<ReportPrintedComponentViewModel>();
|
|
|
|
|
foreach (var printed in printeds)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportPrintedComponentViewModel
|
|
|
|
|
{
|
|
|
|
|
PrintedName = printed.PrintedName,
|
|
|
|
|
Components = new List<(string Component, int Count)>(),
|
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
|
|
|
|
foreach (var component in printed.PrintedComponents.Values)
|
|
|
|
|
{
|
|
|
|
|
record.Components.Add((component.Item1.ComponentName, component.Item2));
|
|
|
|
|
record.TotalCount += component.Item2;
|
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
PrintedName = x.PrintedName,
|
|
|
|
|
Sum = x.Sum,
|
|
|
|
|
Status = x.Status.ToString(),
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент в файл-Word
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SavePrintedsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список изделий",
|
|
|
|
|
Components = _componentStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SavePrintedComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список изделий",
|
|
|
|
|
PrintedComponents = GetPrintedComponents()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <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-05-18 03:40:04 +04:00
|
|
|
|
public void SaveShopsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateTableDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список магазинов",
|
|
|
|
|
Shops = _shopStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public void SaveShopPrintedsToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateShopReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Загруженность магазинов",
|
|
|
|
|
ShopPrinteds = GetShopPrinteds()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public List<ReportShopPrintedsViewModel> GetShopPrinteds()
|
|
|
|
|
{
|
|
|
|
|
var shops = _shopStorage.GetFullList();
|
|
|
|
|
var list = new List<ReportShopPrintedsViewModel>();
|
|
|
|
|
foreach (var shop in shops)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportShopPrintedsViewModel
|
|
|
|
|
{
|
|
|
|
|
ShopName = shop.ShopName,
|
|
|
|
|
Printeds = new List<Tuple<string, int>>(),
|
|
|
|
|
Count = 0
|
|
|
|
|
};
|
|
|
|
|
foreach (var carCount in shop.ShopPrinteds.Values)
|
|
|
|
|
{
|
|
|
|
|
record.Printeds.Add(new Tuple<string, int>(carCount.Item1.PrintedName, carCount.Item2));
|
|
|
|
|
record.Count += carCount.Item2;
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
public List<ReportDateOrdersViewModel> GetDateOrders()
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
DateCreate = x.Key,
|
|
|
|
|
CountOrders = x.Count(),
|
|
|
|
|
SumOrders = x.Sum(y => y.Sum)
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
public void SaveDateOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateReportDateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Заказы по датам",
|
|
|
|
|
DateOrders = GetDateOrders()
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-25 01:48:14 +04:00
|
|
|
|
}
|
|
|
|
|
}
|