高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@isTest
private class MoreMaintenanceContractBatchTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static Account createHospital( String hospitalName) {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
        hospital.Name = hospitalName;
        insert hospital;
        StaticParameter.EscapeAccountTrigger = true;
        return hospital;
    }
    static List<Account> selectStrategicDep( Account hospital) {
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        return strategicDep;
    }
    static Account createDep( Account hospital, Account strategicDep) {
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep.Id;
        dep.Department_Class__c = strategicDep.Id;
        dep.Hospital__c = hospital.Id;
        // dep.State_Text__c = '上海市';
        insert dep;
        return dep;
    }
    static Asset createAsset( Account hospital, Account strategicDep, Account dep) {
        // 製品を作る
        Product2 productA = new Product2( Name = 'テスト商品');
        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 asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dep.Id;
        asset.Department_Class__c = strategicDep.Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        asset.Quantity = 3;
        // asset.Extend_Gurantee_DateTo_Text__c =Date.today().addDays(30);
        // asset.IS_Extend_Gurantee_Txt__c =true;
        // asset.Order_No__c = 'BJ_2020';
 
        insert asset;
 
        return asset;
    }
    static Maintenance_Contract_Asset__c createMiddleTable( Asset asset, Maintenance_Contract__c contract) {
        // 中間テーブルを設ける
        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = contract.id;
        insert middleTable;
        return middleTable;
    }
    static testMethod void testMethod1() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        //StaticParameter.EscapeAccountTrigger = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
        //维修合同
        // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
        // 納入機器を作る
        Asset asset = createAsset( hospital, strategicDep[0], dep);
 
        //维修合同
        Maintenance_Contract__c contract1 = new Maintenance_Contract__c();
        contract1.Name = 'tect contract1';
        contract1.status__c = '契約';
        contract1.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract1.Contract_Conclusion_Date__c = Date.today();
        contract1.Hospital__c = hospital.Id;
        contract1.Department_Class__c = strategicDep[0].Id;
        contract1.Department__c = dep.Id;
        contract1.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
        contract1.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
        contract1.SalesOfficeCode_selection__c = '北京RC';
        contract1.hospitalQuotationTextSum__c = 0.00;
        contract1.Estimate_Target__c = '经销商';
        contract1.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId();
        insert new Maintenance_Contract__c[] {contract1};
 
        Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
        mca1.Asset__c = asset.Id;
        mca1.Estimate_List_Price__c = 100;
        mca1.Maintenance_Contract__c = contract1.Id;
        insert new Maintenance_Contract_Asset__c[] {mca1};
 
        // 修理を作成する01
        Repair__c repair01 = new Repair__c();
        repair01.Account__c = dep.Id;
        repair01.Department_Class__c = strategicDep[0].Id;
        repair01.Hospital__c = hospital.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -11);   // 维修合同判断日がサービス契約開始日の前日
        repair01.Repair_Start_Date__c = Date.today().addDays(-10);
        repair01.Repair_Final_Inspection_Date__c = Date.today().addDays(-3);
        repair01.Repair_List_Price__c = 100.00;
        repair01.RepairOrder_Complete_Day__c = Date.today().addDays(-1);
        repair01.Maintenance_Contract__c = contract1.Id;
        insert repair01;
        
        System.Test.StartTest();
        List<Maintenance_Contract__c> Mc1_1 = [Select Id,Name,RecordType.DeveloperName from Maintenance_Contract__c where RecordType.DeveloperName='NewMaintenance_Contract'];
        system.assertEquals(1,Mc1_1.size());
          Database.executeBatch(new MoreMaintenanceContractBatch(Mc1_1[0].Id), 1);     
        System.Test.StopTest();
    }
    static testMethod void testMethod2() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        //StaticParameter.EscapeAccountTrigger = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
        //维修合同
        // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
        // 納入機器を作る
        Asset asset = createAsset( hospital, strategicDep[0], dep);
 
        //维修合同
        Maintenance_Contract__c contract1 = new Maintenance_Contract__c();
        contract1.Name = 'tect contract1';
        contract1.status__c = '契約';
        contract1.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract1.Contract_Conclusion_Date__c = Date.today();
        contract1.Hospital__c = hospital.Id;
        contract1.Department_Class__c = strategicDep[0].Id;
        contract1.Department__c = dep.Id;
        contract1.Contract_Start_Date__c = Date.today().addDays( -10);   // 10日前
        contract1.Contract_End_Date__c = Date.today().addDays( 5);       // 5日後
        contract1.SalesOfficeCode_selection__c = '北京RC';
        contract1.hospitalQuotationTextSum__c = 0.00;
        contract1.Estimate_Target__c = '经销商';
        contract1.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('VM_Contract').getRecordTypeId();
        insert new Maintenance_Contract__c[] {contract1};
 
        Maintenance_Contract_Asset__c mca1 = new Maintenance_Contract_Asset__c();
        mca1.Asset__c = asset.Id;
        mca1.Estimate_List_Price__c = 100;
        mca1.Maintenance_Contract__c = contract1.Id;
        insert new Maintenance_Contract_Asset__c[] {mca1};
 
        // 修理を作成する01
        Repair__c repair01 = new Repair__c();
        repair01.Account__c = dep.Id;
        repair01.Department_Class__c = strategicDep[0].Id;
        repair01.Hospital__c = hospital.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -11);   // 维修合同判断日がサービス契約開始日の前日
        repair01.Repair_Start_Date__c = Date.today().addDays(-10);
        repair01.Repair_Final_Inspection_Date__c = Date.today().addDays(-3);
        repair01.Repair_List_Price__c = 100.00;
        repair01.RepairOrder_Complete_Day__c = Date.today().addDays(-1);
        repair01.Maintenance_Contract__c = contract1.Id;
        insert repair01;
        
        System.Test.StartTest();
        List<Maintenance_Contract__c> Mc1_1 = [Select Id,Name,RecordType.DeveloperName from Maintenance_Contract__c where RecordType.DeveloperName='VM_Contract'];
        system.assertEquals(1,Mc1_1.size());
          Database.executeBatch(new MoreMaintenanceContractBatch(Mc1_1[0].Id), 1);     
        System.Test.StopTest();
    }
 
}