<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>

<div class="content_wrapper">
    <div class="container-fluid">
        <aside>
            <header><i class="fa fa-fw fa-file"></i>发放&消耗</header>
            <section>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-12">
                            <a style="margin:5px;" class="btn btn-primary " href="#statistics/assetsSta/1" role="button">金币</a>
                            <a style="margin:5px;" class="btn btn-primary " href="#statistics/assetsSta/2" role="button">体力</a>
                            <a style="margin:5px;" class="btn btn-primary " href="#statistics/assetsSta/5" role="button">钻石</a>
                            <a style="margin:5px;" class="btn btn-primary " href="#statistics/assetsSta/3" role="button">净消耗曲线</a>
                        </div>
                    </div>
                </div>
            </section>
        </aside>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#statistics/assetsSta/<?php echo $type?>" name="stanpform">
                                        <input type="hidden" name="moneyinout_post" value="1">
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>开始时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($stime) echo $stime;?>" placeholder="开始时间" name="moneyinout_stime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($etime) echo $etime;?>" placeholder="结束时间" name="moneyinout_etime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>开始等级</label>
                                            <input type="text" class="form-control" value="<?php if($start_level) echo $start_level;?>" placeholder="开始等级" name="start_level" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束等级</label>
                                            <input type="text" class="form-control" value="<?php if($end_level) echo $end_level;?>" placeholder="结束等级" name="end_level" />
                                        </div>
                                        <br>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>开始时分</label>
                                            <input type="text" class="form-control" value="<?php if($sHourMinute) echo $sHourMinute;?>" placeholder="00:00" name="sHourMinute" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束时分</label>
                                            <input type="text" class="form-control" value="<?php if($eHourMinute) echo $eHourMinute;?>" placeholder="00:00" name="eHourMinute" />
                                        </div>
                                        <span class="gap"></span>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
            <div class="row">
                <div class="col-sm-12">
                    <aside>
                        <header><i class="fa fa-fw fa-file"></i>基础数据</header>
                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="table-responsive">
                                            <table id="reportTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                                <thead>
                                                <tr>
                                                    <!--                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">序号</th>-->
                                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">日期</th>
                                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">类型</th>
                                                    <th colspan="<?php echo count($title['add'])+2;?>" style="text-align: center;vertical-align: middle;">发放</th>
                                                    <th colspan="<?php echo count($title['low'])+2;?>" style="text-align: center;vertical-align: middle;">消耗</th>
                                                    <!--                                    <th colspan="7" style="text-align: center">其他</th>-->
                                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">消耗率</th>
                                                    <?php
                                                    	if($type == '1'){
                                                    		echo '<th rowspan="2" style="text-align: center;vertical-align: middle;">卡片回收率</th>';
                                                    	}else{
                                                    		echo '<th rowspan="2" style="text-align: center;vertical-align: middle;">老虎机回收率</th>';
                                                    	}
                                                   
                                                    ?>
                                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">付费比例</th>
                                                    <th rowspan="2" style="text-align: center;vertical-align: middle;">单日汇总</th>
                                                </tr>

                                                <tr>
                                                    <?php
                                                        foreach ($title['add'] as $row){
                                                            echo "<th>{$row}</th>";
                                                        }
                                                    ?>
                                                    <th>发放汇总</th>
                                                    <th>参与人数</th>
                                                    
                                                    <?php
                                                    foreach ($title['low'] as $row){
                                                        echo "<th>{$row}</th>";
                                                    }
                                                    ?>
                                                    <th>消耗汇总</th>
                                                    <th>参与人数</th>
                                                    
                                                </tr>
                                                </thead>
                                                <tbody id="reportBody">
                                                <?php
                                                    function formatChipRound($value, $round=2)
                                                    {
                                                        $value = ceil($value);

                                                        if(1 <= abs($valueB = round($value / 1000000000, $round))) {
                                                            return  $valueB . 'B';
                                                        }else if(1 <= abs($valueM=round($value / 1000000, $round))) {
                                                            return $valueM . 'M';
                                                        }else if(1 <= abs($valueK=round($value / 1000, $round))) {
                                                            return $valueK . 'K';
                                                        }else {
                                                            return $value;
                                                        }
                                                    }
                                                ?>
                                                <?php
                                                if(is_array($data)){
                                                    foreach ($data as $val) {
                                                        ?>
                                                        <tr>
                                                            <td style="white-space: nowrap" rowspan="4"><?php echo $val['date'];?></td>
                                                            <td style="white-space: nowrap">总值</td>
                                                            <?php
                                                                foreach ($title['add'] as $key=>$row){
                                                                    $temp = formatChipRound($val['add'][$key]);
                                                                    echo "<td>$temp</td>";
                                                                }
                                                                $add = formatChipRound(array_sum($val['add']));
                                                                echo "<td>$add</td>";
                                                                
                                                                //参与人数
                                                                echo "<td>{$val['todayLogin']}</td>";
                                                                
                                                                foreach ($title['low'] as $key=>$row){
                                                                    $temp = formatChipRound($val['low'][$key]);
                                                                    echo "<td>$temp</td>";
                                                                }
                                                                $low = formatChipRound(array_sum($val['low']));
                                                                echo "<td>$low</td>";
                                                                
                                                                //参与人数
                                                                echo "<td>{$val['todayLogin']}</td>";
                                                                
                                                                $sum = formatChipRound(array_sum($val['add']) - array_sum($val['low']));
                                                                //消耗率
                                                                echo "<td rowspan='4'>".($add?round($low/$add*100,2)."%":"-")."</td>";
                                                                //回收率
                                                                if($type == '1'){
                                                                	if(empty($val['low']['400']) || empty($val['add']['30'])){
                                                                		echo "<td rowspan='4'>0%</td>";
                                                                	}else{
                                                                		echo "<td rowspan='4'>".round($val['low']['400']/$val['add']['30']*100,2)."%</td>";
                                                                	}
                                                                }else{
                                                                	if(empty($val['low']['1'])){
                                                                		echo "<td rowspan='4'>0%</td>";
                                                                	}else{
                                                                		echo "<td rowspan='4'>".round($val['low']['1']/$val['add']['1']*100,2)."%</td>";
                                                                	}
                                                                	
                                                                }
                                                                
                                                                //金币&体力发放  增加 付费比例= 付费发放/总发放
                                                                echo "<td rowspan='4'>".(empty($val['payTotal'])?0:(round($val['payTotal'] / array_sum($val['add']),4)*100))."%</td>";
                                                                
                                                                echo "<td>$sum</td>";
                                                            ?>
                                                        </tr>
                                                        <tr>
                                                            <td style="white-space: nowrap">人均</td>
                                                            <?php
                                                            foreach ($title['add'] as $key=>$row){
                                                                $temp = formatChipRound($val['add'][$key]/$val['todayLogin']);
                                                                echo "<td>$temp</td>";
                                                            }
                                                            $add = formatChipRound(array_sum($val['add'])/$val['todayLogin']);
                                                            echo "<td>$add</td>";
                                                            
                                                            //参与人数
                                                            echo "<td>{$val['todayLogin']}</td>";
                                                                
                                                            foreach ($title['low'] as $key=>$row){
                                                                $temp = formatChipRound($val['low'][$key]/$val['todayLogin']);
                                                                echo "<td>$temp</td>";
                                                            }
                                                            $low = formatChipRound(array_sum($val['low'])/$val['todayLogin']);
                                                            
                                                            echo "<td>$low</td>";
                                                            
                                                            //参与人数
                                                            echo "<td>{$val['todayLogin']}</td>";
                                                            
                                                            $sum = formatChipRound((array_sum($val['add']) - array_sum($val['low']))/$val['todayLogin']);
                                                            
                                                            echo "<td>$sum</td>";
                                                            ?>
                                                        </tr>
                                                        <tr>
                                                            <td style="white-space: nowrap">参与人数(从流水统计)</td>
                                                            <?php
                                                            foreach ($title['add'] as $key=>$row){
                                                                $temp = $peopleData[$val['date']]['add'][$key] ?? 0;
                                                                echo "<td>{$temp}</td>";
                                                            }
                                                            echo "<td>-</td>";//发放汇总
                                                            echo "<td>-</td>";//参与人数
                                                            foreach ($title['low'] as $key=>$row){
                                                                $temp = $peopleData[$val['date']]['low'][$key] ?? 0;
                                                                echo "<td>{$temp}</td>";
                                                            }
                                                            echo "<td>-</td>";//消耗汇总
                                                            echo "<td>-</td>";//参与人数
                                                            echo "<td>-</td>";//单日汇总
                                                            ?>
                                                        </tr>
                                                        <tr>
                                                            <td style="white-space: nowrap">参与人均</td>
                                                            <?php
                                                            foreach ($title['add'] as $key=>$row){
                                                                $temp = $peopleData[$val['date']]['add'][$key] ?? 0;
//                                                                echo "<td>". (empty($temp) ? "-" : number_format($val['add'][$key] / $temp,2,".","")) ."</td>";
                                                                echo "<td>". (empty($temp) ? "-" : formatChipRound($val['add'][$key] / $temp)) ."</td>";
                                                            }
                                                            echo "<td>-</td>";//发放汇总
                                                            echo "<td>-</td>";//参与人数
                                                            foreach ($title['low'] as $key=>$row){
                                                                $temp = $peopleData[$val['date']]['low'][$key] ?? 0;
//                                                                echo "<td>". (empty($temp) ? "-" : number_format($val['low'][$key] / $temp,2,".","")) ."</td>";
                                                                echo "<td>". (empty($temp) ? "-" : formatChipRound($val['low'][$key] / $temp)) ."</td>";
                                                            }
                                                            echo "<td>-</td>";//消耗汇总
                                                            echo "<td>-</td>";//参与人数
                                                            echo "<td>-</td>";//单日汇总
                                                            ?>
                                                        </tr>
                                                    <?php } } else{?>
                                                    <tr>
                                                        <td colspan="10">暂无数据</td>
                                                    </tr>
                                                <?php } ?>
                                                </tbody>

                                            </table>
                                        </div>

<!--                                        <nav>-->
<!--                                            <ul class="pagination">-->
<!--                                                <li class="disabled"><a href="#">共<span class="pagetotal">--><?php //echo $totalNum;?><!--</span>条</a></li>-->
<!--                                                --><?php //echo $pageurl;?>
<!--                                            </ul>-->
<!--                                        </nav>-->
                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-8">
                    <aside>
                        <header><i class="fa fa-fw fa-file"></i>发放</header>
                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                                </div>
                                <button type="button" class="btn btn-primary" id="all_checked1">全选</button>
                            	<button type="button" class="btn btn-primary" id="all_no_checked1">全不选</button>
                            </div>
                        </section>
                    </aside>
                </div>
                <div class="col-sm-4">
                    <aside>
                        <header><i class="fa fa-fw fa-file"></i>消耗</header>
                        <section>
                            <div class="container-fluid">
                                <div class="row">
                                    <div id="container2" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                                </div>
                                <button type="button" class="btn btn-primary" id="all_checked2">全选</button>
                            	<button type="button" class="btn btn-primary" id="all_no_checked2">全不选</button>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>

    </div>
</div>
</div>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/exporting.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/export-data.js"></script>
<script type="text/javascript">

//设置图表导出格式选项
Highcharts.setOptions({
    lang: {
        printChart: '打印图表',
        downloadJPEG: '下载 JPEG 文件',
        downloadPDF: '下载 PDF   文件',
        downloadPNG: '下载 PNG  文件',
        downloadSVG: '下载 SVG  文件',
        downloadCSV: '下载 CSV  文件',
        downloadXLS: '下载 XLS   文件',
        viewData: '查看数据表格'
    },
    navigation: {
        menuItemStyle: {
            padding: '6px 14px'
        }
    },
    exporting: {
        url: ''
    },
    credits: {
        text: '',
        url: ''
    }
});

    var chart1 = Highcharts.chart('container', {
        chart: {
            type: 'line'
        },
        title: {
            text: '发放'
        },
        subtitle: {
            text: ''
        },
        xAxis: {
            categories: [<?php echo "'".implode("','", array_column($data,'date'))."'";?>]
        },
        yAxis: {
            title: {
                text: '数值'
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        series: [<?php
            foreach ($title['add'] as $key=>$row){
                echo "{name: '{$row}',data: [".implode(",", array_column(array_column($data,'add'),$key))."]},";
            }
            ?>]
    });
    var chart2 = Highcharts.chart('container2', {
        chart: {
            type: 'line'
        },
        title: {
            text: '消耗'
        },
        subtitle: {
            text: ''
        },
        xAxis: {
            categories: [<?php echo "'".implode("','", array_column($data,'date'))."'";?>]
        },
        yAxis: {
            title: {
                text: '数值'
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        series: [<?php
            foreach ($title['low'] as $key=>$row){
                echo "{name: '{$row}',data: [".implode(",", array_column(array_column($data,'low'),$key))."]},";
            }
            ?>]
    });
    
    $(document).on("click","#all_checked1",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart1.series[index].show();//显示
    	})
    })
    $(document).on("click","#all_no_checked1",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart1.series[index].hide();//隐藏
    	})
    })
    $(document).on("click","#all_checked2",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart2.series[index].show();//显示
    	})
    })
    $(document).on("click","#all_no_checked2",function(){
    	$(".highcharts-legend-item").each(function(index){
    		chart2.series[index].hide();//隐藏
    	})
    })
    
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });


    //选择日期
    $('.datetimepicker2').datepicker({
        language:'zh-CN',
        format: 'yyyy-mm-dd hh:ii:ss',
        zIndexOffset:906  //控制z-index
    });
</script>
