GWY
2022-04-15 1b1347f2e6d40aa75bbfdfb4789d60efeff13ea8
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
public without sharing class OrderPdf2Controller {
    public HeaderInfo header { get; set; }
    public List<List<DetailInfo>> pageDetails { get; set; }
    public String productSegment { get; set; }
 
    public List<DetailInfo> inputDetails { get; set; }
 
    public Order order { get; set; }
    // 买方
    public Account buyer { get; set; }
    // 收货方
    public Account delivery { get; set; }
    public Contact delivery_contact { get; set; }
    // 最终用户
    public Account user { get; set; }
    public Contact contact { get; set; }
 
    public String id;
    public String baseUrl { get; set; }
    public String strToday { get; set; }
    public boolean is_parts_direct { get; set; }
    public boolean is_ie_direct { get; set; }
    //public String approveStatus { get; set; }
 
    public Integer pageCnt { get; set; }
    public boolean fistPageBreak { get; set; }
    public boolean lastPageBreak { get; set; }
 
    private Integer firstCnt = 10;
    private Integer firstMaxCnt = 24;
    private Integer eachCnt = 48;
    private Integer lastMaxCnt = 35;
 
    private Integer iRfirstCnt = 9;
    private Integer iRfirstMaxCnt = 23;
    private Integer iReachCnt = 48;
    private Integer iRlastMaxCnt = 30;
 
    private Integer nAfirstCnt = 9;
    private Integer nAfirstMaxCnt = 23;
    private Integer nAeachCnt = 48;
    private Integer nAlastMaxCnt = 30;
 
    public String seller_name1 { get; set; }
    public String seller_address1 { get; set; }
    public String seller_city1 { get; set; }
    public String seller_province1 { get; set; }
    public String seller_phone1 { get; set; }
 
    public String seller_name2 { get; set; }
    public String seller_address2 { get; set; }
    public String seller_city2 { get; set; }
    public String seller_province2 { get; set; }
    public String seller_phone2 { get; set; }
 
    public boolean is_hidden_user { get; set; }
    public boolean is_dealer_user { get; set; }
 
    public Decimal dis {get;set;}
 
    public String ndt_name{get;set;}
    public String ndt_email{get;set;}
    public String ndt_number{get;set;}
    public String ndt_fax{get;set;}
 
    public Boolean notSpecialDealer { get; set; }
    //4月11号之后
    //public Boolean fourMaand { get; set; }
    //是否发货
    public Boolean delivered { get; set; }
 
 
    public OrderPdf2Controller() {
        id = ApexPages.currentPage().getParameters().get('id');
 
        baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
        String path = URL.getCurrentRequestUrl().getPath();
        if (path.indexOf('/apex') > 0) {
            baseUrl += path.substring(0,path.indexOf('/apex'));
        } else if (path.indexOf('production/') > 0) {
            baseUrl += '/production';
        }
 
        Date today = Date.today();
        strToday = today.format();
    }
 
    public PageReference init() {
        notSpecialDealer = true;
        if (id == null || id.length() == 0) {
            return null;
        }
 
        is_hidden_user = false;
        // String profileid = UserInfo.getProfileId().subString(0,15);
 
        //新的获取简档ID  calendarUtil.getMemberProfileID  这里用到的人员ID 和获取到的简档ID都是15位的
        String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15));
 
        if (new_profileId.substring(0, 15) == System.Label.RT_BS_No_Price) {
            is_hidden_user = true;
        }
        is_dealer_user = false;
        if (UserInfo.getUserType() == 'PowerPartner') {
            is_dealer_user = true;
        }
 
        order = new Order();
        List<Order> orderList = [select Id, AccountId, OpportunityId, Opportunity.Dealer__c, Opportunity.SpecialDeliveryAddress__c, Opportunity.SpecialDeliveryContact__c,Opportunity.InquiryNumber__c,
                                        PDF_S_Name__c, PDF_S_Address__c, PDF_S_City__c, PDF_S_Province__c, PDF_S_Phone__c,Opportunity.CreatedBy.ContactId,CreatedBy.ContactId,
                                        Name, Opportunity.ExpectedDeliveryDate__c, PDF_Sap_No__c, OrderNumber, Opportunity.SubDealer__c,
                                        PDF_Property__c, Opportunity.Name, PDF_No__c, Description, PDF_Order_No__c,CrossCooperativeProject__c,
                                        Olympus_Price_BeforeDiscount_D__c, Discount_D__c, OlympusContractPricesD__c, CustomerContractPriceD__c,
                                        Opportunity.ProductSegment__c, Opportunity.SalesChannel__c, Opportunity.Machine_Parts__c,
                                        SpecialDeliveryAccount__c, SpecialDeliveryAccount_D__c, SpecialDeliveryContact2__c, SpecialDeliveryContact2_D__c,ApproveStatus__c,CreatedDate,Is_DeliveredTem__c  
                                   from Order where Id = :id];
        if (orderList.size() == 0) {
            return null;
        }
        order = orderList[0];
        dis = order.Discount_D__c;
        productSegment = order.Opportunity.ProductSegment__c;
        is_parts_direct = false;
        is_ie_direct = false;
        //gwy 4月11号新公司还没有二级备案证
        delivered = order.Is_DeliveredTem__c;
        /*approveStatus = order.ApproveStatus__c;
        Datetime date2 = order.CreatedDate;
        Datetime date3 = Datetime.newInstance(2022,4,11,0,0,0);
        fourMaand = date2>date3 ? true:false;*/
        //还剩下有了新的二级备案证的代码
        if (order.Opportunity.ProductSegment__c == 'IE' && order.Opportunity.SalesChannel__c == 'direct') {
            is_ie_direct = true;
        }
        system.debug(is_ie_direct);
        if (order.Opportunity.SalesChannel__c == 'direct' && order.Opportunity.Machine_Parts__c == 'Parts') {
            is_parts_direct = true;
        }
        /*Contact dealerContact = new Contact();
        if(order.Opportunity.ProductSegment__c == 'NDT' || order.Opportunity.ProductSegment__c == 'ANI'){
            String id = UserInfo.getUserId();
            User user = [select id,ContactID from User where id =: id];
            String conid = user.ContactId;
            dealerContact = [select id, Name,Phone,MobilePhone,Fax,Email from Contact where id =:conid];
        }*/
        buyer = new Account();
        if (order.Opportunity.Dealer__c != null) {
             /*if (order.CrossCooperativeProject__c) {
                buyer = [select Id, Name, Address1__c,Business_license__c, City__c, Province__c, Phone from Account where Id = :order.Dealer_A__c];
            }else{
                buyer = [select Id, Name, Address1__c,Business_license__c, City__c, Province__c, Phone from Account where Id = :order.Opportunity.Dealer__c];
            }*/
            buyer = [select Id, Name, Address1__c,Business_license__c, City__c, Province__c, Phone from Account where Id = :order.Opportunity.Dealer__c];
        }
        notSpecialDealer = !StaticParameter.specialDealerMap.containsKey(((String)order.Opportunity.Dealer__c));
        system.debug('order.Opportunity.Dealer__c' + order.Opportunity.Dealer__c);
        String ndtID = order.CreatedBy.ContactId;
        if(ndtID != null){
            Contact ndtcon =  [select Id, Department, Name, Phone, MobilePhone,Fax,Email from Contact where Id = :ndtID];
            ndt_name = ndtcon.Name;
            ndt_email = ndtcon.Email;
            ndt_number = ndtcon.Phone;
            ndt_fax = ndtcon.Fax;
        }
 
        delivery = new Account();
        if (order.SpecialDeliveryAccount_D__c != null) {
            delivery = [select Id, Name, Address1__c, City__c, Province__c, Sub_Use__c from Account where Id = :order.SpecialDeliveryAccount_D__c];
        }
 
        delivery_contact = new Contact();
        if (order.SpecialDeliveryContact2_D__c != null) {
            delivery_contact = [select Id, Department, Name, Phone, MobilePhone,Address1__c from Contact where Id = :order.SpecialDeliveryContact2_D__c];
        }
 
        user = new Account();
        if (order.AccountId != null) {
            user = [select Id, Name, ManagementCode_F__c, Address1__c,Business_license__c, City__c, Province__c, Sub_Use__c, Phone from Account where Id = :order.AccountId];
        }
 
        List<OpportunityContactRole> ocrList = [select Id, OpportunityId, IsPrimary, ContactId
                                                  from OpportunityContactRole
                                                 where OpportunityId = :order.OpportunityId
                                                 order by IsPrimary desc];
        String contactid = null;
        if (ocrList.size() > 0) {
            contactid = ocrList[0].ContactId;
        }
        contact = new Contact();
        if (contactid != null && contactid.length() > 0) {
            contact = [select Id, Department, Name, Phone, MobilePhone,Fax,Email from Contact where Id = :contactid];
        }
 
        List<OrderItem> oiList = [select Id, PriceBookEntry.Product2.ProductCode, PriceBookEntry.Product2.Product_ECCode__c,PriceBookEntry.Product2.Name,PriceBookEntry.Product2.registrationCode__c,
                                         Quantity, UnitPrice, Factory__c, PriceBookEntry.Hidden_flag__c,PriceBookEntry.Product2.Product_CCode__c
                                    from OrderItem
                                   where OrderId = :id
                                   order by QuoteLineItemId,Id];
 
        if (is_parts_direct == true || is_ie_direct == true) {
            header = new HeaderInfo(order, user, delivery, delivery_contact, user, contact);
        } else {
            header = new HeaderInfo(order, buyer, delivery, delivery_contact, user, contact);
        }
        
        fistPageBreak = false;
        lastPageBreak = false;
        pageCnt = 0;
        pageDetails = new List<List<DetailInfo>>();
        Integer  count = 0;
       
        for (OrderItem oi : oiList) {
            count += getRow(oi);
        }
 
        if(productSegment == 'IE' || productSegment == 'RVI'){
            if (count <= iRfirstCnt) {
                pageCnt = 1;
            } else if (count > iRfirstCnt && count <= iRfirstMaxCnt) {
                fistPageBreak = true;
                pageCnt = 2;
            } else {
                pageCnt = 1 + (count - iRfirstMaxCnt) / iReachCnt;
                Integer mod = Math.mod(count - iRfirstMaxCnt, iReachCnt);
                if (mod > 0 && mod <= iRlastMaxCnt) {
                    pageCnt += 1;
                } else if (mod > iRlastMaxCnt) {
                    lastPageBreak = true;
                    pageCnt += 2;
                }
            }
        }else if (productSegment == 'NDT' || productSegment == 'ANI') {
            if (count <= nAfirstCnt) {
                pageCnt = 1;
            } else if (count > nAfirstCnt && count <= nAfirstMaxCnt) {
                fistPageBreak = true;
                pageCnt = 2;
            } else {
                pageCnt = 1 + (count - nAfirstMaxCnt) / nAeachCnt;
                Integer mod = Math.mod(count - nAfirstMaxCnt, nAeachCnt);
                if (mod > 0 && mod <= nAlastMaxCnt) {
                    pageCnt += 1;
                } else if (mod > nAlastMaxCnt) {
                    lastPageBreak = true;
                    pageCnt += 2;
                }
            }
        }else {
            if (count <= firstCnt) {
                pageCnt = 1;
            } else if (count > firstCnt && count <= firstMaxCnt) {
                fistPageBreak = true;
                pageCnt = 2;
            } else {
                pageCnt = 1 + (count - firstMaxCnt) / eachCnt;
                Integer mod = Math.mod(count - firstMaxCnt, eachCnt);
                if (mod > 0 && mod <= lastMaxCnt) {
                    pageCnt += 1;
                } else if (mod > lastMaxCnt) {
                    lastPageBreak = true;
                    pageCnt += 2;
                }
            }
        }
 
        
 
        Integer nowPage = 1;
        Integer nowLine = 0;
        Integer line = 0;
        List<DetailInfo> details = new List<DetailInfo>();
        for (OrderItem oi : oiList) {
            if (productSegment == 'IE' || productSegment == 'RVI') {
                line += 1;
                nowLine += getRow(oi);
                if (count <= iRfirstMaxCnt) {
                    DetailInfo di = new DetailInfo(line, oi,dis);
                    if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                        di.price = 0;
                        di.totalprice = 0;
                    }
                    details.add(di);
                } else if (nowPage == 1) {
                    if (nowLine <= iRfirstMaxCnt) {
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    } else {
                        nowPage += 1;
                        nowLine = 0;
                        pageDetails.add(details);
                        details = new List<DetailInfo>();
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    }
                } else {
                    if (nowLine <= iReachCnt) {
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    } else {
                        nowPage += 1;
                        nowLine = 0;
                        pageDetails.add(details);
                        details = new List<DetailInfo>();
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    }
                }
            }else if (productSegment == 'NDT' || productSegment == 'ANI') {
                line += 1;
                nowLine += getRow(oi);
                if (count <= nAfirstMaxCnt) {
                    DetailInfo di = new DetailInfo(line, oi,dis);
                    if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                        di.price = 0;
                        di.totalprice = 0;
                    }
                    details.add(di);
                } else if (nowPage == 1) {
                    if (nowLine <= nAfirstMaxCnt) {
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    } else {
                        nowPage += 1;
                        nowLine = 0;
                        pageDetails.add(details);
                        details = new List<DetailInfo>();
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    }
                } else {
                    if (nowLine <= nAeachCnt) {
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    } else {
                        nowPage += 1;
                        nowLine = 0;
                        pageDetails.add(details);
                        details = new List<DetailInfo>();
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    }
                }
            }else {
                line += 1;
                nowLine += getRow(oi);
                if (count <= firstMaxCnt) {
                    DetailInfo di = new DetailInfo(line, oi,dis);
                    if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                        di.price = 0;
                        di.totalprice = 0;
                    }
                    details.add(di);
                } else if (nowPage == 1) {
                    if (nowLine <= firstMaxCnt) {
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    } else {
                        nowPage += 1;
                        nowLine = 0;
                        pageDetails.add(details);
                        details = new List<DetailInfo>();
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    }
                } else {
                    if (nowLine <= eachCnt) {
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    } else {
                        nowPage += 1;
                        nowLine = 0;
                        pageDetails.add(details);
                        details = new List<DetailInfo>();
                        DetailInfo di = new DetailInfo(line, oi,dis);
                        if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                            di.price = 0;
                            di.totalprice = 0;
                        }
                        details.add(di);
                    }
                }
            }
 
            
 
 
        }
 
        /*if (oiList.size() <= firstCnt) {
            pageCnt = 1;
        } else if (oiList.size() > firstCnt && oiList.size() <= firstMaxCnt) {
            fistPageBreak = true;
            pageCnt = 2;
        } else {
            pageCnt = 1 + (oiList.size() - firstMaxCnt) / eachCnt;
            Integer mod = Math.mod(oiList.size() - firstMaxCnt, eachCnt);
            if (mod > 0 && mod <= lastMaxCnt) {
                pageCnt += 1;
            } else if (mod > lastMaxCnt) {
                lastPageBreak = true;
                pageCnt += 2;
            }
        }*/
       /* Integer nowPage = 1;
        Integer nowLine = 0;
        Integer line = 0;
        List<DetailInfo> details = new List<DetailInfo>();
        for (OrderItem oi : oiList) {
            line += 1;
            nowLine += 1;
            if (oiList.size() <= firstMaxCnt) {
                DetailInfo di = new DetailInfo(line, oi);
                if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                    di.price = 0;
                    di.totalprice = 0;
                }
                details.add(di);
            } else if (nowPage == 1) {
                if (nowLine <= firstMaxCnt) {
                    DetailInfo di = new DetailInfo(line, oi);
                    if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                        di.price = 0;
                        di.totalprice = 0;
                    }
                    details.add(di);
                } else {
                    nowPage += 1;
                    nowLine = 0;
                    pageDetails.add(details);
                    details = new List<DetailInfo>();
                    DetailInfo di = new DetailInfo(line, oi);
                    if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                        di.price = 0;
                        di.totalprice = 0;
                    }
                    details.add(di);
                }
            } else {
                if (nowLine <= eachCnt) {
                    DetailInfo di = new DetailInfo(line, oi);
                    if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                        di.price = 0;
                        di.totalprice = 0;
                    }
                    details.add(di);
                } else {
                    nowPage += 1;
                    nowLine = 0;
                    pageDetails.add(details);
                    details = new List<DetailInfo>();
                    DetailInfo di = new DetailInfo(line, oi);
                    if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                        di.price = 0;
                        di.totalprice = 0;
                    }
                    details.add(di);
                }
            }
        }*/
 
        if (fistPageBreak == true) {
            for (Integer i = nowLine + 1; i <= firstMaxCnt; i++) {
                line += 1;
                DetailInfo di = new DetailInfo(line);
                details.add(di);
            }
        } else if (lastPageBreak == true) {
            for (Integer i = nowLine + 1; i <= eachCnt; i++) {
                line += 1;
                DetailInfo di = new DetailInfo(line);
                details.add(di);
            }
        }
 
        pageDetails.add(details);
 
        Decimal sum = 0;
        for(List<DetailInfo> difList : pageDetails){
            for (DetailInfo  dif: difList ) {
                if(dif.price_d != null){
                    sum+=dif.price_d;
                }
            }
        }
        if(sum != 0){
            for(List<DetailInfo> difList : pageDetails){
                for (DetailInfo  dif: difList ) {
                    system.debug(header.order_totalprice+'-----'+sum);
                    dif.price_d = dif.price_d + (header.order_totalprice - sum);
                    break;
                }
                break;
            }
        }
 
        return null;
    }
 
    private Integer getRow(OrderItem oi){
        Integer row = 1;
        if(oi.PriceBookEntry.Product2.Product_ECCode__c != null){
            if (productSegment == 'ANI' || productSegment == 'NDT'){
                row = oi.PriceBookEntry.Product2.Product_ECCode__c.length()/27 +1 > row ? oi.PriceBookEntry.Product2.Product_ECCode__c.length() == 24 ?1:oi.PriceBookEntry.Product2.Product_ECCode__c.length()/24  +1: row;
            } else if (productSegment == 'IE' || productSegment == 'RVI'){
                row = oi.PriceBookEntry.Product2.Product_ECCode__c.length()/17 +1 > row ? oi.PriceBookEntry.Product2.Product_ECCode__c.length() == 17 ?1:oi.PriceBookEntry.Product2.Product_ECCode__c.length()/17  +1: row;
            } else{
                row = oi.PriceBookEntry.Product2.Product_ECCode__c.length()/11 +1 > row ? oi.PriceBookEntry.Product2.Product_ECCode__c.length() == 11 ?1:oi.PriceBookEntry.Product2.Product_ECCode__c.length()/11  +1: row;
            }
        }
        if(oi.PriceBookEntry.Product2.Product_CCode__c != null){
            row = oi.PriceBookEntry.Product2.Product_CCode__c.length()/12 +1> row ? oi.PriceBookEntry.Product2.Product_CCode__c.length() == 12?1:oi.PriceBookEntry.Product2.Product_CCode__c.length()/12 +1: row;
        }
        if(oi.PriceBookEntry.Product2.Name != null){
            if (productSegment == 'BS') {
                row = oi.PriceBookEntry.Product2.Name.length()/9 +1> row ? oi.PriceBookEntry.Product2.Name.length() == 9 ? 1 : oi.PriceBookEntry.Product2.Name.length()/9 +1: row;
            }else if (productSegment == 'NDT' || productSegment == 'ANI') {
                row = oi.PriceBookEntry.Product2.Name.length()/12 +1> row ? oi.PriceBookEntry.Product2.Name.length() == 12 ? 1 : oi.PriceBookEntry.Product2.Name.length()/12 +1: row;
            }
        }
        if(productSegment == 'BS' && oi.PriceBookEntry.Product2.registrationCode__c != null){
            row = oi.PriceBookEntry.Product2.registrationCode__c.length()/17 +1>row? oi.PriceBookEntry.Product2.registrationCode__c.length() == 15 ? 1 : oi.PriceBookEntry.Product2.registrationCode__c.length()/17 +1 : row;
            system.debug('======'+row+'++++++++++'+oi.PriceBookEntry.Product2.registrationCode__c.length() +'-------'+oi.PriceBookEntry.Product2.registrationCode__c);
        }
        system.debug(oi.PriceBookEntry.Product2.Name+'***********'+row+'***'+oi.PriceBookEntry.Product2.Name.length()+'***'+ (oi.PriceBookEntry.Product2.Name.length()/9 +1));
        
        return row;
    }
 
    public PageReference init2() {
        notSpecialDealer = true;
        is_hidden_user = false;
        // String profileid = UserInfo.getProfileId().subString(0,15);
 
        //新的获取简档ID  calendarUtil.getMemberProfileID  这里用到的人员ID 和获取到的简档ID都是15位的
        String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15));
        
        if (new_profileId.substring(0, 15) == System.Label.RT_BS_No_Price) {
            is_hidden_user = true;
        }
        is_dealer_user = false;
        if (UserInfo.getUserType() == 'PowerPartner') {
            is_dealer_user = true;  
        }
 
        seller_name1 = '奥林巴斯(中国)有限公司';
        seller_address1 = '北京市朝阳区新源南路1-3号平安国际金融中心A座8楼';
        seller_city1 = '北京';
        seller_province1 = '北京';
        seller_phone1 = '010-58199000';
 
        seller_name2 = '仪景通光学科技(上海)有限公司';
        seller_address2 = '中国(上海)自由贸易试验区日樱北路199-9号102及302部位';
        seller_city2 = '上海';
        seller_province2 = '上海';
        seller_phone2 = '021-58881300';
 
        header = new HeaderInfo();
        inputDetails = new List<DetailInfo>();
        order = new Order();
 
        List<Order> orderList = [select Id, AccountId, OpportunityId, Opportunity.Dealer__c, Opportunity.SpecialDeliveryAddress__c, Opportunity.SpecialDeliveryContact__c,
                                        PDF_S_Name__c, PDF_S_Address__c, PDF_S_City__c, PDF_S_Province__c, PDF_S_Phone__c,
                                        Name, Opportunity.ExpectedDeliveryDate__c, PDF_Sap_No__c, OrderNumber, Opportunity.SubDealer__c,
                                        PDF_Property__c, Opportunity.Name, PDF_No__c, Description, PDF_Order_No__c,
                                        Olympus_Price_BeforeDiscount_D__c, Discount_D__c, OlympusContractPricesD__c, CustomerContractPriceD__c,
                                        Opportunity.ProductSegment__c
                                   from Order where Id = :id];
        if (orderList.size() == 0) {
            return null;
        }
 
        order = orderList[0];
        dis = order.Discount_D__c;
        header.seller_name = order.PDF_S_Name__c;
        header.seller_address = order.PDF_S_Address__c;
        header.seller_city = order.PDF_S_City__c;
        header.seller_province = order.PDF_S_Province__c;
        header.seller_phone = order.PDF_S_Phone__c;
        header.order_sap_no = order.PDF_Sap_No__c;
        //header.user_property_IE = order.PDF_Property__c;
        header.order_no = order.PDF_No__c;
        header.pdf_order_no = order.PDF_Order_No__c;
        //dealerid = order.Opportunity.Dealer__c.subString(0,15)
        notSpecialDealer = !StaticParameter.specialDealerMap.containsKey(((String)order.Opportunity.Dealer__c));
        system.debug('order.Opportunity.Dealer__c' + StaticParameter.specialDealerMap.containsKey(((String)order.Opportunity.Dealer__c)));
        system.debug(!StaticParameter.specialDealerMap.containsKey(((String)order.Opportunity.Dealer__c)));
        productSegment = order.Opportunity.ProductSegment__c;
 
        //2019-5-20
        if(productSegment == 'IE' && (order.PDF_Property__c == '' || order.PDF_Property__c == null)){
            List<Account> accList = [select id,UserType__c from Account where id = :order.AccountId];
            if(accList.size() > 0 ){
                order.PDF_Property__c = accList[0].UserType__c;
            }
        }
 
        List<OrderItem> oiList = [select Id, PriceBookEntry.Product2.ProductCode, PriceBookEntry.Product2.Product_ECCode__c,PriceBookEntry.Product2.Name,PriceBookEntry.Product2.Factory__c,Discount__c,
                                         Quantity, UnitPrice, Factory__c, PriceBookEntry.Hidden_flag__c,PriceBookEntry.Product2.Product_CCode__c,PriceBookEntry.Product2.registrationCode__c
                                    from OrderItem
                                   where OrderId = :id
                                   order by QuoteLineItemId, Id];
        Integer line = 0;
        for (OrderItem oi : oiList) {
            line += 1;
            DetailInfo di = new DetailInfo(line, oi,dis);
            if (is_hidden_user == true || is_dealer_user == true && oi.PriceBookEntry.Hidden_flag__c == true) {
                di.price = 0;
                di.totalprice = 0;
            }
            di.factory = oi.PriceBookEntry.Product2.Factory__c;
            inputDetails.add(di);
        }
 
        //notSpecialDealer = !StaticParameter.specialDealerMap.containsKey(order.Opportunity.Dealer__c);
        return null;
    }
 
    public PageReference printBtn() {
        PageReference ref = null;
        if (saveFunction() == true) {
            if(productSegment == 'NDT' || productSegment == 'ANI'){
                ref = new Pagereference(baseUrl + '/apex/OrderPdf3?id=' + order.id);
                ref.setRedirect(true);
            }else{
                ref = new Pagereference(baseUrl + '/apex/OrderPdf2?id=' + order.id);
                ref.setRedirect(true);
            }
        }
        return ref;
    }
 
    public PageReference saveBtn() {
        PageReference ref = null;
        if (saveFunction() == true) {
            ref = new Pagereference(baseUrl + '/apex/OrderContract2?id=' + order.id);
            ref.setRedirect(true);
        }
        return ref;
    }
 
    public boolean saveFunction() {
        boolean rt = false;
 
        Order upd_order = new Order();
        upd_order.Id = order.Id;
        upd_order.Name = order.Name;
        upd_order.PDF_S_Name__c = header.seller_name;
        upd_order.PDF_S_Address__c = header.seller_address;
        upd_order.PDF_S_City__c = header.seller_city;
        upd_order.PDF_S_Province__c = header.seller_province;
        upd_order.PDF_S_Phone__c = header.seller_phone;
        upd_order.PDF_Sap_No__c = header.order_sap_no;
        //upd_order.PDF_Property__c = header.user_property_IE;
        upd_order.PDF_Property__c = order.PDF_Property__c;
        upd_order.PDF_No__c = header.order_no;
        upd_order.PDF_Order_No__c = header.pdf_order_no;
 
        List<OrderItem> upd_oiList = new List<OrderItem>();
        for (DetailInfo inputDetail : inputDetails) {
            OrderItem oi = new OrderItem();
            oi.Id = inputDetail.orderItem.Id;
            oi.Factory__c = inputDetail.factory;
            upd_oiList.add(oi);
        }
 
        Savepoint sp = Database.setSavepoint();
        try {
            update upd_order;
            update upd_oiList;
           
            rt = true;
        } catch (Exception ex) {
            system.debug('=====' + ex.getMessage());
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getMessage()));
            Database.rollback(sp);
            return false;
        }
 
        return rt;
    }
 
    public class HeaderInfo {
        // 买方信息
        public String buyer_name { get; set; }
        public String buyer_address { get; set; }
        public String buyer_city { get; set; }
        public String buyer_province { get; set; }
        public String buyer_phone { get; set; }
        public String buyer_code {get; set;}
        // 卖方信息
        public String seller_name { get; set; }
        public String seller_address { get; set; }
        public String seller_city { get; set; }
        public String seller_province { get; set; }
        public String seller_phone { get; set; }
        public String seller_code {get; set;}
        // 订单信息1
        public String order_number { get; set; }
        public String order_require_date { get; set; }
        public String order_sap_no { get; set; }
        public String order_crm_no { get; set; }
        public String order_subdealer { get; set; }
        // 收货信息
        public String delivery_name { get; set; }
        public String delivery_department { get; set; }
        public String delivery_address { get; set; }
        public String delivery_city { get; set; }
        public String delivery_province { get; set; }
        public String delivery_user { get; set; }
        public String delivery_phone { get; set; }
        public String delivery_tel { get; set; }
        // 最终用户信息
        public String user_name { get; set; }
        public String user_no { get; set; }
        public String user_department { get; set; }
        public String user_address { get; set; }
        public String user_city { get; set; }
        public String user_province { get; set; }
        public String user_name2 { get; set; }
        public String user_phone { get; set; }
        public String user_fax {get; set;}
        public String user_email {get;set;}
        public String user_tel { get; set; }
        public String user_property_IE { get; set; }
        public String user_product_IE { get; set; }
        public String user_market_RVI { get; set; }
        // 订单信息2
        public Decimal order_subtotal { get; set; }
        public Decimal order_discount_rate { get; set; }
        public Decimal order_discount_value { get; set; }
        public Decimal order_totalprice { get; set; }
        public Decimal order_dealer_profit { get; set; }
        public Decimal order_dealer_price { get; set; }
        public boolean order_print_dealer { get; set; }
        // 订单信息3
        public String order_inquiry_no { get; set; }
        public String order_no { get; set; }
        public String order_comment { get; set; }
        public String pdf_order_no { get; set; }
 
        public HeaderInfo() {
 
        }
 
        public HeaderInfo(Order order, Account buyer, Account delivery, Contact delivery_contact, Account user, Contact contact) {
            buyer_name = buyer.Name;
            buyer_address = buyer.Address1__c;
            buyer_city = buyer.City__c;
            buyer_province = buyer.Province__c;
            buyer_phone = buyer.Phone;
            buyer_code = buyer.Business_license__c;
 
            seller_name = order.PDF_S_Name__c;
            seller_address = order.PDF_S_Address__c;
            seller_city = order.PDF_S_City__c;
            seller_province = order.PDF_S_Province__c;
            seller_phone = order.PDF_S_Phone__c;
 
            order_number = order.Name;
            Date dt = order.Opportunity.ExpectedDeliveryDate__c;
            order_require_date = dt == null ? '' : dt.format();
            order_sap_no =  order.PDF_Sap_No__c;
            order_crm_no = order.OrderNumber;
            order_subdealer = order.Opportunity.SubDealer__c;
 
            delivery_name = delivery.Name;
            delivery_department = delivery_contact.Department;
            delivery_address = delivery_contact.Address1__c;
            delivery_city = delivery.City__c;
            delivery_province = delivery.Province__c;
            delivery_user = delivery_contact.Name;
            delivery_phone = delivery_contact.Phone;
            delivery_tel = delivery_contact.MobilePhone;
 
            user_name = user.Name;
            user_no = user.ManagementCode_F__c;
            user_department = contact.Department;
            user_address = user.Address1__c;
            user_city = user.City__c;
            user_province = user.Province__c;
            user_name2 = contact.Name;
            user_phone = contact.Phone;
            user_fax = contact.Fax;
            user_email = Contact.Email;
            user_tel = contact.MobilePhone;
            user_property_IE = order.PDF_Property__c;
            user_product_IE = user.Sub_Use__c == 'Automotive' ? '汽车' : user.Sub_Use__c;
            user_market_RVI = user.Sub_Use__c;
 
            order_subtotal = order.Olympus_Price_BeforeDiscount_D__c;
            order_discount_rate = order.Discount_D__c;
            order_totalprice = order.OlympusContractPricesD__c;
            order_discount_value = (order_subtotal == null ? 0 : order_subtotal) - (order_totalprice == null ? 0 : order_totalprice);
            order_dealer_price = order.CustomerContractPriceD__c;
            order_dealer_profit = (order_dealer_price == null ? 0 : order_dealer_price) - (order_totalprice == null ? 0 : order_totalprice);
            order_print_dealer = true;
            if (order_dealer_price == null || order_dealer_price == 0) {
                order_print_dealer = false;
            }
 
            order_inquiry_no = order.Opportunity.Name;
            if(order.Opportunity.ProductSegment__c == 'NDT' || order.Opportunity.ProductSegment__c == 'ANI'){
                order_inquiry_no = order.Opportunity.InquiryNumber__c;
            }
            order_no = order.PDF_No__c;
            order_comment = order.Description;
            pdf_order_no = order.PDF_Order_No__c;
        }
    }
 
    public class DetailInfo {
        public OrderItem orderItem { get; set; }
        public Integer lineno { get; set; }
        public String otcode { get; set; }
        public String eccode { get; set; }
        public Integer quantity { get; set; }
        public Decimal price { get; set; }
        public Decimal totalprice { get; set; }
        public String factory { get; set; }
        public String ccode { get; set; }
        public String name {get; set;}
        public String registrationCode {get; set;}
        public Decimal price_d {get;set;}
        public String discount {get;set;}
 
        public DetailInfo(Integer line) {
            orderItem = new OrderItem();
            lineno = line;
            otcode = null;
            eccode = null;
            quantity = null;
            price = null;
            totalprice = null;
            factory = null;
            ccode = null;
            name = null;
            registrationCode = null;
            discount = null;
        }
 
        public DetailInfo(Integer line, OrderItem oi,Decimal dis) {
            discount = dis + '%';
            orderItem = oi;
            lineno = line;
            otcode = oi.PriceBookEntry.Product2.ProductCode;
            otcode = otcode.startsWith('00000000000') ? otcode.substring(11) : otcode;
            eccode = oi.PriceBookEntry.Product2.Product_ECCode__c;
            //eccode = eccode.startsWith('00000000000') ? eccode.substring(11) : eccode;
            Decimal qty = oi.Quantity;
            quantity = qty.intValue();
            price = oi.UnitPrice;
            price = price.setScale(2, System.RoundingMode.HALF_UP);
            totalprice = qty * price;
            totalprice = totalprice.setScale(2, System.RoundingMode.HALF_UP);
            factory = oi.Factory__c;
            ccode = oi.PriceBookEntry.Product2.Product_CCode__c;
            name = oi.PriceBookEntry.Product2.Name;
            if (oi.PriceBookEntry.Product2.registrationCode__c !=null && oi.PriceBookEntry.Product2.registrationCode__c != '') {
                registrationCode = oi.PriceBookEntry.Product2.registrationCode__c + 'LS内贸';
            }else{
                registrationCode = oi.PriceBookEntry.Product2.registrationCode__c;
            }
            
            system.debug('registrationCode='+registrationCode);
            if(dis != null ){
                price_d =totalprice * (1-(dis/100));
                price_d = price_d.setScale(2, System.RoundingMode.HALF_UP);
            }
        }
    }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    public static void asd() {
        Integer i = 1;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
}