
@{
    ViewData["Title"] = "半成品仓库进销存";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "财务报表", "半成品仓库进销存" };
}

<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" style="display:none;">
                        <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>日期</label>
                        <input id="start" name="start" class="form-control" style="width:100px" value="@(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"))" />至
                        <input id="end" name="end" class="form-control" style="width:100px" 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>
                    </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: '#start' });
            laydate.render({ elem: '#end' });

            list();

            listwarehouse();

        })

        function list() {
            var columns = [
                {
                    field: 'warehouse_name', title: '仓库名称', width: '180', iscount: true, formatter: function (idx, data) {
                        return '<a href="javascript:;" onclick="details(\'' + data.warehouse_code + '\',\'' + data.warehouse_name + '\')">' + data.warehouse_name+'</a>';
                    }
                },
                { field: 'start_stock_amount', title: '期初-在库金额', width: '130', iscount: true, sortable: true },
                { field: 'start_stock_count', title: '期初-在库数量', width: '130', iscount: true, sortable: true },
                { field: 'start_onway_amount', title: '期初-在途金额', width: '130', iscount: true, sortable: true },
                { field: 'start_onway_count', title: '期初-在途数量', width: '130', iscount: true, sortable: true },
                { field: 'end_stock_amount', title: '期末-在库金额', width: '130', iscount: true, sortable: true },
                { field: 'end_stock_count', title: '期末-在库数量', width: '130', iscount: true, sortable: true },
                { field: 'end_onway_amount', title: '期末-在途金额', width: '130', iscount: true, sortable: true },
                { field: 'end_onway_count', title: '期末-在途数量', width: '130', iscount: true, sortable: true },
                { field: 'diff_stock_amount', title: '差异-在库金额', width: '130', iscount: true, sortable: true },
                { field: 'diff_stock_count', title: '差异-在库数量', width: '130', iscount: true, sortable: true },
                { field: 'diff_onway_amount', title: '差异-在途金额', width: '130', iscount: true, sortable: true },
                { field: 'diff_onway_count', title: '差异-在途数量', width: '130', iscount: true, sortable: true },
                { field: 'amount', title: '总金额(差异)', width: '130', iscount: true, sortable: true },
                { field: 'count', title: '总数量(差异)', width: '130', iscount: true, sortable: true }
            ];

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

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "", {
                    showfooter: true, showCount: true
                });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

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

            $.submit({
                url: '@Url.Content("~/Reports/Warehouse/SemiWarehouse")',
                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 details(code,name) {
            var start = $('#start').val();
            var end = $('#end').val();

            layer_show(name + ' Sku进销存', '@Url.Content("~/Reports/Finance/SemiSkuPurchaseSellStock?warehouse=")' + code + '&start=' + start + '&end=' + end, '90%', '90%');

        }

    </script>

}