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);
        }
        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);
        }