|
|
@@ -6,10 +6,11 @@ using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using PRSClasses;
|
|
|
|
|
|
+
|
|
|
namespace Comal.Classes
|
|
|
{
|
|
|
+ using HoldingDictionary = Dictionary<(Guid product, Guid style, Guid location, Guid job, StockDimensions dimensions), StockHolding>;
|
|
|
|
|
|
-
|
|
|
public class StockHoldingLastStocktake : CoreAggregate<StockHolding, StockMovement, DateTime>
|
|
|
{
|
|
|
public override Expression<Func<StockMovement, DateTime>> Aggregate => x => x.Date;
|
|
|
@@ -308,6 +309,49 @@ namespace Comal.Classes
|
|
|
|
|
|
return _result;
|
|
|
}
|
|
|
+
|
|
|
+ public static HoldingDictionary LoadStockHoldings(IEnumerable<IStockHolding> mvts, Columns<StockHolding> columns, HoldingDictionary? holdings = null, IQueryProvider<StockHolding>? query = null)
|
|
|
+ {
|
|
|
+ query ??= Client<StockHolding>.Provider;
|
|
|
+
|
|
|
+ columns.Add(x => x.ID);
|
|
|
+ columns.Add(x => x.Product.ID);
|
|
|
+ columns.Add(x => x.Location.ID);
|
|
|
+ columns.Add(x => x.Style.ID);
|
|
|
+ columns.Add(x => x.Job.ID);
|
|
|
+ columns.AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local);
|
|
|
+
|
|
|
+ if(holdings != null)
|
|
|
+ {
|
|
|
+ mvts = mvts.Where(mvt =>
|
|
|
+ {
|
|
|
+ var key = (mvt.Product.ID, mvt.Style.ID, mvt.Location.ID, mvt.Job.ID, mvt.Dimensions);
|
|
|
+ return !holdings.ContainsKey(key);
|
|
|
+ }).ToArray();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ holdings = new HoldingDictionary();
|
|
|
+ }
|
|
|
+
|
|
|
+ var productIDs = mvts.Select(x => x.Product.ID).Distinct().ToArray();
|
|
|
+ var locationIDs = mvts.Select(x => x.Location.ID).Distinct().ToArray();
|
|
|
+ var styleIDs = mvts.Select(x => x.Style.ID).Distinct().ToArray();
|
|
|
+ var jobIDs = mvts.Select(x => x.Job.ID).Distinct().ToArray();
|
|
|
+
|
|
|
+ var newHoldings = query.Query(new Filter<StockHolding>(x => x.Product.ID).InList(productIDs)
|
|
|
+ .And(x => x.Location.ID).InList(locationIDs)
|
|
|
+ .And(x => x.Style.ID).InList(styleIDs)
|
|
|
+ .And(x => x.Job.ID).InList(jobIDs),
|
|
|
+ columns
|
|
|
+ ).ToObjects<StockHolding>();
|
|
|
+ foreach(var holding in newHoldings)
|
|
|
+ {
|
|
|
+ holdings[(holding.Product.ID, holding.Style.ID, holding.Location.ID, holding.Job.ID, holding.Dimensions)] = holding;
|
|
|
+ }
|
|
|
+
|
|
|
+ return holdings;
|
|
|
+ }
|
|
|
|
|
|
// public static IEnumerable<Tuple<Guid,double>> GetAllocations(this StockHolding holding, bool alwaysshowunallocated)
|
|
|
// {
|