
@{
    ViewData["Title"] = "平台应收账款";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
}

@*<div class="ibox-content m-b-sm border-bottom">
        <table id="tb" class="table table-hover table-bordered" style="width:100%;">
            <thead>
                <tr>
                    <th>付款主体</th>
                    <th>仓库名称</th>
                    <th>存货余额</th>
                    <th>日期</th>
                </tr>
            </thead>

            @if (ViewBag.list.Count > 0)
            {
                foreach (var item in ViewBag.list)
                {
                    <tr>
                        <td>@ViewBag.PayCompanyName</td>
                        <td>@item.warehouse_name</td>
                        <td>@item.balance_rmb.ToString("###,###.##")</td>
                        <td>@item.statistical_time.ToString("yyyy-MM-dd")</td>
                    </tr>
                }
            }
        </table>
    </div>*@

<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">
                        <button type="button" class="btn btn-primary" onclick="exportFile();">导出</button>
                    </div>
                </div>
            </form>
        </div>*@
        <div class="ibox-content m-b-sm border-bottom">
            <table id="roletable" style="table-layout:fixed;"></table>
        </div>
    </div>
</div>

@section scripts{
    <script>
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 100));

            list();
        })

        function list() {
            var columns = [
                { field: 'platform', title: '平台类型', width: '140', sortable: false, iscount: true},
                { field: 'amount_end', title: '期末金额', width: '110', sortable: true, iscount: true },
                { field: 'day', title: '日期', width: '110', sortable: false }
            ];

            var url = '@Url.Content("~/Reports/Finance/ListReceivablesPlatformJson")' + '?date=@(ViewBag.date)&paycompanyid=@(ViewBag.paycompanyid)';

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    showfooter: true, loadsuccess: function (d) {
                        //替换汇总行的相关列值
                        var tr = $('.fixed-table-footer').find('tr');
                        for (var c in columns) {
                            var key = columns[c].field;
                            if (columns[c].iscount) {
                                for (var v in d.count_row) {
                                    if (key == v) {
                                        tr.find('td').eq(c).children('div').first().html(d.count_row[v]);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }
        
        function exportFile() {
            window.open('@Url.Content("~/Reports/Finance/InventoryBalanceExport?date=")' + '@(ViewBag.date)&paycompanyid=@(ViewBag.paycompanyid)&t=@(ViewBag.t)', "_blank");
        }
    </script>

}