@isTest
private class SelectAssetEstimateVMControllerTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static Asset createAsset(String input, String accountid, String dcId, String hpId, String serialNo, String prId, String mark ) {
        Asset asset = new Asset();
        asset.Name = input;
        asset.AccountId = accountid;
        asset.Department_Class__c = dcId;
        asset.Hospital__c = hpId;
        asset.SerialNumber = serialNo;
        asset.Product2Id = prId;
        asset.InstallDate = Date.today();
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        //在接收参数的时候新增了String类型的Mark字段,以及在调用该方法时传递了String类型的Mark字段
        asset.AssetMark__c = mark;
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---End 
        insert asset;
        return asset;
    }

    public class AssetInfo {
        public Integer lineNo {get; private set;}
        public Boolean rec_checkBox_c {get; set;}
        public Asset rec { get; set; }
        public Maintenance_Contract_Asset_Estimate__c mcae { get; set; }
        public Boolean isManual { get; set; }
        public Decimal orgPrice {get; private set;}
        public Id getRecId() {
            Id rtn = null;
            if (rec != null) {
                rtn = rec.Id;
            }
            return rtn;
        }
        public void setRecId(Id value) {
            // なにもしない
        }
        
        // Manual専用
        public AssetInfo(Integer lineNo) {
            this.lineNo = lineNo;
            this.rec = null;
            this.mcae = new Maintenance_Contract_Asset_Estimate__c(
                isNew__c = true
            );
            this.isManual = true;
            this.rec_checkBox_c = false;
            this.orgPrice = 0;
        }
    }
    
    // 2つ見積もりがあり、親のサビコンと同期するのテスト
    static testMethod void testDecide_01() {
        ControllerUtil.EscapeNFM001Trigger = true;
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;

        
        system.runAs(u3) {
            // 病院を作る
            
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            StaticParameter.EscapeSyncProduct2Trigger = true;
            StaticParameter.EscapeAccountTrigger = true;
            StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            // Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset01 = intProCommonMethodController.buildAssetHost('asset01',dep.Id, hospital.Id, strategicDep[0].Id,'使用中');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'耗材');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'耗材');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');

            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;

            Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
            mca1.Asset__c = asset01.Id;
            mca1.Estimate_List_Price__c = 100;
            mca1.Maintenance_Contract__c = contract.Id;
            
            insert new Maintenance_Contract_Asset__c[] {mca1};
            
            // 维修合同报价を作成する
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 1',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Contract_Esti_Start_Date__c = Date.today(),
                Contract_Range__c = 2,
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert contactEsti1;
            
            System.Test.startTest();
            // 新規
            Apexpages.currentPage().getParameters().put('mcid', contract.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.unCheckedAssetsView[0][0].rec_CheckBox_c = true;
            controller.exchangeAsset();
            controller.save();
            controller.approvalProcess();
            
            // 维修合同报价1
            Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
            controller = new SelectAssetEstimateVMController();
            controller.init();
             //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
            // System.assertEquals(5, controller.productCount2);
            //因为默认查询的保有设备类型为主机
            System.assertEquals(2,controller.productCount2);
             //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
            
            controller.getEnablePrintContract();
            controller.getUnDecideBtnDisabled();
            controller.getDecideBtnDisabled();
            controller.getApprovalBtnDisabled();
            controller.getSaveBtnDisabled();
            controller.getPrintBtnDisabled();
            controller.getPageDisabled();
            controller.savePrintFlg();
            
            System.assertEquals(10, controller.productCount);
            controller.unCheckedAssetsView[0][0].rec_CheckBox_c = true;
            controller.exchangeAsset();
            System.assertEquals(11, controller.productCount);
            System.assertEquals(1, controller.productCount3);
            
            controller.productIdx = 1;
            controller.refreshProductData();
            
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.save();
            
            List<Maintenance_Contract_Asset__c> mcaList = [select Id, Asset__r.Name from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :contract.Id];
            System.assertEquals(1, mcaList.size());
            System.assertEquals('asset01', mcaList[0].Asset__r.Name);
            
            controller.print();
            System.Test.stopTest();
        }
    }

    // 2つ見積もりがあり、親のサビコンと同期するのテスト
    static testMethod void testDecide_02() {
        ControllerUtil.EscapeNFM001Trigger = true;
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        system.runAs(u3) {
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            StaticParameter.EscapeSyncProduct2Trigger = true;
            StaticParameter.EscapeAccountTrigger = true;
            StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'主机');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'主机');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'主机');
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // // 维修合同报价を作成する
            // Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
            //     Name = 'contract estimate 1',
            //     RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
            //     Contract_Esti_Start_Date__c = Date.today(),
            //     Contract_Range__c = 2,
            //     Maintenance_Contract__c = contract.Id
            // );
            Maintenance_Contract_Estimate__c contactEsti2 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 2',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Contract_Esti_Start_Date__c = Date.today().addMonths(6),
                Contract_Range__c = 3,
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert  contactEsti2;
            
            System.Test.startTest();
            // 新規
            Apexpages.currentPage().getParameters().put('mcid', contract.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.unCheckedAssetsView[0][0].rec_CheckBox_c = true;
            controller.exchangeAsset();
            controller.save();
            controller.approvalProcess();
            
            // // 维修合同报价1
            // Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
            // controller = new SelectAssetEstimateVMController();
            // controller.init();
            // System.assertEquals(5, controller.productCount2);
            
            // controller.getEnablePrintContract();
            // controller.getUnDecideBtnDisabled();
            // controller.getDecideBtnDisabled();
            // controller.getApprovalBtnDisabled();
            // controller.getSaveBtnDisabled();
            // controller.getPrintBtnDisabled();
            // controller.getcontactBtnDisabled();
            // controller.getPageDisabled();
            // controller.savePrintFlg();
            
            // System.assertEquals(10, controller.productCount);
            // controller.unCheckedAssetsView[0][0].rec_CheckBox_c = true;
            // controller.exchangeAsset();
            // System.assertEquals(11, controller.productCount);
            // System.assertEquals(1, controller.productCount3);
            
            // controller.productIdx = 1;
            // controller.refreshProductData();
            
            // controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            // controller.estimate.Contract_Range__c = 2;
            // controller.save();
            
            // List<Maintenance_Contract_Asset__c> mcaList = [select Id, Asset__r.Name from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :contract.Id];
            // System.assertEquals(1, mcaList.size());
            // System.assertEquals('asset01', mcaList[0].Asset__r.Name);
            
            // controller.print();
            
            // 维修合同报价2の決定ロジック
            Apexpages.currentPage().getParameters().put('id', contactEsti2.Id);
            SelectAssetEstimateVMController controller2 = new SelectAssetEstimateVMController();
            controller2.init();
            
            controller2.unCheckedAssetsView[0][1].rec_CheckBox_c = true;
            controller2.unCheckedAssetsView[0][3].rec_CheckBox_c = true;
            System.assertEquals(10, controller2.productCount);
            controller2.exchangeAsset();
            System.assertEquals(12, controller2.productCount);
            System.assertEquals(2, controller2.productCount3);
            
            // contactEsti1 = [select IsSyncing__c from Maintenance_Contract_Estimate__c where Id = :contactEsti1.Id];
            // System.assertEquals(true, contactEsti1.IsSyncing__c);
            
            controller2.checkedAssets[0].mcae.Check_Result__c = 'test0';
            controller2.checkedAssets[1].mcae.Check_Result__c = 'test1';
            controller2.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller2.estimate.Contract_Range__c = 2;
            controller2.estimate.Process_Status__c = '批准';
            controller2.decide();
            
            // contactEsti1 = [select IsSyncing__c from Maintenance_Contract_Estimate__c where Id = :contactEsti1.Id];
            // System.assertEquals(false, contactEsti1.IsSyncing__c);
            // contactEsti2 = [select IsSyncing__c from Maintenance_Contract_Estimate__c where Id = :contactEsti2.Id];
            // System.assertEquals(true, contactEsti2.IsSyncing__c);
            
            controller2.undecide();
            
            //mcaList = [select Id, Asset__r.Name from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :contract.Id order by Asset__r.Name];
            //System.assertEquals(2, mcaList.size());
            //System.assertEquals('asset02', mcaList[0].Asset__r.Name);
            //System.assertEquals('asset04', mcaList[1].Asset__r.Name);
            System.Test.stopTest();
        }
    }
    
    static testMethod void testcopyid_01() {
        ControllerUtil.EscapeNFM001Trigger = true;
        
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        system.runAs(u3) {
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'主机');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'耗材');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // 维修合同报价を作成する
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Name = 'contract estimate 1',
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert contactEsti1;
            
            Apexpages.currentPage().getParameters().put('copyid', contactEsti1.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.lastFriYearsPriceSum  =3322;
            controller.lastSecYearsPriceSum = 1222;
            controller.alertString ='';
            controller.alertString2 ='';
            controller.alertString3 ='';
            controller.getSaveBtnDisabled();
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.save();
            SelectAssetEstimateVMController.pageDecide(contactEsti1.Id);
            SelectAssetEstimateVMController.pageUndecide(contactEsti1.Id);
//            controller.ComputeLTYRepair();
            controller.ShowLTYRepair();
        }
    }
    
    static testMethod void testInit_01() {
        ControllerUtil.EscapeNFM001Trigger = true;

        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        system.runAs(u3) {
            try {
                SelectAssetEstimateVMController controller001 = new SelectAssetEstimateVMController();
                controller001.init();
            } catch (Exception e) {

            }
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            hospital.Is_Active__c = '有效';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'耗材');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'耗材');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'主机');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // 维修合同/保有设备を作成する
            Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
            mca1.Asset__c = asset01.Id;
            mca1.Estimate_List_Price__c = 100;
            mca1.Maintenance_Contract__c = contract.Id;
            
            Maintenance_Contract_Asset__c mca2 = new Maintenance_Contract_Asset__c();
            mca2.Asset__c = asset01.Id;
            mca2.Estimate_List_Price__c = 100;
            mca2.Maintenance_Contract__c = contract.Id;
            
            insert new Maintenance_Contract_Asset__c[] {mca1, mca2};
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Name = 'contract estimate 1',
                Maintenance_Contract__c = contract.Id,
                Contract_Esti_Start_Date__c = Date.today().addDays(1),
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert contactEsti1;
            
            Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            mcae1.Asset__c = asset01.Id;
            mcae1.Adjustment_Upper_price__c = 1;
            mcae1.Adjustment_Lower_price__c = 1;
            mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae1.Estimate_List_Price__c = 1000;
            mcae1.Check_Result__c = 'OK';
            
            Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            mcae2.Asset__c = asset01.Id;
            mcae2.Adjustment_Upper_price__c = 1;
            mcae2.Adjustment_Lower_price__c = 1;
            mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae2.Estimate_List_Price__c = 1000;
            mcae2.Check_Result__c = 'OK';
            
            insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2};
            
            Apexpages.currentPage().getParameters().put('mcid', contract.Id);
            Apexpages.currentPage().getParameters().put('completion', '1');
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();

            controller.init();
            controller.firstPage();
            controller.currPage = 3;
            controller.previousPage();
            controller.endPage();
            controller.currPage = 200;
            controller.nextPage();
            controller.recordNumChange();
            controller.getSaveBtnDisabled();
            //controller.ComputeLTYRepair();
            controller.cancel();
            controller.saveAndCancel();

            controller.onChDealerUpdate();
            controller.checkDealerId = mcae2.Id;
            controller.onChDealerUpdate();
            controller.checkDealerId = hospital.Id;
            controller.onChDealerUpdate();
        }
    }
    
    static testMethod void testInit_02() {
        ControllerUtil.EscapeNFM001Trigger = true;
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        system.runAs(u3) {
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'主机');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'耗材');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            
            // 修理を作成する01
            Repair__c repair01 = new Repair__c();
            repair01.Account__c = dep.Id;
            repair01.Department_Class__c = strategicDep[0].Id;
            repair01.Hospital__c = hospital.Id;
            repair01.Delivered_Product__c = asset01.Id;
            repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
            repair01.FSE_Work_Location__c = '上海';
            repair01.Agreed_Date__c = Date.today().addDays(-1);
            insert repair01;
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // 维修合同报价を作成する
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 1',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Maintenance_Contract__c = contract.Id,
                Contract_Esti_Start_Date__c = Date.today().addDays(1),
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert contactEsti1;
            
            Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            mcae1.Asset__c = asset01.Id;
            mcae1.Adjustment_Upper_price__c = 1;
            mcae1.Adjustment_Lower_price__c = 1;
            mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae1.Estimate_List_Price__c = 1000;
            mcae1.Check_Result__c = 'OK';
            
            Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            mcae2.Asset__c = asset01.Id;
            mcae2.Adjustment_Upper_price__c = 1;
            mcae2.Adjustment_Lower_price__c = 1;
            mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae2.Estimate_List_Price__c = 1000;
            mcae2.Check_Result__c = 'OK';
            
            insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2};
            
            Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.save();
            Test.startTest();
            controller.ComputeLTYRepair();
            controller.saveAndCancel();

            SelectAssetEstimateVMController.ComputeLTYRepair(controller.targetEstimateId);
            Test.stopTest();
        }
    }
    
    static testMethod void testInit_03() {
        ControllerUtil.EscapeNFM001Trigger = true;

        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        system.runAs(u3) {
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'主机');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'耗材');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // 维修合同报价を作成する
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 1',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert contactEsti1;
            
            Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            mcae1.Asset__c = asset01.Id;
            mcae1.Adjustment_Upper_price__c = 1;
            mcae1.Adjustment_Lower_price__c = 1;
            mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae1.Estimate_List_Price__c = 1000;
            mcae1.Check_Result__c = 'OK';

            Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            mcae2.Product_Manual__c = productA.Id;
            mcae2.Adjustment_Upper_price__c = 1;
            mcae2.Adjustment_Lower_price__c = 1;
            mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae2.Estimate_List_Price__c = 1000;
            mcae2.Check_Result__c = 'OK';
            
            insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2};
            
            Apexpages.currentPage().getParameters().put('copyid', contactEsti1.Id);
            Apexpages.currentPage().getParameters().put('completion', '3');
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.save();
        }
    }
    
    static testMethod void testApprovalProcess_01() {
        
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        system.runAs(u3) {

        ControllerUtil.EscapeNFM001Trigger = true;

        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        
        // 製品を作る
        Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
        insert productA;
        
        // 価格表エントリを作成する        
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
        
        // 納入機器を作成する
        Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
        Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'耗材');
        Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'主机');
        Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'耗材');
        Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
        
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Not_Upper_limit_reason__c = 'tect contract';
        contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        contract.Service_Contract_Staff__c = u3.Id;
        contract.Payment_Plan_Sum_First__c = 1;
        insert contract;
        
        // 维修合同报价を作成する
        Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
            Name = 'contract estimate 1',
            RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
            Contract_Esti_Start_Date__c = Date.today(),
            Contract_Range__c = 2,
            Maintenance_Contract__c = contract.Id,
            Request_quotation_Amount__c = 1,
            EndUserType__c = '既有用户',
            mainTalksTime__c = 1,
            talksStartDate__c = Date.today(),
            Discount_reason__c = 'test',
            Improve_ConsumptionRate_Idea__c = 'test'
        );
        insert new Maintenance_Contract_Estimate__c[] {contactEsti1};

        Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            mcae1.Asset__c = asset01.Id;
            mcae1.Adjustment_Upper_price__c = 1;
            mcae1.Adjustment_Lower_price__c = 1;
            mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae1.Estimate_List_Price__c = 1000;
            mcae1.Check_Result__c = 'OK';
            
            Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            mcae2.Asset__c = asset01.Id;
            mcae2.Adjustment_Upper_price__c = 1;
            mcae2.Adjustment_Lower_price__c = 1;
            mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae2.Estimate_List_Price__c = 1000;
            mcae2.Check_Result__c = 'OK';
            
            insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2};
        
        // 新規
        Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
        SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
        controller.init();
        controller.estimate.Contract_Esti_Start_Date__c = Date.today();
        controller.estimate.Contract_Range__c = 2;
        controller.unCheckedAssetsView[0][0].rec_CheckBox_c = true;
        controller.exchangeAsset();
        controller.checkedAssets[0].mcae.Check_Result__c = 'OK';
        controller.approvalProcess();
        
        // 提交待审批时，更新已填写申请状态
        List<Maintenance_Contract_Estimate__c> mcenew = [select id,ApprovalProcess_Status__c from Maintenance_Contract_Estimate__c where id = :contactEsti1.Id];
        System.assertEquals('已填写完并申请', mcenew[0].ApprovalProcess_Status__c);

        }
    }

    static testMethod void EditUnitTest() {

        //Test.startTest();
        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        system.runAs(u3) {
            ControllerUtil.EscapeNFM001Trigger = true;
            //SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;

            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;

            //// 価格表エントリを作成する        
            //PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            //entry.UnitPrice = 0;
            //entry.IsActive = true;
            //entry.UseStandardPrice = false;
            //entry.CurrencyIsoCode = 'CNY';
            //entry.Product2Id = productA.Id;
            //insert entry;

            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'耗材');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'主机');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'耗材');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');

            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            contract.Payment_Plan_Sum_First__c = 1;
            insert contract;

            // 维修合同报价を作成する
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 1',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Contract_Esti_Start_Date__c = Date.today(),
                Contract_Range__c = 2,
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            Maintenance_Contract_Estimate__c contactEsti2 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 2',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Contract_Esti_Start_Date__c = Date.today().addMonths(6),
                Contract_Range__c = 3,
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert new Maintenance_Contract_Estimate__c[] {contactEsti1, contactEsti2};
            System.Test.startTest();
            Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.text1 = 'S:Name';
            controller.cond1 = 'equals';
            controller.val1 = 'asset01,asset02';
            controller.searchBtn();
            controller.cond1 = 'equals';
            controller.val1 = 'asset02';
            controller.searchBtn();
            controller.cond1 = 'contains';
            controller.val1 = ' asset02';
            controller.searchBtn();
            controller.cond1 = 'notequals';
            controller.searchBtn();
            controller.cond1 = 'starts with';
            controller.searchBtn();
            Test.stopTest();
        }
    }
    // 补充test 实际联动
    static testMethod void testInit_04() {
        ControllerUtil.EscapeNFM001Trigger = true;

        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;

        

        system.runAs(u3) {
            Achievement_linkage__c oppMapping = new Achievement_linkage__c();
            oppMapping.Name = '01';
            oppMapping.Consumption_rate_Lower__c = 0;
            oppMapping.Consumption_rate_Upper__c = 50;                           // 重複してもエラーにはならない
            oppMapping.PriceCount_Lower__c  = -40;
            oppMapping.PriceCount_Upper__c  = -30;

            insert oppMapping;
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'耗材');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'主机');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // 维修合同报价を作成する
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 1',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 1,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test'
            );
            insert contactEsti1;
            
            Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            mcae1.Asset__c = asset01.Id;
            mcae1.Adjustment_Upper_price__c = 1;
            mcae1.Adjustment_Lower_price__c = 1;
            mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae1.Estimate_List_Price__c = 1000;
            mcae1.Check_Result__c = 'OK';
            
            Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            mcae2.Product_Manual__c = productA.Id;
            mcae2.Adjustment_Upper_price__c = 1;
            mcae2.Adjustment_Lower_price__c = 1;
            mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae2.Estimate_List_Price__c = 1000;
            mcae2.Check_Result__c = 'OK';
            
            insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2};
            
            Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.priceChangeReset();
            //controller.getChartData();
            //System.assertEquals(1, controller.dataList.size());
            controller.save();
            controller.changedAfterPrint = true;
            controller.checkChangedAfterPrint();
        }
    }


    static testMethod void testnotargetEstimateId_dataList() {
        ControllerUtil.EscapeNFM001Trigger = true;

        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;
        
        system.runAs(u3) {
            try {
                SelectAssetEstimateVMController controller001 = new SelectAssetEstimateVMController();
                controller001.init();
            } catch (Exception e) {

            }
            Achievement_linkage__c oppMapping = new Achievement_linkage__c();
            oppMapping.Name = '01';
            oppMapping.Consumption_rate_Lower__c = 0;
            oppMapping.Consumption_rate_Upper__c = 50;                           // 重複してもエラーにはならない
            oppMapping.PriceCount_Lower__c  = -40;
            oppMapping.PriceCount_Upper__c  = -30;

            insert oppMapping;
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'耗材');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'主机');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            // 上一期维修合同
            Maintenance_Contract__c lastcontract = new Maintenance_Contract__c();
            lastcontract.Name = 'tect contract';
            lastcontract.Not_Upper_limit_reason__c = 'tect contract';
            lastcontract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            lastcontract.Hospital__c = hospital.Id;
            lastcontract.Department_Class__c = strategicDep[0].Id;
            lastcontract.Department__c = dep.Id;
            lastcontract.Contract_Start_Date__c = Date.today().addMonths(-365);
            lastcontract.Contract_End_Date__c = Date.today().addMonths(1);
            lastcontract.Service_Contract_Staff__c = u3.Id;
            lastcontract.First_Estimate_Date__c = Date.today().addMonths(-1);
            lastcontract.First_contract_usage_Rate__c = 110;
            insert lastcontract;
            
            // 维修合同/保有设备を作成する
            Maintenance_Contract_Asset__c lastmca1 = new Maintenance_Contract_Asset__c();
            lastmca1.Asset__c = asset01.Id;
            lastmca1.Estimate_List_Price__c = 100;
            lastmca1.Estimate_Cost__c = 100;
            lastmca1.Maintenance_Contract__c = lastcontract.Id;

            
            insert new Maintenance_Contract_Asset__c[] {lastmca1};

            asset01.CurrentContract_F__c = lastcontract.Id;
            asset01.CurrentContract_F_asset__c = lastmca1.Id;
            update asset01;
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // 维修合同/保有设备を作成する
            Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
            mca1.Asset__c = asset01.Id;
            mca1.Estimate_List_Price__c = 100;
            mca1.Maintenance_Contract__c = contract.Id;
            
            Maintenance_Contract_Asset__c mca2 = new Maintenance_Contract_Asset__c();
            mca2.Asset__c = asset01.Id;
            mca2.Estimate_List_Price__c = 100;
            mca2.Maintenance_Contract__c = contract.Id;
            
            insert new Maintenance_Contract_Asset__c[] {mca1, mca2};
            // Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
            //     RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
            //     Name = 'contract estimate 1',
            //     Maintenance_Contract__c = contract.Id,
            //     Contract_Esti_Start_Date__c = Date.today().addDays(1),
            //     Request_quotation_Amount__c = 1,
            //     EndUserType__c = '既有用户',
            //     mainTalksTime__c = 1,
            //     talksStartDate__c = Date.today(),
            //     Discount_reason__c = 'test',
            //     Improve_ConsumptionRate_Idea__c = 'test'
            // );
            // insert contactEsti1;
            
            // Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            // mcae1.Asset__c = asset01.Id;
            // mcae1.Adjustment_Upper_price__c = 1;
            // mcae1.Adjustment_Lower_price__c = 1;
            // mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            // mcae1.Estimate_List_Price__c = 1000;
            // mcae1.Check_Result__c = 'OK';
            
            // Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            // mcae2.Asset__c = asset01.Id;
            // mcae2.Adjustment_Upper_price__c = 1;
            // mcae2.Adjustment_Lower_price__c = 1;
            // mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            // mcae2.Estimate_List_Price__c = 1000;
            // mcae2.Check_Result__c = 'OK';
            
            // insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2};
            
            Apexpages.currentPage().getParameters().put('mcid', contract.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();

            controller.init();
            // controller.firstPage();
            // controller.currPage = 3;
            // controller.previousPage();
            // controller.endPage();
            // controller.currPage = 200;
            // controller.nextPage();
            // controller.recordNumChange();
            // controller.getSaveBtnDisabled();
            // //controller.ComputeLTYRepair();
            // controller.cancel();
            // controller.saveAndCancel();
        }
    }

    static testMethod void testSyncEstimate() {
        ControllerUtil.EscapeNFM001Trigger = true;

        User u3 = new User();
        u3.LastName = '_サンブリッジ';
        u3.FirstName = 'う';
        u3.Alias = 'う';
        u3.Email = 'olympusTest03@sunbridge.com';
        u3.Username = 'olympusTest03@sunbridge.com';
        u3.CommunityNickname = 'う';
        u3.IsActive = true;
        u3.EmailEncodingKey = 'ISO-2022-JP';
        u3.TimeZoneSidKey = 'Asia/Tokyo';
        u3.LocaleSidKey = 'ja_JP';
        u3.LanguageLocaleKey = 'ja';
        u3.ProfileId = System.Label.ProfileId_SystemAdmin;
        u3.Job_Category__c = '销售服务';
        u3.Province__c = '北京市';
        u3.Use_Start_Date__c = Date.today().addMonths(-6);
        insert u3;

        

        system.runAs(u3) {
            Achievement_linkage__c oppMapping = new Achievement_linkage__c();
            oppMapping.Name = '01';
            oppMapping.Consumption_rate_Lower__c = 0;
            oppMapping.Consumption_rate_Upper__c = 50;                           // 重複してもエラーにはならない
            oppMapping.PriceCount_Lower__c  = -40;
            oppMapping.PriceCount_Upper__c  = -30;

            insert oppMapping;
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            
            // 戦略科室を得る
            List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
            
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
            dep.Name = 'test dep';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;
            
            // 製品を作る
            Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false);
            insert productA;
            
            // 価格表エントリを作成する        
            PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
            entry.UnitPrice = 0;
            entry.IsActive = true;
            entry.UseStandardPrice = false;
            entry.CurrencyIsoCode = 'CNY';
            entry.Product2Id = productA.Id;
            insert entry;
            
            // 納入機器を作成する
            Asset asset01 = createAsset('asset01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id,'主机');
            Asset asset02 = createAsset('asset02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productA.Id,'主机');
            Asset asset03 = createAsset('asset03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id,'耗材');
            Asset asset04 = createAsset('asset04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id,'耗材');
            Asset asset05 = createAsset('asset05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id,'耗材');
            
            // 维修合同を作成する
            Maintenance_Contract__c contract = new Maintenance_Contract__c();
            contract.Name = 'tect contract';
            contract.Not_Upper_limit_reason__c = 'tect contract';
            contract.RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract__c' and DeveloperName = 'NewMaintenance_Contract'].id;
            contract.Hospital__c = hospital.Id;
            contract.Department_Class__c = strategicDep[0].Id;
            contract.Department__c = dep.Id;
            contract.Service_Contract_Staff__c = u3.Id;
            insert contract;
            
            // 维修合同报价を作成する
            Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 1',
                RecordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Maintenance_Contract_Estimate__c' and DeveloperName = 'NewMaintenance_Quote'].id,
                Maintenance_Contract__c = contract.Id,
                Request_quotation_Amount__c = 2,
                EndUserType__c = '既有用户',
                mainTalksTime__c = 1,
                talksStartDate__c = Date.today(),
                Discount_reason__c = 'test',
                Improve_ConsumptionRate_Idea__c = 'test',
                GuidePrice_Up__c = 1
            );
            insert contactEsti1;
            
            Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
            mcae1.Asset__c = asset01.Id;
            mcae1.Adjustment_Upper_price__c = 1;
            mcae1.Adjustment_Lower_price__c = 1;
            mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae1.Estimate_List_Price__c = 1000;
            mcae1.Check_Result__c = 'OK';
            
            Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c();
            mcae2.Product_Manual__c = productA.Id;
            mcae2.Adjustment_Upper_price__c = 1;
            mcae2.Adjustment_Lower_price__c = 1;
            mcae2.Maintenance_Contract_Estimate__c = contactEsti1.Id;
            mcae2.Estimate_List_Price__c = 1000;
            mcae2.Check_Result__c = 'OK';
            
            insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2};
            
            Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
            SelectAssetEstimateVMController controller = new SelectAssetEstimateVMController();
            controller.init();
            controller.estimate.Contract_Esti_Start_Date__c = Date.today();
            controller.estimate.Contract_Range__c = 2;
            controller.priceChangeReset();
            // controller.getChartData();
            // System.assertEquals(1, controller.dataList.size());
            controller.save();
            controller.changedAfterPrint = true;
            controller.syncEstimate(true,true);
        }
    }

}