@Istest public class lexToMcpApprovalControllerTest { private static Id pricebookId = ControllerUtil.getStandardPricebook().Id; static Asset createAsset(String input, String accountid, String dcId, String hpId, String serialNo, String prId) { 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; insert asset; return asset; } static testMethod void myUnitTest() { Oly_TriggerHandler.bypass(MaintanceContractPackHandler.Class.getName()); // 病院を作る 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; // 製品を作る Product2 productA = new Product2( Name='テスト商品', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false); insert productA; Product2 productB = new Product2( Name='テスト商品123456789012345', Maintenance_Price_Year__c = 12000, Manual_Entry__c = false); insert productB; // 価格表エントリを作成する 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; PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productB.Id); entry2.UnitPrice = 0; entry2.IsActive = true; entry2.UseStandardPrice = false; entry2.CurrencyIsoCode = 'CNY'; entry2.Product2Id = productB.Id; insert entry2; // 納入機器を作成する Asset asset01 = createAsset('asset:01', dep.Id, strategicDep[0].Id, hospital.Id, '00001', productA.Id); Asset asset02 = createAsset('asset:02', dep.Id, strategicDep[0].Id, hospital.Id, '00002', productB.Id); Asset asset03 = createAsset('asset:03', dep.Id, strategicDep[0].Id, hospital.Id, '00003', productA.Id); Asset asset04 = createAsset('asset:04', dep.Id, strategicDep[0].Id, hospital.Id, '00004', productA.Id); Asset asset05 = createAsset('asset:05', dep.Id, strategicDep[0].Id, hospital.Id, '00005', productA.Id); // 服务打包合同 MaintanceContractPack__c target01 = new MaintanceContractPack__c(); target01.Name = 'TestDBMC'; target01.SalesOfficeCode_selection__c = '北京RC'; target01.Contract_Type__c = '上限合同'; target01.Is_Standard_Contract__c = '是'; target01.Inspection_Time__c = '1'; target01.Total_Payment_Time__c = '1'; target01.Term_Of_Payment__c = '多次付款'; target01.Contract_Start_Date__c = Date.today(); target01.Contract_End_Date__c = Date.today().addMonths(+12); target01.URF_Contract__c = false; target01.Contract_Range__c = Decimal.valueOf('12'); insert target01; // 维修合同を作成する Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = hospital.Id; contract.Contract_End_Date__c = Date.today().addMonths(+12); contract.Department_Class__c = strategicDep[0].Id; contract.Department__c = dep.Id; contract.Contract_Amount__c = 7894; contract.Repair_Cost_Sum__c = 7418; contract.MaintanceContractPack__c = target01.Id; insert contract; Maintenance_Contract__c contract2 = new Maintenance_Contract__c(); contract2.Name = 'tect contract2'; contract2.Hospital__c = hospital.Id; contract2.Department_Class__c = strategicDep[0].Id; contract2.Department__c = dep.Id; contract2.Contract_End_Date__c = Date.today().addMonths(+12); contract2.Contract_Amount__c = 7893; contract2.Repair_Cost_Sum__c = 7417; contract2.MaintanceContractPack__c = target01.Id; insert contract2; Maintenance_Contract_Asset__c mcac = new Maintenance_Contract_Asset__c(); mcac.Asset__c = asset01.id; mcac.Maintenance_Contract__c = contract.id; insert mcac; // Maintenance_Contract_Asset__c mcac2 = new Maintenance_Contract_Asset__c(); // mcac2.Asset__c = asset02.id; // mcac2.Maintenance_Contract__c = contract.id; // insert mcac2; // 维修合同报价を作成する Maintenance_Contract_Estimate__c contactEsti = new Maintenance_Contract_Estimate__c( Name = 'BJ-RS-BJ0077008SX-01', Maintenance_Contract__c = contract.Id, New_Contract_Type_TxT__c = '首签合同', Contract_Esti_Start_Date__c = Date.today(), Contract_Start_Date__c = Date.today(), Contract_Range__c = 12, Request_quotation_Amount__c = 85, Limit_Price_Amount__c = 7894561, Asset_Repair_Sum_Price__c = 89653, GuidePrice_Down__c = 123, GuidePrice_Up__c = 456, Estimation_Decision__c = true, Maintenance_Price__c = 8888888, Total_Contract_Price__c = 7894561 ); insert contactEsti; Maintenance_Contract_Estimate__c contactEsti2 = new Maintenance_Contract_Estimate__c( Name = 'BJ-RS-BJ0077008SX-02', Maintenance_Contract__c = contract2.Id, New_Contract_Type_TxT__c = '首签合同', Contract_Esti_Start_Date__c = Date.today(), Contract_Start_Date__c = Date.today(), Contract_Range__c = 12, Request_quotation_Amount__c = 85, Limit_Price_Amount__c = 7894561, Asset_Repair_Sum_Price__c = 89653, GuidePrice_Down__c = 123, GuidePrice_Up__c = 456, Maintenance_Price__c = 8888888, Estimation_Decision__c = true, Total_Contract_Price__c = 7894561 ); insert contactEsti2; MaintanceContractPackEstimate__c mtpE = new MaintanceContractPackEstimate__c( Name = 'DB-2023-BJ000092-01', Process_Status__c = '批准', Decide__c = true, SalesDepartment__c='6.华南', Maintenance_Contract_Estimate_TextArea__c = contactEsti.name+'\n'+contactEsti2.name, Maintenance_Contract_Estimate__c = contactEsti.name+','+contactEsti2.name, MaintanceContractPack__c = target01.id ); insert mtpE; target01.Estimation_Id__c = mtpE.id; update target01; // 维修合同报价/保有设备を作成する Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset01.Id, Lastyear_Repair_Cost_Text__c = 1234, Last_Second_Years_Repair_Cost_Text__c = 5678, Last_Third_Years_Repair_Cost_Text__c = 7891, Last_Third_Years_Repair_Month__c = 500, Maintenance_Contract_Estimate__c = contactEsti.Id, Comment__c = '一二三四五六七八九十一二三四五' ); Maintenance_Contract_Asset_Estimate__c mcae2 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset02.Id, Lastyear_Repair_Cost_Text__c = 1234, Last_Second_Years_Repair_Cost_Text__c = 5678, Last_Third_Years_Repair_Cost_Text__c = 7891, Last_Third_Years_Repair_Month__c = 500, Maintenance_Contract_Estimate__c = contactEsti.Id ); Maintenance_Contract_Asset_Estimate__c mcae3 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset03.Id, Lastyear_Repair_Cost_Text__c = 1234, Last_Second_Years_Repair_Cost_Text__c = 5678, Last_Third_Years_Repair_Cost_Text__c = 7891, Last_Third_Years_Repair_Month__c = 500, Maintenance_Contract_Estimate__c = contactEsti.Id, Comment__c = '一二三四五六七八九十' ); Maintenance_Contract_Asset_Estimate__c mcae4 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset04.Id, Lastyear_Repair_Cost_Text__c = 1234, Last_Second_Years_Repair_Cost_Text__c = 5678, Last_Third_Years_Repair_Cost_Text__c = 7891, Last_Third_Years_Repair_Month__c = 500, Maintenance_Contract_Estimate__c = contactEsti.Id, Comment__c = '一二三四五' ); Maintenance_Contract_Asset_Estimate__c mcae5 = new Maintenance_Contract_Asset_Estimate__c( Asset__c = asset05.Id, Lastyear_Repair_Cost_Text__c = 1234, Last_Second_Years_Repair_Cost_Text__c = 5678, Last_Third_Years_Repair_Cost_Text__c = 7891, Last_Third_Years_Repair_Month__c = 500, Maintenance_Contract_Estimate__c = contactEsti.Id ); insert new Maintenance_Contract_Asset_Estimate__c[] {mcae1, mcae2, mcae3, mcae4, mcae5}; List initDataList = lexToMcpApprovalController.init(target01.Id, mtpE.Id); List mceIds = new List{contactEsti.name, contactEsti2.name}; String recordId = target01.Id; String mcpeName = 'Test MCP'; String mcpeReson = 'Test MCP2'; String mcpeId = mtpE.Id; String consumptionRateSolution = '789789798'; Boolean isDecide = true; String mcpAprroval = lexToMcpApprovalController.mcpAprroval(recordId, mceIds, mcpeReson, mcpeId, isDecide, consumptionRateSolution); isDecide = false; mcpeId = '223232121222'; String mcpAprroval2 = lexToMcpApprovalController.mcpAprroval(recordId, mceIds, mcpeReson, mcpeId, isDecide, consumptionRateSolution); } }