PIbd-23_Mochalov_D.V._LawFirm/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs

112 lines
4.4 KiB
C#
Raw Normal View History

2023-03-11 14:11:03 +04:00
using LawFirmBusinessLogic.OfficePackage;
using LawFirmBusinessLogic.OfficePackage.HelperModels;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IBlankStorage _blankStorage;
private readonly IDocumentStorage _documentStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IDocumentStorage documentStorage, IBlankStorage blankStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_documentStorage = documentStorage;
_blankStorage = blankStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
/// Получение списка компонент с указанием, в каких изделиях используются
public List<ReportDocumentBlankViewModel> GetDocumentBlanks()
2023-03-11 14:11:03 +04:00
{
var blanks = _blankStorage.GetFullList();
var documents = _documentStorage.GetFullList();
var list = new List<ReportDocumentBlankViewModel>();
foreach (var doc in documents)
2023-03-11 14:11:03 +04:00
{
var record = new ReportDocumentBlankViewModel
{
DocumentName = doc.DocumentName,
Blanks = new List<(string Blank, int Count)>(),
2023-03-11 14:11:03 +04:00
TotalCount = 0
};
foreach (var blank in blanks)
2023-03-11 14:11:03 +04:00
{
if (doc.DocumentBlanks.ContainsKey(blank.Id))
2023-03-11 14:11:03 +04:00
{
record.Blanks.Add(new (blank.BlankName, doc.DocumentBlanks[blank.Id].Item2));
record.TotalCount += doc.DocumentBlanks[blank.Id].Item2;
2023-03-11 14:11:03 +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,
DocumentName = x.DocumentName,
2023-03-11 20:51:58 +04:00
Sum = x.Sum,
Status = x.Status.ToString(),
2023-03-11 14:11:03 +04:00
})
.ToList();
}
/// Сохранение компонент в файл-Word
public void SaveDocumentsToWordFile(ReportBindingModel model)
2023-03-11 14:11:03 +04:00
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список документов",
Documents = _documentStorage.GetFullList()
2023-03-11 14:11:03 +04:00
});
}
/// Сохранение компонент с указаеним продуктов в файл-Excel
public void SaveProductComponentToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список документов",
DocumentBlanks = GetDocumentBlanks()
2023-03-11 14:11:03 +04:00
});
}
/// Сохранение заказов в файл-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)
});
}
}
}