Улучшайзинги 2 и 3
This commit is contained in:
parent
d8084733ab
commit
421b3d728f
@ -27,7 +27,7 @@ internal class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Поставки топлива")
|
.AddHeader("Поставки топлива")
|
||||||
.AddPieChart("Виды топлива", GetData(dateTime))
|
.AddPieChart($"Поставленные виды топлива на {dateTime:dd.MM.yyyy}", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -44,8 +44,7 @@ internal class ChartReport
|
|||||||
.ToDictionary(f => f.Id, f => f.Type);
|
.ToDictionary(f => f.Id, f => f.Type);
|
||||||
|
|
||||||
return _suppliersFuelRepository
|
return _suppliersFuelRepository
|
||||||
.ReadSuppliersFuels()
|
.ReadSuppliersFuels(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.Date.Date == dateTime.Date)
|
|
||||||
.SelectMany(x => x.SuppliersFuelFuel)
|
.SelectMany(x => x.SuppliersFuelFuel)
|
||||||
.GroupBy(x => x.FuelId)
|
.GroupBy(x => x.FuelId)
|
||||||
.Select(g => (Caption: fuelNames[g.Key].ToString(), Value: (double)g.Sum(x => x.Quantity)))
|
.Select(g => (Caption: fuelNames[g.Key].ToString(), Value: (double)g.Sum(x => x.Quantity)))
|
||||||
|
@ -30,7 +30,7 @@ internal class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по движению топлива", 0, 3)
|
.AddHeader("Сводка по движению топлива", 0, 3)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||||
.AddTable([10, 15, 15], GetData(fuelId, startDate, endDate))
|
.AddTable([10, 15, 15], GetData(fuelId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@ -42,31 +42,35 @@ internal class TableReport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<string[]> GetData(int fuelId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int fuelId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var suppliersData = _suppliersFuelRepository
|
var suppliersData = _suppliersFuelRepository
|
||||||
.ReadSuppliersFuels()
|
.ReadSuppliersFuels(startDate, endDate, fuelId)
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.SuppliersFuelFuel.Any(y => y.FuelId == fuelId))
|
.Select(x => new { x.Date, CountIn = x.SuppliersFuelFuel.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity, CountOut = (int?)null })
|
||||||
.Select(x => new { Date = x.Date, CountIn = x.SuppliersFuelFuel.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity, CountOut = (int?)null });
|
.Union(
|
||||||
|
_fuelSalesRepository
|
||||||
var salesData = _fuelSalesRepository
|
.ReadFuelSale(startDate, endDate, fuelId)
|
||||||
.ReadFuelSale()
|
.Select(x => new { Date = x.SaleDate, CountIn = (int?)null, CountOut = x.FuelFuelSale.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity })
|
||||||
.Where(x => x.SaleDate >= startDate && x.SaleDate <= endDate && x.FuelFuelSale.Any(y => y.FuelId == fuelId))
|
)
|
||||||
.Select(x => new { Date = x.SaleDate, CountIn = (int?)null, CountOut = x.FuelFuelSale.FirstOrDefault(y => y.FuelId == fuelId)?.Quantity });
|
|
||||||
|
|
||||||
var combinedData = suppliersData.Union(salesData)
|
|
||||||
.GroupBy(x => x.Date)
|
|
||||||
.Select(g => new { Date = g.Key, CountIn = g.Sum(x => x.CountIn ?? 0), CountOut = g.Sum(x => x.CountOut ?? 0) })
|
|
||||||
.OrderBy(x => x.Date);
|
.OrderBy(x => x.Date);
|
||||||
|
|
||||||
return new List<string[]>() { item }
|
var groupedData = suppliersData
|
||||||
|
.GroupBy(x => x.Date)
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
Date = g.Key,
|
||||||
|
TotalIn = g.Sum(x => x.CountIn),
|
||||||
|
TotalOut = g.Sum(x => x.CountOut)
|
||||||
|
})
|
||||||
|
.OrderBy(x => x.Date);
|
||||||
|
|
||||||
|
return
|
||||||
|
new List<string[]>() { item }
|
||||||
|
.Union(groupedData
|
||||||
|
.Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.TotalIn?.ToString("N0") ?? string.Empty, x.TotalOut?.ToString("N0") ?? string.Empty }))
|
||||||
.Union(
|
.Union(
|
||||||
combinedData
|
new[] { new string[] { "Всего", groupedData.Sum(x => x.TotalIn)?.ToString("N0") ?? string.Empty, groupedData.Sum(x => x.TotalOut)?.ToString("N0") ?? string.Empty } }
|
||||||
.Select(x => new string[] { x.Date.ToString(), x.CountIn.ToString(), x.CountOut.ToString() }))
|
)
|
||||||
.Union(
|
|
||||||
new List<string[]>() { new string[] { "Всего", combinedData.Sum(x => x.CountIn).ToString(), combinedData.Sum(x => x.CountOut).ToString() } })
|
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -97,8 +97,22 @@ public class FuelSalesRepository : IFuelSalesRepository
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("fs.SaleDate >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("fs.SaleDate <= @dateTo");
|
||||||
|
}
|
||||||
|
if (fuelId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ffs.FuelId = @fuelId");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT
|
var querySelect = $@"SELECT
|
||||||
fs.*,
|
fs.*,
|
||||||
CONCAT(s.LastName, ' ', s.FirstName) as CashierName,
|
CONCAT(s.LastName, ' ', s.FirstName) as CashierName,
|
||||||
ffs.FuelId,
|
ffs.FuelId,
|
||||||
@ -107,7 +121,8 @@ public class FuelSalesRepository : IFuelSalesRepository
|
|||||||
FROM FuelSale fs
|
FROM FuelSale fs
|
||||||
LEFT JOIN Cashier s on s.Id = fs.CashierId
|
LEFT JOIN Cashier s on s.Id = fs.CashierId
|
||||||
INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id
|
INNER JOIN FuelFuelSale ffs on ffs.FuelSaleId = fs.Id
|
||||||
LEFT JOIN Fuel f on f.id = ffs.FuelId";
|
LEFT JOIN Fuel f on f.id = ffs.FuelId
|
||||||
|
{builder.Build()}";
|
||||||
var salesDict = new Dictionary<int, List<FuelFuelSale>>();
|
var salesDict = new Dictionary<int, List<FuelFuelSale>>();
|
||||||
|
|
||||||
var fuelSales = connection.Query<FuelSale, FuelFuelSale, FuelSale>(querySelect,
|
var fuelSales = connection.Query<FuelSale, FuelFuelSale, FuelSale>(querySelect,
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace GasStation.Repositories.Implementations;
|
||||||
|
|
||||||
|
internal class QueryBuilder
|
||||||
|
{
|
||||||
|
private readonly StringBuilder _builder;
|
||||||
|
|
||||||
|
public QueryBuilder()
|
||||||
|
{
|
||||||
|
_builder = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryBuilder AddCondition(string condition)
|
||||||
|
{
|
||||||
|
if (_builder.Length > 0)
|
||||||
|
{
|
||||||
|
_builder.Append(" AND ");
|
||||||
|
}
|
||||||
|
|
||||||
|
_builder.Append(condition);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Build()
|
||||||
|
{
|
||||||
|
if (_builder.Length == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"WHERE {_builder}";
|
||||||
|
}
|
||||||
|
}
|
@ -94,8 +94,22 @@ public class SuppliersFuelRepository : ISuppliersFuelRepository
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cf.Date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cf.Date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (fuelId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cff.FuelId = @fuelId");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT
|
var querySelect = $@"SELECT
|
||||||
cf.*,
|
cf.*,
|
||||||
c.Brand as SuppliersBrand,
|
c.Brand as SuppliersBrand,
|
||||||
cff.FuelId,
|
cff.FuelId,
|
||||||
@ -104,7 +118,8 @@ public class SuppliersFuelRepository : ISuppliersFuelRepository
|
|||||||
FROM SuppliersFuel cf
|
FROM SuppliersFuel cf
|
||||||
LEFT JOIN Supplier c on c.Id = cf.SuppliersId
|
LEFT JOIN Supplier c on c.Id = cf.SuppliersId
|
||||||
INNER JOIN SuppliersFuelFuel cff on cff.SuppliersFuelId = cf.Id
|
INNER JOIN SuppliersFuelFuel cff on cff.SuppliersFuelId = cf.Id
|
||||||
LEFT JOIN Fuel f on f.Id = cff.FuelId";
|
LEFT JOIN Fuel f on f.Id = cff.FuelId
|
||||||
|
{builder.Build()}";
|
||||||
|
|
||||||
var suppliersDict = new Dictionary<int, List<SuppliersFuelFuel>>();
|
var suppliersDict = new Dictionary<int, List<SuppliersFuelFuel>>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user