|
@@ -234,29 +234,34 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
&& !entity.Qty.IsEffectivelyEqual(0.0))
|
|
|
{
|
|
|
poCost += entity.Cost * entity.Consignment.ExTax / consigntask.Result;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // First, we receive all stock into the main allocation.
|
|
|
+ CreateReceive(movements, entity, locationid, entity.Job, null, entity.Qty, poCost);
|
|
|
|
|
|
foreach (var poia in allocations)
|
|
|
{
|
|
|
+ if (poia.Quantity == 0) continue;
|
|
|
+
|
|
|
+ // Then, we make transfers into each of the allocations.
|
|
|
var jri = poia.JobRequisitionItem.ID == Guid.Empty ? null : poia.JobRequisitionItem;
|
|
|
- CreateMovement(entity, locationid, movements, poia.Job, jri, poia.Quantity, poCost);
|
|
|
-
|
|
|
- //CreateMovement(entity, locationid, movements, poia.Job, poia.JobRequisitionItem, poia.Quantity, poCost);
|
|
|
-
|
|
|
- //// Going through each jri, make sure we don't allocate more than the po line allows
|
|
|
- //var jriQty = Math.Min(jri.Qty, _pototal);
|
|
|
- //// And reduce the po balance by the jri Allocation
|
|
|
- //_pototal -= jriQty;
|
|
|
- //
|
|
|
- //// Let's not make zero-quantity transactions
|
|
|
- //if (!jriQty.IsEffectivelyEqual(0.0))
|
|
|
- // CreateMovement(entity, locationid, movements, jri, jriQty, poCost);
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- // If there is any left over (ie over/under-ordered), now we can create
|
|
|
- // a second transaction to receive the unallocated stock
|
|
|
- CreateMovement(entity, locationid, movements, entity.Job, null, freeQty, poCost);
|
|
|
+ var tOut = CreateStockMovement(movements, entity, locationid, entity.Job, null, poCost);
|
|
|
+ tOut.Type = StockMovementType.TransferOut;
|
|
|
+ tOut.Issued = poia.Quantity;
|
|
|
+ tOut.System = true;
|
|
|
+
|
|
|
+ var tIn = CreateStockMovement(movements, entity, locationid, poia.Job, jri, poCost);
|
|
|
+ tIn.Type = StockMovementType.TransferIn;
|
|
|
+ tIn.Received = poia.Quantity;
|
|
|
+ tIn.Transaction = tOut.Transaction;
|
|
|
+ tIn.System = true;
|
|
|
+
|
|
|
+ if(jri is not null)
|
|
|
+ {
|
|
|
+ CreateJRICancelledTransfer(tIn, entity, movements, jri, poia.Quantity);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
FindSubStore<StockMovementBatch>().Save(batch, "Received on PO");
|
|
|
foreach(var mvt in movements)
|
|
@@ -313,7 +318,73 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
entity.CancelChanges();
|
|
|
}
|
|
|
|
|
|
- private static void CreateMovement(PurchaseOrderItem entity, Guid locationid, List<StockMovement> movements, IJob? job, IJobRequisitionItem? jri, double qty, double cost)
|
|
|
+ private static void CreateJRICancelledTransfer(
|
|
|
+ IStockHolding movement,
|
|
|
+ PurchaseOrderItem entity,
|
|
|
+ List<StockMovement> movements,
|
|
|
+ IJobRequisitionItem jri,
|
|
|
+ double qty)
|
|
|
+ {
|
|
|
+ var lastMovement = movements.Count > 0 ? movements[^1] : null;
|
|
|
+
|
|
|
+ var tOut = movement.CreateMovement();
|
|
|
+ tOut.JobRequisitionItem.ID = jri.ID;
|
|
|
+ tOut.Date = lastMovement is not null ? lastMovement.Date.AddTicks(1) : entity.ReceivedDate;
|
|
|
+ tOut.Issued = qty;
|
|
|
+ tOut.OrderItem.ID = entity.ID;
|
|
|
+ tOut.Notes = "Internal transfer from cancelled requisition";
|
|
|
+ tOut.System = true;
|
|
|
+ tOut.Cost = entity.Cost;
|
|
|
+ tOut.Type = StockMovementType.TransferOut;
|
|
|
+
|
|
|
+ var tIn = movement.CreateMovement();
|
|
|
+ tIn.Transaction = tOut.Transaction;
|
|
|
+ tIn.Date = tOut.Date.AddTicks(1);
|
|
|
+ tIn.Received = qty;
|
|
|
+ tIn.OrderItem.ID = entity.ID;
|
|
|
+ tOut.Notes = "Internal transfer from cancelled requisition";
|
|
|
+ tOut.System = true;
|
|
|
+ tIn.Cost = entity.Cost;
|
|
|
+ tIn.Type = StockMovementType.TransferIn;
|
|
|
+
|
|
|
+ movements.Add(tOut);
|
|
|
+ movements.Add(tIn);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static StockMovement CreateStockMovement(
|
|
|
+ List<StockMovement> movements,
|
|
|
+ PurchaseOrderItem entity,
|
|
|
+ Guid locationID,
|
|
|
+ IJob? job, IJobRequisitionItem? jri,
|
|
|
+ double cost)
|
|
|
+ {
|
|
|
+ var movement = new StockMovement();
|
|
|
+ movement.Product.ID = entity.Product.ID;
|
|
|
+ movement.Location.ID = locationID;
|
|
|
+ movement.Style.ID = entity.Style.ID;
|
|
|
+ if(job is not null)
|
|
|
+ {
|
|
|
+ movement.Job.ID = job.ID;
|
|
|
+ }
|
|
|
+ movement.Dimensions.CopyFrom(entity.Dimensions);
|
|
|
+
|
|
|
+ var lastMovement = movements.Count > 0 ? movements[^1] : null;
|
|
|
+
|
|
|
+ movement.Date = lastMovement is not null ? lastMovement.Date.AddTicks(1) : entity.ReceivedDate;
|
|
|
+ movement.Employee.ID = Guid.Empty;
|
|
|
+ movement.Cost = cost;
|
|
|
+
|
|
|
+ if (jri is not null)
|
|
|
+ {
|
|
|
+ movement.JobRequisitionItem.ID = jri.ID;
|
|
|
+ }
|
|
|
+
|
|
|
+ movements.Add(movement);
|
|
|
+
|
|
|
+ return movement;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void CreateReceive(List<StockMovement> movements, PurchaseOrderItem entity, Guid locationid, IJob? job, IJobRequisitionItem? jri, double qty, double cost)
|
|
|
{
|
|
|
if (qty.IsEffectivelyEqual(0.0)) return;
|
|
|
|
|
@@ -334,39 +405,13 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
movement.Notes = string.Format("Received on PO {0}", entity.PurchaseOrderLink.PONumber);
|
|
|
movement.Cost = cost;
|
|
|
movement.Type = StockMovementType.Receive;
|
|
|
- movements.Add(movement);
|
|
|
|
|
|
if (jri is not null)
|
|
|
{
|
|
|
movement.JobRequisitionItem.ID = jri.ID;
|
|
|
- if (!jri.Cancelled.IsEmpty())
|
|
|
- {
|
|
|
- // We need to create an immediate transfer in and out of the job requisition item.
|
|
|
-
|
|
|
- var tOut = movement.CreateMovement();
|
|
|
- tOut.JobRequisitionItem.ID = jri.ID;
|
|
|
- tOut.Date = entity.ReceivedDate;
|
|
|
- tOut.Issued = qty;
|
|
|
- tOut.OrderItem.ID = entity.ID;
|
|
|
- tOut.Notes = "Internal transfer from cancelled requisition";
|
|
|
- tOut.System = true;
|
|
|
- tOut.Cost = entity.Cost;
|
|
|
- tOut.Type = StockMovementType.TransferOut;
|
|
|
-
|
|
|
- var tIn = movement.CreateMovement();
|
|
|
- tIn.Transaction = tOut.Transaction;
|
|
|
- tIn.Date = entity.ReceivedDate;
|
|
|
- tIn.Received = qty;
|
|
|
- tIn.OrderItem.ID = entity.ID;
|
|
|
- tOut.Notes = "Internal transfer from cancelled requisition";
|
|
|
- tOut.System = true;
|
|
|
- tIn.Cost = entity.Cost;
|
|
|
- tIn.Type = StockMovementType.TransferIn;
|
|
|
-
|
|
|
- movements.Add(tOut);
|
|
|
- movements.Add(tIn);
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
+ movements.Add(movement);
|
|
|
}
|
|
|
|
|
|
private void DeleteStockMovements(PurchaseOrderItem entity)
|