public string AddStockHistoryForAdjustment(string item_code, string desc, int adjustedQty, DateTime updateDate, int empid)
        {
            StockHistory history = new StockHistory();
            history.Item_Code = item_code;
            history.Description = desc;
            history.Quantity = adjustedQty;
            history.UpdateDate = updateDate;
            history.UpdateBy = empid;

            edm.StockHistories.AddObject(history);
            this.edm.SaveChanges();
            return "Adding StockHistory is Successful";
        }
        public void AddStockHistory(string ic, string desc, int deliveredQty, DateTime updateDate, int empid)
        {
            StockHistory his = new StockHistory();

            his.Item_Code = ic;
            his.Description = desc;
            his.Quantity = deliveredQty;
            his.UpdateDate = updateDate;
            his.UpdateBy = empid;

            edm.StockHistories.AddObject(his);
            this.edm.SaveChanges();
        }
        public StockHistory GetItembyItemCode(string ic)
        {
            var q = (from r in edm.StockHistories where r.Item_Code == ic select r);
            StockHistory s = new StockHistory();
            s = q.First<StockHistory>();

            return s;
        }
        public void ProcessPending()
        {
            var repository = (from m in team.Pendings
                            where m.Pending_Status == "current"
                            select m).ToList<Pending>();

            foreach (var pendingGather in repository)
            {
                if (pendingGather.Status == "UnFullFilled")
                {
                    var z = (from jay in team.Pending_Detail
                             where jay.PendingID == pendingGather.PendingID
                             select jay).ToList<Pending_Detail>();

                    foreach (var m in z)
                    {
                        var stock = (from s in team.Stock_Item
                                     where s.Item_Code == m.Item_Code
                                     select s).First<Stock_Item>();

                        int tempQuantity = 0;

                        if ((stock.Quantity - m.Quantity) < 0)
                        {
                            tempQuantity = stock.Quantity;
                        }

                        else
                        {
                            tempQuantity = m.Quantity;
                        }

                        StockHistory sh = new StockHistory
                        {
                            Item_Code = stock.Item_Code,
                            Description = stock.Description,
                            Quantity = tempQuantity * (-1),
                            UpdateDate = DateTime.Now,
                            UpdateBy = 1000 //session value
                        };

                        team.StockHistories.AddObject(sh);
                        stock.Quantity = stock.Quantity - m.Quantity;

                        if (stock.Quantity <= 0)
                        {

                            m.Quantity = (-1) * (stock.Quantity);
                            stock.Quantity = 0;
                            m.Status = "UnFullFilled";
                        }

                        else
                        {
                            m.Quantity = 0;
                            m.Status = "FullFilled";
                        }

                    }

                }
            }

            team.SaveChanges();
            UpdateStatus();
        }
 /// <summary>
 /// Create a new StockHistory object.
 /// </summary>
 /// <param name="stock_HistoryID">Initial value of the Stock_HistoryID property.</param>
 /// <param name="item_Code">Initial value of the Item_Code property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="updateDate">Initial value of the UpdateDate property.</param>
 /// <param name="updateBy">Initial value of the UpdateBy property.</param>
 public static StockHistory CreateStockHistory(global::System.Int32 stock_HistoryID, global::System.String item_Code, global::System.String description, global::System.Int32 quantity, global::System.DateTime updateDate, global::System.Int32 updateBy)
 {
     StockHistory stockHistory = new StockHistory();
     stockHistory.Stock_HistoryID = stock_HistoryID;
     stockHistory.Item_Code = item_Code;
     stockHistory.Description = description;
     stockHistory.Quantity = quantity;
     stockHistory.UpdateDate = updateDate;
     stockHistory.UpdateBy = updateBy;
     return stockHistory;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the StockHistories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStockHistories(StockHistory stockHistory)
 {
     base.AddObject("StockHistories", stockHistory);
 }
 public void UpdateStock(string code, int quant)
 {
     Stock_Item st = new Stock_Item();
     var stock = (from m in cntxt.Stock_Item
                  where m.Item_Code == code
                  select m).First<Stock_Item>();
     stock.Quantity = stock.Quantity - quant;
     StockHistory sh = new StockHistory()
     {
         Item_Code = stock.Item_Code,
         Description = stock.Description,
         Quantity = -quant,
         UpdateDate = DateTime.Now,
         UpdateBy = 1000   //session
     };
     cntxt.StockHistories.AddObject(sh);
     cntxt.SaveChanges();
 }