Exemple #1
0
 private InventoryItemTransaction CreateInventoryTransaction(int quantity, InventoryTransactionReason reason, Part part)
 => new InventoryItemTransactionBuilder(this.Session).WithQuantity(quantity).WithReason(reason).WithPart(part).Build();
Exemple #2
0
 private InventoryItemTransaction CreateInventoryTransaction(int quantity, InventoryTransactionReason reason, Part part, SerialisedItem serialisedItem, Facility facility)
 => new InventoryItemTransactionBuilder(this.Session).WithQuantity(quantity).WithReason(reason).WithPart(part).WithSerialisedItem(serialisedItem).WithFacility(facility).Build();
        private void SyncInventoryTransactions(InventoryItem inventoryItem, int initialQuantity, InventoryTransactionReason reason, bool isCancellation)
        {
            var adjustmentQuantity   = 0;
            var existingQuantity     = 0;
            var matchingTransactions = this.InventoryItemTransactions.Where(t => t.Reason.Equals(reason) && t.Part.Equals(inventoryItem.Part)).ToArray();

            if (matchingTransactions.Length > 0)
            {
                existingQuantity = matchingTransactions.Sum(t => t.Quantity);
            }

            if (isCancellation)
            {
                adjustmentQuantity = 0 - existingQuantity;
            }
            else
            {
                adjustmentQuantity = initialQuantity - existingQuantity;
            }

            if (adjustmentQuantity != 0)
            {
                this.AddInventoryItemTransaction(new InventoryItemTransactionBuilder(this.strategy.Session)
                                                 .WithPart(inventoryItem.Part)
                                                 .WithQuantity(adjustmentQuantity)
                                                 .WithReason(reason)
                                                 .Build());
            }
        }
Exemple #4
0
        private void SyncInventoryTransactions(IDerivation derivation, InventoryItem inventoryItem, decimal initialQuantity, InventoryTransactionReason reason, bool isCancellation)
        {
            var adjustmentQuantity   = 0M;
            var existingQuantity     = 0M;
            var matchingTransactions = this.InventoryItemTransactions
                                       .Where(t => t.Reason.Equals(reason) && t.Part.Equals(inventoryItem.Part)).ToArray();

            if (matchingTransactions.Length > 0)
            {
                existingQuantity = matchingTransactions.Sum(t => t.Quantity);
            }

            if (isCancellation)
            {
                adjustmentQuantity = 0 - existingQuantity;
            }
            else
            {
                adjustmentQuantity = initialQuantity - existingQuantity;

                if (inventoryItem is NonSerialisedInventoryItem nonserialisedInventoryItem && nonserialisedInventoryItem.QuantityOnHand < adjustmentQuantity)
                {
                    derivation.Validation.AddError(this, M.NonSerialisedInventoryItem.QuantityOnHand, ErrorMessages.InsufficientStock);
                }
            }

            if (adjustmentQuantity != 0)
            {
                this.AddInventoryItemTransaction(new InventoryItemTransactionBuilder(this.Session())
                                                 .WithPart(inventoryItem.Part)
                                                 .WithFacility(inventoryItem.Facility)
                                                 .WithQuantity(adjustmentQuantity)
                                                 .WithCost(inventoryItem.Part.PartWeightedAverage.AverageCost)
                                                 .WithReason(reason)
                                                 .Build());
            }
        }
        private void SyncInventoryTransactions(InventoryItem inventoryItem, decimal initialQuantity, InventoryTransactionReason reason, bool isCancellation)
        {
            var adjustmentQuantity   = 0M;
            var existingQuantity     = 0M;
            var matchingTransactions = this.InventoryItemTransactions.Where(t => t.Reason.Equals(reason) && t.Part.Equals(inventoryItem.Part) && t.InventoryItem.Equals(inventoryItem)).ToArray();

            if (matchingTransactions.Length > 0)
            {
                existingQuantity = matchingTransactions.Sum(t => t.Quantity);
            }

            if (isCancellation)
            {
                adjustmentQuantity = 0 - existingQuantity;
            }
            else
            {
                adjustmentQuantity = initialQuantity - existingQuantity;
            }

            if (adjustmentQuantity != 0)
            {
                var newTransaction = new InventoryItemTransactionBuilder(this.Session())
                                     .WithPart(inventoryItem.Part)
                                     .WithQuantity(adjustmentQuantity)
                                     .WithReason(reason)
                                     .WithFacility(inventoryItem.Facility)
                                     .Build();

                if (inventoryItem is SerialisedInventoryItem serialisedInventoryItem)
                {
                    newTransaction.SerialisedItem = serialisedInventoryItem.SerialisedItem;
                }

                // HACK: DerivedRoles
                ((InventoryItemTransactionDerivedRoles)newTransaction).InventoryItem = inventoryItem;
                this.AddInventoryItemTransaction(newTransaction);
            }
        }