@isTest
|
private class SelectAssetEstimateControllerTest {
|
|
/*static testMethod void addRepairData(){
|
Repair__c rpr = [select Id, Name, Account__c,Department_Class__c,
|
Delivered_Product__c,Hospital__c,SalesOfficeCode_selection__c,
|
SAPRepairNo__c,Status__c,Incharge_Staff__c,Repair_Detail__c
|
from Repair__c];
|
|
Repair_Quotation__c rq = new Repair_Quotation__c();
|
rq.Name = 'testNFM104';
|
rq.Repair__c = rpr.Id;
|
rq.MessageGroupNumber__c = '1';
|
insert rq;
|
}*/
|
|
static testMethod void addDatabase(){
|
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.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',
|
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',
|
Contract_Esti_Start_Date__c = Date.today().addMonths(6),
|
Contract_Range__c = 3,
|
Maintenance_Contract__c = contract.Id
|
);
|
|
insert new Maintenance_Contract_Estimate__c[] {contactEsti1, contactEsti2};
|
|
|
// 调用方法测试, 参数
|
Apexpages.currentPage().getParameters().put('mcid', contract.Id);
|
Apexpages.currentPage().getParameters().put('completion', '5');
|
Apexpages.currentPage().getParameters().put('id', contactEsti2.Id);
|
|
// 创建对象,定义,调用方法测试
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
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.savePrintFlg();
|
controller.ShowLTYRepair();
|
controller.getPageDisabled();
|
controller.priceChangeReset();
|
}
|
}
|
|
|
|
|
|
|
|
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
|
//在创建Asset的时候添加AssetMark__c 字段
|
asset.AssetMark__c = mark;
|
//JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
|
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'];
|
|
// 診療科を作る
|
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.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',
|
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',
|
Contract_Esti_Start_Date__c = Date.today().addMonths(6),
|
Contract_Range__c = 3,
|
Maintenance_Contract__c = contract.Id
|
);
|
insert new Maintenance_Contract_Estimate__c[] {contactEsti1, contactEsti2};
|
|
System.Test.startTest();
|
// 新規
|
Apexpages.currentPage().getParameters().put('mcid', contract.Id);
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
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 SelectAssetEstimateController();
|
controller.init();
|
//JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
|
// System.assertEquals(5, controller.productCount2);
|
//默认查询的是主机
|
System.assertEquals(3, controller.productCount2);
|
//JZHG-BSDUT4 ---20200825---update By rentongxiao---End
|
|
controller.getEnablePrintContract();
|
controller.getUnDecideBtnDisabled();
|
controller.getDecideBtnDisabled();
|
controller.getApprovalBtnDisabled();
|
controller.getSaveBtnDisabled();
|
controller.getPrintBtnDisabled();
|
// System.Test.startTest();
|
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);
|
// SelectAssetEstimateController controller2 = new SelectAssetEstimateController();
|
// controller2.init();
|
|
// controller2.unCheckedAssetsView[0][1].rec_CheckBox_c = true;
|
// controller2.unCheckedAssetsView[0][2].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.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',
|
Maintenance_Contract__c = contract.Id
|
);
|
insert contactEsti1;
|
|
Apexpages.currentPage().getParameters().put('copyid', contactEsti1.Id);
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
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();
|
SelectAssetEstimateController.pageDecide(contactEsti1.Id);
|
SelectAssetEstimateController.pageUndecide(contactEsti1.Id);
|
controller.ComputeLTYRepair();
|
}
|
}
|
|
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 {
|
SelectAssetEstimateController controller001 = new SelectAssetEstimateController();
|
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';
|
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.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(
|
Name = 'contract estimate 1',
|
Maintenance_Contract__c = contract.Id,
|
Contract_Esti_Start_Date__c = Date.today().addDays(1)
|
);
|
insert contactEsti1;
|
|
Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
|
mcae1.Asset__c = asset01.Id;
|
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.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');
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
|
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 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,'耗材');
|
|
// 维修合同を作成する
|
Maintenance_Contract__c contract = new Maintenance_Contract__c();
|
contract.Name = 'tect contract';
|
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',
|
Maintenance_Contract__c = contract.Id,
|
Contract_Esti_Start_Date__c = Date.today().addDays(1)
|
);
|
insert contactEsti1;
|
|
Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
|
mcae1.Asset__c = asset01.Id;
|
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.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', '2');
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
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();
|
|
SelectAssetEstimateController.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.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',
|
Maintenance_Contract__c = contract.Id
|
);
|
insert contactEsti1;
|
|
Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
|
mcae1.Asset__c = asset01.Id;
|
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.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');
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
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.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',
|
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',
|
Contract_Esti_Start_Date__c = Date.today().addMonths(6),
|
Contract_Range__c = 3,
|
Maintenance_Contract__c = contract.Id
|
);
|
insert new Maintenance_Contract_Estimate__c[] {contactEsti1, contactEsti2};
|
|
// 新規
|
Apexpages.currentPage().getParameters().put('mcid', contract.Id);
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
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 = :controller.targetEstimateId];
|
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;
|
//SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
// 病院を作る
|
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.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',
|
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',
|
Contract_Esti_Start_Date__c = Date.today().addMonths(6),
|
Contract_Range__c = 3,
|
Maintenance_Contract__c = contract.Id
|
);
|
insert new Maintenance_Contract_Estimate__c[] {contactEsti1, contactEsti2};
|
System.Test.startTest();
|
Apexpages.currentPage().getParameters().put('id', contactEsti1.Id);
|
SelectAssetEstimateController controller = new SelectAssetEstimateController();
|
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();
|
}
|
}
|
|
|
}
|