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

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 해피포인트 사후 적립 메인 화면 처리
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class HPAfterSave : SaleTranCallBase, IHpAfterSaveUs
    {
        /// <summary>
        /// 생성자
        /// </summary>
        public HPAfterSave()
        {
            
        }

        /// <summary>
        /// 사후 적립 대상 거래 데이터 리스트 조회
        /// </summary>
        /// <param name="sSaleDate"></param>
        /// <param name="sPosNo"></param>
        /// <param name="sTradeNo"></param>
        /// <param name="sTradeType"></param>
        /// <returns></returns>
        public DataTable SearchSaleReceiptList(string sSaleDate, string sPosNo, string sTradeNo, string sPayTime, string sTradeType)
        {
            string sQuery = "";
            try
            {
                m_cDataService.TranComplete();

                //#20171123 추후적립, 영수증반품, 영수증재발행 조회시 느린 증상 수정 start
                //아래 select 쿼리의 파라미터 변경
                
                sQuery += " DECLARE @CMP_CD  AS VARCHAR(5) ";
                sQuery += " DECLARE @STOR_CD AS VARCHAR(10) ";
                sQuery += " DECLARE @POS_NO  AS VARCHAR(2) ";
                sQuery += " DECLARE @SALE_DT AS VARCHAR(8) ";
                sQuery += " SET @CMP_CD  = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += " SET @STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                sQuery += " SET @POS_NO  = '" + sPosNo + "'";
                sQuery += " SET @SALE_DT = '" + sSaleDate + "'";
                
                //#20171123 추후적립, 영수증반품, 영수증재발행 조회시 느린 증상 수정 end

                if (m_cPosStatus.Base.TrainingFlag == "1")  //연습모드이면
                {
                    sQuery += " SELECT  A.SALE_DT, A.POS_NO, A.REG_NO AS TRADE_NO, A.SYS_DT, A.PAY_TIME, A.NET_SALE_AMT, A.AF_ACCUM_POINT_AMT, A.AF_ACCUM_POINT_INFO,  ";
                    sQuery += "        ISNULL(C.SALE_DT + C.POS_NO + C.REG_NO,'') SAVE_INFO , ISNULL(D.PAY_WAY_CD + D.PAY_DTL_CD_01,'') MOBILE_INFO ";
                    sQuery += "FROM POSLOG..ETC_SALE_HEADER A ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..ETC_SALE_HEADER ";
                    sQuery += "		        WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "' AND TRADE_DIV = '1') B ";
                    sQuery += "          ON A.SALE_DT = B.ORG_BILLDT AND A.POS_NO = B.ORG_BILL_POSNO AND A.REG_NO = B.ORG_BILL_NO ";
                    sQuery += "	    LEFT JOIN (SELECT * FROM POSLOG..ETC_SALE_HEADER ";
                    sQuery += "		        WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "' AND TRADE_DIV = '0' AND TRADE_KINDPER = '30') C ";
                    sQuery += "          ON A.SALE_DT = C.ORG_BILLDT AND A.POS_NO = C.ORG_BILL_POSNO AND A.REG_NO = C.ORG_BILL_NO ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..ETC_SALE_PAY ";
                    sQuery += "		        WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' AND SALE_DT = '" + sSaleDate + "' AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'  ";
                    sQuery += "                      AND PAY_WAY_CD = '03' AND PAY_DTL_CD_01 IN ('00','01','02')) D ";
                    sQuery += "          ON A.SALE_DT = D.SALE_DT AND A.POS_NO = D.POS_NO AND A.REG_NO = D.REG_NO ";
                    sQuery += "WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' ";
                    sQuery += "   AND A.SALE_DT = '" + sSaleDate + "'  ";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "' ";
                    sQuery += "   AND A.TRAIN_MODE_YN = '" + m_cPosStatus.Base.TrainingFlag + "' ";
                    sQuery += "   AND A.TRADE_DIV = '0' ";
                    sQuery += "   AND A.TRADE_KINDPER = '" + ItemConst.TRAN_KIND.NORMAL.SALE + "'  ";
                    sQuery += "   AND (A.AF_ACCUM_POINT_AMT > 0 OR A.AF_ACCUM_POINT_INFO != '') ";
                    sQuery += "   AND ISNULL(B.SALE_DT,'') = ''  ";
                    sQuery += "   AND ISNULL(C.SALE_DT,'') = ''  ";

                    if (sTradeNo.Trim().Length == 5)
                        sQuery += "    AND A.REG_NO = '" + sTradeNo + "' ";
                    if (sPayTime.Trim().Length == 6)
                        sQuery += "    AND A.PAY_TIME = '" + sPayTime + "' ";

                }
                else
                {
                    //#20171123 추후적립, 영수증반품, 영수증재발행 조회시 느린 증상 수정 start
                    //기존
                    /*
                    sQuery += " SELECT  A.SALE_DT, A.POS_NO, A.TRADE_NO, A.SYS_DT, A.PAY_TIME, A.NET_SALE_AMT, A.AF_ACCUM_POINT_AMT, A.AF_ACCUM_POINT_INFO,  ";
                    sQuery += "        ISNULL(C.SALE_DT + C.POS_NO + C.REG_NO,'') SAVE_INFO , ISNULL(D.PAY_WAY_CD + D.PAY_DTL_CD_01,'') MOBILE_INFO ";
                    sQuery += "FROM POSLOG..TR_SALE_HEADER A ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..TR_SALE_HEADER ";
                    sQuery += "          WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "' AND TRADE_DIV = '1') B ";
                    sQuery += "          ON A.SALE_DT = B.ORG_BILLDT AND A.POS_NO = B.ORG_BILL_POSNO AND A.TRADE_NO = B.ORG_BILL_NO ";
                    sQuery += "	    LEFT JOIN (SELECT * FROM POSLOG..ETC_SALE_HEADER ";
                    sQuery += "		     WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "' AND TRADE_DIV = '0' AND TRADE_KINDPER = '30') C ";
                    sQuery += "          ON A.SALE_DT = C.ORG_BILLDT AND A.POS_NO = C.ORG_BILL_POSNO AND A.TRADE_NO = C.ORG_BILL_NO ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..TR_SALE_PAY ";
                    sQuery += "	         WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' AND SALE_DT = '" + sSaleDate + "' AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'  ";
                    sQuery += "             AND PAY_WAY_CD = '03' AND PAY_DTL_CD_01 IN ('00','01','02')  AND CANCEL_DIV = '0') D ";
                    sQuery += "          ON A.SALE_DT = D.SALE_DT AND A.POS_NO = D.POS_NO AND A.TRADE_NO = D.TRADE_NO ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..TR_SALE_ETC ";       
                    sQuery += "          WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' AND SALE_DT = '" + sSaleDate + "' AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'  ";
                    sQuery += "             AND ETC_WAY_CD = '80' AND ETC_DTL_CD_01 ='01' AND CANCEL_DIV = '0') E ";
                    sQuery += "          ON A.SALE_DT = E.SALE_DT AND A.POS_NO = E.POS_NO AND A.TRADE_NO = E.TRADE_NO ";
                    sQuery += "WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "' ";
                    sQuery += "   AND A.SALE_DT = '" + sSaleDate + "'  ";
                    sQuery += "   AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "' ";
                    sQuery += "   AND A.TRAIN_MODE_YN = '" + m_cPosStatus.Base.TrainingFlag + "' ";
                    sQuery += "   AND A.TRADE_DIV = '0' ";
                    sQuery += "   AND A.TRADE_KINDPER = '" + ItemConst.TRAN_KIND.NORMAL.SALE + "'  ";
                    sQuery += "   AND (A.AF_ACCUM_POINT_AMT > 0 OR A.AF_ACCUM_POINT_INFO != '') ";
                    sQuery += "   AND ISNULL(B.SALE_DT,'') = ''  ";
                    sQuery += "   AND ISNULL(C.SALE_DT,'') = ''  ";
                    sQuery += "   AND ISNULL(E.SALE_DT,'') = ''  ";
                    */
                    //변경
                    
                    sQuery += " SELECT  A.SALE_DT, A.POS_NO, A.TRADE_NO, A.SYS_DT, A.PAY_TIME, A.NET_SALE_AMT, A.AF_ACCUM_POINT_AMT, A.AF_ACCUM_POINT_INFO,  ";
                    sQuery += "        ISNULL(C.SALE_DT + C.POS_NO + C.REG_NO,'') SAVE_INFO , ISNULL(D.PAY_WAY_CD + D.PAY_DTL_CD_01,'') MOBILE_INFO ";
                    sQuery += "FROM POSLOG..TR_SALE_HEADER A ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..TR_SALE_HEADER ";
                    sQuery += "          WHERE CMP_CD = @CMP_CD AND ORG_BILLDT = @SALE_DT AND STOR_CD = @STOR_CD AND TRADE_DIV = '1') B ";
                    sQuery += "          ON A.SALE_DT = B.ORG_BILLDT AND A.POS_NO = B.ORG_BILL_POSNO AND A.TRADE_NO = B.ORG_BILL_NO ";
                    sQuery += "	    LEFT JOIN (SELECT * FROM POSLOG..ETC_SALE_HEADER ";
                    sQuery += "		     WHERE CMP_CD = @CMP_CD AND ORG_BILLDT = @SALE_DT AND STOR_CD = @STOR_CD AND TRADE_DIV = '0' AND TRADE_KINDPER = '30') C ";
                    sQuery += "          ON A.SALE_DT = C.ORG_BILLDT AND A.POS_NO = C.ORG_BILL_POSNO AND A.TRADE_NO = C.ORG_BILL_NO ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..TR_SALE_PAY ";
                    sQuery += "	         WHERE CMP_CD = @CMP_CD AND SALE_DT = @SALE_DT AND STOR_CD = @STOR_CD  ";
                    sQuery += "             AND PAY_WAY_CD = '03' AND PAY_DTL_CD_01 IN ('00','01','02')  AND CANCEL_DIV = '0') D ";
                    sQuery += "          ON A.SALE_DT = D.SALE_DT AND A.POS_NO = D.POS_NO AND A.TRADE_NO = D.TRADE_NO ";
                    sQuery += "     LEFT JOIN (SELECT * FROM POSLOG..TR_SALE_ETC ";
                    sQuery += "          WHERE CMP_CD = @CMP_CD AND SALE_DT = @SALE_DT AND STOR_CD = @STOR_CD  ";
                    sQuery += "             AND ETC_WAY_CD = '80' AND ETC_DTL_CD_01 ='01' AND CANCEL_DIV = '0') E ";
                    sQuery += "          ON A.SALE_DT = E.SALE_DT AND A.POS_NO = E.POS_NO AND A.TRADE_NO = E.TRADE_NO ";
                    sQuery += "WHERE A.CMP_CD = @CMP_CD ";
                    sQuery += "   AND A.SALE_DT = @SALE_DT  ";
                    sQuery += "   AND A.STOR_CD = @STOR_CD ";
                    sQuery += "   AND A.TRAIN_MODE_YN = '" + m_cPosStatus.Base.TrainingFlag + "' ";
                    sQuery += "   AND A.TRADE_DIV = '0' ";
                    sQuery += "   AND A.TRADE_KINDPER = '" + ItemConst.TRAN_KIND.NORMAL.SALE + "'  ";
                    sQuery += "   AND (A.AF_ACCUM_POINT_AMT > 0 OR A.AF_ACCUM_POINT_INFO != '') ";
                    sQuery += "   AND ISNULL(B.SALE_DT,'') = ''  ";
                    sQuery += "   AND ISNULL(C.SALE_DT,'') = ''  ";
                    sQuery += "   AND ISNULL(E.SALE_DT,'') = ''  ";
                    
                    //#20171123 추후적립, 영수증반품, 영수증재발행 조회시 느린 증상 수정 end

                    if (sTradeNo.Trim().Length == 5)
                        sQuery += "    AND A.TRADE_NO = '" + sTradeNo + "' ";
                    if (sPayTime.Trim().Length == 6)
                        sQuery += "    AND A.PAY_TIME = '" + sPayTime + "' ";

                }

                if (sPosNo.Trim().Length == 2)
                    sQuery += "    AND A.POS_NO = '" + sPosNo + "' ";

                if (sTradeType == "1")          // 추후적립
                {
                    sQuery += "    AND ISNULL(D.SALE_DT,'') = ''";              
                }
                else if (sTradeType == "2")     // 추가적립
                {
                    sQuery += "    AND ISNULL(D.SALE_DT,'') != ''";              
                }
                sQuery += " ORDER BY A.TRADE_NO DESC ";

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

        /// <summary>
        /// 사후 적립 대상 거래 데이터 사후 적립 가능여부 체크
        /// </summary>
        /// <param name="sSaleDate"></param>
        /// <param name="sPosNo"></param>
        /// <param name="sTradeNo"></param>
        /// <returns></returns>
        public bool LoadLocalTran(string sSaleDate, string sPosNo, string sTradeNo)
        {
            bool bRet = false;

            try
            {
                m_cDataService.TranComplete();

                // 해더정보 로딩
                if (LoadLocalTrHeader(sSaleDate, sPosNo, sTradeNo) == false)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0248);
                    m_cDataService.TranComplete();
                    return bRet;
                }

                // 상품정보 로딩
                LoadLocalTrDetail(sSaleDate, sPosNo, sTradeNo);

                // 결제정보 로딩
                LoadLocalTrPayment(sSaleDate, sPosNo, sTradeNo);

                // 기타정보 로딩
                LoadLocalTrEtc(sSaleDate, sPosNo, sTradeNo);

                // 캠페인정보 로딩
                LoadLocalTrCampaign(sSaleDate, sPosNo, sTradeNo);

                // 매출객수정보 로딩
                LoadLocalTrGuestCnt(sSaleDate, sPosNo, sTradeNo);

                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);
                m_cDataService.TranComplete();
            }
            return bRet;
        }

        /// <summary>
        /// 사후 적립 대상 거래 데이터 서버 조회
        /// </summary>
        /// <param name="sSaleDate"></param>
        /// <param name="sPosNo"></param>
        /// <param name="sTradeNo"></param>
        /// <param name="SaleTime"></param>
        /// <returns></returns>
        public string SearchServerTran(string sSaleDate, string sPosNo, string sTradeNo, string SaleTime)
        {
            string sStat = UserCom.RST_ERR;
            bool bRet = false;

            try
            {
                m_cDataService.TranComplete();

                // 거래 데이터 서버 조회
                Hashtable htRecvData = new Hashtable();

                sStat = ExecServerTranCallIrt(ItemConst.IRT_INQ_TYPE.TRAN_CALL, sSaleDate, sPosNo, sTradeNo, SaleTime, ref htRecvData);
                if (sStat != UserCom.RST_OK)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0259);
                    return sStat;
                }

                if (htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RES_CD].ToString() != "00")
                {
                    if (htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RES_CD].ToString() == "09")
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0248);    // 해당거래 없음
                    else
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0259) + "\n\r ERROR CODE => " + htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RES_CD]);
                    return UserCom.RST_ERR;
                }

                // 거래데이터
                string sTranData = htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.TRAN_DATA].ToString();

                m_cTrnStatus.Head.CmpCd = m_cPosStatus.Base.CmpCd;          // CMP_CD
                m_cTrnStatus.Head.StoreCd = m_cPosStatus.Base.StoreNo;      // STOR_CD
                m_cTrnStatus.Head.SaleDate = sSaleDate;                     // SALE_DT
                m_cTrnStatus.Head.PosNo = sPosNo;                           // POS_NO
                m_cTrnStatus.Head.TradeNo = htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.TRADE_NO].ToString();                       // TRADE_NO

                // 거래 분해 처리
                string[] aTranData = sTranData.Split(new string[] { "#~" }, StringSplitOptions.None);
                for (int i = 0; i < aTranData.Length; i++)
                {
                    if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranHeader))
                        bRet = TranParserToHeader(aTranData[i]);
                    else if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranDetail))
                        bRet = TranParserToDetail(aTranData[i]);
                    else if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranPay))
                        bRet = TranParserToPayment(aTranData[i]);
                    else if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranCpiRslt))
                        bRet = TranParserToCampaign(aTranData[i]);
                    else if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranEtc))
                        bRet = TranParserToEtc(aTranData[i]);
                    //                    else if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranDpst))
                    //                        bRet = TranParserToGuestCnt(aTranData[i]);
                    //                    else if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranAdmt))
                    //                        bRet = TranParserToGuestCnt(aTranData[i]);
                    else if (aTranData[i].StartsWith(ItemConst.IRT_TRAN_TYPE.TranGuestCnt))
                        bRet = TranParserToGuestCnt(aTranData[i]);

                    if (bRet == false)
                    {
                        m_cDataService.TranComplete();
                        return sStat;
                    }
                }

                // 영수증 반품 체크
                string sRetDIV = htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RET_DIV].ToString();
                if (sRetDIV != "0")         // 이미 반품된 거래
                {
                    m_cTrnStatus.Head.RefundInfo = htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RET_SALE_DT].ToString() + htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RET_POS_NO].ToString() + htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RET_TRADE_NO].ToString();
                }
                // 추후적립 정보 체크
                string sAddPointDIV = htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.ADD_POINT_DIV].ToString();
                if (sAddPointDIV != "0")    // 추후적립된 거래
                {
                    
                }

                sStat = 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);
                m_cDataService.TranComplete();
            }
            return sStat;
        }

        /// <summary>
        /// 영수증 추후적립 가능 여부 조회
        /// </summary>
        /// <param name="sSaleDate"></param>
        /// <param name="sPosNo"></param>
        /// <param name="sTradeNo"></param>
        /// <returns></returns>
        public bool ChekcAfterSaveTran(string sSaleDate, string sPosNo, string sTradeNo)
        {
            bool bRet = false;

            try
            {
                if (m_cPosStatus.Base.TrainingFlag == "1") return true;

                // 사후적립 가능 거래 여부 체크
                if (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.REFUND)
                {
                    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 + "()",
                                         "사후적립요청 실패(반품거래), SALE_DT=" + sSaleDate + ", POS_NO = " + sPosNo + ", TRADE_NO = " + sTradeNo);
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0230);
                    return false;
                }
                else if (m_cTrnStatus.Head.TradeKind != ItemConst.TRAN_KIND.NORMAL.SALE)
                {
                    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 + "()", 
                                         "사후적립요청 실패(판매거래아님), SALE_DT=" + sSaleDate + ", POS_NO = " + sPosNo + ", TRADE_NO = " + sTradeNo);
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0262);
                    return false;
                }
                //else if (m_cTrnStatus.Head.AftSavePoint == 0 && m_cTrnStatus.Head.AftSaveAddInfo.Trim() == "")
                //{
                //    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0268);
                //    return false;
                //}

                // 서버 IRT로 해당 거래 반품 가능여부 체크
                Hashtable htRecvData = new Hashtable();

                string sStat = ExecServerTranCallIrt(ItemConst.IRT_INQ_TYPE.TRAN_CALL, sSaleDate, sPosNo, sTradeNo, "", ref htRecvData);
                if (sStat != UserCom.RST_OK)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0259);
                    return true;
                }

                if (htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RES_CD].ToString() != "00")
                {
                    if (htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RES_CD].ToString() == "09")
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0248);    // 해당거래 없음
                    else
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0259) + "\n\r ERROR CODE => " + htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RES_CD]);
                    return true;
                }

                // 영수증 반품 체크
                string sRetDIV = htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.RET_DIV].ToString();
                if (sRetDIV != "0")
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0229);
                    return false;
                }
                // 추후적립 가능여부 체크
                string sAddPointDIV = htRecvData[Column.IQ_TRAN_CALL_REQ.DATA.ADD_POINT_DIV].ToString();
                if (sAddPointDIV != "0")
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0267);
                    return false;
                }

                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 bRet;
        }

        //2017-06-02 dkshin 해피앱 추후적립
        public bool HPAPP_After_Update_Tran(string sSaleDate, string sPosNo, string sTradeNo)
        {
            bool bRet = false;

            try
            {
                if (m_cPosStatus.Base.TrainingFlag == "1") return true;

                // 서버 IRT로 해당 거래 반품 가능여부 체크
                Hashtable htRecvData = new Hashtable();

                HPAPP_After_Save_Update_TranCallIrt(ItemConst.IRT_INQ_TYPE.HPAPP_AFTER_SAVE_UPDATE, sSaleDate, sPosNo, sTradeNo, "", ref htRecvData);

                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 bRet;
        }
    }


}
