using System;
using System.Collections;

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 예약결제
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class ReservedPay : IPaymentUs
    {
        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 IDataProcessUs m_cDataSrv = null;                                   // 거래데이터 합계금액 계산 및 관리
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스

        public ReservedPay()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보
            m_cDataSrv = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
        }

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

            string sRet = UserCom.RST_ERR;

            try
            {
                
                
            }
            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 UserCom.RST_ERR;
        }
        #endregion

        #region 결제 정보 획득
        /// <summary>
        /// 결제 정보 획득
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public object GetPayment(string[] aParam)
        {
            try
            {
                //return m_cPayItem;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return null;
        }
        #endregion

        #region 결제 등록
        /// <summary>
        /// 결제 등록
        /// </summary>
        /// <param name="aParam">현금 결제금액(0), 현금,수표구분(1)</param>
        /// <returns></returns>
        public string SetPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            try
            {

                double nPayAmt = CmUtil.DoubleParse(aParam[0]);

                // 등록된 할인을 취소 하시겠습니까?
                if (WinManager.QuestionMessage(string.Format(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0212), m_cPosStatus.Global.NumericTOCurrency(nPayAmt))) == false)    
                    return sRet;
                
                // 결제 내역 받아 오기
                ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);

                Column.TR_PAYMENT.DATA m_cPayItem = new Column.TR_PAYMENT.DATA();
                
                
                // 예약 결제
                m_cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.RESERVATION_ITEM;                          //예약 결제 그룹 코드
                m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.RESERVATION.BALANCE_PAY;                //예약 결제 코드
                m_cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0281); //결제 수단명
                

                m_cPayItem.OCCUR_ENTRY_21 = ItemConst.PAY_CASHBILL_DIV.NO;

                m_cPayItem.PAY_AMT = nPayAmt;                               //결제 금액
                m_cPayItem.AMT_ENTRY_01 = nPayAmt;                          //받은돈
                m_cPayItem.AMT_ENTRY_02 = 0;                                //거스름
                m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;

                m_cPayItem.SEQ = aPayItem.Count + 1;

                m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.NORMAL;

                aPayItem.Add(m_cPayItem);

                // 결제 금액 재 계산 처리
                m_cDataSrv.UpdatePayAmount();

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

        #region 결제 취소
        /// <summary>
        /// 결제 취소
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string CancelPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                int nPayRow = CmUtil.IntParse(aParam[0]); // 취소할 행번호

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

                Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA) alPayItem[nPayRow];

                cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;

                // 결제 금액 재 계산 처리
                m_cDataSrv.UpdateTranAmount();

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

        #region 결제 반품
        /// <summary>
        /// 결제 반품
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string RefundPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                // 반품시 처리 내역 없음
                sRet = UserCom.RST_OK;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }
        #endregion

        #region 결제 수기 등록(임의등록)
        /// <summary>
        /// 결제 수기 등록(임의등록)
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetMenualPayment(string[] aParam) 
        {
            try
            {
                return UserCom.RST_OK;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return UserCom.RST_ERR;
        }
        #endregion 결제 수기 등록(임의등록)

    }
}
