public GetPolicyDetailForPayment_Result GetPolicyDetailForPayment(string partnerUsername, string partnerPassword, string policyNumber)
    {
        GetPolicyDetailForPayment_Result obj = new GetPolicyDetailForPayment_Result();
        RefRunningTBBLL runningobj = new RefRunningTBBLL();
        this.refnum = runningobj.AddRefRunningTBAndReturn();
        WSLogBLL logobj = new WSLogBLL();
        string methodName = "GetPolicyDetailForPayment";

        try
        {
            if (partnerUsername == "" || partnerPassword == "" || policyNumber == "")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุข้อมูลให้ครบถ้วน";
            }
            else if (policyNumber.Trim().Substring(0, 2) == "PA")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์";
            }
            else if (policyNumber.Length != 10 || !MTL.Utils.ThisWeb.CheckIsNumeric(policyNumber))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุเลขกรมธรรม์ให้ถูกต้อง";
            }
            else
            {
                // พิสูจน์ตัวตนของพันธมิตรก่อนที่จะให้ใช้งานจริง
                NETWS_ForPartnerAuthenticationChecking.CheckPartnerAuthentication_Result pacobj = CheckPartnerAuthenticationReturnDetail(partnerUsername, partnerPassword, this.ipaddress);
                if (pacobj.Result.Trim().ToLower() == "passed")
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                    // ดึงข้อมูลรายละเอียดของกรมธรรม์กับ ApplinX WS_Admin
                    ApplinXGetShortPolicyDetail2Result resAdminObj = new ApplinXGetShortPolicyDetail2Result();
                    MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService adminWSObj = new MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService();
                    resAdminObj.fld_result = adminWSObj.GetShortPolicyDetail2(this.admin_username, this.admin_password, policyNumber, out resAdminObj.fld_sessionID, out resAdminObj.fld_service_agent, out resAdminObj.fld_client_name, out resAdminObj.fld_face_amount, out resAdminObj.fld_paid_mode, out resAdminObj.fld_plan_code, out resAdminObj.fld_plan_name, out resAdminObj.fld_total_premium, out resAdminObj.fld_policy_status, out resAdminObj.fld_issue_date, out resAdminObj.fld_warning_message);
                    if (resAdminObj.fld_result.Trim().ToLower() == "found")
                    {
                        //// ตรวจสอบว่าสถานะกรมธรรม์เป็น 1/B/7/9 หรือไม่ ถ้าไม่เป็นจะไม่ยอมให้ชำระต่ออายุออนไลน์
                        //if (resAdminObj.fld_policy_status.Trim().ToUpper() != "1" && resAdminObj.fld_policy_status.Trim().ToUpper() != "B" && resAdminObj.fld_policy_status.Trim().ToUpper() != "7" && resAdminObj.fld_policy_status.Trim().ToUpper() != "9")
                        // 20150115 พี่ไร, พี่มด ให้รองรับเฉพาะสถานะกรมธรรม์เป็น 1 เท่านั้น
                        // ตรวจสอบว่าสถานะกรมธรรม์เป็น 1 หรือไม่ ถ้าไม่เป็นจะไม่ยอมให้ชำระต่ออายุออนไลน์
                        if (resAdminObj.fld_policy_status.Trim().ToUpper() != "1")
                        {
                            obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์";
                        }
                        else
                        {
                            // ตรวจสอบว่าเป็นกรมธรรม์ที่สามารถรับชำระด้วยวิธีการใดได้บ้าง
                            if (resAdminObj.fld_warning_message.Contains("อนุโลม"))
                            {
                                obj.PaymentTypeToPay = "CCP|CDC";
                            }
                            else if (resAdminObj.fld_warning_message.Contains("ไม่รับบัตรเครดิต"))
                            {
                                obj.PaymentTypeToPay = "CCP";
                            }
                            else
                            {
                                obj.PaymentTypeToPay = "CCP|CDC";
                            }

                            // ตรวจสอบว่าเป็นกรมธรรม์ประเภท PA หรือไม่ (เลขกรมธรรม์ขึ้นต้นด้วย 8) ถ้าใช่จะต้องไปเอาค่าเบี้ยประกันรวมจากหน้าจอใบเสร็จ
                            if (policyNumber.Trim().Substring(0, 1) == "8")
                            {
                                MTL.WS_Admin.WS_Admin_ForMTLmPOS.CPINQ03_ReceiptDetailList[] receiptList;
                                string receiptResult = adminWSObj.GetReceiptDetailList(this.admin_username, this.admin_password, policyNumber, "", "", out resAdminObj.fld_sessionID, out receiptList);
                                if (receiptResult.Trim().ToLower() == "completed")
                                {
                                    var lastListResult = receiptList.Last();

                                    obj.TotalPremium = lastListResult.Amount.Trim();
                                }
                                else
                                {
                                    obj.TotalPremium = resAdminObj.fld_total_premium.Trim();
                                }
                            }
                            else
                            {
                                obj.TotalPremium = resAdminObj.fld_total_premium.Trim();
                            }

                            obj.Result = "completed";
                            obj.SessionID = resAdminObj.fld_sessionID.Trim();
                            obj.ClientName = resAdminObj.fld_client_name.Trim();
                            obj.FaceAmount = resAdminObj.fld_face_amount.Trim();
                            obj.IssueDate = resAdminObj.fld_issue_date.Trim();
                            obj.PaidMode = resAdminObj.fld_paid_mode.Trim();
                            obj.PlanCode = resAdminObj.fld_plan_code.Trim();
                            obj.PlanName = resAdminObj.fld_plan_name.Trim();
                            obj.PolicyStatus = resAdminObj.fld_policy_status.Trim();
                            obj.ServiceAgent = resAdminObj.fld_service_agent.Trim();
                            obj.WarningMessage = resAdminObj.fld_warning_message.Trim();
                        }
                    }
                    else
                    {
                        obj.Result = resAdminObj.fld_result.Trim().Replace("notfound_", "notcomplete_");
                    }
                }
                else
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                    obj.Result = pacobj.Result.Trim().Replace("notpass_", "notcomplete_");
                }
            }

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result + "|" + obj.PolicyStatus + "|" + obj.TotalPremium + "|" + "|" + obj.WarningMessage + "|" + obj.PlanCode + "|" + obj.PlanName + "|" + obj.ClientName + "|" + obj.SessionID, this.refnum);

            return obj;
        }
        catch (Exception ex)
        {
            obj.Result = "notcomplete_" + ex.Message.ToString();

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result, this.refnum);

            return obj;
        }
    }
    public GetPolicyDetailForPayment_Result GetPolicyDetailForPayment(string partnerUsername, string partnerPassword, string policyNumber)
    {
        GetPolicyDetailForPayment_Result obj   = new GetPolicyDetailForPayment_Result();
        PremiumDetail_Result             pmobj = new PremiumDetail_Result();
        RefRunningTBBLL runningobj             = new RefRunningTBBLL();

        this.refnum = runningobj.AddRefRunningTBAndReturn();
        WSLogBLL logobj     = new WSLogBLL();
        string   methodName = "GetPolicyDetailForPayment";

        try
        {
            if (partnerUsername == "" || partnerPassword == "" || policyNumber == "")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุข้อมูลให้ครบถ้วน";
            }
            else if (policyNumber.Trim().Substring(0, 2) == "PA")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์";
            }
            else if (policyNumber.Length != 10 || !MTL.Utils.ThisWeb.CheckIsNumeric(policyNumber))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุเลขกรมธรรม์ให้ถูกต้อง";
            }
            else
            {
                // พิสูจน์ตัวตนของพันธมิตรก่อนที่จะให้ใช้งานจริง
                NETWS_ForPartnerAuthenticationChecking.CheckPartnerAuthentication_Result pacobj = CheckPartnerAuthenticationReturnDetail(partnerUsername, partnerPassword, this.ipaddress);
                if (pacobj.Result.Trim().ToLower() == "passed")
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                    // ดึงข้อมูลรายละเอียดของกรมธรรม์กับ ApplinX WS_Admin
                    //ApplinXGetShortPolicyDetail2Result resAdminObj = new ApplinXGetShortPolicyDetail2Result();
                    //MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService adminWSObj = new MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService();
                    //resAdminObj.fld_result = adminWSObj.GetpolicyDetail(this.admin_username, this.admin_password, policyNumber, out resAdminObj.fld_sessionID, out resAdminObj.fld_service_agent, out resAdminObj.fld_client_name, out resAdminObj.fld_face_amount, out resAdminObj.fld_paid_mode, out resAdminObj.fld_plan_code, out resAdminObj.fld_plan_name, out resAdminObj.fld_total_premium, out resAdminObj.fld_policy_status, out resAdminObj.fld_issue_date, out resAdminObj.fld_warning_message);
                    ApplinXGetPolicyDetail2Result resAdminObj = new ApplinXGetPolicyDetail2Result();

                    MTL.WS_Admin.WS_Admin_SmileServices.WS_Admin_ForSmartCardService adminWSObj = new MTL.WS_Admin.WS_Admin_SmileServices.WS_Admin_ForSmartCardService();
                    MTL.WS_Admin.WS_Admin_SmileServices.CPINQ02C_F6_PolicyList[]     fld_f6_policy_list;
                    MTL.WS_Admin.WS_Admin_SmileServices.CPINQ02_PolicyRiderList[]    fld_f8_policy_rider_list;

                    resAdminObj.fld_result = adminWSObj.GetPolicyDetail2(this.admin_username, this.admin_password, policyNumber, out resAdminObj.fld_sessionID,
                                                                         out resAdminObj.fld_approve_date, out resAdminObj.fld_attained_date, out resAdminObj.fld_belong_to_agent, out resAdminObj.fld_billed_to_date, out resAdminObj.fld_client_address, out resAdminObj.fld_client_dob, out resAdminObj.fld_client_name, out resAdminObj.fld_coverage_period, out resAdminObj.fld_disability_premium, out resAdminObj.fld_dividend_method,
                                                                         out resAdminObj.fld_extra_paid_period, out resAdminObj.fld_extra_premium, out resAdminObj.fld_face_amount, out resAdminObj.fld_issue_date, out resAdminObj.fld_last_paid_by, out resAdminObj.fld_last_paid_date, out resAdminObj.fld_luanch_date, out resAdminObj.fld_maturity_date, out resAdminObj.fld_next_paid_age, out resAdminObj.fld_owner_agent,
                                                                         out resAdminObj.fld_paid_date, out resAdminObj.fld_paid_mode, out resAdminObj.fld_paid_period, out resAdminObj.fld_payor, out resAdminObj.fld_plan_code, out resAdminObj.fld_plan_name, out resAdminObj.fld_rate_age, out resAdminObj.fld_rider_premium, out resAdminObj.fld_sale_department, out resAdminObj.fld_service_agent,
                                                                         out resAdminObj.fld_total_premium, out resAdminObj.fld_tranche_billed_to, out resAdminObj.fld_tranche_paid, out resAdminObj.fld_year_billed_to, out resAdminObj.fld_year_paid, out resAdminObj.fld_f2_mode_01, out resAdminObj.fld_f2_mode_03, out resAdminObj.fld_f2_mode_06, out resAdminObj.fld_f2_mode_12, out resAdminObj.fld_f4_address1,
                                                                         out resAdminObj.fld_f4_address2, out resAdminObj.fld_f4_business_phone, out resAdminObj.fld_f4_client_number, out resAdminObj.fld_f4_face_amount, out resAdminObj.fld_f4_mobile_phone, out resAdminObj.fld_f4_policy_status, out resAdminObj.fld_f4_resident_phone, out resAdminObj.fld_f4_responsible_team, out resAdminObj.fld_f4_sum_insured, out resAdminObj.fld_f5_misc_susp_date,
                                                                         out resAdminObj.fld_f5_misc_susp_value, out resAdminObj.fld_f5_prem_susp_date, out resAdminObj.fld_f5_prem_susp_value, out fld_f6_policy_list, out resAdminObj.fld_f7_assurance_code, out resAdminObj.fld_f7_hazard_health, out resAdminObj.fld_f7_hazard_occupation, out resAdminObj.fld_f7_health_check_code, out resAdminObj.fld_f8_disability_extra_premium, out resAdminObj.fld_f8_disability_premium,
                                                                         out resAdminObj.fld_f8_disability_total_premium, out resAdminObj.fld_f8_life_extra_premium, out resAdminObj.fld_f8_life_premium, out resAdminObj.fld_f8_life_total_premium, out resAdminObj.fld_f8_sum_extra_premium, out resAdminObj.fld_f8_sum_premium, out resAdminObj.fld_f8_sum_total_premium, out resAdminObj.fld_f8_tranche, out resAdminObj.fld_f8_year, out fld_f8_policy_rider_list,
                                                                         out resAdminObj.fld_warning_message, out resAdminObj.fld_f4_paid_by, out resAdminObj.fld_f4_paid_by_text, out resAdminObj.fld_f4_paid_by_create_date, out resAdminObj.fld_f4_paid_by_cancel_date, out resAdminObj.fld_f4_paid_by_account_number, out resAdminObj.fld_f4_MDC_bank, out resAdminObj.fld_f4_MDC_create_date, out resAdminObj.fld_f4_MDC_cancel_date, out resAdminObj.fld_f4_MDC_account_number,
                                                                         out resAdminObj.fld_f7_preserve_code, out resAdminObj.fld_f7_reinsurance, out resAdminObj.fld_f7_fpo_at, out resAdminObj.fld_f7_message, out resAdminObj.fld_f7_f11_message, out resAdminObj.fld_last_paid_by_text, out resAdminObj.fld_policyIsTakaful, out resAdminObj.fld_policy_status_code, out resAdminObj.fld_policy_status_subcode);
                    //, out resAdminObj.fld_smile_club, out resAdminObj.fld_topup_loan);


                    if (resAdminObj.fld_result.Trim().ToLower() == "found")
                    {
                        //// ตรวจสอบว่าสถานะกรมธรรม์เป็น 1/B/7/9 หรือไม่ ถ้าไม่เป็นจะไม่ยอมให้ชำระต่ออายุออนไลน์
                        //if (resAdminObj.fld_policy_status.Trim().ToUpper() != "1" && resAdminObj.fld_policy_status.Trim().ToUpper() != "B" && resAdminObj.fld_policy_status.Trim().ToUpper() != "7" && resAdminObj.fld_policy_status.Trim().ToUpper() != "9")
                        // 20150115 พี่ไร, พี่มด ให้รองรับเฉพาะสถานะกรมธรรม์เป็น 1 เท่านั้น
                        // ตรวจสอบว่าสถานะกรมธรรม์เป็น 1 หรือไม่ ถ้าไม่เป็นจะไม่ยอมให้ชำระต่ออายุออนไลน์
                        // ตรวจสอบfld_billed_to_date (Next due date กำหนดชำระครั้งต่อไป) ต้องมีค่า
                        // ตรวจสอบ ไม่รับกรมธรรม์ที่เป็นกองทุน IL  จะใช้กรมธรรม์ที่ขึ้นด้วย 9 ใน 10 หลัก(ของเดิม) และ เป็นกรมธรรม์ที่เป็น 8 หลัก จะไม่รับชำระทุกช่องทาง
                        if ((resAdminObj.fld_policy_status_code.Trim().ToUpper() != "1" || resAdminObj.fld_billed_to_date.Trim() == "" || (policyNumber.Trim().Substring(0, 1) == "9" && policyNumber.Trim().Length == 10) || (policyNumber.Trim().Length == 8)))
                        {
                            obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์";
                        }
                        else
                        { // กรณีค้างจ่ายตรวจสอบเงื่อนไขวันกำหนดชำระ ไม่เกิน 31 วัน
                            DateTime nextDue   = Convert.ToDateTime(resAdminObj.fld_billed_to_date);
                            DateTime nextDue_2 = Convert.ToDateTime(resAdminObj.fld_billed_to_date).AddDays(31);
                            DateTime paid_date = Convert.ToDateTime(resAdminObj.fld_paid_date);

                            //กรณีจ่ายก่อนล่วงหน้างวด รับเงื่อนไขnextduedate -วันที่จ่าย <= ตามงวด(1ปี ,รายเดือน ,3เดือน ,6เดือน)
                            long diff   = DateDiff(DateInterval.Month, DateTime.Today, nextDue);
                            long period = DateDiff(DateInterval.Month, paid_date, nextDue);


                            int compareValue = nextDue.CompareTo(DateTime.Today);
                            if (compareValue < 0)
                            {
                                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์ เนื่องจากเกินกำหนดที่รับชำระ กรุณาชำระช่องทางอื่นๆ";
                            }
                            else if (diff > period)
                            {
                                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์ เนื่องจากยังไม่ถึงกำหนดชำระ";
                            }
                            else
                            {
                                obj.TypePaid = "ชำระเบี้ยประกันภัย";
                                // ตรวจสอบว่าเป็นกรมธรรม์ที่สามารถรับชำระด้วยวิธีการใดได้บ้าง
                                if (resAdminObj.fld_warning_message.Contains("อนุโลม"))
                                {
                                    obj.PaymentTypeToPay = "CCP|CDC";
                                }
                                else if (resAdminObj.fld_warning_message.Contains("ไม่รับบัตรเครดิต"))
                                {
                                    obj.PaymentTypeToPay = "CCP";
                                }
                                else
                                {
                                    obj.PaymentTypeToPay = "CCP|CDC";
                                }

                                // ตรวจสอบว่าเป็นกรมธรรม์ประเภท PA แบบรายเดือนหรือไม่ (เลขกรมธรรม์ขึ้นต้นด้วย 8) ถ้าใช่จะต้องไปเอาค่าเบี้ยประกันรวมจากหน้าจอใบเสร็จ
                                if (policyNumber.Trim().Substring(0, 1) == "8")
                                {
                                    MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService adminWSObj_mPos = new MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService();

                                    MTL.WS_Admin.WS_Admin_ForMTLmPOS.CPINQ03_ReceiptDetailList[] receiptList;
                                    string receiptResult = adminWSObj_mPos.GetReceiptDetailList(this.admin_username, this.admin_password, policyNumber, "", "", out resAdminObj.fld_sessionID, out receiptList);
                                    if (receiptResult.Trim().ToLower() == "completed")
                                    {
                                        var lastListResult = receiptList.Last();

                                        obj.TotalPremium = lastListResult.Amount.Trim();
                                    }
                                    else
                                    {
                                        obj.TotalPremium = resAdminObj.fld_total_premium.Trim();
                                    }
                                }
                                else
                                {
                                    obj.TotalPremium = resAdminObj.fld_total_premium.Trim();
                                }

                                obj.Result          = "completed";
                                obj.PolicyNumber    = policyNumber;
                                obj.PlanCode        = resAdminObj.fld_plan_code.Trim();
                                obj.PlanName        = resAdminObj.fld_plan_name.Trim();
                                obj.IssueBilledDate = resAdminObj.fld_year_billed_to.Trim() + "/" + resAdminObj.fld_tranche_billed_to.Trim();
                                obj.BilledToDate    = resAdminObj.fld_billed_to_date.Trim();
                                obj.FaceAmount      = resAdminObj.fld_face_amount.Trim();
                                obj.PaidMode        = resAdminObj.fld_paid_mode.Trim();
                                obj.PolicyStatus    = resAdminObj.fld_policy_status_code.Trim();


                                //obj.WarningMessage = resAdminObj.fld_warning_message.Trim();
                                //obj.SessionID = resAdminObj.fld_sessionID.Trim();
                                //obj.ClientName = resAdminObj.fld_client_name.Trim();
                                //obj.IssueDate = resAdminObj.fld_issue_date.Trim();
                                //obj.ServiceAgent = resAdminObj.fld_service_agent.Trim();
                            }
                        }
                    }
                    else
                    {
                        obj.Result = resAdminObj.fld_result.Trim().Replace("notfound_", "notcomplete_");
                    }
                }
                else
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                    obj.Result = pacobj.Result.Trim().Replace("notpass_", "notcomplete_");
                }
            }

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result + "|" + obj.PolicyStatus + "|" + obj.TotalPremium + "|" + "|" + obj.WarningMessage + "|" + obj.PlanCode + "|" + obj.PlanName + "|" + obj.ClientName + "|" + obj.SessionID, this.refnum);

            return(obj);
        }
        catch (Exception ex)
        {
            obj.Result = "notcomplete_" + ex.Message.ToString();

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result, this.refnum);

            return(obj);
        }
    }
    public GetPolicyDetailForPayment_Result GetPolicyDetailForPayment(string partnerUsername, string partnerPassword, string policyNumber)
    {
        GetPolicyDetailForPayment_Result obj = new GetPolicyDetailForPayment_Result();
        PremiumDetail_Result pmobj = new PremiumDetail_Result();
        RefRunningTBBLL runningobj = new RefRunningTBBLL();
        this.refnum = runningobj.AddRefRunningTBAndReturn();
        WSLogBLL logobj = new WSLogBLL();
        string methodName = "GetPolicyDetailForPayment";

        try
        {
            if (partnerUsername == "" || partnerPassword == "" || policyNumber == "")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุข้อมูลให้ครบถ้วน";
            }
            else if (policyNumber.Trim().Substring(0, 2) == "PA")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์";
            }
            else if (policyNumber.Length != 10 || !MTL.Utils.ThisWeb.CheckIsNumeric(policyNumber))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุเลขกรมธรรม์ให้ถูกต้อง";
            }
            else
            {
                // พิสูจน์ตัวตนของพันธมิตรก่อนที่จะให้ใช้งานจริง
                NETWS_ForPartnerAuthenticationChecking.CheckPartnerAuthentication_Result pacobj = CheckPartnerAuthenticationReturnDetail(partnerUsername, partnerPassword, this.ipaddress);
                if (pacobj.Result.Trim().ToLower() == "passed")
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                    // ดึงข้อมูลรายละเอียดของกรมธรรม์กับ ApplinX WS_Admin
                    //ApplinXGetShortPolicyDetail2Result resAdminObj = new ApplinXGetShortPolicyDetail2Result();
                    //MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService adminWSObj = new MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService();
                    //resAdminObj.fld_result = adminWSObj.GetpolicyDetail(this.admin_username, this.admin_password, policyNumber, out resAdminObj.fld_sessionID, out resAdminObj.fld_service_agent, out resAdminObj.fld_client_name, out resAdminObj.fld_face_amount, out resAdminObj.fld_paid_mode, out resAdminObj.fld_plan_code, out resAdminObj.fld_plan_name, out resAdminObj.fld_total_premium, out resAdminObj.fld_policy_status, out resAdminObj.fld_issue_date, out resAdminObj.fld_warning_message);
                    ApplinXGetPolicyDetail2Result resAdminObj = new ApplinXGetPolicyDetail2Result();

                    MTL.WS_Admin.WS_Admin_SmileServices.WS_Admin_ForSmartCardService adminWSObj = new MTL.WS_Admin.WS_Admin_SmileServices.WS_Admin_ForSmartCardService();
                    MTL.WS_Admin.WS_Admin_SmileServices.CPINQ02C_F6_PolicyList[] fld_f6_policy_list;
                    MTL.WS_Admin.WS_Admin_SmileServices.CPINQ02_PolicyRiderList[] fld_f8_policy_rider_list;

                    resAdminObj.fld_result = adminWSObj.GetPolicyDetail2(this.admin_username, this.admin_password, policyNumber, out resAdminObj.fld_sessionID,
                   out resAdminObj.fld_approve_date, out resAdminObj.fld_attained_date, out resAdminObj.fld_belong_to_agent, out resAdminObj.fld_billed_to_date, out resAdminObj.fld_client_address, out resAdminObj.fld_client_dob, out resAdminObj.fld_client_name, out resAdminObj.fld_coverage_period, out resAdminObj.fld_disability_premium, out resAdminObj.fld_dividend_method,
                   out resAdminObj.fld_extra_paid_period, out resAdminObj.fld_extra_premium, out resAdminObj.fld_face_amount, out resAdminObj.fld_issue_date, out resAdminObj.fld_last_paid_by, out resAdminObj.fld_last_paid_date, out resAdminObj.fld_luanch_date, out resAdminObj.fld_maturity_date, out resAdminObj.fld_next_paid_age, out resAdminObj.fld_owner_agent,
                   out resAdminObj.fld_paid_date, out resAdminObj.fld_paid_mode, out resAdminObj.fld_paid_period, out resAdminObj.fld_payor, out resAdminObj.fld_plan_code, out resAdminObj.fld_plan_name, out resAdminObj.fld_rate_age, out resAdminObj.fld_rider_premium, out  resAdminObj.fld_sale_department, out resAdminObj.fld_service_agent,
                   out resAdminObj.fld_total_premium, out resAdminObj.fld_tranche_billed_to, out resAdminObj.fld_tranche_paid, out resAdminObj.fld_year_billed_to, out resAdminObj.fld_year_paid, out resAdminObj.fld_f2_mode_01, out resAdminObj.fld_f2_mode_03, out resAdminObj.fld_f2_mode_06, out resAdminObj.fld_f2_mode_12, out resAdminObj.fld_f4_address1,
                   out resAdminObj.fld_f4_address2, out resAdminObj.fld_f4_business_phone, out resAdminObj.fld_f4_client_number, out resAdminObj.fld_f4_face_amount, out resAdminObj.fld_f4_mobile_phone, out resAdminObj.fld_f4_policy_status, out resAdminObj.fld_f4_resident_phone, out resAdminObj.fld_f4_responsible_team, out resAdminObj.fld_f4_sum_insured, out resAdminObj.fld_f5_misc_susp_date,
                   out resAdminObj.fld_f5_misc_susp_value, out resAdminObj.fld_f5_prem_susp_date, out resAdminObj.fld_f5_prem_susp_value, out  fld_f6_policy_list, out resAdminObj.fld_f7_assurance_code, out resAdminObj.fld_f7_hazard_health, out resAdminObj.fld_f7_hazard_occupation, out resAdminObj.fld_f7_health_check_code, out resAdminObj.fld_f8_disability_extra_premium, out resAdminObj.fld_f8_disability_premium,
                   out resAdminObj.fld_f8_disability_total_premium, out resAdminObj.fld_f8_life_extra_premium, out resAdminObj.fld_f8_life_premium, out resAdminObj.fld_f8_life_total_premium, out resAdminObj.fld_f8_sum_extra_premium, out resAdminObj.fld_f8_sum_premium, out resAdminObj.fld_f8_sum_total_premium, out resAdminObj.fld_f8_tranche, out resAdminObj.fld_f8_year, out fld_f8_policy_rider_list,
                   out resAdminObj.fld_warning_message, out resAdminObj.fld_f4_paid_by, out resAdminObj.fld_f4_paid_by_text, out resAdminObj.fld_f4_paid_by_create_date, out resAdminObj.fld_f4_paid_by_cancel_date, out resAdminObj.fld_f4_paid_by_account_number, out resAdminObj.fld_f4_MDC_bank, out resAdminObj.fld_f4_MDC_create_date, out resAdminObj.fld_f4_MDC_cancel_date, out resAdminObj.fld_f4_MDC_account_number,
                   out resAdminObj.fld_f7_preserve_code, out resAdminObj.fld_f7_reinsurance, out resAdminObj.fld_f7_fpo_at, out resAdminObj.fld_f7_message, out resAdminObj.fld_f7_f11_message, out resAdminObj.fld_last_paid_by_text, out resAdminObj.fld_policyIsTakaful, out resAdminObj.fld_policy_status_code, out resAdminObj.fld_policy_status_subcode);
                    //, out resAdminObj.fld_smile_club, out resAdminObj.fld_topup_loan);

                    if (resAdminObj.fld_result.Trim().ToLower() == "found")
                    {
                        //// ตรวจสอบว่าสถานะกรมธรรม์เป็น 1/B/7/9 หรือไม่ ถ้าไม่เป็นจะไม่ยอมให้ชำระต่ออายุออนไลน์
                        //if (resAdminObj.fld_policy_status.Trim().ToUpper() != "1" && resAdminObj.fld_policy_status.Trim().ToUpper() != "B" && resAdminObj.fld_policy_status.Trim().ToUpper() != "7" && resAdminObj.fld_policy_status.Trim().ToUpper() != "9")
                        // 20150115 พี่ไร, พี่มด ให้รองรับเฉพาะสถานะกรมธรรม์เป็น 1 เท่านั้น
                        // ตรวจสอบว่าสถานะกรมธรรม์เป็น 1 หรือไม่ ถ้าไม่เป็นจะไม่ยอมให้ชำระต่ออายุออนไลน์
                        // ตรวจสอบfld_billed_to_date (Next due date กำหนดชำระครั้งต่อไป) ต้องมีค่า
                        // ตรวจสอบ ไม่รับกรมธรรม์ที่เป็นกองทุน IL  จะใช้กรมธรรม์ที่ขึ้นด้วย 9 ใน 10 หลัก(ของเดิม) และ เป็นกรมธรรม์ที่เป็น 8 หลัก จะไม่รับชำระทุกช่องทาง
                        if ((resAdminObj.fld_policy_status_code.Trim().ToUpper() != "1" || resAdminObj.fld_billed_to_date.Trim() == "" || (policyNumber.Trim().Substring(0, 1) == "9" && policyNumber.Trim().Length == 10) || (policyNumber.Trim().Length == 8)))
                        {
                                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์";
                        }
                        else
                        { // กรณีค้างจ่ายตรวจสอบเงื่อนไขวันกำหนดชำระ ไม่เกิน 31 วัน
                            DateTime nextDue = Convert.ToDateTime(resAdminObj.fld_billed_to_date);
                            DateTime nextDue_2 = Convert.ToDateTime(resAdminObj.fld_billed_to_date).AddDays(31);
                            DateTime paid_date = Convert.ToDateTime(resAdminObj.fld_paid_date);

                            //กรณีจ่ายก่อนล่วงหน้างวด รับเงื่อนไขnextduedate -วันที่จ่าย <= ตามงวด(1ปี ,รายเดือน ,3เดือน ,6เดือน)
                            long diff = DateDiff(DateInterval.Month, DateTime.Today, nextDue);
                            long period = DateDiff(DateInterval.Month, paid_date, nextDue);

                            int compareValue = nextDue.CompareTo(DateTime.Today);
                            if (compareValue < 0 )
                            {
                                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์ เนื่องจากเกินกำหนดที่รับชำระ กรุณาชำระช่องทางอื่นๆ";

                            }
                            else if (diff > period)
                            {
                                obj.Result = "notcomplete_กรมธรรม์นี้ไม่รับชำระค่าเบี้ยประกันต่ออายุออนไลน์ เนื่องจากยังไม่ถึงกำหนดชำระ";
                            }
                            else
                            {
                                obj.TypePaid = "ชำระเบี้ยประกันภัย";
                                // ตรวจสอบว่าเป็นกรมธรรม์ที่สามารถรับชำระด้วยวิธีการใดได้บ้าง
                                if (resAdminObj.fld_warning_message.Contains("อนุโลม"))
                                {
                                    obj.PaymentTypeToPay = "CCP|CDC";
                                }
                                else if (resAdminObj.fld_warning_message.Contains("ไม่รับบัตรเครดิต"))
                                {
                                    obj.PaymentTypeToPay = "CCP";
                                }
                                else
                                {
                                    obj.PaymentTypeToPay = "CCP|CDC";
                                }

                                // ตรวจสอบว่าเป็นกรมธรรม์ประเภท PA แบบรายเดือนหรือไม่ (เลขกรมธรรม์ขึ้นต้นด้วย 8) ถ้าใช่จะต้องไปเอาค่าเบี้ยประกันรวมจากหน้าจอใบเสร็จ
                                if (policyNumber.Trim().Substring(0, 1) == "8" )
                                {
                                    MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService adminWSObj_mPos = new MTL.WS_Admin.WS_Admin_ForMTLmPOS.WS_Admin_ForMPosService();

                                    MTL.WS_Admin.WS_Admin_ForMTLmPOS.CPINQ03_ReceiptDetailList[] receiptList;
                                    string receiptResult = adminWSObj_mPos.GetReceiptDetailList(this.admin_username, this.admin_password, policyNumber, "", "", out resAdminObj.fld_sessionID, out receiptList);
                                    if (receiptResult.Trim().ToLower() == "completed")
                                    {
                                        var lastListResult = receiptList.Last();

                                        obj.TotalPremium = lastListResult.Amount.Trim();
                                    }
                                    else
                                    {
                                        obj.TotalPremium = resAdminObj.fld_total_premium.Trim();
                                    }
                                }
                                else
                                {
                                    obj.TotalPremium = resAdminObj.fld_total_premium.Trim();
                                }

                                obj.Result = "completed";
                                obj.PolicyNumber = policyNumber;
                                obj.PlanCode = resAdminObj.fld_plan_code.Trim();
                                obj.PlanName = resAdminObj.fld_plan_name.Trim();
                                obj.IssueBilledDate = resAdminObj.fld_year_billed_to.Trim() + "/" + resAdminObj.fld_tranche_billed_to.Trim();
                                obj.BilledToDate = resAdminObj.fld_billed_to_date.Trim();
                                obj.FaceAmount = resAdminObj.fld_face_amount.Trim();
                                obj.PaidMode = resAdminObj.fld_paid_mode.Trim();
                                obj.PolicyStatus = resAdminObj.fld_policy_status_code.Trim();

                                //obj.WarningMessage = resAdminObj.fld_warning_message.Trim();
                                //obj.SessionID = resAdminObj.fld_sessionID.Trim();
                                //obj.ClientName = resAdminObj.fld_client_name.Trim();
                                //obj.IssueDate = resAdminObj.fld_issue_date.Trim();
                                //obj.ServiceAgent = resAdminObj.fld_service_agent.Trim();

                            }

                        }
                    }
                    else
                    {
                        obj.Result = resAdminObj.fld_result.Trim().Replace("notfound_", "notcomplete_");
                    }
                }
                else
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + policyNumber, this.refnum);

                    obj.Result = pacobj.Result.Trim().Replace("notpass_", "notcomplete_");
                }
            }

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result + "|" + obj.PolicyStatus + "|" + obj.TotalPremium + "|" + "|" + obj.WarningMessage + "|" + obj.PlanCode + "|" + obj.PlanName + "|" + obj.ClientName + "|" + obj.SessionID, this.refnum);

            return obj;
        }
        catch (Exception ex)
        {
            obj.Result = "notcomplete_" + ex.Message.ToString();

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result, this.refnum);

            return obj;
        }
    }