исправление для отчётов

This commit is contained in:
Николай 2023-04-07 18:48:40 +04:00
parent db7f79ed81
commit 0b0e6abcde
5 changed files with 26 additions and 19 deletions

View File

@ -47,22 +47,9 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{
Id = purchase.Id,
Builds = new List<(string Build, int count, List<(string Component, int count)>)>(),
Goods = new List<(string Good, int count, List<(string Component, int count)>)>(),
TotalCount = 0,
TotalCost = 0
};
foreach (var good in purchase.PurchaseGoods)
{
List<(string Component, int count)> componentList = new List<(string Component, int count)>();
int goodTotalCount = 0;
foreach (var component in good.Value.Item1.GoodComponents)
{
componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
goodTotalCount += component.Value.Item2;
}
record.Goods.Add(new(good.Value.Item1.GoodName, good.Value.Item2, componentList));
record.TotalCount += goodTotalCount * good.Value.Item2;
}
foreach (var build in purchase.PurchaseBuilds)
{
List<(string Component, int count)> componentList = new List<(string Component, int count)>();

View File

@ -12,8 +12,6 @@ namespace HardwareShopContracts.ViewModels
public List<(string Build, int count, List<(string Component, int count)>)> Builds { get; set; } = new();
public List<(string Good, int count, List<(string Component, int count)>)> Goods { get; set; } = new();
public int TotalCount { get; set; }
public int TotalCost { get; set; }

View File

@ -27,8 +27,13 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
if (!model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.ThenInclude(x => x.Components)
.ThenInclude(x => x.Component)
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.ThenInclude(x => x.Comments)
.Where(x => x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
@ -50,6 +55,23 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.ToList();
}
public List<PurchaseViewModel> GetReportFilteredList(PurchaseSearchModel model)
{
using var context = new HardwareShopDatabase();
if (!model.UserId.HasValue)
{
return null;
}
return context.Purchases
.Include(x => x.Builds)
.ThenInclude(x => x.Build)
.ThenInclude(x => x.Components)
.ThenInclude(x => x.Component)
.Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
}
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
{
if (!model.Id.HasValue)

View File

@ -27,7 +27,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
public virtual List<Comment> Comments { get; set; } = new();
[ForeignKey("BuildId")]
public virtual List<ComponentBuild>? Components { get; set; }
public virtual List<ComponentBuild> Components { get; set; } = new();
[ForeignKey("BuildId")]

View File

@ -27,7 +27,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
public virtual User User { get; set; }
[ForeignKey("PurchaseId")]
public virtual List<PurchaseBuild>? Builds { get; set; }
public virtual List<PurchaseBuild> Builds { get; set; } = new();
[ForeignKey("PurchaseId")]
public virtual List<PurchaseGood> Goods { get; set; } = new();