
@{
    ViewData["Title"] = "仓库库存分析报告";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "库存", "库存分析报表" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="alert alert-info">
            说明：日销为过去7天日均销量
        </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>
                        <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>
                            <option value="耗材仓">耗材仓</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>仓库：</label>
                        <select id="code" name="code" class="form-control" style="width:160px;">
                            <option value="">选择仓库</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="day" name="day" class="form-control" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" placeholder="请选择日期" />
                    </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>
                    </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 type="text/javascript">
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 160));
            
            list();

            laydate.render({ elem: '#day' });

            listwarehouse();

            $('#warehousetype').change(function () {
                listwarehouse();
            })

        })

        function list() {
            var columns = [
                {
                    field: 'warehouse_name', title: '仓库名称', width: '190', sortable: false, iscount: true, formatter: function (idx, data) {
                        return '<div  style="color:#7CABD9;cursor:pointer;" onclick="ShowSku(\'' + data.warehouse_code + '\',\'' + data.warehouse_name + '\')">' + data.warehouse_name + '</div>';
                    }
                },
                {
                    field: 'skucount', title: 'Sku总库存', width: '120', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div  style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'skucount\',\'Sku总个数\',\'' + data.warehouse_name + '\')" >' + data.skucount + '</div>';
                    }
                },
                {
                    field: 'productcount', title: '产品个数', width: '110', sortable: true, iscount: true, formatter: function (idx,data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'productcount\',\'产品个数\',\'' + data.warehouse_name + '\')" >' + data.productcount + '</div>';
                    }
                },
                {
                    field: 'onway_count', title: '在途数', width: '110', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'onway_count\',\'在途数\',\'' + data.warehouse_name + '\')" >' + data.onway_count + '</div>';
                    }
                },
                {
                    field: 'amount_total', title: '总金额', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'amount_total\',\'总金额\',\'' + data.warehouse_name + '\')" >' + data.amount_total + '</div>';
                    }
                },
                {
                    field: 'skusales_count', title: '日销sku个数', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'skusales_count\',\'日销sku个数\',\'' + data.warehouse_name + '\')" >' + data.skusales_count + '</div>';
                    }
                },
                {
                    field: 'skusales_rate', title: '动销sku比例', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'skusales_rate\',\'动销sku比例\',\'' + data.warehouse_name + '\')" >' + data.skusales_rate + '</div>';
                    }
                },
                {
                    field: 'daily_productsale_count', title: '日销产品个数', width: '150', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'daily_productsale_count\',\'日销产品个数\',\'' + data.warehouse_name + '\')" >' + data.daily_productsale_count + '</div>';
                    }
                },
                {
                    field: 'productsale_rate', title: '动销产品比例', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'productsale_rate\',\'动销产品比例\',\'' + data.warehouse_name + '\')" >' + data.productsale_rate + '</div>';
                    }
                },
                {
                    field: 'dailysale_amount', title: '日销金额', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'dailysale_amount\',\'日销金额\',\'' + data.warehouse_name + '\')" >' + data.dailysale_amount + '</div>';
                    }
                },
                {
                    field: 'saleamount_rate', title: '动销金额比例', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'saleamount_rate\',\'动销金额比例\',\'' + data.warehouse_name + '\')" >' + data.saleamount_rate + '</div>';
                    }
                },
                {
                    field: 'redundancy_sku_count', title: '冗余sku个数', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'redundancy_sku_count\',\'冗余sku个数\',\'' + data.warehouse_name + '\')" >' + data.redundancy_sku_count + '</div>';
                    }
                },
                {
                    field: 'redundancy_sku_rate', title: '冗余sku个数比例', width: '150', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'redundancy_sku_rate\',\'冗余sku个数比例\',\'' + data.warehouse_name + '\')" >' + data.redundancy_sku_rate + '</div>';
                    }
                },
                {
                    field: 'redundancy_product_count', title: '冗余产品个数', width: '120', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'redundancy_product_count\',\'冗余产品个数\',\'' + data.warehouse_name + '\')" >' + data.redundancy_product_count + '</div>';
                    }
                },
                {
                    field: 'redundancy_product_rate', title: '冗余产品个数比例', width: '150', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'redundancy_product_rate\',\'冗余产品个数比例\',\'' + data.warehouse_name + '\')" >' + data.redundancy_product_rate + '</div>';
                    }
                },
                {
                    field: 'redundancy_amount', title: '冗余金额', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'redundancy_amount\',\'冗余金额\',\'' + data.warehouse_name + '\')" >' + data.redundancy_amount + '</div>';
                    }
                },
                {
                    field: 'redundancy_amount_rate', title: '冗余金额比例', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div style="cursor:pointer;" onclick="ShowHistoryData(\'' + data.warehouse_code + '\',\'redundancy_amount_rate\',\'冗余金额比例\',\'' + data.warehouse_name + '\')" >' + data.redundancy_amount_rate + '</div>';
                    }
                },
            ];

            var url = '@Url.Content("~/Reports/Warehouse/WarehouseRedundancyJson")' + '?' + $("#toolbar").serialize();

            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 listwarehouse() {
            var type = $('#warehousetype').val();

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

        function ShowSku(warehousecode,title) {
            var day = $('#day').val();
            layer_show(day+' '+title + ' sku仓库库存分析', '@Url.Content("~/Reports/Warehouse/SkuRedundancy?warehousecode=")' + warehousecode + '&day=' + day + '&warehousename=' + title, '95%', '95%');
        }

        function ShowHistoryData(warehousecode, col, coltitle,warehousename) {
            var day = $('#day').val();

            layer_show(day + ' ' + warehousename + ' 前两个月的库存分析', '@Url.Content("~/Reports/Warehouse/WHRedundancyChart?warehousecode=")' + warehousecode + '&day=' + day + '&warehousename=' + warehousename + '&col=' + col + '&colname=' + coltitle, '95%', '95%');
        }

        

    </script>

}

