using System;
using System.Collections;
using System.IO;
using System.Data;

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 거래데이터 합계금액 계산 및 관리
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class DataService : IDataProcessUs
    {
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조
        private DataCommon m_cDataCommon = null;

        public DataService()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보 
        }

        /// <summary>
        /// 거래(TRAN) 합계금액 재계산 처리
        /// </summary>
        public void UpdateTranAmount()
        {
            try
            {
                UpdatePluAmount();
                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);
            }
        }

        /// <summary>
        /// 상품행별 영수 금액 재계산 처리
        /// </summary>
        public void UpdatePluItemAmount(Column.TR_PLU.DATA cPluItem)
        {
            try
            {
                double nTotDcAmt = 0;


                //판매 loss일 경우 0원 처리
                if (m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.ETC.LOSS)
                {
                    cPluItem.SALE_AMT = 0;
                    cPluItem.TOT_DC_AMT = 0;
                    cPluItem.BILL_AMT = 0;
                }
                else
                {
                    // 상품 영수금액 재계산
                    cPluItem.SALE_AMT = CmUtil.DoubleMultiplication(cPluItem.SALE_QTY, cPluItem.SALE_PRC);

                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.ITEM_DC_AMT);              // 단품 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.SUM_DC_AMT);               // 소계 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.CPI_DC_AMT);               // 행사 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.COOP_CARD_DC_AMT);         // 제휴카드 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.POINT_DC_AMT);             // 포인트 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.CPN_DC_AMT);               // 쿠폰 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.EMP_DC_AMT);               // 직원 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.SET_DC_AMT);               // 세트 할인 금액
                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.ETC_DC_AMT);               // 기타 할인 금액

                    nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.EXCEP_DC_AMT);             // 예외 할인 금액

                    cPluItem.TOT_DC_AMT = nTotDcAmt;
                    cPluItem.BILL_AMT = CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT);  // 영수금액


                    // 상품 부가세 미 포함일 경우 부가세 더해주기!
                    //2018.01.04; 상품 부가세 미 포함일 경우 부가세 더해 주기(미주의 경우 별도 처리);girak.kim;start
                    //기존소스
                    //if (cPluItem.TAX_AMT_INCLUDE_YN == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED)
                    //{
                    //    cPluItem.BILL_AMT = CmUtil.DoubleAdd(cPluItem.BILL_AMT, cPluItem.APPLY_TAX_AMT);
                    //}
                    if (m_cPosStatus.Base.CmpCd.ToUpper().Equals(PosConst.POS_COMPANY_CODE.PCUS))
                    {
                        if (cPluItem.TAX_AMT_INCLUDE_YN == ItemConst.MST_ITEM_TAX_AMT_INCLUDE_YN.NOT_INCLUDED)
                        {
                            cPluItem.BILL_AMT = CmUtil.DoubleAdd(cPluItem.BILL_AMT, cPluItem.APPLY_TAX_AMT);
                        }
                    }
                    else
                    {
                        if (cPluItem.TAX_AMT_INCLUDE_YN == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED)
                        {
                            cPluItem.BILL_AMT = CmUtil.DoubleAdd(cPluItem.BILL_AMT, cPluItem.APPLY_TAX_AMT);
                        }
                    }
                    //2018.01.04;미주의 경우 상품 부가세 미 포함일 경우 부가세 더해 주기;girak.kim;End
                }



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

        /// <summary>
        /// 거래(TRAN) 상품 합계금액 재계산 처리
        /// </summary>
        public void UpdatePluAmount()
        {
            // 합계금액 재계산 처리 시 세금 계산 처리는 기본으로 처리 하도록 수정(2017/05/01)
            //UpdatePluAmount(false);
            UpdatePluAmount(true);
        }
        /// <summary>
        /// 거래(TRAN) 상품 합계금액 재계산 처리
        /// </summary>
        public void UpdatePluAmount(bool bTaxExec)
        {
            try
            {
                if (bTaxExec == true)
                {
                    // 세금 계산 처리
                    ItemVatProc();
                }

                // 헤더 정보 초기화
                #region

                m_cTrnStatus.Head.TotSaleAmt = 0;
                m_cTrnStatus.Head.TotQty = 0;
                m_cTrnStatus.Head.TotDcAmt = 0;
                m_cTrnStatus.Head.NetSaleAmt = 0;

                m_cTrnStatus.Head.LossTotSaleAmt = 0;

                m_cTrnStatus.Head.CoopCardDcAmt = 0;
                m_cTrnStatus.Head.PointDcAmt = 0;
                m_cTrnStatus.Head.CpnDcAmt = 0;
                m_cTrnStatus.Head.EmpDcAmt = 0;
                m_cTrnStatus.Head.ItemDcAmt = 0;
                m_cTrnStatus.Head.CpiDcAmt = 0;
                m_cTrnStatus.Head.SetDcAmt = 0;
                m_cTrnStatus.Head.EtcDcAmt = 0;

                m_cTrnStatus.Head.ExcepDcAmt = 0;
                m_cTrnStatus.Head.SvcFeeAmt = 0;
                m_cTrnStatus.Head.SvcFeeVat = 0;
                m_cTrnStatus.Head.TotVatAmt = 0;

                m_cTrnStatus.Sale.VatPluAmt = 0;
                m_cTrnStatus.Sale.NoVatPluAmt = 0;

                #endregion

                // 상품정보
                ArrayList aSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

                //#20170828 해피포인트 적립 제외 버튼 추가 phj, start
                //선택 상품이 없을 경우 0으로 초기화 
                if (aSaleItem.Count == 0) m_cTrnStatus.Head.HP_EXCLUDE_YN = "0";
                //#20170828 해피포인트 적립 제외 버튼 추가 phj, end

                for (int iRow = 0; iRow < aSaleItem.Count; iRow++)
                {
                    Column.TR_PLU.DATA cSaleItem = (Column.TR_PLU.DATA)aSaleItem[iRow];

                    if (cSaleItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cSaleItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue;    // 지정취소

                    if (bTaxExec == true) UpdatePluItemAmount(cSaleItem);

                    #region
                    // 총매출
                    m_cTrnStatus.Head.TotSaleAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.TotSaleAmt, cSaleItem.SALE_AMT);
                    // 판매수량
                    if (cSaleItem.ITEM_DIV != ItemConst.PLU_ITEM_DIV.SET_MAIN && cSaleItem.ITEM_DIV != ItemConst.PLU_ITEM_DIV.OPT_MENU && cSaleItem.FLAVOUR_DIV != ItemConst.PLU_FLAVOUR_DIV.FLAVOUR)
                        m_cTrnStatus.Head.TotQty += cSaleItem.SALE_QTY;
                    // 총할인 금액
                    m_cTrnStatus.Head.TotDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.TotDcAmt, cSaleItem.TOT_DC_AMT);
                    // 순매출 금액
                    m_cTrnStatus.Head.NetSaleAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.NetSaleAmt, cSaleItem.BILL_AMT);

                    //아이템 부가세 합
                    m_cTrnStatus.Head.TotVatAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.TotVatAmt, cSaleItem.APPLY_TAX_AMT);

                    //서비스 합계
                    m_cTrnStatus.Head.SvcFeeAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.SvcFeeAmt, cSaleItem.SVC_FEE_AMT);

                    //서비스 부가세 합
                    m_cTrnStatus.Head.SvcFeeVat = CmUtil.DoubleAdd(m_cTrnStatus.Head.SvcFeeVat, cSaleItem.SVC_FEE_VAT);

                    m_cTrnStatus.Head.CoopCardDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.CoopCardDcAmt, cSaleItem.COOP_CARD_DC_AMT);
                    m_cTrnStatus.Head.PointDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.PointDcAmt, cSaleItem.POINT_DC_AMT);
                    m_cTrnStatus.Head.CpnDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.CpnDcAmt, cSaleItem.CPN_DC_AMT);
                    m_cTrnStatus.Head.EmpDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.EmpDcAmt, cSaleItem.EMP_DC_AMT);
                    m_cTrnStatus.Head.ItemDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.ItemDcAmt, cSaleItem.ITEM_DC_AMT);
                    m_cTrnStatus.Head.CpiDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.CpiDcAmt, cSaleItem.CPI_DC_AMT);
                    m_cTrnStatus.Head.SetDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.SetDcAmt, cSaleItem.SET_DC_AMT);
                    m_cTrnStatus.Head.EtcDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.EtcDcAmt, cSaleItem.ETC_DC_AMT);

                    m_cTrnStatus.Head.ExcepDcAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.ExcepDcAmt, cSaleItem.EXCEP_DC_AMT);


                    if (cSaleItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX && cSaleItem.NOTAX_DIV != PosConst.ITEM_NOTAX_DIV.YES)
                    {
                        m_cTrnStatus.Sale.VatPluAmt = CmUtil.DoubleAdd(m_cTrnStatus.Sale.VatPluAmt, CmUtil.DoubleSubtraction(cSaleItem.BILL_AMT, cSaleItem.APPLY_TAX_AMT));
                    }
                    else
                    {
                        m_cTrnStatus.Sale.NoVatPluAmt = CmUtil.DoubleAdd(m_cTrnStatus.Sale.NoVatPluAmt, cSaleItem.BILL_AMT);
                    }

                    m_cTrnStatus.Head.LossTotSaleAmt = CmUtil.DoubleAdd(m_cTrnStatus.Head.LossTotSaleAmt, CmUtil.DoubleMultiplication(cSaleItem.SALE_QTY, cSaleItem.SALE_PRC));

                    #endregion

                }

                // 순매출 금액
                m_cTrnStatus.Sale.NetSaleAmt = m_cTrnStatus.Head.NetSaleAmt;
                // 받을금액
                //m_cTrnStatus.Sale.RemainPayAmt = m_cTrnStatus.Head.NetSaleAmt;
                m_cTrnStatus.Sale.RemainPayAmt = CmUtil.DoubleAdd(CmUtil.DoubleSubtraction(m_cTrnStatus.Head.NetSaleAmt, m_cTrnStatus.Sale.RecvedPayAmt), CmUtil.DoubleAdd(m_cTrnStatus.Head.SvcFeeAmt, m_cPosStatus.Mst.TaxAmtIncludeYn == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED ? m_cTrnStatus.Head.SvcFeeVat : 0));

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

        /// <summary>
        /// 거래(TRAN) 결제 합계금액 재계산 처리
        /// </summary>
        public void UpdatePayAmount()
        {
            try
            {
                // 헤더 정보 초기화
                m_cTrnStatus.Sale.RecvedPayAmt = 0;        // 받은금액

                //#20171113 최종 결제수단의 거스름돈만 표기되는 현상 수정 start
                //반영시 주석 해제
                //m_cPosStatus.Sale.ChangeCashAmt = 0;
                //#20171113 최종 결제수단의 거스름돈만 표기되는 현상 수정 end

                // 결제 금액 계산 처리
                ArrayList alPayment = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                for (int iRow = 0; iRow < alPayment.Count; iRow++)
                {
                    Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)alPayment[iRow];

                    if (cPayItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;
                    if (cPayItem.PAY_DTL_CD_05 != "" && cPayItem.PAY_DTL_CD_05 != "1") continue;

                    if (cPayItem.BILLSPR_NO != m_cTrnStatus.Sale.BillSplitNo) continue;

                    // 받은금액 계산 처리
                    m_cTrnStatus.Sale.RecvedPayAmt = CmUtil.DoubleAdd(m_cTrnStatus.Sale.RecvedPayAmt, cPayItem.PAY_AMT);

                    //#20171113 최종 결제수단의 거스름돈만 표기되는 현상 수정 start
                    //거스름돈 계산 처리
                    //반영시 주석 해제
                    //m_cPosStatus.Sale.ChangeCashAmt = CmUtil.DoubleAdd(m_cPosStatus.Sale.ChangeCashAmt, cPayItem.AMT_ENTRY_02);
                    //#20171113 최종 결제수단의 거스름돈만 표기되는 현상 수정 end
                }
                m_cPosStatus.Sale.PayRecvedAmt = CmUtil.DoubleAdd(m_cTrnStatus.Sale.RecvedPayAmt, m_cPosStatus.Sale.ChangeCashAmt);
                // 받을금액
                //m_cTrnStatus.Sale.RemainPayAmt = CmUtil.DoubleSubtraction(m_cTrnStatus.Head.NetSaleAmt, m_cTrnStatus.Sale.RecvedPayAmt);

                m_cTrnStatus.Sale.RemainPayAmt = CmUtil.DoubleAdd(CmUtil.DoubleSubtraction(m_cTrnStatus.Head.NetSaleAmt, m_cTrnStatus.Sale.RecvedPayAmt), CmUtil.DoubleAdd(m_cTrnStatus.Head.SvcFeeAmt, m_cPosStatus.Mst.TaxAmtIncludeYn == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED ? m_cTrnStatus.Head.SvcFeeVat : 0));

                if (m_cTrnStatus.Sale.RemainPayAmt < 0) m_cTrnStatus.Sale.RemainPayAmt = 0;

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

        /// <summary>
        /// 모든 거래데이터 삭제
        /// </summary>
        public bool DeleteTranItem()
        {
            try
            {

                //결제 내역 지우기
                ArrayList alPays = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                for (int iRow = 0; iRow < alPays.Count; iRow++)
                {
                    Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)alPays[iRow];
                    CmUtil.ZeroFillClear(ref cPayItem.OCCUR_ENTRY_01);
                    CmUtil.ZeroFillClear(ref cPayItem.CanFiller1);
                }

                //기타 내역 지우기
                ArrayList alEtcs = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                for (int iRow = 0; iRow < alEtcs.Count; iRow++)
                {
                    Column.TR_ETC.DATA cEtcItem = (Column.TR_ETC.DATA)alEtcs[iRow];
                    CmUtil.ZeroFillClear(ref cEtcItem.OCCUR_ENTRY_01);
                    CmUtil.ZeroFillClear(ref cEtcItem.CanFiller1);
                }


                // 거래데이터 삭제 처리
                IEnumerator ienum = StateObject.GetItemObject().Keys.GetEnumerator();
                ienum.Reset();
                while (ienum.MoveNext())
                {
                    string sKey = (string)ienum.Current;
                    ((ArrayList)StateObject.GetItemObject(sKey)).Clear();
                }
                return true;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return false;
        }

        /// <summary>
        /// 거래 완료 후 처리
        /// </summary>
        public bool TranComplete()
        {
            try
            {
                DeleteTranItem();
                InitTranHeader();
                return true;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return false;
        }

        /// <summary>
        ///  거래해더 초기화
        /// </summary>
        /// <returns></returns>
        public bool InitTranHeader()
        {
            try
            {
                string sOrderNo = m_cTrnStatus.Head.OrderNo;

                m_cTrnStatus.ClearAll();

                m_cTrnStatus.Head.CmpCd = m_cPosStatus.Base.CmpCd;
                m_cTrnStatus.Head.StoreCd = m_cPosStatus.Base.StoreNo;
                m_cTrnStatus.Head.SaleDate = m_cPosStatus.Base.SaleDate;
                m_cTrnStatus.Head.PosNo = m_cPosStatus.Base.PosNo;
                m_cTrnStatus.Head.RegNo = m_cPosStatus.Base.RegNo;
                m_cTrnStatus.Head.TradeNo = m_cPosStatus.Base.TradeNo;
                m_cTrnStatus.Head.TradeDiv = ItemConst.TRAN_DIV.NORMAL;
                m_cTrnStatus.Head.TrainModeYn = m_cPosStatus.Base.TrainingFlag;
                m_cTrnStatus.Head.TradeKind = ItemConst.TRAN_KIND.NORMAL.SALE;
                m_cTrnStatus.Head.SysYmd = DateTime.Now.ToString("yyyyMMdd");
                m_cTrnStatus.Head.OrderHms = "";
                m_cTrnStatus.Head.PayHms = DateTime.Now.ToString("HHmmss");
                m_cTrnStatus.Head.CashierId = m_cPosStatus.Base.CashierNo;
                m_cTrnStatus.Head.OrderPicNo = "";
                m_cTrnStatus.Head.OwnPartDiv = m_cPosStatus.Base.OwnPartDiv;
                m_cTrnStatus.Head.OrgPosNo = "";
                m_cTrnStatus.Head.OrgSaleDate = "";
                m_cTrnStatus.Head.OrgTradeNo = "";
                m_cTrnStatus.Head.RtnReasonCd = "";
                m_cTrnStatus.Head.RtnReasonMemo = "";
                m_cTrnStatus.Head.NonSaleRsnCd = "";
                m_cTrnStatus.Head.ReserveNo = "";
                m_cTrnStatus.Head.ReserveYmd = "";
                m_cTrnStatus.Head.MemberCustNo = "";
                m_cTrnStatus.Head.OrderFlag = "0";
                m_cTrnStatus.Head.FloorCd = "";
                m_cTrnStatus.Head.TableNo = "";
                m_cTrnStatus.Head.CustFloor = "";
                m_cTrnStatus.Head.ForeignFlag = "";
                m_cTrnStatus.Head.PayGndrDiv = "";
                m_cTrnStatus.Head.AmtDutchPayYn = "";
                m_cTrnStatus.Head.OrderNo = sOrderNo;   //  2019-04-18 - 1997fx11 : 주문(대기)번호 Return을 위해 초기화 하지 않는다.
                m_cTrnStatus.Head.FloorNm = "";
                m_cTrnStatus.Head.TableNm = "";
                m_cTrnStatus.Head.OrderPicNm = "";
                m_cTrnStatus.Head.PpCardCustNm = "";
                m_cTrnStatus.Head.AftSaveAddDiv = "";
                m_cTrnStatus.Head.AftSaveAddInfo = "";
                m_cTrnStatus.Head.RefundInfo = "";
                m_cTrnStatus.Head.MidCloseSeq = m_cPosStatus.Base.MidCloseSeq;
                m_cTrnStatus.Head.PpCardCustId = "";
                m_cTrnStatus.Head.PackTradeDiv = "";
                m_cTrnStatus.Head.HoldStat = "";
                m_cTrnStatus.Head.HoldOrgRegNo = "";
                m_cTrnStatus.Head.VipTy = "";

                m_cTrnStatus.Head.TotSaleAmt = 0;
                m_cTrnStatus.Head.TotDcAmt = 0;
                m_cTrnStatus.Head.NetSaleAmt = 0;
                m_cTrnStatus.Head.ItemDcAmt = 0;
                m_cTrnStatus.Head.CpiDcAmt = 0;
                m_cTrnStatus.Head.CoopCardDcAmt = 0;
                m_cTrnStatus.Head.PointDcAmt = 0;
                m_cTrnStatus.Head.CpnDcAmt = 0;
                m_cTrnStatus.Head.EmpDcAmt = 0;
                m_cTrnStatus.Head.SetDcAmt = 0;
                m_cTrnStatus.Head.EtcDcAmt = 0;
                m_cTrnStatus.Head.TotVatAmt = 0;
                m_cTrnStatus.Head.SvcFeeAmt = 0;
                m_cTrnStatus.Head.SvcFeeVat = 0;
                m_cTrnStatus.Head.EtcVatAmt = 0;
                m_cTrnStatus.Head.AftSavePoint = 0;
                m_cTrnStatus.Head.ExcepDcAmt = 0;
                m_cTrnStatus.Head.CustCnt = 0;
                m_cTrnStatus.Head.PayAge = 0;
                m_cTrnStatus.Head.ManCmpnpsnCnt = 0;
                m_cTrnStatus.Head.WomanCmpnpsnCnt = 0;
                m_cTrnStatus.Head.TotQty = 0;
                m_cTrnStatus.Head.BillSplitCnt = 0;

                m_cTrnStatus.Head.LossTotSaleAmt = 0;

                //#20170828 해피포인트 적립 제외 버튼 추가 phj, start
                m_cTrnStatus.Head.HP_EXCLUDE_YN = "0";
                //#20170828 해피포인트 적립 제외 버튼 추가 phj, end

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

                m_cTrnStatus.Head.ShockingBoxBarcodeData = "";
                m_cTrnStatus.Head.ShockingBoxTradeKind = "";
                m_cTrnStatus.Head.ShockingBoxStat = "";

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

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

        /// <summary>
        /// 트란해더 필수정보 재설정
        /// </summary>
        public void SetTranBaseToHead()
        {
            try
            {
                m_cTrnStatus.Head.CmpCd = m_cPosStatus.Base.CmpCd;
                m_cTrnStatus.Head.StoreCd = m_cPosStatus.Base.StoreNo;
                m_cTrnStatus.Head.SaleDate = m_cPosStatus.Base.SaleDate;
                m_cTrnStatus.Head.PosNo = m_cPosStatus.Base.PosNo;
                m_cTrnStatus.Head.RegNo = m_cPosStatus.Base.RegNo;
                m_cTrnStatus.Head.TradeNo = m_cPosStatus.Base.TradeNo;

                m_cTrnStatus.Head.MidCloseSeq = m_cPosStatus.Base.MidCloseSeq;

                m_cTrnStatus.Head.SysYmd = DateTime.Now.ToString("yyyyMMdd");
                m_cTrnStatus.Head.PayHms = DateTime.Now.ToString("HHmmss");

                m_cTrnStatus.Head.CashierId = m_cPosStatus.Base.CashierNo;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }


        /// <summary>
        /// 거래 번호 증가
        /// </summary>
        /// <param name="bMsgSeq">전문순번증가여부</param>
        /// <param name="bRegNo">등록번호증가여부</param>
        /// <param name="bTradeNo">거래번호증가여부</param>
        /// <returns></returns>
        public bool SetMsgNoInc(bool bMsgSeq, bool bRegNo, bool bTradeNo)
        {
            return SetMsgNoInc(bMsgSeq, bRegNo, bTradeNo, "");
        }
        public bool SetMsgNoInc(bool bMsgSeq, bool bRegNo, bool bTradeNo, string sTranKind)
        {
            try
            {
                CmMessage m_PosSaleInfo = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);

                if (bMsgSeq == true)
                {
                    // 전문 순번 증가
                    #region
                    if (m_cPosStatus.Base.MsgSeqNo == null || m_cPosStatus.Base.MsgSeqNo == "" || int.Parse(m_cPosStatus.Base.MsgSeqNo) >= 9999)
                        m_cPosStatus.Base.MsgSeqNo = "000001";
                    else
                        m_cPosStatus.Base.MsgSeqNo = string.Format("{0:D06}", int.Parse(m_cPosStatus.Base.MsgSeqNo) + 1);

                    m_PosSaleInfo.GetMessage("MSGNO").MakeMessageOverWrite("MsgSeqNo", m_cPosStatus.Base.MsgSeqNo);
                    #endregion
                }

                if (bRegNo == true)
                {
                    // 등록 번호 증가
                    #region
                    if (m_cPosStatus.Base.RegNo == null || m_cPosStatus.Base.RegNo == "" || int.Parse(m_cPosStatus.Base.RegNo) >= 99999)
                        m_cPosStatus.Base.RegNo = "00001";
                    else
                        m_cPosStatus.Base.RegNo = string.Format("{0:D5}", int.Parse(m_cPosStatus.Base.RegNo) + 1);

                    m_PosSaleInfo.GetMessage("MSGNO").MakeMessageOverWrite("RegNo", m_cPosStatus.Base.RegNo);
                    #endregion
                }

                if (bTradeNo == true)
                {
                    // 거래 번호 증가
                    #region
                    if (m_cPosStatus.Base.TradeNo == null || m_cPosStatus.Base.TradeNo == "" || int.Parse(m_cPosStatus.Base.TradeNo) >= 99999)
                        m_cPosStatus.Base.TradeNo = "00001";
                    else
                        m_cPosStatus.Base.TradeNo = string.Format("{0:D5}", int.Parse(m_cPosStatus.Base.TradeNo) + 1);

                    m_PosSaleInfo.GetMessage("MSGNO").MakeMessageOverWrite("TradeNo", m_cPosStatus.Base.TradeNo);
                    #endregion
                }

                if (sTranKind == ItemConst.TRAN_KIND.STATEMENT.MIDDLE_ADJUSTMENT)
                {
                    // 중간정산 차수 증가
                    #region
                    if (m_cPosStatus.Base.MidCloseSeq == null || m_cPosStatus.Base.MidCloseSeq == "")
                        m_cPosStatus.Base.MidCloseSeq = "01";
                    else if (int.Parse(m_cPosStatus.Base.MidCloseSeq) >= 89)
                        m_cPosStatus.Base.MidCloseSeq = "89";           // 최대 89까지만 가능, 99는 영업마감
                    else
                        m_cPosStatus.Base.MidCloseSeq = string.Format("{0:00}", int.Parse(m_cPosStatus.Base.MidCloseSeq) + 1);

                    m_PosSaleInfo.GetMessage("MSGNO").MakeMessageOverWrite("MidCloseSeq", m_cPosStatus.Base.MidCloseSeq);
                    #endregion
                }

                m_PosSaleInfo.MakeFileFromMessage(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                return true;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return false;
        }

        #region 현금영수증 승인 금액 계산
        /// <summary>
        /// 현금영수증 승인 금액 계산
        /// </summary>
        /// <returns></returns>
        public double GetCashAmt()
        {
            double dCashAmt = 0;
            try
            {
                ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);

                for (int iRow = 0; iRow < aPayItem.Count; iRow++)
                {
                    Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)aPayItem[iRow];

                    if (cPayItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPayItem.OCCUR_ENTRY_21 == ItemConst.PAY_CASHBILL_DIV.YES
                        && cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.PAY_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.SMILE_PAY)
                    {
                        // 스마일 페이 현금영수증 승인 금액
                        dCashAmt = CmUtil.DoubleAdd(dCashAmt, cPayItem.AMT_ENTRY_07);
                    }
                    else if (cPayItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPayItem.OCCUR_ENTRY_21 == ItemConst.PAY_CASHBILL_DIV.YES)
                    {
                        dCashAmt = CmUtil.DoubleAdd(dCashAmt, cPayItem.PAY_AMT);
                    }
                }
            }
            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 dCashAmt;
        }
        #endregion

        /// <summary>
        /// 할인 금액 획득
        /// </summary>
        /// <param name="bPosDc"></param>
        /// <param name="bCpi"></param>
        /// <param name="bCoop"></param>
        /// <param name="bPoint"></param>
        /// <param name="bCpn"></param>
        /// <param name="bEmp"></param>
        /// <param name="bSet"></param>
        /// <param name="bEtc"></param>
        /// <returns></returns>
        public double GetPluDiscountAmount(bool bPosDc, bool bCpi, bool bCoop, bool bPoint, bool bCpn, bool bEmp, bool bSet, bool bEtc, bool bExcep, int iRow)
        {
            double nTotDcAmt = 0;
            try
            {
                ArrayList aSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

                //for (int i = 0; i < aSaleItem.Count; i++)
                //{
                Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)aSaleItem[iRow];

                if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) return 0; // continue;    // 지정취소

                if (bPosDc == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.ITEM_DC_AMT);              // 단품 할인 금액
                if (bPosDc == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.SUM_DC_AMT);               // 소계 할인 금액
                if (bCpi == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.CPI_DC_AMT);                 // 행사 할인 금액
                if (bCoop == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.COOP_CARD_DC_AMT);          // 제휴카드 할인 금액
                if (bPoint == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.POINT_DC_AMT);             // 포인트 할인 금액
                if (bCpn == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.CPN_DC_AMT);                 // 쿠폰 할인 금액
                if (bEmp == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.EMP_DC_AMT);                 // 직원 할인 금액
                if (bSet == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.SET_DC_AMT);                 // 세트 할인 금액
                if (bEtc == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.ETC_DC_AMT);                 // 기타 할인 금액
                if (bExcep == true) nTotDcAmt = CmUtil.DoubleAdd(nTotDcAmt, cPluItem.EXCEP_DC_AMT);             // 예외 할인 금액
                //}
            }
            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 nTotDcAmt;
        }

        #region 할인, 적립 대상 금액 획득
        /// <summary>
        /// 할인, 적립 대상 금액 획득
        /// </summary>
        /// <param name="sMenuKey"></param>
        /// <returns></returns>
        public double GetPluTagetAmount(string sMenuKey)
        {
            return GetPluTagetAmount(sMenuKey, false);
        }
        public double GetPluTagetAmount(string sMenuKey, bool bHpSaveNoCampaign)
        {
            double nTotAmt = 0;
            //#20171206 17크리스마스캠페인 start
            double dCpiDcAddAmt = 0;
            //#20171206 17크리스마스캠페인 end
            try
            {
                //#20170828 해피포인트 적립 제외 버튼 추가 phj, start
                //해피포인트 적립제외 버튼 선택 시 무조건 0.5% 적립으로 변경
                

                //#13501 PAS 부산남천_해피포인트 기본 적립제외를 누르면 임직원 할인이 대상금액이 0이뜨는 증상 수정 요청. start, phj
                //기존
                //if (m_cTrnStatus.Head.HP_EXCLUDE_YN == "1") return 0;

                //변경
                if (sMenuKey == PosKey.MENU_KEY.HAPPY_POINT || sMenuKey == PosKey.MENU_KEY.HAPPY_POINT_SAVE_CHINA)
                {
                    if (m_cTrnStatus.Head.HP_EXCLUDE_YN == "1") return 0;
                }
                //#13501 PAS 부산남천_해피포인트 기본 적립제외를 누르면 임직원 할인이 대상금액이 0이뜨는 증상 수정 요청. end, phj


                //#20170828 해피포인트 적립 제외 버튼 추가 phj, end

                ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);

                // 할인대상금액 유형 => 0:대상아님, 1:총액, 2:결제금액
                string TagGetAmtType = "";

                #region
                if (sMenuKey == PosKey.MENU_KEY.SKT)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.KT)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.LGT)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);

                //#20180413 웰컴카드 신규기능 추가 start,phj
                else if (sMenuKey == PosKey.MENU_KEY.WELCOMECARD_DC)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                //#20180413 웰컴카드 신규기능 추가 end,phj

                else if (sMenuKey == PosKey.MENU_KEY.HAPPY_POINT)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.ETC_INFO_ITEM, ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.HAPPY_POINT_SAVE_CHINA)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.ETC_INFO_ITEM, ItemConst.TR_ITEM_ID.ETC_INFO.POINT_SAVE_CHINA, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.OKCASHBACK_SAVE)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.ETC_INFO_ITEM, ItemConst.TR_ITEM_ID.ETC_INFO.OCB_SAVE, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.HAPPY_DC_COUPON)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.COUPON_ITEM, ItemConst.TR_ITEM_ID.COUPON.INCARD, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);

                else if (sMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.EMP_DC_ITEM, ItemConst.TR_ITEM_ID.EMP_DC.SPC, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC_PAY)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.EMP_DC_ITEM, ItemConst.TR_ITEM_ID.EMP_DC.SPC_PAY, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.SEVERANCE_DC)      // 세브란스할인(2017.05.23)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.EMP_DC_ITEM, ItemConst.TR_ITEM_ID.EMP_DC.SEVERANCE, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);
                else if (sMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC_CHINA)     // 중국임직원할인(2017.05.30)
                    TagGetAmtType = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.EMP_DC_ITEM, ItemConst.TR_ITEM_ID.EMP_DC.SPC_CHINA, PosMst.MST_PAY_DC.DATA.DC_TRGT_AMT_TYPE);

                #endregion

                foreach (Column.TR_PLU.DATA cPluItem in alSaleItem)
                {
                    // 해당상품이 할인 적립 가능한지 체크
                    if (CheckPluDiscountAble(sMenuKey, cPluItem) == false) continue;

                    if (sMenuKey == PosKey.MENU_KEY.SKT || sMenuKey == PosKey.MENU_KEY.KT || sMenuKey == PosKey.MENU_KEY.LGT
                        //#20180413 웰컴카드 신규기능 추가 start,phj
                        || sMenuKey == PosKey.MENU_KEY.WELCOMECARD_DC
                        //#20180413 웰컴카드 신규기능 추가 end,phj
                        || sMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC || sMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC_PAY)
                    {
                        ///////////////////////////////////////////////////////////////////////////////////////////////
                        // 통신사 할인 대상금액
                        ///////////////////////////////////////////////////////////////////////////////////////////////

                        #region
                        if ((cPluItem.ITEM_DC_AMT > 0 || cPluItem.SUM_DC_AMT > 0) && cPluItem.DC_DIV.Length >= 4)    // 단품 할인, 소계 할인 금액
                        {
                            // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.DC_DIV.Substring(0, 2), cPluItem.DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.DC_DIV.Substring(0, 2), cPluItem.DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") continue;
                        }
                        if (cPluItem.POINT_DC_AMT > 0 && cPluItem.POINT_DC_DIV.Length >= 4)                              // 포인트 할인 금액
                        {
                            // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.POINT_DC_DIV.Substring(0, 2), cPluItem.POINT_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.POINT_DC_DIV.Substring(0, 2), cPluItem.POINT_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") continue;
                        }
                        if (cPluItem.CPN_DC_AMT > 0 && cPluItem.CPN_DC_DIV.Length >= 4)                                // 쿠폰 할인 금액
                        {
                            // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.CPN_DC_DIV.Substring(0, 2), cPluItem.CPN_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.CPN_DC_DIV.Substring(0, 2), cPluItem.CPN_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") continue;
                        }
                        if (cPluItem.EMP_DC_AMT > 0 && cPluItem.EMP_DC_DIV.Length >= 4)                                // 직원 할인 금액
                        {
                            // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.EMP_DC_DIV.Substring(0, 2), cPluItem.EMP_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.EMP_DC_DIV.Substring(0, 2), cPluItem.EMP_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") continue;
                        }
                        if (cPluItem.SET_DC_AMT > 0)       // 세트할인
                        {
                            // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(ItemConst.PLU_DC_DIV.SET_DC.Substring(0, 2), ItemConst.PLU_DC_DIV.SET_DC.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(ItemConst.PLU_DC_DIV.SET_DC.Substring(0, 2), ItemConst.PLU_DC_DIV.SET_DC.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") continue;
                        }
                        if (cPluItem.ETC_DC_AMT > 0 && cPluItem.ETC_DC_DIV.Length >= 4)                                // 기타 할인 금액
                        {
                            // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.ETC_DC_DIV.Substring(0, 2), cPluItem.ETC_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.ETC_DC_DIV.Substring(0, 2), cPluItem.ETC_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") continue;
                        }

                        #endregion

                        if (cPluItem.alTrSaleCpi != null)
                        {
                            // 통신사 할인 대상상품 선택시 캠페인 할인상품은 제외(2017.06.20)
                            bool bCpiExist = false;
                            foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                            {
                                #region
                                //#20170811 제휴할인그룹 중복 여부 체크가 할인캠페인만 적용이 되어 다른 캠페인에도 적용 되도록 수정 start
                                //기존
                                if (cTrSaleCpi.DC_SUM_AMT > 0)      // 캠페인 성립 상품과 중복 적용 가능여부 체크
                                //변경
                                //if (cTrSaleCpi.DC_QTY > 0)      // 캠페인 성립 상품과 중복 적용 가능여부 체크
                                //#20170811 제휴할인그룹 중복 여부 체크가 할인캠페인만 적용이 되어 다른 캠페인에도 적용 되도록 수정 end
                                {
                                    //#20171206 17크리스마스캠페인 start
                                    //기존
                                    /*
                                    // 제휴할인그룹 중복 여부(0:중복적용불가, 1:중복적용가능)
                                    if (cTrSaleCpi.TELECOM_COOP_DUP_PRMT_YN == "0")
                                        return -1;      // 캠페인 취소 후 가능
                                    else
                                        bCpiExist = true;
                                    */
                                    //변경
                                    
                                    // 제휴할인그룹 중복 여부(0:중복적용불가, 1:중복적용가능, 2:중복적용가능(할인금액포함))
                                    if (cTrSaleCpi.TELECOM_COOP_DUP_PRMT_YN == "0")
                                        return -1;      // 캠페인 취소 후 가능
                                    else if (cTrSaleCpi.TELECOM_COOP_DUP_PRMT_YN == "1")
                                        bCpiExist = true;
                                    else
                                    {
                                        //통신사 할인이 아니면 통신사할인 대상금액에서 제외
                                        if (sMenuKey != PosKey.MENU_KEY.SKT && 
                                            sMenuKey != PosKey.MENU_KEY.KT && 
                                            sMenuKey != PosKey.MENU_KEY.LGT && 
                                            //#20180413 웰컴카드 신규기능 추가 start,phj
                                            sMenuKey != PosKey.MENU_KEY.WELCOMECARD_DC
                                            //#20180413 웰컴카드 신규기능 추가 end,phj
                                            )
                                        {
                                            bCpiExist = true;
                                        }
                                    }
                                    
                                    //#20171206 17크리스마스캠페인 end
                                }
                                #endregion
                            }
                            if (bCpiExist == true) continue;

                            //foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                            //{
                            //    if (cTrSaleCpi.DC_SUM_AMT > 0)      // 캠페인 성립 상품과 중복 적용 가능여부 체크
                            //    {
                            //        // 제휴할인그룹 중복 여부(0:중복적용불가, 1:중복적용가능)
                            //        if (cTrSaleCpi.TELECOM_COOP_DUP_PRMT_YN == "0") return -1;      // 캠페인 취소 후 가능
                            //    }
                            //}
                        }
                    }
                    else if (sMenuKey == PosKey.MENU_KEY.HAPPY_POINT || sMenuKey == PosKey.MENU_KEY.HAPPY_POINT_SAVE_CHINA || sMenuKey == PosKey.MENU_KEY.OKCASHBACK_SAVE)
                    {
                        ///////////////////////////////////////////////////////////////////////////////////////////////
                        // 해피포인트 기본적립 대상금액 
                        ///////////////////////////////////////////////////////////////////////////////////////////////

                        #region
                        if ((cPluItem.ITEM_DC_AMT > 0 || cPluItem.SUM_DC_AMT > 0) && cPluItem.DC_DIV.Length >= 4)       // 단품 할인, 소계 할인 금액
                        {
                            // HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.DC_DIV.Substring(0, 2), cPluItem.DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.DC_DIV.Substring(0, 2), cPluItem.DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2") continue;
                        }
                        if (cPluItem.COOP_CARD_DC_AMT > 0 && cPluItem.COOP_CARD_DC_DIV.Length >= 4)                     // 제휴 할인 금액
                        {
                            // HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.COOP_CARD_DC_DIV.Substring(0, 2), cPluItem.COOP_CARD_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.COOP_CARD_DC_DIV.Substring(0, 2), cPluItem.COOP_CARD_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2") continue;
                        }
                        if (cPluItem.POINT_DC_AMT > 0 && cPluItem.POINT_DC_DIV.Length >= 4)                             // 포인트 할인 금액
                        {
                            // HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.POINT_DC_DIV.Substring(0, 2), cPluItem.POINT_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.POINT_DC_DIV.Substring(0, 2), cPluItem.POINT_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2") continue;
                        }
                        if (cPluItem.CPN_DC_AMT > 0 && cPluItem.CPN_DC_DIV.Length >= 4)                                // 쿠폰 할인 금액
                        {
                            // HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.CPN_DC_DIV.Substring(0, 2), cPluItem.CPN_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.CPN_DC_DIV.Substring(0, 2), cPluItem.CPN_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2") continue;
                        }
                        if (cPluItem.EMP_DC_AMT > 0 && cPluItem.EMP_DC_DIV.Length >= 4)                                // 직원 할인 금액
                        {
                            // HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.EMP_DC_DIV.Substring(0, 2), cPluItem.EMP_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.EMP_DC_DIV.Substring(0, 2), cPluItem.EMP_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2") continue;
                        }
                        if (cPluItem.SET_DC_AMT > 0)       // 세트할인
                        {
                            // HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(ItemConst.PLU_DC_DIV.SET_DC.Substring(0, 2), ItemConst.PLU_DC_DIV.SET_DC.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(ItemConst.PLU_DC_DIV.SET_DC.Substring(0, 2), ItemConst.PLU_DC_DIV.SET_DC.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2") continue;
                        }
                        if (cPluItem.ETC_DC_AMT > 0 && cPluItem.ETC_DC_DIV.Length >= 4)                                // 기타 할인 금액
                        {
                            // HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPluItem.ETC_DC_DIV.Substring(0, 2), cPluItem.ETC_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPluItem.ETC_DC_DIV.Substring(0, 2), cPluItem.ETC_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2") continue;
                        }
                        #endregion

                        // 캠페인 제외여부(추가적립시 기본적립 1000원 이하일때 캠페인 제외)
                        if (bHpSaveNoCampaign == false)
                        {
                            // 기본적립일때 캠페인 성립 상품과 중복 적용 가능여부 체크
                            bool bNotSave = false;
                            if (cPluItem.alTrSaleCpi != null)
                            {
                                foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                                {
                                    #region
                                    if (cTrSaleCpi.DC_QTY > 0 || cTrSaleCpi.DC_SUM_AMT > 0)
                                    {
                                        // 기본 HP 적립여부(0:적립없음, 1:적립가능)
                                        if (cTrSaleCpi.BASIC_HP_ACCUM_YN == "0") return 0;
                                        // 기본 HP 적립기준(0:적립안함, 1:행사상품포함, 2:행사상품제외, 3:사은품제외)
                                        if (cTrSaleCpi.BASIC_HP_ACCUM_STD == "0") return 0;
                                        else if (cTrSaleCpi.BASIC_HP_ACCUM_STD == "2") bNotSave = true;
                                        else if (cTrSaleCpi.BASIC_HP_ACCUM_STD == "3")
                                        {
                                            if (cPluItem.CAMPAIGN_FREEGIFT == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT || cPluItem.CAMPAIGN_FREEGIFT == PosConst.SALE_PLU_INPUT_TYPE.FREEGIFT_HP) bNotSave = true;
                                        }
                                    }
                                    #endregion
                                }
                            }
                            if (bNotSave == true) continue;
                        }
                    }

                    // 할인대상금액 유형 => 0:대상아님, 1:총액, 2:결제금액
                    if (TagGetAmtType == "1")
                        nTotAmt = CmUtil.DoubleAdd(nTotAmt, cPluItem.SALE_AMT);     // 총매출
                    else
                    //#20171206 17크리스마스캠페인 start
                    //기존
                    //    nTotAmt = CmUtil.DoubleAdd(nTotAmt, cPluItem.BILL_AMT);     // 순매출
                    //변경
                    
                    {
                        if (cPluItem.alTrSaleCpi != null)
                        {
                            dCpiDcAddAmt = 0;

                            foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                            {
                                if (cTrSaleCpi.DC_SUM_AMT > 0)      // 캠페인 성립 상품과 중복 적용 가능여부 체크
                                {
                                    //통신사 할인시 해당 상품시 캠페인 적용되어 있고 통신사 제휴 중복 할인금액 포함이면 캠페인 할인금액 포함.
                                    if ((sMenuKey == PosKey.MENU_KEY.SKT || 
                                         sMenuKey == PosKey.MENU_KEY.KT ||
                                         sMenuKey == PosKey.MENU_KEY.LGT ||
                                         //#20180413 웰컴카드 신규기능 추가 start,phj
                                         sMenuKey == PosKey.MENU_KEY.WELCOMECARD_DC
                                         //#20180413 웰컴카드 신규기능 추가 end,phj
                                        ) &&
                                        (cTrSaleCpi.TELECOM_COOP_DUP_PRMT_YN == "2"))
                                    {
                                        dCpiDcAddAmt = CmUtil.DoubleAdd(dCpiDcAddAmt, cTrSaleCpi.DC_SUM_AMT);     // 캠페인할인금액
                                    }

                                }
                            }
                        }

                        nTotAmt = CmUtil.DoubleAdd(nTotAmt, cPluItem.BILL_AMT + dCpiDcAddAmt);     // 순매출
                    }
                    
                    //#20171206 17크리스마스캠페인 end
                }

                if (sMenuKey == PosKey.MENU_KEY.HAPPY_POINT || sMenuKey == PosKey.MENU_KEY.HAPPY_POINT_SAVE_CHINA || sMenuKey == PosKey.MENU_KEY.OKCASHBACK_SAVE)
                {
                    // 적립불가 상품의 캠페인 성립여부 체크
                    foreach (Column.TR_PLU.DATA cPluItem in alSaleItem)
                    {
                        if (bHpSaveNoCampaign == false && cPluItem.alTrSaleCpi != null)
                        {
                            foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                            {
                                if (cTrSaleCpi.DC_QTY > 0 || cTrSaleCpi.DC_SUM_AMT > 0)
                                {
                                    // 기본 HP 적립여부(0:적립없음, 1:적립가능)
                                    if (cTrSaleCpi.BASIC_HP_ACCUM_YN == "0") return 0;
                                }
                            }
                        }
                    }

                    // 해피포인트 적립 대상금액은 결제 금액중 적립가능 결제금액만 설정 함.
                    double nExceptPayAmt = 0;
                    foreach (Column.TR_PAYMENT.DATA cPayItem in alPayItem)
                    {
                        if (cPayItem.CANCEL_DIV != PosConst.CANCEL_DIV.NORMAL) continue;

                        if (cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.PAY)        // 할인결제구분 (1:결제, 2:할인)
                        {
                            // 결제수단별 HP 기본 적립 여부 체크(적립불가 결제수단) => HP 기본 적립 여부(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
                            {
                                nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                            }
                            else if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.CREDITCARD_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD)
                            {
                                if (CmUtil.IntParse(cPayItem.OCCUR_ENTRY_14) >= 60 && cPayItem.PAY_DTL_CD_02 != "")
                                {
                                    switch(cPayItem.PAY_DTL_CD_02)
                                    {
                                        #region
                                        case ItemConst.CREDITCARD_DC_TY.CREDIT_SPNT: //삼성포인트
                                            if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM , ItemConst.TR_ITEM_ID.POINT_USE.SAMSUNG_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
                                            {
                                                return 0;
                                            }
                                            else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.SAMSUNG_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
                                            {
                                                nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                                            }
                                            break;
                                        case ItemConst.CREDITCARD_DC_TY.SHINHAN_CARD_POINT: //신한포인트
                                            if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.SHINHAN_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
                                            {
                                                return 0;
                                            }
                                            else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.SHINHAN_POINT, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
                                            {
                                                nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                                            }
                                            break;
                                        case ItemConst.CREDITCARD_DC_TY.HYUNDAI_M_POINTS: //현대M
                                            if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.HYUNDAI_MPOINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
                                            {
                                                return 0;
                                            }
                                            else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.HYUNDAI_MPOINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
                                            {
                                                nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                                            }
                                            break;
                                        // grayber@20180102 우리모아포인트 추가 start - 결제수단별 HP 기본 적립 여부 체크 분기 추가
                                        case ItemConst.CREDITCARD_DC_TY.WOORIMORE_POINTS:
                                            if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.WOORIMORE_POINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "0")
                                            {
                                                return 0;
                                            }
                                            else if (PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.POINT_ITEM, ItemConst.TR_ITEM_ID.POINT_USE.WOORIMORE_POINTS, PosMst.MST_PAY_DC.DATA.HP_BASIC_ACCUM_YN) == "2")
                                            {
                                                nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                                            }
                                            break;
                                        // grayber@20180102 우리모아포인트 추가 end
                                        default:
                                            if (CmUtil.IntParse(cPayItem.OCCUR_ENTRY_14) >= 60) nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                                            break;

                                        #endregion
                                    }
                                }
                                else
                                {
                                    // 신용카드 포인트사용 결제 적립 없음
                                    if (CmUtil.IntParse(cPayItem.OCCUR_ENTRY_14) >= 60) nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                                }

                            }
                            
                        }
                    }
                    if (nExceptPayAmt > 0)
                    {
                        //#20171219 할인, 적립 제외 금액 계산시 상품리스트에서 계산된 금액에서 빼도록 수정 start
                        //기존
                        //double nPaySaveAmt = m_cTrnStatus.Head.NetSaleAmt - nExceptPayAmt;
                        //변경
                        double nPaySaveAmt = nTotAmt - nExceptPayAmt;
                        //#20171219 할인, 적립 제외 금액 계산시 상품리스트에서 계산된 금액에서 빼도록 수정 end

                        //#20171222 대상금액이 0보다 작은 경우 전문 오류 발생으로 0으로 변경 start
                        if (nPaySaveAmt <= 0) return 0;
                        //#20171222 대상금액이 0보다 작은 경우 전문 오류 발생으로 0으로 변경 end

                        if (nTotAmt > nPaySaveAmt) nTotAmt = nPaySaveAmt;
                    }
                }
                else if (sMenuKey == PosKey.MENU_KEY.SKT || sMenuKey == PosKey.MENU_KEY.KT || sMenuKey == PosKey.MENU_KEY.LGT || sMenuKey == PosKey.MENU_KEY.KT_VIP
                        //#20180413 웰컴카드 신규기능 추가 start,phj
                        || sMenuKey == PosKey.MENU_KEY.WELCOMECARD_DC
                        //#20180413 웰컴카드 신규기능 추가 end,phj
                        || sMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC || sMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC_PAY)
                {
                    // 통신사할인 대상금액은 결제 금액중 통신사할인가능 결제금액만 설정 함.
                    double nExceptPayAmt = 0;
                    foreach (Column.TR_PAYMENT.DATA cPayItem in alPayItem)
                    {
                        if (cPayItem.CANCEL_DIV != PosConst.CANCEL_DIV.NORMAL) continue;

                        if (cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.PAY)        // 할인결제구분 (1:결제, 2:할인)
                        {
                            // 통신사 할인 구분(0:불가, 1:가능, 2:제외)
                            if (PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "0") return 0;
                            if (PosMstManager.GetMstPayDc(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2")
                            {
                                nExceptPayAmt = CmUtil.DoubleAdd(nExceptPayAmt, cPayItem.PAY_AMT);
                            }
                        }
                    }
                    if (nExceptPayAmt > 0)
                    {
                        //#20171206 17크리스마스캠페인 start
                        //결제항목중 통신사할인 제외 처리시 할인금액포함 캠페인 할인 금액 합산 
                        //기존
                        //double nPaySaveAmt = m_cTrnStatus.Head.NetSaleAmt - nExceptPayAmt;
                        //변경
                        //#20171219 할인, 적립 제외 금액 계산시 상품리스트에서 계산된 금액에서 빼도록 수정 start
                        //기존
                        //double nPaySaveAmt = m_cTrnStatus.Head.NetSaleAmt - nExceptPayAmt + dCpiDcAddAmt;
                        //변경
                        double nPaySaveAmt = nTotAmt - nExceptPayAmt + dCpiDcAddAmt;
                        //#20171219 할인, 적립 제외 금액 계산시 상품리스트에서 계산된 금액에서 빼도록 수정 end
                        //#20171206 17크리스마스캠페인 end

                        //#20171222 대상금액이 0보다 작은 경우 전문 오류 발생으로 0으로 변경 start
                        if (nPaySaveAmt <= 0) return 0;
                        //#20171222 대상금액이 0보다 작은 경우 전문 오류 발생으로 0으로 변경 end

                        if (nTotAmt > nPaySaveAmt) nTotAmt = nPaySaveAmt;
                    }
                }
            }
            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 nTotAmt;
        }
        #endregion

        #region 해당 상품이 할인 적립 가능한지 체크
        /// <summary>
        /// 해당 상품이 할인 적립 가능한지 체크
        /// </summary>
        /// <param name="sMenuKey"></param>
        /// <returns>true:가능, false:불가</returns>
        public bool CheckPluDiscountAble(string sMenuKey, Column.TR_PLU.DATA cPluItem)
        {
            try
            {
                if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) return false;      // 지정취소
                if (cPluItem.NONSALES_RSN_CD != "0") return false;                                                                                  // 비매출구분
                if (cPluItem.BILLSPR_NO != m_cTrnStatus.Sale.BillSplitNo) return false;                                                             // 빌분리번호

                #region
                if (sMenuKey == PosKey.MENU_KEY.SKT || 
                    sMenuKey == PosKey.MENU_KEY.KT || 
                    sMenuKey == PosKey.MENU_KEY.LGT || 
                    sMenuKey == PosKey.MENU_KEY.KT_VIP
                    //#20180413 웰컴카드 신규기능 추가 start,phj
                    || sMenuKey == PosKey.MENU_KEY.WELCOMECARD_DC
                    //#20180413 웰컴카드 신규기능 추가 end,phj
                    )
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    // 통신사 할인 대상
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    if (cPluItem.COOP_CARD_DC_NOADM_YN == "1") return false;    // 제휴 할인 불가 여부(0:가능, 1:불가)

                    #region

                    if ((cPluItem.ITEM_DC_AMT > 0 || cPluItem.SUM_DC_AMT > 0) && cPluItem.DC_DIV.Length >= 4)    // 단품 할인, 소계 할인 금액
                    {
                        // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                        if (PosMstManager.GetMstPayDc(cPluItem.DC_DIV.Substring(0, 2), cPluItem.DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") return false;
                    }
                    if (cPluItem.POINT_DC_AMT > 0 && cPluItem.POINT_DC_DIV.Length >= 4)                              // 포인트 할인 금액
                    {
                        // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                        if (PosMstManager.GetMstPayDc(cPluItem.POINT_DC_DIV.Substring(0, 2), cPluItem.POINT_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") return false;
                    }
                    if (cPluItem.CPN_DC_AMT > 0 && cPluItem.CPN_DC_DIV.Length >= 4)                                // 쿠폰 할인 금액
                    {
                        // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                        if (PosMstManager.GetMstPayDc(cPluItem.CPN_DC_DIV.Substring(0, 2), cPluItem.CPN_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") return false;
                    }
                    if (cPluItem.EMP_DC_AMT > 0 && cPluItem.EMP_DC_DIV.Length >= 4)                                // 직원 할인 금액
                    {
                        // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                        if (PosMstManager.GetMstPayDc(cPluItem.EMP_DC_DIV.Substring(0, 2), cPluItem.EMP_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") return false;
                    }
                    if (cPluItem.SET_DC_AMT > 0)       // 세트할인
                    {
                        // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                        if (PosMstManager.GetMstPayDc(ItemConst.PLU_DC_DIV.SET_DC.Substring(0, 2), ItemConst.PLU_DC_DIV.SET_DC.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") return false;
                    }
                    if (cPluItem.ETC_DC_AMT > 0 && cPluItem.ETC_DC_DIV.Length >= 4)                                // 기타 할인 금액
                    {
                        // 통신사할인 대상구분(0:불가, 1:가능, 2:제외)
                        if (PosMstManager.GetMstPayDc(cPluItem.ETC_DC_DIV.Substring(0, 2), cPluItem.ETC_DC_DIV.Substring(2, 2), PosMst.MST_PAY_DC.DATA.MOBILE_DC_DIV) == "2") return false;
                    }

                    #endregion

                    // 통신사 할인 대상상품 선택시 캠페인 할인상품은 제외(2017.06.20)
                    if (cPluItem.alTrSaleCpi != null)
                    {
                        foreach (Column.TR_SALE_CPI_RSLT.DATA cTrSaleCpi in cPluItem.alTrSaleCpi)
                        {
                            //#20171206 17크리스마스캠페인 start
                            //기존
                            //if (cTrSaleCpi.DC_SUM_AMT > 0) return false;    // 캠페인 성립 상품과 중복 적용 가능여부 체크
                            //변경
                            if (cTrSaleCpi.DC_SUM_AMT > 0 && cTrSaleCpi.TELECOM_COOP_DUP_PRMT_YN != "2") return false;
                            //#20171206 17크리스마스캠페인 end
                        }
                    }
                }
                else if (sMenuKey == PosKey.MENU_KEY.OLIBANK || sMenuKey == PosKey.MENU_KEY.OKCASHBACK || sMenuKey == PosKey.MENU_KEY.BLUE_MEMBERS || sMenuKey == PosKey.MENU_KEY.RED_MEMBERS)
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    // 제휴 포인트 할인 대상 
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    if (cPluItem.COOP_CARD_DC_NOADM_YN == "1") return false;    // 제휴 할인 불가 여부(0:가능, 1:불가)
                }
                else if (sMenuKey == PosKey.MENU_KEY.HAPPY_POINT || sMenuKey == PosKey.MENU_KEY.HAPPY_POINT_SAVE_CHINA || sMenuKey == PosKey.MENU_KEY.OKCASHBACK_SAVE)
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    // 해피포인트 기본적립 대상
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    if (cPluItem.ACCUM_PRMT_YN == "0") return false;                // 적립허용 여부

                }
                else if (sMenuKey == PosKey.MENU_KEY.ONLINE_COUPONS || sMenuKey == PosKey.MENU_KEY.ONLINE_COUPONS_SCH)
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    // 온라인 쿠폰(중국)
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    if (cPluItem.DC_PRMT_YN == "1") return false;

                    // 기존 할인이 적용되어 있으면 제외
                    if (cPluItem.ITEM_DC_AMT > 0 || cPluItem.SUM_DC_AMT > 0) return false;  // 단품 할인 금액
                    if (cPluItem.COOP_CARD_DC_AMT > 0) return false;                        // 제휴카드 할인 금액
                    if (cPluItem.POINT_DC_AMT > 0) return false;                            // 포인트 할인 금액
                    if (cPluItem.CPN_DC_AMT > 0) return false;                              // 쿠폰 할인 금액
                    //if (cPluItem.CPN_DC_AMT > 0 && cPluItem.CPN_DC_DIV != ItemConst.PLU_CPN_DC_TYPE.DC_ONLINE_CPN) return false; // 쿠폰 할인 금액
                    if (cPluItem.EMP_DC_AMT > 0) return false;                              // 직원 할인 금액
                    if (cPluItem.SET_DC_AMT > 0) return false;                              // 묶음 할인 금액
                }
                else
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    // 일반 할인 대상
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    if (cPluItem.DC_PRMT_YN == "1") return false;
                }
                #endregion

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

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

            try
            {

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

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

                double dTaxTakeInSumAppy = 0;   //적용한 TakeIn 부가세 금액 
                double dTaxTakeOutSumAppy = 0;  //적용한 TakeOut부가세 금액 

                double dTakeInRate = 0;         //TakeIn 부가세 율
                double dTakeOutRate = 0;        //TakeOut 부가세 율


                double dTakeInMax = 0;          //TakeIn 부가세 최대값
                double dTakeOutMax = 0;         //TakeOut 부가세 최대값

                int iTakeInMaxIndx = 0;         //TakeIn 부가세 최대값 인덱스
                int iTakeOutMaxIndx = 0;        //TakeOut 부가세 최대값 인덱스


                ArrayList alTrPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                IDataCommonUs m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
                

                dTakeInRate = m_cDataCommon.ItemTaxRate(m_cPosStatus.Mst.BasicTakeInTaxCd);
                dTakeOutRate = m_cDataCommon.ItemTaxRate(m_cPosStatus.Mst.BasicTakeOutTaxCd);
                
                //1. 부가세 계산 방식 체크(아이템SUM or 거래합계 배분)
                if (m_cPosStatus.Mst.TaxAmtCalcMethd == ItemConst.TAX_AMT_CALC_METHD.BILL)
                {
                    //거래 합계 후 아이템 분배
                    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                    {
                        #region
                        if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.NOTAX_DIV != PosConst.ITEM_NOTAX_DIV.YES && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
                        {
                            //면세 체크(2016-12-05 100% 할인경우 체크 추가)
                            if (cPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX && cPluItem.BILL_AMT > 0)
                            {
                                if (cPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN)
                                {
                                    cPluItem.TAXRATE_CD = m_cPosStatus.Mst.BasicTakeInTaxCd;
                                    cPluItem.TAX_RATE = dTakeInRate;
                                    dItemTakeInSum = CmUtil.DoubleAdd(dItemTakeInSum, CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT));
                                }
                                else
                                {
                                    cPluItem.TAXRATE_CD = m_cPosStatus.Mst.BasicTakeOutTaxCd;
                                    cPluItem.TAX_RATE = dTakeOutRate;
                                    dItemTakeOutSum = CmUtil.DoubleAdd(dItemTakeOutSum, CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT));
                                }
                            }
                            else
                            {
                                cPluItem.APPLY_TAX_AMT = 0;
                                cPluItem.TAX_RATE = 0;
                            }
                        }
                        #endregion
                    }

                    if (dItemTakeInSum > 0 || dItemTakeOutSum > 0)
                    {
                        //전체 부가세 계산

                        #region
                        if (dItemTakeInSum > 0)
                        {
                            //dTaxTakeInSum = dItemTakeInSum - (dItemTakeInSum / (1 + (dTakeInRate / 100)));
                            dTaxTakeInSum = CmUtil.DoubleSubtraction(dItemTakeInSum, CmUtil.DoubleDivision(dItemTakeInSum, CmUtil.DoubleAdd(1, CmUtil.DoubleDivision(dTakeInRate, 100))));
                            dTaxTakeInSum = CmUtil.MathRounds(dTaxTakeInSum, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                        }

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

                        double dItemTaxRate;
                        double dItemTaxAmt;
                        
                        //아이템 배분 처리
                        //foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                        for (int iRow = 0; alTrPluItem.Count > iRow ; iRow++)
                        {
                            #region
                            Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alTrPluItem[iRow];

                            if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
                            {

                                dItemTaxRate = 0;
                                dItemTaxAmt = 0;
                                
                                //면세 체크
                                if (cPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX && cPluItem.NOTAX_DIV != PosConst.ITEM_NOTAX_DIV.YES && cPluItem.BILL_AMT > 0)
                                {
                                    #region

                                    if (cPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN)
                                    {
                                        dItemTaxRate = CmUtil.DoubleMultiplication(CmUtil.DoubleDivision(CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT), dItemTakeInSum), 100);
                                        dItemTaxAmt = CmUtil.DoubleDivision(dTaxTakeInSum, CmUtil.DoubleDivision(100, dItemTaxRate));
                                        cPluItem.APPLY_TAX_AMT = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                                        dTaxTakeInSumAppy = CmUtil.DoubleAdd(dTaxTakeInSumAppy, cPluItem.APPLY_TAX_AMT);


                                        if (dTakeInMax == 0 || dTakeInMax <= cPluItem.APPLY_TAX_AMT)
                                        {
                                            dTakeInMax = cPluItem.APPLY_TAX_AMT;
                                            iTakeInMaxIndx = iRow;
                                        }

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

                                        if (dTakeOutMax == 0 || dTakeOutMax <= cPluItem.APPLY_TAX_AMT)
                                        {
                                            dTakeOutMax = cPluItem.APPLY_TAX_AMT;
                                            iTakeOutMaxIndx = iRow;
                                        }
                                    }

                                    #endregion
                                }
                            }

                            #endregion
                        }
                        
                        //짜투리 금액 계산 Take In
                        if (dTaxTakeInSum != dTaxTakeInSumAppy)
                        {
                            #region
                            Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)alTrPluItem[iTakeInMaxIndx];

                            dItemTaxAmt = 0;
                            dItemTaxAmt = CmUtil.DoubleSubtraction(dTaxTakeInSum, dTaxTakeInSumAppy);

                            tmpPluItem.APPLY_TAX_AMT = CmUtil.DoubleAdd(tmpPluItem.APPLY_TAX_AMT, dItemTaxAmt);
                            #endregion

                        }

                        //짜투리 금액 계산 Take Out
                        if (dTaxTakeOutSum != dTaxTakeOutSumAppy)
                        {
                            #region
                            Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)alTrPluItem[iTakeOutMaxIndx];


                            dItemTaxAmt = 0;
                            dItemTaxAmt = CmUtil.DoubleSubtraction(dTaxTakeOutSum, dTaxTakeOutSumAppy);

                            tmpPluItem.APPLY_TAX_AMT = CmUtil.DoubleAdd(tmpPluItem.APPLY_TAX_AMT, dItemTaxAmt);
                            #endregion

                        }

                        #endregion
                    }
                }
                else
                {

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

                    double dItemTaxAmt;
                    double dTargetAmt;

                    //상품 낱개별 처리후 거래합 적용
                    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                    {
                        #region
                        dItemTaxAmt = 0;
                        dTargetAmt = 0;

                        if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
                        {
                            //면세 체크
                            if (cPluItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.TAX && cPluItem.NOTAX_DIV != PosConst.ITEM_NOTAX_DIV.YES && cPluItem.BILL_AMT > 0)
                            {
                                dTargetAmt = CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT);

                                #region

                                double dTaxRate = 0;
                                // 상품별 VATCD는 상품마스터만 참조 하면됨(2017.05.29)
                                if (cPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN)
                                {
                                    cPluItem.TAXRATE_CD = cPluItem.ITEM_TAKE_IN_VAT_CD;
                                }
                                else
                                {
                                    cPluItem.TAXRATE_CD = cPluItem.ITEM_TAKE_OUT_VAT_CD;
                                }
                                dTaxRate = m_cDataCommon.ItemTaxRate(cPluItem.TAXRATE_CD);
                                #region
                                //if (m_cPosStatus.Mst.TaxAmtApplydiv == ItemConst.TAX_AMT_APPLY_DIV.BASIC_TAX_APPY)
                                //{
                                //    if (cPluItem.TAKE_IN_OUT_DIV == PosConst.TAKE_IN_OUT_DIV.TAKE_IN)
                                //    {
                                //        dTaxRate = dTakeInRate;
                                //        cPluItem.TAXRATE_CD = m_cPosStatus.Mst.BasicTakeInTaxCd;
                                //    }
                                //    else
                                //    {
                                //        dTaxRate = dTakeOutRate;
                                //        cPluItem.TAXRATE_CD = m_cPosStatus.Mst.BasicTakeOutTaxCd;
                                //    }
                                //}
                                //else
                                //{
                                //    dTaxRate = m_cDataCommon.ItemTaxRate(cPluItem.TAXRATE_CD);
                                //}

                                //dItemTaxAmt = dTargetAmt - (dTargetAmt / (1 + (dTaxRate / 100)));
                                #endregion


                                //#2018.01.02;미주일 경우 부가세 포함, 미포함 옵션에 따라 계산식 다르게 처리;girak.kim;Start
                                /* 기존 소스
                                dItemTaxAmt = CmUtil.DoubleSubtraction(dTargetAmt, CmUtil.DoubleDivision(dTargetAmt, CmUtil.DoubleAdd(1, CmUtil.DoubleDivision(dTaxRate, 100))));
                                
                                dItemTaxAmt = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                                cPluItem.APPLY_TAX_AMT = dItemTaxAmt;
                                cPluItem.TAX_RATE = dTaxRate;
                                */

                                if ( m_cPosStatus.Base.CmpCd.ToUpper().Equals(PosConst.POS_COMPANY_CODE.PCUS))  //m_cPosStatus.Mst.CntryDiv == ItemConst.CNTRY_DIV.US
                                {
                                    #region 미주일경우 상품별 부가세 포함/미포함
                                    if (cPluItem.TAX_AMT_INCLUDE_YN == ItemConst.MST_ITEM_TAX_AMT_INCLUDE_YN.NOT_INCLUDED)//부가세 미포함 경우
                                    {
                                        // (4.75 * 1.07 ) - (4.75)
                                        dItemTaxAmt = CmUtil.DoubleAdd(1, CmUtil.DoubleDivision(dTaxRate, 100));//1 + (7/100) = 1.07
                                        dItemTaxAmt = CmUtil.DoubleMultiplication(dTargetAmt, dItemTaxAmt); //4.75*1.07
                                        dItemTaxAmt = CmUtil.DoubleSubtraction(dItemTaxAmt, dTargetAmt);//(4.75*1.07) - (4.75)
                                        dItemTaxAmt = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                                        //dItemTaxAmt = CmUtil.MathRounds(dItemTaxAmt, "2", CmUtil.IntParse("3"));//소수점 3째자리 무조건 버림
                                        cPluItem.APPLY_TAX_AMT = dItemTaxAmt;
                                        cPluItem.TAX_RATE = dTaxRate;
                                    }
                                    else if (cPluItem.TAX_AMT_INCLUDE_YN == ItemConst.MST_ITEM_TAX_AMT_INCLUDE_YN.INCLUDED)  // 부가세 포함
                                    {
                                        //dItemTaxAmt = CmUtil.DoubleSubtraction(dTargetAmt, CmUtil.DoubleDivision(dTargetAmt, CmUtil.DoubleAdd(1, CmUtil.DoubleDivision(dTaxRate, 100))));

                                        dItemTaxAmt = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                                        cPluItem.APPLY_TAX_AMT = dItemTaxAmt;
                                        cPluItem.TAX_RATE = dTaxRate;
                                    }
                                    else // N , 또는 설정 없음 일 경우 면세처리..
                                    {
                                        cPluItem.APPLY_TAX_AMT = 0;
                                        cPluItem.TAX_RATE = 0;
                                    }
                                    #endregion
                                }
                                else//그 외는 국가는 기존 계산 방식과 동일
                                {                                    
                                    dItemTaxAmt = CmUtil.DoubleSubtraction(dTargetAmt, CmUtil.DoubleDivision(dTargetAmt, CmUtil.DoubleAdd(1, CmUtil.DoubleDivision(dTaxRate, 100))));

                                    dItemTaxAmt = CmUtil.MathRounds(dItemTaxAmt, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                                    cPluItem.APPLY_TAX_AMT = dItemTaxAmt;
                                    cPluItem.TAX_RATE = dTaxRate;
                                }

                                //#2018.01.02;미주일 경우 부가세 포함, 미포함 옵션에 따라 계산식 다르게 처리;girak.kim;End

                                #endregion
                            }
                            else
                            {
                                cPluItem.APPLY_TAX_AMT = 0;
                                cPluItem.TAX_RATE = 0;
                            }
                        }
                        #endregion
                    }
                }


                ServiceChargeProc();

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

        }

        /// <summary>
        /// 봉사료 적용
        /// </summary>
        /// <returns></returns>
        public bool ServiceChargeProc()
        {
            bool bRet = false;

            try
            {

                ArrayList alTrPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                IDataCommonUs m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);



                double dBasicAmt = 0;       //봉사료 대상 기준 금액

                double dTargetAmt = 0;      //봉사료 대상 금액
                double dItemTaxAmt = 0;     //봉사료 세금 금액

                double dApplyAmt = 0;       //봉사료 적용 금액

                double dLastService = 0;        //Service 짜투리 적용 금액

                double dServiceMax = 0;         //Service 최대값
                int iServiceIdx = 0;            //Service 최대값 인덱스


                if (m_cPosStatus.Mst.SeriveFreeApplyDiv == ItemConst.SERVICE_CHARGE_APPLY_DIV.BILL)
                {
                    //거래 합계 후 아이템 분배

                    #region
                    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                    {
                        if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL && cPluItem.BILL_AMT > 0 && cPluItem.SVC_FEE_TRGT_YN == "1")
                        {
                            dBasicAmt = CmUtil.DoubleAdd(dBasicAmt, CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT));
                        }

                        cPluItem.SVC_TAXREATE_CD = "";
                        cPluItem.SVC_FEE_AMT = 0;
                        cPluItem.SVC_FEE_VAT = 0;
                    }

                    if (dBasicAmt > 0)
                    {
                        dItemTaxAmt = 0;

                        //1-1. 적용 금액 체크

                        #region
                        if (m_cPosStatus.Mst.SeriveFreeDiv == ItemConst.SERVICE_CHARGE_DIV.RATE)    //율
                        {
                            if (m_cPosStatus.Mst.SeriveFree > 0)
                            {
                                dTargetAmt = GetPercentageAmt(dBasicAmt, m_cPosStatus.Mst.SeriveFree, 1);
                            }
                            else
                            {
                                dTargetAmt = 0;
                                UserLog.WriteLogFile(UserCom.LOG_ERROR,System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()","봉사료 적용 율 없음!");
                            }
                        }
                        else if (m_cPosStatus.Mst.SeriveFreeDiv == ItemConst.SERVICE_CHARGE_DIV.AMT)    //금액
                        {
                            dTargetAmt = CmUtil.MathRounds(m_cPosStatus.Mst.SeriveFree, m_cPosStatus.Mst.ItemRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.ItemRudDwLoc));
                        }

                        #endregion


                        if (dTargetAmt > 0)
                        {
                            //1-2. 분배 처리
                            for (int iRow = 0; alTrPluItem.Count > iRow; iRow++)
                            {
                                #region
                                Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alTrPluItem[iRow];

                                if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL && cPluItem.SVC_FEE_TRGT_YN == "1")
                                {
                                    cPluItem.SVC_FEE_AMT = GetPercentageDcAmt(dBasicAmt, CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT), dTargetAmt, 1);
                                    dApplyAmt = CmUtil.DoubleAdd(dApplyAmt, cPluItem.SVC_FEE_AMT);

                                    if (dServiceMax == 0 || dServiceMax <= cPluItem.SVC_FEE_AMT)
                                    {
                                        dServiceMax = cPluItem.SVC_FEE_AMT;
                                        iServiceIdx = iRow;
                                    }
                                }
                                #endregion
                            }

                            //1-3. 짜투리 금액 계산
                            if (dTargetAmt != dApplyAmt)
                            {
                                #region
                                Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)alTrPluItem[iServiceIdx];

                                dLastService = 0;

                                dLastService = CmUtil.DoubleSubtraction(dTargetAmt, dApplyAmt);

                                tmpPluItem.SVC_FEE_AMT = CmUtil.DoubleAdd(tmpPluItem.APPLY_TAX_AMT, dLastService);


                                //for (int iRow = alTrPluItem.Count - 1; iRow >= 0; iRow--)
                                //{
                                //    Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)alTrPluItem[iRow];

                                //    if (tmpPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && tmpPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL && tmpPluItem.SVC_FEE_TRGT_YN == "1")
                                //    {
                                //        tmpPluItem.SVC_FEE_AMT = CmUtil.DoubleAdd(tmpPluItem.SVC_FEE_AMT, CmUtil.DoubleSubtraction(dTargetAmt, dApplyAmt));
                                //        break;
                                //    }
                                //}

                                #endregion
                            }

                            // 2. 봉사료 부가세 처리
                            if (m_cPosStatus.Mst.SeriveFreeTaxAmtDiv != "")
                            {
                                #region
                                double dRate = m_cDataCommon.ItemTaxRate(m_cPosStatus.Mst.SeriveFreeTaxAmtDiv);

                                if (dRate > 0)
                                {
                                    //상품 낱개별 처리후 거래합 적용
                                    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                                    {
                                        if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL && cPluItem.SVC_FEE_TRGT_YN == "1" && cPluItem.SVC_FEE_AMT > 0)
                                        {
                                            cPluItem.SVC_FEE_VAT = GetTaxAmt(cPluItem.SVC_FEE_AMT, dRate);
                                            cPluItem.SVC_TAXREATE_CD = m_cPosStatus.Mst.SeriveFreeTaxAmtDiv;
                                        }
                                    }
                                }

                                #endregion
                            }
                        }
                    }

                    #endregion
                }
                else if (m_cPosStatus.Mst.SeriveFreeApplyDiv == ItemConst.SERVICE_CHARGE_APPLY_DIV.ITEM)
                {
                    //아이템 계산 후 합계 적용
                    #region
                    //상품 낱개별 처리후 거래합 적용
                    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                    {
                        dTargetAmt = 0;
                        dItemTaxAmt = 0;

                        if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL && cPluItem.SVC_FEE_TRGT_YN =="1")
                        {
                            //1. 적용 금액 체크

                            #region
                            if (m_cPosStatus.Mst.SeriveFreeDiv == ItemConst.SERVICE_CHARGE_DIV.RATE)    //율
                            {
                                if (m_cPosStatus.Mst.SeriveFree > 0)
                                {
                                    dTargetAmt = GetPercentageAmt(CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT), m_cPosStatus.Mst.SeriveFree, 1);
                                }
                                else
                                {
                                    dTargetAmt = 0;
                                    UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "봉사료 적용 율 없음!");
                                }
                            }
                            else if (m_cPosStatus.Mst.SeriveFreeDiv == ItemConst.SERVICE_CHARGE_DIV.AMT)    //금액
                            {
                                dTargetAmt = CmUtil.MathRounds(m_cPosStatus.Mst.SeriveFree, m_cPosStatus.Mst.ItemRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.ItemRudDwLoc));
                            }
                            #endregion

                            //2. 부가세 금액 체크

                            #region
                            if (m_cPosStatus.Mst.SeriveFreeTaxAmtDiv != "" && dTargetAmt > 0)
                            {
                                double dRate = m_cDataCommon.ItemTaxRate(m_cPosStatus.Mst.SeriveFreeTaxAmtDiv);

                                if (dRate > 0)
                                {
                                    dItemTaxAmt = GetTaxAmt(cPluItem.SVC_FEE_AMT, dRate);
                                }
                                else
                                {
                                    dItemTaxAmt = 0;
                                }
                            }

                            #endregion
                        }

                        cPluItem.SVC_FEE_AMT = dTargetAmt;
                        cPluItem.SVC_FEE_VAT = dItemTaxAmt;

                        if (cPluItem.SVC_FEE_VAT > 0)
                            cPluItem.SVC_TAXREATE_CD = m_cPosStatus.Mst.SeriveFreeTaxAmtDiv;
                    }
                    #endregion
                }
                else
	            {
                    // 미국의 경우 입력 받았을 때 처리!
                    if (m_cTrnStatus.Head.SvcFeeAmt > 0 || m_cTrnStatus.Head.SvcFeeAmt == -999)
                    {
                        #region
                        // -999면 등록 취소
                        if (m_cTrnStatus.Head.SvcFeeAmt == -999)
                        {
                            m_cTrnStatus.Head.SvcFeeAmt = 0;
                            
                            //1-2. 분배 처리
                            foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                            {
                                if (cPluItem.SVC_FEE_AMT > 0 || cPluItem.SVC_FEE_VAT > 0)
                                {
                                    cPluItem.SVC_TAXREATE_CD = "";
                                    cPluItem.SVC_FEE_AMT = 0;
                                    cPluItem.SVC_FEE_VAT = 0;
                                }
                            }
                        }
                        else
                        {
                            dApplyAmt = 0;
                            dTargetAmt = m_cTrnStatus.Head.SvcFeeAmt;
                            dBasicAmt = m_cTrnStatus.Head.NetSaleAmt;

                            //1-2. 분배 처리

                            #region
                            for (int iRow = 0; alTrPluItem.Count > iRow; iRow++)
                            {
                                Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alTrPluItem[iRow];

                                if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
                                {
                                    cPluItem.SVC_FEE_AMT = GetPercentageDcAmt(dBasicAmt, CmUtil.DoubleSubtraction(cPluItem.SALE_AMT, cPluItem.TOT_DC_AMT), dTargetAmt, 1);
                                    dApplyAmt = CmUtil.DoubleAdd(dApplyAmt, cPluItem.SVC_FEE_AMT);

                                    if (dServiceMax == 0 || dServiceMax <= cPluItem.SVC_FEE_AMT)
                                    {
                                        dServiceMax = cPluItem.SVC_FEE_AMT;
                                        iServiceIdx = iRow;
                                    }

                                }
                                else
                                {
                                    cPluItem.SVC_TAXREATE_CD = "";
                                    cPluItem.SVC_FEE_AMT = 0;
                                }
                            }

                            #endregion

                            //1-3. 짜투리 금액 계산

                            #region
                            if (dTargetAmt != dApplyAmt)
                            {


                                Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)alTrPluItem[iServiceIdx];

                                dLastService = 0;

                                dLastService = CmUtil.DoubleSubtraction(dTargetAmt, dApplyAmt);

                                tmpPluItem.SVC_FEE_AMT = CmUtil.DoubleAdd(tmpPluItem.APPLY_TAX_AMT, dLastService);


                                //for (int iRow = alTrPluItem.Count - 1; iRow >= 0; iRow--)
                                //{
                                //    Column.TR_PLU.DATA tmpPluItem = (Column.TR_PLU.DATA)alTrPluItem[iRow];

                                //    if (tmpPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && tmpPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL)
                                //    {
                                //        tmpPluItem.SVC_FEE_AMT = CmUtil.DoubleAdd(tmpPluItem.SVC_FEE_AMT, CmUtil.DoubleSubtraction(dTargetAmt, dApplyAmt));
                                //        break;
                                //    }
                                //}
                            }

                            #endregion

                            // 2. 봉사료 부가세 처리

                            #region
                            if (m_cPosStatus.Mst.SeriveFreeTaxAmtDiv != "")
                            {
                                m_cTrnStatus.Head.SvcFeeVat = 0;
                                double dRate = m_cDataCommon.ItemTaxRate(m_cPosStatus.Mst.SeriveFreeTaxAmtDiv);

                                if (dRate > 0)
                                {
                                    //상품 낱개별 처리후 거래합 적용
                                    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                                    {
                                        if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.NORMAL && cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.NORMAL && cPluItem.SVC_FEE_AMT > 0)
                                        {
                                            cPluItem.SVC_FEE_VAT = GetTaxAmt(cPluItem.SVC_FEE_AMT, dRate);
                                            cPluItem.SVC_TAXREATE_CD = m_cPosStatus.Mst.SeriveFreeTaxAmtDiv;
                                            m_cTrnStatus.Head.SvcFeeVat = CmUtil.DoubleAdd(m_cTrnStatus.Head.SvcFeeVat, cPluItem.SVC_FEE_VAT);
                                        }
                                    }
                                }
                                else
                                {
                                    //상품 낱개별 처리후 거래합 적용
                                    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                                    {
                                        if (cPluItem.SVC_FEE_VAT > 0)
                                        {
                                            cPluItem.SVC_FEE_VAT = 0;
                                            cPluItem.SVC_TAXREATE_CD = "";
                                        }
                                    }
                                }
                            }
                            #endregion
                        }

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

            }
            return bRet;

        }

        /// <summary>
        /// 기준 대비 대상 율 구하기
        /// </summary>
        /// <param name="dBasic"></param>
        /// <param name="dTarget"></param>
        /// <param name="bPoint"></param>
        /// <returns></returns>
        public double GetPercentageRate(double dBasic, double dTarget, bool bPoint)
        {

            double bRate = 0;

            try
            {
                bRate = CmUtil.DoubleMultiplication(CmUtil.DoubleDivision(dTarget, dBasic), bPoint == true ? 1 : 100);
            }
            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 bRate;
        }

        /// <summary>
        /// 대상을 율로 값 구하기
        /// </summary>
        /// <param name="dTarget">대상</param>
        /// <param name="dRate">율</param>
        /// <param name="iCutFlag">1:금액배분절삭,2:부가세배분절삭,그외없음</param>
        /// <returns></returns>
        public double GetPercentageAmt(double dTarget, double dRate, int iCutFlag)
        {
            try
            {
                
                
                if (dRate > 1) dRate = CmUtil.DoubleDivision(dRate, 100);

                double dRetValue = CmUtil.DoubleMultiplication(dTarget, dRate);

                if (iCutFlag == 1)  //금액 배분 절삭
                {
                    dRetValue = CmUtil.MathRounds(dRetValue, m_cPosStatus.Mst.ItemRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.ItemRudDwLoc));
                }
                else if (iCutFlag == 2) //부가세 배분 절삭
                {
                    dRetValue = CmUtil.MathRounds(dRetValue, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                }

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

        /// <summary>
        /// 최종기준 금액 구하기
        /// </summary>
        /// <param name="dBasic">기준</param>
        /// <param name="dTarget">대상</param>
        /// <param name="dDcAmt">최종기준</param>
        /// <param name="iCutFlag">1:금액배분절삭,2:부가세배분절삭,그외없음</param>
        /// <returns></returns>
        public double GetPercentageDcAmt(double dBasic, double dTarget, double dLastBasic, int iCutFlag)
        {

            try
            {
                double dRetValue = CmUtil.DoubleMultiplication(dLastBasic, GetPercentageRate(dBasic, dTarget, true));

                if (iCutFlag == 1)  //금액 배분 절삭
                {
                    dRetValue = CmUtil.MathRounds(dRetValue, m_cPosStatus.Mst.ItemRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.ItemRudDwLoc));
                }
                else if (iCutFlag == 2) //부가세 배분 절삭
                {
                    dRetValue = CmUtil.MathRounds(dRetValue, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                }

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

            }
            return 0;
        }

        public double GetTaxAmt(double dTarget, double dTaxRate)
        {

            try
            {

                if (dTaxRate > 1) dTaxRate = CmUtil.DoubleDivision(dTaxRate, 100);

                double dRetValue = CmUtil.DoubleSubtraction(dTarget, CmUtil.DoubleDivision(dTarget, CmUtil.DoubleAdd(1, dTaxRate)));

                dRetValue = CmUtil.MathRounds(dRetValue, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
                
                return dRetValue;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);

            }
            return 0;
        }


        //public double GetPercentageDcAmt(double dBasic, double dTarget, double dDcRate)
        //{

        //    double bRate = 0;

        //    try
        //    {

        //        if (dDcRate > 1) dDcRate = CmUtil.DoubleDivision(dDcRate, 100);

        //        // 기준 금액에 할인율 할인 금액 구하기!
        //        double dDcAmt = CmUtil.DoubleMultiplication(dBasic, dDcRate);
                
        //        // 기준 금액을 기준으로 대상 금액 할인율 구하기
        //        double dTargetDcRate = GetPercentage(dBasic, dTarget, true);

        //        // 할인 금액을 대상 금액 비율로 금액 구하기!
        //        bRate = CmUtil.DoubleMultiplication(dDcAmt, dTargetDcRate);

        //    }
        //    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 bRate;
        //}


        /// <summary>
        /// 문자열의 숫자(Int)로 변환
        /// </summary>
        /// <param name="sValue"></param>
        /// <returns></returns>
        public int IntParse(string sValue)
        {
            return (int)DoubleParse(sValue);
        }
        /// <summary>
        /// 문자열의 숫자(Long)로 변환
        /// </summary>
        /// <param name="sValue"></param>
        /// <returns></returns>
        public long LongParse(string sValue)
        {
            return (long)DoubleParse(sValue);
        }
        /// <summary>
        /// 문자열의 숫자(Double)로 변환
        /// </summary>
        /// <param name="sValue"></param>
        /// <returns></returns>
        public double DoubleParse(string sValue)
        {
            double dValue = 0;
            try
            {
                if (sValue.Trim().Length > 0)
                {
                    // 화폐 문자열 이면 글로벌 변환 처리
                    if (sValue.Trim().Contains(m_cPosStatus.Global.m_stCultureMaster.strGroupingSymbol) == true || sValue.Trim().Contains(m_cPosStatus.Global.m_stCultureMaster.strDecimalSymbol) == true)
                        dValue = m_cPosStatus.Global.CurrencyTONumeric(sValue.Trim());
                    else
                        dValue = double.Parse(sValue.Trim());
                }
            }
            catch { }

            return dValue;
        }

        /// <summary>
        /// 전체 금액 대비 결제 금액 부가세 구하기
        /// </summary>
        /// <param name="dPayAmt"></param>
        /// <returns></returns>
        public double GetPaymentAmtVAT(double dPayAmt)
        {

            double dTax = 0;

            try
            {
                dTax = m_cTrnStatus.Head.TotVatAmt * (dPayAmt / m_cTrnStatus.Head.NetSaleAmt);
                dTax = CmUtil.MathRounds(dTax, m_cPosStatus.Mst.VatRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.VatRudDwLoc));
            }
            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 dTax;
        }
    }
}
