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

}

<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>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>仓库：</label>
                        <select id="warehouse" name="warehouse" class="form-control" style="width:160px;">
                            <option value="">选择仓库</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>月份</label>
                        <input id="date_" name="date_" class="form-control"  style="width:110px;" readonly />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="sku" name="sku" class="form-control" style="width:160px" placeholder="Sku编码" />
                    </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));

            laydate.render({ elem: '#date_', type: 'month'});

            list();

            listwarehouse();
        })

        function list() {
            var columns = [
                {
                    field: 'warehouse_name', title: '仓库名称', width: '190', sortable: false
                },
                {
                    field: 'bailun_sku', title: 'Sku', width: '160', sortable: false, iscount: true, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.bailun_sku + '">' + data.bailun_sku + '</div>';
                    }
                },
                {
                    field: 'quantity_begin_month_inventory', title: '月初库存数量', width: '140', sortable: true
                },
                {
                    field: 'quantity_purchase_transit', title: '采购在途', width: '110', sortable: true, iscount: true
                },
                { field: 'quantity_purchase_inbound', title: '采购入库数量', width: '130', sortable: true, iscount: true },
                {
                    field: 'quantity_transfer_transit', title: '调拨在途数量', width: '130', sortable: true, iscount: true
                },
                {
                    field: 'quantity_transfer_inbound', title: '调拨入库数量', width: '130', sortable: true, iscount: true
                },
                {
                    field: 'quantity_damaged', title: '报损数量', width: '110', sortable: true, iscount: true
                },
                {
                    field: 'quantity_overflow', title: '报溢数量', width: '110', sortable: true, iscount: true
                },
                { field: 'quantity_sku_changed', title: 'Sku转换数量', width: '130', sortable: true, iscount: true },
                { field: 'quantity_sales', title: '销售数量', width: '110', sortable: true, iscount: true },
                { field: 'quantity_end_month_inventory', title: '月末库存数量', width: '130', sortable: true },
                { field: 'turnover_rate', title: '周转率', width: '110', sortable: true },
                { field: 'turnover_date', title: '周转天数', width: '110', sortable: true },
                { field: 'inv_age_0to1_month', title: '库龄0-1月', width: '130', sortable: true, iscount: true },
                { field: 'inv_age_1to3_month', title: '库龄1-3月', width: '130', sortable: true, iscount: true },
                { field: 'inv_age_3to6_month', title: '库龄3-6月', width: '130', sortable: true, iscount: true },
                { field: 'inv_age_6to12_month', title: '库龄6-12月', width: '130', sortable: true, iscount: true },
                { field: 'inv_age_1to2_year', title: '库龄1-2年', width: '130', sortable: true, iscount: true },
                { field: 'inv_age_gt3_year', title: '库龄3年以上', width: '140', sortable: true, iscount: true },
                { field: 'quantity_instant_inventory', title: '即时库存数', width: '130', sortable: true, iscount: true },
                { field: 'instant_inventory_amount', title: '即时库存金额', width: '130', sortable: true, iscount: true },
                { field: 'month_total_exports', title: '本月累计出口数量', width: '180', sortable: true, iscount: true },
                { field: 'exportamount', title: '本月累计出口金额', width: '180', sortable: true, iscount: true },
                //{ field: 'thirtyday_total_sales', title: '一个月销售额趋势图', width: '180', sortable: true }
            ];

            var date = $('#date_').val();
            if (date != null) {
                date = date + '_01';
            }

            var url = '@Url.Content("~/Reports/Inventory/ListSkuInventoryJson")' + '?' + $("#toolbar").serialize() + '&date=' + date;

            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/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>');
                        }
                    }
                }
            })
        }
        

    </script>

}


