|
@@ -688,25 +688,32 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private double CalculateSupplierProductRequiredQuantity(StockOrderingItem item, SupplierProduct supplierProduct)
|
|
|
+ /// <summary>
|
|
|
+ /// Calculate the number of units of the given <paramref name="supplierProduct"/> are needed to fill the given item.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// If we are doing breakups, and <paramref name="useRequiredQuantity"/> is <see langword="true"/>, then we use the <see cref="StockOrderingItem.GetJobRequiredQuantities"/>; otherwise, we use <see cref="StockForecastOrderingItemQuantity.Breakups"/>.
|
|
|
+ /// </remarks>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="supplierProduct"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private double CalculateSupplierProductRequiredQuantity(StockOrderingItem item, SupplierProduct supplierProduct, bool useRequiredQuantity)
|
|
|
{
|
|
|
var supplierIdx = Suppliers.WithIndex().FirstOrDefault(x => x.Value.ID == supplierProduct.SupplierLink.ID).Key;
|
|
|
var qty = item.GetQuantity(supplierIdx);
|
|
|
- var req = OrderType == StockForecastOrderingType.StockOrder ? item.RequiredQuantity : qty.Breakups.Sum(x => x.Value);
|
|
|
+ var req = OrderType == StockForecastOrderingType.StockOrder
|
|
|
+ ? item.RequiredQuantity
|
|
|
+ : (useRequiredQuantity ? item.GetJobRequiredQuantities().Sum(x => x.Value) : qty.Breakups.Sum(x => x.Value));
|
|
|
|
|
|
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);
|
|
|
+ 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:
|
|
@@ -715,13 +722,13 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
.MinBy(x => x.CostPrice);
|
|
|
|
|
|
case SupplierProductOrderStrategy.LowestOverallPrice:
|
|
|
- return supplierProducts.MinBy(x => x.CostPrice * Math.Ceiling(CalculateSupplierProductRequiredQuantity(item, x) * DimensionsRatio(x)));
|
|
|
+ return supplierProducts.MinBy(x => x.CostPrice * Math.Ceiling(CalculateSupplierProductRequiredQuantity(item, x, true)));
|
|
|
|
|
|
case SupplierProductOrderStrategy.LowestUnitPrice:
|
|
|
- return supplierProducts.MinBy(x => x.CostPrice * DimensionsRatio(x));
|
|
|
+ return supplierProducts.MinBy(x => x.CostPrice / x.Dimensions.Value);
|
|
|
|
|
|
case SupplierProductOrderStrategy.LowestOverstock:
|
|
|
- return supplierProducts.MinBy(x => x.Dimensions.Value * Math.Ceiling(CalculateSupplierProductRequiredQuantity(item, x) * DimensionsRatio(x)));
|
|
|
+ return supplierProducts.MinBy(x => x.Dimensions.Value * Math.Ceiling(CalculateSupplierProductRequiredQuantity(item, x, true)));
|
|
|
|
|
|
default:
|
|
|
return null;
|
|
@@ -730,12 +737,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
|
|
|
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 requiredQuantity = CalculateSupplierProductRequiredQuantity(item, supplierProduct, useRequiredQuantity: false);
|
|
|
|
|
|
var _strategy = item.CustomStrategy
|
|
|
? SupplierProductOrderStrategy.LowestOverstock
|
|
@@ -750,7 +752,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockOrderingItem>
|
|
|
case SupplierProductOrderStrategy.LowestOverallPrice:
|
|
|
case SupplierProductOrderStrategy.LowestUnitPrice:
|
|
|
case SupplierProductOrderStrategy.LowestOverstock:
|
|
|
- return Math.Ceiling(requiredQuantity * DimensionsRatio(supplierProduct));
|
|
|
+ return Math.Ceiling(requiredQuantity);
|
|
|
default:
|
|
|
return 0.0;
|
|
|
}
|