Все работает, кроме подсчета суммы и нужно формочку поменять
This commit is contained in:
parent
9226bb13b9
commit
368960a0f4
@ -103,20 +103,38 @@ WHERE Id = @Id";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<AddMoney> ReadAddMoneys()
|
public IEnumerable<AddMoney> ReadAddMoneys(DateTime? dateFrom = null, DateTime? dateTo = null, int? addMoneyId = null, int? clientId = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("am.Date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("am.Date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (addMoneyId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("am.Id =@addMoneyId");
|
||||||
|
}
|
||||||
|
if (clientId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("am.ClientId =@clientId");
|
||||||
|
}
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT
|
var querySelect = $@"SELECT
|
||||||
am.*,
|
am.*,
|
||||||
c.FullName AS ClientName
|
c.FullName AS ClientName
|
||||||
FROM
|
FROM
|
||||||
AddMoneys am
|
AddMoneys am
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
Clients c ON c.Id = am.ClientId";
|
Clients c ON c.Id = am.ClientId
|
||||||
var AddMoneys = connection.Query<AddMoney>(querySelect);
|
{builder.Build()}";
|
||||||
|
var AddMoneys = connection.Query<AddMoney>(querySelect, new {dateFrom, dateTo, addMoneyId, clientId});
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(AddMoneys));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(AddMoneys));
|
||||||
return AddMoneys;
|
return AddMoneys;
|
||||||
|
|
||||||
|
37
project/ProjectTourAgency/Implementations/QueryBuilder.cs
Normal file
37
project/ProjectTourAgency/Implementations/QueryBuilder.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectTourAgency.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}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -81,8 +81,24 @@ WHERE Id = @id";
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("t.DepartureDate >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("t.DepartureDate <= @dateTo");
|
||||||
|
}
|
||||||
|
if(tourId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("t.Id = @tourId");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = $@"
|
||||||
SELECT
|
SELECT
|
||||||
t.*,
|
t.*,
|
||||||
CONCAT(r.Departure,'-', r.Destination) AS RouteName,
|
CONCAT(r.Departure,'-', r.Destination) AS RouteName,
|
||||||
@ -95,12 +111,12 @@ FROM
|
|||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
Routes r ON r.Id = t.RouteId
|
Routes r ON r.Id = t.RouteId
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
Employees e ON e.Id = t.EmployeeId -- соединяем с таблицей Employees
|
Employees e ON e.Id = t.EmployeeId
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
ClientTour ct ON ct.TourId = t.Id -- соединяем с таблицей ClientTour
|
ClientTour ct ON ct.TourId = t.Id
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
Clients c ON c.Id = ct.ClientId;
|
Clients c ON c.Id = ct.ClientId
|
||||||
";
|
{builder.Build()}";
|
||||||
|
|
||||||
var clientTourDict = new Dictionary<int, List<ClientTour>>();
|
var clientTourDict = new Dictionary<int, List<ClientTour>>();
|
||||||
|
|
||||||
@ -114,7 +130,7 @@ LEFT JOIN
|
|||||||
}
|
}
|
||||||
ct.Add(tours);
|
ct.Add(tours);
|
||||||
return clientTour;
|
return clientTour;
|
||||||
}, splitOn: "ClientId");
|
}, splitOn: "ClientId",param: new {dateFrom, dateTo, tourId, clientId});
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(tours));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(tours));
|
||||||
|
|
||||||
return clientTourDict.Select(x =>
|
return clientTourDict.Select(x =>
|
||||||
|
@ -43,8 +43,7 @@ internal class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _addMoneyRepository
|
return _addMoneyRepository
|
||||||
.ReadAddMoneys()
|
.ReadAddMoneys(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.Date.Date == dateTime.Date)
|
|
||||||
.GroupBy(x => x.ClientId, (key, group) => new { Id = key, Count = group.Count() })
|
.GroupBy(x => x.ClientId, (key, group) => new { Id = key, Count = group.Count() })
|
||||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
@ -31,7 +31,7 @@ namespace ProjectTourAgency.Reports
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по движению корма", 0, 4)
|
.AddHeader("Сводка по движению корма", 0, 4)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||||
.AddTable(new[] { 10, 10, 15, 15 }, GetData(tourId, startDate, endDate))
|
.AddTable(new[] { 10, 10, 15, 15 }, GetData(tourId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@ -46,25 +46,25 @@ namespace ProjectTourAgency.Reports
|
|||||||
private List<string[]> GetData(int tourId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int tourId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
|
|
||||||
var tourData = _tourRepository.ReadTours()
|
var tourData = _tourRepository.ReadTours(startDate, endDate, tourId)
|
||||||
.Where(x => x.DepartureDate >= startDate && x.DepartureDate <= endDate && x.ClientTours.Any(y => y.TourId == tourId))
|
|
||||||
.SelectMany(x => x.ClientTours
|
.SelectMany(x => x.ClientTours
|
||||||
.Where(y => y.TourId == tourId)
|
|
||||||
.Select(y => new {
|
.Select(y => new {
|
||||||
ClientId = (int?)y.ClientId,
|
ClientId = y.ClientId,
|
||||||
|
ClientName = y.CLientName,
|
||||||
Date = x.DepartureDate,
|
Date = x.DepartureDate,
|
||||||
CountIn = (int?)null,
|
CountIn = (int?)null,
|
||||||
CountOut = (int?)y.Cost
|
CountOut = (int?)y.Cost
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
var clientIds = tourData.Select(x => x.ClientId).Distinct().ToList();
|
var clientId = tourData.Select(x =>x.ClientId).Distinct().ToList();
|
||||||
|
|
||||||
|
|
||||||
var addMoneyData = _addMoneyRepository.ReadAddMoneys()
|
var addMoneyData = _addMoneyRepository.ReadAddMoneys(startDate, endDate)
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && clientIds.Contains(x.ClientId))
|
.Where(x => clientId.Contains(x.ClientId))
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
ClientId = (int?)x.ClientId,
|
ClientId = x.ClientId,
|
||||||
|
ClientName = x.ClientName,
|
||||||
Date = x.Date,
|
Date = x.Date,
|
||||||
CountIn = (int?)x.MoneyAmount,
|
CountIn = (int?)x.MoneyAmount,
|
||||||
CountOut = (int?)null
|
CountOut = (int?)null
|
||||||
@ -77,15 +77,15 @@ namespace ProjectTourAgency.Reports
|
|||||||
|
|
||||||
return new List<string[]>() { item }
|
return new List<string[]>() { item }
|
||||||
.Union(data.Select(x => new string[] {
|
.Union(data.Select(x => new string[] {
|
||||||
x.ClientId.ToString(),
|
x.ClientName.ToString(),
|
||||||
x.Date.ToString(),
|
x.Date.ToString(),
|
||||||
x.CountIn?.ToString() ?? string.Empty,
|
x.CountIn?.ToString() ?? string.Empty,
|
||||||
x.CountOut?.ToString() ?? string.Empty }))
|
x.CountOut?.ToString() ?? string.Empty }))
|
||||||
.Union(new[] { new string[] {
|
.Union(new[] { new string[] {
|
||||||
"Всего",
|
"Всего",
|
||||||
"",
|
"",
|
||||||
data.Sum(x => x.CountIn ?? 0).ToString(),
|
data.Sum(x => x.CountIn ?? 0).ToString("NO"),
|
||||||
data.Sum(x => x.CountOut ?? 0).ToString()
|
data.Sum(x => x.CountOut ?? 0).ToString("NO")
|
||||||
}})
|
}})
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace ProjectTourAgency.Repositories;
|
|||||||
|
|
||||||
public interface IAddMoneyRepository
|
public interface IAddMoneyRepository
|
||||||
{
|
{
|
||||||
IEnumerable<AddMoney> ReadAddMoneys();
|
IEnumerable<AddMoney> ReadAddMoneys(DateTime? dateFrom = null, DateTime? dateTo = null, int? addMoneyId = null, int? clientId = null);
|
||||||
|
|
||||||
AddMoney ReadAddMoneyById(int id);
|
AddMoney ReadAddMoneyById(int id);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user