2024-03-27 11:04:28 +04:00
|
|
|
|
using PlumbingRepairBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using PlumbingRepairBusinessLogic.OfficePackage;
|
|
|
|
|
using PlumbingRepairContracts.BindingModels;
|
|
|
|
|
using PlumbingRepairContracts.BusinessLogicsContracts;
|
|
|
|
|
using PlumbingRepairContracts.SearchModels;
|
|
|
|
|
using PlumbingRepairContracts.StoragesContracts;
|
|
|
|
|
using PlumbingRepairContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PlumbingRepairBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IWorkStorage _workStorage;
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
|
public ReportLogic (IWorkStorage workStorage, IComponentStorage
|
|
|
|
|
componentStorage, IOrderStorage orderStorage,
|
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
|
|
|
|
|
AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
|
|
|
|
_workStorage = workStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
2024-04-09 13:35:33 +04:00
|
|
|
|
|
2024-03-27 11:04:28 +04:00
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
2024-04-09 13:35:33 +04:00
|
|
|
|
public List<ReportWorkComponentViewModel> GetWorkComponent()
|
2024-03-27 11:04:28 +04:00
|
|
|
|
{
|
2024-04-09 13:35:33 +04:00
|
|
|
|
var Works = _workStorage.GetFullList();
|
|
|
|
|
|
2024-03-27 11:04:28 +04:00
|
|
|
|
var list = new List<ReportWorkComponentViewModel>();
|
2024-04-09 13:35:33 +04:00
|
|
|
|
|
|
|
|
|
foreach (var work in Works)
|
2024-03-27 11:04:28 +04:00
|
|
|
|
{
|
|
|
|
|
var record = new ReportWorkComponentViewModel
|
|
|
|
|
{
|
2024-04-09 13:35:33 +04:00
|
|
|
|
WorkName = work.WorkName,
|
|
|
|
|
Components = new List<(string Component, int Count)>(),
|
|
|
|
|
TotalCount = 0,
|
2024-03-27 11:04:28 +04:00
|
|
|
|
};
|
2024-04-09 13:35:33 +04:00
|
|
|
|
foreach (var component in work.WorkComponents)
|
2024-03-27 11:04:28 +04:00
|
|
|
|
{
|
2024-04-09 13:35:33 +04:00
|
|
|
|
record.Components.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
|
|
|
|
record.TotalCount += component.Value.Item2;
|
2024-03-27 11:04:28 +04:00
|
|
|
|
}
|
2024-04-09 13:35:33 +04:00
|
|
|
|
|
2024-03-27 11:04:28 +04:00
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
2024-04-09 13:35:33 +04:00
|
|
|
|
|
2024-03-27 11:04:28 +04:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
|
|
|
|
{
|
2024-04-09 13:35:33 +04:00
|
|
|
|
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
|
|
|
|
|
.Select(x => new ReportOrdersViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
DateCreate = x.DateCreate,
|
|
|
|
|
WorkName = x.WorkName,
|
|
|
|
|
OrderStatus = x.Status.ToString(),
|
|
|
|
|
Sum = x.Sum
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2024-03-27 11:04:28 +04:00
|
|
|
|
}
|
2024-04-09 13:35:33 +04:00
|
|
|
|
public void SaveWorksToWordFile(ReportBindingModel model)
|
2024-03-27 11:04:28 +04:00
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список компонент",
|
2024-04-09 13:35:33 +04:00
|
|
|
|
Works = _workStorage.GetFullList()
|
2024-03-27 11:04:28 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-09 13:35:33 +04:00
|
|
|
|
public void SaveWorkComponentToExcelFile(ReportBindingModel model)
|
2024-03-27 11:04:28 +04:00
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список компонент",
|
2024-04-09 13:35:33 +04:00
|
|
|
|
WorkComponents = GetWorkComponent()
|
2024-03-27 11:04:28 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов",
|
2024-04-10 01:01:51 +04:00
|
|
|
|
DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc),
|
|
|
|
|
DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc),
|
2024-03-27 11:04:28 +04:00
|
|
|
|
Orders = GetOrders(model)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|