buli
2022-05-13 2f4492ee18f90274582fcc2bb06f5e9bf64136e8
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
@isTest
private class SWOControllerTest {
    
 
    public static User UserD(){
        User user2 = new User();
        user2.LastName = 'test2';
        user2.FirstName = 'test2';
        user2.Alias = 'test2';
        user2.Email = 'test2@test.com';
        user2.Username = 'Xin_Prectech@olympus.com.cn';
        user2.CommunityNickname = 'test2';
        user2.IsActive = true;
        user2.EmailEncodingKey = 'ISO-2022-JP';
        user2.TimeZoneSidKey = 'Asia/Tokyo';
        user2.LocaleSidKey = 'ja_JP';
        user2.LanguageLocaleKey = 'ja';
        user2.ProfileId = '00e28000001sZE6';//System.Label.SystemAdmin;
        insert user2;
 
        return user2;
    }    
 
    static testMethod void testMethod1() {
 
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD'];
        Id pricebookId = Test.getStandardPricebookId();
        
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            CurrencyIsoCode = 'CNY'
        );
        insert pricebook;
        
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.IsActive = true;
        product1.ProductCode = 'product1';
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
        insert product1;
 
        User_FaultInfo__c uf = new User_FaultInfo__c();
        // uf.Name = 'Test';
        insert uf;
 
        // User user = new User();
        // user.LastName = 'test3';
        // user.FirstName = 'test3';
        // user.Alias = 'test3';
        // user.Email = 'test3@test.com';
        // user.Username = 'test111@test222.com';
        // user.CommunityNickname = 'test3';
        // user.IsActive = true;
        // user.EmailEncodingKey = 'ISO-2022-JP';
        // user.TimeZoneSidKey = 'Asia/Tokyo';
        // user.LocaleSidKey = 'ja_JP';
        // user.LanguageLocaleKey = 'ja';
        // user.ProfileId = '00e28000001sZE6';//System.Label.SystemAdmin;
        // insert user;
 
        // User_FaultInfo__c uf = new User_FaultInfo__c();
        // uf.Name = 'Test';
        // insert uf;
 
        PageReference page = new PageReference('apex/SWOPage?caseId='+uf.Id);
        System.Test.setCurrentPage(page);
        SWOController controller = new SWOController();
        controller.init();
        // controller.swo.REPEAT_REPAIR__c = true;
        controller.swo.QUANTITY__c = 22;
        controller.swo.ESTIMATED_LABOUR_HOURS__c = 22;
        controller.swo.LABOUR_RATE__c = 22;
        controller.swo.OFFICE__c = 'Beijing';
        controller.swo.SWO_PRIORITY__c = 'Medium';
        controller.swo.SWO_STATUS__c = 'Closed';
        controller.swo.TYPE__c = 'Service';
        controller.swo.ASSIGNEDTO__c = UserD().Id;
        controller.swo.DEPARTMENT__c = 'Field Service';
        controller.swo.REASON__c = 'Replacement';
        controller.swo.PRODUCT_TYPE__c = 'NDT';
        controller.swo.ITEM__c = product1.Id;
        // controller.swo.INSTRUMENT_RECEIVE_DATE__c = Datetime.now();
        // controller.swo.ASSIGNED_TO_TECHNICIAN_DATE__c = Datetime.now().addDays(-1);
        // TECHNICIAN_COMPLETION_DATE__c = 
        // Datetime.
        controller.save();
 
 
 
    }
 
    static testMethod void updateTest() {
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD'];
        Id pricebookId = Test.getStandardPricebookId();
        
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            CurrencyIsoCode = 'CNY'
        );
        insert pricebook;
        
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.IsActive = true;
        product1.ProductCode = 'product1';
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
        insert product1;
 
        User_FaultInfo__c uf = new User_FaultInfo__c();
        // uf.Name = 'Test';
        insert uf;
 
         List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        Profile prof = [select Id from Profile where Name ='SSBG DEALER IE'];
        Account dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'BS';
        dealer.PostCode__c='000000';
        insert dealer;
        Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        User testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = '00e28000001sZE6',TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
 
        User user2 = UserD();//new User();
        // user2.LastName = 'test2';
        // user2.FirstName = 'test2';
        // user2.Alias = 'test2';
        // user2.Email = 'test2@test.com';
        // user2.Username = 'Xin_Prectech@olympus.com.cn';
        // user2.CommunityNickname = 'test2';
        // user2.IsActive = true;
        // user2.EmailEncodingKey = 'ISO-2022-JP';
        // user2.TimeZoneSidKey = 'Asia/Tokyo';
        // user2.LocaleSidKey = 'ja_JP';
        // user2.LanguageLocaleKey = 'ja';
        // user2.ProfileId = '00e28000001sZE6';//System.Label.SystemAdmin;
        // insert user2;
 
        SWO__c swo = new SWO__c();
        swo.Name = 'Test';
        swo.QUANTITY__c = 22;
        swo.ESTIMATED_LABOUR_HOURS__c = 22;
        swo.LABOUR_RATE__c = 22;
        swo.OFFICE__c = 'Beijing';
        swo.SWO_PRIORITY__c = 'Medium';
        swo.SWO_STATUS__c = 'Close Denied';
        swo.TYPE__c = 'Service';
        swo.ASSIGNEDTO__c = user2.Id;
        swo.DEPARTMENT__c = 'Field Service';
        swo.REASON__c = 'Replacement';
        swo.PRODUCT_TYPE__c = 'NDT';
        swo.ITEM__c = product1.Id;
        swo.INSTRUMENT_RECEIVE_DATE__c = Datetime.now();
        swo.INSTRUMENT_SHIP_DATE__c = Datetime.now().addDays(1);
        swo.DIAGNOSIS_START__c = Datetime.now();
        swo.DIAGNOSIS_END__c = Datetime.now().addDays(1);
        swo.PO_RECEIVE_DATE__c = Datetime.now();
        swo.Quotation_send__c = Datetime.now().addDays(1);
        swo.REPAIR_START__c = Datetime.now();
        swo.REPAIR_END__c = Datetime.now().addDays(1);
 
        swo.CALIBRATION_START__c = Datetime.now();
        swo.CALIBRATION_END__c = Datetime.now().addDays(1);
 
        swo.FQC_START__c = Datetime.now();
        swo.FQC_end__c = Datetime.now().addDays(1);
 
        swo.Repair_DateTime__c = Datetime.now();
        swo.DELIVERED_TO_SERVICE__c = Datetime.now().addDays(1);
        swo.CASE_NUMBER__c = uf.Id;
 
        // swo.REPAIR_START__c = Datetime.now();
        // swo.REPAIR_END__c = Datetime.now().addDays(1);
 
        insert swo;
 
        Quotes__c quotes = new Quotes__c();
        quotes.SWO__c = swo.Id;
        quotes.QuotesType__c = '零件报价单';
        quotes.DATE__c = Date.today();
        quotes.LEAD_TIME__c = '1 week';
        quotes.STATUS__c = 'Qualifying';
        quotes.LOCATION__c = 'China - Service';
        quotes.TERMS__c = '1% 10 Net 30';
        quotes.EXPIRES__c = Date.today();
        quotes.EXP_CLOSE__c = Date.today();
        quotes.ORDER_TYPE__c = 'LS Core Clinical';
 
        insert quotes;
 
        Diagnosis_Part__c diagnosisPart = new Diagnosis_Part__c();
        diagnosisPart.SWO__c = swo.Id;
        insert diagnosisPart;
 
        Mail_Merge__c  mailMerge = new Mail_Merge__c(); 
        mailMerge.SWO__c = swo.Id;
        insert mailMerge;
        Attachment att = new Attachment(
            Name = 'ORDER-123456.pdf',
            parentId = mailMerge.Id,
            Body = EncodingUtil.base64Decode('test')
        );
        insert att;
 
        PageReference page = new PageReference('apex/SWOPage?id='+swo.Id +'&type=Product');
        System.Test.setCurrentPage(page);
        SWOController controller = new SWOController(new ApexPages.StandardController(swo));
        controller.init();
        controller.save();
        controller.sendEmail(swo.ASSIGNEDTO__c);
 
        controller.init();
        // Integer num = Integer.valueOf('Test--->'+controller.SwoStatus);
        // controller.SwoStatus = '1111';
        controller.swo.SWO_STATUS__c = 'Quotation for approval';
        controller.swo.ASSIGNEDTO__c = user2.Id;
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'Quotation approved';
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'Ready for Quote';
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'Parts Hold';
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'Delivered to Technician';
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'Ready to Quote';
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'Ready for Sales order';
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'Repair';
        controller.save();
 
        controller.init();
        swo.SWO_STATUS__c = 'In Queue';
        controller.save();
 
 
        controller.setMail();
        controller.setFault();
        controller.setCase();
        controller.setProduct();
        controller.setQuotes();
        controller.setRepair();
        controller.setTracking();
        controller.setTechnical();
        controller.setEstimation();
        controller.setGeneral();
        controller.setIncoming();
        controller.setOutgoing();
        controller.setDiagnosis();
 
        controller.uploadFile();
        controller.edit();
        controller.addDiagnosisInfo();
        controller.openPageSave();
        controller.repairReturn();
 
    }
 
    
    static testMethod void testMethod3() {
 
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        List<RecordType> rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD'];
        Id pricebookId = Test.getStandardPricebookId();
        
        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            CurrencyIsoCode = 'CNY'
        );
        insert pricebook;
        
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.IsActive = true;
        product1.ProductCode = 'product1';
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
        insert product1;
 
        User_FaultInfo__c uf = new User_FaultInfo__c();
        // uf.Name = 'Test';
        insert uf;
 
        // User user = new User();
        // user.LastName = 'test';
        // user.FirstName = 'test';
        // user.Alias = 'test';
        // user.Email = 'test@test.com';
        // user.Username = 'test111@test222.com';
        // user.CommunityNickname = 'test';
        // user.IsActive = true;
        // user.EmailEncodingKey = 'ISO-2022-JP';
        // user.TimeZoneSidKey = 'Asia/Tokyo';
        // user.LocaleSidKey = 'ja_JP';
        // user.LanguageLocaleKey = 'ja';
        // user.ProfileId = '00e28000001sZE6';//System.Label.SystemAdmin;
        // insert user;
 
 
        PageReference page = new PageReference('apex/SWOPage?caseId='+uf.Id);
        System.Test.setCurrentPage(page);
        SWOController controller = new SWOController();
        controller.init();
 
        controller.save();
 
 
 
    }
 
}