
@{
    ViewData["Title"] = "UnReasonable";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "财务报表", "每月进销存差异汇总" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="alert alert-warning">
            说明：数据从2019-12月份开始
        </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">
                        <label>请选择开始月份</label>
                        <input id="month" name="month" class="form-control" style="width:130px;" placeholder="年-月" value="@(DateTime.Now.AddMonths(-1).ToString("yyyy-MM"))" />
                    </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">
            <label>汇总</label>
            <table id="tb0" class="table table-hover table-bordered table-condensed table-striped">
                <thead>
                    <tr>
                        <td>仓库类型</td>
                        <td>出库数量</td>
                        <td>出库金额</td>
                        <td>入库数量</td>
                        <td>入库金额</td>
                        <td>(入库-出库)数量</td>
                        <td>(入库-出库)金额</td>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <hr />
            <label>增加部分</label>
            <table id="tb1" class="table table-hover table-bordered table-condensed table-striped">
                <thead>
                    <tr>
                        <td>仓库类型</td>
                        <td>百伦简单分类</td>
                        <td>出库数量</td>
                        <td>出库金额</td>
                        <td>入库数量</td>
                        <td>入库金额</td>
                        <td>(入库-出库)数量</td>
                        <td>(入库-出库)金额</td>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <label>减少部分</label>
            <table id="tb2" class="table table-hover table-bordered table-condensed table-striped">
                <thead>
                    <tr>
                        <td>仓库类型</td>
                        <td>百伦简单分类</td>
                        <td>出库数量</td>
                        <td>出库金额</td>
                        <td>入库数量</td>
                        <td>入库金额</td>
                        <td>(入库-出库)数量</td>
                        <td>(入库-出库)金额</td>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</div>

@section scripts{
    <script src="~/css/Layer-2.1/extend/layer.ext.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            laydate.render({ elem: '#month', type: 'month' });

            init();
        })

        function init() {
            var m = $('#month').val();

            if (m == '') {
                layer.msg('请选择月份');
                return;
            }

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

                        $('#tb0').find('tbody').html('');
                        $('#tb1').find('tbody').html('');
                        $('#tb2').find('tbody').html('');

                        //汇总
                        for (var i in result.list0) {
                            var o = result.list0[i];
                            var s = '<tr><td><a href="javascript:;" onclick="showdetail(\'' + o.warehouse_type+'汇总明细\',\'' + m + '\',\'' + o.warehouse_type + '\');">' + o.warehouse_type + '</a></td>';
                            s += '<td>' + o.count_outbound+'</td>';
                            s += '<td>' + o.amount_outbound+'</td>';
                            s += '<td>' + o.count_putin+'</td>';
                            s += '<td>' + o.amount_putin+'</td>';
                            s += '<td>' + o.count_diff+'</td>';
                            s += '<td>' + o.amount_diff+'</td>';
                            s += '</tr>';

                            $('#tb0').find('tbody').append(s);
                        }

                        //增加
                        for (var i in result.list1) {
                            var o = result.list1[i];
                            var s = '<tr><td><a href="javascript:;" onclick="showdetail(\'' + o.warehouse_type + '增加部分的明细\',\'' + m + '\',\'' + o.warehouse_type + '\',1,\'' + o.category_simple_name+'\');">' + o.warehouse_type + '</a></td>';
                            s += '<td>' + o.category_simple_name+'</td>';
                            s += '<td>' + o.count_outbound + '</td>';
                            s += '<td>' + o.amount_outbound + '</td>';
                            s += '<td>' + o.count_putin + '</td>';
                            s += '<td>' + o.amount_putin + '</td>';
                            s += '<td>' + o.count_diff + '</td>';
                            s += '<td>' + o.amount_diff + '</td>';
                            s += '</tr>';

                            $('#tb1').find('tbody').append(s);
                        }

                        //减少
                        for (var i in result.list2) {
                            var o = result.list2[i];
                            var s = '<tr><td><a href="javascript:;" onclick="showdetail(\'' + o.warehouse_type + '减少部分的明细\',\'' + m + '\',\'' + o.warehouse_type + '\',2,\'' + o.category_simple_name +'\');">' + o.warehouse_type + '</a></td>';
                            s += '<td>' + o.category_simple_name + '</td>';
                            s += '<td>' + o.count_outbound + '</td>';
                            s += '<td>' + o.amount_outbound + '</td>';
                            s += '<td>' + o.count_putin + '</td>';
                            s += '<td>' + o.amount_putin + '</td>';
                            s += '<td>' + o.count_diff + '</td>';
                            s += '<td>' + o.amount_diff + '</td>';
                            s += '</tr>';

                            $('#tb2').find('tbody').append(s);
                        }

                    }
                    else {
                        layer.msg(result.msg);
                    }
                }
            })
        }

        function showdetail(title, month, warehousetype, type,category) {

            if (warehousetype == '总计') {
                return false;
            }

            if (category == undefined) {
                category = '';
            }

            layer_show((category == '' ? "" : category+"+") + title, '@Url.Content("~/Reports/Finance/ListUnReasonable?month=")' + month + '&warehousetype=' + warehousetype + ((type == null || type == undefined) ? "" : '&type=' + type) + '&category=' + category, '95%', '95%');
        }
        
    </script>
}

