高章伟
2022-03-10 1312ba82d4c880bdb5357d28e0d4af5b285f610f
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
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
// FIXME 見積もり商品の Asset_Model_No__c ですが、数式になっています。トランザクションデータとして、項目を持つべきかと思います。by katsu 20130216
// 商談商品のId__c を PricebookEntry.Product2Idに変更すべき
// 見積もり可否 ですが、保存時みていますが、Sales_Possibilityを見ないですか?いいえ、js側で見ています
public class NewQuoteEntryController {
  public Integer quoteEntryMaxLine { get; private set; }
  public Id oppId { get; set; }
  public Id quoId { get; set; }
  public Boolean productStatusUpdated { get; set; }               // 状態更新、{!$Label.Status_Update} を押下したかどうか
  public Boolean changedAfterPrint { get; set; }                  // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにて実施
  public Boolean changedAfterBid { get; set; }                    // true の場合、画面に confirm メッセージが表示します。quoIdを新しいinsert。判定はjsにで実施
  //public Id qlistId { get; set; }
  //lastbuy  2022/2/9 fy start
  public Boolean filg { get; set; }
  public Integer flglastbuy { get; set; }
  public String errorProductmodel { get; set; }
  //lastbuy  2022/2/9 fy end
 
  public String excel_text { get; set; }
  public Integer select_index { get; set; }                       // excelImport専用ですが、jsにて制御することになるので、TODO katsu 削除予定
  public String Product_text { get; set; }
  public String setProduct_text { get; set; }
 
  public List<QELine> activities { get; set; }
  public List<QELine> tmpactivities { get; set; }
  public QELine active_activity { get; set; }
  public OppInfo oppInfo { get; set; }
  //用于检查询价报价具体产品状态是否变更
  public List<QuoteLineItem> CheckItem {get; set;}
  //値引き
  public Decimal DisCalculation { get; set; }
  public Decimal DisAmount { get; set; }
 
  //第一販売店
  //public String SalesName1 { get; set; }
  public String SalesShopClass1 { get; set; }
  //public Decimal SalesAmount1 { get; set; }
  public Decimal Salesprofit1 { get; set; }
  public Decimal SalesCalculation1 { get; set; }
  public String SalesId1 { get; set; }
  // 2018/09/29 CHAN-B4YAB8 经销商折扣 start
  public Decimal AgencyDiscount { get; set; }
  //第二販売店
  //public String SalesName2 { get; set; }
  public String SalesShopClass2 { get; set; }
  //public Decimal SalesAmount2 { get; set; }
  public Decimal Salesprofit2 { get; set; }
  public Decimal SalesCalculation2 { get; set; }
  public String SalesId2 { get; set; }
  //病院マスタ選択リスト
  public String selection_hp { get; set; }
  public List<SelectOption> options_hp { get; set; }
  //画面制御判定用
  public Boolean displayCost { get; set; }
  //public Boolean enableEntry { get; set; }
  public Boolean enableSales { get; set; }
  public Boolean specialAuthority { get; set; }
  public Boolean verified { get; set; }
  public Boolean QuoteDecision { get; set; }
  public boolean QuoteDecide {get; set;}
  public Boolean QuoteSapSented { get; set; }
  public Boolean QuoteCorrect { get; set; }
  //public Boolean salesEntry { get; set; }
  public Boolean enableContract { get; set; }
  //ボタン制御用
  public Boolean print_button { get; set; }
  public Boolean sap_button { get; set; }
  public Boolean Decision_button { get; set; }
  public Boolean Save_button { get; set; }
  public Boolean WinOrDecideAlert {get; set;}
 
  public Boolean over3month { get; set; }
  public Boolean newQuoteFlag=false;
 
  // 多年保修 start
  public string trade {get; private set;}
  public string quoteGurantee_Period;
  public string quotemultiYearWarranty;
  // 多年保修 end
  //报价试算 判断经销商是否变化 start
  public string agency1Name;
  public string agency2Name;
  //报价试算 判断经销商是否变化 end
  public Boolean getHiddenSaveBtn() {
    Boolean rtn = quo.Cancel_Decide__c;
    Schema.DescribeSObjectResult quoteDesc = Quote.SObjectType.getDescribe();
    rtn = (rtn == false) ? !quoteDesc.isUpdateable() : rtn;
    return rtn;
  }
  //見積調整金額
  //public Decimal QuoAmount { get; set; }
  //public Decimal QuoCalculation { get; set; }
  //見積
  public Pricebook2 standardPricebook;                // 画面上使わないため、get setなし
  public Quote quo { get; set; }
  public Decimal quoStocking_Price_c { get; set; }
 
  //Get Opportunity Object
  public Opportunity opp;
 
  private Map<Id, Product2> prd2LatestValMap;
 
  public boolean errorflg { get; set; }
  public String errorMessage { get; set; }
  public String errorMessagechack { get; set; }
  public String baseUrl { get; set; }
  public boolean Messageflg { get; set; }
  public String Message { get; set; }
  public Boolean viewSpecialAgencyAmout { get; set; }
  public Boolean displayFlg { get; set; }
  public QuoteBean qb { get; set; }
  public Integer rowIdx { get; set; }
 
  public NewQuoteEntryController() {
    quoteEntryMaxLine = Integer.valueOf(System.Label.QuoteEntryMaxLine2);
    //Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
    baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
    changedAfterPrint = false;
    changedAfterBid = false;
    productStatusUpdated = false;
    // CHAN-AVG3PW 询价报价画面规则变更
    over3month = false;
    newQuoteFlag = false;
  }
 
  public NewQuoteEntryController(ApexPages.StandardController controller) {
    this();
  }
 
  public PageReference init() {
 
    system.debug('============start init==============');
    boolean quoteflg = true;
    WinOrDecideAlert = false;
    errorflg = false;
    displayFlg = true;
    //Quote
    standardPricebook = ControllerUtil.getStandardPricebook();
    quo = new Quote();
    qb = new QuoteBean();
    String DeveloperName = '';
    //Opportunityid
    if (oppId == null) {
      oppId = System.currentPageReference().getParameters().get('oppid');
      if (oppId == Null) {
        quoId = System.currentPageReference().getParameters().get('id');
 
        List<Quote> ql = New List<Quote>();
        //添加行
        ql = [select Id, OpportunityId, Opportunity.RecordType.DeveloperName,LineItemCount From Quote Where Id = :quoId];
        if (ql.size() > 0) {
          oppId = ql[0].OpportunityId;
          //添加行
          if(ql[0].LineItemCount >quoteEntryMaxLine){
            quoteEntryMaxLine = ql[0].LineItemCount;
          }
          DeveloperName = ql[0].Opportunity.RecordType.DeveloperName;
        }
      } else {
        quoId = System.currentPageReference().getParameters().get('copyid');
        system.debug('copyid++++++++++++'+quoId);
        if (quoId != null) {
          // コピーのデータが後で作成する
        } else {
          List<Quote> ql = New List<Quote>();
          //添加行
          ql = [select Id, OpportunityId,LineItemCount From Quote Where OpportunityId = :oppId];
          if (ql.size() > 0) {
            //添加行
            if(ql[0].LineItemCount >quoteEntryMaxLine){
                quoteEntryMaxLine = ql[0].LineItemCount;
            }
            quoteflg = true;
          } else {
            quoteflg = false;
          }
        }
      }
    }
 
    if (DeveloperName == 'SI_Oppor') {
      PageReference pageRef = new PageReference('/apex/SI_NewQuoteEntry?id=' + quoId);
      return pageRef;
    }
    system.debug('DeveloperName============' + DeveloperName);
    //--User
    List<User> us = New List<User>();
    String userid = UserInfo.getUserId();
    if (userid != null) {
      us = [Select Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c, ViewSpecialAgencyAmout__c From User Where Id = :userid];
      if (us.size() > 0) {
        verified = us[0].Quote_Correct__c;
        specialAuthority = us[0].Quote_Special_Operation__c;
        displayCost = us[0].Cost_Referable__c;
        viewSpecialAgencyAmout = us[0].ViewSpecialAgencyAmout__c;
      }
    }
    //--Opportunity
    List<Opportunity> oppList = New List<Opportunity>();
    String accountid;
 
    oppList = [SELECT Account.Name, Account.RecordType.DeveloperName,
               CLBIC_Category__c, HP_Name__c, Name, CurrencyIsoCode, Wholesale_Price__c, Department_Name__c,
               Direct_Separate__c, Trade__c, AccountId, New_Opportunity__c, Estimation_Decision__c, SAP_Send_OK__c, Sales_Root__c,
               Agency1__c, Agency2__c, Stocking_Price__c, Purchasing_Cost__c, Opportunity_No__c, StageName,
               Agency1__r.Special__c, Agency2__r.Special__c, Account.Parent.Special__c
               // LHJ Start
               , Authorized_DB_No__c, Authorized_Finish_Sales__c, If_Need_Authorize__c
               // LHJ End
               // 多年保修 start
               , Gurantee_Period__c , multiYearWarranty__c, MultiYearWarrantyTotalPrice__c
               // 多年保修 end
               // CHAN-BEN5UC start
               , Hospital__c, Department_Class__c
               ,Is_Corrosion__c,
               // CHAN-BEN5UC end
               //【是否需要价格申请】 thh start
               If_Need_PriceApply__c
               //【是否需要价格申请】 thh end
               FROM Opportunity Where Id = :oppId];
    // 多年保修 start
    trade = '外貿';
    // 多年保修 end
    if (oppList.size() > 0) {
 
      opp = oppList[0];
      // 多年保修 start
      trade = opp.Trade__c;
      // 多年保修 end
      QuoteDecision = opp.Estimation_Decision__c;
      QuoteDecide = QuoteDecision;
      QuoteSapSented = opp.SAP_Send_OK__c;
      QuoteCorrect = opp.New_Opportunity__c;
 
      enableSales = false;
      if (opp.Sales_Root__c != null) {
        if (opp.Sales_Root__c == '販売店') {
          enableSales = true;
          opp.Sales_Root__c = System.Label.Sales_Outlet;
        } else {
          enableSales = false;
          opp.Sales_Root__c = System.Label.OCM_Direct;
        }
      }
 
      accountid = opp.AccountId;
 
      if (QuoteDecision == true) {
        enableContract = true;
      } else {
        enableContract = false;
      }
 
      oppInfo = new OppInfo(opp);
 
      if (opp.SAP_Send_OK__c == false) {
        displayFlg = true;
      } else {
        if (opp.Agency1__r.Special__c || opp.Agency1__r.Special__c || opp.Account.Parent.Special__c) {
          // 特別販売店の引合い
          if (viewSpecialAgencyAmout) {
            displayFlg = true;
          } else {
            displayFlg = false;
          }
        } else {
          displayFlg = true;
        }
      }
    }
 
    //Quote
    Integer i;
    if (quoId == null) {
      quoId = System.currentPageReference().getParameters().get('id');
    }
    if (quoId == null) {
      if (quoteflg == false) {
        //商談商品が存在、見積が存在しないデータの対応
        List<OpportunityLineItem> items = New List<OpportunityLineItem>();
        if (oppId == null) {
          oppId = System.currentPageReference().getParameters().get('oppid');
        }
        items = [Select Id, Asset_Model_No__c, SFDA_Status__c, Name__c, ProductCode__c, PricebookEntry.Product2.StorageStatus__c,
                 //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段,不可取消多年保&& 增加检索阿西赛多 2020/09/10start
                 Qty_Unit__c, Cost__c, UnitPrice, ListPrice__c, Quantity, BSS_Category__c, TotalPrice,PricebookEntry.Product2.VenderName__c,PricebookEntry.Product2.CanNotCancelledGurantee__c,PricebookEntry.Product2.Is_DangerousChemicals__c,
                 //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                 PricebookEntry.Product2.SFDA_Status__c, Product_Cost__c, Product_ListPrice__c, PricebookEntry.Product2.Sales_Possibility__c, PricebookEntry.Product2.Name,
                 PricebookEntryId, PricebookEntry.Product2Id, Opportunity.Trade__c, PricebookEntry.Product2.Intra_Trade_List_RMB__c, PricebookEntry.Product2.Intra_Trade_Cost_RMB__c,
                 PricebookEntry.Product2.Foreign_Trade_List_US__c, PricebookEntry.Product2.Packing_list_manual__c, PricebookEntry.Product2.Foreign_Trade_Cost_US__c, UnitPrice__c, TotalPrice__c
                 , AgencyUnitPrice__c, AgencySubtotal__c, Present__c // CHAN-B4YAB8 2018/09/29 业务机会产品的赠送、经销商小计、单价
                 //多年保修 start
                 , multiYearWarranty__c , If_Cancel_Guarantee__c , GuaranteePeriod__c,
                 ServicePrice__c , GuranteePrice__c,
                 ProductEntend_gurantee_period_all__c,
                 ProductGuranteePrice__c, GuranteeType__c,
                 //ProductIfConsumable__c,
                 warrantyType__c, productServicePrice__c,
                 NoDiscountTotal__c
                 , provistonPeriod__c
                 , PricebookEntry.Product2.Entend_gurantee_period_all__c
                 , PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c
                 , PricebookEntry.Product2.Intra_Trade_Service_RMB__c
                 , PricebookEntry.Product2.GuranteeType__c
                 // 维修合同报价
                 , PricebookEntry.Product2.Maintenance_Price_Year__c
                 , Maintenance_Price_Year__c
                 //多年保修 end
                 //外贸多年保 2021/01/04 精琢技术 wql start
                 //维修合同报价(USD)
                 ,PricebookEntry.Product2.Repair_Contract_USD__c
                 //计提金额(不含税,USD)
                 ,PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c
                 //NoDiscount 金额(USD)
                 ,PricebookEntry.Product2.NoDiscount_Foreign__c
                 //外贸多年保 2021/01/04 精琢技术 wql end
 
                //SFDC停止预警 lt 20211009 start
                ,PricebookEntry.Product2.Estimated_ConsumptionDueDate__c
                //SFDC停止预警 lt 20211009 end
 
                 From OpportunityLineItem
                 Where OpportunityId = :oppId Order by Item_Order__c, Id];
 
        if (items.size() > 0) {
          activities = new List<QELine>();
          i = 0;
 
          for (OpportunityLineItem o : items) {
            QELine c = new QELine(o, i);
            activities.add(c);
            i++;
          }
          for (integer j = i; j < quoteEntryMaxLine; j++) {
            QELine c = new QELine(j);
            activities.add(c);
          }
          productStatusUpdated = true;
 
        } else {
          //新規リストコントローラの取得
          if (activities == null) {
            activities = new List<QELine>();
            for (i = 0; i < quoteEntryMaxLine; i++) {
              QELine active_activity = new QELine(i);
              activities.add(active_activity);
            }
          }
        }
      } else {
        //新規リストコントローラの取得
        if (activities == null) {
          activities = new List<QELine>();
          for (i = 0; i < quoteEntryMaxLine; i++) {
            QELine active_activity = new QELine(i);
            activities.add(active_activity);
          }
        }
      }
    } else {
      //添加行
      List<Quote> quoList =
        [ SELECT Id, Name, Cancel_Decide__c, CreatedDate, PriceRefreshDate__c, Quote_Print_Date__c,
          Dealer_Final_Price__c, TotalPrice__c, Estimation_List_Price__c, QuoteNumber,
          QuoteToName, Quote_Expiration_Date__c, Quote_Comment__c, Stocking_Price__c, Unit_Price__c,
          Offer_Amount__c, TOTAL__c, Discount__c, Pricing__c, Preferential_Trading_Price__c, Contract__c,
          Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Print_HP_Name__c,
          Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c, Quote_No__c,
          Quote_Adjust_Amount__c, Quote_Adjust_Calculate__c, Discount_Amount__c, Discount_Amount_Calculate__c, Installation_location__c,
          QuoteTotal_Page__c, Dealer_Final_Price_Page__c, Quote_Adjust_Amount_Page__c, OCM_Agent1_Price_Page__c, Agent1_Agent2_Price_Page__c
          , AgencyDiscount__c //  2018/09/28 CHAN-B4YAB8 经销商折扣
          //  多年保修 start
          , Gurantee_Period__c , multiYearWarranty__c, MultiYearWarrantyTotalPrice__c,
          Preferential_Gurantee_Period__c,LineItemCount 
          // 多年保修 end
          //报价试算 start
            ,IsQuoteTrial__c  
            //报价试算 end
          FROM Quote Where Id = :quoId];
      List<QuoteLineItem> items =
        [Select Id, Asset_Model_No__c, SFDA_Status__c, Product_Sales_Possibility__c,
        //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段 不可取消多年保&&增加检索阿西赛多 2020/09/10
         Name__c, BSS_Category__c, Quote.Quote_Print_Date__c,PricebookEntry.Product2.VenderName__c,PricebookEntry.Product2.CanNotCancelledGurantee__c,PricebookEntry.Product2.Is_DangerousChemicals__c,
         //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
         Qty_Unit__c, Cost__c, UnitPrice__c, ListPrice__c, Quantity, TotalPrice__c,
         PricebookEntry.Product2.SFDA_Status__c, ProductCode__c, Product_Cost__c, Product_ListPrice__c, PricebookEntry.Product2.Sales_Possibility__c, PricebookEntry.Product2.Name,
         PricebookEntryId, PricebookEntry.Product2Id, UnitPrice_Page__c, PricebookEntry.Product2.Packing_list_manual__c, PricebookEntry.Product2.StorageStatus__c
         , AgencyUnitPrice__c, AgencySubtotal__c, Present__c // CHAN-B4YAB8 2018/9/29 赠送、经销商单价和小计
         //  多年保修 start
         //ET促销标记 start
         , multiYearWarranty__c , If_Cancel_Guarantee__c , GuaranteePeriod__c,
         //ET促销标记 end
         ServicePrice__c , GuranteePrice__c, ProductEntend_gurantee_period_all__c,
         ProductGuranteePrice__c,  GuranteeType__c,
         warrantyType__c, productServicePrice__c, NoDiscountTotal__c
         , provistonPeriod__c
         , PricebookEntry.Product2.Entend_gurantee_period_all__c
         , PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c
         , PricebookEntry.Product2.Intra_Trade_Service_RMB__c
         , PricebookEntry.Product2.GuranteeType__c
         // 维修合同报价
         , PricebookEntry.Product2.Maintenance_Price_Year__c
         , Maintenance_Price_Year__c
         // 多年保修 end
         //外贸多年保 2021/01/04 精琢技术 wql start
         //维修合同报价(USD)
         ,PricebookEntry.Product2.Repair_Contract_USD__c
         //计提金额(不含税,USD)
         ,PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c
         //NoDiscount 金额(USD)
         ,PricebookEntry.Product2.NoDiscount_Foreign__c 
         //fy 预留产品标识
         ,PricebookEntry.Product2.LastbuyProductFLG__c
         ,Quote.Opportunity.Trade__c 
         //外贸多年保 2021/01/04 精琢技术 wql end
 
         //SFDC停止预警 lt 20211009 start
         ,PricebookEntry.Product2.Estimated_ConsumptionDueDate__c
         //SFDC停止预警 lt 20211009 end
 
         From QuoteLineItem where Quoteid = :quoId Order by Item_Order__c, Id];
      String copyQuoId = System.currentPageReference().getParameters().get('copyid');
      system.debug('copyid2++++++++++++'+copyQuoId);
      CheckItem = items;
 
      if (copyQuoId == null) {
      } else {
        // copyの場合、quoIdをnullに戻す
        quoId = null;
      }
      if (quoList.size() > 0) {
        //添加行
        if(quoList[0].LineItemCount >quoteEntryMaxLine){
            quoteEntryMaxLine = quoList[0].LineItemCount;
        }
        if (copyQuoId == null) {
          quo = quoList[0];
          quo.QuoteName__c = quo.Name;
          // 多年保修 start
          quoteGurantee_Period = quo.Gurantee_Period__c;
          quotemultiYearWarranty = '' + quo.multiYearWarranty__c;
          // 多年保修 end
          //报价试算 增加经销商前后对比 wql 20210508 start
          agency1Name = quo.Agency1__c;
          agency2Name = quo.Agency2__c;
          //报价试算 增加经销商前后对比 wql 20210508 end
          // 多年保修 start
          //HWAG-BLDE6J   带出字段 2020/02/10 Start
          quo.Gurantee_Period__c              = quoList[0].Gurantee_Period__c;
          quo.multiYearWarranty__c            = quoList[0].multiYearWarranty__c;
          quo.MultiYearWarrantyTotalPrice__c  = quoList[0].MultiYearWarrantyTotalPrice__c;
          // 多年保修 end
          qb.setPriceRefreshPeriodByDate(quo.PriceRefreshDate__c == null ? quo.CreatedDate.Date() : quo.PriceRefreshDate__c);
          qb.Estimation_List_Price = quo.Estimation_List_Price__c;
          quo.QuoteTotal_Page__c = quo.TotalPrice__c;
          quo.Dealer_Final_Price_Page__c = quo.Dealer_Final_Price__c;
          qb.Quote_Adjust_Calculate = quo.Quote_Adjust_Calculate__c;
          quo.Quote_Adjust_Amount_Page__c = quo.Quote_Adjust_Amount__c;
          DisCalculation = quo.Discount_Amount_Calculate__c;
          DisAmount = quo.Discount_Amount__c;
          quo.Agency1__c = quo.Agency1__c;
          AgencyDiscount = quo.AgencyDiscount__c; //2018/09/28 CHAN-B4YAB8 经销商折扣
          quo.OCM_Agent1_Price_Page__c = quo.OCM_Agent1_Price__c;
          Salesprofit1 = quo.Agency1_Profit__c;
          qb.SalesCalculation1 = quo.Agency1_Profit_Rate__c;
          //                quo.Agency1_Profit_Rate__c = quo.Agency1_Profit_Rate__c;
          quo.Agency2__c = quo.Agency2__c;
          quo.Agent1_Agent2_Price_Page__c = quo.Agent1_Agent2_Price__c;
          Salesprofit2 = quo.Agency2_Profit__c;
          qb.SalesCalculation2 = quo.Agency2_Profit_Rate__c;
        //HWAG-BLDE6J   带出字段 2020/02/10 end
        } else {
          
          
          //HWAG-BLDE6J   带出字段 2020/02/11 Start
          // quo.QuoteName__c = '';
          quo = quoList[0];
          //再报价新出来的报价名称,把“已取消”三个字去掉  精琢技术 thh 2021-09-30 start
          Integer QX = quo.Name.indexof('已取消:');
          System.debug('Name is ' + quo.Name + ', QX is ' + QX);
          if (QX >= 0) {
            quo.Name = quo.Name.subString(QX + 4);
          }
          //再报价新出来的报价名称,把“已取消”三个字去掉  精琢技术 thh 2021-09-30 end
          //报价名称
          quo.QuoteName__c = quo.Name;
          //再报价时是否进行过报价计算设为未进行过报价计算  fy 2021-11-23 start
          quo.IsQuoteTrial__c = false;
          //再报价时是否进行过报价计算设为未进行过报价计算  fy 2021-11-23 end
          quo.Cancel_Decide__c = quo.Cancel_Decide__c;
          quo.Cancel_Decide__c = false;
          quo.PriceRefreshDate__c = Date.today();
          quo.Quote_Date__c = null;
          quo.Quote_Print_Date__c = null;
          //报价总额
          quo.QuoteTotal_Page__c = quo.TotalPrice__c;
          //第一经销商
          quo.OCM_Agent1_Price_Page__c = quo.OCM_Agent1_Price__c;
          //第二经销商
          quo.Agent1_Agent2_Price_Page__c = quo.Agent1_Agent2_Price__c;
          //医院的合同金额
          quo.Dealer_Final_Price_Page__c = quo.Dealer_Final_Price__c;
          //HWAG-BLDE6J   带出字段 2020/02/11 end
        }
        // 多年保修 start
        // quo.Gurantee_Period__c              = quoList[0].Gurantee_Period__c;
        // quo.multiYearWarranty__c            = quoList[0].multiYearWarranty__c;
        // quo.MultiYearWarrantyTotalPrice__c  = quoList[0].MultiYearWarrantyTotalPrice__c;
        // // 多年保修 end
        // qb.setPriceRefreshPeriodByDate(quo.PriceRefreshDate__c == null ? quo.CreatedDate.Date() : quo.PriceRefreshDate__c);
        // qb.Estimation_List_Price = quo.Estimation_List_Price__c;
        // quo.QuoteTotal_Page__c = quo.TotalPrice__c;
        // quo.Dealer_Final_Price_Page__c = quo.Dealer_Final_Price__c;
        // qb.Quote_Adjust_Calculate = quo.Quote_Adjust_Calculate__c;
        // quo.Quote_Adjust_Amount_Page__c = quo.Quote_Adjust_Amount__c;
        // DisCalculation = quo.Discount_Amount_Calculate__c;
        // DisAmount = quo.Discount_Amount__c;
        // quo.Agency1__c = quo.Agency1__c;
        // AgencyDiscount = quo.AgencyDiscount__c; //2018/09/28 CHAN-B4YAB8 经销商折扣
        // quo.OCM_Agent1_Price_Page__c = quo.OCM_Agent1_Price__c;
        // Salesprofit1 = quo.Agency1_Profit__c;
        // qb.SalesCalculation1 = quo.Agency1_Profit_Rate__c;
        // //                quo.Agency1_Profit_Rate__c = quo.Agency1_Profit_Rate__c;
        // quo.Agency2__c = quo.Agency2__c;
        // quo.Agent1_Agent2_Price_Page__c = quo.Agent1_Agent2_Price__c;
        // Salesprofit2 = quo.Agency2_Profit__c;
        // qb.SalesCalculation2 = quo.Agency2_Profit_Rate__c;
        //                quo.Agency2_Profit_Rate__c = quo.Agency2_Profit_Rate__c;
      }
 
      activities = new List<QELine>();
      i = 0;
      QELine c = new QELine(i);
      if (items.size() > 0) {
        for (QuoteLineItem o : items) {
          c = new QELine(o, i, copyQuoId);
          activities.add(c);
          i++;
        }
 
        for (integer j = i; j < quoteEntryMaxLine; j++) {
          c = new QELine(j);
          activities.add(c);
        }
 
      } else {
        activities = new List<QELine>();
        for (i = 0; i < quoteEntryMaxLine; i++) {
          QELine active_activity = new QELine(i);
          activities.add(active_activity);
        }
      }
      //******************************************************************************************
      //            增加检测产品状态是否发生变化
      //******************************************************************************************
 
      // CHAN-BHN7P5 start
 
      //全件洗い替えします。
      if (activities.size() > 0  && !QuoteDecision) {
        productStatusUpdated = false;
        for (QELine a : activities) {
          if (string.isNotEmpty(a.Asset_Model)) {
            // CHAN-AVG3PW 询价报价画面规则变更
            // 只要更新,就生成新报价编码
            if (a.PageObject.SFDA_Status__c != a.latestInfo.SFDA_Status ||
                a.PageObject.Name__c != a.latestInfo.ProductName ||
                a.ListPrice_Page != a.latestInfo.ListPrice ||
                a.PageObject.Cost__c != a.latestInfo.Cost ||
                a.Cost_c != a.latestInfo.Cost
                // 多年保修 start
                //计提金额
                || a.ProductGuranteePrice != a.latestInfo.Intra_Trade_Gurantee
                || a.PageObject.productServicePrice__c  != a.latestInfo.Intra_Trade_Service
                // 维修合同报价
                || a.Maintenance_Price_Year != a.latestInfo.Maintenance_Price_Year
                || a.PageObject.GuranteeType__c != a.latestInfo.GuranteeType
                || a.PageObject.ProductEntend_gurantee_period_all__c != a.latestInfo.ProductEntend_gurantee_period_all
                //不可取消多年保 询价根据勾不同 自动更新价格 精琢技术 wql 20200924
                || a.PageObject.PricebookEntry.Product2.CanNotCancelledGurantee__c != a.latestInfo.CanNotCancelledGurantee
                //不可取消多年保 询价根据勾不同 自动更新价格 精琢技术 wql 20200924
                // 多年保修 end
               ) {
              system.debug('qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq:');
               system.debug('上次SFDA状态:'+a.PageObject.SFDA_Status__c);
                system.debug('最新的SFDA状态:'+a.latestInfo.SFDA_Status);
                system.debug('上次Name__c:'+a.PageObject.Name__c);
                system.debug('最新的ProductName:'+a.latestInfo.ProductName);
                system.debug('上次ListPrice:'+a.ListPrice_Page);
                system.debug('最新的上次ListPrice:'+a.latestInfo.ListPrice);
                system.debug('上次Cost__c:'+a.Cost_c);
                system.debug('最新的Cost:'+a.latestInfo.Cost);
                system.debug('上次Cost__c:'+a.Cost_c);
                system.debug('最新的Cost:'+a.latestInfo.Cost);
                system.debug('上次计提金额:'+a.ProductGuranteePrice);
                system.debug('最新的计提金额:'+a.latestInfo.Intra_Trade_Gurantee);
                system.debug('上次nodis:'+a.PageObject.productServicePrice__c);
                system.debug('最新的nodis:'+a.latestInfo.Intra_Trade_Service);
                system.debug('上次维修合同报价:'+a.Maintenance_Price_Year);
                system.debug('最新的维修合同报价:'+a.latestInfo.Maintenance_Price_Year);
                system.debug('上次GuranteeType__c:'+a.PageObject.GuranteeType__c);
                system.debug('最新的GuranteeType__c:'+a.latestInfo.GuranteeType);
                system.debug('上次ProductEntend_gurantee_period_all__c:'+a.PageObject.ProductEntend_gurantee_period_all__c);
                system.debug('最新的ProductEntend_gurantee_period_all__c:'+a.latestInfo.ProductEntend_gurantee_period_all);
                system.debug('上次CanNotCancelledGurantee__c:'+a.PageObject.PricebookEntry.Product2.CanNotCancelledGurantee__c);
                system.debug('最新的CanNotCancelledGurantee__c:'+a.latestInfo.CanNotCancelledGurantee);
                system.debug('newQuoteFlag11:'+newQuoteFlag);
              newQuoteFlag = true;
              productStatusUpdated = true;
            }
            if (a.pageObject.Name__c != a.latestInfo.ProductName) {
              a.changed_name = true;
              productStatusUpdated = true;
            }
            if (a.pageObject.SFDA_Status__c != a.latestInfo.SFDA_Status) {
              a.changed_sfda = true;
              productStatusUpdated = true;
            }
            if (a.ListPrice_Page != a.latestInfo.ListPrice) {
              a.changed_list = true;
              productStatusUpdated = true;
            }
            if (a.pageObject.Cost__c != a.latestInfo.Cost) {
              a.changed_cost = true;
              productStatusUpdated = true;
            }
            // TODO katsu SFDAステータスの確認などいらないですか(最新商品XXXの項目も)
 
            a.PageObject.SFDA_Status__c = a.latestInfo.SFDA_Status;
 
            a.PageObject.Name__c = a.latestInfo.ProductName;
            a.ListPrice_Page = a.latestInfo.ListPrice;
            a.PageObject.Cost__c = a.latestInfo.Cost;
            a.Cost_c = a.latestInfo.Cost;
            //多年保修 start
            a.ProductGuranteePrice =  a.latestInfo.Intra_Trade_Gurantee;
            // 计提金额
            a.PageObject.productServicePrice__c = a.latestInfo.Intra_Trade_Service;
            // 维修合同报价
            a.Maintenance_Price_Year = a.latestInfo.Maintenance_Price_Year;
            // 多年保修年限
            a.PageObject.ProductEntend_gurantee_period_all__c
              = a.latestInfo.ProductEntend_gurantee_period_all;
            a.PageObject.GuranteeType__c = a.latestInfo.GuranteeType;
            //多年保修 end
          }
        }
 
      }
      pageArrange();
 
      // CHAN-BHN7P5 end
      // CHAN-BHN7P5 原逻辑 start
      // else {
      //   List<String> product2Ids = New List<String>();
      //   if (activities.size() > 0) {
      //     for (QELine a : activities) {
      //       if (String.isBlank(a.PageObject.Id__c) == false) {
      //         product2Ids.add(a.PageObject.Id__c);
      //       }
      //     }
      //   }
      //   Map<String, QuoteLineItem> loopMap = new Map<String, QuoteLineItem>();
      //   if (CheckItem.size() > 0) {
      //     for (QuoteLineItem qli : CheckItem) {
      //       loopMap.put(qli.PricebookEntry.Product2Id, qli);
      //     }
      //   }
      //   // ここを修正したら、NFM007.triggerも要確認
      //   prd2LatestValMap = new Map<Id, Product2>();
      //   if (CheckItem.size() > 0) {
      //     List<Product2> plo = [Select Id, Name, Estimation_Entry_Possibility__c, SFDA_Status__c, Packing_list_manual__c,
      //                           Intra_Trade_List_RMB__c, Foreign_Trade_List_US__c,
      //                           Intra_Trade_Cost_RMB__c, Foreign_Trade_Cost_US__c
      //                           // 多年保修 start
      //                           , Intra_Trade_Gurantee_RMB__c
      //                           , Intra_Trade_Service_RMB__c
      //                           , Maintenance_Price_Year__c
      //                           // 多年保修 end
      //                           From Product2 Where Id IN :product2Ids];
      //     if (plo.size() > 0) {
      //       for (Product2 prd2 : plo) {
      //         Decimal listPrice = 0;
      //         Decimal costPrice = 0;
      //         //多年保修 start
      //         decimal ProductGuranteePrice = 0;
      //         decimal productService = 0;
      //         decimal productMaintenance_Price_Year = 0;
      //         //多年保修 end
      //         if (opp.Trade__c == '内貿') {
      //           listPrice = prd2.Intra_Trade_List_RMB__c;
      //           costPrice = prd2.Intra_Trade_Cost_RMB__c;
      //           //多年保修 start
      //           ProductGuranteePrice = prd2.Intra_Trade_Gurantee_RMB__c;
      //           productService = prd2.Intra_Trade_Service_RMB__c;
      //           productMaintenance_Price_Year = prd2.Maintenance_Price_Year__c == null ? 0 : prd2.Maintenance_Price_Year__c;
      //           //多年保修 end
      //         } else if (opp.Trade__c == '外貿') {
      //           listPrice = prd2.Foreign_Trade_List_US__c;
      //           costPrice = prd2.Foreign_Trade_Cost_US__c;
      //         }
      //         if ( prd2.Name.replaceAll('\\s+', '')            != loopMap.get(prd2.Id).Name__c.replaceAll('\\s+', '')     ||
      //              prd2.SFDA_Status__c != loopMap.get(prd2.Id).SFDA_Status__c ||
      //              listPrice           != loopMap.get(prd2.Id).ListPrice__c   ||
      //              costPrice           != loopMap.get(prd2.Id).Cost__c
      //              // 多年保修 start
      //              || ( opp.Trade__c == '内貿' &&
      //                   (ProductGuranteePrice != loopMap.get(prd2.Id).ProductGuranteePrice__c
      //                    || productService != loopMap.get(prd2.Id).productServicePrice__c
      //                    || productMaintenance_Price_Year !=
      //                    loopMap.get(prd2.Id).Maintenance_Price_Year__c
      //                   ))
      //              // 多年保修 end
      //            ) {
      //           WinOrDecideAlert = true;
      //         }
 
      //       }
      //     }
 
      //   }
      //   system.debug('WinOrDecideAlert:::::::2' + WinOrDecideAlert );
      // }// CHAN-BHN7P5 原逻辑 end
      //******************************************************************************************
      //            增加检测产品状态是否发生变化==================End 20161115 by ZDF
      //******************************************************************************************
    }
 
    // 多年保修 start
    if (quo.Gurantee_Period__c == null) {
      quo.Gurantee_Period__c = '1';
    }
 
    // 多年保修 end
    //初期値設定
    if (accountid != null) {
      List<Account> accs2 = [Select Id, RecordType.DeveloperName, Hospital__c, Agent_Ref__c From Account Where Id = :accountid];
      if (accs2.size() > 0) {
        List<Account> accs = new List<Account>();
        if (accs2[0].RecordType.DeveloperName != 'AgencyContract') {
          accs = [Select Id, Name, Site, Alias_Name2__c From Account Where Id = :accs2[0].Hospital__c];
        } else {
          accs = [Select Id, Name, Site, Alias_Name2__c From Account Where Id = :accs2[0].Agent_Ref__c];
        }
        if (accs.size() > 0) {
          options_hp = new List<SelectOption>();
          if (accs[0].Name != null) {
            options_hp.add(new SelectOption(accs[0].Name, accs[0].Name));
          }
          if (accs[0].Site != null) {
            options_hp.add(new SelectOption(accs[0].Site, accs[0].Site));
          }
          if (accs[0].Alias_Name2__c != null) {
            options_hp.add(new SelectOption(accs[0].Alias_Name2__c, accs[0].Alias_Name2__c));
          }
          //初期値設定
          if (quo.Print_HP_Name__c == null) {
            selection_hp = accs[0].Name;
          } else {
            selection_hp = quo.Print_HP_Name__c;
          }
        }
      }
    }
 
    if (quo.Quote_Expiration_Date__c == null) {
      quo.Quote_Expiration_Date__c = Date.today() + 30;
    }
 
    //--Printbutton
    if (QuoteCorrect == false) {
      print_button = true;
    } else if (verified == false) {
      print_button = true;
    } else {
      print_button = false;
    }
    //--SAPButton
    if (QuoteDecision == false) {
      sap_button = true;
    } else if (specialAuthority == false) {
      sap_button = true;
    } else {
      sap_button = false;
    }
    //--Decisionbutton
    if (verified == true) {
      Decision_button = false;
    } else if (QuoteCorrect == false) {
      Decision_button = true;
    } else if (QuoteDecision == true) {
      Decision_button = true;
    } else {
      Decision_button = false;
    }
    // もし、すでに決定ずみの場合、決定ボタンをつかえないようにする
    if (QuoteSapSented == true || QuoteDecision == true) {
      Decision_button = true;
    }
    //--Savebutton
    if (QuoteDecision == true) {
      Save_button = true;
    } else {
      Save_button = false;
    }
    // CHAN-AVG3PW 询价报价画面规则变更
    Datetime cDate = quo.CreatedDate;
    over3month = cDate != null && cDate.date().addMonths(3) < Date.today();
 
    return null;
  }
 
 
  //Search Events============================================================
  // TODO ManualEntryと同様、jsにて解決できる、ここでwebserviceだけを実装、今後 by katsu
  public PageReference setProductEntry() {
    system.debug('-----:start');
    system.debug('○○○○○○○○○○○○○○○Welcome to setProductEntry!!');
    system.debug('▼▼▼▼▼setProduct_text:' + setProduct_text);
    setOppFromOppInfo();
    List<String> productIDLIST = new List<String>();
    //既存データ数の確認
    Integer currentDetailNumber = 0;
    for (QELine s : activities) {
      //データ判定にAsset_Model_Noを使用
      if ((s.Asset_Model == null) || (s.Asset_Model == '')) {
        break;
      }
      currentDetailNumber++;
    }
 
    //既存データ数が150以上?
    if (currentDetailNumber >= quoteEntryMaxLine) {
      //添加行
      errorflg = true;
      errormessage = System.Label.Error_Message32;
      PageArrange();
      system.debug('-----:強制終了:00');
      return null;
    }
 
    // SearchSetProductから、セット品コードは渡ってきたか?
    if (setProduct_text == null) {
      // セット品コードが渡ってこなかった場合
      // 終了
      PageArrange();
      system.debug('-----:強制終了:01');
      return null;
    } else {
      productIDLIST = setProduct_text.split(',');
    }
 
    // セット品明細の ProductId一覧を格納する
    // pricebookEntry + product2へのクエリのWhere句で使用する
    List<Id> productIds = null;
 
    // ----------------------------------------------------------------------------------------
    // 該当するセット品明細のレコードを取得
    // ----------------------------------------------------------------------------------------
    system.debug('-----:Product_Set_Detail__c select start');
    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段&&增加检索阿西赛多 start
    List<Product_Set_Detail__c> productSetDetails = [SELECT Id, Product__c, Quantity__c, Product_Set__r.Name,Product__r.VenderName__c,Product__r.CanNotCancelledGurantee__c,Product__r.Is_DangerousChemicals__c FROM Product_Set_Detail__c Where Product_Set__c in :productIDLIST];
    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
    system.debug('-----:Product_Set_Detail__c select end');
    if (productSetDetails.size() == 0) {
      PageArrange();
      return null;
    } else {
      productIds = new List<Id>();
      for (Product_Set_Detail__c local : productSetDetails) {
        productIds.add(local.Product__c);
      }
    }
 
    //=======Temporary=====
    tmpactivities = activities;
 
    //=======Initialize=========
    activities = new List<QELine>();
 
    boolean lineflg = false;
 
    // ----------------------------------------------------------------------------------------
    // Product2へのクエリを実行
    // 一度Listで結果を受けた後に、Product2Idの Mapにする
    // ----------------------------------------------------------------------------------------
    system.debug('-----:Product2 select start');
    Map<Id, Product2> items = new Map<Id, Product2>();
    List<Product2> products = [select Id, Name, ProductCode,
                               Foreign_Trade_Cost_US__c, Foreign_Trade_List_US__c, Intra_Trade_Cost_RMB__c, Intra_Trade_List_RMB__c,
                               //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段
                               Asset_Model_No__c, Sales_Possibility__c, Estimation_Entry_Possibility__c,VenderName__c,
                               //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                               SFDA_Status__c, Qty_Unit__c, BSSCategory__c, Packing_list_manual__c, StorageStatus__c
                               // 多年保修 start
                               , Entend_gurantee_period_all__c
                               , Intra_Trade_Gurantee_RMB__c
                               , Intra_Trade_Service_RMB__c
                               , GuranteeType__c
                               // 维修合同价格
                               , Maintenance_Price_Year__c
                               // 多年保修 end
                               //增加检索 不可取消多年保 2020/08/27
                               ,CanNotCancelledGurantee__c
                               //增加检索 阿西赛多 2020/09/10 start
                               ,Is_DangerousChemicals__c
                               //外贸多年保 2021/01/04 精琢技术 wql start
                               //维修合同报价(USD)
                               ,Repair_Contract_USD__c
                               //fy 预留产品标识
                               ,LastbuyProductFLG__c
                               //计提金额(不含税,USD)
                               ,Intra_Trade_Foreign_RMB__c
                               //NoDiscount 金额(USD)
                               ,NoDiscount_Foreign__c
                               //外贸多年保 2021/01/04 精琢技术 wql end
 
                              //SFDC停止预警 lt 20211009 start
                              ,Estimated_ConsumptionDueDate__c
                              //SFDC停止预警 lt 20211009 end
 
                               FROM Product2 Where Id IN :productIds
                               And Manual_Entry__c = false];
    for (Product2 product : products) {
      items.put(product.Id, product);
    }
    system.debug('-----:Product2 select end');
    system.debug('-----:PricebookEntry select start');
    Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>();
    List<PricebookEntry> workEntries = [
                                         SELECT Id, Product2Id
                                         FROM PricebookEntry Where Product2Id IN :productIds
                                         AND CurrencyIsoCode = :(opp.Trade__c == '外貿' ? 'USD' : 'CNY')
                                             AND IsActive = true
                                       ];
    for (PricebookEntry workEntry : workEntries) {
      entries.put(workEntry.Product2Id, workEntry);
    }
    system.debug('-----:PricebookEntry select end');
 
    // ----------------------------------------------------------------------------------------
    // 画面の明細行のループ
    // ----------------------------------------------------------------------------------------
    Integer i = 0;
    Integer rightcnt = 0; // 成功した数をカウント
    for (QELine t : tmpactivities) {
 
      QELine a = New QELine(i);
 
      system.debug('-----:i=' + i + ', currentDetailNumber=' + currentDetailNumber);
 
      if (i == currentDetailNumber) {
        // ----------------------------------------------------------------------------------------
        // 一回だけ実行されるコード
        // ----------------------------------------------------------------------------------------
        system.debug('-----:items.size()=' + items.size());
        if (items.size() > 0) {
          // ----------------------------------------------------------------------------------------
          // セット品明細のループ
          // ----------------------------------------------------------------------------------------
          system.debug('-----:セット品明細のループスタート');
          for (Integer l = 0; l < productSetDetails.size(); l++) {
            Product_Set_Detail__c nowDetail = productSetDetails[l];
            Product2 prd = items.get(nowDetail.product__c);
            PricebookEntry pbe = entries.get(nowDetail.product__c);
 
            if (pbe == null) {
              system.debug('This Productid(' + nowDetail.product__c +  ') is not exist PricebookEntry');
              // ----------------------------------------------------------------------------------------
              // 取得済みの Product2のリストの中に、セット品明細の情報がみつからない場合
              // なにもしないでスルーする
              // ----------------------------------------------------------------------------------------
            } else {
              // ----------------------------------------------------------------------------------------
              // 取得済みの Product2のリストの中に、セット品明細の情報がみつかった
              // 明細のその Product2の情報をセットする?
              // ----------------------------------------------------------------------------------------
              QELine c = null;
              Integer Quantity_c = nowDetail.Quantity__c > 0 ? Integer.valueOf(nowDetail.Quantity__c) : 1;
              if (opp.Trade__c == '外貿') {
                if (prd.Foreign_Trade_List_US__c > 0 && prd.Foreign_Trade_Cost_US__c > 0) {
                  //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段&& 增加检索阿西赛多
                  c = new QELine(i, prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c,prd.VenderName__c,
                                prd.Estimated_ConsumptionDueDate__c, //20211009 lt add   ('',)
                                pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c,
                    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                                 prd.ProductCode, nowDetail.product__c, prd.SFDA_Status__c,
                                 prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
                                 Quantity_c, prd.Foreign_Trade_List_US__c,
                                 prd.Foreign_Trade_List_US__c, prd.Foreign_Trade_Cost_US__c,
                                 prd.Packing_list_manual__c
                                 // 多年保修 start
                                 , prd.Entend_gurantee_period_all__c
                                 //外贸多年保 取产品主数据上的金额及维修合同报价 精琢技术 wql 2021/01/04 start
                                 , prd.Intra_Trade_Foreign_RMB__c
                                 , prd.GuranteeType__c
                                 , prd.NoDiscount_Foreign__c, prd.Repair_Contract_USD__c
                                 //外贸多年保 取产品主数据上的金额及维修合同报价 精琢技术 wql 2021/01/04 end
                                 // 多年保修 end
                                );
 
                } else {
                  continue;
                }
              } else if (opp.Trade__c == '内貿') {
                if (prd.Intra_Trade_List_RMB__c > 0 && prd.Intra_Trade_Cost_RMB__c > 0) {
                  //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段&&增加检索阿西赛多
                  c = new QELine(i,prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c,prd.VenderName__c, 
                                prd.Estimated_ConsumptionDueDate__c,   //20211009 lt add
                                pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c,
                    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                                 prd.ProductCode, nowDetail.product__c, prd.SFDA_Status__c,
                                 prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
                                 Quantity_c, prd.Intra_Trade_List_RMB__c,
                                 prd.Intra_Trade_List_RMB__c, prd.Intra_Trade_Cost_RMB__c,
                                 prd.Packing_list_manual__c
                                 // 多年保修 start
                                 , prd.Entend_gurantee_period_all__c
                                 , prd.Intra_Trade_Gurantee_RMB__c
                                 , prd.GuranteeType__c
                                 , prd.Intra_Trade_Service_RMB__c
                                 //维修合同报价
                                 , prd.Maintenance_Price_Year__c
                                 // 多年保修 end
                                );
 
                } else {
                  continue;
                }
              } else {
                continue;
                // c = new QELine(i, pbe.Id, prd.Asset_Model_No__c, prd.ProductCode, nowDetail.product__c, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
                //        Quantity_c, 0, 0, 0);
              }
              activities.add(c);
 
              if (i == 149) {
                // 明細行の最大値に達したら、処理を終了する
                PageArrange();
                system.debug('-----:強制終了:98');
                return null;
              }
 
              i++;
              rightcnt++;
              lineflg = true;
            }
          }
          system.debug('-----:セット品明細のループ終了');
          if (lineflg == true) {
            i--;
          }
        } else {
          // ----------------------------------------------------------------------------------------
          // Product2へのクエリが結果を返さなかった時に実行されるコード
          // ----------------------------------------------------------------------------------------
          a = t;
          a.lineNo = i;
          activities.add(a);
        }
      } else {
        // ----------------------------------------------------------------------------------------
        // Product2へクエリを投げない時に実行されるコード
        // ----------------------------------------------------------------------------------------
        a = t;
        a.lineNo = i;
        activities.add(a);
      }
 
      i++;
      if (i > 149) {
        break;
      }
    }
 
    PageArrange();
    if (productSetDetails.size() > 0) {
      errorflg = true;
      errormessage = productSetDetails[0].Product_Set__r.Name + ' 导入结束,导入 ' + productSetDetails.size() + ' 件,成功' + rightcnt + ' 件';
    }
    system.debug('-----:終了:' + errormessage);
    return null;
  }
 
  // xudan 20140626 行追加ロジック実装
  public void addRow() {
    List<QELine> tmpQELine = new List<QELine>();
    system.debug('添加行size:'+activities.size());
    system.debug('需要添加行:'+rowIdx);
    for (Integer i = 0; i < activities.size(); i++) {
      if (i < rowIdx) {
        tmpQELine.add(activities[i]);
      } else if ( i == rowIdx) {
        tmpQELine.add(new QELine(i));
      } else {
        tmpQELine.add(activities[i - 1]);
        tmpQELine[tmpQELine.size() - 1].lineNo = i;
      }
    }
    activities = new List<QELine>();
    activities.addAll(tmpQELine);
    PageArrange();
  }
  //添加行
  public void addMultipleRow() {
    List<QELine> tmpQELine = new List<QELine>();
    //页面上的输入框追加 (只能在末尾追加)
    
    Integer lineRows  = activities.size() + rowIdx;
    if(lineRows>0 && lineRows>activities.size()&&activities.size()>0){
        //页面输入0或负数都不应该继续执行
        for (Integer i = 0; i < lineRows; i++) {
            if (i < activities.size()) {
                tmpQELine.add(activities[i]);
            } else{
                tmpQELine.add(new QELine(i));
            } 
        }
        system.debug('tmpQELine:'+tmpQELine);
        //如果发生行数变化 则后台最大报价行也更新
        if(quoteEntryMaxLine < lineRows){
            quoteEntryMaxLine = lineRows;
        }
 
        
        //重画页面 重画新增行
        activities = new List<QELine>();
        activities.addAll(tmpQELine);
        PageArrange();
    }
    
  }
 
  //excelImport
  public PageReference excelImport() {
    system.debug('○○○○○○○○○○○○○○○Welcome to excelImport!!');
    system.debug('▼▼▼▼▼excel_text:' + excel_text);
    //oppに画面の値を設定
    setOppFromOppInfo();
 
    errorflg = false;
    errormessage = null;
 
    //既存データ数の確認
    Integer j = 0;
    for (QELine s : activities) {
      //データ判定にAsset_Model_Noを使用
      if ((s.Asset_Model == null) || (s.Asset_Model == '')) {
        break;
      }
      j++;
    }
 
    //=======Temporary=====
    tmpactivities = activities;
 
    //=======Initialize=========
    activities = new List<QELine>();
    //List<OpportunityLineItem> items = New List<OpportunityLineItem>();
    Integer i = 0;
    Integer xlscnt = 0;
    Integer rightcnt = 0; // 成功した数をカウント
 
    string[] xlslists = excel_text.split('\n', -1);
    List<string> xlslist = New list<string>();
    List<string> codelist = New List<string>();
    List<Integer> Quantitylist = New List<Integer>();
    //String str ;
 
    Map<String, Integer> mp = new Map<String, Integer>();
    string xlscode;
    Integer xlsQuantity;
 
    try {
      for (string xls : xlslists) {
        if (xls == null || xls == '') {
          //null
        } else {
          xlscode = null;
          xlsQuantity = null;
          xlslist = xls.split('\t', -1);
          for (String s : xlslist) {
            //odd number or even number
            if (math.mod(i, 2) != 0) {
              //odd number
              if (s == '' || s == null) {
                errorflg = true;
                errormessage = System.Label.Error_Message31;
                activities = tmpactivities;
                pageArrange();
                return null;
              } else {
                s = s.trim();
                xlsQuantity = Integer.valueOf(s);
                Quantitylist.add(xlsQuantity);
              }
            } else {
              //even number
              if (s == '' || s == null) {
                errorflg = true;
                errormessage = System.Label.Error_Message31;
                activities = tmpactivities;
                pageArrange();
                return null;
              } else {
                s = s.trim();
                codelist.add(s);
                xlscode = s;
              }
            }
            i++;
          }
          //mp.put(xlscode, xlsQuantity);
          xlscnt++;
        }
      }
    } catch (Exception ex) {
      activities = tmpactivities;
      errorflg = true;
      errormessage = System.Label.Error_Message31;
      pageArrange();
      return null;
    }
 
    system.debug(j);
    system.debug('xlscnt:::::' + xlscnt);
 
    if (codelist.size() == 0 || Quantitylist.size() == 0) {
      activities = tmpactivities;
      errorflg = true;
      errormessage = System.Label.Error_Message31;
      pageArrange();
      return null;
    }
 
    xlscnt = j + xlscnt;
    if (xlscnt > quoteEntryMaxLine) {
      activities = tmpactivities;
      errorflg = true;
      errormessage = System.Label.Error_Message32;
      pageArrange();
      return null;
    }
 
    i = 0;
    boolean lineflg = false;
    for (QELine t : tmpactivities) {
      if (i == j) {
        Map<String, Product2> mpProduct2 = new Map<String, Product2>();                     // keyがProductCodeです。
        List<Product2> items = [select Id, Name, ProductCode,
                                Foreign_Trade_Cost_US__c, Foreign_Trade_List_US__c, Intra_Trade_Cost_RMB__c, Intra_Trade_List_RMB__c,
                                //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段
                                Asset_Model_No__c, Sales_Possibility__c, Estimation_Entry_Possibility__c,VenderName__c,
                                //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                                SFDA_Status__c, Qty_Unit__c, BSSCategory__c, Packing_list_manual__c, StorageStatus__c
                                // 多年保修 start
                                , Entend_gurantee_period_all__c
                                , Intra_Trade_Gurantee_RMB__c
                                , Intra_Trade_Service_RMB__c
                                , GuranteeType__c
                                // 维修合同报价
                                ,  Maintenance_Price_Year__c
                                // 多年保修 end
                                //增加检索 不可取消多年保 2020/08/27
                               ,CanNotCancelledGurantee__c
                               //增加检索 阿西赛多 2020/09/10
                               ,Is_DangerousChemicals__c
                               //外贸多年保 2021/01/04 精琢技术 wql start
                               //维修合同报价(USD)
                               ,Repair_Contract_USD__c
                               //计提金额(不含税,USD)
                               ,Intra_Trade_Foreign_RMB__c
                               //NoDiscount 金额(USD)
                               ,NoDiscount_Foreign__c
                               //外贸多年保 2021/01/04 精琢技术 wql end  
 
                              //SFDC停止预警 lt 20211009 start
                              ,Estimated_ConsumptionDueDate__c
                              //SFDC停止预警 lt 20211009 end
 
                                FROM Product2 Where ProductCode In :codelist
                                And Manual_Entry__c = false];
        for (Product2 prd : items) {
          system.debug('prd.ProductCode:::::' + prd.ProductCode);
          mpProduct2.put(prd.ProductCode, prd);
        }
        Map<String, PricebookEntry> entries = new Map<String, PricebookEntry>();            // keyがProductCodeです。
        List<PricebookEntry> pbes = [
                                      select Id, PricebookEntry.Product2.ProductCode
                                      FROM PricebookEntry Where PricebookEntry.Product2.ProductCode IN :codelist
                                      AND CurrencyIsoCode = :(opp.Trade__c == '外貿' ? 'USD' : 'CNY')
                                          AND IsActive = true];
        for (PricebookEntry pbe : pbes) {
          system.debug('pbe.Product2.ProductCode:::::' + pbe.Product2.ProductCode);
          entries.put(pbe.Product2.ProductCode, pbe);
        }
 
        for (Integer l = 0; l < codelist.size(); l++) {
          system.debug('codelist[l]:::::' + codelist[l]);
          Product2 prd = mpProduct2.get(codelist[l]);
          if (prd != null) {
            PricebookEntry pbe = entries.get(codelist[l]);
            QELine c = null;
            if (pbe != null && (opp.Trade__c == '外貿' || opp.Trade__c == '内貿')) {
              if (opp.Trade__c == '外貿') {
                if (prd.Foreign_Trade_List_US__c > 0 && prd.Foreign_Trade_Cost_US__c > 0) {
                  //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段&&增加阿西赛多
                  c = new QELine(i,prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c, prd.VenderName__c,
                                  prd.Estimated_ConsumptionDueDate__c,//20211009 lt add  ('',)
                                  pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c, prd.ProductCode, prd.Id, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
                    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                                 Quantitylist[l], prd.Foreign_Trade_List_US__c, prd.Foreign_Trade_List_US__c, prd.Foreign_Trade_Cost_US__c, prd.Packing_list_manual__c
                                 // 多年保修 start
                                 //外贸多年保 取产品主数据上的金额及维修合同报价 精琢技术 wql 2021/01/04 start
                                 , prd.Entend_gurantee_period_all__c
                                 , prd.Intra_Trade_Foreign_RMB__c
                                 , prd.GuranteeType__c
                                 , prd.NoDiscount_Foreign__c,
                                 prd.Repair_Contract_USD__c
                                 //外贸多年保 取产品主数据上的金额及维修合同报价 精琢技术 wql 2021/01/04 end
                                 // 多年保修 end
                                );
 
                } else {
                  continue;
                }
              } else {
                if (prd.Intra_Trade_List_RMB__c > 0 && prd.Intra_Trade_Cost_RMB__c > 0) {
                  //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段&&增加检索阿西赛多
                  c = new QELine(i,prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c,prd.VenderName__c, 
                                prd.Estimated_ConsumptionDueDate__c,//20211009 lt add
                                pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c, prd.ProductCode, prd.Id, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
                    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                                 Quantitylist[l], prd.Intra_Trade_List_RMB__c, prd.Intra_Trade_List_RMB__c, prd.Intra_Trade_Cost_RMB__c, prd.Packing_list_manual__c
                                 // 多年保修 start
                                 , prd.Entend_gurantee_period_all__c
                                 , prd.Intra_Trade_Gurantee_RMB__c
                                 , prd.GuranteeType__c
                                 , prd.Intra_Trade_Service_RMB__c
                                 , prd.Maintenance_Price_Year__c
                                 // 多年保修 end
                                );
 
                } else {
                  continue;
                }
              }
            } else {
              continue;
              // c = new QELine(i, pbe.Id, prd.Asset_Model_No__c, prd.ProductCode, prd.Id, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
              //        Quantitylist[l], 0, 0, 0);              // pbe ない時も追加する、setProductEntry() のロジックと違います。
            }
            activities.add(c);
            i++;
            rightcnt++;
            lineflg = true;
          }
        }
        if (lineflg == true) {
          i--;
        } else {
          // 20140507,LW修改。
          // 当导入的所有商品都不成功时,当前明细行什么都没有做,并且i加一。导致下面循环New QELine(t, i)中i错误。
          // 修改为:当导入的所有商品都不成功时,当前明细行插入一个空行,之后i加一。
          QELine a = New QELine(t, i);
          activities.add(a);
        }
      } else {
        QELine a = New QELine(t, i);
        activities.add(a);
      }
      i++;
      if (i > 149) {
        break;
      }
    }
    // messageを出す
    errorflg = true;
    errormessage = '数据导入结束,导入 ' + codelist.size() + ' 件,成功' + rightcnt + ' 件';
    pageArrange();
 
    return null;
 
  }
 
  //販売店1
  public void getSalesId1() {
    system.debug('○○○○○○○○○○○○○○○Welcome to getSalesId1!!');
    system.debug('▼▼▼▼▼SalesId1:' + SalesId1);
    //oppに画面の値を設定
    setOppFromOppInfo();
 
    errorflg = false;
    errormessage = null;
 
    List<Account> accs = New List<Account>();
    accs = [select Id, Name, Sales_Shop_Class__c From Account Where Id = :SalesId1];
    If (accs.size() > 0) {
      SalesShopClass1 = accs[0].Sales_Shop_Class__c;
      opp.Agency1__c = accs[0].Id;
    }
    pageArrange();
  }
 
  //販売店2
  public void getSalesId2() {
    system.debug('○○○○○○○○○○○○○○○Welcome to getSalesId2!!');
    system.debug('▼▼▼▼▼SalesId2:' + SalesId2);
    //oppに画面の値を設定
    setOppFromOppInfo();
 
    errorflg = false;
    errormessage = null;
 
    List<Account> accs = New List<Account>();
    accs = [select Id, Name, Sales_Shop_Class__c From Account Where Id = :SalesId2];
    If (accs.size() > 0) {
      SalesShopClass2 = accs[0].Sales_Shop_Class__c;
      opp.Agency2__c = accs[0].Id;
    }
    pageArrange();
  }
 
 
  //Button Ivents============================================================
 
  //cancel button
  public void cancel() {
    system.debug('○○○○○○○○○○○○○○○Welcome to CancelButton!!');
    system.debug('selection_hp' + selection_hp);
  }
 
  //PriceStatusUpdate button、TODO productCompare(jsのところ)1件ずつ検索していますが、今後、webserviceを使って一括か高速かできます。
  public void PriceStatusUpdate() {
    system.debug('○○○○○○○○○○○○○○○Welcome to PriceStatusUpdate!!');
    //oppに画面の値を設定
    setOppFromOppInfo();
 
    errorflg = false;
    errormessage = null;
 
    //全件洗い替えします。
    if (activities.size() > 0) {
      for (QELine a : activities) {
        if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
          // CHAN-AVG3PW 询价报价画面规则变更
          // 只要更新,就生成新报价编码
          if (a.PageObject.SFDA_Status__c != a.latestInfo.SFDA_Status ||
              a.PageObject.Name__c != a.latestInfo.ProductName ||
              a.ListPrice_Page != a.latestInfo.ListPrice ||
              a.PageObject.Cost__c != a.latestInfo.Cost ||
              a.Cost_c != a.latestInfo.Cost
              // 多年保修 start
              //计提金额
              || a.ProductGuranteePrice != a.latestInfo.Intra_Trade_Gurantee
              || a.PageObject.productServicePrice__c  != a.latestInfo.Intra_Trade_Service
              // 维修合同报价
              || a.Maintenance_Price_Year != a.latestInfo.Maintenance_Price_Year
              // 多年保修 end
             ) {
            system.debug('qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq:');
            system.debug('上次SFDA状态:'+a.PageObject.SFDA_Status__c);
            system.debug('最新的SFDA状态:'+a.latestInfo.SFDA_Status);
            system.debug('上次Name__c:'+a.PageObject.Name__c);
            system.debug('最新的ProductName:'+a.latestInfo.ProductName);
            system.debug('上次ListPrice:'+a.ListPrice_Page);
            system.debug('最新的上次ListPrice:'+a.latestInfo.ListPrice);
            system.debug('上次Cost__c:'+a.Cost_c);
            system.debug('最新的Cost:'+a.latestInfo.Cost);
            system.debug('上次Cost__c:'+a.Cost_c);
            system.debug('最新的Cost:'+a.latestInfo.Cost);
            system.debug('上次计提金额:'+a.ProductGuranteePrice);
            system.debug('最新的计提金额:'+a.latestInfo.Intra_Trade_Gurantee);
            system.debug('上次nodis:'+a.PageObject.productServicePrice__c);
            system.debug('最新的nodis:'+a.latestInfo.Intra_Trade_Service);
            system.debug('上次维修合同报价:'+a.Maintenance_Price_Year);
            system.debug('最新的维修合同报价:'+a.latestInfo.Maintenance_Price_Year);
            system.debug('newQuoteFlag6:'+newQuoteFlag);
            newQuoteFlag = true;
          }
          if (a.pageObject.Name__c != a.latestInfo.ProductName) {
            a.changed_name = true;
          }
          if (a.pageObject.SFDA_Status__c != a.latestInfo.SFDA_Status) {
            a.changed_sfda = true;
          }
          if (a.ListPrice_Page != a.latestInfo.ListPrice) {
            a.changed_list = true;
          }
          if (a.pageObject.Cost__c != a.latestInfo.Cost) {
            a.changed_cost = true;
          }
          // TODO katsu SFDAステータスの確認などいらないですか(最新商品XXXの項目も)
          a.PageObject.SFDA_Status__c = a.latestInfo.SFDA_Status;
          a.PageObject.Name__c = a.latestInfo.ProductName;
          a.ListPrice_Page = a.latestInfo.ListPrice;
          a.PageObject.Cost__c = a.latestInfo.Cost;
          a.Cost_c = a.latestInfo.Cost;
          //多年保修 start
          a.PageObject.ProductGuranteePrice__c =  a.latestInfo.Intra_Trade_Gurantee;
          a.PageObject.GuranteeType__c = a.latestInfo.GuranteeType;
          // 计提金额
          a.PageObject.productServicePrice__c = a.latestInfo.Intra_Trade_Service;
          // 多年保修年限
          a.PageObject.ProductEntend_gurantee_period_all__c
            = a.latestInfo.ProductEntend_gurantee_period_all;
          // 维修合同报价
          a.Maintenance_Price_Year = a.latestInfo.Maintenance_Price_Year;
          //多年保修 end
        }
      }
      productStatusUpdated = true;
    }
    pageArrange();
  }
 
  //Save button
  public PageReference Save() {
    // Boolean ifdecide=false;
    // List<Opportunity> oppsde = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
    // if (oppsde.size() > 0) {
    //   if(oppsde[0].Estimation_Decision__c){
    //     ifdecide=true;
    //   }else{
    //     ifdecide=false;
    //   }
    // }
    // system.debug('oppsde:::::::1' + oppsde );
    // if(!ifdecide){
      setOppFromOppInfo();
      System.debug('Save() start at: ' + System.currentTimeMillis());
      system.debug('WinOrDecideAlert:::::::3' + WinOrDecideAlert );
      errorflg = false;
      errormessage = null;
      errorMessagechack = null;
      Savepoint sp = Database.setSavepoint();
      try {
        // CHAN-AVG3PW 询价报价画面规则变更
        // 报价创建日超过三个月时,点保存时强制更新
        // CHAN-AZG864 不管在不在报价有效期内,CFDA不可销售的时候,都是报错的,其中不可销售产品显示红字,不应该保存。
        if (WinOrDecideAlert && (!productStatusUpdated)) {
          errorflg = true;
          errorMessage = '产品状态发生变化,请更新';
          return null;
        }
        if (checkSFDAStatus1(false) == false) {
          errorflg = true;
          errormessage = '请更新不可销售的产品。';
          return null;
        }
 
        System.debug('checkSFDAStatus1 finished at: ' + System.currentTimeMillis());
 
        //データチェック
        if (dataCheck() == false) {
          return null;
        }
 
        System.debug('dataCheck finished at: ' + System.currentTimeMillis());
 
        // LHJ 授权check Start
        if (enableSales == true && opp.Trade__c == '内貿') {
 
          //经销商产品注册证匹配
          Map<Id, String> proMap = new Map<Id, String>();
          
          if (activities.size() > 0) {
            for (QELine qli : activities) {
              if (qli.Asset_Model != null && qli.Asset_Model != '') {
                proMap.put(qli.pageObject.Id__c, qli.PageObject.Name__c);
              }
            }
          }
          
          // GZW 画面出错误消息
          Map<String, String> chkMap = OpportunityWebService.MapCheckProRegisterDecide(proMap, opp.Agency1__c, '');
          //this.haveno_Register 没有注册证 状态红色
          //this.wrong_Register  匹配不上  名字红色
          if (chkMap.size() > 0) {
            errorflg = true;
            //阿西塞多 取消该检查
            if (chkMap.containsKey('agency')&&!opp.Is_Corrosion__c) {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '第一经销商没有有效的医疗器械经营许可证。'));
            }
            Integer inerr = 0;
            if (activities.size() > 0) {
              for (QELine s : activities) {
                if (s.Asset_Model != null && s.Asset_Model != '') {
                  s.haveno_Register = false;
                  s.wrong_Register = false;
                  if (chkMap.containsKey(s.PageObject.Id__c)) {
                    if (chkMap.get(s.PageObject.Id__c) == '1') {
                      s.haveno_Register = true;
                      inerr ++;
                    } else if (chkMap.get(s.PageObject.Id__c) == '2') {
                      s.wrong_Register = true;
                      inerr ++;
                    }
                  }
                }
              }
            }
            if (inerr > 0) {
              errorMessagechack = '请检查红字内容(NMPA状态红字,不可销售产品;产品名称红字,超过经销商经营范围)。';
            }
          }
          //阿西赛多 是否危险化学品经营许可证 保存提示可以保存 decide提示不可decide 精琢技术 wql 2020/12/30 start
 
          //询价是阿西赛多 判断标识
          Boolean isDangerError = false;
          //询价不是阿西赛多 判断标识
          Boolean isNotDangerError = false;
 
          //条件是 内贸 && 经销商  && 是否是阿西赛多 为true
          //没有合并在上面的for循环的原因是,怕有冲突将标识置为false
          if (activities.size() > 0) {
            for (QELine qli : activities) {
              if (qli.Asset_Model != null && qli.Asset_Model != '') {
                  //阿西赛多 页面提示报错信息 2020/12/30 start
                  //如果询价是阿西赛多 则选择一般产品的标红
                  system.debug('是否阿西赛多询价');
                  system.debug(opp.Is_Corrosion__c);
                  if (opp.Is_Corrosion__c) {
                      //不是危化品
                      if(!qli.Is_DangerousChemicals){
                        //提示报错
                        isNotDangerError =true;
                        //名称报红
                        qli.wrong_Register = true;
 
                      }
 
                  }else{
                    //如果询价不是阿西赛多,则选择危化品的标红
                    if(qli.Is_DangerousChemicals){
                        //提示报错
                        isDangerError =true;
                        //名称报红
                        qli.wrong_Register = true;
                    }
                  }
                  //阿西赛多 页面提示报错信息 wql 2020/12/30 end
                
              }
              
              
            }
          }
 
          
          if (opp.Is_Corrosion__c) {
            String str = OpportunityWebService.checkDangerItem(opp.agency1__c);
            if (str != 'OK') {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  str));
            } 
            system.debug('不是危化品标识:'+isNotDangerError);
              //代表行项目有不是危化品的
              if(isNotDangerError){
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '当阿西塞多时,行项目的产品必须全选择危化品。'));
                errorflg = true;
                errormessage = '当阿西塞多时,行项目的产品必须全选择危化品。';
                return null;
              }
              
            
          }else{
        
            system.debug('危化品标识:'+isDangerError);
              //代表行项目有危化品
              if(isDangerError){
                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '当询价不是阿西塞多时,行项目的产品不能选择危化品。'));
                errorflg = true;
                errormessage = '当询价不是阿西塞多时,行项目的产品不能选择危化品。';
                return null;
              }
          }
          system.debug('阿西赛多~~~~~end');
          //阿西赛多 是否危险化学品经营许可证 保存提示可以保存 decide提示不可decide 精琢技术 wql 2020/12/30 end
 
        }
        // LHJ End
 
        System.debug('pageCheck finished at: ' + System.currentTimeMillis());
 
        PageReference pageRef = new PageReference('/' + oppid);
        if (dataEntry() == false) {
          //msg
          return null;
        } else {
          System.debug('data save finished at: ' + System.currentTimeMillis());
          //msg
          errorflg = true;
          errorMessage = System.Label.Message_002;
          return null;
        }
      } catch (DmlException de) {
        Database.rollback(sp);
        errorflg = true;
        errormessage = de.getDmlMessage(0);           // 1件目のエラーのみ表示
        system.debug(Logginglevel.ERROR, de.getMessage());
        system.debug(Logginglevel.ERROR, de.getStackTraceString());
      } catch (Exception e) {
        Database.rollback(sp);
        errorflg = true;
        errormessage = e.getMessage();
        system.debug(Logginglevel.ERROR, e.getMessage());
        system.debug(Logginglevel.ERROR, e.getStackTraceString());
      }
      
    // }
    // else{
    //   errorflg = true;
    //   errormessage = '该询价已经decide,不可再修改';
    //   return null;
    // }
 
    return null;
  }
 
  //OppReflection button
  public PageReference OppReflection() {
    //oppに画面の値を設定
    setOppFromOppInfo();
    Savepoint sp = Database.setSavepoint();
    try {
      errorflg = false;
      errormessage = null;
 
      // CHAN-AVG3PW 询价报价画面规则变更
      // 报价创建日超过三个月时,点保存时强制更新
      // CHAN-AZG864 不管在不在报价有效期内,CFDA不可销售的时候,都是报错的,其中不可销售产品显示红字,不应该保存。
 
      if (WinOrDecideAlert && (!productStatusUpdated)) {
        errorflg = true;
        errorMessage = '产品状态发生变化,请更新';
        return null;
      }
      if (checkSFDAStatus1(false) == false) {
        errorflg = true;
        errormessage = '请更新不可销售的产品。';
        return null;
      }
 
      //データチェック
      if (dataCheck() == false) {
        return null;
      }
 
      PageReference pageRef = new PageReference('/' + oppid);
      if (dataEntry() == false) {
        //msg
        return null;
      } else {
        //msg
        return pageRef;
      }
    } catch (DmlException de) {
      Database.rollback(sp);
      errorflg = true;
      errormessage = de.getDmlMessage(0);           // 1件目のエラーのみ表示
      system.debug(Logginglevel.ERROR, de.getMessage());
      system.debug(Logginglevel.ERROR, de.getStackTraceString());
    } catch (Exception e) {
      Database.rollback(sp);
      errorflg = true;
      errormessage = e.getMessage();
      system.debug(Logginglevel.ERROR, e.getMessage());
      system.debug(Logginglevel.ERROR, e.getStackTraceString());
    }
 
    return null;
  }
 
  //QuoteDecisionButton
  public PageReference QuoteDecision() {
    system.debug('○○○○○○○○○○○○○○○Welcome to QuoteDecision!!');
    Savepoint sp = Database.setSavepoint();
    try {
      //oppに画面の値を設定
      setOppFromOppInfo();
      if (WinOrDecideAlert && (!productStatusUpdated)) {
        errorflg = true;
        errorMessage = '产品状态发生变化,请更新';
        return null;
      }
 
      errorflg = false;
      errormessage = null;
      //20220214 fy lastbuy start 
      if(!ReservedProductVerification()){
        system.debug('flglastbuy++++'+flglastbuy);
        if(flglastbuy==1){
          errorflg = true;
          errormessage =  '预留产品表中没有录入该报价的预留产品' ;
          return null;
        }else if(flglastbuy==2){
          errorflg = true;
          errormessage =  errorProductmodel+'产品数量不可超过产品预留数量' ;
          return null;
        }else if(flglastbuy==3){
          errorflg = true;
          errormessage =  '预留产品'+errorProductmodel+'未录入预留产品表';
          return null;
        }
      }
      //20220214 fy lastbuy end
      // 2022-01-12 ssm 报价计算check
      if (checkIsQuoteTrial()) {
        errorflg = true;
        return null;
      }
 
      if (enableSales == true) {
        //販売店状態チェック
        if (dataCheckDecide() == false) {
          return null;
        }
      }
      system.debug('zzzzzzzz2:');
      // CHAN-AVG3PW 询价报价画面规则变更
      if (checkSFDAStatus2(true) == false) {
        errorflg = true;
        errormessage = '请更新不可销售的产品。';
        return null;
      }
 
      PageReference pageRef = new PageReference('/' + oppid);
      if (dataCheck() == false) {
        return null;
      }
 
      if (dataEntry() == false) {
        return null;
      } else {
        //引合に見積決定をオン
        if (oppId == null) {
          system.debug('Error is Opportunityid null!!!');
        } else {
          List<Opportunity> opps = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
          if (opps.size() > 0) {
            opps[0].Estimation_Decision__c = true;
            /*↓↓↓見積同期↓↓↓2012/11/28 未使用
            opps[0].SyncedQuoteId = quoId;
            ↑↑↑    ↑↑↑*/
            ControllerUtil.updOpp(opps[0]);
          }
 
          errorflg = true;
          errorMessage = System.Label.Message_002;
 
          // cic 134906 start
          Quote q = [select Id from Quote where Id = :quoId];
          q.Quote_Decision_Date__c = date.Today();
          update q;
          // cic 134906 end
 
          QuoteDecision = true;
          enableContract = true;
          //--Savebutton
          Save_button = true;
          //--Decisionbutton判定
          if (verified == true) {
            Decision_button = false;
          } else if (QuoteCorrect == false) {
            Decision_button = true;
          } else if (QuoteDecision == true) {
            Decision_button = true;
          } else {
            Decision_button = false;
          }
          //--SAPButton
          if (QuoteDecision == false) {
            sap_button = true;
          } else if (specialAuthority == false) {
            sap_button = true;
          } else {
            sap_button = false;
          }
          //--決定ボタン使えないようにする
          Decision_button = true;
 
          pageArrange();
        }
      }
    } catch (DmlException de) {
      Database.rollback(sp);
      errorflg = true;
      errormessage = de.getDmlMessage(0);           // 1件目のエラーのみ表示
      system.debug(Logginglevel.ERROR, de.getMessage());
      system.debug(Logginglevel.ERROR, de.getStackTraceString());
    } catch (Exception e) {
      Database.rollback(sp);
      errorflg = true;
      errormessage = e.getMessage();
      system.debug(Logginglevel.ERROR, e.getMessage());
      system.debug(Logginglevel.ERROR, e.getStackTraceString());
    }
 
    //return pageRef;
    return null;
  }
 
  //PrintButton
  public PageReference Print() {
    Savepoint sp = Database.setSavepoint();
    try {
      //oppに画面の値を設定
      setOppFromOppInfo();
 
      errorflg = false;
      errormessage = null;
 
      system.debug('○○○○○○○○○○○○○○○Welcome to Print!!');
      PageReference pageRef;
 
      //Decide前or後
      if (QuoteDecision == true) {
        //NoSave
      } else {
        // CHAN-AVG3PW 询价报价画面规则变更
        // 报价创建日超过三个月时,点保存时强制更新
        // CHAN-AZG864 不管在不在报价有效期内,CFDA不可销售的时候,都是报错的,其中不可销售产品显示红字,不应该保存。
        if (WinOrDecideAlert && (!productStatusUpdated)) {
          errorflg = true;
          errorMessage = '产品状态发生变化,请更新';
          return null;
        }
 
 
        //データチェック
        if (dataCheck() == false ) {
          return null;
        }
 
        if (dataEntry() == false) {
          //msg
          return null;
        }
      }
 
      //引合に見積提出日を保存
      List<Opportunity> opps = New List<Opportunity>();
      if (oppId == null) {
      } else {
          // 打印时,不再更新决定报价
        opps = [Select Id
                //, Estimation_Decision__c
                From Opportunity Where Id = : oppId];
        if (opps.size() > 0) {
          //見積に見積印刷日を保存
          List<Quote> quos = New List<Quote>();
          if (quoId == null) {
            //印刷させない?
          } else {
              // 打印时,不再更新决定报价
            quos = [Select Id, 
                    //Quote_Decision__c, 
                    Quote_Print_Date__c, Quote_Date__c From Quote Where Id = : quoId];
            if (quos.size() > 0) {
              //优惠成交价
              quos[0].Preferential_Trading_Price__c = quo.Preferential_Trading_Price__c;
              //优惠折扣
              quos[0].Discount__c = quo.Discount__c;
              //优惠价格
              quos[0].Pricing__c = quo.Pricing__c;
              //单价
              quos[0].Unit_Price__c = quo.Unit_Price__c;
              //报价金额
              quos[0].Offer_Amount__c = quo.Offer_Amount__c;
              //Total
              quos[0].TOTAL__c = quo.TOTAL__c;
              //契約内容
              quos[0].Contract__c = quo.Contract__c;
              //多年保修 start
              quos[0].Preferential_Gurantee_Period__c = quo.Preferential_Gurantee_Period__c;
              //多年保修 end
              if (quos[0].Quote_Date__c == null) {
                quos[0].Quote_Date__c = date.Today();
                opps[0].Estimation_Proposal_Date__c = date.Today();
                ControllerUtil.updOpp(opps[0]);
              }
              quos[0].Quote_Print_Date__c = date.Today();
              ControllerUtil.updQuote(quos[0]);
            }
          }
        }
      }
      pageArrange();
    } catch (DmlException de) {
      Database.rollback(sp);
      errorflg = true;
      errormessage = de.getDmlMessage(0);           // 1件目のエラーのみ表示
      system.debug(Logginglevel.ERROR, de.getMessage());
      system.debug(Logginglevel.ERROR, de.getStackTraceString());
    } catch (Exception e) {
      Database.rollback(sp);
      errorflg = true;
      errormessage = e.getMessage();
      system.debug(Logginglevel.ERROR, e.getMessage());
      system.debug(Logginglevel.ERROR, e.getStackTraceString());
    }
 
    return null;
 
  }
 
  //BackButton
  public PageReference Back() {
    return new Pagereference('/' + oppid);
  }
  public PageReference Jump() {
    System.debug('报价id1:'+quoId);
    //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy start
    Boolean isDecide = checkIsDecide();
    System.debug('询价:' + oppid + '|是否decide: ' + isDecide);
    //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy end
    // LHJ 授权check Start
    if (opp.If_Need_Authorize__c == true) {
      ID tmpid = opp.Agency2__c == null ? opp.Agency1__c : opp.Agency2__c;
      List<Account> accName = [select name from Account where id = : tmpid];
      //授权前允许进行报价试算  精琢技术 thh 2021-09-30 
      // if (accName[0].name != opp.Authorized_Finish_Sales__c) {
      //   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '请先授权后,再进行报价试算。'));
      // }else{
        //报价试算点击时,保存行项目 精琢技术 wql 2021/05/07 start
        if (!isDecide) {
          Save();
        } else {
          errorflg = true;
          errorMessage = System.Label.Message_002;
        }
        //报价试算点击时,保存行项目 精琢技术 wql 2021/05/07  end
        //报价试算点击时,如果保存了会生成新的报价,进入新报价的报价试算页面  精琢技术 thh 2021-09-30 start
        Quote jump = [select id from Quote where Quote_No__c = :quo.Quote_No__c];
        System.debug('报价id2:'+jump.Id);
        if(errorMessage == System.Label.Message_002){
          return new Pagereference('/apex/QuoteTrial?Id=' + jump.Id);
        }
        return null;
        //报价试算点击时,如果保存了会生成新的报价,进入新报价的报价试算页面  精琢技术 thh 2021-09-30 end
      // }
    }else{
      //报价试算点击时,保存行项目 精琢技术 wql 2021/05/07 start
      if (!isDecide) {
        Save();
      }
      //报价试算点击时,保存行项目 精琢技术 wql 2021/05/07  end
      System.debug('报价id2:'+quoId);
      return new Pagereference('/apex/QuoteTrial?Id=' + quoId);
    }
    return null;
  }
  // 0表示 対策
  private void pageArrange() {
    if (activities.size() > 0) {
      for (QELine a : activities) {
        if ((a.Asset_Model == null) || (a.Asset_Model == '')) {
          system.debug('○○○○○○○○○○○○Welcome to pageArrange Asset_Model is △');
          a.pageobject.subtotal__c = null;
          a.ListPrice_Page = null;
        } else {
          system.debug('○○○○○○○○○○○○Welcome to pageArrange Asset_Model=[' + a.Asset_Model + ']');
        }
      }
    }
    if (quo.OCM_Agent1_Price_Page__c == null) {
      Salesprofit1 = null;
      qb.SalesCalculation1 = null;
    }
    if (quo.Agent1_Agent2_Price_Page__c == null) {
      Salesprofit2 = null;
      qb.SalesCalculation2 = null;
    }
  }
 
  public boolean dataCheck() {
    //WinOrDecideAlert = false;
    system.debug('○○○○○○○○○○○○Welcome to dataCheck class!!○○○○○○○○○○○○');
    errorflg = false;
    errormessage = null;
    Boolean error = false;
    integer Gcnt = 0;
    List<String> product2Ids = New List<String>();
 
    if (activities.size() > 0) {
      system.debug('save:::'+activities);
      for (QELine a : activities) {
        if (String.isBlank(a.PageObject.Id__c) == false) {
          product2Ids.add(a.PageObject.Id__c);
        }
      }
      Map<String, String> loopMap = new Map<String, String>();
      if (CheckItem != null) {
        Gcnt = CheckItem.size();
        if (CheckItem.size() > 0) {
          for (QuoteLineItem qli : CheckItem) {
            loopMap.put(qli.PricebookEntry.Product2Id, qli.SFDA_Status__c);
          }
        }
      }
      //
      // ここを修正したら、NFM007.triggerも要確認
      prd2LatestValMap = new Map<Id, Product2>();
      integer cntPrd2 = 0;
      for (Product2 prd2 : [Select Id, Estimation_Entry_Possibility__c, SFDA_Status__c, Packing_list_manual__c,
      //fy 预留产品标识
      LastbuyProductFLG__c
                            From Product2 Where Id IN :product2Ids]) {
        cntPrd2 = cntPrd2   +   1;
        if (prd2.Estimation_Entry_Possibility__c != '○') {
          error = true;
        }
        if (prd2.Estimation_Entry_Possibility__c == 'M') {
 
          error = false;
        }
        if (prd2.SFDA_Status__c != loopMap.get(prd2.Id)) {
          //
          WinOrDecideAlert    =   true;
        }
 
        prd2LatestValMap.put(prd2.Id, prd2);
      }
      if (cntPrd2  !=  Gcnt) {
        WinOrDecideAlert    =   false;
      }
 
    }
 
    if (error == true && WinOrDecideAlert == false) {
      PageArrange();
      errorflg = true;
      errorMessage = System.Label.Error_Message37;
      return false;
    }
 
    if (checkAgentsDeleteFlag() == false) {
      return false;
    }
 
 
    PageArrange();
    errorflg = false;
    errorMessage = null;
    return true;
  }
 
  private boolean checkIsQuoteTrial() {
    Boolean error = false;
    errorflg = false;
    errormessage = null;
    //询价上的【是否需要价格申请】为是的场合,才要检查做没做过报价试算 thh 2021-11-03 start
    if(opp.If_Need_PriceApply__c){
      //wql 报价试算 判断是否进行过报价试算 start
      if(!quo.IsQuoteTrial__c){
        //没有报价试算过进入
        error = true;
        errormessage =  'decide报价还没进行报价试算,请先报价试算!' ;   
      }
      //wql 报价试算 判断是否进行过报价试算 end
      //wql 报价试算 检索促销政策是否有效 start
      //1.获取报价id
      //2.根据报价id 检索出所有报价试算行,并带出每一行,选择的政策的有效期  3个表
      //3.循环遍历 是否所有选择的政策有效期都为true 只有有一个为false 就返回true 直接跳出循环
      //如果报价id不为空的话
      if(quoId !=null){
        boolean IsActivePsp = true;
        String errorPsp ='';
        //根据id 检索 所有的试算行上面选择政策的有效期
        List<PromotionSalesProducts__c> promotionSalesProductsList =[select id,PromotionSales__c,QuantityId__c,PromotionSales__r.name,PromotionSales__r.IsPolicyEffective__c,recordTypeName__c from PromotionSalesProducts__c where QuantityId__c=:  quoId];
        //如果有报价试算数据 说明选择了促销政策
        if(promotionSalesProductsList.size()>0){
          for(PromotionSalesProducts__c psp :promotionSalesProductsList){
            if(psp.PromotionSales__r.IsPolicyEffective__c == '无效'&&psp.recordTypeName__c!='NormalProduct'){
                IsActivePsp =false;
                errorPsp = psp.PromotionSales__r.name;
                break;
            }
          }
        }
 
        if(!IsActivePsp){
          error = true;
          errormessage =  '报价试算中,选择的促销政策:'+errorPsp+',不在有效期内,请检查!' ;
        }
      }
      //wql 报价试算 检索促销政策是否有效 end
    }
    //询价上的【是否需要价格申请】为是的场合,才要检查做没做过报价试算 thh 2021-11-03 end
    return error;
  }
 
  private boolean dataCheckDecide() {
    Boolean error = false;
    errorflg = false;
    errormessage = null;
 
    if (checkAgentsDeleteFlag() == false) {
      return false;
    }
    if (WinOrDecideAlert && (!productStatusUpdated)) {
      //    error = true;
      //    // CHAN-AVG3PW 询价报价画面规则变更
      //    //errorMessage = '产品状态发生变化,请更新';
      PriceStatusUpdate();
      //    errorMessage = '产品状态发生变化,已经更新,请确认后再次点击决定。';
    }
    if (opp.Agency1__c == null) {
      opp.Agency1__c.addError(System.Label.Error_Message3);
      error = true;
      errormessage = System.Label.Error_Message3;
    }
    if (quo.OCM_Agent1_Price_Page__c == null || quo.OCM_Agent1_Price_Page__c == 0) {
      quo.OCM_Agent1_Price__c.addError(System.Label.Error_Message3);
      error = true;
      errormessage = System.Label.Error_Message3;
    }
    if (opp.Agency2__c == null && quo.Agent1_Agent2_Price_Page__c != null) {
      opp.Agency2__c.addError(System.Label.Error_Message3);
      error = true;
      errormessage = System.Label.Error_Message3;
    }
    if (opp.Agency2__c != null && quo.Agent1_Agent2_Price_Page__c == null) {
      quo.Agent1_Agent2_Price__c.addError(System.Label.Error_Message3);
      error = true;
      errormessage = System.Label.Error_Message3;
    }
 
    // LHJ 授权check Start
    if (opp.If_Need_Authorize__c == true) {
      ID tmpid = opp.Agency2__c == null ? opp.Agency1__c : opp.Agency2__c;
      System.debug('tmpid==='+tmpid);
      List<Account> accName = [select name from Account where id = : tmpid];
      System.debug('accName==='+accName);
      System.debug('Authorized_Finish_Sales__c==='+opp.Authorized_Finish_Sales__c);
      if (accName[0].name != opp.Authorized_Finish_Sales__c) {
        error = true;
        errormessage =  '经销商未授权或授权未完成,请先授权。' ;
      }
    }
 
    if (opp.Trade__c == '内貿') {
      // //经销商产品注册证匹配
      Map<Id, String> proMap = new Map<Id, String>();
      if (activities.size() > 0) {
        for (QELine qli : activities) {
          if (qli.Asset_Model != null && qli.Asset_Model != '') {
            proMap.put(qli.pageObject.Id__c, qli.PageObject.Name__c);
          }
        }
      }
      //阿西赛多 取消查询医疗器械经营许可证 精琢技术 wql  2021/01/14 start 
      Map<String, String> chkMap = new Map<String, String>();
      if(!opp.Is_Corrosion__c){
        // GZW 画面出错误消息
        chkMap = OpportunityWebService.MapCheckProRegisterDecide(proMap, opp.Agency1__c, '');
      }
      //阿西赛多 取消查询医疗器械经营许可证 精琢技术 wql  2021/01/14 end
      //this.haveno_Register 没有注册证 状态红色
      //this.wrong_Register  匹配不上  名字红色
      if (chkMap.size() > 0) {
        errorflg = true;
        error = true;
        //errormessage = '请检查红字内容(NMPA状态红字,不可销售产品;产品名称红字,超过经销商经营范围)。';
        if (chkMap.containsKey('agency')) {
          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '第一经销商没有有效的医疗器械经营许可证。'));
        }
        Integer inerr = 0;
        if (activities.size() > 0) {
          for (QELine s : activities) {
            if (s.Asset_Model != null && s.Asset_Model != '') {
              if (chkMap.containsKey(s.PageObject.Id__c)) {
                if (chkMap.get(s.PageObject.Id__c) == '1') {
                  s.haveno_Register = true;
                  inerr ++;
                } else if (chkMap.get(s.PageObject.Id__c) == '2') {
                  s.wrong_Register = true;
                  inerr ++;
                }
              }
            }
          }
        }
        if (inerr > 0) {
          errormessage = '请检查红字内容(NMPA状态红字,不可销售产品;产品名称红字,超过经销商经营范围)。';
        }
        return false;
      }
      //阿西赛多 是否危险化学品经营许可证 保存提示可以保存 decide提示不可decide 精琢技术 wql 2020/12/30 start
 
      //询价是阿西赛多 判断标识
      Boolean isDangerError = false;
      //询价不是阿西赛多 判断标识
      Boolean isNotDangerError = false;
      
      //条件是 内贸 && 经销商  && 是否是阿西赛多 为true
      //没有合并在上面的for循环的原因是,怕有冲突将标识置为false
      if (activities.size() > 0) {
        for (QELine qli : activities) {
          if (qli.Asset_Model != null && qli.Asset_Model != '') {
              //阿西赛多 页面提示报错信息 2020/12/30 start
              //如果询价是阿西赛多 则选择一般产品的标红
              system.debug('是否阿西赛多询价');
              system.debug(opp.Is_Corrosion__c);
              if (opp.Is_Corrosion__c) {
                  //不是危化品
                  if(!qli.Is_DangerousChemicals){
                    //提示报错
                    isNotDangerError =true;
                    //名称报红
                    qli.wrong_Register = true;
 
                  }
 
              }else{
                //如果询价不是阿西赛多,则选择危化品的标红
                if(qli.Is_DangerousChemicals){
                    //提示报错
                    isDangerError =true;
                    //名称报红
                    qli.wrong_Register = true;
                }
              }
              //阿西赛多 页面提示报错信息 wql 2020/12/30 end
            
          }
          
          
        }
      }
      //阿西赛多 是否危险化学品经营许可证 保存提示可以保存 decide提示不可decide 精琢技术 wql 2020/09/10 start
      
      if (enableSales == true&&opp.Is_Corrosion__c&&opp.Trade__c == '内貿') {
        //条件是 内贸  && 经销商  && 是否是阿西赛多 为true
        String str = OpportunityWebService.checkDangerItem(opp.agency1__c);
        if (str != 'OK') {
          error = true;
          errormessage = str;
        }
 
        //代表行项目有不是危化品的
        if(isNotDangerError){
          error = true;
          errormessage = '当阿西塞多时,行项目的产品必须全选择危化品。';
        }
      }else if(!opp.Is_Corrosion__c){
        //代表行项目有危化品
        if(isDangerError){
          error = true;
          errormessage = '当询价不是阿西塞多时,行项目的产品不能选择危化品。';
        }
      }
      //阿西赛多 是否危险化学品经营许可证 保存提示可以保存 decide提示不可decide 精琢技术 wql 2020/09/10 end
 
 
    }
    // LHJ End
 
    if (error == true) {
      PageArrange();
      errorflg = true;
      return false;
    } else {
      return true;
    }
  }
 
  private Boolean checkAgentsDeleteFlag() {
    // Check Agents
    List<Id> accIds = new List<Id>();
    if (opp.Agency1__c != null) {
      accIds.add(opp.Agency1__c);
    }
    if (opp.Agency2__c != null) {
      accIds.add(opp.Agency2__c);
    }
    if (accIds.size() > 0) {
      List<Account> agentAccs = [SELECT Id, Delete_Flag__c, Is_Active_Formula__c, Sales_Shop_Class__c FROM Account WHERE Id IN :accIds];
      //Boolean deleteFlag1 = false, deleteFlag2 = false;
      String activeFormula1 = null, activeFormula2 = null;
      for (Account local : agentAccs) {
        if (local.Sales_Shop_Class__c == '医疗修理经销商') {
          PageArrange();
          errorflg = true;
          //-------CHAN-B9TBG4; 20190301----------UpdateStart----------------------------------------
          if (local.Id == opp.Agency1__c) {
            errorMessage = '请确认第一经销商的经销商资质';
            return false;
          }
          //else {
          //    errorMessage = '请确认第二经销商的经销商资质';
          //}
          //return false;
          //-------CHAN-B9TBG4; 20190301----------UpdateStop----------------------------------------
        }
 
        if (local.Id == opp.Agency1__c) {
          activeFormula1 = local.Is_Active_Formula__c;
        }
      }
      for (Account local : agentAccs) {
        if (local.Id == opp.Agency2__c) {
          activeFormula2 = local.Is_Active_Formula__c;
        }
      }
 
      if (activeFormula1 == '无效' && activeFormula2 == '无效') {
        PageArrange();
        errorflg = true;
        errorMessage = System.Label.Agent1_and_Agent2_were_Deleted;
        return false;
      } else if (activeFormula1 == '无效') {
        PageArrange();
        errorflg = true;
        errorMessage = System.Label.Agent1_was_Deleted;
        return false;
      } else if (activeFormula2 == '无效') {
        PageArrange();
        errorflg = true;
        errorMessage = System.Label.Agent2_was_Deleted;
        return false;
      }
    }
 
    // 内貿の場合Check Agency1
    if (opp.Agency1__c != null && opp.Trade__c == '内貿') {
      Account acc = [select Sales_Shop_Class__c, Business_Authorization_No__c, Business_Paper_Expiration_Date__c,
                     Tax_Practice_No__c, Tax_Practice_Expiration_Date__c, Medical_Equipment_Num__c, Is_Active_Formula__c,
                     Medical_Equipment_Expiration_Date__c from Account where Id = :opp.Agency1__c];
      //经销商分类只有特约、一级或者集中采购才可以进行报价
      List<String> salesClazz = new List<String> {'特約販売店(区域)', '特約販売店(製品)', '特約販売店(製品+区域)', '一級販売店', '集采经销商'};
      // 有效/无效(公式)!= 有效
      if (acc.Is_Active_Formula__c != '有效') {
        PageArrange();
        errorflg = true;
        errorMessage = '请选择有效的经销商';
        return false;
      }
      // 经销商分类 是 二级 或 其他
      //else if (acc.Sales_Shop_Class__c == '二級販売店' || acc.Sales_Shop_Class__c == 'その他') {
      //CHAN-BQE6LA  【委托】【重要】询价经销商1判断逻辑 精琢技术 wql 2020/06/10 start
      //注释原来逻辑
      // else if (acc.Sales_Shop_Class__c == '二級販売店') {
      //   PageArrange();
      //   errorflg = true;
      //   errorMessage = '请确认第一经销商的经销商资质';
      //   return false;
      // }
      else if(!salesClazz.contains(acc.Sales_Shop_Class__c)){
        PageArrange();
        errorflg = true;
        errorMessage = '经销商1的经销商分类为:特约,一级,集中采购才可以报价';
        return false;
      }
      //CHAN-BQE6LA  【委托】【重要】询价经销商1判断逻辑 精琢技术 wql 2020/06/10 end
      // 营业执照有效期限” 或“税务登记证有效期限” 或“医疗器械经营企业许可证有效期限” 其中一个证超过有效期的话
      //去掉营业许可证的检查 因为阿西赛多不用检查 一般产品上面检查过  精琢技术 wql 2021/01/15 start
      //&& String.isBlank(acc.Medical_Equipment_Num__c) == false
      //       && acc.Medical_Equipment_Expiration_Date__c != null && acc.Medical_Equipment_Expiration_Date__c >= Date.today()
      else if (!
               // 满足如下六个字段条件为有效,否则无效
               (String.isBlank(acc.Tax_Practice_No__c) == false
                && (acc.Tax_Practice_Expiration_Date__c == null || acc.Tax_Practice_Expiration_Date__c >= Date.today())
                
                && String.isBlank(acc.Business_Authorization_No__c) == false
                && acc.Business_Paper_Expiration_Date__c != null && acc.Business_Paper_Expiration_Date__c >= Date.today())
              ) {
        PageArrange();
        errorflg = true;
        errorMessage = '请确认第一经销商的经销商资质';
        return false;
      } 
      //去掉营业许可证的检查 因为阿西赛多不用检查 一般产品上面检查过  精琢技术 wql 2021/01/15 end
      else {}
      /*
      if (acc.Sales_Shop_Class__c == '二級販売店' || acc.Sales_Shop_Class__c == 'その他') {
          if (!
              (!String.isBlank(acc.Tax_Practice_No__c)
                  && (acc.Tax_Practice_Expiration_Date__c == null || acc.Tax_Practice_Expiration_Date__c >= Date.today())
                  && !String.isBlank(acc.Medical_Equipment_Num__c)
                  && (acc.Medical_Equipment_Expiration_Date__c != null && acc.Medical_Equipment_Expiration_Date__c >= Date.today())
                  && !String.isBlank(acc.Business_Authorization_No__c)
                  && (acc.Business_Paper_Expiration_Date__c != null && acc.Business_Paper_Expiration_Date__c >= Date.today()))) {
              PageArrange();
              errorflg = true;
              errorMessage = '请确认第一经销商的经销商资质';
              return false;
          }
      }
      */
    }
 
    return true;
  }
 
  // CHAN-AVG3PW 询价报价画面规则变更
  // 报价创建日超过三个月时,如产品停产或CFDA失效,不可以保存,提示“请更新停止销售的产品”
  //             做DECIDE时,如产品停产或CFDA失效,不可以保存,提示“请更新停止销售的产品”
  private boolean checkSFDAStatus2(boolean dodecide) {
    // CHAN-AZG864 不管在不在报价有效期内,CFDA不可销售的时候,都是报错的,其中不可销售产品显示红字,不应该保存。
    //if (over3month == false && dodecide == false) {
    //    return true;
    //}
 
    for (QELine a : activities) {
      if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
        system.debug('zzzzzzzz1:'+a.PageObject.SFDA_Status__c);
        if (a.PageObject.SFDA_Status__c != '有効' &&
            a.PageObject.SFDA_Status__c != '有効(再申請中)' &&
            a.PageObject.SFDA_Status__c != '不要' &&
            // LHJ 20181221 CBPR Start
            a.PageObject.SFDA_Status__c != '暂停出库(短期)' &&
            // LHJ 20181221 CBPR End
            a.PageObject.SFDA_Status__c != '失効(期限内生産済在庫対応)'
            /*&&
            (a.PageObject.SFDA_Status__c != '失効(再申請中)' || dodecide != false)*/
           ) {
          return false;
        }
      }
    }
    return true;
  }
 
  private boolean checkSFDAStatus1(boolean dodecide) {
    // CHAN-AZG864 不管在不在报价有效期内,CFDA不可销售的时候,都是报错的,其中不可销售产品显示红字,不应该保存。
    //if (over3month == false && dodecide == false) {
    //    return true;
    //}
    for (QELine a : activities) {
      if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
        if (a.PageObject.SFDA_Status__c != '有効' &&
            a.PageObject.SFDA_Status__c != '有効(再申請中)' &&
            a.PageObject.SFDA_Status__c != '不要' &&
            a.PageObject.SFDA_Status__c != '失効(期限内生産済在庫対応)' &&
            // LHJ CBPR 20181221 Start
            (a.PageObject.SFDA_Status__c != '暂停出库(长期)') &&
            (a.PageObject.SFDA_Status__c != '暂停出库(短期)') &&
            // LHJ CBPR 20181221 End
            (a.PageObject.SFDA_Status__c != '失効(再申請中)' || dodecide != false)
           ) {
          return false;
        }
      }
    }
    return true;
  }
 
  //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy start
  private boolean checkIsDecide() {
    List<Opportunity> oppsde = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
    if (oppsde.size() > 0) {
      if(oppsde[0].Estimation_Decision__c){
        return true;
      }
    }
    return false;
  }
  //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy end
 
  public boolean dataEntry() {
    system.debug('activities++++----****3'+activities);
    //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy start
    // Boolean ifdecide=false;
    // List<Opportunity> oppsde = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
    // if (oppsde.size() > 0) {
    //   if(oppsde[0].Estimation_Decision__c){
    //     ifdecide=true;
    //   }else{
    //     ifdecide=false;
    //   }
    // }
    System.debug('start checkIsDecide at: ' + System.currentTimeMillis());
    Boolean ifdecide=checkIsDecide();
    System.debug('finished checkIsDecide at: ' + System.currentTimeMillis());
    if(!ifdecide){
      //SWAG-C9JCS8 【委托】【紧急】询价GZ-SP-GD0757135报价单问题 fy end
      system.debug('○○○○○○○○○○○○Welcome to dataEntry class!!○○○○○○○○○○○○');
      Boolean error = false;
      Boolean detail = false;
      if ((quo.QuoteName__c == null) || (quo.QuoteName__c == '')) {
        quo.QuoteName__c.addError(System.Label.Error_Message3);
        error = true;
        errormessage = System.Label.Error_Message3;
      }
      if (quo.Dealer_Final_Price_Page__c == null) {
        quo.Dealer_Final_Price__c.addError(System.Label.Error_Message3);
        error = true;
        errormessage = System.Label.Error_Message3;
      }
      if (qb.Quote_Adjust_Calculate == null) {
        quo.Quote_Adjust_Calculate__c.addError(System.Label.Error_Message3);
        error = true;
        errormessage = System.Label.Error_Message3;
      }
      if (quo.Quote_Adjust_Amount_Page__c == null) {
        quo.Quote_Adjust_Amount__c.addError(System.Label.Error_Message3);
        error = true;
        errormessage = System.Label.Error_Message3;
      }
      if (quo.Quote_Expiration_Date__c == null) {
        quo.Quote_Expiration_Date__c.addError(System.Label.Error_Message3);
        error = true;
        errormessage = System.Label.Error_Message3;
      }
      //decimal temSalesAmount1 = 0; // 2018/09/28 CHAN-B4YAB8 经销商小计合计 end
      system.debug('activities++++----****2'+activities);
      for (QELine a : activities) {
        if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
          if (a.PageObject.Quantity__c == null || a.PageObject.Quantity__c == 0) {
            a.PageObject.Quantity__c.addError(System.Label.Error_Message3);
            error = true;
            errormessage = System.Label.Error_Message3;
          }
          if (a.PageObject.UnitPrice_Page__c == null) {
            a.PageObject.UnitPrice__c.addError(System.Label.Error_Message3);
            error = true;
            errormessage = System.Label.Error_Message3;
          }
          if (a.PageObject.AgencyUnitPrice__c == null) {
            a.PageObject.AgencyUnitPrice__c.addError(System.Label.Error_Message3);
            error = true;
            errormessage = System.Label.Error_Message3;
          }
          //temSalesAmount1 = temSalesAmount1 + a.PageObject.AgencySubtotal__c; // 2018/09/29 CHAN-B4YAB8 经销商小计累加
          if (a.PageObject.PricebookEntryId == null) {
            error = true;
            errormessage = System.Label.Error_Message27;
          }
          detail = true;
        }
      }
      if (enableSales == true) {
        // LHJ Start
        if (quo.Agency1__c == null) {
          quo.Agency1__c.addError(System.Label.Error_Message3);
          error = true;
          errormessage = System.Label.Error_Message3;
        }
        // LHJ End
        if (quo.OCM_Agent1_Price_Page__c == null) {
          quo.OCM_Agent1_Price__c.addError(System.Label.Error_Message3);
          error = true;
          errormessage = System.Label.Error_Message3;
        } else {
 
        }
      } else {
 
        if (opp.Agency1__c != null) {
          opp.Agency1__c.addError(System.Label.Error_Message30);
          error = true;
          errormessage = System.Label.Error_Message30;
        }
        if (quo.OCM_Agent1_Price_Page__c != null) {
          quo.OCM_Agent1_Price__c.addError(System.Label.Error_Message30);
          error = true;
          errormessage = System.Label.Error_Message30;
        }
        if (opp.Agency2__c != null) {
          opp.Agency2__c.addError(System.Label.Error_Message30);
          error = true;
          errormessage = System.Label.Error_Message30;
        }
        if (quo.Agent1_Agent2_Price_Page__c != null) {
          quo.Agent1_Agent2_Price__c.addError(System.Label.Error_Message30);
          error = true;
          errormessage = System.Label.Error_Message30;
        }
 
      }
 
      if (DisCalculation >= 1000 || DisCalculation <= -1000) {
        error = true;
        errormessage = System.Label.Error_Message38;
      }
      if (qb.SalesCalculation1 >= 1000 || qb.SalesCalculation1 <= -1000) {
        error = true;
        errormessage = System.Label.Error_Message38;
      }
      if (qb.SalesCalculation2 >= 1000 || qb.SalesCalculation2 <= -1000) {
        error = true;
        errormessage = System.Label.Error_Message38;
      }
 
      if (error == true) {
        PageArrange();
 
        errorflg = true;
        return false;
      }
 
      //Quote-------------------------------------------------------------
      //商談Id、価格表Id
      //見積名称、標準定価合計、見積金額合計(積上)、病院の契約金額、原価、
      //値引金額計算、値引き金額金額、見積調整金額計算、見積調整金額金額
      //第一販売店名称、金額、利益、%、第二販売店名称、金額、利益、%
      //优惠成交价、优惠折扣、优惠价格、单价、报价金额、Total
      //契約内訳、印刷病院名称、見積有効期限日、見積表記コメント
 
      //引合単位の見積Noが必要
      List<Quote> maxQuote_No = [select Quote_No__c From Quote Where OpportunityId = :oppid and (not Quote_No__c like '%Old') order by Quote_No_last2__c desc NULLS LAST limit 1];
      String oppNo;
      Integer l = 1;
      if (maxQuote_No.size() > 0) {
        try {
          oppNo = maxQuote_No[0].Quote_No__c;
          l = Integer.valueOf(oppNo.substring(oppNo.length() - 2)) + 1;
        } catch (System.TypeException e) {
          system.debug('maxQuote_No Error: quote.id=' + maxQuote_No[0].id);
        }
      } else {
        system.debug('first Quote');
      }
      oppNo = '00' + String.valueof(l);
      oppNo = oppNo.substring(oppNo.length() - 2);
 
      Quote q = New Quote();
      if (changedAfterPrint) {
        system.debug('id空1:');
        quoId = null;
      }
      // false伝票から新規作成
      if (changedAfterBid) {
        system.debug('id空2:');
        quoId = null;
      }
      // CHAN-AVG3PW 询价报价画面规则变更
      if (newQuoteFlag) {
        system.debug('id空3:');
        quoId = null;
      }
      // 多年保修 start
      //报价试算 增加经销商前后对比 精琢技术 wql 20210508 start
      if ((quoteGurantee_Period != null &&
          !quoteGurantee_Period.equals(quo.Gurantee_Period__c))
          ||
          (quotemultiYearWarranty != null &&
          !quotemultiYearWarranty.equals('' + quo.multiYearWarranty__c))
          ||
          (agency1Name !=null &&!agency1Name.equals(quo.Agency1__c))
          ||
          (agency2Name !=null &&!agency2Name.equals(quo.Agency2__c))
        ) {
        quoId = null;
      }
      agency1Name = quo.Agency1__c;
      agency2Name = quo.Agency2__c;
      //报价试算 增加经销商前后对比 精琢技术 wql 20210508 end
      quoteGurantee_Period = quo.Gurantee_Period__c;
      quotemultiYearWarranty = '' + quo.multiYearWarranty__c;
      // 多年保修 end
      if (quoId == null) {
        q = New Quote();
        q.OpportunityId = oppId;
 
        if (detail == true) {
          if (standardPricebook == null) {
            errormessage = System.Label.Error_Message27;
            errorflg = true;
            return false;
          } else {
            q.Pricebook2Id = standardPricebook.Id;
          }
        }
 
      } else {
        List<Quote> qs = New List<Quote>();
        qs = [select Id, OpportunityId, CreatedDate, Pricebook2Id, Name, Estimation_List_Price__c, Dealer_Final_Price__c,
              Stocking_Price__c, Discount_Amount__c, Discount_Amount_Calculate__c, Quote_Adjust_Amount__c, Quote_Adjust_Calculate__c,
              Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Quote_No__c,
              Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c,
              Preferential_Trading_Price__c, Discount__c, Pricing__c, Unit_Price__c, Offer_Amount__c, TOTAL__c,
              Contract__c, Print_HP_Name__c, Quote_Expiration_Date__c, Quote_Comment__c, OCM_Sales_Forecast__c, Installation_location__c, HasType3Machine__c
              // 多年保修 start
              , Gurantee_Period__c , multiYearWarranty__c, MultiYearWarrantyTotalPrice__c
              , Preferential_Gurantee_Period__c
              // 多年保修 end
              //报价试算 start
              ,IsQuoteTrial__c 
              //报价试算 end
              From Quote Where Id = :quoId];
        if (qs.size() > 0) {
          q = qs[0];
        }
        if (q.Pricebook2Id == null) {
          if (detail == true) {
            if (standardPricebook == null) {
              errormessage = System.Label.Error_Message27;
              errorflg = true;
              return false;
            } else {
              q.Pricebook2Id = standardPricebook.Id;
            }
          }
        }
      }
 
      if (quoId == null) {
        q.Quote_No__c = opp.Opportunity_No__c + '-' + oppNo;
        q.PriceRefreshDate__c = Date.today();
      }
      if (productStatusUpdated) {
        q.PriceRefreshDate__c = Date.today();
      }
 
      // 20150302 jo 見積の主机安装地点を設定
      List<String> pIds = new List<String>();
      system.debug('activities++++----****1'+activities);
      for (QELine s : activities) {
        if (String.isBlank(s.PageObject.Id__c) == false) {
          pIds.add(s.PageObject.Id__c);
        }
      }
      List<Product2> pList = [select Id from Product2 where Id in :pids and Category3__c = '主机'];
      if (pList.size() > 0) q.HasType3Machine__c = true;
 
      q.Name = quo.QuoteName__c;
      // TODO katsu 新規じゃない場合セットする必要ですか?
      q.Estimation_List_Price__c = qb.Estimation_List_Price;
      //q.TotalPrice = quo.TotalPrice; ===============-Field is not writeable: Quote.TotalPrice
      q.Dealer_Final_Price__c =  quo.Dealer_Final_Price_Page__c;
      q.OCM_Sales_Forecast__c = opp.Wholesale_Price__c;
      q.Stocking_Price__c = quoStocking_Price_c;
      quo.Stocking_Price__c = quoStocking_Price_c;
 
      q.Quote_Adjust_Amount__c = quo.Quote_Adjust_Amount_Page__c;
      q.Quote_Adjust_Calculate__c = qb.Quote_Adjust_Calculate;
      q.Discount_Amount__c = DisAmount;
      q.Discount_Amount_Calculate__c = DisCalculation;
      q.Agency1__c = opp.Agency1__c;
      q.OCM_Agent1_Price__c = quo.OCM_Agent1_Price_Page__c;
      q.Agency1_Profit__c = Salesprofit1;
      q.AgencyDiscount__c  = AgencyDiscount; // 2018/09/28 CHAN-B4YAB8 经销商折扣
 
      //多年保修 start
      q.Gurantee_Period__c = quo.Gurantee_Period__c;
      q.multiYearWarranty__c = quo.multiYearWarranty__c;
      q.MultiYearWarrantyTotalPrice__c = quo.MultiYearWarrantyTotalPrice__c;
      q.quoteSavedDate__c = Date.today();
      //多年保修 end
 
      q.Agency1_Profit_Rate__c = qb.SalesCalculation1;
      q.Agency2__c = opp.Agency2__c;
      q.Agent1_Agent2_Price__c = quo.Agent1_Agent2_Price_Page__c;
      q.Agency2_Profit__c = Salesprofit2;
      q.Agency2_Profit_Rate__c = qb.SalesCalculation2;
 
      //----checkbox は印刷直前に保存
      q.Print_HP_Name__c = selection_hp;
      q.Quote_Expiration_Date__c = quo.Quote_Expiration_Date__c;
      q.Quote_Comment__c = quo.Quote_Comment__c;
 
      q.Installation_location__c = quo.Installation_location__c;
      /*
      if (hasType3Machine) {
          q.Installation_location__c = '';
      }
      */
      System.debug('start save quote at: ' + System.currentTimeMillis());
      if (quoId == null) {
        insert q;
        quo.Quote_No__c = q.Quote_No__c;
      } else {
        update q;
      }
      System.debug('finished save quote at: ' + System.currentTimeMillis());
 
      system.debug('○○○○○Save1○○○○○');
 
      //QuoteLineItem;
      List<QuoteLineItem> qlist = New List<QuoteLineItem>();
      qlist = [Select Id From QuoteLineItem Where QuoteId = :quoId];
      if (qlist.size() > 0) {
        //delete
        delete qlist;
      }
 
      //QuoteLineItem--------------------------------------------
      //製品型番、品目コード、SFDAステータス、品目名、ListPrice、数量
      //価格、単位、小計、OCM売上予測金額(税抜)、価格表
      qlist = New List<QuoteLineItem>();
      //Sap送信,Printに合わせて1~
      Integer i = 1;
      if (activities.size() > 0) {
        system.debug('activities++++----****'+activities);
        for (QELine s : activities) {
          if (s.Asset_Model != null && s.Asset_Model != '') {
            if (s.pageObject.PricebookEntryId != null) {
              // TODO katsu なぜclone()しますか?意味不明。
              QuoteLineItem ql = s.pageObject.clone();
              ql.Quantity = ql.Quantity__c;
              ql.UnitPrice = 0;                        // UnitPriceを使わないけど、必須なので、0を入れる
              ql.QuoteId = q.Id;
              ql.Name__c = s.PageObject.Name__c;
              ql.Cost__c = s.Cost_c;
              ql.Cost_Subtotal__c = s.Cost_Subtotal_c;
              s.pageObject.Cost__c = s.Cost_c;
              s.pageObject.Cost_Subtotal__c = s.Cost_Subtotal_c;
              ql.UnitPrice__c = ql.UnitPrice_Page__c;
              ql.UnitPrice_Page__c = 0;
              ql.ListPrice__c = s.ListPrice_Page;
              // 多年保修  start
              // 计提金额
              ql.GuranteePrice__c        = s.GuranteePrice;
              ql.ProductGuranteePrice__c = s.ProductGuranteePrice;
              // 维修合同报价
              ql.Maintenance_Price_Year__c = s.Maintenance_Price_Year;
              // 多年保修  end
              //CHAN-BWH2WP 精琢技术 wql 2020/12/22 start 
              //如果产品为不可取消多年保 则打上标识
              system.debug(s.CanNotCancelledGurantee);
              ql.CanNotCancelFlag__c = s.CanNotCancelledGurantee;
              
              //CHAN-BWH2WP 精琢技术 wql 2020/12/22 end
              // CHAN-AVG3PW 询价报价画面规则变更
              //ql.SFDA_Status__c = prd2LatestValMap.get(s.pageObject.Id__c).SFDA_Status__c;
              //並び順
              ql.Item_Order__c = i;
              //OCM売上予測金額(税込) = OCM成約予測金額(税込み) * (小計 / 見積合計)
              if (s.PageObject.Subtotal__c != null && opp.Wholesale_Price__c != null && quo.QuoteTotal_Page__c != null) {
                if (s.PageObject.Subtotal__c > 0 && quo.QuoteTotal_Page__c > 0) {
                  ql.OCM_Sales_Forecast__c =  opp.Wholesale_Price__c * (s.PageObject.Subtotal__c / quo.QuoteTotal_Page__c);
                }
              }
              qlist.add(ql);
              i++;
            }
          }
        }
        System.debug('start save quote lines at: ' + System.currentTimeMillis());
        system.debug('qlist+++---+++'+qlist);
        insert qlist;
        System.debug('finished save quote lines at: ' + System.currentTimeMillis());
 
      }
      system.debug('○○○○○Save2○○○○○');
 
      //Opportunity--------------------------------------------
      //標準定価合計価格、見積金額総合計(税抜き)、病院契約金額、
      //1次販売店、1次販売店利益金額、1次販売店利益率、
      //2次販売店、2次販売店利益金額、2次販売店利益率
      //見積番号、見積名
      Opportunity o = New Opportunity();
      List<Opportunity> os = New List<Opportunity>();
      
      os = [select Id, Estimation_List_Price__c, Dealer_Final_Price__c, Estimation_List_Price_Without_Tax__c,
            Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Stocking_Price__c,
            Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c, Quote_Update_Sum__c , Hospital__c,Is_Corrosion__c 
            From Opportunity Where Id = :oppid];
      if (os.size() > 0) {
        o = os[0];
        o.Estimation_List_Price__c = qb.Estimation_List_Price;
        o.Wholesale_Price__c = opp.Wholesale_Price__c;
        o.Dealer_Final_Price__c = quo.Dealer_Final_Price_Page__c;
        o.Agency1__c = opp.Agency1__c;
        o.OCM_Agent1_Price__c = quo.OCM_Agent1_Price_Page__c;
        o.Agency1_Profit__c = Salesprofit1;
        o.Agency1_Profit_Rate__c = qb.SalesCalculation1;
        //            o.Agency1_Profit_Rate__c = quo.Agency1_Profit_Rate__c;
        o.Agency2__c = opp.Agency2__c;
        o.Agent1_Agent2_Price__c = quo.Agent1_Agent2_Price_Page__c;
        o.Agency2_Profit__c = Salesprofit2;
        o.Agency2_Profit_Rate__c = qb.SalesCalculation2;
        //            o.Agency2_Profit_Rate__c = quo.Agency2_Profit_Rate__c;
 
        o.Stocking_Price__c = quo.Stocking_Price__c;
 
        o.Estimation_No__c = quo.Quote_No__c;
        //o.Estimation_Name__c = quo.Name;
        o.Estimation_Name__c = q.Name;
        o.Estimation_Id__c = q.Id;
        o.Installation_location__c = q.Installation_location__c;
        o.HasType3Machine__c = q.HasType3Machine__c;
        // 2018/09/29 CHAN-B4YAB8 经销商折扣 start
        o.AgencyDiscount__c  = AgencyDiscount;
        // 2018/09/29 CHAN-B4YAB8 经销商折扣 end
        // 多年保修 start
        o.Gurantee_Period__c              = quo.Gurantee_Period__c ;
        o.multiYearWarranty__c            = quo.multiYearWarranty__c ;
        o.MultiYearWarrantyTotalPrice__c  = quo.MultiYearWarrantyTotalPrice__c ;
        o.quoteSavedDate__c = Date.today();
        // 多年保修 end
 
 
        if (o.Quote_Update_Sum__c == null) {
          o.Quote_Update_Sum__c = 1;
        } else {
          o.Quote_Update_Sum__c = o.Quote_Update_Sum__c + 1;
        }
        System.debug('start 1st save Opportunity at: ' + System.currentTimeMillis());
        ControllerUtil.updOpp(o);
        System.debug('finished 1st save Opportunity at: ' + System.currentTimeMillis());
 
        system.debug('○○○○○Save3○○○○○');
 
        //OpportunityLineItem--------------------------------------------
        //製品型番、品目コード、SFDAステータス、品目名、ListPrice、数量
        //価格、単位、小計、OCM売上予測金額(税抜)、価格表
        List<OpportunityLineItem> ols = New List<OpportunityLineItem>();
        OpportunityLineItem ol = New OpportunityLineItem();
        ols = [select Id from OpportunityLineItem Where OpportunityId = :oppid];
        if (ols.size() > 0) {
          //delete
          ControllerUtil.delOppLine(ols);
          system.debug('○○○○○Save4○○○○○');
        }
        //Sap送信,Printに合わせて1~
        i = 1;
        ols = New List<OpportunityLineItem>();
        if (activities.size() > 0) {
          for (QELine s : activities) {
            if (s.Asset_Model != null && s.Asset_Model != '') {
              if (s.PageObject.PricebookEntryId != null) {
                ol = New OpportunityLineItem();
                ol.OpportunityId = oppid;
                ol.Id__c = s.PageObject.Id__c;
                // CHAN-AVG3PW 询价报价画面规则变更
                ol.SFDA_Status__c = s.PageObject.SFDA_Status__c;
                //ol.SFDA_Status__c = prd2LatestValMap.get(s.pageObject.Id__c).SFDA_Status__c;
                ol.Name__c = s.PageObject.Name__c;
                ol.ListPrice__c = s.ListPrice_Page;
                ol.Quantity = s.PageObject.Quantity__c;
                ol.UnitPrice = 0;
                ol.UnitPrice__c = s.PageObject.UnitPrice_Page__c;
                // 2018-10-31 CHAN-B4YAB8 赠送、经销商单价和小计 start
                ol.AgencyUnitPrice__c =  s.PageObject.AgencyUnitPrice__c;
                ol.Present__c =  s.PageObject.Present__c;
                ol.AgencySubtotal__c =  s.PageObject.AgencySubtotal__c;
                // 2018-10-31 CHAN-B4YAB8 赠送、经销商单价和小计 start
                // 多年保修 start
                ol.GuaranteePeriod__c =  s.PageObject.GuaranteePeriod__c;
                //外贸多年保 取消CNY 的判断 &&  oppInfo.CurrencyIsoCode.equals('CNY')
                //外贸多年保 精琢技术 wql 2021/01/18 start 
                if (oppInfo.CurrencyIsoCode != null ) {
                  ol.multiYearWarranty__c =  s.PageObject.multiYearWarranty__c;
                  ol.ServicePrice__c =  s.PageObject.ServicePrice__c;
                  ol.If_Cancel_Guarantee__c =  s.PageObject.If_Cancel_Guarantee__c;
                  ol.ProductEntend_gurantee_period_all__c
                    =  s.PageObject.ProductEntend_gurantee_period_all__c;
                  ol.GuranteeType__c =  s.PageObject.GuranteeType__c;
                  ol.NoDiscountTotal__c =  s.PageObject.NoDiscountTotal__c;
                  ol.warrantyType__c =  s.PageObject.warrantyType__c;
                  ol.productServicePrice__c =  s.PageObject.productServicePrice__c;
                  // 计提金额
                  ol.GuranteePrice__c        = s.GuranteePrice;
                  ol.ProductGuranteePrice__c = s.ProductGuranteePrice;
                  // 维修合同报价
                  ol.Maintenance_Price_Year__c = s.Maintenance_Price_Year;
 
                  ol.provistonPeriod__c = s.PageObject.provistonPeriod__c;
 
                }
                //外贸多年保 精琢技术 wql 2021/01/18 end
                // 多年保修 end
                ol.Qty_Unit__c = s.PageObject.Qty_Unit__c;
                //コストは小計済を登録
                ol.Cost__c = s.PageObject.Cost__c;
                ol.BSS_Category__c = s.PageObject.BSS_Category__c;
                //CHAN-BWH2WP 精琢技术 wql 2020/12/22 start 
                //如果产品为不可取消多年保 则打上标识
                system.debug(s.CanNotCancelledGurantee);
                ol.CanNotCancelFlag__c = s.CanNotCancelledGurantee;
                //CHAN-BWH2WP 精琢技术 wql 2020/12/22 end
                //OCM売上予測金額 * (小計/見積合計)
                if (s.PageObject.Subtotal__c != null && opp.Wholesale_Price__c != null && quo.QuoteTotal_Page__c != null) {
                  if (s.PageObject.Subtotal__c > 0 && quo.QuoteTotal_Page__c > 0) {
                    ol.OCM_Sales_Forecast__c =  opp.Wholesale_Price__c * (s.PageObject.Subtotal__c / quo.QuoteTotal_Page__c);
                  }
                }
                //価格表
                ol.PricebookEntryId = s.PageObject.PricebookEntryId;
                //並び順
                ol.Item_Order__c = i;
                ols.add(ol);
                i++;
              }
            }
          }
          // CHAN-BEN5UC   [委托]询价:创建报价后,判断询价一定期间内,是否出借备品 by vivek start
          // CHAN-C9Y3HL 【委托】【评估需求】询价里报价画面速度优化 2022-02-09 
          // 查询出借备品逻辑从保存逻辑中移除,由Batch进行统一操作,以提升保存速度及统计数据准确性。
          // Date createdDateStr;
          // if (quoId != null && quo.CreatedDate != null ) {
          //   // createdDateStr = [select id,CreatedDate from Quote where id = :quoId][0].CreatedDate.date();
          //   createdDateStr = quo.CreatedDate.date();
          // } else {
          //   createdDateStr = Date.today();
          // }
          // // 一年前的日期
          // Date createdDateYear = createdDateStr.addYears(-1);
          // List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [select id, product__c, Bollow_Date__c, Rental_Apply__r.Hospital__c from Rental_Apply_Equipment_Set_Detail__c where Rental_Apply__r.Strategic_dept__c = : opp.Department_Class__c and Key_product__c != null and Bollow_Date__c >= :createdDateYear order by Bollow_Date__c ];
 
          // Map<String, Date> ProOfDate = new Map<String, Date>();
          // for (Rental_Apply_Equipment_Set_Detail__c raesd : raesdList) {
          //   ProOfDate.put(raesd.product__c, raesd.Bollow_Date__c);
          // }
 
          // o.WhetherTrySpareParts_3m__c = false;
          // o.WhetherTrySpareParts_6m__c = false;
          // o.WhetherTrySpareParts_1y__c = false;
          // for (OpportunityLineItem oppitem : ols) {
          //   if (ProOfDate.containsKey(((String)oppitem.Id__c).substring(0, 15))) {
          //     Date bollDate = ProOfDate.get(((String)oppitem.Id__c).substring(0, 15));
          //     if (bollDate != null && bollDate.addMonths(3) > createdDateStr) {
          //       o.WhetherTrySpareParts_3m__c = true;
          //     }
          //     if (bollDate != null && bollDate.addMonths(6) > createdDateStr && bollDate.addMonths(3) < createdDateStr) {
          //       o.WhetherTrySpareParts_6m__c = true;
          //     }
          //     if (bollDate != null && bollDate.addYears(1) > createdDateStr && bollDate.addMonths(6) < createdDateStr) {
          //       o.WhetherTrySpareParts_1y__c = true;
          //     }
 
          //   }
          // }
 
          
          // System.debug('start 2nd save Opportunity at: ' + System.currentTimeMillis());
          // ControllerUtil.updOpp(o);
          // System.debug('finished 2nd save Opportunity at: ' + System.currentTimeMillis());
          // CHAN-BEN5UC   [委托]询价:创建报价后,判断询价一定期间内,是否出借备品 by vivek end
          System.debug('start save Opportunity item lines at: ' + System.currentTimeMillis());
          ControllerUtil.insOppLine(ols);
          System.debug('finished save Opportunity item lines at: ' + System.currentTimeMillis());
        }
 
      } else {
        system.debug('*****SystemError OpportunityId is Null*****');
      }
      //保存時引合Pageに戻らない処理とした為にQuoteIdをここでセット
      if (quoId == null) {
        quoId = q.Id;
        newQuoteFlag = false;
      } 
    }else{
      errorflg = true;
      errormessage = '该询价已经decide,不可再修改';
      return false;
    }
    return true;
  }
  //lastbuy  2022/2/9 fy start
  public boolean ReservedProductVerification() {
 
    filg=true;
    Map<string,QuoteLineItem> quotlinitMap = new Map<string,QuoteLineItem>();
    List<Id> lastProductFLGListId = new List<Id>();
    List<QuoteLineItem> lastProductFLGList = new List<QuoteLineItem>();
    List<QuoteLineItem> act = new List<QuoteLineItem>();
    List<QuoteLineItem> act2 = new List<QuoteLineItem>();
    for(QELine aaa :activities){
      if(aaa.pageObject.PricebookEntry.Product2Id!=null){
        act.add(aaa.pageObject);
      }
    }
    act2=act.deepClone();
    Map<String,QuoteLineItem> map1 = new Map<String,QuoteLineItem>();
    System.debug('activities1111111111112为所当为多多!!!'+activities);
    integer i =0;
    for(QuoteLineItem pspsc :act2){
      if(pspsc.PricebookEntry.Product2Id!=null){
        if(map1.containsKey(pspsc.PricebookEntry.Product2Id)){
          QuoteLineItem quoteLine = map1.get(pspsc.PricebookEntry.Product2Id);
          quoteLine.Quantity__c =quoteLine.Quantity__c+pspsc.Quantity__c;
          map1.put(pspsc.PricebookEntry.Product2Id,quoteLine);
        }else{
          map1.put(pspsc.PricebookEntry.Product2Id,pspsc);
        }
        System.debug('34499879!!!'+activities);
      }
    }
    System.debug('3434343!!!'+activities);
    System.debug('5656565!!!'+map1);
    for (QuoteLineItem value : map1.values()) {
      if(value.PricebookEntry.Product2.LastbuyProductFLG__c){
        lastProductFLGListId.add(value.PricebookEntry.Product2Id);
        quotlinitMap.put(value.PricebookEntry.Product2Id,value);
        lastProductFLGList.add(value);
      }
    }
    System.debug('activities++++!!!'+activities);
    System.debug('activities!!!'+map1.values());
    System.debug('oppId!!!'+oppId);
    System.debug('lastProductFLGList!!!'+lastProductFLGListId);
    if(lastProductFLGListId!=null&&lastProductFLGListId.size()!=0){
        List<LastbuyProduct__c> LastbuyObjList=[select id,LastbuyQuantity__c,InquiryCode__c,ProductName__c,effectiveFLG__c from LastbuyProduct__c where InquiryCode__c= : oppId and ProductName__c in :lastProductFLGListId and effectiveFLG__c = true];
        Map<string,LastbuyProduct__c> LastbuyObjMap = new Map<string,LastbuyProduct__c>();
        System.debug('LastbuyObjList+++++!!!'+LastbuyObjList);
        if(LastbuyObjList!=null&&LastbuyObjList.size()!=0){
          for(LastbuyProduct__c lastbuypr :LastbuyObjList){
            LastbuyObjMap.put(lastbuypr.ProductName__c,lastbuypr);
          }
        }else{
          flglastbuy=1;
          filg=false;
          return filg;
        }
        System.debug('LastbuyObjMap!!!'+LastbuyObjMap);
        System.debug('lastProductFLGList+++++++!!!'+lastProductFLGList);
        if(lastProductFLGList!=null&&lastProductFLGList.size()!=0){
          for(QuoteLineItem lastbuypr :lastProductFLGList){
            Decimal quoteLItemNum=0;
            if(LastbuyObjMap.containsKey(lastbuypr.PricebookEntry.Product2Id)){
                quoteLItemNum=LastbuyObjMap.get(lastbuypr.PricebookEntry.Product2Id).LastbuyQuantity__c;
                System.debug('quoteLItemNum!!!'+quoteLItemNum);
                System.debug('lastbuypr.pageObject.Quantity__c+++!!!'+lastbuypr.Quantity__c);
                if(lastbuypr.Quantity__c>quoteLItemNum){
                  errorProductmodel=lastbuypr.Asset_Model_No__c;
                  flglastbuy=2;
                  filg=false;
                  break;
                }
            }else{
              errorProductmodel=lastbuypr.Asset_Model_No__c;
              flglastbuy=3;
              filg=false;
              break;
            }
          }
        }
    }
    system.debug('filg====='+filg);
    return filg;
  }
  //lastbuy  2022/2/9 fy end
  //oppに画面の値を設定
  private void setOppFromOppInfo() {
    opp.Wholesale_Price__c = oppInfo.Wholesale_Price;
    opp.Agency1__c = quo.Agency1__c;
    opp.Agency2__c = quo.Agency2__c;
  }
 
  public class OppInfo {
    public String Account_RecordType_DeveloperName { get; set; }
    public String Direct_Separate { get; set; }
    public String Trade { get; set; }
    public Decimal Wholesale_Price { get; set; }
    public String CurrencyIsoCode { get; set; }
    public String HP_Name { get; set; }
    public String Department_Name { get; set; }
    public String Sales_Root { get; set; }
    // LHJ Start
    public boolean If_Need_Authorize { get; set; }
    public String Authorized_DB_No { get; set; }
    // LHJ End
 
    public OppInfo(Opportunity opp) {
      Account_RecordType_DeveloperName = opp.Account.RecordType.DeveloperName;
      Direct_Separate = opp.Direct_Separate__c;
      Trade = opp.Trade__c;
      Wholesale_Price = opp.Wholesale_Price__c;
      CurrencyIsoCode = opp.CurrencyIsoCode;
      HP_Name = opp.HP_Name__c;
      Department_Name = opp.Department_Name__c;
      Sales_Root = opp.Sales_Root__c;
      // LHJ Start
      If_Need_Authorize = opp.If_Need_Authorize__c;
      Authorized_DB_No = opp.Authorized_DB_No__c;
      // LHJ End
    }
  }
  //TODO 1.Quoteオブジェクト追加
  //TODO 2.コンストラクタを追加
  public class QuoteBean {
    public Decimal Estimation_List_Price { get; set; }
    //TODO 999.99以下しか入力できない。
    public Decimal Quote_Adjust_Calculate { get; set; }
    public Decimal SalesCalculation1 { get; set; }
    public Decimal SalesCalculation2 { get; set; }
    public Integer PriceRefreshPeriod { get; set; }
    public void setPriceRefreshPeriodByDate(Date PriceRefreshDate) {
      this.PriceRefreshPeriod = PriceRefreshDate.daysBetween(Date.today());
    }
  }
 
  public class QELinelatestInfo {
    public String ProductCode { get; set; }
    public String ProductName { get; set; }
    public String SFDA_Status { get; set; }
    public String Sales_Possibility { get; set; }
    public Decimal ListPrice { get; set; }              // 最新
    public Decimal Cost { get; set; }                    // 最新
    public Integer Specifications {get; set;}
 
    // 多年保修 start
    public string GuranteeType {get; set;}
    public Decimal Intra_Trade_Gurantee {get; set;}
    public Decimal ProductEntend_gurantee_period_all {get; set;}
    public Decimal Intra_Trade_Service {get; set;}
    // 维修合同报价
    public Decimal Maintenance_Price_Year {get; set;}
    // 多年保修 end
    // 维修合同报价
    //不可取消多年保
    public Boolean CanNotCancelledGurantee {get; set;}
    // 多年保修 end
 
    //阿西赛多
    public Boolean Is_DangerousChemicals {get; set;}
    //阿西赛多
 
  }
  public class QELine {
    public Integer lineNo { get; set; }                                // 画面の順序
    public String Asset_Model { get; set; }
    public String Sales_Possibility { get; set; }                         // 販売可否○×判断用、使ってないようです。TODO 削除
    public QuoteLineItem pageObject { get; set; }                      // Id__cは空行判断用、SFDA_Status__c など、翻訳される項目表示するため使う必要があります
    public Decimal Cost_c { get; set; }
    public Decimal Cost_Subtotal_c { get; set; }
    public Decimal ListPrice_Page { get; set; }
    //*******************************liukun******************//
    public String StorageStatus { get; set; }
    //********************Insert [OLY_OCM-228] [20160706] [赵德芳] Start********************//
    public Integer Specifications {get; set;}
    //********************Insert [OLY_OCM-228] [20160706] [赵德芳] End**********************//
    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start
    public String VenderName { get; set; }
    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end
 
    //不可取消多年保
    public Boolean CanNotCancelledGurantee {get;set;}
    //阿西赛多
    public Boolean Is_DangerousChemicals {get;set;}
 
    // PriceStatusUpdate() 用の項目、TODO 初期値の設定
    public QELinelatestInfo latestInfo { get; set; }
 
    public boolean changed_name { get; set; }
    public boolean changed_sfda { get; set; }
    public boolean changed_list { get; set; }
    public boolean changed_cost { get; set; }
    public boolean haveno_Register { get; set; }
    public boolean wrong_Register { get; set; }
 
    //SFDC停止预警 lt 20211009 start
    public String Estimated_ConsumptionDueDate { get; set; }
    //SFDC停止预警 lt 20211009 end
 
    // 多年保修 start
    //计提金额
    public Decimal GuranteePrice { get; set; }
    public Decimal ProductGuranteePrice { get; set; }
    // 维修合同报价
    public decimal Maintenance_Price_Year {get; set;}
    // 多年保修 end
 
    // TODO ほんとうはいらない、使うところのロジックを修正しなければいけない、削除するようにしたいです。
    public QELine(Integer i) {
      pageObject = New QuoteLineItem();
      latestInfo = New QELinelatestInfo();
      this.lineNo = i;
    }
    // tmp 直接使う場合のパターン
    public QELine(QELine tmp, Integer i) {
      pageObject = tmp.pageObject;
      this.lineNo = i;
      this.Asset_Model = tmp.Asset_Model;
      this.Sales_Possibility = tmp.Sales_Possibility;
      this.latestInfo = tmp.latestInfo;
      this.Cost_Subtotal_c = tmp.Cost_Subtotal_c;
      this.Cost_c = tmp.Cost_c;
      this.ListPrice_Page = tmp.ListPrice_Page;
      this.StorageStatus = tmp.StorageStatus;
      // 多年保修  start
      // 计提金额
      this.GuranteePrice          = tmp.GuranteePrice;
      this.ProductGuranteePrice   = tmp.ProductGuranteePrice;
      //维修合同报价
      this.Maintenance_Price_Year = tmp.Maintenance_Price_Year;
      // 多年保修 计提金额 end
 
      this.changed_name = tmp.changed_name;
      this.changed_sfda = tmp.changed_sfda;
      this.changed_list = tmp.changed_list;
      this.changed_cost = tmp.changed_cost;
      this.haveno_Register = false;
      this.wrong_Register  = false;
      //不可取消多年保
      this.CanNotCancelledGurantee = tmp.CanNotCancelledGurantee;
      //供应商名称
      this.VenderName = tmp.VenderName;
 
      //SFDC停止预警 lt 20211009 start
      this.Estimated_ConsumptionDueDate = tmp.Estimated_ConsumptionDueDate;
      //SFDC停止预警 lt 20211009 end
 
    }
    public QELine(OpportunityLineItem oli, Integer i) {
      pageObject = New QuoteLineItem();
      pageObject.Quantity__c = oli.Quantity;
 
      this.lineNo = i;
      this.Asset_Model = oli.Asset_Model_No__c;
      this.Sales_Possibility = oli.PricebookEntry.Product2.Sales_Possibility__c;
      this.StorageStatus = oli.PricebookEntry.Product2.StorageStatus__c;
      //********************Insert [OLY_OCM-228] [20160706] [赵德芳] Start********************//
      if (oli.PricebookEntry.Product2.Packing_list_manual__c != null) {
        this.Specifications = integer.valueof(oli.PricebookEntry.Product2.Packing_list_manual__c + '');
      }
      //********************Insert [OLY_OCM-228] [20160706] [赵德芳] End**********************//
      PageObject.Id__c = oli.PricebookEntry.Product2Id;
      PageObject.UnitPrice_Page__c = oli.UnitPrice__c;
      //CHAN-B4YAB8 2018/9/28 小计经销商单价和小计
      PageObject.AgencySubtotal__c = oli.AgencySubtotal__c;
      PageObject.AgencyUnitPrice__c = oli.AgencyUnitPrice__c;
      // CHAN-B4YAB8 2018/9/28 经销商单价和小计
 
      //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start
      this.VenderName = oli.PricebookEntry.Product2.VenderName__c;
 
      //SFDC停止预警 lt 20211009  ①不能定义date变量 因为前台返回的是String日期  ②将util里的方法转为日期格式 start
      if(oli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c != null){
        this.Estimated_ConsumptionDueDate = NFMUtil.formatDate2StrSpo(oli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c).replaceAll('-','/');
      }else{
        this.Estimated_ConsumptionDueDate = '';
      }
      //SFDC停止预警 lt 20211009 end
 
      if(VenderName==null||VenderName==''){
          this.VenderName =' 无 ';
      }else{
          this.VenderName = oli.PricebookEntry.Product2.VenderName__c;
      }
      //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end
      //不可取消多年保
      this.CanNotCancelledGurantee = oli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
      //阿西赛多
      this.Is_DangerousChemicals = oli.PricebookEntry.Product2.Is_DangerousChemicals__c;
      // 多年保修 start
      PageObject.multiYearWarranty__c = oli.multiYearWarranty__c;
      PageObject.GuaranteePeriod__c = oli.GuaranteePeriod__c;
      PageObject.ServicePrice__c = oli.ServicePrice__c;
      PageObject.If_Cancel_Guarantee__c = oli.If_Cancel_Guarantee__c;
      PageObject.warrantyType__c = oli.warrantyType__c;
 
      PageObject.NoDiscountTotal__c = oli.NoDiscountTotal__c;
      // 计提金额
      this.GuranteePrice          = oli.GuranteePrice__c;
      // 维修合同报价
      this.Maintenance_Price_Year = oli.Maintenance_Price_Year__c;
      PageObject.provistonPeriod__c = oli.provistonPeriod__c;
 
      PageObject.ProductEntend_gurantee_period_all__c =  oli.PricebookEntry.Product2.Entend_gurantee_period_all__c;
      PageObject.GuranteeType__c = oli.PricebookEntry.Product2.GuranteeType__c;
      
      
      // 多年保修 end
      PageObject.SFDA_Status__c = oli.PricebookEntry.Product2.SFDA_Status__c;
      //不可取消多年保
//      PageObject.CanNotCancelledGurantee__c = oli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
 
 
      PageObject.Name__c = oli.PricebookEntry.Product2.Name;
 
      Decimal cost;
      if (oli.Opportunity.Trade__c == '内貿') {
        this.ListPrice_Page = oli.PricebookEntry.Product2.Intra_Trade_List_RMB__c;
        cost = oli.PricebookEntry.Product2.Intra_Trade_Cost_RMB__c;
        this.ProductGuranteePrice   = oli.PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c;
        PageObject.productServicePrice__c = oli.PricebookEntry.Product2.Intra_Trade_Service_RMB__c;
      } else if (oli.Opportunity.Trade__c == '外貿') {
        this.ListPrice_Page = oli.PricebookEntry.Product2.Foreign_Trade_List_US__c;
        cost = oli.PricebookEntry.Product2.Foreign_Trade_Cost_US__c;
        this.ProductGuranteePrice   = oli.PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c;
        PageObject.productServicePrice__c = oli.PricebookEntry.Product2.NoDiscount_Foreign__c;
      }
      if (cost > 0 && oli.Quantity > 0) {
        this.Cost_Subtotal_c = cost * oli.Quantity;
      }
      this.Cost_c = cost;
      if (oli.UnitPrice__c > 0 && oli.Quantity > 0) {
        oli.TotalPrice__c = oli.UnitPrice__c * oli.Quantity;
      }
 
      PageObject.BSS_Category__c = oli.BSS_Category__c;
      pageObject.Subtotal__c = oli.TotalPrice__c;
      pageObject.PricebookEntryId = oli.PricebookEntryId;
      latestInfo = New QELinelatestInfo();
      latestInfo.ProductCode = oli.ProductCode__c;
      latestInfo.ProductName = oli.PricebookEntry.Product2.Name;
      latestInfo.SFDA_Status = oli.PricebookEntry.Product2.SFDA_Status__c;
      latestInfo.Sales_Possibility = oli.PricebookEntry.Product2.Sales_Possibility__c;
      // 多年保修 start
      //外贸多年保 取产品主数据的外贸金额 以及 报价 精琢技术 wql 2021/01/04 start 
      latestInfo.ProductEntend_gurantee_period_all    =  oli.PricebookEntry.Product2.Entend_gurantee_period_all__c;
      if (oli.Opportunity.Trade__c == '内貿') {
        latestInfo.Intra_Trade_Gurantee             =  oli.PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c;
        latestInfo.Intra_Trade_Service              =  oli.PricebookEntry.Product2.Intra_Trade_Service_RMB__c;
 
        // 维修合同报价
        latestInfo.Maintenance_Price_Year = oli.PricebookEntry.Product2.Maintenance_Price_Year__c;
      } else if (oli.Opportunity.Trade__c == '外貿') {
        latestInfo.Intra_Trade_Gurantee             =  oli.PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c;
        latestInfo.Intra_Trade_Service              =  oli.PricebookEntry.Product2.NoDiscount_Foreign__c;
        
 
        // 维修合同报价
        latestInfo.Maintenance_Price_Year = oli.PricebookEntry.Product2.Repair_Contract_USD__c;
      }
      //外贸多年保 取产品主数据的外贸金额 以及 报价 精琢技术 wql 2021/01/04 end
        latestInfo.GuranteeType                        =  oli.PricebookEntry.Product2.GuranteeType__c;
      // 多年保修 end
      if (oli.PricebookEntry.Product2.Packing_list_manual__c != null) {
        latestInfo.Specifications = integer.valueof(oli.PricebookEntry.Product2.Packing_list_manual__c + '');
      }
      latestInfo.ListPrice = oli.Product_ListPrice__c;
      latestInfo.Cost = oli.Product_Cost__c;
      //不可取消多年保 
      latestInfo.CanNotCancelledGurantee  = oli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
      this.changed_name = false;
      this.changed_sfda = false;
      this.changed_list = false;
      this.changed_cost = false;
      this.haveno_Register = false;
      this.wrong_Register  = false;
    }
    public QELine(QuoteLineItem qli, Integer i, String copyQuoId) {
      //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, ' qli Id__c=' + qli.PricebookEntry.Product2Id));
      pageObject = qli.clone();
      pageObject.Id__c = qli.PricebookEntry.Product2Id;
      pageObject.Quantity__c = qli.Quantity;
      //ET促销标记 start
      // pageObject.ETPromotionalFlag__c = qli.ETPromotionalFlag__c;
      //ET促销标记 end
      if (copyQuoId != null) {
        pageObject.SFDA_Status__c = qli.PricebookEntry.Product2.SFDA_Status__c;
        pageObject.Name__c = qli.PricebookEntry.Product2.Name;
        //PageObject.PricebookEntry.Product2.Packing_list_manual__c = qli.PricebookEntry.Product2.Packing_list_manual__c;
      }
      this.lineNo = i;
      this.Asset_Model = qli.Asset_Model_No__c;
      if (qli.Cost__c > 0 && qli.Quantity > 0) {
        this.Cost_Subtotal_c = qli.Cost__c * qli.Quantity;
      }
      //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start
      this.VenderName = qli.PricebookEntry.Product2.VenderName__c;
 
      //SFDC停止预警 lt 20211009  ①不能定义date变量 因为前台返回的是String日期  ②将util里的方法转为日期格式 start
      if(qli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c != null){
        this.Estimated_ConsumptionDueDate = NFMUtil.formatDate2StrSpo(qli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c).replaceAll('-','/');
      }else{
        this.Estimated_ConsumptionDueDate = '';
      }
      //SFDC停止预警 lt 20211009 end
 
            if(VenderName==null||VenderName==''){
                this.VenderName =' 无 ';
            }else{
                //this.VenderName = qli.PricebookEntry.Product2.VenderName__c;
            }
      //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start
      //不可取消多年保
      this.CanNotCancelledGurantee = qli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
      //阿西赛多
      this.Is_DangerousChemicals = qli.PricebookEntry.Product2.Is_DangerousChemicals__c;
      //************************************liukun*****************************************************//
      this.StorageStatus = qli.PricebookEntry.Product2.StorageStatus__c;
 
      this.ListPrice_Page = qli.ListPrice__c;
      this.Cost_c = qli.Cost__c;
      pageObject.Subtotal__c = qli.TotalPrice__c;
      pageObject.UnitPrice_Page__c = qli.UnitPrice__c;
      latestInfo = New QELinelatestInfo();
      latestInfo.ProductCode = qli.ProductCode__c;
      latestInfo.ProductName = qli.PricebookEntry.Product2.Name;
 
      latestInfo.SFDA_Status = qli.PricebookEntry.Product2.SFDA_Status__c;
      // 多年保修 start
 
      latestInfo.ProductEntend_gurantee_period_all    =  qli.PricebookEntry.Product2.Entend_gurantee_period_all__c;
      //外贸多年保 取产品主数据上的金额及报价 精琢技术 wql start
      if(qli.Quote.Opportunity.Trade__c == '内貿'){
        latestInfo.Intra_Trade_Gurantee             =  qli.PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c;
        latestInfo.Intra_Trade_Service             =  qli.PricebookEntry.Product2.Intra_Trade_Service_RMB__c;
        //维修合同报价
        //HWAG-BLDE4M decide后成本为空 精琢技术 20200227 start
        if(qli.PricebookEntry.Product2.Maintenance_Price_Year__c == null){
          latestInfo.Maintenance_Price_Year = 0;
        }else{
          latestInfo.Maintenance_Price_Year = qli.PricebookEntry.Product2.Maintenance_Price_Year__c;
        }
        //HWAG-BLDE4M decide后成本为空 精琢技术 20200227 end
      }else if(qli.Quote.Opportunity.Trade__c == '外貿'){
          latestInfo.Intra_Trade_Gurantee             =  qli.PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c;
          latestInfo.Intra_Trade_Service              =  qli.PricebookEntry.Product2.NoDiscount_Foreign__c;
          //维修合同报价
          //HWAG-BLDE4M decide后成本为空 精琢技术 20200227 start
          if(qli.PricebookEntry.Product2.Maintenance_Price_Year__c == null){
            latestInfo.Maintenance_Price_Year = 0;
          }else{
            latestInfo.Maintenance_Price_Year = qli.PricebookEntry.Product2.Repair_Contract_USD__c;
          }
          //HWAG-BLDE4M decide后成本为空 精琢技术 20200227 end
      }
      //外贸多年保 取产品主数据上的金额及报价 精琢技术 wql end
      
      latestInfo.GuranteeType                         =  qli.PricebookEntry.Product2.GuranteeType__c;
      //不可取消多年保 
      latestInfo.CanNotCancelledGurantee  = qli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
      // 计提金额
      this.Maintenance_Price_Year                     = qli.Maintenance_Price_Year__c;
      this.GuranteePrice                              =  qli.GuranteePrice__c;
      this.ProductGuranteePrice                       =  qli.ProductGuranteePrice__c;
      // 多年保修 end
      latestInfo.Sales_Possibility = qli.PricebookEntry.Product2.Sales_Possibility__c;
      if (qli.PricebookEntry.Product2.Packing_list_manual__c != null) {
        latestInfo.Specifications = integer.valueof(qli.PricebookEntry.Product2.Packing_list_manual__c + '');
      }
      latestInfo.ListPrice = qli.Product_ListPrice__c;
      latestInfo.Cost = qli.Product_Cost__c;
      //********************Insert [OLY_OCM-228] [20160706] [赵德芳] Start********************//
      if (qli.PricebookEntry.Product2.Packing_list_manual__c != null) {
        this.Specifications = integer.valueof(qli.PricebookEntry.Product2.Packing_list_manual__c + '');
      }
      //********************Insert [OLY_OCM-228] [20160706] [赵德芳] End**********************//
      this.changed_name = false;
      this.changed_sfda = false;
      this.changed_list = false;
      this.changed_cost = false;
      this.haveno_Register = false;
      this.wrong_Register  = false;
    }
 
    // TODO Subtotal__c、以前のロジックを確認
    /*public QELine(Integer i, String PricebookEntryId,
                  String Asset_Model, String StorageStatus,
                  String ProductCode, String Id_c,
                  String SFDA_Status_c, String Sales_Possibility_c,
                  String Name_c, String BSS_Category_c,
                  Integer Quantity, Decimal ListPrice_c,
                  Decimal UnitPrice_c, Decimal Cost_c,
                  Decimal Packing_list_manual
                 ) {
        pageObject = New QuoteLineItem();
        pageObject.Quantity__c = Quantity;
        this.lineNo = i;
        this.Asset_Model = Asset_Model;
        this.Sales_Possibility = Sales_Possibility_c;
 
        this.StorageStatus = StorageStatus;
 
        pageObject.Id__c = Id_c;
        pageObject.SFDA_Status__c = SFDA_Status_c;
        pageObject.Name__c = Name_c;
        pageObject.BSS_Category__c = BSS_Category_c;
        this.ListPrice_Page = ListPrice_c;
        pageObject.UnitPrice_Page__c = UnitPrice_c;
        pageObject.Subtotal__c = UnitPrice_c * Quantity;
        //PageObject.PricebookEntry.Product2.Packing_list_manual__c = Packing_list_manual;
        this.Cost_c = Cost_c;
        // TODO katsu なぜここ > 0 の判断はいらない?
        this.Cost_Subtotal_c = Cost_c * Quantity;
        pageObject.PricebookEntryId = PricebookEntryId;
        latestInfo = New QELinelatestInfo();
        latestInfo.ProductCode = ProductCode;
        latestInfo.ProductName = Name_c;
        latestInfo.SFDA_Status = SFDA_Status_c;
        latestInfo.Sales_Possibility = Sales_Possibility_c;
        latestInfo.ListPrice = this.ListPrice_Page;
        latestInfo.Cost = pageObject.Cost__c;
        if (Packing_list_manual != null) {
            latestInfo.Specifications = integer.valueof('' + Packing_list_manual);
        }
        this.changed_name = false;
        this.changed_sfda = false;
        this.changed_list = false;
        this.changed_cost = false;
        this.haveno_Register = false;
        this.wrong_Register  = false;
    }
    */
 
    //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start 增加字段
    // 多年保修 start
    public QELine(Integer i,Boolean Is_DangerousChemicals,Boolean CanNotCancelledGurantee,String VenderName,
                  Date Estimated_ConsumptionDueDate,   //20211009 lt add
                  String PricebookEntryId,
      //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end 增加字段
                  String Asset_Model, String StorageStatus,
                  String ProductCode, String Id_c,
                  String SFDA_Status_c, String Sales_Possibility_c,
                  String Name_c, String BSS_Category_c,
                  Integer Quantity, Decimal ListPrice_c,
                  Decimal UnitPrice_c, Decimal Cost_c,
                  Decimal Packing_list_manual
                  , Decimal Entend_gurantee_period_all
                  , decimal ProductGuranteePrice
                  , string GuranteeType
                  , Decimal productServicePrice
                  , Decimal productMaintenance_Price_Year
                 ) {
      pageObject = New QuoteLineItem();
      pageObject.Quantity__c = Quantity;
      this.lineNo = i;
      this.Asset_Model = Asset_Model;
      this.Sales_Possibility = Sales_Possibility_c;
 
      //SFDC停止预警 lt 20211009  ①不能定义date变量 因为前台返回的是String日期  ②将util里的方法转为日期格式 start
      if(Estimated_ConsumptionDueDate != null){
        this.Estimated_ConsumptionDueDate = NFMUtil.formatDate2StrSpo(Estimated_ConsumptionDueDate).replaceAll('-','/');
      }else{
        this.Estimated_ConsumptionDueDate = '';
      }
      //SFDC停止预警 lt 20211009 end
 
      this.StorageStatus = StorageStatus;
 
      pageObject.Id__c = Id_c;
      pageObject.SFDA_Status__c = SFDA_Status_c;
      pageObject.Name__c = Name_c;
      pageObject.BSS_Category__c = BSS_Category_c;
      this.ListPrice_Page = ListPrice_c;
      pageObject.UnitPrice_Page__c = UnitPrice_c;
      pageObject.Subtotal__c = UnitPrice_c * Quantity;
 
      //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 Start
       system.debug('VenderName=========='+VenderName);
        if(VenderName==null||VenderName==''){
            this.VenderName =' 无 ';
        }else{
            this.VenderName = VenderName;
        }
      //不可取消多年保
      this.CanNotCancelledGurantee = CanNotCancelledGurantee;
      //阿西赛多
      this.Is_DangerousChemicals = Is_DangerousChemicals;
      //CHAN-BKU3XH 检查是否存在不是同一个供销商名称 精琢技术 2020/02/17 end
      // 多年保修 start
      pageObject.ProductEntend_gurantee_period_all__c = Entend_gurantee_period_all;
      pageObject.productServicePrice__c               = productServicePrice;
      pageObject.GuranteeType__c                      = GuranteeType;
      // 计提金额
      this.ProductGuranteePrice                       =  ProductGuranteePrice;
      // 维修合同报价
      this.Maintenance_Price_Year                     = productMaintenance_Price_Year;
      // 多年保修 end
      //PageObject.PricebookEntry.Product2.Packing_list_manual__c = Packing_list_manual;
      this.Cost_c = Cost_c;
      // TODO katsu なぜここ > 0 の判断はいらない?
      this.Cost_Subtotal_c = Cost_c * Quantity;
      pageObject.PricebookEntryId = PricebookEntryId;
      latestInfo = New QELinelatestInfo();
      latestInfo.ProductCode = ProductCode;
      latestInfo.ProductName = Name_c;
 
      latestInfo.SFDA_Status = SFDA_Status_c;
      latestInfo.Sales_Possibility = Sales_Possibility_c;
      latestInfo.ListPrice = this.ListPrice_Page;
      latestInfo.Cost = pageObject.Cost__c;
      // 多年保修 start
      latestInfo.ProductEntend_gurantee_period_all    =  Entend_gurantee_period_all;
      latestInfo.Intra_Trade_Gurantee             =  ProductGuranteePrice;
      latestInfo.Intra_Trade_Service              =  productServicePrice;
      latestInfo.GuranteeType                         =  GuranteeType;
      latestInfo.Maintenance_Price_Year               =  productMaintenance_Price_Year;
      //不可取消多年保
      latestInfo.CanNotCancelledGurantee = CanNotCancelledGurantee;
      //阿西赛多
      latestInfo.Is_DangerousChemicals = Is_DangerousChemicals;
      // 多年保修 end
 
 
      if (Packing_list_manual != null) {
        latestInfo.Specifications = integer.valueof('' + Packing_list_manual);
      }
      this.changed_name = false;
      this.changed_sfda = false;
      this.changed_list = false;
      this.changed_cost = false;
      this.haveno_Register = false;
      this.wrong_Register  = false;
    }
    // 多年保修 end
  }
 
  @TestVisible private void testI() {
    integer i = 0;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
    i++;
  }
}