Exemple #1
0
        public void InventoryDrop(Inventory currentInventory, int?quantity, Int32 dropTypeId, Int32?saleId)
        {
            Inventory originalInventory = GetProductInventory(currentInventory.CompanyId, currentInventory.ProductId,
                                                              currentInventory.DepositId);

            var inventoryManager = new InventoryManager(this);

            if (dropTypeId != (int)DropType.Sell &&
                !inventoryManager.CheckIfCanTransfer(currentInventory.CompanyId, currentInventory.ProductId,
                                                     currentInventory.DepositId, quantity.Value))
            {
                throw new InvalidOperationException();
            }

            //
            //insert one row in InventoryHistory
            //

            InsertHistoryFromInventory(originalInventory, dropTypeId, saleId, null);

            originalInventory.Quantity -= Convert.ToInt32(quantity);

            //
            //drop StockComposite
            //

            var productManager = new ProductManager(this);

            Product product = productManager.GetProduct(originalInventory.ProductId);

            if (product.DropCompositeInStock)
            {
                List <CompositeProduct> listCompositProduct =
                    productManager.GetChildCompositeProducts(product.ProductId).ToList();
                for (int i = 0; i < listCompositProduct.Count; i++)
                {
                    Inventory compositeInventory = GetProductInventory(currentInventory.CompanyId,
                                                                       listCompositProduct[i].ProductId,
                                                                       originalInventory.DepositId);
                    if (compositeInventory != null)
                    {
                        InventoryDrop(compositeInventory, 1, dropTypeId, saleId);
                    }
                }
            }

            DbContext.SubmitChanges();
        }
        public void InventoryDrop(Inventory currentInventory, int? quantity, Int32 dropTypeId, Int32? saleId)
        {
            Inventory originalInventory = GetProductInventory(currentInventory.CompanyId, currentInventory.ProductId,
                                                              currentInventory.DepositId);

            var inventoryManager = new InventoryManager(this);
            if (dropTypeId != (int)DropType.Sell &&
                !inventoryManager.CheckIfCanTransfer(currentInventory.CompanyId, currentInventory.ProductId,
                                                     currentInventory.DepositId, quantity.Value))
                throw new InvalidOperationException();

            //
            //insert one row in InventoryHistory
            //

            InsertHistoryFromInventory(originalInventory, dropTypeId, saleId, null);

            originalInventory.Quantity -= Convert.ToInt32(quantity);
           
            //
            //drop StockComposite
            //
           
            var productManager = new ProductManager(this);

            Product product = productManager.GetProduct(originalInventory.ProductId);

            if (product.DropCompositeInStock)
            {
                List<CompositeProduct> listCompositProduct =
                    productManager.GetChildCompositeProducts(product.ProductId).ToList();
                for (int i = 0; i < listCompositProduct.Count; i++)
                {
                    Inventory compositeInventory = GetProductInventory(currentInventory.CompanyId,
                                                                       listCompositProduct[i].ProductId,
                                                                       originalInventory.DepositId);
                    if (compositeInventory != null)
                        InventoryDrop(compositeInventory, 1, dropTypeId, saleId);
                }
            }

            DbContext.SubmitChanges();
        }