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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
@isTest 
public class QuoteTrialControllerTest {
    private static Product2 product = null;
    private static Pricebook2 pricebook = null;
 
 
    private static  Opportunity opprtunity = null;
 
    static final String RC_HOSPITAL = '病院';
    static final String RC_OPP = '引合';
    static final String RC_SENRYAKUKASHITSUBUNRUI = '戦略科室分類 消化科';
    static final String RC_BYOUIN = '病院';
    static final String RC_SHINRYOUKA = '診療科 その他';
    static final String RC_HANBAOITEN = '販売店';
    static final String RC_KEIYAKU = '契約';
 
    static {
        product = new Product2( Name = 'テスト商品');
        insert product;
        system.debug('##product.Id=[' + product.Id + ']' );
 
        pricebook = ControllerUtil.getStandardPricebook();
        system.debug('##pricebook.Id=[' + pricebook.Id + ']' );
    }
 
    private static PricebookEntry buildPB( String input) {
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product.Id);
 
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = input;
        insert entry;
        return entry;
    }
 
    public static Opportunity buildOppInstance( String inputTrade, String CurrencyIsoCode) {
        Opportunity target = new Opportunity( Name = 'aiueo', StageName = 'contact', CloseDate = Date.today());
        target.Trade__c = inputTrade;
        target.owner_not_automatically_update__c = true;
        target.CurrencyIsoCode = CurrencyIsoCode;
        target.Wholesale_Price__c = 9000;
        return target;
    }
 
    private static QuoteLineItem insertQuoteLineItem( Quote input, Pricebookentry entry) {
        QuoteLineItem target = new QuoteLineItem();
        target.Name__c = 'テスト商品';
        target.QuoteId = input.Id;
        target.Quantity = 1;
        target.Cost_Subtotal__c = 0;
        target.Cost__c = 200;
        //        target.TotalPrice = 100;
        target.UnitPrice = 10;
        target.PricebookEntryId = entry.Id;
        insert target;
        return target;
    }
 
 
    private static String quoteNo = 'textQutote01';
    public static String trade = '内貿';
    public static String CurrencyIso = 'CNY';
 
    private static Boolean isUnitPrice = true;
    private static Boolean isOfferAmount = true;
    private static Boolean isTotalPrice = true;
    private static Boolean isDiscountRate = true;
    private static Boolean isDiscountAmount = true;
    private static Boolean isTradingPrice = true;
    private static Boolean isContractDetail = true;
 
    private static Date offerExpireDate = Date.today();
    private static String clientName = 'test client';
    private static String offerComment = 'test comment';
    private static Date offerPrintDate = Date.today();
    private static String agentName = 'test agent name';
 
 
    public class GeDatass {
          public  String Id;//产品编码(产品代码)
          public String JxsType;
          public String Categoryc;
          public String GuaranteeDiscountcInput;
          public String NormalDiscountcInput;
          public String PromotionNocEqual;
          public String typess;
          public String PromotionNoc;
          public String Name;
          public String itemIdStr;
          public String IsTempItems;
          public String itemCounts;
          public String ParamIdStr;
          public String GuaranteeDiscountc;
          public String NormalDiscountc;
          public String Descriptionc;
          public Boolean ifContainNodc;
          public Boolean ifFixc;
          public Double PriceCNYc;
          public Double Total;
          public Double HeTongTotal;
          public Boolean ifNecessaryc;
          public Decimal maxCounts;
          public Double ListPriceTotalc;
          public Double sumNod;
          public String CompareId;
          public String Trade;
          public String sumNoDiscountTotal;
          public Double GuaranteeDiscountHMoneyc;
          public Double NormalDiscountHMoneyc;
      }
 
      public class Discount {
          public  String Id;//产品编码(产品代码)
          public String AssetModelNoc;
          public String Namec;
          public Integer Quantity;
          public String IGuranteeTypecd;
          public String PromotionNoc;
          public String Name;
          public Double ListPrice;
          public Double AgencyUnitPricec;
          public Double AgencySubtotalc;
          public Double NoDiscountTotalc;
          public String ParamIdStr;
          public String TypeName;
          public String UUID;
          public String ismatch;
          public String PromotionId;
          public Integer UseCountc;
          public String Product2c;
          public Double ServicePricec;
          public Boolean ifFixc;
          public Boolean ifNecessaryc;
          public String CompareId;
          public Double DiscountcInput;
          public String Categoryc;
          public String NormalDiscountcInput;
          public String GuaranteeDiscountcInput;
          public Boolean multiYearWarrantyc;
      }
 
 
    static testMethod void TestInit01() {
        String userId = UserInfo.getUserId();
        User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
        u1.Quote_Correct__c = false;
        u1.Quote_Special_Operation__c = true;
        u1.Cost_Referable__c = true;
        update u1;
 
        // PricebookEntry
        PricebookEntry entryUSD = buildPB( 'USD');
        PricebookEntry entryCNY = buildPB( 'CNY');
 
        // 引合作成
        Opportunity opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.owner_not_automatically_update__c = true;
        opp.Sales_Root__c = 'AAA';
        opp.Pricebook2Id = pricebook.id;
        insert opp;
 
        //見積データ作成
        Quote quote = new Quote( Name = 'テスト見積');
        quote.OpportunityId = opp.Id;
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;
 
        quote.Unit_Price__c = isUnitPrice;
        quote.Offer_Amount__c = isOfferAmount;
        quote.TOTAL__c = isTotalPrice;
        quote.Discount__c = isDiscountRate;
        quote.Pricing__c = isDiscountAmount;
        quote.Preferential_Trading_Price__c = isTradingPrice;
        quote.Contract__c = isContractDetail;
        quote.Quote_Comment__c = offerComment;
        insert quote;
        quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
        System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);
 
        // 見積品目作成
        QuoteLineItem item01 = insertQuoteLineItem( quote, entryCNY);
        QuoteLineItem item02 = insertQuoteLineItem( quote, entryCNY);
 
        //创建促销方案 / 记录类型=促销方案
        PromotionHead__c head1 = new PromotionHead__c();
        head1.Name = '202';
        head1.PromotionNo__c = '202';
        head1.Category__c = '固定价格';
        head1.if_Contain_Nod__c = true;
        head1.RecordTypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'PromotionHead__c' and DeveloperName = 'Promotion'].id;
        head1.DateFrom__c = Date.today().addDays(-1);
        head1.DateTo__c = Date.today().addDays(1);
        head1.Description__c = '(202)153P-GI-001-05 奥辉(AXEON)-M1层以下 胃肠(CF-LV1I)标套(MX192适用)';
        head1.Memo__c = 'CV-V1(A)/GIF-LV1/CF-LV1I/MX192彩色液晶显示器/TC-A4/MU-1/MB-155';
        head1.Price_CNY__c = 254000.00;
        head1.Price_USD__c = 20000.00;
        insert head1;
 
 
        //创建促销方案 / 记录类型=一般产品
        PromotionHead__c head2 = new PromotionHead__c();
        head2.Name = '203';
        head2.PromotionNo__c = '203';
        head2.Category__c = '固定价格';
        head2.if_Contain_Nod__c = true;
        head2.RecordTypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'PromotionHead__c' and DeveloperName = 'NormalProduct'].id;
        head2.DateFrom__c = Date.today().addDays(-1);
        head2.DateTo__c = Date.today().addDays(1);
        head2.Description__c = '(202)153P-GI-001-05 奥辉(AXEON)-M1层以下213-LV1I)标套(MX192适用)';
        head2.Memo__c = 'CV-V1(A)/GIF-LV1/CF-LV1I/MX192彩色液晶显示器/TC-A4/前21 -155';
        head2.Price_CNY__c = 254000.00;
        head2.Price_USD__c = 20000.00;
        insert head2;
 
        //创建促销方案 / 记录类型=特约固定
        PromotionHead__c head3 = new PromotionHead__c();
        head3.Name = '203';
        head3.PromotionNo__c = '203';
        head3.Category__c = '固定价格';
        head3.if_Contain_Nod__c = true;
        head3.RecordTypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'PromotionHead__c' and DeveloperName = 'Authorizer'].id;
        head3.DateFrom__c = Date.today().addDays(-1);
        head3.DateTo__c = Date.today().addDays(1);
        head3.Description__c = '(202)153P-GI-001-05 奥辉(AXEON)-M1层以下213-LV1I)标套(MX192适用)';
        head3.Memo__c = 'CV-V1(A)/GIF-LV1/CF-LV1I/MX192彩色液晶显示器/TC-A4/前21 -155';
        head3.Price_CNY__c = 254000.00;
        head3.Price_USD__c = 20000.00;
        insert head3;
 
 
        //创建促销方案产品
        PromotionProduct__c pro1 = new PromotionProduct__c();
        pro1.Name = 'TEST1';
        pro1.PromotionHead__c = head1.Id;
        // pro1.Product__c = product.Id;
        pro1.Quantity__c = 2;
        insert pro1;
 
        //创建 测试_报价促销方案  
        PromotionSales__c sales1 = new PromotionSales__c();
        sales1.Name = 'test1';
        sales1.PromotionNo__c  = '203';
        sales1.if_Contain_Nod__c = true;
        // sales1.ParamIdStr__c = quote.Id;
        insert sales1;
 
        //创建 测试_报价促销产品
        PromotionSalesProducts__c salesPro = new PromotionSalesProducts__c();
        // salesPro.ParamIdStr__c = quote.Id;
        insert salesPro;
 
        //保存所选方案,价格政策和折扣政策,JsonStr 是要保存的数据的转成的json字符串,ParamIdStr 保存方案表的id
        List<GeDatass> testList = new List<GeDatass>();
        GeDatass data = new GeDatass();
        data.Id      = head1.Id;
        data.JxsType = 'testType';
        data.Categoryc = 'testcategory';
        data.GuaranteeDiscountcInput = 'testinput';
        data.NormalDiscountcInput = 'testnormal';
        data.PromotionNocEqual ='testequal';
        data.typess = 'testtypess';
        data.PromotionNoc = 'testpromotion';
        data.Name = '202';
        data.itemIdStr = 'test12';
        data.IsTempItems = 'testtemp';
        data.itemCounts = 'testitemcounts';
        data.ParamIdStr = quote.Id;
        data.GuaranteeDiscountc = 'testguaranteediscount';
        data.NormalDiscountc = 'testnormal';
        data.Descriptionc = 'testdesc';
        data.ifContainNodc = true;
        data.ifFixc = true;
        data.PriceCNYc = 12.21;
        data.Total     = 22.22;
        data.HeTongTotal = 222.22;
        testList.add(data);
        String jsonStr = JSON.serialize(testList);
 
 
        //保存所选产品和未选产品,JsonStr 是要保存的数据的转成的json字符串,ParamIdStrs 保存产品表的id
        List<Discount> disList = new List<Discount>();
        Discount dis = new Discount();
        dis.Id = 'a4S1m0000004r4AEAQ';
        dis.AssetModelNoc = 'testno';
        dis.Namec = 'testname';
        dis.Quantity = 12;
        dis.IGuranteeTypecd = 'testtype';
        dis.PromotionNoc = 'testpromotion';
        dis.Name = 'testname';
        dis.ListPrice = 12.22;
        dis.AgencyUnitPricec = 14.44;
        dis.AgencySubtotalc = 23.32;
        dis.NoDiscountTotalc = 99.32;
        dis.ParamIdStr = quote.Id;
        dis.TypeName = 'testtypename';
        dis.UUID = '12achuvqwh';
        dis.ismatch = 'test';
        dis.PromotionId = head1.Id;
        dis.multiYearWarrantyc = true;
        disList.add(dis);
        String jsonStr1 = JSON.serialize(disList);
        //几个政策Id集合
        List<String> jiaGe=new List<String>();
        jiaGe.add('321654');
        jiaGe.add('234234');
        jiaGe.add('231636');
        //1.获取报价数据
        QuoteTrialController.GetQuoteData(quote.Id);
        //2.获取待选择产品
        QuoteTrialController.GetPromotionDefalut(quote.Id);
        //3.获取促销方案
        QuoteTrialController.GetPromotionPromotionSearch(1,1,'','','');
        //4.获取固定资产
        QuoteTrialController.GetNormalProductSearch(1,1,'','','');
        //5.获取特约折扣
        QuoteTrialController.GetAuthorizerSearch(1,1,'','','','');
        //6.产品对应的Item
        QuoteTrialController.GetSearchProductById(head1.Id);
        //7.获取所有PromotionSales__c表中的数据
        QuoteTrialController.selectAllDataProduct(quote.Id);
        //8.获取所有PromotionSalesProducts__c表中的数据
        QuoteTrialController.selectAllDataDiscount(quote.Id);
        //9.保存所选方案,价格政策和折扣政策,JsonStr 是要保存的数据的转成的json字符串,ParamIdStr 保存方案表的id
        Double ContractPrice=12.12;
        Double DealerFinalPriceFc=100000.00;
        Double Agent1Agent2Pricec=10000.0;
        Double Agent1Agent2Pricec1=null;
        QuoteTrialController.saveAllDataProduct(jsonStr,(String)quote.Id,jsonStr1,(String)item01.QuoteId,'販売店',ContractPrice,(String)quote.OpportunityId,DealerFinalPriceFc,Agent1Agent2Pricec);
        QuoteTrialController.saveAllDataProduct(jsonStr,(String)quote.Id,jsonStr1,(String)item01.QuoteId,'販売店',ContractPrice,(String)quote.OpportunityId,DealerFinalPriceFc,Agent1Agent2Pricec1);
        QuoteTrialController.saveAllDataProduct(jsonStr,(String)quote.Id,jsonStr1,(String)item01.QuoteId,'OCM直接販売',ContractPrice,(String)quote.OpportunityId,DealerFinalPriceFc,Agent1Agent2Pricec);
        QuoteTrialController.selectUniqueKey((String)quote.Id);
        //10.判断所处数据是否为空
        QuoteTrialController.GetParamToId('123');
        QuoteTrialController.GetParamToId('');
        //11.测试清空表中数据,非正式环境
        QuoteTrialController.deleteAlltable();
        //12.保存所选产品和未选产品,JsonStr是要保存的数据的转成的json字符串,ParamIdStrs 保存产品表的id
        // QuoteTrialController.saveAllDataDiscount(jsonStr1,quote.Id);
        //13.测试清空表中数据,非正式环境
        QuoteTrialController.deleteAllDiscounttable();
        //14.获取经销商姓名
        QuoteTrialController.GetAgencyRName();
        //15.根据保存的Id查询 Header 表的数据
        QuoteTrialController.selectUpdateFiexedpriceData(jiaGe);
        QuoteTrialController.selectUpdateQuoteLineItemData(jiaGe);
    }
 
}