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;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace TravelCompanyBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
2024-03-22 19:04:16 +04:00
|
|
|
|
public ReportLogic(ITravelStorage TravelStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, 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;
|
|
|
|
|
_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
|
|
|
|
{
|
|
|
|
|
var components = _componentStorage.GetFullList();
|
2024-03-22 19:04:16 +04:00
|
|
|
|
var Travels = _TravelStorage.GetFullList();
|
2024-03-22 01:29:50 +04:00
|
|
|
|
var list = new List<ReportTravelComponentViewModel>();
|
2024-03-22 19:04:16 +04:00
|
|
|
|
foreach (var Travel in Travels)
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
|
|
|
|
var record = new ReportTravelComponentViewModel
|
|
|
|
|
{
|
2024-03-22 19:04:16 +04:00
|
|
|
|
TravelName = Travel.TravelName,
|
|
|
|
|
Components = new List<(string Component, int Count)>(),
|
2024-03-22 01:29:50 +04:00
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
2024-03-22 19:04:16 +04:00
|
|
|
|
foreach (var component in components)
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
2024-03-22 19:04:16 +04:00
|
|
|
|
if (Travel.TravelComponents.ContainsKey(component.Id))
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
2024-03-22 19:04:16 +04:00
|
|
|
|
record.Components.Add(new(component.ComponentName, Travel.TravelComponents[component.Id].Item2));
|
|
|
|
|
record.TotalCount += Travel.TravelComponents[component.Id].Item2;
|
2024-03-22 01:29:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2024-03-22 19:04:16 +04:00
|
|
|
|
|
2024-03-22 01:29:50 +04:00
|
|
|
|
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.GetFilteredList(new OrderSearchModel
|
|
|
|
|
{
|
2024-03-22 19:04:16 +04:00
|
|
|
|
DateFrom = model.DateFrom,
|
2024-03-22 01:29:50 +04:00
|
|
|
|
DateTo = model.DateTo
|
|
|
|
|
})
|
|
|
|
|
.Select(x => new ReportOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
DateCreate = x.DateCreate,
|
|
|
|
|
TravelName = x.TravelName,
|
2024-03-22 19:04:16 +04:00
|
|
|
|
Sum = x.Sum,
|
|
|
|
|
Status = x.Status.ToString(),
|
2024-03-22 01:29:50 +04:00
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2024-03-22 19:04:16 +04:00
|
|
|
|
|
|
|
|
|
public void SaveTravelsToWordFile(ReportBindingModel model)
|
2024-03-22 01:29:50 +04:00
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-03-22 19:04:16 +04:00
|
|
|
|
Title = "Список ЖИ",
|
|
|
|
|
Travels = _TravelStorage.GetFullList()
|
2024-03-22 01:29:50 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public void SaveTravelComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
2024-03-22 19:04:16 +04:00
|
|
|
|
Title = "Список ЖИ",
|
|
|
|
|
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-03-22 01:29:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|