|
@@ -236,8 +236,10 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
poCost += entity.Cost * entity.Consignment.ExTax / consigntask.Result;
|
|
|
}
|
|
|
|
|
|
+ var transactionID = Guid.NewGuid();
|
|
|
+
|
|
|
// First, we receive all stock into the main allocation.
|
|
|
- CreateReceive(movements, entity, locationid, entity.Job, null, entity.Qty, poCost);
|
|
|
+ CreateReceive(movements, entity, locationid, entity.Job, null, entity.Qty, poCost, transactionID);
|
|
|
|
|
|
foreach (var poia in allocations)
|
|
|
{
|
|
@@ -246,20 +248,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);
|
|
|
+ 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);
|
|
|
+ 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;
|
|
|
|
|
|
- if(jri is not null)
|
|
|
+ if(jri is not null && !jri.Cancelled.IsEmpty())
|
|
|
{
|
|
|
- CreateJRICancelledTransfer(tIn, entity, movements, jri, poia.Quantity);
|
|
|
+ CreateJRICancelledTransfer(tIn, entity, movements, jri, poia.Quantity, Guid.NewGuid());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -323,7 +325,8 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
PurchaseOrderItem entity,
|
|
|
List<StockMovement> movements,
|
|
|
IJobRequisitionItem jri,
|
|
|
- double qty)
|
|
|
+ double qty,
|
|
|
+ Guid transactionID)
|
|
|
{
|
|
|
var lastMovement = movements.Count > 0 ? movements[^1] : null;
|
|
|
|
|
@@ -335,10 +338,11 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
tOut.Notes = "Internal transfer from cancelled requisition";
|
|
|
tOut.System = true;
|
|
|
tOut.Cost = entity.Cost;
|
|
|
+ tOut.Transaction = transactionID;
|
|
|
tOut.Type = StockMovementType.TransferOut;
|
|
|
|
|
|
var tIn = movement.CreateMovement();
|
|
|
- tIn.Transaction = tOut.Transaction;
|
|
|
+ tIn.Transaction = transactionID;
|
|
|
tIn.Date = tOut.Date.AddTicks(1);
|
|
|
tIn.Received = qty;
|
|
|
tIn.OrderItem.ID = entity.ID;
|
|
@@ -356,7 +360,7 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
PurchaseOrderItem entity,
|
|
|
Guid locationID,
|
|
|
IJob? job, IJobRequisitionItem? jri,
|
|
|
- double cost)
|
|
|
+ double cost, Guid transactionID)
|
|
|
{
|
|
|
var movement = new StockMovement();
|
|
|
movement.Product.ID = entity.Product.ID;
|
|
@@ -374,6 +378,8 @@ internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
|
|
|
movement.Employee.ID = Guid.Empty;
|
|
|
movement.Cost = cost;
|
|
|
|
|
|
+ movement.Transaction = transactionID;
|
|
|
+
|
|
|
if (jri is not null)
|
|
|
{
|
|
|
movement.JobRequisitionItem.ID = jri.ID;
|
|
@@ -384,11 +390,12 @@ 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)
|
|
|
+ private static void 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;
|
|
|
if(job is not null)
|
|
|
{
|