liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
@isTest
public class lexToAddMaintenanceContractTest {
    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 testDecide_02() {
        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.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();
        // 记录类型ID
        // 01210000000QemGAAS
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        // 客户名
        hospital.Name = '北京市医院';
        insert hospital;
        
        // 戦略科室を得る
        
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 客户
        Account dep = new Account();
        // 01210000000Qfm7AAC
        // 记录类型ID
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        // 客户名
        dep.Name = 'test de/p';
        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;
        
 
        
 
        // 维修合同
        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};
        // 打包合同
        MaintanceContractPack__c MP = new MaintanceContractPack__c(
            Name = 'testmp',
            Contract_Type__c = '服务合同',
            SalesOfficeCode_selection__c='北京RC'
        );
        insert MP;
 
 
        // 维修合同
        Maintenance_Contract__c testMC = new Maintenance_Contract__c();
        // 绑定维修合同和打包合同的关系
        testMC.MaintanceContractPack__c=MP.id;
        testMC.Name = '青岛市市立医院';
        testMC.Hospital__c=hospital.Id;
        testMC.Service_Contract_Staff__c=u3.id;
        testMC.Department__c = dep.Id;
        testMC.Negotiate_Mean__c  = '1';
        testMC.Estimation_Id__c   = contactEsti1.id;
        upsert testMC;
        PageReference page = new PageReference('/apex/lexToAddMaintenanceContract?contractType=服务合同&id=' + MP.Id);
        System.Test.setCurrentPage(page);
        // lexToAddMaintenanceContractController  testController  = new lexToAddMaintenanceContractController();
        String recordId=testMC.Id+'';
        String contractType='服务合同';
        lexToAddMaintenanceContractController.init(recordId, contractType);
        lexToAddMaintenanceContractController.searchMc('S:Management_Code__c','','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Management_Code__c','equals','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('','contains','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Management_Code__c','','','','');
        lexToAddMaintenanceContractController.searchMc('A:','equals','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Management_Code__c','notequals','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Name','notequals','a b','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Name','contains','a b','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Name','starts with','a b','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Name','equals','a b','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Name','equals','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Name','','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Name','notequals','','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Management_Code__c','contains','a b','服务合同','北京市医院');
        lexToAddMaintenanceContractController.searchMc('S:Management_Code__c','equals',testMC.Management_Code__c+'a,b','服务合同','');
        lexToAddMaintenanceContractController.searchMc('S:Management_Code__c','contains','aaaa','服务合同','');
 
 
        List<String> strs=new List<String>();
        strs.add(testMC.id);
        lexToAddMaintenanceContractController.getContractType(MP.ID);
        lexToAddMaintenanceContractController.canAddMc(MP.ID);
        lexToAddMaintenanceContractController.exchangeMc(strs,MP.ID);
        strs=null;
        lexToAddMaintenanceContractController.exchangeMc(strs,MP.ID);
    }
 
        
    }
    static testMethod void myUnitTest02() {
        // 病院を作る
        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;
        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<String> mceIds = new List<String>{contactEsti.name, contactEsti2.name};
       
        lexToAddMaintenanceContractController.updateLastMc(mtpE.Id);
        lexToAddMaintenanceContractController.initDBPast2YearsRepairPriceRep(contactEsti.Id);
        lexToAddMaintenanceContractController.initToAmpApprovalEdit(contactEsti.Id);
        lexToAddMaintenanceContractController.initMcpPreSubmit(target01.Id);
        lexToAddMaintenanceContractController.updateMcDate(target01.Id);
        lexToAddMaintenanceContractController.initUploadToRecognition(target01.Id);
    } 
}