CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs

99 lines
3.9 KiB
C#
Raw Normal View History

2024-06-01 02:22:36 +04:00
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;
2024-07-02 17:28:23 +04:00
private readonly IProductStorage _productstorage;
private readonly IOrderStorage _orderStorage;
2024-06-01 02:22:36 +04:00
private readonly AbstractSaveToExcelClient _saveToExcel;
private readonly AbstractSaveToWordClient _saveToWord;
2024-07-02 17:28:23 +04:00
public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient,
IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage) {
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-06-01 02:22:36 +04:00
}
2024-07-02 17:28:23 +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
// Получение списка товаров с указанием, в какие оплаты товар входит
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 void SavePaymeantToExcelFile(ReportBindingModel model, int _clientID)
2024-06-01 02:22:36 +04:00
{
_saveToExcel.CreateReport(new ExcelInfoClient
{
2024-07-02 17:28:23 +04:00
FileName = model.FileName,
2024-06-01 02:22:36 +04:00
Title = "Список оплат",
2024-07-02 17:28:23 +04:00
PaymeantProducts = GetPaymeantProducts(_clientID)
});
2024-06-01 02:22:36 +04:00
}
public void SavePaymeantToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfoClient
{
2024-06-06 17:21:39 +04:00
//FileName = model.ProductName,
2024-06-01 02:22:36 +04:00
Title = "Список оплат",
ListPaymeant = _paymeantstorage.GetFullList(),
}) ;
}
2024-07-02 17:28:23 +04:00
}
2024-06-01 02:22:36 +04:00
}