2024-03-22 01:29:50 +04:00
|
|
|
|
using TravelCompanyBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using TravelCompanyBusinessLogic.OfficePackage;
|
|
|
|
|
using TravelCompanyContracts.BindingModels;
|
|
|
|
|
using TravelCompanyContracts.BusinessLogicsContracts;
|
|
|
|
|
using TravelCompanyContracts.SearchModels;
|
|
|
|
|
using TravelCompanyContracts.StoragesContracts;
|
|
|
|
|
using TravelCompanyContracts.ViewModels;
|
|
|
|
|
|
2024-05-02 23:20:19 +04:00
|
|
|
|
namespace TravelCompanyBusinessLogic.BusinessLogics
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
2024-03-22 19:04:16 +04:00
|
|
|
|
private readonly ITravelStorage _TravelStorage;
|
2024-03-22 01:29:50 +04:00
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
2024-05-02 23:20:19 +04:00
|
|
|
|
private readonly IShopStorage _shopStorage;
|
2024-03-22 01:29:50 +04:00
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
2024-05-02 23:20:19 +04:00
|
|
|
|
|
|
|
|
|
public ReportLogic(ITravelStorage TravelStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
|
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
2024-03-22 19:04:16 +04:00
|
|
|
|
_TravelStorage = TravelStorage;
|
2024-03-22 01:29:50 +04:00
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
2024-05-02 23:20:19 +04:00
|
|
|
|
_shopStorage = shopStorage;
|
|
|
|
|
|
2024-03-22 01:29:50 +04:00
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
2024-03-22 19:04:16 +04:00
|
|
|
|
|
|
|
|
|
public List<ReportTravelComponentViewModel> GetTravelComponents()
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
2024-05-02 23:20:19 +04:00
|
|
|
|
return _TravelStorage.GetFullList().Select(x => new ReportTravelComponentViewModel
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
2024-05-02 23:20:19 +04:00
|
|
|
|
TravelName = x.TravelName,
|
|
|
|
|
Components = x.TravelComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(),
|
|
|
|
|
TotalCount = x.TravelComponents.Select(x => x.Value.Item2).Sum()
|
|
|
|
|
}).ToList();
|
2024-03-22 01:29:50 +04:00
|
|
|
|
}
|
2024-03-22 19:04:16 +04:00
|
|
|
|
|
2024-03-22 01:29:50 +04:00
|
|
|
|
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
|
|
|
|
{
|
2024-05-02 23:20:19 +04:00
|
|
|
|
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
|
|
|
|
|
.Select(x => new ReportOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
DateCreate = x.DateCreate,
|
|
|
|
|
TravelName = x.TravelName,
|
|
|
|
|
Sum = x.Sum,
|
|
|
|
|
OrderStatus = x.Status.ToString()
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2024-03-22 01:29:50 +04:00
|
|
|
|
}
|
2024-03-22 19:04:16 +04:00
|
|
|
|
|
|
|
|
|
public void SaveTravelsToWordFile(ReportBindingModel model)
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
2024-05-02 23:20:19 +04:00
|
|
|
|
_saveToWord.CreateTravelDoc(new WordInfo
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-05-02 23:20:19 +04:00
|
|
|
|
Title = "Список путевок",
|
2024-03-22 19:04:16 +04:00
|
|
|
|
Travels = _TravelStorage.GetFullList()
|
2024-03-22 01:29:50 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-05-02 23:20:19 +04:00
|
|
|
|
|
2024-03-22 01:29:50 +04:00
|
|
|
|
public void SaveTravelComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-05-02 23:20:19 +04:00
|
|
|
|
Title = "Список путевок",
|
2024-03-22 19:04:16 +04:00
|
|
|
|
TravelComponents = GetTravelComponents()
|
2024-03-22 01:29:50 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-22 19:04:16 +04:00
|
|
|
|
|
2024-03-22 01:29:50 +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-03-22 19:04:16 +04:00
|
|
|
|
|
2024-05-02 23:20:19 +04:00
|
|
|
|
public List<ReportShopsViewModel> GetShops()
|
|
|
|
|
{
|
|
|
|
|
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
|
|
|
|
|
{
|
|
|
|
|
ShopName = x.ShopName,
|
|
|
|
|
Travels = x.ShopTravels.Select(x => (x.Value.Item1.TravelName, x.Value.Item2)).ToList(),
|
|
|
|
|
TotalCount = x.ShopTravels.Select(x => x.Value.Item2).Sum()
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ReportGroupOrdersViewModel> GetGroupedOrders()
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
Date = x.Key,
|
|
|
|
|
OrdersCount = x.Count(),
|
|
|
|
|
OrdersSum = x.Select(y => y.Sum).Sum()
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveShopsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateShopsDoc(new WordShopInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список магазинов",
|
|
|
|
|
Shops = _shopStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveShopsToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateShopTravelsReport(new ExcelShop
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Наполненость магазинов",
|
|
|
|
|
ShopTravels = GetShops()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов сгруппированных по дате заказов",
|
|
|
|
|
GroupedOrders = GetGroupedOrders()
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-22 01:29:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|