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
@isTest
public class DealerConsumableManageBatch4Test {
 
    @isTest
    static void Test2(){
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass(ContactTriggerHandler.class.getName());
        Oly_TriggerHandler.bypass(AgencyHospitalHandler.class.getName());
        StaticParameter.EscapeOppandStaTrigger = true;
 
        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;
        }
        //签收单最终用户记录类型
        List < RecordType > recordTypeList = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '戦略科室分類 呼吸科'
        ];
        if (recordTypeList.size() == 0) {
            return;
        }
        // 省
        Address_Level__c al = new Address_Level__c();
        al.Name = '广东省';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        upsert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '广东省';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        upsert al2;
        // 产品
        Product2 prd = new Product2();
        prd.ProductCode_Ext__c = 'N2656630';
        prd.ProductCode = 'N2656630';
        prd.Name = 'N2656630';
        prd.Manual_Entry__c = false;
        prd.ENG_New__c = 'ENG2';
        upsert prd;
        //客户医院
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name = 'NFM008TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        section.State_Master__c = al.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name = '*';
        depart.Department_Name__c = 'NFM008TestDepart';
        depart.ParentId = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c = company.Id;
        upsert depart;
        //签收单最终用户记录类型
        Account recordType = new Account();
        recordType.RecordTypeId = recordTypeList[0].Id;
        recordType.Name = '*';
        recordType.Department_Class_Label__c = '消化科';
        recordType.ParentId = company.Id;
        recordType.Hospital_Department_Class__c = company.Id;
        upsert recordType;
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name='販売店' limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Hospital__c = company.Id;
        sellerA.ParentId = depart.Id;
        sellerA.Tax_Practice_No__c = '001';
        sellerA.Sales_Shop_Class__c = '特約販売店(区域)';
        sellerA.Business_Authorization_No__c = '001';
        sellerA.Tax_Practice_Expiration_Date__c =   Date.ValueOf('2023-12-10').addDays(20);
        sellerA.Business_Paper_Expiration_Date__c =  Date.ValueOf('2023-12-10').addDays(20);
        insert sellerA;
        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'
            and DeveloperName = 'Opportunity'
        ];
        //询价
        Opportunity opp = new Opportunity(Name = 'testOpp1', StageName = '引合', CloseDate =  Date.ValueOf('2024-05-10'), AccountId = depart.Id, Sales_Root__c = '販売店', Competitor__c = 'A', Click_Close_Date__c = null, RecordType = rectOpp);
        opp.Opportunity_Category__c = 'ET';
        opp.Agency1__c = sellerA.Id;
        opp.SAP_Province__c = '广东省';
        opp.Opp_order_Type__c='ET';
        upsert opp;
        Statu_Achievements__c Sac = new Statu_Achievements__c(name = 'zhucan_one', Opportunity__c = opp.id, DeliveryDate__c = Date.ValueOf('2023-12-10'), ContractNO__c = 'ContractNO1', ContractAmount__c = 100);
        
        insert Sac;
        
        String keys1= sellerA.Id+'-ET-FY2024-广东';
        Dealer_ConsumableManage__c dc1 = new Dealer_ConsumableManage__c();
        dc1.TMS_Key__c = keys1;
        dc1.ET_ENG__c = 'ET';
        dc1.FY__c = 'FY2024';
        dc1.Dealer_Name__c = sellerA.Id;
        dc1.FY_S_1__c = 50;
        dc1.FY_S_2__c = 50;
        dc1.FY_S_3__c = 50;
        dc1.FY_S_4__c = 50;
        dc1.FY_S_5__c = 50;
        dc1.FY_S_6__c = 50;
        dc1.FY_S_7__c = 50;
        dc1.FY_S_8__c = 50;
        dc1.FY_S_9__c = 50;
        dc1.FY_S_10__c = 50;
        dc1.FY_S_11__c = 50;
        dc1.FY_S_12__c = 50;
        insert dc1;
        Test.StartTest();
        Database.executeBatch( new DealerConsumableManageBatch4( Date.ValueOf('2023-12-10').addDays(-70), Date.ValueOf('2023-12-10').addDays(50),false),10);        
        Database.executeBatch( new DealerConsumableManageBatch4( Date.ValueOf('2023-12-10').addDays(-70), Date.ValueOf('2023-12-10').addDays(50),false),10);
        Test.stopTest();
    }
}