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

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 제휴포인트 사용(OCB,OILBANK,BLUE MEMBER...)
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class PointMemberUse : PaymentBase, IPaymentUs
    {
        private IOCBDirect m_OCBDirect = null;

        public PointMemberUse()
        {
            m_OCBDirect = (IOCBDirect)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.OCB_DIRECT);
        }

        #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 = "", sInPutType = "", sInPutData = "", sCardData = "";
            try
            {
                sPosMenuKey = aParam[0];                     // 메뉴키
                sInPutType = aParam[1];                      // 입력구분
                sInPutData = aParam[2];                      // 입력데이터
                sCardData = aParam[3];                       // 카드데이터
                
                string sPointType = GetMenuKeyToPointType(sPosMenuKey);

                m_cPayItem = new Column.TR_PAYMENT.DATA();      // 결과 저장 변수 생성
                m_cPayItem.PAY_WAY_CD = GetMenuKeyToPayWayCd(sPosMenuKey);
                m_cPayItem.PAY_DTL_CD_01 = GetMenuKeyToPayDtlCd(sPosMenuKey);

                if (sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                {
                    sRet = ExecutePointOCBDirectIrt(PosConst.CANCEL_DIV.NORMAL, PosConst.POS_OCB_DIRECT.INQ_POINT, sInPutType, sInPutData, sCardData, "", m_cTrnStatus.Sale.NetSaleAmt, "", "", "");
                }
                else
                {
                    sRet = ExecutePointMemberUseIrt(PosConst.CANCEL_DIV.NORMAL, PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_QRY_A, sPointType, sInPutType, sInPutData, sCardData, 0, 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);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sCardData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

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

        #region SetPayment 결제 등록
        /// <summary>
        /// 결제 등록(제휴 포인트 사용)
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            string sPosMenuKey = "", sInPutType = "", sInPutData = "", sInEncData = "";

            try
            {

                double nApprAmt = 0;
                m_cPayItem = new Column.TR_PAYMENT.DATA();      // 결과 저장 변수 생성

                if (aParam.Length > 0 && aParam[0] == PosConst.POS_CAT_MASTER.TRAN_TYPE)    //단말기승인
                {
                    nApprAmt = CmUtil.DoubleParse(aParam[3]);        // 대상금액

                    m_cPayItem.PAY_WAY_CD = GetMenuKeyToPayWayCd(aParam[12]);
                    m_cPayItem.PAY_DTL_CD_01 = GetMenuKeyToPayDtlCd(aParam[12]);

                    sRet = CatExecuteIrt(aParam[1], aParam);
                    if (sRet != UserCom.RST_OK) return sRet;
                }
                else
                {

                    sPosMenuKey = aParam[0];                     // 메뉴키
                    sInPutType = aParam[1];                      // 입력구분
                    sInPutData = aParam[2];                      // 입력데이터
                    sInEncData = aParam[3];                      // 카드데이터

                    double nDestAmt = CmUtil.DoubleParse(aParam[4]);    // 대상금액
                    string sPassWord = aParam[5];                // 비밀번호

                    string sPointType = GetMenuKeyToPointType(sPosMenuKey);

                    
                    m_cPayItem.PAY_WAY_CD = GetMenuKeyToPayWayCd(sPosMenuKey);
                    m_cPayItem.PAY_DTL_CD_01 = GetMenuKeyToPayDtlCd(sPosMenuKey);

                    nApprAmt = nDestAmt;
                    if (sPointType == "BLU") 
                    {
                        nApprAmt = m_cDataCommon.ExecTermCoopCmpPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, "", nDestAmt);
                        if (sPointType == "BLU")
                        {
                            // 블루 레드 멤버스 승인 금액 100원 단위 절삭 처리
                            nApprAmt = CmUtil.MathRounds(nApprAmt, PosConst.MATH_ROUND.TRANCATE, -2);
                        }
                    }

                    // 현대오일뱅크 할인 조회, 그외 포인트 사용 
                    string sTrType = sPointType == "HOB" ? PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_DIS_A : PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_A;

                    if (sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                    {
                        sRet = ExecutePointOCBDirectIrt(PosConst.CANCEL_DIV.NORMAL, PosConst.POS_OCB_DIRECT.USE_POINT, sInPutType, sInPutData, sInEncData, sPassWord, nApprAmt, "", "", "");
                    }
                    else
                    {
                        sRet = ExecutePointMemberUseIrt(PosConst.CANCEL_DIV.NORMAL, sTrType, sPointType, sInPutType, sInPutData, sInEncData, nDestAmt, nApprAmt, sPassWord, "", "");
                    }
                    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);

                if (m_cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.DC)
                {
                    // 상품아이템에 할인금액 설정
                    SetPluDiscountAmount(-1, m_cPayItem.PAY_WAY_CD + m_cPayItem.PAY_DTL_CD_01, "", m_cPayItem.PAY_AMT);
                }

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

                //WinManager.ConfirmMessage(sPointType + " " + MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0067));
            }
            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
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region CancelPayment 결제 취소
        /// <summary>
        /// 결제 취소
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string CancelPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            string sInPutType = "", sInPutData = "", sInEncData = "";

            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.CAT_TERMINAL)
                {

                    string[] m_aParam = new string[15];

                    //InParam
                    // 0.전문구분,1.거래유형, 2.할부개월, 3.승인금액 , 4.봉사료, 5.세금, 6.원승인번호, 7.원거래일자, 8.포인트거래구분, 9.상품코드,
                    //10.전표인쇄여부,11.추가항목,12.제휴할인코드,13.제휴할인금액,14.예비1

                    string sAppId = PosConst.POS_CAT_MASTER.TRADE_ID.CAT_POINT_USE_CANCEL;

                    m_aParam[0] = PosConst.POS_CAT_MASTER.TRAN_TYPE;
                    m_aParam[1] = sAppId;
                    m_aParam[2] = "00";
                    m_aParam[3] = m_cPayItem.PAY_AMT.ToString();
                    m_aParam[4] = "0"; //봉사료
                    m_aParam[5] = "0"; //세금
                    m_aParam[6] = m_cPayItem.OCCUR_ENTRY_02;
                    m_aParam[7] = m_cPayItem.OCCUR_ENTRY_03;
                    m_aParam[8] = "";
                    m_aParam[9] = "";
                    m_aParam[10] = "";
                    m_aParam[11] = "";
                    m_aParam[12] = "";
                    m_aParam[13] = "";
                    m_aParam[14] = "";

                    sRet = CatExecuteIrt(m_aParam[1], m_aParam);
                    if (sRet != UserCom.RST_OK) return sRet;
                }
                else
                {

                    sInPutType = m_cPayItem.OCCUR_ENTRY_05;          // 입력구분
                    sInPutData = m_cPayItem.OCCUR_ENTRY_01;          // 입력데이터
                    sInEncData = m_cPayItem.CanFiller1;              // 카드데이터

                    if (m_cPayItem.OCCUR_ENTRY_08.ToString() == ItemConst.PAY_APP_DIV.COMPULSION)
                    {
                        m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;              // 원승인번호
                        m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;              // 원승인일자
                    }
                    else
                    {
                        double nDestAmt = m_cPayItem.AMT_ENTRY_10;              // 대상금액
                        double nApprAmt = m_cPayItem.PAY_AMT;                   // 승인금액
                        string sApprDate = m_cPayItem.OCCUR_ENTRY_03;           // 승인일자
                        string sApprNo = m_cPayItem.OCCUR_ENTRY_02;             // 승인번호

                        string sPointType = GetPayDtlCdToPointType(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);
                        string sTrType = sPointType == "HOB" ? PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_DIS_C : PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_C;
                        if (sPointType == "HOB") nApprAmt = m_cPayItem.AMT_ENTRY_10;

                        if (sPointType == "OCB" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                        {
                            sRet = ExecutePointOCBDirectIrt(PosConst.CANCEL_DIV.CANCEL, PosConst.POS_OCB_DIRECT.USE_CAN_POINT, sInPutType, sInPutData, sInEncData, "", nApprAmt, sApprDate, sApprNo, m_cPayItem.OCCUR_ENTRY_17);
                        }
                        else
                        {
                            sRet = ExecutePointMemberUseIrt(PosConst.CANCEL_DIV.CANCEL, sTrType, sPointType, sInPutType, sInPutData, sInEncData, nDestAmt, nApprAmt, "", sApprDate, sApprNo);
                        }
                        if (sRet != UserCom.RST_OK) return sRet;
                    }
                }
                if (m_cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.DC)
                {
                    ClearPluDiscountAmount(m_cPayItem.PAY_WAY_CD + m_cPayItem.PAY_DTL_CD_01, "");        // 할인금액 삭제
                }

                m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;

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

                //WinManager.ConfirmMessage(sPointType + " " + MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0068));
                // 여전법 대응 ///////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
                //////////////////////////////////////////////////////////////////////////////////
                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);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region RefundPayment 결제 반품
        /// <summary>
        /// 결제 반품
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string RefundPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            string sInPutType = "", sInPutData = "", sInEncData = "";

            try
            {
                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.CAT_TERMINAL)
                {

                    string[] m_aParam = new string[15];

                    //InParam
                    // 0.전문구분,1.거래유형, 2.할부개월, 3.승인금액 , 4.봉사료, 5.세금, 6.원승인번호, 7.원거래일자, 8.포인트거래구분, 9.상품코드,
                    //10.전표인쇄여부,11.추가항목,12.제휴할인코드,13.제휴할인금액,14.예비1

                    string sAppId = PosConst.POS_CAT_MASTER.TRADE_ID.CAT_POINT_USE_CANCEL;

                    m_aParam[0] = PosConst.POS_CAT_MASTER.TRAN_TYPE;
                    m_aParam[1] = sAppId;
                    m_aParam[2] = "00";
                    m_aParam[3] = m_cPayItem.PAY_AMT.ToString();
                    m_aParam[4] = "0"; //봉사료
                    m_aParam[5] = "0"; //세금
                    m_aParam[6] = m_cPayItem.OCCUR_ENTRY_02;
                    m_aParam[7] = m_cPayItem.OCCUR_ENTRY_03;
                    m_aParam[8] = "";
                    m_aParam[9] = "";
                    m_aParam[10] = "";
                    m_aParam[11] = "";
                    m_aParam[12] = "";
                    m_aParam[13] = "";
                    m_aParam[14] = "";

                    sRet = CatExecuteIrt(m_aParam[1], m_aParam);
                    if (sRet != UserCom.RST_OK) return sRet;
                }
                else
                {
                    sInPutType = m_cPayItem.OCCUR_ENTRY_05;          // 입력구분
                    sInPutData = m_cPayItem.OCCUR_ENTRY_01;          // 입력데이터(마스킹)
                    sInEncData = m_cPayItem.CanFiller1;              // 카드데이터(암호화)

                    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;              // 원승인일자
                    }
                    else
                    {
                        double nDestAmt = m_cPayItem.AMT_ENTRY_10;              // 대상금액
                        double nApprAmt = m_cPayItem.PAY_AMT;                   // 승인금액
                        string sApprDate = m_cPayItem.OCCUR_ENTRY_03;           // 승인일자
                        string sApprNo = m_cPayItem.OCCUR_ENTRY_02;             // 승인번호

                        string sPointType = GetPayDtlCdToPointType(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);
                        string sTrType = sPointType == "HOB" ? PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_DIS_C : PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_C;
                        if (sPointType == "HOB") nApprAmt = m_cPayItem.AMT_ENTRY_10;

                        if (sPointType == "OCB" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                        {
                            sRet = ExecutePointOCBDirectIrt(PosConst.CANCEL_DIV.CANCEL, PosConst.POS_OCB_DIRECT.USE_CAN_POINT, sInPutType, sInEncData, sInEncData, "", nApprAmt, sApprDate, sApprNo, m_cPayItem.OCCUR_ENTRY_17);
                        }
                        else
                        {
                            sRet = ExecutePointMemberUseIrt(PosConst.CANCEL_DIV.CANCEL, sTrType, sPointType, sInPutType, sInPutData, sInEncData, nDestAmt, nApprAmt, "", sApprDate, sApprNo);
                        }
                        if (sRet != UserCom.RST_OK) return sRet;
                    }
                }

                // 여전법 대응 ///////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
                //////////////////////////////////////////////////////////////////////////////////
                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);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region 제휴 포인트 수기 수기승인
        /// <summary>
        /// 수기 승인
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetMenualPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            string sPosMenuKey = "", sInPutType = "", sInPutData = "", sInEncData = "";

            try
            {
                sPosMenuKey = aParam[0];                     // 메뉴키
                sInPutType = aParam[1];                      // 입력구분
                sInPutData = aParam[2];                      // 입력데이터
                sInEncData = aParam[3];                      // 카드데이터
                
                double nDestAmt = CmUtil.DoubleParse(aParam[4]);    // 대상금액
                string sPassWord = aParam[5];                       // 비밀번호

                string sPointType = GetMenuKeyToPointType(sPosMenuKey);

                m_cPayItem = new Column.TR_PAYMENT.DATA();      // 결과 저장 변수 생성
                m_cPayItem.PAY_WAY_CD = GetMenuKeyToPayWayCd(sPosMenuKey);
                m_cPayItem.PAY_DTL_CD_01 = GetMenuKeyToPayDtlCd(sPosMenuKey);

                double nApprAmt = nDestAmt;
                if (sPointType == "BLU")  //|| sPointType == "HOB")
                {
                    nApprAmt = m_cDataCommon.ExecTermCoopCmpPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, "", nDestAmt);
                    if (sPointType == "BLU")
                    {
                        // 블루 레드 멤버스 승인 금액 100원 단위 절삭 처리
                        nApprAmt = CmUtil.MathRounds(nApprAmt, PosConst.MATH_ROUND.TRANCATE, -2);
                    }
                }                

                sRet = SetTrainingData(PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_A, sPointType, sInPutType, sInPutData, sInEncData, nDestAmt, nApprAmt, sPassWord, "", "", "");
                if (sRet != UserCom.RST_OK) return sRet;

                m_cPayItem.PAY_AMT = nApprAmt;   // 사용포인트(할인금액)
                m_cPayItem.AMT_ENTRY_01 = m_cPayItem.PAY_AMT; // 사용포인트(할인금액)
                m_cPayItem.AMT_ENTRY_03 = 0;    // 총포인트
                m_cPayItem.AMT_ENTRY_04 = 0;    // 가용포인트(할인후결제금액)
                m_cPayItem.AMT_ENTRY_05 = 0;    // 잔여포인트

                m_cPayItem.OCCUR_ENTRY_02 = "";                                 // 승인번호
                m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.COMPULSION;   // 승인구분

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

                if (m_cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.DC)
                {
                    // 상품아이템에 할인금액 설정
                    SetPluDiscountAmount(-1, m_cPayItem.PAY_WAY_CD + m_cPayItem.PAY_DTL_CD_01, "", m_cPayItem.PAY_AMT);
                }

                m_cDataService.UpdatePluAmount();       // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePayAmount();       // 결제 금액 재 계산 처리
            }
            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
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region 제휴포인트 조회
        /// <summary>
        /// 제휴포인트 조회
        /// </summary>
        public string ExecutePointMemberUseIrt(string sTradeDiv, string sTrType, string sPointType, string sInPutType, string sInPutData, string sInEncData, double nDestAmt, double nApprAmt, string sPassWord, string sApprDate, string sApprNo)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (sInPutData.Length >= 6) sInPutData = sInPutData.Substring(0, 6).PadRight(sInPutData.Length, '*');

                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1" ) return SetTrainingData(sTrType, sPointType, sInPutType, sInPutData, sInEncData, nDestAmt, nApprAmt, sPassWord, sApprDate, sApprNo, "");

                string sAddInfo = "";
                if (sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_A || sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_C)
                {
                    // 사용,사용취소
                    sAddInfo += "N";                                            // 쿠폰거래유무
                    sAddInfo += CmUtil.RPadH("", 10);                           // 요청 사용자 ID
                    sAddInfo += CmUtil.RPadH(m_cPosStatus.Base.SaleDate, 8);    // POS 영업일자 - POS 매출일자 8자리
                    sAddInfo += "2001";                                         // 거래사유코드 - 2001:대금결제
                    sAddInfo += CmUtil.RPadH(m_cPosStatus.Base.SaleDate, 10);   // SAP 코드 - POS 매출일자 10자리
                    sAddInfo += CmUtil.RPadH(m_cPosStatus.Base.PosNo, 2);       // POS 번호
                    sAddInfo += string.Format("{0:D10}", (long)nDestAmt);       // 사용대상거래금액
                    sAddInfo += CmUtil.RPadH("", 20);                           // 결제카드번호 - 신용 결제한 카드번호
                    sAddInfo += CmUtil.RPadH("", 135); ;                        // VReserved
                }

                string sVanCD = GetPayDtlCdToVanCode(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);    // 승인업체 코드 조회
                if (sVanCD == "")
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0563);
                    return sRet;
                }

                // 포인트 조회,사용,사용취소
                string[] aIrtRsp = null;
                sRet = ExecutePointIrt(sTradeDiv, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sVanCD, sTrType, sPointType, sInPutType, sInPutData, sInEncData, nApprAmt, sApprDate, sApprNo, sPassWord, "", "", "", sAddInfo, ref aIrtRsp, "", "");
                if (sRet != UserCom.RST_OK) return sRet;

                if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL)
                {
                    if (sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_A || sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_C)
                    {
                        m_cPayItem.PAY_AMT = nApprAmt;          // 사용포인트(할인금액)
                    }
                    else
                    {
                        m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrPoint]);          // 사용포인트(할인금액)
                    }

                    // 블루멤버스, 레드멤버스 응답(가맹점번호)으로 설정
                    if (m_cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT || m_cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT)
                    {
                        if (aIrtRsp[Column.POS_RES_POINT.SEQ.ResStoreNo].StartsWith("H"))
                            m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT;
                        else if (aIrtRsp[Column.POS_RES_POINT.SEQ.ResStoreNo].StartsWith("K"))
                            m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT;
                    }

                    m_cPayItem.PAY_DTL_CD_03 = "0";                                 // 할인금액아이템적용여부 (0:미적용, 1:적용)
                    m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;            // 할인결제구분 (1:결제, 2:할인)
                    if (m_cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT
                        && PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.PAY_DC_TYPE) == PosConst.PAY_DC_TYPE.DC)
                    {
                        m_cPayItem.PAY_DTL_CD_03 = "1";                             // 할인금액아이템적용여부 (0:미적용, 1:적용)
                        m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.DC;         // 할인결제구분 (1:결제, 2:할인)
                    }

                    m_cPayItem.AMT_ENTRY_01 = m_cPayItem.PAY_AMT;       // 사용포인트(할인금액)
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSavePoint]);    // 총포인트
                    if (sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_QRY_A)
                        m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResUsesPoint]);    // 가용포인트(할인후결제금액)
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSavePoint]);    // 잔여포인트
                    m_cPayItem.AMT_ENTRY_10 = nDestAmt;

                    m_cPayItem.OCCUR_ENTRY_01 = sInPutData;             // 카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtRsp[Column.POS_RES_POINT.SEQ.ResApprNo].Trim();                 // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 0, 6);     // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 6, 4);     // 승인시간
                    m_cPayItem.OCCUR_ENTRY_05 = sInPutType;             // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = sApprNo;                // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = sApprDate;              // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL;   //승인구분

                    m_cPayItem.OCCUR_ENTRY_16 = sVanCD;                 // VAN 구분
                    m_cPayItem.OCCUR_ENTRY_18 = aIrtRsp[Column.POS_RES_POINT.SEQ.ResStoreNo];                       // 가맹점번호
                    m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                    m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 현금영수증 발행여부

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

                    // 제휴카드번호 저장 후 직전취소시 사용(2017.08.28) -- START
                    m_cPayItem.CanFiller1 = sInEncData;
                    // 제휴카드번호 저장 후 직전취소시 사용(2017.08.28) -- END
                }
                else
                {
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSavePoint]);    // 총포인트
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSavePoint]);    // 잔여포인트

                    m_cPayItem.OCCUR_ENTRY_01 = sInPutData;             // 카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtRsp[Column.POS_RES_POINT.SEQ.ResApprNo].Trim();                 // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 0, 6);     // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 6, 4);     // 승인시간
                    m_cPayItem.OCCUR_ENTRY_05 = sInPutType;             // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = sApprNo;                // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = sApprDate;              // 원승인일자
                }
                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);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }

        /// <summary>
        /// 연습 데이터 설정
        /// </summary>
        public string SetTrainingData(string sTrType, string sPointType, string sInPutType, string sInPutData, string sInEncData, double nDestAmt, double nApprAmt, string sPassWord, string sApprDate, string sApprNo, string sUniqueID)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                // 연습모드이면 연습 데이터 설정
                string sVanCD = GetPayDtlCdToVanCode(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);    // 승인업체 코드 조회
                if (sVanCD == "")
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0563);
                    return sRet;
                }

                if (sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_A || sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_C)
                {
                    m_cPayItem.PAY_AMT = nApprAmt;
                }
                else
                {
                    m_cPayItem.PAY_AMT = m_cDataCommon.ExecTermCoopCmpPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, "", nDestAmt);     // 제휴사 결제 할인 금액 계산
                }

                m_cPayItem.PAY_DTL_CD_03 = "0";                                 // 할인금액아이템적용여부 (0:미적용, 1:적용)
                m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;            // 할인결제구분 (1:결제, 2:할인)
                if (m_cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT
                    && PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.PAY_DC_TYPE) == PosConst.PAY_DC_TYPE.DC)
                {
                    m_cPayItem.PAY_DTL_CD_03 = "1";                             // 할인금액아이템적용여부 (0:미적용, 1:적용)
                    m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.DC;         // 할인결제구분 (1:결제, 2:할인)
                }

                m_cPayItem.AMT_ENTRY_01 = m_cPayItem.PAY_AMT;       // 사용포인트
                m_cPayItem.AMT_ENTRY_03 = 0;                        // 총포인트
                m_cPayItem.AMT_ENTRY_04 = 0;                        // 가용포인트(할인후결제금액)
                m_cPayItem.AMT_ENTRY_05 = 0;                        // 잔여포인트
                m_cPayItem.AMT_ENTRY_10 = nDestAmt;

                m_cPayItem.OCCUR_ENTRY_01 = sInPutData;             // 카드번호
                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 = sInPutType;             // 입력 구분
                m_cPayItem.OCCUR_ENTRY_06 = sApprNo;                // 원승인번호
                m_cPayItem.OCCUR_ENTRY_07 = sApprDate;              // 원승인일자
                m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.COMPULSION;   //승인구분
                
                m_cPayItem.OCCUR_ENTRY_16 = sVanCD;                 // VAN 구분
                m_cPayItem.OCCUR_ENTRY_17 = sUniqueID;              // UniqueID
                m_cPayItem.OCCUR_ENTRY_18 = "";                     // 가맹점번호
                m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 현금영수증 발행여부

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

                //m_cPayItem.CanFiller1 = sInEncData;

                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);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }

        #endregion

        #region CAT 단말기 승인
        /// <summary>
        /// CAT 단말기 승인
        /// </summary>
        /// <param name="sAppType"></param>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string CatExecuteIrt(string sAppType, string[] aParam)
        {

            string sRet = UserCom.RST_ERR;
            string sSendData = string.Empty;

            try
            {

                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return SetTrainingData(PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_USE_A, "", PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN , "999999*********", "", 0, CmUtil.DoubleParse(aParam[3]), "", DateTime.Now.ToString("yyyyMMdd"), "99999999", "");

                string sRecvdData = "";
                string sAppLogDiv = "";
                string sInputType = "";

                if (sAppType == PosConst.POS_CAT_MASTER.TRADE_ID.CAT_POINT_USE)
                {
                    sAppLogDiv = PosConst.CANCEL_DIV.NORMAL;
                }
                else
                {
                    sAppLogDiv = PosConst.CANCEL_DIV.CANCEL;
                }

                string[] aIrtDTLRsp = new string[Column.POS_RES_SPCN_CAT.LEN.Length];

                //전문 송/수신
                if (CatTerminalExecuteIrtCom(sAppType, sAppLogDiv, aParam, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, ref aIrtDTLRsp, ref sRecvdData, ref sInputType) == false)
                {
                    return sRet;
                }

                if (sAppLogDiv == PosConst.CANCEL_DIV.NORMAL)
                {
                    m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aParam[3]);             // 사용포인트(할인금액)

                    m_cPayItem.PAY_DTL_CD_03 = "0";                                 // 할인금액아이템적용여부 (0:미적용, 1:적용)
                    m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;            // 할인결제구분 (1:결제, 2:할인)
                    if (PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.PAY_DC_TYPE) == PosConst.PAY_DC_TYPE.DC)
                    {
                        m_cPayItem.PAY_DTL_CD_03 = "1";                             // 할인금액아이템적용여부 (0:미적용, 1:적용)
                        m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.DC;         // 할인결제구분 (1:결제, 2:할인)
                    }

                    m_cPayItem.AMT_ENTRY_01 = m_cPayItem.PAY_AMT;       // 사용포인트(할인금액)

                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 18, 9));  // 총포인트
                    m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 9, 9));   // 가용포인트(할인후결제금액)
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 18, 9));   // 잔여포인트
                    m_cPayItem.AMT_ENTRY_10 = CmUtil.DoubleParse(aParam[3]);

                    m_cPayItem.OCCUR_ENTRY_01 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.CardBinData].Trim() + "*********";   // 카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppNo].Trim();                       // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 0, 6);     // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 6, 4);     // 승인시간
                    m_cPayItem.OCCUR_ENTRY_05 = sInputType;                         // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = "";                                 // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = "";                                 // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.CAT_TERMINAL; // 승인구분
                    m_cPayItem.OCCUR_ENTRY_16 = GetPayDtlCdToVanCode(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);      // VAN 구분
                    m_cPayItem.OCCUR_ENTRY_18 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.FranchiseNo];                     // 가맹점번호
                    m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                    m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 현금영수증 발행여부

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

                }
                else
                {
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 18, 9));  // 총포인트
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 18, 9));  // 잔여포인트

                    m_cPayItem.OCCUR_ENTRY_01 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.CardBinData].Trim() + "*********";   //카드번호
                    m_cPayItem.OCCUR_ENTRY_05 = sInputType;                 // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;  // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;  // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppNo].Trim();                    // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 0, 6);  // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 6, 4);  // 승인시간
                    
                }

                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);
            }
            finally
            {
                CmUtil.ZeroFillClear(ref sSendData);
            }

            return sRet;
        }
        #endregion


        #region OCB 직통신
        /// <summary>
        /// OCB 직통신
        /// </summary>
        /// <param name="sTradeDiv"></param>
        /// <param name="sTrType"></param>
        /// <param name="sInPutType"></param>
        /// <param name="sInPutData"></param>
        /// <param name="sInEncData"></param>
        /// <param name="sCardPwd"></param>
        /// <param name="nPayAmt"></param>
        /// <param name="sApprDate"></param>
        /// <param name="sApprNo"></param>
        /// <param name="sUniqueID"></param>
        /// <returns></returns>
        public string ExecutePointOCBDirectIrt(string sTradeDiv, string sTrType, string sInPutType, string sInPutData, string sInEncData, string sCardPwd, double nPayAmt, string sApprDate, string sApprNo, string sUniqueID)
        {
            string sRet = UserCom.RST_ERR;
            string sResMsg = "";

            try
            {
                if (sInPutData.Length >= 6) sInPutData = sInPutData.Substring(0, 6).PadRight(sInPutData.Length, '*');

                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return SetTrainingData(sTrType, "OCB", sInPutType, sInPutData, sInEncData, nPayAmt, nPayAmt, sCardPwd, sApprDate, sApprNo, sUniqueID);

                // 포인트 조회
                string[] aIrtRsp = null;
                sRet = m_OCBDirect.OCB_Direct_Point(sTradeDiv, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sTrType, sInEncData, sCardPwd, nPayAmt.ToString(), sApprDate, sApprNo, sUniqueID, ref sResMsg, ref aIrtRsp);
                if (sRet != UserCom.RST_OK)
                {
                    if (sResMsg.Trim() != "")
                        WinManager.ErrorMessage(sResMsg);
                    return sRet;
                }
                // 가맹점번호
                string sCMPApprID = PosMstManager.GetMstVan(PosMstManager.GetPosOption(POS_OPTION.OPT326), PosMst.MST_VAN.DATA.CMP_APPR_ID);

                if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL)
                {
                    if (sTrType == PosConst.POS_OCB_DIRECT.INQ_POINT)
                    {
                        // 포인트 조회
                        m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_INQPOINT.SEQ.ACC_POINT1]);      // 총포인트(누적포인트)
                        m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_INQPOINT.SEQ.REM_POINT1]);      // 가용포인트
                        m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_INQPOINT.SEQ.ACC_POINT1]);      // 누적포인트
                        m_cPayItem.OCCUR_ENTRY_13 = CmUtil.MidH(aIrtRsp[Column.POS_REQ_OCB_INQPOINT.SEQ.SAVEPOINT_YN], 0, 1);   // 적립가능여부 
                        m_cPayItem.OCCUR_ENTRY_14 = CmUtil.MidH(aIrtRsp[Column.POS_REQ_OCB_INQPOINT.SEQ.USEPOINT_YN], 0, 1);    // 사용가능여부
                    }
                    else
                    {
                        // 포인트 사용
                        m_cPayItem.AMT_ENTRY_01 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.CUR_POINT1]);         // 적립포인트     
                        m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.ACC_POINT1]);         // 총포인트(누적포인트)
                        m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.REM_POINT1]);         // 가용포인트
                        m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.ACC_POINT1]);         // 누적포인트
                        m_cPayItem.AMT_ENTRY_06 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.FEE_AMT1]);           // 가맹점수수료
                        m_cPayItem.OCCUR_ENTRY_02 = aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.APPR_NO].Trim();                       // 승인번호
                        m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.APPR_DATE], 0, 8);         // 승인일자
                        m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtRsp[Column.POS_REQ_OCB_POINT.SEQ.APPR_TIME], 0, 6);         // 승인시간
                    }

                    m_cPayItem.PAY_AMT = nPayAmt;

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

                    m_cPayItem.AMT_ENTRY_01 = m_cPayItem.PAY_AMT;           // 사용포인트

                    m_cPayItem.OCCUR_ENTRY_01 = sInPutData;                 // 카드번호
                    m_cPayItem.OCCUR_ENTRY_05 = sInPutType;                 // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = sApprNo;                    // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = sApprDate;                  // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL;   //승인구분

                    m_cPayItem.OCCUR_ENTRY_16 = PosMstManager.GetPosOption(POS_OPTION.OPT326);                                  // VAN 구분
                    m_cPayItem.OCCUR_ENTRY_17 = sUniqueID;                                                                      // UniqueID
                    m_cPayItem.OCCUR_ENTRY_18 = sCMPApprID;                                                                     // 가맹점번호
                    m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);       // 결제수단명
                    m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);       // 현금영수증 발행여부

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

                    m_cPayItem.CanFiller1 = sInEncData;
                }
                else
                {
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_CANPOINT.SEQ.ACC_POINT1]);          // 총포인트(누적포인트)
                    m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_CANPOINT.SEQ.REM_POINT1]);          // 가용포인트
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_CANPOINT.SEQ.ACC_POINT1]);          // 누적포인트
                    m_cPayItem.AMT_ENTRY_06 = CmUtil.DoubleParse(aIrtRsp[Column.POS_REQ_OCB_CANPOINT.SEQ.CAN_POINT1]);          // 실차감포인트

                    m_cPayItem.OCCUR_ENTRY_01 = sInPutData.Length > 16 ? sInPutData.Substring(0, 16) : sInPutData;              // 카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtRsp[Column.POS_REQ_OCB_CANPOINT.SEQ.APPR_NO].Trim();                        // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtRsp[Column.POS_REQ_OCB_CANPOINT.SEQ.APPR_DATE], 0, 8);          // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtRsp[Column.POS_REQ_OCB_CANPOINT.SEQ.APPR_TIME], 0, 6);          // 승인시간

                    m_cPayItem.OCCUR_ENTRY_01 = sInPutData;                 // 카드번호
                    m_cPayItem.OCCUR_ENTRY_05 = sInPutType;                 // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = sApprNo;                    // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = sApprDate;                  // 원승인일자
                }
                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);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion
    }
}
