高章伟
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
@isTest
private class SpecialPriceControllerTest {
    static Account myAccount2;          //经销商
    static Account contract;            //经销商合同
    static Product2__c pro1;            //产品检索1
    static Product2__c pro2;            //产品检索2
    static Product2__c pro3;            //产品检索3
    static Product2__c pro4;            //产品检索4
    static Product2__c pro5;            //产品检索5
    static Dealer_Product__c dp1;       //经销商产品1
    static Dealer_Product__c dp2;       //经销商产品2
 
    static void initData(){
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount2;
 
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo1.size() == 0) {
            return;
        }
        contract = new Account(Name ='contractName',ParentId = myAccount2.id,Agent_Ref__c =myAccount2.id, Contract_Department_Class__c = 'ET',ET_SP_Dealer__c = true,Contract_Decide_Start_Date__c=Date.today().addDays(-2),
        Contract_Decide_End_Date__c = Date.today().addDays(2),Dealer_discount__c = 0.8,RecordTypeId = rectCo1[0].Id);
        insert contract;
        Product2 prod01 = new Product2(Name='Test01',
                            ProductCode='Test01',
                            Asset_Model_No__c = 'Test01',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'CDS',
                            Category4__c = 'OER',
                            Category5__c = '其它',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test001',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
 
        Product2 prod02 = new Product2(Name='Test02',
                            ProductCode='Test02',
                            Asset_Model_No__c = 'Test02',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'ENT',
                            Category4__c = 'Celon',
                            Category5__c = 'Celon',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test002',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
 
                            );
 
        Product2 prod03 = new Product2(Name='Test03',
                            ProductCode='Test03',
                            Asset_Model_No__c = 'Test03',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'US',
                            Category4__c = 'ALOKA',
                            Category5__c = '体外超声',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
 
        Product2 prod04 = new Product2(Name='Test04',
            ProductCode='Test04',Asset_Model_No__c = 'Test04',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'OCS',
                            Category4__c = '附属品',
                            Category5__c = 'OCS',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
        Product2 prod05 = new Product2(Name='Test05',
                            ProductCode='Test05',
                            Asset_Model_No__c = 'Test05',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = '光源',
                            Category4__c = 'CLV',
                            Category5__c = 'S45',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1),
                            ENG_DeaerProFlag__c = true 
                            );
        insert new Product2[] {prod01,prod02,prod03, prod04, prod05};
        pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
        pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
        pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
        pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
        insert new Product2__c[] {pro1,pro2,pro3,pro4, pro5};
 
        dp1 = new Dealer_Product__c();
        dp1.Dealer_Product2__c = pro1.Id;
        dp1.Dealer_Contact__c = contract.Id;
        dp1.Special_Discount__c =60;
 
        dp2 = new Dealer_Product__c();
        dp2.Dealer_Product2__c = pro2.Id;
        dp2.Dealer_Contact__c = contract.Id;
        dp2.Special_Campaign_Price__c = 200;
        insert new Dealer_Product__c[] {dp1,dp2};
 
    }
 
    @isTest
    static void init_test()
    {
        initData();
 
        PageReference page = new PageReference('/apex/SpecialPrice?userid='+contract.id);
        System.Test.setCurrentPage(page);
        SpecialPriceController conTest = new SpecialPriceController();
        conTest.init();
        conTest.keyword = 'Test';
        conTest.searchProduct();
        // conTest.category1 = 'GI';
        // conTest.category2 = '耗材';
        // conTest.category3 = '其他';
        // conTest.category4 = '其他';
        // conTest.category5 = '其他';
        conTest.SpecialDiscount='50';
        conTest.geCategory();
        conTest.showcategory2();
        conTest.showcategory3();
        conTest.showcategory4();
        conTest.showcategory5();
        conTest.searchProduct();
        // conTest.productInfoListview.sort();
        conTest.productInfoListview[0].check = true;
        conTest.productInfoListview[0].dealerPro.Special_discount__c=120;    
        conTest.searchProduct();
        conTest.save();
        conTest.productInfoListview[0].check = true;
        conTest.productInfoListview[0].dealerPro.Special_discount__c=80; 
        conTest.refreshPageSize();   
        conTest.save();
        conTest.productInfoListview[0].check = true;
        conTest.productInfoListview[0].dealerPro.Special_discount__c=0;    
        conTest.save();
        conTest.productInfoListview[0].check = false;
        conTest.productInfoListview[0].dealerPro.Special_discount__c=null;    
        conTest.save();
        conTest.refreshPageSize();
 
         //创建一个特价产品申请
        DiscountProductApplication__c dpc = new DiscountProductApplication__c();
        Id ProductTypeId = [select Id from RecordType where IsActive = true and DeveloperName = 'ProductDiscount'].Id;
        dpc.RecordTypeId = ProductTypeId;
        dpc.Dealer_Contact__c = contract.Id;
        dpc.ApplicationStatus__c = '草案中';
        dpc.RecordTypeId = ProductTypeId;
        insert dpc;
        DiscountProductApplicationDetail__c dpadc1 = new DiscountProductApplicationDetail__c();
        dpadc1.DiscountProductApplication__c = dpc.Id;                        
        dpadc1.ProductDiscount__c = 12345;
        dpadc1.Product2__c = pro1.Id;
        DiscountProductApplicationDetail__c dpadc2 = new DiscountProductApplicationDetail__c();
        dpadc2.DiscountProductApplication__c = dpc.Id;                        
        dpadc2.ProductDiscount__c = 8888;
        dpadc2.Product2__c = pro2.Id;
        insert new DiscountProductApplicationDetail__c[] {dpadc1,dpadc2};
 
        page = new PageReference('/apex/SpecialPrice?id='+dpc.Id+'&userid='+contract.id);
        System.Test.setCurrentPage(page);
        conTest = new SpecialPriceController();
        conTest.init();
    }
 
 
    @isTest
    static void selectfill()
    {
        initData();
        PageReference page = new PageReference('/apex/SpecialPrice?userid='+contract.id);
        System.Test.setCurrentPage(page);
        SpecialPriceController conTest = new SpecialPriceController();
        conTest.init();
        conTest.keyword = 'Test01';
        conTest.searchProduct();
        conTest.pagecount=10;
        conTest.currentpage=1;
        conTest.moveToNext();
        conTest.currentpage=2;
        conTest.moveToPrevious();
        conTest.moveToLast();
        conTest.category1 = 'GI';
        conTest.category2 = '耗材';
        conTest.category3 = '其他';
        conTest.category4 = '其他';
        conTest.category5 = '其他';
        conTest.showcategory2();
        conTest.refreshPageSize();
        conTest.searchAllProduct();
    }
}