<?php
use \common\libs\MyLib;
use \common\models\CaiwuT;
use \common\models\OrderGiftT;
?>
<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/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<script type="text/javascript" language="javascript">
    $(function(){
        $("#search-btn").click(function(){
            $('#page').val(0);
            var params = $('#searchForm').serialize();
            window.location.href = "/finance/caiwu-tj-list?" + params;
        });
        $('#searchForm').submit(function(){
            $('#search-btn').click();
            return false;
        });
    });


</script>
<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="date_type">
                    <option value="1" <?=$data_type==1?'selected':''?>>正本日期</option>
                    <option value="2" <?=$data_type==2?'selected':''?>>回款日期</option>
                    <option value="3" <?=$data_type==3?'selected':''?>>退款日期</option>
                </select>
                <input name="record_s_date" id="record_s_date" class="Wdate" type="text" value="<?=$record_s_date?>" onClick="WdatePicker()">
                -
                <input name="record_e_date" id="record_e_date" class="Wdate" type="text" value="<?=$record_e_date?>" onClick="WdatePicker()">
                <select name="type">
                    <option value="0" <?=$type==0?'selected':''?>>全部</option>
                    <option value="1" <?=$type==1?'selected':''?>>商业</option>
                    <option value="2" <?=$type==2?'selected':''?>>交强</option>
                    <option value="3" <?=$type==3?'selected':''?>>退款</option>
                </select>
                保险公司：<select name="company_id">
                    <option value="0">全部</option>
                    <?php
                    foreach($company_items as $item) {
                        echo '<option value="'.$item->id.'">'.$item->name.'</option>';
                    }
                    ?>
                </select>
                车牌号：<input typeof="text" name="car_no" value="<?=$car_no?>" style="width:100px;">
                保单号：<input typeof="text" name="insurer_no" value="<?=$insurer_no?>" style="width:100px;">
                座席工号：<input typeof="text" name="userid" value="<?=$userid?>" style="width:100px;">
                待摊费用：<input typeof="text" name="zc_rate" value="<?=$zc_rate?>" style="width:50px;">%
                <input type="submit" class="act_btn" id="search-btn" name="search-btn" value="搜索">
            </td>
        </tr>
    </form>
</table>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <tr>
        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
        <td align="center" class="bg_tr" nowrap>座席工号</td>
        <td align="center" class="bg_tr" nowrap>车牌号</td>
        <td align="center" class="bg_tr" nowrap>提单日期</td>
        <td align="center" class="bg_tr" nowrap>出单日期</td>
        <td align="center" class="bg_tr" nowrap>保险公司</td>
        <td align="center" class="bg_tr" nowrap>保单号</td>
        <td align="center" class="bg_tr" nowrap>类型</td>
        <td align="center" class="bg_tr" nowrap>总保费（退保保费）</td>
        <td align="center" class="bg_tr" nowrap>净保费</td>
        <td align="center" class="bg_tr" nowrap>手续费比例</td>
        <td align="center" class="bg_tr" nowrap>应得金额</td>
        <td align="center" class="bg_tr" nowrap>应回金额（退保手续费）</td>
        <td align="center" class="bg_tr" nowrap>税差</td>
        <td align="center" class="bg_tr" nowrap>已回金额</td>
        <td align="center" class="bg_tr" nowrap>回款差额</td>
        <td align="center" class="bg_tr" nowrap>优惠款</td>
        <td align="center" class="bg_tr" nowrap>新保提成</td>
        <td align="center" class="bg_tr" nowrap>续保提成</td>
        <td align="center" class="bg_tr" nowrap>核保提成</td>
        <td align="center" class="bg_tr" nowrap>送单提成</td>
        <td align="center" class="bg_tr" nowrap>正本提成</td>
        <td align="center" class="bg_tr" nowrap>待摊费用</td>
        <td align="center" class="bg_tr" nowrap>礼券</td>
        <td align="center" class="bg_tr" nowrap>礼品</td>
        <td align="center" class="bg_tr" nowrap>净利</td>
        <td align="center" class="bg_tr" nowrap>回款（退保）日期</td>
        <td align="center" class="bg_tr" nowrap>更多</td>
    </tr>
        <?php
        foreach($items as $index => $item) {
            $order_info = $item->order;
            $order_caiwu_info = $order_info->caiwu;
            ?>
            <tr onMouseOver=overColor(this) onMouseOut=outColor(this)>
                <td width="50" align="center" class="td_bg" nowrap><?=$index+1?></td>
                <td align="center" class="td_bg" nowrap><?=$order_info->user?$order_info->user->username:''?></td>
                <td align="center" class="td_bg" nowrap><?=$order_info->car_no?></td>
                <td align="center" class="td_bg" nowrap><?=$order_info->submit_date?></td>
                <td align="center" class="td_bg" nowrap><?=$order_info->print_date?></td>
                <td align="center" class="td_bg" nowrap><?=$order_info->company?$order_info->company->name:''?></td>
                <td align="center" class="td_bg" nowrap><?=$item->insurer_no?></td>
                <?php
                if($item->insurer_type == 1) {
                    $tmp_items = OrderGiftT::find()
                        ->where('order_id='.$order_info->id)
                        ->all();
                    $tc_total = 0;
                    if($order_caiwu_info)
                        $tc_total = round($order_caiwu_info->money1 + $order_caiwu_info->money2 + $order_caiwu_info->money3 + $order_caiwu_info->send_money + $order_caiwu_info->money4 + $order_caiwu_info->money5 - $order_info->total1_dis,2);
                    $jl_total = round($item->r_total - $order_info->total1_dis - $tc_total - ($item->total_clear * $zc_rate / 100),2);
                    ?>
                    <td align="center" class="td_bg" nowrap><?='商业'?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total_clear?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total_rate.'%'?></td>
                    <td align="center" class="td_bg" nowrap><?=round($item->total * $item->total_rate/100,2)?></td>
                    <td align="center" class="td_bg" nowrap><?=round($item->total_clear * $item->total_rate/100,2)?></td>
                    <td align="center" class="td_bg" nowrap><?=round(($item->total-$item->total_clear) * $item->total_rate/100,2)?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->r_total?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total_dis>0?$item->total_dis:''?></td>
                    <td align="center" class="td_bg" nowrap><?=$order_info->total1_dis>0?$order_info->total1_dis:''?></td>
                    <td align="center" class="td_bg" nowrap><?=$order_caiwu_info && $order_caiwu_info->money1>0?($order_caiwu_info->money3>0?$order_caiwu_info->money1:$order_caiwu_info->money1-$order_info->total1_dis):''?></td>
                    <td align="center" class="td_bg" nowrap><?=$order_caiwu_info && $order_caiwu_info->money3>0?$order_caiwu_info->money3-$order_info->total1_dis:''?></td>
                    <td align="center" class="td_bg" nowrap><?=$order_caiwu_info && $order_caiwu_info->money4>0?$order_caiwu_info->money4:''?></td>
                    <td align="center" class="td_bg" nowrap><?=$order_caiwu_info && $order_caiwu_info->send_money>0?$order_caiwu_info->send_money:''?></td>
                    <td align="center" class="td_bg" nowrap><?=$order_caiwu_info && $order_caiwu_info->money5>0?$order_caiwu_info->money5:''?></td>
                    <td align="center" class="td_bg" nowrap><?=$zc_rate>0?$zc_rate.'%':''?></td>
                    <td align="center" class="td_bg" nowrap></td>
                    <td align="center" class="td_bg" nowrap></td>
                    <td align="center" class="td_bg" nowrap><?=$jl_total?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->r_date?></td>
                    <?php
                } else {
                    $jl_total = round($item->r_total - ($item->total_clear * $zc_rate / 100),2);
                    ?>
                    <td align="center" class="td_bg" nowrap><?='交强'?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total_clear?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total_rate.'%'?></td>
                    <td align="center" class="td_bg" nowrap><?=round($item->total * $item->total_rate/100,2)?></td>
                    <td align="center" class="td_bg" nowrap><?=round($item->total_clear * $item->total_rate/100,2)?></td>
                    <td align="center" class="td_bg" nowrap><?=round(($item->total-$item->total_clear) * $item->total_rate/100,2)?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->r_total?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->total_dis>0?$item->total_dis:''?></td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap><?=$zc_rate>0?$zc_rate.'%':''?></td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap>&nbsp;</td>
                    <td align="center" class="td_bg" nowrap><?=$jl_total?></td>
                    <td align="center" class="td_bg" nowrap><?=$item->r_date?></td>
                    <?php
                }
                ?>
                <td align="center" class="td_bg" nowrap>[<a href="/insurer/info?id=<?=$item->order_id?>" target="_blank">详情</a>]</td>
            </tr>
            <?php
        }
        ?>
    <tr>
        <td width="50" align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap>&nbsp;</td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_zbf'],2)?></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_jbf'],2)?></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_yd'],2)?></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_sd'],2)?></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_yd']-$totals['total_sd'],2)?></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_yhje'],2)?></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_hkce'],2)?></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_yhk'],2)?></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap><?=number_format($totals['total_jl'],2)?></td>
        <td align="center" class="bg_tr" nowrap></td>
        <td align="center" class="bg_tr" nowrap></td>
    </tr>
    <tr >
        <td height="25" colspan="30" align="center" class="td_bg"><?=$page_info?></td>
    </tr>
</table>
