<?php
$this->title = '名下账户统计概要';
?>

<div class="row">
    <div class="col-md-3">
        <?= $this->render('/common/_inner_left_menu.php', ['login' => $login]) ?>
    </div>
    <div class="col-md-9">

        <div class="ibox">
            <div class="ibox-title">
                <h5>所属代理</h5>
            </div>

            <div class="ibox-content">
                <table class="table table-striped">
                    <tbody>
                    <tr>
                        <th>姓名</th>
                        <td><?= $ib['name'] ?></td>
                        <th>返佣账户</th>
                        <td><?= $ib['logins'] ?></td>
                    </tr>
                    <tr>
                        <th>邮箱</th>
                        <td><?= $ib['username'] ?></td>
                        <th>手机</th>
                        <td><?= $ib['mobile'] ?></td>
                    </tr>

                    </tbody>
                </table>
            </div>
        </div>


        <div class="ibox">
            <div class="ibox-title">
                <h5>账户信息</h5>
            </div>

            <div class="ibox-content">
                <table class="table table-striped">
                    <tbody>
                    <tr>
                        <th>邮箱</th>
                        <td><?= isset($member['username']) ? $member['username'] : '' ?></td>
                        <th>手机</th>
                        <td><?= isset($member['mobile']) ? $member['mobile'] : '' ?></td>
                    </tr>
                    <tr>
                    <tr>
                        <th>账户</th>
                        <td><?= $mt4User['LOGIN'] ?></td>
                        <th>杠杆</th>
                        <td>1:<?= $mt4User['LEVERAGE'] ?></td>
                    </tr>
                    <tr>
                        <th>余额</th>
                        <td><?= $mt4User['BALANCE'] ?></td>
                        <th>保证金</th>
                        <td><?= $mt4User['MARGIN'] ?></td>
                    </tr>
                    <tr>
                        <th>可用保证金</th>
                        <td><?= $mt4User['MARGIN_FREE'] ?></td>
                        <th>保证金比例</th>
                        <td><?= $mt4User['MARGIN_LEVEL'] ?></td>
                    </tr>
                    <tr>
                        <th>净值</th>
                        <td><?= $mt4User['EQUITY'] ?></td>
                        <th>总交易次数</th>
                        <td><?= $tradeCount['totalCount'] ?></td>
                    </tr>
                    <tr>
                        <th>盈利交易</th>
                        <td><?php if ($tradeCount['totalCount'] != 0) { echo $tradeCount['winCount'] . ' (' . $tradeCount['winPercent'] . '%)'; } else { echo 0; } ?></td>
                        <th>亏损交易</th>
                        <td><?php if ($tradeCount['totalCount'] != 0) { echo $tradeCount['lossCount'] . ' (' . $tradeCount['lossPercent'] . '%)'; } else { echo 0; } ?></td>
                    </tr>

                    </tbody>
                </table>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">

                <div class="ibox-title">
                    <h5>总收益</h5>
                </div>
                <div class="ibox-content">
                    <div class="flot-chart">
                        <div class="flot-chart-content" id="sumProfitByDay"></div>
                    </div>
                </div>

            </div>
        </div>
        <hr>
        <div class="row">
            <div class="col-md-12">

                <div class="ibox-title">
                    <h5>交易手数</h5>
                </div>
                <div class="ibox-content">
                    <div class="flot-chart">
                        <div class="flot-chart-content" id="volumeSumByDay"></div>
                    </div>
                </div>

            </div>


        </div>

        <hr>
        <div class="row">
            <div class="col-md-4">

                <div class="ibox-title">
                    <h5>总笔数</h5>
                    <span class="pull-right label label-warning"><?= $tradeCount['totalCount'] ?></span>
                </div>
                <div class="ibox-content">
                    <div class="flot-chart">
                        <div class="flot-chart-pie-content" id="totalCount"></div>
                    </div>
                </div>

            </div>
            <div class="col-md-4">

                <div class="ibox-title">
                    <h5>交易货币分布</h5>
                </div>
                <div class="ibox-content">
                    <div class="flot-chart">
                        <div class="flot-chart-pie-content" id="symbolCount"></div>
                    </div>
                </div>

            </div>
            <div class="col-md-4">

                <div class="ibox-title">
                    <h5>交易来源分布</h5>
                </div>
                <div class="ibox-content">
                    <div class="flot-chart">
                        <div class="flot-chart-pie-content" id="reasonCount"></div>
                    </div>
                </div>

            </div>

        </div>


    </div>

</div>

<?php $this->beginBlock('footer_script'); ?>
<!-- Mainly scripts -->
<!-- Flot -->
<script src="<?= STATIC_URL ?>/ui/js/plugins/flot/jquery.flot.js"></script>
<script src="<?= STATIC_URL ?>/ui/js/plugins/flot/jquery.flot.tooltip.min.js"></script>
<script src="<?= STATIC_URL ?>/ui/js/plugins/flot/jquery.flot.resize.js"></script>
<script src="<?= STATIC_URL ?>/ui/js/plugins/flot/jquery.flot.pie.js"></script>
<script src="<?= STATIC_URL ?>/ui/js/plugins/flot/jquery.flot.time.js"></script>
<script>
$(document).ready(function() {

    var profitSumByDay = <?= $profitSumByDay ?>;

    $.plot($("#sumProfitByDay"), [{
        data: profitSumByDay
    }], {
        xaxes: [{
            mode: 'time',
            timeformat: "%y/%m/%d"
        }],
        colors: ["#1ab394"],
        grid: {
            color: "#999999",
            hoverable: true,
            clickable: true,
            tickColor: "#D4D4D4",
            borderWidth:0,
            hoverable: true //IMPORTANT! this is needed for tooltip to work,
        },
        tooltip: true,
        tooltipOpts: {
            content: "截止 %x 的总收益 %y ",
            xDateFormat: "%y/%m/%d",
            onHover: function(flotItem, $tooltipEl) {
                // console.log(flotItem, $tooltipEl);
            }
        }

    });

    var volumeSumByDay = <?= $volumeSumByDay ?>;

    $.plot($("#volumeSumByDay"), [{
        data: volumeSumByDay
    }], {
        xaxes: [{
            mode: 'time',
            timeformat: "%y/%m/%d"
        }],
        yaxis: {
            tickDecimals: 2
        },
        colors: ["#1ab394"],
        grid: {
            color: "#999999",
            hoverable: true,
            clickable: true,
            tickColor: "#D4D4D4",
            borderWidth:0,
            hoverable: true //IMPORTANT! this is needed for tooltip to work,
        },
        tooltip: true,
        tooltipOpts: {
            content: "截止 %x 的总交易手数 %y 手",
            xDateFormat: "%y/%m/%d",
            onHover: function(flotItem, $tooltipEl) {
                // console.log(flotItem, $tooltipEl);
            }
        }

    });


    var data1 = <?= $symbolCount ?>;
    if (!$.isEmptyObject(data1)) {
        var plotObj1 = $.plot($("#symbolCount"), data1, {
            series: {
                pie: {
                    show: true
                }
            },
            grid: {
                hoverable: true
            },
            tooltip: true,
            tooltipOpts: {
                content: "%p.0%, %s", // show percentages, rounding to 2 decimal places
                shifts: {
                    x: 20,
                    y: 0
                },
                defaultTheme: false
            }
        });
    }

    var data2 = <?= $reasonCount ?>;
    if (!$.isEmptyObject(data2)) {
        var plotObj2 = $.plot($("#reasonCount"), data2, {
            series: {
                pie: {
                    show: true
                }
            },
            grid: {
                hoverable: true
            },
            tooltip: true,
            tooltipOpts: {
                content: "%p.0%, %s", // show percentages, rounding to 2 decimal places
                shifts: {
                    x: 20,
                    y: 0
                },
                defaultTheme: false
            }
        });
    }

    var data3 = [
        {
            label: "Win",
            data: <?= $tradeCount['winCount'] ?>,
        },
        {
            label: "Loss",
            data: <?= $tradeCount['lossCount'] ?>,
        }
    ];
    var plotObj3 = $.plot($("#totalCount"), data3, {
        series: {
            pie: {
                show: true
            }
        },
        grid: {
            hoverable: true
        },
        tooltip: true,
        tooltipOpts: {
            content: "%p.0%, %s", // show percentages, rounding to 2 decimal places
            shifts: {
                x: 20,
                y: 0
            },
            defaultTheme: false
        }
    });
});
</script>
<?php $this->endBlock(); ?>



