
@{
    ViewData["Title"] = "每日收支报表";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "财务", "跨境电商现金流报告" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>统计日期</label>
                        <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"))" />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-primary" onclick="init();"><i class="fa fa-search"></i>&nbsp;查询</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <p>总支出：<span id="txtpay" style="color:forestgreen;">0</span>；总收入：<span id="txtincoming" style="color:red;">0</span>；</p>
            <table id="roletable" class="table table-hover table-bordered table-condensed table-striped">
                <thead>
                    <tr></tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <p>动态分析表格</p>
            <table id="roletable2" class="table table-hover table-bordered table-condensed table-striped">
                <thead>
                    <tr></tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
    <div class="col-sm-12">
        <div class="alert alert-warning">
            取数说明：
            <br />
            1、支出的取值：成品采购+半成品采购+百伦（广州、香港）支付给哈倪曼和拉古娜的费用+百伦的管理费+物流费<br />
            2、收入的取值：当天提现到账的资金（已转换成CNY）<br />
            3、采购下单的取值：成品采购系统当天下单的采购金额<br />
            4、财务付款的取值：当天支付给成品采购+半成品采购+百伦（广州、香港）支付给哈倪曼和拉古娜的费用+百伦的管理费+物流费<br />
            5、到货的取值：当天成品采购系统到货的总采购额<br />
            6、库存的取值：当天在库的库存金额<br />
            7、售出的取值：当天销售订单的产品成本<br />
            8、应收款的取值：当天各个平台的帐号余额<br />
            9、放款在途的取值：统计当前提现未到账的金额<br />
            10、银行卡余额的取值：当天银行卡的余额。
        </div>
    </div>
</div>

@section css{
    <link href="~/css/bootstrap-table-fixed-columns.css" rel="stylesheet" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script src="~/js/bootstrap-table-fixed-columns.js" type="text/javascript"></script>
    <script type="text/javascript">
        var tb;
        var companyid = 0;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            init();
        })

        function init() {
            list();
            list2();
        }

        function list() {
            var lindex = layer.load(1, { shade: false }); //0代表加载的风格，支持0-2
            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Finance/TotalIncomePayJson")',
                paramData: $("#toolbar").serialize(),
                func: function (result) {
                    layer.close(lindex);

                    $('#roletable').find('tbody').html('');
                    $('#roletable').find('thead').html('');
                    $('#txtpay').html('0');
                    $('#txtincoming').html('0');

                    if (result.success) {
                        if (result.list.length == 0) {
                            alert('没有找到符合条件的数据');
                            return false;
                        }

                        var w = $('#roletable').parent().width()+40;

                        if (w < (120 * result.list.length + 40)) {
                            w = (120 * result.list.length + 40);
                        }

                        $('#roletable').parent().css('width', (w) + 'px');
                        $('#roletable').css('width', (w-40) + 'px');



                        var head = '<tr><th style="width:120px;">日期</th>';
                        var row1 = '<tr><td style="width:120px;">总支出</td>';
                        var row2 = '<tr><td style="width:120px;">总收入</td>';

                        for (var i = 0; i < result.list.length; i++) {
                            var obj = result.list[i];
                            head+= '<th style="width:120px;">' + obj.record_time+'</th>';

                            row1 += '<td style="width:120px;"><span onclick="showpaydetail(\'' + obj.record_time+'\')">' + obj.amount_payed+'</span></td>';
                            row2 += '<td style="width:120px;">' + obj.amount_income+'</td>';
                        }

                        head += '</tr>';
                        row1 += '</tr>';
                        row2 += '</tr>';

                        $('#roletable').find('thead').append(head);
                        $('#roletable').find('tbody').append(row1);
                        $('#roletable').find('tbody').append(row2)

                        $('#txtpay').html(result.countpayed);
                        $('#txtincoming').html(result.countincoming);

                    }
                    else {
                        layer.msg('出现异常。');
                    }
                }
            })
        }

        function list2() {
            var lindex = layer.load(1, { shade: false }); //0代表加载的风格，支持0-2
            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Finance/ListDailyCompanyMoneyJson")',
                paramData: $("#toolbar").serialize(),
                func: function (result) {
                    layer.close(lindex);

                    $('#roletable2').find('tbody').html('');
                    $('#roletable2').find('thead').html('');
                    

                    if (result.success) {
                        if (result.list.length == 0) {
                            alert('没有找到符合条件的数据');
                            return false;
                        }

                        var w = $('#roletable2').parent().width()+40;

                        if (w < (120 * result.list.length + 40)) {
                            w = (120 * result.list.length + 40);
                        }

                        $('#roletable2').parent().css('width', (w) + 'px');
                        $('#roletable2').css('width', (w-40) + 'px');



                        var head = '<tr><th style="width:120px;">日期</th>';
                        var row1 = '<tr><td style="width:120px;">采购下单</td>';
                        var row2 = '<tr><td style="width:120px;">财务付款</td>';
                        var row3 = '<tr><td style="width:120px;">到货</td>';
                        var row4 = '<tr><td style="width:120px;">库存</td>';
                        var row5 = '<tr><td style="width:120px;">售出</td>';
                        var row6 = '<tr><td style="width:120px;">应收款</td>';
                        var row7 = '<tr><td style="width:120px;">放款在途</td>';
                        var row8 = '<tr><td style="width:120px;">银行卡余额</td>';

                        for (var i = 0; i < result.list.length; i++) {
                            var obj = result.list[i];
                            head+= '<th style="width:120px;">' + obj.record_time+'</th>';

                            row1 += '<td style="width:120px;">' + obj.amount_purchase+'</td>';
                            row2 += '<td style="width:120px;">' + obj.amount_payed + '</td>';
                            row3 += '<td style="width:120px;">' + obj.amount_arrivaled + '</td>';
                            row4 += '<td style="width:120px;">' + obj.amount_stock + '</td>';
                            row5 += '<td style="width:120px;">' + obj.amount_sale + '</td>';
                            row6 += '<td style="width:120px;">' + obj.amount_receivable + '</td>';
                            row7 += '<td style="width:120px;">' + obj.amount_withdrawonway + '</td>';
                            row8 += '<td style="width:120px;">' + obj.amount_incoming + '</td>';
                        }

                        head += '</tr>';
                        row1 += '</tr>';
                        row2 += '</tr>';
                        row3 += '</tr>';
                        row4 += '</tr>';
                        row5 += '</tr>';
                        row6 += '</tr>';
                        row7 += '</tr>';
                        row8 += '</tr>';

                        $('#roletable2').find('thead').append(head);
                        $('#roletable2').find('tbody').append(row1);
                        $('#roletable2').find('tbody').append(row2);
                        $('#roletable2').find('tbody').append(row3);
                        $('#roletable2').find('tbody').append(row4);
                        $('#roletable2').find('tbody').append(row5);
                        $('#roletable2').find('tbody').append(row6);
                        $('#roletable2').find('tbody').append(row7);
                        $('#roletable2').find('tbody').append(row8);


                        //$('#txtdetailcount').html('合计：采购下单：' + result.count.amount_purchase + '；财务付款：' + result.count.amount_payed + '；到货：' + result.count.amount_arrivaled + '；库存：' + result.count.amount_stock + '；售出：' + result.count.amount_sale + '；应收款：' + result.count.amount_receivable + '；放款在途：' + result.count.amount_withdrawonway + '；银行到账：' + result.count.amount_incoming+'；');

                    }
                    else {
                        layer.msg('出现异常。');
                    }
                }
            })
        }

        function showpaydetail(date) {
            layer_show(date + "的支出明细导出", '@Url.Content("~/Reports/Finance/TotalIncomePay_PayDetail?date=")'+date, '90%', '90%');
        }

    </script>
}


