PIbd-24 Antonova A.A. LabWork_4 #4
@ -45,14 +45,16 @@ public class TableReport
|
||||
|
||||
private List<string[]> GetData(int productID, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var erte = _invoiceRepository
|
||||
.ReadInvoices(startDate, endDate, productID);
|
||||
var data = _invoiceRepository
|
||||
.ReadInvoices(startDate, endDate)
|
||||
.Select(x => new {x.Products.FirstOrDefault(y => y.ProductID == productID).ProductName, Date = x.DateInvoice, CountIn = (int?)null, CountOut =(int?) x.Products.FirstOrDefault(y => y.ProductID == productID)?.Count })
|
||||
.ReadInvoices(startDate, endDate, productID)
|
||||
.Select(x => new {x.Products.FirstOrDefault(y => y.ProductID == productID)?.ProductName, Date = x.DateInvoice, CountIn = (int?)null, CountOut =(int?) x.Products.FirstOrDefault(y => y.ProductID == productID)?.Count })
|
||||
.Union(
|
||||
_productMovementRepository
|
||||
.ReadProductMovements(startDate, endDate, productID)
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.ProductID == productID && x.MovementType == Movement.Reseipt)
|
||||
.Select(x => new {x.ProductName, x.Date, CountIn = (int?)x.Count, CountOut = (int?)null }))
|
||||
.Select(x => new {x?.ProductName, x.Date, CountIn = (int?)x.Count, CountOut = (int?)null }))
|
||||
.OrderBy(x => x.Date);
|
||||
return
|
||||
new List<string[]>() { item }
|
||||
|
@ -9,7 +9,7 @@ namespace ProjectCompanyFurniture.Repositories;
|
||||
|
||||
public interface IInvoiceRepository
|
||||
{
|
||||
IEnumerable<Invoice> ReadInvoices (DateTime? dateForm = null, DateTime? dateTo = null, int? clientId = null);
|
||||
IEnumerable<Invoice> ReadInvoices (DateTime? dateForm = null, DateTime? dateTo = null, int? productID = null);
|
||||
void CreateInvoice(Invoice invoice);
|
||||
void DeleteInvoice(int id);
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class InvoiceRepository : IInvoiceRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Invoice> ReadInvoices(DateTime? dateForm = null, DateTime? dateTo = null, int? clientID = null)
|
||||
public IEnumerable<Invoice> ReadInvoices(DateTime? dateForm = null, DateTime? dateTo = null, int? productID = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
@ -90,16 +90,17 @@ public class InvoiceRepository : IInvoiceRepository
|
||||
{
|
||||
builder.AddCondition("inv.DateInvoice <= @dateTo");
|
||||
}
|
||||
if (clientID.HasValue)
|
||||
if (productID.HasValue)
|
||||
{
|
||||
builder.AddCondition("inv.ClientID = @clientID");
|
||||
// builder.AddCondition("ipr.ProductID = @productID");
|
||||
}
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @$"SELECT inv.*, cl.Name as ClientName, ipr.ProductID, ipr.Count
|
||||
var querySelect = @$"SELECT inv.*, cl.Name as ClientName, ipr.ProductID, ipr.Count, pr.Name as ProductName
|
||||
FROM Invoices inv
|
||||
INNER JOIN InvoiceProducts ipr ON ipr.InvoiceID = inv.ID
|
||||
INNER JOIN InvoiceProducts ipr ON ipr.InvoiceID = inv.ID AND ipr.ProductID = @productID
|
||||
INNER JOIN Clients cl ON inv.ClientID = cl.ID
|
||||
INNER JOIN Products pr ON pr.ID = ipr.ProductID
|
||||
{builder.Build()}";
|
||||
var productDict = new Dictionary<int, List<InvoiceProduct>>();
|
||||
var invoices = connection.Query<Invoice, InvoiceProduct, Invoice>(querySelect,
|
||||
@ -112,7 +113,7 @@ public class InvoiceRepository : IInvoiceRepository
|
||||
}
|
||||
pr.Add(invoiceProducts);
|
||||
return invoice;
|
||||
}, splitOn: "ProductID", param: new {dateForm, dateTo, clientID});
|
||||
}, splitOn: "ProductID", param: new {dateForm, dateTo, productID});
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(invoices));
|
||||
|
||||
|
@ -62,9 +62,12 @@ public class ProductMovementRepository : IProductMovementRepository
|
||||
}
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @$"SELECT pm.* FROM ProductMovements pm
|
||||
var querySelect = @$"SELECT pm.*, pr.Name as ProductName
|
||||
FROM ProductMovements pm
|
||||
INNER JOIN Products pr ON pm.ProductID = pr.ID
|
||||
{builder.Build()}";
|
||||
|
||||
|
||||
var productMovements = connection.Query<ProductMovement>(querySelect, new {dateForm, dateTo, productID});
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(productMovements));
|
||||
|
Loading…
x
Reference in New Issue
Block a user