
@{
    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">
                <input id="isfba" name="isfba" type="hidden" value="0" />
                <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="warehousecode" name="warehousecode" class="form-control" style="width:160px;">
                            <option value="">选择仓库</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>日期</label>
                        <input id="day" name="day" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" />
                    </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" type="button" class="btn btn-success" onclick="exportxls()">导出</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{
    <link href="~/css/bootstrap-table-fixed-columns.css" rel="stylesheet" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script src="~/js/bootstrap-table-fixed-columns.js" type="text/javascript"></script>
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 160));
            laydate.render({ elem: '#day' });

            list();

            listwarehouse();

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

        })

        function list() {

            var day = $('#day').val();
            if (day == '') {
                alert('请选择日期');
                return;
            }

            var columns = [
                {
                    field: 'warehousetype', title: '仓库类型', width: '100', formatter: function (idx, data) {
                        return data.warehousetype;
                    }
                },
                {
                    field: 'warehousename', title: '仓库名称', width: '160', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" onclick="SkuDetail(\'' + data.warehousecode + '\',\'' + data.warehousename+'\')">' + data.warehousename+'</a>';
                    }
                },
                {
                    field: 'usable_stock', title: 'sku数', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.usable_stock;
                    }
                },
                {
                    field: 'amount_stock', title: 'sku金额', width: '100', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.amount_stock;
                    }
                },
                {
                    field: 'quantity_purchase', title: '采购在途sku数', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.quantity_purchase;
                    }
                },
                {
                    field: 'quantity_purchase_product', title: '采购在途产品数', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.quantity_purchase_product;
                    }
                },
                {
                    field: 'purchase_amount', title: '采购在途金额', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.purchase_amount;
                    }
                },
                {
                    field: 'quantity_transfer', title: '调拨在途sku数', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.quantity_transfer;
                    }
                },
                {
                    field: 'quantity_transfer_product', title: '调拨在途产品数', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.quantity_transfer_product;
                    }
                },
                {
                    field: 'transfer_amount', title: '调拨在途金额', width: '130', sortable: true, iscount: true, formatter: function (idx, data) {
                        return data.transfer_amount;
                    }
                },
                {
                    field: 'sale10_rate', title: '日销大于10sku占比%', width: '170', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale10_rate\',\'日销大于10sku占比\')">' + data.sale10_rate + '</a>';
                    }
                },
                {
                    field: 'sale10_count', title: '日销大于10sku数', width: '150', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" onclick="SkuDetail(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',10,\'日销大于10sku数\')">' + data.sale10_count + '</a>';
                    }
                },
                {
                    field: 'sale10_amount_rate', title: '日销大于10库存金额占比%', width: '197', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale10_amount_rate\',\'日销大于10库存金额占比\')">' + data.sale10_amount_rate + '</a>';
                    }
                },
                {
                    field: 'sale10_amount', title: '日销大于10库存金额', width: '170', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale10_amount\',\'日销大于10库存金额\')">' + data.sale10_amount + '</a>';
                    }
                },
                {
                    field: 'sale5_10_rate', title: '日销5-10sku数占比%', width: '170', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale5_10_rate\',\'日销5-10sku数占比\')">' + data.sale5_10_rate + '</a>';
                    }
                },
                {
                    field: 'sale5_10_count', title: '日销5-10sku数', width: '140', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" onclick="SkuDetail(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',5,\'日销5-10sku数\')">' + data.sale5_10_count + '</a>';
                    }
                },
                {
                    field: 'sale5_10_amount_rate', title: '日销5-10库存金额占比%', width: '190', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale5_10_amount_rate\',\'日销5-10库存金额占比\')">' + data.sale5_10_amount_rate + '</a>';
                    }
                },
                {
                    field: 'sale5_10_amount', title: '日销5-10库存金额', width: '170', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale5_10_amount\',\'日销5-10库存金额\')">' + data.sale5_10_amount + '</a>';
                    }
                },
                {
                    field: 'sale1_5_amount_rate', title: '日销1-5库存金额占比%', width: '190', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale1_5_amount_rate\',\'日销1-5库存金额占比\')">' + data.sale1_5_amount_rate + '</a>';
                    }
                },
                {
                    field: 'sale1_5_amount', title: '日销1-5库存金额', width: '170', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale1_5_amount\',\'日销1-5库存金额\')">' + data.sale1_5_amount + '</a>';
                    }
                },
                {
                    field: 'sale1_amount_rate', title: '日销0-1库存金额占比%', width: '190', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale1_amount_rate\',\'日销0-1库存金额占比\')">' + data.sale1_amount_rate + '</a>';
                    }
                },
                {
                    field: 'sale1_amount', title: '日销0-1库存金额', width: '170', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale1_amount\',\'日销0-1库存金额\')">' + data.sale1_amount + '</a>';
                    }
                },
                {
                    field: 'sale0_count_rate', title: '日销为0sku数占比%', width: '180', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale0_count_rate\',\'日销为0sku数占比\')">' + data.sale0_count_rate + '</a>';
                    }
                },
                {
                    field: 'sale0_amount', title: '日销为0sku库存金额', width: '180', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" style="color:#B2B2B2" title="趋势图" onclick="ShowTrendChart(\'' + data.warehousecode + '\',\'' + data.warehousename + '\',\'sale0_amount\',\'日销为0sku库存金额\')">' + data.sale0_amount + '</a>';
                    }
                }
            ];

            var url = '@Url.Content("~/Reports/Warehouse/InventorySummaryJson")' + '?' + $("#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) {
                                        @*if (d.count_row[v] != '总计') {


                                            tr.find('td').eq(c).children('div').first().html(d.count_row[v] + '<img src="@Url.Content("~/img/icon-trendchart.png")" title="总趋势图" style="height:20px;margin-left:3px;" onclick="ShowTrendChart(\'\',\'' + columns[c].title + '的总趋势图\',\'' + v + '\',\'\');" />');
                                        }
                                        else {
                                            tr.find('td').eq(c).children('div').first().html(d.count_row[v]);
                                        }*@

                                        tr.find('td').eq(c).children('div').first().html(d.count_row[v]);
                                        break;
                                    }
                                }
                            }
                        };

                        if (d.isexport == 1) {
                            $('#btnexport').show();
                        }
                    }
                }, {
                        fixedcol: true,
                        fixedcolnum: 2
                    });
            }
            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) {
                        $('#warehousecode').html('<option value="">仓库不限</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#warehousecode').append('<option value="' + result[i].warehouse_code + '">' + result[i].warehouse_name + '</option>');
                        }
                    }
                }
            })
        }

        //导出
        function exportxls() {
            var day = $('#day').val();
            if (day == '') {
                alert('请选择日期');
                return;
            }

            window.open('@Url.Content("~/Reports/Warehouse/ExportInventorySummary?")' + $("#toolbar").serialize(), '_blank');
        }

        function SkuDetail(code,name, type,typename) {

            var day = $('#day').val();
            if (day == '') {
                alert('请选择日期');
                return;
            }

            var _url = '@Url.Content("~/Reports/Warehouse/ListWareHouseSku?code=")'+code;
            if (type != undefined) {
                _url += '&onedaysalescount=' + type;
            }

            _url += '&day='+day;

            layer_show('【' + name + (type != undefined ? '-' + typename:'') + '】仓库SKU明细', _url, '90%', '90%');
        }

        function ShowTrendChart(code, name, key, title) {
            if (code == null) {
                code = '';
            }

            var day = $('#day').val();
            if (day == '') {
                alert('请选择日期');
                return;
            }

            var _url = '@Url.Content("~/Reports/Warehouse/InventorySummaryChart?warehousecode=")' + code + '&warehousename=' + name + '&key=' + key + '&title=' + title;

            _url += '&day=' + day;

            layer_show(name + "=》" + title + '的趋势图', _url , '90%', '90%');
        }

    </script>

}


