
@{
    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>
                        <select id="warehousetype" name="warehousetype" class="form-control">
                            <option value="">选择仓库类型</option>
                            <option value="国内仓">国内仓</option>
                            <option value="海外仓">海外仓</option>
                            <option value="FBA仓">FBA仓</option>
                            <option value="第三方仓库">第三方仓库</option>
                            <option value="耗材仓">耗材仓</option>
                        </select>
                    </div>
                    @*<div class="form-group">
            <label>仓库：</label>
            <select id="warehouse" name="warehouse" class="form-control">
                <option value="">请选择仓库</option>
            </select>
        </div>*@
                    <div class="form-group">
                        <label>请选择开始月份</label>
                        <input id="month" name="month" class="form-control" style="width:130px;" placeholder="年-月" value="@(ViewBag.month)" />
                    </div>
                    <div class="form-group">
                        <label>差异类型</label>
                        <select id="type" name="type" class="form-control">
                            <option value="">选择差异类型</option>
                            <option value="1">增加部分</option>
                            <option value="2">减少部分</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>是否合理</label>
                        <select id="isreasonable" name="isreasonable" class="form-control">
                            <option value="">请选择</option>
                            <option value="0">不合理</option>
                            <option value="1">合理</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>是否新品</label>
                        <select id="isnew" name="isnew" class="form-control">
                            <option value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>是否清货</label>
                        <select id="isclear" name="isclear" class="form-control">
                            <option value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>是否Aims下单</label>
                        <select id="isaims" name="isaims" class="form-control">
                            <option value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
                        <button id="btnexport" style="display:none;" type="button" class="btn btn-success" onclick="exportlist();">导出</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 css{
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}

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

            if ('@(ViewBag.warehousetype)' != '') {
                $('#warehousetype').val('@(ViewBag.warehousetype)');
            }
            if (@(ViewBag.type)!= -1) {
                $('#type').val(@(ViewBag.type));
            }

            if (@(ViewBag.isun)== 0) {
                $('#isreasonable').val(0);
            }
            
            list();
        })

        function list() {
            var columns = [
                { field: 'warehouse_type', title: '仓库类型', width: '130', iscount: true, sortable: true },
                { field: 'warehouse_name', title: '仓库名称', width: '160', iscount: true, sortable: true },
                { field: 'bailun_sku', title: 'sku', width: '180', iscount: true, sortable: true },
                { field: 'category_simple_name', title: '百伦分类', width: '130' },
                { field: 'count_outbound', title: '出库数量', width: '110', iscount: true, sortable: true },
                { field: 'amount_outbound', title: '出库金额', width: '110', iscount: true },
                { field: 'count_putin', title: '入库数量', width: '110', iscount: true, sortable: true },
                { field: 'amount_putin', title: '入途金额', width: '110', iscount: true },
                { field: 'count_diff', title: '(入库-出库)数量', width: '150', iscount: true, sortable: true },
                { field: 'amount_diff', title: '(入库-出库)金额', width: '150', iscount: true }
            ];
            
            columns.push({ field: 'is_clear', title: '是否清货', width: '110', sortable: true });
            columns.push({ field: 'is_new', title: '是否新品', width: '110', sortable: true });
            columns.push({ field: 'is_aimsorder', title: 'Aims下单', width: '110', sortable: true });
            columns.push({ field: 'count_usable_stock', title: '可用库存', width: '110', sortable: true, iscount: true });

            columns.push({ field: 'avg_sevenday_sales', title: '7日日均', width: '110' });
            columns.push({ field: 'avg_fourteenday_sales', title: '14日日均', width: '110' });
            columns.push({ field: 'avg_thirtyday_sales', title: '30天日均', width: '110' });
            columns.push({ field: 'avg_weighting_day_sales', title: '加权日均', width: '110' });
            columns.push({ field: 'avg_sales', title: '可消耗天数', width: '110', sortable: true });
            columns.push({ field: 'sale_putin_id', title: '是否合理', width: '110', sortable: true });

            var url = '@Url.Content("~/Reports/Finance/ListUnReasonableJson")' + '?' + $("#toolbar").serialize() +'&category=@(ViewBag.category)';

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    showfooter: true, showCount: true,
                    loadsuccess: function (d) {
                        if (d.isexport == 1) {
                            $('#btnexport').show();
                        }
                    }
                });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function listwarehouse() {
            var type = $('#warehousetype').val();

            $.submit({
                url: '@Url.Content("~/Home/ListWareHouse")',
                paramData: 'warehousetype=' + type,
                type:'POST',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#warehouse').html('<option value="">仓库不限</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#warehouse').append('<option value="' + result[i].warehouse_code + '">' + result[i].warehouse_name + '</option>');
                        }
                    }
                }
            })
        }

        function exportlist() {
            window.open('@Url.Content("~/Reports/Finance/ExportUnReasonable?")' + $("#toolbar").serialize() + (@(ViewBag.isun)== 0 ? '&isreasonable=0' : '')+'&category=@(ViewBag.category)', '_blank');
        }
    </script>

}

