高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
public without sharing class summonsCreatController {
    /*****************検索用******************/
    //经销商用户产品分类(ET、ENG)
    public String agencyProType {get;set;}
    public Consumable_order__c coc { get; set; }            // 画view用, 可能是 出库指示单, 也有可能是到货单, 也有可能 空instance
    public User localuser { get; set; }
    public String category1 { get; set; }
    Public Integer noOfRecords{get; set;}
    //public String category_Goods {get ; set;}
    public Boolean cansee{get;set;}
    Public Integer size{get;set;}
    //经销商定价查看权限
    public ApexPages.StandardSetController setCon { get; set; }
    public Boolean dealerPricesee {get;set;}
    /*****************画面初始化用********************************/
    /******20160313_add**************/
    public String IdCheck {get;set;}
    public Boolean editAble {get;set;}
    public String statusEdit {get;set;}
    public String alertMessage{set;get;}
    public String SearchDone {get;set;}
    List<String> zaikuId = new List<String>();
    List<String> orderzaikuId = new List<String>();
    //附件
    public List<ConsumableorderdetailsInfo> attachmentRecoeds { get; set; }
    public Boolean getExistarrive() {
        return (coc.Arrive_Order__c != null);
    }
    //总价格计算结果
    public Decimal sumPrice {get;set;}
    /******20160317_add**************/
    public String SummonsFlag {get;set;}         // 新規: hidden, 更新: visible
    public String category5 { get; set; }
    public String category4 { get; set; }
    public String category3 { get; set; }
    public List<SelectOption> categoryOptionList{get;set;}
    public List<SelectOption> category4OptionList{get;set;}
    public List<SelectOption> category5OptionList{get;set;}
    /*****************画面表示Bean******************/
    private List<ConsumableorderdetailsInfo> consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
    public List<ConsumableorderdetailsInfo> pageRecords { get; set; }
    //public List<List<ConsumableorderdetailsInfo>> consumableorderdetailsRecordsview { get; set; }
    public List<ConsumableorderdetailsInfo> consumableorderdetails2Records { get; set; }
    public List<Consumable_order__c> consumableInvoiceRecords { get; set; }
    private List<ConsumableorderdetailsInfo> consumableproductdetailsRecords = new List<ConsumableorderdetailsInfo>();
    private List<Attachment> attachmentinfo = new List<Attachment>();
    List<Product2__c> product2Selected = new List<Product2__c>();
    //选择产品size
    public Integer consumableorderdetailsCount {
        get {
            return pageRecords == null ? 0 : pageRecords.size();
        }
    }
    //消耗品明细2数量
    public Integer consumableorderdetails2Count {
        get {
            return consumableorderdetails2Records == null ? 0 : consumableorderdetails2Records.size();
        }
    }
    //订货单号
    public String consumableorderId {
        get {
            return (coc.Arrive_Order__c);
        }
    }
    //选择框
    public List<SelectOption> provinceOpts  { get; set; }
    public String SecondDealer {get;set;}
    //public List<SelectOption> orderForHospitalOpts { get; set; }
    public String HospitalInfo {get;set;}
    public String HospitalName {get;set;}
 
    public Boolean EditDelCommitBtnDisabled {get; private set;}
    public Boolean saveBtnDisabled { get; private set; }
    public Boolean SorderBtnDisabled { get; private set; }
    // 保存后动作: 1.检索 2.排序
    public String sortKey { get; set; }
    public String preSortKey { get; private set; }
    public Boolean sortOrderAsc { get; private set; }
    public String[] sortOrder { get; private set; }
    private String[] columus = new String[]{ 'Consumable_Product__r.Name','Consumable_Product__r.Asset_Model_No__c','Consumable_Product__r.Intra_Trade_List_RMB__c','','','Consumable_Product__r.Category3__c','Consumable_Product__r.Category4__c','Consumable_Product__r.Category5__c'};
    private String[] columus_no = new String[]{ 'Product2__c.Name','Product2__c.Asset_Model_No__c','Product2__c.Intra_Trade_List_RMB__c','','','Category3__c','Category4__c','Category5__c'};
 
    //到货单明细1
    private List<Consumable_Orderdetails__c> consumableorderdetailsSelected = new List<Consumable_Orderdetails__c>();
    //到货单明细2
    private List<Consumable_order_details2__c> consumablearriveproductdetailsSelected = new List<Consumable_order_details2__c>();
 
    //出库单明细2
    private List<Consumable_order_details2__c> consumableorderdetails2RecordsList = new List<Consumable_order_details2__c>();
    /*****************ソート時再検索条件(画面からの入力条件を無視するため)******************/
    //private String cate1ForSort = null;
    private String accountid = null;
    private String accountName = null;
 
    // 产品 ID
    private String ESetId = '';
    public String arriveorder {get;set;}
    private String userId = '';
    //private String[] ProidListAll = new String[]{};
 
    // 登录者工作地
    private String userWorkLocation;
 
    //add by rentx 2021-01-29 
    public List<SelectOption> outOutPatternOptionList{get;set;}
    public String outOutPattern {get;set;}
    public Boolean hasHos {get;set;}
    public Boolean hasHosPro {get;set;}
 
    private Map<String,String> HosProMap = new Map<String,String>();
    //add by rentx 2021-01-29
 
    public summonsCreatController() {
        size = Integer.valueOf(System.Label.orderdetLimitsize);
        ESetId = ApexPages.currentPage().getParameters().get('esetId');
        arriveorder = ApexPages.currentPage().getParameters().get('arriveorder');
        statusEdit = ApexPages.currentPage().getParameters().get('KeyWords');
        provinceOpts = new List<SelectOption>();
        pageRecords = new List<ConsumableorderdetailsInfo>();
        consumableproductdetailsRecords = new List<ConsumableorderdetailsInfo>();
        consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
        attachmentRecoeds = new List<ConsumableorderdetailsInfo>();
        consumableorderdetails2Records = new List<ConsumableorderdetailsInfo>();
        consumableInvoiceRecords = new List<Consumable_order__c>();
        categoryOptionList = new List<SelectOption>();
        category4OptionList = new List<SelectOption>();
        category5OptionList = new List<SelectOption>();
        outOutPatternOptionList = new List<SelectOption>();
        outOutPatternOptionList.add(new SelectOption('','-无-'));
        outOutPatternOptionList.add(new SelectOption('ishos','医院特价产品'));
        outOutPatternOptionList.add(new SelectOption('nothos','非医院特价产品'));
 
    }
    private void initStandardController(String soql){
        // init standard controller
        setCon = new ApexPages.StandardSetController(Database.getQueryLocator(soql));
        // sets the number of records in each page set
        setCon.setPageSize(size);
        //因为现在有区分医院特价和非医院特价,所以产品数应该为展示的数据长度
        // noOfRecords = setCon.getResultSize();
    }
    public List<Product2__c> product2s() {
         return (List<Product2__c>) setCon.getRecords();
    }
    //Changes the size of pagination
    public PageReference refreshPageSize() {
        setCon.setPageSize(size);
        product2Selected = product2s();
        makepagerecords();
        return null;
    }
    public List<ConsumableorderdetailsInfo> makepagerecords() {
        List<ConsumableorderdetailsInfo> reSet = new List<ConsumableorderdetailsInfo>();
        Map<String, String> selectedIdMap = new Map<String, String>();
        //取出选择的产品
        for (ConsumableorderdetailsInfo ass : pageRecords)  {
            //update by rentx 2021-2-26
            // if(ass.check == true){
                // selectedIdMap.put(ass.Prod.id,ass.Prod.id);
                // reSet.add(ass);
            // }
            if (ass.check == true) {
                if (ass.hospitalSpecialOffer == true) {
                    selectedIdMap.put(ass.Prod.Id +'ishos' , ass.Prod.Id);
                }else{
                    selectedIdMap.put(ass.Prod.Id +'nothos', ass.Prod.Id);
                }
                reSet.add(ass);
            }
            //update by rentx 2021-2-26 
 
        }
        pageRecords = new List<ConsumableorderdetailsInfo>();
        if (editAble && String.isBlank(arriveorder)){
            pageRecords = reSet;
        }
        Integer pagestartNo = (setCon.getPageNumber() * size)-size;
        Integer pageendNo = (setCon.getPageNumber() * size)>noOfRecords ? noOfRecords :(setCon.getPageNumber() * size-1);
        Integer addNo = 0;
        //update by rentx 2021-2-26 start
        for (ConsumableorderdetailsInfo info : consumableorderdetailsSelectRecords) {
 
            Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
            if ((info.hospitalSpecialOffer && selectedIdMap.containsKey(info.Prod.Id + 'ishos')) 
                || (info.hospitalSpecialOffer == false && selectedIdMap.containsKey(info.Prod.Id + 'nothos'))) {
                addNo++;
 
            }else{
                if(info.check == false){
                    info.orderdetails1 = orderdetails1;
                }
                pageRecords.add(info);
                addNo++;
            }
            // if(addNo >= size)break;
        }
        // for (Integer i = pagestartNo; i < consumableorderdetailsSelectRecords.size(); i++) {
        //     Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
        //     if(selectedIdMap.containsKey(consumableorderdetailsSelectRecords[i].Prod.Id)){
        //         addNo++;
        //         //continue;
        //     }else{
        //         //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '-----'));
        //         if(consumableorderdetailsSelectRecords[i].check == false){
        //             consumableorderdetailsSelectRecords[i].orderdetails1 = orderdetails1;
        //         }
        //         pageRecords.add(consumableorderdetailsSelectRecords[i]);
        //         addNo++;
        //     }
        //     if(addNo >= size)break;
        // }
        //update by rentx 2021-2-26 end
         return pageRecords;
    }
    //add by rentx 2021-2-26 start
    public void checkOutPattern(){
        //根据用户选中的产品给 出库单上的是否医院特价出库字段赋值
        Integer isHos = 0;
        for(ConsumableorderdetailsInfo CheckCount : pageRecords) {
            if (CheckCount.check == true && CheckCount.hospitalSpecialOffer == true) {
                ishos = ishos +1;
            }
        }
        if (isHos > 0) {
            coc.OutPattern__c = true;
        }else{
            coc.OutPattern__c = false;
        }
    }
    //add by rentx 2021-2-26 end
    // 画面初始化
    public   void init() {
 
        this.sortKey = '1';
        this.preSortKey = '1';
        this.sortOrderAsc = false;
        this.sortOrder = new String[8];
        this.sortOrder = new String[]{' ',' ',' ',' ','↓','','',''};
        //cate1ForSort = '';
        sumPrice = 0;
        IdCheck = EsetId;
        if(ESetId!=null&&ESetId!=''&&(statusEdit==''|| statusEdit==null)){
            editAble = false;
        }else if((ESetId == null||ESetId=='')&&(statusEdit==''||statusEdit==null)){
            editAble = true;
        }else if(ESetId != null&&ESetId!=''&&statusEdit!=''&&statusEdit!=null){
            editAble = true;
        }
        userId = UserInfo.getUserId();
        localuser = [select id, State_Hospital__c from User where id = :UserInfo.getUserId()];
        //userId = '00510000005QO75';
        user Useracc = [SELECT accountid, Work_Location__c,UserPro_Type__c FROM user WHERE id = :userId ];
        accountid = Useracc.accountid;
        userWorkLocation = Useracc.Work_Location__c;
        agencyProType = Useracc.UserPro_Type__c;
        if(String.isBlank(Useracc.UserPro_Type__c)){
            agencyProType = 'ET';
        }
        Account accountInfo = [SELECT Name FROM account WHERE id =:accountid];
        accountName = accountInfo.Name;
        //coc.Order_date__c = Date.today();
        list<Dealer_elationship__c> Dealerelationship = new list<Dealer_elationship__c>();
        Dealerelationship = [SELECT Dealer_subordinate__c,Dealer_subordinate__r.Name FROM Dealer_elationship__c WHERE Dealer_principal__c =:accountid ];
 
        List<Agency_Hospital_Link__c> AgencyHospitalLink = new List<Agency_Hospital_Link__c>();
        AgencyHospitalLink = [select Id,Hospital__c, Hospital__r.Name from Agency_Hospital_Link__c WHERE Agency__c = :accountid];
 
        //add by rentx 2021-3-1 start
        //判断当前经销商下是否有特价医院
        List<hospitalprice__c> hlist = [select id,product__c from hospitalprice__c where account__c = :accountid];
        if (hlist == null || hlist.size() == 0) {
            hasHos = false;
        }else{
            for (hospitalprice__c hp : hlist) {
                HosProMap.put(hp.product__c, '');
            }
            hasHos = true;
        }
        //add by rentx 2021-3-1 end
 
 
        saveBtnDisabled = false;
        SorderBtnDisabled = false;
        String sqlagencyProType = '%' + agencyProType + '%';
        coc = new Consumable_order__c();
        consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> MidMap = new Map<String,ConsumableorderdetailsInfo>();
        //add by rentx 2021-01-29
        Map<String,ConsumableorderdetailsInfo> MidMap2 = new Map<String,ConsumableorderdetailsInfo>();
        //add by rentx 2021-01-29
 
        List<AggregateResult> orderdetailCount = [SELECT count(id),Consumable_Product__c cpc,Box_Piece__c
                                                    FROM Consumable_order_details2__c
                                                    WHERE Dealer_Arrive__c = true
                                                    AND Dealer_Shipment__c = false
                                                    AND Dealer_Saled__c = false
                                                    AND Lose_Flag__c = false
                                                    AND Cancellation_Flag__c = false
                                                    AND Bar_Code__c !=null
                                                    AND Isoverdue__c = 1
                                                    AND Product_Type__c like : sqlagencyProType
                                                    AND Dealer_Info_text__c = :accountName
                                                    AND Arrive_Owner_Work_Location__c =: userWorkLocation
                                                    group by Consumable_Product__c,Box_Piece__c ];
        for(AggregateResult orderdetail : orderdetailCount){
            zaikuId.add(String.valueOf(orderdetail.get('cpc')));
        }
        List<Consumable_order_details2__c> CountDel = [SELECT Id,
                                                        Bar_Code__c,
                                                        Name,
                                                        Inventory_date__c,
                                                        Consumable_Product__c,
                                                        Consumable_Product__r.Asset_Model_No__c,
                                                        Recordtypeid,
                                                        Box_Piece__c,ProductPacking_list_manual__c,
                                                        //add by rentx 2020-11-27 start
                                                        hospitalSpecialOffer__c 
                                                        //add by rentx 2020-11-27 end
                                                    FROM Consumable_order_details2__c
                                                    WHERE Dealer_Arrive__c = true
                                                    AND Dealer_Shipment__c = false
                                                    AND Dealer_Saled__c = false
                                                    AND Dealer_Returned__c = false
                                                    AND Lose_Flag__c = false
                                                    AND Cancellation_Flag__c = false
                                                    AND Bar_Code__c !=null
                                                    AND Isoverdue__c = 1
                                                    AND Product_Type__c like : sqlagencyProType
                                                    AND Arrive_Owner_Work_Location__c =: userWorkLocation
                                                    AND Dealer_Info_text__c = :accountName ];
        // 新規
        if (ESetId== NULL || ESetId=='') {
            SummonsFlag = 'hidden';
            String msoql = makeSoqlinventory();
            initStandardController(msoql);
            product2Selected = Database.query(msoql);
            //product2Selected = product2s();
            if (String.isBlank(arriveorder)) {
                EditDelCommitBtnDisabled = true;
                for (Integer i = 0; i < product2Selected.size(); i++) {
                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
                }
                //update by rentx 2021-01-29
                /*for(Integer i = 0 ; i< CountDel.size();i++){
                    //然后循环CountDel去修改map里的allnumber
                    if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                        ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                        MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
                    }
 
                }*/
                for(Integer i = 0 ; i< CountDel.size();i++){
                    String str = '';
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        str = 'isHos';
                    }else{
                        str = 'notHos';
                    }
                    //明细2对应的产品存在于MidMap中
                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                        //设置map中key的后缀 用于区分医院特价和非医院特价
                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }else{
                            //midmap2中没有对应的产品
                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }
                    }
                    /*//然后循环CountDel去修改map里的allnumber
                    if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                        ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        if (CountDel[i].hospitalSpecialOffer__c) {
                            Jstage.hospitalSpecialOffer = true;
                        }else{
                            Jstage.hospitalSpecialOffer = false;
                        }
                        //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                        MidMap.put(CountDel[i].Consumable_Product__c+str, Jstage);
                    }*/
 
                }
 
                //update by rentx 2021-01-29 end
 
 
                //再把map里的值从新赋给ConsumableorderdetailsRecords
                //update by rentx 2021-01-29
                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
                for(ConsumableorderdetailsInfo bss : MidMap2.values()){
                //update by rentx 2021-01-29
                    //if(bss.allnumber>0){
                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                        consumableorderdetailsSelectRecords.add(bss);
                    //}
                }
                
                Integer ishosnum = 0;
                for(ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords){
                    ass.sortBy = this.sortOrderAsc;
                    //add by rentx 2021-3-10
                    if (ass.hospitalSpecialOffer) {
                        ishosnum = ishosnum +1;
                    }
                }
                if (ishosnum > 0) {
                    hasHosPro = true;
                }else{
                    hasHosPro = false;
                }
                consumableorderdetailsSelectRecords.sort();
                //add by rentx
                noOfRecords = consumableorderdetailsSelectRecords.size();
                //add by rentx
                makepagerecords();
                //listCut();
 
 
            } else {
                if(statusEdit=='' || statusEdit==null){
                    editAble = false;
                }else if(statusEdit!=''&&statusEdit!=null){
                    editAble = true;
                }
                // upadte start by vivek 2019-7-15
                // coc = [SELECT Id,Name,Summons_Order_type__c,SummonsStatus_c__c,Order_ForDealerText__c,
                //             Dealer_Info__c,Order_ForDealer__c,Order_ForDealer__r.Name,Order_ForDealerTextID__c,
                //             Order_ForHospital__c,SummonsForDirction__c,Order_date__c,Arrive_Order__c,
                //             Order_status__c,Shipment_total_amount__c,Offers_Price__c,
                //             Billed_Status__c,ShipmentAccount__c,Order_Dealer_Info__c,Order_ForCustomerText__c,ConInvoice_Code__c,Onchange_order__c
                //         FROM Consumable_order__c
                //         WHERE Id =:arriveorder AND Order_Owner_WorkLocal__c =: userWorkLocation
                //         AND recordtypeid = :System.Label.RT_ConOrder_Arrive];
                coc = [SELECT Id,Name,Summons_Order_type__c,NoConfirmedPrice__c,SummonsStatus_c__c,Order_ForDealerText__c,
                            Dealer_Info__c,Order_ForDealer__c,Order_ForDealer__r.Name,Order_ForDealerTextID__c,
                            Order_ForHospital__c,SummonsForDirction__c,Order_date__c,Arrive_Order__c,
                            Order_status__c,Shipment_total_amount__c,Offers_Price__c,
                            Billed_Status__c,ShipmentAccount__c,Order_Dealer_Info__c,Order_ForCustomerText__c,ConInvoice_Code__c,Onchange_order__c,OutPattern__c 
                        FROM Consumable_order__c
                        WHERE Id =:arriveorder AND Order_Owner_WorkLocal__c =: userWorkLocation
                        AND recordtypeid = :System.Label.RT_ConOrder_Arrive];
                // update end by vivek 2019-7-15
                //明细1获取
                consumableorderdetailsSelected = [SELECT Id,Dealer_Custom_Price__c,Delivery_List_RMB__c,
                                                    Consumable_Product__r.Name__c, Name, Consumable_order__c,
                                                    Consumable_Product__c,Consumable_Product__r.Name,Consumable_Product__r.Category3__c,
                                                    Consumable_Product__r.Category4__c,Consumable_Product__r.Category5__c,
                                                    Shipment_Count__c,Consumable_Product__r.Intra_Trade_List_RMB__c,
                                                    Consumable_Product__r.Asset_Model_No__c,Sum_of_money__c,Box_Piece__c,
                                                    ProductPacking_list_manual__c,Consumable_Product__r.SFDA_Status__c,
                                                    Consumable_count__c,Invoiced_Procount__c,
                                                    RrturnPro_count__c,
                                                    InvoiceProNot_count__c,
                                                    //Unitprice_To_agency__c,
                                                    Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
                                                    Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c
                                                FROM Consumable_Orderdetails__c
                                                WHERE Consumable_order__c = :coc.Arrive_Order__c
                                                order by Name ];
                for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
                    orderzaikuId.add(cdc1.Consumable_Product__c);
                }
                msoql = makeSoqlorderdet();
                product2Selected = Database.query(msoql);
                size = product2Selected.size();
                initStandardController(msoql);
                for (Integer i = 0; i < product2Selected.size(); i++) {
                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
                }
                //update by rentx 2021-01-29 
                /*for(Integer i = 0 ; i< CountDel.size();i++){
                    //然后循环CountDel去修改map里的allnumber
                    if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                        ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                        MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
                    }
 
                }*/
                for (Integer i = 0; i<CountDel.size() ; i++) {
                    String str = '';
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        str = 'isHos';
                    }else{
                        str = 'notHos';
                    }
                    //明细2对应的产品存在于MidMap中
                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                        //设置map中key的后缀 用于区分医院特价和非医院特价
                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
 
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }else{
                            //midmap2中没有对应的产品
                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
 
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }
                    }
                }
 
                //再把map里的值从新赋给ConsumableorderdetailsRecords
                //update by rentx 2021-01-29 
                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
                for(ConsumableorderdetailsInfo bss : MidMap2.values()){
                //update by rentx 2021-01-29 
                    bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                    consumableorderdetailsSelectRecords.add(bss);
                }
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'test11111' + consumableorderdetailsSelected.size()));
                //return;
 
                Integer ishosnum = 0;
                for(ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords){
                    ass.sortBy = this.sortOrderAsc;
                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
                        cdc1.Shipment_Count__c = cdc1.Consumable_count__c;
                        if(ass.prod.Id == cdc1.Consumable_Product__c){
                            ass.check = true;
                            ass.orderdetails1 = cdc1;
                        }
                    }
                    if (ass.hospitalSpecialOffer == true) {
                        ishosnum = ishosnum + 1;
                    }
                }
                if (ishosnum > 0) {
                    hasHosPro = true;
                }else{
                    hasHosPro = false;
                }
 
                consumableorderdetailsSelectRecords.sort();
                //add by rentx
                noOfRecords = consumableorderdetailsSelectRecords.size();
                //add by rentx
                makepagerecords();
                consumablearriveproductdetailsSelected = [
                        SELECT Id,
                            Name,
                            Intra_Trade_List_RMB__c,
                            Asset_Model_No__c,
                            Consumable_Product__c,
                            Consumable_Product__r.Name,
                            Consumable_Product__r.Name__c,
                            Consumable_Product__r.Category3__c,
                            Consumable_Product__r.Category4__c,
                            Consumable_Product__r.Category5__c,
                            Sterilization_limit__c,
                            Deliver_date__c,
                            Bar_Code__c,
                            Arrive_date__c,
                            Send_Date__c,
                            Consumable_order_minor__r.Name,
                            Consumable_order_minor__c,
                            Dealer_Arrive__c,
                            Delivery_List_RMB__c,
                            Box_Piece__c,ProductPacking_list_manual__c,
                            //add by rentx start
                            hospitalSpecialOffer__c
                            //add by rentx end
                        FROM Consumable_order_details2__c
                        WHERE Consumable_order_minor__c = :coc.Arrive_Order__c
                        AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                        AND Dealer_Arrive__c = true
                        order by Name];
                for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
                    if (consumablearriveproductdetailsSelected[i].hospitalSpecialOffer__c && HosProMap.containsKey(consumablearriveproductdetailsSelected[i].Consumable_product__c)) {
                        coc.OutPattern__c = true;
                    }
                    consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
                }
            }
        }
        // 更新、
        else {
            SummonsFlag = 'visible';
            // update start by vivek 2019-7-15 add “NoConfirmedPrice__c” in select
            consumableInvoiceRecords  = [SELECT Id,Name,Invoice_Date__c,NoConfirmedPrice__c,Invoice_total_amount__c,Invoice_status__c
                    FROM Consumable_order__c
                    WHERE Id in (select Invoice_Code_link__c FROM Consumable_order_LinkTable__c WHERE Outboundorder_Code_link__c = :ESetId)
                    AND Invoice_status__c != '草案中'];
 
            coc = [SELECT Id,Name,Summons_Order_type__c,NoConfirmedPrice__c,SummonsStatus_c__c,Order_ForDealerText__c,
                        Dealer_Info__c,Order_ForDealer__c,Order_ForDealer__r.Name,Order_ForDealerTextID__c,
                        Order_ForHospital__c,SummonsForDirction__c,Order_date__c,Arrive_Order__c,
                        Order_status__c,Shipment_total_amount__c,Offers_Price__c,
                        Billed_Status__c,ShipmentAccount__c,Order_Dealer_Info__c,Order_ForCustomerText__c,ConInvoice_Code__c,Onchange_order__c,OutPattern__c
                    FROM Consumable_order__c
                    WHERE Id =:ESetId AND Order_Owner_WorkLocal__c =: userWorkLocation
                    AND Order_type__c = '传票'];
            // update start by vivek 2019-7-15
            if(getExistarrive()){
                arriveorder = coc.Arrive_Order__c;
            }
            // 到货订单来的时候
            if (getExistarrive()) {
                if(editAble){
                    alertMessage = '到货订单直接出库,出库单明细不可编辑。';
                }
                if(coc.SummonsStatus_c__c == '已提交' || coc.SummonsStatus_c__c == '批准'){
                    system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
                    saveBtnDisabled = true;
                    SorderBtnDisabled = true;
                    EditDelCommitBtnDisabled = false;
                }
                //医院二级经销商分类
                Integer io = 0;
                while( io < Dealerelationship.size()){
                    if(coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c){
                        SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
                        coc.Order_ForDealer__c = null;
                        io = io+Dealerelationship.size();
                     }
                     io++;
                }
 
                Integer ik = 0;
                while( ik < AgencyHospitalLink.size()){
                    if(coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c){
                        HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
                        HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
                        coc.Order_ForHospital__c = null;
                        ik = ik+AgencyHospitalLink.size();
                     }
                     ik++;
                }
                //出库单明细1取得
                consumableorderdetailsSelected = [SELECT Id,
                                                        Dealer_Custom_Price__c,
                                                        Delivery_List_RMB__c,
                                                        Consumable_Product__r.Name__c,
                                                        Consumable_Product__r.SFDA_Status__c,
                                                        Name, Consumable_order__c,
                                                        Consumable_Product__c,
                                                        Consumable_Product__r.Name,
                                                        Shipment_Count__c,
                                                        Consumable_Product__r.Intra_Trade_List_RMB__c,
                                                        Consumable_Product__r.Asset_Model_No__c,
                                                        Consumable_Product__r.Category3__c,
                                                        Consumable_Product__r.Category4__c,
                                                        Consumable_Product__r.Category5__c,
                                                        Shipment_amount__c,
                                                        //Unitprice_To_agency__c,
                                                        Box_Piece__c,ProductPacking_list_manual__c
                                                        ,Invoiced_Procount__c,
                                                        RrturnPro_count__c,
                                                        InvoiceProNot_count__c,
                                                        Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
                                                        Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c
                                                        ,isOutPattern__c
                                                     FROM Consumable_orderdetails__c
                                                     WHERE Consumable_order__c = :ESetId
                                                     AND Consumable_order__r.Order_Owner_WorkLocal__c =: userWorkLocation
                                                     order by Name ];
                Map<String,Consumable_Orderdetails__c> cocMap = new Map<String,Consumable_Orderdetails__c>();
 
                for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
                    sumPrice += cdc1.Shipment_amount__c;
                    orderzaikuId.add(cdc1.Consumable_Product__c);
                    //add by rentx 2021-2-26
                    String tempId = cdc1.Consumable_product__c;
                    if (cdc1.isOutPattern__c) {
                        cocMap.put(tempId+'ishos', cdc1);
                    }else{
                        cocMap.put(tempId+'nothos', cdc1);
                    }
                    //add by rentx 2021-2-26
                }
                String msoql = makeSoqlorderdet();
                product2Selected = Database.query(msoql);
                size = product2Selected.size();
                initStandardController(msoql);
 
 
                for (Integer i = 0; i < product2Selected.size(); i++) {
                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
                }
                //update by rentx 2021-01-29
                /*for(Integer i = 0 ; i< CountDel.size();i++){
                    //然后循环CountDel去修改map里的allnumber
                    if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                        ConsumableorderdetailsInfo Jstage =  MidMap.get(CountDel[i].Consumable_Product__c);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                        MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
                    }
                }*/
 
                for (Integer i = 0; i < CountDel.size() ;i++ ) {
                    String str = '';
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        str = 'isHos';
                    }else{
                        str = 'notHos';
                    }
                    //明细2对应的产品存在于MidMap中
                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                        //设置map中key的后缀 用于区分医院特价和非医院特价
                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
 
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }else{
                            //midmap2中没有对应的产品
                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }
                    }
                }
                //update by rentx 2021-01-29
                consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
                //再把map里的值从新赋给ConsumableorderdetailsRecords
                //update by rentx 2021-01-29 
                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
                for(ConsumableorderdetailsInfo bss : MidMap2.values()){
                //update by rentx 2021-01-29 
 
                    //if(bss.allnumber > 0){
                    //bss.UnitpriceToagency = bss.orderdetails1.Unitprice_To_agency__c == null  || bss.orderdetails1.Unitprice_To_agency__c == 0 ? '' :bss.orderdetails1.Unitprice_To_agency__c.format();
                    bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
 
                    //update by rentx 2021-2-26 start
                        if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
                            consumableorderdetailsSelectRecords.add(bss);
                        }else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
                            consumableorderdetailsSelectRecords.add(bss);
                        }
                    //update by rentx 2021-2-26 end
                    // consumableorderdetailsSelectRecords.add(bss);
                    //}
                }
                Integer ishosnum = 0;
                for(ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords){
                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
                        //update by rentx 2012-3-1 start
                        // if(ass.prod.Id == cdc1.Consumable_Product__c){
                        //     ass.check = true;
                        //     ass.orderdetails1 = cdc1;
                        // }
                        if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
                            ass.check = true;
                            ass.orderdetails1 = cdc1;
                        }
                        //update by rentx 2012-3-1 end
                    }
                    if (ass.hospitalSpecialOffer == true) {
                        ishosnum = ishosnum + 1;
                    }
                }
                 if (ishosnum > 0) {
                    hasHosPro = true;
                }else{
                    hasHosPro = false;
                }
 
                //add by rentx
                noOfRecords = consumableorderdetailsSelectRecords.size();
                //add by rentx
                makepagerecords();
                //listCut();
                // 消耗品明细2を取得
                consumableorderdetails2RecordsList = [SELECT Id,
                                                        Name,
                                                        SerialLotNo__c,
                                                        Consumable_Product__r.Name__c,
                                                        TracingCode__c,
                                                        Sterilization_limit__c,
                                                        Consumable_Product__c,
                                                        Consumable_Product__r.Name,
                                                        Consumable_Product__r.Category3__c,
                                                        Consumable_Product__r.Category4__c,
                                                        Consumable_Product__r.Category5__c,
                                                        Return_date__c,
                                                        Invoice_Date__c,
                                                        Box_Piece__c,ProductPacking_list_manual__c,
                                                        //add by rentx start
                                                        hospitalSpecialOffer__c
                                                        //add by rentx end
                                                        FROM Consumable_order_details2__c
                                                        WHERE Consumable_ZS_order__c = :ESetId
                                                        order by Name ];
                for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
                    consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
                }
                //产品明细取得
                consumablearriveproductdetailsSelected = [SELECT Id,Delivery_List_RMB__c,
                                                        Consumable_Product__r.Name__c, Name,
                                                        Consumable_Product__r.SFDA_Status__c,Consumable_Product__r.Category3__c,
                                                        Consumable_Product__r.Category4__c,Consumable_Product__r.Category5__c,
                                                        Consumable_Product__c,Consumable_Product__r.Name, Sterilization_limit__c,
                                                        Consumable_Product__r.Intra_Trade_List_RMB__c,
                                                        Consumable_Product__r.Asset_Model_No__c,Box_Piece__c,
                                                        ProductPacking_list_manual__c,
                                                        //add by rentx start
                                                        hospitalSpecialOffer__c
                                                        //add by rentx end
                                                        FROM Consumable_order_details2__c
                                                        WHERE Consumable_ZS_order__c = :ESetId
                                                        order by Name];
                for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
                    consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
                }
            }
            // 不是到货订单来的时候
            else {
                if(coc.SummonsStatus_c__c == '已提交' || coc.SummonsStatus_c__c == '批准'){
                    system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
                    saveBtnDisabled = true;
                    SorderBtnDisabled = true;
                    EditDelCommitBtnDisabled = false;
                }
                //医院二级经销商分类
                Integer io = 0;
                while( io < Dealerelationship.size()){
                    if(coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c){
                        SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
                        coc.Order_ForDealer__c = null;
                        io = io+Dealerelationship.size();
                     }
                     io++;
                }
                Integer ik = 0;
                while( ik < AgencyHospitalLink.size()){
                    if(coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c){
                        HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
                        HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
                        coc.Order_ForHospital__c = null;
                        ik = ik+AgencyHospitalLink.size();
                     }
                     ik++;
                }
                // 消耗品明细1を取得
                consumableorderdetailsSelected = [SELECT Id,
                                                        Dealer_Custom_Price__c,
                                                        Delivery_List_RMB__c,
                                                        Consumable_Product__r.Name__c,
                                                        Consumable_Product__r.SFDA_Status__c,
                                                        Name, Consumable_order__c,
                                                        Consumable_Product__c,
                                                        Consumable_Product__r.Name,
                                                        Shipment_Count__c,
                                                        Consumable_Product__r.Intra_Trade_List_RMB__c,
                                                        Consumable_Product__r.Asset_Model_No__c,
                                                        Shipment_amount__c,
                                                        Box_Piece__c,ProductPacking_list_manual__c
                                                        ,Invoiced_Procount__c,
                                                        RrturnPro_count__c,
                                                        //Unitprice_To_agency__c,
                                                        InvoiceProNot_count__c,
                                                        Consumable_Product__r.Category3__c,
                                                        Consumable_Product__r.Category4__c,Consumable_Product__r.Category5__c,
                                                        Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
                                                        Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c
                                                        ,isOutPattern__c
                                                        FROM Consumable_orderdetails__c
                                                        WHERE Consumable_order__c = :ESetId
                                                        AND Consumable_order__r.Order_Owner_WorkLocal__c =: userWorkLocation
                                                        order by Name ];
                //add by rentx 202-2-26
                Map<String,Consumable_Orderdetails__c> cocMap = new Map<String,Consumable_Orderdetails__c>();
 
                for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
                    sumPrice += cdc1.Shipment_amount__c;
                    orderzaikuId.add(cdc1.Consumable_Product__c);
                    //add by rentx 2021-2-26
                    String tempId = cdc1.Consumable_product__c;
                    if (cdc1.isOutPattern__c) {
                        cocMap.put(tempId+'ishos', cdc1);
                    }else{
                        cocMap.put(tempId+'nothos', cdc1);
                    }
                    //add by rentx 2021-2-26
 
                }
 
                String msoql = makeSoqlorderdet();
                product2Selected = Database.query(msoql);
                size = product2Selected.size();
                initStandardController(msoql);
                for (Integer i = 0; i < product2Selected.size(); i++) {
                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
                }
                //update by rentx 2021-01-29
                /*for(Integer i = 0 ; i< CountDel.size();i++){
                    //然后循环CountDel去修改map里的allnumber
                    if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                        ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                        MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
                    }
 
                }
                */
                for (Integer i = 0; i<CountDel.size() ;i++ ) {
                    String str = '';
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        str = 'isHos';
                    }else{
                        str = 'notHos';
                    }
                    //明细2对应的产品存在于MidMap中
                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                        //设置map中key的后缀 用于区分医院特价和非医院特价
                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }else{
                            //midmap2中没有对应的产品
                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            //add by rentx 202-2-26
                            //是医院特价出库产品
                            // if (cocMap.get(CountDel[i].Consumable_Product__c+'ishos') != null ) {
 
                            //     Jstage.hospitalSpecialOffer = true;
                            //     MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
 
                            // }else if (cocMap.get(CountDel[i].Consumable_Product__c+'nothos') != null) {
                            //     Jstage.hospitalSpecialOffer = false;
                            //     MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                            
                            // }
                            //add by rentx 2021-2-26
 
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }
                    }
                }
 
 
 
                //再把map里的值从新赋给ConsumableorderdetailsRecords
                //update by rentx 2021-01-29 
                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
                for(ConsumableorderdetailsInfo bss : MidMap2.values()){
 
                //update by rentx 2021-01-29 
 
                    //if(bss.allnumber>0){
                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
 
                        //update by rentx 2021-2-26 start
                        if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
                            consumableorderdetailsSelectRecords.add(bss);
                        }else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
                            consumableorderdetailsSelectRecords.add(bss);
                        }
                        // consumableorderdetailsSelectRecords.add(bss);
                    //}
                }
        // return null;
                Integer ishosnum = 0;
                for(ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords){
                    ass.sortBy = this.sortOrderAsc;
                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
                        //update by rentx 2012-3-1 start
                        // if(ass.prod.Id == cdc1.Consumable_Product__c){
                        //     ass.check = true;
                        //     ass.orderdetails1 = cdc1;
                        // }
                        if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
                            ass.check = true;
                            ass.orderdetails1 = cdc1;
                        }
                        //update by rentx 2012-3-1 end
                    }
 
                    if (ass.hospitalSpecialOffer == true) {
                        ishosnum = ishosnum + 1;
                    }
                }
 
                 if (ishosnum > 0) {
                    hasHosPro = true;
                }else{
                    hasHosPro = false;
                }
 
                consumableorderdetailsSelectRecords.sort();                    
                //add by rentx
                noOfRecords = consumableorderdetailsSelectRecords.size();
                //add by rentx
                makepagerecords();
 
                // 消耗品明细2を取得
                consumableorderdetails2RecordsList = [SELECT Id,
                                                        Name,
                                                        SerialLotNo__c,
                                                        Consumable_Product__r.Name__c,
                                                        TracingCode__c,
                                                        Sterilization_limit__c,
                                                        Consumable_Product__c,
                                                        Consumable_Product__r.Name,
                                                        Consumable_Product__r.Category3__c,
                                                        Consumable_Product__r.Category4__c,
                                                        Consumable_Product__r.Category5__c,
                                                        Return_date__c,
                                                        Invoice_Date__c,
                                                        Box_Piece__c,ProductPacking_list_manual__c,
                                                        //add by rentx start
                                                        hospitalSpecialOffer__c
                                                        //add by rentx end
 
                                                        FROM Consumable_order_details2__c
                                                        WHERE Consumable_ZS_order__c = :ESetId
                                                        order by Name ];
                for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
                    consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
                }
            }
        }
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'test++++++' + SecondDealer));
        if(SecondDealer==null||SecondDealer==''){
            provinceOpts.add(new SelectOption('', '-无-'));
            for(Integer i = 0; i < Dealerelationship.size(); i++){
                provinceOpts.add(new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name));
            }
        }else{
            provinceOpts.add(new SelectOption('', '-无-'));
            for(Integer i = 0; i < Dealerelationship.size(); i++){
                if(Dealerelationship[i].Dealer_subordinate__c == SecondDealer){
                    provinceOpts.add(new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name));
                }
            }
            for(Integer i = 0; i < Dealerelationship.size(); i++){
                if(Dealerelationship[i].Dealer_subordinate__c != SecondDealer){
                    provinceOpts.add(new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name));
                }
            }
        }
 
        /*if(HospitalInfo==null||HospitalInfo==''){
            orderForHospitalOpts.add(new SelectOption('', '-无-'));
            for(Integer i = 0; i < AgencyHospitalLink.size(); i++){
                orderForHospitalOpts.add(new SelectOption(AgencyHospitalLink[i].Hospital__c, AgencyHospitalLink[i].Hospital__r.Name));
            }
        }else{
            orderForHospitalOpts.add(new SelectOption('', '-无-'));
            for(Integer i = 0; i < AgencyHospitalLink.size(); i++){
                if(AgencyHospitalLink[i].Hospital__c == HospitalInfo){
                    orderForHospitalOpts.add(new SelectOption(AgencyHospitalLink[i].Hospital__c, AgencyHospitalLink[i].Hospital__r.Name));
                }
            }
            for(Integer i = 0; i < AgencyHospitalLink.size(); i++){
                if(AgencyHospitalLink[i].Hospital__c != HospitalInfo){
                    orderForHospitalOpts.add(new SelectOption(AgencyHospitalLink[i].Hospital__c, AgencyHospitalLink[i].Hospital__r.Name));
                }
            }
        }*/
        //listCut();
 
        Schema.DescribeFieldResult dfr = Product2__c.Intra_Trade_List_RMB__c.getDescribe();
        cansee = dfr.isAccessible();
        Schema.DescribeFieldResult dealerPrice = Consumable_orderdetails__c.Dealer_Custom_Price__c.getDescribe();
        dealerPricesee = dealerPrice.isAccessible();
        // 显示数据条数信息
        //    makeMessage();
        //附件
        attachmentinfo =[SELECT Id, Name,OwnerId FROM Attachment WHERE  parentid =:ESetId  ];
        if(attachmentinfo.size()>0){
            for (Integer i = 0; i < attachmentinfo.size(); i++) {
                attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
            }
        }
        AggregateResult[] categoryList = [select Count(id), Category3_text__c c3c from Product2__c WHERE Category3_text__c != null group by Category3_text__c];
        
         categoryOptionList = new List<SelectOption>();
         categoryOptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category3Search : categoryList) {
            String deliverycnt = String.valueOf(category3Search.get('c3c'));
            categoryOptionList.add(new SelectOption(deliverycnt,deliverycnt));
         }
 
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-无-'));
         /*for(AggregateResult category4Search : category4List) {
            String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
            category4OptionList.add(new SelectOption(deliverycnt4,deliverycnt4));
         }*/
        
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-无-'));
         /*for(AggregateResult category5Search : category5List) {
            String deliverycnt5 = String.valueOf(category5Search.get('c5c'));
            category5OptionList.add(new SelectOption(deliverycnt5,deliverycnt5));
         }*/
    }
  public void categoryAllload() {
         AggregateResult[] category4List = [select Count(id), Category4_text__c c4c from Product2__c WHERE Category3_text__c=:category3 AND Category4_text__c != null AND Category5_text__c != null group by Category4_text__c];
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category4Search : category4List) {
            String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
            category4OptionList.add(new SelectOption(deliverycnt4,deliverycnt4));
         }
 
           AggregateResult[] category5List = [select Count(id), Category5_text__c c5c from Product2__c WHERE Category3_text__c=:category3 AND Category4_text__c != null AND Category5_text__c != null group by Category5_text__c];
        
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category5Search : category5List) {
            String deliverycnt5 = String.valueOf(category5Search.get('c5c'));
            category5OptionList.add(new SelectOption(deliverycnt5,deliverycnt5));
         }
 
    }
    
    public void categoryload() {
         AggregateResult[] category4List = [select Count(id), Category4_text__c c4c from Product2__c WHERE Category3_text__c=:category3 AND Category4_text__c != null AND Category5_text__c != null group by Category4_text__c];
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category4Search : category4List) {
            String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
            category4OptionList.add(new SelectOption(deliverycnt4,deliverycnt4));
         }
 
           AggregateResult[] category5List = [select Count(id), Category5_text__c c5c from Product2__c WHERE Category3_text__c=:category3 AND Category4_text__c=:category4 AND Category5_text__c != null group by Category5_text__c];
        
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-无-'));
         for(AggregateResult category5Search : category5List) {
            String deliverycnt5 = String.valueOf(category5Search.get('c5c'));
            category5OptionList.add(new SelectOption(deliverycnt5,deliverycnt5));
         }
 
    }
    //开票,保存出库单
    /*public void upchangeorder(){
        Consumable_order__c p = new Consumable_order__c();
        if(coc.ConInvoice_Code__c != null){
            p.ConInvoice_Code__c = coc.ConInvoice_Code__c;
            p.Onchange_order__c = true;
            update p;
        }
    }*/
 
    //库存排序
    /*public void SortStore(){
        if (this.sortKey == this.preSortKey) {
            // 方向が変わるのみ
            this.sortOrderAsc = !this.sortOrderAsc;
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        } else {
            this.sortOrderAsc = true;
            this.sortOrder[Integer.valueOf(this.preSortKey)] = ' ';
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        }
        this.preSortKey = this.sortKey;
        //取出被选中的部分
        List<ConsumableorderdetailsInfo> ConsumableorderdetailsChecked = new List<ConsumableorderdetailsInfo>();
        List<ConsumableorderdetailsInfo> ConsumableorderdetailsUnChecked = new List<ConsumableorderdetailsInfo>();
        for(ConsumableorderdetailsInfo Checked : consumableorderdetailsSelectRecords){
            if(Checked.Check == true){
                Checked.sortBy = this.sortOrderAsc;
                ConsumableorderdetailsChecked.add(Checked);
            }else{
                Checked.sortBy = this.sortOrderAsc;
                ConsumableorderdetailsUnChecked.add(Checked);
            }
        }
        //已选择的明细
        ConsumableorderdetailsChecked.sort();
        //未选择的明细
        ConsumableorderdetailsUnChecked.sort();
 
        consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
        for(ConsumableorderdetailsInfo CheckedAdd : ConsumableorderdetailsChecked){
            consumableorderdetailsSelectRecords.add(CheckedAdd);
        }
        for(ConsumableorderdetailsInfo UncheckedAdd : ConsumableorderdetailsUnChecked){
            consumableorderdetailsSelectRecords.add(UncheckedAdd);
        }
        //makeMessage();
        //listCut();
    }*/
 
    /**
     * 選択済み/未選択製品の置き換え
     */
    /*public PageReference exchangeConsumableProduct() {
        List<ConsumableorderdetailsInfo> tmpChecked = new List<ConsumableorderdetailsInfo>();
        List<ConsumableorderdetailsInfo> tmpUnChecked = new List<ConsumableorderdetailsInfo>();
        for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
            if (ass.check) {
                tmpChecked.add(ass);
            } else {
                tmpUnChecked.add(ass);
            }
        }
        for (ConsumableorderdetailsInfo ass : consumableorderdetailsunSelectRecords) {
            if (ass.check) {
                tmpChecked.add(ass);
            } else {
                tmpUnChecked.add(ass);
            }
        }
        //选择明细
        consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
        for (ConsumableorderdetailsInfo ass : tmpChecked) {
            consumableorderdetailsSelectRecords.add(ass);
        }
        //未选择明细
        consumableorderdetailsunSelectRecords = new List<ConsumableorderdetailsInfo>();
        consumableorderdetailsunSelectRecords.addAll(tmpUnChecked);
        listCut();
        System.debug('exchangeConsumableProduct end');
        return null;
    } */
 
    //打印PDF
    public PageReference PraseToPDF(){
        if(coc.SummonsStatus_c__c =='批准'){
            Consumable_order__c P = new Consumable_order__c();
            List<Consumable_order__c> cocinfo = New List<Consumable_order__c>();
            // update start by vivek 2019-7-15 add “NoConfirmedPrice__c” in select 
            cocinfo = [SELECT Id,Name,SummonsStatus_c__c,NoConfirmedPrice__c,Dealer_Info__c,Order_ForHospital__c,SummonsForDirction__c,Billed_Status__c FROM Consumable_order__c WHERE Id =:ESetId];
            // update end by vivek 2019-7-15
                if (cocinfo.size()>0){
                    p = cocinfo[0];
                }
            p.SummonsStatus_c__c = '出库单已打印';
            update p;
        }
        return UnabletoEdit();
    }
    //限制性排序
    public void SortLimited(){
        List<ConsumableorderdetailsInfo> reSet = new List<ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> MidMap = new Map<String,ConsumableorderdetailsInfo>();
        //add by rentx 2021-01-29
        Map<String,ConsumableorderdetailsInfo> MidMap2 = new Map<String,ConsumableorderdetailsInfo>();
        //add by rentx 2021-01-29
 
        List<Consumable_order_details2__c> CountDel = [SELECT Id,
                                                            Bar_Code__c,
                                                            Name,Inventory_date__c,
                                                            Consumable_Product__c,
                                                            Consumable_Product__r.Asset_Model_No__c,
                                                            Recordtypeid,Box_Piece__c,ProductPacking_list_manual__c,
                                                            //add by rentx start
                                                            hospitalSpecialOffer__c
                                                            //add by rentx end
                                                        FROM Consumable_order_details2__c
                                                        WHERE Dealer_Arrive__c = true
                                                        AND Dealer_Shipment__c = false
                                                        AND Dealer_Saled__c = false
                                                        AND Dealer_Returned__c = false
                                                        AND Lose_Flag__c = false
                                                        AND Bar_Code__c !=null
                                                        AND Isoverdue__c = 1
                                                        AND Arrive_Owner_Work_Location__c =: userWorkLocation
                                                        //AND Consumable_order_minor__r.Dealer_Info__c = :accountid
                                                        AND Dealer_Info_text__c = :accountName];
        if (this.sortKey == this.preSortKey) {
            // 方向が変わるのみ
            this.sortOrderAsc = !this.sortOrderAsc;
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        } else {
            this.sortOrderAsc = true;
            this.sortOrder[Integer.valueOf(this.preSortKey)] = '';
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        }
        this.preSortKey = this.sortKey;
        // 所有产品取得
        if((EsetId==null||ESetId=='')||(EsetId!=null&&ESetId!=''&&statusEdit== 'Redirect'&&SearchDone=='SearchDone')){
            if(!String.isEmpty(arriveorder)){
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '00000'));
                //orderzaikuId.clear();
                String strProd = null;
                for (ConsumableorderdetailsInfo ass : pageRecords)  {
                    //orderzaikuId.add(ass.prod.Id);
                    if(strProd==null || strProd.length()==0){
                        strProd = '\'' + String.valueOf(ass.prod.Id) + '\'';
                    }
                    else{
                        strProd += ',\'' + String.valueOf(ass.prod.Id) + '\'';
                    }
                }
                String soql = 'SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,Product2__r.Packing_list_manual__c,SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Category3__c,Category4__c,Category5__c  FROM Product2__c ';
                //soql += ' WHERE Estimation_Entry_Possibility__c = \'○\'';
                soql += ' WHERE Id IN (' + strProd + ')';
                soql += ' order by ' + this.columus_no[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
                List<Product2__c> product2List = Database.query(soql);
 
                for (Integer i = 0; i < product2List.size(); i++) {
                    MidMap.put(product2List[i].Id, new ConsumableorderdetailsInfo(product2List[i]));
                }
                pageRecords= new List<ConsumableorderdetailsInfo>();
 
                //update by rentx 2021-01-29
                /*for(Integer i = 0 ; i< CountDel.size();i++){
                    //然后循环CountDel去修改map里的allnumber
                    if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                        ConsumableorderdetailsInfo Jstage =  MidMap.get(CountDel[i].Consumable_Product__c);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
                    }
                }*/
                for (Integer i = 0; i<CountDel.size() ; i++ ) {
                    String str = '';
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        str = 'isHos';
                    }else{
                        str = 'notHos';
                    }
                    //明细2对应的产品存在于MidMap中
                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                        //设置map中key的后缀 用于区分医院特价和非医院特价
                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }else{
                            //midmap2中没有对应的产品
                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }
                    }
                }
                //update by rentx 2021-01-29
                
                //再把map里的值从新赋给ConsumableorderdetailsRecords 
                //update by rentx 2021-01-29 
                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
                for(ConsumableorderdetailsInfo bss : MidMap2.values()){
                //update by rentx 2021-01-29 
 
                    //if(selectedIdMap.containsKey(bss.orderdetails1.id)){
                    //    continue;
                    //}else{
                        //if(bss.allnumber > 0){
                    bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                    pageRecords.add(bss);
                        //}
                    //}
                }
                List<Consumable_orderdetails__c> queryList = [SELECT Id,Dealer_Custom_Price__c,Delivery_List_RMB__c,
                                                    Consumable_Product__r.Name__c, Name, Consumable_order__c,
                                                    Consumable_Product__c,Consumable_Product__r.Name,Consumable_Product__r.Category3__c,
                                                    Consumable_Product__r.Category4__c,Consumable_Product__r.Category5__c,
                                                    Shipment_Count__c,Consumable_Product__r.Intra_Trade_List_RMB__c,
                                                    Consumable_Product__r.Asset_Model_No__c,Sum_of_money__c,Box_Piece__c,
                                                    ProductPacking_list_manual__c,Consumable_Product__r.SFDA_Status__c,
                                                    Consumable_count__c,Invoiced_Procount__c,
                                                    RrturnPro_count__c,
                                                    InvoiceProNot_count__c,
                                                    //Unitprice_To_agency__c,
                                                    Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
                                                    Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c
                                                FROM Consumable_Orderdetails__c
                                                WHERE Consumable_order__c = :consumableorderId
                                                AND Order_Owner_WorkLocal__c = : userWorkLocation
                                                order by Name ];
 
 
                /*String SqlOrder = 'SELECT Id,Dealer_Custom_Price__c,Delivery_List_RMB__c,Consumable_Product__r.Name__c, Name, Consumable_order__c,';
                SqlOrder += 'Consumable_Product__c,Consumable_Product__r.Name,Shipment_Count__c,Consumable_Product__r.Intra_Trade_List_RMB__c,';
                SqlOrder += 'Consumable_Product__r.Category3__c,Consumable_Product__r.Category4__c,Consumable_Product__r.Category5__c,Unitprice_To_agency__c,';
                SqlOrder += 'Consumable_Product__r.Asset_Model_No__c,Shipment_amount__c,Box_Piece__c,ProductPacking_list_manual__c,Consumable_Product__r.SFDA_Status__c,';
                SqlOrder += 'Invoiced_Procount__c,RrturnPro_count__c,InvoiceProNot_count__c,Consumable_Product__r.Category5__c ';
                SqlOrder += ' FROM Consumable_orderdetails__c WHERE Consumable_order__c = \''+consumableorderId+'\'';
 
                List<Consumable_orderdetails__c> queryList = Database.query(SqlOrder); */
                for(ConsumableorderdetailsInfo ass : pageRecords){
                    ass.sortBy = this.sortOrderAsc;
                    for (Consumable_Orderdetails__c cdc1 : queryList) {
                        cdc1.Shipment_Count__c = cdc1.Consumable_count__c;
                        if(ass.prod.Id == cdc1.Consumable_Product__c){
                            ass.check = true;
                            ass.orderdetails1 = cdc1;
                        }
                    }
                }
            }else{
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '11111'));
                //当前页消耗品取得
                /*String strProd = null;
                List<Product2__c> product2Selected =  setCon.getRecords();
                for (Integer i = 0; i < product2Selected.size(); i++) {
                    if(strProd==null || strProd.length()==0){
                        strProd = '\'' + String.valueOf(product2Selected[i].Id) + '\'';
                    }
                    else{
                        strProd += ',\'' + String.valueOf(product2Selected[i].Id) + '\'';
                    }
                }*/
                //orderzaikuId.clear();
                String strProd = null;
                for (ConsumableorderdetailsInfo ass : pageRecords)  {
                    //orderzaikuId.add(ass.prod.Id);
                    if(strProd==null || strProd.length()==0){
                        strProd = '\'' + String.valueOf(ass.prod.Id) + '\'';
                    }
                    else{
                        strProd += ',\'' + String.valueOf(ass.prod.Id) + '\'';
                    }
                }
                String soql = 'SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,Product2__r.Packing_list_manual__c,SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Category3__c,Category4__c,Category5__c  FROM Product2__c ';
                //soql += ' WHERE Estimation_Entry_Possibility__c = \'○\'';
                soql += ' WHERE Id IN (' + strProd + ')';
                soql += ' order by ' + this.columus_no[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
                List<Product2__c> queryList = Database.query(soql);
                // 選択済みの明细を取得
                Map<String, String> selectedIdMap = new Map<String, String>();
                for (ConsumableorderdetailsInfo ass : pageRecords)  {
                    if(ass.check == true){
                        selectedIdMap.put(ass.Prod.id,ass.Prod.id);
                        reSet.add(ass);
                    }
                }
                for (Integer i = 0; i < queryList.size(); i++) {
                    if (selectedIdMap.containsKey(queryList[i].Id)) {
                        // 跳过已经选择的消耗品明细
                        continue;
                        } else {
                        // 未选择的消耗品明细
                        MidMap.put(queryList[i].Id, new ConsumableorderdetailsInfo(queryList[i]));
                    }
                }
                pageRecords= new List<ConsumableorderdetailsInfo>();
                pageRecords = reSet;
                //update by rentx 2021-01-29
                /*for(Integer i = 0 ; i< CountDel.size();i++){
                    //然后循环CountDel去修改map里的allnumber
                    if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                        ConsumableorderdetailsInfo Jstage =  MidMap.get(CountDel[i].Consumable_Product__c);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
                    }
                }*/
 
                for (Integer i = 0; i< CountDel.size() ; i++ ) {
                    String str = '';
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        str = 'isHos';
                    }else{
                        str = 'notHos';
                    }
                    //明细2对应的产品存在于MidMap中
                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                        //设置map中key的后缀 用于区分医院特价和非医院特价
                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }else{
                            //midmap2中没有对应的产品
                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                            Jstage.allnumber = Jstage.allnumber+1 ;
                            if(CountDel[i].Box_Piece__c == '盒'){
                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
                            }else if(CountDel[i].Box_Piece__c == '个'){
                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
                            }
                            if (CountDel[i].hospitalSpecialOffer__c) {
                                Jstage.hospitalSpecialOffer = true;
                            }else{
                                Jstage.hospitalSpecialOffer = false;
                            }
                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
                                Jstage.hosPro = true;
                            }
                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                            MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                        }
                    }
                }
                //update by rentx 2021-01-29
 
 
                //再把map里的值从新赋给ConsumableorderdetailsRecords
                //update by rentx 2021-01-29 
                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
                for(ConsumableorderdetailsInfo bss : MidMap2.values()){
                //update by rentx 2021-01-29 
 
                    if(selectedIdMap.containsKey(bss.orderdetails1.id)){
                        continue;
                    }else{
                        //if(bss.allnumber > 0){
                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                        pageRecords.add(bss);
                        //}
                    }
                }
                //listCut();
            }
        }else if(SearchDone!='SearchDone'){
            //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '22222'));
            String strProd = null;
            for (ConsumableorderdetailsInfo ass : pageRecords)  {
                //orderzaikuId.add(ass.prod.Id);
                if(strProd==null || strProd.length()==0){
                    strProd = '\'' + String.valueOf(ass.prod.Id) + '\'';
                }
                else{
                    strProd += ',\'' + String.valueOf(ass.prod.Id) + '\'';
                }
            }
            String SqlOrder = 'SELECT Id,  Name, Consumable_order__c, Consumable_Product__r.Name__c,Invoiced_Procount__c,RrturnPro_count__c,InvoiceProNot_count__c,';
            SqlOrder += 'Consumable_Product__c,Consumable_Product__r.Name,Consumable_Product__r.Category3__c,Consumable_Product__r.Category4__c,Consumable_Product__r.Category5__c,';
            SqlOrder += 'Shipment_Count__c,Consumable_Product__r.Intra_Trade_List_RMB__c,';
            SqlOrder += 'Consumable_Product__r.Asset_Model_No__c,Shipment_amount__c,Dealer_Custom_Price__c,Delivery_List_RMB__c,Box_Piece__c,ProductPacking_list_manual__c,';
            SqlOrder += 'Consumable_Product__r.SFDA_Status__c,Consumable_Product__r.Product2__r.Packing_list_manual__c,Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,';
            SqlOrder += 'Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c ';
            SqlOrder += ' FROM Consumable_orderdetails__c WHERE Consumable_order__c = \''+ESetId+'\'';
            SqlOrder += ' AND Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\'';
            SqlOrder += ' AND Consumable_Product__c IN (' + strProd + ')';
            SqlOrder += ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
            List<Consumable_orderdetails__c> queryList = Database.query(SqlOrder);
            // 選択済みの明细を取得
 
            for (Integer i = 0; i < queryList.size(); i++) {
                // 未选择的消耗品明细
                MidMap.put(queryList[i].Consumable_Product__c, new ConsumableorderdetailsInfo(queryList[i]));
            }
            pageRecords = new List<ConsumableorderdetailsInfo>();
            // 显示数据条数信息
            //update by rentx 2021-01-29
            /*for(Integer i = 0 ; i< CountDel.size();i++){
                //然后循环CountDel去修改map里的allnumber
                if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                    ConsumableorderdetailsInfo Jstage =  MidMap.get(CountDel[i].Consumable_Product__c);
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Box_Piece__c == '盒'){
                        Jstage.Boxnumber = Jstage.Boxnumber + 1;
                    }else if(CountDel[i].Box_Piece__c == '个'){
                        Jstage.Piecenumber = Jstage.Piecenumber + 1;
                    }
                    MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
                }
            }*/
            for (Integer i = 0; i<CountDel.size() ; i++ ) {
                String str = '';
                if (CountDel[i].hospitalSpecialOffer__c) {
                    str = 'isHos';
                }else{
                    str = 'notHos';
                }
                //明细2对应的产品存在于MidMap中
                if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                    //设置map中key的后缀 用于区分医院特价和非医院特价
                    if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                        ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        if (CountDel[i].hospitalSpecialOffer__c) {
                            Jstage.hospitalSpecialOffer = true;
                        }else{
                            Jstage.hospitalSpecialOffer = false;
                        }
                        if (HosProMap.containsKey(Jstage.Prod.Id)) {
                            Jstage.hosPro = true;
                        }
                        MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                    }else{
                        //midmap2中没有对应的产品
                        ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                        Jstage.allnumber = Jstage.allnumber+1 ;
                        if(CountDel[i].Box_Piece__c == '盒'){
                            Jstage.Boxnumber = Jstage.Boxnumber + 1;
                        }else if(CountDel[i].Box_Piece__c == '个'){
                            Jstage.Piecenumber = Jstage.Piecenumber + 1;
                        }
                        if (CountDel[i].hospitalSpecialOffer__c) {
                            Jstage.hospitalSpecialOffer = true;
                        }else{
                            Jstage.hospitalSpecialOffer = false;
                        }
                        if (HosProMap.containsKey(Jstage.Prod.Id)) {
                            Jstage.hosPro = true;
                        }
                        //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                        MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                    }
                }
            }
            //update by rentx 2021-01-29
 
            //再把map里的值从新赋给ConsumableorderdetailsRecords 
            // for(ConsumableorderdetailsInfo bss : MidMap.values()){
            for(ConsumableorderdetailsInfo bss : MidMap2.values()){
                //if(bss.allnumber > 0){
                bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                pageRecords.add(bss);
                //}
            }
            //listCut();
        }
    }
    //上传附件
    public PageReference FilesUpload(){
        PageReference ref = new Pagereference('/p/attach/NoteAttach?pid='+ESetid+'&retURL=%2F' + '/summonsCreat?ESetid=' +ESetid);
        ref.setRedirect(true);
        return ref;
    }
    // 检索
    public void searchConsumableorderdetails() {
        SearchDone = 'SearchDone';
        Map<String, String> selectedIdMap = new Map<String, String>();
        List<ConsumableorderdetailsInfo> reSet = new List<ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> MidMap = new Map<String,ConsumableorderdetailsInfo>();
        //update by rentx 2021-01-29
        Map<String,ConsumableorderdetailsInfo> MidMap2 = new Map<String,ConsumableorderdetailsInfo>();
        /*List<Consumable_order_details2__c> CountDel = [SELECT Id,
                                                            Bar_Code__c, 
                                                            Name,
                                                            Inventory_date__c,
                                                            Consumable_Product__c,
                                                            Consumable_Product__r.Asset_Model_No__c,
                                                            Recordtypeid,Box_Piece__c,ProductPacking_list_manual__c,
                                                            //add by rentx start
                                                            hospitalSpecialOffer__c
                                                            //add by rentx end
                                                        FROM Consumable_order_details2__c
                                                        WHERE Dealer_Arrive__c = true
                                                        AND Dealer_Shipment__c = false
                                                        AND Dealer_Saled__c = false
                                                        AND Dealer_Returned__c = false
                                                        AND Lose_Flag__c = false
                                                        AND Bar_Code__c !=null
                                                        AND Isoverdue__c = 1
                                                        AND Arrive_Owner_Work_Location__c = : userWorkLocation
                                                        //AND Consumable_order_minor__r.Dealer_Info__c = :accountid
                                                        AND Dealer_Info_text__c = :accountName];*/
        String countdelSoql = 'SELECT Id,Bar_Code__c,Name,Inventory_date__c,Consumable_Product__c,Consumable_Product__r.Asset_Model_No__c,Recordtypeid,Box_Piece__c,ProductPacking_list_manual__c,hospitalSpecialOffer__c FROM Consumable_order_details2__c WHERE  Dealer_Arrive__c = true AND Dealer_Shipment__c = false AND Dealer_Saled__c = false AND Dealer_Returned__c = false AND Lose_Flag__c = false AND Bar_Code__c != null AND Isoverdue__c = 1 AND Arrive_Owner_Work_Location__c =  :userWorkLocation AND Dealer_Info_text__c = :accountName ';
        if (String.isNotBlank(outOutPattern) && outOutPattern.equals('ishos')) {
            countdelSoql += ' AND hospitalSpecialOffer__c = true';
        }else if (String.isNotBlank(outOutPattern) && outOutPattern.equals('nothos')) {
            countdelSoql += ' AND hospitalSpecialOffer__c = false';
        }
        List<Consumable_order_details2__c> CountDel = Database.query(countdelSoql);
        //update by rentx 2021-01-29
 
        consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
        //consumableorderdetailsSelectRecords = reSet;
        String soql = this.makeSoql(category1,category3,category4,category5);
        size = Integer.valueOf(System.Label.orderdetLimitsize);
        initStandardController(soql);
        product2Selected = Database.query(soql);
        for (Integer i = 0; i < product2Selected.size(); i++) {
            MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
        }
 
        //update by rentx 2021-01-29
        /*for(Integer i = 0 ; i< CountDel.size();i++){
            //然后循环CountDel去修改map里的allnumber
            if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
                Jstage.allnumber = Jstage.allnumber+1 ;
                if(CountDel[i].Box_Piece__c == '盒'){
                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
                }else if(CountDel[i].Box_Piece__c == '个'){
                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
                }
                //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
            }
 
        }*/
 
        for (Integer i = 0; i < CountDel.size() ;i++ ) {
            String str = '';
            if (CountDel[i].hospitalSpecialOffer__c) {
                str = 'isHos';
            }else{
                str = 'notHos';
            }
            //明细2对应的产品存在于MidMap中
            if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
                //设置map中key的后缀 用于区分医院特价和非医院特价
                if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
                    ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c+str);
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Box_Piece__c == '盒'){
                        Jstage.Boxnumber = Jstage.Boxnumber + 1;
                    }else if(CountDel[i].Box_Piece__c == '个'){
                        Jstage.Piecenumber = Jstage.Piecenumber + 1;
                    }
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else{
                        Jstage.hospitalSpecialOffer = false;
                    }
                    if (HosProMap.containsKey(Jstage.Prod.Id)) {
                        Jstage.hosPro = true;
                    }
                    MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                }else{
                    //midmap2中没有对应的产品
                    ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Box_Piece__c == '盒'){
                        Jstage.Boxnumber = Jstage.Boxnumber + 1;
                    }else if(CountDel[i].Box_Piece__c == '个'){
                        Jstage.Piecenumber = Jstage.Piecenumber + 1;
                    }
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                    }else{
                        Jstage.hospitalSpecialOffer = false;
                    }
                    if (HosProMap.containsKey(Jstage.Prod.Id)) {
                        Jstage.hosPro = true;
                    }
                    //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    MidMap2.put(CountDel[i].Consumable_Product__c+str, Jstage);
                }
            }
        }
        //update by rentx 2021-01-29
 
        //再把map里的值从新赋给ConsumableorderdetailsRecords
        //update by rentx 2021-01-29
        // for(ConsumableorderdetailsInfo bss : MidMap.values()){
        Integer ishosnum = 0;
        for(ConsumableorderdetailsInfo bss : MidMap2.values()){
        //update by rentx 2021-01-29
            if(selectedIdMap.containsKey(bss.Prod.id)){
                continue;
            }else{
                bss.sortBy = false;
                bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                consumableorderdetailsSelectRecords.add(bss);
 
                if (bss.hospitalSpecialOffer == true) {
                    ishosnum = ishosnum + 1;
                }
            }
        }
         if (ishosnum > 0) {
            hasHosPro = true;
        }else{
            hasHosPro = false;
        }
 
 
        consumableorderdetailsSelectRecords.sort();
        //add by rentx
        noOfRecords = consumableorderdetailsSelectRecords.size();
        //add by rentx
        makepagerecords();
        this.sortKey = '1';
        this.preSortKey = '1';
        this.sortOrderAsc = false;
        this.sortOrder = new String[8];
        this.sortOrder = new String[]{' ',' ',' ',' ','↓','','',''};
 
        //cate1ForSort = category1;
        // 显示数据条数信息
        //makeMessage();
    }
    // 编辑按钮
    public PageReference seteditAble(){
        statusEdit = 'Redirect';
        PageReference ref = new Pagereference('/apex/summonsCreat?ESetid='+ESetid+'&KeyWords='+statusEdit);
        ref.setRedirect(true);
        return ref;
    }
    //删除按钮
    public PageReference DelConsumable(){
        List<Consumable_order__c> qs = New List<Consumable_order__c>();
        List<Consumable_orderdetails__c> Dqs= New List<Consumable_orderdetails__c>();
        Dqs = [SELECT Id FROM Consumable_orderdetails__c WHERE Consumable_order__c =:ESetId];
        qs  = [SELECT Id FROM Consumable_order__c WHERE Id =:ESetId];
         if (Dqs.size()>0||qs.size()>0){
                delete Dqs;
                delete qs;
            }
        PageReference ref = new Pagereference('/SaleAndDelivery');
        ref.setRedirect(true);
        return ref;
    }
    //出货
    public PageReference GoodsDelivery(){
        if(coc.SummonsForDirction__c =='互相调货'){
            List<Account> accList = [SELECT Id from Account WHERE Name = :coc.Order_ForDealerText__c AND RecordType.DeveloperName = 'Agency'];
            if(accList.size() < 1){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请输入二级经销商全称!'));
                return null;
            }
        }
        if(coc.SummonsStatus_c__c =='批准'){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请先打印指示单!'));
                return null;
        }
        for(ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords){
            if(ass.orderdetails1.Shipment_Count__c > ass.allnumber){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足')); 
                return null;
            }
        }
 
        PageReference ref = new Pagereference('/apex/SaleOrder?ESetid='+ESetid);
        ref.setRedirect(true);
        return ref;
    }
         // 提交按钮
 
    public void approval() {
        //判断库存
        for(ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords){
            if(ass.orderdetails1.Box_Piece__c == '盒'){
                if(ass.orderdetails1.Shipment_Count__c > ass.Boxnumber){
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足')); 
                    return;
                }
            }else if(ass.orderdetails1.Box_Piece__c == '个'){
                if(ass.orderdetails1.Shipment_Count__c > ass.Piecenumber){
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足')); 
                    return;
                }
            }
            
        }
 
        Consumable_order__c P = new Consumable_order__c();
        List<Consumable_order__c> cocinfo = New List<Consumable_order__c>();
        //update start by vivek 2019-7-15 add “NoConfirmedPrice__c” in select
        cocinfo = [SELECT Id,Name,NoConfirmedPrice__c,SummonsStatus_c__c,Dealer_Info__c,Order_ForHospital__c,SummonsForDirction__c,Billed_Status__c FROM Consumable_order__c WHERE Id =:ESetId];
        // update end by vivek 2019-7-15
            if (cocinfo.size()>0){
                p = cocinfo[0];
            }
        system.debug(p.id);
        p.SummonsStatus_c__c = '出库单已打印';
        p.Order_date__c = date.today();
        update p;
        //update start by vivek 2019-7-15 add “NoConfirmedPrice__c” in select
        coc = [SELECT Id,Name,Summons_Order_type__c,NoConfirmedPrice__c,SummonsStatus_c__c,Order_ForDealerText__c,
                    Dealer_Info__c,Order_ForDealer__c,Order_ForDealer__r.Name,Order_ForDealerTextID__c,
                    Order_ForHospital__c,SummonsForDirction__c,Order_date__c,Arrive_Order__c,
                    Order_status__c,Shipment_total_amount__c,Offers_Price__c,
                    Billed_Status__c,ShipmentAccount__c,Order_Dealer_Info__c,Order_ForCustomerText__c,ConInvoice_Code__c,Onchange_order__c
                FROM Consumable_order__c
                WHERE Id =:ESetId
                AND Order_type__c = '传票'];
        // update end by vivek 2019-7-15
    }
 
    // 保存按钮
    public PageReference save() {
        //订单信息确认
        if(coc.SummonsForDirction__c  ==''||coc.SummonsForDirction__c  == null){
            coc.SummonsForDirction__c.addError('请输入指示单目的。');
            return null;
        }
        else if(coc.SummonsForDirction__c =='直接销售给医院'){
            if(String.isBlank(HospitalInfo) || String.isBlank(HospitalName)){
                coc.addError('请输入医院。');
                return null;
            }
            if(String.isBlank(coc.Order_ForCustomerText__c)){
                coc.Order_ForCustomerText__c.addError('请输入科室。');
                return null;
            }
            else if(String.isNotBlank(SecondDealer) || String.isNotBlank(coc.Order_ForDealerText__c)){
                coc.addError('不需要二级经销商和经销商(录入)信息。' );
                return null;
            }
        }else if(coc.SummonsForDirction__c =='医院试用'){
            if(String.isBlank(HospitalInfo) || String.isBlank(HospitalName)){
                coc.addError('请输入医院。');
                return null;
            }
            if(String.isBlank(coc.Order_ForCustomerText__c)){
                coc.Order_ForCustomerText__c.addError('请输入科室。');
                return null;
            }
            /*if(SecondDealer == null && coc.Order_ForDealerText__c ==null){
                coc.addError('必须输入二级经销商或经销商(录入)。');
                return null;
            }
            if(SecondDealer != null && coc.Order_ForDealerText__c !=null){
                coc.addError('请输入二级经销商或经销商(录入)。');
                return null;
            }*/
        }
        else if(coc.SummonsForDirction__c =='销售给二级经销商'){
            /*
            if(coc.Order_ForHospital__c!=null){
                coc.Order_ForHospital__c.addError('不需要输入医院。');
                return null;
            }
            if(coc.Order_ForCustomerText__c !=null){
                coc.Order_ForCustomerText__c.addError('不需要输入科室。');
                return null;
            }
            */
            if(String.isBlank(SecondDealer) && String.isBlank(coc.Order_ForDealerText__c)){
                coc.addError('必须输入二级经销商或经销商(录入)。');
                return null;
            }
            if(String.isBlank(HospitalInfo) || String.isBlank(HospitalName)){
                coc.addError('请输入医院。');
                return null;
            }
            if(String.isBlank(coc.Order_ForCustomerText__c)){
                coc.Order_ForCustomerText__c.addError('请输入科室。');
                return null;
            }
        }
        else if(coc.SummonsForDirction__c =='互相调货'){
            if(String.isNotBlank(HospitalInfo) || String.isNotBlank(HospitalName)){
                coc.addError('不需要输入医院。');
                return null;
            }
            if(String.isNotBlank(coc.Order_ForCustomerText__c)){
                coc.Order_ForCustomerText__c.addError('不需要输入科室。');
                return null;
            }
            if(String.isBlank(SecondDealer) && String.isBlank(coc.Order_ForDealerText__c)){
                coc.addError('必须输入二级经销商或经销商(录入)。');
                return null;
            }
        }
 
        Integer isHos = 0;
 
        Integer FLG = 0;
        Integer Count = 0;
        for(ConsumableorderdetailsInfo CheckCount : pageRecords) {
            FLG = FLG + 1;
            if(CheckCount.check == false){ 
                Count = Count + 1;
            }else{
                //add by rentx
                if (CheckCount.hospitalSpecialOffer) {
                    isHos = isHos+1;
                }
                //add by rentx
            }
        }
        if(Count == FLG){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请选择所需消耗品'));
            return null;
        }
        // gzw 注释 判断提前 20210308
        checkOutPattern();
 
        // add by rentx 2021-3-10 start
        //特价医院出库非本医院维护的特价商品时,报错 非特价医院出库维护在医院特价关系表的产品时 报错
        if(coc.SummonsForDirction__c !='互相调货'){
            //非特价医院出库特价产品时 报错(当前经销商下没有特价医院除外)
            List<hospitalprice__c> hopList = [select id,hospital__c,product__c from hospitalprice__c where account__c = :accountid];
            //经销商对应医院下的所有特价产品
            Map<String,String> proMap = new Map<String,String>();
            //经销商下的所有特价产品
            Map<String,String> allProMap = new Map<String,String>();
 
            if (hopList != null && hopList.size() > 0) {
                Boolean flag = false;
                if (HospitalInfo != null && HospitalInfo != '') {
                    for (hospitalprice__c hp : hopList) {
                        allProMap.put(hp.product__c, '');
                        //如果当前 医院特价关系中的医院对应出库单上出库的医院,则放产品id到map
                        if (hp.hospital__c == HospitalInfo) {
                            flag = true; 
                            proMap.put(hp.product__c, '');
                        }
 
                    }
                }
                for(ConsumableorderdetailsInfo ass : pageRecords){
                    if (ass.check == true) {
                        //判断选中的医院特价产品
                        if (ass.hospitalSpecialOffer == true) {
                            //用户选中了当前医院下的特价产品
                            if (proMap.containsKey(ass.Prod.Id)) {
                                continue;
                            //用户选中了没有维护特价医院的特价产品
                            }else if (!allProMap.containsKey(ass.Prod.Id)) {
                                continue;
                            }else{
                                //用户选中非当前医院维护的特价产品
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '当前医院没有维护 消耗品:'+ ass.Prod.Name__c +' 的特价'));
                                return null;
                            }
                        }//非医院特价产品可以出库给任意医院,所以不需要判断
                    }
                }
            }
        }else{
            //如果是互相调货,判断 经销商(录入) 是否维护了 当前选中的特价产品 
            List<hospitalprice__c> hopList = [select id,hospital__c,product__c from hospitalprice__c where account__c = :coc.Order_ForDealerTextID__c];
            Map<Id,String> proMap = new Map<Id,String>();
            if (hopList != null && hopList.size() > 0) {
                for (hospitalprice__c hpc : hopList) {
                    proMap.put(hpc.product__c, '');
                }
 
                String proStr = '';
                for(ConsumableorderdetailsInfo ass : pageRecords){
                    if (ass.check == true) {
                        if (ass.hospitalSpecialOffer == true) {
                            if (!proMap.containsKey(ass.Prod.Id)) {
                                proStr += ass.Prod.Name__c+',';
                            }
                        }
                    }
                }
                if (proStr != '') {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '经销商:'+coc.Order_ForDealerText__c +' 没有消耗品:'+proStr.substring(0,proStr.length()-1) + ' 的特价'));
                    return null;
                }
            }else{
                //add by rentx 20210623 start 
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '经销商:'+coc.Order_ForDealerText__c +' 下没有特价医院,请重新选择后出库!'));
                return null;
                //add by rentx 20210623 end
 
            }
        }
        
 
        // add by rentx 2021-3-10 end
 
        //注释 by rentx at2021-3-10
        /*//需要根据 出库医院特价产品,但出库的产品中包含非医院特价产品
        if (coc.OutPattern__c == true) {
            //add by rentx 2020-12-02 start  是  并且该医院维护在医院特价
            if (String.isNotBlank(HospitalInfo) && coc.SummonsForDirction__c !='互相调货') {
                //判断当前医院是否为特价医院
                List<hospitalprice__c> hlist = [select id from hospitalprice__c where account__c = :accountid and hospital__c = :HospitalInfo];
                // List<hospitalprice__c> hlist = [select id from hospitalprice__c where hospital__c = :HospitalInfo];
                if (hlist.size() == 0) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '出库商品到特价医院时,请选择医院特价产品'));
                    return null; 
                }else{
                    if (FLG - Count > isHos && ishos != 0) {
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '出库商品到特价医院时,请选择医院特价产品'));
                        return null; 
                    }
                }
            }
            
        }
        //add by rentx 2021-2-26 start
        //判断当前经销商下是否有特价医院
        List<hospitalprice__c> hlist = [select id from hospitalprice__c where account__c = :accountid];
        if (hlist == null || hlist.size() == 0) {
        }else {
            //add by rentx 2021-2-26 end
            if (coc.OutPattern__c == false) {
                if (isHos >0 ) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '出库商品到非特价医院时,请选择非医院特价产品'));
                    return null; 
                }
            }
            //add by rentx 2020-12-02 end
        }*/
        // gzw 注释 判断提前 20210308
        // checkOutPattern();
        Consumable_order__c P = new Consumable_order__c();
        List<Consumable_orderdetails__c> Ins = New List<Consumable_orderdetails__c>();
        List<Consumable_order_details2__c> InsProduct = New List<Consumable_order_details2__c>();
        Savepoint sp = Database.setSavepoint();
        try {
            //新建订单时
            if(String.isEmpty(ESetId)){
                p.Name = '*';
                p.Order_type__c = '传票';
                p.Order_ProType__c = agencyProType;
                if(coc.SummonsStatus_c__c ==null||String.isBlank(coc.SummonsStatus_c__c))coc.SummonsStatus_c__c ='草案中'; 
                // update strat by vivek 2019-7-12
                p.NoConfirmedPrice__c = coc.NoConfirmedPrice__c;
                // update end by vivek 2019-7-12
                p.SummonsStatus_c__c = coc.SummonsStatus_c__c;
                if(coc.Arrive_Order__c != null){
                    p.Arrive_Order__c = coc.Arrive_Order__c;
                }
                p.Offers_Price__c = coc.Offers_Price__c;
                p.Dealer_Info__c = accountid;
                if(SecondDealer==null){
                    p.Order_ForHospital__c =String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
                    p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
                }else {
                    p.Order_ForHospital__c = String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
                    p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
                    p.Order_ForDealer__c = SecondDealer;
                }
                P.Order_ForDealerText__c = coc.Order_ForDealerText__c;
                P.Order_ForDealerTextID__c = coc.Order_ForDealerTextID__c;
                p.Order_date__c = coc.Order_date__c;
                p.SummonsForDirction__c = coc.SummonsForDirction__c;
                p.RecordTypeid = System.Label.RT_ConOrder_Outboundorder;
                // update start by vivek 2019-7-15
                p.NoConfirmedPrice__c = coc.NoConfirmedPrice__c;
                // update end by vivek 2019-7-15
                //add by rentx 
                p.OutPattern__c = coc.OutPattern__c;
                //add by rentx
                //Map<String,String> ProductNewMap = new Map<String, String>();
                for(ConsumableorderdetailsInfo ass : pageRecords){
                    if(ass.check == true){
                        if(ass.orderdetails1.Delivery_List_RMB__c < 0){
                            ass.orderdetails1.Delivery_List_RMB__c.addError('请输入正确的出货单价 (元)。');
                            return null;
                        }
                        //if(ass.orderdetails1.Unitprice_To_agency__c < 0){
                        //    ass.orderdetails1.Delivery_List_RMB__c.addError('请输入正确的二级经销商给客户单价。');
                        //    return null;
                        //}
                        if(ass.orderdetails1.Delivery_List_RMB__c == null && coc.SummonsForDirction__c !='医院试用'){
                            ass.orderdetails1.Delivery_List_RMB__c.addError('请输入出货单价 (元)。');
                            return null;
                        }
                        if(ass.orderdetails1.Delivery_List_RMB__c == 0 && (coc.SummonsForDirction__c =='销售给二级经销商' || coc.SummonsForDirction__c =='直接销售给医院')){
                            ass.orderdetails1.Delivery_List_RMB__c.addError('请输入出货单价 (元)。');
                            return null;
                        }
                        //if(coc.SummonsForDirction__c =='互相调货' || coc.SummonsForDirction__c =='直接销售给医院' || coc.SummonsForDirction__c =='医院试用'){
                        //    if(ass.orderdetails1.Unitprice_To_agency__c != null && ass.orderdetails1.Unitprice_To_agency__c != 0){
                        //        ass.orderdetails1.Unitprice_To_agency__c.addError('不需要输入二级经销商给客户单价。');
                        //        return null;
                        //    }
                        //}
                        //销售给二级经销商 时,可以录入
                        /*else if(coc.SummonsForDirction__c =='销售给二级经销商'){
                            if(ass.orderdetails1.Unitprice_To_agency__c == null || ass.orderdetails1.Unitprice_To_agency__c == 0){
                                ass.orderdetails1.Unitprice_To_agency__c.addError('必须输入二级经销商给客户单价。');
                                return null;
                            }
                        }*/
                        if(ass.orderdetails1.Shipment_Count__c == null ||ass.orderdetails1.Shipment_Count__c ==0){
                            ass.orderdetails1.Shipment_Count__c.addError('请输入出货数量。');
                            return null;
                        }
 
                        if(ass.orderdetails1.Box_Piece__c == null ||ass.orderdetails1.Box_Piece__c ==''){
                            ass.orderdetails1.Box_Piece__c.addError('请输入单位。');
                            return null;
                        }
                        if(ass.orderdetails1.Box_Piece__c == '盒'){
                            if(ass.orderdetails1.Shipment_Count__c > ass.Boxnumber){
                                //ass.orderdetails1.Shipment_Count__c.addError('库存不足');
                                if(ass.oldCheck == false){
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                                }else{
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                                }
                                return null;
                            }
                        }else if(ass.orderdetails1.Box_Piece__c == '个'){
                            if(ass.orderdetails1.Shipment_Count__c > ass.Piecenumber){
                                //ass.orderdetails1.Shipment_Count__c.addError('库存不足'); 
                                if(ass.oldCheck == false){
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                                }else{
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                                }
                                return null;
                            }
                        }
                    }
                }
                insert p;
                ESetId = p.id;
                List<Consumable_order__c> detailName = new List<Consumable_order__c>();
                detailName = [SELECT id,Name FROM Consumable_order__c WHERE id =:ESetId];
                Integer i = 1;
                for (ConsumableorderdetailsInfo ass : pageRecords)  {
                    if(ass.check == true){
                        Consumable_orderdetails__c InsAfterDel = new Consumable_orderdetails__c();
                        String str = string.valueOf(i);
                        if(str.length() == 1){
                            str = '0' + str;
                        }
                        InsAfterDel.Name = detailName[0].name + '-'+ str;
                        InsAfterDel.Shipment_Count__c = ass.orderdetails1.Shipment_Count__c;
                        InsAfterDel.Consumable_order__c = p.id;
                        InsAfterDel.Consumable_Product__c = ass.Prod.id;
                        InsAfterDel.Intra_Trade_List_RMB__c =ass.Prod.Intra_Trade_List_RMB__c;
                        InsAfterDel.Delivery_List_RMB__c = ass.orderdetails1.Delivery_List_RMB__c;
                        // TODO 默认 盒 ,需要修正
                        InsAfterDel.Box_Piece__c = ass.orderdetails1.Box_Piece__c;
                        InsAfterDel.Out_unit__c = ass.orderdetails1.Box_Piece__c;
                        //InsAfterDel.Unitprice_To_agency__c = ass.orderdetails1.Unitprice_To_agency__c;
                        InsAfterDel.Dealer_Custom_Price__c = ass.orderdetails1.Dealer_Custom_Price__c;
                        InsAfterDel.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
                        //add by rentx 2021-2-26 start
                        InsAfterDel.isOutPattern__c = ass.hospitalSpecialOffer;
                        //add by rentx 2021-2-26 end
                        i++;
                        Ins.add(InsAfterDel);
                    }
                }
                // 如果 出库单 和 OCM发货Header连 的话,发货的Detail2 Copy到 出库单的Detail2里
                if (getExistarrive()) {
                    for (ConsumableorderdetailsInfo ass : consumableproductdetailsRecords)  {
                        //BlockForP;
                        Consumable_order_details2__c InsProductDet = new Consumable_order_details2__c();
                        InsProductDet.Id = ass.orderdetails2.Id;
                        InsProductDet.Consumable_ZS_order__c = p.id;
                        i++;
                        InsProduct.add(InsProductDet);
                    }
                }
                if(Ins.size()>0){
                    insert Ins;
                }
                if(InsProduct.size() >0){
                    ControllerUtil.updateOrderDetailsSatus(InsProduct);
                }
            }
            //修改之后 保存订单
            else if(ESetId != null || ESetId.length() >0 ){
                List<Consumable_order__c> cocinfo = New List<Consumable_order__c>();
                // update start by vivek 2019-7-15 add "NoConfirmedPrice__c" in select
                cocinfo = [SELECT Id,
                                Name,
                                SummonsStatus_c__c,
                                NoConfirmedPrice__c,
                                Dealer_Info__c,
                                Order_ForHospital__c,
                                SummonsForDirction__c
                            FROM Consumable_order__c
                            WHERE Id =:ESetId];
                // update end by vivek 2019-7-15
                if (cocinfo.size()>0){
                    p = cocinfo[0];
                }
                p.Name = coc.Name;
                p.Dealer_Info__c = accountid;
                p.Order_ProType__c = agencyProType;
                if(SecondDealer == null){
                    p.Order_ForHospital__c = String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
                    p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
                    p.Order_ForDealer__c = SecondDealer;
                }else {
                    p.Order_ForHospital__c = String.isNotBlank(HospitalInfo) ? HospitalInfo : null;
                    p.Order_ForCustomerText__c = coc.Order_ForCustomerText__c;
                    p.Order_ForDealer__c = SecondDealer;
                }
                P.Order_ForDealerText__c = coc.Order_ForDealerText__c;
                P.Order_ForDealerTextID__c = coc.Order_ForDealerTextID__c;
                p.Order_date__c = coc.Order_date__c;
                p.SummonsForDirction__c = coc.SummonsForDirction__c;
                //add by rentx
                p.OutPattern__c = coc.OutPattern__c;
                // update start by vivek 2019-7-15
                if(p.SummonsStatus_c__c== '价格未定'){
                    p.NoConfirmedPrice__c = false;
                    p.SummonsStatus_c__c= '已完成';
                }else{
                    p.SummonsStatus_c__c = '草案中';
                }
                // p.SummonsStatus_c__c = '草案中';
                // update end by vivek 2019-7-15
                Integer i = 1;
                //Map<String,String> ProductOldMap = new Map<String, String>();
                for (ConsumableorderdetailsInfo ass : pageRecords)  {
                    if(ass.check == true){
                        if(ass.orderdetails1.Delivery_List_RMB__c < 0){
                            ass.orderdetails1.Delivery_List_RMB__c.addError('请输入正确的出货单价 (元)。');
                            return null;
                        }
                        //if(ass.orderdetails1.Unitprice_To_agency__c < 0){
                        //    ass.orderdetails1.Delivery_List_RMB__c.addError('请输入正确的二级经销商给客户单价。');
                        //    return null;
                        //}
                        Consumable_orderdetails__c InsAfterDel = new Consumable_orderdetails__c();
                        if(ass.orderdetails1.Delivery_List_RMB__c == null && coc.SummonsForDirction__c !='医院试用'){
                            ass.orderdetails1.Delivery_List_RMB__c.addError('请输入出货单价 (元)。');
                            return null;
                        }
                        if(ass.orderdetails1.Delivery_List_RMB__c == 0 && (coc.SummonsForDirction__c =='销售给二级经销商' || coc.SummonsForDirction__c =='直接销售给医院')){
                            ass.orderdetails1.Delivery_List_RMB__c.addError('请输入出货单价 (元)。');
                            return null;
                        }
                        //if(coc.SummonsForDirction__c =='互相调货' || coc.SummonsForDirction__c =='直接销售给医院' || coc.SummonsForDirction__c =='医院试用'){
                        //    if(ass.orderdetails1.Unitprice_To_agency__c != null && ass.orderdetails1.Unitprice_To_agency__c != 0){
                        //        ass.orderdetails1.Unitprice_To_agency__c.addError('不需要输入二级经销商给客户单价。');
                        //        return null;
                        //    }
                        //}
                        //销售给二级经销商 时,二级经销商给客户单价可以录入
                        /*else if(coc.SummonsForDirction__c =='销售给二级经销商'){
                            if(ass.orderdetails1.Unitprice_To_agency__c == null || ass.orderdetails1.Unitprice_To_agency__c == 0){
                                ass.orderdetails1.Unitprice_To_agency__c.addError('必须输入二级经销商给客户单价。');
                                return null;
                            }
                        }*/
                        if(ass.orderdetails1.Box_Piece__c == null ||ass.orderdetails1.Box_Piece__c ==''){
                            ass.orderdetails1.Box_Piece__c.addError('请输入单位。');
                            return null;
                        }
                        if(ass.orderdetails1.Box_Piece__c == '盒'){
                            if(ass.orderdetails1.Shipment_Count__c > ass.Boxnumber){
                                //ass.orderdetails1.Shipment_Count__c.addError('库存不足');
                                if(ass.oldCheck == false){
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                                }else{
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                                }
                                return null;
                            }
                        }else if(ass.orderdetails1.Box_Piece__c == '个'){
                            if(ass.orderdetails1.Shipment_Count__c > ass.Piecenumber){
                                if(ass.oldCheck == false){
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.Prod.Name__c + '库存不足'));
                                }else{
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '消耗品'+ ass.orderdetails1.Consumable_Product__r.Name__c + '库存不足'));
                                }
                                return null;
                            }
                        }
                        if(ass.orderdetails1.Shipment_Count__c == null||ass.orderdetails1.Shipment_Count__c==0){
                            ass.orderdetails1.Shipment_Count__c.addError('请输入出货数量。');
                            return null;
                        }else{
 
                            String str = string.valueOf(i);
                            if(str.length() == 1){
                                str = '0' + str;
                            }
                            InsAfterDel.Name = p.name + '-'+ str;
                            InsAfterDel.Shipment_Count__c = ass.orderdetails1.Shipment_Count__c;
                            InsAfterDel.Consumable_order__c = ESetId;
                            InsAfterDel.Consumable_Product__c = ass.Prod.id;
                            InsAfterDel.Intra_Trade_List_RMB__c =ass.Prod.Intra_Trade_List_RMB__c;
                            InsAfterDel.Delivery_List_RMB__c = ass.orderdetails1.Delivery_List_RMB__c;
                            InsAfterDel.Box_Piece__c = ass.orderdetails1.Box_Piece__c;
                            InsAfterDel.Out_unit__c = ass.orderdetails1.Box_Piece__c;
                            //InsAfterDel.Unitprice_To_agency__c = ass.orderdetails1.Unitprice_To_agency__c;
                            InsAfterDel.Dealer_Custom_Price__c = ass.orderdetails1.Dealer_Custom_Price__c;
                            InsAfterDel.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
                            //add by rentx 2021-2-26 start
                            InsAfterDel.isOutPattern__c = ass.hospitalSpecialOffer;
                            //add by rentx 2021-2-26 end
                            i++;
                            Ins.add(InsAfterDel);
                        }
                    }
                }
                update p;
                List<Consumable_orderdetails__c> qs = New List<Consumable_orderdetails__c>();
                qs = [SELECT Id FROM Consumable_orderdetails__c WHERE Consumable_order__c =:ESetId];
                if (qs.size()>0){
                    delete qs;
                }
                if(Ins.size()>0){
                    insert Ins;
                }
 
            }
        }catch (Exception ex) {
            Database.rollback(sp);
            ApexPages.addMessages(ex);
            return null;
        }
        return UnabletoEdit();
    }
    // 返回不可编辑状态
    public PageReference UnabletoEdit(){
        PageReference ref = new Pagereference('/apex/summonsCreat?ESetid='+ESetId);
        ref.setRedirect(true);
        return ref;
    }
 
    // 做成检索SQL文
    private String makeSoql(String CateName,String Category3,String Category4,String Category5){
        //String sqlTail = '(\'';
        //for(Integer i = 0 ; i< orderzaikuId.size();i++){
        //    if(i<orderzaikuId.size()-1){
        //        sqlTail += orderzaikuId[i]+'\',\'';
        //    }else{
        //        sqlTail += orderzaikuId[i]+'\')';
        //    }
        //}
        String sqlTail1 = '(\'';
        for(Integer i = 0 ; i< zaikuId.size();i++){
            if(i<zaikuId.size()-1){
                sqlTail1 += zaikuId[i]+'\',\'';
            }else{
                sqlTail1 += zaikuId[i];
            }
        }
        sqlTail1 += '\')';
        String soql = 'SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,Product2__r.Packing_list_manual__c,SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Category3__c,Category4__c,Category5__c  FROM Product2__c ';
        //soql += ' WHERE Estimation_Entry_Possibility__c = \'○\'';
        soql += ' WHERE Id in' + sqlTail1;
       /* if(!String.isBlank(CateCode)){
            soql += ' AND Asset_Model_No__c = \'' +  CateCode + '\'';
        }else*/ if(!String.isBlank(CateName)){
            soql += ' AND (Name__c like \'%' + String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) + '%\' or Asset_Model_No__c like \'%' + String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) + '%\')';
        }if(!String.isBlank(Category3)){
            soql += ' AND Category3__c = \'' +  Category3 + '\'';
        }if(!String.isBlank(Category4)){
            soql += ' AND Category4__c = \'' +  Category4 + '\'';
        }if(!String.isBlank(Category5)){
            soql += ' AND Category5__c = \'' +  Category5 + '\'';
        }
        //if(orderzaikuId.size() > 0){
        //    soql += ' AND Id not in' + sqlTail;
        //}
        //if(zaikuId.size() > 0){
            //soql += ' AND Id in' + sqlTail1;
        //}
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'soql ++++++' + soql));
        return soql;
    }
 
    private String makeSoqlinventory(){
        String sqlTail = '(\'';
        for(Integer i = 0 ; i< zaikuId.size();i++){
            if(i<zaikuId.size()-1){
                sqlTail += zaikuId[i]+'\',\'';
            }else{
                sqlTail += zaikuId[i];
            }
        }
        sqlTail += '\')';
        String msoql = 'SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,Product2__r.Packing_list_manual__c,SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Category3__c,Category4__c,Category5__c  FROM Product2__c ';
        //msoql += ' WHERE Estimation_Entry_Possibility__c = \'○\'';
        //if(zaikuId.size() > 0){
            msoql += ' WHERE Id in' + sqlTail;
        //}
        return msoql;
    }
    private String makeSoqlorderdet(){
        String sqlTail = '(\'';
        for(Integer i = 0 ; i< orderzaikuId.size();i++){
            if(i<orderzaikuId.size()-1){
                sqlTail += orderzaikuId[i]+'\',\'';
            }else{
                sqlTail += orderzaikuId[i];
            }
        }
        sqlTail += '\')';
        String msoql = 'SELECT Id, Name,Name__c,Intra_Trade_List_RMB__c,Asset_Model_No__c,Product2__r.Packing_list_manual__c,SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,Category3__c,Category4__c,Category5__c  FROM Product2__c ';
        //msoql += ' WHERE Estimation_Entry_Possibility__c = \'○\'';
        //if(orderzaikuId.size() > 0){
            msoql += ' WHERE Id in' + sqlTail;
        //}
        return msoql;
    }
    // 显示数据条数信息
    private void makeMessage() {
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '库存共有' + consumableorderdetailsCount + '可出货件产品'));
    }
    
    // Data Bean
    class ConsumableorderdetailsInfo implements Comparable {
        public Boolean check { get; set; }
        public Boolean oldCheck { get; set; }
        public Consumable_Orderdetails__c orderdetails1 { get; set; }
        public Consumable_order_details2__c orderdetails2 { get; set; }
        public Product2__c Prod { get; set; }
        //盒的个数
        public Decimal Boxnumber { get; set; }
        //个的个数
        public Decimal Piecenumber { get; set; }
        public Decimal allnumber { get; set; }
        public Decimal oldConsumableCount { get; set; }
        public Boolean canSelect { get; set; }
        public Boolean sortBy { get; set; }
        public Integer packinglist { get; set; }
        public String approbation_No { get; set; }
        public Date expiration_Date { get; set; }
        public String boxorpiecein {get;set;}
        public List<SelectOption> boxorpiece  { get; set; }
        public Attachment concc { get; set; }
        public String BoxPiece { get; set; }
        //public String UnitpriceToagency { get; set; }
 
        //add by rentx 
        public Boolean hospitalSpecialOffer {get;set;}
        public Boolean hosPro {get;set;}
        //add by rentx
        // 消耗品订货明细
        public ConsumableorderdetailsInfo(Consumable_Orderdetails__c e) {
            check = true;
            oldCheck = true;
            orderdetails1 = e;
            orderdetails2 = new Consumable_order_details2__c();
            Prod = e.Consumable_Product__r;
            oldConsumableCount = e.Shipment_Count__c;
            canSelect = true;
            allnumber = 0;
            Boxnumber = 0;
            Piecenumber = 0;
            BoxPiece = e.Box_Piece__c;
            boxorpiece = new List<SelectOption>();
            boxorpiece.add(new SelectOption('盒', '盒'));
            boxorpiece.add(new SelectOption('个', '个'));
            hospitalSpecialOffer = false;
            hosPro =false;
        }
 
        // 消耗品发货明细
        public ConsumableorderdetailsInfo(Consumable_order_details2__c e) {
            check = true;
            oldCheck = true;
            orderdetails1 = new Consumable_Orderdetails__c();
            orderdetails2 = e;
            Prod = e.Consumable_Product__r;
            canSelect = true;
            allnumber = 0;
            Boxnumber = 0;
            Piecenumber = 0;
            //boxorpiece = new List<SelectOption>();
            //boxorpiece.add(new SelectOption('盒', '盒'));
            //boxorpiece.add(new SelectOption('个', '个'));
            hospitalSpecialOffer = false;
            hosPro = false;
        }
        
        //附件
        public ConsumableorderdetailsInfo(Attachment e) {
            concc = e;
            hospitalSpecialOffer = false;
            hosPro = false;
        }
        public ConsumableorderdetailsInfo(Product2__c e) {
            check = false;
            oldCheck = false;
            orderdetails1 = new Consumable_Orderdetails__c();
            orderdetails2 = new Consumable_order_details2__c();
            Prod = e;
            //oldConsumableCount = null;
            canSelect = true;
            allnumber = 0;
            Boxnumber = 0;
            Piecenumber = 0;
            orderdetails1.Box_Piece__c = '盒';
            boxorpiece = new List<SelectOption>();
            boxorpiece.add(new SelectOption('盒', '盒'));
            boxorpiece.add(new SelectOption('个', '个'));
            hospitalSpecialOffer = false;
            hosPro = false;
        }
        
        // 排序
        public Integer compareTo(Object compareTo) {
            ConsumableorderdetailsInfo compareToorderdetails1 =(ConsumableorderdetailsInfo)compareTo;
            Integer returnValue = 0;
            if(sortBy == false){
                if (Boxnumber > compareToorderdetails1.Boxnumber) {
                    returnValue = -1;
                } else if (Boxnumber < compareToorderdetails1.Boxnumber) {
                    returnValue = 1;
                }
                return returnValue;
            }else{
                if (Boxnumber > compareToorderdetails1.Boxnumber) {
                    returnValue = 1;
                } else if (Boxnumber < compareToorderdetails1.Boxnumber) {
                    returnValue = -1;
                }
                return returnValue;
            }
        }
        
    }
}