Пример #1
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);
        }
Пример #2
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));
        }
Пример #3
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));
        }