public bool ProductLocationAdd(string branchCode, string locationCode, string warehouseCode, List <ProductLocation> productLocations)
        {
            bool isSaved = false;

            try
            {
                using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;

                        SAPProxyII.ZMM_ASSIGNLOCTable productLocationTable = new SAPProxyII.ZMM_ASSIGNLOCTable();


                        // clear old data in SAP.
                        prx.Zdd_Handheld_Del_Zmm_Assignloc(locationCode, warehouseCode, ref productLocationTable);

                        foreach (var item in productLocations)
                        {
                            if (string.IsNullOrEmpty(item.ProductCode))
                            {
                                var product = ProductBarcodeGetByProductCodeOrBarcode3(branchCode, item.ProductBarcode);
                                if (product == null)
                                {
                                    continue;
                                }
                                item.ProductCode     = product.ProductCode;
                                item.ProductUnitCode = product.UnitCode;
                            }

                            productLocationTable = new SAPProxyII.ZMM_ASSIGNLOCTable();
                            prx.Zdd_Handheld_Set_Zmm_Assignloc(locationCode,
                                                               "X",
                                                               item.LocationType,
                                                               SapProductCodeFormated(item.ProductCode),
                                                               item.PutLevel,
                                                               item.PutQuantity,
                                                               item.DisplayOrder,
                                                               warehouseCode,
                                                               item.ProductUnitCode,
                                                               ref productLocationTable);
                        }

                        isSaved = true;
                    }
                }
            }
            catch
            {
                isSaved = false;
            }

            return(isSaved);
        }
        public ProductLocation ProductLocationGetByBarcode(string barcode, string locationCode, string warehouseCode, string branchCode)
        {
            var product = ProductBarcodeGetByProductCodeOrBarcode3(branchCode, barcode);

            if (product == null)
            {
                return(null);
            }

            ProductLocation productLocation = new ProductLocation();

            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    SAPProxyII.ZMM_ASSIGNLOCTable tables = new SAPProxyII.ZMM_ASSIGNLOCTable();
                    prx.Zdd_Handheld_Set_Zmm_Assignloc(locationCode, "", "", "", 0, 0, 0, "", "", ref tables);
                    DataTable locationTable = tables.ToADODataTable();

                    string productCode = SapProductCodeFormated(product.ProductCode);

                    var condition = new StringBuilder();
                    condition.AppendFormat(" STORAGE_LOC='{0}'", warehouseCode);
                    condition.AppendFormat(" AND BIN_CODE='{0}'", locationCode);
                    condition.AppendFormat(" AND MATERIAL='{0}'", productCode);
                    condition.AppendFormat(" AND UNITOFMEASURE='{0}'", product.UnitCode);

                    var rows = locationTable.Select(condition.ToString());
                    if (rows.Length > 0)
                    {
                        productLocation.StatusText = "พบ";
                    }
                    else
                    {
                        productLocation.StatusText = "ไม่พบ";
                    }
                }
            }

            productLocation.LocationCode    = locationCode;
            productLocation.ProductCode     = product.ProductCode;
            productLocation.ProductName     = product.ProductName;
            productLocation.ProductBarcode  = product.Barcode;
            productLocation.ProductUnitCode = product.UnitCode;
            productLocation.ProductUnitName = product.UnitName;

            return(productLocation);
        }
        private bool SapLocationGetIsContains(string productCode, string unitCode, string locationCode, string warehouseCode, out int displayOrder)
        {
            bool isContain = false;

            displayOrder = 0;
            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    SAPProxyII.ZMM_ASSIGNLOCTable tables = new SAPProxyII.ZMM_ASSIGNLOCTable();
                    prx.Zdd_Handheld_Set_Zmm_Assignloc(locationCode, "", "", "", 0, 0, 0, "", "", ref tables);
                    DataTable locationTable = tables.ToADODataTable();


                    string sapProductCode = SapProductCodeFormated(productCode);

                    var condition = new StringBuilder();
                    condition.AppendFormat(" STORAGE_LOC='{0}'", warehouseCode);
                    condition.AppendFormat(" AND BIN_CODE='{0}'", locationCode);
                    condition.AppendFormat(" AND MATERIAL='{0}'", sapProductCode);
                    condition.AppendFormat(" AND UNITOFMEASURE='{0}'", unitCode);

                    var rows = locationTable.Select(condition.ToString());
                    if (rows.Length > 0)
                    {
                        isContain    = true;
                        displayOrder = Convert.ToInt32(rows[0]["ROWORDER"]);
                    }
                    else
                    {
                        isContain = false;
                    }
                }
            }


            return(isContain);
        }
Exemplo n.º 4
0
        public List <OrderAccrual> OrderAccrualGetByProductCode(string productCode, string branchCode)
        {
            List <OrderAccrual> orderAccrual = new List <OrderAccrual>();

            try
            {
                using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;


                        var sapProductCode = SapProductCodeFormated(productCode);


                        //prepare Sale Profit
                        var     stockUnit    = GetProductStockUnit(branchCode, productCode);
                        var     productPrice = GetProductPrice(productCode, stockUnit, branchCode);
                        decimal stockCost    = 0;

                        SAPProxyII.EKETTable eket = new SAPProxyII.EKETTable();
                        SAPProxyII.EKKOTable ekko = new SAPProxyII.EKKOTable();
                        SAPProxyII.EKPOTable ekpo = new SAPProxyII.EKPOTable();
                        prx.Zdd_Export_Po_Not_Rec(sapProductCode, branchCode, out stockCost, ref eket, ref ekko, ref ekpo);

                        foreach (SAPProxyII.EKPO po in ekpo)
                        {
                            DateTime?appointDate = null;
                            DateTime?orderDate   = null;

                            string sAppointDate = "", sPoDocNo = "", sPoDocDate = "", sUser = "";
                            //วันที่นัดรับ
                            foreach (SAPProxyII.EKET ek in eket)
                            {
                                if (ek.Ebeln == po.Ebeln && ek.Ebelp == po.Ebelp)
                                {
                                    // appointDate = DateTime.Parse(ek.Eindt, new System.Globalization.CultureInfo("en-US"));
                                    appointDate = DateTime.ParseExact(ek.Eindt, "yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                                    //sAppointDate = ek.Eindt.Substring(6, 2) + "/" + ek.Eindt.Substring(4, 2) + "/" + ek.Eindt.Substring(0, 4);
                                    //sAppointDate = Convert.ToDateTime(sAppointDate).ToString("dd/MM/yyyy");
                                }
                            }
                            //เลขที่ใบสั่งซื้อ - วันที่สั่งซื้อ
                            sPoDocNo  = po.Ebeln;
                            orderDate = DateTime.ParseExact(po.Aedat, "yyyyMMdd", new System.Globalization.CultureInfo("en-US"));

                            //พนักงานจัดซื้อ
                            foreach (SAPProxyII.EKKO ko in ekko)
                            {
                                if (ko.Ebeln == po.Ebeln)
                                {
                                    sUser = ko.Ernam;
                                }
                            }

                            orderAccrual.Add(new OrderAccrual {
                                OrderNo = sPoDocNo, OrderDate = orderDate, AppointDate = appointDate, EmployeeNo = sUser
                            });
                            ////เช็คว่ามีใบสั่งซื้อเลขที่ๆเลือกไว้แล้วหรือยัง
                            //bool IsHased = false;
                            //foreach (ListViewItem olt in this.lvwPoNotRec.Items)
                            //{
                            //    SAPProxyII.EKKO opo = (SAPProxyII.EKKO)olt.Tag;
                            //    if (sPoDocNo == opo.Ebeln)
                            //    {
                            //        IsHased = true;
                            //        break;
                            //    }
                            //}
                            //if (!IsHased)
                            //{
                            //    ListViewItem item = new ListViewItem(sAppointDate);
                            //    item.SubItems.Add(sPoDocNo);
                            //    item.SubItems.Add(sPoDocDate);
                            //    item.SubItems.Add(sUser);
                            //    item.Tag = po;
                            //    this.lvwPoNotRec.Items.Add(item);
                            //}
                        }
                    }
                }
            }
            catch
            {
                orderAccrual = null;
            }

            return(orderAccrual);
        }
        public ProductSaleDetail ProductSaleDetailGetByProductCode(string productCode, string branchCode, bool isShowProfit)
        {
            //log.Debug("ProductSaleDetailGetByProductCode start " + DateTime.Now);

            ProductSaleDetail productSaleDetail;

            try
            {
                using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;

                        string  saleProductType = string.Empty;
                        decimal salePerDay      = 0;
                        decimal saleAmount      = 0;
                        decimal saleBackOffice  = 0;
                        decimal SalePos         = 0;
                        decimal saleQuantity    = 0;
                        decimal saleRate        = 0;
                        string  lastGrDate      = "";
                        decimal lastGrQty       = 0;
                        string  lastSaleDate    = "";
                        decimal lastSaleQty     = 0;

                        var sapProductCode = SapProductCodeFormated(productCode);
                        //prx.Zdd_Export_Pos_Saleinfo(sapProductCode,
                        //    branchCode,
                        //    out saleProductType,
                        //    out salePerDay,
                        //    out saleAmount,
                        //    out saleBackOffice,
                        //    out SalePos,
                        //    out saleQuantity,
                        //    out saleRate);

                        using (PrxHandheld.PrxHandheld prx2 = new PrxHandheld.PrxHandheld())
                        {
                            prx2.Connection = sapConnection;

                            prx2.Zdd_Export_Pos_Saleinfo(sapProductCode,
                                                         branchCode,
                                                         out lastGrDate,
                                                         out lastGrQty,
                                                         out lastSaleDate,
                                                         out lastSaleQty,
                                                         out saleProductType,
                                                         out salePerDay,
                                                         out saleAmount,
                                                         out saleBackOffice,
                                                         out SalePos,
                                                         out saleQuantity,
                                                         out saleRate);
                        }

                        productSaleDetail = new ProductSaleDetail();
                        productSaleDetail.SaleProductType = saleProductType;
                        productSaleDetail.SalePerDay      = salePerDay;
                        //productSaleDetail.SaleProfit
                        productSaleDetail.SaleQuantity = saleQuantity;
                        productSaleDetail.SaleRate     = saleRate;

                        productSaleDetail.LastGrDate   = lastGrDate;
                        productSaleDetail.LastGrQty    = lastGrQty;
                        productSaleDetail.LastSaleDate = lastSaleDate;
                        productSaleDetail.LastSaleQty  = lastSaleQty;

                        if (isShowProfit)
                        {
                            //prepare Sale Profit
                            var     stockUnit    = GetProductStockUnit(branchCode, productCode);
                            var     productPrice = GetProductPrice(productCode, stockUnit, branchCode);
                            decimal stockCost    = 0;
                            decimal profit       = 0;

                            SAPProxyII.EKETTable eket = new SAPProxyII.EKETTable();
                            SAPProxyII.EKKOTable ekko = new SAPProxyII.EKKOTable();
                            SAPProxyII.EKPOTable ekpo = new SAPProxyII.EKPOTable();
                            prx.Zdd_Export_Po_Not_Rec(sapProductCode, branchCode, out stockCost, ref eket, ref ekko, ref ekpo);
                            eket = null;
                            ekko = null;
                            ekpo = null;

                            //คำนวนกำไรที่ได้ของหน่วยย่อยสุด
                            if (productPrice != 0)
                            {
                                profit = 100 * (productPrice - stockCost) / productPrice;
                            }

                            if (profit >= 10)
                            {
                                productSaleDetail.SaleProfit = "++";
                            }
                            else if (profit < 0)
                            {
                                productSaleDetail.SaleProfit = "-";
                            }
                            else
                            {
                                productSaleDetail.SaleProfit = "+";
                            }
                        }
                        else
                        {
                            productSaleDetail.SaleProfit = "*******";
                        }
                    }
                }
            }
            catch
            {
                productSaleDetail = null;
            }

            //log.Debug("ProductSaleDetailGetByProductCode end " + DateTime.Now);

            return(productSaleDetail);
        }
Exemplo n.º 6
0
        public List <ProductBarcode> ProductBarcodeGetByProductCodeOrBarcode5(string branchCode, string productCodeOrBarcode, string warehouseCode)
        {
            var product    = new List <ProductBarcode>();
            var tmpproduct = new List <ProductBarcode>();

            using (DbManager db = new DbManager(branchCode))
            {
                product = db
                          .SetCommand(GetSql(104),
                                      db.Parameter("@Barcode", productCodeOrBarcode),
                                      db.Parameter("@Branchcode", branchCode),
                                      db.Parameter("@Warehousecode", warehouseCode)
                                      )
                          .ExecuteList <ProductBarcode>();

                if (product != null)
                {
                    var Result = product.Where(x => x.Barcode == productCodeOrBarcode && x.ProductCode != productCodeOrBarcode).Take(1).ToList();
                    if (Result.Count > 0)
                    {
                        product = product.Where(x => x.UnitCode != Result.First().UnitCode).ToList();
                        product.Add(Result.First());
                    }

                    //List<UnitBarcode> barcode = new List<UnitBarcode>();
                    //var results = (product.GroupBy(p => p.UnitCode, (key, g) => new { Unit = key, Products = g.ToList() })).ToList();
                    //foreach (var item in results)
                    //{
                    //    if (item.Products.Count>1)
                    //    {
                    //        foreach (var itemin in item.Products)
                    //        {
                    //            if (itemin.Barcode == productCodeOrBarcode)
                    //            {
                    //                barcode.Add(new UnitBarcode { BarCode = itemin.Barcode, UnitCode = itemin.UnitCode });
                    //            }
                    //        }
                    //        if (barcode.Count> 1)
                    //        {
                    //            //product = from o in product where o.Barcode != productCodeOrBarcode  select o;
                    //        }
                    //    }
                    //}
                    //tmpproduct.Clear();
                    SAPProxyII.UWProxy          prx    = new SAPProxyII.UWProxy();
                    SAP.Connector.SAPConnection cnnSAP = new SAP.Connector.SAPConnection(GlobalContext.SapDestination);
                    cnnSAP.Open();
                    prx.Connection = cnnSAP;
                    SAPProxyII.MARCTable  marcs  = new SAPProxyII.MARCTable();
                    SAPProxyII.TLOGTTable tlogts = new SAPProxyII.TLOGTTable();
                    SAPProxyII.WERKS      werks  = new SAPProxyII.WERKS();
                    werks.Werks = branchCode;
                    foreach (var item in product)
                    {
                        var price = ProductPriceGetCurrentPrice(branchCode, item.ProductCode, item.UnitCode);
                        if (price != null)
                        {
                            item.ProductPrice     = price.Saleprice;
                            item.ProductPriceText = price.Saleprice.ToString("N2");
                        }
                        var Li = product.Where(x => x.ProductCode == item.ProductCode && x.LOGGR != null).ToList();
                        if (Li.Count == 0)
                        {
                            try
                            {
                                prx.Zdd_Export_Pos_Marc(AddZero(item.ProductCode, 18), werks, ref marcs, ref tlogts);
                                foreach (SAPProxyII.TLOGT itemin in tlogts)
                                {
                                    item.LOGGR = itemin.Loggr + "-" + itemin.Ltext;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else
                        {
                            item.LOGGR = Li.First().LOGGR;
                        }
                        try
                        {
                            var Position = GetProductPosition(item.ProductCode, warehouseCode, item.UnitCode);
                            var i        = 0;
                            foreach (var items in Position)
                            {
                                if (i == 0)
                                {
                                    item.PositionCode = items.PositionCode;
                                }
                                else
                                {
                                    var TmpItem = new ProductBarcode()
                                    {
                                        Barcode          = item.Barcode,
                                        BinCode          = item.BinCode,
                                        LOGGR            = item.LOGGR,
                                        PositionCode     = item.PositionCode,
                                        ProductCode      = item.ProductCode,
                                        ProductName      = item.ProductName,
                                        ProductPrice     = item.ProductPrice,
                                        ProductPriceText = item.ProductPriceText,
                                        Quantity         = item.Quantity,
                                        Status           = item.Status,
                                        StockQuantity    = item.StockQuantity,
                                        StoreLocation    = item.StoreLocation,
                                        UnitCode         = item.UnitCode,
                                        UnitName         = item.UnitName,
                                        UnitRate         = item.UnitRate
                                    };
                                    TmpItem.PositionCode = items.PositionCode;
                                    tmpproduct.Add(TmpItem);
                                }
                                i += 1;
                            }
                            //if (Position != null)
                            //{
                            //    item.PositionCode = Position.PositionCode;
                            //}
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                foreach (var item in tmpproduct)
                {
                    product.Add(item);
                }
                return(product);
            }
        }
        public string ProductLocationAddHandHeldLocation(string branchCode, List <ProductLocation> products)
        {
            var documentNo = string.Empty;

            if (string.IsNullOrEmpty(products[0].DocumentNo))
            {
                documentNo = ProductLocationHandHeldLocationGetDocumentNo(branchCode);
            }
            else
            {
                documentNo = products[0].DocumentNo;
            }

            var createdDate       = DateTime.Now;
            var createdDateFormat = createdDate.ToString("yyyy.MM.dd", new System.Globalization.CultureInfo("en-US"));
            var createdTimeFormat = createdDate.ToString("HH:mm:ss");
            int displayOrder      = 0;
            var isContains        = false;

            SAPProxyII.ZHANDHELD_LOCTable locationTable = new SAPProxyII.ZHANDHELD_LOCTable();

            using (DbManager db = new DbManager(branchCode))
            {
                try
                {
                    SqlQuery <ProductLocation> productQuery = new SqlQuery <ProductLocation>(db);
                    db.BeginTransaction();

                    //Clear old data for location and employee.
                    db.SetCommand(GetSql(40)
                                  , db.Parameter("@DocumentNo", documentNo))
                    .ExecuteNonQuery();

                    foreach (var item in products)
                    {
                        // modify for offline mode.
                        if (string.IsNullOrEmpty(item.ProductCode))
                        {
                            var product = ProductBarcodeGetByProductCodeOrBarcode3(branchCode, item.ProductBarcode);
                            if (product == null)//if not exists skip to next row.
                            {
                                continue;
                            }

                            item.SalePrice       = GetProductPrice(product.ProductCode, product.UnitCode, branchCode);
                            item.ProductCode     = product.ProductCode;
                            item.ProductName     = product.ProductName;
                            item.ProductUnitCode = product.UnitCode;
                            item.ProductUnitName = product.UnitName;
                        }

                        if (item.SalePrice != item.ShopPrice)
                        {
                            item.PriceStatus = "ราคาไม่ตรง";
                        }
                        else
                        {
                            item.PriceStatus = "ราคาถูกต้อง";
                        }

                        isContains = SapLocationGetIsContains(item.ProductCode, item.ProductUnitCode, item.LocationCode, item.WarehouseCode, out displayOrder);
                        if (!isContains)
                        {
                            item.LocationStatus = "ไม่พบสินค้าในตำแหน่งนี้";
                        }
                        else
                        {
                            if (displayOrder == item.DisplayOrder)
                            {
                                item.LocationStatus = "ตำแหน่งถูกต้อง";
                            }
                            else
                            {
                                item.LocationStatus = "ลำดับไม่ตรง";
                            }
                        }

                        item.DocumentNo   = documentNo;
                        item.DocumentDate = createdDate.Date;
                        item.CreateDate   = createdDate;
                        item.Remark       = string.Concat(item.PriceStatus, ",", item.LocationStatus);
                        var locationItem = new SAPProxyII.ZHANDHELD_LOC();
                        locationItem.Docno = documentNo;
                        //string sDocDate = DateTime.Today.Year.ToString() + DateTime.Today.ToString(".MM.dd");
                        //string sTime = DateTime.Now.ToString("HH:mm:ss");
                        locationItem.Docdate      = createdDateFormat;
                        locationItem.Createdate   = createdDateFormat;
                        locationItem.Createtime   = createdTimeFormat;
                        locationItem.Roworder     = item.DisplayOrder;
                        locationItem.Productcode  = item.ProductCode;// SapProductCodeFormated(item.ProductCode);
                        locationItem.Productname  = item.ProductName;
                        locationItem.Warehouse    = item.WarehouseCode;
                        locationItem.Location     = item.LocationCode;
                        locationItem.Unitcode     = item.ProductUnitCode;
                        locationItem.Unitname     = item.ProductUnitName;
                        locationItem.Barcode      = item.ProductBarcode;
                        locationItem.Sys_Price    = item.SalePrice;
                        locationItem.Pos_Price    = item.ShopPrice;
                        locationItem.Remark       = item.Remark;
                        locationItem.Userid       = item.UserID;
                        locationItem.Officerid    = item.OfficerID;
                        locationItem.Res_Location = item.LocationStatus;
                        locationItem.Res_Price    = item.PriceStatus;

                        locationTable.Add(locationItem);

                        productQuery.Insert(item);

                        displayOrder = 0;
                    }

                    //commit transaction to SQL Server.
                    db.CommitTransaction();
                }
                catch (Exception ex)
                {
                    db.RollbackTransaction();
                    throw ex;
                }

                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyII.UWProxy())
                    {
                        prx.Connection = sapConnection;
                        prx.Zdd_Export_Tbhandheldlocation(ref locationTable);
                    }
                }
            }

            return(documentNo);
        }
        public List <ProductLocation> ProductLocationGetAllByBarcode(string barcode, string branchCode, string warehouseCode)
        {
            List <ProductLocation> productLocations = new List <ProductLocation>();

            using (SAP.Connector.SAPConnection sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (SAPProxyII.UWProxy prx = new SAPProxyII.UWProxy())
                {
                    prx.Connection = sapConnection;
                    var productBarcode = ProductBarcodeGetByBarcode(barcode, branchCode);
                    var sapProductCode = SapProductCodeFormated(productBarcode.ProductCode);

                    SAPProxyII.MARDTable Tables = new SAPProxyII.MARDTable();
                    prx.Zdd_Handheld_Get_Mard(sapProductCode, ref Tables);
                    string          branchCodePrefix = branchCode.Substring(0, 2);
                    double          balanceQuantity1 = 0;
                    double          balanceQuantity2 = 0;
                    List <Location> locations        = null;
                    int             index            = 0;
                    // old logic by P' Tommy
                    foreach (SAPProxyII.MARD tbl in Tables)
                    {
                        if (tbl.Werks.Substring(2, 2) != "99" && tbl.Werks.Substring(0, 2) == branchCodePrefix)
                        {
                            var productLocation = new ProductLocation();
                            productLocation.ProductUnitCode = productBarcode.UnitCode;
                            productLocation.ProductUnitName = productBarcode.UnitName;
                            productLocation.WarehouseCode   = tbl.Lgort;
                            productLocation.WarehouseName   = WareHouseGetSingle(tbl.Lgort, branchCode).Name;
                            balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, tbl.Lgort, productBarcode.UnitCode, branchCodePrefix + "00");
                            balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, tbl.Lgort, productBarcode.UnitCode, branchCodePrefix + "99");

                            //productLocation.LocationCode = location.Code;
                            productLocation.BalanceQuantity     = (balanceQuantity1 + balanceQuantity2);
                            productLocation.BalanceQuantityText = productLocation.BalanceQuantity.ToString("N2");
                            productLocations.Add(productLocation);

                            locations = SAPGetLocation(productBarcode.ProductCode, productBarcode.UnitCode, tbl.Lgort);
                            index     = 0;
                            foreach (var location in locations)
                            {
                                //productLocation = productLocations.Find(p => p.WarehouseCode == location.Code);

                                if (index == 0)
                                {
                                    productLocation.LocationCode = location.Code;
                                    //balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "00");
                                    //balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "99");
                                    //productLocation.BalanceQuantity = (balanceQuantity1 + balanceQuantity2);
                                }
                                else
                                {
                                    productLocation = new ProductLocation();
                                    productLocation.BalanceQuantityText = string.Empty;
                                    //productLocation.WarehouseCode = tbl.Lgort;
                                    //productLocation.WarehouseName = WareHouseGetSingle(tbl.Lgort, branchCode).Name;
                                    productLocation.LocationCode = location.Code;
                                    //balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "00");
                                    //balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "99");
                                    //productLocation.BalanceQuantity = (balanceQuantity1 + balanceQuantity2);
                                    productLocations.Add(productLocation);
                                }
                                //if (index == 0)
                                //{
                                //    productLocation = productLocations.Find(p => p.WarehouseCode == location.Code);
                                //}
                                //else {
                                //    productLocation = new ProductLocation();
                                //    productLocation.WarehouseCode = tbl.Lgort;
                                //    productLocation.WarehouseName = WareHouseGetSingle(tbl.Lgort, branchCode).Name;
                                //    balanceQuantity1 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "00");
                                //    balanceQuantity2 = SAPGetBalanceQuantity(productBarcode.ProductCode, location.Code, productBarcode.UnitCode, branchCodePrefix + "99");

                                //    productLocation.LocationCode = location.Code;
                                //    productLocation.BalanceQuantity = (balanceQuantity1 + balanceQuantity2);
                                //    productLocations.Add(productLocation);
                                //}

                                index++;
                            }
                        }
                    }
                }
            }

            //var productBarcode = ProductBarcodeGetByBarcode(barcode);
            //List<ProductLocation> productLocations = new List<ProductLocation>();
            //var productLocation = new ProductLocation();
            //productLocation.LocationCode = SAPGetLocation(productBarcode.ProductCode, productBarcode.UnitCode, warehouseCode, branchCode);
            //productLocation.BalanceQuantity = SAPGetBalanceQuantity(productBarcode.ProductCode, warehouseCode, productBarcode.UnitCode, branchCode);
            //productLocation.ProductUnitCode = productBarcode.UnitCode;
            //productLocation.ProductUnitName = productBarcode.UnitName;
            //productLocations.Add(productLocation);

            return(productLocations);
        }