2024-03-24 13:36:55 +04:00
|
|
|
|
using IceCreamShopBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using IceCreamShopBusinessLogic.OfficePackage;
|
|
|
|
|
using IceCreamShopContracts.BindingModels;
|
|
|
|
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
|
|
|
|
using IceCreamShopContracts.SearchModels;
|
|
|
|
|
using IceCreamShopContracts.StoragesContracts;
|
|
|
|
|
using IceCreamShopContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace IceCreamShopBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
|
|
|
|
private readonly IIceCreamStorage _iceCreamStorage;
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
|
public ReportLogic(IIceCreamStorage iceCreamStorage, IComponentStorage
|
|
|
|
|
componentStorage, IOrderStorage orderStorage,
|
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
|
|
|
|
|
AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
|
|
|
|
_iceCreamStorage = iceCreamStorage;
|
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
public List<ReportIceCreamComponentViewModel> GetIceCreamComponent()
|
|
|
|
|
{
|
|
|
|
|
var iceCreams = _iceCreamStorage.GetFullList();
|
|
|
|
|
var list = new List<ReportIceCreamComponentViewModel>();
|
|
|
|
|
foreach (var iceCream in iceCreams)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportIceCreamComponentViewModel
|
|
|
|
|
{
|
|
|
|
|
IceCreamName = iceCream.IceCreamName,
|
|
|
|
|
Components = new List<Tuple<string, int>>(),
|
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
|
|
|
|
foreach (var component in iceCream.IceCreamComponents)
|
|
|
|
|
{
|
|
|
|
|
record.Components.Add(new Tuple<string,
|
|
|
|
|
int>(component.Value.Item1.ComponentName, component.Value.Item2));
|
|
|
|
|
record.TotalCount +=
|
|
|
|
|
component.Value.Item2;
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
IceCreamName = x.IceCreamName,
|
|
|
|
|
OrderStatus = x.Status.ToString(),
|
|
|
|
|
Sum = x.Sum
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2024-03-24 15:07:49 +04:00
|
|
|
|
public void SaveIceCreamsToWordFile(ReportBindingModel model)
|
2024-03-24 13:36:55 +04:00
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список мороженного",
|
|
|
|
|
IceCreams = _iceCreamStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public void SaveIceCreamComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список мороженного",
|
|
|
|
|
IceCreamComponents = GetIceCreamComponent()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
|
|
|
|
Orders = GetOrders(model)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|