CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs
Илья Федотов 1e4ea0c6d7 docx Report exp
2024-07-10 18:32:46 +04:00

95 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DocumentFormat.OpenXml.Packaging;
using ElectronicsShopBusinessLogic.OfficePackage;
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class ReportClientLogic : IReportClientLogic
{
private readonly IPaymeantStorage _paymeantstorage;
private readonly IProductStorage _productstorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcelClient _saveToExcel;
private readonly AbstractSaveToWordClient _saveToWord;
public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient,
IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage) {
_saveToExcel = abstractSaveToExcelClient;
_saveToWord= abstractSaveToWordClient;
_paymeantstorage = paymeantStorage;
_productstorage = productStorage;
_orderStorage = orderStorage;
}
// получение списка оплат за период
public List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model)
{
return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
DateFrom = model.DateFrom,
DateTo = model.DateTo
}).Select(x => new ReportPaymeantsViewModel {
ID = x.ID,
DatePaymeant = x.DatePaymeant,
OrderID = x.OrderID,
ClientID = x.ClientID,
SumPayment = x.SumPayment,
PayOption = x.PayOption,
}).ToList();
}
// Получение списка товаров с указанием, в какие оплаты товар входит
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID) {
var products = _productstorage.GetFullList();
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID });
var list = new List<ReportPaymeantProductsViewModel>();
foreach (var paymeant in paymeants) {
var record = new ReportPaymeantProductsViewModel {
PaymeantID = paymeant.ID,
Products = new(),
TotalCount = 0
};
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID });
if (order == null) {
continue;
}
foreach (var product in products) {
if (order.ProductList.ContainsKey(product.ID)) {
record.Products.Add(new(product.ProductName, order.ProductList[product.ID].Item2));
record.TotalCount += order.ProductList[product.ID].Item2;
}
}
list.Add(record);
}
return list;
}
public byte[] SavePaymeantToExcelFile(int _clientID)
{
var document = _saveToExcel.CreateReport(new ExcelInfoClient
{
Title = "Список оплат",
PaymeantProducts = GetPaymeantProducts(_clientID)
});
return document;
}
public byte[] SavePaymeantToWordFile(int _clientID)
{
var document = _saveToWord.CreateDoc(new WordInfoClient {
Title = "Список оплат",
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }),
});
return document;
}
}
}