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

//获取上个月日期
$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));

//  echo 465;die;

$title = "我的单日质检报表";
$adminName = $_SESSION[$web_auth]["username"];
 
 
//获取个人经纪人审核质检结果（暂不处理real房和账号）
$sql = "select id,dateline,admin,head_pass,head_no,cert_pass,cert_no  from admin_broker_qa_stat where  dateline >='".$begin_date."' and dateline <='".$end_date."'   and admin='".$adminName."'";
$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;
	}
}

//下载报表
if($actiontype == 'exportcsv'){
	$data = "日期,头像质检量,头像不通过量,头像通过率,经纪人证书质检量,经纪人证书不通过量,经纪人证书通过率,real房证书质检量,real房证书不通过量,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'].'%' : '--';
			$data .= $val['dateline'].','.$val['head_total'].','.$val['head_no'].','.$head_pass_perc.','.$val['cert_total'].','.$val['cert_no'].','.$cert_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/my_qa"));
include_once(Template("footer"));