Browse Source

Merge remote-tracking branch 'origin/kenric' into frank

frankvandenbos 9 months ago
parent
commit
b4d946454a

+ 1 - 1
prs.desktop/Panels/Products/Locations/StockHoldingGrid.cs

@@ -148,7 +148,7 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
 
     private bool RecalculateHoldings(Button arg1, CoreRow[] arg2)
     {
-        var result = StockUtils.RecalculateHoldings([Location.ID], out var _report);
+        var result = StockUtils.RecalculateHoldingsOfLocations([Location.ID], out var _report);
         MessageWindow.ShowMessage(String.Join("\n", _report ),"Recalculate");
         return result;
     }

+ 1 - 1
prs.desktop/Panels/Products/Locations/StockLocationPanel.xaml.cs

@@ -43,7 +43,7 @@ namespace PRSDesktop
             if (MessageWindow.ShowYesNo("Recalculate selected locations?", "Confirm"))
             {
                 var ids = Locations.ExtractValues(x => x.ID, Selection.Selected).ToArray();
-                if (StockUtils.RecalculateHoldings(ids, out var _report))
+                if (StockUtils.RecalculateHoldingsOfLocations(ids, out var _report))
                     Refresh();
                 MessageWindow.ShowMessage(String.Join("\n",_report ),"Recalculate");
             }

+ 4 - 110
prs.desktop/Panels/Products/Master List/ProductHoldingControl.cs

@@ -151,116 +151,10 @@ public class ProductHoldingControl : DynamicDataGrid<StockHolding>, IProductCont
         return false;
     }
     
-       private bool RecalculateHoldings(Button arg1, CoreRow[] arg2)
+    private bool RecalculateHoldings(Button arg1, CoreRow[] arg2)
     {
-        Dictionary<String, int> messages = new();
-        void AddMessage(String type)
-        {
-            messages.TryGetValue(type, out int count);
-            messages[type] = ++count;
-        }
-        
-        Progress.ShowModal("Recalculating", progress =>
-        {
-            progress.Report("Loading Data");
-            MultiQuery query = new MultiQuery();
-            
-            query.Add(
-                new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(Product.ID),
-                Columns.Required<StockHolding>().Add(x => x.ID)
-                    .Add(x => x.Product.ID)
-                    .Add(x => x.Job.ID)
-                    .Add(x => x.Style.ID)
-                    .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local)
-                    .Add(x => x.Units)
-                    .Add(x => x.AverageValue)            
-                    .Add(x => x.Available)            
-                    .Add(x => x.Qty)
-                    .Add(x => x.Weight)
-                    .Add(x => x.Value)
-            );
-            
-            query.Add(
-                new Filter<StockMovement>(x => x.Product.ID).IsEqualTo(Product.ID),
-                Columns.None<StockMovement>().Add(x => x.ID)
-                    .Add(x => x.Product.ID)
-                    .Add(x => x.Job.ID)
-                    .Add(x => x.Style.ID)
-                    .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local)
-                    .Add(x => x.Units)
-                    .Add(x => x.Cost)
-                    .Add(x => x.JobRequisitionItem.ID)
-            );
-            query.Query();
-            var holdings = query.Get<StockHolding>().ToObjects<StockHolding>().ToList();
-            var toDelete = new List<StockHolding>();
-            var movements = query.Get<StockMovement>().ToObjects<StockMovement>().ToList();
-
-            progress.Report("Processing");
-            var updates = new List<StockHolding>();
-            
-            while (movements.Any())
-            {
-                var first = movements.First();
-                var selected = movements.Where(x => x.IsEqualTo(first)).ToList();
-
-                var holding = holdings.FirstOrDefault(x => x.IsEqualTo(first));
-                if (holding == null)
-                {
-                    holding = new StockHolding();
-                    holding.Location.ID = first.Location.ID;
-                    holding.Product.ID = Product.ID;
-                    holding.Style.ID = first.Style.ID;
-                    holding.Job.ID = first.Job.ID;
-                    holding.Dimensions.CopyFrom(first.Dimensions);
-                }
-                holding.Recalculate(selected);
-
-                // Removing from the list so that it is not deleted.
-                if (holdings.Contains(holding))
-                    holdings.Remove(holding);
-
-                if (holding.Units.IsEffectivelyEqual(0.0) && holding.Available.IsEffectivelyEqual(0.0))
-                {
-                    if(holding.ID != Guid.Empty)
-                    {
-                        toDelete.Add(holding);
-                    }
-                }
-                else if (holding.IsChanged())
-                {
-                    AddMessage(holding.ID != Guid.Empty ? "updated" : "added");
-                    updates.Add(holding);
-                }
-
-                movements.RemoveAll(x => selected.Any(s => s.ID == x.ID));
-            }
-
-            toDelete.AddRange(holdings);
-            foreach (var holding in toDelete)
-                AddMessage("deleted");
-
-            if (updates.Any())
-            {
-                progress.Report($"Updating {updates.Count} Holdings");
-                new Client<StockHolding>().Save(updates.Where(x => x.IsChanged()), "Updated by Recalculation");
-            }
-
-            if (toDelete.Any())
-            {
-                progress.Report($"Deleting {toDelete.Count} Holdings");
-                new Client<StockHolding>().Delete(toDelete, "Removed by Recalculation");
-            }
-
-        });
-        MessageWindow.ShowMessage(
-            messages.Any() 
-                ? String.Join("\n", messages.Select(x => $"{x.Value} holdings {x.Key}"))
-                : "Nothing to Update!"
-            ,"Recalculate");
-        return true;
+        var result = StockUtils.RecalculateHoldingsOfProducts([Product.ID], out var messages);
+        MessageWindow.ShowMessage(string.Join("\n", messages), "Recalculate");
+        return result;
     }
-
- 
-
 }

+ 12 - 3
prs.desktop/Utils/StockUtils.cs

@@ -11,7 +11,16 @@ namespace PRSDesktop;
 
 public static class StockUtils
 {
-    public static bool RecalculateHoldings(Guid[] locationIDs, out List<String> report)
+    public static bool RecalculateHoldingsOfLocations(Guid[] locationIDs, out List<String> report)
+    {
+        return RecalculateHoldings(new Filter<IStockHolding>(x => x.Location.ID).InList(locationIDs), out report);
+    }
+    public static bool RecalculateHoldingsOfProducts(Guid[] productIDs, out List<String> report)
+    {
+        return RecalculateHoldings(new Filter<IStockHolding>(x => x.Product.ID).InList(productIDs), out report);
+    }
+
+    public static bool RecalculateHoldings(Filter<IStockHolding> filter, out List<String> report)
     {
         bool result = false;
         Dictionary<String, int> messages = new();
@@ -28,7 +37,7 @@ public static class StockUtils
             MultiQuery query = new MultiQuery();
 
             query.Add(
-                new Filter<StockHolding>(x => x.Location.ID).InList(locationIDs),
+                filter.Cast<StockHolding>(),
                 Columns.Required<StockHolding>().Add(x => x.ID)
                     .Add(x => x.Location.ID)
                     .Add(x => x.Product.ID)
@@ -44,7 +53,7 @@ public static class StockUtils
             );
 
             query.Add(
-                new Filter<StockMovement>(x => x.Location.ID).InList(locationIDs),
+                filter.Cast<StockMovement>(),
                 Columns.None<StockMovement>().Add(x => x.ID)
                     .Add(x=>x.Location.ID)
                     .Add(x => x.Product.ID)

+ 1 - 1
prs.desktop/prsdesktop.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Desktop"
-#define MyAppVersion "8.24"
+#define MyAppVersion "8.24a"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSDesktop.exe"

+ 1 - 1
prs.licensing/PRSLicensing.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Licensing"
-#define MyAppVersion "8.24"
+#define MyAppVersion "8.24a"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSLicensing.exe"

+ 1 - 1
prs.server/PRSServer.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Server"
-#define MyAppVersion "8.24"
+#define MyAppVersion "8.24a"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSServer.exe"