|
@@ -8,7 +8,6 @@ using NPOI.SS.Formula.Functions;
|
|
|
using Syncfusion.Data;
|
|
|
using Syncfusion.Data.Extensions;
|
|
|
using Syncfusion.UI.Xaml.Grid;
|
|
|
-using Syncfusion.Windows.Shared;
|
|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
@@ -24,6 +23,7 @@ using System.Windows.Media.Imaging;
|
|
|
using Columns = InABox.Core.Columns;
|
|
|
using PRSDesktop.Panels.StockForecast.OrderScreen;
|
|
|
using PRSDimensionUtils;
|
|
|
+using Syncfusion.Windows.Shared;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
|
|
|
@@ -56,6 +56,7 @@ public class StockForecastOrderData(ProductLink product, ProductStyleLink style,
|
|
|
|
|
|
public class QuantityBreakup(Guid jobID, Guid requiID, string description, double qty)
|
|
|
{
|
|
|
+ // This may be blank, in which case this refers to General Stock.
|
|
|
public Guid JobID { get; set; } = jobID;
|
|
|
|
|
|
public Guid JobRequiItemID { get; set; } = requiID;
|
|
@@ -146,7 +147,10 @@ public class StockOrderingItem : BaseObject
|
|
|
[EnumLookupEditor(typeof(SupplierProductOrderStrategy))]
|
|
|
public SupplierProductOrderStrategy OrderStrategy { get; set; }
|
|
|
|
|
|
- private Dictionary<StockForecastBreakupKey, double> JobRequiredQuantities { get; set; } = [];
|
|
|
+ private Dictionary<StockForecastBreakupKey, double> JobRequiredQuantities { get; set; } = new()
|
|
|
+ {
|
|
|
+ { new(Guid.Empty, Guid.Empty), 0.0 }
|
|
|
+ };
|
|
|
public Dictionary<StockForecastBreakupKey, double> GetJobRequiredQuantities()
|
|
|
{
|
|
|
return JobRequiredQuantities;
|
|
@@ -167,6 +171,10 @@ public class StockOrderingItem : BaseObject
|
|
|
? Quantities.Sum(x => x.OrderTotal)
|
|
|
: Quantities.Sum(x => x.JobTotal);
|
|
|
|
|
|
+ public double GetRequiredQuantity(StockForecastOrderingType type) => type == StockForecastOrderingType.StockOrder
|
|
|
+ ? RequiredQuantity
|
|
|
+ : JobRequiredQuantities.Values.Sum();
|
|
|
+
|
|
|
public void SetQuantities(StockForecastOrderingItemQuantity[] quantities)
|
|
|
{
|
|
|
Quantities = quantities;
|
|
@@ -203,13 +211,11 @@ public enum StockForecastOrderingStrategy
|
|
|
|
|
|
public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>, ISpecificGrid
|
|
|
{
|
|
|
+ #region Internal Data + Caches
|
|
|
+
|
|
|
private List<SupplierProduct> SupplierProducts = [];
|
|
|
private SupplierLink[] Suppliers = [];
|
|
|
|
|
|
- public IList<StockForecastOrderData> OrderData { get; set; }
|
|
|
-
|
|
|
- public double TotalQuantity => Items.Sum(x => x.GetTotalQuantity(OrderType));
|
|
|
-
|
|
|
private DynamicActionColumn[] SupplierProductColumns = [];
|
|
|
private DynamicActionColumn[] QuantityColumns = [];
|
|
|
private DynamicActionColumn[] CostColumns = [];
|
|
@@ -217,8 +223,14 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
private readonly Dictionary<Guid, Job> JobDetails = [];
|
|
|
private readonly Dictionary<Guid, JobRequisitionItem> JobRequiDetails = [];
|
|
|
|
|
|
+ #endregion
|
|
|
+
|
|
|
private static BitmapImage _warning = PRSDesktop.Resources.warning.AsBitmapImage();
|
|
|
|
|
|
+ #region Public Properties
|
|
|
+
|
|
|
+ public IList<StockForecastOrderData> OrderData { get; set; }
|
|
|
+
|
|
|
private StockForecastOrderingType _orderType = StockForecastOrderingType.Breakup;
|
|
|
public StockForecastOrderingType OrderType
|
|
|
{
|
|
@@ -254,7 +266,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
{
|
|
|
foreach (var item in Items)
|
|
|
{
|
|
|
- item.OrderStrategy = ForecastOrderStrategyToProductOrderStrategy(value, item.Product.OrderStrategy);
|
|
|
+ item.OrderStrategy = CastOrderStrategyToProductOrderStrategy(value, item.Product.OrderStrategy);
|
|
|
item.CustomStrategy = false;
|
|
|
}
|
|
|
CalculateQuantities(false);
|
|
@@ -263,20 +275,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static SupplierProductOrderStrategy ForecastOrderStrategyToProductOrderStrategy(StockForecastOrderingStrategy strategy, SupplierProductOrderStrategy defaultValue)
|
|
|
- {
|
|
|
- return strategy switch
|
|
|
- {
|
|
|
- StockForecastOrderingStrategy.Exact => SupplierProductOrderStrategy.Exact,
|
|
|
- StockForecastOrderingStrategy.LowestOverallPrice => SupplierProductOrderStrategy
|
|
|
- .LowestOverallPrice,
|
|
|
- StockForecastOrderingStrategy.LowestUnitPrice => SupplierProductOrderStrategy.LowestUnitPrice,
|
|
|
- StockForecastOrderingStrategy.LowestOverstock => SupplierProductOrderStrategy.LowestOverstock,
|
|
|
- StockForecastOrderingStrategy.RoundUp => SupplierProductOrderStrategy.RoundUp,
|
|
|
- StockForecastOrderingStrategy.PerProduct or _ => defaultValue
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
+ public double TotalQuantity => Items.Sum(x => x.GetTotalQuantity(OrderType));
|
|
|
public IEnumerable<StockForecastOrderingResult> Results
|
|
|
{
|
|
|
get
|
|
@@ -314,11 +313,28 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ #endregion
|
|
|
+
|
|
|
public StockForecastOrderingGrid()
|
|
|
{
|
|
|
HiddenColumns.Add(x => x.Product.Image.ID);
|
|
|
}
|
|
|
|
|
|
+ private static SupplierProductOrderStrategy CastOrderStrategyToProductOrderStrategy(StockForecastOrderingStrategy strategy, SupplierProductOrderStrategy defaultValue)
|
|
|
+ {
|
|
|
+ return strategy switch
|
|
|
+ {
|
|
|
+ StockForecastOrderingStrategy.Exact => SupplierProductOrderStrategy.Exact,
|
|
|
+ StockForecastOrderingStrategy.LowestOverallPrice => SupplierProductOrderStrategy
|
|
|
+ .LowestOverallPrice,
|
|
|
+ StockForecastOrderingStrategy.LowestUnitPrice => SupplierProductOrderStrategy.LowestUnitPrice,
|
|
|
+ StockForecastOrderingStrategy.LowestOverstock => SupplierProductOrderStrategy.LowestOverstock,
|
|
|
+ StockForecastOrderingStrategy.RoundUp => SupplierProductOrderStrategy.RoundUp,
|
|
|
+ StockForecastOrderingStrategy.PerProduct or _ => defaultValue
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
#region UI Component
|
|
|
|
|
|
private Component? _uiComponent;
|
|
@@ -399,11 +415,13 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
private bool _loadedData = false;
|
|
|
private void LoadData()
|
|
|
{
|
|
|
- var supplierColumns = Columns.None<SupplierProduct>().Add(x => x.ID)
|
|
|
+ var supplierProductColumns = Columns.None<SupplierProduct>().Add(x => x.ID)
|
|
|
.Add(x => x.SupplierLink.ID)
|
|
|
.Add(x => x.Product.ID)
|
|
|
.Add(x => x.Style.ID)
|
|
|
.Add(x => x.Style.Code)
|
|
|
+ .Add(x => x.Job.ID)
|
|
|
+ .Add(x => x.Job.JobNumber)
|
|
|
.Add(x => x.ForeignCurrencyPrice)
|
|
|
.Add(x => x.CostPrice)
|
|
|
.AddDimensionsColumns(x => x.Dimensions)
|
|
@@ -412,7 +430,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
SupplierProducts = Client.Query(
|
|
|
new Filter<SupplierProduct>(x => x.Product.ID).InList(OrderData.Select(x => x.Product.ID).ToArray())
|
|
|
.And(x => x.SupplierLink.ID).IsNotEqualTo(Guid.Empty),
|
|
|
- supplierColumns,
|
|
|
+ supplierProductColumns,
|
|
|
new SortOrder<SupplierProduct>(x => x.SupplierLink.Code))
|
|
|
.ToList<SupplierProduct>();
|
|
|
|
|
@@ -444,11 +462,6 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
var qty = item.GetQuantity(supplierIdx);
|
|
|
qty.SupplierProduct = supplierProduct;
|
|
|
qty.OrderTotal = 0;
|
|
|
- qty.Breakups.Clear();
|
|
|
- foreach(var id in item.GetJobRequiredQuantities().Keys)
|
|
|
- {
|
|
|
- qty.Breakups[id] = 0;
|
|
|
- }
|
|
|
|
|
|
return supplierProduct;
|
|
|
}
|
|
@@ -473,19 +486,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
if(supplierIdx != -1)
|
|
|
{
|
|
|
var qty = item.GetQuantity(supplierIdx);
|
|
|
- if(OrderType == StockForecastOrderingType.StockOrder)
|
|
|
- {
|
|
|
- qty.OrderTotal = GetRequiredQuantity(item, selectedSupplierProduct, item.RequiredQuantity);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- qty.Breakups.Clear();
|
|
|
- qty.OrderTotal = GetRequiredQuantity(item, selectedSupplierProduct, item.RequiredQuantity);
|
|
|
- foreach(var (id, q) in item.GetJobRequiredQuantities())
|
|
|
- {
|
|
|
- qty.Breakups[id] = q; // / item.RequiredQuantity * qty.OrderTotal;
|
|
|
- }
|
|
|
- }
|
|
|
+ qty.OrderTotal = GetRequiredQuantity(item, selectedSupplierProduct);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -503,7 +504,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
item.Product.CopyFrom(dataItem.Product);
|
|
|
item.Style.CopyFrom(dataItem.Style);
|
|
|
item.Dimensions.CopyFrom(dataItem.Dimensions);
|
|
|
- item.OrderStrategy = ForecastOrderStrategyToProductOrderStrategy(OrderStrategy, item.Product.OrderStrategy);
|
|
|
+ item.OrderStrategy = CastOrderStrategyToProductOrderStrategy(OrderStrategy, item.Product.OrderStrategy);
|
|
|
item.RequiredQuantity = dataItem.RequiredQuantity;
|
|
|
foreach(var breakup in dataItem.GetRequiredQuantities())
|
|
|
{
|
|
@@ -534,43 +535,53 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
|
|
|
#region Order Strategy
|
|
|
|
|
|
+ private double CalculateSupplierProductRequiredQuantity(StockOrderingItem item, SupplierProduct supplierProduct)
|
|
|
+ {
|
|
|
+ var req = item.GetRequiredQuantity(OrderType);
|
|
|
+
|
|
|
+ var d = new StockDimensions();
|
|
|
+ d.CopyFrom(supplierProduct.Dimensions);
|
|
|
+ var result = DimensionUtils.ConvertDimensions(d, 1.0, (f,c) => Client.Query(f,c));
|
|
|
+ req = Math.Ceiling(req / result);
|
|
|
+ return req;
|
|
|
+ }
|
|
|
+
|
|
|
private SupplierProduct? SelectSupplierProduct(IEnumerable<SupplierProduct> supplierProducts, StockOrderingItem item)
|
|
|
{
|
|
|
+ double DimensionsRatio(SupplierProduct x)
|
|
|
+ {
|
|
|
+ return item.Dimensions.Value / (x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value);
|
|
|
+ }
|
|
|
switch (item.OrderStrategy)
|
|
|
{
|
|
|
case SupplierProductOrderStrategy.Exact:
|
|
|
case SupplierProductOrderStrategy.RoundUp:
|
|
|
- return supplierProducts.Where(x => x.Dimensions.Equals(item.Dimensions) && x.Style.ID == item.Style.ID)
|
|
|
- .MinBy(x => x.CostPrice)
|
|
|
- ?? supplierProducts.Where(x => x.Dimensions.Equals(item.Dimensions))
|
|
|
- .MinBy(x => x.CostPrice);
|
|
|
+ return supplierProducts.Where(x => x.Dimensions.Equals(item.Dimensions))
|
|
|
+ .MinBy(x => x.CostPrice);
|
|
|
|
|
|
case SupplierProductOrderStrategy.LowestOverallPrice:
|
|
|
- return supplierProducts.Where(x => x.Style.ID == item.Style.ID)
|
|
|
- .MinBy(x => x.CostPrice *
|
|
|
- Math.Ceiling(item.RequiredQuantity * item.Dimensions.Value / (x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value)))
|
|
|
- ?? supplierProducts
|
|
|
- .MinBy(x => x.CostPrice * Math.Ceiling(item.RequiredQuantity * item.Dimensions.Value / (x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value)));
|
|
|
-
|
|
|
+ return supplierProducts.MinBy(x => x.CostPrice * Math.Ceiling(CalculateSupplierProductRequiredQuantity(item, x) * DimensionsRatio(x)));
|
|
|
+
|
|
|
case SupplierProductOrderStrategy.LowestUnitPrice:
|
|
|
- return supplierProducts.Where(x => x.Style.ID == item.Style.ID)
|
|
|
- .MinBy(x=>x.CostPrice * item.Dimensions.Value/(x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value))
|
|
|
- ?? supplierProducts
|
|
|
- .MinBy(x=>x.CostPrice * item.Dimensions.Value/(x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value));
|
|
|
+ return supplierProducts.MinBy(x => x.CostPrice * DimensionsRatio(x));
|
|
|
|
|
|
case SupplierProductOrderStrategy.LowestOverstock:
|
|
|
- return supplierProducts.Where(x => x.Style.ID == item.Style.ID)
|
|
|
- .MinBy(x=>x.Dimensions.Value * Math.Ceiling(item.RequiredQuantity * item.Dimensions.Value / (x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value)))
|
|
|
- ?? supplierProducts
|
|
|
- .MinBy(x=>x.Dimensions.Value * Math.Ceiling(item.RequiredQuantity * item.Dimensions.Value / (x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value)));
|
|
|
+ return supplierProducts.MinBy(x => x.Dimensions.Value * Math.Ceiling(CalculateSupplierProductRequiredQuantity(item, x) * DimensionsRatio(x)));
|
|
|
|
|
|
default:
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private double GetRequiredQuantity(StockOrderingItem item, SupplierProduct supplierProduct, double requiredQuantity)
|
|
|
+ private double GetRequiredQuantity(StockOrderingItem item, SupplierProduct supplierProduct)
|
|
|
{
|
|
|
+ var requiredQuantity = CalculateSupplierProductRequiredQuantity(item, supplierProduct);
|
|
|
+
|
|
|
+ double DimensionsRatio(SupplierProduct x)
|
|
|
+ {
|
|
|
+ return item.Dimensions.Value / (x.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : x.Dimensions.Value);
|
|
|
+ }
|
|
|
+
|
|
|
var _strategy = item.CustomStrategy
|
|
|
? SupplierProductOrderStrategy.LowestOverstock
|
|
|
: item.OrderStrategy;
|
|
@@ -584,7 +595,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
case SupplierProductOrderStrategy.LowestOverallPrice:
|
|
|
case SupplierProductOrderStrategy.LowestUnitPrice:
|
|
|
case SupplierProductOrderStrategy.LowestOverstock:
|
|
|
- return Math.Ceiling(requiredQuantity * item.Dimensions.Value / (supplierProduct.Dimensions.Value.IsEffectivelyEqual(0.0) ? (item.Dimensions.Value.IsEffectivelyEqual(0.0) ? 1.0 : item.Dimensions.Value) : supplierProduct.Dimensions.Value));
|
|
|
+ return Math.Ceiling(requiredQuantity * DimensionsRatio(supplierProduct));
|
|
|
default:
|
|
|
return 0.0;
|
|
|
}
|
|
@@ -666,9 +677,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
if(new Column<SupplierProduct>(x => x.SupplierLink.ID).IsEqualTo(column.ColumnName)
|
|
|
|| new Column<SupplierProduct>(x => x.Product.ID).IsEqualTo(column.ColumnName)
|
|
|
|| new Column<SupplierProduct>(x => x.Style.ID).IsEqualTo(column.ColumnName)
|
|
|
- || new Column<SupplierProduct>(x => x.Job.ID).IsEqualTo(column.ColumnName)
|
|
|
- // || new Column<SupplierProduct>(x => x.Dimensions).IsEqualTo(column.ColumnName)
|
|
|
- )
|
|
|
+ || new Column<SupplierProduct>(x => x.Job.ID).IsEqualTo(column.ColumnName))
|
|
|
{
|
|
|
editor.Editable = editor.Editable.Combine(Editable.Disabled);
|
|
|
}
|
|
@@ -766,6 +775,8 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ #region Job Data Cache
|
|
|
+
|
|
|
private void LoadJobData(IEnumerable<Guid> ids)
|
|
|
{
|
|
|
var neededIDs = ids.Where(x => x != Guid.Empty && !JobDetails.ContainsKey(x)).ToArray();
|
|
@@ -799,6 +810,8 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ #endregion
|
|
|
+
|
|
|
private class QuantityControl : ContentControl
|
|
|
{
|
|
|
private readonly StockOrderingItem Item;
|
|
@@ -817,7 +830,8 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
public void UpdateControl(StockForecastOrderingType mode)
|
|
|
{
|
|
|
// If no supplier product has been selected for this cell, we can't allow the user to select a quantity.
|
|
|
- if(Item.GetQuantity(SupplierIndex).SupplierProduct is null)
|
|
|
+ var supplierProduct = Item.GetQuantity(SupplierIndex).SupplierProduct;
|
|
|
+ if(supplierProduct is null)
|
|
|
{
|
|
|
Content = null;
|
|
|
return;
|
|
@@ -825,7 +839,6 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
|
|
|
if(mode == StockForecastOrderingType.StockOrder)
|
|
|
{
|
|
|
- // Otherwise, simple quantity textbox editor.
|
|
|
var editor = new DoubleTextBox
|
|
|
{
|
|
|
VerticalAlignment = VerticalAlignment.Stretch,
|
|
@@ -878,15 +891,6 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
btn.Click += (o, e) =>
|
|
|
{
|
|
|
var qty = Item.GetQuantity(SupplierIndex);
|
|
|
-
|
|
|
- var alloc = qty.Breakups
|
|
|
- .Where(x => !Guid.Equals(x.Key.JobID,Guid.Empty) || !Guid.Equals(x.Key.RequiID,Guid.Empty))
|
|
|
- .Sum(x => x.Value);
|
|
|
- var order = qty.OrderTotal;
|
|
|
- var dim = new StockDimensions();
|
|
|
- dim.CopyFrom(qty.SupplierProduct.Dimensions);
|
|
|
- DimensionUtils.ConvertDimensions(dim, ref order, (f,c) => Client.Query(f,c));
|
|
|
- var general = order - alloc;
|
|
|
|
|
|
Parent.LoadJobData(qty.Breakups.Keys.Select(x => x.JobID));
|
|
|
Parent.LoadJobRequiData(qty.Breakups.Keys.Select(x => x.RequiID));
|
|
@@ -919,20 +923,22 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
}).ToList();
|
|
|
|
|
|
var genitem = items.FirstOrDefault(x =>
|
|
|
- Guid.Equals(x.JobID, Guid.Empty) && Guid.Equals(x.JobRequiID, Guid.Empty));
|
|
|
+ x.JobID == Guid.Empty && x.JobRequiID == Guid.Empty);
|
|
|
if (genitem == null)
|
|
|
{
|
|
|
genitem = new StockForecastOrderingJobItem
|
|
|
{
|
|
|
Description = "General Stock",
|
|
|
JobID = Guid.Empty,
|
|
|
- JobRequiID = Guid.Empty,
|
|
|
-
|
|
|
+ JobRequiID = Guid.Empty
|
|
|
};
|
|
|
- items.Insert(0,genitem);
|
|
|
+ items.Insert(0, genitem);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ items.Remove(genitem);
|
|
|
+ items.Insert(0, genitem);
|
|
|
}
|
|
|
- genitem.Quantity = general;
|
|
|
-
|
|
|
|
|
|
var window = new StockForecastOrderJobScreen();
|
|
|
window.Items = items;
|
|
@@ -943,12 +949,9 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
qty.Breakups[new(item.JobID, item.JobRequiID)] = item.Quantity;
|
|
|
}
|
|
|
qty.DoChanged();
|
|
|
- var req = items.Sum(x => x.Quantity);
|
|
|
- var x = 1.0;
|
|
|
- var d = new StockDimensions();
|
|
|
- d.CopyFrom(qty.SupplierProduct.Dimensions);
|
|
|
- DimensionUtils.ConvertDimensions(d, ref x, (f,c) => Client.Query(f,c));
|
|
|
- req = Math.Ceiling(req / x);
|
|
|
+
|
|
|
+ var req = Parent.GetRequiredQuantity(Item, supplierProduct);
|
|
|
+
|
|
|
editor.Value = req;
|
|
|
qty.OrderTotal = req;
|
|
|
}
|
|
@@ -983,10 +986,13 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
|
|
|
var comboBox = new ComboBox();
|
|
|
comboBox.Tag = idx;
|
|
|
- var items = SupplierProducts.Where(x => x.SupplierLink.ID == Suppliers[idx].ID && x.Product.ID == instance.Product.ID)
|
|
|
- .Select(x => new KeyValuePair<SupplierProduct?, string>(
|
|
|
- x,
|
|
|
- x.Style.ID != Guid.Empty ? $"{x.Dimensions.UnitSize}/{x.Style.Code}" : $"{x.Dimensions.UnitSize}"));
|
|
|
+
|
|
|
+ var supplierProducts = string.IsNullOrWhiteSpace(instance.Dimensions.Unit.Conversion)
|
|
|
+ ? SupplierProducts.Where(x => x.Dimensions.Equals(instance.Dimensions))
|
|
|
+ : SupplierProducts;
|
|
|
+
|
|
|
+ var items = supplierProducts.Where(x => x.SupplierLink.ID == Suppliers[idx].ID && x.Product.ID == instance.Product.ID)
|
|
|
+ .Select(x => new KeyValuePair<SupplierProduct?, string>(x, $"Job {x.Job.JobNumber}: {x.Dimensions.UnitSize}"));
|
|
|
if (items.Any())
|
|
|
items = items.Prepend(new KeyValuePair<SupplierProduct?, string>(null, ""));
|
|
|
comboBox.SelectedValuePath = "Key";
|
|
@@ -1003,10 +1009,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
instance.CustomStrategy = true;
|
|
|
var _item = LoadItem(row);
|
|
|
var _product = ((o as ComboBox)?.SelectedValue as SupplierProduct ?? new SupplierProduct());
|
|
|
- qty.OrderTotal = GetRequiredQuantity(_item, _product, _item.RequiredQuantity);
|
|
|
- qty.Breakups.Clear();
|
|
|
- foreach(var (id, q) in _item.GetJobRequiredQuantities())
|
|
|
- qty.Breakups[id] = q;
|
|
|
+ qty.OrderTotal = GetRequiredQuantity(_item, _product);
|
|
|
|
|
|
InvalidateRow(row);
|
|
|
};
|
|
@@ -1015,7 +1018,6 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
comboBox.Margin = new Thickness(2);
|
|
|
if(!items.Any())
|
|
|
comboBox.IsEnabled = false;
|
|
|
-
|
|
|
|
|
|
return comboBox;
|
|
|
})
|