2023-03-13 00:05:47 +04:00
|
|
|
|
using AutomobilePlantBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using AutomobilePlantBusinessLogic.OfficePackage;
|
|
|
|
|
using AutomobilePlantContracts.BindingModels;
|
|
|
|
|
using AutomobilePlantContracts.BusinessLogicContracts;
|
|
|
|
|
using AutomobilePlantContracts.SearchModels;
|
|
|
|
|
using AutomobilePlantContracts.StorageContracts;
|
|
|
|
|
using AutomobilePlantContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
|
|
|
|
private readonly ICarStorage _carStorage;
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
|
public ReportLogic(ICarStorage carStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
|
|
|
|
_carStorage = carStorage;
|
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
/// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
public List<ReportCarComponentViewModel> GetCarComponents()
|
|
|
|
|
{
|
|
|
|
|
var cars = _carStorage.GetFullList();
|
|
|
|
|
var list = new List<ReportCarComponentViewModel>();
|
|
|
|
|
foreach (var car in cars)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportCarComponentViewModel
|
|
|
|
|
{
|
|
|
|
|
CarName = car.CarName,
|
|
|
|
|
Components = new List<(string Component, int Count)>(),
|
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
2023-04-09 21:34:28 +04:00
|
|
|
|
foreach (var component in car.CarComponents.Values)
|
2023-03-13 00:05:47 +04:00
|
|
|
|
{
|
2023-04-09 21:34:28 +04:00
|
|
|
|
record.Components.Add((component.Item1.ComponentName, component.Item2));
|
|
|
|
|
record.TotalCount += component.Item2;
|
2023-03-13 00:05:47 +04:00
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
CarName = x.CarName,
|
|
|
|
|
Sum = x.Sum,
|
|
|
|
|
Status = x.Status.ToString(),
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
/// Сохранение компонент в файл-Word
|
|
|
|
|
public void SaveCarsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список автомобилей",
|
|
|
|
|
Cars = _carStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
|
|
|
|
public void SaveCarComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список автомобилей",
|
|
|
|
|
CarComponents = GetCarComponents()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// Сохранение заказов в файл-Pdf
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
|
|
|
|
Orders = GetOrders(model)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|