Selaa lähdekoodia

Fixed Stock Movement Transfers when Requisition JobLinks do not match Requisition Item (ie Holding) JobLinks

frogsoftware 1 vuosi sitten
vanhempi
commit
0887c23995
1 muutettua tiedostoa jossa 26 lisäystä ja 4 poistoa
  1. 26 4
      prs.stores/RequisitionStore.cs

+ 26 - 4
prs.stores/RequisitionStore.cs

@@ -53,6 +53,7 @@ namespace Comal.Stores
                         .Add(x => x.Style.ID)
                         .Add(x => x.Product.ID)
                         .Add(x => x.JobRequisitionItem.ID)
+                        .Add(x =>x.JobLink.ID)
                         .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local)
                         .Add(x => x.ActualQuantity)
                         .AddDimensionsColumns(x => x.Product.DefaultInstance.Dimensions, Dimensions.ColumnsType.Local)
@@ -274,14 +275,14 @@ namespace Comal.Stores
             foreach (var item in items)
             {
                 var holdingQty = 0.0;
-                if(entity.JobLink.ID != Guid.Empty)
+                if(item.JobLink.ID != Guid.Empty)
                 {
                     var holdings = Provider.Query<StockHolding>(
                         new Filter<StockHolding>(x => x.Location.ID).IsEqualTo(item.Location.ID)
                             .And(x => x.Product.ID).IsEqualTo(item.Product.ID)
                             .And(x => x.Style.ID).IsEqualTo(item.Style.ID)
                             .And(x => x.Dimensions).DimensionEquals(item.Dimensions)
-                            .And(x => x.Job.ID).IsEqualTo(entity.JobLink.ID)
+                            .And(x => x.Job.ID).IsEqualTo(item.JobLink.ID)
                             .And(x => x.Qty).IsGreaterThan(0.0),
                         Columns.None<StockHolding>().Add(x => x.Qty)
                     );
@@ -308,7 +309,7 @@ namespace Comal.Stores
                     from.Type = StockMovementType.TransferOut;
 
                     // ... to the job.
-                    var to = CreateStockMovement(entity.Employee, entity.Filled, batch, item.Product, item.Location, item.Style, entity.JobLink, item.JobRequisitionItem, dimensions, txnid, true,
+                    var to = CreateStockMovement(entity.Employee, entity.Filled, batch, item.Product, item.Location, item.Style, item.JobLink, item.JobRequisitionItem, dimensions, txnid, true,
                         $"Requisition #{entity.Number} Internal Transfer");
                     to.Received = extraRequired;
                     to.Type = StockMovementType.TransferIn;
@@ -319,7 +320,28 @@ namespace Comal.Stores
                     // Now we have a full qty in the job holding, and we can issue to site.
                 }
 
-                var mvt = CreateStockMovement(entity.Employee, entity.Filled, batch, item.Product, item.Location, item.Style, entity.JobLink, item.JobRequisitionItem, dimensions, txnid,
+                JobRequisitionItemLink? link = item.JobRequisitionItem;
+                if (entity.JobLink.ID != item.JobLink.ID)
+                {
+                    // Transfer from the item job to the requisition job
+                    var from = CreateStockMovement(entity.Employee, entity.Filled, batch, item.Product, item.Location, item.Style, item.JobLink, link,
+                        dimensions, txnid, true, $"Requisition #{entity.Number} Internal Transfer");
+                    from.Issued = qty;
+                    from.Type = StockMovementType.TransferOut;
+
+                    // ... to the job.
+                    var to = CreateStockMovement(entity.Employee, entity.Filled, batch, item.Product, item.Location, item.Style, entity.JobLink, null, dimensions, txnid, true,
+                        $"Requisition #{entity.Number} Internal Transfer");
+                    to.Received = qty;
+                    to.Type = StockMovementType.TransferIn;
+
+                    updates.Add(from);
+                    updates.Add(to);
+
+                    link = null;
+                }
+
+                var mvt = CreateStockMovement(entity.Employee, entity.Filled, batch, item.Product, item.Location, item.Style, entity.JobLink, link, dimensions, txnid,
                     false,
                     $"Requisition #{entity.Number}");
                 mvt.Issued = qty;