
@{
    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">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>统计类型：</label>
                        <select id="t" name="t" class="form-control">
                            <option value="1">按销售维度</option>
                            <option value="2">按发货维度</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>统计时间</label>
                        <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(ViewBag.start)" />
                        <span>至</span>
                        <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(ViewBag.end)" />
                    </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 type="button" class="btn btn-warning" onclick="exportlistpurchase()">导出采购下单明细</button>
                        @*<button type="button" class="btn btn-success" onclick="exportlistputin();">导出入库明细</button>
                        <button type="button" class="btn btn-success" onclick="exportlistshipping();">导出发货明细</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;
        var companyid = 0;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            $('#t').val(@(ViewBag.t));
            
            list();
        })

        function list(cid) {
            var columns = [
                {
                    field: 'day', title: '统计日期', width: '110'
                },
                {
                    field: 'warehouse_name', title: '仓库名称', width: '200'
                },
                {
                    field: 'bailun_sku', title: 'Sku', width: '160', iscount: true, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.bailun_sku + '">' + data.bailun_sku+'</div>';
                    }
                },
                { field: 'stock_start', title: '期初库存', width: '100' },
                { field: 'stockamount_start', title: '期初库存金额', width: '130' },
                { field: 'count_purchase', title: '采购(入库)数', width: '130', sortable: true, iscount: true },
                { field: 'amount_purchase', title: '采购(入库)金额', width: '130', sortable: true, iscount: true },
                { field: 'count_sales', title: '销售(发货)数', width: '130', sortable: true, iscount: true },
                { field: 'amount_sales', title: '销售(发货)金额', width: '130', sortable: true, iscount: true },
                { field: 'diff_count', title: '差异数', width: '100', sortable: true, iscount: true },
                { field: 'diff_amount', title: '差异金额', width: '110', sortable: true, iscount: true },
                { field: 'stock_end', title: '期末库存', width: '100', sortable: true, iscount: true },
                { field: 'stockamount_end', title: '期末库存金额', width: '130', sortable: true, iscount: true }
            ];

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

                        companyid = d.companyid;
                        if (cid != undefined) {
                            showleft();
                        }
                    }
                }, {
                        fixedcol: true,
                        fixedcolnum:1
                    });
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }
        
        @*function exportlistputin() {
            if (confirm("确定要导出入库明细吗?")) {
                window.open('@Url.Content("~/ExportFile/Putin/ExportPurchasePutin")' + '?' + $("#toolbar").serialize() + '&companyid=' + companyid, '_blank');
                window.open('@Url.Content("~/ExportFile/Putin/ExportAllotPutin")' + '?' + $("#toolbar").serialize() + '&companyid=' + companyid, '_blank');
            }
        }

        function exportlistshipping() {
            if (confirm("确定要导出发货明细吗?")) {
                window.open('@Url.Content("~/ExportFile/Shipping/ListShipping")' + '?' + $("#toolbar").serialize() + '&companyid=' + companyid, '_blank');
            }
        }*@

        function exportlistpurchase() {
            if (confirm('确定要导出采购下单明细吗？')) {
                window.open('@Url.Content("~/ExportFile/Purchase/ExportSemiPurchase")' + '?' + $("#toolbar").serialize() + '&companyid=' + companyid, '_blank');
            }
        }
        

    </script>
}


