
@{
    ViewData["Title"] = (ViewBag.type == 1 ? "OMS" : "FBA") +"发货收入";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "财务报表", "OMS发货收入" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="alert alert-warning" style="display:none;">
            说明：数据从2019年9月份开始
        </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>
                        <input id="month" name="month" class="form-control" style="width:130px;" placeholder="年.月" value="@(DateTime.Now.AddMonths(-1).ToString("yyyy-MM"))" />
                    </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-danger" onclick="exportxls();">导出</button>
                        @if (ViewBag.type == 1)
                        { 
                            <button type="button" class="btn btn-danger" onclick="exportCert();">导出凭证</button>
                        }
                        
                    </div>
                </div>
            </form>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <h2 style="text-align:center;">@(ViewBag.type==1? "OMS":"FBA")发货收入</h2>
            <div class="bootstrap-table">
                <div class="fixed-table-container">
                    <div class="fixed-table-body">
                        <table id="tb" style="table-layout: fixed;" class="table table-border table-bordered table-hover table-bg table-sort form-inline">
                            <thead>
                                <tr>
                                    <td>平台</td>
                                    <td>站点</td>
                                    <td>原始币种</td>
                                    <td>中文分类</td>
                                    <td>订单总金额</td>
                                </tr>
                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section css{
    <style>
        a {
            margin-left: 10px;
        }
    </style>
}

@section scripts{
    <script src="~/css/Layer-2.1/extend/layer.ext.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            laydate.render({ elem: '#month', type: 'month' });

            list();
        })

        function list() {
            $.submit({
                url: '@Url.Content("~/Reports/Finance/ShippingIncomingJson")',
                type: 'POST',
                paramData: $("#toolbar").serialize()+'&type=@(ViewBag.type)',
                func: function (result) {
                    if (result.success) {
                        $('#tb').find('tbody').html('');
                        if (result.data.length > 0) {

                            //组装行
                            var rows = '';

                            for (var i in result.data) {
                                var obj = result.data[i];
                                rows += '<tr>';
                                rows += '<td>' + obj.platform_type + '</td>';
                                rows += '<td>' + obj.website + '</td>';
                                rows += '<td>' + obj.currency + '</td>';
                                rows += '<td>' + obj.financecategoryname + '</td>';
                                rows += '<td>' + obj.amount + '</td>';
                                rows += '</tr>';
                            }

                            $('#tb').find('tbody').append(rows);


                        }
                        else {
                            layer.msg('没有' + $('#month').val()+'月份的OMS发货收入数据。');
                        }
                    }
                    else {
                        layer.msg(result.msg);
                    }

                    return false;
                }
            })
        }

        function EditFee(name, col,v,mon) {
            layer.prompt({ title: '编辑' + name, value:v}, function (text, index) {
                layer.close(index);
                Save(col, text, mon);
            });
        }

        function Save(col, val, mon) {
            $.submit({
                url: '@Url.Content("~/Reports/Finance/SaveMonthSaleProfitNew")',
                paramData: 'month=' + mon+'&'+col+'='+val,
                type:'POST',
                func: function (result) {
                    if (result.success) {
                        layer.msg('提交成功');
                        setTimeout(function () {
                            list();
                        }, 1.5 * 1000);
                    }
                    else {
                        layer.msg(result.msg);
                    }
                }
            })
        }

        function EditDescription(col, val, mon, name) {
            layer.prompt({ title: '编辑 ' + name, value: val }, function (text, index) {
                layer.close(index);
                SaveDescription(col, text, mon);
            });
        }

        function SaveDescription(col, val, mon) {
            $.submit({
                url: '@Url.Content("~/Reports/Finance/UpdateMonthSaleProfitDescription")',
                paramData: 'month=' + mon+'&'+col+'='+val,
                type:'POST',
                func: function (result) {
                    if (result.success) {
                        layer.msg('提交成功');
                        setTimeout(function () {
                            list();
                        }, 1.5 * 1000);
                    }
                    else {
                        layer.msg(result.msg);
                    }
                }
            })
        }

        function ShowDetail(col, mon, name) {
            layer_show(mon + ' ' + name + "的明细", '@Url.Content("~/Reports/Finance/MonthSaleProfitDetails")' + '?month=' + mon + '&col=' + col + '&colname=' + name, '95%', '95%');
        }

        function exportxls() {
            var mon = $('#month').val();
            if (mon == '') {
                alert('请选择月份');
                return;
            }

            window.open('@Url.Content("~/Reports/Finance/ExportShippingIncoming?month=")' + mon+'&type=@(ViewBag.type)', '_blank');
        }

        function exportCert() {
            var mon = $('#month').val();
            if (mon == '') {
                alert('请选择月份');
                return;
            }

            window.open('@Url.Content("~/Reports/Finance/ExportShippingIncomingCertficate?month=")' + mon+'&type=@(ViewBag.type)', '_blank');
        }

        function clearHtml(s) {
            // 去除 富文本格式
            s = s.replace(/(\n)/g, "");
            s = s.replace(/(\t)/g, "");
            s = s.replace(/(\r)/g, "");
            s = s.replace(/<\/?[^>]*>/g, "");
            s = s.replace(/\s*/g, "");

            return s;
        }
    </script>
}

