Вроде норм отчеты
This commit is contained in:
parent
6011ed3f90
commit
51a8119546
@ -1,27 +1,17 @@
|
|||||||
using HardwareShopContracts.BindingModels;
|
using HardwareShopContracts.BindingModels;
|
||||||
using HardwareShopContracts.BusinessLogicsContracts;
|
using HardwareShopContracts.BusinessLogicsContracts;
|
||||||
using HardwareShopContracts.SearchModels;
|
|
||||||
using HardwareShopContracts.StoragesContracts;
|
using HardwareShopContracts.StoragesContracts;
|
||||||
using HardwareShopContracts.ViewModels;
|
using HardwareShopContracts.ViewModels;
|
||||||
using HardwareShopDatabaseImplement.Models.Worker;
|
|
||||||
using HardwareShopDataModels.Models;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
||||||
{
|
{
|
||||||
public class ReportStorekeeperLogic : IReportStorekeeperLogic
|
public class ReportStorekeeperLogic : IReportStorekeeperLogic
|
||||||
{
|
{
|
||||||
private readonly IComponentStorage _componentStorage;
|
private readonly IComponentStorage _componentStorage;
|
||||||
private readonly IGoodStorage _goodStorage;
|
|
||||||
private readonly IPurchaseStorage _purchaseStorage;
|
|
||||||
private readonly IBuildStorage _buildStorage;
|
|
||||||
|
|
||||||
public ReportStorekeeperLogic(IComponentStorage componentStorage, IGoodStorage goodStorage, IPurchaseStorage purchaseStorage, IBuildStorage buildStorage)
|
public ReportStorekeeperLogic(IComponentStorage componentStorage)
|
||||||
{
|
{
|
||||||
_componentStorage = componentStorage;
|
_componentStorage = componentStorage;
|
||||||
_goodStorage = goodStorage;
|
|
||||||
_purchaseStorage = purchaseStorage;
|
|
||||||
_buildStorage = buildStorage;
|
|
||||||
}
|
}
|
||||||
public List<ReportBuildGoodViewModel> GetBuildGood(List<GoodViewModel> goods)
|
public List<ReportBuildGoodViewModel> GetBuildGood(List<GoodViewModel> goods)
|
||||||
{
|
{
|
||||||
@ -46,60 +36,39 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
/// Получение сведений по комплектующим за период,
|
||||||
public List<ReportComponentsViewModel> GetComponents(ReportBindingModel model)
|
/// с указанием в каких товарах и сборках они использовались
|
||||||
|
public List<ReportComponentsViewModel> GetComponents(UserBindingModel user, ReportBindingModel model)
|
||||||
{
|
{
|
||||||
var list = new List<ReportComponentsViewModel>();
|
var result = new List<ReportComponentsViewModel>();
|
||||||
var purchases = _purchaseStorage
|
var components = _componentStorage.GetFilteredList(new()
|
||||||
.GetFilteredList(new PurchaseSearchModel
|
|
||||||
{
|
{
|
||||||
|
UserId = user.Id,
|
||||||
DateFrom = model.DateFrom,
|
DateFrom = model.DateFrom,
|
||||||
DateTo = model.DateTo
|
DateTo = model.DateTo
|
||||||
});
|
});
|
||||||
var components = _componentStorage.GetFullList();
|
|
||||||
foreach (var component in components)
|
foreach (var component in components)
|
||||||
{
|
{
|
||||||
var record = new ReportComponentsViewModel
|
var builds = component.ComponentBuilds
|
||||||
|
.Select(x => Tuple.Create(x.Value.Item1.BuildName, x.Value.Item2))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var goods = component.ComponentBuilds
|
||||||
|
.SelectMany(x =>
|
||||||
|
_componentStorage.GetComponentGoods(new() { Id = x.Key }))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
ReportComponentsViewModel record = new()
|
||||||
{
|
{
|
||||||
ComponentName = component.ComponentName,
|
ComponentName = component.ComponentName,
|
||||||
TotalCount = 0,
|
TotalCount = builds.Sum(x => x.Item2) + goods.Sum(x => x.Item2),
|
||||||
GoodOrBuilds = new List<(string GoodOrBuild, int Count)>()
|
GoodOrBuilds = builds.Concat(goods).ToList()
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var purchase in purchases)
|
result.Add(record);
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
foreach (var build in purchase.PurchaseBuilds)
|
|
||||||
{
|
|
||||||
int countBuildsInPurchase = build.Value.Item2;
|
|
||||||
if (build.Value.Item1.BuildComponents.ContainsKey(component.Id))
|
|
||||||
{
|
|
||||||
int countComponentsInBuild = build.Value.Item1
|
|
||||||
.BuildComponents.First(x => x.Key == component.Id)
|
|
||||||
.Value.Item2;
|
|
||||||
sum += countComponentsInBuild * countBuildsInPurchase;
|
|
||||||
|
|
||||||
record.GoodOrBuilds.Add((build.Value.Item1.BuildName, countComponentsInBuild));
|
|
||||||
}
|
}
|
||||||
}
|
return result;
|
||||||
foreach (var good in purchase.PurchaseGoods)
|
|
||||||
{
|
|
||||||
int countGoodsInPurchase = good.Value.Item2;
|
|
||||||
if (good.Value.Item1.GoodComponents.ContainsKey(component.Id))
|
|
||||||
{
|
|
||||||
int countComponentsInGood = good.Value.Item1
|
|
||||||
.GoodComponents.First(x => x.Key == component.Id)
|
|
||||||
.Value.Item2;
|
|
||||||
sum += countComponentsInGood * countGoodsInPurchase;
|
|
||||||
|
|
||||||
record.GoodOrBuilds.Add((good.Value.Item1.GoodName, countComponentsInGood));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
record.TotalCount = sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
using HardwareShopClientApp;
|
using HardwareShopClientApp;
|
||||||
using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
|
|
||||||
using HardwareShopDatabaseImplement.Implements.Storekeeper;
|
|
||||||
using HardwareShopDatabaseImplement.Implements.Worker;
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -31,30 +26,4 @@ app.MapControllerRoute(
|
|||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||||
|
|
||||||
//app.Run();
|
app.Run();
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ComponentStorage _componentStorage = new();
|
|
||||||
GoodStorage _goodStorage = new();
|
|
||||||
PurchaseStorage _purchaseStorage = new();
|
|
||||||
BuildStorage _buildStorage = new();
|
|
||||||
|
|
||||||
ReportStorekeeperLogic reportLogic = new(_componentStorage, _goodStorage, _purchaseStorage, _buildStorage);
|
|
||||||
|
|
||||||
var goods = _goodStorage.GetFilteredList(new() { UserId = 1 });
|
|
||||||
var reportRecords = reportLogic.GetBuildGood(goods);
|
|
||||||
|
|
||||||
Console.WriteLine("start");
|
|
||||||
foreach (var reportRecord in reportRecords)
|
|
||||||
{
|
|
||||||
Console.WriteLine("good: " + reportRecord.GoodName);
|
|
||||||
Console.WriteLine("> builds:");
|
|
||||||
for (int i = 0; i < reportRecord.Builds.Count; i++)
|
|
||||||
{
|
|
||||||
Console.WriteLine(i + 1 + ". " + reportRecord.Builds[i]);
|
|
||||||
}
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ namespace HardwareShopContracts.BindingModels
|
|||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
public Dictionary<int, (IBuildModel, int)> ComponentBuilds
|
public Dictionary<int, (IBuildModel, int)> ComponentBuilds
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
@ -16,7 +16,8 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
|||||||
/// с указанием в каких товарах и сборках они использовались
|
/// с указанием в каких товарах и сборках они использовались
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="model"></param>
|
/// <param name="model"></param>
|
||||||
|
/// <param name="user"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
List<ReportComponentsViewModel> GetComponents(ReportBindingModel model);
|
List<ReportComponentsViewModel> GetComponents(UserBindingModel user, ReportBindingModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,7 @@
|
|||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? ComponentName { get; set; }
|
public string? ComponentName { get; set; }
|
||||||
public int? UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
|
public DateTime? DateFrom { get; set; }
|
||||||
|
public DateTime? DateTo { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,6 @@ namespace HardwareShopContracts.StoragesContracts
|
|||||||
ComponentViewModel? Update(ComponentBindingModel model);
|
ComponentViewModel? Update(ComponentBindingModel model);
|
||||||
ComponentViewModel? Delete(ComponentBindingModel model);
|
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||||
List<Tuple<string, int>> GetComponentBuilds(ComponentSearchModel model);
|
List<Tuple<string, int>> GetComponentBuilds(ComponentSearchModel model);
|
||||||
|
List<Tuple<string, int>> GetComponentGoods(ComponentSearchModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@ namespace HardwareShopContracts.ViewModels
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Компонент")]
|
[DisplayName("Компонент")]
|
||||||
public string ComponentName { get; set; } = string.Empty;
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
[DisplayName("Цена")]
|
[DisplayName("Стоимость")]
|
||||||
public double Cost { get; set; }
|
public double Cost { get; set; }
|
||||||
|
[DisplayName("Дата приобретения")]
|
||||||
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
public Dictionary<int, (IBuildModel, int)>? ComponentBuilds
|
public Dictionary<int, (IBuildModel, int)> ComponentBuilds
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
|
|
||||||
public int TotalCount { get; set; }
|
public int TotalCount { get; set; }
|
||||||
|
|
||||||
public List<(string GoodOrBuild, int Count)> GoodOrBuilds { get; set; } = new();
|
public List<Tuple<string, int>> GoodOrBuilds { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
string ComponentName { get; }
|
string ComponentName { get; }
|
||||||
double Cost { get; }
|
double Cost { get; }
|
||||||
int UserId { get; }
|
int UserId { get; }
|
||||||
Dictionary<int, (IBuildModel, int)>? ComponentBuilds { get; }
|
Dictionary<int, (IBuildModel, int)> ComponentBuilds { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,16 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
|
|||||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
|
if (model.UserId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||||
|
{
|
||||||
|
return context.Components
|
||||||
|
.Include(x => x.Builds)
|
||||||
|
.ThenInclude(x => x.Build)
|
||||||
|
.Where(x => x.UserId == model.UserId && x.DateCreate >= model.DateFrom
|
||||||
|
&& x.DateCreate <= model.DateTo)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
if (model.UserId.HasValue)
|
if (model.UserId.HasValue)
|
||||||
{
|
{
|
||||||
return context.Components
|
return context.Components
|
||||||
@ -132,5 +142,19 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
|
|||||||
.ToList();
|
.ToList();
|
||||||
return builds;
|
return builds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Tuple<string, int>> GetComponentGoods(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new HardwareShopDatabase();
|
||||||
|
var goods = context.GoodsComponents
|
||||||
|
.Where(x => x.ComponentId == model.Id)
|
||||||
|
.Select(x => Tuple.Create(x.Good.GoodName, x.Count))
|
||||||
|
.ToList();
|
||||||
|
return goods;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using HardwareShopContracts.BindingModels;
|
using HardwareShopContracts.BindingModels;
|
||||||
using HardwareShopContracts.ViewModels;
|
using HardwareShopContracts.ViewModels;
|
||||||
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
||||||
using HardwareShopDatabaseImplement.Models.Worker;
|
|
||||||
using HardwareShopDataModels.Models;
|
using HardwareShopDataModels.Models;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
@ -20,6 +19,8 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
|
||||||
[ForeignKey("ComponentId")]
|
[ForeignKey("ComponentId")]
|
||||||
public virtual List<GoodComponent> Goods { get; set; } = new();
|
public virtual List<GoodComponent> Goods { get; set; } = new();
|
||||||
@ -30,7 +31,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
private Dictionary<int, (IBuildModel, int)>? _componentBuilds = null;
|
private Dictionary<int, (IBuildModel, int)>? _componentBuilds = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IBuildModel, int)>? ComponentBuilds
|
public Dictionary<int, (IBuildModel, int)> ComponentBuilds
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -54,7 +55,8 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
ComponentName = model.ComponentName,
|
ComponentName = model.ComponentName,
|
||||||
Cost = model.Cost,
|
Cost = model.Cost,
|
||||||
UserId = model.UserId
|
UserId = model.UserId,
|
||||||
|
DateCreate = model.DateCreate
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +76,8 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
|||||||
ComponentName = ComponentName,
|
ComponentName = ComponentName,
|
||||||
Cost = Cost,
|
Cost = Cost,
|
||||||
UserId = UserId,
|
UserId = UserId,
|
||||||
ComponentBuilds = ComponentBuilds
|
ComponentBuilds = ComponentBuilds,
|
||||||
|
DateCreate = DateCreate
|
||||||
};
|
};
|
||||||
|
|
||||||
public void UpdateBuilds(HardwareShopDatabase context, ComponentBindingModel model)
|
public void UpdateBuilds(HardwareShopDatabase context, ComponentBindingModel model)
|
||||||
|
@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopBusinessLogic",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopDatabaseImplement", "HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj", "{1E5156F6-1F67-497C-A660-8AC61BC451BC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopDatabaseImplement", "HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj", "{1E5156F6-1F67-497C-A660-8AC61BC451BC}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopClientApp", "HardwareShopClientApp\HardwareShopClientApp.csproj", "{3DCD1BA3-4D72-4B0E-BB06-323E09B75EBB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopStorekeeperApp", "HardwareShopClientApp\HardwareShopStorekeeperApp.csproj", "{3DCD1BA3-4D72-4B0E-BB06-323E09B75EBB}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopWorkerApp", "HardwareShopWorkerApp\HardwareShopWorkerApp.csproj", "{3C590713-871F-4D9B-A97A-3898D4E09506}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopWorkerApp", "HardwareShopWorkerApp\HardwareShopWorkerApp.csproj", "{3C590713-871F-4D9B-A97A-3898D4E09506}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Loading…
Reference in New Issue
Block a user