/// <summary> /// Reduces the stock balance for article in order. /// </summary> /// <param name="order">The order.</param> /// <param name="token">The token.</param> public void ReduceStockBalance(Order order, SecurityToken token) { if (order == null) { return; } var inventories = _stockStatusCalculator.GetInventories(new StockStatusCalculatorArgs { CountrySystemId = order.CountryID, UserSystemId = order.CustomerInfo.PersonID, WebSiteSystemId = order.WebSiteID, }); try { var orderCarrier = order.GetAsCarrier(true, true, true, true, true, true); var articlesPurchased = from o in orderCarrier.OrderRows group o by o.ArticleNumber into g select new { ArticleNumber = g.Key, Quantity = g.Sum(p => p.Quantity) }; foreach (var item in articlesPurchased) { var article = _variantService.Get(item.ArticleNumber); if (article != null) { var stockItems = inventories.Select(x => _inventoryItemService.Get(article.SystemId, x.SystemId)); var stock = (stockItems.FirstOrDefault(x => x?.InStockQuantity > 0) ?? stockItems.FirstOrDefault())?.MakeWritableClone(); //this will set the stock quantities to negative values, if purchased more than the available stocks. //we expect this to be correct to show how much deficit is there for the given article. if (stock != null) { stock.InStockQuantity -= item.Quantity; using (Solution.Instance.SystemToken.Use("OrderUtilities.ReduceStockBalance")) { _inventoryItemService.Update(stock); } } } } } catch (Exception ex) { Solution.Instance.Log.CreateLogEntry("Could not reduce the stock quantity for order " + order.ExternalOrderID, ex, LogLevels.ERROR); } }
public IActionResult Put(int id, [FromBody] InventoryItem InventoryItem) { _inventoryItemService.Update(id, InventoryItem); return(new JsonResult(InventoryItem)); }