Пример #1
0
        public List <ProductPosition> GetProductPosition(string sProductCode, string sWarehouse)
        {
            var ProdReturn = new List <ProductPosition>();

            try
            {
                using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
                {
                    using (var prx = new SAPProxyIII.UWProxy())
                    {
                        prx.Connection = sapConnection;
                        SAPProxyIII.ZMM_ASSIGNLOCTable tables = new SAPProxyIII.ZMM_ASSIGNLOCTable();
                        prx.Zdd_Handheld_Get_Zmm_Assignloc("", sWarehouse, sProductCode, ref tables);
                        DataTable dt = tables.ToADODataTable();
                        foreach (DataRow item in dt.Rows)
                        {
                            if (item["LOCTYPE"].ToString().ToUpper() != "T")
                            {
                                ProdReturn.Add(new ProductPosition {
                                    PositionCode = item["BIN_CODE"].ToString(), ProductCode = item["MATERIAL"].ToString(), UnitCode = item["UNITOFMEASURE"].ToString()
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(ProdReturn);
        }
Пример #2
0
        public List <ZMMInvoiceCnTh> GetHandHeldCounterMainHoldZMMInvoiceCnThFromSap(string officerID)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;
                    SAPProxyIII.PERNR pernr = new SAPProxyIII.PERNR();
                    SAPProxyIII.ZMM_INV_CNTH_UWTable tables = new SAPProxyIII.ZMM_INV_CNTH_UWTable();
                    pernr.Pernr = officerID;
                    prx.Zdd_Handheld_Checkdoc(pernr, ref tables);

                    var ZMMInvoiceCnThList = new List <ZMMInvoiceCnTh>();
                    foreach (SAPProxyIII.ZMM_INV_CNTH_UW item in tables)
                    {
                        var zmm = new ZMMInvoiceCnTh();
                        zmm.iblnr       = item.Iblnr;
                        zmm.gjahr       = item.Gjahr;
                        zmm.budat       = DateTime.ParseExact(item.Budat, "yyyyMMdd", new System.Globalization.CultureInfo("en-US"));
                        zmm.DisplayText = string.Format("{0} : {1} : {2:dd.MM.yyyy}", zmm.iblnr, zmm.gjahr, zmm.budat);
                        ZMMInvoiceCnThList.Add(zmm);
                    }


                    return(ZMMInvoiceCnThList);
                }
            }
        }
Пример #3
0
        public void AddMajorHandHeldCounterMainHoldToSap(string branchCode, string documentNo, string officerID1, string officerID2)
        {
            var    counterHolds   = GetHandHeldCounterMainHoldByDocumentNo(branchCode, documentNo);
            string accountingYear = string.Empty;
            string officerID      = string.Empty;

            SAPProxyIII.ZDD_HH_CHKSTOCKTable tables = new SAPProxyIII.ZDD_HH_CHKSTOCKTable();

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

                    foreach (var item in counterHolds)
                    {
                        var zdd = new SAPProxyIII.ZDD_HH_CHKSTOCK();
                        zdd.Iblnr       = item.Iblnr;
                        zdd.Gjahr       = item.Gjahr;
                        zdd.Zeili       = item.Zeili;
                        zdd.Matnr       = item.Matnr;
                        zdd.Ean11       = item.Ean11;
                        zdd.Maktx       = item.Maktx;
                        zdd.Shelf       = item.Shelf;
                        zdd.Bin_Code    = item.BinCode;
                        zdd.Erfmg_Sku   = item.ErfmgSku;
                        zdd.Erfme_Sku   = item.ErfmeSku;
                        zdd.Ratio       = item.Ratio;
                        zdd.Erfmg_Sales = item.ErfmgSales;
                        zdd.Erfme_Sales = item.ErfmeSales;

                        accountingYear = item.Gjahr;
                        officerID      = item.Createuser;

                        tables.Add(zdd);
                    }

                    try
                    {
                        prx.Zdd_Handheld_Checkstock(accountingYear, documentNo, "X", officerID1, officerID1, ref tables);

                        using (var db = new DbManager(branchCode))
                        {
                            db.SetCommand(GetSql(33), db.Parameter("@DocumentNo", documentNo)).ExecuteNonQuery();
                        }

                        prx.CommitWork();
                    }
                    catch (Exception ex)
                    {
                        prx.RollbackWork();
                        throw ex;
                    }
                }
            }
        }
        //public Location LocationGetByCode(string locationCode)
        //{
        //    using (DbManager db = new DbManager())
        //    {
        //        return db
        //            .SetCommand("SELECT * FROM TBUnit Where Code = @UnitCode;",
        //            db.Parameter("@UnitCode", unitCode))
        //            .ExecuteObject<ProductUnit>();
        //    }
        //}

        public List <ProductLocation> ProductLocationGetByLocation(string branchCode, string locationCode, string warehouseCode)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    var Tables = new SAPProxyIII.ZMM_ASSIGNLOCTable();

                    prx.Zdd_Handheld_Get_Zmm_Assignloc(locationCode, warehouseCode, string.Empty, ref Tables);

                    var locations = (List <SAPProxyIII.ZMM_ASSIGNLOC>)CollectionHelper.ConvertTo <SAPProxyIII.ZMM_ASSIGNLOC>(Tables.ToADODataTable());

                    List <ProductLocation> productLocations = new List <ProductLocation>();
                    var         productCode = string.Empty;
                    Product     product     = null;
                    ProductUnit productUnit = null;
                    foreach (var item in locations)
                    {
                        productCode = SystemProductCodeFormated(item.Material);

                        product     = GetProductByCode(branchCode, productCode);
                        productUnit = ProductUnitGetByCode(branchCode, item.Unitofmeasure);
                        productLocations.Add(new ProductLocation
                        {
                            LocationCode    = item.Bin_Code,
                            ProductCode     = productCode,
                            ProductBarcode  = GetProductBarcodeByProductCode(branchCode, productCode, item.Unitofmeasure),
                            ProductName     = product.NameTh,
                            ProductUnitCode = item.Unitofmeasure,
                            ProductUnitName = productUnit.Name,
                            PutLevel        = item.Putlevel,
                            PutQuantity     = item.Putqty,
                            DisplayOrder    = Convert.ToInt32(item.Roworder)
                        });
                    }

                    productLocations.Sort(delegate(ProductLocation p1, ProductLocation p2) { return(p1.DisplayOrder.CompareTo(p2.DisplayOrder)); });

                    return(productLocations);
                }
            }
        }
Пример #5
0
        public List <HandHeldCounterMainHold> GetHandHeldCounterMainHoldZDDHandHeldCheckStockFromSap(string branchCode, string iblnr, string Gjahr, string officerID)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;
                    SAPProxyIII.PERNR pernr = new SAPProxyIII.PERNR();
                    SAPProxyIII.ZDD_HH_CHKSTOCKTable tables = new SAPProxyIII.ZDD_HH_CHKSTOCKTable();
                    pernr.Pernr = officerID;
                    prx.Zdd_Handheld_Checkstock(Gjahr, iblnr, string.Empty, string.Empty, string.Empty, ref tables);

                    var zDDHandHeldCheckStockList = new List <HandHeldCounterMainHold>();
                    foreach (SAPProxyIII.ZDD_HH_CHKSTOCK item in tables)
                    {
                        var zdd = new HandHeldCounterMainHold();
                        zdd.Matnr           = item.Matnr;
                        zdd.ProductCode     = FormatedProductCode(item.Matnr);
                        zdd.Maktx           = item.Maktx;
                        zdd.BinCode         = item.Bin_Code;
                        zdd.ErfmeSales      = item.Erfme_Sales;
                        zdd.UnitNameForSale = GetUnitByCode(branchCode, item.Erfme_Sales);
                        zdd.ErfmeSku        = item.Erfme_Sku;
                        zdd.UnitNameForSKU  = GetUnitByCode(branchCode, item.Erfme_Sku);
                        zdd.Iblnr           = item.Iblnr;
                        zdd.Gjahr           = item.Gjahr;
                        zdd.Zeili           = item.Zeili;
                        zdd.Ean11           = item.Ean11;
                        zdd.Shelf           = zdd.Shelf;
                        zdd.ErfmgSku        = item.Erfmg_Sku;
                        zdd.Ratio           = item.Ratio;
                        zdd.ErfmgSales      = item.Erfmg_Sales;

                        zDDHandHeldCheckStockList.Add(zdd);
                    }

                    return(zDDHandHeldCheckStockList);
                }
            }
        }
Пример #6
0
        private void AddHandHeldCheckProductToSAP(string userCode, string userName, string employeeID, string locationCode, string warehouseCode, string branchCode, List <LocationDescription> locationDescriptions, List <ProductBarcode> products, string remark)
        {
            using (var sapConnection = new SAP.Connector.SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;


                    SAPProxyIII.ZDD_HH_CHECKAREATable zdd_hh_checkarea = new SAPProxyIII.ZDD_HH_CHECKAREATable();
                    SAPProxyIII.ZDD_HH_CHECKAREA      area             = new SAPProxyIII.ZDD_HH_CHECKAREA();

                    foreach (var item in locationDescriptions)
                    {
                        #region เก็บข้อมูลลง Internal Table
                        area.Bin_Code = locationCode;
                        switch (item.ID + 1)
                        {
                        case 1:
                            area.F01 = " ";
                            if (item.Checked)
                            {
                                area.F01 = "X";
                            }
                            break;

                        case 2:
                            area.F02 = " ";
                            if (item.Checked)
                            {
                                area.F02 = "X";
                            }
                            break;

                        case 3:
                            area.F03 = " ";
                            if (item.Checked)
                            {
                                area.F03 = "X";
                            }
                            break;

                        case 4:
                            area.F04 = " ";
                            if (item.Checked)
                            {
                                area.F04 = "X";
                            }
                            break;

                        case 5:
                            area.F05 = " ";
                            if (item.Checked)
                            {
                                area.F05 = "X";
                            }
                            break;

                        case 6:
                            area.F06 = " ";
                            if (item.Checked)
                            {
                                area.F06 = "X";
                            }
                            break;

                        case 7:
                            area.F07 = " ";
                            if (item.Checked)
                            {
                                area.F07 = "X";
                            }
                            break;

                        case 8:
                            area.F08 = " ";
                            if (item.Checked)
                            {
                                area.F08 = "X";
                            }
                            break;

                        case 9:
                            area.F09 = " ";
                            if (item.Checked)
                            {
                                area.F09 = "X";
                            }
                            break;

                        case 10:
                            area.F10 = 0;
                            if (item.Checked)
                            {
                                short areaF10 = 0;
                                Int16.TryParse(item.BlankNumber, out areaF10);
                                area.F10 = areaF10;
                            }
                            break;

                        case 11:
                            area.F11 = " ";
                            if (item.Checked)
                            {
                                area.F11 = "X";
                            }
                            break;

                        case 12:
                            area.F12 = " ";
                            if (item.Checked)
                            {
                                area.F12 = "X";
                            }
                            break;

                        case 13:
                            area.F13 = " ";
                            if (item.Checked)
                            {
                                area.F13 = "X";
                            }
                            break;

                        case 14:
                            area.F14 = " ";
                            if (item.Checked)
                            {
                                area.F14 = "X";
                            }
                            break;

                        case 15:
                            area.F15 = " ";
                            if (item.Checked)
                            {
                                area.F15 = "X";
                            }
                            break;

                        case 16:
                            area.F16 = " ";
                            if (item.Checked)
                            {
                                area.F16 = "X";
                            }
                            break;

                        case 17:
                            area.F17 = " ";
                            if (item.Checked)
                            {
                                area.F17 = "X";
                            }
                            break;

                        case 18:
                            area.F18 = " ";
                            if (item.Checked)
                            {
                                area.F18 = "X";
                            }
                            break;

                        case 19:
                            area.F19 = " ";
                            if (item.Checked)
                            {
                                area.F19 = "X";
                            }
                            break;

                        case 20:
                            area.Expoint = 0;
                            if (item.Checked)
                            {
                                short areaExpoint = 0;
                                Int16.TryParse(item.BlankNumber, out areaExpoint);
                                area.Expoint = areaExpoint;
                            }
                            break;

                        default:
                            break;
                        }
                        #endregion
                    }

                    area.Remark = remark;
                    area.Lgort  = warehouseCode;
                    area.Werks  = branchCode;

                    using (DbManager db = new DbManager(branchCode))
                    {
                        db.Command.CommandTimeout = 200;
                        var sql        = GetSql(28);
                        var documentNo = this.GetHandHeldCheckProductDocumentNo(branchCode);
                        try
                        {
                            db.BeginTransaction();

                            foreach (var item in products)
                            {
                                area.Matnr = item.ProductCode;
                                area.Meins = item.UnitCode;
                                zdd_hh_checkarea.Add(area);
                                prx.Zdd_Handheld_Checkarea(userName, employeeID, ref zdd_hh_checkarea);
                                if (zdd_hh_checkarea.Count > 0)
                                {
                                    if (!string.IsNullOrEmpty(zdd_hh_checkarea[0].Chkareano))
                                    {
                                        db.SetCommand(sql,
                                                      db.Parameter("@DOCNO", documentNo),
                                                      db.Parameter("@LOCATION", locationCode),
                                                      db.Parameter("@DOCDATE", DateTime.Now.Date),
                                                      db.Parameter("@USERID", userCode),
                                                      db.Parameter("@OFFICERID", employeeID),
                                                      db.Parameter("@CHKAREANO", zdd_hh_checkarea[0].Chkareano))
                                        .ExecuteNonQuery();

                                        documentNo = PrepareHandHeldCheckProductDocumentNo(documentNo);
                                    }
                                }
                            }

                            prx.CommitWork();
                            db.CommitTransaction();
                        }
                        catch (Exception ex)
                        {
                            prx.RollbackWork();
                            db.RollbackTransaction();
                            throw ex;
                        }
                    }
                }
            }
        }
Пример #7
0
        public List <HandHeldCounterHold> HandHeldCounterHoldGetByProductCode(string productCode, string userCode, string officerID, string warehouseCode, string branchCode, out string messageAlert)
        {
            string sapProductCode = SapProductCodeFormated(productCode);
            string e_iblnr        = "";
            string e_zcountqi     = "";

            string branchShort = "01";

            switch (branchCode)
            {
            case "1100":
                branchShort = "01";
                break;

            case "1200":
                branchShort = "02";
                break;

            case "1300":
                branchShort = "04";
                break;

            case "1400":
                branchShort = "05";
                break;

            default:
                branchShort = "03";         //ASM
                break;
            }
            try
            {
                //log.Info(string.Format("GlobalContext.SapDestination = {0}", GlobalContext.SapDestination));
                using (var sapConnection = new SAPConnection(GlobalContext.SapDestination))
                {
                    using (var proxy = new SAPProxyIII.UWProxy())
                    {
                        proxy.Connection = sapConnection;

                        SAPProxyIII.BAPIRET2Table    ret2    = new SAPProxyIII.BAPIRET2Table();
                        SAPProxyIII.WSELMATNRTable   table   = new SAPProxyIII.WSELMATNRTable();
                        SAPProxyIII.WSELMATNR        item    = new SAPProxyIII.WSELMATNR();
                        SAPProxyIII.ZCOUNT_ITEMTable itcount = new SAPProxyIII.ZCOUNT_ITEMTable();

                        item.Sign   = "I";
                        item.Option = "EQ";
                        item.Low    = sapProductCode;
                        table.Add(item);

                        //log.Info(string.Format("branchShort = {0}", branchShort));
                        //log.Info(string.Format("userCode = {0}", userCode));
                        //log.Info(string.Format("warehouseCode = {0}", warehouseCode));
                        //log.Info(string.Format("officerID = {0}", officerID));
                        //log.Info(string.Format("sapProductCode = {0}", sapProductCode));

                        proxy.Zmm_Inv_Cre_Count_Doc(branchShort
                                                    , userCode
                                                    , warehouseCode
                                                    , string.Empty
                                                    , officerID
                                                    , string.Empty
                                                    , out e_iblnr
                                                    , out e_zcountqi
                                                    , ref itcount
                                                    , ref table
                                                    , ref ret2);

                        if (ret2.Count > 0)
                        {
                            if (ret2[0].Type == "E")//I -สร้างได้ E -สร้างไม่ได้
                            {
                                // Nic Edit Add Reason
                                //messageAlert = "สินค้านี้มีสถานะเป็น E (สร้างไม่ได้)\nหรือสินค้าอาจถูกสร้างใบนับไปแล้วในวันนี้\nหรือสินค้านี้ไม่มีในคลัง\nไม่สามารถสร้างใบนับได้";
                                messageAlert = ret2[0].Message;
                                //End Nic Edit
                                //return null;
                                return(new List <HandHeldCounterHold>());
                            }
                        }
                    }
                }

                messageAlert = string.Empty;
                //return SAPHandHeldCounterHoldGetLocation(productCode, sapProductCode, warehouseCode, branchCode);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                messageAlert = ex.Message;
            }

            return(SAPHandHeldCounterHoldGetLocation(productCode, sapProductCode, warehouseCode, branchCode));
        }
Пример #8
0
        private string SapAddHandHeldCounter(string branchCode, List <HandHeldCounterHold> productStocks, bool confirm, out string e_zcountqi, out string e_iblnr)
        {
            HandHeldCounterHold productStock = productStocks[0];
            string _iblnr       = string.Empty;
            string _zcountqi    = string.Empty;
            string alertMessage = string.Empty;


            List <string> productCodeList = null;

            using (DbManager db = new DbManager(branchCode))
            {
                productCodeList = db.SetCommand(GetSql(22), db.Parameter("@DocumentNo", productStock.Docno)).ExecuteScalarList <string>();
            }

            string branchShort = "01";

            switch (productStock.Branchcode)
            {
            case "1100":
                branchShort = "01";
                break;

            case "1200":
                branchShort = "02";
                break;

            case "1300":
                branchShort = "04";
                break;

            case "1400":
                branchShort = "05";
                break;

            default:
                branchShort = "03";         //ASM
                break;
            }

            using (var sapConnection = new SAPConnection(GlobalContext.SapDestination))
            {
                using (var prx = new SAPProxyIII.UWProxy())
                {
                    prx.Connection = sapConnection;

                    SAPProxyIII.BAPIRET2Table    ret2         = new SAPProxyIII.BAPIRET2Table();
                    SAPProxyIII.WSELMATNRTable   tbCor        = new SAPProxyIII.WSELMATNRTable();
                    SAPProxyIII.WSELMATNRTable   tbIncor      = new SAPProxyIII.WSELMATNRTable();
                    SAPProxyIII.ZCOUNT_ITEMTable tbCorCount   = new SAPProxyIII.ZCOUNT_ITEMTable();
                    SAPProxyIII.ZCOUNT_ITEMTable tbIncorCount = new SAPProxyIII.ZCOUNT_ITEMTable();
                    SAPProxyIII.ZCOUNT_ITEM      itcount;//= new SAPProxyIII.ZCOUNT_ITEM();


                    decimal sumBalanceQuantity       = 0;
                    decimal sumQuantity              = 0;
                    string  sapProductCode           = string.Empty;
                    List <HandHeldCounterHold> holds = null;

                    //var sums = productStocks
                    //            .GroupBy(x => new { x.Productcode })
                    //            .Select(group => group.Sum(x => x.Balanceqty));

                    foreach (var productCode in productCodeList)
                    {
                        holds = productStocks.FindAll(p => p.Productcode == productCode);

                        if (holds != null)
                        {
                            foreach (var item in holds)
                            {
                                //sumBalanceQuantity += item.Balanceqty;
                                sumBalanceQuantity = item.Balanceqty;
                                sumQuantity       += item.Quantity;
                            }

                            sapProductCode = SapProductCodeFormated(productCode.ToString());

                            SAPProxyIII.WSELMATNR it = new SAPProxyIII.WSELMATNR();
                            it.Sign   = "I";
                            it.Option = "EQ";
                            it.Low    = sapProductCode;

                            tbCor.Add(it);
                            //SAPProxyIII.ZCOUNT_ITEM zCountITem = null;
                            foreach (var item in holds)
                            {
                                //zCountITem = new SAPProxyIII.ZCOUNT_ITEM();
                                itcount          = new SAPProxyIII.ZCOUNT_ITEM();
                                itcount.Bin_Code = item.Location;
                                itcount.Erfmg1   = item.Quantity;
                                itcount.Meins1   = item.Unitcode;
                                itcount.Matnr    = sapProductCode;

                                log.Debug("itcount.Bin_Code=" + itcount.Bin_Code);
                                log.Debug("itcount.Erfmg1=" + itcount.Erfmg1);
                                log.Debug("itcount.Meins1=" + itcount.Meins1);
                                log.Debug("itcount.Matnr=" + itcount.Matnr);

                                //log.Debug("sumQuantity == sumBalanceQuantity=" + sumQuantity == sumBalanceQuantity);
                                //tbCorCount.Add(itcount);
                                if (sumQuantity == sumBalanceQuantity)
                                {
                                    tbCorCount.Add(itcount);
                                }
                                else
                                {
                                    tbIncorCount.Add(itcount);
                                }
                            }

                            sumBalanceQuantity = 0;
                            sumQuantity        = 0;
                        }
                    }

                    //ตรง
                    if (tbCorCount.Count > 0)
                    {
                        //prx.Zmm_Inv_Cre_Count_Doc(branchShort, productStock.Createuser, productStock.Warehouse, "X", productStock.Officerid, "X", out _iblnr, out _zcountqi, ref tbCorCount, ref tbCor, ref ret2);
                        prx.Zmm_Inv_Cre_Count_Doc(branchShort, productStock.Createuser, productStock.Warehouse, "X", productStock.Officerid, "X", out _iblnr, out _zcountqi, ref tbCorCount, ref tbCor, ref ret2);
                    }
                    if (ret2.Count > 0)
                    {
                        alertMessage = string.Format("{0} - {1}", "นับตรง(true)", ret2[0].Message);
                    }
                    //ไม่ตรง
                    if (tbIncorCount.Count > 0)
                    {
                        if (confirm)
                        {
                            //prx.Zmm_Inv_Cre_Count_Doc(branchShort, productStock.Createuser, productStock.Warehouse, "", productStock.Officerid, "X", out _iblnr, out _zcountqi, ref tbIncorCount, ref tbIncor, ref ret2);
                            //prx.Zmm_Inv_Cre_Count_Doc(branchShort, productStock.Createuser, productStock.Warehouse, "", productStock.Officerid, "X", out _iblnr, out _zcountqi, ref tbIncorCount, ref tbCor, ref ret2);
                            //alertMessage = ret2[0].Message;// "บันทึกข้อมูลเรียบร้อยแล้ว\n คุณได้ยืนยัน\nนับไม่ตรง";

                            prx.Zmm_Inv_Cre_Count_Doc(branchShort, productStock.Createuser, productStock.Warehouse, "X", productStock.Officerid, "X", out _iblnr, out _zcountqi, ref tbIncorCount, ref tbCor, ref ret2);
                            if (ret2.Count > 0)
                            {
                                alertMessage = string.Format("บันทึกข้อมูลเรียบร้อยแล้ว\n คุณได้ยืนยัน\nนับไม่ตรง(true)\n{0}", ret2[0].Message);
                            }
                        }
                        else
                        {
                            alertMessage = "นับไม่ตรง(false)กับสต็อกจริง\nคุณยืนยันการนับหรือไม่";
                        }
                    }
                    //if (ret2.Count > 0)
                    //    alertMessage = string.Format("{0} - {1}", "นับไม่ตรง", ret2[0].Message);
                }
            }


            e_zcountqi = _zcountqi;
            e_iblnr    = _iblnr;

            return(alertMessage);
        }
Пример #9
0
        public List <HandHeldCounterHold> HandHeldCounterHoldGetByProductCode(string productCode, string userCode, string officerID, string warehouseCode, string branchCode, out string messageAlert)
        {
            string sapProductCode = SapProductCodeFormated(productCode);
            string e_iblnr        = "";
            string e_zcountqi     = "";

            string branchShort = "01";

            switch (branchCode)
            {
            case "1100":
                branchShort = "01";
                break;

            case "1200":
                branchShort = "02";
                break;

            case "1300":
                branchShort = "04";
                break;

            default:
                branchShort = "03";         //ASM
                break;
            }

            using (var sapConnection = new SAPConnection(GlobalContext.SapDestination))
            {
                using (var proxy = new SAPProxyIII.UWProxy())
                {
                    proxy.Connection = sapConnection;

                    SAPProxyIII.BAPIRET2Table    ret2    = new SAPProxyIII.BAPIRET2Table();
                    SAPProxyIII.WSELMATNRTable   table   = new SAPProxyIII.WSELMATNRTable();
                    SAPProxyIII.WSELMATNR        item    = new SAPProxyIII.WSELMATNR();
                    SAPProxyIII.ZCOUNT_ITEMTable itcount = new SAPProxyIII.ZCOUNT_ITEMTable();

                    item.Sign   = "I";
                    item.Option = "EQ";
                    item.Low    = sapProductCode;
                    table.Add(item);
                    proxy.Zmm_Inv_Cre_Count_Doc(branchShort
                                                , userCode
                                                , warehouseCode
                                                , string.Empty
                                                , officerID
                                                , string.Empty
                                                , out e_iblnr
                                                , out e_zcountqi
                                                , ref itcount
                                                , ref table
                                                , ref ret2);

                    if (ret2.Count > 0)
                    {
                        if (ret2[0].Type == "E")//I -สร้างได้ E -สร้างไม่ได้
                        {
                            messageAlert = "สินค้านี้มีสถานะเป็น E (สร้างไม่ได้)\nหรือสินค้าอาจถูกสร้างใบนับไปแล้วในวันนี้\nไม่สามารถสร้างใบนับได้";
                            return(null);
                        }
                    }
                }
            }

            messageAlert = string.Empty;
            return(SAPHandHeldCounterHoldGetLocation(productCode, sapProductCode, warehouseCode, branchCode));
        }