<?php
$this->title = '持仓报表';
?>

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

<style>
    table.table-bordered.dataTable th, table.table-bordered.dataTable td {
        white-space: nowrap;
    }
    @media (min-width: 1600px){
        .container {
            width: 1550px;
        }
    }
    @media (min-width: 1920px){
        .container {
            width: 1550px;
        }
    }

</style>

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

        <div class="ibox">
            <div class="ibox-title">
                <h2>持仓报表</h2>
            </div>
            <form>
                <input type="hidden" name="type" value="<?= $type ?>">
                <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-2">
                            <div class="form-group">
                                <label class="control-label" for="price">客户姓名</label>
                                <input type="text" id="name" name="name" value="<?= $name ?>" placeholder="客户姓名" class="form-control">
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <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-2">
                            <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>SL</th>
                            <th>TP</th>
                            <th>手数</th>
                            <th>开仓价格</th>
                            <th>开仓时间</th>
                            <th>利息</th>
                            <th>佣金</th>
                            <th>获利</th>
                            <th>更新时间</th>
                        </tr>
                        </thead>
                    </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() {
    table = $('#datatables').DataTable({
        <?php if ($isHaveAdmin) : ?>
        "aLengthMenu": [[20,50,100,500,999999999], [20,50,100,500,"ALL"]],
        <?php else : ?>
        "aLengthMenu": [[20,50,100,500], [20,50,100,500]],
        <?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": ": 以降序排列此列"
            }
        },
        "processing": true,
            "serverSide": true,
            "ajax": '/ib/trades?type=<?= $type ?>&sTime=<?= $sTime ?>&eTime=<?= $eTime ?>&name=<?= $name ?>&ibId=<?= $ibId ?>',
            "order": [[0, "desc"]],
            "columns": [{
                "data": "TICKET"
            },{
                "data": "LOGIN"
            },{
                "data": "NAME"
            },
            {
                "data": "CMD"
            },
            {
                "data": "SYMBOL"
            },
            {
                "data": "SL"
            },
            {
                "data": "TP"
            },
            {
                "data": "VOLUME"
            },
            {
                "data": "OPEN_PRICE"
            },
            {
                "data": "OPEN_TIME"
            },
            {
                "data": "SWAPS"
            },
            {
                "data": "COMMISSION"
            },
            {
                "data": "PROFIT"
            },
            {
                "data": "MODIFY_TIME"
            }],
            columnDefs: [{
            targets: 2,
            "orderable": false
        },{
            targets: 3,
            render: function(data, type, row, meta) {
                if(data==0){
                    return 'BUY';
                }else if (data==1){
                    return 'SELL';
                }else if (data==2){
                    return 'BUY LIMIT';
                }else if (data==3){
                    return 'SELL LIMIT';
                }else if (data==4){
                    return 'BUY STOP';
                }else if (data==5){
                    return 'SELL STOP';
                }else if (data==6){
                    return 'BALANCE';
                }else if (data==7){
                    return 'CREDIT';
                }else{
                    return '';
                }
            },
            "orderable": true
        },{
            targets: 7,
            render: function(data, type, row, meta) {
                if(data!=""){
                    return data/100;
                }else{
                    return "";
                }
            },
            "orderable": true
        }],
            "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');
        }
    });

});
</script>
<?php $this->endBlock(); ?>

