2024-12-11 18:13:28 +04:00
|
|
|
|
using GasStation.Repositories;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace GasStation.Reports;
|
|
|
|
|
|
|
|
|
|
internal class DocReport
|
|
|
|
|
{
|
|
|
|
|
private readonly IGasmanRepository _gasmanRepository;
|
|
|
|
|
private readonly ISupplierRepository _supplierRepository;
|
|
|
|
|
private readonly IProductRepository _productRepository;
|
|
|
|
|
private readonly ILogger<DocReport> _logger;
|
|
|
|
|
|
|
|
|
|
public DocReport(IGasmanRepository gasmanRepository, ISupplierRepository supplierRepository,
|
|
|
|
|
IProductRepository productRepository, ILogger<DocReport> logger)
|
|
|
|
|
{
|
|
|
|
|
_gasmanRepository = gasmanRepository ??
|
|
|
|
|
throw new
|
|
|
|
|
ArgumentNullException(nameof(gasmanRepository));
|
|
|
|
|
_supplierRepository = supplierRepository ??
|
|
|
|
|
throw new ArgumentNullException(nameof(supplierRepository));
|
|
|
|
|
_productRepository = productRepository ??
|
|
|
|
|
throw new ArgumentNullException(nameof(productRepository));
|
|
|
|
|
_logger = logger ??
|
|
|
|
|
throw new ArgumentNullException(nameof(logger));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CreateDoc(string filePath, bool includeGasmen, bool includeSuppliers, bool includeProducts)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var builder = new WordBuilder(filePath)
|
|
|
|
|
.AddHeader("Документ со справочниками");
|
|
|
|
|
if (includeGasmen)
|
|
|
|
|
{
|
|
|
|
|
builder.AddParagraph("Запрвщики")
|
|
|
|
|
.AddTable([2400, 2400, 2400],
|
|
|
|
|
GetGasmen());
|
|
|
|
|
}
|
|
|
|
|
if (includeSuppliers)
|
|
|
|
|
{
|
|
|
|
|
builder.AddParagraph("Поставщики")
|
|
|
|
|
.AddTable([2400], GetSuppliers());
|
|
|
|
|
}
|
|
|
|
|
if (includeProducts)
|
|
|
|
|
{
|
|
|
|
|
builder.AddParagraph("Товары")
|
|
|
|
|
.AddTable([2400, 2400], GetProducts());
|
|
|
|
|
}
|
|
|
|
|
builder.Build();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка при формировании документа");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<string[]> GetGasmen()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
["Имя работника", "Телефон", "Должность"],
|
|
|
|
|
.. _gasmanRepository
|
|
|
|
|
.ReadGasman()
|
|
|
|
|
.Select(x => new string[] { x.GasmanName, x.PhoneNumber, x.Post.ToString() }),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<string[]> GetSuppliers()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
["Название поставщика"],
|
|
|
|
|
.. _supplierRepository
|
|
|
|
|
.ReadSupplier()
|
|
|
|
|
.Select(x => new string[] { x.SupplierName }),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<string[]> GetProducts()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2024-12-21 10:43:19 +04:00
|
|
|
|
["Стоимость товара", "Тип товара"],
|
2024-12-11 18:13:28 +04:00
|
|
|
|
.. _productRepository
|
|
|
|
|
.ReadProduct()
|
|
|
|
|
.Select(x => new string[] { x.ProductCost.ToString(), x.ProductType.ToString() }),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|