<?php
use \common\libs\MyLib;
?>
<link rel="stylesheet" href="/js/fileupload/css/jquery.fileupload.css">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <form id="theFrm">
        <tr>
            <td align="center" width="100" height="25" class="td_bg">导入类型</td>
            <td height="25" class="td_bg">手续费导入</td>
        </tr>
        <tr>
            <td align="center" width="100" height="25" class="td_bg">保险公司</td>
            <td height="25" class="td_bg">
                <select name="company">
                    <option>人保</option>
                    <option>太平洋</option>
                </select>
            </td>
        </tr>
        <tr>
            <td align="center" width="100" height="25" class="td_bg">批对日期</td>
            <td height="25" class="td_bg">
                <input type="text" name="urlfile" id="urlfile" style="width: 300px;">
                <input id="fileupload" type="file" name="file">
            </td>
        </tr>
    </form>
    <tr>
        <td height="22" colspan="2" align="center" class="td_bg">
<!--            <input id="submit-btn" type=button class="ACT_btn" name=Submit1 value=" 提交 "/>-->
            &nbsp;&nbsp;
            <input type="button" class="ACT_btn" name="Submit3" value=" 刷新 " onclick="window.location.reload();">
        </td>
    </tr>
</table>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <form id="searchForm">
        <input type="hidden" id="page" name="page" value="<?=$page?>">
        <tr>
            <td class="td_bg">
                <!--新增搜索项-->
                <!--完成程度-->
                <select name="status" class="status">
                    <option value=0>全部</option>
                    <option value=1 <?= $status==1?'selected':'' ?>>未匹配</option>
                    <option value=2 <?= $status==2?'selected':'' ?>>已完成</option>
                    <option value=3 <?= $status==3?'selected':'' ?>>匹配差额</option>
                </select>
                保单号：<input name="insurer_no" type="text" value="<?=$insurer_no?>">
                被保险人：<input name="id_man" type="text" value="<?=$id_man?>">

                <!--日期-->
                出单日期：
                <input type="Text" class="Wdate" name="begin_date" onclick="WdatePicker()" value="<?= $begin_date ?>" />
                --
                <input type="Text" class="Wdate" name="end_date" onclick="WdatePicker()" value="<?= $end_date ?>" />
                回单日期：
                <input type="Text" class="Wdate" name="r_begin_date" onclick="WdatePicker()" value="<?= $r_begin_date ?>" />
                --
                <input type="Text" class="Wdate" name="r_end_date" onclick="WdatePicker()" value="<?= $r_end_date ?>" />

                级别：<select name="group_id">
                    <option value="0">全部</option>
                    <?php
                    foreach($group_items as $item) {
                        echo '<option value="'.$item->id.'"';
                        if($item->id == $group_id)
                            echo ' selected ';
                        echo '>'.$item->name.'</option>';
                    }
                    ?>
                </select>
                排序：
                <select name="sort_key">
                    <option value="0">请选择</option>
                    <option value="print_date" <?= $sort_key == 'print_date' ? 'selected' : ''?>>出单日期</option>
                    <option value="total" <?= $sort_key == 'total' ? 'selected' : ''?>>商业总保费</option>
                    <option value="total_clear" <?= $sort_key == 'total_clear' ? 'selected' : ''?>>商业净保费</option>
                    <option value="total_rate" <?= $sort_key == 'total_rate' ? 'selected' : ''?>>手续费比例</option>
                </select>
                <select name="sort_value">
                    <option value="0">请选择</option>
                    <option value="ASC" <?= $sort_value == 'ASC' ? 'selected' : ''?>>正序</option>
                    <option value="DESC" <?= $sort_value == 'DESC' ? 'selected' : ''?>>倒序</option>
                </select>
                <input type="button" class="act_btn" id="search-btn" name="search-btn" value="搜索">
                <input type="button" class="act_btn" id="output-btn" name="output-btn" value="导出">
            </td>
        </tr>
    </form>
</table>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <tr>
        <td width="24" align="center" class="bg_tr">序号</td>
        <td align="center" class="bg_tr">被保险人</td>
        <td align="center" class="bg_tr">保单号</td>
        <td align="center" class="bg_tr">保险公司</td>
        <td align="center" class="bg_tr">级别</td>
        <td align="center" class="bg_tr">提单日期</td>
        <td align="center" class="bg_tr">出单日期</td>
        <td align="center" class="bg_tr">起保日期</td>
        <td align="center" class="bg_tr">终保日期</td>
        <td align="center" class="bg_tr">总保费</td>
        <td align="center" class="bg_tr">手续费比例</td>
        <td align="center" class="bg_tr">应得金额</td>
        <td align="center" class="bg_tr">回款金额</td>
        <td align="center" class="bg_tr">回款差额</td>
        <td align="center" class="bg_tr">回款日期</td>
        <td align="center" class="bg_tr">编辑</td>
    </tr>
    <?php
    foreach($items as $index => $item) {
        $start_index = ($page-1)*20+$index;
        $order = $item->order;
        $users=$item->user->group;
        $username=$item->user;
        $uname=$username['name'];
        $nams=$users['name'];


        ?>
        <tr style="height:24px;" onMouseOver="overColor(this)" onMouseOut="outColor(this)">
            <td align="center" class="td_bg" nowrap><?=$start_index+1?></td>
            <td align="center" class="td_bg" nowrap><?=$item->id_man?></td>
            <td align="center" class="td_bg" nowrap><?=$item->insurer_no?></td>
            <td align="center" class="td_bg" nowrap>人保</td>
            <td align="center" class="td_bg" nowrap><?=$uname?>-<?=$nams?></td>
            <td align="center" class="td_bg" nowrap><?=$order ? $order->submit_date : ''?></td>
            <td align="center" class="td_bg" nowrap><?=$order ? $order->print_date : ''?></td>
            <td align="center" class="td_bg" nowrap><?=$order ? $order->insurer_date_start : ''?></td>
            <td align="center" class="td_bg" nowrap><?=$order ? $order->insurer_date_end : ''?></td>
            <td align="center" class="td_bg" nowrap><?=$item->total?></td>
            <td align="center" class="td_bg" nowrap><?=$item->total_rate?></td>
            <td align="center" class="td_bg" nowrap><?=$item->total_real?></td>
            <td align="center" class="td_bg" nowrap><?=$item->r_total?></td>
            <td align="center" class="td_bg" nowrap><?=$item->total_dis?></td>
            <td align="center" class="td_bg" nowrap><?=$item->r_date?></td>
            <td align="center" class="td_bg" nowrap>
                [<a href="javascript:void(0);" onclick="edit(<?=$item->id?>)">维护</a>]
            </td>
        </tr>
        <?php
    }
    ?>
    <tr>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap><?=number_format($sum_total,2)?></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap><?=number_format($sum_r_total,2)?></td>
        <td align="center" class="td_bg" nowrap><?=number_format($sum_total_dis,2)?></td>
        <td align="center" class="td_bg" nowrap></td>
        <td align="center" class="td_bg" nowrap></td>

    </tr>
    <tr>
        <td height="25" colspan="16" align="center" class="td_bg"><?=$page_info?></td>
    </tr>
</table>
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/datepicker/WdatePicker.js"></script>
<script type="text/javascript" language="javascript" src="/js/fileupload/js/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" language="javascript" src="/js/fileupload/js/jquery.iframe-transport.js"></script>
<script type="text/javascript" language="javascript" src="/js/fileupload/js/jquery.fileupload.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<script type="text/javascript" language="javascript">
    //编辑
    function edit(id) {
        var params = $('#searchForm').serialize();
        window.location.href = '/finance/non-receipt-info?id=' + id + '&back_params=' + encodeURIComponent(params);
    }

    $(function () {
        //上传按钮
        $('#upload-btn').click(function(){
            $('#fileupload').click();
        });

        //提交按钮
        $("#submit-btn").click(function(){
            if(confirm('是否确认提交?')) {
                var urlfile = $("#urlfile").val();
                var import_type = $(".import_type").val();

                if(urlfile == ''){
                    alert('请先选择文件！');
                    return false;
                }
                var last_url = '/finance/receipt-process';
                var params = $("#theFrm").serialize();

                $.post(last_url,params,function(obj){
                    alert(obj.msg);
                    if(obj.success){
                        $('#theFrm')[0].reset();
                        window.location.reload();
                    }
                },'json');
            }
        });
        //上传
        $('#fileupload').fileupload({
            url: '/finance/receipt-upload',
            dataType: 'json',
            done: function (e, data) {
                var file_info = data.result.files[0];
                $('#urlfile').val(file_info.url);
                $('#submit-btn').removeAttr('disabled');
            }
        });
        //搜索
        $("#search-btn").click(function(){
            $('#page').val(0);
            var params = $('#searchForm').serialize();
            window.location.href = "/finance/non-receipt?" + params;
        });
        //导出
        $("#output-btn").click(function(){
            $('#page').val(0);
            var params = $('#searchForm').serialize();
            window.location.href = "/finance/non-receipt-output?" + params;
        });
    })
</script>
<style>
    input[type="text"] {
        width: 134px;
    }

</style>