<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">
        <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">
                                    <a style="margin:5px;" class="btn btn-primary <?php if($isChart != 1){echo 'active';}?>" href="#statistics/moneyinout/2" role="button">表格</a>
                                    <a style="margin:5px;" class="btn btn-primary <?php if($isChart == 1){echo 'active';}?>" href="#statistics/moneyinout/1" role="button">图表</a>
                                </div>
                            </div>
                        </div>
                    </section>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#statistics/moneyinout/<?php echo $isChart?>" 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>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>

        </div>
            <?php if($isChart != 1) { ?>
            <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 colspan="7" style="text-align: center;vertical-align: middle;">消耗</th>
                                    <th colspan="5" 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>
                                </tr>

                                <tr>
                                    <th>台费</th>
                                    <th>赠送荷官筹码</th>
                                    <th>老虎机扣钱</th>
                                    <th>互动消耗</th>
                                    <th>百人场总盈亏</th>
                                    <th>机器人总盈亏</th>
                                    
                                    <th>消耗汇总</th>
                                    <th>免费发放</th>
                                    <th>商城购物</th>
                                    <th>购买VIP加钱</th>
                                   <!--  <th>后台加减钱</th>
                                    <th>机器人加减钱</th> -->
                                    <th>活动发放</th>
                                    <th>发放汇总</th>

                                </tr>
                                </thead>
                                <tbody id="reportBody">


                                <?php

                                function formatChipRound($value, $round=2)
                                {
                                    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;
                                    }
                                }

                                rsort($dayList);
                                $totalNum = 0;
                                foreach ($dayList as $day){//循环日期
                                    $totalNum++;
                                    $act_20 = $list[20][$day] ?? 0;
                                    $act_903 = $list[903][$day] ?? 0;
                                    $act_1009 = $list[1009][$day] ?? 0;
                                    $act_1015 = $list[1015][$day] ?? 0;
                                    $act_1113 = $list[1113][$day] ?? 0;
                                    $act_5003 = $list[5003][$day] ?? 0;//夺金岛下注
                                    $act_5001 = $list[5001][$day] ?? 0;//夺金岛获奖
                                    $act_1099 = $list[1099][$day] ?? 0;//后台加减钱
                                    $act_1025 = $list[1025][$day] ?? 0;//机器人加钱

                                    //百人场的盈亏
                                    $redblack = $redBlackList[$day] ?? [];
                                    $betTotal = $winTotal = 0;
                                    if(!empty($redblack)) {
                                        $betTotal = $redblack['betTotal'] ?? 0;
                                        $winTotal = $redblack['winTotal'] ?? 0;
                                    }
                                    $redblackWincoins = $betTotal - $winTotal;

                                    //机器人盈亏
                                    $dayTmp = date('Ymd', strtotime($day));
                                    $robotWincoins = $robotList['list'][$dayTmp] ?? 0;

                                    //夺金岛盈亏
                                    $jackpotWincoins = 0;

                                    //活动汇总
                                    $activityFlowTotal = 0;
                                    $activityFlowTypeName = '';
                                    foreach ($activityFlowList as $actID3){
                                        $activityFlowTotal += $list[$actID3][$day] ?? 0;
                                        $activityFlowTypeName .= ($typeNameList[$actID3] ?? $actID3).',';
                                    }

                                    $expendToOther = 0;
                                    $expendToOtherTypeName  = '';
                                    foreach ($expendToOtherList as $actID1){
                                        $expendToOther += $list[$actID1][$day] ?? 0;
                                        $expendToOtherTypeName .= ($typeNameList[$actID1] ?? $actID1).',';
                                     }
                                    $totalExpend = $act_20 + $act_903   + $expendToOther + $redblackWincoins + $robotWincoins + $jackpotWincoins;
                                    $expendToOtherTypeName = rtrim($expendToOtherTypeName, ',');

                                    $freeFlowTotal = 0;
                                    $freeFlowTypeName = '';
                                    foreach ($freeFlowList as $actID2){
                                        $freeFlowTotal += $list[$actID2][$day] ?? 0;
                                        $freeFlowTypeName .= ($typeNameList[$actID2] ?? $actID2).',';
                                    }
                                    $outFlowTotal = $freeFlowTotal + $act_1015 + $act_1113 +   $activityFlowTotal;


                                    ?>
                                    <tr>
                                        <td style="white-space: nowrap"><?php echo $day;?></td>
                                      <td><?php echo formatChipRound($act_20);?></td>
                                      <td><?php echo formatChipRound($act_903);?></td>
                                      <td><?php echo formatChipRound($act_1009);?></td>
                                      <td><?php echo formatChipRound($expendToOther);?></td>
                                    <td><?php echo formatChipRound($redblackWincoins);?></td>
                                    <td><?php echo formatChipRound($robotWincoins);?></td>
                                     
                                      <td style="font-weight: bold"><?php echo formatChipRound($totalExpend);?></td>
                                      <td><?php echo formatChipRound($freeFlowTotal);?></td>
                                      <td><?php echo formatChipRound($act_1015);?></td>
                                      <td><?php echo formatChipRound($act_1113);?></td>
                                        
                                        <td><?php echo formatChipRound($activityFlowTotal);?></td>
                                      <td style="font-weight: bold"><?php echo formatChipRound($outFlowTotal);?></td>
<!--                                      <td style="font-weight: bold">--><?php //echo formatChipRound($otherFlowTotal);?><!--</td>-->
                                      <td style="font-weight: bold"><?php echo formatChipRound($totalExpend-$outFlowTotal);?></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-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="form-group">
                                            <label style="font-weight: bold">消耗：(台费， 赠送荷官筹码， 老虎机扣钱， 互动消耗，百人场盈亏，机器人盈亏)</label>
                                            <br/>
                                            <label style="font-weight: normal">互动消耗包含内容：<?php echo '【'.$expendToOtherTypeName.'】';?></label>
                                            <br/>
                                            <label style="font-weight: normal">夺金岛总盈亏：【夺金岛下注-夺金岛获奖】</label>
                                            <br/>
                                            <label style="font-weight: bold">发放：(免费发放， 商城购物， 购买VIP加钱，活动发放)</label>
                                            <br/>
                                          <!--   <label style="font-weight: normal">免费发放包含内容：<?php echo '【'.$freeFlowTypeName.'】';?></label>
                                            <br/> -->
                                            <label style="font-weight: normal">活动发放：<?php echo '【'.$activityFlowTypeName.'】';?></label>
                                            <br/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
            </div>
           <?php  }else{ ?>
                <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 id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></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 id="container-col" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                                    </div>
                                </div>
                            </section>
                        </aside>
                    </div>
                </div>

                <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="form-group">
                                            <label style="font-weight: normal">消耗：<?php echo '('.$inFlowStr.')';?></label>
                                            <label style="font-weight: normal">发放：<?php echo '('.$outFlowStr.')';?></label>
                                            <label style="font-weight: normal">其他：<?php echo '('.$otherFlowStr.')';?></label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </aside>
                </div>
           <?php }?>




    </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">


$('#container').highcharts({
    chart: {
        zoomType: 'xy'
    },
    title: {
        text:  '金币流水曲线图'
    },
    subtitle: {
        text: '左坐标轴筹码，右坐标轴百分比'
    },
    xAxis: [{
        categories:  [<?php echo "'".implode("','", $dayList)."'";?>],
        crosshair: true
    }],
    yAxis: [{ // Primary yAxis
        labels: {
//            format: '{value / 1000}  K',
            formatter: function (){
                var value = this.value,
                    valueB,valueM, valueK;
                if(1 < Math.abs(valueB =value / 1000000000)) {
                    return valueB + 'B';
                }else if(1 < Math.abs(valueM=value / 1000000)) {
                    return valueM + 'M';
                }else if(1 < Math.abs(valueK = value / 1000)) {
                    return valueK + 'K';
                }else {
                    return value;
                }

            },

            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        title: {
            text: '筹码',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        }
    }, { // Secondary yAxis
        title: {
            text: '百分比',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        labels: {
            format: '{value} %',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        opposite: true
    }],
    tooltip: {
        shared: true
    },

    series: [
        {
            name: '汇总消耗',
            data: [<?php echo implode(",", $inFlowMoney);?>]
        },{
            name: '汇总发放',
            data: [<?php echo implode(",", $outFlowMoney);?>]
        },{
            name: '汇总净发放',
            data: [<?php echo implode(",", $differ);?>]
        },{
            name: '汇总发放率(汇总净发放/汇总发放)',
            yAxis: 1,
            data: [<?php echo implode(",", $outFlowPercent);?>],
            tooltip: {
                valueSuffix: '%'
            }
        },{
            name: '消耗率(消耗/发放)',
            yAxis: 1,
            data: [<?php echo implode(",", $consumptionRate);?>],
            tooltip: {
                valueSuffix: '%'
            }
        },{
            visible:false,
            name: '人均消耗',
            data: [<?php echo implode(",", $avgInFlowMoney);?>]
        },{
            visible:false,
            name: '人均发放',
            data: [<?php echo implode(",", $avgOutFlowMoney);?>]
        },{
            name: '人均免费发放',
            data: [<?php echo implode(",", $usergetmoneyforfree);?>]
        }
        <?php echo $seriesStr ?? '';?>
    ]
});



var chart = Highcharts.chart('container-col', {
    title: {
        text: '金币流水柱状图  --注意：柱状图每组的显示顺序分别是（1.消耗汇总 2.发放汇总 3.输牌 4.赢牌 5.消耗明细 6.发放明细 7.其他）'
    },
    xAxis: {
        categories: [<?php echo "'".implode("','", $dayList)."'";?>]
    },
    plotOptions: {
        series: {
            stacking: 'normal'
        }
    },
    yAxis: [{ // Primary yAxis
        labels: {
//            format: '{value / 1000}  K',
            formatter: function (){
                var value = this.value,
                    valueB,valueM, valueK;
                if(1 < Math.abs(valueB =value / 1000000000)) {
                    return valueB + 'B';
                }else if(1 < Math.abs(valueM=value / 1000000)) {
                    return valueM + 'M';
                }else if(1 < Math.abs(valueK = value / 1000)) {
                    return valueK + 'K';
                }else {
                    return value;
                }

            },

            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        title: {
            text: '筹码',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        }
    }, { // Secondary yAxis
        title: {
            text: '百分比',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        labels: {
            format: '{value} %',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        opposite: true
    }],
    tooltip: {
        shared: true
    },

    series: [{
        type: 'column',
        name: '消耗汇总',
        visible:false,
        data: [<?php echo implode(",", $inFlowMoney);?>],
        stack: 'inFlowSummary'
    }, {
        type: 'column',
        name: '发放汇总',
        visible:false,
        data: [<?php echo implode(",", $outFlowMoney);?>],
        stack: 'outFlowSummary'
    }
        <?php echo $seriesStrColumn;?>
        , {
            type: 'line',
            name: '消耗率(消耗/发放)',
            yAxis: 1,
            data: [<?php echo implode(",", $outFlowPercent);?>],
            tooltip: {
                valueSuffix: '%'
            }
        }]
});



</script>
<script type="text/javascript">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });
</script>