|
@@ -226,9 +226,6 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
}
|
|
|
|
|
|
var transactionID = Guid.NewGuid();
|
|
|
-
|
|
|
- // First, we receive all stock into the main allocation.
|
|
|
- CreateReceive(movements, entity, locationid, entity.Job, null, entity.Qty, poCost, transactionID);
|
|
|
|
|
|
foreach (var poia in allocations)
|
|
|
{
|
|
@@ -236,24 +233,20 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
|
|
|
// Then, we make transfers into each of the allocations.
|
|
|
var jri = poia.JobRequisitionItem.ID == Guid.Empty ? null : poia.JobRequisitionItem;
|
|
|
-
|
|
|
- var tOut = CreateStockMovement(movements, entity, locationid, entity.Job, null, poCost, transactionID);
|
|
|
- tOut.Type = StockMovementType.TransferOut;
|
|
|
- tOut.Issued = poia.Quantity;
|
|
|
- tOut.System = true;
|
|
|
-
|
|
|
- var tIn = CreateStockMovement(movements, entity, locationid, poia.Job, jri, poCost, transactionID);
|
|
|
- tIn.Type = StockMovementType.TransferIn;
|
|
|
- tIn.Received = poia.Quantity;
|
|
|
- tIn.Transaction = tOut.Transaction;
|
|
|
- tIn.System = true;
|
|
|
+ var mvt = CreateReceive(movements, entity, locationid, poia.Job, jri, poia.Quantity, poCost, transactionID);
|
|
|
|
|
|
if(jri is not null && !jri.Cancelled.IsEmpty())
|
|
|
{
|
|
|
- CreateJRICancelledTransfer(tIn, entity, movements, jri, poia.Quantity, Guid.NewGuid());
|
|
|
+ CreateJRICancelledTransfer(mvt, entity, movements, jri, poia.Quantity, Guid.NewGuid());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var qty = entity.Qty - allocations.Sum(x => x.Quantity);
|
|
|
+ if(qty != 0)
|
|
|
+ {
|
|
|
+ CreateReceive(movements, entity, locationid, entity.Job, null, qty, poCost, transactionID);
|
|
|
+ }
|
|
|
+
|
|
|
FindSubStore<StockMovementBatch>().Save(batch, "Received on PO");
|
|
|
foreach(var mvt in movements)
|
|
|
{
|
|
@@ -379,10 +372,8 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
return movement;
|
|
|
}
|
|
|
|
|
|
- private static void CreateReceive(List<StockMovement> movements, PurchaseOrderItem entity, Guid locationid, IJob? job, IJobRequisitionItem? jri, double qty, double cost, Guid transactionID)
|
|
|
+ private static StockMovement CreateReceive(List<StockMovement> movements, PurchaseOrderItem entity, Guid locationid, IJob? job, IJobRequisitionItem? jri, double qty, double cost, Guid transactionID)
|
|
|
{
|
|
|
- if (qty.IsEffectivelyEqual(0.0)) return;
|
|
|
-
|
|
|
var movement = new StockMovement();
|
|
|
movement.Transaction = transactionID;
|
|
|
movement.Product.ID = entity.Product.ID;
|
|
@@ -408,6 +399,7 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
}
|
|
|
|
|
|
movements.Add(movement);
|
|
|
+ return movement;
|
|
|
}
|
|
|
|
|
|
private void DeleteStockMovements(PurchaseOrderItem entity)
|