
@{
    ViewData["Title"] = "库龄列表";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "库存", "库龄列表" };
}

@*3：3个月以上，6：6个月以上，12：1年以上，24：2年以上，36：3年以上，4：3个月以上，6个月以下，7：6个月以上，12个月以下，13：12个月以上，24个月以下，25：24个月以上，36个月以下*@
<div class="row">
    <div class="col-sm-12">

        <div class="alert alert-warning">
            说明：库龄数据是根据当天入库数和当前库存推算得来的，入库包括采购非调拨入库、调拨入库
        </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="type" name="type" class="form-control">
                            <option value="0">1个月以下</option>
                            <option value="1">1个月以上</option>
                            <option value="2">1-3个月</option>
                            <option value="-3">0-3个月</option>
                            <option value="3">3个月以上</option>
                            <option value="4">3至6个月的</option>
                            <option value="6">6个月以上</option>
                            <option value="7">6至12个月的</option>
                            <option value="12">1年以上</option>
                            <option value="13">1至2年的</option>
                            <option value="24">2年以上</option>
                            <option value="25">2至3年的</option>
                            <option value="36">3年以上</option>
                        </select>
                    </div>
                    <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="warehouse" name="warehouse" class="form-control">
                            <option value="">请选择仓库</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <select id="isfinish" name="isfinish" class="form-control" style="width:160px;">
                            <option value="">选择成品或原料</option>
                            <option value="1">成品</option>
                            <option value="2">原料</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <select id="category" name="category" class="form-control" style="width:160px;">
                            <option value="">选择产品类型</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>采购员名称：</label>
                        <input id="buyername" name="buyername" class="form-control" style="width:120px" placeholder="采购员名称" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <input id="sku" name="sku" class="form-control" style="width:150px" 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>
                        <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 type="text/javascript">
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 160));

            list();

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

            $('#isfinish').change(function () {
                if ($(this).val() == '') {
                    $('#category').html('<option value="">产品类型</option>');
                }
                else if ($(this).val() == 1) {  //成品
                    listFinanceCategory();
                }
                else {  //半成品
                    listSemiCategory();
                }
            })

        })

        function list() {
            var columns = [
                { field: 'bailun_sku', title: 'sku编码', width: '130' },
                {
                    field: 'sku_name', title: 'sku名称', width: '220', formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.sku_name + '">' + data.sku_name + '</div>';
                    }
                },
                { field: 'sku_category', title: '产品类型', width: '150' },
                { field: 'warehouse_name', title: '仓库名称', width: '150', iscount: true },
                { field: 'stock', title: '库存数量', width: '150', iscount: true, sortable: true },
                { field: 'amount', title: '库存金额', width: '150', iscount: true, sortable: true },
                {
                    field: 'stock_time', title: '库龄(天)', width: '110', sortable: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" onclick="ShowDetail('+data.id+')">' + data.stock_time + "</a>";
                    }
                }
            ];

            var url = '@Url.Content("~/Reports/Sku/ListInventoryAgingJson")' + '?' + $("#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;
                                    }
                                }
                            }
                        };

                        if (d.isexport == 1) {
                            $('#btnexport').show();
                        }

                    }
                });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function ShowDetail(id) {
            layer_show('库龄推算规则', '@Url.Content("~/Reports/Sku/InventoryAgingDetail?id=")'+id, '90%', '90%');
        }

        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() {
            if (confirm("确定要导出明细吗？")) {
                //ExportInventoryAging
                window.open('@Url.Content("~/Reports/Sku/ExportInventoryAging")' + '?' + $("#toolbar").serialize(), '_blank');
            }
        }

        var financecategory;
        function listFinanceCategory() {
            if (financecategory == undefined) {
                $.submit({
                    url: '@Url.Content("~/Reports/Warehouse/ListFinanceCategory")',
                    paramData: '',
                    type: 'POST',
                    func: function (result) {
                        if (result != null && result != undefined) {
                            financecategory = result;

                            $('#category').html('<option value="">产品类型</option>');
                            for (var i in financecategory) {
                                $('#category').append('<option value="' + financecategory[i].financecategoryname + '">' + financecategory[i].financecategoryname + '</option>');
                            }
                        }
                    }
                })
            }
            else {
                $('#category').html('<option value="">产品类型</option>');
                for (var i in financecategory) {
                    $('#category').append('<option value="' + financecategory[i].financecategoryname + '">' + financecategory[i].financecategoryname + '</option>');
                }
            }
        }

        var semiCategory;
        function listSemiCategory() {
            if (semiCategory == undefined) {

                $('#category').html('<option value="">产品类型</option>');

                $.submit({
                    url: '@Url.Content("~/Reports/Warehouse/ListSemiSkuCategory")',
                    paramData: '',
                    type: 'POST',
                    func: function (result) {
                        if (result != null && result != undefined) {
                            semiCategory = result;

                            $('#category').html('<option value="">产品类型</option>');
                            for (var i in semiCategory) {
                                $('#category').append('<option value="' + semiCategory[i].product_category_name + '">' + semiCategory[i].product_category_name + '</option>');
                            }
                        }
                    }
                })
            }
            else {
                $('#category').html('<option value="">产品类型</option>');
                for (var i in semiCategory) {
                    $('#category').append('<option value="' + semiCategory[i].product_category_name + '">' + semiCategory[i].product_category_name + '</option>');
                }
            }
        }

    </script>

}

