170 lines
6.5 KiB
C#
170 lines
6.5 KiB
C#
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 IShopStorage _shopStorage;
|
||
private readonly AbstractSaveToExcel _saveToExcel;
|
||
private readonly AbstractSaveToWord _saveToWord;
|
||
private readonly AbstractSaveToPdf _saveToPdf;
|
||
public ReportLogic(IDocumentStorage documentStorage, IBlankStorage blankStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||
{
|
||
_documentStorage = documentStorage;
|
||
_blankStorage = blankStorage;
|
||
_orderStorage = orderStorage;
|
||
_shopStorage = shopStorage;
|
||
_saveToExcel = saveToExcel;
|
||
_saveToWord = saveToWord;
|
||
_saveToPdf = saveToPdf;
|
||
}
|
||
/// Получение списка компонент с указанием, в каких изделиях используются
|
||
public List<ReportDocumentBlankViewModel> GetDocumentBlanks()
|
||
{
|
||
var documents = _documentStorage.GetFullList();
|
||
var list = new List<ReportDocumentBlankViewModel>();
|
||
foreach (var doc in documents)
|
||
{
|
||
var record = new ReportDocumentBlankViewModel
|
||
{
|
||
DocumentName = doc.DocumentName,
|
||
Blanks = new List<(string Blank, int Count)>(),
|
||
TotalCount = 0
|
||
};
|
||
foreach (var blank in doc.DocumentBlanks.Values)
|
||
{
|
||
record.Blanks.Add((blank.Item1.BlankName, blank.Item2));
|
||
record.TotalCount += blank.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,
|
||
Status = x.Status.ToString(),
|
||
})
|
||
.ToList();
|
||
}
|
||
/// Сохранение компонент в файл-Word
|
||
public void SaveDocumentsToWordFile(ReportBindingModel model)
|
||
{
|
||
_saveToWord.CreateDoc(new WordInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список документов",
|
||
Documents = _documentStorage.GetFullList()
|
||
});
|
||
}
|
||
/// Сохранение компонент с указаеним продуктов в файл-Excel
|
||
public void SaveProductComponentToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveToExcel.CreateReport(new ExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список документов",
|
||
DocumentBlanks = GetDocumentBlanks()
|
||
});
|
||
}
|
||
/// Сохранение заказов в файл-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)
|
||
});
|
||
}
|
||
|
||
public void SaveShopsToWordFile(ReportBindingModel model)
|
||
{
|
||
_saveToWord.CreateTableDoc(new WordInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список магазинов",
|
||
Shops = _shopStorage.GetFullList()
|
||
});
|
||
}
|
||
public void SaveShopDocumentsToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveToExcel.CreateShopReport(new ExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Загруженность магазинов",
|
||
ShopDocuments = GetShopDocuments()
|
||
});
|
||
}
|
||
|
||
public List<ReportShopDocumentsViewModel> GetShopDocuments()
|
||
{
|
||
var shops = _shopStorage.GetFullList();
|
||
var list = new List<ReportShopDocumentsViewModel>();
|
||
foreach (var shop in shops)
|
||
{
|
||
var record = new ReportShopDocumentsViewModel
|
||
{
|
||
ShopName = shop.Name,
|
||
Documents = new List<Tuple<string, int>>(),
|
||
Count = 0
|
||
};
|
||
foreach (var docCount in shop.ShopDocuments.Values)
|
||
{
|
||
record.Documents.Add(new Tuple<string, int>(docCount.Item1.DocumentName, docCount.Item2));
|
||
record.Count += docCount.Item2;
|
||
}
|
||
list.Add(record);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
public List<ReportDateOrdersViewModel> GetDateOrders()
|
||
{
|
||
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel
|
||
{
|
||
DateCreate = x.Key,
|
||
CountOrders = x.Count(),
|
||
SumOrders = x.Sum(y => y.Sum)
|
||
}).ToList();
|
||
}
|
||
public void SaveDateOrdersToPdfFile(ReportBindingModel model)
|
||
{
|
||
_saveToPdf.CreateReportDateDoc(new PdfInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Заказы по датам",
|
||
DateOrders = GetDateOrders()
|
||
});
|
||
}
|
||
}
|
||
}
|