
@{
    ViewData["Title"] = "Sku利润统计分析";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "统计", "仓库", "SKU利润统计分析" };
}

<div class="row">
    <div class="col-sm-12">
        <div id="leftcontain" style="position:relative;float:left;width:215px;margin-right:-220px;background-color:#fff;height:780px;border-top:solid 1px #E7EAEC;display:none;">
            <div id="ztree" class="ztree" style="margin:5px 10px;max-height: 800px;overflow: auto;">

            </div>
        </div>
        <div style="float:right;width:100%;">
            <div id="rightcontain">
                <div class="ibox-content m-b-sm border-bottom">
                    <div class="alert alert-success">
                        1、成本毛利率=毛利/销售库存金额；2、库存金额周转率=销量金额/（在库金额+采购在途金额+调拨在途金额）；3、金额销进比=(卖出数*采购价)/(采购入库金额+调拨入库金额)；4、件数库存周转率=销量/(在库库存+采购在途+调拨在途)；5、件数销进比=销量/（采购入库+调拨入库）；6、30天金额可售天数=当前库存金额*30/30天总销量库存金额；7、30天件数可售天数=(当前库存*30)/30天总销量；
                    </div>
                    <form id="toolbar">
                        <div class="form-inline" style="line-height:40px;">
                            <div class="form-group">
                                <label>&nbsp;</label>
                                <button type="button" class="btn btn-success" onclick="showleft();">分类筛选</button>
                            </div>
                            <div class="form-group">
                                <label>&nbsp;</label>
                                <select id="warehousecode" name="warehousecode" class="form-control" style="width:160px;">
                                    <option value="">请选择仓库</option>
                                </select>
                            </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>
    </div>
</div>

@section css{
    <link href="~/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .alink {
            color: cornflowerblue;
            cursor: pointer;
        }
    </style>
}
@section scripts{
    <script src="~/js/jquery.ztree.core.min.js"></script>
    <script src="~/js/jquery.ztree.excheck.min.js"></script>
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

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

            list();

            listwarehouse();

            //listcategory12();

            listsimplecategory();
        })

        function list() {
            var columns = [
                { field: 'warehouse_name', title: '仓库名称', width: '170', sortable: false },
                { field: 'bailun_sku', title: 'sku', width: '130', sortable: false, iscount: true },
                {
                    field: 'category_name', title: '品类', width: '220', sortable: true, iscount: true, formatter: function (idx, data) {
                        return '<div class="mules" title="' + data.category_name + '">' + data.category_name + '</div>';
                    }
                },
                { field: 'usable_stock', title: '在库库存', width: '100', sortable: true, iscount: true },
                { field: 'usable_stock_amount', title: '在库金额', width: '100', sortable: true, iscount: true },
                { field: 'quantity_purchase', title: '采购在途数', width: '120', sortable: true, iscount: true },
                { field: 'quantity_purchase_amount', title: '采购在途金额', width: '130', sortable: true, iscount: true },
                { field: 'quantity_transfer', title: '调拨在途数', width: '120', sortable: true, iscount: true },
                { field: 'quantity_transfer_amount', title: '调拨在途金额', width: '130', sortable: true, iscount: true },
                { field: 'yd_sales_amount', title: '昨日销售额', width: '120', sortable: true, iscount: true },
                { field: 'yd_sales_count', title: '昨日销售数量', width: '130', sortable: true, iscount: true },
                { field: 'yd_sales_stockamount', title: '昨日销售库存额', width: '130', sortable: false, iscount: true },
                { field: 'yd_grossprofit', title: '昨日销售毛利额', width: '130', sortable: true, iscount: true },
                { field: 'yd_grossprofit_rate', title: '昨日成本毛利率', width: '130', sortable: true, iscount: true },
                { field: 'pre30_sales_amount', title: '30天销售额', width: '120', sortable: true, iscount: true },
                { field: 'pre30_sales_count', title: '30天销售数量', width: '120', sortable: true, iscount: true},
                { field: 'pre30_stockamount', title: '30天销售库存额', width: '140', sortable: true, iscount: true },
                { field: 'pre30_grossprofit', title: '30天毛利额', width: '130', sortable: true, iscount: true },
                { field: 'pre30_grossprofit_rate', title: '30天成本毛利率', width: '140', sortable: true, iscount: true },
                { field: 'pre30_return_rate', title: '退货率', width: '100', sortable: true, iscount: true },
                { field: 'pre30_stockamount_turn_rate', title: '30天金额库存周转率', width: '160', sortable: true, iscount: true },
                { field: 'pre30_stockamount_add', title: '30天累积入库金额', width: '150', sortable: true, iscount: true },
                { field: 'pre30_stockamount__rate', title: '30天金额销进比', width: '150', sortable: true, iscount: true },
                { field: 'pre30_stocknum_turn_rate', title: '30天件数库存周转率', width: '160', sortable: true, iscount: true },
                { field: 'pre30_stock_add_count', title: '30天累积入库数', width: '150', sortable: true, iscount: true },
                { field: 'pre30_stocknum_rate', title: '30天件数销进比', width: '150', sortable: true, iscount: true },
                { field: 'pre30_stockamount_vendibility_day', title: '30天金额可售天数', width: '150', sortable: true, iscount: true },
                { field: 'pre30_stocknum_vendibility_day', title: '30天件数可售天数', width: '150', sortable: true, iscount: true },
            ];

            var s = '';

            try {
                s = getChkNode();
            } catch (e) {
                s = '';
            }

            var url = '@Url.Content("~/Reports/Warehouse/ListSkuProfitJson")' + '?' + $("#toolbar").serialize() + '&skucategoryids=' + s;

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


        function listwarehousetype() {
            $.submit({
                url: '@Url.Content("~/Home/ListWarehouseType")',
                type: 'POST',
                paramData: '',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#warehousetype').html('<option value="">选择仓库类型</option>');
                        for (var i in result) {
                            if (result[i].indexOf('FBA') < 0) {
                                $('#warehousetype').append('<option value="' + result[i] + '">' + result[i] + '</option>');
                            }
                        }
                    }
                }
            })
        }

        function listwarehouse() {
            $.submit({
                url: '@Url.Content("~/Home/ListWarehouseByExtType")',
                type: 'POST',
                paramData: '',
                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].code + '">' + result[i].name + '</option>');
                        }
                    }
                }
            })
        }

        function ShowDetail(platform, website, account, coltitle, colval, single) {
            layer_show(platform + " " + website + " " + $('#start').val() + "至" + $('#end').val() + ' 订单明细', '@Url.Content("~/Reports/Orders/ListOrderDetail?platform=")' + platform + '&website=' + website + '&account=' + account + '&start=' + $('#start').val() + '&end=' + $('#end').val() + '&col=' + colval + '&coltitle=' + coltitle + '&showsingle=' + single, '90%', '90%');
        }

        function showleft() {
            var c = $('#leftcontain').css('display');
            if (c == 'none') {
                $('#leftcontain').css('display', 'inline');
                $("#rightcontain").animate({ marginLeft: "220px" });
            }
            else {
                $('#leftcontain').css('display', 'none');
                $("#rightcontain").animate({ marginLeft: "0px" });
            }
        }

        function listcategory12() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListSkuCategoryOneAndSecondLevel")',
                paramData: '',
                type: 'POST',
                func: function (result) {
                    var setting = {
                        check: {
                            chkStyle:'checkbox',
                            enable: true
                        }
                    };
                    zTreeObj = $.fn.zTree.init($("#ztree"), setting, eval('('+result+')'));
                }
            })
        }

        function listsimplecategory() {
            $.submit({
                url: '@Url.Content("~/Home/ListSimpleCategory")',
                paramData: '',
                type: 'POST',
                func: function (result) {
                    var setting = {
                        check: {
                            chkStyle: 'checkbox',
                            enable: true
                        }
                    };
                    zTreeObj = $.fn.zTree.init($("#ztree"), setting, result);
                }
            })
        }

        function getChkNode() {
            var s = '';
            var o = $.fn.zTree.getZTreeObj("ztree");
            var nodes = o.getCheckedNodes();
            for (var i in nodes) {
                if (nodes[i].children == null || nodes[i].children.length <= 0) {
                    s += (nodes[i].id) + '|';
                }
            }

            return s;
        }


    </script>

}


