buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
@isTest
private class LoanerApplicationWebServiceTest {
    static Product2 prd1;
    static Product2 prd2;
    static Account acc;
    static Account dealer;
    static Contact core;
    static User testUser;
    static Asset asset;
    static void setupTestData() {
 
        OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc13 = new OlympusCalendar__c(Date__c = Date.today().addDays(-1), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc14 = new OlympusCalendar__c(Date__c = Date.today().addDays(-2), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc15 = new OlympusCalendar__c(Date__c = Date.today().addDays(-3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc16 = new OlympusCalendar__c(Date__c = Date.today().addDays(-4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc17 = new OlympusCalendar__c(Date__c = Date.today().addDays(-5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
 
        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12,oc13,oc14,oc15,oc16,oc17};
 
        List<RecordType> dealerIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        if (dealerIE.size() == 0) {
            return;
        }
        List<RecordType> olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany'];
        if (olyCompany.size() == 0) {
            return;
        }
 
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        List<RecordType> loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理'];
        if (loa_number.size() == 0) {
            return;
        }
 
        //代理商用户
        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'];
        dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'IE';
        dealer.PostCode__c='000000';
        insert dealer;
        core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
        insert testUser;
 
        //样机客户
        acc = new Account();
        acc.Name = 'test dealer';
        acc.RecordTypeId = olyCompany[0].Id;
        acc.ProductSegment__c = 'IE';
        acc.PostCode__c='000000';
        insert acc;
 
        // 产品
        prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'testSBG001';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;
 
        prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'testSBG002';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        insert new Product2[] {prd1, prd2};
 
        // 保有设备 (数量管理)
        asset = new Asset();
        asset.RecordTypeId = loa_number[0].Id;
        asset.SerialNumber = 'asset';
        asset.Name = 'asset';
        asset.AccountId = acc.Id;
        asset.Product2Id = prd2.Id;
        asset.Quantity = 1;
        asset.Status = '在库';
        asset.Equipment_Type__c = 'IE';
        asset.loaner_place__c = '广州办';
        asset.total_number__c = 20;
        asset.Remarks2__c = 'asset';
 
        // 保有设备 (个体管理)
        Asset assetC1 = new Asset();
        assetC1.RecordTypeId = loa_individual[0].Id;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = acc.Id;
        assetC1.Product2Id = prd1.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '在库';
        assetC1.Equipment_Type__c = 'IE';
        assetC1.loaner_place__c = '北京酒仙桥';
        assetC1.Remarks2__c = 'assetC1';
        
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        insert new Asset[] {asset,assetC1};
    }
    //出库指示
    @isTest static void loanIndicationTest() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        LoanerApplicationWebService.loanIndication('111111111111111');
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '申请中';
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.pickup_time__c = Date.today().addDays(2);
        insert loanerApp;
        LoanerApplicationWebService.loanIndication(loanerApp.Id);
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        update loanerApp;
        LoanerApplicationWebService.loanIndication(loanerApp.Id);
 
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '已批准';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        LoanerApplicationWebService.loanIndication(loanerApp.Id);
    }
    @isTest static void sendOutAllTest01() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        System.Test.startTest();
        LoanerApplicationWebService.sendOutAll('111111111111111');
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        insert loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
 
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '出库前已检测';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        loanerApp.Status__c = '已出库指示';
           update loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        loanerApp.Status__c = '出库前已检测';
        update loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        loanerApp.pickup_time__c = Date.today();
        update loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        System.Test.stopTest();
 
    }
    @isTest static void sendOutAllTest02() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '出库前已检测';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '出库前已检测';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
    }
 
    @isTest static void installConfirmTest() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
        LoanerApplicationWebService.installConfirm('111111111');
        LoanerApplicationWebService.installConfirm(loanerApp.Id);
        loanerApp.Status__c = '申请者已收货';
        update loanerApp;
        LoanerApplicationWebService.installConfirm(loanerApp.Id);
 
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
    }
 
    @isTest static void sendBackAllTest() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
        LoanerApplicationWebService.sendBackAll('111111111');
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
        loanerApp.Status__c = '申请者已收货';
        loanerApp.Return_Track_Company__c = '11111';
        loanerApp.Return_Track_Number__c = '11111';
        loanerApp.Return_Trake_Staff__c = '11111';
        update loanerApp;
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
 
    }
    @isTest static void sendBackAllTest1() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'NDT'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'NDT';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'NDT';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '培训';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
        LoanerApplicationWebService.sendBackAll('111111111');
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
        loanerApp.Status__c = '申请者已收货';
        loanerApp.Return_Track_Company__c = '11111';
        loanerApp.Return_Track_Number__c = '11111';
        loanerApp.Return_Trake_Staff__c = '11111';
        loanerApp.loaner_manage_place__c = '北京酒仙桥';
        loanerApp.loaner_return__c = true;
        update loanerApp;
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
 
    }
 
    @isTest static void splitLoanerApplicationTest() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
        loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-02';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = asset.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        System.Test.startTest();
 
        LoanerApplicationWebService.splitLoanerApplication('111111111');
        loanerApp.Status__c = '申请者已收货';
        update loanerApp;
 
        LoanerApplicationWebService.splitLoanerApplication(loanerApp.Id);
        loanerApp.Status__c = '销售担当批准';
        update loanerApp;
        LoanerApplicationWebService.splitLoanerApplication(loanerApp.Id);
        System.Test.stopTest();
 
    }
 
    @isTest static void cancelLoanerApplicationTest() {
        setupTestData();
 
        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '申请中';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        loanerApp.pickup_time__c = Date.today().addDays(2);
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
        loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-02';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = asset.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
 
        LoanerApplicationWebService.cancelLoanerApplication('111111111');
        LoanerApplicationWebService.cancelLoanerApplication(loanerApp.Id);
        loanerApp.Status__c = '已批准';
        update loanerApp;
        LoanerApplicationWebService.cancelLoanerApplication(loanerApp.Id);
        loanerApp.Cancel_Reason__c = 'test';
        update loanerApp;
        LoanerApplicationWebService.cancelLoanerApplication(loanerApp.Id);
 
    }
}