/// <summary>
 /// Deprecated Method for adding a new object to the StockCardDetails EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStockCardDetails(StockCardDetail stockCardDetail)
 {
     base.AddObject("StockCardDetails", stockCardDetail);
 }
        public Constants.ACTION_STATUS CreateAdjustment()
        {
            Constants.ACTION_STATUS status = Constants.ACTION_STATUS.UNKNOWN;
            Constants.DB_STATUS dbStatus = discrepancyBroker.Insert(stockAdjustment);
            if (dbStatus == Constants.DB_STATUS.SUCCESSFULL)
                status = Constants.ACTION_STATUS.SUCCESS;
            else
                status = Constants.ACTION_STATUS.FAIL;
             //   discrepancy.Status = Converter.objToInt(Constants.VISIBILITY_STATUS.HIDDEN);
            List<DiscrepancyDetail> dd = GetList(discrepancy.DiscrepancyDetails.ToList());
            foreach (DiscrepancyDetail temp in dd)
            {
                StockCardDetail stockCardDetail = new StockCardDetail();
                stockCardDetail.Id = itemBroker.GetStockCardDetailId();
                stockCardDetail.Item = temp.Item;
                stockCardDetail.Description = "Stock Adjsutment " + stockAdjustment.Id;
                stockCardDetail.Qty = temp.Qty;
                stockCardDetail.CreatedDate = DateTime.Now;
                stockCardDetail.CreatedBy = Util.GetEmployee(employeeBroker);
                stockCardDetail.Status = Converter.objToInt(Constants.VISIBILITY_STATUS.SHOW);
                stockCardDetail.Balance = itemBroker.GetCurrentBalance(temp.Item) + Converter.objToInt(temp.Qty);
                itemBroker.Insert(stockCardDetail);
                temp.Status = Converter.objToInt(Constants.VISIBILITY_STATUS.HIDDEN);
                //discrepancyBroker.Update(temp);
            }

            bool flag = false;
            foreach (DiscrepancyDetail temp in discrepancy.DiscrepancyDetails)
            {
                if(temp.Status == Converter.objToInt(Constants.VISIBILITY_STATUS.SHOW)){
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                discrepancy.Status = Converter.objToInt(Constants.VISIBILITY_STATUS.HIDDEN);
            }
            else
            {
                discrepancy.Status = Converter.objToInt(Constants.VISIBILITY_STATUS.SHOW);
            }
            discrepancyBroker.Update(discrepancy);

            return status;
        }
 /// <summary>
 /// Create a new StockCardDetail object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="qty">Initial value of the Qty property.</param>
 /// <param name="balance">Initial value of the Balance property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static StockCardDetail CreateStockCardDetail(global::System.Int32 id, global::System.String description, global::System.Int32 qty, global::System.Int32 balance, global::System.DateTime createdDate, global::System.Int32 status)
 {
     StockCardDetail stockCardDetail = new StockCardDetail();
     stockCardDetail.Id = id;
     stockCardDetail.Description = description;
     stockCardDetail.Qty = qty;
     stockCardDetail.Balance = balance;
     stockCardDetail.CreatedDate = createdDate;
     stockCardDetail.Status = status;
     return stockCardDetail;
 }
        public Constants.ACTION_STATUS ClickReceived(DataTable dt, string deliveryNo, string poNumber)
        {
            Constants.ACTION_STATUS status = Constants.ACTION_STATUS.UNKNOWN;
            string itemNo, itemDesc, quantity, remark;
            PurchaseOrder po = new PurchaseOrder();
            po.Id = Converter.objToInt(poNumber);
            po = purchaseOrderBroker.GetPurchaseOrder(po);
            po.DeliveryOrderNumber = deliveryNo;
            po.DeliveryDate = DateTime.Now;
            po.AcceptedBy = Util.GetEmployee(employeeBroker);

            List<PurchaseOrderDetail> poDetailList = po.PurchaseOrderDetails.ToList();
            foreach (DataRow dr in dt.Rows)
            {
                itemNo = dr[detail[0]].ToString();

                itemDesc = dr[detail[1]].ToString();

                quantity = dr[detail[2]].ToString();

                remark = dr[detail[3]].ToString();

                foreach (PurchaseOrderDetail poDetail in poDetailList)
                {
                    if(poDetail.Item.Id.Equals(itemNo)){
                        poDetail.AcceptedQty = Converter.objToInt(quantity);
                        Item item = poDetail.Item;
                        item.Cost = poDetail.Price;
                        itemBroker.Update(item);
                        StockCardDetail stockCardDetail = new StockCardDetail();
                        stockCardDetail.Item = item;
                        stockCardDetail.Description = "Supplier-" + po.Supplier.Id;
                        stockCardDetail.Qty = Converter.objToInt(quantity);
                        stockCardDetail.CreatedDate = DateTime.Now;
                        stockCardDetail.CreatedBy = Util.GetEmployee(employeeBroker);
                        stockCardDetail.Status = Converter.objToInt(Constants.VISIBILITY_STATUS.SHOW);
                        //List<StockCardDetail> stockCardDetailList = itemBroker.GetAllStockCardDetail().ToList();
                        //List<StockCardDetail> newList = new List<StockCardDetail>();
                        //foreach(StockCardDetail scd in stockCardDetailList){
                        //    if(scd.Item.Id.Equals(item.Id)){
                        //        newList.Add(scd);
                        //    }
                        //}

                        //StockCardDetail scDetail = newList.Last<StockCardDetail>();
                        stockCardDetail.Balance = itemBroker.GetCurrentBalance(item) + Converter.objToInt(quantity);
                        stockCardDetail.Id = itemBroker.GetStockCardDetailId();
                        itemBroker.Insert(stockCardDetail);
                        // add remark later
                    }
                }

            }

            Constants.DB_STATUS dbStatus = purchaseOrderBroker.Update(po);
            if(dbStatus == Constants.DB_STATUS.SUCCESSFULL)
                status = Constants.ACTION_STATUS.SUCCESS;
            else
                status = Constants.ACTION_STATUS.FAIL;
            return status;
        }
 /// <summary>
 /// Don't need to set the status.There is no status in StockCardDetail Table
 /// </summary>
 /// <param name="stockCardDetail"></param>
 /// <returns></returns>
 public Constants.DB_STATUS Delete(StockCardDetail stockCardDetail)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 ///  Update StockDetail data to StockDetail Table according to the StockDetail Parameter
 ///   Return Constants.DB_STATUS
 /// </summary>
 /// <param name="stockCardDetail"></param>
 /// <returns></returns>
 public Constants.DB_STATUS Update(StockCardDetail stockCardDetail)
 {
     Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;
     try
     {
         StockCardDetail stcDetail = inventory.StockCardDetails.Where(s => s.Id == stockCardDetail.Id).First();
         if (!stcDetail.Equals(null))
         {
             Item item = inventory.Items.Where(i => i.Id == stockCardDetail.Item.Id).First();
             Employee createdBy = inventory.Employees.Where(e => e.Id == stockCardDetail.CreatedBy.Id).First();
             stcDetail.Id = stockCardDetail.Id;
             stcDetail.Item = item;
             stcDetail.Description = stockCardDetail.Description;
             stcDetail.Qty = stockCardDetail.Qty;
             stcDetail.Balance = stockCardDetail.Balance;
             stcDetail.CreatedDate = stockCardDetail.CreatedDate;
             stcDetail.CreatedBy = createdBy;
             inventory.AddToStockCardDetails(stockCardDetail);
             inventory.SaveChanges();
             status = Constants.DB_STATUS.SUCCESSFULL;
         }
     }
     catch (Exception e)
     {
         status = Constants.DB_STATUS.FAILED;
     }
     return status;
 }
        /// <summary>
        /// Insert StockDetail data to StockDetail Table according to the StockDetail Parameter Return Constants.DB_STATUS
        /// </summary>
        /// <param name="stockCardDetail"></param>
        /// <returns></returns>
        public Constants.DB_STATUS Insert(StockCardDetail stockCardDetail)
        {
            Constants.DB_STATUS status = Constants.DB_STATUS.UNKNOWN;

            try
            {
                
                    inventory.AddToStockCardDetails(stockCardDetail);
                    inventory.SaveChanges();
                    status = Constants.DB_STATUS.SUCCESSFULL;
                
            }
            catch (Exception e)
            {
                status = Constants.DB_STATUS.FAILED;
            }

            return status;
        }
 /// <summary>
 ///  Retrieve the StockCardDetail information according to the stockCardDetail Parameter 
 /// </summary>
 /// <param name="stockCardDetail"></param>
 /// <returns></returns>
 public StockCardDetail GetStockCardDetail(StockCardDetail stockCardDetail)
 {
     try
     {
         stockCardDetailObj = inventory.StockCardDetails.Where(stcDetailObj => stcDetailObj.Id == stockCardDetail.Id).First();
     }
     catch (Exception e)
     {
         stockCardDetailObj = null;
     }
     return stockCardDetailObj;
 }