Browse Source

Batch improvements

Kenric Nugteren 1 year ago
parent
commit
ec3b99cc9b

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

@@ -353,7 +353,7 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
                 min.Notes = $"Moved From {holding.Location.Code} by {App.EmployeeName}";
                 updates.Add(min);
             }
-            Client.Save(updates, "Relocated from Stock Locations Screen");
+            SaveBatch(StockMovementBatchType.Transfer, updates);
             DoChanged();
             Refresh(false, true);
         }
@@ -412,7 +412,7 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
         return result;
     }
 
-    private static void SaveBatch(StockMovementBatchType type, StockMovement[] movements)
+    private static void SaveBatch(StockMovementBatchType type, IList<StockMovement> movements)
     {
         var batch = new StockMovementBatch();
         batch.Type = type;

+ 25 - 2
prs.stores/PurchaseOrderItemStore.cs

@@ -80,7 +80,8 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
                     x => x.Dimensions.Unit.Formula,
                     x => x.Dimensions.Unit.Format,
                     x => x.Dimensions.Unit.Code,
-                    x => x.Dimensions.Unit.Description
+                    x => x.Dimensions.Unit.Description,
+                    x => x.Batch.ID
                 )
             ).Rows.Select(x => x.ToObject<StockMovement>()).ToList();
             if (!result.Any())
@@ -283,9 +284,19 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
             }
         }
 
+        StockMovementBatch? batch = null;
         foreach (var movement in movements)
         {
-            movement.Batch.Type = StockMovementBatchType.Receipt;
+            if(movement.Batch.ID == Guid.Empty)
+            {
+                batch ??= new StockMovementBatch
+                {
+                    Type = StockMovementBatchType.Receipt,
+                    TimeStamp = DateTime.Now,
+                    Notes = $"Received on PO"
+                };
+            }
+
             movement.Date = entity.ReceivedDate;
             movement.Product.ID = entity.Product.ID;
             movement.Received = entity.Qty;
@@ -309,6 +320,18 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
             movement.JobRequisitionItem.ID = jobRequisitionItemID;
         }
 
+        if(batch is not null)
+        {
+            FindSubStore<StockMovementBatch>().Save(batch, "Received on PO");
+            foreach(var movement in movements)
+            {
+                if(movement.Batch.ID == Guid.Empty)
+                {
+                    movement.Batch.ID = batch.ID;
+                }
+            }
+        }
+
         var updates = movements.Where(x => x.IsChanged()).ToList();
         if (updates.Any())
             FindSubStore<StockMovement>().Save(updates, "Updated by Purchase Order Modification");