using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TravelCompanyBusinessLogic.BusinessLogic.OfficePackage.HelperModels;
using TravelCompanyBusinessLogic.OfficePackage;
using TravelCompanyBusinessLogic.OfficePackage.HelperModels;
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.BusinessLogicsContracts;
using TravelCompanyContracts.SearchModels;
using TravelCompanyContracts.StoragesContracts;
using TravelCompanyContracts.ViewModels;
namespace TravelCompanyBusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IConditionStorage _conditionStorage;
private readonly ITravelStorage _travelStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ITravelStorage travelStorage, IConditionStorage
conditionStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
AbstractSaveToPdf saveToPdf)
{
_travelStorage = travelStorage;
_conditionStorage = conditionStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
///
/// Получение списка компонент с указанием, в каких изделиях используются
///
///
public List GetTravelCondition()
{
var conditions = _conditionStorage.GetFullList();
var travels = _travelStorage.GetFullList();
var list = new List();
foreach (var travel in travels)
{
var record = new ReportTravelConditionViewModel
{
TravelName = travel.TravelName,
Conditions = new List>(),
TotalCount = 0
};
foreach (var condition in conditions)
{
if (travel.TravelConditions.ContainsKey(condition.Id))
{
record.Conditions.Add(new(condition.ConditionName, travel.TravelConditions[condition.Id].Item2));
record.TotalCount +=
travel.TravelConditions[condition.Id].Item2;
}
}
list.Add(record);
}
return list;
}
///
/// Получение списка заказов за определенный период
///
///
///
public List GetOrders(ReportBindingModel model)
{
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,
Status = x.Status.ToString(),
})
.ToList();
}
///
/// Сохранение компонент в файл-Word
///
///
public void SaveTravelsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список путешествий",
Travels = _travelStorage.GetFullList()
});
}
///
/// Сохранение компонент с указаеним продуктов в файл-Excel
///
///
public void SaveTravelConditionToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список путешествий",
TravelConditions = GetTravelCondition()
});
}
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список заказов",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
});
}
}
}