public TransactionModel(InventoryLog log) { this.InvId = log.Inventory.Id; this.TransId = log.Id; this.Quantity = log.Quantity; this.Size = log.Size; this.UnitId = log.Unit.Id; this.ActionId = log.InventoryAction.Id; this.Cost = log.Cost; this.Description = log.Inventory.Item.Description; this.TimeStamp = log.TransactionDate; }
/// <summary> /// Create a new InventoryLog object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="transactionDate">Initial value of the TransactionDate property.</param> /// <param name="quantity">Initial value of the Quantity property.</param> /// <param name="cost">Initial value of the Cost property.</param> /// <param name="unitId">Initial value of the UnitId property.</param> public static InventoryLog CreateInventoryLog(global::System.Int64 id, global::System.DateTime transactionDate, global::System.Double quantity, global::System.Double cost, global::System.Int32 unitId) { InventoryLog inventoryLog = new InventoryLog(); inventoryLog.Id = id; inventoryLog.TransactionDate = transactionDate; inventoryLog.Quantity = quantity; inventoryLog.Cost = cost; inventoryLog.UnitId = unitId; return inventoryLog; }
/// <summary> /// Deprecated Method for adding a new object to the InventoryLogs EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToInventoryLogs(InventoryLog inventoryLog) { base.AddObject("InventoryLogs", inventoryLog); }
//(StockUpdateEnum action, double quantity, double size, long itemId, Unit units, double cost) /// <summary> /// Updates the inventory entry for the item /// Calls to update shopping list /// Creates a transaction log entry /// </summary> /// <param name="action">ADD/REMOVE/CURRENT</param> /// <param name="quantity">Count Multiplier</param> /// <param name="size">Size of each Item</param> /// <param name="itemId">ID of the item we're updating</param> /// <param name="units">Units of quantity coming in</param> /// <returns></returns> private InventoryLog UpdateStock(TransactionModel model) { #region Setup objects JourListDMContainer dm = new JourListDMContainer(); InventoryLog log = new InventoryLog(); var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name); if (member == null) return null; var inv = member.Inventories.FirstOrDefault(z => z.Id == model.InvId); if (inv == null) return null; // Update the inventory numbers var action = dm.InventoryActions.Single(z => z.Id == model.ActionId).Description; var uaction = (StockUpdateEnum)Enum.Parse(typeof(StockUpdateEnum), action); #endregion #region Update inventory values var units = dm.Units.Single(z => z.Id == model.UnitId); double size; try { size = Tools.Tools.ConvertUnits(model.Size, units, inv.Unit); } catch (Exception e) { throw e; } double total = size * model.Quantity; switch (uaction) { case StockUpdateEnum.ADD: inv.OnHand += total; log.Cost = model.Cost; break; case StockUpdateEnum.REMOVE: model.Quantity *= -1; inv.OnHand -= total; model.Cost = 0; break; case StockUpdateEnum.ADJUST: if (inv.OnHand > total) { model.Quantity *= -1; model.Size = -1 * (inv.OnHand - total); } else // if inv.onhand < total model.Size = total - inv.OnHand; inv.OnHand = total; model.Cost = 0; break; default: break; } #endregion dm.SaveChanges(); #region Make a transaction log // Create an inventory transaction log.Quantity = model.Quantity; log.Inventory = inv; log.TransactionDate = DateTime.Now; log.InventoryAction = dm.InventoryActions.Single(z => z.Id == model.ActionId); log.Size = model.Size; log.Quantity = model.Quantity; log.Unit = dm.Units.Single(z => z.Id == model.UnitId); log.Cost = model.Cost; dm.SaveChanges(); model.TransId = log.Id; #endregion // With any inventory update, it's possible the item need to be included/excluded from the shopping list. UpdateShoppingList(inv); // Success return log; }