|
@@ -110,6 +110,8 @@ public class StockForecastOrderingItem : BaseObject
|
|
|
[EnumLookupEditor(typeof(SupplierProductOrderStrategy))]
|
|
|
public SupplierProductOrderStrategy OrderStrategy { get; set; }
|
|
|
|
|
|
+ public bool CustomStrategy { get; set; } = false;
|
|
|
+
|
|
|
public StockForecastOrderingItemQuantity[] Quantities = [];
|
|
|
|
|
|
public StockForecastOrderingItemQuantity GetQuantity(int i) => Quantities[i];
|
|
@@ -210,6 +212,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
StockForecastOrderingStrategy.RoundUp => SupplierProductOrderStrategy.RoundUp,
|
|
|
StockForecastOrderingStrategy.PerProduct or _ => item.Product.OrderStrategy
|
|
|
};
|
|
|
+ item.CustomStrategy = false;
|
|
|
}
|
|
|
|
|
|
CalculateQuantities(false);
|
|
@@ -382,17 +385,22 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
return qty;
|
|
|
}
|
|
|
|
|
|
+ private SupplierProduct CalculateSupplierProduct(StockForecastOrderingItem item, int supplierIdx)
|
|
|
+ {
|
|
|
+ var supplierProduct = SelectSupplierProduct(SupplierProducts.Where(x => x.Product.ID == item.Product.ID && x.Style.ID == item.Style.ID && x.SupplierLink.ID == Suppliers[supplierIdx].ID), item);
|
|
|
+
|
|
|
+ var qty = item.GetQuantity(supplierIdx);
|
|
|
+ qty.SupplierProduct = supplierProduct;
|
|
|
+ qty.Total = 0;
|
|
|
+ return supplierProduct;
|
|
|
+ }
|
|
|
+
|
|
|
private void CalculateSupplierProduct(StockForecastOrderingItem item)
|
|
|
{
|
|
|
var selectedSupplierProducts = new List<SupplierProduct>();
|
|
|
for(int i = 0; i < Suppliers.Length; ++i)
|
|
|
{
|
|
|
- var supplierProduct = SelectSupplierProduct(SupplierProducts.Where(x => x.Product.ID == item.Product.ID && x.Style.ID == item.Style.ID && x.SupplierLink.ID == Suppliers[i].ID), item);
|
|
|
-
|
|
|
- var qty = item.GetQuantity(i);
|
|
|
- qty.SupplierProduct = supplierProduct;
|
|
|
- qty.Total = 0;
|
|
|
-
|
|
|
+ var supplierProduct = CalculateSupplierProduct(item, i);
|
|
|
if(supplierProduct is not null)
|
|
|
{
|
|
|
selectedSupplierProducts.Add(supplierProduct);
|
|
@@ -512,8 +520,8 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
var columns = new DynamicGridColumns();
|
|
|
columns.Add<StockForecastOrderingItem, string>(x => x.Product.Code, 120, "Product Code", "", Alignment.MiddleCenter);
|
|
|
columns.Add<StockForecastOrderingItem, string>(x => x.Product.Name, 200, "Product Name", "", Alignment.MiddleLeft);
|
|
|
- columns.Add<StockForecastOrderingItem, string>(x => x.Style.Code, 80, "Style", "", Alignment.MiddleCenter);
|
|
|
columns.Add<StockForecastOrderingItem, string>(x => x.Dimensions.UnitSize, 80, "Size", "", Alignment.MiddleCenter);
|
|
|
+ columns.Add<StockForecastOrderingItem, string>(x => x.Style.Code, 80, "Style", "", Alignment.MiddleCenter);
|
|
|
if(OrderType == StockForecastOrderingType.JobOrder)
|
|
|
{
|
|
|
columns.Add<StockForecastOrderingItem, string>(x => x.Job.JobNumber, 80, "Job No.", "", Alignment.MiddleCenter);
|
|
@@ -536,10 +544,12 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
.Select(x => new KeyValuePair<SupplierProductOrderStrategy, string>(x, CoreUtils.Neatify(x.ToString())));
|
|
|
box.DisplayMemberPath = "Value";
|
|
|
box.SelectedValuePath = "Key";
|
|
|
- box.SelectedValue = item.OrderStrategy;
|
|
|
+ box.SelectedValue = item.CustomStrategy ? null : item.OrderStrategy;
|
|
|
box.SelectionChanged += (o, e) =>
|
|
|
{
|
|
|
- item.OrderStrategy = (SupplierProductOrderStrategy)box.SelectedValue;
|
|
|
+ if (box.SelectedValue is not SupplierProductOrderStrategy strategy) return;
|
|
|
+ item.OrderStrategy = strategy;
|
|
|
+ item.CustomStrategy = false;
|
|
|
CalculateSupplierProduct(item);
|
|
|
InvalidateRow(row);
|
|
|
};
|
|
@@ -735,11 +745,6 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
if (row is null) return null;
|
|
|
|
|
|
var item = LoadItem(row);
|
|
|
- var supplierProduct = GetSupplierProduct(item, Suppliers[idx].ID);
|
|
|
- if (supplierProduct is not null)
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
var menu = new ContextMenu();
|
|
|
menu.AddItem("Create Supplier Product", null, new Tuple<StockForecastOrderingItem, int>(item, idx), CreateSupplierProduct_Click);
|
|
@@ -753,20 +758,31 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
|
|
|
var comboBox = new ComboBox();
|
|
|
|
|
|
- comboBox.ItemsSource =
|
|
|
- SupplierProducts.Where(x => x.SupplierLink.ID == Suppliers[idx].ID && x.Product.ID == instance.Product.ID)
|
|
|
+ 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}"));
|
|
|
+ x.Style.ID != Guid.Empty ? $"{x.Dimensions.UnitSize}/{x.Style.Code}" : $"{x.Dimensions.UnitSize}"))
|
|
|
+ .ToArray();
|
|
|
comboBox.SelectedValuePath = "Key";
|
|
|
+
|
|
|
+ comboBox.ItemsSource = items;
|
|
|
comboBox.DisplayMemberPath = "Value";
|
|
|
|
|
|
var qty = instance.GetQuantity(idx);
|
|
|
|
|
|
comboBox.Bind(ComboBox.SelectedValueProperty, qty, x => x.SupplierProduct);
|
|
|
+ comboBox.SelectionChanged += (o, e) =>
|
|
|
+ {
|
|
|
+ instance.CustomStrategy = true;
|
|
|
+ InvalidateRow(row);
|
|
|
+ };
|
|
|
|
|
|
comboBox.VerticalContentAlignment = VerticalAlignment.Center;
|
|
|
comboBox.Margin = new Thickness(2);
|
|
|
+ if(items.Length == 0)
|
|
|
+ {
|
|
|
+ comboBox.IsEnabled = false;
|
|
|
+ }
|
|
|
|
|
|
return comboBox;
|
|
|
})
|
|
@@ -837,21 +853,15 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
if (DynamicGridUtils.EditEntity(supplierProduct, customiseGrid: EditSupplierProductGrid))
|
|
|
{
|
|
|
SupplierProducts.Add(supplierProduct);
|
|
|
+ var qty = item.GetQuantity(supplierIdx);
|
|
|
+ if(qty.SupplierProduct is null)
|
|
|
+ {
|
|
|
+ CalculateSupplierProduct(item, supplierIdx);
|
|
|
+ }
|
|
|
InvalidateGrid();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static bool Matches(StockForecastOrderingItem item, SupplierProduct supplierProduct)
|
|
|
- {
|
|
|
- return item.Product.ID == supplierProduct.Product.ID
|
|
|
- && item.Style.ID == supplierProduct.Style.ID
|
|
|
- && item.Dimensions.Equals(supplierProduct.Dimensions);
|
|
|
- }
|
|
|
- private SupplierProduct? GetSupplierProduct(StockForecastOrderingItem item, Guid supplierID)
|
|
|
- {
|
|
|
- return SupplierProducts.FirstOrDefault(x => x.SupplierLink.ID == supplierID && Matches(item, x));
|
|
|
- }
|
|
|
-
|
|
|
private class CostAggregate : ISummaryAggregate
|
|
|
{
|
|
|
public double Sum { get; private set; }
|