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
//public without sharing class SearchProductController {
public virtual class SearchProductController {
    public List<ProductLine> cl {get;set;}
    public Boolean getHascl() {
        Boolean rtn = true;
        if (cl != null && cl.size() > 0) {
            rtn = false;
        }
        return rtn;
    }
 
    public String searchMode;                         // 検索モード
    public String trade {get;set;}                    // hidden項目からもらった CNY か USD の文字列
    public String lineNo {get;set;}                   // 親画面の選択した行
    public String val {get;set;}                      // 親画面のからの検索文字列
    public String celon {get;set;}                    // 親画面のからの検索文字列 Celon询价增加 2022-04-24 ssm
    public String maxLen {get;set;}                   //20231103 李文涛 lightning升级
    public String SearchName {get;set;}               // 検索文字列
    //DB202306255146  you start
    public String NameCode {get;set;}
    public String Product2Ids {get;set;}
    //DB202306255146  you end
    public SearchProductController(ApexPages.StandardController controller){
        this();
    }
    public SearchProductController() {
//        this.trade = Apexpages.currentPage().getParameters().get('trade');
        this.lineNo = Apexpages.currentPage().getParameters().get('lineno');
        this.val = Apexpages.currentPage().getParameters().get('val');
        this.celon = Apexpages.currentPage().getParameters().get('celon');
 
        if (val!=null && val!=''){
            SearchName = val;
            val = null;
        }
 
        cl = new List<ProductLine>();
    }
    //DB202306255146  you start
    public PageReference SendEmailQuoteIrai() {
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
        List<String>  MailsList = new List<String>();
        MailsList.add('youchang@prec-tech.com');
        //MailsList.add('shuo_wang@olympus.com.cn');
        MailsList.add(System.Label.CN_MEBG_BusinessSupport);
        String title = NameCode+'产品无价格报价委托失败';
        String body = '您好!<br/>';
        body += '由于产品' + NameCode + '没有报价/成本 报价委托未导入,请确认.<br/>'; 
        body += '产品链接:<br/>';
        body += '<a href="' + System.Label.Environment_Url + Product2Ids + '">'
                    + System.Label.Environment_Url+ Product2Ids +'</a><br/>'; 
        body += '谢谢!<br/>';
 
        mail.setToAddresses(MailsList);
        mail.setReplyTo(UserInfo.getUserEmail());
        mail.setSubject(title);
        mail.setHtmlBody(body);
        mail.setCharset('UTF-8');
 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        return null;
 
    }    
    //DB202306255146  you end
    public PageReference serContact(){
 
        String x = '×';
        String searchSql = 'select Id,Product2Id,Product2.Name,Product2.ProductCode,Product2.StorageStatus__c,Product2.OT_CODE_no_link__c, Product2.Alternative_Products__c, '
                        + 'Product2.Foreign_Trade_Cost_US__c, Product2.Foreign_Trade_List_US__c, Product2.Intra_Trade_Cost_RMB__c, Product2.Intra_Trade_List_RMB__c, '
                        + 'Product2.Asset_Model_No__c, Product2.Serial_Lot_No__c, Product2.Sales_Possibility__c, Product2.Estimation_Entry_Possibility__c, '
                        + 'Product2.SFDA_Status__c, Product2.Qty_Unit__c, Product2.BSSCategory__c, Product2.Asset_loaner_category__c, Product2.Packing_list_manual__c '
                        // 多年保修 start
                        + ' ,Product2.Extend_new_product_gurantee_MD__c , Product2.Extend_new_product_gurantee__c , Product2.Entend_gurantee_period_all__c , '
                        + '  Product2.Intra_Trade_Gurantee_RMB__c  '
                        //外贸多年保 取产品主数据上的外贸金额及报价 精琢技术 wql 2021/01/04 start
                        + ',Product2.Intra_Trade_Foreign_RMB__c,Product2.NoDiscount_Foreign__c,Product2.Repair_Contract_USD__c '
                        //外贸多年保 取产品主数据上的外贸金额及报价 精琢技术 wql 2021/01/04 end
                        //+ ' , Product2.If_Consumable__c '
                        //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 start 阿西赛多 2020/12/29 start 
                        + ' , Product2.Intra_Trade_Service_RMB__c,Product2.CanNotCancelledGurantee__c,Product2.Is_DangerousChemicals__c '
                        //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 end 阿西赛多 2020/12/29 end
                        + ' , Product2.GuranteeType__c , product2.VenderName__c , product2.Maintenance_Price_Year__c '
                        // 多年保修 end
                        // 20221020 ljh SWAG-CJ98AJ start
                        + ' , Product2.suitDepartment__c '
                        // 20221020 ljh SWAG-CJ98AJ end
                        //SFDC停止预警(预计消耗到期日) lt 20210929 add start
                        + ' , Product2.Estimated_ConsumptionDueDate__c '
                        //SFDC停止预警(预计消耗到期日) lt 20210929 add end
 
                        + 'FROM PricebookEntry ';
                        //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 Start
 
                        //注释原来逻辑
        String whereStr = 'Where Product2.Asset_Model_No__c != null And Product2.Manual_Entry__c = false And Product2.Estimation_Entry_Possibility__c !=' + '\'' + x + '\' '
                        // String whereStr = 'Where Product2.Asset_Model_No__c != null And Product2.Manual_Entry__c = false '
                        //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 end
                        + 'AND CurrencyIsoCode =' + '\'' + String.escapeSingleQuotes(trade) + '\' '
                        + 'AND IsActive = true '
                        + 'AND Product2.UnableQuoteReason__c != \'模型/备品\' ';//DB202306255146 you
        String whereSql = '';
        if (searchMode == 'CS') {
            whereSql += 'and Product2.Asset_loaner_category__c = \'为耗材管理\' ';
        }
        if (SearchName != null && SearchName != '') {
            String likename = String.escapeSingleQuotes(SearchName);
            String prdcd = String.escapeSingleQuotes(SearchName);
            if (likename.indexOf('*') >= 0) {
                // TODO escapeは考量してないけど、問題ないと思います。一文字の _ の対応はいらないと思います。
                likename = likename.replace('*', '%');
            } else {
                // default両側あいまい検索
                likename = '%' + likename + '%';
            }
            whereSql += 'and (Product2.Name Like ' + '\'' + likename + '\' or Product2.ProductCode = ' + '\'' + prdcd + '\' or Product2.Asset_Model_No__c Like ' + '\'' + likename + '\') ';
        }
        if (trade=='CNY') {
            //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 Start
 
            //注释原逻辑
 
            // whereSql += 'and Product2.Intra_Trade_List_RMB__c > 0 and Product2.Intra_Trade_Cost_RMB__c > 0';
            whereSql += '';
        } else if(trade=='USD'){
            // whereSql += 'and Product2.Foreign_Trade_List_US__c > 0 and Product2.Foreign_Trade_Cost_US__c > 0';
            whereSql += '';
            //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 end
        } else {
            system.debug(' trade = '+ trade);
        }
 
        // Celon询价修改 2022-04-24 ssm start
        celon = String.isNotBlank(celon) ? celon : null;
        whereSql += ' and Product2.Celon_Product__c = :celon ';
        // Celon询价修改 2022-04-24 ssm end
 
        searchSql = searchSql + whereStr + whereSql;
 
        //20211123 lt update 450 原500
        searchSql += ' order by Product2.Asset_Model_No__c Limit 450';
        System.debug('searchSql::::::' + searchSql);
    System.debug('whereStr::::::' + whereStr);
        System.debug('whereSql::::::' + whereSql);
        // system.debug(searchSql);
 
        // String searchSql1 = 'select Id,Product2Id,Product2.Name,Product2.ProductCode,Product2.StorageStatus__c,Product2.OT_CODE_no_link__c, Product2.Alternative_Products__c, '
        //                 + 'Product2.Foreign_Trade_Cost_US__c, Product2.Foreign_Trade_List_US__c, Product2.Intra_Trade_Cost_RMB__c, Product2.Intra_Trade_List_RMB__c, '
        //                 + 'Product2.Asset_Model_No__c, Product2.Serial_Lot_No__c, Product2.Sales_Possibility__c, Product2.Estimation_Entry_Possibility__c, '
        //                 + 'Product2.SFDA_Status__c, Product2.Qty_Unit__c, Product2.BSSCategory__c, Product2.Asset_loaner_category__c, Product2.Packing_list_manual__c '
        //                 // 多年保修 start
        //                 + ' ,Product2.Extend_new_product_gurantee_MD__c , Product2.Extend_new_product_gurantee__c , Product2.Entend_gurantee_period_all__c , '
        //                 + '  Product2.Intra_Trade_Gurantee_RMB__c  '
        //                 //外贸多年保 取产品主数据上的外贸金额及报价 精琢技术 wql 2021/01/04 start
        //                 + ',Product2.Intra_Trade_Foreign_RMB__c,Product2.NoDiscount_Foreign__c,Product2.Repair_Contract_USD__c '
        //                 //外贸多年保 取产品主数据上的外贸金额及报价 精琢技术 wql 2021/01/04 end
        //                 //+ ' , Product2.If_Consumable__c '
        //                 //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 start 阿西赛多 2020/12/29 start 
        //                 + ' , Product2.Intra_Trade_Service_RMB__c,Product2.CanNotCancelledGurantee__c,Product2.Is_DangerousChemicals__c '
        //                 //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 end 阿西赛多 2020/12/29 end
        //                 + ' , Product2.GuranteeType__c , product2.VenderName__c , product2.Maintenance_Price_Year__c '
        //                 // 多年保修 end
        //                 // 20221020 ljh SWAG-CJ98AJ start
        //                 + ' , Product2.suitDepartment__c '
        //                 // 20221020 ljh SWAG-CJ98AJ end
        //                 //SFDC停止预警(预计消耗到期日) lt 20210929 add start
        //                 + ' , Product2.Estimated_ConsumptionDueDate__c '
        //                 //SFDC停止预警(预计消耗到期日) lt 20210929 add end
 
        //                 + 'FROM PricebookEntry Where Product2.Category5__c = \'虚拟\' ';
        // if (SearchName != null && SearchName != '') {
        //     String likename = String.escapeSingleQuotes(SearchName);
        //     String prdcd = String.escapeSingleQuotes(SearchName);
        //     if (likename.indexOf('*') >= 0) {
        //         // TODO escapeは考量してないけど、問題ないと思います。一文字の _ の対応はいらないと思います。
        //         likename = likename.replace('*', '%');
        //     } else {
        //         // default両側あいまい検索
        //         likename = '%' + likename + '%';
        //     }
        //     searchSql1 += 'and (Product2.Name Like ' + '\'' + likename + '\' or Product2.ProductCode = ' + '\'' + prdcd + '\' or Product2.Asset_Model_No__c Like ' + '\'' + likename + '\') ';
        // }
        
        // List<PricebookEntry> pbes1 = Database.query(searchSql1);
        List<PricebookEntry> pbes = Database.query(searchSql);
        // pbes.addAll(pbes1);
 
        cl = new List<ProductLine>();
        for (Integer i = 0; i < pbes.size(); i++) {
            ProductLine pl = new ProductLine(i, pbes[i]);
            cl.add(pl);
        }
 
        return null;
    }
 
    public class ProductLine {
        public Integer idx {get; set;}
        public PricebookEntry pbe {get; set;}
        public Decimal Intra_Trade_Cost_RMB {get; set;}
        public Decimal Foreign_Trade_Cost_US {get; set;}
        public String NameCode {get; set;}
        public String Sales_Possibility {get; set;}
        public String Bsscategory {get; set;}
        public String Product_Id {get; set;}
        public String PricebookEntryId {get; set;}
        public Decimal Packing_list_manual { get; set; }
        // 多年保修 start
        public string  GuranteeType {get;set;}
        public Decimal Entend_gurantee_period_all { get; set; }
        public Decimal Intra_Trade_Gurantee_RMB { get; set; }
        public Decimal Intra_Trade_Service_RMB { get; set; }
         //2021/01/06 liying start
        public Decimal NoDiscount_Foreign {get; set;}
        //2021/01/06 liying end
        public string VenderName {get; set;}
        public decimal Maintenance_Price_Year {get; set; }
 
        //外贸多年保 取产品主数据上的外贸金额以及维修合同报价 精琢技术 wql 2021/01/04 start 
        public Decimal Intra_Trade_Gurantee_USD { get; set; }
        public Decimal Intra_Trade_Service_USD { get; set; }
        public decimal Maintenance_Price_Year_USD {get; set; }
        //外贸多年保 取产品主数据上的外贸金额以及维修合同报价 精琢技术 wql 2021/01/04 end
 
        //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 Start
        //是否登录报价
        public boolean Estimation_Entry_Possibility {get; set; }
        //内贸成本是否为空
        public boolean CostFlag {get; set; }
        //内贸报价金额是否为空
        public boolean Intra_TradeFlag {get; set; }
        //外贸成本是否为空
        public boolean Cost_USFlag1 {get; set; }
        //外贸报价金额是否为空
        public boolean Foreign_TradeFlag {get; set; }
 
 
 
        //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 end
 
        //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 start
        public boolean CanNotCancelledGurantee {get; set;}
        //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 end
 
        //增加阿西赛多逻辑 精琢技术 wql 2020/12/29 start
        public boolean Is_DangerousChemicals {get; set;}
        //增加阿西赛多逻辑 精琢技术 wql 2020/12/29 end
 
 
        // 多年保修 end
        public ProductLine(Integer i, PricebookEntry pbe) {
            this.idx = i;
            this.pbe = pbe;
            this.Intra_Trade_Cost_RMB = pbe.Product2.Intra_Trade_Cost_RMB__c;
            this.Foreign_Trade_Cost_US = pbe.Product2.Foreign_Trade_Cost_US__c;
            this.NameCode = pbe.Product2.ProductCode;
            this.Sales_Possibility = pbe.Product2.Sales_Possibility__c;
            this.Bsscategory = pbe.Product2.BSSCategory__c;
            this.Product_Id = pbe.Product2Id;
            this.PricebookEntryId = pbe.Id;
            this.Packing_list_manual = pbe.Product2.Packing_list_manual__c;
 
            // 多年保修 start
            this.GuranteeType = pbe.Product2.GuranteeType__c;
            this.Entend_gurantee_period_all = pbe.Product2.Entend_gurantee_period_all__c;
            this.Intra_Trade_Gurantee_RMB = pbe.Product2.Intra_Trade_Gurantee_RMB__c;
            this.Intra_Trade_Service_RMB= pbe.Product2.Intra_Trade_Service_RMB__c;
 
             //2021/01/06 liying start
            this.NoDiscount_Foreign=pbe.Product2.NoDiscount_Foreign__c;
            //2021/01/06 liying end
            this.Maintenance_Price_Year = pbe.Product2.Maintenance_Price_Year__c;
            
            //外贸多年保 取产品主数据上的外贸金额以及维修合同报价 精琢技术 wql 2021/01/04 start 
            this.Intra_Trade_Gurantee_USD = pbe.Product2.Intra_Trade_Foreign_RMB__c;
            this.Intra_Trade_Service_USD = pbe.Product2.NoDiscount_Foreign__c;
            this.Maintenance_Price_Year_USD = pbe.Product2.Repair_Contract_USD__c;
            //外贸多年保 取产品主数据上的外贸金额以及维修合同报价 精琢技术 wql 2021/01/04 end
 
 
            if(pbe.Product2.VenderName__c==null||
                pbe.Product2.VenderName__c.trim().length() == 0){
                this.VenderName =' 无 ';
            }else{
                this.VenderName = pbe.Product2.VenderName__c;
            }
            // 多年保修 end
 
            //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 start
            this.CanNotCancelledGurantee = pbe.Product2.CanNotCancelledGurantee__c;
            //增加产品不可取消多年保逻辑 精琢技术 wql 2020/09/02 end
            //增加阿西赛多逻辑 精琢技术 wql 2020/12/29 start
            this.Is_DangerousChemicals = pbe.Product2.Is_DangerousChemicals__c;
            //增加阿西赛多逻辑 精琢技术 wql 2020/12/29 end
 
 
            //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 Start
            //是否登录报价
            System.debug('aaaaaa:'+pbe.Product2.Estimation_Entry_Possibility__c);
            if(pbe.Product2.Estimation_Entry_Possibility__c=='×' ){
                this.Estimation_Entry_Possibility = true;
            }else{
                this.Estimation_Entry_Possibility = false;
            }
            //内贸成本是否为空
            system.debug('bbbbb:'+pbe.Product2.Intra_Trade_Cost_RMB__c);
            if(pbe.Product2.Intra_Trade_Cost_RMB__c > 0 ){
                this.CostFlag = false;
            }else{
                this.CostFlag = true;
            }
            //内贸报价金额是否为空
            if(pbe.Product2.Intra_Trade_List_RMB__c > 0 ){
                this.Intra_TradeFlag = false;
            }else{
                this.Intra_TradeFlag = true;
            }
            //外贸成本是否为空
            if(pbe.Product2.Foreign_Trade_Cost_US__c > 0 ){
                this.Cost_USFlag1 = false;
            }else{
                this.Cost_USFlag1 = true;
            }
            //外贸报价金额是否为空
            if(pbe.Product2.Foreign_Trade_List_US__c > 0 ){
                this.Foreign_TradeFlag = false;
            }else{
                this.Foreign_TradeFlag = true;
            }
            //HWAG-BLWB9F 询价报价:多年保产品未登录计提金额时不可报价 精琢技术 2020/03/03 end
        }
    }
    //20231103 李文涛 lightning升级 start
    public  void searchNameisNUll(){
        maxLen =SearchName; 
        SearchName='';
    }
    //20231103 李文涛 lightning升级 end
 
}