public with sharing class NewMCHUpperLimitPDFController {
    public MCInfo targetMC {get; set;}
    public NewMCHUpperLimitPDFController() {

    }
     public NewMCHUpperLimitPDFController(ApexPages.StandardController controller) {
    }
    public void init() {
        String Maintenance_ContractID = ApexPages.currentPage().getParameters().get('id');
        List<Maintenance_Contract__c> MCList = [select
                                                id,
                                                Name,
                                                Department_Class__r.Name,
                                                Department__r.Name,
                                                Service_Contract_Staff__c,
                                                Payment_Plan_Sum_First__c,
                                                Payment_Plan_Date_First__c,
                                                Payment_Plan_Sum_Fifth__c,
                                                Payment_Plan_Date_Fifth__c,
                                                Payment_Plan_Sum_Third__c,
                                                Payment_Plan_Date_Third__c,
                                                Payment_Plan_Sum_Forth__c,
                                                Payment_Plan_Date_Forth__c,
                                                Payment_Plan_Sum_Second__c,
                                                Payment_Plan_Date_Second__c,
                                                Payment_Plan_Sum_Sixth__c,
                                                Payment_Plan_Date_Sixth__c,
                                                MainLeaderManager__c,
                                                Service_Contract_Staff__r.JingliApprovalManager__c,
                                                User_Salesdepartment__c,
                                                User_Salesdepartment_Sec__c,
                                                Service_Contract_Staff__r.Salesdepartment__c,
                                                Small_Repair_Time__c,
                                                Big_Repair_Time__c,
                                                Live_Technical_Support_Time__c,
                                                Engineer_Name__c,
                                                Phone_Number__c,
                                                Tour_Check__c,
                                                Inspection_Time__c,
                                                Dedust__c,
                                                Negotiate_Mean__c,
                                                First_Party_Contract_Number__c,
                                                Second_Party_Contract_Number__c,
                                                Term_Of_Payment__c,
                                                one_off_payment_agreed_period__c,
                                                Contract_Amount__c,
                                                Total_Contract_Amount_In_Words__c,
                                                Limit_Price_Amount__c,
                                                Limit_Price_Amount_in_Word__c,
                                                Service_Contract_Staff__r.Name,
                                                Total_Payment_Time__c,
                                                Payment_Plan_Sum_First_in_Word__c,
                                                Payment_Plan_Sum_Second_in_Word__c,
                                                Payment_Plan_Sum_Third_in_Word__c,
                                                Payment_Plan_Sum_Forth_in_Word__c,
                                                Payment_Plan_Sum_Fifth_in_Word__c,
                                                Payment_Plan_Sum_Sixth_in_Word__c,
                                                Estimation_Id__c,
                                                SalesOfficeCode_selection__c,
                                                Hospital__r.Name,
                                                Management_Code__c,
                                                Contract_Start_Date__c,
                                                Contract_End_Date__c,
                                                Total_Contract_Number__c,
                                                Is_New_Contract__c,
                                                Amount_Warranty_Coverage__c,
                                                Amount_Warranty_Coverage_In_Word__c,
                                                //URF限次合同2期 xxf 2022/08/23 start
                                                (select Id,name,Total_Number_Asset_P__c,Total_Number_Asset_V__c,
                                                    URF_P_MaxRepairCount__c,URF_V_MaxRepairCount__c,
                                                    URF_P_RepairTime__c,URF_V_RepairTime__c
                                                from Maintenance_Contract__r
                                                where Estimation_Decision__c = true)
                                                //URF限次合同2期 xxf 2022/08/23 end
                                                from
                                                Maintenance_Contract__c
                                                where
                                                id = :Maintenance_ContractID];
        if (MCList.size() == 0) {
            throw new ControllerUtil.myException('维修合同不存在。');
        }
        if(MCList[0].Estimation_Id__c == null){
            throw new ControllerUtil.myException('维修合同报价不存在。');
        }

        //巡回、点检和除尘为0是显示为'/'
        if(MCList[0].Tour_Check__c == null || MCList[0].Tour_Check__c.equals('0')){
            MCList[0].Tour_Check__c = ' / ';
        }
        if(MCList[0].Inspection_Time__c == null || MCList[0].Inspection_Time__c.equals('0')){
            MCList[0].Inspection_Time__c = ' / ';
        }
        if(MCList[0].Dedust__c == null || MCList[0].Dedust__c.equals('0')){
            MCList[0].Dedust__c = ' / ';
        }   

        list<Maintenance_Contract_Asset_Estimate__c> MCAs = [select Id from Maintenance_Contract_Asset_Estimate__c
                                                                       where Maintenance_Contract_Estimate__c = :MCList[0].Estimation_Id__c];
        this.targetMC = new MCInfo(MCList,MCAs.size());
        

       
    }


    public integer getStringLength() {
        integer StringLength = 0;
        if( targetMC.MC.Hospital__r.Name != null ){
            StringLength = targetMC.MC.Hospital__r.Name.length();
        }
        if(targetMC.BCompany !=null && targetMC.BCompany.length() > StringLength){
            StringLength = targetMC.BCompany.length();
        }
        return StringLength;
    }

    private static Map<String, String> companyApiMap = new Map<String, String> {
        '北京RC' => '奥林巴斯（北京）销售服务有限公司',
        '上海RC' => '奥林巴斯（北京）销售服务有限公司上海分公司',
        '广州RC' => '奥林巴斯（北京）销售服务有限公司广州分公司',
        '沈阳RC' => '奥林巴斯（北京）销售服务有限公司',
        //wangweipeng  2021/07/30   start
        '成都RC' => '奥林巴斯（北京）销售服务有限公司成都维修分公司',
        '西安RC' => '奥林巴斯（北京）销售服务有限公司西安维修分公司',
        '杭州RC' => '奥林巴斯（北京）销售服务有限公司杭州维修分公司'
        //wangweipeng  2021/07/30   start
    };

        /**
     * 印刷するデータを格納するオブジェクを定義する、親
     */
    public class MCInfo {
        public Maintenance_Contract__c MC {get; private set;}
        public String BCompany {get; private set;}
        public String Department {get; private set;}
        public String HospitalName {get; private set;}
        public integer AssetSize {get; private set;}
        public String StartYear {get; private set;}
        public String StartMonth {get; private set;}
        public String StartDay {get; private set;}
        public String EndYear {get; private set;}
        public String EndMonth {get; private set;}
        public String EndDay {get; private set;}
        public String First_Payment_Year {get; private set;}
        public String First_Payment_Month {get; private set;}
        public String First_Payment_Day {get; private set;}
        public String Second_Payment_Year {get; private set;}
        public String Second_Payment_Month {get; private set;}
        public String Second_Payment_Day {get; private set;}
        public String Third_Payment_Year {get; private set;}
        public String Third_Payment_Month {get; private set;}
        public String Third_Payment_Day {get; private set;}
        public String Forth_Payment_Year {get; private set;}
        public String Forth_Payment_Month {get; private set;}
        public String Forth_Payment_Day {get; private set;}
        public String Fifth_Payment_Year {get; private set;}
        public String Fifth_Payment_Month {get; private set;}
        public String Fifth_Payment_Day {get; private set;}
        public String Sixth_Payment_Year {get; private set;}
        public String Sixth_Payment_Month {get; private set;}
        public String Sixth_Payment_Day {get; private set;}
        
        public String Payment_Plan_Sum_First_in_Word {get; private set;}
        public String Payment_Plan_Sum_Second_in_Word {get; private set;}
        public String Payment_Plan_Sum_Third_in_Word {get; private set;}
        public String Payment_Plan_Sum_Forth_in_Word {get; private set;}
        public String Payment_Plan_Sum_Fifth_in_Word {get; private set;}
        public String Payment_Plan_Sum_Sixth_in_Word {get; private set;}
        public String Total_Contract_Amount_In_Words {get; private set;}
        public Decimal Limit_Price_Amount {get; private set;}
        public String Limit_Price_Amount_in_Word {get; private set;}
        

        public integer Total_Payment_Time {get; private set;}

        public String TermZero_One {get; private set;}
        public String TermZero_Two {get; private set;}
        public String TermZero_Three {get; private set;}
        public String TermOne_One {get; private set;}
        public String TermOne_Two {get; private set;}
        public String TermTwo_One {get; private set;}
        public String TermTwo_Two {get; private set;}
        public String TermThree_One {get; private set;}
        public String TermThree_Two {get; private set;}
        public String TermThree_Three {get; private set;}
        public String TermTen_One {get; private set;}
        public String TermTen_Two {get; private set;}
        public String TermTen_Three {get; private set;}
        public String TermTen_Four {get; private set;}
        public String TermTen_Four_one {get; private set;}
        public String TermTen_Four_two {get; private set;}
        public String TermTen_Four_Three {get; private set;}
        public String TermFour_One {get; private set;}
        public String TermFour_Two {get; private set;}
        public String TermFour_Once {get; private set;}
        public String TermFour_Once_One {get; private set;}
        public String TermFour_Once_Two {get; private set;}
        public String TermFour_Once_Three {get; private set;}
        public String TermFour_Once_Four {get; private set;}
        public String TermFour_Much {get; private set;}
        public String TermFour_Much_One {get; private set;}
        public String TermFour_Much_Two {get; private set;}
        public String TermFour_Much1 {get; private set;}
        public String TermFour_Much_Same1 {get; private set;}
        public String TermFour_Much_Same2 {get; private set;}
        public String TermFour_Much_Same3 {get; private set;}
        public String TermFour_Much2 {get; private set;}
        public String TermFour_Much3 {get; private set;}
        public String TermFour_Much4 {get; private set;}
        public String TermFour_Much5 {get; private set;}
        public String TermFour_Much6 {get; private set;}
        public String TermFive_Title {get; private set;}
        public String TermFive_Head {get; private set;}
        public String TermFive_One {get; private set;}
        public String TermFive_One2 {get; private set;}
        public String TermFive_One3 {get; private set;}
        public String TermFive_One3Append {get; private set;}
        public String TermFive_One4 {get; private set;}
        public String TermFive_One5 {get; private set;}
        public String TermFive_One6 {get; private set;}
        public String TermFive_One6Append {get; private set;}
        public String TermFive_One7 {get; private set;}
        public String TermFive_One8 {get; private set;}
        public String TermFive_One9 {get; private set;}
        public String TermFive_Two {get; private set;}
        public String TermFive_Two2 {get; private set;}
        public String TermFive_Three {get; private set;}
        public String TermFive_Three1 {get; private set;}
        public String TermFive_Three2 {get; private set;}
        public String TermFive_Four {get; private set;}
        public String TermFive_Five {get; private set;}
        // public String TermFive_Five2 {get; private set;}
        public String TermFive_Six {get; private set;}
        // public String TermFive_Seven {get; private set;}
        public String TermFive_Eight {get; private set;}
        public String TermFive_Nine {get; private set;}
        public String TermFive_Ten {get; private set;}
        public String TermFive_Ten2 {get; private set;}
        public String TermFive_Eleven1 {get; private set;}
        public String TermFive_Eleven2 {get; private set;}
        //XLIU-CEP8WW 【委托】合同文本更新/新增 XXF 20221031 end
        //XLIU-CEP8WW 【委托】合同文本更新/新增 LY 20220524 start
        public String TermFive_Eleven {get; private set;}
        public String TermFive_Table11 {get; private set;}
        public String TermFive_Table12 {get; private set;}
        public String TermFive_Table21 {get; private set;}
        public String TermFive_Table22 {get; private set;}
        public String TermFive_Table31 {get; private set;}
        public String TermFive_Table32 {get; private set;}
        public String TermFive_Table41 {get; private set;}
        public String TermFive_Table42 {get; private set;}
        public String TermFive_Table51 {get; private set;}
        public String TermFive_Table52 {get; private set;}
        public String TermSix_Title {get; private set;}
        public String TermSix_One {get; private set;}
        public String TermSix_Two {get; private set;}
        public String TermSix_Three {get; private set;}
        public String TermSix_Four {get; private set;}
        public String TermSix_Five {get; private set;}
        public String TermSix_Five2 {get; private set;}
        public String TermSix_Six {get; private set;}
        public String TermSix_Seven {get; private set;}
        public String TermSix_Eight {get; private set;}
        public String TermSeven_Title {get; private set;}
        public String TermSeven_One {get; private set;}
        public String TermSeven_Two {get; private set;}
        public String TermSeven_Table11 {get; private set;}
        public String TermSeven_Table12 {get; private set;}
        public String TermSeven_Table21 {get; private set;}
        public String TermSeven_Table22 {get; private set;}
        public String TermSeven_Table31 {get; private set;}
        public String TermSeven_Table32 {get; private set;}
        public String TermSeven_Table41 {get; private set;}
        public String TermSeven_Table42 {get; private set;}
        public String TermSeven_Table51 {get; private set;}
        public String TermSeven_Table52 {get; private set;}
        public String TermSeven_Table53 {get; private set;}
        public String TermSeven_Table54 {get; private set;}
        public String TermSeven_Table55 {get; private set;}
        public String TermSeven_Table56 {get; private set;}
        public String TermSeven_Table57 {get; private set;}
        public String TermSeven_Table58 {get; private set;}
        public String TermSeven_Table61 {get; private set;}
        public String TermSeven_Table62 {get; private set;}
        public String TermSeven_Table71 {get; private set;}
        public String TermSeven_Table72 {get; private set;}
        public String TermSeven_Table81 {get; private set;}
        public String TermSeven_Table82 {get; private set;}
        public String TermSeven_Table91 {get; private set;}
        public String TermSeven_Table92 {get; private set;}
        public String TermSeven_Table101 {get; private set;}
        public String TermSeven_Table102 {get; private set;}
        public String TermSeven_Table111 {get; private set;}
        public String TermSeven_Table112 {get; private set;}
        public String TermEight_Title {get; private set;}
        public String TermEight_Title2 {get; private set;}
        public String TermEight_One {get; private set;}
        public String TermEight_Two {get; private set;}
        public String TermEight_Three {get; private set;}
        public String TermNine_One {get; private set;}
        public String TermNine_Two {get; private set;}
        public String TermNine_Three {get; private set;}
        // HWAG-BLWFGC  追加第八条，原八九条顺延 update by vivek start
        public String TermEightAppend_Title {get; private set;}
        public String TermEightAppend_One {get; private set;}
        public String TermEightAppend_Two {get; private set;}
        public String TermEightAppend_Three {get; private set;}
        public String TermEightAppend_Three1 {get; private set;}
        public String TermEightAppend_Four {get; private set;}
        public String TermEightAppend_Five {get; private set;}
        public String TermEightAppend_Six {get; private set;}
        // HWAG-BLWFGC  追加第八条，原八九条顺延 update by vivek end
     //    public String TermTen_One {get; private set;}
     //    public String TermTen_Two {get; private set;}
     //    public String TermTen_Three {get; private set;}
     //    public String TermTen_Four {get; private set;}
     //    public String TermTen_Four_one {get; private set;}
     //    public String TermTen_Four_two {get; private set;}
     //    public String TermTen_Four_Three {get; private set;}

     //    public String TermSeven_Table11 {get; private set;}
     //    public String TermSeven_Table12 {get; private set;}
     //    public String TermSeven_Table21 {get; private set;}
     //    public String TermSeven_Table22 {get; private set;}
        // public String TermSeven_Table31 {get; private set;}
        // public String TermSeven_Table32 {get; private set;}
        // public String TermSeven_Table41 {get; private set;}
        // public String TermSeven_Table42 {get; private set;}
        // public String TermSeven_Table51 {get; private set;}
        // public String TermSeven_Table52 {get; private set;}
        // public String TermSeven_Table61 {get; private set;}
        // public String TermSeven_Table62 {get; private set;}
        // public String TermSeven_Table71 {get; private set;}
        // public String TermSeven_Table72 {get; private set;}
        // public String TermSeven_Table81 {get; private set;}
        // public String TermSeven_Table82 {get; private set;}
        // public String TermSeven_Table91 {get; private set;}
        // public String TermSeven_Table92 {get; private set;}
        // public String TermSeven_Table101 {get; private set;}
        // public String TermSeven_Table102 {get; private set;}
        // public String TermSeven_Table111 {get; private set;}
        // public String TermSeven_Table112 {get; private set;}

        public boolean Checked {get; set;}
        // public String Payment {get; private set;}
        // public String Payment_One {get; private set;}
        // public String Payment_Two {get; private set;}
        // public String Payment_Three {get; private set;}
        // public String Payment_Four {get; private set;}
        
        // public String FirstParty {get; private set;}
        // public String FirstParty_One {get; private set;}
        // public String FirstParty_Two {get; private set;}
        // public String FirstParty_Three {get; private set;}
        // public String FirstParty_Four {get; private set;}
        // public String FirstParty_Four_One {get; private set;}
        // public String FirstParty_Five {get; private set;}
        // public String FirstParty_Six {get; private set;}
        // public String FirstParty_Six_One {get; private set;}
        // public String FirstParty_Seven {get; private set;}
        // public String FirstParty_Eight {get; private set;}
        // public String FirstParty_Nine {get; private set;}
        // public String SecondParty {get; private set;}
        
        // public String Negotiate {get; private set;}
        // public String Negotiate1 {get; private set;}
        // public String Negotiate_One {get; private set;}
        // public String ContractCopies {get; private set;}
        // public String ContractNumber {get; private set;}
        // public String ExceptionTerm {get; private set;}
        // public String ContractExtension {get; private set;}


        public String Payment_Plan_Sum_First {get; private set;}
        public String Payment_Plan_Sum_Second {get; private set;}
        public String Payment_Plan_Sum_Third {get; private set;}
        public String Payment_Plan_Sum_Forth {get; private set;}
        public String Payment_Plan_Sum_Fifth {get; private set;}
        public String Payment_Plan_Sum_Sixth {get; private set;}
        public String Contract_Amount {get; private set;}
        public Decimal Amount_Warranty_Coverage {get; private set;}
        public String Amount_Warranty_Coverage_In_Word {get; private set;}

        private String returnNewStr(String hospitalName){
            String hospitalNames = '';
            if(hospitalName.contains('/')){
                Integer index = hospitalName.lastIndexOf('/');
                hospitalNames = hospitalName.substring(0,index)+'<br/>'+hospitalName.substring(index+1);
            }else{
                if(hospitalName.length()>22){
                    hospitalNames = hospitalName.substring(0,22)+'<br/>'+hospitalName.substring(22);
                }else{
                    hospitalNames = hospitalName;
                }
                
            }
            return hospitalNames;
        }


        private void setDate(Date StartDate, Date EndDate, Date FirstPaymentDate,
            Date SecondPaymentDate,Date ThirdPaymentDate,
            Date ForthPaymentDate,Date FifthPaymentDate,
            Date SixthPaymentDate){
            if( StartDate != null ){
                this.StartYear = String.valueOf(StartDate.year());
                this.StartMonth =  String.valueOf(StartDate.month());
                this.StartDay =  String.valueOf(StartDate.day());

            }else{
                this.StartYear = ' / ';
                this.StartMonth =  ' / ';
                this.StartDay =  ' / ';
            }
            if( EndDate != null ){
                this.EndYear = String.valueOf(EndDate.year());
                this.EndMonth =  String.valueOf(EndDate.month());
                this.EndDay =  String.valueOf(EndDate.day());
            }else{
                this.EndYear = ' / ';
                this.EndMonth =  ' / ';
                this.EndDay =  ' / ';
            }
            if( FirstPaymentDate != null ){
                this.First_Payment_Year = String.valueOf(FirstPaymentDate.year());
                this.First_Payment_Month =  String.valueOf(FirstPaymentDate.month());
                this.First_Payment_Day =  String.valueOf(FirstPaymentDate.day());
            }else{
                this.First_Payment_Year = ' / ';
                this.First_Payment_Month =  ' / ';
                this.First_Payment_Day =  ' / ';

            }
            if( SecondPaymentDate != null ){
                this.Second_Payment_Year = String.valueOf(SecondPaymentDate.year());
                this.Second_Payment_Month =  String.valueOf(SecondPaymentDate.month());
                this.Second_Payment_Day =  String.valueOf(SecondPaymentDate.day());
            }else{
                this.Second_Payment_Year = ' / ';
                this.Second_Payment_Month =  ' / ';
                this.Second_Payment_Day =  ' / ';
            }
            if( ThirdPaymentDate != null ){
                this.Third_Payment_Year = String.valueOf(ThirdPaymentDate.year());
                this.Third_Payment_Month =  String.valueOf(ThirdPaymentDate.month());
                this.Third_Payment_Day =  String.valueOf(ThirdPaymentDate.day());
            }else{
                this.Third_Payment_Year = ' / ';
                this.Third_Payment_Month =  ' / ';
                this.Third_Payment_Day =  ' / ';
            }
            if( ForthPaymentDate != null ){
                this.Forth_Payment_Year = String.valueOf(ForthPaymentDate.year());
                this.Forth_Payment_Month =  String.valueOf(ForthPaymentDate.month());
                this.Forth_Payment_Day =  String.valueOf(ForthPaymentDate.day());
            }else{
                this.Forth_Payment_Year = ' / ';
                this.Forth_Payment_Month =  ' / ';
                this.Forth_Payment_Day =  ' / ';
            }
            if( FifthPaymentDate != null ){
                this.Fifth_Payment_Year = String.valueOf(FifthPaymentDate.year());
                this.Fifth_Payment_Month =  String.valueOf(FifthPaymentDate.month());
                this.Fifth_Payment_Day =  String.valueOf(FifthPaymentDate.day());
            }else{
                this.Fifth_Payment_Year = ' / ';
                this.Fifth_Payment_Month =  ' / ';
                this.Fifth_Payment_Day =  ' / ';
            }
            if( SixthPaymentDate != null ){
                this.Sixth_Payment_Year = String.valueOf(SixthPaymentDate.year());
                this.Sixth_Payment_Month =  String.valueOf(SixthPaymentDate.month());
                this.Sixth_Payment_Day =  String.valueOf(SixthPaymentDate.day());
            }else{
                this.Sixth_Payment_Year = ' / ';
                this.Sixth_Payment_Month =  ' / ';
                this.Sixth_Payment_Day =  ' / ';
            }


        }

        public MCInfo(List<Maintenance_Contract__c> MCList,integer AssetSize) {
            if (MCList.size() > 0) {
                this.MC = MCList[0];
                this.Checked = true;
                this.BCompany = companyApiMap.get(MC.SalesOfficeCode_selection__c);
                this.Department = MC.Department__r.Name.substring(MC.Department_Class__r.Name.length());
                this.AssetSize = AssetSize;
                String Hospital = MC.Hospital__r.Name;
                this.HospitalName = returnNewStr(Hospital);
                if(MC.Total_Contract_Amount_In_Words__c != null){
                    this.Total_Contract_Amount_In_Words = MC.Total_Contract_Amount_In_Words__c;
                    // this.Total_Contract_Amount_In_Words = MC.Total_Contract_Amount_In_Words__c.substring(0,MC.Total_Contract_Amount_In_Words__c.length()-2);
                }
                if(MC.Limit_Price_Amount__c != null){
                    this.Limit_Price_Amount = MC.Limit_Price_Amount__c;
                    // this.Total_Contract_Amount_In_Words = MC.Total_Contract_Amount_In_Words__c.substring(0,MC.Total_Contract_Amount_In_Words__c.length()-2);
                }
                if(MC.Limit_Price_Amount_in_Word__c != null){
                    this.Limit_Price_Amount_in_Word = MC.Limit_Price_Amount_in_Word__c;
                    // this.Total_Contract_Amount_In_Words = MC.Total_Contract_Amount_In_Words__c.substring(0,MC.Total_Contract_Amount_In_Words__c.length()-2);
                }
                if(MC.Payment_Plan_Sum_First_in_Word__c != null){
                    this.Payment_Plan_Sum_First_in_Word = MC.Payment_Plan_Sum_First_in_Word__c;
                    // this.Payment_Plan_Sum_First_in_Word = MC.Payment_Plan_Sum_First_in_Word__c.substring(0,MC.Payment_Plan_Sum_First_in_Word__c.length()-2);
                }
                if(MC.Payment_Plan_Sum_Second_in_Word__c != null){
                    this.Payment_Plan_Sum_Second_in_Word = MC.Payment_Plan_Sum_Second_in_Word__c;
                    // this.Payment_Plan_Sum_Second_in_Word = MC.Payment_Plan_Sum_Second_in_Word__c.substring(0,MC.Payment_Plan_Sum_Second_in_Word__c.length()-2);
                }
                if(MC.Payment_Plan_Sum_Third_in_Word__c != null){
                    this.Payment_Plan_Sum_Third_in_Word = MC.Payment_Plan_Sum_Third_in_Word__c;
                    // this.Payment_Plan_Sum_Third_in_Word = MC.Payment_Plan_Sum_Third_in_Word__c.substring(0,MC.Payment_Plan_Sum_Third_in_Word__c.length()-2);
                }
                if(MC.Payment_Plan_Sum_Forth_in_Word__c != null){
                    this.Payment_Plan_Sum_Forth_in_Word = MC.Payment_Plan_Sum_Forth_in_Word__c;
                    // this.Payment_Plan_Sum_Forth_in_Word = MC.Payment_Plan_Sum_Forth_in_Word__c.substring(0,MC.Payment_Plan_Sum_Forth_in_Word__c.length()-2);
                }
                if(MC.Payment_Plan_Sum_Fifth_in_Word__c != null){
                    this.Payment_Plan_Sum_Fifth_in_Word = MC.Payment_Plan_Sum_Fifth_in_Word__c;
                    // this.Payment_Plan_Sum_Fifth_in_Word = MC.Payment_Plan_Sum_Fifth_in_Word__c.substring(0,MC.Payment_Plan_Sum_Fifth_in_Word__c.length()-2);
                }
                if(MC.Payment_Plan_Sum_Sixth_in_Word__c != null){
                    this.Payment_Plan_Sum_Sixth_in_Word = MC.Payment_Plan_Sum_Sixth_in_Word__c;
                    // this.Payment_Plan_Sum_Sixth_in_Word = MC.Payment_Plan_Sum_Sixth_in_Word__c.substring(0,MC.Payment_Plan_Sum_Sixth_in_Word__c.length()-2);
                }
                

              //   if('一次性付款'.equals(MC.Term_Of_Payment__c)){
              //       this.Payment_One = '本合同正式签订之日起';
              //       this.Payment_two = '日内，甲方向乙方支付全部合同款人民币';
              //       this.Payment_Four = '元 ( 大写';
              //   }else{
                    // this.Payment_Three = '日前，甲方向乙方支付人民币';
                    // this.Payment_Four = '元 ( 大写';
              //   }
                setDate(MC.Contract_Start_Date__c,MC.Contract_End_Date__c, 
                    MC.Payment_Plan_Date_First__c, MC.Payment_Plan_Date_Second__c,
                    MC.Payment_Plan_Date_Third__c, MC.Payment_Plan_Date_Forth__c, 
                    MC.Payment_Plan_Date_Fifth__c, MC.Payment_Plan_Date_Sixth__c);
                if(MC.Total_Payment_Time__c!=null){
                    this.Total_Payment_Time = integer.valueof(MC.Total_Payment_Time__c);
                }
                
                list<String> args = new String[]{'0','number','###,###,###,###,##0'};
                if(MC.Payment_Plan_Sum_First__c != null ){
                    this.Payment_Plan_Sum_First     =  String.format(MC.Payment_Plan_Sum_First__c.format(), args);
                }
                if(MC.Payment_Plan_Sum_Second__c != null ){
                    this.Payment_Plan_Sum_Second    =  String.format(MC.Payment_Plan_Sum_Second__c.format(), args);
                }
                if(MC.Payment_Plan_Sum_Third__c != null ){
                    this.Payment_Plan_Sum_Third     =  String.format(MC.Payment_Plan_Sum_Third__c.format(), args);
                }
                if(MC.Payment_Plan_Sum_Forth__c != null ){
                    this.Payment_Plan_Sum_Forth     =  String.format(MC.Payment_Plan_Sum_Forth__c.format(), args);
                }
                if(MC.Payment_Plan_Sum_Fifth__c != null ){
                    this.Payment_Plan_Sum_Fifth     =  String.format(MC.Payment_Plan_Sum_Fifth__c.format(), args);
                }
                if(MC.Payment_Plan_Sum_Sixth__c != null ){
                    this.Payment_Plan_Sum_Sixth     =  String.format(MC.Payment_Plan_Sum_Sixth__c.format(), args);
                }
                if(MC.Contract_Amount__c != null ){
                    this.Contract_Amount            =  String.format(MC.Contract_Amount__c.format(), args);
                }
                this.Amount_Warranty_Coverage = MC.Amount_Warranty_Coverage__c;
                this.Amount_Warranty_Coverage_In_Word = MC.Amount_Warranty_Coverage_In_Word__c;
                this.TermZero_One = '甲、乙双方经过共同协商，就甲方共';
                this.TermZero_Two = '科/室共';
                this.TermZero_Three = '件奥林巴斯系列产品在本合同服务委托期限内由乙方提供有偿服务（包括乙方协助甲方对参保设备进行预防故障工作，为参保设备提供维修服务、备品服务、小修保养等服务）而签订本服务合同（以下简称“本合同”）。';
                this.TermOne_One = '一、    本合同的参保设备清单参见附件1，且必须在服务委托期开始时处于健康完好状态。如参保时有故障存在，除双方有另行约定外，已有故障应该先进行修理且不计入本合同，之后乙方按本合同约定承担相应责任。';
                this.TermOne_Two = '所有附件是本合同有效组成部分，与本合同具有同等法律效力。';
                this.TermTwo_One = '二、     本合同服务委托期限为';
                this.TermTwo_Two = '';
                this.TermThree_One = '三、   本合同总金额';
                this.TermThree_Two = '元(人民币大写';
                this.TermThree_Three = ')。';

                
                this.TermTen_One = '四、   本合同的保修范围金额为';
                this.TermTen_Two = '元(人民币大写';
                this.TermTen_Three = ')。';
                this.TermTen_Four  = '1、在本合同服务委托期间内，对累计修理报价金额在保修范围金额内（含）的维';
                this.TermTen_Four_one ='修，由乙方提供维修等服务。甲方无须额外支付费用。';
                this.TermTen_Four_two =  '2、在本合同服务委托期间内，若累计修理报价金额达到保修范围金额时仍旧需要乙方继续对本合同参保设备提供维修服务，则甲方对超过保修范围金额的维修费用进行付费，付费标准为超过保修范围金额的75%。';
                this.TermTen_Four_Three = '如累计修理报价金额暂未超过保修范围金额(即累计修理报价金额＜保修范围金额)，再发生的单笔维修金额计算入累计修理报价金额即便超过保修范围金额，该笔维修仍由乙方提供无偿维修。自下一笔维修产生时，再行依据前款实施付费维修。';
               

                this.TermFour_One = '五、 付款方式';
                this.TermFour_Two = '本合同金额由甲方：';
                this.TermFour_Once = '一次性支付';
                this.TermFour_Once_One = '本合同正式签订之日起';
                this.TermFour_Once_Two = '日内，甲方向乙方支付全部合同款人民币';
                this.TermFour_Once_Three = '元（大写';
                this.TermFour_Once_Four = ')。';
                this.TermFour_Much = '多次支付';
                this.TermFour_Much_One = '本合同款项分';
                this.TermFour_Much_Two = '期付出，详细如下：';
                this.TermFour_Much1 = '第一期款项付款时间为';
                this.TermFour_Much_Same1 = '前（含），甲方向乙方支付人民币';
                this.TermFour_Much_Same2 = '元(人民币大写';
                this.TermFour_Much_Same3 = ')。';
                this.TermFour_Much2 = '第二期款项付款时间为';
                this.TermFour_Much3 = '第三期款项付款时间为';
                this.TermFour_Much4 = '第四期款项付款时间为';
                this.TermFour_Much5 = '第五期款项付款时间为';
                this.TermFour_Much6 = '第六期款项付款时间为';

                this.TermFive_Title = '六、   乙方责任范围';
                this.TermFive_Head = '在本合同服务委托期间内，乙方对本合同参保设备提供如下服务：';
                this.TermFive_One = '1、本合同参保设备因自然损耗或按照乙方要求进行清洗消毒的情况下发生故障';
                this.TermFive_One2 = '时，由乙方进行维修。因故意人为损坏导致的故障，不在本合同维修范围内。';
                this.TermFive_One3 = '纤维输尿管肾盂镜（URF-P5、URF-P6）：单根设备每年度至多';
                this.TermFive_One3Append = '次大修，本合同参保设备中共';
                this.TermFive_One4 = '条累计至多';
                this.TermFive_One5 = '次（含）大维修，小维修次数不限；';
                this.TermFive_One6 = '电子输尿管肾盂镜（URF-V、URF-V2）：单根设备每年度至多';
                this.TermFive_One6Append = '次大修，本合同参保设备中共';
                this.TermFive_One7 = '条累计至多';
                this.TermFive_One8 = '次（含）大维修，小维修次数不限。';
                this.TermFive_One9 = '当纤维输尿管肾盂镜（URF-P5、URF-P6）和电子输尿管肾盂镜（URF-V、URF-V2）的大维修次数均已达到合同约定的上限时，本合同自动终止，乙方停止提供本合同内约定的一切服务，包含但不限于大、小维修对应、备品提供等。';
                this.TermFive_Two = '2、 在零件齐备的情况下，乙方保证';
                this.TermFive_Two2 = '个工作日之内完成小维修。';
                this.TermFive_Three = '3、 在零件齐备的情况下，乙方保证';
                this.TermFive_Three1 = '个工作日内完成大维修。';
                this.TermFive_Three2 = '4、 乙方只对本合同参保设备中周边仪器的主机，光源，超声主机、内镜清洗消毒机和监视器进行维修。其他与周边仪器相关的不可维修的设备（如电缆线、超声探头、水瓶、键盘、脚踏等）和耗品（如清洗用具、治疗附件、光源灯泡等）不属于维修范围。';
                this.TermFive_Four = '5、 原则上本合同所附设备在本合同第二条约定的合同服务委托期限内且在本合同生效之前发生的故障，乙方在本合同生效后提供维修服务且维修次数计入本合同。但是特例情况可由甲乙双方以补充协议的方式另行约定。';
                this.TermFive_Five = '6、 若由于零件订购、停产等原因无法修理，则乙方只修理可维修的产品或产品的部分功能。';
                // this.TermFive_Five2 = '同生效之前发生的故障，乙方在本合同生效后提供维修服务且维修费用计入本合同。但是特例情况可由甲乙双方以补充协议的方式另行约定。';
                // this.TermFive_Six = '6、 若由于零件订购、停产等原因无法修理，则乙方只修理可维修的产品或产品的部分功能。';
                this.TermFive_Six = '7、 如果本合同参保设备发生乙方修理责任范围内的故障需要进行大维修时，乙方优先向甲方提供备品。乙方确保周边设备类的备品提供。';
                // this.TermFive_Seven = '7、 如果本合同参保设备发生乙方修理责任范围内的故障需要进行大维修时，乙方优先向甲方提供备品。乙方确保对本合同参保设备清单中标记“*”的周边设备提供备品。';
                this.TermFive_Eight = '8、 自本合同生效日起每隔3个月且在本合同服务委托期内，乙方将向甲方提供合同执行报告，具体内容由乙方制定，包括且不限于：合同执行数据，乙方工作汇报，合同参保设备故障情况和相应故障预防建议等。';
                this.TermFive_Nine = '9、 在本合同服务委托期内，乙方结合甲方的实际情况，判断是否要向本合同参保设备提供故障预防工具。如乙方判断需要时，由乙方直接向甲方提供。具体提供方式和数量，以乙方判断为准。';
                this.TermFive_Ten = '10、 乙方指定工程师为甲方提供1年';
                this.TermFive_Ten2 = '次点检，并提交检查报告给医院备档。';
                this.TermFive_Eleven1 = '11、若附件1《参保设备清单》中包含“内镜清洗消毒装置”（型号：OER-AW、';
                this.TermFive_Eleven2 = 'OER-Smart，以下简称“OER-AW、OER-Smart”）的，在本合同期限内，乙方将安排工程师进行每6个月1次上门维护检测。乙方接到甲方设备出现维护保养报警提示通知后进行维护保养服务，更换相关组件。';
                this.TermFive_Eleven = '12、 若附件1《参保设备清单》中包含下表中的奥辉系列产品，本条第8款、第9款、及第10款不适用于该奥辉系列产品。';
                this.TermFive_Table11 = '产品名称';
                this.TermFive_Table12 = '型号';
                this.TermFive_Table21 = '电子结肠镜';
                this.TermFive_Table22 = 'CF-LV1I';
                this.TermFive_Table31 = '电子结肠镜';
                this.TermFive_Table32 = 'CF-LV1L';
                this.TermFive_Table41 = '电子胃镜';
                this.TermFive_Table42 = 'GIF-LV1';
                this.TermFive_Table51 = '图像处理装置';
                this.TermFive_Table52 = 'CV-V1';
                this.TermSix_Title = '七、   甲方责任范围 ';
                this.TermSix_One = '1、 甲方应爱护本合同内所包含之设备，应按照乙方说明书积极做好本合同参保设备的日常维护和保养工作，确保内镜始终处于良好的工作状态。当设备出现维护保养报警提示时，甲方应及时通知乙方。';
                this.TermSix_Two = '2、 无论在任何情况下，甲方均不得将本合同参保设备送至非奥林巴斯厂家进行维修。否则，乙方对经过非奥林巴斯厂家维修的设备进行维修时，将按正常标准向甲方收取维修费用，而不视为本合同费用。';
                this.TermSix_Three = '3、无论在任何情况下，甲方均不得自行拆卸本合同参保设备。否则，乙方对甲方自行拆卸的设备进行维修时，将按正常标准向甲方收取维修费用，而不视为本合同费用。';
                this.TermSix_Four = '4、甲方不可以将本合同参保设备借给其他医院或机构使用，若由此造成的故障，乙方将向甲方收取正常的维修费，而不视为本合同费用。';
                this.TermSix_Five = '5、甲方如果因为使用不匹配的非奥林巴斯或乙方不推荐内镜附件导致的损坏故';
                this.TermSix_Five2 = '障，乙方将向甲方收取正常的维修费，而不视为本合同费用。';
                this.TermSix_Six = '6、甲方应该主动积极配合乙方管理设备，降低因为人为原因造成的损坏。';
                this.TermSix_Seven = '7、甲方未经乙方事先书面同意，不得将本合同当事人的地位以及依本合同产生的任何权利义务转让给第三人或提供担保。';
                this.TermSix_Eight = '8、甲方应保守乙方的商业机密，不得向任何第三方泄露任何或全部包括乙方的销售、市场、技术、维修以及任何其它被告知或从另一方取得乙方的信息；无论此信息在本合同中是否标明或界定为机密。同时不得将该信息用于非本合同所述的目的。本条规定的保密期限在本合同期满或终止后继续有效。';

                this.TermSeven_Title = '八、   甲乙双方同意本合同进行续签时，继续参加合同的参保设备的续签金额由该设备在本合同中的参保价格与本合同的合同消费率计算，公式：续签金额=本合同参保价格*（1+调整比例%）。 ';
                this.TermSeven_One = '（注：合同消费率=本合同委托期限内所有参保设备发生的维修报价金额之和/合同金额*100%。委托期限届满前由乙方负责对合同消费率进行预估，双方认可后可以按此作为制定续签金额的依据。）”';
                this.TermSeven_Table11 = 'X<50%';
                this.TermSeven_Table12 = '-30%';
                this.TermSeven_Table21 = '50%≦X<60%';
                this.TermSeven_Table22 = '-20%';
                this.TermSeven_Table31 = '60%≦X<70%';
                this.TermSeven_Table32 = '-15%';
                this.TermSeven_Table41 = '70%≦X<80%';
                this.TermSeven_Table42 = '-10%';
                this.TermSeven_Table51 = '80%≦X<90%';
                this.TermSeven_Table52 = '-5%';
                this.TermSeven_Table53 = '90%≦X<100%';
                this.TermSeven_Table54 = '0%';
                this.TermSeven_Table55 = '100%≦X<110%';
                this.TermSeven_Table56 = '5%';
                this.TermSeven_Table57 = '110%≦X<120%';
                this.TermSeven_Table58 = '10%';
                this.TermSeven_Table61 = '120%≦X<130%';
                this.TermSeven_Table62 = '20%';
                this.TermSeven_Table101 = '130%≦X<140%';
                this.TermSeven_Table102 = '25%';
                this.TermSeven_Table111 = 'X≧140%';
                this.TermSeven_Table112 = '30%';


                this.TermSeven_Two = '2、   如参加续签的参保设备包含本合同项下设备以外的设备，则这部分设备的合同金额由双方另行协商约定。';


                // HWAG-BLWFGC  追加第八条，原八九条顺延 update by vivek start
                this.TermEightAppend_Title = '九、    合同变更、修改、解除和终止';
                this.TermEightAppend_One = '经甲乙双方协商同意，可对本合同进行修改和补充，修改及补充的内容经双方签字或盖章后作为本合同的有效组成部分，与本合同具有同等法律效力。若补充协议内容与本合同有冲突以补充协议为准。';
                this.TermEightAppend_Two = '本合同任何一方有下列情形之一，对方可不经催告解除本合同：';
                this.TermEightAppend_Three = '1、一方被采取查封、扣押、冻结等，或被申请开始进行拍卖、破产、清算、合';
                this.TermEightAppend_Three1 = '并、分立；';
                this.TermEightAppend_Four = '2、一方迟延履行本合同主要义务，经催告后在一方规定的合理期限内仍未履行；';
                this.TermEightAppend_Five = '3、一方有其他违约或违法行为致使本合同目的不能实现的。';
                this.TermEightAppend_Six = '4、由于不可抗力的原因，导致本合同部分不能履行、不能履行或延期履行时，遇有不可抗力事件的一方，应立即将事故情况通知对方，并提供部分不能履行、不能履行或延期履行的理由和所有相关的文件资料。';
                // HWAG-BLWFGC  追加第八条，原八九条顺延 update by vivek end

                this.TermEight_Title = '十、  本合同的解释与执行适用中华人民共和国法律，在履行本合同过程中出现的争议双方应友好协商解决；协商不成的，可选择以下第（ ';
                this.TermEight_Title2 = '）种方式解决：';

                this.TermEight_One = '1、 任何一方有权向设在北京的中国国际经济贸易仲裁委员会申请仲裁，仲裁的裁决是终局性的，对双方均有约束力。';
                this.TermEight_Two = '2、 向甲方所在地有管辖权的人民法院提起诉讼。';
                this.TermEight_Three = '3、 向乙方所在地有管辖权的人民法院提起诉讼。';

                this.TermNine_One = '十一、    本合同甲方执';
                // this.TermNine_Two = '份，';
                this.TermNine_Three = '份，乙方执1份，自双方盖章之日起生效。如生效日期与本合同第二条约定的委托期限起始日期不一致时，双方同意以两者中较晚日期作为本合同的生效时间。';
            }
                
        }

    }

}