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
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
@isTest
private class EquipmentRenewMoleculeBatchTest {
     @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(2022,2,5);   
        contract.Contract_End_Date__c = Date.newInstance(2023,11,1);       
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.New_Contract_TypeF_Text__c = '续签合同';
        contract.Contract_Conclusion_Date__c=Date.newInstance(2022,3,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_Estimate__c contactEsti = new Maintenance_Contract_Estimate__c(
            Name = 'contract estimate 1',
            Maintenance_Contract__c = contract.Id,
            Contract_Esti_Start_Date__c = Date.today(),
            Contract_Start_Date__c = Date.today(),
            Contract_Range__c = 12,
            Maintenance_Price__c = 1500,
            Estimate_Trial_Money__c = 1500,
            NotUse_Oxygenated_Water__c = true,
            Discount_Percentage__c = 12.3,
            New_Contract_Type_TxT__c = '续签合同',
            Discount_Price__c = 1000
        );
 
        insert contactEsti;
 
        Maintenance_Contract__c contract2 = new Maintenance_Contract__c();
        contract2.Name = 'tect contract2';
        contract2.Hospital__c = hospital.Id;
        contract2.Estimation_Id__c = contactEsti.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(2022,1,1);       
        contract2.SalesOfficeCode_selection__c = '北京RC';
        contract2.Contract_Conclusion_Date__c=Date.newInstance(2021,10,5);
        contract2.IF_Taget_MC__c='1';
        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.IF_Renewalrate_Target_Asset__c   = '1';
        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=contract2.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.IF_Renewalrate_Target_Asset__c   = '1';
        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.IF_Renewalrate_Target_Asset__c   = '1';
        ast2.Department_Class__c              = section.Id;
        // ast.Asset_owner_delaer_name__c       = hospital.Id;
        ast2.Hospital__c                      = hospital.Id;
        ast2.CurrentContract__c = contract2.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.IF_Renewalrate_Target_Asset__c   = '1';
        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;
 
        Maintenance_Contract_Estimate__c contactEsti1 = new Maintenance_Contract_Estimate__c(
                Name = 'contract estimate 1',
                RecordtypeId = 
                         Schema.SObjectType.Maintenance_Contract_Estimate__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Quote').getRecordTypeId(),
                Contract_Esti_Start_Date__c = Date.today(),
                Contract_Range__c = 2,
                Maintenance_Contract__c = contract.Id,
            Asset_Sum_Price__c = 1000,
            mainTalksTime__c = 1,
            talksStartDate__c = date.today(),
             Discount_reason__c ='1',
            Improve_ConsumptionRate_Idea__c = '1',
            NewEstimation_Amount__c = 100
            );
        insert contactEsti1;
 
        Maintenance_Contract_Asset_Estimate__c mcae1 = new Maintenance_Contract_Asset_Estimate__c();
        mcae1.Asset__c = ast3.Id;
        mcae1.Maintenance_Contract_Estimate__c = contactEsti1.Id;
        mcae1.ifHaveleftInPrevious__c = true;
        mcae1.Estimate_List_Price__c = 1000;
        mcae1.Check_Result__c = 'OK';
        insert mcae1;
 
        Maintenance_Contract_Asset__c contractasset = new Maintenance_Contract_Asset__c();
        contractasset.Asset__c = ast.Id;
        contractasset.Maintenance_Contract__c = contract.Id;
        contractasset.Estimate_List_Price_All_Manual__c = 1000;
        contractasset.Maintenance_Contract_Asset_Estimate__c = mcae1.id;
        contractasset.LastMContract__c = contract2.Id;
        insert contractasset;
 
 
        Account_Service_Of_Target__c asot=new Account_Service_Of_Target__c();
        asot.OCSM_Period_half__c='1H';
        asot.OCSM_Period__c = 'FY2023';
        asot.Account_HP__c=hospital.Id;
        insert asot;
 
    }
 
 
    static testMethod void testMethod1() {
        system.Test.startTest();
        List<Account> accs =[select Id,(select Id,CurrentContract_F__r.IF_Taget_MC__c,CurrentContract__c,CurrentContract__r.Contract_Conclusion_Date__c,CurrentContract__r.New_Contract_TypeF_Text__c,Product2.ServiceCategory__c,Product2.Category3__c,Product2.Category4__c from Asset_Hospital__r where IF_StopParts_production__c != '1' ) from Account limit 10];
            for (Account acc : accs) {
                system.debug('医院相关数据'+acc);
            }
        database.executeBatch(new EquipmentRenewMoleculeBatch(),200);
        system.Test.stopTest();
    }
 
    static testMethod void testMethod2() {
        system.Test.startTest();
        List<Account_Service_Of_Target__c> asotl=[select Id,Account_HP__c,OCSM_Period_half__c from Account_Service_Of_Target__c];
        delete asotl;
        List<Account_Service_Of_Target__c> asot2=[select Id,Account_HP__c,OCSM_Period_half__c from Account_Service_Of_Target__c];
        System.debug('this is test 2-----------------------------');
        if(asot2==null){
            System.debug('this is test 2 value ==null');
        }
        System.debug('value is'+asot2);
        database.executeBatch(new EquipmentRenewMoleculeBatch(),200);
        system.Test.stopTest();
 
    }
}