<?php
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
include_once($conf_basedir."base.inc.php");
checkAuth('54');	//判断登录和权限

//获取上个月日期
$ym = date('Y-m');
$last_date = getMonthRange($ym);
$begin_date = $last_date[0];
$end_date = $last_date[1];
$lastym = date('Y-m',strtotime($begin_date));

//获取上个月总天数，生成日期
$day_num = substr($end_date,8,2);
$search_arr = array();
for($i=1;$i<=$day_num;$i++){
	$day = $i < 10 ? '0'.$i : $i ;
	$search_arr[$lastym.'-'.$day] = $lastym.'-'.$day;
}
$search_display = getSelect($search_arr,'search_day',$search_day);

$search_day = $search_day ? $search_day : $begin_date;

$title = "单日质检报表";
 
//获取个人经纪人审核质检结果 
$sql = "select id,dateline,admin,head_pass,head_no,cert_pass,cert_no,real_pass,real_no  from admin_broker_qa_stat where   dateline ='".$search_day."' ";
$data_info = $dbback->GetAll($sql);
 

 //对数据进行重新整理
if(is_array($data_info) && !empty($data_info)){
	foreach($data_info as $key=>$val){
		$data_info[$key]['head_total'] = $val['head_pass'] + $val['head_no'];
		$data_info[$key]['head_pass_perc'] = $data_info[$key]['head_total'] ? ceil(($val['head_pass']/$data_info[$key]['head_total'])*100) : 0;

		$data_info[$key]['cert_total'] = $val['cert_pass'] + $val['cert_no'];
		$data_info[$key]['cert_pass_perc'] = $data_info[$key]['cert_total'] ? ceil(($val['cert_pass']/$data_info[$key]['cert_total'])*100) : 0;

		$data_info[$key]['real_total'] = $val['real_pass'] + $val['real_no'];
		$data_info[$key]['real_pass_perc'] = $data_info[$key]['real_total'] ? ceil(($val['real_pass']/$data_info[$key]['real_total'])*100) : 0;
	}
}

//下载报表
if($actiontype == 'exportcsv'){
	$data = $lastym."月,头像质检通过率,经纪人证书质检通过率,real房证书质检通过率
	";

	if(is_array($data_info) && !empty($data_info)){
		foreach($data_info as $key=>$val){
			$head_pass_perc = $data_info[$key]['head_pass_perc'] ?  $data_info[$key]['head_pass_perc'].'%' : '--';
			$cert_pass_perc = $data_info[$key]['cert_pass_perc'] ?  $data_info[$key]['cert_pass_perc'].'%' : '--';
			$real_pass_perc = $data_info[$key]['real_pass_perc'] ?  $data_info[$key]['real_pass_perc'].'%' : '--';
			$data .= $val['admin'].','.$head_pass_perc.','.$cert_pass_perc.','.$real_pass_perc.'
			';
		}
	}

	$mime_type = 'text/x-csv';
	header('Content-Type: ' . $mime_type);
    header("Content-Disposition: attachment; filename=经纪人审核单日报表".$lastym.".csv");
    $actiontype = '';
    echo $data;
    exit();
}

 //引用模版文件
include_once(Template("header"));
include_once(Template("broker_statistic/daily_qa_audit"));
include_once(Template("footer"));