<?php 
$this->title = '交易量报表';
?>

<?php $this->beginBlock('header_script'); ?>
    <link href="<?= STATIC_URL ?>/ui/css/plugins/dataTables/datatables.min.css" rel="stylesheet">
<?php $this->endBlock(); ?>

<div class="row">
    <div class="col-md-3">
        <?= $this->render('/common/_left_menu.php') ?>
    </div>
    <div class="col-md-9">

        <div class="ibox">
            <div class="ibox-title">
                <h2 class="pull-left">交易量报表<small>(截止昨日凌晨24:00)</small></h2>

                <div class="btn-group pull-right">
                    <a href="/ib/volume/export?ibId=<?= $ibId ?>&sTime=<?= $sTime ?>&eTime=<?= $eTime ?>" class="btn btn-primary" target="_blank">导出全部</a>
                </div>
                <div class="clearfix"></div>
            </div>

            <form>
                <div class="ibox-content m-b-sm border-bottom">
                    <div class="row">
                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="control-label" for="price">上级代理商</label>
                                <select name="ibId" class="form-control select22">
                                    <option value="">请选择</option>
                                    <?php foreach ($ibs as $k => $v) : ?>
                                        <option value="<?= $v['id'] ?>" <?= $ibId == $v['id'] ? 'selected="selected"' : '' ?> ><?= $v['name'] ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="control-label" for="price">开始时间</label>
                                <input readonly="readonly" type="text" id="sTime" name="sTime" value="<?= $sTime ?>" placeholder="开始时间" class="data form-control">
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="control-label" for="quantity">结束时间</label>
                                <input readonly="readonly" type="text" id="eTime" name="eTime" value="<?= $eTime ?>" placeholder="结束时间" class="data form-control">
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="form-group">
                                <label class="control-label" for="quantity">操作</label>
                                <input type="submit" class="btn btn-primary form-control" value="搜索直属客户">
                            </div>
                        </div>
                    </div>
                </div>
            </form>


            <div class="ibox-content">

                <div class="table-responsive">
                    <table id="datatables" class="table table-striped table-bordered table-hover dataTables-example">
                        <thead>
                        <tr>
                            <th>代理商</th>
                            <th>账户</th>
                            <th>姓名</th>
                            <th>外汇</th>
                            <th>佣金</th>
                            <th>黄金</th>
                            <th>佣金</th>
                            <th>白银</th>
                            <th>佣金</th>
                            <th>CFD</th>
                            <th>佣金</th>
                            <th>股指</th>
                            <th>佣金</th>
                            <th>BTC</th>
                            <th>佣金</th>
                            <th>总外佣</th>
                            <th>总佣金</th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr id="calHtml">
                            <td colspan="3">合计：</td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                            <td><img src="<?= STATIC_URL ?>/ui/img/loading.gif"></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>


            </div>
        </div>

    </div>
</div>

<?php $this->beginBlock('footer_script'); ?>
<!-- Mainly scripts -->
<script src="<?= STATIC_URL ?>/ui/js/plugins/dataTables/datatables.min.js"></script>
<script>

var table;
$(document).ready(function() {
    cal();

    table = $('#datatables').DataTable({
        <?php if ($isHaveAdmin) : ?>
        "aLengthMenu": [[20,50,100,500,999999999], [20,50,100,500,"ALL"]],
        <?php else : ?>
        "aLengthMenu": [[20,50,100], [20,50,100]],
        <?php endif; ?>
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索账户,客户姓名:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
        "bProcessing": true,
        "serverSide": true,
        "ajax": '/ib/volume/list?ibId=<?= $ibId ?>&sTime=<?= $sTime ?>&eTime=<?= $eTime ?>',
        "order": [[1, "desc"]],
        "columns": [{
            "data": "name"
        },{
            "data": "LOGIN"
        },{
            "data": "NAME"
        },{
            "data": "fv"
        },{
            "data": "fvc"
        },{
            "data": "mvGold"
        },{
            "data": "gvc"
        },{
            "data": "mvSilver"
        },{
            "data": "svc"
        },{
            "data": "cv"
        },{
            "data": "cvc"
        },{
            "data": "stv"
        },{
            "data": "stvc"
        },{
            "data": "btv"
        },{
            "data": "btvc"
        },{
            "data": "wvc"
        },{
            "data": "tvc"
        }],
        columnDefs: [{
            targets: 3,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 4,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 5,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 6,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 7,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 8,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 9,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 10,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 11,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 12,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 13,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 14,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 15,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        },{
            targets: 16,
            render: function(data, type, row, meta) {
                return doData(data);
            },
            "orderable": false
        }],
        "sPaginationType": "full_numbers",
        dom: '<"html5buttons"B>lTfgitp',
        buttons: [{
            extend: 'copy'
        },
            {
                extend: 'csv'
            },
            {
                extend: 'excel'
            },
            {
                extend: 'pdf'
            },
            {
                extend: 'print',
                customize: function(win) {
                    $(win.document.body).addClass('white-bg');
                    $(win.document.body).css('font-size', '10px');
                    $(win.document.body).find('table').addClass('compact').css('font-size', 'inherit');
                }
            }]

    });

    $('#datatables tbody').on('click', 'tr', function() {
        if ($(this).hasClass('selected')) {
            $(this).removeClass('selected');
        } else {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
        var data=table.row('.selected').data();
        if(data != undefined && data.LOGIN != ""){
            var url="/ib/statistics?login="+data.LOGIN+"&ibId="+data.member_id;
            window.location.href=url;
        }
    });

});

function cal(){
    $.ajax({
        type: "GET",
        url: "/ib/volume/cal?ibId=<?= $ibId ?>&sTime=<?= $sTime ?>&eTime=<?= $eTime ?>",
        dataType: "json",
        success: function(data) {
            var html = '<td colspan="3">合计：</td>';
            html += '<td>' + doData(data.fvSum) + '</td>';
            html += '<td>' + doData(data.fvcSum) + '</td>';
            html += '<td>' + doData(data.mvGoldSum) + '</td>';
            html += '<td>' + doData(data.gvcSum) + '</td>';
            html += '<td>' + doData(data.mvSilverSum) + '</td>';
            html += '<td>' + doData(data.svcSum) + '</td>';
            html += '<td>' + doData(data.cvSum) + '</td>';
            html += '<td>' + doData(data.cvcSum) + '</td>';
            html += '<td>' + doData(data.stvSum) + '</td>';
            html += '<td>' + doData(data.stvcSum) + '</td>';
            html += '<td>' + doData(data.btvSum) + '</td>';
            html += '<td>' + doData(data.btvcSum) + '</td>';
            html += '<td>' + doData(data.wvcSum) + '</td>';
            html += '<td>' + doData(data.tvcSum) + '</td>';
            
            $("#calHtml").html(html);
        }
    });
}

function doData(data) {
    data = data / 100;
    var arr = data.toString().split('.');
    if (arr[1] && arr[1].length > 4) {
        arr[1] = arr[1].slice(0, 4);
        data = arr.join('.');
    }
    return data;
}
</script>
<?php $this->endBlock(); ?>