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
@isTest
private class AccountServiceOfTarget1Hto2HBatchTest {
    static testMethod void testMethod1() {
        system.Test.startTest();
         database.executeBatch(new AccountServiceOfTarget1Hto2HBatch(),200);
        system.Test.stopTest();
    }
 
    @testSetup
    private static void initData(){
         List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        } 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com',Job_Category__c = '销售服务', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert MacOwner;
 
        Account hospital = new Account();
        hospital.RecordTypeId = rectCo[0].Id;
        hospital.Name         = 'NFM007Testhospital';
        insert hospital;
 
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = hospital.Id;
        section.Hospital_Department_Class__c = hospital.Id;
        section.AgentCode_Ext__c = '9999900';
        insert section;
 
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId = strategicDep[0].Id;
        depart.Department_Class__c = strategicDep[0].Id;
        depart.Hospital__c = hospital.Id;
        insert depart;
 
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'Prd1';
        prd1.ProductCode            = 'Prd1';
        prd1.Repair_Product_Code__c = 'Prd1_RP';
        prd1.Name                   = 'Prd1';
        prd1.Manual_Entry__c        = false;
        // prd1.Category2__c = '本体';
        prd1.Category3__c = '纤维镜';
        prd1.Category4__c = '妇科用硬性镜';
        // prd1.Category5__c = '260SL系列';
        prd1.Asset_Model_No__c = '1001';
        prd1.Important_product__c = true;
        prd1.Important_Rroduct_1GI__c = true;
        insert prd1;
 
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'Prd2';
        prd2.ProductCode            = 'Prd2';
        prd2.Repair_Product_Code__c = 'Prd2_RP';
        prd2.Name                   = 'Prd2';
        prd2.Manual_Entry__c        = false;
        // prd1.Category2__c = '本体';
        prd2.Category3__c = '光源';
        // prd2.Category4__c = 'SD EndoEYE';
        // prd1.Category5__c = '260SL系列';
        prd2.Asset_Model_No__c = '1001';
        prd2.Important_product__c = true;
        prd2.Important_Rroduct_1GI__c = true;
        insert prd2;
 
        Product2 prd3 = new Product2();
        prd3.ProductCode_Ext__c     = 'Prd3';
        prd3.ProductCode            = 'Prd3';
        prd3.Repair_Product_Code__c = 'Prd3_RP';
        prd3.Name                   = 'Prd3';
        prd3.Manual_Entry__c        = false;
        // prd1.Category2__c = '本体';
        prd3.Category3__c = '纤维镜';
        // prd2.Category4__c = 'SD EndoEYE';
        // prd1.Category5__c = '260SL系列';
        prd3.Asset_Model_No__c = '1001';
        prd3.Important_product__c = true;
        prd3.Important_Rroduct_1GI__c = true;
        insert prd3;
 
        Product2 prd4 = new Product2();
        prd4.ProductCode_Ext__c     = 'Prd4';
        prd4.ProductCode            = 'Prd4';
        prd4.Repair_Product_Code__c = 'Prd4_RP';
        prd4.Name                   = 'Prd4';
        prd4.Manual_Entry__c        = false;
        // prd1.Category2__c = '本体';
        prd4.Category4__c = '妇科用硬性镜';
        // prd2.Category4__c = 'SD EndoEYE';
        // prd1.Category5__c = '260SL系列';
        prd4.Asset_Model_No__c = '1001';
        prd4.Important_product__c = true;
        prd4.Important_Rroduct_1GI__c = true;
        insert prd4;
 
        Consumable_order_details2__c saledet1 = new Consumable_order_details2__c();
        saledet1.Name = 'OCM_01_001001';
        // saledet1.Consumable_order_minor__c = Order1.Id;
        saledet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
        saledet1.Bar_Code__c = '0114953170032070111804001082K250BBBBB';
        // saledet1.Consumable_Product__c = prd1.Id;
        saledet1.Used_account__c = section.Id;
        saledet1.Delivery_List_RMB__c = 11;
        saledet1.Box_Piece__c = '盒';
        saledet1.TracingCode__c = 'BBBBB';
        saledet1.SerialLotNo__c = '82K';
        saledet1.Guarantee_period_for_products__c = Date.today().addDays(5);
        saledet1.Sterilization_limit__c = Date.today().addDays(5);
        saledet1.Send_Date__c = null;
        //saledet1.Dealer_Shipment__c = false;
        saledet1.Arrive_date__c = null;
        //saledet1.Dealer_Arrive__c = false;
        saledet1.Used_date__c = null;
        //saledet1.Dealer_Saled__c = false;
        saledet1.Deliver_date__c = Date.today().addDays(-10);
        insert saledet1;
 
        // 维修合同を作成する
        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 = depart.Id;
        contract.Service_Contract_Staff__c = MacOwner.Id;
        contract.Payment_Plan_Sum_First__c = 1;
        contract.Status__c = '契約満了';
        contract.Maintenance_Contract_No__c = '11123';
         contract.recordtypeId = 
             Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId();
        contract.Not_Upper_limit_reason__c = ' 1';
        contract.Contract_Start_Date__c = Date.newInstance(2021,10,5);   
        contract.Contract_End_Date__c = Date.newInstance(2021,11,1);       
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.New_Contract_TypeF_Text__c = '续签合同';
        contract.IF_Target_Renew__c='1';
        contract.Contract_Conclusion_Date__c=Date.newInstance(2021,10,5);
        system.assertEquals(contract.Contract_End_Date__c >= Date.newInstance(2021,10,1) && contract.Contract_End_Date__c <= Date.newInstance(2022,9,30),true);
        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 = depart.Id;
        contract2.Service_Contract_Staff__c = MacOwner.Id;
        contract2.Payment_Plan_Sum_First__c = 1;
        contract2.Status__c = '契約';
        contract2.Maintenance_Contract_No__c = '11123111';
        contract2.Not_Upper_limit_reason__c = ' 2';
        contract2.Contract_Start_Date__c = Date.newInstance(2021,10,5);   
        contract2.Contract_End_Date__c = Date.newInstance(2021,11,1);       
        contract2.SalesOfficeCode_selection__c = '北京RC';
        contract2.IF_Target_Renew__c='1';
        contract2.Contract_Conclusion_Date__c=Date.newInstance(2021,10,5);
        system.assertEquals(contract2.Contract_End_Date__c >= Date.newInstance(2021,10,1) && contract2.Contract_End_Date__c <= Date.newInstance(2022,9,30),true);
        insert contract2;
 
        asset ast = new asset();
        ast.Name                             = prd1.Name;
        ast.Product2Id                       = prd1.Id;
        ast.SerialNumber                     = saledet1.SerialLotNo__c + '(' + saledet1.TracingCode__c + ')';
        ast.SLMark__c                        = 'Serial Number';         // 固定 dnInfo.SorLMark;
        ast.Guarantee_period_for_products__c = saledet1.Guarantee_period_for_products__c;
        ast.TracingCode__c                   = saledet1.TracingCode__c;
        ast.Guaranteen_end__c                = saledet1.Sterilization_limit__c;
        ast.Barcode__c                       = saledet1.Bar_Code__c;
        ast.Product_Serial_No__c             = saledet1.SerialLotNo__c  + '(' + saledet1.TracingCode__c + ')';
        ast.Asset_Owner__c                   = '经销商资产';
        ast.AccountId                        = depart.Id;
        ast.Department_Class__c              = section.Id;
        // ast.Asset_owner_delaer_name__c       = hospital.Id;
        ast.Hospital__c                      = hospital.Id;
        ast.CurrentContract__c = contract.Id;
        ast.CurrentContract_Asset_Price__c = 0;
        ast.CurrentContract_F__c=contract.Id;
        insert ast;
 
        asset ast1 = new asset();
        ast1.Name                             = prd2.Name;
        ast1.Product2Id                       = prd2.Id;
        ast1.SerialNumber                     = saledet1.SerialLotNo__c + '(' + saledet1.TracingCode__c + ')';
        ast1.SLMark__c                        = 'Serial Number';         // 固定 dnInfo.SorLMark;
        ast1.Guarantee_period_for_products__c = saledet1.Guarantee_period_for_products__c;
        ast1.TracingCode__c                   = saledet1.TracingCode__c;
        ast1.Guaranteen_end__c                = saledet1.Sterilization_limit__c;
        ast1.Barcode__c                       = saledet1.Bar_Code__c;
        ast1.Product_Serial_No__c             = saledet1.SerialLotNo__c  + '(' + saledet1.TracingCode__c + ')';
        ast1.Asset_Owner__c                   = '经销商资产';
        ast1.AccountId                        = depart.Id;
        ast1.Department_Class__c              = section.Id;
        // ast.Asset_owner_delaer_name__c       = hospital.Id;
        ast1.Hospital__c                      = hospital.Id;
        ast1.CurrentContract__c = contract2.Id;
        ast1.CurrentContract_Asset_Price__c = 0;
        insert ast1;
 
        asset ast2 = new asset();
        ast2.Name                             = prd3.Name;
        ast2.Product2Id                       = prd3.Id;
        ast2.SerialNumber                     = saledet1.SerialLotNo__c + '(' + saledet1.TracingCode__c + ')';
        ast2.SLMark__c                        = 'Serial Number';         // 固定 dnInfo.SorLMark;
        ast2.Guarantee_period_for_products__c = saledet1.Guarantee_period_for_products__c;
        ast2.TracingCode__c                   = saledet1.TracingCode__c;
        ast2.Guaranteen_end__c                = saledet1.Sterilization_limit__c;
        ast2.Barcode__c                       = saledet1.Bar_Code__c;
        ast2.Product_Serial_No__c             = saledet1.SerialLotNo__c  + '(' + saledet1.TracingCode__c + ')';
        ast2.Asset_Owner__c                   = '经销商资产';
        ast2.AccountId                        = depart.Id;
        ast2.Department_Class__c              = section.Id;
        // ast.Asset_owner_delaer_name__c       = hospital.Id;
        ast2.Hospital__c                      = hospital.Id;
        ast2.CurrentContract__c = contract.Id;
        ast2.CurrentContract_Asset_Price__c = 0;
        insert ast2;
 
        asset ast3 = new asset();
        ast3.Name                             = prd4.Name;
        ast3.Product2Id                       = prd4.Id;
        ast3.SerialNumber                     = saledet1.SerialLotNo__c + '(' + saledet1.TracingCode__c + ')';
        ast3.SLMark__c                        = 'Serial Number';         // 固定 dnInfo.SorLMark;
        ast3.Guarantee_period_for_products__c = saledet1.Guarantee_period_for_products__c;
        ast3.TracingCode__c                   = saledet1.TracingCode__c;
        ast3.Guaranteen_end__c                = saledet1.Sterilization_limit__c;
        ast3.Barcode__c                       = saledet1.Bar_Code__c;
        ast3.Product_Serial_No__c             = saledet1.SerialLotNo__c  + '(' + saledet1.TracingCode__c + ')';
        ast3.Asset_Owner__c                   = '经销商资产';
        ast3.AccountId                        = depart.Id;
        ast3.Department_Class__c              = section.Id;
        // ast.Asset_owner_delaer_name__c       = hospital.Id;
        ast3.Hospital__c                      = hospital.Id;
        ast3.CurrentContract__c = contract.Id;
        ast3.CurrentContract_Asset_Price__c = 0;
        insert ast3;
 
 
        Account_Service_Of_Target__c asot=new Account_Service_Of_Target__c();
        asot.OCSM_Period_half__c='2H';
        asot.Account_HP__c=hospital.Id;
        insert asot;
         Account_Service_Of_Target__c asot2=new Account_Service_Of_Target__c();
        asot2.OCSM_Period_half__c='1H';
        asot2.Account_HP__c=hospital.Id;
        insert asot2;
    }
}