2024-04-03 00:11:17 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using PrecastConcretePlantBusinessLogic.OfficePackage;
|
|
|
|
|
using PrecastConcretePlantBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using PrecastConcretePlantContracts.BindingModels;
|
|
|
|
|
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
|
|
|
|
using PrecastConcretePlantContracts.SearchModels;
|
|
|
|
|
using PrecastConcretePlantContracts.StoragesContracts;
|
|
|
|
|
using PrecastConcretePlantContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace PrecastConcretePlantBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IReinforcedStorage _reinforcedStorage;
|
|
|
|
|
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
|
2024-06-16 13:37:46 +04:00
|
|
|
|
private readonly IShopStorage _shopStorage;
|
|
|
|
|
|
2024-04-03 00:11:17 +04:00
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
|
|
2024-06-16 13:37:46 +04:00
|
|
|
|
public ReportLogic(IReinforcedStorage reinforcedStorage, IComponentStorage componentStorage, IShopStorage shopStorage, IOrderStorage orderStorage,
|
2024-04-03 00:11:17 +04:00
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
|
|
|
|
_reinforcedStorage = reinforcedStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
2024-06-16 13:37:46 +04:00
|
|
|
|
_shopStorage = shopStorage;
|
2024-04-03 00:11:17 +04:00
|
|
|
|
|
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ReportReinforcedComponentViewModel> GetReinforcedComponents()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var reinforceds = _reinforcedStorage.GetFullList();
|
|
|
|
|
|
|
|
|
|
var list = new List<ReportReinforcedComponentViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var reinforced in reinforceds)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportReinforcedComponentViewModel
|
|
|
|
|
{
|
|
|
|
|
ReinforcedName = reinforced.ReinforcedName,
|
|
|
|
|
Components = new List<(string Component, int Count)>(),
|
|
|
|
|
TotalCount = 0,
|
|
|
|
|
};
|
|
|
|
|
foreach (var component in reinforced.ReinforcedComponents)
|
|
|
|
|
{
|
|
|
|
|
record.Components.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
|
|
|
|
record.TotalCount += component.Value.Item2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 13:37:46 +04:00
|
|
|
|
public List<ReportShopReinforcedViewModel> GetShopReinforceds()
|
|
|
|
|
{
|
|
|
|
|
var shops = _shopStorage.GetFullList();
|
|
|
|
|
|
|
|
|
|
var list = new List<ReportShopReinforcedViewModel>();
|
|
|
|
|
|
|
|
|
|
foreach (var shop in shops)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportShopReinforcedViewModel
|
|
|
|
|
{
|
|
|
|
|
ShopName = shop.ShopName,
|
|
|
|
|
Reinforceds = new List<(string Reinforced, int Count)>(),
|
|
|
|
|
TotalCount = 0,
|
|
|
|
|
};
|
|
|
|
|
foreach (var reinforced in shop.ShopReinforceds)
|
|
|
|
|
{
|
|
|
|
|
record.Reinforceds.Add(new(reinforced.Value.Item1.ReinforcedName, reinforced.Value.Item2));
|
|
|
|
|
record.TotalCount += reinforced.Value.Item2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 00:11:17 +04:00
|
|
|
|
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,
|
|
|
|
|
ReinforcedName = x.ReinforcedName,
|
|
|
|
|
OrderStatus = x.Status.ToString(),
|
|
|
|
|
Sum = x.Sum
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 13:37:46 +04:00
|
|
|
|
public List<ReportOrdersByDateViewModel> GetGroupedByDateOrders()
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date)
|
|
|
|
|
.Select(x => new ReportOrdersByDateViewModel
|
|
|
|
|
{
|
|
|
|
|
Date = x.Key,
|
|
|
|
|
Count = x.Count(),
|
|
|
|
|
Sum = x.Sum(y => y.Sum)
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-03 00:11:17 +04:00
|
|
|
|
public void SaveReinforcedsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список изделий",
|
|
|
|
|
Reinforceds = _reinforcedStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 13:37:46 +04:00
|
|
|
|
public void SaveShopsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateShopsTable(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список магазинов",
|
|
|
|
|
Shops = _shopStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 00:11:17 +04:00
|
|
|
|
public void SaveReinforcedComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список изделий",
|
|
|
|
|
ReinforcedComponents = GetReinforcedComponents()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 13:37:46 +04:00
|
|
|
|
public void SaveShopReinforcedToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateShopReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Загруженность магазинов",
|
|
|
|
|
ShopReinforceds = GetShopReinforceds()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 00:11:17 +04:00
|
|
|
|
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-06-16 13:37:46 +04:00
|
|
|
|
|
|
|
|
|
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDocWithGroupedOrders(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Заказы по датам",
|
|
|
|
|
GroupedOrders = GetGroupedByDateOrders()
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-03 00:11:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|