
@{
    ViewData["Title"] = "资产负债表";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "报表管理", "资产负债表" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="alert alert-warning">
            说明：按周显示时，默认显示周二的数据，按月显示时，默认显示每月月末的数据
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        @*<input id="chk_showdetail" type="checkbox" checked="checked" /><label for="chk_showdetail">是否可看明细</label>*@
                        @*<select id="timetype" class="form-control" style="width:120px;">
                            <option value="2">按周的方式</option>
                            <option value="3">按月的方式</option>
                        </select>*@
                        <input id="start" name="start" value="@(DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"))" class="form-control" placeholder="开始日期" />-
                        <input id="end" name="end" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" class="form-control" placeholder="结束日期" />
                        @*<label>付款主体</label>
                        <select id="sel_paycompany" class="form-control" style="width:200px;">
                            <option value="0">百伦供应链</option>
                        </select>*@
                        <button type="button" class="btn btn-sm btn-primary" onclick="GetData();"><i class="fa fa-search"></i>&nbsp;查询</button>
                        @*<button id="btnexport" style="display:none;" type="button" class="btn btn-sm btn-success" onclick="ExportXsl();">导出</button>*@
                    </div>
                </div>
            </form>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <h2 style="text-align:center;">资产负债表</h2>
            <div class="bootstrap-table">
                <div class="fixed-table-container">
                    <div class="fixed-table-body">
                        <table id="tb" style="table-layout: fixed;" class="table table-border table-bordered table-hover table-bg table-sort form-inline">
                            <thead>

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

@section css{
    <style>
        
    </style>
}

@section scripts{
    <script src="~/css/Layer-2.1/extend/layer.ext.js"></script>
    <script type="text/javascript">
        var tb;
        var _data=[];

        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            GetData();
        })


        function GetData() {
            var start = $('#start').val();
            var end = $('#end').val();
            if ($('#start').val() == '' || $('#end').val() == '') {
                alert('日期不能为空');
                return;
            }


            $.submit({
                url: '@Url.Content("~/Reports/Finance/BalanceSheetNewJson")',
                type: "POST",
                paramData: 'type=3&paycompanyvalue=0&start='+start+'&end='+end,
                func: function (result) {
                    if (result.success) {
                        $('#tb').find('thead').html('');
                        $('#tb').find('tbody').html('');
                        if (result.data.length > 0) {
                            var s = '';

                            var m = '<tr><th style="height:40px;text-align: center;line-height: 40px;width:160px;" rowspan="2">项目</th>';
                            var m2 = '<tr>';
                            for (var i in result.data) {
                                var d = result.data[i]['statistical_time'].split('T')[0];

                                m += ('<th style="height:40px;text-align: center;line-height: 40px;" colspan="3">' + d + '</th>');

                                m2 += '<td>基础数据</td><td>调整数据</td><td>合计数据</td>';

                            }
                            m2 += '</tr>';
                            m += '</tr>';



                            $('#tb').find('thead').html(m + m2);

                            //组装行
                            var rows = '';

                            for (var i in result.head) {
                                var col = result.head[i];
                                var row = col.item3 == 0 ? '<tr><td style="width:160px;">' + col.item1 + '</td>' : '<tr><td style="font-weight:bold;width:160px;">' + col.item1 + '</td>';


                                for (var d in result.data) {

                                    if (col.item2 == "") {
                                        row += "<td></td><td></td><td></td>";
                                        continue;
                                    }

                                    var objData = result.data[d];

                                    for (var a in objData) {
                                        if (a == col.item2) {
                                            row += '<td>' + objData[a] + '</td>';
                                            continue;
                                        }
                                    }

                                    //查看是否有编辑对象
                                    var objEdit = undefined;
                                    for (var e in result.listEdit) {
                                        if (objData.statistical_time == result.listEdit[e].statistical_time) {
                                            objEdit = result.listEdit[e];
                                            continue;
                                        }
                                    }

                                    if (objEdit != undefined) {
                                        for (var a in objEdit) {
                                            if (a == col.item2) {
                                                row += '<td>' + objEdit[a] + (col.item3 == 1 ? "" : ('<a href="javascript:;" onclick="EditData(\'' + col.item1 + '\',\'' + col.item2 + '\',' + objEdit[a] + ',\'' + objData.statistical_time + '\')">编辑</a>')) + '</td>';
                                                continue;
                                            }
                                        }
                                    }
                                    else {
                                        row += '<td>0' + (col.item3 == 1 ? "" : '<a href="javascript:;" onclick="EditData(\'' + col.item1 + '\',\'' + col.item2 + '\',0,\'' + objData.statistical_time + '\')">编辑</a>') + '</td>';
                                    }


                                    //合计
                                    var objCount = undefined;
                                    for (var e in result.listCount) {
                                        if (objData.statistical_time == result.listCount[e].statistical_time) {
                                            objCount = result.listCount[e];
                                            continue;
                                        }
                                    }
                                    if (objCount != undefined) {
                                        for (var a in objCount) {
                                            if (a == col.item2) {
                                                //合计
                                                row += '<td>' + objCount[a] + '</td>';
                                            }
                                        }
                                    }
                                    else {
                                        //合计
                                        row += '<td>0</td>';
                                    }


                                }

                                row += '</tr>';
                                rows += row;
                            }

                            $('#tb').find('tbody').append(rows);


                        }
                        else {
                            layer.msg('没有数据。');
                        }
                    }
                    else {
                        layer.msg(result.msg);
                    }

                    return false;
                }
            })
        }


        function EditData(name, col, v, mon) {
            layer.prompt({ title: '编辑' + name, value:v}, function (text, index) {
                layer.close(index);
                Save(col, text, mon);
            });
        }

        function Save(col, val, mon) {

            var obj = {
                "statistical_time": mon.split('T')[0]
            };

            obj[col] = val;

            $.submit({
                url: 'http://api.dcjava.bailuntec.com/balanceSheetModify/record',
                paramData: '{"statistical_time":"' + mon.split('T')[0] + '","' + col + '":' + val +',"company_value":0,"company_name":"百伦供应链"}',
                contenttype:'application/json',
                type:'POST',
                func: function (result) {
                    if (result.success) {
                        layer.msg('提交成功');
                        setTimeout(function () {
                            GetData();
                        }, 1.5 * 1000);
                    }
                    else {
                        layer.msg(result.msg);
                    }
                }
            })
        }

    </script>
}



