|
|
@@ -696,8 +696,6 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
|
|
|
protected override void Reload(Filters<StockForecastItem> criteria, Columns<StockForecastItem> columns, ref SortOrder<StockForecastItem>? sort, CancellationToken token, Action<CoreTable?, Exception?> action)
|
|
|
{
|
|
|
- Items.Clear();
|
|
|
-
|
|
|
// Need to query ProductInstances, StockHoldings, Job BOM and PO.
|
|
|
KeyedQueryDef<T> GetQuery<T>(Filter<T>? filter = null, Columns<T>? columns = null) where T : Entity, IJobMaterial, IRemotable, IPersistent, new()
|
|
|
{
|
|
|
@@ -741,6 +739,17 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
.Add(x => x.MinimumStockLevel)),
|
|
|
GetQuery<StockHolding>(
|
|
|
columns: Columns.None<StockHolding>().Add(x => x.Units)),
|
|
|
+ new KeyedQueryDef<PurchaseOrderItem>(
|
|
|
+ new Filter<PurchaseOrderItem>(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue)
|
|
|
+ .And(x => x.Product.Group.ID).InList(GroupIDs),
|
|
|
+ Columns.None<PurchaseOrderItem>()
|
|
|
+ .Add(x => x.ID)
|
|
|
+ .Add(x => x.Qty)
|
|
|
+ .Add(x => x.Product.ID)
|
|
|
+ .Add(x => x.Style.ID)
|
|
|
+ .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local)
|
|
|
+ .Add(x => x.Dimensions.UnitSize)
|
|
|
+ .Add(x => x.Dimensions.Value)),
|
|
|
new KeyedQueryDef<PurchaseOrderItemAllocation>(
|
|
|
new Filter<PurchaseOrderItemAllocation>(x => x.Item.ReceivedDate).IsEqualTo(DateTime.MinValue)
|
|
|
.And(x => x.Item.Product.Group.ID).InList(GroupIDs)
|
|
|
@@ -749,6 +758,7 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
Columns.None<PurchaseOrderItemAllocation>()
|
|
|
.Add(x => x.Quantity)
|
|
|
.Add(x => x.Job.ID)
|
|
|
+ .Add(x => x.Item.ID)
|
|
|
.Add(x => x.Item.Product.ID)
|
|
|
.Add(x => x.Item.Style.ID)
|
|
|
.AddDimensionsColumns(x => x.Item.Dimensions, Dimensions.ColumnsType.Local)
|
|
|
@@ -816,6 +826,9 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var purchaseOrderItems = results.GetObjects<PurchaseOrderItem>()
|
|
|
+ .ToDictionary(x => x.ID);
|
|
|
+
|
|
|
var allocations = results.Get<PurchaseOrderItemAllocation>();
|
|
|
foreach(var allocation in allocations.Rows)
|
|
|
{
|
|
|
@@ -827,17 +840,26 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
var jobID = allocation.Get<PurchaseOrderItemAllocation, Guid>(x => x.Job.ID);
|
|
|
|
|
|
var qty = allocation.Get<PurchaseOrderItemAllocation, double>(x => x.Quantity);
|
|
|
- if(jobID == Guid.Empty)
|
|
|
- {
|
|
|
- item.GenPO += qty;
|
|
|
- }
|
|
|
- else
|
|
|
+ item.JobPO += qty;
|
|
|
+ item.AddJobPO(jobID, qty);
|
|
|
+
|
|
|
+ if(purchaseOrderItems.TryGetValue(allocation.Get<PurchaseOrderItemAllocation, Guid>(x => x.Item.ID), out var poi))
|
|
|
{
|
|
|
- item.JobPO += qty;
|
|
|
- item.AddJobPO(jobID, qty);
|
|
|
+ poi.Qty -= qty;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ foreach(var poi in purchaseOrderItems.Values)
|
|
|
+ {
|
|
|
+ var key = new ItemKey(
|
|
|
+ poi.Product.ID,
|
|
|
+ poi.Style.ID,
|
|
|
+ poi.Dimensions);
|
|
|
+ var item = GetItem(key);
|
|
|
+
|
|
|
+ item.GenPO += poi.Qty;
|
|
|
+ }
|
|
|
+
|
|
|
var jobBOMItems = results.Get<JobBillOfMaterialsItem>();
|
|
|
foreach(var bomItem in jobBOMItems.Rows)
|
|
|
{
|
|
|
@@ -977,6 +999,10 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
{
|
|
|
var item = new StockForecastOrderData(forecastItem.Product, forecastItem.Style, forecastItem.Dimensions);
|
|
|
item.RequiredQuantity = Optimise ? forecastItem.Optimised : forecastItem.Required;
|
|
|
+ if(forecastItem.StockRequired > 0)
|
|
|
+ {
|
|
|
+ item.SetRequiredQuantity(Guid.Empty, Guid.Empty, "", forecastItem.StockRequired);
|
|
|
+ }
|
|
|
|
|
|
foreach(var (id, jobInfo) in forecastItem.JobInfo)
|
|
|
{
|