using System;
using System.Collections;

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 배달(콜센터) 및 배달의민족
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class SaleDelivery : PaymentBase, IPaymentUs
    {
        public SaleDelivery()
        {
        }

        #region 결제 조회
        /// <summary>
        /// 결제 조회
        /// </summary>
        /// <param name="aParam"></param>
        /// <param name="aRet"></param>
        /// <returns></returns>
        public string SearchPayment(string[] aParam, ref string[] aRet)
        {
            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
            {
            }
            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">결제세부코드</param>
        /// <returns></returns>
        public string SetPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                string sMenuKey = aParam[0];            // 기능코드
                
                if (m_cTrnStatus.Sale.RecvedPayAmt > 0)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0198);
                    return sRet;
                }

                if (sMenuKey == PosKey.MENU_KEY.ORDER_CALLCENTER)      // 배달(콜센터)
                {
                    if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0362) == false) return sRet;

                    // 배달 배송비 상품 등록 처리
                    if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0372) == true)
                    {
                        ISalePluItemUs cPluService = (ISalePluItemUs)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.SALE_PLU_ITEM);
                        sRet = cPluService.SetItemCode("", PosConst.SALE_PLU_INPUT_TYPE.MENUKEY + CmUtil.RPadH(m_cTrnStatus.Sale.SubStoreCode, 10) + PosConst.ORDER_CALLCENTER.PLU_CD, "");
                        if (sRet != UserCom.RST_OK) return sRet;
                    }
                }
                else if (sMenuKey == PosKey.MENU_KEY.ORDER_BAEMIN)     // 배달(배달의민족))
                {
                    if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0363) == false) return sRet;
                }
                else if (sMenuKey == PosKey.MENU_KEY.ORDER_YOGIYO)     // 배달(요기요)(2017.05.15)
                {
                    if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0695) == false) return sRet;
                }

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

                Column.TR_PAYMENT.DATA cPayItem = new Column.TR_PAYMENT.DATA();

                cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.ORDER_ITEM;   
                if ( sMenuKey == PosKey.MENU_KEY.ORDER_CALLCENTER)          // 배달(콜센터)
                    cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.ORDER.CALLCENTER_PAY;
                else if ( sMenuKey == PosKey.MENU_KEY.ORDER_BAEMIN)         // 배달(배달의민족))
                    cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.ORDER.BAEMIN_PAY;
                else if (sMenuKey == PosKey.MENU_KEY.ORDER_YOGIYO)          // 배달(요기요)(2017.05.15)
                    cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.ORDER.YOGIYO_PAY;

                cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;
    
                cPayItem.PAY_AMT = m_cTrnStatus.Sale.RemainPayAmt;          // 결제 금액

                cPayItem.AMT_ENTRY_01 = m_cTrnStatus.Sale.RemainPayAmt;     // 받은돈

                cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01);   // 결제수단명
                cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01);   // 현금영수증 발행여부

                if (cPayItem.OCCUR_ENTRY_20 == "")
                {
                    if (sMenuKey == PosKey.MENU_KEY.ORDER_CALLCENTER)      // 배달(콜센터)
                        cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0578);  
                    else if (sMenuKey == PosKey.MENU_KEY.ORDER_BAEMIN)     // 배달(배달의민족))
                        cPayItem.OCCUR_ENTRY_20 = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0579);  
                }
                if (cPayItem.OCCUR_ENTRY_21 == "")
                {
                    cPayItem.OCCUR_ENTRY_21 = ItemConst.PAY_CASHBILL_DIV.NO;
                }

                cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;        // 빌분리 번호
                cPayItem.SEQ = aPayItem.Count + 1;
                cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.NORMAL;

                aPayItem.Add(cPayItem);

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

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

        #region 결제 취소
        /// <summary>
        /// 결제 취소
        /// </summary>
        /// <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_cDataService.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


    }
}
