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

using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using System.Data;
using Newtonsoft.Json;

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 선불카드
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class PrepaidCard : PaymentBase, IPaymentUs
    {

        public PrepaidCard()
        {
        }

        #region SearchPayment 결제 조회
        /// <summary>
        /// 결제 조회
        /// </summary>
        /// <param name="aParam"></param>
        /// <param name="aRet"></param>
        /// <returns></returns>
        public string SearchPayment(string[] aParam, ref string[] aRet)
        {
            string sRet = UserCom.RST_ERR;

            string sPosMenuKey = "", sSaleGbn = "", sInqFlag = "", sCustType = "", sCustID = "", sWcc = "";
            double nBalanceAmt = 0, nPayAmt = 0;

            try
            {

                if (aParam[0] == ItemConst.IRT_INQ_TYPE.PRPAIDCARD_INQ && aParam[1] == "" && aParam[2] == "")
                {
                    //선불 카드 고객 존재 유무 체크 일때!
                    m_cPayItem = new Column.TR_PAYMENT.DATA();                  // 결과 저장 변수 생성
                    m_cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.PPCARD_ITEM;   // 결제 그룹코드
                    m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.PPCARD.PP_CARD;                       // 결제 상세코드

                    sPosMenuKey = aParam[0];                                // 메뉴키
                    sSaleGbn = "0";                                         // 판매구분 (0:정상, 1:반품)
                    sInqFlag = aParam[6];                                   // 조회구분 (0:이름, 1:코드) - 3:선불고객명 서버채번
                    sCustType = "";                                         // 고객구분 (2:개인, 1:법인)
                    sCustID = aParam[4];                                    // 고객 ID
                    sWcc = aParam[5];                                       // 입력구분
                    nBalanceAmt = 0;                                        // 선불잔액 - 사용전
                    nPayAmt = 0;                                            // 금액                 

                    sRet = ExecuteIrtPPCustOnly(PosConst.CANCEL_DIV.NORMAL, sPosMenuKey, sSaleGbn, sWcc, sInqFlag, sCustType, sCustID, nBalanceAmt, nPayAmt, "", "", ref aRet);                    
                }
                else
	            {
                    m_cPayItem = new Column.TR_PAYMENT.DATA();              // 결과 저장 변수 생성

                    sPosMenuKey = aParam[0];                                // 메뉴키
                    m_cPayItem.PAY_WAY_CD = aParam[1];                      // 결제 그룹코드
                    m_cPayItem.PAY_DTL_CD_01 = aParam[2];                   // 결제 상세코드
                    sSaleGbn = "0";                                         // 판매구분 (0:정상, 1:반품)
                    sInqFlag = "0";                                         // 조회구분 (0:이름, 1:코드)
                    sCustType = "";                                         // 고객구분 (2:개인, 1:법인)
                    sCustID = aParam[4];                                    // 고객 ID
                    sWcc = aParam[5];                                       // 입력구분
                    nBalanceAmt = 0;                                        // 선불잔액 - 사용전
                    nPayAmt = 0;                                            // 금액                 

                    sRet = ExecuteIrt(PosConst.CANCEL_DIV.NORMAL, sPosMenuKey, sSaleGbn, sWcc, sInqFlag, sCustType, sCustID, nBalanceAmt, nPayAmt, "", "", ref aRet, "");
	            }

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

        #region 결제 정보 획득
        /// <summary>
        /// 결제 정보 획득
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public object GetPayment(string[] aParam)
        {
            return m_cPayItem;
        }
        #endregion

        #region SetMenualPayment
        public string SetMenualPayment(string[] aParam)
        {
            throw new NotImplementedException();
        }
        #endregion

        #region 결제 등록
        /// <summary>
        /// 결제 등록
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

            try
            {
                m_cPayItem = new Column.TR_PAYMENT.DATA();                  // 결과 저장 변수 생성

                string sPosMenuKey = aParam[0];                             // 메뉴키
                m_cPayItem.PAY_WAY_CD = aParam[1];                          // 결제 그룹코드
                m_cPayItem.PAY_DTL_CD_01 = aParam[2];                       // 결제 상세코드
                string sSaleGbn = "0";                                      // 판매구분 (0:정상, 1:반품)
                string sInqFlag = aParam[3];                                // 거래구분 (0:이름, 1:코드)
                string sCustType = "0";                                     // 고객구분 (0:개인, 1:법인)
                string sCustID = aParam[4];                                 // 고객 ID
                double nBalanceAmt = CmUtil.DoubleParse(aParam[5]);         // 선불잔액-사용전
                double nPayAmt = CmUtil.DoubleParse(aParam[6]);             // 사용금액 
                string sWcc = aParam[7];                                    // 입력구분 
                string sCustName = aParam[8];                               // 고객명

                string[] aRet = null;
                sRet = ExecuteIrt(PosConst.CANCEL_DIV.NORMAL, sPosMenuKey, sSaleGbn, sWcc, sInqFlag, sCustType, sCustID, nBalanceAmt, nPayAmt, "", "", ref aRet, sCustName);
                if (sRet != UserCom.RST_OK) return sRet;

                // 결제 아이템 추가
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);     // 결제 내역 받아 오기
                m_cPayItem.SEQ = alPayItem.Count + 1;
                alPayItem.Add(m_cPayItem);

                m_cDataService.UpdatePluAmount();       // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePayAmount();       // 결제 금액 재 계산 처리

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

        #region 결제 취소
        /// <summary>
        /// 결제 취소
        /// </summary>
        /// <returns></returns>
        public string CancelPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

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

                int nPayRow = CmUtil.IntParse(aParam[0]); // 취소할 행번호

                // 결제 내역 받아 오기
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[nPayRow];

                string sPosMenuKey = ItemConst.IRT_INQ_TYPE.PRPAIDCARD_USE_REQ;                                         // 메뉴키
                string sSaleGbn = "1";                                                                                  // 판매구분 (0:정상, 1:반품)
                string sInqFlag = "1";                                                                                  // 거래구분 (0:이름, 1:코드)
                string sCustType = "0";                                                                                 // 고객구분 (0:개인, 1:법인)
                string sCustID = m_cPayItem.OCCUR_ENTRY_01;                                                             // 고객 ID
                double nBalanceAmt = m_cPayItem.AMT_ENTRY_03;                                                           // 선불잔액 = 사용전 
                double nPayAmt = m_cPayItem.AMT_ENTRY_01;                                                               // 사용금액 
                string sApprNo = m_cPayItem.OCCUR_ENTRY_02;                                                             // 승인번호
                string sApprDT = m_cPayItem.OCCUR_ENTRY_03;                                                             // 승인일자
                string sWcc = m_cPayItem.OCCUR_ENTRY_05 ;                                                               // 입력구분
                string sCustName = m_cPayItem.OCCUR_ENTRY_15;                                                           //  고개명

                string[] aRet = null;
                sRet = ExecuteIrt(PosConst.CANCEL_DIV.CANCEL, sPosMenuKey, sSaleGbn, sWcc, sInqFlag, sCustType, sCustID, nBalanceAmt, nPayAmt, sApprNo, sApprDT, ref aRet, sCustName);
                if (sRet != UserCom.RST_OK) return sRet;

                m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;

                m_cDataService.UpdatePluAmount();       // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePayAmount();       // 결제 금액 재 계산 처리

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

        #region 결제 반품
        /// <summary>
        /// 결제 반품
        /// </summary>
        /// <returns></returns>
        public string RefundPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

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

                int nPayRow = CmUtil.IntParse(aParam[0]); // 취소할 행번호

                // 결제 내역 받아 오기
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[nPayRow];

                if (m_cPayItem.OCCUR_ENTRY_08.ToString() != ItemConst.PAY_APP_DIV.NORMAL)
                {
                    //임의 등록 이면 승인 없이 데이터 처리
                    //WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0240));
                    m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;
                    m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;

                    sRet = UserCom.RST_OK;
                }
                else
                {
                    string sPosMenuKey = ItemConst.IRT_INQ_TYPE.PRPAIDCARD_USE_REQ;                                         // 메뉴키
                    string sSaleGbn = "1";                                                                                  // 판매구분 (0:정상, 1:반품)
                    string sInqFlag = "1";                                                                                  // 거래구분 (0:이름, 1:코드)
                    string sCustType = "0";                                                                                 // 고객구분 (0:개인, 1:법인)
                    string sCustID = m_cPayItem.OCCUR_ENTRY_01;                                                             // 고객 ID
                    double nBalanceAmt = m_cPayItem.AMT_ENTRY_03;                                                           // 선불잔액 = 사용전 
                    double nPayAmt = m_cPayItem.AMT_ENTRY_01;                                                               // 사용금액 
                    string sApprNo = m_cPayItem.OCCUR_ENTRY_02;                                                             // 승인번호
                    string sApprDT = m_cPayItem.OCCUR_ENTRY_03;                                                             // 승인일자
                    string sWcc = m_cPayItem.OCCUR_ENTRY_05;                                                                // 입력구분
                    string sCustName = m_cPayItem.OCCUR_ENTRY_15;                                                           //  고개명

                    string[] aRet = null;
                    sRet = ExecuteIrt(PosConst.CANCEL_DIV.CANCEL, sPosMenuKey, sSaleGbn, sWcc, sInqFlag, sCustType, sCustID, nBalanceAmt, nPayAmt, sApprNo, sApprDT, ref aRet, sCustName);
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }
        #endregion

        #region 조회 실행
        /// <summary>
        /// 조회 실행
        /// </summary>
        public string ExecuteIrt(string sTradeDiv, string sPosMenuKey, string sSaleGbn, string sWcc, string sInqFlag, string sCustType, string sCustID, double nBalanceAmt, double nPayAmt, string sOrgApprNo, string sOrgApprDT, ref string[] aRet, string sCustName)
        {
            string sRet = UserCom.RST_ERR;
            string sApprNo = "";
            string sApprDT = "";
            string sApprTime = ""; 

            Hashtable htRecvData = new Hashtable();

            try
            {
                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1")
                {    // 조회시
                    if (sPosMenuKey == ItemConst.IRT_INQ_TYPE.PRPAIDCARD_INQ || sPosMenuKey == ItemConst.IRT_INQ_TYPE.SALEONCREDIT_CUSTINQ)
                        aRet = new string[] { "" };
                    return SetTrainingData(sPosMenuKey, sSaleGbn, sWcc, sInqFlag, sCustType, sCustID, nBalanceAmt, nPayAmt, sOrgApprNo, sOrgApprDT, sCustName);
                }

                // 조회
                sRet = ExecuteHostIrt(sTradeDiv, sPosMenuKey, sSaleGbn, sInqFlag, sCustType, sCustID, nPayAmt, sOrgApprNo, sOrgApprDT, ref htRecvData);
                if (sRet != UserCom.RST_OK) return sRet;

                if (sPosMenuKey == ItemConst.IRT_INQ_TYPE.PRPAIDCARD_INQ || sPosMenuKey == ItemConst.IRT_INQ_TYPE.SALEONCREDIT_CUSTINQ)
                {    // 조회시
                    aRet = htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.CUSTOMER_VALUE].ToString().Split(new string[] { "#~" }, StringSplitOptions.None);
                }
                else
                {
                    // 승인시
                    sApprNo = htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.APPR_NO].ToString();                                // 승인번호
                    sApprDT = CmUtil.MidH(htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.APPR_DT].ToString(), 0, 8);             // 승인일자
                    sApprTime = CmUtil.MidH(htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.APPR_DT].ToString(), 8, 6);           // 승인시간 
                    nBalanceAmt = CmUtil.DoubleParse(htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.BALANCE_AMT].ToString());    // 사용후 잔액
                    nPayAmt = CmUtil.DoubleParse(htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.SALE_AMT].ToString());           // 요청금액 
                }

                // 결제구분 (1:결제, 2:할인)
                DataRow dr = PosMstManager.GetMstPayDc(new string[] { m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01 });
                 
                m_cPayItem.PAY_AMT = nPayAmt;

                m_cPayItem.PAY_DTL_CD_02 = "";                                                                          // 캠페인코드
                m_cPayItem.PAY_DTL_CD_03 = "0";                                                                         // 할인금액 아이템 적용 여부 (0:미적용, 1:적용)
                m_cPayItem.PAY_DTL_CD_04 = "";                                                                          // 상품코드
                m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;                                                    // 할인결제구분 (1:결제, 2:할인)

                m_cPayItem.QTY_ENTRY_01 = 0;                                                                            // 수량
                m_cPayItem.QTY_ENTRY_02 = 0;    
                m_cPayItem.QTY_ENTRY_03 = 0;
                m_cPayItem.QTY_ENTRY_04 = 0;
                m_cPayItem.QTY_ENTRY_05 = 0;

                m_cPayItem.AMT_ENTRY_01 = nPayAmt;                                                                      // 받은돈
                m_cPayItem.AMT_ENTRY_02 = 0;                                                                            // 거스름
                if (sTradeDiv == PosConst.CANCEL_DIV.CANCEL)
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleSubtraction(nBalanceAmt,  nPayAmt);                                  // 선불잔액-사용전
                else
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleAdd(nBalanceAmt, nPayAmt);                                   // 선불잔액-사용전

                m_cPayItem.AMT_ENTRY_04 = nBalanceAmt;                                                                  // 선불잔액-사용후
                m_cPayItem.AMT_ENTRY_05 = 0;
                m_cPayItem.AMT_ENTRY_08 = 0;
                m_cPayItem.AMT_ENTRY_09 = 0;
                m_cPayItem.AMT_ENTRY_10 = 0;

                m_cPayItem.OCCUR_ENTRY_01 = sCustID;                                                                    // 카드번호
                m_cPayItem.OCCUR_ENTRY_02 = sApprNo;                                                                    // 승인번호
                m_cPayItem.OCCUR_ENTRY_03 = sApprDT;                                                                    // 승인일자
                m_cPayItem.OCCUR_ENTRY_04 = sApprTime;                                                                  // 승인시간
                m_cPayItem.OCCUR_ENTRY_05 = sWcc;                                                                       // 입력 구분
                m_cPayItem.OCCUR_ENTRY_06 = sOrgApprNo;                                                                 // 원승인번호
                m_cPayItem.OCCUR_ENTRY_07 = sOrgApprDT;                                                                 // 원승인일자
                m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL;                                               // 승인구분
                m_cPayItem.OCCUR_ENTRY_10 = "";                                                                         //  
                m_cPayItem.OCCUR_ENTRY_11 = "";                                                                         //  
                m_cPayItem.OCCUR_ENTRY_12 = "";                                                                         //  
                m_cPayItem.OCCUR_ENTRY_13 = "";                                                                         //
                m_cPayItem.OCCUR_ENTRY_15 = sCustName;                                                                  //  고개명
                m_cPayItem.OCCUR_ENTRY_16 = CmUtil.GetDataRowStr(dr, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);              // VAN 구분
                m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                m_cPayItem.OCCUR_ENTRY_22 = "";
                m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;                                                  // 빌분리 번호

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

        /// <summary>
        /// 연습 데이터 설정
        /// </summary>
        public string SetTrainingData(string sPosMenuKey, string sSaleGbn, string sWcc, string sInqFlag, string sCustType, string sCustID, double nBalanceAmt, double nPayAmt, string sOrgApprNo, string sOrgApprDT, string sCustName)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                // 연습모드이면 연습 데이터 설정

                // 결제구분 (1:결제, 2:할인)
                DataRow dr = PosMstManager.GetMstPayDc(new string[] { m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01 });

                m_cPayItem.PAY_AMT = nPayAmt;

                m_cPayItem.PAY_DTL_CD_02 = "";                                                                          // 캠페인코드
                m_cPayItem.PAY_DTL_CD_03 = "0";                                                                         // 할인금액 아이템 적용 여부 (0:미적용, 1:적용)
                m_cPayItem.PAY_DTL_CD_04 = "";                                                                          // 상품코드
                m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;                                                    // 할인결제구분 (1:결제, 2:할인)

                m_cPayItem.QTY_ENTRY_01 = 0;                                                                            // 수량
                m_cPayItem.QTY_ENTRY_02 = 0;
                m_cPayItem.QTY_ENTRY_03 = 0;
                m_cPayItem.QTY_ENTRY_04 = 0;
                m_cPayItem.QTY_ENTRY_05 = 0;

                m_cPayItem.AMT_ENTRY_01 = nPayAmt;                                                                      // 받은돈
                m_cPayItem.AMT_ENTRY_02 = 0;                                                                            // 거스름돈
                m_cPayItem.AMT_ENTRY_03 = nBalanceAmt;                                                                  // 선불잔액-사용전                                                           
                m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleSubtraction(nBalanceAmt, nPayAmt);                               // 선불잔액-사용후
                m_cPayItem.AMT_ENTRY_05 = 0;
                m_cPayItem.AMT_ENTRY_08 = 0;
                m_cPayItem.AMT_ENTRY_09 = 0;
                m_cPayItem.AMT_ENTRY_10 = 0;

                m_cPayItem.OCCUR_ENTRY_01 = sCustID;                                                                    // 카드번호
                m_cPayItem.OCCUR_ENTRY_02 = "99999999";                                                                 // 승인번호
                m_cPayItem.OCCUR_ENTRY_03 = DateTime.Now.ToString("yyMMdd");                                            // 승인일자
                m_cPayItem.OCCUR_ENTRY_04 = DateTime.Now.ToString("HHmm");                                              // 승인시간
                m_cPayItem.OCCUR_ENTRY_05 = sWcc;                                                                       // 입력 구분
                m_cPayItem.OCCUR_ENTRY_06 = sOrgApprNo;                                                                 // 원승인번호
                m_cPayItem.OCCUR_ENTRY_07 = sOrgApprDT;                                                                 // 원승인일자
                m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.COMPULSION;                                           // 승인구분
                m_cPayItem.OCCUR_ENTRY_10 = "";                                                                         // 조회구분(0:이름, 1:코드)
                m_cPayItem.OCCUR_ENTRY_11 = "";                                                                         // 고객형태(0:개인, 1:법인) 
                m_cPayItem.OCCUR_ENTRY_12 = "";                                                                         //  
                m_cPayItem.OCCUR_ENTRY_13 = "";                                                                         //  
                m_cPayItem.OCCUR_ENTRY_15 = sCustName;                                                                  //  고개명
                m_cPayItem.OCCUR_ENTRY_16 = CmUtil.GetDataRowStr(dr, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);              // VAN 구분
                m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                m_cPayItem.OCCUR_ENTRY_22 = "";

                m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;                                                // 취소여부
                m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;                                                  // 빌분리 번호

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

        #region Host 조회 실행
        /// <summary>
        /// Host 조회 실행
        /// </summary>
        public string ExecuteHostIrt(string sTradeDiv, string sPosMenuKey, string sSaleGbn, string sInqFlag, string sCustType, string sCustID, double nSaleAmt, string sApprNo, string sApprDT, ref Hashtable htRecvData)
        {
            int iRecvTimeOut = 10000; 
            string sRet = UserCom.RST_ERR;

            Hashtable htSendData = new Hashtable();

            try
            {
                if (m_cPayItem.PAY_WAY_CD != ItemConst.TR_ITEM_ID.PPCARD_ITEM ) return null;

                if (sPosMenuKey == ItemConst.IRT_INQ_TYPE.PRPAIDCARD_INQ || sPosMenuKey == ItemConst.IRT_INQ_TYPE.SALEONCREDIT_CUSTINQ)
                {
                    // 조회
                    htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.INQ_TYPE, sPosMenuKey);
                    

                    //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 start, phj
                    //기존
                    //htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.STOR_CD, m_cPosStatus.Base.StoreNo);
                    //변경
                    htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.STOR_CD, m_cPosStatus.Base.SubShopNo);
                    //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 end, phj

                    htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.INQ_FLAG, sInqFlag);
                    htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.CUSTOMER_TY, sCustType);
                    htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.CUSTOMER_ID, sCustID);

                    // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                    m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sPosMenuKey, "S", sCustID, nSaleAmt.ToString(), "", "", "", "", "", JsonConvert.SerializeObject(htSendData) });

                    sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.POSIRT, m_cPosStatus.Base.CommSvrIp, (int)m_cPosStatus.Base.PayInqPort, iRecvTimeOut, htSendData, ref htRecvData);
                    if (sRet != UserCom.RST_OK)
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0214));

                        sRet = UserCom.RST_ERR;
                        return sRet;
                    }

                    // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                    m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sPosMenuKey, "R"
                                                            , sCustID, nSaleAmt.ToString()
                                                            , "", "", ""
                                                            , htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.RES_CD].ToString()
                                                            , ""
                                                            , JsonConvert.SerializeObject(htRecvData) });

                    if (htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.RES_CD].ToString() != "00")
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0214) + " (" + htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.RES_CD].ToString() + ")" + "\n\r");

                        sRet = UserCom.RST_ERR;
                        return sRet;
                    }
                }
                else if (sPosMenuKey == ItemConst.IRT_INQ_TYPE.PRPAIDCARD_USE_REQ)
                {
                    // 사용
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.INQ_TYPE, sPosMenuKey);
                    

                    //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 start, phj
                    //기존
                    //htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.STOR_CD, m_cPosStatus.Base.StoreNo);
                    //변경
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.STOR_CD, m_cPosStatus.Base.SubShopNo);
                    //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 end, phj


                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.POS_NO, m_cPosStatus.Base.PosNo);
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.SALE_DT, m_cPosStatus.Base.SaleDate);
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.REG_NO, m_cPosStatus.Base.RegNo);
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.SALE_GBN, sSaleGbn);
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.CUST_ID, sCustID);
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.SALE_AMT, nSaleAmt.ToString());
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.APPR_NO, sApprNo);
                    htSendData.Add(Column.IQ_PREPAIDCARD_USE_REQ.DATA.APPR_DT, sApprDT);

                    // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                    m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sPosMenuKey, "S", sCustID, nSaleAmt.ToString(), "", "", "", "", "", JsonConvert.SerializeObject(htSendData) });

                    sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.POSIRT, m_cPosStatus.Base.CommSvrIp, (int)m_cPosStatus.Base.BizInqPort, iRecvTimeOut, htSendData, ref htRecvData);
                    if (sRet != UserCom.RST_OK)
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0223));

                        sRet = UserCom.RST_ERR;
                        return sRet;
                    }

                    // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                    m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sPosMenuKey, "R"
                                                            , sCustID, nSaleAmt.ToString()
                                                            , htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.APPR_NO].ToString(), CmUtil.MidH(htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.APPR_DT].ToString(), 0, 8), CmUtil.MidH(htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.APPR_DT].ToString(), 8, 6)
                                                            , htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.RES_CD].ToString()
                                                            , htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.RES_MSG].ToString()
                                                            , JsonConvert.SerializeObject(htRecvData) });

                    if (htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.RES_CD].ToString() != "00" && htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.RES_CD].ToString() != "02")
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0223) + " (" + htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.RES_CD].ToString() + ")" + "\n\r" + htRecvData[Column.IQ_PREPAIDCARD_USE_RSP.DATA.RES_MSG].ToString());

                        sRet = UserCom.RST_ERR;
                        return sRet;
                    }
                }


                sRet = UserCom.RST_OK;
                return sRet;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }
        #endregion
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sPosMenuKey"></param>
        /// <param name="sSaleGbn"></param>
        /// <param name="sWcc"></param>
        /// <param name="sInqFlag"></param>
        /// <param name="sCustType"></param>
        /// <param name="sCustID"></param>
        /// <param name="nBalanceAmt"></param>
        /// <param name="nPayAmt"></param>
        /// <param name="sOrgApprNo"></param>
        /// <param name="sOrgApprDT"></param>
        /// <param name="aRet"></param>
        /// <returns></returns>
        private string ExecuteIrtPPCustOnly(string sTradeDiv, string sPosMenuKey, string sSaleGbn, string sWcc, string sInqFlag, string sCustType, string sCustID, double nBalanceAmt, double nPayAmt, string sOrgApprNo, string sOrgApprDT, ref string[] aRet)
        {
            string sRet = UserCom.RST_ERR;
            int iRecvTimeOut = 10000; 

            Hashtable htRecvData = new Hashtable();
            Hashtable htSendData = new Hashtable();
            
            try
            {
                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1")
                {
                    aRet[0] = "01";
                    return UserCom.RST_OK;
                }
                
                // 조회
                htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.INQ_TYPE, sPosMenuKey);
                

                //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 start, phj
                //기존
                //htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.STOR_CD, m_cPosStatus.Base.StoreNo);
                //변경
                htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.STOR_CD, m_cPosStatus.Base.SubShopNo);
                //#20171016 스퀘어 점포일 때 실점포 코드로 넘기기 end, phj

                htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.INQ_FLAG, sInqFlag);
                htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.CUSTOMER_TY, sCustType);
                htSendData.Add(Column.IQ_SALEONCREDIT_CUSTINQ_REQ.DATA.CUSTOMER_ID, sCustID);
                
                // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sPosMenuKey, "S", sCustID, nPayAmt.ToString(), "", "", "", "", "", JsonConvert.SerializeObject(htSendData) });

                sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.POSIRT, m_cPosStatus.Base.CommSvrIp, (int)m_cPosStatus.Base.PayInqPort, iRecvTimeOut, htSendData, ref htRecvData);
                if (sRet != UserCom.RST_OK)
                {
                    WinManager.ErrorMessage(sRet);
                    sRet = UserCom.RST_ERR;
                    return sRet;
                }
                aRet = new string[] { htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.RES_CD].ToString(), htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.CUSTOMER_VALUE].ToString() };

                // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sPosMenuKey, "R"
                                                            , sCustID, "0"
                                                            , "", "", ""
                                                            , htRecvData[Column.IQ_SALEONCREDIT_CUSTINQ_RSP.DATA.RES_CD].ToString()
                                                            , ""
                                                            , JsonConvert.SerializeObject(htRecvData)  });

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

    }
}
