2024-03-24 00:36:52 +04:00
|
|
|
|
using AbstractLawFirmBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using AbstractLawFirmBusinessLogic.OfficePackage;
|
|
|
|
|
using AbstractLawFirmContracts.BindingModels;
|
|
|
|
|
using AbstractLawFirmContracts.BusinessLogicsContracts;
|
|
|
|
|
using AbstractLawFirmContracts.SearchModels;
|
|
|
|
|
using AbstractLawFirmContracts.StoragesContracts;
|
|
|
|
|
using AbstractLawFirmContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AbstractLawFirmBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IComponentStorage _componentStorage;
|
|
|
|
|
private readonly IDocumentStorage _documentStorage;
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
|
public ReportLogic(IDocumentStorage documentStorage, IComponentStorage
|
|
|
|
|
componentStorage, IOrderStorage orderStorage,
|
|
|
|
|
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
|
|
|
|
|
AbstractSaveToPdf saveToPdf)
|
|
|
|
|
{
|
|
|
|
|
_documentStorage = documentStorage;
|
|
|
|
|
_componentStorage = componentStorage;
|
|
|
|
|
_orderStorage = orderStorage;
|
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка компонент с указанием, в каких изделиях используются
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ReportDocumentComponentViewModel> GetDocumentComponent()
|
|
|
|
|
{
|
2024-03-25 11:07:44 +04:00
|
|
|
|
var documents = _documentStorage.GetFullList();
|
2024-03-24 00:36:52 +04:00
|
|
|
|
var list = new List<ReportDocumentComponentViewModel>();
|
2024-03-25 11:07:44 +04:00
|
|
|
|
foreach (var document in documents)
|
2024-03-24 00:36:52 +04:00
|
|
|
|
{
|
|
|
|
|
var record = new ReportDocumentComponentViewModel
|
|
|
|
|
{
|
2024-03-25 11:07:44 +04:00
|
|
|
|
DocumentName = document.DocumentName,
|
|
|
|
|
Components = new List<(string Component, int Count)>(),
|
2024-03-24 00:36:52 +04:00
|
|
|
|
TotalCount = 0
|
|
|
|
|
};
|
2024-03-25 11:07:44 +04:00
|
|
|
|
foreach (var component in document.DocumentComponents.Values)
|
2024-03-24 00:36:52 +04:00
|
|
|
|
{
|
2024-03-25 11:07:44 +04:00
|
|
|
|
record.Components.Add((component.Item1.ComponentName, component.Item2));
|
|
|
|
|
record.TotalCount += component.Item2;
|
2024-03-24 00:36:52 +04:00
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение списка заказов за определенный период
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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,
|
|
|
|
|
DocumentName = x.DocumentName,
|
2024-03-24 19:08:21 +04:00
|
|
|
|
Sum = x.Sum,
|
|
|
|
|
Status = x.Status.ToString(),
|
2024-03-24 00:36:52 +04:00
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент в файл-Word
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveDocumentsToWordFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список пакетов документов",
|
|
|
|
|
Documents = _documentStorage.GetFullList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveDocumentComponentToExcelFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список компонент",
|
|
|
|
|
DocumentComponents = GetDocumentComponent()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохранение заказов в файл-Pdf
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заказов",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
|
|
|
|
Orders = GetOrders(model)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|