<?php
use \common\libs\MyLib;
?>
<?php $this->beginBlock('header_css'); ?>
<link href="/assets/css/plugins/iCheck/custom.css" rel="stylesheet">
<?php $this->endBlock(); ?>

<div class="wrapper wrapper-content animated fadeInRight">
    <form role="form" class="form-horizontal data-from" id="theFrm">
        <input type="hidden" name="id" value="<?=$pay_info->id?>">
        <input type="hidden" name="pay_chexian" value="<?=$pay_chexian?>">
        <input type="hidden" name="pay_dz" value="<?=$pay_dz?>">
        <input type="hidden" name="pay_date" value="<?=$pay_date?>">
        <input type="hidden" name="user_id" value="<?=$user_info->id?>">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>提成工资</h5>
            </div>
            <div class="ibox-content">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">职务</label>
                            <div class="col-sm-3">
                                <label class="form-control-static"><?=$user_info->group?$user_info->group->getPath():''?></label>
                            </div>
                            <label class="col-sm-1 control-label">姓名</label>
                            <div class="col-sm-3">
                                <label class="form-control-static"><?=$user_info->getShowName()?></label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">保单提成</label>
                            <div class="col-sm-3">
                                <label class="form-control-static"><?=$pay_chexian?></label>
                            </div>
                            <label class="col-sm-1 control-label">团队长提成</label>
                            <div class="col-sm-3">
                                <label class="form-control-static"><?=$pay_dz?></label>
                            </div>
                            <label class="col-sm-1 control-label">合计</label>
                            <div class="col-sm-3">
                                <label class="form-control-static"><?=$pay_chexian + $pay_dz?></label>
                            </div>
                        </div>
                        <?php if($pay_info->status_id < 4 || $pay_info->status_id == 8) { ?>
                            <div>
                                <div class="row">
                                    <div class="col-sm-5 col-sm-offset-5">
                                        <button class="btn btn-primary btn-save" type="button">
                                            <strong>保 存</strong>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>保单提成</h5>
            </div>
            <div class="ibox-content">
                <div class="row">
                    <div class="col-sm-12">
                        <?php if($my_type1_query->count() > 0) { ?>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th colspan="13">我的新保</th>
                                </tr>
                                <tr>
                                    <th>序号</th>
                                    <th>车牌号</th>
                                    <th>正本日期</th>
                                    <th>商业净保费</th>
                                    <th>加点比例</th>
                                    <th>基本比例</th>
                                    <th>应提金额</th>
                                    <!--            <td height="25" align="center" class="bg_tr">原新保提成</td>-->
                                    <th>减免金额</th>
                                    <th>自费礼品</th>
                                    <th>自费礼券</th>
                                    <th>业务自付</th>
                                    <th>实提金额</th>
                                    <th>详情</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $should_pay = 0;
                                $real_pay = 0;
                                $total1_clear = 0;
                                $total1_dis = 0;
                                $ticket_all = 0;
                                $gift_all = 0;
                                $zifu_all = 0;
                                foreach($my_type1_query->each() as $index=>$pay_order) {
                                    $order_info = $pay_order->order;
                                    $caiwu_info = $order_info->caiwu;//carwuordert
                                    $money = $caiwu_info->money1;
                                    $ticket = $order_info->getGiftPrice(1,1);
                                    $gift = $order_info->getGiftPrice(1,0);
                                    $should_pay += $pay_order->should_pay;
                                    $real_pay += $pay_order->real_pay;
                                    $total1_clear += $order_info->total1_clear;
                                    $total1_dis += $order_info->total1_dis;
                                    $ticket_all += $ticket;
                                    $gift_all += $gift;
                                    if($order_info->yuangong_money > 0){
                                        $zifu_all += $order_info->yuangong_money;
                                    }
                                    ?>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="tc_my_payids_1[]" value="<?=$pay_order->id?>">
                                            <?=$index+1?>
                                        </td>
                                        <td><?=$order_info->car_no?></td>
                                        <td><?=$order_info->print_date?></td>
                                        <td><?=$order_info->total1_clear?></td>

                                        <td><?=$caiwu_info->ticheng_zong_rate?></td>
                                        <td><?=$caiwu_info->yeji_rate?></td>
                                        <td><?=$pay_order->should_pay?></td>
                                        <td><?=$order_info->total1_dis?></td>
                                        <td><a href="javascript:void(0);" onclick="open_gift_dlg(<?=$order_info->id?>,1,1)"><?=$ticket?></a></td>
                                        <td><a href="javascript:void(0);" onclick="open_gift_dlg(<?=$order_info->id?>,1,0)"><?=$gift?></a></td>
                                        <td><?=$order_info->yuangong_money?></td>
                                        <td><?=$pay_order->real_pay?></td>
                                        <td>[<a href="/insurer/info?id=<?=$order_info->id?>" target="_blank">详情</a>]</td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><?=number_format($total1_clear,2)?></td>
                                    <td></td>
                                    <td></td>
                                    <td><?=number_format($should_pay,2)?></td>
                                    <td><?=number_format($total1_dis,2)?></td>
                                    <td><?=number_format($ticket_all,2)?></td>
                                    <td><?=number_format($gift_all,2)?></td>
                                    <td><?=number_format($zifu_all,2)?></td>
                                    <td><?=number_format($real_pay,2)?></td>
                                    <td></td>
                                </tr>
                                </tfoot>
                            </table>
                        <?php } ?>
                        <?php if($my_type3_query->count() > 0) { ?>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th colspan="13">我的续保</th>
                                </tr>
                                <tr>
                                    <th>序号</th>
                                    <th>车牌号</th>
                                    <th>正本日期</th>
                                    <th>商业净保费</th>
                                    <th>加点比例</th>
                                    <th>基本比例</th>
                                    <th>应提金额</th>
                                    <th>优惠金额</th>
                                    <th>自费礼品</th>
                                    <th>自费礼券</th>
                                    <th>自付减免</th>
                                    <th>实提金额</th>
                                    <th>详情</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $should_pay = 0;
                                $real_pay = 0;
                                $total1_clear = 0;
                                $total1_dis = 0;
                                $ticket_all = 0;
                                $gift_all = 0;
                                $zifu_all = 0;
                                foreach($my_type3_query->each() as $index=>$pay_order) {
                                    $order_info = $pay_order->order;
                                    $caiwu_info = $order_info->caiwu;//carwuordert
                                    $money = $caiwu_info->money1;
                                    $ticket = $order_info->getGiftPrice(1,1);
                                    $gift = $order_info->getGiftPrice(1,0);
                                    $should_pay += $pay_order->should_pay;
                                    $real_pay += $pay_order->real_pay;
                                    $total1_clear += $order_info->total1_clear;
                                    $total1_dis += $order_info->total1_dis;
                                    $ticket_all += $ticket;
                                    $gift_all += $gift;
                                    if($order_info->yuangong_money > 0){
                                        $zifu_all += $order_info->yuangong_money;
                                    }

                                    ?>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="tc_my_payids_1[]" value="<?=$pay_order->id?>">
                                            <?=$index+1?>
                                        </td>
                                        <td><?=$order_info->car_no?></td>
                                        <td><?=$order_info->print_date?></td>
                                        <td><?=$order_info->total1_clear?></td>

                                        <td><?=$caiwu_info->ticheng_zong_rate?></td>
                                        <td><?=$caiwu_info->yeji_rate?></td>
                                        <td><?=$pay_order->should_pay?></td>
                                        <td><?=$order_info->total1_dis?></td>
                                        <td><a href="javascript:void(0);" onclick="open_gift_dlg(<?=$order_info->id?>,1,1)"><?=$order_info->getGiftPrice(1,1)?></a></td>
                                        <td><a href="javascript:void(0);" onclick="open_gift_dlg(<?=$order_info->id?>,1,0)"><?=$order_info->getGiftPrice(1,0)?></a></td>
                                        <td><?=$order_info->yuangong_money?></td>
                                        <td><?=$pay_order->real_pay?></td>
                                        <td>[<a href="/insurer/info?id=<?=$order_info->id?>" target="_blank">详情</a>]</td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><?=number_format($total1_clear,2)?></td>
                                    <td></td>
                                    <td></td>
                                    <td><?=number_format($should_pay,2)?></td>
                                    <td><?=number_format($total1_dis,2)?></td>
                                    <td><?=number_format($ticket_all,2)?></td>
                                    <td><?=number_format($gift_all,2)?></td>
                                    <td><?=number_format($zifu_all,2)?></td>
                                    <td><?=number_format($real_pay,2)?></td>
                                    <td></td>
                                </tr>
                                </tfoot>
                            </table>
                        <?php } ?>
                        <?php if($my_type0_query->count() > 0) { ?>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th colspan="9">我的原新保</th>
                                </tr>
                                <tr>
                                    <th>序号</th>
                                    <th>车牌号</th>
                                    <th>正本日期</th>
                                    <th>商业净保费</th>
                                    <th>基本比例</th>
                                    <th>应提金额</th>
                                    <th>原新保提成</th>
                                    <th>实提金额</th>
                                    <th>详情</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $should_pay = 0;
                                $real_pay = 0;
                                $total1_clear = 0;
                                $total1_dis = 0;
                                foreach($my_type0_query->each() as $index=>$pay_order) {
                                    $order_info = $pay_order->order;
                                    $caiwu_info = $order_info->caiwu;//carwuordert
//                            $money = $caiwu_info->money1;
                                    $should_pay += $pay_order->should_pay;
                                    $real_pay += $pay_order->real_pay;
                                    $total1_clear += $order_info->total1_clear;
//                            $total1_dis += $order_info->total1_dis;
                                    ?>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="tc_my_payids_1[]" value="<?=$pay_order->id?>">
                                            <?=$index+1?>
                                        </td>
                                        <td><?=$order_info->car_no?></td>
                                        <td><?=$order_info->print_date?></td>
                                        <td><?=$order_info->total1_clear?></td>

                                        <td><?=$caiwu_info->first_xinbao_rate?></td>
                                        <td><?=$pay_order->should_pay?></td>
                                        <td><?=$pay_order->first_xinbao_ticheng?></td>
                                        <td><?=$pay_order->real_pay?></td>
                                        <td>[<a href="/insurer/info?id=<?=$order_info->id?>" target="_blank">详情</a>]</td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><?=number_format($total1_clear,2)?></td>
                                    <td></td>
                                    <td><?=number_format($should_pay,2)?></td>
                                    <td></td>
                                    <td><?=number_format($real_pay,2)?></td>
                                    <td></td>
                                </tr>
                                </tfoot>
                            </table>
                        <?php } ?>

                        <!--    内勤核保-->

                        <?php if($my_type5_query->count() > 0) { ?>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th colspan="7">核保统计</th>
                                </tr>
                                <tr>
                                    <th>序号</th>
                                    <th>车牌号</th>
                                    <th>正本日期</th>
                                    <th>被保险人</th>
                                    <th>核保比例</th>
                                    <th>核保提成</th>
                                    <th>详情</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $real_pay = 0;
                                foreach($my_type5_query->each() as $index=>$pay_order) {
                                    $order_info = $pay_order->order;
                                    $caiwu_info = $order_info->caiwu;
                                    $rate = $caiwu_info->hebao_ticheng;
//                $money = $caiwu_info->money4;
                                    $send_info = $order_info->sendLog;
                                    $real_pay += $pay_order->real_pay;
                                    ?>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="neqi_payids[]" value="<?=$pay_order->id?>">
                                            <?=$index+1?>
                                        </td>
                                        <td><?=$order_info->car_no?></td>
                                        <td><?=$order_info->print_date?></td>
                                        <td><?=MyLib::substr_cut($order_info->id_man,15)?></td>
                                        <td><?=$rate?>元</td>
                                        <td><?=$pay_order->real_pay?>元</td>
                                        <td>[<a href="/insurer/info?id=<?=$order_info->id?>" target="_blank">详情</a>]</td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><?=number_format($real_pay,2)?></td>
                                    <td></td>
                                </tr>
                                </tfoot>
                            </table>
                        <?php } ?>

                        <!--    内勤正本-->
                        <?php if($my_type6_query->count() > 0) { ?>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th colspan="7">正本统计</th>
                                </tr>
                                <tr>
                                    <th>序号</th>
                                    <th>车牌号</th>
                                    <th>正本时间</th>
                                    <th>被保险人</th>
                                    <th>正本比例</th>
                                    <th>正本提成</th>
                                    <th>详情</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $real_pay = 0;
                                foreach($my_type6_query->each() as $index=>$pay_order) {
                                    $order_info = $pay_order->order;
                                    $caiwu_info = $order_info->caiwu;
                                    $rate = $caiwu_info->zhengben_ticheng;
                                    $send_info = $order_info->sendLog;
                                    $real_pay += $pay_order->real_pay;
                                    ?>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="zhengben[]" value="<?=$pay_order->id?>">
                                            <?=$index+1?>
                                        </td>
                                        <td><?=$order_info->car_no?></td>
                                        <td><?=$order_info->print_date?></td>
                                        <td><?=MyLib::substr_cut($order_info->id_man,15)?></td>
                                        <td><?=$rate?>元</td>
                                        <td><?=$pay_order->real_pay?></td>
                                        <td>[<a href="/insurer/info?id=<?=$order_info->id?>" target="_blank">详情</a>]</td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><?=number_format($real_pay,2)?></td>
                                    <td></td>
                                </tr>
                                </tfoot>
                            </table>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<?php $this->beginBlock('footer_js'); ?>
<script type="text/javascript" language="javascript">
    $(function () {
        $('.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });
        //提交按钮
        $(".btn-save").click(function(){
            parent.layer.confirm('是否确认提交？', {
                btn: ['确认','取消'], //按钮
                shade: false //不显示遮罩
            }, function(){
                var params = $("#theFrm").serialize();
                $.post('/finance/chuna-gongzi-save',params,function(obj){
                    if(obj.success) {
                        parent.layer.msg('保存成功');
                        parent.refreshList();
                        layer_close();
                    } else {
                        parent.layer.msg(data.msg);
                    }
                },'json');
            }, function(){
                //
            });
        });
    })
</script>
<?php $this->endBlock('footer_js'); ?>
