2024-07-09 19:40:24 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
|
|
|
using ElectronicsShopBusinessLogic.OfficePackage;
|
2024-06-01 02:22:36 +04:00
|
|
|
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
|
|
|
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
|
|
|
|
using ElectronicsShopContracts.SearchModels;
|
|
|
|
|
using ElectronicsShopContracts.StorageContracts;
|
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
2024-07-23 20:29:10 +04:00
|
|
|
|
using MigraDoc.DocumentObjectModel;
|
|
|
|
|
using PdfSharp.Pdf;
|
|
|
|
|
using System.Collections.Generic;
|
2024-06-01 02:22:36 +04:00
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class ReportClientLogic : IReportClientLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IPaymeantStorage _paymeantstorage;
|
2024-07-02 17:28:23 +04:00
|
|
|
|
private readonly IProductStorage _productstorage;
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
2024-07-23 20:29:10 +04:00
|
|
|
|
private readonly ICostItemStorage _costItemStorage;
|
2024-06-01 02:22:36 +04:00
|
|
|
|
private readonly AbstractSaveToExcelClient _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWordClient _saveToWord;
|
2024-07-23 20:29:10 +04:00
|
|
|
|
private readonly AbstractSaveToPdfClient _saveToPdf;
|
2024-06-01 02:22:36 +04:00
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient,
|
2024-07-23 20:29:10 +04:00
|
|
|
|
IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage,
|
|
|
|
|
AbstractSaveToPdfClient abstractSaveToPdfClient, ICostItemStorage costItemStorage) {
|
2024-06-01 02:22:36 +04:00
|
|
|
|
_saveToExcel = abstractSaveToExcelClient;
|
|
|
|
|
_saveToWord= abstractSaveToWordClient;
|
2024-06-01 05:27:52 +04:00
|
|
|
|
_paymeantstorage = paymeantStorage;
|
2024-07-02 17:28:23 +04:00
|
|
|
|
_productstorage = productStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
2024-07-23 20:29:10 +04:00
|
|
|
|
_costItemStorage = costItemStorage;
|
|
|
|
|
_saveToPdf = abstractSaveToPdfClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Получение списка оплаченных товаров за период
|
2024-08-07 21:48:54 +04:00
|
|
|
|
public List<ReportProductsViewModel>? GetProducts (ReportBindingModel? model = null, List<PaymeantViewModel>? paymeants = null) {
|
|
|
|
|
|
|
|
|
|
List<PaymeantViewModel> paymeantList = new();
|
|
|
|
|
|
|
|
|
|
if (model != null) {
|
|
|
|
|
paymeantList = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
|
|
|
|
ClientID = model.ClientID,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (paymeants != null){
|
|
|
|
|
paymeantList = paymeants;
|
|
|
|
|
}
|
2024-07-23 20:29:10 +04:00
|
|
|
|
|
|
|
|
|
List<ReportProductsViewModel>? products = new();
|
|
|
|
|
|
2024-07-26 12:41:39 +04:00
|
|
|
|
|
2024-08-07 21:48:54 +04:00
|
|
|
|
foreach (var paymeant in paymeantList) {
|
2024-07-26 12:41:39 +04:00
|
|
|
|
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID })
|
|
|
|
|
?? throw new Exception("Ошибка полуения данных");
|
|
|
|
|
|
|
|
|
|
foreach (var product in order.ProductList) {
|
2024-07-23 20:29:10 +04:00
|
|
|
|
products.Add(new ReportProductsViewModel {
|
|
|
|
|
ID = product.Value.Item1.ID,
|
|
|
|
|
ProductName = product.Value.Item1.ProductName,
|
|
|
|
|
Price = product.Value.Item1.Price,
|
2024-07-24 13:02:15 +04:00
|
|
|
|
CostItemName = _costItemStorage.GetElement(new CostItemSearchModel { ID = product.Value.Item1.CostItemID })?.Name
|
2024-07-27 14:58:51 +04:00
|
|
|
|
?? "Отсутствует",
|
|
|
|
|
PaymentID = paymeant.ID,
|
|
|
|
|
count = product.Value.Item2
|
2024-07-23 20:29:10 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return products;
|
2024-06-01 02:22:36 +04:00
|
|
|
|
}
|
2024-07-02 17:28:23 +04:00
|
|
|
|
|
2024-08-07 21:48:54 +04:00
|
|
|
|
public List<ReportProductsViewModel>? GetProductsFix(List<PaymeantViewModel> paymeants) {
|
|
|
|
|
|
|
|
|
|
List<ReportProductsViewModel>? products = new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var paymeant in paymeants) {
|
|
|
|
|
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID })
|
|
|
|
|
?? throw new Exception("Ошибка полуения данных");
|
|
|
|
|
|
|
|
|
|
foreach (var product in order.ProductList) {
|
|
|
|
|
products.Add(new ReportProductsViewModel {
|
|
|
|
|
ID = product.Value.Item1.ID,
|
|
|
|
|
ProductName = product.Value.Item1.ProductName,
|
|
|
|
|
Price = product.Value.Item1.Price,
|
|
|
|
|
CostItemName = _costItemStorage.GetElement(new CostItemSearchModel { ID = product.Value.Item1.CostItemID })?.Name
|
|
|
|
|
?? "Отсутствует",
|
|
|
|
|
PaymentID = paymeant.ID,
|
|
|
|
|
count = product.Value.Item2
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return products;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// получение списка оплат за период
|
2024-07-23 20:29:10 +04:00
|
|
|
|
public List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model)
|
2024-06-01 02:22:36 +04:00
|
|
|
|
{
|
2024-06-06 17:21:39 +04:00
|
|
|
|
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();
|
2024-06-01 02:22:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
// Получение списка товаров с указанием, в какие оплаты товар входит
|
2024-08-08 16:12:26 +04:00
|
|
|
|
public List<ReportPaymeantProductsViewModel> GetPaymeantProducts(List<PaymeantViewModel> paymeants) {
|
2024-07-26 12:41:39 +04:00
|
|
|
|
|
2024-07-02 17:28:23 +04:00
|
|
|
|
var list = new List<ReportPaymeantProductsViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var paymeant in paymeants) {
|
|
|
|
|
var record = new ReportPaymeantProductsViewModel {
|
|
|
|
|
PaymeantID = paymeant.ID,
|
|
|
|
|
Products = new(),
|
2024-07-27 13:38:35 +04:00
|
|
|
|
TotalCount = 0,
|
|
|
|
|
PaymeantPrice = paymeant.SumPayment,
|
2024-07-02 17:28:23 +04:00
|
|
|
|
};
|
|
|
|
|
|
2024-07-27 12:48:31 +04:00
|
|
|
|
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID })
|
|
|
|
|
?? throw new Exception("Ошибка полуения данных");
|
2024-07-02 17:28:23 +04:00
|
|
|
|
|
2024-07-27 12:48:31 +04:00
|
|
|
|
foreach (var product in order.ProductList) {
|
2024-07-27 13:38:35 +04:00
|
|
|
|
record.Products.Add(new(product.Value.Item1.ProductName, product.Value.Item2,
|
|
|
|
|
_costItemStorage.GetElement (new CostItemSearchModel { ID = product.Value.Item1.CostItemID})?.Name ??
|
|
|
|
|
throw new Exception("Ошиюак получения данных"),
|
|
|
|
|
product.Value.Item1.Price * product.Value.Item2));
|
2024-07-27 12:48:31 +04:00
|
|
|
|
record.TotalCount += product.Value.Item2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.Add(record);
|
2024-07-02 17:28:23 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 16:12:26 +04:00
|
|
|
|
public byte[]? SavePaymeantToExcelFile(List<PaymeantViewModel> paymeants)
|
2024-06-01 02:22:36 +04:00
|
|
|
|
{
|
2024-07-09 19:40:24 +04:00
|
|
|
|
var document = _saveToExcel.CreateReport(new ExcelInfoClient
|
2024-06-01 02:22:36 +04:00
|
|
|
|
{
|
2024-07-27 14:00:54 +04:00
|
|
|
|
Title = "Список оплат и товаров",
|
2024-08-08 16:12:26 +04:00
|
|
|
|
PaymeantProducts = GetPaymeantProducts(paymeants),
|
2024-07-02 17:28:23 +04:00
|
|
|
|
});
|
2024-07-09 19:40:24 +04:00
|
|
|
|
return document;
|
2024-06-01 02:22:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 21:48:54 +04:00
|
|
|
|
public byte[]? SavePaymeantToWordFile(List<PaymeantViewModel> paymeants)
|
2024-06-01 02:22:36 +04:00
|
|
|
|
{
|
2024-07-10 18:32:46 +04:00
|
|
|
|
var document = _saveToWord.CreateDoc(new WordInfoClient {
|
2024-07-27 14:00:54 +04:00
|
|
|
|
Title = "Список оплат",
|
2024-08-07 21:48:54 +04:00
|
|
|
|
Products = GetProductsFix(paymeants)
|
2024-07-10 18:32:46 +04:00
|
|
|
|
});
|
|
|
|
|
return document;
|
2024-06-01 02:22:36 +04:00
|
|
|
|
}
|
2024-07-23 20:29:10 +04:00
|
|
|
|
|
|
|
|
|
public PdfDocument SaveProductToPdfFile(ReportBindingModel model) {
|
|
|
|
|
var document = _saveToPdf.CreteDoc(new PdfInfoClient {
|
|
|
|
|
Title = "Список оплаченных товаров",
|
|
|
|
|
FileName = "Report",
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
|
|
|
|
Products = GetProducts(model)
|
|
|
|
|
});
|
|
|
|
|
return document;
|
|
|
|
|
}
|
2024-07-02 17:28:23 +04:00
|
|
|
|
}
|
2024-07-09 19:40:24 +04:00
|
|
|
|
}
|