李彤
2022-04-02 1949e7ccb3bfab67ad2b16d7e0172851c3f823bb
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
@isTest
private class PaymentMaintenanceContractTriggerTest {
    static testMethod void testMethod1() {
        // 取引先
        Account account1 = new Account();
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
        Account account2 = new Account();
        account2.Name = 'test1经销商';
        account2.RecordTypeId = '01210000000Qem1';
        insert account2;
 
        Contact contact2 = new Contact();
        contact2.AccountId = account1.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test2医院';
        insert contact2;
        // ユーザー
        Profile p = [select Id from Profile where Name = '901_经销商活动系统'];
        User user = new User();
        user.ProfileId = p.Id;
        user.ContactId = contact2.Id;
        user.FirstName = 'ユーザー';
        user.LastName = 'テスト';
        user.Email = 'test_user@example.com';
        user.emailencodingkey='UTF-8';
        user.languagelocalekey='zh_CN';
        user.localesidkey='ja_JP';
        user.timezonesidkey='Asia/Shanghai';
        user.Username = 'test_user@example.com';
        user.Alias = 'テユ';
        user.CommunityNickname = 'テストユーザー';
        insert user;
 
        // 代理店医院
        Agency_Hospital_Link__c agency_hospital_link = new Agency_Hospital_Link__c();
        agency_hospital_link.Name = 'test1代理店医院';
        agency_hospital_link.Hospital__c = account1.Id;
        agency_hospital_link.Agency__c = account2.Id;
        agency_hospital_link.OwnerId = user.Id;
        insert agency_hospital_link;
 
 
        Agency_Contact__c ac1 = new Agency_Contact__c();
        ac1.Name = 'test1のび太';
        ac1.Agency_Hospital__c = agency_hospital_link.Id;
        insert ac1;
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
 
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        insert depart1;
 
 
        //新建维修合同
        Maintenance_Contract__c test = new Maintenance_Contract__c();
        test.Name = 'Test合同';
        test.RecordTypeId='01210000000QjeF';
        test.Department__c = depart1.Id;
        test.Management_Code__c =  'BJ-RS-BJ0062233';
        test.Status__c = '询价中';
        test.Service_Contract_Staff__c = user.Id;
        insert test;
 
 
        Payment_Maintenance_Contract__c pmc = new Payment_Maintenance_Contract__c();
        pmc.Find_Dealers__c = account1.id;
        pmc.Find_Contact__c = test.id;
        pmc.Amount__c = 123.23;
        //pmc.Employees__c = ac1.Id;
        pmc.ReceiveNo__c = '134';
        pmc.ReceiveNoKey__c = '3245';
        insert pmc;
    }
}