171 lines
6.3 KiB
C#
171 lines
6.3 KiB
C#
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 IShopStorage _shopStorage;
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
public ReportLogic(IIceCreamStorage iceCreamStorage, IComponentStorage
|
|
componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
|
|
AbstractSaveToPdf saveToPdf)
|
|
{
|
|
_iceCreamStorage = iceCreamStorage;
|
|
_componentStorage = componentStorage;
|
|
_orderStorage = orderStorage;
|
|
_shopStorage = shopStorage;
|
|
_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<ReportShopIceCreamViewModel> GetShopsIceCreams()
|
|
{
|
|
var shops = _shopStorage.GetFullList();
|
|
var list = new List<ReportShopIceCreamViewModel>();
|
|
foreach (var shop in shops)
|
|
{
|
|
var record = new ReportShopIceCreamViewModel
|
|
{
|
|
ShopName = shop.ShopName,
|
|
IceCreams = new List<Tuple<string, int>>(),
|
|
TotalCount = 0
|
|
};
|
|
foreach (var iceCream in shop.ShopIceCreams)
|
|
{
|
|
record.IceCreams.Add(new Tuple<string,
|
|
int>(iceCream.Value.Item1.IceCreamName, iceCream.Value.Item2));
|
|
record.TotalCount +=
|
|
iceCream.Value.Item2;
|
|
}
|
|
list.Add(record);
|
|
}
|
|
return list;
|
|
}
|
|
public List<ReportDateOrdersViewModel> GetDatesOrders()
|
|
{
|
|
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel
|
|
{
|
|
DateOfOrders = x.Key,
|
|
Count = x.Count(),
|
|
Sum = x.Sum(y => y.Sum)
|
|
}).ToList();
|
|
}
|
|
public void SaveDatesOrdersToPdfFile(ReportBindingModel model)
|
|
{
|
|
_saveToPdf.CreateReportDateDoc(new PdfInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Заказы по датам",
|
|
DateOrders = GetDatesOrders()
|
|
});
|
|
}
|
|
public void SaveShopsToWordFile(ReportBindingModel model)
|
|
{
|
|
var tmp = _shopStorage.GetFullList();
|
|
_saveToWord.CreateTableDoc(new WordInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Список магазинов",
|
|
Shops = _shopStorage.GetFullList()
|
|
});
|
|
}
|
|
public void SaveShopsIceCreamsToExcelFile(ReportBindingModel model)
|
|
{
|
|
_saveToExcel.CreateShopReport(new ExcelInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Загруженность магазинов",
|
|
ShopIceCreams = GetShopsIceCreams()
|
|
});
|
|
}
|
|
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();
|
|
}
|
|
public void SaveIceCreamToWordFile(ReportBindingModel model)
|
|
{
|
|
_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)
|
|
});
|
|
}
|
|
}
|
|
}
|