高章伟
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
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
@isTest
private class NFM202triggerTest {
    static final String RC_BYOUIN = '病院';
    static final String RC_HANBAOITEN = '販売店';
    static final String RC_KEIYAKU = '契約';
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    
    @isTest static void test_method_one() {
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        // Implement test code
        RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1];
        Account hospital = new Account(Name = 'テスト病院');
        hospital.RecordTypeId = recByoin.id;
        hospital.Site = 'テスト病院部門';
        hospital.Alias_Name2__c = 'テスト病院別名';
        insert hospital;
 
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Hospital__c = hospital.id;
        sellerA.Ban_On_Use_Date__c = Date.today().addDays(20);
        insert sellerA;
 
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        insert product;
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
 
        RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1];
        Account contractA = new Account(Name = '*');
        contractA.RecordTypeId = recKeiyaku.id;
        contractA.Agent_Ref__c = sellerA.id;
        contractA.ParentId = sellerA.id;
        contractA.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        contractA.Contract_Decide_End_Date__c = Date.today().addDays(20);
        //contractA.Contract_Quote_Decide_Flag_checkbox__c = true;
        contractA.ET_SP_Dealer__c = true;
 
        insert contractA;
        System.Test.startTest();
        Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today().addDays(60));
        opp.Trade__c = '内貿';
        //opp.CurrencyIsoCode = CurrencyIso;
        opp.Sales_Root__c = '販売店';
        opp.StageName = '引合';
        opp.Fixed_Check__c = false;
        opp.owner_not_automatically_update__c = true;
        //opp.Pricebook2Id = pricebook.id;
        opp.Purchase_Type__c = '一般引合';
        opp.Promise_Class__c = '内貿';
        opp.Fund_Basis__c = '政府資金';
        opp.AccountId = contractA.id;
        opp.Hospital__c = contractA.id;
        opp.Agency1__c = sellerA.id;
        opp.Wholesale_Price__c = 9000;
        opp.Opportunity_stage__c = '还没申请预算';
        opp.Close_Forecasted_Date__c = Date.today().addDays(50);
        opp.Special_Opp_lanhai__c = false;
        opp.Competitor__c = 'A';
        opp.If_Authorizing__c = false;
        opp.Contract_Authorize__c = false;
        opp.Special_Opp_lanhai__c = true;
        opp.Estimation_Id__c = 'a1';
        insert opp;
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '111';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        opp.If_Authorizing__c = true;
        //opp.Competitor__c = 'A';
        opp.Contract_Authorize__c = true;
        update opp;
        String CRON_EXP = '0 0 0 3 9 ? 2032';
        // system.schedule('AgencyIntelligenceExpireTest', CRON_EXP, new AgencyIntelligenceExpireSchedule());
        System.Test.StopTest();
    }
    
    //@isTest static void test_method_two() {
    //    Opportunity opp = new Opportunity(
 //           Opportunity_No__c = '1234567',
 //           Name='Opp',
 //           StageName='引合',
 //           CloseDate=Date.today(),
 //           CurrencyIsoCode = 'CNY'
 //       );
 //       insert opp;
 //       //opp.old_Oppo_No__c = '123456789';
 //       //opp.SeparateBillMark__c = '1';
 //       Opportunity opp1 = new Opportunity(
 //           Name='Opp',
 //           StageName='引合',
 //           CloseDate=Date.today(),
 //           CurrencyIsoCode = 'CNY',
 //           old_Oppo_No__c = '1234567',
 //           SeparateBillMark__c = '1'
 //       );
 //       insert opp1;
    //}
    
    @isTest static void test_method_two() {
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        // Implement test code
        RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1];
        Account hospital = new Account(Name = 'テスト病院');
        hospital.RecordTypeId = recByoin.id;
        hospital.Site = 'テスト病院部門';
        hospital.Alias_Name2__c = 'テスト病院別名';
        insert hospital;
 
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Hospital__c = hospital.id;
        sellerA.Ban_On_Use_Date__c = Date.today().addDays(20);
        insert sellerA;
 
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        insert product;
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
 
        RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1];
        Account contractA = new Account(Name = '*');
        contractA.RecordTypeId = recKeiyaku.id;
        contractA.Agent_Ref__c = sellerA.id;
        contractA.ParentId = sellerA.id;
        contractA.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        contractA.Contract_Decide_End_Date__c = Date.today().addDays(20);
        //contractA.Contract_Quote_Decide_Flag_checkbox__c = true;
        contractA.ET_SP_Dealer__c = true;
 
        insert contractA;
        System.Test.startTest();
        Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today().addDays(60));
        opp.Trade__c = '内貿';
        //opp.CurrencyIsoCode = CurrencyIso;
        opp.Sales_Root__c = '販売店';
        opp.StageName = '引合';
        opp.Fixed_Check__c = false;
        opp.owner_not_automatically_update__c = true;
        //opp.Pricebook2Id = pricebook.id;
        opp.Purchase_Type__c = '一般引合';
        opp.Promise_Class__c = '内貿';
        opp.Fund_Basis__c = '政府資金';
        opp.AccountId = contractA.id;
        opp.Hospital__c = contractA.id;
        opp.Agency1__c = sellerA.id;
        opp.Wholesale_Price__c = 9000;
        opp.Opportunity_stage__c = '还没申请预算';
        opp.Close_Forecasted_Date__c = Date.today().addDays(50);
        opp.Special_Opp_lanhai__c = false;
        opp.Competitor__c = 'A';
        opp.If_Authorizing__c = false;
        opp.Contract_Authorize__c = false;
        opp.Special_Opp_lanhai__c = true;
        insert opp;
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '111';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
 
         //見積データ作成
         Quote quote = new Quote( Name = 'テスト見積');
         quote.OpportunityId = opp.Id;
        //  quote.Pricebook2Id = entry.id;
         quote.Quote_No__c = 'quoteNo';
 
         quote.Unit_Price__c = true;
         quote.Offer_Amount__c = true;
         quote.TOTAL__c = true;
         quote.Discount__c = true;
         quote.Pricing__c = true;
         quote.Preferential_Trading_Price__c = true;
         quote.Contract__c = true;
         quote.Quote_Comment__c = 'true';
         insert quote;
 
        opp.If_Authorizing__c = true;
        //opp.Competitor__c = 'A';
        opp.Contract_Authorize__c = true;
        opp.Estimation_Id__c = quote.id;
        update opp;
        PromotionHead__c ph = new PromotionHead__c();
        ph.SpoId__c = 'SPOXX';
        ph.name = 'SPOXX';
        //写死促销方案id
        // ph.recordTypeId = '01210000000aLmw';
        insert ph;
 
        PromotionSales__c ps =new PromotionSales__c();
        ps.PromotionHead__c = ph.id;
        ps.Category__c = '促销政策';
        ps.name ='xxx';
 
        insert ps;
 
 
        PromotionSalesProducts__c psp = new PromotionSalesProducts__c();
        psp.QuantityId__c = quote.id;
        // psp.PromotionSales__r.PromotionHead__r.SpoId__c
        // psp.PromotionSales__r.Category__c
        psp.Asset_Model_No__c = 'N/A';
        psp.Quantity__c = 2;
        psp.AgencyUnitPrice__c =12.0;
        psp.UseCount__c =2;
 
        insert psp;
 
        PromotionSalesProducts__c psp3 = new PromotionSalesProducts__c();
        psp3.QuantityId__c = quote.id;
        // psp.PromotionSales__r.PromotionHead__r.SpoId__c
        // psp.PromotionSales__r.Category__c
        psp3.Asset_Model_No__c = 'A321:啊乌拉乌拉乌拉哇哇';
        psp3.Quantity__c = 2;
        psp3.AgencyUnitPrice__c =12.0;
        psp3.UseCount__c =2;
 
        insert psp3;
 
        NFM202Controller.testI();
    }
    
}