Получение данных для формирования отчёта готово
This commit is contained in:
parent
76c9fa6580
commit
0f7148fbe5
@ -0,0 +1,146 @@
|
|||||||
|
|
||||||
|
using HardwareShopContracts.BindingModels;
|
||||||
|
using HardwareShopContracts.SearchModels;
|
||||||
|
using HardwareShopContracts.StoragesContracts;
|
||||||
|
using HardwareShopContracts.ViewModels;
|
||||||
|
using HardwareShopDatabaseImplement.Implements.Storekeeper;
|
||||||
|
using HardwareShopDatabaseImplement.Implements.Worker;
|
||||||
|
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||||
|
using HardwareShopDatabaseImplement.Models.Worker;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace HardwareShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public class WorkerReportLogic : IWorkerReportLogic
|
||||||
|
{
|
||||||
|
private readonly IComponentStorage _componentStorage;
|
||||||
|
|
||||||
|
private readonly BuildStorage _buildStorage;
|
||||||
|
|
||||||
|
private readonly IPurchaseStorage _purchaseStorage;
|
||||||
|
|
||||||
|
private readonly IGoodStorage _goodStorage;
|
||||||
|
|
||||||
|
private readonly ICommentStorage _commentStorage;
|
||||||
|
|
||||||
|
public WorkerReportLogic(IComponentStorage componentStorage, BuildStorage buildStorage, IPurchaseStorage purchaseStorage, IGoodStorage goodStorage, ICommentStorage commentStorage)
|
||||||
|
{
|
||||||
|
_componentStorage = componentStorage;
|
||||||
|
_buildStorage = buildStorage;
|
||||||
|
_purchaseStorage = purchaseStorage;
|
||||||
|
_goodStorage = goodStorage;
|
||||||
|
_commentStorage = commentStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка компонент с указанием, в каких покупках используются
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<ReportPurchaseComponentViewModel> GetPurchaseComponent(List<PurchaseViewModel> purchaseList)
|
||||||
|
{
|
||||||
|
var list = new List<ReportPurchaseComponentViewModel>();
|
||||||
|
|
||||||
|
foreach (var purchase in purchaseList)
|
||||||
|
{
|
||||||
|
var record = new ReportPurchaseComponentViewModel
|
||||||
|
{
|
||||||
|
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.GoodsComponents)
|
||||||
|
{
|
||||||
|
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)>();
|
||||||
|
int buildTotalCount = 0;
|
||||||
|
foreach (var component in build.Value.Item1.BuildComponents)
|
||||||
|
{
|
||||||
|
componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
||||||
|
buildTotalCount += component.Value.Item2;
|
||||||
|
}
|
||||||
|
record.Builds.Add(new(build.Value.Item1.BuildName, build.Value.Item2, componentList));
|
||||||
|
record.TotalCount += buildTotalCount * build.Value.Item2;
|
||||||
|
}
|
||||||
|
list.Add(record);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка покупок за определенный период
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
var list = new List<ReportPurchaseViewModel>();
|
||||||
|
var purchases = _purchaseStorage.GetFilteredList(new PurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
||||||
|
|
||||||
|
foreach (var purchase in purchases)
|
||||||
|
{
|
||||||
|
var record = new ReportPurchaseViewModel
|
||||||
|
{
|
||||||
|
Id = purchase.Id,
|
||||||
|
Builds = new List<(string Build, int count, List<string>, List<(string Component, int count)>)>(),
|
||||||
|
};
|
||||||
|
foreach (var build in purchase.PurchaseBuilds)
|
||||||
|
{
|
||||||
|
List<string> commentList = new List<string>();
|
||||||
|
foreach (var comment in build.Value.Item1.BuildComments)
|
||||||
|
{
|
||||||
|
commentList.Add(new(comment.Value.Text));
|
||||||
|
}
|
||||||
|
List<(string Component, int count)> componentList = new List<(string Component, int count)>();
|
||||||
|
foreach (var component in build.Value.Item1.BuildComponents)
|
||||||
|
{
|
||||||
|
componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
||||||
|
}
|
||||||
|
record.Builds.Add(new (build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Word
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Excel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
public void SaveDishComponentToExcelFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение отчёта по покупкам в файл-Pdf
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
|
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -13,5 +13,7 @@ namespace HardwareShopContracts.BindingModels
|
|||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,7 @@ namespace HardwareShopContracts.BindingModels
|
|||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
using HardwareShopContracts.BindingModels;
|
||||||
|
using HardwareShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace HardwareShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IWorkerReportLogic
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка компонент с указанием, в каких покупках используются
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<ReportPurchaseComponentViewModel> GetPurchaseComponent(List<PurchaseViewModel> purchaseList);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка покупок за определенный период
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Word
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
void SaveComponentsToWordFile(ReportBindingModel model);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Excel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
void SaveDishComponentToExcelFile(ReportBindingModel model);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение отчёта по покупкам в файл-Pdf
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
using HardwareShopDataModels.Enums;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
namespace HardwareShopContracts.SearchModels
|
namespace HardwareShopContracts.SearchModels
|
||||||
{
|
{
|
||||||
@ -8,6 +9,10 @@ namespace HardwareShopContracts.SearchModels
|
|||||||
|
|
||||||
public int? UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
|
|
||||||
public DateTime? DatePurchase { get; set; }
|
public PurchaseStatus? PurchaseStatus { get; set; }
|
||||||
|
|
||||||
|
public DateTime? DateFrom { get; set; }
|
||||||
|
|
||||||
|
public DateTime? DateTo { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,6 @@ namespace HardwareShopContracts.ViewModels
|
|||||||
|
|
||||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,7 @@ namespace HardwareShopContracts.ViewModels
|
|||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HardwareShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportPurchaseComponentViewModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
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; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HardwareShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportPurchaseViewModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public List<(string Build, int count, List<string>, List<(string Component, int count)>)> Builds { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -16,5 +16,9 @@ namespace HardwareShopDataModels.Models
|
|||||||
int UserId { get; }
|
int UserId { get; }
|
||||||
|
|
||||||
Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; }
|
Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; }
|
||||||
|
|
||||||
|
Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
|
||||||
|
|
||||||
|
Dictionary<int, ICommentModel> BuildComments { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@ namespace HardwareShopDataModels.Models
|
|||||||
int UserId { get; }
|
int UserId { get; }
|
||||||
|
|
||||||
Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; }
|
Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; }
|
||||||
|
|
||||||
|
Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,14 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
if (!model.UserId.HasValue && !model.DatePurchase.HasValue)
|
if (!model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return context.Purchases
|
||||||
|
.Include(x => x.Goods)
|
||||||
|
.ThenInclude(x => x.Good)
|
||||||
|
.Where(x => x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
if (model.UserId.HasValue)
|
if (model.UserId.HasValue)
|
||||||
{
|
{
|
||||||
@ -40,7 +45,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Purchases
|
return context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Where(x => x.DatePurchase == model.DatePurchase)
|
.Where(x => x.PurchaseStatus == model.PurchaseStatus)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,37 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
[ForeignKey("BuildId")]
|
[ForeignKey("BuildId")]
|
||||||
public virtual List<PurchaseBuild> Purchases { get; set; } = new();
|
public virtual List<PurchaseBuild> Purchases { get; set; } = new();
|
||||||
|
|
||||||
public Dictionary<int, (IPurchaseModel, int)>? _buildPurchases = null;
|
private Dictionary<int, ICommentModel> _buildComments = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, ICommentModel> BuildComments
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_buildComments == null)
|
||||||
|
{
|
||||||
|
_buildComments = Comments.ToDictionary(recBC=> recBC.Id, recBC => recBC as ICommentModel);
|
||||||
|
}
|
||||||
|
return _buildComments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> BuildComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_buildComponents == null)
|
||||||
|
{
|
||||||
|
_buildComponents = Components.ToDictionary(recBC => recBC.ComponentId, recBC => (recBC.Component as IComponentModel, recBC.Count));
|
||||||
|
}
|
||||||
|
return _buildComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (IPurchaseModel, int)>? _buildPurchases = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases
|
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases
|
||||||
@ -116,7 +146,5 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
|
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
[ForeignKey("PurchaseId")]
|
[ForeignKey("PurchaseId")]
|
||||||
public virtual List<PurchaseGood> Goods { get; set; } = new();
|
public virtual List<PurchaseGood> Goods { get; set; } = new();
|
||||||
|
|
||||||
public Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null;
|
private Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods
|
public Dictionary<int, (IGoodModel, int)> PurchaseGoods
|
||||||
@ -47,6 +47,21 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_purchaseBuilds == null)
|
||||||
|
{
|
||||||
|
_purchaseBuilds = Builds.ToDictionary(recPG => recPG.BuildId, recPG => (recPG.Build as IBuildModel, recPG.Count));
|
||||||
|
}
|
||||||
|
return _purchaseBuilds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model)
|
public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model)
|
||||||
{
|
{
|
||||||
return new Purchase()
|
return new Purchase()
|
||||||
|
Loading…
Reference in New Issue
Block a user