李彤
2023-05-29 41a627eaaf29658a401ac43e4da838a5b622f44e
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/**
 * 見積PDFのコントローラです。
 */
public class QuotePDFExtensionController {
 
    /** 処理対象の見積オブジェクトのIDです。 */
    private Id targetQuoteId;
 
    /** 処理対象の見積オブジェクトです。 */
    private Quote targetObj;
 
    /** 1ページに表示する明細の数です。 */
    private Integer rowSize = 32;
 
    private Shipment_address__c shipmentAddress;
 
    /** 最終ページに表示する明細の数です。 */
    private Integer lastRowSize = 24;
 
    /** 製品名を開業する文字数です。 */
    private Integer nameMax = 23;
 
    /** 印刷するページ数です。 */
    public Integer maxPageNumber { get; set; }
 
    /** 印刷対象の見積の配下にある見積品目データです。 */
    public List<QuoteLineItemBean[]> printRecords {get; private set;}
 
    private boolean contractFlag = false;
    /**
     * 印刷するデータを格納するオブジェクを定義する、インナークラスです。
     */
    public class QuoteLineItemBean {
        public QuoteLineItem qli {get; private set;}
        public Decimal UnitPrice_c {get; private set;}
        public Decimal TotalPrice_c {get; private set;}
        public String ApprobationNo_c {get; private set;}
        public String ProduceCompany_c {get; private set;}
        public String SalesPackagingUnit_c {get; private set;}
        public Decimal PackingListManual_c {get; private set;}
        public String PackingListManual2_c {get; private set;}
        public QuoteLineItemBean(QuoteLineItem qli) {
            this.qli = qli;
            this.UnitPrice_c = qli.UnitPrice__c;
            this.TotalPrice_c = qli.TotalPrice__c;
            if (qli.PricebookEntry.Product2.SFDA_Status__c != '不要') {
                this.ApprobationNo_c = qli.PricebookEntry.Product2.SFDA_Approbation_No__c;
            }
            //this.ProduceCompany_c = qli.PricebookEntry.Product2.ProduceCompany_F__c;
            this.ProduceCompany_c = qli.Description;
            this.SalesPackagingUnit_c = qli.PricebookEntry.Product2.SalesPackagingUnit_Chinese__c;
            if (this.qli.Item_Order__c != null && (SalesPackagingUnit_c == null || SalesPackagingUnit_c == '')) {
                this.SalesPackagingUnit_c = '件';
            }
            this.PackingListManual_c = qli.PricebookEntry.Product2.Packing_list_manual__c;
            this.PackingListManual2_c = this.PackingListManual_c == null ? '' : 'Pcs';
        }
    }
 
 
    private static Map<String, String> addressNameApiMap = new Map<String, String> {
        '湖南省' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '四川省' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '广东省' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '贵州省' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '云南省' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '广西自治区' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '深圳市' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '湖北省' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '重庆市' => '奥林巴斯(北京)销售服务有限公司广州分公司',
        '北京市' => '奥林巴斯(北京)销售服务有限公司',
        '吉林省' => '奥林巴斯(北京)销售服务有限公司',
        '大连市' => '奥林巴斯(北京)销售服务有限公司',
        '黑龙江省' => '奥林巴斯(北京)销售服务有限公司',
        '内蒙古' => '奥林巴斯(北京)销售服务有限公司',
        '山东省' => '奥林巴斯(北京)销售服务有限公司',
        '甘肃省' => '奥林巴斯(北京)销售服务有限公司',
        '青岛市' => '奥林巴斯(北京)销售服务有限公司',
        '辽宁省' => '奥林巴斯(北京)销售服务有限公司',
        '河北省' => '奥林巴斯(北京)销售服务有限公司',
        '山西省' => '奥林巴斯(北京)销售服务有限公司',
        '天津市' => '奥林巴斯(北京)销售服务有限公司',
        '新疆自治区' => '奥林巴斯(北京)销售服务有限公司',
        '陕西省' => '奥林巴斯(北京)销售服务有限公司',
        '青海省' => '奥林巴斯(北京)销售服务有限公司',
        '宁夏自治区' => '奥林巴斯(北京)销售服务有限公司',
        '河南省' => '奥林巴斯(北京)销售服务有限公司',
        '浙江省' => '奥林巴斯(北京)销售服务有限公司上海分公司',
        '安徽省' => '奥林巴斯(北京)销售服务有限公司上海分公司',
        'OSH-安徽省' => '奥林巴斯贸易(上海)有限公司',   //20230323 lt DB202303088261 两票制 add
        '江西省' => '奥林巴斯(北京)销售服务有限公司上海分公司',
        '福建省' => '奥林巴斯(北京)销售服务有限公司上海分公司',
        '江苏省' => '奥林巴斯(北京)销售服务有限公司上海分公司',
        '上海市' => '奥林巴斯(北京)销售服务有限公司上海分公司'
    };
 
 
    /**
     * 印刷するデータを格納するオブジェクトです。
     * ページ側は、このオブジェクト経由で印刷するデータにアクセスします。
     */
    public Parameters params { get; set;}
 
    /**
     * 印刷するデータを格納するオブジェクを定義する、インナークラスです。
     */
    public class Parameters {
        public String quoteNo {get; set;}
        public String departmentName {get; set;}
        public String ownerName {get; set;}
        public String mobilePhone {get; set;}
        public String trade {get; set;}
        
        public Boolean isUnitPrice {get; set;}
        public Boolean isOfferAmount {get; set;}
        public Boolean isTotalPrice {get; set;}
        public Boolean isDiscountRate {get; set;}
        public Boolean isDiscountAmount {get; set;}
        public Boolean isTradingPrice {get; set;}
        public Boolean isContractDetail {get; set;}
        // LHJ 多年保修 Start
        public Boolean isGuranteePeriod {get;set;}
        // LHJ 多年保修 End
        
        public Decimal totalPrice {get; set;}
        public Decimal discountRate {get; set;}
        public Decimal discountAmount {get; set;}
        public Decimal tradingPrice {get; set;}
        
        public Date quoteDate {get; set;}
        public String quoteDateString {get; set;}
        public String clientName {get; set;}
 
        public Date offerPrintDate {get; set;}
        public String offerPrintDateString {get; set;}
        public String offerPrintDateStringContract {get; set;}
 
        //电子签收ID号 wql 精琢技术  2020/11/20 start 
        public String esignAgencyNum {get; set;}
        //电子签收ID号 wql 精琢技术  2020/11/20 end
        
        public String agent1Name {get; set;}
        public String agent1Phone {get; set;}
        public String agent1Fax {get; set;}
        public String agent2Name {get; set;}
        public String agent2Phone {get; set;}
        public String agent2Fax {get; set;}
        public Integer lenAgentName{get; set;}
 
        public String address {get; set;}
        public String postCode {get;set;}
        public String addressName {get;set;}
        public String addressName1 {get;set;}//20230323 lt DB202303088261 两票制 start  报价单用
        
        public String salesRoot {get;set;}
        public Decimal newTotalPrice {get;set;}
        //WLIG-BYRD37  【委托】询价 打印配置单 字段修改 精琢技术 wql 2021/03/08 start
        public String PurchaseType {get;set;}
        //WLIG-BYRD37  【委托】询价 打印配置单 字段修改 精琢技术 wql 2021/03/08 end
        public Date Quote_Print_Date {get;set;}
        
        
        public String getAgentNameForContract() {
            String ret = null;
            if ( agent1Name == null && agent2Name == null) {
                ret = '';
            }
            else if ( agent1Name != null && agent2Name == null) {
                ret = agent1Name;
            }
            else if ( agent1Name == null && agent2Name != null) {
                ret = agent2Name;
            }
            else if ( agent1Name != null && agent2Name != null) {
                ret = agent1Name;
            }
            lenAgentName = ret.length();
            return ret;
        }
    }
 
    /**
     * コンストラクタです。
     * テスト用に作成しました。本来は不要です。
     */
    public QuotePDFExtensionController( String quoteId) {
        this.mainProc( quoteId);
    }
 
    /**
     * Visualforceページがアクセスするコンストラクタです。
     * 印刷するデータを収集し、インスタンス変数にセットします。
     * @param controller スタンダードコントローラーのインスタンス
     */
    public QuotePDFExtensionController(ApexPages.StandardController controller) {
        this.targetQuoteId = controller.getRecord().Id;
    }
    
    /**
     * 見積書で、actionから呼ばれます。
     */    
    public void startQuote() {
        this.contractFlag = false;
        this.rowSize = 35;
        this.lastRowSize = 28;
        this.nameMax = 27;
        this.mainProc( this.targetQuoteId);
    }
    
    /**
     * 契約内訳で、actionから呼ばれます。
     */    
    public void startContract() {
        this.contractFlag = true;
        // 2022-02-11 SWAG-CBJ8TN 外贸报价配置单打印问题
        // 超长报价单,单页最多只能打印下30行,最终客户名称也超长需要换行,单页明细行改为28行
        this.rowSize = 28;
        this.lastRowSize = 28;
        // this.rowSize = 44;
        // this.lastRowSize = 44;
        //this.nameMax = 18;因为一行显示不完全,为防止错版,改为17;
        // this.nameMax = 16;
        this.nameMax = 12;
        this.mainProc( this.targetQuoteId);
    }
    
    /**
     * 主処理です。
     * @param quoteId 見積番号
     */
    private void mainProc( String quoteId) {
        this.params = new Parameters();
        
        // 見積情報を取得
        List<Quote> quotes =  [SELECT Id, Opportunity.Trade__c, Opportunity.Owner.Name, Opportunity.Owner.MobilePhone, 
                                        Opportunity.Department_Name__c, Quote_No__c, Name, Unit_Price__c, TotalPrice__c, 
                                        Offer_Amount__c, TOTAL__c, Preferential_Gurantee_Period__c, Discount__c, Discount_Amount__c, Discount_Amount_Calculate__c, 
                                        Pricing__c, Preferential_Trading_Price__c, Contract__c, Quote_Date__c, quoteSavedDate__c, Print_HP_Name__c, 
                                        Agency1__r.Name, Agency1__r.Phone, Agency1__r.Fax, Agency2__r.Name, Agency2__r.Phone, 
                                        Agency2__r.Fax, Opportunity.Account.RecordType.DeveloperName, 
                                        Opportunity.Account.Agent_Ref__r.Phone, Opportunity.Account.Agent_Ref__r.Fax, 
                                        Opportunity.SAP_Province__c, OCM_Agent1_Price__c, Dealer_Final_Price__c, 
                                        //电子签收ID号 增加字段检索 wql start
                                        Opportunity.Sales_Root__c,Opportunity.Agency1__r.Management_FormulaCode__c
                                        //电子签收ID号 增加字段检索 wql end
                                        //WLIG-BYRD37  【委托】询价 打印配置单 字段修改 精琢技术 wql 2021/03/08 start
                                        ,Opportunity.Purchase_Type__c ,Quote_Print_Date__c 
                                        //WLIG-BYRD37  【委托】询价 打印配置单 字段修改 精琢技术 wql 2021/03/08 end
                                 FROM Quote WHERE Id = :quoteId];
        // 見積を取得できない場合
        if ( quotes.size() != 1) {
            return;
        }
        this.targetObj = quotes[0];
        
        this.setQueryStringData();
        this.bindQuoteData( quoteId);
        this.bindQuoteLineData();
        this.getShipmentaddress();
    }
 
    /**
     * URLパラメータを取得して、インスタンス変数にセットします。
     */
    private void setQueryStringData() {
        try {
            String rawRowSize = ApexPages.currentPage().getParameters().get( 'rowSize');
            this.rowSize = rawRowSize != null ? Integer.valueOf( rawRowSize) : this.rowSize;
        }
        catch ( Exception e) {
            
        }
    }
 
    /**
     * 見積データを、インスタンス変数にセットします。
     * @param quoteId 見積ID
     */
    private void bindQuoteData( String quoteId) {
        this.params.quoteNo = this.targetObj.Quote_No__c;
        
        this.params.isUnitPrice = this.targetObj.Unit_Price__c;
        this.params.isOfferAmount = this.targetObj.Offer_Amount__c;
        this.params.isTotalPrice = this.targetObj.TOTAL__c;
        this.params.isDiscountRate = this.targetObj.Discount__c;
        this.params.isDiscountAmount = this.targetObj.Pricing__c;
        this.params.isTradingPrice = this.targetObj.Preferential_Trading_Price__c;
        this.params.isContractDetail = this.targetObj.Contract__c;
        // LHJ 多年保修 Start
        // this.params.quoteDate = this.targetObj.Quote_Date__c;
        // this.params.quoteDateString = this.targetObj.Quote_Date__c == null ? '' : this.targetObj.Quote_Date__c.year() + '-' + this.targetObj.Quote_Date__c.month() + '-' + this.targetObj.Quote_Date__c.day();
        this.params.quoteDate = this.targetObj.quoteSavedDate__c;
        this.params.quoteDateString = this.targetObj.quoteSavedDate__c == null ? '' : this.targetObj.quoteSavedDate__c.year() + '-' + this.targetObj.quoteSavedDate__c.month() + '-' + this.targetObj.quoteSavedDate__c.day();
        this.params.isGuranteePeriod = this.targetObj.Preferential_Gurantee_Period__c;
        // LHJ 多年保修 End
        this.params.clientName = this.targetObj.Print_HP_Name__c;
        
        this.params.totalPrice = this.targetObj.totalPrice__c;
        this.params.discountRate = 100 - ( this.targetObj.Discount_Amount_Calculate__c == null ? 0 : this.targetObj.Discount_Amount_Calculate__c);
        this.params.discountAmount = ( this.targetObj.Discount_Amount__c == null ? 0 : this.targetObj.Discount_Amount__c) * 1;
 
        this.params.ownerName = this.targetObj.Opportunity.owner.Name;
        this.params.departmentName = this.targetObj.Opportunity.Department_Name__c;
        
        this.params.trade = this.targetObj.Opportunity.Trade__c == '内貿' ? 'RMB' : this.targetObj.Opportunity.Trade__c == '外貿' ? 'USD' : '不明';
        this.params.MobilePhone = this.targetObj.Opportunity.Owner.MobilePhone;
        
        this.params.offerPrintDate = this.targetObj.Quote_Date__c;
        this.params.offerPrintDateString =         this.targetObj.Quote_Date__c == null ? '' : this.targetObj.Quote_Date__c.year() + '-' + this.targetObj.Quote_Date__c.month() + '-' + this.targetObj.Quote_Date__c.day();
        this.params.offerPrintDateStringContract = this.targetObj.Quote_Date__c == null ? '' : this.targetObj.Quote_Date__c.year() + '/' + this.targetObj.Quote_Date__c.month() + '/' + this.targetObj.Quote_Date__c.day();
 
        
        if (this.targetObj.Opportunity.Account.RecordType.DeveloperName == 'AgencyContract') {
            this.params.agent1Name = this.targetObj.Print_HP_Name__c;
            this.params.agent1Phone = this.targetObj.Opportunity.Account.Agent_Ref__r.Phone;
            this.params.agent1Fax = this.targetObj.Opportunity.Account.Agent_Ref__r.Fax;
        } else {
            this.params.agent1Name = this.targetObj.Agency1__r.Name;
            this.params.agent1Phone = this.targetObj.Agency1__r.Phone;
            this.params.agent1Fax = this.targetObj.Agency1__r.Fax;
        }
        this.params.agent2Name = this.targetObj.Agency2__r.Name;
        this.params.agent2Phone = this.targetObj.Agency2__r.Phone;
        this.params.agent2Fax = this.targetObj.Agency2__r.Fax;
 
        this.params.salesRoot = this.targetObj.Opportunity.Sales_Root__c;
        this.params.newTotalPrice = this.targetObj.Opportunity.Sales_Root__c == '販売店' ? this.targetObj.OCM_Agent1_Price__c : this.targetObj.Dealer_Final_Price__c;
        //电子签收ID号 wql 精琢技术 2020/11/20 start
        this.params.esignAgencyNum = this.targetObj.Opportunity.Sales_Root__c == '販売店' ? this.targetObj.Opportunity.Agency1__r.Management_FormulaCode__c : '';
        //电子签收ID号 wql 精琢技术 2020/11/20 end
        //打印日期
        this.params.Quote_Print_Date = this.targetObj.Quote_Print_Date__c;
        //WLIG-BYRD37  【委托】询价 打印配置单 字段修改 精琢技术 wql 2021/03/08 start
        this.params.PurchaseType = this.targetObj.Opportunity.Purchase_Type__c ;
        //WLIG-BYRD37  【委托】询价 打印配置单 字段修改 精琢技术 wql 2021/03/08 end
        
        // 20150416 xudan 単価など金額列が出ると、Name列の幅が縮む、改行の文字数を合わせて変更必要
        // 同じく、最終ページの明細数も、合計行が出る/出ないにより、調整
        // TODO xud NameよりCodeが長い場合は未対応、等幅文字ではない限り、ここまでか
        if (this.params.isUnitPrice && contractFlag == false) nameMax = nameMax - 2;
        if (this.params.isOfferAmount && contractFlag == false) nameMax = nameMax - 2;
        
        if (this.params.isTotalPrice && contractFlag == false) lastRowSize--;
        if (this.params.isDiscountRate && contractFlag == false) lastRowSize--;
        if (this.params.isDiscountAmount && contractFlag == false) lastRowSize--;
        if (this.params.isTradingPrice && contractFlag == false) lastRowSize--;
    }
 
    /**
     * 見積品目データを取得して、インスタンス変数にセットします。
     */
    private void bindQuoteLineData(){
        this.maxPageNumber = 0;
        String nowId = targetObj.Id;
        Integer rowNum = 1;
        Map<String,Integer> itemsNum = new Map<String,Integer>();
        Integer repeatCount = null;
        String nowName = null, nowRightAsstModelNo = null;
        List<String> nameStringArray = null;
        // String nowCompany = null;
        List<String> companyStringArray = null;
        boolean hasEnglish = false;
        QuoteLineItem work = null;
        QuoteLineItem[] itemsOrg = [SELECT id, Description, Asset_Model_No__c, Name__c, UnitPrice__c, Quantity, TotalPrice__c, Item_Order__c,
                                           PricebookEntry.Product2.SFDA_Approbation_No__c, PricebookEntry.Product2.ProduceCompany__c,
                                           PricebookEntry.Product2.ProduceCompanySummary__c,
                                           //生产企业 WLIG-BZ699Z 精琢技术 wql 2021/03/19 start 如果需要传注册证再打开
                                           //PricebookEntry.Product2.SFDA_Approbated_Status__c,
                                           //生产企业 WLIG-BZ699Z 精琢技术 wql 2021/03/19 end 
                                           PricebookEntry.Product2.ProduceCompany_F__c, PricebookEntry.Product2.SalesPackagingUnit_Chinese__c,
                                           PricebookEntry.Product2.Packing_list_manual__c, PricebookEntry.Product2.SFDA_Status__c
                                           // LHJ 多年保修 Start
                                           , GuaranteePeriod__c ,PricebookEntry.Product2.GuranteeType__c,lastestGuaranteePeriod__c
                                           // LHJ 多年保修 End
                                           //不可取消多年保  增加检索不可取消多年保 和 市场保修期(年) 精琢技术 wql 2020/09/02 start
                                           ,PricebookEntry.Product2.CanNotCancelledGurantee__c,PricebookEntry.Product2.Entend_gurantee_period_MD__c
                                           //不可取消多年保 增加检索不可取消多年保 和 市场保修期(年) 精琢技术 wql 2020/09/02 end
                                           // Gzw CHAN-BGU53N  Start 10/8前Decided的报价单,打印合同配置单时,显示 服务多年保的年限,其他都默认空
                                           , Quote.Opportunity.DecideQuoteDate__c, Quote.Opportunity.Estimation_Decision__c
                                           // Gzw 多年保修 End
                                           //lt 20220223 CHAN-CBW9FX 特殊交货期影响的对应  start
                                           ,DeliveryDate__c
                                           //lt 20220223 CHAN-CBW9FX 特殊交货期影响的对应  end
                                      FROM QuoteLineItem
                                     WHERE QuoteId = :nowId
                                     ORDER BY Item_Order__c ASC];
        QuoteLineItem[] items = new List<QuoteLineItem>();
        for ( Integer i = 0; i < itemsOrg.size(); i++) {
            // 2018/10/11 CHAN-B5F35C 内贸时不显示 注册证号/备案凭证编号start
            if('内貿'.equals(this.targetObj.Opportunity.Trade__c)){
                itemsOrg[i].PricebookEntry.Product2.SFDA_Approbation_No__c = null;
            }
            // 2018/10/11 CHAN-B5F35C end     
            nowName = itemsOrg[i].Name__c == null ? '' : itemsOrg[i].Name__c;
            // Gzw CHAN-BGU53N  Start 10/8前Decided的报价单,打印合同配置单时,显示 服务多年保的年限,其他都默认空
            Boolean oldDate = false;
            //if (itemsOrg[i].Quote.Opportunity.DecideQuoteDate__c == null || itemsOrg[i].Quote.Opportunity.DecideQuoteDate__c < Date.valueOf(Label.GuaranteeWin)) {
            if (itemsOrg[i].Quote.Opportunity.Estimation_Decision__c ==true && 
                    (itemsOrg[i].Quote.Opportunity.DecideQuoteDate__c == null || itemsOrg[i].Quote.Opportunity.DecideQuoteDate__c < Date.valueOf(Label.GuaranteeWin))) {
                oldDate = true;
            } else {
                oldDate = false;
            }
 
            //外贸多年保修 精琢技术 wql 2021/03/23 start
            //上线前decide的询价标识
            Boolean oldDecideDateUSD = false;
            //已经decide 并且在上线前decide
            //itemsOrg[i].Quote.Opportunity.DecideQuoteDate__c== null ||  wql 没有这一段逻辑 这一段属于还未decide不影响
            if((itemsOrg[i].Quote.Opportunity.DecideQuoteDate__c!= null &&itemsOrg[i].Quote.Opportunity.DecideQuoteDate__c < Date.valueOf(Label.GuaranteeUSD)&&'外貿'.equals(this.targetObj.Opportunity.Trade__c))){
                oldDecideDateUSD = true;
            }else{
                oldDecideDateUSD = false;
            }
            //外贸多年保修 精琢技术 wql 2021/03/23 end
            // CHAN-BGU53N  End
            //CHAN-B368WS 当产品编号为:N/A时,打印报价单/合同配置单/系统合同配置单时,打印的产品型号处空白(现在显示产品CODE)
            // LHJ 多年保修 Start
            if (!oldDate && itemsOrg[i].PricebookEntry.Product2.GuranteeType__c == null) {
               itemsOrg[i].GuaranteePeriod__c = null;
            }
            // LHJ 多年保修 End
            // Gzw CHAN-BGU53N  Start
            if (oldDate && itemsOrg[i].PricebookEntry.Product2.GuranteeType__c == '服务') {
                itemsOrg[i].GuaranteePeriod__c = itemsOrg[i].lastestGuaranteePeriod__c;
            }
 
            //外贸多年保修 4.1 切换 start 
            // 20211230 外贸和内贸保持一致 LHJ Start
            // if('外貿'.equals(this.targetObj.Opportunity.Trade__c)){
            //     if(oldDecideDateUSD){
            //         itemsOrg[i].GuaranteePeriod__c = null;
            //     }else{
            //         itemsOrg[i].GuaranteePeriod__c = itemsOrg[i].lastestGuaranteePeriod__c;
            //     }
            // }
            // 20211230 外贸和内贸保持一致 LHJ End
            //外贸多年保修 4.1 切换 end
            //不可取消多年保  增加检索不可取消多年保 和 市场保修期(年) 精琢技术 wql 2020/09/02 start
            //因为市场保修期(年) 是一个选项列表字段 所以需要转一下 因为就4个值所以直接匹配就行
            // if(itemsOrg[i].PricebookEntry.Product2.CanNotCancelledGurantee__c){
            //     if(itemsOrg[i].PricebookEntry.Product2.Entend_gurantee_period_MD__c !=null){
            //         if(itemsOrg[i].PricebookEntry.Product2.Entend_gurantee_period_MD__c.equals('两年')){
            //             itemsOrg[i].GuaranteePeriod__c = 2;
            //         }else if(itemsOrg[i].PricebookEntry.Product2.Entend_gurantee_period_MD__c.equals('三年')){
            //             itemsOrg[i].GuaranteePeriod__c = 3;
            //         }else if(itemsOrg[i].PricebookEntry.Product2.Entend_gurantee_period_MD__c.equals('四年')){
            //             itemsOrg[i].GuaranteePeriod__c = 4;
            //         }else if(itemsOrg[i].PricebookEntry.Product2.Entend_gurantee_period_MD__c.equals('五年')){
            //             itemsOrg[i].GuaranteePeriod__c = 5;
            //         }
            //     }
                
            // }
            //不可取消多年保  增加检索不可取消多年保 和 市场保修期(年) 精琢技术 wql 2020/09/02 end
            // Gzw CHAN-BGU53N  end
            if(itemsOrg[i].Asset_Model_No__c == 'N/A'){
                nowRightAsstModelNo = '';
            }else if( nowName.indexOf( ':') >= 0) {
                nowRightAsstModelNo = nowName.subString( 0, nowName.indexOf( ':'));
                nowName = nowName.subString( nowName.indexOf( ':')+1);
            }
            else if( nowName.indexOf( ':') >= 0) {
                nowRightAsstModelNo = nowName.subString( 0, nowName.indexOf( ':'));
                nowName = nowName.subString( nowName.indexOf( ':')+1);
            }
            else {
                nowRightAsstModelNo = '';
            }
            //nameStringArray = new List<String>();
            Integer repeatCount1 = (nowName.length() / nameMax) + ( Math.mod( nowName.length(), nameMax) > 0 ? 1 : 0);
            String nowCompany = null;
            //companyStringArray = new List<String>();
            ////生产企业 WLIG-BZ699Z 精琢技术 wql 2021/03/19 start  注释原代码
            //nowCompany = itemsOrg[i].PricebookEntry.Product2.ProduceCompany_F__c;
            
            //CHAN-C4X63A 【委托】NFM204字段“生产企业地址”优化 XHL 20210716 Start
            //if(itemsOrg[i].PricebookEntry.Product2.ProduceCompany__c !=null){
            //    nowCompany = getProduceCompanyName(itemsOrg[i].PricebookEntry.Product2.ProduceCompany__c);
            //}
            if(itemsOrg[i].PricebookEntry.Product2.ProduceCompanySummary__c !=null){
                nowCompany = getProduceCompanyName(itemsOrg[i].PricebookEntry.Product2.ProduceCompanySummary__c);
            }
            //CHAN-C4X63A 【委托】NFM204字段“生产企业地址”优化 XHL 20210716 End
            //
            //如果需要传注册证状态的话
            // if(itemsOrg[i].PricebookEntry.Product2.ProduceCompany__c !=null&&itemsOrg[i].PricebookEntry.Product2.SFDA_Approbated_Status__c != null){
            //     nowCompany = getProduceCompanyName(itemsOrg[i].PricebookEntry.Product2.ProduceCompany__c,itemsOrg[i].PricebookEntry.Product2.SFDA_Approbated_Status__c);
            // }
            ////生产企业 WLIG-BZ699Z 精琢技术 wql 2021/03/19 end 
            if (nowCompany == null) nowCompany = '';
            hasEnglish = Pattern.matches('.*[a-zA-Z]+.*', nowCompany);
            Integer companyMax = hasEnglish ? 14 : 10;
            Integer repeatCount2 = (nowCompany.length() / companyMax) + ( Math.mod( nowCompany.length(), companyMax) > 0 ? 1 : 0);
            String descri = itemsOrg[i].Description == null ? '' : itemsOrg[i].Description;
            Integer repeetCount3 = (descri.length() / 10) + (Math.mod(descri.length(), 10) > 0 ? 1 : 0);
 
            repeatCount = repeatCount1 >= repeatCount2 ? (repeatCount1 >= repeetCount3 ? repeatCount1 : repeetCount3) : (repeatCount2 >= repeetCount3 ? repeatCount2 : repeetCount3);
          /*  nameStringArray.add(nowName);
            companyStringArray.add(nowCompany);*/
            work = itemsOrg[i];
            work.NameForPrintDelimiter__c = ':';
            work.Asset_Model_No_forPrint__c = nowRightAsstModelNo;
            work.NameForPrint__c = nowName;
            work.Description = nowCompany.trim();
            items.add( work);
            //合同换行逻辑修改
            /*for ( Integer j = 0; j < repeatCount; j++) {
                if (( j + 1) == repeatCount1) {
                    nameStringArray.add( nowName.substring( j * nameMax));
                }
                else if ((j + 1) > repeatCount1) {
                    nameStringArray.add('');
                }
                else {
                    nameStringArray.add( nowName.substring( j * nameMax, (j+1) * nameMax));
                }
                
 
                if (( j + 1) == repeatCount2) {
                    companyStringArray.add( nowCompany.substring( j * companyMax));
                }
                else if ((j + 1) > repeatCount2) {
                    companyStringArray.add('');
                }
                else {
                    companyStringArray.add( nowCompany.substring( j * companyMax, (j+1) * companyMax));
                }
                
            }*/
            /*for ( Integer k = 0; k < repeatCount; k++) {
                if ( k == 0) {
                    rowNum = 1;
                }
                else {
                    rowNum++;
                }*/
               
            //}
            itemsNum.put(itemsOrg[i].id, repeatCount);
        }
        
        printRecords = new List<QuoteLineItemBean[]>();
 
        QuoteLineItemBean[] pageItems = new QuoteLineItemBean[]{};
        Integer counter = 0;
        for ( QuoteLineItem c : items) {
 
            if ( counter < rowSize) {
                pageItems.add(new QuoteLineItemBean(c));
                counter+= itemsNum.get(c.id);
            }
            if ( counter >= rowSize) {
                counter = 0;
                printRecords.add( pageItems);
                pageItems = new QuoteLineItemBean[]{};
                this.maxPageNumber += 1;
            }
        }
        if ( !pageItems.isEmpty()) {
            printRecords.add( pageItems);
            this.maxPageNumber += 1;
        }
        
        if ( printRecords.size() > 0) {
            List<QuoteLineItemBean> lastList = printRecords[printRecords.size()-1];
system.debug('=====lastList:' + lastList.size());
system.debug('=====lastRowSize:' + lastRowSize);
            if ( lastList.size() > lastRowSize) {
                printRecords.add( new List<QuoteLineItemBean>());
                this.maxPageNumber += 1;
            }
        }
        
        this.params.tradingPrice = params.totalPrice - params.discountAmount;
    }
 
 
 
    //获取办事处地址
    private void getShipmentaddress(){
        String province = this.targetObj.Opportunity.SAP_Province__c;
        //20230323 lt DB202303088261 两票制  start
        String province1 = this.targetObj.Opportunity.SAP_Province__c;
        if(province == 'OSH-安徽省'){
            province = '安徽省';
        }
        //20230323 lt DB202303088261 两票制 end
        
        List<Shipment_address__c> shipmentAddresses =  [SELECT id, Address__c, Post_Code__c FROM Shipment_address__c WHERE Name=:province];
        // 見積を取得できない場合
        if ( shipmentAddresses.size() != 1) {
            return;
        }
        this.shipmentAddress = shipmentAddresses[0];
        
        //20230323 lt DB202303088261 两票制 start
        if(province1 == 'OSH-安徽省'){
            this.params.addressName1 = ' ';
            if(addressNameApiMap.get(province1) != null){
                this.params.addressName = addressNameApiMap.get(province1);
            }else{
                this.params.addressName = ' ';
            }
        }else
        //20230323 lt DB202303088261 两票制 end
        if(addressNameApiMap.get(province) != null){
            this.params.addressName = addressNameApiMap.get(province);
            this.params.addressName1 = addressNameApiMap.get(province); //20230323 lt DB202303088261 两票制 add
        }else{
            this.params.addressName = ' ';
            this.params.addressName1 = ' '; //20230323 lt DB202303088261 两票制 add
        }
        
        this.params.address = this.shipmentAddress.Address__c;
        this.params.postCode = this.shipmentAddress.Post_Code__c;
        
    }
    //生产企业 WLIG-BZ699Z 精琢技术 wql 2021/03/19 start
    //产品主数据生产企业 获取企业名称 (生产企业)
    private String getProduceCompanyName(String produceCompany){
        //获取企业名称 (生产企业,注册证状态)
        //getProduceCompanyName(String produceCompany,String sfdaApprobatedStatus)
        //取前一部分 eg: 生产企业名称 :
        //String firstHalf = '';
 
        //①统一中英文符号  找不到就返回原数据
        String tempProduceCompany = produceCompany.replace(';', ';');
        tempProduceCompany = tempProduceCompany.replace(':', ':');
 
        //②先截取第一个分号前的数据
        if(tempProduceCompany.indexOf(';')>0){
                 tempProduceCompany = tempProduceCompany.substring(0, tempProduceCompany.indexOf(';'));
            }
 
        
        //③截取第一个分号前 冒号后 分号前的数据
        if(tempProduceCompany.indexOf(':') > 0){
            //如果需要传入注册证状态的话 再拼接前一部分
            //firstHalf = tempProduceCompany.substring(0, tempProduceCompany.indexOf(':')+1);
 
            tempProduceCompany = tempProduceCompany.substring(tempProduceCompany.indexOf(':')+1, tempProduceCompany.length());
        }
        
        
        //④正则 只取出中文 不包括 全角符号  # %  不包括英文名
        //[\u4E00-\u9FA5\\s]+ 多个汉字,包括空格
        //[\u4E00-\u9FA5]+ 多个汉字,不包括空格
        //[\u4E00-\u9FA5] 一个汉字
        ///u0800-/u4e00 日文
        //输出中日文
        Pattern p = Pattern.compile('[\u0800-\u9fa5()()]{2,}');
        Matcher pm = p.matcher(tempProduceCompany);
        if( pm.find() ){
            system.debug('123');
             tempProduceCompany = pm.group(0);
        }
        //如果注册证等于不要 拼接前一部分
        // if(sfdaApprobatedStatus == '不要'){
        //     //如果前半部分不为空 则拼接上前半部分
        //     if(firstHalf!= ''){
        //         tempProduceCompany = firstHalf +tempProduceCompany;
        //     }
        // }
        return tempProduceCompany;
    }
    //生产企业 WLIG-BZ699Z 精琢技术 wql 2021/03/19 end
 
 
 
}