using System;
using System.Text;
using System.Collections;
using System.Data;

using Cosmos.BaseFrame;
using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using System.Windows.Forms;

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 상품등록 관리 기본 기능
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    /// <summary>
    /// 상품등록 관리 기본 클래스
    /// </summary>
    class SalePluItemBase
    {
        protected SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        protected StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        protected PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        protected TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조

        protected IDatabaseSQL m_cSqlDbService = null;                                // 데이터베이스 관리
        protected IDataProcessUs m_cDataService = null;                               // 거래데이터 합계금액 계산 및 관리
        protected IMasterUs m_cMstService = null;                                     // 마스터 인터페이스
        protected IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        protected ICampaignUs m_cCampaingMain = null;                                 // 캠페인 관리
        protected ICustDisplayUs m_cCustDisp = null;                                  // 고객용 화면 관리

        frmInputPrc m_cfInPrc = new frmInputPrc();                                    // 단가 입력 폼

        /// <summary>
        /// 상품등록 트란 정보
        /// </summary>
        //protected ArrayList m_alTrPluItem = null;
        public ArrayList m_alTrPluItem = null;

        /// <summary>
        /// 생성자
        /// </summary>
        public SalePluItemBase()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;
            m_cTrnStatus = (TranStatus)StateObject.TRAN;

            m_cSqlDbService = (IDatabaseSQL)sManager.InitServiceInstance(ServiceLists.AGENT_DATABASE.DLL, ServiceLists.AGENT_DATABASE.DATABASE_MSSQL);
            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
            m_cMstService = (IMasterUs)sManager.InitServiceInstance(ServiceLists.ASV_MASTER.DLL, ServiceLists.ASV_MASTER.POS_MASTER);
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
            m_cCampaingMain = (ICampaignUs)sManager.InitServiceInstance(ServiceLists.ASV_CAMPAIGN.DLL, ServiceLists.ASV_CAMPAIGN.CAMPAIGN_MAIN);
            m_cCustDisp = (ICustDisplayUs)sManager.InitServiceInstance(ServiceLists.ASV_CUSTDISPLAY.DLL, ServiceLists.ASV_CUSTDISPLAY.CUST_DISPLAY);

            // 상품등록 정보
            m_alTrPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
        }


        ///// <summary>
        ///// 상품 등록 처리
        ///// </summary>
        ///// <param name="sSelRow">선택행</param>
        ///// <param name="sInPutTypeCode">(0:수입력, 1:메뉴, 2:스켄, 3:플레이버) + (메뉴코드,스캔코드)</param>
        ///// <param name="sInPutData">입력데이터(수량)</param>
        ///// <returns></returns>
        //public string SetItemCode(string sSelRow, string sInPutTypeCode, string sInPutData)
        //{
        //    string sSubStoreNo = "", sItemCode = "", sScanCode = "";      //점포코드, 상품코드, 스켄코드
        //    string sRet = UserCom.RST_ERR;

        //    try
        //    {
        //        string sInPutType = PosConst.SALE_PLU_INPUT_TYPE.MENUKEY;
        //        if (sInPutTypeCode.Length > 0) sInPutType = sInPutTypeCode.Substring(0, 1);

        //        if (sInPutTypeCode.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.MENUKEY) || sInPutTypeCode.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.FLAVOUR))              // 메뉴코드
        //        {
        //            // 메뉴코드 = (점포코드(10)+상품코드) 
        //            sSubStoreNo = sInPutTypeCode.Substring(1, 10).Trim();   // 점포코드
        //            sItemCode = sInPutTypeCode.Substring(11);               // 상품코드
        //        }
        //        else if (sInPutTypeCode.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.KEY_IN) || sInPutTypeCode.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.SCANNER))         // 스캔입력 
        //        {
        //            sSubStoreNo = m_cPosStatus.Base.StoreNo;                // 점포코드
        //            sScanCode = sInPutTypeCode.Substring(1);                // 스캔코드
        //        }
        //        else
        //        {
        //            sSubStoreNo = m_cPosStatus.Base.StoreNo;                // 점포코드
        //            sItemCode = sInPutTypeCode.Substring(1);                // 상품코드
        //        }
            
        //        sRet = SetItemCode(sSelRow, sInPutType, sSubStoreNo, sItemCode, sScanCode , sInPutData);
        //    }
        //    catch (Exception ex)
        //    {
        //        WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
        //            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
        //    }
        //    return sRet;
        //}
        /// <summary>
        /// 상품 등록 처리
        /// </summary>
        /// <param name="sSelRow">선택행</param>
        /// <param name="sInPutType">(0:수입력, 1:메뉴, 2:스켄, 3:플레이버</param>
        /// <param name="sSubStoreNo">서브점포코드</param>
        /// <param name="sItemCode">메뉴코드</param>
        /// <param name="sScanCode">스캔코드</param>
        /// <param name="sInPutData">입력데이터(수량)</param>
        /// <returns></returns>
        public string SetItemCode(string sSelRow, string sInPutType, string sSubStoreNo, string sItemCode, string sScanCode, string sInPutData)
        {
            int nSelRow = 0;
            string sRet = UserCom.RST_ERR;
            //string sRetItem = ""; string sRetScan = ""; string sShtcutItemNm = "";
            string sItemNm = string.Empty;
            //#20171120 유통기한 바코드 인식률 start, phj
            string sBar_No = string.Empty;
            //#20171120 유통기한 바코드 인식률 end, phj

            try
            {
                string sCampignFreeGift = sInPutType;   // 캠페인 사은품 여부(B:사은품, C:사은품(HP))
                if (sInPutType == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT || sInPutType == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT_HP) sInPutType = PosConst.SALE_PLU_INPUT_TYPE.MENUKEY;

                //#20171018 상품등록 유통기한 체크하기 start, phj 
                bool TimeStampBarCodeYN = false;
                //#20171018 상품등록 유통기한 체크하기 end, phj

                // 바코드 체크
                if (sScanCode.Length >= 6)
                {
                    // 브랜드별 바코드 규칙 체크(유통기간 및 상품코드 변경!)
                    string sRetItem = ""; string sRetScan = ""; string sShtcutItemNm = "";
                    
                    #region
                    //#20171018 상품등록 유통기한 체크하기 start, phj
                    //기존
                    //string sItemRet = m_cDataCommon.SeletItemMstToBarCode(sSubStoreNo, sScanCode, ref sRetItem, ref sRetScan, ref sShtcutItemNm);
           
                    //변경 
                    
                    string sItemRet = string.Empty;

                    //#20171207 유통기한 바코드 CHECK DIGIT 체크 기능 start
                    //기존
                    /*
                    if ((sScanCode.Length == 13) &&
                        (sScanCode.Substring(0, 1) == "2") &&
                        (sScanCode.Substring(12, 1) == "1"))
                    */
                    //변경
                    if ((sScanCode.Length == 13) &&
                        (sScanCode.Substring(0, 1) == "2") &&
                        (sScanCode.Substring(12, 1) == TimeStampBarCode_CheckDigit(sScanCode)))
                    //#20171207 유통기한 바코드 CHECK DIGIT 체크 기능 end
                    {
                        //#20171120 유통기한 바코드 인식률 start, phj
                        sBar_No = sScanCode;
                        //#20171120 유통기한 바코드 인식률 end, phj

                        sItemRet = m_cDataCommon.TimeStampBarCodeCheck(sSubStoreNo, sScanCode, ref sRetItem);
                        TimeStampBarCodeYN = true;

                    } 
                    else
                    {
                        // grayber@20171129 필터 추가 및 바코드 상품 검색 조건 개선 start
                        sItemRet = m_cDataCommon.SeletItemMstToBarCode(sSubStoreNo, sScanCode, ref sRetItem, ref sRetScan, ref sShtcutItemNm);
                      
                        if (sScanCode.Length == 6 && sScanCode.StartsWith("N") == true && m_cPosStatus.Mst.CorpDiv.Equals(ItemConst.CORP_DIV.BR) == true) 
                        { 
                            TimeStampBarCodeYN = true;
                            //grayber@20171207 BR N코드에 대하여 유통기한 바코드 인식률 대한 무시 처리
                            sBar_No = sScanCode;
                            //grayber@20171207 BR N코드에 대하여 유통기한 바코드 인식률 대한 무시 처리
                        }
                        else
                        { 
                            TimeStampBarCodeYN = false; 
                        }
                        // grayber@20171129 필터 추가 및 바코드 상품 검색 조건 개선 start
                    }                    
                    //#20171018 상품등록 유통기한 체크하기 end, phj

                    #endregion

                    #region
                    if (sItemRet == UserCom.RST_ERR)
                    {
                        //#16401 해피오더)주문내역 바코드 리딩 시 자동 완료처리 start - 20180829
                        //기존
                        /*
                        //#20171120 유통기한 바코드 인식률 start, phj
                        //0 : 실패 1 : 성공 
                        if (TimeStampBarCodeYN == true)
                        {
                            m_cDataCommon.BarCodeSuccessRate(sBar_No, "0");
                        }
                        //#20171120 유통기한 바코드 인식률 end, phj
                        */

                        //변경
                        if (sShtcutItemNm != "HP_ORD") 
                        {
                            //#20171120 유통기한 바코드 인식률 start, phj
                            if (TimeStampBarCodeYN == true)
                            {
                                //0 : 실패 1 : 성공 
                                m_cDataCommon.BarCodeSuccessRate(sBar_No, "0");
                            }
                            //#20171120 유통기한 바코드 인식률 end, phj
                        }
                        //#16401 해피오더)주문내역 바코드 리딩 시 자동 완료처리 end - 20180829

                        return sRet;
                    }                    
                    else if (sItemRet == UserCom.RST_OK)    //정상이면 넘어온값으로 셋팅
                    {
                        sItemCode = sRetItem;
                        sScanCode = sRetScan;
                    }
                    #endregion
                }

                //#20171018 상품등록 유통기한 체크하기 start, phj
                //기존
                //상품 마스터 조회
                //DataTable dtDataInfo = m_cDataCommon.SearchItemCode(sSubStoreNo, sItemCode, sScanCode);

                //변경
                DataTable dtDataInfo = m_cDataCommon.SearchItemCode(sSubStoreNo, sItemCode, sScanCode, TimeStampBarCodeYN);
                //#20171018 상품등록 유통기한 체크하기 end, phj
                if (dtDataInfo == null || dtDataInfo.Rows.Count == 0)
                {
                    #region
                    //#20171120 유통기한 바코드 인식률 start, phj
                    
                    //0 : 실패 1 : 성공 
                    if (TimeStampBarCodeYN == true)
                    {
                        m_cDataCommon.BarCodeSuccessRate(sBar_No, "0");
                    }
                    
                    //#20171120 유통기한 바코드 인식률 end, phj

                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0010);        // 등록되지 않은 상품 입니다
                    return sRet;

                    #endregion
                }

                //#20171120 유통기한 바코드 인식률 start, phj
                
                //0 : 실패 1 : 성공 
                if (TimeStampBarCodeYN == true)
                {
                    m_cDataCommon.BarCodeSuccessRate(sBar_No, "1");
                }
                
                //#20171120 유통기한 바코드 인식률 end, phj

                DataRow drPlu = dtDataInfo.Rows[0];

                if (PosMstManager.GetPosOption(POS_OPTION.OPT041) == "1")    
                {
                    #region
                    if (CmUtil.LongParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_START_DT)) > 0 && CmUtil.LongParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_FNSH_DT)) > 0)
                    {
                        if (CmUtil.LongParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_START_DT)) > CmUtil.LongParse(m_cPosStatus.Base.SaleDate)
                            || CmUtil.LongParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_FNSH_DT)) < CmUtil.LongParse(m_cPosStatus.Base.SaleDate))
                        {
                            // 판매 불가 상품 입니다
                            WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0011) + PosConst.CRLF
                                + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0870) + " : "
                                + CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_START_DT) + " - " + CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_FNSH_DT));        
                            return sRet;
                        }
                    }

                    if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_PRMT_YN) == "0")
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0011);        // 판매 불가 상품 입니다
                        return sRet;
                    }

                    //if (sInPutType == PosConst.SALE_PLU_INPUT_TYPE.KEY_IN || sInPutType == PosConst.SALE_PLU_INPUT_TYPE.MENUKEY || sInPutType == PosConst.SALE_PLU_INPUT_TYPE.SCANNER)
                    //{
                        
                    //}

                    #endregion
                }

                //#15347 주류 경고메시지 출력 start
                //if (m_cPosStatus.Mst.CorpDiv == ItemConst.CORP_DIV.PC && m_cPosStatus.Mst.CntryDiv == ItemConst.CNTRY_DIV.KR)
                //if (m_cTrnStatus.Head.CmpCd == "PBKR")
                if (m_cPosStatus.Base.BrandCd  == PosConst.MST_BRAND_CODE.PC_PB)
                {
                    if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ALCOHOL_ITEM_TYPE) != "0" &&
                    CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ALCOHOL_ITEM_TYPE) != "")
                    {
                        bool bItemRegister = false;
                        ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                        foreach (Column.TR_PLU.DATA cPluItem in alSaleItem)
                        {
                            if (cPluItem.ITEM_PLU_CD == CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_CD))
                            {
                                bItemRegister = true;
                                break;
                            }
                        }

                        if (bItemRegister == false)
                        {
                            if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ALCOHOL_ITEM_TYPE) == "5")
                            {
                                //성인용 음료로 미성년자에게 판매할 수 없습니다. 신분증을 확인해주세요.
                                WinManager.ErrorMessage(MessageManager.GetGuideMessage(POS_MESSAGE.GUIDE.MSG_0015));
                            }
                            else
                            {
                                //주류상품은 미성년자에게 판매할 수 없습니다. 신분증을 확인해주세요.
                                WinManager.ErrorMessage(MessageManager.GetGuideMessage(POS_MESSAGE.GUIDE.MSG_0016));
                            }
                        }
                    }
                }
                //#15347 주류 경고메시지 출력 end 



                if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TIME_BAR_CD_YN) == "1")
                {
                    #region
                    if (sScanCode.Length == 15 && sScanCode.StartsWith("S88") == true)
                    {
                        if ( CmUtil.LongParse(sScanCode.Substring(9, 6)) > CmUtil.LongParse( DateTime.Now.ToString("yyMMdd")))
                        {
                            WinManager.ErrorMessage( MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0011) + PosConst.CRLF
                                                   + MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0329));    // 판매 불가 상품 입니다
                            return sRet;
                        }
                    }

                    #endregion
                }

                if (m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.CHARGESALE.PREPAID)
                {
                          
                }
                else
                {
                    if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.CHARGESALE.GIFT)
                    {
                        #region
                        //상품권 판매가 아닌경우 상품권 상품이 들어올 경우 에러!
                        if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_TYPE).Equals(PosConst.ITEM_TYPE.GIFT.ToString()))
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0076);
                            return sRet;
                        }
                        //선불카드 판매가 아닌경우 선불카드 상품이 들어올 경우 에러!
                        if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_TYPE).Equals(PosConst.ITEM_TYPE.PREPAID.ToString()))
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0077);
                            return sRet;
                        }
                        #endregion
                    }

                }

                // 같은 상품 등록 여부 체크(수량증가)
                bool bQtyAdd = false;
                //nSelRow = m_alTrPluItem.Count - 1;
                //if ((m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING && sInPutType.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.SUBMENU))
                //        || sInPutType.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.FLAVOUR))
                //{
                //    nSelRow = CmUtil.IntParse(sSelRow);
                //}

                //if (m_alTrPluItem.Count > 0 && sInPutData == ""
                //    && (PosMstManager.GetPosOption(POS_OPTION.OPT031) == "1" || PosMstManager.GetPosOption(POS_OPTION.OPT031) == "2"))  // 수량 합산 처리(0:미합산, 1:최종상품합산, 2:전체상품합산)
                //{
                //    #region
                //    if ( (m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING && sInPutType.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.SUBMENU))
                //        || sInPutType.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.FLAVOUR))
                //    {
                //        nSelRow = CmUtil.IntParse(sSelRow);
                //        if (nSelRow + 1 < m_alTrPluItem.Count)
                //        {
                //            #region
                //            Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)m_alTrPluItem[nSelRow + 1];
                //            if (cPluItem.SUB_SHOP_CD == CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SUB_STOR_CD)
                //                && cPluItem.ITEM_PLU_CD == CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_CD)
                //                && cPluItem.ORDER_OK_FLAG == PosConst.PLU_ORDER_OK_FLAG.ORDER_ING
                //                //#20170825 오픈 상품은 무조건 새 row로 입력 start
                //                //기존
                //                //&& cPluItem.CANCEL_DIV == "0" && cPluItem.DC_DIV == ItemConst.PLU_DC_DIV.NORMAL && cPluItem.SALE_QTY < 99999)
                //                //변경
                //                && cPluItem.CANCEL_DIV == "0" && cPluItem.DC_DIV == ItemConst.PLU_DC_DIV.NORMAL && cPluItem.SALE_QTY < 99999
                //                && CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.OPEN_ITEM_DIV) != "1")
                //                //#20170825 오픈 상품은 무조건 새 row로 입력 end

                //            {
                //                // 수량 증가
                //                cPluItem.SALE_QTY += 1;
                //                bQtyAdd = true;
                //            }
                //            #endregion
                //        }
                //    }
                //    else
                //    {
                //        Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)m_alTrPluItem[nSelRow];
                //        if (cPluItem.SUB_SHOP_CD == CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SUB_STOR_CD)
                //            && cPluItem.ITEM_PLU_CD == CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_CD)
                //            && cPluItem.ORDER_OK_FLAG == PosConst.PLU_ORDER_OK_FLAG.ORDER_ING
                //            && cPluItem.CANCEL_DIV == "0" //&& cPluItem.DC_DIV == ItemConst.PLU_DC_DIV.NORMAL 
                //            && cPluItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.NORMAL && cPluItem.SALE_QTY < 99999
                //            && cPluItem.EXCEP_DC_AMT == 0 && cPluItem.SET_DC_AMT == 0 && cPluItem.ITEM_DC_AMT == 0 && cPluItem.SUM_DC_AMT == 0
                //            //#20170825 오픈 상품은 무조건 새 row로 입력 start
                //            //기존
                //            //&& cPluItem.NOTAX_DIV != PosConst.ITEM_NOTAX_DIV.YES )
                //            //변경
                //            && cPluItem.NOTAX_DIV != PosConst.ITEM_NOTAX_DIV.YES
                //            && CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.OPEN_ITEM_DIV) != "1")
                //            //#20170825 오픈 상품은 무조건 새 row로 입력 end
                //            //&& cPluItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.NORMAL)
                //        {
                //            // 수량 증가
                //            cPluItem.SALE_QTY += 1;
                //            bQtyAdd = true;
                //        }
                //    }
                //    #endregion
                //}

                if (bQtyAdd == false)
                {
                    // 상품등록 한거래에 99이상 안되도록 수정(2017.05.20)
                    if (m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING)
                    {
                        #region
                        if (sCampignFreeGift.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.MENUKEY)
                            || sCampignFreeGift.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.KEY_IN) || sCampignFreeGift.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.SCANNER))
                        {
                            if (m_alTrPluItem.Count >= 99)
                            {
                                WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0499);
                                return sRet;
                            }
                        }
                        #endregion
                    }

                    // 상품 정보 생성
                    Column.TR_PLU.DATA cPluItem = new Column.TR_PLU.DATA();

                    cPluItem.ITEM_BRAND_CD = ""; //CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_BRAND_CD); 마스터 추가 필요!!!!

                    cPluItem.SUB_SHOP_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SUB_STOR_CD);
                    cPluItem.ITEM_PLU_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_CD);
                    cPluItem.ITEM_DIV = "0";
                    cPluItem.SALE_QTY = 1;

                    //#Rhee, 20180209 미국 상품검색 후 상품 추가시 상품의 중분류로 이동 Start
                    if (m_cPosStatus.Base.CmpCd.ToUpper().Equals(PosConst.POS_COMPANY_CODE.PCUS) && CmUtil.GetDataRowStr(drPlu, "GRP_SEQ") != string.Empty)
                    {
                        cPluItem.GRP_SEQ = CmUtil.GetDataRowStr(drPlu, "GRP_SEQ");
                    }
                    //#Rhee, 20180209 미국 상품검색 후 상품 추가시 상품의 중분류로 이동 End
                    
                    //금액 과 세금 구분은 옵션으로 변경 해야함!!!!
                    #region
                    if (PosMstManager.GetPosOption(POS_OPTION.OPT005) == "0")
                    {
                        cPluItem.SALE_PRC = CmUtil.GetDataRowDouble(drPlu, PosMst.MST_ITEM.DATA.TAKE_OUT_SALE_AMT);
                        cPluItem.TAXRATE_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_OUT_VAT_CD);
                    }
                    else
                    {
                        cPluItem.SALE_PRC = CmUtil.GetDataRowDouble(drPlu, PosMst.MST_ITEM.DATA.TAKE_IN_SALE_AMT);
                        cPluItem.TAXRATE_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_IN_VAT_CD);
                    }
                    #endregion

                    cPluItem.ITEM_TAKE_IN_VAT_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_IN_VAT_CD);
                    cPluItem.ITEM_TAKE_OUT_VAT_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_OUT_VAT_CD);

                    // 상품권 or 선불카드 판매 일때!
                    #region
                    if (m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.CHARGESALE.GIFT || m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.CHARGESALE.PREPAID)
                    {
                        cPluItem.SALE_GIFT_NO = sInPutData.Trim();
                    }
                    else
                    {
                        cPluItem.SALE_GIFT_NO = "";
                    }
                    #endregion


                    cPluItem.SALE_AMT = 0;
                    #region
                    if (sInPutType == PosConst.SALE_PLU_INPUT_TYPE.FLAVOUR)
                    {
                        if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_DIV) != ItemConst.PLU_FLAVOUR_DIV.FLAVOUR)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0029);
                            return UserCom.RST_ERR;
                        }
                    }
                    else
                    {
                        if (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_DIV) == ItemConst.PLU_FLAVOUR_DIV.FLAVOUR)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0011);        // 판매 불가 상품 입니다
                            return UserCom.RST_ERR;
                        }
                    }
                    #endregion

                    #region

                    cPluItem.FLAVOUR_DIV = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_DIV) == "" ? ItemConst.PLU_FLAVOUR_DIV.NORMAL : CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_DIV);
                    cPluItem.FLAVOUR_QTY = CmUtil.GetDataRowLong(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_QTY);
                    cPluItem.FLAVOUR_STOCK = CmUtil.GetDataRowDouble(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_STOCK);
                    cPluItem.ITEM_INPUT_DIV = (sInPutType.StartsWith("0") == true) ? "2" : "1";
                    cPluItem.ITEM_BAR_CD = sScanCode;
                    cPluItem.TAKE_IN_OUT_DIV = "1";
                    cPluItem.ITEM_TAX_DIV = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_TAX_AMT_DIV);
                    
                    cPluItem.NOTAX_DIV = PosConst.ITEM_NOTAX_DIV.NO;

                    //2018.01.04;미주 상품별 부가세 적용 처리;girak.kim;Start
                    //cPluItem.TAX_AMT_INCLUDE_YN = m_cPosStatus.Mst.TaxAmtIncludeYn;//기존 소스
                    if( m_cPosStatus.Base.CmpCd.ToUpper().Equals(PosConst.POS_COMPANY_CODE.PCUS) )
                    {
                        cPluItem.TAX_AMT_INCLUDE_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAX_AMT_INCLUDE_YN);
                    }
                    else
                    {
                        cPluItem.TAX_AMT_INCLUDE_YN = m_cPosStatus.Mst.TaxAmtIncludeYn;
                    }
                    //2018.01.04;미주 상품별 부가세 적용 처리;girak.kim;End

                    cPluItem.APPLY_TAX_AMT = 0;
                    cPluItem.SVC_FEE_AMT = 0;
                    cPluItem.SVC_FEE_VAT = 0;
                    cPluItem.BILL_AMT = 0;                
                    cPluItem.SUM_DC_AMT = 0;
                    cPluItem.CPI_DC_AMT = 0;
                    cPluItem.COOP_CARD_DC_AMT = 0;
                    cPluItem.SET_DC_AMT = 0;
                    cPluItem.SET_DC_GROUP_CD = 0;
                    cPluItem.ETC_DC_DIV = "0000";
                    cPluItem.ETC_DC_AMT = 0;

                    cPluItem.EXCEP_DC_DIV = "0000";
                    cPluItem.EXCEP_DC_AMT = 0;

                    cPluItem.PACK_DIV = "0";
                    cPluItem.SET_MENU_CD = "";
                    cPluItem.CPI_PRESENT_DIV = "0";
                    cPluItem.BILLSPR_NO = 0;
                    cPluItem.CANCEL_DIV = "0";
                    cPluItem.CANCEL_DATE = "";
                    cPluItem.SUB_MENU_MAIN_CD = "";
                    

                    cPluItem.DISPO_ITEM_DIV = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.DISPO_ITEM_DIV);
                    
                    cPluItem.SUB_SET_MNG_TYPE = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SUB_SET_MNG_TYPE);

                    //#15746 해피오더 '쇼킹박스' 관련 POS 시스템 개발 요청 start

                    cPluItem.ITEM_INFO = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_INFO); // 영양성분 
                    cPluItem.ITEM_EXPLN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_EXPLN); // 상품설명 
                    cPluItem.ALLERGY = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ALLERGY); // 알레르기성분 
                    cPluItem.PLACE_ORIGIN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.PLACE_ORIGIN); // 원산지

                    //#15746 해피오더 '쇼킹박스' 관련 POS 시스템 개발 요청 end


                    //#20180903 해피오더 매출 생성 시 tr_sale_detail에 구분자 추가 start
                    cPluItem.HPO_REG_YN = "0";
                    //#20180903 해피오더 매출 생성 시 tr_sale_detail에 구분자 추가 end

                    #endregion


                    #region
                    if (m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING_SET)
                    {
                        // 세트 하위 메뉴
                        cPluItem.ITEM_DIV = ItemConst.PLU_ITEM_DIV.SET_DETL;
                        cPluItem.ITEM_NAME = ">" + CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SHTCUT_ITEMNM);
                        cPluItem.SET_MENU_CD = m_cTrnStatus.Sale.SetPluSetMainCode;
                        cPluItem.SALE_PRC = m_cTrnStatus.Sale.SetPluUpSalePrc;

                        cPluItem.SET_PLU_SET_GROUP_CODE = m_cTrnStatus.Sale.SetPluSetGroupCode;
                    }
                    else if (sInPutType.StartsWith(PosConst.SALE_PLU_INPUT_TYPE.SUBMENU) == true)
                    {
                        // 부가메뉴
                        cPluItem.ITEM_DIV = ItemConst.PLU_ITEM_DIV.OPT_MENU;
                        cPluItem.ITEM_NAME = ">>" + CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SHTCUT_ITEMNM);
                        cPluItem.SUB_MENU_MAIN_CD = m_cTrnStatus.Sale.SubMenuMainCode;
                        cPluItem.SUBPRC_MENU_KEY_DIV = m_cTrnStatus.Sale.SubMenuKeyDiv;
                        // 부가메뉴구분(1:속성,2:업차지,3:선택메뉴)
                        if (cPluItem.SUBPRC_MENU_KEY_DIV != "2")
                        {
                            //cPluItem.SALE_PRC = 0;
                            //  2019-05-03 - 1997fx11 : 부가옵션에 대한 금액부여, 파라미터 'sInPutData' 에 Take in / out 구분을 가져올 예정.
                            string[] stemp = sInPutData.Split('|');
                            if (stemp[0] == "1002")
                            {
                                cPluItem.SALE_PRC = CmUtil.DoubleParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_IN_SALE_AMT));
                            }
                            else
                            {
                                cPluItem.SALE_PRC = CmUtil.DoubleParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_OUT_SALE_AMT));
                            }
                        }
                        else { cPluItem.SALE_PRC = m_cTrnStatus.Sale.SubMenuUpSalePrc; }
                    }
                    else if (cPluItem.FLAVOUR_DIV == ItemConst.PLU_FLAVOUR_DIV.FLAVOUR)
                    {
                        // 플레이버
                        cPluItem.ITEM_NAME = ">" + CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SHTCUT_ITEMNM);
                    }
                    else
                    {
                        #region
                        if (cPluItem.SUB_SET_MNG_TYPE == PosConst.MST_SUB_SET_MNG_TYPE.SET_MENU)
                        {
                            cPluItem.ITEM_DIV = ItemConst.PLU_ITEM_DIV.SET_MAIN;
                        }
                        else
                        {
                            if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.CHARGESALE.GIFT && m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.CHARGESALE.PREPAID)
                            {
                                // 상품 수량 입력된 수량으로 변경
                                if (sInPutData.Length > 0 && sInPutData.Length <= 5 && CmUtil.LongParse(sInPutData) > 0 ) cPluItem.SALE_QTY = CmUtil.LongParse(sInPutData);
                            }
                        }

                        #endregion
                        
                        cPluItem.ITEM_NAME = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SHTCUT_ITEMNM);
                    }

                    #endregion

                    cPluItem.OPEN_ITEM_DIV = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.OPEN_ITEM_DIV);

                    ////판매 loss일 경우 0원 처리
                    #region
                    if (m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.ETC.LOSS)
                    {
                    //    cPluItem.DC_RATE = 100;
                    //    cPluItem.ITEM_DC_AMT = cPluItem.SALE_PRC;
                    //    cPluItem.DC_DIV = "";
                        cPluItem.NONSALES_RSN_CD = m_cTrnStatus.Head.NonSaleRsnCd;
                        cPluItem.NONSALES_RSN_NM = m_cTrnStatus.Head.LossTitle;
                    }
                    else
                    {
                        cPluItem.NONSALES_RSN_CD = "0";
                        cPluItem.NONSALES_RSN_NM = "";
                    }
                    #endregion

                    cPluItem.DC_RATE = 0;
                    cPluItem.ITEM_DC_AMT = 0;
                    cPluItem.DC_DIV = ItemConst.PLU_DC_DIV.NORMAL;
                     
                    //상품권, 선불카드 판매일때 변경!
                    switch (CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_TYPE))
                    {
                       #region
                        case PosConst.ITEM_TYPE.GIFT:
                            //상품권일때 변경
                            cPluItem.ITEM_DIV = ItemConst.PLU_ITEM_DIV.GIFT;
                            break;
                        case PosConst.ITEM_TYPE.PREPAID:
                            //선불카드일때 변경
                            cPluItem.ITEM_DIV = ItemConst.PLU_ITEM_DIV.PREPAID;
                            break;

                      #endregion
                    }


                    if ((m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.NORMAL.SALE || m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.CHARGESALE.PREPAID
                        || m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.CHARGESALE.GIFT || m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.ETC.LOSS))
                    {
                        #region
                        if ((cPluItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.NORMAL || cPluItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.SET_MAIN ||
                                cPluItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.GIFT || cPluItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.PREPAID)
                                && cPluItem.OPEN_ITEM_DIV == "1" && (cPluItem.SALE_PRC == 1 || cPluItem.SALE_PRC == 0))
                        {
                            m_cfInPrc.PosMenuKeyOut = "";

                            //#16577 결제창 내부 봉투 추가 기능 도입 start
                            //오픈 상품인 경우 금액 입력 창에 상품명 및 안내 문구 표시
                            m_cfInPrc.PosMenuNm = cPluItem.ITEM_NAME;
                            //#16577 결제창 내부 봉투 추가 기능 도입 end

                            if (m_cfInPrc.ShowDialog() == DialogResult.Cancel)
                            {
                                // 취소면 에러
                                return UserCom.RST_ERR;
                            }
                            else
                            {
                                cPluItem.SALE_PRC = m_cDataService.DoubleParse(m_cfInPrc.PosMenuKeyOut);
                            }
                        }

                        #endregion
                    }

                    #region
                    cPluItem.CANCEL_DIV_MAIN = "0";
                    cPluItem.FREE_GIFT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.FREE_GIFT_YN);
                    cPluItem.DC_PRMT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.DC_PRMT_YN);
                    if (cPluItem.DC_PRMT_YN != "1") cPluItem.DC_PRMT_YN = "0";   // db에서 가져오지 않고 있어 임시 작업

                    cPluItem.ACCUM_PRMT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ACCUM_PRMT_YN);
                    cPluItem.SVC_FEE_TRGT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SVC_FEE_TRGT_YN);
                    cPluItem.COOP_CARD_DC_NOADM_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.COOP_CARD_DC_NOADM_YN);
                    
                    cPluItem.TOT_DC_AMT = 0;
                    cPluItem.ORDER_OK_FLAG = PosConst.PLU_ORDER_OK_FLAG.ORDER_ING;
                    cPluItem.L_CLSS = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.L_CLSS);
                    cPluItem.M_CLSS = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.M_CLSS);
                    cPluItem.S_CLSS = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.S_CLSS);

                    #endregion
                    
                    
                    //if (PosMstManager.GetPosOption(POS_OPTION.OPT034) == "1") //세브란스 일 경우
                    //{
                    //    cPluItem.SEVERANCE_MENU_DIV = SearchMenuMasterForSeverance(cPluItem.ITEM_PLU_CD, "", "");
                    //}
                    //else
                    //{
                        cPluItem.SEVERANCE_MENU_DIV = "0";
                    //}

                    cPluItem.CAKE_EXCHNG_CPN_USE_POSS_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.CAKE_EXCHNG_CPN_USE_POSS_YN);   // 케익교환권 가능 여부
                    cPluItem.CAMPAIGN_FREEGIFT = sCampignFreeGift;

                    cPluItem.ORD_TIME = DateTime.Now.ToString("HHmmss");

                    nSelRow = CmUtil.IntParse(sSelRow);
                    if (nSelRow == 0)
                    {
                        m_alTrPluItem.Add(cPluItem);                    // 등록 처리
                    }
                    else
                    {
                        if (nSelRow + 1 >= m_alTrPluItem.Count)
                            m_alTrPluItem.Add(cPluItem);                    // 등록 처리
                        else
                            m_alTrPluItem.Insert(nSelRow + 1, cPluItem);    // 등록 처리
                    }
                    m_cDataService.UpdatePluItemAmount(cPluItem);

                    //if (m_cPosStatus.Base.DmbIf == "1")
                    //{
                    //    // 디지털메뉴보드 I/F
                    //    IDataServiceUs cDigitalMenuBoard = (IDataServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.DMB_IF);

                    //    //#16569 파스쿠찌 드라이브 스루 기능 개발 요청 start
                    //    //기존
                    //    #region 주석
                    //    /*
                    //    ArrayList alPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                    //    if (alPluItem.Count == 1)
                    //    {
                    //        // 판매개시
                    //        cDigitalMenuBoard.Execute(new string[] { ItemConst.DMB_IRT_ID.SALE_BEGIN });
                    //    }
                        
                    //    // 상품등록
                    //    cDigitalMenuBoard.Execute(new string[] { ItemConst.DMB_IRT_ID.PRODUCT_REG, cPluItem.ITEM_PLU_CD, cPluItem.ITEM_NAME, "1" });
                    //    */
                    //    #endregion 주석
                    //    //변경
                    //    if (PosMstManager.GetPosOption(POS_OPTION.OPT554) != "1")
                    //    {
                    //        ArrayList alPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                    //        if (alPluItem.Count == 1)
                    //        {
                    //            // 주문시작
                    //            //cDigitalMenuBoard.Execute(new string[] { ItemConst.DMB_IRT_ID.SALE_BEGIN });
                    //        }

                    //        // 상품등록
                    //        //cDigitalMenuBoard.Execute(new string[] { ItemConst.DMB_IRT_ID.PRODUCT_REG, cPluItem.ITEM_PLU_CD, cPluItem.ITEM_NAME, "1" });
                    //    }
                    //    //#16569 파스쿠찌 드라이브 스루 기능 개발 요청 end
                    //}
                }

                sRet = UserCom.RST_OK;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }

        /// <summary>
        /// 상품 마스터 조회후 상품 정보 설정
        /// </summary>
        /// <param name="cPluItem"></param>
        /// <param name="sSubStoreNo"></param>
        /// <param name="sItemCode"></param>
        /// <returns></returns>
        public bool SetTrPluItemToMst(Column.TR_PLU.DATA cPluItem, string sSubStoreNo, string sItemCode)
        {
            try
            {
                // 상품 마스터 조회
                DataTable dtDataInfo = m_cDataCommon.SearchItemCode(sSubStoreNo, sItemCode, "");
                if (dtDataInfo == null || dtDataInfo.Rows.Count == 0)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0010);            // 등록되지 않은 상품 입니다
                    return false;
                }

                DataRow drPlu = dtDataInfo.Rows[0];
                if (CmUtil.LongParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_START_DT)) > CmUtil.LongParse(m_cPosStatus.Base.SaleDate)
                    || CmUtil.LongParse(CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SALE_FNSH_DT)) < CmUtil.LongParse(m_cPosStatus.Base.SaleDate))
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0011);            // 판매 불가 상품 입니다
                    return false;
                }

                cPluItem.SUB_SHOP_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SUB_STOR_CD);
                cPluItem.ITEM_PLU_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_CD);

                if (PosMstManager.GetPosOption(POS_OPTION.OPT005) == "0")
                {
                    cPluItem.SALE_PRC = CmUtil.GetDataRowDouble(drPlu, PosMst.MST_ITEM.DATA.TAKE_OUT_SALE_AMT);
                    cPluItem.TAXRATE_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_OUT_VAT_CD);
                }
                else
                {
                    cPluItem.SALE_PRC = CmUtil.GetDataRowDouble(drPlu, PosMst.MST_ITEM.DATA.TAKE_IN_SALE_AMT);
                    cPluItem.TAXRATE_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_IN_VAT_CD);
                }

                cPluItem.ITEM_TAKE_IN_VAT_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_IN_VAT_CD);
                cPluItem.ITEM_TAKE_OUT_VAT_CD = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.TAKE_OUT_VAT_CD);

                cPluItem.FLAVOUR_DIV = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_DIV);
                cPluItem.FLAVOUR_QTY = CmUtil.GetDataRowLong(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_QTY);
                cPluItem.FLAVOUR_STOCK = CmUtil.GetDataRowDouble(drPlu, PosMst.MST_ITEM.DATA.FLAVOUR_STOCK);
                cPluItem.ITEM_TAX_DIV = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_TAX_AMT_DIV);
                cPluItem.SUB_SET_MNG_TYPE = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SUB_SET_MNG_TYPE);
                cPluItem.ITEM_NAME = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SHTCUT_ITEMNM);
                
                cPluItem.FREE_GIFT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.FREE_GIFT_YN);
                cPluItem.DC_PRMT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.DC_PRMT_YN);
                cPluItem.ACCUM_PRMT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ACCUM_PRMT_YN);
                cPluItem.SVC_FEE_TRGT_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.SVC_FEE_TRGT_YN);
                cPluItem.COOP_CARD_DC_NOADM_YN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.COOP_CARD_DC_NOADM_YN);
                cPluItem.L_CLSS = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.L_CLSS);
                cPluItem.M_CLSS = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.M_CLSS);
                cPluItem.S_CLSS = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.S_CLSS);

                //#15746 해피오더 '쇼킹박스' 관련 POS 시스템 개발 요청 start

                cPluItem.ITEM_INFO = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_INFO); // 영양성분 
                cPluItem.ITEM_EXPLN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ITEM_EXPLN); // 상품설명 
                cPluItem.ALLERGY = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.ALLERGY); // 알레르기성분 
                cPluItem.PLACE_ORIGIN = CmUtil.GetDataRowStr(drPlu, PosMst.MST_ITEM.DATA.PLACE_ORIGIN); // 원산지

                //#15746 해피오더 '쇼킹박스' 관련 POS 시스템 개발 요청 end

                return true;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return false;
        }

        /// <summary>
        /// 상품 판매가 재계산
        /// </summary>
        public string ItemAmountExeccute(bool bEvtExec, bool bTaxExec)
        {
            string sRet = UserCom.RST_ERR;

            try
            {
                // 단가, 수량 반영 ==> 상품 판매가 재설정(수량,단가,할인,행사)
                foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
                {
                    m_cDataService.UpdatePluItemAmount(cPluItem);
                }
                // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePluAmount();

                if (bEvtExec == true)
                {
                    //정상 거래 와 예약 등록 거래시만 체크!
                    if (m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.NORMAL.SALE || m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.UNDECIDED.RESERVATION_REG)
                    {
                        // 상품 행사 처리
                        double dcAmt = m_cCampaingMain.RegisterCampaignPlu(true);
                        // 캠페인 반영 ==> 상품 판매가 재설정(수량,단가,할인,행사)
                        foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
                        {
                            m_cDataService.UpdatePluItemAmount(cPluItem);
                        }
                        // 상품 합계금액 계산(거래해더)
                        m_cDataService.UpdatePluAmount();
                    }
                }

                if (bTaxExec == true)
                {
                    // 세금 계산 처리
                    m_cDataService.ItemVatProc();
                    
                    // 상품 판매가 재설정(수량,단가,할인,행사)
                    foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
                    {
                        m_cDataService.UpdatePluItemAmount(cPluItem);
                    }
                    // 상품 합계금액 계산(거래해더)
                    m_cDataService.UpdatePluAmount();
                }

                //#16569 파스쿠찌 드라이브 스루 기능 개발 요청 start
                //DMBIF 사용, PAS DT 사용, 후불, 정상매출만 처리
                //if (m_cPosStatus.Base.DmbIf == "1" &&
                //    PosMstManager.GetPosOption(POS_OPTION.OPT554) == "1" &&
                //    m_cPosStatus.Base.PosType == PosConst.POS_TYPE.DEFERRED_PAYMENT &&
                //    m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL &&
                //    m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.NORMAL.SALE &&
                //    m_cPosStatus.Sale.EtcOperateMode == PosConst.ETC_OPERATION_MODE.NORMAL)
                //{
                //    //상품등록 대기, 상품등록 중, 세트메뉴 등록 중, 강제부가메뉴 등록 중, 세트메뉴 하위 강제부가메뉴 등록 중
                //    if (m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_WAIT ||
                //        m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING ||
                //        m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING_SET ||
                //        m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING_OPT ||
                //        m_cPosStatus.Sale.SaleFlow == PosConst.SALE_FLOW.SALE_DOING_SET_OPT)
                //    {
                //        // 디지털메뉴보드 I/F
                //        IDataServiceUs cDigitalMenuBoard = (IDataServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.DMB_IF);

                //        // 판매완료 
                //        cDigitalMenuBoard.Execute(new string[] { ItemConst.DT_IRT_ID.PRODUCT_REG });
                //    }

                //}
                //#16569 파스쿠찌 드라이브 스루 기능 개발 요청 end

                sRet = UserCom.RST_OK;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }

        //#20171207 유통기한 바코드 CHECK DIGIT 체크 기능 start
        //계산방법(12자리로 계산)
        //1. 우측부터 홀수위치 숫자 SUM
        //2. 1단계의 값에 3을 곱한다
        //3. 우측부터 짝수위치 숫자 SUM
        //4. 2단계결과 + 3단계결과
        //5. 4단계결과 값에 임의의 값을 더해 다음 10단위 숫자를 만든다.
        //6. 5단계에서 더한 임의의 값이 CHECK DIGIT 값.
        /// <summary>
        /// 유통기한 바코드 CHECK DIGIT 체크
        /// </summary>
        public string TimeStampBarCode_CheckDigit(string sBarCd)
        {
            string sRet = "";

            try
            {
                //ex) "2100131712099";

                // Test string for correct length
                if (sBarCd.Length != 13) return sRet;

                // Test string for being numeric
                for (int i = 0; i < sBarCd.Length; i++)
                {
                    if (sBarCd[i] < 0x30 || sBarCd[i] > 0x39) return sRet;
                }

                int sum = 0;

                for (int ii = 11; ii >= 0; ii--)
                {
                    int digit = sBarCd[ii] - 0x30;
                    if ((ii & 0x01) == 1)
                        sum += digit * 3;
                    else
                        sum += digit;
                }

                int mod = sum % 10;
                int iRet = mod == 0 ? 0 : 10 - mod;
                sRet = iRet.ToString();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }
        //#20171207 유통기한 바코드 CHECK DIGIT 체크 기능 end

        ///// <summary>
        ///// 상품 부가세 계산 처리
        ///// </summary>
        ///// <returns></returns>
        //private bool ItemVatProc()
        //{
        //    bool bRet = false;

        //    try
        //    {

        //        double dItemTakeInSum = 0;      //부가세 TakeIn 대상 금액에 합
        //        double dItemTakeOutSum = 0;     //부가세 TakeOut대상 금액에 합

        //        double dTaxTakeInSum = 0;       //합 TakeIn 부가세 금액
        //        double dTaxTakeOutSum = 0;      //합 TakeOut부가세 금액

        //        double dTaxTakeInSumAppy = 0;   //적용한 TakeIn 부가세 금액 
        //        double dTaxTakeOutSumAppy = 0;  //적용한 TakeOut부가세 금액 
                
        //        double dTakeInRate = 0;         //TakeIn 부가세 율
        //        double dTakeOutRate = 0;        //TakeOut 부가세 율
                
        //        //1. 부가세 계산 방식 체크(아이템SUM or 거래합계 배분)
        //        if(m_cPosStatus.Mst.TaxAmtCalcMethd == ItemConst.TAX_AMT_CALC_METHD.BILL)
        //        {

        //            //거래 합계 후 아이템 분배


        //            //거래 금액 합 
        //            foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
        //            {

        //                if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
        //                {
        //                    //면세 체크
        //                    if (cPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX)
        //                    {
        //                        if (cPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN)
        //                            dItemTakeInSum = CmUtil.DoubleAdd(dItemTakeInSum, cPluItem.SALE_AMT - cPluItem.TOT_DC_AMT);
        //                        else
        //                            dItemTakeOutSum = CmUtil.DoubleAdd(dItemTakeOutSum, cPluItem.SALE_AMT - cPluItem.TOT_DC_AMT);
        //                    }
        //                    else
        //                    {
        //                        cPluItem.APPLY_TAX_AMT = 0;
        //                    }
        //                }
        //            }

        //            if (dItemTakeInSum > 0 || dItemTakeOutSum > 0)
        //            {
        //                //부가세 코드로 율 가져오기
        //                DataTable dt = m_cDataCommon.SeletCommonCode(PosConst.COMMON_CODE_GROUP.M0101, "");
                        
        //                if (dt == null || dt.Rows.Count == 0)
        //                {
        //                    //부가세 값 없음!! - ERR!
        //                }
        //                else
        //                {

        //                    //foreach(DataRow dr in dt.Rows)
        //                    //{
        //                    //    if(CmUtil.GetDataRowStr(dr,PosMst.MST_COMMON.DATA.CMM_CD) == m_cPosStatus.Mst.BasicTakeInTaxCd)
        //                    //    {
        //                    //        dTakeInRate = CmUtil.GetDataRowDouble(dr, PosMst.MST_COMMON.DATA.NUM_VAL_TITLE_VAL_01);
        //                    //    }
        //                    //    if(CmUtil.GetDataRowStr(dr,PosMst.MST_COMMON.DATA.CMM_CD) == m_cPosStatus.Mst.BasicTakeOutTaxCd)
        //                    //    {
        //                    //        dTakeOutRate = CmUtil.GetDataRowDouble(dr, PosMst.MST_COMMON.DATA.NUM_VAL_TITLE_VAL_01);
        //                    //    }

        //                    //    if (dTakeInRate > 0 && dTakeOutRate > 0)
        //                    //        break;

        //                    //}

        //                    DataRow[] adr = null;

        //                    adr = dt.Select(" " + PosMst.MST_COMMON.DATA.CMM_CD + " = '" + m_cPosStatus.Mst.BasicTakeInTaxCd + "'");
        //                    dTakeInRate = CmUtil.GetDataRowDouble(adr[0], PosMst.MST_COMMON.DATA.NUM_VAL_TITLE_VAL_01);

        //                    adr = dt.Select(" " + PosMst.MST_COMMON.DATA.CMM_CD + " = '" + m_cPosStatus.Mst.BasicTakeOutTaxCd + "'");
        //                    dTakeOutRate = CmUtil.GetDataRowDouble(adr[0], PosMst.MST_COMMON.DATA.NUM_VAL_TITLE_VAL_01);

        //                    //전체 부가세 계산
        //                    if(dItemTakeInSum > 0)
        //                    {
        //                        dTaxTakeInSum = dItemTakeInSum - (dItemTakeInSum / (1 + (dTakeInRate / 100)));
        //                        dTaxTakeInSum = CmUtil.MathRounds(dTaxTakeInSum, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
        //                    }

        //                    if (dItemTakeOutSum > 0)
        //                    {
        //                        dTaxTakeOutSum = dItemTakeOutSum - (dItemTakeOutSum / (1 + (dTakeOutRate / 100)));
        //                        dTaxTakeOutSum = CmUtil.MathRounds(dTaxTakeOutSum, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));

        //                    }

        //                    double dItemTaxRate;
        //                    double dItemTaxAmt;


        //                    //아이템 배분 처리
        //                    foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
        //                    {
                                
        //                        if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
        //                        {

        //                            dItemTaxRate = 0;
        //                            dItemTaxAmt = 0;


        //                            //면세 체크
        //                            if (cPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX && cPluItem.BILL_AMT > 0)
        //                            {
        //                                if(cPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN)
        //                                {
        //                                    dItemTaxRate = CmUtil.DoubleMultiplication(CmUtil.DoubleDivision(cPluItem.SALE_AMT - cPluItem.TOT_DC_AMT, dItemTakeInSum), 100);

        //                                    dItemTaxAmt = CmUtil.DoubleDivision(dTaxTakeOutSum, CmUtil.DoubleDivision(100, dItemTaxRate));

        //                                    cPluItem.APPLY_TAX_AMT = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                                            
                                            
        //                                    dTaxTakeInSumAppy = CmUtil.DoubleAdd(dTaxTakeInSumAppy, cPluItem.APPLY_TAX_AMT);
        //                                }
        //                                else
        //                                {
        //                                    dItemTaxRate = CmUtil.DoubleMultiplication(CmUtil.DoubleDivision(cPluItem.SALE_AMT - cPluItem.TOT_DC_AMT, dItemTakeOutSum), 100);
        //                                    dItemTaxAmt = CmUtil.DoubleDivision(dTaxTakeOutSum,CmUtil.DoubleDivision(100, dItemTaxRate));
        //                                    cPluItem.APPLY_TAX_AMT = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                                                                                        
        //                                    dTaxTakeOutSumAppy = CmUtil.DoubleAdd(dTaxTakeOutSumAppy, cPluItem.APPLY_TAX_AMT);

        //                                }

        //                            }
        //                        }

        //                    }


        //                    //짜투리 금액 계산 Take In
        //                    if (dTaxTakeInSum != dTaxTakeInSumAppy)
        //                    {
        //                        for (int iRow = m_alTrPluItem.Count - 1; iRow >= 0; iRow--)
        //                        {
        //                            Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)m_alTrPluItem[iRow];

        //                            if (tmpPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && tmpPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
        //                            {
        //                                //면세 체크
        //                                if (tmpPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX
        //                                    && tmpPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN && tmpPluItem.BILL_AMT > 0)
        //                                {
        //                                    tmpPluItem.APPLY_TAX_AMT = CmUtil.DoubleAdd(tmpPluItem.APPLY_TAX_AMT, dTaxTakeInSum - dTaxTakeInSumAppy);
        //                                    break;
        //                                }
        //                            }

        //                        }
        //                    }

        //                    //짜투리 금액 계산 Take Out
        //                    if (dTaxTakeOutSum != dTaxTakeOutSumAppy)
        //                    {
        //                        for (int iRow = m_alTrPluItem.Count - 1; iRow >= 0; iRow--)
        //                        {
        //                            Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)m_alTrPluItem[iRow];

        //                            if (tmpPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && tmpPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
        //                            {
        //                                //면세 체크
        //                                if (tmpPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX
        //                                    && tmpPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_OUT && tmpPluItem.BILL_AMT > 0)
        //                                {
        //                                    tmpPluItem.APPLY_TAX_AMT = CmUtil.DoubleAdd(tmpPluItem.APPLY_TAX_AMT, dTaxTakeOutSum - dTaxTakeOutSumAppy);
        //                                    break;
        //                                }
        //                            }

        //                        }
        //                    }


        //                }

        //            }
        //        }
        //        else
        //        {

        //            //아이템 계산 후 합계 적용


        //            //부가세 코드로 율 가져오기
        //            DataTable dt = m_cDataCommon.SeletCommonCode(PosConst.COMMON_CODE_GROUP.M0101, "");

        //            if (dt == null || dt.Rows.Count == 0)
        //            {
        //                //부가세 값 없음!! - ERR!
        //            }
        //            else
        //            {

        //                DataRow[] adr = null;
                        
        //                adr = dt.Select(" " + PosMst.MST_COMMON.DATA.CMM_CD + " = '" + m_cPosStatus.Mst.BasicTakeInTaxCd + "'");
        //                if( adr.Length > 0) dTakeInRate = CmUtil.GetDataRowDouble(adr[0], PosMst.MST_COMMON.DATA.NUM_VAL_TITLE_VAL_01);
                        
        //                adr = dt.Select(" " + PosMst.MST_COMMON.DATA.CMM_CD + " = '" + m_cPosStatus.Mst.BasicTakeOutTaxCd + "'");
        //                if (adr.Length > 0) dTakeOutRate = CmUtil.GetDataRowDouble(adr[0], PosMst.MST_COMMON.DATA.NUM_VAL_TITLE_VAL_01);


        //                double dItemTaxAmt;
        //                double dTargetAmt;

        //                //상품 낱개별 처리후 거래합 적용
        //                foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
        //                {

        //                    dItemTaxAmt = 0;
        //                    dTargetAmt = 0;

        //                    if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
        //                    {
        //                        //면세 체크
        //                        if (cPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX && cPluItem.BILL_AMT > 0)
        //                        {
        //                            dTargetAmt = cPluItem.SALE_AMT - cPluItem.TOT_DC_AMT;
                                    
        //                            double dTaxRate = 0;

        //                            if(m_cPosStatus.Mst.TaxAmtApplydiv == ItemConst.TAX_AMT_APPLY_DIV.BASIC_TAX_APPY)
        //                            {
        //                                if (cPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN)
        //                                {
        //                                    dTaxRate = dTakeInRate;
        //                                }
        //                                else
        //                                {
        //                                    dTaxRate = dTakeOutRate;
        //                                }
        //                            }
        //                            else
        //                            {
        //                                adr = dt.Select(" " + PosMst.MST_COMMON.DATA.CMM_CD + " = '" + cPluItem.TAXRATE_CD + "'");
        //                                dTaxRate = CmUtil.GetDataRowDouble(adr[0], PosMst.MST_COMMON.DATA.NUM_VAL_TITLE_VAL_01);
        //                            }

        //                            dItemTaxAmt = dTargetAmt - (dTargetAmt / (1 + (dTaxRate / 100)));
        //                            dItemTaxAmt = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
        //                            cPluItem.APPLY_TAX_AMT = dItemTaxAmt;

        //                        }
        //                        else
        //                        {
        //                            cPluItem.APPLY_TAX_AMT = 0;
        //                        }
        //                    }
        //                }
        //            }

        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
        //            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                
        //    }
        //    return bRet;

        //}

        #region SearchMenuMaster 메뉴 구성 마스터 조회
        /// <summary>
        /// 메뉴키 마스터 조회
        /// </summary>
        /// <param name="sMstName"></param>
        /// <returns></returns>
        public DataTable SearchMenuMaster(string sMstName)
        {
            return SearchMenuMaster(sMstName, "", "");
        }
        /// <summary>
        /// 메뉴 구성 마스터 조회
        /// </summary>
        /// <param name="sMstName"></param>
        /// <returns></returns>
        public DataTable SearchMenuMaster(string sMstName, string sPara1, string sPara2)
        {
            string sQuery = "";
            try
            {
                if (sMstName == PosMst.MST_ITEM_KEY_COMPNT.TABLE_NAME)
                {
                    // 상품키 구성 마스터
                    sQuery += " SELECT * FROM POSMST..MST_ITEM_KEY_COMPNT ";
                    sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    //sQuery += "   AND POS_SCRN_TYPE = '" + m_cPosStatus.Base.DesignType + "'";
                    sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                }
                else if (sMstName == PosMst.MST_ITEM_KEY_L_CLSS.TABLE_NAME)
                {
                    // 상품키 대분류
                    if (m_cPosStatus.Mst.ComplexShopType == "2")  // 0:단독매장,1:복합매장구성점포,2:복합매장점포
                    {
                        sQuery += " SELECT A.*, B.DISP_SEQ, B.COMPLEX_SHOP_STOR_NM FROM POSMST..MST_ITEM_KEY_L_CLSS A ";
                        sQuery += "  JOIN POSMST..MST_COMPLEX_SHOP_STOR B ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.SUB_SHOP_CD=B.COMPLEX_SHOP_STOR_CD ";
                        sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                        sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                        sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                        sQuery += " ORDER BY A.SEQ, B.DISP_SEQ, A.SUB_SHOP_CD ";
                    }
                    else
                    {
                        sQuery += " SELECT * FROM POSMST..MST_ITEM_KEY_L_CLSS ";
                        sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                        sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                        sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                        sQuery += " ORDER BY SEQ ";
                    }
                }
                else if (sMstName == PosMst.MST_ITEM_KEY_CLSS.TABLE_NAME)
                {
                    // 상품키 중분류
                    sQuery += " SELECT * FROM POSMST..MST_ITEM_KEY_CLSS A ";
                    sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY A.SUB_STOR_CD,A.L_CLSS_CD, A.FIX_YN, A.GRP_SEQ ";
                }
                else if (sMstName == PosMst.MST_ITEM_KEY.TABLE_NAME)
                {
                    // 상품키 메뉴버튼
                    //
                    //#20171206 대표상품코드 없는 경우 상품코드로 이미지 표시 start
                    //기존
                    //sQuery += " SELECT A.*, B.SHTCUT_ITEMNM, B.TAKE_IN_SALE_AMT, B.TAKE_OUT_SALE_AMT, B.BTN_ITEM_IMG ,B.RPST_ITEM_CD";
                    //변경
                    sQuery += " SELECT A.*, B.SHTCUT_ITEMNM, B.TAKE_IN_SALE_AMT, B.TAKE_OUT_SALE_AMT, B.BTN_ITEM_IMG";
                    sQuery += "       , (CASE WHEN B.RPST_ITEM_CD IS NULL THEN A.ITEM_CD ELSE (CASE WHEN B.RPST_ITEM_CD = '' THEN A.ITEM_CD ELSE B.RPST_ITEM_CD END) END) RPST_ITEM_CD ";
                    //#20171206 대표상품코드 없는 경우 상품코드로 이미지 표시 end
                    sQuery += " FROM POSMST..MST_ITEM_KEY A ";
                    sQuery += "    JOIN POSMST..MST_ITEM B ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.SUB_STOR_CD = B.SUB_STOR_CD AND A.ITEM_CD = B.ITEM_CD";
                    sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY A.L_CLSS_CD, A.FIX_YN, A.GRP_SEQ, A.SEQ";

                }
                else if (sMstName == PosMst.MST_BOOKMK.TABLE_NAME)
                {
                    // 상품키 즐겨찾기
                    sQuery += " SELECT A.*, B.SHTCUT_ITEMNM, B.TAKE_IN_SALE_AMT, B.TAKE_OUT_SALE_AMT, B.BTN_ITEM_IMG ";
                    sQuery += " FROM POSMST..MST_BOOKMK A ";
                    sQuery += "    JOIN POSMST..MST_ITEM B ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.SUB_STOR_CD = B.SUB_STOR_CD AND A.ITEM_CD = B.ITEM_CD";
                    sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY A.SEQ ";
                }
                else if (sMstName == PosMst.MST_FUNC_KEY_GRP.TABLE_NAME)
                {
                    // 기능키 그룹
                    return m_cDataCommon.SeletFuncKeyGroup("");
                }
                else if (sMstName == PosMst.MST_SUBPRC_MENU.TABLE_NAME)
                {
                    // 부가메뉴 그룹
                    sQuery += " SELECT * FROM POSMST..MST_SUBPRC_MENU ";
                    sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND SUB_STOR_CD = '" + sPara1 + "'";
                    sQuery += "   AND M_CLSS = '" + sPara2 + "'";
                    //sQuery += "   AND ITEM_CD = '" + sPara2 + "'";
                    sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY SEQ_NO ";
                }
                else if (sMstName == PosMst.MST_SUBPRC_MENU_GRP.TABLE_NAME)
                {
                    // 부가메뉴 그룹 상세
                    sQuery += " SELECT B.*, ISNULL(C.TAKE_OUT_SALE_AMT, 0) TAKE_OUT_SALE_AMT, ISNULL(C.TAKE_IN_SALE_AMT, 0) TAKE_IN_SALE_AMT, ISNULL(C.SHTCUT_ITEMNM,'') SHTCUT_ITEMNM ";
                    sQuery += " FROM POSMST..MST_SUBPRC_MENU A  ";
                    sQuery += "  JOIN POSMST..MST_SUBPRC_MENU_GRP B ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.SUB_STOR_CD = B.SUB_STOR_CD AND A.SUBPRC_MENU_GRP_CD = B.SUBPRC_MENU_GRP_CD  ";
                    sQuery += "  LEFT JOIN POSMST..MST_ITEM C ON B.CMP_CD=C.CMP_CD AND B.STOR_CD=C.STOR_CD AND B.SUB_STOR_CD = C.SUB_STOR_CD AND B.SUBPRC_MENU_KEY_VAL = C.ITEM_CD";
                    sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND A.SUB_STOR_CD = '" + sPara1 + "'";
                    sQuery += "   AND A.M_CLSS = '" + sPara2 + "'";
                    //sQuery += "   AND A.ITEM_CD = '" + sPara2 + "'";
                    sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY B.SUBPRC_MENU_GRP_CD, B.SEQ_NO ";
                }
                else if (sMstName == PosMst.MST_ITEM_SET.TABLE_NAME)
                {
                    // 세트메뉴 그룹
                    sQuery += " SELECT * FROM POSMST..MST_ITEM_SET ";
                    sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND SUB_STOR_CD = '" + sPara1 + "'";
                    sQuery += "   AND ITEM_CD = '" + sPara2 + "'";
                    sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY SEQ_NO ";
                }
                else if (sMstName == PosMst.MST_ITEM_SET_GRP.TABLE_NAME)
                {
                    // 세트메뉴 그룹 상세
                    sQuery += " SELECT B.* , ISNULL(C.SHTCUT_ITEMNM,'') SHTCUT_ITEMNM ";
                    sQuery += " FROM POSMST..MST_ITEM_SET A  ";
                    sQuery += "   JOIN POSMST..MST_ITEM_SET_GRP B ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.SUB_STOR_CD = B.SUB_STOR_CD AND A.SET_ITEM_CD = B.SET_ITEM_GRP_CD  ";
                    sQuery += "   JOIN POSMST..MST_ITEM C ON B.CMP_CD=C.CMP_CD AND B.STOR_CD=C.STOR_CD AND B.SUB_STOR_CD = C.SUB_STOR_CD AND B.SET_ITEM_CD = C.ITEM_CD";
                    sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND A.SUB_STOR_CD = '" + sPara1 + "'";
                    sQuery += "   AND A.ITEM_CD = '" + sPara2 + "'";
                    sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY B.SET_ITEM_GRP_CD, B.SEQ_NO ";
                }
                else if (sMstName == PosMst.MST_FLAVOUR.TABLE_NAME)
                {
                    // 플레이버
                    sQuery += " SELECT A.*, B.SHTCUT_ITEMNM, B.BTN_ITEM_IMG  FROM POSMST..MST_FLAVOUR A  ";
                    sQuery += " JOIN POSMST..MST_ITEM B ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.SUB_STOR_CD = B.SUB_STOR_CD AND A.ITEM_CD = B.ITEM_CD  ";
                    sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND A.SUB_STOR_CD = '" + sPara1 + "'";
                    sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY A.ITEM_LOC ";
                }

                else if (sMstName == PosMst.MST_GIFT_PREPAID.TABLE_NAME_GIFT || sMstName == PosMst.MST_GIFT_PREPAID.TABLE_NAME_PREPAID)
                {
                    // 상품권,선불카드
                    sQuery += " SELECT * FROM POSMST..MST_ITEM ";
                    sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    if (sPara1 != "")
                    {
                        sQuery += "   AND SUB_STOR_CD = '" + sPara1 + "'";
                    }
                    if (sMstName == PosMst.MST_GIFT_PREPAID.TABLE_NAME_GIFT)
                        sQuery += "   AND ITEM_TYPE = '" + PosConst.ITEM_TYPE.GIFT + "'";
                    else
                        sQuery += "   AND ITEM_TYPE = '" + PosConst.ITEM_TYPE.PREPAID + "'";
                    sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                }
                else if (sMstName == PosMst.MST_PLU_NM.TABLE_NAME)
                {
                    sQuery += " SELECT CMP_CD ";
                    sQuery += " ,STOR_CD ";
                    sQuery += " ,KEY_MODE ";
                    sQuery += " ,PLU_SEQ ";
                    sQuery += " ,PLU_NM ";
                    sQuery += " ,P_POSITION ";
                    sQuery += " ,PLU_1_FR ";
                    sQuery += " ,PLU_1_TO ";
                    sQuery += " ,PLU_2_FR ";
                    sQuery += " ,PLU_2_TO ";
                    sQuery += " ,PLU_3_FR ";
                    sQuery += " ,PLU_3_TO ";
                    sQuery += " ,USE_YN ";
                    sQuery += " FROM POSMST.dbo.MST_PLU_NM ";
                    sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                }
                else if (sMstName == PosMst.MST_PLU_AMT.TABLE_NAME)
                {
                    sQuery += " SELECT CMP_CD ";
                    sQuery += " ,STOR_CD ";
                    sQuery += " ,PLU_SEQ ";
                    sQuery += " ,PLU_AMT_NM ";
                    sQuery += " ,P_POSITION ";
                    sQuery += " ,FROM_AMT ";
                    sQuery += " ,TO_AMT ";
                    sQuery += " ,USE_YN ";
                    sQuery += " FROM POSMST.dbo.MST_PLU_AMT ";
                    sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                }
                else if (sMstName == PosMst.MST_ITEM_SEARCH.TABLE_NAME)
                {
                    sQuery += " SELECT ROW_NUMBER() OVER( ORDER BY A.ITEM_CD DESC) AS NO ";
                    sQuery +="       , A.ITEM_CD ";
                    sQuery += "      ,A.SHTCUT_ITEMNM AS ITEM_NM ";
                    //sQuery +="       ,A.ITEM_NM ";

                    if (PosMstManager.GetPosOption(POS_OPTION.OPT005) == "0")
                        sQuery += "       ,CONVERT(VARCHAR,A.TAKE_IN_SALE_AMT)  AS SALE_PRC";
                    else
                        sQuery += "       ,CONVERT(VARCHAR,A.TAKE_OUT_SALE_AMT) AS SALE_PRC";

                    sQuery += "      ,A.SUB_STOR_CD ";
                    sQuery += "      ,A.SUB_SET_MNG_TYPE ";
                    sQuery +="   FROM POSMST.dbo.MST_ITEM A ";

                    if (m_cPosStatus.Mst.CorpDiv == ItemConst.CORP_DIV.PC)  //PC일경우는 키에 등록된것만 보여져야함!
                    {
                        sQuery += "   INNER JOIN POSMST.dbo.MST_ITEM_KEY B ";
                        sQuery += "      ON A.CMP_CD     = B.CMP_CD ";
                        sQuery += "     AND A.STOR_CD    = B.STOR_CD ";
                        sQuery += "     AND A.SUB_STOR_CD= B.SUB_STOR_CD ";
                        sQuery += "     AND A.ITEM_CD    = B.ITEM_CD ";
                    }
                    
                    sQuery += "  WHERE A.CMP_CD       = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "    AND A.STOR_CD      = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "    AND A.SUB_STOR_CD  = '" + sPara1 + "' ";
                    sQuery += "    AND A.ITEM_TYPE NOT IN ('" + PosConst.ITEM_TYPE.GIFT + "','" + PosConst.ITEM_TYPE.PREPAID + "')";
                    sQuery += "    AND '" + m_cPosStatus.Base.SaleDate + "' BETWEEN A.SALE_START_DT AND A.SALE_FNSH_DT ";   //판매기간
                    sQuery += "    AND FREE_GIFT_YN   = '0' ";  //사은품 제외

                    if (sPara2 != "")
                        sQuery += sPara2;
                    
                    sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                }
                else if (sMstName == "MST_ITEM_SET_GRP_CHANGE")
                {
                    // 세트메뉴 그룹 상세(세트메뉴 변경 용)
                    sQuery += " SELECT B.* , ISNULL(C.SHTCUT_ITEMNM,'') SHTCUT_ITEMNM  FROM POSMST..MST_ITEM_SET_GRP B";
                    sQuery += "   JOIN POSMST..MST_ITEM C ON B.CMP_CD=C.CMP_CD AND B.STOR_CD=C.STOR_CD AND B.SUB_STOR_CD = C.SUB_STOR_CD AND B.SET_ITEM_CD = C.ITEM_CD";
                    sQuery += " WHERE B.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "   AND B.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "   AND B.SUB_STOR_CD = '" + sPara1 + "'";
                    sQuery += "   AND B.SET_ITEM_GRP_CD = '" + sPara2 + "'";
                    sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += " ORDER BY B.SEQ_NO ";
                }

                //#16577 결제창 내부 봉투 추가 기능 도입 start
                else if (sMstName == "MST_ITEM_ADD_BAG")
                {
                    // 봉투 상품 조회
                    sQuery += " SELECT TOP 8 A.DISP_SEQ SEQ, B.SUB_STOR_CD, B.ITEM_CD, B.RPST_ITEM_CD, ISNULL(B.SHTCUT_ITEMNM,'') SHTCUT_ITEMNM, ";
                    sQuery += "        B.TAKE_OUT_SALE_AMT, B.TAKE_IN_SALE_AMT";
                    sQuery += "   FROM POSMST..MST_CMM A INNER JOIN POSMST..MST_ITEM B ";
                    sQuery += "     ON A.CMP_CD = B.CMP_CD AND A.CHAR_VAL_TITLE_VAL_01 = B.ITEM_CD ";
                    sQuery += "  WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                    sQuery += "    AND A.CMM_GRP_CD = 'T0042'";
                    sQuery += "    AND A.SALES_ORG_CD = '" + m_cPosStatus.Base.BrandCd + "'";
                    sQuery += "    AND A.USE_YN = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += "    AND B.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                    sQuery += "    AND B.SUB_STOR_CD = '" + m_cPosStatus.Base.SubShopNo + "'";
                    sQuery += "    AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                    sQuery += "  ORDER BY A.DISP_SEQ ";
                }
                //#16577 결제창 내부 봉투 추가 기능 도입 end

                return m_cMstService.Select(new string[] { sQuery });
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return null;
        }

        /// <summary>
        /// 세브란스 아이템 체크
        /// </summary>
        /// <param name="sItemCd"></param>
        /// <param name="sPara1"></param>
        /// <param name="sPara2"></param>
        /// <returns></returns>
        public string SearchMenuMasterForSeverance(string sItemCd, string sPara1, string sPara2)
        {

            string sRet = "0";

            string sQuery = "";
            try
            {
                // 세브란스 메뉴 검색
                sQuery = "";
                sQuery += " SELECT * FROM POSMST.dbo.MST_TERM_COOP_CMP_DC_ITEM WITH(NOLOCK) ";
                sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                sQuery += "   AND PAY_DC_GRP_TYPE = '" + ItemConst.TR_ITEM_ID.EMP_PAY_ITEM + "'";
                sQuery += "   AND PAY_DC_CD = '" + ItemConst.TR_ITEM_ID.EMP_PAY.SEVERANCE + "'";
                sQuery += "   AND COOP_CMP_GRADE_CD  = 'SV'";
                sQuery += "   AND START_DT  <= '" + m_cPosStatus.Base.SaleDate + "'";
                sQuery += "   AND ITEM_CD  = '" + sItemCd + "'";
                sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                
                DataTable dt =  m_cMstService.Select(new string[] { sQuery });

                if (dt != null && dt.Rows.Count > 0)
                {
                    sRet = "1";
                }

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }

        #endregion

    }
}
