<?php
use \common\libs\MyLib;
?>


<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="account_status">
                    <option value=''>全部</option>
                    <option value=1 <?=$account_status==1?'selected':'' ?>>已对账未支付</option>
                    <option value=2 <?= $account_status==2?'selected':'' ?>>已对账已支付</option>
                </select>


<!--                收款人：<select name="payee_id" id="payee_id" style="width:100px;">-->
<!--                    <option value="">全部</option>-->
<!--                    --><?php
//                    foreach($payee_items as $item) {
//                        echo '<option value="'.$item->id.'"';
//                        if($item->id == $payee_id)
//                            echo ' selected ';
//                        echo '>'.$item->name.'</option>';
//                    }
//                    ?>
<!--                </select>-->
                收款方式：<select name="payment_id" id="payment_id" style="width:100px;">
                    <option value="">全部</option>
                    <?php
                    foreach($payment_items as $item) {
                        echo '<option value="'.$item->id.'"';
                        if($item->id == $payment_id)
                            echo ' selected ';
                        echo '>'.$item->name.'</option>';
                    }
                    ?>
                </select>
                保单号：<input name="insurer_no" type="text" value="<?=$insurer_no?>">
                车牌：<input name="car_no" type="text" value="<?=$car_no?>">
                <!--日期-->
                出单日期：
                <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 ?>" />

                保险公司：<select name="company_id">
                    <option value="0">所有模型</option>
                    <?php
                    foreach($company_items as $item) {
                        echo '<option value="'.$item->id.'"';
                        if($item->id == $company_id)
                            echo ' selected ';
                        echo '>'.$item->name.'</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>
                级别：<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>

                <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>
        <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'];

        $total_real1 = $item->total1 * $item->total1_rate/100;
        $total_real2 = $item->total2 * $item->total2_rate/100;
        $total_clear_real1 = $item->total1_clear * $item->total1_rate/100;
        $total_clear_real2 = $item->total2_clear * $item->total2_rate/100;
//        $total_dis = round($total_clear_real - $item->r_total,2);
        ?>
        <tr style="height:24px;" >
            <td align="center" class="td_bg" nowrap><?=$start_index+1?></td>
            <td align="center" class="td_bg" nowrap><?=$item->car_no?></td>
            <td align="center" class="td_bg" nowrap><?=$item->id_man?></td>
            <td align="center" class="td_bg" nowrap><?=$item && $item->company ?mb_substr($item->company->name, 0, 4, 'utf-8'):''?></td>
            <td align="center" class="td_bg" nowrap><?=$uname?>-<?=$nams?></td>

            <td align="center" class="td_bg" nowrap><?=$item->shoufei_id?MyLib::zhifufs($item->shoufei_id).'-':''?><?=$item->payType?$item->payType->name:''?></td>
            <td align="center" class="td_bg" nowrap><?=$item->payee_id?$item->payee->name:''?></td>
            <td align="center" class="td_bg" nowrap><?=$item->payment_id?$item->payment->name:''?></td>
            <td align="center" class="td_bg" nowrap><?=$item && $item->payer? MyLib::payers($item->payer):''?></td>
            <td align="center" class="td_bg tits" nowrap limit="5"><?=$item->insurer1_no?$item->insurer1_no:''?></td>
            <td align="center" class="td_bg tits" nowrap limit="5"><?=$item->insurer2_no?$item->insurer2_no:''?></td>

            <td align="center" class="td_bg" nowrap><?=$item ? $item->zhifu_date : ''?></td>
            <td align="center" class="td_bg" nowrap><?=$item ? $item->print_date : ''?></td>

            <td align="center" class="td_bg" nowrap><?=$item->total1?></td>

            <td align="center" class="td_bg" nowrap><?=$item->total2?></td>

            <td align="center" class="td_bg" nowrap><?=$item->total1_rate?></td>
            <td align="center" class="td_bg" nowrap><?=$item->total2_rate?></td>
            <td align="center" class="td_bg" nowrap><?=sprintf("%.2f",$total_real1)?></td>
            <td align="center" class="td_bg" nowrap><?=sprintf("%.2f",$total_real2)?></td>
            <td align="center" class="td_bg" nowrap><?=$item->account_status?MyLib::duizhang($item->account_status):''?></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></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><?=number_format($sum_total1,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><?=$items?number_format($sum_total2,2):0?></td>
        <td align="center" class="td_bg" nowrap><?=$items?number_format($sum_total3,2):0?></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>-->
    </tr>
    <tr >
        <td height="25" colspan="30" 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/receipt-ad-edit?id=' + id + '&back_params=' + encodeURIComponent(params);
    }
    jQuery.fn.limit=function(){
        var self = $(".tits");
        self.each(function(){
            var objString = $(this).text();
            var objLength = $(this).text().length;
            var num = $(this).attr("limit");
            // console.log(num);
            if(objLength > num){
                $(this).attr("title",objString);
                $(this).attr("titles",objString.substring(0,num) + "..");
                objString = $(this).text(objString.substring(0,num) + "..");
            } })
    }
    $(function () {
        //上传按钮
//        $('#upload-btn').click(function(){
//            $('#fileupload').click();
//        });
        $(document.body).limit();

//        $(".tits").dblclick(function(){
//            var yz=$(this).html();
//            var tit=$(this).attr('title');
//
//            $(this).html(tit)
//        })
        $(".td_bg").click(function(){
//            alert(2)
            var yz=$(this).attr('titles');
            var tit=$(this).attr('title');
            $(this).toggleClass('tits');
            if($(this).hasClass('tits')){
                $(this).html(yz)
            }else{
                $(this).html(tit)
            }
        });

        //搜索
        $("#search-btn").click(function(){
            $('#page').val(0);
            var params = $('#searchForm').serialize();
            window.location.href = "/finance/receipt-ad?" + params;
        });
        //导出
        $("#output-btn").click(function(){
            $('#page').val(0);
            var params = $('#searchForm').serialize();
            window.location.href = "/finance/receipt-ad-output?" + params;
        });
    })
</script>
<style>
    input[type="text"] {
        width: 134px;
    }

</style>