<?php
include_once "../inc/config.php";
$mysqli = get_mysqli_connection();
include_once dirname(__FILE__) . "/../inc/getBasic.inc.php";
include_once dirname(__FILE__) . "/../inc/getData.inc.php";
include_once dirname(__FILE__) . "/../inc/tradeRec.inc.php";
include_once __DIR__ . "/../html/headChart.php";
$ts_code=   ts_code_conv($_REQUEST['ts_code']);
$day_st =   ($_REQUEST['s']=='')?'20180101':reformDate($_REQUEST['s']);
$day_end=   ($_REQUEST['e']=='')?date('Ymd'):reformDate($_REQUEST['e']);

$unit   =   '股';   # Without a unit on PE
$data   =   getStockHist($ts_code,date("Ymd",strtotime($day_st)),date("Ymd",strtotime($day_end)));
//$data2  =   getBasicData($ts_code,$day_st,$day_end,$item);
if($_REQUEST['t_vendor']=='方正证券') {$flg3   = '买入'; $flg4   = '卖出';}
elseif($_REQUEST['t_vendor']=='长江证券') {$flg3   = '证券买入'; $flg4   = '证券卖出';}
$trdData  = trade_rec($ts_code, $day_st, $day_end,'');
$data3  = recDataSort($trdData,$flg3);
$data4  = recDataSort($trdData,$flg4);
$data3Avg = avePrice($data3['tvol'],$data3['tprice']);
$data4Avg = avePrice($data4['tvol'],$data4['tprice']);

$subtext_ext   = " {$flg3}均价: {$data3Avg['avePrice']}, 量{$data3Avg['ttlVol']}股 ";
$subtext_ext  .= "-- {$flg4}均价: {$data4Avg['avePrice']}, 量{$data4Avg['ttlVol']}股 ";

$ts_name      = tscodeToName($ts_code);
$legend       = array('不复权股价','交易买入','交易卖出','买入量','卖出量');
if($_REQUEST['adj']) $legend[0]='复权股价';
?>
<form name="form1" id="form1" method="post">
    <input type="hidden" name="adj" id="adj" value="<?=$_REQUEST['adj'] ?>">
    <input type="hidden" name="ts_code" id="ts_code" value="<?=$ts_code ?>">
    <input type="hidden" name="s" id="s" value="<?=$day_st ?>">
    <input type="hidden" name="e" id="e" value="<?=$day_end ?>">

</form>
<script type="text/javascript">
    var legend = <?php echo json_encode($legend);?>;
    var unit ='<?=$unit ?>';
    var headtxt = '<?php echo $ts_name.'('.$ts_code.')'; ?>';
    var subtxt = '<?=$subtext_ext ?>';
    var data1 = <?php echo json_encode($data['data']); ?>;
    var data2 = <?php echo json_encode($data3['data']); ?>;
    var data3 = <?php echo json_encode($data4['data']); ?>;
    var data4 = <?php echo json_encode($data3['data2']); ?>;
    var data5 = <?php echo json_encode($data4['data2']); ?>;

    console.log(data1[0]['value'][0]);
    console.log(data1[0]['value'][1]);
</script>
<script type="text/javascript" src="../js/adj.ajax.js?verion=3.14"></script>
<script>
    console.log(data1[0]['value'][0]);
    console.log(data1[0]['value'][1]);
</script>
<script type="text/javascript" src="../js/chartStDetail.js?version=3.16"></script>
   </body>
</html>