@isTest private class lexSelectAssetEstimateURFControllerTest { 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.Product_Old__c = 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 testInitById() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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(); // 新規 String initMcidStr = lexSelectAssetEstimateURFController.init(contract.Id,'mcid'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initMcidStr,lexSelectAssetEstimateURFController.InitData.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; initData.unCheckedAssets[0].rec_CheckBox_c = true; String initMcidStrExchangeAsset = lexSelectAssetEstimateURFController.exchangeAsset(Json.serialize(initData)); lexSelectAssetEstimateURFController.save(initMcidStrExchangeAsset); lexSelectAssetEstimateURFController.approvalProcess(initMcidStrExchangeAsset); // 维修合同报价1 Apexpages.currentPage().getParameters().put('id', contactEsti1.Id); String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'id'); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); System.assertEquals(2,initData.productCount2); System.assertEquals(10, initData.productCount); initData.unCheckedAssets[0].rec_CheckBox_c = true; String initStrExchangeAsset = lexSelectAssetEstimateURFController.exchangeAsset(Json.serialize(initData)); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStrExchangeAsset,lexSelectAssetEstimateURFController.InitData.class); System.assertEquals(11, initData.productCount); System.assertEquals(1, initData.productCount3); Integer productIdx=1; String refreshProductDataStr = lexSelectAssetEstimateURFController.refreshProductData(Json.serialize(initData.checkedAssets),Json.serialize(initData.TopProductModel),productIdx,initData.isNewPriceAdj); initData.checkedAssets = ( List)JSON.deserialize(refreshProductDataStr, List.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; lexSelectAssetEstimateURFController.save(Json.serialize(initData)); List 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); lexSelectAssetEstimateURFController.print(Json.serialize(initData)); lexSelectAssetEstimateURFController.addNewRows(Json.serialize(initData.checkedAssets)); lexSelectAssetEstimateURFController.interceptsend(Json.serialize(initData.estimate),initData.targetEstimateId); lexSelectAssetEstimateURFController.savePrintFlg(initData); lexSelectAssetEstimateURFController.onChDealerUpdate(Json.serialize(initData.estimate),initData.estimate.Dealer__c); lexSelectAssetEstimateURFController.getMCAEIsCreateable(); System.Test.stopTest(); } } // 2つ見積もりがあり、親のサビコンと同期するのテスト static testMethod void testDecide() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; insert contract; 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); String initMcidStr = lexSelectAssetEstimateURFController.init(contract.Id,'mcid'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initMcidStr,lexSelectAssetEstimateURFController.InitData.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; initData.unCheckedAssets[0].rec_CheckBox_c = true; String initMcidStrExchangeAsset = lexSelectAssetEstimateURFController.exchangeAsset(Json.serialize(initData)); lexSelectAssetEstimateURFController.save(initMcidStrExchangeAsset); lexSelectAssetEstimateURFController.approvalProcess(initMcidStrExchangeAsset); Apexpages.currentPage().getParameters().put('id', contactEsti2.Id); String initStr = lexSelectAssetEstimateURFController.init(contactEsti2.Id,'id'); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.unCheckedAssets[1].rec_CheckBox_c = true; initData.unCheckedAssets[3].rec_CheckBox_c = true; System.assertEquals(10, initData.productCount); String initStrExchangeAsset = lexSelectAssetEstimateURFController.exchangeAsset(Json.serialize(initData)); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStrExchangeAsset,lexSelectAssetEstimateURFController.InitData.class); System.assertEquals(12, initData.productCount); System.assertEquals(2, initData.productCount3); initData.checkedAssets[0].mcae.Check_Result__c = 'test0'; initData.checkedAssets[1].mcae.Check_Result__c = 'test1'; initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; initData.estimate.Process_Status__c = '批准'; lexSelectAssetEstimateURFController.decide(Json.serialize(initData)); lexSelectAssetEstimateURFController.undecide(initData.targetEstimateId,Json.serialize(initData.estimate)); System.Test.stopTest(); } } static testMethod void testCopyid() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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; System.Test.startTest(); String initCopyidStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'copyid'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initCopyidStr,lexSelectAssetEstimateURFController.InitData.class); initData.alertString =''; initData.alertString2 =''; initData.alertString3 =''; initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; lexSelectAssetEstimateURFController.save(Json.serialize(initData)); lexSelectAssetEstimateURFController.ShowLTYRepair(initData.targetEstimateId); lexSelectAssetEstimateURFController.ShowLTYRepair(contactEsti1.Id); System.Test.stopTest(); } } static testMethod void testInitByMcid() { 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 { lexSelectAssetEstimateURFController.init(null,null); } 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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', URF_P_MaxRepairCount__c = '0' ); 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}; System.Test.startTest(); String initMcidStr = lexSelectAssetEstimateURFController.init(contract.Id,'mcid'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initMcidStr,lexSelectAssetEstimateURFController.InitData.class); // initMcidStr =lexSelectAssetEstimateURFController.firstPage(Json.serialize(initData)); // initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initMcidStr,lexSelectAssetEstimateURFController.InitData.class); // initData.currPage = 3; // initMcidStr = lexSelectAssetEstimateURFController.previousPage(Json.serialize(initData)); // initMcidStr = lexSelectAssetEstimateURFController.endPage(initMcidStr); // initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initMcidStr,lexSelectAssetEstimateURFController.InitData.class); // initData.currPage = 200; // initMcidStr = lexSelectAssetEstimateURFController.recordNumChange(initMcidStr); lexSelectAssetEstimateURFController.saveAndCancel(initMcidStr); } } static testMethod void testSave() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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); repair01.AWS_Data_Id__c = '123'; 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; contract.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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', URF_P_MaxRepairCount__c = '0'); 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}; String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'id'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; Test.startTest(); initData.estimate.Request_quotation_Amount__c = 1; // initData.checkedAssets[0].mcae.Estimate_List_Price__cs lexSelectAssetEstimateURFController.save(Json.serialize(initData)); lexSelectAssetEstimateURFController.approvalProcess(Json.serialize(initData)); lexSelectAssetEstimateURFController.ComputeLTYRepair(initData.targetEstimateId); initData.estimate.URF_V_MaxRepairCount__c = '1'; initData.estimate.URF_P_MaxRepairCount__c = '3'; String saveAndCancelRes = lexSelectAssetEstimateURFController.saveAndCancel(Json.serialize(initData)); System.assertEquals(true, saveAndCancelRes != null); Test.stopTest(); } } static testMethod void testByCopyid() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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 = 2000, EndUserType__c = '既有用户', mainTalksTime__c = 1, talksStartDate__c = Date.today(), Discount_reason__c = 'test', Improve_ConsumptionRate_Idea__c = 'test', GuidePrice_Up__c = 1000, GuidePrice_Down__c =1 , URF_P_MaxRepairCount__c='0', URF_V_MaxRepairCount__c='2' ); 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}; System.Test.startTest(); String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'copyid'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; initData.changedAfterPrint = true; String syncEstimateRes = lexSelectAssetEstimateURFController.syncEstimate(true,true,initData); System.assertEquals(true, syncEstimateRes!= null); System.Test.stopTest(); } } static testMethod void testApprovalProcess() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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; contract.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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}; List mcaeList = new List(); for(Integer i =0; i<2001; i++){ 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'; mcaeList.add(mcae1); } // 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 mcaeList; // 新規 System.Test.startTest(); String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'id'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; initData.unCheckedAssets[0].rec_CheckBox_c = true; initStr = lexSelectAssetEstimateURFController.exchangeAsset(Json.serialize(initData)); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.checkedAssets[0].mcae.Check_Result__c = 'OK'; String approvalProcessRes = lexSelectAssetEstimateURFController.approvalProcess(Json.serialize(initData)); System.assertEquals(true, approvalProcessRes != null); // 提交待审批时,更新已填写申请状态 List mcenew = [select id,ApprovalProcess_Status__c from Maintenance_Contract_Estimate__c where id = :contactEsti1.Id]; System.Test.stopTest(); } } static testMethod void EditUnitTest() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); insert productA; // 納入機器を作成する 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; contract.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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(); String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'id'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.text1 = 'S:Name'; initData.cond1 = 'equals'; initData.val1 = 'asset01,asset02'; initStr = lexSelectAssetEstimateURFController.searchBtn(Json.serialize(initData)); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.cond1 = 'equals'; initData.val1 = 'asset02'; initStr = lexSelectAssetEstimateURFController.searchBtn(Json.serialize(initData)); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.cond1 = 'contains'; initData.val1 = ' asset02'; initStr = lexSelectAssetEstimateURFController.searchBtn(Json.serialize(initData)); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.cond1 = 'notequals'; initStr = lexSelectAssetEstimateURFController.searchBtn(Json.serialize(initData)); initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.cond1 = 'starts with'; String searchBtnRes = lexSelectAssetEstimateURFController.searchBtn(Json.serialize(initData)); System.assertEquals(true, searchBtnRes != null); Test.stopTest(); } } // // 补充test 实际联动 static testMethod void testInitCheckChangedAfterPrint() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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}; System.Test.startTest(); String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'id'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; List checkedAssets = lexSelectAssetEstimateURFController.priceChangeReset(initData.checkedAssets); initData.checkedAssets = checkedAssets; System.assertEquals(true, checkedAssets != null); lexSelectAssetEstimateURFController.save(Json.serialize(initData)); initData.changedAfterPrint = true; lexSelectAssetEstimateURFController.checkChangedAfterPrint(initData); System.Test.stopTest(); } } static testMethod void testISyncEstimateWithMcid() { 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) { System.Test.startTest(); try { lexSelectAssetEstimateURFController.init(null,null); } 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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(-11); 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; lastcontract.URF_Contract__c = true; lastcontract.agree_Upper_limit__c = true; 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; contract.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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}; String initMcidStr = lexSelectAssetEstimateURFController.init(contract.Id,'mcid'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initMcidStr,lexSelectAssetEstimateURFController.InitData.class); String syncEstimateRes = lexSelectAssetEstimateURFController.syncEstimate(true, true,initData); // String nextPageRes = lexSelectAssetEstimateURFController.nextPage(initMcidStr); // System.assertEquals(true, nextPageRes != null); System.Test.stopTest(); } } 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c= 110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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 = 2000, EndUserType__c = '既有用户', mainTalksTime__c = 1, talksStartDate__c = Date.today(), Discount_reason__c = 'test', Improve_ConsumptionRate_Idea__c = 'test', GuidePrice_Up__c = 1000, GuidePrice_Down__c =1 , URF_P_MaxRepairCount__c='0', URF_V_MaxRepairCount__c='2' ); insert contactEsti1; Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c(); mcae1.Asset__c = asset01.Id; // mcae1.Product_Manual__c = productA.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}; System.Test.startTest(); String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'id'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; List checkedAssets = lexSelectAssetEstimateURFController.priceChangeReset(initData.checkedAssets); initData.checkedAssets = checkedAssets; System.assertEquals(true, checkedAssets != null); lexSelectAssetEstimateURFController.save(Json.serialize(initData)); System.Test.stopTest(); } } static testMethod void testRefreshProductData() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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(); // 维修合同报价1 Apexpages.currentPage().getParameters().put('id', contactEsti1.Id); String initStr = lexSelectAssetEstimateURFController.init(contactEsti1.Id,'id'); lexSelectAssetEstimateURFController.InitData initData = (lexSelectAssetEstimateURFController.InitData)JSON.deserialize(initStr,lexSelectAssetEstimateURFController.InitData.class); initData.unCheckedAssets[0].rec_CheckBox_c = true; Integer productIdx=1; String refreshProductDataStr = lexSelectAssetEstimateURFController.refreshProductData(Json.serialize(initData.checkedAssets),Json.serialize(initData.TopProductModel),productIdx,initData.isNewPriceAdj); initData.checkedAssets = ( List)JSON.deserialize(refreshProductDataStr, List.class); initData.estimate.Contract_Esti_Start_Date__c = Date.today(); initData.estimate.Contract_Esti_End_Date__c = Date.today().addMonths(10); initData.estimate.Contract_Range__c = 10; System.Test.stopTest(); } } static testMethod void testSaveBeforeCheckPriceChangeAsset() { 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 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; ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000); insert purf; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false,ProductURF__c = purf.Id); 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.URF_Contract__c = true; contract.agree_Upper_limit__c = true; 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(); List assetList = [SELECT Id, Maintenance_Price_Month__c, Posting_Date__c, InstallDate FROM Asset WHERE Name='asset01' OR Name='asset02' OR Name='asset03']; List IdList = new List(); String idsStr = ''; for (Asset assetObj : assetList) { idsStr +='\''+ assetObj.Id+'\','; } List saveBeforeCheckPriceChangeAssetResById = lexSelectAssetEstimateURFController.saveBeforeCheckPriceChangeAsset(idsStr.substring(0,idsStr.length()-1)); idsStr = ''; List product2List = [SELECT Id,Name FROM Product2 WHERE Name='テスト商品']; for (Product2 product2Obj : product2List) { idsStr +='\''+ product2Obj.Id+'\','; } List saveBeforeCheckPriceChangeProduct2ResById = lexSelectAssetEstimateURFController.saveBeforeCheckPriceChangeProduct2(idsStr.substring(0,idsStr.length()-1)); System.assertEquals(true, saveBeforeCheckPriceChangeProduct2ResById != null); System.Test.stopTest(); } } }