|
@@ -835,8 +835,12 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
foreach(var mvt in movements.Rows)
|
|
|
{
|
|
|
var item = GetItem(GetKey(mvt));
|
|
|
-
|
|
|
- item.AddJobBOM(mvt.Get<StockMovement, Guid>(x => x.Job.ID), mvt.Get<StockMovement, double>(x => x.Units));
|
|
|
+
|
|
|
+ var jobID = mvt.Get<StockMovement, Guid>(x => x.Job.ID);
|
|
|
+ if(jobID != Guid.Empty)
|
|
|
+ {
|
|
|
+ item.AddJobBOM(jobID, mvt.Get<StockMovement, double>(x => x.Units));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
_supplierProducts = results.GetArray<SupplierProduct>();
|
|
@@ -980,88 +984,10 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- var orders = new List<Tuple<PurchaseOrder, Dictionary<StockForecastOrderingResult,PurchaseOrderItem>>>();
|
|
|
- Progress.ShowModal("Creating Orders", progress =>
|
|
|
- {
|
|
|
- int iOrder = 1;
|
|
|
- foreach(var perSupplier in window.Results.GroupBy(x => x.Supplier.ID))
|
|
|
- {
|
|
|
- progress.Report($"Creating Orders ({iOrder++}/{window.Results.ToArray().Length})");
|
|
|
- var order = new PurchaseOrder();
|
|
|
- order.Description = "Purchase Order created from Stock Forecast Screen";
|
|
|
- order.RaisedBy.ID = App.EmployeeID;
|
|
|
-
|
|
|
- LookupFactory.DoLookup<PurchaseOrder, Supplier, SupplierLink>(order, x => x.SupplierLink, perSupplier.Key);
|
|
|
-
|
|
|
- var orderItems = new Dictionary<StockForecastOrderingResult,PurchaseOrderItem>();
|
|
|
- var results = perSupplier.ToArray();
|
|
|
- foreach(var item in results)
|
|
|
- {
|
|
|
- var orderItem = new PurchaseOrderItem();
|
|
|
- orderItem.Product.ID = item.Item.Product.ID;
|
|
|
- orderItem.Style.ID = item.Item.Style.ID;
|
|
|
- orderItems[item] = orderItem;
|
|
|
- }
|
|
|
-
|
|
|
- LookupFactory.DoLookups<PurchaseOrderItem, Product, ProductLink>(
|
|
|
- orderItems.Values.Select(x => new Tuple<PurchaseOrderItem, Guid>(x, x.Product.ID)),
|
|
|
- x => x.Product);
|
|
|
- LookupFactory.DoLookups<PurchaseOrderItem, ProductStyle, ProductStyleLink>(
|
|
|
- orderItems.Values.Select(x => new Tuple<PurchaseOrderItem, Guid>(x, x.Style.ID)),
|
|
|
- x => x.Style);
|
|
|
- LookupFactory.DoLookups<PurchaseOrderItem, Job, JobLink>(
|
|
|
- orderItems.Values.Select(x => new Tuple<PurchaseOrderItem, Guid>(x, x.Job.ID)),
|
|
|
- x => x.Job);
|
|
|
- LookupFactory.DoLookups<PurchaseOrderItem, TaxCode, TaxCodeLink>(
|
|
|
- orderItems.Values.Select(x => new Tuple<PurchaseOrderItem, Guid>(x, x.TaxCode.ID)),
|
|
|
- x => x.TaxCode);
|
|
|
-
|
|
|
- foreach(var item in results)
|
|
|
- {
|
|
|
- var orderItem = orderItems[item];
|
|
|
- orderItem.Dimensions.CopyFrom(item.Item.Dimensions);
|
|
|
- orderItem.Qty = item.Quantity;
|
|
|
- orderItem.ForeignCurrencyCost = item.SupplierProduct.ForeignCurrencyPrice;
|
|
|
- orderItem.Cost = item.SupplierProduct.CostPrice;
|
|
|
- }
|
|
|
-
|
|
|
- orders.Add(new(order, orderItems));
|
|
|
- }
|
|
|
-
|
|
|
- progress.Report($"Saving {orders.Count} Orders");
|
|
|
- Client.Save(orders.Select(x => x.Item1), "Created from Stock Forecast screen");
|
|
|
- foreach(var (order, orderItems) in orders)
|
|
|
- {
|
|
|
- foreach(var pair in orderItems)
|
|
|
- pair.Value.PurchaseOrderLink.ID = order.ID;
|
|
|
- }
|
|
|
- Client.Save(orders.SelectMany(x => x.Item2.Values), "Created from Stock Forecast screen");
|
|
|
-
|
|
|
- List<PurchaseOrderItemAllocation> allocations = new();
|
|
|
- progress.Report($"Processing Breakups");
|
|
|
- foreach(var (order, orderItems) in orders)
|
|
|
- {
|
|
|
- foreach(var pair in orderItems)
|
|
|
- {
|
|
|
- foreach (var breakup in pair.Key.Breakups)
|
|
|
- {
|
|
|
- var alloc = new PurchaseOrderItemAllocation();
|
|
|
- alloc.Item.ID = pair.Value.ID;
|
|
|
- alloc.Job.ID = breakup.Item1;
|
|
|
- alloc.Quantity = breakup.Item4;
|
|
|
- allocations.Add(alloc);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (allocations.Any())
|
|
|
- Client.Save(allocations,"Created from Stock Forecast Screen");
|
|
|
- });
|
|
|
-
|
|
|
+ window.CreateOrders("Stock Forecast");
|
|
|
|
|
|
SelectedForOrder.Clear();
|
|
|
OrderButton.IsEnabled = false;
|
|
|
- MessageWindow.ShowMessage($"The following orders were created:\n- {string.Join("\n- ",orders.Select(x=>x.Item1.PONumber))}", $"Created {orders.Count} orders");
|
|
|
return true;
|
|
|
}
|
|
|
|