using System;
using System.Text;
using System.Collections;
using System.Data;
using System.IO;
using System.Threading;

using Cosmos.Common;
using Cosmos.CommonManager;
using Cosmos.BaseFrame;
using Cosmos.UserFrame;

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 캠페인 처리
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/ 
namespace Cosmos.Service
{
    class CampaignMain : CampaignBase , ICampaignUs
    {
        public CampaignMain()
            :base()
        {
        }

        /// <summary>
        /// 캠페인 조건 마스터 획득
        /// </summary>
        /// <returns></returns>
        public Hashtable GetCampaignCondition()
        {
            return m_htMstSaleCpi;
        }

        /// <summary>
        /// 캠페인 조건에서 캠페인명 획득
        /// </summary>
        /// <param name="sCpiCode">캠페인코드</param>
        /// <param name="nNameDiv">명종류(0:캠페인명, 1:영수증명, 2:수량제한명)</param>
        /// <returns></returns>
        public string GetCampaignName(string sCpiCode, int nNameDiv)
        {
            string sCpiName = "";
            try
            {
                Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                if (cMstSaleCpi != null)
                {
                    sCpiName = cMstSaleCpi.CPI_NM;
                    if ( nNameDiv == 1)         // 영수증명
                    {
                        if (cMstSaleCpi.CPI_BILL_NM.Trim() != "") sCpiName = cMstSaleCpi.CPI_BILL_NM;
                    }
                    else if (nNameDiv == 2)     // 수량제한명
                    {
                        if (cMstSaleCpi.QTY_LIMIT_MSG.Trim() != "") sCpiName = cMstSaleCpi.QTY_LIMIT_MSG;
                    }
                }
            }
            catch { }
            return sCpiName;
        }

        /// <summary>
        /// 캠페인 조건의 행사상품 합계금액 및 행사금액 초기화
        /// </summary>
        /// <returns></returns>
        public void ClearCampaignAmt()
        {
            CancelCampaignPayment(PosConst.CAMPAIGN_PAY_KEY.HP_SAVE, PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT_HP);   // HP 캠페인 할인 취소 처리(재계산)
            CancelCampaignPayment("", PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT);                                     // 사은품 캠페인 등록 취소
            ClearCampaginItem("");
        }

        #region LoadCampaignCondition 캠페인 조건 마스터 로드
        /// <summary>
        /// 캠페인 조건 마스터 로드
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public bool LoadCampaignCondition(string[] aParam)
        {
            string sQuery;
            try
            {
                m_htMstSaleCpi.Clear();
                m_alMstSaleCpi.Clear();

                //UserLog.WriteLogFile(UserCom.LOG_ERROR, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                //        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "START");

                // 캠페인 마스터
                sQuery = " SELECT * FROM POSMST..MST_CPI WITH(NOLOCK) ";
                sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                sQuery += "   AND '" + m_cTrnStatus.Head.SysYmd + "' BETWEEN STARTDAY AND FNSHDAY ";
                sQuery += "   AND PRGRS_STATUS = 'C'";
                sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += " ORDER BY PRRTY, STARTDAY DESC, CPI_CD DESC ";
                
                DataTable dtMstCpi =  m_cMstService.Select(new string[] { sQuery });
                if (dtMstCpi != null && dtMstCpi.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtMstCpi.Rows)
                    {
                        // 행사기간 체크
                        //if (CmUtil.GetDataRowLong(dr, PosMst.MST_CPI.DATA.STARTDAY) > CmUtil.LongParse(m_cTrnStatus.Head.SysYmd) || CmUtil.GetDataRowLong(dr, PosMst.MST_CPI.DATA.FNSHDAY) < CmUtil.LongParse(m_cTrnStatus.Head.SysYmd)) continue;

                        // 캠페인 조건정보 생성
                        Column.MST_SALE_CPI.DATA cMstSaleCpi = new Column.MST_SALE_CPI.DATA();
                        cMstSaleCpi.CPI_CD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CPI_CD);
                        cMstSaleCpi.CPI_NM = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CPI_NM);
                        cMstSaleCpi.STARTDAY = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.STARTDAY);
                        cMstSaleCpi.FNSHDAY = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.FNSHDAY);
                        if (CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.REPT_YN) != "1")
                            cMstSaleCpi.REPT_APPNT_TYPE = "0";
                        else
                            cMstSaleCpi.REPT_APPNT_TYPE = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.REPT_APPNT_TYPE);
                        cMstSaleCpi.REPT_WEEK = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.REPT_WEEK);
                        cMstSaleCpi.REPT_DT = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.REPT_DT);
                        cMstSaleCpi.DUP_APPLY_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.DUP_APPLY_YN);
                        cMstSaleCpi.BASIC_RULE_EXCEP_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.BASIC_RULE_EXCEP_YN);
                        cMstSaleCpi.TELECOM_COOP_DUP_PRMT_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.TELECOM_COOP_DUP_PRMT_YN);

                        //#15583 캠페인 기능 개선 요청 start
                        if (cMstSaleCpi.TELECOM_COOP_DUP_PRMT_YN == "") cMstSaleCpi.TELECOM_COOP_DUP_PRMT_YN = "0";

                        cMstSaleCpi.MOBILE_CPN_DUP_PRMT_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.MOBILE_CPN_DUP_PRMT_YN);
                        cMstSaleCpi.HPY_CPN_DUP_PRMT_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.HPY_CPN_DUP_PRMT_YN);
                        //#15583 캠페인 기능 개선 요청 end

                        //cMstSaleCpi.CPNDC_GRP_DUP_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CPNDC_GRP_DUP_YN);
                        //cMstSaleCpi.GNRL_DC_GRP_DUP_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.GNRL_DC_GRP_DUP_YN);
                        cMstSaleCpi.TRGT_CUST_TYPE = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.TRGT_CUST_TYPE);
                        cMstSaleCpi.CPI_CUST_BNFT_TYPE = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CPI_CUST_BNFT_TYPE);
                        cMstSaleCpi.ITEM_APPLY_METHD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.ITEM_APPLY_METHD);
                        cMstSaleCpi.CUST_PAY_TYPE = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CUST_PAY_TYPE);
                        cMstSaleCpi.TRGT_AMT_TYPE = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.TRGT_AMT_TYPE);
                        cMstSaleCpi.TRGT_AMT = CmUtil.GetDataRowDouble(dr, PosMst.MST_CPI.DATA.TRGT_AMT);
                        if (CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.QTY_LMT_YN) != "1")
                            cMstSaleCpi.LMT_QTY = 0;
                        else
                            cMstSaleCpi.LMT_QTY = CmUtil.GetDataRowLong(dr, PosMst.MST_CPI.DATA.LMT_QTY);
                        cMstSaleCpi.QTY_LMT_STD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.QTY_LMT_STD);
                        if (CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.HP_CUST_JOIN_LMT_YN) != "1")
                            cMstSaleCpi.HP_CUST_MAX_JOIN_CNT = 0;
                        else
                            cMstSaleCpi.HP_CUST_MAX_JOIN_CNT = CmUtil.GetDataRowLong(dr, PosMst.MST_CPI.DATA.HP_CUST_MAX_JOIN_CNT);
                        cMstSaleCpi.HP_CUST_JOIN_LMT_STD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.HP_CUST_JOIN_LMT_STD);

                        cMstSaleCpi.BASIC_HP_ACCUM_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.BASIC_HP_ACCUM_YN);
                        cMstSaleCpi.BASIC_HP_ACCUM_STD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.BASIC_HP_ACCUM_STD);
                        cMstSaleCpi.ADD_HP_ACCUM_TELECOM_DIV = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.ADD_HP_ACCUM_TELECOM_DIV);
                        cMstSaleCpi.ADD_HP_ACCUM_TRGT_STD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.ADD_HP_ACCUM_TRGT_STD);
                        cMstSaleCpi.ADD_HP_ACCUM_RATE = CmUtil.GetDataRowDouble(dr, PosMst.MST_CPI.DATA.ADD_HP_ACCUM_RATE);
                        cMstSaleCpi.ADD_HP_ACCUM_AF_DIV = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.ADD_HP_ACCUM_AF_DIV);
                        cMstSaleCpi.ADD_HP_ACCUM_CD1 = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.ADD_HP_ACCUM_CD1);
                        cMstSaleCpi.ADD_HP_ACCUM_CD2 = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.ADD_HP_ACCUM_CD2);
                        cMstSaleCpi.OFFER_ID = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.OFFER_ID);
                        cMstSaleCpi.FREE_GIFT_PROVD_STD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.FREE_GIFT_PROVD_STD);
                        cMstSaleCpi.FREE_GIFT_STD_AMT = CmUtil.GetDataRowDouble(dr, PosMst.MST_CPI.DATA.FREE_GIFT_STD_AMT);
                        cMstSaleCpi.FREE_GIFT_PROVD_QTY = CmUtil.GetDataRowLong(dr, PosMst.MST_CPI.DATA.FREE_GIFT_PROVD_QTY);
                        cMstSaleCpi.FREE_GIFT_ADD_SALE_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.FREE_GIFT_ADD_SALE_YN);
                        cMstSaleCpi.CPI_EXPLN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CPI_EXPLN);
                        cMstSaleCpi.CUST_DSP_FILE_DIV = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CUST_DSP_FILE_DIV);
                        cMstSaleCpi.CUST_DSP_FILENM = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CUST_DSP_FILENM);

                        cMstSaleCpi.STAMP_QTY = CmUtil.GetDataRowLong(dr, PosMst.MST_CPI.DATA.STAMP_QTY);
                        cMstSaleCpi.SOUND_FILE_DIV = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.SOUND_FILE_DIV);
                        cMstSaleCpi.SOUND_FILE_NM = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.SOUND_FILE_NM);
                        cMstSaleCpi.TTS_DSCRP = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.TTS_DSCRP);
                        cMstSaleCpi.SOUND_FILE_PLAY_CHK_PNT = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.SOUND_FILE_PLAY_CHK_PNT);

                        cMstSaleCpi.JOIN_QUSTN_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.JOIN_QUSTN_YN);
                        cMstSaleCpi.ITEM_DUP_PRMT_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.ITEM_DUP_PRMT_YN);
                        cMstSaleCpi.LTTR_MULTI_PRT_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.LTTR_MULTI_PRT_YN);
                        cMstSaleCpi.CPI_DC_PAY_WAY = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CPI_DC_PAY_WAY);

                        cMstSaleCpi.CPI_BILL_NM = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.CPI_BILL_NM);
                        cMstSaleCpi.QTY_LIMIT_MSG = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.QTY_LIMIT_MSG);

                        cMstSaleCpi.HP_CUST_LVL = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.HP_CUST_LVL);
                        cMstSaleCpi.DC_NOADM_PASS_YN = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI.DATA.DC_NOADM_PASS_YN);

                        m_htMstSaleCpi.Add(cMstSaleCpi.CPI_CD, cMstSaleCpi);
                        m_alMstSaleCpi.Add(cMstSaleCpi.CPI_CD);
                    }
                }

                // 캠페인 시간 마스터
                sQuery = " SELECT A.* FROM POSMST..MST_CPI_HOUR A WITH(NOLOCK) ";
                sQuery += "   JOIN POSMST..MST_CPI B WITH(NOLOCK) ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.CPI_CD=B.CPI_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 '" + m_cTrnStatus.Head.SysYmd + "' BETWEEN B.STARTDAY AND B.FNSHDAY ";
                sQuery += "   AND B.PRGRS_STATUS  = 'C'";
                sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                
                DataTable dtMstCpiHour =  m_cMstService.Select(new string[] { sQuery });
                if (dtMstCpiHour != null && dtMstCpiHour.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtMstCpiHour.Rows)
                    {
                        string sCPI_CD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_HOUR.DATA.CPI_CD);

                        if (m_htMstSaleCpi.Contains(sCPI_CD))
                        {
                            Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCPI_CD];

                            Column.MST_SALE_CPI.DATA_HOUR cMstCpiHour = new Column.MST_SALE_CPI.DATA_HOUR();

                            cMstCpiHour.DOW_DIV = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_HOUR.DATA.DOW_DIV);
                            cMstCpiHour.START_HOUR = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_HOUR.DATA.START_HOUR);
                            cMstCpiHour.FNSH_HOUR = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_HOUR.DATA.FNSH_HOUR);

                            cMstSaleCpi.alDATA_HOUR.Add(cMstCpiHour);
                        }
                    }
                }

                // 캠페인 구성 마스터
                sQuery = " SELECT A.* FROM POSMST..MST_CPI_COMPNT A WITH(NOLOCK) ";
                sQuery += "   JOIN POSMST..MST_CPI B WITH(NOLOCK) ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.CPI_CD=B.CPI_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 '" + m_cTrnStatus.Head.SysYmd + "' BETWEEN B.STARTDAY AND B.FNSHDAY ";
                sQuery += "   AND B.PRGRS_STATUS  = 'C'";
                sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += " ORDER BY A.CPI_CD, A.CPI_ITEM_GRP_CD ";
                
                DataTable dtMstCpiCompnt = m_cMstService.Select(new string[] { sQuery });
                if (dtMstCpiCompnt != null && dtMstCpiCompnt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtMstCpiCompnt.Rows)
                    {
                        string sCPI_CD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_COMPNT.DATA.CPI_CD);
                        if (m_htMstSaleCpi.Contains(sCPI_CD))
                        {
                            Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCPI_CD];

                            Column.MST_SALE_CPI.DATA_COMPNT cMstCpiCompnt= new Column.MST_SALE_CPI.DATA_COMPNT();

                            cMstCpiCompnt.CPI_ITEM_GRP_CD = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_COMPNT.DATA.CPI_ITEM_GRP_CD);
                            cMstCpiCompnt.CPI_COND_TYPE = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_COMPNT.DATA.CPI_COND_TYPE);
                            cMstCpiCompnt.QTY_AMT = CmUtil.GetDataRowDouble(dr, PosMst.MST_CPI_COMPNT.DATA.QTY_AMT);
                            cMstCpiCompnt.CPI_DC_TYPE = CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_COMPNT.DATA.CPI_DC_TYPE);
                            cMstCpiCompnt.DC_RATE_QTY_AMT = CmUtil.GetDataRowDouble(dr, PosMst.MST_CPI_COMPNT.DATA.DC_RATE_QTY_AMT);
                            cMstCpiCompnt.DC_MAX_AMT = CmUtil.GetDataRowDouble(dr, PosMst.MST_CPI_COMPNT.DATA.DC_MAX_AMT);

                            cMstSaleCpi.alDATA_COMPNT.Add(cMstCpiCompnt);
                        }
                    }
                }

                m_alMstCpiCard.Clear();
                // 캠페인 카드 마스터
                sQuery = " SELECT A.* FROM POSMST..MST_CPI_CARD A WITH(NOLOCK) ";
                sQuery += "   JOIN POSMST..MST_CPI B WITH(NOLOCK) ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.CPI_CD=B.CPI_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 '" + m_cTrnStatus.Head.SysYmd + "' BETWEEN B.STARTDAY AND B.FNSHDAY ";
                sQuery += "   AND B.PRGRS_STATUS  = 'C'";
                sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += " ORDER BY A.CPI_CD ";
                
                DataTable dtMstCpiCard =  m_cMstService.Select(new string[] { sQuery });
                if (dtMstCpiCard != null && dtMstCpiCard.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtMstCpiCard.Rows)
                    {
                        m_alMstCpiCard.Add(new string[] { CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_CARD.DATA.CPI_CD), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_CARD.DATA.CARD_PRFX_CD).Trim(), 
                            CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_CARD.DATA.LOC).Trim(), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_CARD.DATA.CHECK_VAL).Trim() });
                    }
                }

                m_alMstCpiPrtMsg.Clear();
                // 캠페인 명판 출력메시지 마스터
                sQuery = " SELECT A.* FROM POSMST..MST_CPI_PRT_MSG A WITH(NOLOCK) ";
                sQuery += "   JOIN POSMST..MST_CPI B WITH(NOLOCK) ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.CPI_CD=B.CPI_CD";
                sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                sQuery += "   AND A.PRT_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += "   AND '" + m_cTrnStatus.Head.SysYmd + "' BETWEEN B.STARTDAY AND B.FNSHDAY ";
                sQuery += "   AND B.PRGRS_STATUS  = 'C'";
                sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += " ORDER BY A.CPI_CD, A.CPI_BILL_PRT_AREA_TYPE, A.PRT_SEQ ";
                
                DataTable dtMstCpiPrt =  m_cMstService.Select(new string[] { sQuery });
                if (dtMstCpiPrt != null && dtMstCpiPrt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtMstCpiPrt.Rows)
                    {
                        //0:유형(0:명판,1:복권), 1:캠페인코드, 2:출력위치(등수), 3:확대문자, 4:BOLD여부, 5:정렬유형, 6:문자열
                        m_alMstCpiPrtMsg.Add(new string[] { "0", CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.CPI_CD), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.CPI_BILL_PRT_AREA_TYPE),
                            CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.PRT_EXPAND_TYPE), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.BOLD_YN),
                            CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.ALIGN_TYPE), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.MSG_VAL) });
                    }
                }
                // 캠페인 복권 출력메시지 마스터
                sQuery = " SELECT A.* FROM POSMST..MST_CPI_LTTR_PRT A WITH(NOLOCK) ";
                sQuery += "   JOIN POSMST..MST_CPI B WITH(NOLOCK) ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.CPI_CD=B.CPI_CD";
                sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                sQuery += "   AND A.PRT_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += "   AND '" + m_cTrnStatus.Head.SysYmd + "' BETWEEN B.STARTDAY AND B.FNSHDAY ";
                sQuery += "   AND B.PRGRS_STATUS  = 'C'";
                sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += " ORDER BY A.CPI_CD, A.GRADE, A.PRT_SEQ ";

                DataTable dtMstCpiLttPrt = m_cMstService.Select(new string[] { sQuery });
                if (dtMstCpiLttPrt != null && dtMstCpiLttPrt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtMstCpiLttPrt.Rows)
                    {
                        //0:유형(0:명판,1:복권), 1:캠페인코드, 2:출력위치(등수), 3:확대문자, 4:BOLD여부, 5:정렬유형, 6:문자열
                        m_alMstCpiPrtMsg.Add(new string[] { "1", CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_LTTR_PRT.DATA.CPI_CD), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_LTTR_PRT.DATA.GRADE),
                            CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_LTTR_PRT.DATA.PRT_EXPAND_TYPE), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.BOLD_YN),
                            CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_PRT_MSG.DATA.ALIGN_TYPE), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_LTTR_PRT.DATA.MSG_VAL) });
                    }
                }

                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;
        }
        #endregion

        #region RegisterCampaignPlu 캠페인 상품 등록 및 실행
        /// <summary>
        /// 캠페인 상품 등록 및 실행
        /// </summary>
        /// <param name="bExecCampign">캠페인실행여부</param>
        /// <returns></returns>
        public double RegisterCampaignPlu(bool bExecCampaign)
        {
            try
            {
                Column.TR_PLU.DATA cNewSaleItem = null;         // 신규상품 등록 정보

                bool bStartCampaign = true;
                for (int i = 0; i < m_alTrPluItem.Count; i++)
                {
                    Column.TR_PLU.DATA cSaleItem = (Column.TR_PLU.DATA)m_alTrPluItem[i];

                    // 캠페인 상품 정보가 없으면 마스터 로딩 처리
                    if (cSaleItem.alTrSaleCpi == null)
                    {
                        cSaleItem.alTrSaleCpi = new ArrayList();

                        if (cSaleItem.ITEM_DIV != ItemConst.PLU_ITEM_DIV.NORMAL
                            && cSaleItem.ITEM_DIV != ItemConst.PLU_ITEM_DIV.SET_MAIN && cSaleItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.SET_DETL
                            && cSaleItem.ITEM_DIV != ItemConst.PLU_ITEM_DIV.OPT_MENU && cSaleItem.ITEM_DIV != ItemConst.PLU_ITEM_DIV.SET_DIS) continue;      // 상품 체크

                        if (cSaleItem.FLAVOUR_DIV == ItemConst.PLU_FLAVOUR_DIV.FLAVOUR) continue;
                        if (cSaleItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.OPT_MENU && cSaleItem.SUBPRC_MENU_KEY_DIV == "1") continue;                        // 부가상품(속성) 제외

                        // 캠페인 상품 마스터
                        string sQuery = " SELECT A.* FROM POSMST..MST_CPI_ITEM A WITH(NOLOCK) ";
                        sQuery += "   JOIN POSMST..MST_CPI B WITH(NOLOCK) ON A.CMP_CD=B.CMP_CD AND A.STOR_CD=B.STOR_CD AND A.CPI_CD=B.CPI_CD";
                        sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                        sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                        //#20171010 스퀘어 점포 대상상품 캠페인 적용 안되는 현상 수정 start
                        //일반 점포는 stor_cd, sub_stor_cd 가 동일, 스퀘어 점포는 stor_cd, sub_stor_cd가 달라서 대상상품 체크가 안됨.
                        //sQuery += "   AND A.SUB_STOR_CD = '" + cSaleItem.SUB_SHOP_CD + "'";
                        //#20171010 스퀘어 점포 대상상품 캠페인 적용 안되는 현상 수정 end
                        sQuery += "   AND ((A.ITEM_LVL = '1' AND A.ITEM_CD = '" + cSaleItem.ITEM_PLU_CD + "')";
                        sQuery += "     OR (A.ITEM_LVL = '2' AND A.ITEM_CD = '" + cSaleItem.S_CLSS + "')";
                        sQuery += "     OR (A.ITEM_LVL = '3' AND A.ITEM_CD = '" + cSaleItem.M_CLSS + "')";
                        sQuery += "     OR (A.ITEM_LVL = '4' AND A.ITEM_CD = '" + cSaleItem.L_CLSS + "'))";
                        sQuery += "   AND A.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                        sQuery += "   AND '" + m_cTrnStatus.Head.SysYmd + "' BETWEEN B.STARTDAY AND B.FNSHDAY ";
                        sQuery += "   AND B.PRGRS_STATUS  = 'C'";
                        sQuery += "   AND B.USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                        sQuery += " ORDER BY A.CPI_CD, A.CPI_ITEM_GRP_CD, A.ITEM_LVL";

                        DataTable dtMstCpiItem = m_cMstService.Select(new string[] { sQuery });
                        if (dtMstCpiItem != null && dtMstCpiItem.Rows.Count > 0)
                        {
                            foreach (DataRow dr in dtMstCpiItem.Rows)
                            {
                                AddSaleItemTrSaleCpiData(cSaleItem, CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_ITEM.DATA.CPI_CD), CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_ITEM.DATA.CPI_ITEM_GRP_CD),
                                        CmUtil.GetDataRowStr(dr, PosMst.MST_CPI_ITEM.DATA.CPI_DC_TYPE), CmUtil.GetDataRowDouble(dr, PosMst.MST_CPI_ITEM.DATA.DC_RATE_AMT));
                            }
                        }
                        cNewSaleItem = cSaleItem;
                    }
                    else
                    {
                        bStartCampaign = false;
                    }
                }

                if (bStartCampaign == true)
                {
                    foreach (string sCpiCode in m_alMstSaleCpi)
                    {
                        Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];
                        cMstSaleCpi.SOUND_PLAY_YN = false;
                        cMstSaleCpi.JOIN_QUSTN_ANSWER = "";
                    }
                }

                if (bExecCampaign == false) return 0;        // 캠페인 계산 안함.

                //////////////// 캠페인 안내를 위한 처리(음성 및 고객화면 이미지) ///////////////////////////
                m_cTrnStatus.Sale.CampaignFileName = "";
                if ( cNewSaleItem != null)
                {
                    foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cNewSaleItem.alTrSaleCpi)
                    {
                        Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[cTrSaleCpi.CPI_CD];

                        if ( cMstSaleCpi.SOUND_PLAY_YN == true) continue;
                        if ( cMstSaleCpi.SOUND_FILE_PLAY_CHK_PNT != "1") continue;      // 1:상품등록, 2:캠페인성립


                        //#13521 일반캠페인 등록 start, phj
                        //기존
                        //캠페인 대상 체크
                        //if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.NORMAL) continue;
                        //캠페인 지불구분 체크
                        //if (cMstSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.NORMAL) continue;
                        //#13521 일반캠페인 등록 end, phj


                        if ( cMstSaleCpi.SOUND_FILE_DIV == "01" || cMstSaleCpi.SOUND_FILE_DIV == "02")
                        {
                            PlayCampaignSound(cMstSaleCpi.SOUND_FILE_DIV, cMstSaleCpi.SOUND_FILE_NM, cMstSaleCpi.TTS_DSCRP);
                        }

                        // 고객화면에 캠페인 안내 이미지 표시
                        if (cMstSaleCpi.CUST_DSP_FILENM.Trim() != "")
                        {
                            m_cCustDisp.DisplayCampaign(cMstSaleCpi.CUST_DSP_FILE_DIV, cMstSaleCpi.CUST_DSP_FILENM);
                        }
                        cMstSaleCpi.SOUND_PLAY_YN = true;
                    }
                }

                //return ExecuteCampaignPlu("");      // 상품 캠페인 계산
                return ExecuteCampaignPluHappyPoint("", 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 0;
        }
        #endregion

        /// <summary>
        /// 상품 캠페인 및 해피포인트 캠페인 할인 계산 처리
        /// </summary>
        /// <param name="sPayKeySeqNo">키값(취소시사용 "":상품캠페인, 그외 HP캠페인</param>
        /// <param name="bPluAllClear">상품캠페인일때전체취소후재계산여부(true:전체쉬소, false:사은품제외)</param>
        /// <param name="sPosOpInputDiv">사은품캠페인("":상품만, 그외:사은품캠페인계산)</param>
        /// <param name="sCardNo">카드번호</param>
        /// <param name="sTrgtCustType">고객구분(앱여부):N:일반고객, Y:앱고객</param>
        /// <param name="sCustID">고객ID</param>
        /// <param name="sCustLvlCd">고객등급코드</param>
        /// <returns></returns>
        public double ExecuteCampaignPluHappyPoint(string sPayKeySeqNo, bool bPluAllClear, string sPosOpInputDiv, string sCardNo = "", string sTrgtCustType = "", string sCustID = "", string sCustLvlCd = "")
        {
            double nTotDisAmt = 0, nDisAmt = 0;
            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return 0;
                if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.NORMAL.SALE && m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.UNDECIDED.RESERVATION_REG) return 0;

                // 캠페인 상품이 로드되어 있지 않다면 로드 처리함
                foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
                {
                    if (cPluItem.alTrSaleCpi == null)
                    {
                        RegisterCampaignPlu(false);
                        break;
                    }
                }

                m_sHpCustID = sCustID;
                if (sPayKeySeqNo == "" && bPluAllClear == true)
                {
                    // 모든 캠페인 성립정보 초기화
                    RegisterCampaignPlu(false);     // 캠페인 상품 등록
                    ClearCampaginItem("");          // 모든 행사 초기화
                }
                else
                {
                    // 해피포인트 캠페인 삭제
                    CancelCampaignPayment(PosConst.CAMPAIGN_PAY_KEY.HP_SAVE, PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT_HP);  // HP 캠페인 할인 취소 처리(재계산)

                    // 일반 사은품 캠페인 제외한 캠페인 성립정보 초기화
                    foreach (Column.TR_PLU.DATA cPluItem in m_alTrPluItem)
                    {
                        foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                        {
                            if (cTrSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.FREEGIFT && cTrSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.FREE_SAVE)
                            {
                                ClearCampaginItem(cTrSaleCpi.CPI_CD);
                            }
                        }
                    }
                }
                
                if (CheckCampaignDuplication() == false) return 0;      // 캠페인 중복불가 결제 수단 체크

                //m_cPosStatus.Mst.ItemRudDwLocMethd = m_cPosStatus.Mst.DcRudDwLocMethd;
                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    // 캠페인고객혜택=>할인
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DISCOUNT && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DIS_SAVE
                        && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.FREEGIFT && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.FREE_SAVE) continue;

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;         // 캠페인 적용일자 및 시간 체크

                    nDisAmt = 0;
                    if (sPayKeySeqNo == "")
                    {
                        // 캠페인 대상 체크(상품캠페인)
                        if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.NORMAL) continue;
                    }
                    else
                    {
                        // 캠페인 대상 체크(HP 캠페인)
                        if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.NORMAL 
                            && cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HPC_CUST && cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP) continue;
                        if (cMstSaleCpi.TRGT_CUST_TYPE == ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP)
                        {
                            if (sTrgtCustType != "Y") continue;
                        }
                        
                        // 고객 등급별 캠페인
                        if (cMstSaleCpi.HP_CUST_LVL.TrimEnd().Length > 3 && CmUtil.LongParse(cMstSaleCpi.HP_CUST_LVL) > 0)
                        {
                            bool bHpCustLvlExist = false;           // 해피고객 등급별 행사 여부
                            if (cMstSaleCpi.HP_CUST_LVL.StartsWith("111") == true)
                            {
                                bHpCustLvlExist = true;
                            }
                            if (cMstSaleCpi.HP_CUST_LVL.Substring(0, 1) == "1")     // 핑크
                            {
                                if (sCustLvlCd.StartsWith("G") == false && sCustLvlCd != "VIP") bHpCustLvlExist = true;
                            }
                            if (cMstSaleCpi.HP_CUST_LVL.Substring(1, 1) == "1")     // 골드
                            {
                                if (sCustLvlCd.StartsWith("G") == true) bHpCustLvlExist = true;
                            }
                            if (cMstSaleCpi.HP_CUST_LVL.Substring(2, 1) == "1")     // 플레티넘
                            {
                                if (sCustLvlCd == "VIP") bHpCustLvlExist = true;
                            }

                            if (bHpCustLvlExist == false) continue;
                        }
                    }

                    // 캠페인 지불구분체크
                    if (cMstSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.NORMAL) continue;

                    // 캠페인 중복적용 여부(1:중복적용 가능, 0:중복적용 불가)
                    if (ExistCampaignDupApply(cMstSaleCpi.CPI_CUST_BNFT_TYPE, cMstSaleCpi.DUP_APPLY_YN) == true) continue;

                    //#15583 캠페인 기능 개선 요청 start
                    // 캠페인 마스터의 중복 가능 여부 체크
                    // (통신사 제휴 중복 허용 여부, 모바일쿠폰 중복 허용 여부, 해피쿠폰 중복 허용 여부)
                    if (CheckCampaignMstDuplication(cMstSaleCpi) == false) continue;
                    //#15583 캠페인 기능 개선 요청 end

                    // 캠페인고객혜택=>할인
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DISCOUNT || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_SAVE)
                    {
                        if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLUITEM)
                        {
                            //#17198 (구포스 기능) 영수건 별 최대 할인 금액 제한 확인요청 start
                            //할인 최대 금액 제한이 있는 경우 할인적용방법 전체상품 형태로 변경.
                            //기존
                            
                            // 할인적용방법=> 상품별 할인
                            nDisAmt = CampaignPluItemDiscount(cMstSaleCpi, 0);
                            
                            //변경
                            /*
                            //할인 최대 금액 존재 여부
                            bool bCpnAllDcYN = false;
                            if (cMstSaleCpi.alDATA_COMPNT.Count == 0)
                            {
                                bCpnAllDcYN = false;
                            }
                            else
                            {
                                Column.MST_SALE_CPI.DATA_COMPNT cMstCpiCompnt = (Column.MST_SALE_CPI.DATA_COMPNT)cMstSaleCpi.alDATA_COMPNT[0];

                                if (cMstCpiCompnt.DC_MAX_AMT > 0)
                                {
                                    bCpnAllDcYN = true;
                                }
                                else
                                {
                                    bCpnAllDcYN = false;
                                }
                            }

                            //할인 최대 금액 존재 여부
                            if (bCpnAllDcYN == false)
                            {
                                // 할인적용방법=> 상품별 할인
                                nDisAmt = CampaignPluItemDiscount(cMstSaleCpi, 0);
                            }
                            else
                            {
                                // 할인적용방법=> 전체상품
                                nDisAmt = CampaignRectSumDiscount(cMstSaleCpi, 0);
                            }
                            */
                            //#17198 (구포스 기능) 영수건 별 최대 할인 금액 제한 확인요청 end
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.NPLUS)
                        {
                            // 할인적용방법=> N+1
                            nDisAmt = CampaignPlusOneDiscount(cMstSaleCpi, 0);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLULINK)
                        {
                            // 할인적용방법=> 결합
                            nDisAmt = CampaignLinkPluDiscount(cMstSaleCpi, 0);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLUSUM)
                        {
                            // 할인적용방법=> 상품합산
                            nDisAmt = CampaignPluSumDiscount(cMstSaleCpi, 0);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.RECTSUM)
                        {
                            // 할인적용방법=> 전체상품
                            nDisAmt = CampaignRectSumDiscount(cMstSaleCpi, 0);
                        }

                        if (nDisAmt <= 0) continue;

                        if (sPayKeySeqNo != "")
                        {
                            // 캠페인 HP횟수제한 체크
                            if (CheckCampaignCntLimit(cMstSaleCpi, sCustID) == false)
                            {
                                ClearCampaginItem(cMstSaleCpi.CPI_CD);
                                continue;
                            }

                            // 캠페인 참여문의 여부
                            if (CheckCampaignJoinQustn(cMstSaleCpi, true) == false)
                            {
                                ClearCampaginItem(cMstSaleCpi.CPI_CD);
                                continue;
                            }
                        }
                        else
                        {
                            // 캠페인 참여문의 여부
                            if (CheckCampaignJoinQustn(cMstSaleCpi) == false)
                            {
                                ClearCampaginItem(cMstSaleCpi.CPI_CD);
                                continue;
                            }
                        }
                    }
                    // 캠페인고객혜택=> 사은품
                    else if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.FREEGIFT || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.FREE_SAVE)
                    {
                        if (sPosOpInputDiv != ""
                            && (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLUITEM || cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.RECTSUM))
                        {
                            if (sPayKeySeqNo == "" && sPosOpInputDiv == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT)
                            {
                                // 일반사은품
                                if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.NORMAL) continue;
                                // 할인적용방법 => 사은품
                                nDisAmt = CampaignFreeGiftDiscount(cMstSaleCpi, 0, sPosOpInputDiv, sCustID);
                            }
                            if (sPayKeySeqNo != "" && sPosOpInputDiv == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT_HP)
                            {
                                // 해피사은품
                                if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HPC_CUST && cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP) continue;
                                if (cMstSaleCpi.TRGT_CUST_TYPE == ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP)
                                {
                                    if (sTrgtCustType != "Y") continue;
                                }
                                // 할인적용방법 => 사은품
                                nDisAmt = CampaignFreeGiftDiscount(cMstSaleCpi, 0, sPosOpInputDiv, sCustID);
                            }

                            if (nDisAmt <= 0) continue;
                        } 
                    }

                    // 결제캠페인 적용 정보 저장
                    if (nDisAmt > 0)
                    {
                        if (sPayKeySeqNo != "" )
                        {
                            m_alSaleCpiPay.Add(new string[] { sPayKeySeqNo, cMstSaleCpi.CPI_CD, "", "", "0" });
                        }
                        PlayCompleteSound(cMstSaleCpi, false);           // 캠페인 성립시 사운드 출력

                        nTotDisAmt = CmUtil.DoubleAdd(nTotDisAmt, nDisAmt);
                    }
                }

                // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePluAmount(true);

                if (sPayKeySeqNo != "" || sPosOpInputDiv != "")
                {
                    //UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    //        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                    //        , string.Format("CAMPAIGN = PayKey:{0}, CardNo:{1}, TrgtCustType:{2} => DisAmt:{3}", sPayKeySeqNo, sCardNo, sTrgtCustType, nTotDisAmt));
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                m_sHpCustID = "";
            }
            return nTotDisAmt;
        }

        /// <summary>
        /// 해피포인트 결제 캠페인 할인 계산 처리
        /// </summary>
        /// <param name="sPayKey">키값(취소시사용)</param>
        /// <param name="sCardNo">카드번호</param>
        /// <param name="nPayAmt">지불금액</param>
        /// <param name="nExpPoint">소멸예정포인트</param>
        /// <param name="sCustID">고객번호</param>
        /// <returns></returns>
        public double ExecuteCampaignHappyUse(string sPayKey, string sCardNo, double nPayAmt, double nExpPoint, string sCustID)
        {
            double nTotDisAmt = 0, nDisAmt = 0;
            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return 0;
                if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.NORMAL.SALE && m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.UNDECIDED.RESERVATION_REG) return 0;

                m_nHpExpPoint = nExpPoint;          // 소멸예정포인트
                m_sHpCustID = sCustID;              // 고객번호

                //m_cPosStatus.Mst.ItemRudDwLocMethd = m_cPosStatus.Mst.DcRudDwLocMethd;

                CancelCampaignPayment(sPayKey, "");                     // 결제 캠페인 할인 취소 처리(재계산)

                if (CheckCampaignDuplication() == false) return 0;      // 캠페인 중복불가 결제 수단 체크

                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    // 캠페인고객혜택=>할인
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DISCOUNT && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DIS_SAVE
                        && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DIS_POINT_ALL && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DIS_POINT) continue;

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;         // 캠페인 적용일자 및 시간 체크

                    // 해피포인트 결제
                    if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HPC_PAY) continue;

                    // 캠페인 지불구분체크
                    if (cMstSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.NORMAL) continue;

                    string sPayDcType = PosConst.PAY_DC_TYPE.DC;        // 결제할인구분
                    string sPayDtlCode = "";                            // 결제할인상세코드
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_POINT_ALL || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_POINT)
                    {
                        // 실효포인트 행사(실효포인트가 있을때만 적용)
                        // 실효포인트 행사 => 실효포인트가 없더라도 가능하게 처리(2017.06.21)
                        //if (m_nHpExpPoint == 0) continue;

                        sPayDcType = PosConst.PAY_DC_TYPE.PAY;
                        sPayDtlCode = ItemConst.TR_ITEM_ID.CPI_PAY.HPEXT_PAY;
                    }

                    // 캠페인 중복적용 여부(1:중복적용 가능, 0:중복적용 불가)
                    if (ExistCampaignDupApply(cMstSaleCpi.CPI_CUST_BNFT_TYPE, cMstSaleCpi.DUP_APPLY_YN) == true) continue;

                    //#15583 캠페인 기능 개선 요청 start
                    // 캠페인 마스터의 중복 가능 여부 체크
                    // (통신사 제휴 중복 허용 여부, 모바일쿠폰 중복 허용 여부, 해피쿠폰 중복 허용 여부)
                    if (CheckCampaignMstDuplication(cMstSaleCpi) == false) continue;
                    //#15583 캠페인 기능 개선 요청 end

                    // 캠페인고객혜택=>할인
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DISCOUNT || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_SAVE
                        || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_POINT_ALL || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_POINT)
                    {
                        if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLUITEM)
                        {
                            // 할인적용방법=> 상품별 할인
                            nDisAmt = CampaignPluItemDiscount(cMstSaleCpi, nPayAmt, sPayDcType);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.NPLUS)
                        {
                            // 할인적용방법=> N+1
                            nDisAmt = CampaignPlusOneDiscount(cMstSaleCpi, nPayAmt, sPayDcType);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLULINK)
                        {
                            // 할인적용방법=> 결합
                            nDisAmt = CampaignLinkPluDiscount(cMstSaleCpi, nPayAmt, sPayDcType);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLUSUM)
                        {
                            // 할인적용방법=> 상품합산
                            nDisAmt = CampaignPluSumDiscount(cMstSaleCpi, nPayAmt, sPayDcType);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.RECTSUM)
                        {
                            // 할인적용방법=> 전체상품
                            nDisAmt = CampaignRectSumDiscount(cMstSaleCpi, nPayAmt, sPayDcType);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PAYMENT)
                        {
                            // 할인적용방법=> 결제금액
                            nDisAmt = CampaignPaymentDiscount(cMstSaleCpi, nPayAmt, sPayDcType);
                        }
                    }

                    // 결제캠페인 적용 정보 저장
                    if (nDisAmt > 0)
                    {
                        //// 캠페인 제한 수량 체크
                        //if (CheckCampaignQtyLimit(cMstSaleCpi) == false)
                        //{
                        //    ClearCampaginItem(cMstSaleCpi.CPI_CD);
                        //    continue;
                        //}

                        // 캠페인 HP횟수제한 체크
                        if (CheckCampaignCntLimit(cMstSaleCpi, m_sHpCustID) == false)
                        {
                            ClearCampaginItem(cMstSaleCpi.CPI_CD);
                            continue;
                        }

                        // 캠페인 참여문의 여부
                        if (CheckCampaignJoinQustn(cMstSaleCpi, true) == false)
                        {
                            ClearCampaginItem(cMstSaleCpi.CPI_CD);
                            continue;
                        }

                        m_alSaleCpiPay.Add(new string[] { sPayKey, cMstSaleCpi.CPI_CD, sPayDtlCode, sCardNo, nDisAmt.ToString() });

                        nTotDisAmt = CmUtil.DoubleAdd(nTotDisAmt, nDisAmt);

                        PlayCompleteSound(cMstSaleCpi, false);     // 캠페인 성립시 사운드 출력
                    }
                }

                // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePluAmount(true);
                m_cDataService.UpdatePayAmount();

                //UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                //        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                //        , string.Format("CAMPAIGN = PayKey:{0}, CardNo:{1}, PayAmt:{2}, HpExpPnt:{3} => DisAmt:{4}", sPayKey, sCardNo, nPayAmt, m_nHpExpPoint, nTotDisAmt));
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                m_sHpCustID = "";
            }
            return nTotDisAmt;
        }

        /// <summary>
        /// 결제 캠페인 할인 계산 처리
        /// </summary>
        /// <param name="sPayKey">키값(취소시사용)</param>
        /// <param name="sCardNo">카드번호</param>
        /// <param name="sPaymentDiv">지불구분(01:신용카드, 02:캐시비, 03:티머니, 04:스마일페이)</param>
        /// <param name="nPayAmt">지불금액</param>
        /// <returns></returns>
        //#14538 스마일페이 캠페인 확인창 중복 팝업 확인요청 start,phj
        //기존
        //public double ExecuteCampaignPayment(string sPayKey, string sCardNo, string sPaymentDiv, double nPayAmt)
        //변경
        public double ExecuteCampaignPayment(string sPayKey, string sCardNo, string sPaymentDiv, double nPayAmt, bool bPopupYN)
        //#14538 스마일페이 캠페인 확인창 중복 팝업 확인요청 end,phj
        {
            double nTotDisAmt = 0, nDisAmt = 0;
            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return 0;
                if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.NORMAL.SALE && m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.UNDECIDED.RESERVATION_REG) return 0;

                //m_cPosStatus.Mst.ItemRudDwLocMethd = m_cPosStatus.Mst.DcRudDwLocMethd;

                CancelCampaignPayment(sPayKey, "");                     // 결제 캠페인 할인 취소 처리(재계산)
                
                if (CheckCampaignDuplication() == false) return 0;      // 캠페인 중복불가 결제 수단 체크

                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    // 캠페인고객혜택=>할인
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DISCOUNT && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DIS_SAVE) continue;

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;         // 캠페인 적용일자 및 시간 체크
                        
                    // 캠페인 대상 체크
                    if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.NORMAL && cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.CREDIT_CARD) continue;

                    // 캠페인 지불구분체크
                    if (cMstSaleCpi.CUST_PAY_TYPE != sPaymentDiv) continue;

                    // 카드 프리픽스 체크
                    if (CheckCampaginCard(cMstSaleCpi.CPI_CD, sCardNo, cMstSaleCpi.TRGT_CUST_TYPE == ItemConst.CPI_TRGT_CUST_TYPE.CREDIT_CARD ? true : false) == false) continue;
                    
                    // 캠페인 중복적용 여부(1:중복적용 가능, 0:중복적용 불가)
                    if (ExistCampaignDupApply(cMstSaleCpi.CPI_CUST_BNFT_TYPE, cMstSaleCpi.DUP_APPLY_YN) == true) continue;

                    //#15583 캠페인 기능 개선 요청 start
                    // 캠페인 마스터의 중복 가능 여부 체크
                    // (통신사 제휴 중복 허용 여부, 모바일쿠폰 중복 허용 여부, 해피쿠폰 중복 허용 여부)
                    if (CheckCampaignMstDuplication(cMstSaleCpi) == false) continue;
                    //#15583 캠페인 기능 개선 요청 end

                    //#17169 스마일페이 변경요청 건 start
                    if (sPaymentDiv == ItemConst.CPI_CUST_PAY_TYPE.SMILEPAY)
                    {
                        // 문의해야할것.
                        // 스마일페이결제승인 시 스마일페이 중복적용 된 할인금액으로 보내야하는지?
                        // 아니면 중복적용 안된 한 건으로 적용된 할인금액으로 보내야하는지?
                        // 만약 전자라면 위치변경해야함.
                        if (CheckSmilepayCampaignDuplication() == true) continue;
                    }
                    //#17169 스마일페이 변경요청 건 end

                    // 캠페인고객혜택=>할인
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DISCOUNT || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_SAVE
                        || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_POINT_ALL || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_POINT)
                    {
                        if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLUITEM)
                        {
                            // 할인적용방법=> 상품별 할인
                            nDisAmt = CampaignPluItemDiscount(cMstSaleCpi, nPayAmt, PosConst.PAY_DC_TYPE.PAY);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.NPLUS)
                        {
                            // 할인적용방법=> N+1
                            nDisAmt = CampaignPlusOneDiscount(cMstSaleCpi, nPayAmt, PosConst.PAY_DC_TYPE.PAY);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLULINK)
                        {
                            // 할인적용방법=> 결합
                            nDisAmt = CampaignLinkPluDiscount(cMstSaleCpi, nPayAmt, PosConst.PAY_DC_TYPE.PAY);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PLUSUM)
                        {
                            // 할인적용방법=> 상품합산
                            nDisAmt = CampaignPluSumDiscount(cMstSaleCpi, nPayAmt, PosConst.PAY_DC_TYPE.PAY);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.RECTSUM)
                        {
                            // 할인적용방법=> 전체상품
                            nDisAmt = CampaignRectSumDiscount(cMstSaleCpi, nPayAmt, PosConst.PAY_DC_TYPE.PAY);
                        }
                        else if (cMstSaleCpi.ITEM_APPLY_METHD == ItemConst.CPI_ITEM_APPLY_METHD.PAYMENT)
                        {
                            // 할인적용방법=> 결제금액
                            nDisAmt = CampaignPaymentDiscount(cMstSaleCpi, nPayAmt, PosConst.PAY_DC_TYPE.PAY);
                        }
                    }

                    // 결제캠페인 적용 정보 저장
                    if (nDisAmt > 0)
                    {
                        //// 캠페인 제한 수량 체크
                        //if (CheckCampaignQtyLimit(cMstSaleCpi) == false)
                        //{
                        //    ClearCampaginItem(cMstSaleCpi.CPI_CD);
                        //    continue;
                        //}


                        //#14538 스마일페이 캠페인 확인창 중복 팝업 확인요청 start,phj
                        if (bPopupYN == true)
                        {
                            // 캠페인 참여문의 여부
                            if (CheckCampaignJoinQustn(cMstSaleCpi, true) == false)
                            {
                                ClearCampaginItem(cMstSaleCpi.CPI_CD);
                                continue;
                            }
                        }
                        //#14538 스마일페이 캠페인 확인창 중복 팝업 확인요청 end,phj


                        m_alSaleCpiPay.Add(new string[] { sPayKey, cMstSaleCpi.CPI_CD, cMstSaleCpi.CPI_DC_PAY_WAY, sCardNo, nDisAmt.ToString() });

                        nTotDisAmt = CmUtil.DoubleAdd(nTotDisAmt, nDisAmt);

                        PlayCompleteSound(cMstSaleCpi, false);     // 캠페인 성립시 사운드 출력
                    }
                }

                // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePluAmount(true);
                m_cDataService.UpdatePayAmount();

                //UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                //        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                //        , string.Format("CAMPAIGN = PayKey:{0}, CardNo:{1}, PayDiv:{2}, PayAmt:{3} => DisAmt:{4}", sPayKey, sCardNo, sPaymentDiv, nPayAmt, nTotDisAmt));
            }
            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 nTotDisAmt;
        }

        //#17169 스마일페이 변경요청 건 start
        /// <summary>
        /// 적용된 스마일페이캠페인 존재여부 체크한다. 
        /// 현재 스마일페이 중복 적용 가능하나
        /// 결제 승인 시 프로모션 코드를 하나만 넘겨야 하므로 
        /// 스마일페이 캠페인 중복적용을 막는다.
        /// true : 컨티뉴, false : 적용안됨        
        /// </summary>
        public bool CheckSmilepayCampaignDuplication()
        {
            bool bRet = false;
            try
            {
                if (m_alSaleCpiPay.Count > 0)
                {
                    foreach (string[] saCpiPay in m_alSaleCpiPay)
                    {
                        string sPaySeq = saCpiPay.Length > 1 ? saCpiPay[0] : "";
                        string sCpiCode = saCpiPay.Length > 2 ? saCpiPay[1] : "";
                        string sCpiDcPayWay = saCpiPay.Length > 3 ? saCpiPay[2] : "";
                        string sCardNo = saCpiPay.Length > 4 ? saCpiPay[3] : "";
                        string sDisAmt = saCpiPay.Length > 5 ? saCpiPay[4] : "";

                        if (sPaySeq == "") continue;
                        if (sCpiCode == "") continue;
                        if (sCpiDcPayWay == ItemConst.TR_ITEM_ID.CPI_PAY.SMAILE_PAY) { bRet = 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 bRet;
        }
        //#17169 스마일페이 변경요청 건 end

        //#17169 스마일페이 변경요청 건 start, 20181113
        /// <summary>
        /// 적용된 스마일페이 오퍼아이디 있으면 넣고, 없으면 공백
        /// 적용된 캠페인 존재 시 0원, 없으면 스마일페이 결제금액 
        /// pSmilepayPayAmt: 결제금액
        /// pSmilepayPromotionCode: 프로모션코드
        /// pSmileCashTargetAmt: 스마일캐시
        /// pApplyCampaign: 적용된 캠페인 유무 
        /// </summary>
        public void GetSmailePayCampaignCheck(double pSmilepayPayAmt, out string pSmilepayPromotionCode, out double pSmileCashTargetAmt, out bool pApplyCampaign)
        {
            string sSmilepayPromotionCode = "";
            double dSmileCashTargetAmt = 0;
            bool bApplyCampaign = false;

            try
            {
                #region 적용된 스마일페이 캠페인의 오퍼아이디 구하기
                string sSmilepayCampaingCode = "";
                if (m_alSaleCpiPay.Count > 0)
                {
                    foreach (string[] saCpiPay in m_alSaleCpiPay)
                    {
                        string sPaySeq = saCpiPay.Length > 1 ? saCpiPay[0] : "";
                        string sCpiCode = saCpiPay.Length > 2 ? saCpiPay[1] : "";
                        string sCpiDcPayWay = saCpiPay.Length > 3 ? saCpiPay[2] : "";
                        string sCardNo = saCpiPay.Length > 4 ? saCpiPay[3] : "";
                        string sDisAmt = saCpiPay.Length > 5 ? saCpiPay[4] : "";

                        if (sPaySeq == "") continue;
                        if (sCpiCode == "") continue;
                        if (sCpiDcPayWay != ItemConst.TR_ITEM_ID.CPI_PAY.SMAILE_PAY) continue;
                        sSmilepayCampaingCode = sCpiCode;
                        break;
                    }
                    if (sSmilepayCampaingCode != "")
                    {
                        foreach (string sCpiCode in m_alMstSaleCpi)
                        {
                            Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];
                            if (cMstSaleCpi.CPI_CD != sSmilepayCampaingCode) continue;
                            if (cMstSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.SMILEPAY) continue;
                            sSmilepayPromotionCode = cMstSaleCpi.OFFER_ID;
                        }
                    }
                }
                #endregion 적용된 스마일페이 캠페인의 오퍼아이디 구하기

                #region 적용된 캠페인 유무
                // 캠페인 상품
                foreach (Column.TR_PLU.DATA cSaleItem in m_alTrPluItem)
                {
                    if (cSaleItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cSaleItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue;    // 지정취소
                    if (cSaleItem.BILLSPR_NO != m_cTrnStatus.Sale.BillSplitNo) continue;                                                            // 빌분리번호
                    if (cSaleItem.SALE_PRC == 0) continue;
                    if (cSaleItem.alTrSaleCpi == null) continue;
                    foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cSaleItem.alTrSaleCpi)
                    {
                        if (cTrSaleCpi.CPI_CD == "") continue;
                        if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
                        if (cTrSaleCpi.DC_SUM_AMT <= 0 && cTrSaleCpi.DC_QTY <= 0) continue;
                        bApplyCampaign = true;
                        break;
                    }
                }

                // 캠페인 정보
                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                {
                    if (cTrSaleCpi.CPI_CD == "") continue;
                    if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
                    if (cTrSaleCpi.DC_SUM_AMT <= 0 && cTrSaleCpi.DC_QTY <= 0) continue;
                    if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTTERY ||
                        cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.RECEIPT ||
                        cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTT_REC ||
                        cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTRY ||
                        cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTR_REC || 
                        cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.HP_STAMP)
                    {
                        if (cTrSaleCpi.LTTR_NMPLAT_NO.Trim() == "") continue;//복권
                    }
                    bApplyCampaign = true;
                    break;
                }
                #endregion 적용된 캠페인 유무

                #region 스마일캐시 금액구하기
                if (bApplyCampaign == false)
                {
                    dSmileCashTargetAmt = pSmilepayPayAmt;
                }
                else
                {
                    dSmileCashTargetAmt = 0;
                }
                #endregion 스마일캐시 금액구하기

                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "스마일페이오퍼아이디: " + sSmilepayPromotionCode + " , 스마일캐시금액: " + dSmileCashTargetAmt.ToString() + " 적용캠페인존재유무: " + bApplyCampaign.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);
            }
            pSmilepayPromotionCode = sSmilepayPromotionCode;
            pSmileCashTargetAmt = dSmileCashTargetAmt;
            pApplyCampaign = bApplyCampaign;
        }
        //#17169 스마일페이 변경요청 건 end, 20181113

        //#17169 스마일페이 변경요청 건 start, 20181113
        #region 기존소스
        ////#17169 스마일페이 변경요청 건 start
        ///// <summary>
        ///// 스마일페이 프로모션코드
        ///// ※ 기존에는 스탬프 캠페인의 OFFER_ID 필드였으나, 스마일페이 캠페인 일 때는 프로모션 코드로 사용
        ///// SmilepayCampaingCode : 스마일페이캠페인코드, SmilepayPromotionCode : 스마일페이프로모션코드        
        ///// </summary>
        //public void GetSmilepayPromotionCode(out string SmilepayCampaingCode, out string SmilepayPromotionCode)
        //{
        //    string sSmilepayCampaingCode = ""; // 스마일페이 결제캠페인코드
        //    string sSmilepayPromotionCode = ""; //스마일페이 프로모션코드
        //    try
        //    {
        //        if (m_alSaleCpiPay.Count > 0)
        //        {
        //            foreach (string[] saCpiPay in m_alSaleCpiPay)
        //            {
        //                string sPaySeq = saCpiPay.Length > 1 ? saCpiPay[0] : "";
        //                string sCpiCode = saCpiPay.Length > 2 ? saCpiPay[1] : "";
        //                string sCpiDcPayWay = saCpiPay.Length > 3 ? saCpiPay[2] : "";
        //                string sCardNo = saCpiPay.Length > 4 ? saCpiPay[3] : "";
        //                string sDisAmt = saCpiPay.Length > 5 ? saCpiPay[4] : "";
        //
        //                if (sPaySeq == "") continue;
        //                if (sCpiCode == "") continue;
        //
        //                //if (sCpiDcPayWay != ItemConst.TR_ITEM_ID.CPI_PAY.SMAILE_PAY) continue;
        //                if (sCpiDcPayWay == ItemConst.TR_ITEM_ID.CPI_PAY.SMAILE_PAY)
        //                {
        //                    sSmilepayCampaingCode = sCpiCode;
        //                    break;
        //                }
        //            }
        //        }
        //        if (sSmilepayCampaingCode != "")
        //        {
        //            foreach (string sCpiCode in m_alMstSaleCpi)
        //            {
        //                Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];
        //
        //                //if (cMstSaleCpi.CPI_CD != sSmilepayCampaingCode) continue;
        //                if (cMstSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.SMILEPAY) continue;
        //                if (cMstSaleCpi.CPI_CD == sSmilepayCampaingCode) { sSmilepayPromotionCode = cMstSaleCpi.OFFER_ID; }
        //            }
        //        }
        //
        //        //foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrPluItem)
        //        //{
        //        //    if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
        //        //    if (cTrSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.SMILEPAY) continue;
        //        //    if (cTrSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DISCOUNT && cTrSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DIS_SAVE) continue;
        //        //    if (cTrSaleCpi.DC_SUM_AMT < 0 && cTrSaleCpi.DC_QTY < 0) continue;
        //        //    sSmilepayPromotionCode = cTrSaleCpi.CPI_CD;
        //        //    sSmilepayPromotionCode = cTrSaleCpi.OFFER_ID;
        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //        WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
        //                                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
        //                                    System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
        //                                    ex.Message);
        //    }
        //    SmilepayCampaingCode = sSmilepayCampaingCode;
        //    SmilepayPromotionCode = sSmilepayPromotionCode;
        //}
        ////#17169 스마일페이 변경요청 건 end
        #endregion
        //#17169 스마일페이 변경요청 건 end, 20181113

        //#17169 스마일페이 변경요청 건 start, 20181113
        #region 기존소스
        ////#17169 스마일페이 변경요청 건 start
        ///// <summary>
        ///// 스마일캐시 적립대상금액 구하기
        ///// - 할인 적용된 상품 제외
        ///// - 상품 적립 불가 상품 제외
        ///// - 스마일페이 할인 캠페인 적용된 상품 제외        
        ///// </summary>
        //public double GetSmileCashTargetAmt(string pCampainCode)
        //{
        //    double dSmileCashTargetAmt = 0; //스마일캐시 적립대상금액
        //    try
        //    {
        //        ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
        //        ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
        //
        //        #region 할인 적용된 상품 제외, 상품 적립 불가 상품 제외, 스마일페이 할인 캠페인 적용된 상품 제외
        //        foreach (Column.TR_PLU.DATA cSaleItem in m_alTrPluItem)
        //        //foreach (Column.TR_PLU.DATA cSaleItem in alSaleItem)
        //        {
        //            if (cSaleItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cSaleItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue; // 지정취소
        //            if (cSaleItem.BILLSPR_NO != m_cTrnStatus.Sale.BillSplitNo) continue;                                                         // 빌분리번호					
        //            if (cSaleItem.FLAVOUR_DIV == ItemConst.PLU_FLAVOUR_DIV.FLAVOUR) continue;                                                    // 플레이버 제외
        //            if (cSaleItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.OPT_MENU && cSaleItem.SUBPRC_MENU_KEY_DIV == "1") continue;                 // 부가상품(속성) 제외
        //
        //            if ((cSaleItem.ITEM_DC_AMT > 0 || cSaleItem.SUM_DC_AMT > 0) && cSaleItem.DC_DIV.Length >= 4) continue;                       // 단품 할인, 소계 할인 금액
        //            if (cSaleItem.COOP_CARD_DC_AMT > 0 && cSaleItem.COOP_CARD_DC_DIV.Length >= 4) continue;                                      // 제휴 할인 금액
        //            if (cSaleItem.POINT_DC_AMT > 0 && cSaleItem.POINT_DC_DIV.Length >= 4) continue;                                              // 포인트 할인 금액
        //            if (cSaleItem.CPN_DC_AMT > 0 && cSaleItem.CPN_DC_DIV.Length >= 4) continue;                                                  // 쿠폰 할인 금액
        //            if (cSaleItem.EMP_DC_AMT > 0 && cSaleItem.EMP_DC_DIV.Length >= 4) continue;                                                  // 직원 할인 금액
        //            if (cSaleItem.SET_DC_AMT > 0) continue;                                                                                      // 세트할인
        //            if (cSaleItem.ETC_DC_AMT > 0) continue;                                                                                      // 기타할인
        //            if (cSaleItem.CPI_DC_AMT > 0) continue;                                                                                      // 캠페인 할인금액 
        //            //if (cSaleItem.DC_PRMT_YN == "1") continue;                                                                                 // 할인 불가 여부(0:가능, 1:불가)
        //            if (cSaleItem.ACCUM_PRMT_YN == "0") continue;                                                                                // 적립허용여부 (0: 불가능, 1:가능)
        //
        //            bool bExist = false;
        //            if (cSaleItem.alTrSaleCpi != null)
        //            {
        //                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cSaleItem.alTrSaleCpi)
        //                {
        //                    if (cTrSaleCpi.CPI_CD == "") continue;
        //                    if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
        //
        //                    //스마일페이 캠페인 적용대상 상품이면 제외                    
        //                    if (pCampainCode == cTrSaleCpi.CPI_CD) { bExist = true; break; };
        //
        //                    //다른 결제할인캠페인 적용된 것이 있으면 상품제외
        //                    if (cTrSaleCpi.DC_SUM_AMT > 0 || cTrSaleCpi.DC_QTY > 0) { bExist = true; break; };
        //                }
        //                if (bExist == true) { continue; }
        //            }
        //
        //            dSmileCashTargetAmt += cSaleItem.BILL_AMT;
        //        }
        //        #endregion
        //
        //        #region 결제 금액중 적립가능 결제금액만 설정 함 -- 주석처리
        //        /* 
        //        double nExceptPayAmt = 0;
        //        foreach (Column.TR_PAYMENT.DATA cPayItem in alPayItem)
        //        {
        //            if (cPayItem.CANCEL_DIV != PosConst.CANCEL_DIV.NORMAL) continue;
        //            if (cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.PAY)        // 할인결제구분 (1:결제, 2:할인)
        //            {
        //                // 결제수단별 HP 기본 적립 여부 체크(적립불가 결제수단) => HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
        //                if (PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
        //                if (PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
        //                {
        //                    nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
        //                }
        //                else if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.CREDITCARD_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD)
        //                {
        //                    if (CmUtil.IntParse(cPayItem.OCCUR_ENTRY_14) >= 60 && cPayItem.PAY_DTL_CD_02 != "")
        //                    {
        //                        switch (cPayItem.PAY_DTL_CD_02)
        //                        {
        //                            #region
        //                            case ItemConst.CREDITCARD_DC_TY.CREDIT_SPNT: //삼성포인트
        //                                if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.SAMSUNG_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
        //                                {
        //                                    return 0;
        //                                }
        //                                else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.SAMSUNG_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
        //                                {
        //                                    nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
        //                                }
        //                                break;
        //                            case ItemConst.CREDITCARD_DC_TY.SHINHAN_CARD_POINT: //신한포인트
        //                                if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.SHINHAN_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
        //                                {
        //                                    return 0;
        //                                }
        //                                else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.SHINHAN_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
        //                                {
        //                                    nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
        //                                }
        //                                break;
        //                            case ItemConst.CREDITCARD_DC_TY.HYUNDAI_M_POINTS: //현대M
        //                                if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.HYUNDAI_MPOINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
        //                                {
        //                                    return 0;
        //                                }
        //                                else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.HYUNDAI_MPOINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
        //                                {
        //                                    nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
        //                                }
        //                                break;
        //                            // grayber@20180102 우리모아포인트 추가 start - 결제수단별 HP 기본 적립 여부 체크 분기 추가
        //                            case ItemConst.CREDITCARD_DC_TY.WOORIMORE_POINTS:
        //                                if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.WOORIMORE_POINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
        //                                {
        //                                    return 0;
        //                                }
        //                                else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.WOORIMORE_POINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
        //                                {
        //                                    nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
        //                                }
        //                                break;
        //                            // grayber@20180102 우리모아포인트 추가 end
        //                            default:
        //                                if (CmUtil.IntParse(cPayItem.OCCUR_ENTRY_14) >= 60) nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
        //                                break;
        //
        //                            #endregion
        //                        }
        //                    }
        //                    else
        //                    {
        //                        // 신용카드 포인트사용 결제 적립 없음
        //                        if (CmUtil.IntParse(cPayItem.OCCUR_ENTRY_14) >= 60) nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
        //                    }
        //
        //                }
        //
        //            }
        //        }
        //        if (nExceptPayAmt > 0)
        //        {
        //            double nPaySaveAmt = dSmileCashTargetAmt - nExceptPayAmt;
        //            if (nPaySaveAmt <= 0) return 0;
        //            if (dSmileCashTargetAmt > nPaySaveAmt) dSmileCashTargetAmt = nPaySaveAmt;
        //        }
        //        */
        //        #endregion
        //    }
        //    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 dSmileCashTargetAmt;
        //}
        ////#17169 스마일페이 변경요청 건 end
        #endregion 기존소스
        //#17169 스마일페이 변경요청 건 end, 20181113

        /// <summary>
        /// 결제 캠페인 할인 취소 처리
        /// </summary>
        /// <param name="sPayKeySeqNo">키값(취소시사용)</param>
        /// <param name="sPosOpInputDiv">사은품취소구분</param>
        /// <returns></returns>
        public bool CancelCampaignPayment(string sPayKeySeqNo, string sPosOpInputDiv)
        {
            try
            {
                if (sPayKeySeqNo != "")         // 키값(결제수단 등록 인덱스번호)
                {
                    ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);

                    foreach (string[] saCpiPay in m_alSaleCpiPay)
                    {
                        if (saCpiPay[0] == "") continue;

                        // 해당 캠페인 취소 처리
                        if (saCpiPay[0] == sPayKeySeqNo)
                        {
                            saCpiPay[0] = "";
                            if (sPayKeySeqNo == PosConst.CAMPAIGN_PAY_KEY.HP_SAVE)
                            {
                                ClearCampaginItem(saCpiPay[1], false);
                            }
                            else
                            {
                                // 결제아이템 취소
                                foreach (Column.TR_PAYMENT.DATA cPayItem in alPayItem)
                                {
                                    if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.CPI_PAY_ITEM && cPayItem.OCCUR_ENTRY_02 == saCpiPay[1])
                                    {
                                        cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.CANCEL;
                                    }
                                }

                                // 상품아이템 취소
                                ClearCampaginItem(saCpiPay[1], true);
                            }

                            Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[saCpiPay[1]];
                            cMstSaleCpi.SOUND_PLAY_YN = false;
                        }
                    }
                }

                if (sPosOpInputDiv == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT || sPosOpInputDiv == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT_HP)
                {
                    // 취소할 사은품(상품, HP)
                    ArrayList aSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM); // 상품 정보
                    for (int i = 0; i < aSaleItem.Count; i++)
                    {
                        Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)aSaleItem[i];

                        if (cPluItem.CAMPAIGN_FREEGIFT == sPosOpInputDiv)
                        {
                            if (cPluItem.alTrSaleCpi != null)
                            {
                                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                                {
                                    ClearCampaginItem(cTrSaleCpi.CPI_CD);
                                }
                            }

                            aSaleItem.Remove(cPluItem);
                            i--;
                        }
                    }
                }

                // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePluAmount(true);
                m_cDataService.UpdatePayAmount();           

                //UserLog.WriteLogFile(UserCom.LOG_ERROR, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                //        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                //        , string.Format("CAMPAIGN = PayKey:{0}, InputDiv:{1}", sPayKeySeqNo, sPosOpInputDiv));
                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>
        /// <param name="sPayKeySeqNo">키값(취소시사용)</param>
        /// <returns></returns>
        public bool CompleteCampaignPayment(string sPayKeySeqNo)
        {
            try
            {
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);

                foreach (string[] saCpiPay in m_alSaleCpiPay)
                {
                    if (saCpiPay[0] == "") continue;
                    if (saCpiPay[0] != sPayKeySeqNo) continue;

                    Column.TR_PAYMENT.DATA cPayItem = new Column.TR_PAYMENT.DATA();

                    cPayItem.PAY_AMT = CmUtil.DoubleParse(saCpiPay[4]);     // 결제금액

                    cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.CPI_PAY_ITEM;
                    cPayItem.PAY_DTL_CD_01 = saCpiPay[2];                   // 결제코드
                    cPayItem.PAY_DTL_CD_03 = "0";                           // 할인금액 아이템 적용여부(0:미적용, 1:적용)
                    cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;      // 할인결제구분 (1:결제, 2:할인)

                    cPayItem.AMT_ENTRY_01 = cPayItem.PAY_AMT;               // 결제금액

                    cPayItem.OCCUR_ENTRY_01 = saCpiPay[3].Length > 16 ? saCpiPay[3].Substring(0, 16).Trim() : saCpiPay[3];  // 카드번호
                    cPayItem.OCCUR_ENTRY_02 = saCpiPay[1];                  // 캠페인번호

                    cPayItem.OCCUR_ENTRY_20 = PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.PAY_DC_NM);             // 결제수단명
                    cPayItem.OCCUR_ENTRY_21 = PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.CASH_BILL_ISSUE_YN);    // 현금영수증발행여부
                  
                    if (cPayItem.OCCUR_ENTRY_20 == "")
                    {
                        if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CPI_PAY.TMONEY)
                        {
                            cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0977);   // 결제수단명
                        }
                        else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CPI_PAY.CASHBEE)
                        {
                            cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0978);   // 결제수단명                        
                        }
                        else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CPI_PAY.SMAILE_PAY)
                        {
                            cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0979);   // 결제수단명
                        }
                        else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CPI_PAY.HPEXT_PAY)
                        {
                            cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0789)
                                                    + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0018);   // 결제수단명
                        }
                        else
                        {
                            cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0976);   // 결제수단명
                        }
                    }

                    cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;
                    cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;  // 빌분리 번호

                    // 결제 아이템 추가
                    cPayItem.SEQ = alPayItem.Count + 1;
                    alPayItem.Add(cPayItem);
                }
                m_cDataService.UpdatePayAmount();

                //UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                //        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                //        , string.Format("CAMPAIGN = PayKey:{0}", sPayKeySeqNo));
                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>
        /// <param name="cEtcItemHP"></param>
        public void ExecuteCampaignHappyPointSave(string sPayKey, Column.TR_ETC.DATA cEtcItemHP)
        {
            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return;
                if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.NORMAL.SALE && m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.UNDECIDED.RESERVATION_REG) return;

                // 기존(적립) 캠페인 정보 초기화
                CancelCampaignPayment(sPayKey, "");
                m_cTrnStatus.Head.AftSaveAddDiv = "0";
                m_cTrnStatus.Head.AftSaveAddInfo = "";

                // 고객 구분 획득
                string sTrgtCustType = "N";   // 고객구분(앱여부) :N:일반고객, Y:앱고객
                ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                foreach (Column.TR_ETC.DATA cEtcItem in alEtcItem)
                {
                    if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                    if (cEtcItem.ETC_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT)
                    {
                        sTrgtCustType = cEtcItem.OCCUR_ENTRY_12;
                        m_sHpCustID = cEtcItem.OCCUR_ENTRY_10;
                        cEtcItemHP = cEtcItem;
                        break;
                    }
                }

                // 통신사 구분 획득
                string sTelecomDiv = "0";   // 0: 일반, 1: SKT, 2: KT,3: LGT
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                foreach (Column.TR_PAYMENT.DATA cPayItem in alPayItem)
                {
                    if (cPayItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                    if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT)
                    {
                        sTelecomDiv = "1";
                    }
                    else if ((cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF)
                        || (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_VIP)
                        || (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_DOUBLE))
                    {
                        sTelecomDiv = "2";
                    }
                    else if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT)
                    {
                        sTelecomDiv = "3";
                    }

                    //#20180413 웰컴카드 신규기능 추가 start,phj
                    /////////////////////////////////
                    //#20180618_웰컴카드 수정_grayber
                    // 해피포인트 적립을 위하여 아래 내용 주석 처리
                    //else if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD)
                    //{
                    //    sTelecomDiv = "4";
                    //}
                    /////////////////////////////////
                    if (sTelecomDiv != "0") break;
                }

                if (CheckCampaignDuplication() == true)      // 캠페인 중복불가 결제 수단 체크
                {
                    if (sTelecomDiv != "0")   // 0: 일반, 1: SKT, 2: KT,3: LGT)
                    {
                        // 해피포인트 통신사 추가적립 캠페인 계산 처리
                        ExecuteCampaingHpMobileSave(sPayKey, cEtcItemHP, sTrgtCustType, sTelecomDiv);
                    }
                    else
                    {
                        // 해피포인트 추가적립 캠페인 계산 처리
                        ExecuteCampaingHpAddSave(sPayKey, cEtcItemHP, sTrgtCustType, sTelecomDiv);
                    }
                }

                // 해피포인트 결제수단별 추가 적립 계산 처리
                if (m_cTrnStatus.Head.AftSaveAddInfo == "") ExecutePaymentAddSave();  
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                m_sHpCustID = "";
            }
        }

        /// <summary>
        /// 해피포인트 통신사 추가적립 캠페인 계산 처리
        /// </summary>
        /// <param name="cEtcItemHP"></param>
        public void ExecuteCampaingHpMobileSave(string sPayKey, Column.TR_ETC.DATA cEtcItemHP, string sTrgtCustType, string sTelecomDiv)
        {
            double nSaveAmt = 0;
            long nSavePnt = 0;

            try
            {
                // 추가적립 캠페인(통신사 추가 적립)
                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    // 캠페인고객혜택=> 적립
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.PNTSAVE) continue;

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;         // 캠페인 적용일자 및 시간 체크

                    // 캠페인 대상 체크
                    if (cMstSaleCpi.TRGT_CUST_TYPE == ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP)
                    {
                        if (sTrgtCustType != "Y") continue;
                    }

                    // 적립통신사 구분 체크
                    if (cMstSaleCpi.ADD_HP_ACCUM_TELECOM_DIV != sTelecomDiv) continue;

                    // 캠페인 중복적용 여부(1:중복적용 가능, 0:중복적용 불가)
                    if (ExistCampaignDupApply(cMstSaleCpi.CPI_CUST_BNFT_TYPE, cMstSaleCpi.DUP_APPLY_YN) == true) continue;

                    //#15583 캠페인 기능 개선 요청 start
                    // 캠페인 마스터의 중복 가능 여부 체크
                    // (통신사 제휴 중복 허용 여부, 모바일쿠폰 중복 허용 여부, 해피쿠폰 중복 허용 여부)
                    if (CheckCampaignMstDuplication(cMstSaleCpi) == false) continue;
                    //#15583 캠페인 기능 개선 요청 end

                    // 추가적립 행사 계산
                    if (CampaignHappyPointSave(cMstSaleCpi, ref nSaveAmt, ref nSavePnt) <= 0) continue;

                    // 통신사 추가 적립 정보
                    // 추가적립 정보[캠페인코드(10)+대상상품금액(15)+추가적립여부(1)+추가적립상세코드(2)+본사부담금(7)+매장부담금(7)]
                    string sAddHpAccume = CmUtil.RPadH(cMstSaleCpi.CPI_CD, 10) + CmUtil.RPadH(nSaveAmt.ToString(), 15) + "N" + CmUtil.RPadH(cMstSaleCpi.ADD_HP_ACCUM_CD1, 2) + string.Format("{0:D7}{1:D7}", (long)nSavePnt, 0);
                    m_cTrnStatus.Head.AftSavePoint = nSaveAmt;
                    m_cTrnStatus.Head.AftSaveAddDiv = cMstSaleCpi.ADD_HP_ACCUM_AF_DIV;
                    m_cTrnStatus.Head.AftSaveAddInfo = sAddHpAccume;

                    UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                        , string.Format("CAMPAIGN MOBILE POINT = {0}", sAddHpAccume));

                    if (cEtcItemHP != null)
                    {
                        // 캠페인 실적 생성
                        AddTrCampaignData(cMstSaleCpi.CPI_CD, nSavePnt, "", "");
                        m_alSaleCpiPay.Add(new string[] { sPayKey, cMstSaleCpi.CPI_CD, "", "", "0" });
                    }

                    break;  // 적립 캠페인은 한번만 적용
                }
                // 통신사 추가 적립 없을때 적립대상금액 초기화
                if (m_cTrnStatus.Head.AftSaveAddInfo == "") m_cTrnStatus.Head.AftSavePoint = 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);
            }
        }

        /// <summary>
        /// 해피포인트 추가적립 캠페인 계산 처리
        /// </summary>
        /// <param name="cEtcItemHP"></param>
        public void ExecuteCampaingHpAddSave(string sPayKey, Column.TR_ETC.DATA cEtcItemHP, string sTrgtCustType, string sTelecomDiv)
        {
            double nSaveAmt = 0;
            long nSavePnt = 0;

            try
            {
                // 추가적립 캠페인(해피포인트)
                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    // 캠페인고객혜택=> 적립
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.PNTSAVE
                        && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.DIS_SAVE && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.FREE_SAVE) continue;

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;         // 캠페인 적용일자 및 시간 체크

                    // 캠페인 대상 체크
                    if (cMstSaleCpi.TRGT_CUST_TYPE == ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP)
                    {
                        if (sTrgtCustType != "Y") continue;
                    }

                    // 적립통신사 구분 체크
                    if (cMstSaleCpi.ADD_HP_ACCUM_TELECOM_DIV != sTelecomDiv) continue;

                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.DIS_SAVE || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.FREE_SAVE)
                    {
                        // 할인적립 캠페인==> 할인캠페인이 있어야 함.
                        if (ExistCampaignDiscount(cMstSaleCpi.CPI_CD) == false) continue;
                    }
                    else
                    {
                        // 캠페인 중복적용 여부(1:중복적용 가능, 0:중복적용 불가)
                        if (ExistCampaignDupApply(cMstSaleCpi.CPI_CUST_BNFT_TYPE, cMstSaleCpi.DUP_APPLY_YN) == true) continue;
                    }

                    //#15583 캠페인 기능 개선 요청 start
                    // 캠페인 마스터의 중복 가능 여부 체크
                    // (통신사 제휴 중복 허용 여부, 모바일쿠폰 중복 허용 여부, 해피쿠폰 중복 허용 여부)
                    if (CheckCampaignMstDuplication(cMstSaleCpi) == false) continue;
                    //#15583 캠페인 기능 개선 요청 end

                    // 추가적립 행사 계산
                    if (CampaignHappyPointSave(cMstSaleCpi, ref nSaveAmt, ref nSavePnt) <= 0) continue;

                    // 일반 추가 적립
                    string sAddHpAccume = "";
                    if (m_cTrnStatus.Head.AftSavePoint >= 1000)
                    {
                        // 추가적립 정보[캠페인코드(10)+대상상품금액(15)+추가적립여부(1)+추가적립상세코드(2)+본사부담금(7)+매장부담금(7)]
                        sAddHpAccume = CmUtil.RPadH(cMstSaleCpi.CPI_CD, 10) + CmUtil.RPadH(nSaveAmt.ToString(), 15) + "Y" + CmUtil.RPadH(cMstSaleCpi.ADD_HP_ACCUM_CD2, 2) + string.Format("{0:D7}{1:D7}", (long)nSavePnt, 0);
                        m_cTrnStatus.Head.AftSaveAddDiv = cMstSaleCpi.ADD_HP_ACCUM_AF_DIV;
                        m_cTrnStatus.Head.AftSaveAddInfo = sAddHpAccume;
                    }
                    else
                    {
                        sAddHpAccume = CmUtil.RPadH(cMstSaleCpi.CPI_CD, 10) + CmUtil.RPadH(nSaveAmt.ToString(), 15) + "N" + CmUtil.RPadH(cMstSaleCpi.ADD_HP_ACCUM_CD1, 2) + string.Format("{0:D7}{1:D7}", (long)nSavePnt, 0);
                        m_cTrnStatus.Head.AftSaveAddDiv = cMstSaleCpi.ADD_HP_ACCUM_AF_DIV;
                        m_cTrnStatus.Head.AftSaveAddInfo = sAddHpAccume;

                        // 적립 대상 금액 설정
                        m_cTrnStatus.Head.AftSavePoint = m_cDataService.GetPluTagetAmount(PosKey.MENU_KEY.HAPPY_POINT, true);
                    }

                    UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                        , string.Format("CAMPAIGN HP ADD POINT = {0}", sAddHpAccume));

                    if (cEtcItemHP != null)
                    {
                        // 캠페인 실적 생성
                        AddTrCampaignData(cMstSaleCpi.CPI_CD, nSavePnt, "", "");
                        m_alSaleCpiPay.Add(new string[] { sPayKey, cMstSaleCpi.CPI_CD, "", "", "0" });
                    }

                    break;  // 적립 캠페인은 한번만 적용
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 해피포인트 결제수단별 추가적립 계산 처리
        /// </summary>
        /// <param name="cEtcItemHP"></param>
        public void ExecutePaymentAddSave()
        {
            double nSaveAmt = 0;
            long nSavePnt = 0;

            try
            {
                // 천미만코드, 천이상코드, 적립율, 추후적립가능여부
                string sADD_HP_ACCUM_CD1 = "A0", sADD_HP_ACCUM_CD2 = "A5", sADD_HP_ACCUM_RATE = "0.5", sADD_HP_ACCUM_AF_DIV = "1";

                DataTable dtData = m_cDataCommon.SeletCommonCode(PosConst.COMMON_CODE_GROUP.Z0022, "");
                if (dtData != null && dtData.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtData.Rows)
                    {
                        sADD_HP_ACCUM_CD1 = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_01);
                        sADD_HP_ACCUM_CD2 = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_02);
                        sADD_HP_ACCUM_RATE = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_03);
                        sADD_HP_ACCUM_AF_DIV = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_04);
                        break;
                    }
                }

                // 결제수단별 추가적립 행사 대상 계산
                nSaveAmt = PaymentHappyPointSave();
                if (nSaveAmt <= 0 || (m_cTrnStatus.Head.AftSavePoint < 1000 && nSaveAmt < 1000)) return;

                // 기본적립 > 추가적립 = 추가적립 없음.
                if (m_cTrnStatus.Head.AftSavePoint >= nSaveAmt) return;

                bool bHpSave1000 = false;       // 1000원이하 적립 가능여부
                if (m_cPosStatus.Mst.CorpDiv == ItemConst.CORP_DIV.PC && m_cPosStatus.Mst.CntryDiv == ItemConst.CNTRY_DIV.KR)
                {
                    ArrayList alPayment = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                    foreach (Column.TR_PAYMENT.DATA cPayItem in alPayment)
                    {
                        if (cPayItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;

                        // 천원이하 기본적립 가능
                        if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILECON_ITEM)     // 모바일카드
                        {
                            bHpSave1000 = true;
                            break;
                        }
                    }
                }

                // 추가적립 대상 금액은 기본적립 대상 금액을 제외함
                if ((bHpSave1000 == true && m_cTrnStatus.Head.AftSavePoint > 0) || (bHpSave1000 == false && m_cTrnStatus.Head.AftSavePoint >= 1000)) 
                {
                    nSaveAmt = CmUtil.DoubleSubtraction(nSaveAmt, m_cTrnStatus.Head.AftSavePoint);
                }

                // 적립 포인트 계산(무조건 올림 처리)
                nSavePnt = (long)CmUtil.MathRounds(CmUtil.MathAmtPercent(nSaveAmt, CmUtil.DoubleParse(sADD_HP_ACCUM_RATE)), PosConst.MATH_ROUND.CEILING, 0);
                if (nSavePnt <= 0) return;

                // 일반 추가 적립
                string sAddHpAccume = "";
                if ((bHpSave1000 == true && m_cTrnStatus.Head.AftSavePoint == 0) || (bHpSave1000 == false && m_cTrnStatus.Head.AftSavePoint < 1000))
                {
                    // 추가적립 정보[캠페인코드(10)+대상상품금액(15)+추가적립여부(1)+추가적립상세코드(2)+본사부담금(7)+매장부담금(7)]
                    sAddHpAccume = CmUtil.RPadH("", 10) + CmUtil.RPadH(nSaveAmt.ToString(), 15) + "N" + CmUtil.RPadH(sADD_HP_ACCUM_CD1, 2) + string.Format("{0:D7}{1:D7}", (long)nSavePnt, 0);
                    m_cTrnStatus.Head.AftSaveAddDiv = sADD_HP_ACCUM_AF_DIV;
                    m_cTrnStatus.Head.AftSaveAddInfo = sAddHpAccume;
                    m_cTrnStatus.Head.AftSavePoint = nSaveAmt;          // 적립 대상 금액 설정
                }
                else
                {
                    // 추가적립 정보[캠페인코드(10)+대상상품금액(15)+추가적립여부(1)+추가적립상세코드(2)+본사부담금(7)+매장부담금(7)]
                    sAddHpAccume = CmUtil.RPadH("", 10) + CmUtil.RPadH(nSaveAmt.ToString(), 15) + "Y" + CmUtil.RPadH(sADD_HP_ACCUM_CD2, 2) + string.Format("{0:D7}{1:D7}", (long)nSavePnt, 0);
                    m_cTrnStatus.Head.AftSaveAddDiv = sADD_HP_ACCUM_AF_DIV;
                    m_cTrnStatus.Head.AftSaveAddInfo = sAddHpAccume;
                }

                //// 추가적립 대상 금액은 기본적립 대상 금액을 제외함
                //if (m_cTrnStatus.Head.AftSavePoint >= 1000) nSaveAmt = CmUtil.DoubleSubtraction(nSaveAmt, m_cTrnStatus.Head.AftSavePoint);
                
                //// 적립 포인트 계산(무조건 올림 처리)
                //nSavePnt = (long)CmUtil.MathRounds(CmUtil.MathAmtPercent(nSaveAmt, CmUtil.DoubleParse(sADD_HP_ACCUM_RATE)), PosConst.MATH_ROUND.CEILING, 0);
                //if (nSavePnt <= 0) return;

                //// 일반 추가 적립
                //string sAddHpAccume = "";
                //if (m_cTrnStatus.Head.AftSavePoint < 1000)
                //{
                //    // 추가적립 정보[캠페인코드(10)+대상상품금액(15)+추가적립여부(1)+추가적립상세코드(2)+본사부담금(7)+매장부담금(7)]
                //    sAddHpAccume = CmUtil.RPadH("", 10) + CmUtil.RPadH(nSaveAmt.ToString(), 15) + "N" + CmUtil.RPadH(sADD_HP_ACCUM_CD1, 2) + string.Format("{0:D7}{1:D7}", (long)nSavePnt, 0);
                //    m_cTrnStatus.Head.AftSaveAddDiv = sADD_HP_ACCUM_AF_DIV;
                //    m_cTrnStatus.Head.AftSaveAddInfo = sAddHpAccume;
                //    m_cTrnStatus.Head.AftSavePoint = nSaveAmt;          // 적립 대상 금액 설정
                //}
                //else
                //{
                //    // 추가적립 정보[캠페인코드(10)+대상상품금액(15)+추가적립여부(1)+추가적립상세코드(2)+본사부담금(7)+매장부담금(7)]
                //    sAddHpAccume = CmUtil.RPadH("", 10) + CmUtil.RPadH(nSaveAmt.ToString(), 15) + "Y" + CmUtil.RPadH(sADD_HP_ACCUM_CD2, 2) + string.Format("{0:D7}{1:D7}", (long)nSavePnt, 0);
                //    m_cTrnStatus.Head.AftSaveAddDiv = sADD_HP_ACCUM_AF_DIV;
                //    m_cTrnStatus.Head.AftSaveAddInfo = sAddHpAccume;
                //}

                UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                    , string.Format("PAYMENT HP ADD POINT = {0}", sAddHpAccume));

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        /// <summary>
        /// 해피포인트 스템프 캠페인 상품정보 획득 처리
        /// </summary>
        public string GetCampaignHappyStampInfo()
        {
            ArrayList alStampPluInfo = new ArrayList();     // 스템프 상품 정보

            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return "";
                if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.NORMAL.SALE && m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.UNDECIDED.RESERVATION_REG) return "";

                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                {
                    if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
                    // 캠페인고객혜택 => 스탬프 캠페인
                    if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.HP_STAMP)
                    {
                        if (cTrSaleCpi.HP_CAMPAIGN_INFO != "")      // 적용 되어있으면 안함
                            return "";
                        else
                            return cTrSaleCpi.HP_STAMP_PLU;
                    }
                }

                if (CheckCampaignDuplication() == false) return "";         // 캠페인 중복불가 결제 수단 체크

                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    // 캠페인고객혜택=> 스탬프
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.HP_STAMP) continue;

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;         // 캠페인 적용일자 및 시간 체크

                    // 캠페인 중복적용 여부(1:중복적용 가능, 0:중복적용 불가)
                    if (ExistCampaignDupApply(cMstSaleCpi.CPI_CUST_BNFT_TYPE, cMstSaleCpi.DUP_APPLY_YN) == true) continue;

                    //#15583 캠페인 기능 개선 요청 start
                    // 캠페인 마스터의 중복 가능 여부 체크
                    // (통신사 제휴 중복 허용 여부, 모바일쿠폰 중복 허용 여부, 해피쿠폰 중복 허용 여부)
                    if (CheckCampaignMstDuplication(cMstSaleCpi) == false) continue;
                    //#15583 캠페인 기능 개선 요청 end

                    // 스템프 캠페인 상품정보 생성
                    CampaignHappyPointStamp(cMstSaleCpi, ref alStampPluInfo);
                }

                // 스템프 캠페인 상품 정보("ST" + 구매상품건수(2) + 상품 정보(10)
                if (alStampPluInfo.Count > 0)
                {
                    string sStampPlu = "ST" + string.Format("{0:D2}", alStampPluInfo.Count);
                    foreach (string sInfo in alStampPluInfo)
                    {
                        sStampPlu += sInfo;
                    }
                    foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                    {
                        if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
                        // 캠페인고객혜택 => 스탬프 캠페인
                        if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.HP_STAMP)
                        {
                            cTrSaleCpi.HP_STAMP_PLU = sStampPlu;
                        }
                    }

                    UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                                , string.Format("CAMPAIGN = {0}", sStampPlu));

                    return sStampPlu;
                }
            }
            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 "";
        }


        /// <summary>
        /// 해피포인트 스템프 캠페인 설정 처리
        /// </summary>
        /// <param name="sHP_CAMPAIGN_INFO"></param>
        /// <param name="sStmapCntInfo"></param>
        /// <returns></returns>
        public void SetCampaignHappyStampInfo(string sHP_CAMPAIGN_INFO, string sStmapCntInfo, string sCustID)
        {
            try
            {
                if (sHP_CAMPAIGN_INFO == "")
                {
                    // 미성립 스템프 캠페인 삭제
                    foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                    {
                        if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;

                        // 캠페인고객혜택 => 스탬프 캠페인
                        if (cTrSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.HP_STAMP) continue;

                        if (cTrSaleCpi.HP_CAMPAIGN_INFO == "" && cTrSaleCpi.LTTR_NMPLAT_NO == "")
                        {
                            cTrSaleCpi.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;
                        }
                    }
                    return;
                }

                // 캠페인별 구분자 파싱
                string[] saCampInfo = sHP_CAMPAIGN_INFO.Split(new string[] { PosConst.VAN_HEXA.GS }, StringSplitOptions.None);

                foreach (string sCampInfo in saCampInfo)
                {
                    if (sCampInfo.Trim() == "") continue;

                    foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                    {
                        if (cTrSaleCpi.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
                        
                        // 캠페인고객혜택 => 스탬프 캠페인
                        if (cTrSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.HP_STAMP) continue;
                        if (cTrSaleCpi.OFFER_ID != sCampInfo.Substring(0, 16).Trim()) continue;

                        cTrSaleCpi.HP_STAMP_COUPON = "";
                        cTrSaleCpi.HP_CAMPAIGN_INFO = "";
                        cTrSaleCpi.HP_STAMP_COUPON_INFO = "";
                        cTrSaleCpi.LTTR_NMPLAT_NO = sStmapCntInfo;
                        cTrSaleCpi.SLACK_FIELD = sCustID;

                        // 스템프 캠페인 룰파일 데이터 획득
                        string sRuleData = CmUtil.ReadTextFile(BaseCom.NxMstPath + @"RULE\" + sCampInfo.Substring(0, 16).Trim() + ".txt", System.Text.Encoding.UTF8);
                        if (sRuleData == "") 
                        {
                            UserLog.WriteLogFile(UserCom.LOG_ERROR, UserCom.INFO_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                                , string.Format("RULE FILE NOT FIND = {0}", sCampInfo.Substring(0, 16).Trim()));
                            continue;
                        }

                        string[] saCampSplit = sCampInfo.Split(new string[] { PosConst.VAN_HEXA.FS }, StringSplitOptions.None);
                        string[] saRuleSplit = sRuleData.Split(new string[] { "$$" }, StringSplitOptions.None);

                        string sStampData = "";
                        string sCoupnData = "";
                        for (int i = 1; i < saCampSplit.Length; i++)
                        {
                            if (saRuleSplit.Length > (i - 1) * 2) sStampData += saRuleSplit[(i - 1) * 2];       // 영수증 출력정보  

                            // 쿠폰번호 체크
                            int nCpnNmPos = saCampSplit[i].LastIndexOf("쿠폰번호");
                            if (nCpnNmPos >= 0)
                            {
                                string sCpnNoInfo = saCampSplit[i].Substring(nCpnNmPos);
                                int nCpnNoPos = sCpnNoInfo.LastIndexOf(";");
                                if (nCpnNoPos < 0) nCpnNoPos = sCpnNoInfo.LastIndexOf(":");
                                if (nCpnNoPos >= 0)
                                {
                                    cTrSaleCpi.HP_STAMP_COUPON = sCpnNoInfo.Substring(nCpnNoPos + 1).Trim().Replace("&", "").Replace("\r","").Replace("\n","");           // 쿠폰번호
                                    sCoupnData = saCampSplit[i].Substring(0, nCpnNmPos + nCpnNoPos).Replace("&", "");        // 쿠폰 출력정보
                                }
                            }
                            else
                            {
                                sStampData += saCampSplit[i];
                            }
                        }
                        cTrSaleCpi.HP_CAMPAIGN_INFO = sStampData;    // 출력정보 설정(스템프)
                        cTrSaleCpi.HP_STAMP_COUPON_INFO = cTrSaleCpi.HP_STAMP_COUPON == "" ? "" : sCoupnData;    // 출력정보 설정(쿠폰)

                        if (cTrSaleCpi.HP_STAMP_COUPON != "")
                        {
                            Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[cTrSaleCpi.CPI_CD];
                            PlayCompleteSound(cMstSaleCpi, false);     // 캠페인 성립시 사운드 출력
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }


        /// <summary>
        /// 영수증 출력 캠페인 계산 처리
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public double ExecuteCampaignPrint(string[] aParam)
        {
            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return 0;
                if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.NORMAL.SALE && m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.UNDECIDED.RESERVATION_REG) return 0;

                // 수량/횟수 제한 캠페인 완료 메시지 출력
                foreach (string[] saCpiQtyLmt in m_alSaleCpiQtyLmt)
                {
                    // 캠페인코드(0), 이전성립수량(1), 캠페인명(2), 제한수량(3), 현성립수량(4)
                    if (CmUtil.LongParse(saCpiQtyLmt[1]) + CmUtil.LongParse(saCpiQtyLmt[4]) >= CmUtil.LongParse(saCpiQtyLmt[3]))
                    {
                        bool bShowMsg = false;
                        foreach (Column.TR_PLU.DATA cSaleItem in m_alTrPluItem)
                        {
                            if (cSaleItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cSaleItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue;// 지정취소
                            if (cSaleItem.alTrSaleCpi == null) continue;

                            foreach (Column.TR_SALE_CPI_RSLT.DATA cTrPluCpi in cSaleItem.alTrSaleCpi)
                            {
                                if (saCpiQtyLmt[0] != cTrPluCpi.CPI_CD) continue;
                                if (cTrPluCpi.DC_SUM_AMT <= 0 || cTrPluCpi.DC_QTY <= 0) continue;

                                WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0658) + PosConst.CRLF
                                    + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0399) + " : " + saCpiQtyLmt[2]);
                                bShowMsg = true;
                                break;
                            }
                            if (bShowMsg == true) break;
                        }
                    }
                }

                if (CheckCampaignDuplication() == false) return 0;      // 캠페인 중복불가 결제 수단 체크

                string sTrgtCustType = "";   // 고객구분(앱여부) :N:일반고객, Y:앱고객
                ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                foreach (Column.TR_ETC.DATA cEtcItem in alEtcItem)
                {
                    if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                    if (cEtcItem.ETC_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT)
                    {
                        sTrgtCustType = cEtcItem.OCCUR_ENTRY_12;
                        break;
                    }
                }

                // 영수증 출력 캠페인 체크
                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    // 캠페인고객혜택=> 영수행사

                    //grayber@20171214 캠페인 리펀드 쿠폰 start
                    // 캠페인 리펀드 구분 추가 - 기존코드 남김
                    if (PosMstManager.GetPosOption(POS_OPTION.OPT431).Equals("1") == true)
                    {
                        if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.RECEIPT && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.REFUND
                        && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.LOTTERY && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.LOTT_REC
                        && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.ENTRY && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.ENTR_REC) continue;
                    }
                    else
                    {
                        if (cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.RECEIPT
                        && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.LOTTERY && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.LOTT_REC
                        && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.ENTRY && cMstSaleCpi.CPI_CUST_BNFT_TYPE != ItemConst.CPI_CUST_BNFT.ENTR_REC) continue;
                    }
                    //grayber@20171214 캠페인 리펀드 쿠폰 end

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;      // 캠페인 적용일자 및 시간 체크

                    // 캠페인 대상 체크
                    if (cMstSaleCpi.TRGT_CUST_TYPE == ItemConst.CPI_TRGT_CUST_TYPE.HPC_CUST)
                    {
                        if (sTrgtCustType == "") continue;
                    }
                    else if (cMstSaleCpi.TRGT_CUST_TYPE == ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP)
                    {
                        if (sTrgtCustType != "Y") continue;
                    }

                    // 캠페인 중복적용 여부(1:중복적용 가능, 0:중복적용 불가)
                    if (ExistCampaignDupApply(cMstSaleCpi.CPI_CUST_BNFT_TYPE, cMstSaleCpi.DUP_APPLY_YN) == true) continue;

                    //#15583 캠페인 기능 개선 요청 start
                    // 캠페인 마스터의 중복 가능 여부 체크
                    // (통신사 제휴 중복 허용 여부, 모바일쿠폰 중복 허용 여부, 해피쿠폰 중복 허용 여부)
                    if (CheckCampaignMstDuplication(cMstSaleCpi) == false) continue;
                    //#15583 캠페인 기능 개선 요청 end

                    // 영수행사 적용방법 => 전체상품, 상품합산
                    long nDisQty = CampaignPluRectPrint(cMstSaleCpi);
                    if (nDisQty == 0) continue;

                    PlayCompleteSound(cMstSaleCpi, false);     // 캠페인 성립시 사운드 출력
                    break;
                }
            }
            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 0;
        }

        /// <summary>
        /// 캠페인 출력데이터 획득(본영수증)
        /// </summary>
        public ArrayList GetCampaignPrintData(string[] aParam)
        {
            ArrayList alPrintBuf = new ArrayList();

            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return alPrintBuf;

                // 수량/횟수 제한 캠페인 메시지 출력
                bool bPrtMsg = false;
                foreach (string[] saCpiQtyLmt in m_alSaleCpiQtyLmt)
                {
                    // 캠페인코드(0), 이전성립수량(1), 캠페인명(2), 제한수량(3), 현성립수량(4)
                    if (CmUtil.LongParse(saCpiQtyLmt[1]) + CmUtil.LongParse(saCpiQtyLmt[4]) <= CmUtil.LongParse(saCpiQtyLmt[3]))
                    {
                        bool bShowMsg = false;
                        foreach (Column.TR_PLU.DATA cSaleItem in m_alTrPluItem)
                        {
                            if (cSaleItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cSaleItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue;// 지정취소
                            if (cSaleItem.alTrSaleCpi == null) continue;

                            foreach (Column.TR_SALE_CPI_RSLT.DATA cTrPluCpi in cSaleItem.alTrSaleCpi)
                            {
                                if (saCpiQtyLmt[0] != cTrPluCpi.CPI_CD) continue;
                                if (cTrPluCpi.DC_SUM_AMT <= 0 || cTrPluCpi.DC_QTY <= 0) continue;

                                alPrintBuf.Add(PosConst.PRT_HDR.PRT_NOR + CmUtil.RPadH(saCpiQtyLmt[2], 30) + CmUtil.LPadH("[" + (CmUtil.LongParse(saCpiQtyLmt[1]) + CmUtil.LongParse(saCpiQtyLmt[4])) + "/" + saCpiQtyLmt[3] + "]", 12));

                                bShowMsg = true;
                                bPrtMsg = true;
                                break;
                            }
                            if (bShowMsg == true) break;
                        }
                    }
                }
                if (bPrtMsg == true) alPrintBuf.Add(PosConst.PRT_HDR.PRT_NOR + "------------------------------------------");

                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // 본영수증에 포힘된 캠페인 정보
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                // 복권 명판 스템프 캠페인 출력 데이터 설정
                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                {
                    if (cTrSaleCpi.CANCEL_DIV == "1") continue;

                    if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.RECEIPT
                        || cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTTERY || cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTT_REC
                        || cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTRY || cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTR_REC)
                    {
                        //#20170807 명판 캠페인 커팅 start
                        if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.RECEIPT) continue;
                        //#20170807 명판 캠페인 커팅 end

                        if (cTrSaleCpi.LTTR_NMPLAT_NO.Trim() != "") continue;

                        // 캠페인 명판 출력정보 획득
                        GetCampaignPrintData("", cTrSaleCpi.CPI_CD, "", "", ref alPrintBuf);
                    }
                    else if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.HP_STAMP)
                    {
                        if (cTrSaleCpi.HP_CAMPAIGN_INFO.Trim() == "") continue;

                        // 스템프 정보 영수증(도식화) 출력
                        GetStampCntPrintData(cTrSaleCpi.CPI_CD, cTrSaleCpi.HP_CAMPAIGN_INFO, cTrSaleCpi.LTTR_NMPLAT_NO, ref alPrintBuf);
                    }
                }

                // 캠페인 안내(설명) 출력 데이터 생성
                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    //grayber@20171214 캠페인 리펀드 쿠폰 start
                    // 캠페인 리펀드 구분자 추가
                    // 캠페인 리펀드가 캠페인 안내 출력 데이터와 합쳐지지 않도록 처리
                    if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.RECEIPT || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.REFUND
                        || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTTERY || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTT_REC
                        || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTRY || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTR_REC
                        || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.HP_STAMP) continue;
                    //기존
                    //if (cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.RECEIPT
                    //    || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTTERY || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTT_REC
                    //    || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTRY || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.ENTR_REC
                    //    || cMstSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.HP_STAMP) continue;
                    //grayber@20171214 캠페인 리펀드 쿠폰 end


                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;      // 캠페인 적용일자 및 시간 체크

                    // 캠페인 안내 출력정보 획득
                     GetCampaignPrintData("", cMstSaleCpi.CPI_CD, "", "", ref alPrintBuf);
                }
                
            }
            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 alPrintBuf;
        }

        

       
        
        //grayber@20171214 캠페인 리펀드 쿠폰 start
        /// <summary>
        /// 캠페인 리펀드 출력데이터 획득(본영수증)
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public ArrayList GetRefundCampaignPrintData(string[] aParam)
        {
            ArrayList alPrintBuf = new ArrayList();
            try
            {
                // POS_OPTION 430 이 활성화 되지 않으면 가져올 필요 없음.
                if (PosMstManager.GetPosOption(POS_OPTION.OPT431).Equals("1") != true) return alPrintBuf;
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return alPrintBuf;

                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                {
                    if (cTrSaleCpi.CANCEL_DIV == "1") continue;
                    if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.REFUND)
                    {
                        GetCampaignPrintData(cTrSaleCpi.CPI_CUST_BNFT_TYPE, cTrSaleCpi.CPI_CD, "", "", ref alPrintBuf);
                    }
                }
            }
            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 alPrintBuf;
        }
        //grayber@20171214 캠페인 리펀드 쿠폰 end

        /// <summary>
        /// 캠페인 출력데이터 획득(별도영수증)
        /// </summary>
        public ArrayList GetCampaignPrintDataAddBill(string[] aParam)
        {
            ArrayList alPrintBuf = new ArrayList();

            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return alPrintBuf;

                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // 별도 영수증 캠페인 정보
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                // 복권 명판 캠페인 출력 데이터 설정
                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in m_alTrSaleCpi)
                {
                    if (cTrSaleCpi.CANCEL_DIV == "1") continue;

                    if (cTrSaleCpi.CPI_CD == aParam[0])
                    {
                        if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.HP_STAMP)
                        {
                            // 캠페인 스템프 쿠폰 출력
                            string sCouponNo = aParam[1];
                            GetStampCouponPrintData(cTrSaleCpi.CPI_CD, sCouponNo, cTrSaleCpi.HP_STAMP_COUPON_INFO, ref alPrintBuf);
                        }
                        else if (cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTTERY || cTrSaleCpi.CPI_CUST_BNFT_TYPE == ItemConst.CPI_CUST_BNFT.LOTT_REC)
                        {
                            // 복권번호
                            if (cTrSaleCpi.LTTR_NMPLAT_NO.Trim() != "")
                            {
                                cTrSaleCpi.DC_QTY = 0;
                                string[] saLTTR_NMPLAT_NO = cTrSaleCpi.LTTR_NMPLAT_NO.Split('|');
                                foreach(string sLTTR_NMPLAT_NO in saLTTR_NMPLAT_NO)
                                {
                                    if ( sLTTR_NMPLAT_NO.Trim() != "")
                                    {
                                        GetCampaignPrintData(cTrSaleCpi.CPI_CUST_BNFT_TYPE, cTrSaleCpi.CPI_CD, sLTTR_NMPLAT_NO, cTrSaleCpi.LTTR_GRADE, ref alPrintBuf);

                                        cTrSaleCpi.DC_QTY++;
                                    }
                                }
                                cTrSaleCpi.LTTR_NMPLAT_NO = saLTTR_NMPLAT_NO[0];
                            }
                        }
                        else
                        {
                            // 캠페인 출력정보 획득
                            GetCampaignPrintData(cTrSaleCpi.CPI_CUST_BNFT_TYPE, cTrSaleCpi.CPI_CD, cTrSaleCpi.LTTR_NMPLAT_NO, cTrSaleCpi.LTTR_GRADE, ref alPrintBuf);
                        }
                    }
                }
            }
            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 alPrintBuf;
        }


        /// <summary>
        /// 고객화면 캠페인 컨텐츠 표시
        /// </summary>
        /// <param name="sPaymentDiv">지불구분(01:신용카드, 02:캐시비, 03:티머니, 98:해피포인트적립, 99:해피포인트결제)</param>
        public void CustDisplayCampaign(string sPaymentDiv)
        {
            try
            {
                foreach (string sCpiCode in m_alMstSaleCpi)
                {
                    Column.MST_SALE_CPI.DATA cMstSaleCpi = (Column.MST_SALE_CPI.DATA)m_htMstSaleCpi[sCpiCode];

                    if (cMstSaleCpi.SOUND_PLAY_YN == true) continue;
                    if (cMstSaleCpi.SOUND_FILE_PLAY_CHK_PNT != "1") continue;      // 1:상품등록, 2:캠페인성립

                    // 행사 조건 체크
                    if (CheckCampaignDateTime(cMstSaleCpi) == false) continue;         // 캠페인 적용일자 및 시간 체크

                    // 캠페인 대상 체크
                    if (sPaymentDiv == "98")            //98:해피포인트적립
                    {
                        // 캠페인 대상 체크
                        if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HPC_CUST && cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HAPPYAPP) continue;
                        
                        // 캠페인 지불구분체크
                        if (cMstSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.NORMAL) continue;
                    }
                    else if (sPaymentDiv == "99")       //99:해피포인트결제
                    {
                        // 해피포인트 결제
                        if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.HPC_PAY) continue;

                        // 캠페인 지불구분체크
                        if (cMstSaleCpi.CUST_PAY_TYPE != ItemConst.CPI_CUST_PAY_TYPE.NORMAL) continue;
                    }
                    else
                    {
                        // 캠페인 대상 체크
                        if (cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.NORMAL && cMstSaleCpi.TRGT_CUST_TYPE != ItemConst.CPI_TRGT_CUST_TYPE.CREDIT_CARD) continue;

                        // 캠페인 지불구분체크
                        if (sPaymentDiv != cMstSaleCpi.CUST_PAY_TYPE) continue;
                    }

                    if (cMstSaleCpi.SOUND_FILE_DIV == "01" || cMstSaleCpi.SOUND_FILE_DIV == "02")
                    {
                        PlayCampaignSound(cMstSaleCpi.SOUND_FILE_DIV, cMstSaleCpi.SOUND_FILE_NM, cMstSaleCpi.TTS_DSCRP);
                    }

                    // 고객화면에 캠페인 안내 이미지 표시
                    if (cMstSaleCpi.CUST_DSP_FILENM.Trim() != "")
                    {
                        m_cCustDisp.DisplayCampaign(cMstSaleCpi.CUST_DSP_FILE_DIV, cMstSaleCpi.CUST_DSP_FILENM);
                    }
                    cMstSaleCpi.SOUND_PLAY_YN = 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);
            }
        }

        /// <summary>
        /// 캠페인 성립시 사운드 출력 처리
        /// </summary>
        /// <param name="cMstSaleCpi"></param>
        /// <returns></returns>
        public void PlayCompleteSound(Column.MST_SALE_CPI.DATA cMstSaleCpi, bool bReSound)
        {
            try
            {
                if (cMstSaleCpi.SOUND_PLAY_YN == true && bReSound == false) return;
                if (cMstSaleCpi.SOUND_FILE_PLAY_CHK_PNT != "2") return;             // 1:상품등록, 2:캠페인성립

                if (cMstSaleCpi.SOUND_FILE_DIV == "01" || cMstSaleCpi.SOUND_FILE_DIV == "02")
                {
                    PlayCampaignSound(cMstSaleCpi.SOUND_FILE_DIV, cMstSaleCpi.SOUND_FILE_NM, cMstSaleCpi.TTS_DSCRP);  
                }

                // 고객화면에 캠페인 안내 이미지 표시
                if (cMstSaleCpi.CUST_DSP_FILENM.Trim() != "")
                {
                    m_cCustDisp.DisplayCampaign(cMstSaleCpi.CUST_DSP_FILE_DIV, cMstSaleCpi.CUST_DSP_FILENM);
                }

                cMstSaleCpi.SOUND_PLAY_YN = 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);
            }
        }

        /// <summary>
        /// 캠페인 음성 출력 처리
        /// </summary>
        public void PlayCampaignSound(string sFielDiv, string sFileName, string sTtsDscrp)
        {
            try
            {
                // 음성 사용 유무(0:미사용, 1:사용)
                if (PosMstManager.GetPosOption(POS_OPTION.OPT309) == "0") return;

                if (sFielDiv == "01")           // 00(없음), 01(WAVE), 02(TTS)
                {
                    string sFilePath = BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CAMPAIGN + sFileName;
                    CmUtil.PlaySound(sFilePath);
                }
                else if (sFielDiv == "02")      // 00(없음), 01(WAVE), 02(TTS)
                {
                    CmUtil.SpeakByTTSEngine(m_cPosStatus.Base.Country, sTtsDscrp, 150);
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }   
     

    }
}
