Ver código fonte

Added validation for StockForecsatOrderScreen

Kenric Nugteren 9 meses atrás
pai
commit
1db03c6e48

+ 1 - 6
prs.desktop/Panels/Stock Forecast/OrderScreen/StockForecastOrderScreen.xaml.cs

@@ -108,6 +108,7 @@ public partial class StockForecastOrderScreen : Window, INotifyPropertyChanged
 
     private void OKButton_Click(object sender, RoutedEventArgs e)
     {
+        if (!Grid.Validate()) return;
         DialogResult = true;
         Close();
     }
@@ -204,12 +205,6 @@ public partial class StockForecastOrderScreen : Window, INotifyPropertyChanged
                 {
                     foreach (var breakup in result.Breakups)
                     {
-                        if(breakup.JobID == Guid.Empty)
-                        {
-                            // This is a general stock allocation, which doesn't get an allocation.
-                            continue;
-                        }
-
                         var alloc = new PurchaseOrderItemAllocation();
                         alloc.Item.ID = poi.ID;
                         alloc.Job.ID = breakup.JobID;

+ 22 - 18
prs.desktop/Panels/Stock Forecast/OrderScreen/StockForecastOrderingGrid.cs

@@ -37,7 +37,7 @@ public class StockForecastOrderData(ProductLink product, ProductStyleLink style,
 
     public class QuantityBreakup(Guid jobID, Guid requiID, string description, double qty)
     {
-        public Guid JobID { get; set; } = jobID;
+        public Guid JobID { get; set; } = jobID != Guid.Empty ? jobID : throw new ArgumentException("jobID cannot be Guid.Empty!", "jobID");
 
         public Guid JobRequiItemID { get; set; } = requiID;
 
@@ -269,6 +269,23 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
         HiddenColumns.Add(x => x.Product.Image.ID);
     }
 
+    public bool Validate()
+    {
+        if(OrderType == StockForecastOrderingType.Breakup)
+        {
+            foreach(var item in Items)
+            {
+                var sum = item.Breakups.Sum(x => x.Quantity);
+                if(sum > item.GetTotalQuantity(OrderType))
+                {
+                    MessageWindow.ShowMessage($"Not enough being ordered for {item.Product.Code}/{item.Style.Code}: requires at least {sum}", "Not enough");
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
     #region UI Component
 
     private Component? _uiComponent;
@@ -482,6 +499,8 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
         DoChanged();
     }
 
+    #region Order Strategy
+
     private SupplierProduct? SelectSupplierProduct(IEnumerable<SupplierProduct> supplierProducts, StockForecastOrderingItem item)
     {
         switch (item.OrderStrategy)
@@ -534,6 +553,8 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
         }
     }
 
+    #endregion
+
     private bool _loadedColumns = false;
     protected override DynamicGridColumns LoadColumns()
     {
@@ -697,23 +718,6 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
         }
     }
 
-    // private void LoadJobData(IEnumerable<Guid> ids)
-    // {
-    //     var neededIDs = ids.Where(x => !JobDetails.ContainsKey(x)).ToArray();
-    //     if(neededIDs.Length > 0)
-    //     {
-    //         var details = Client.Query(
-    //             new Filter<Job>(x => x.ID).InList(neededIDs),
-    //             Columns.None<Job>().Add(x => x.ID)
-    //                 .Add(x => x.JobNumber)
-    //                 .Add(x => x.Name));
-    //         foreach(var job in details.ToObjects<Job>())
-    //         {
-    //             JobDetails[job.ID] = job;
-    //         }
-    //     }
-    // }
-
     private class QuantityControl : ContentControl
     {
         private readonly StockForecastOrderingItem Item;

+ 1 - 1
prs.desktop/Panels/Stock Forecast/StockForecastGrid.cs

@@ -962,7 +962,7 @@ public class StockForecastGrid : DynamicItemsListGrid<StockForecastItem>, IDataM
             var item = new StockForecastOrderData(forecastItem.Product, forecastItem.Style, forecastItem.Dimensions);
             item.RequiredQuantity = Optimise ? forecastItem.Optimised : forecastItem.Required;
 
-            item.RequiredQuantity = forecastItem.StockRequired;
+            //item.RequiredQuantity = forecastItem.StockRequired;
             // if(forecastItem.StockRequired > 0)
             // {
             //     item.SetRequiredQuantity(Guid.Empty, Guid.Empty, "", forecastItem.StockRequired);