Логика отчетов
This commit is contained in:
parent
90050520d8
commit
17214cd823
110
LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
110
LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
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> GetProductComponent()
|
||||||
|
{
|
||||||
|
var blanks = _blankStorage.GetFullList();
|
||||||
|
var documents = _documentStorage.GetFullList();
|
||||||
|
var list = new List<ReportDocumentBlankViewModel>();
|
||||||
|
foreach (var blank in blanks)
|
||||||
|
{
|
||||||
|
var record = new ReportDocumentBlankViewModel
|
||||||
|
{
|
||||||
|
BlankName = blank.BlankName,
|
||||||
|
Documents = new List<(string Document, int Count)>(),
|
||||||
|
TotalCount = 0
|
||||||
|
};
|
||||||
|
foreach (var document in documents)
|
||||||
|
{
|
||||||
|
if (document.DocumentBlanks.ContainsKey(blank.Id))
|
||||||
|
{
|
||||||
|
record.Documents.Add((document.DocumentName, document.DocumentBlanks[blank.Id].Item2));
|
||||||
|
record.TotalCount += document.DocumentBlanks[blank.Id].Item2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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,
|
||||||
|
Sum = x.Sum
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
/// Сохранение компонент в файл-Word
|
||||||
|
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
_saveToWord.CreateDoc(new WordInfo
|
||||||
|
{
|
||||||
|
FileName = model.FileName,
|
||||||
|
Title = "Список бланков",
|
||||||
|
Blanks = _blankStorage.GetFullList()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
||||||
|
public void SaveProductComponentToExcelFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
_saveToExcel.CreateReport(new ExcelInfo
|
||||||
|
{
|
||||||
|
FileName = model.FileName,
|
||||||
|
Title = "Список бланков",
|
||||||
|
DocumentBlanks = GetProductComponent()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// Сохранение заказов в файл-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)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@ namespace LawFirmBusinessLogic.OfficePackage
|
|||||||
CellToName = "C1"
|
CellToName = "C1"
|
||||||
});
|
});
|
||||||
uint rowIndex = 2;
|
uint rowIndex = 2;
|
||||||
foreach (var pc in info.ProductComponents)
|
foreach (var pc in info.DocumentBlanks)
|
||||||
{
|
{
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,6 @@ namespace LawFirmBusinessLogic.OfficePackage.HelperModels
|
|||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string FileName { get; set; } = string.Empty;
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
public List<ReportDocumentBlankViewModel> ProductComponents { get; set; } = new();
|
public List<ReportDocumentBlankViewModel> DocumentBlanks { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user