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

//获取上个月日期
$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,surface_pass,surface_no,sort0_pass,sort0_no,sort1_pass,sort1_no,sort2_pass,sort2_no,remark_pass,remark_no from admin_house_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]['surface_total'] = $val['surface_pass'] + $val['surface_no'];
		$data_info[$key]['surface_perc'] = $data_info[$key]['surface_total'] ? ceil(($val['surface_pass']/$data_info[$key]['surface_total'])*100) : 0;

		$data_info[$key]['sort0_total'] = $val['sort0_pass'] + $val['sort0_no'];
		$data_info[$key]['sort0_perc'] = $data_info[$key]['sort0_total'] ? ceil(($val['sort0_pass']/$data_info[$key]['sort0_total'])*100) : 0;

		$data_info[$key]['sort1_total'] = $val['sort1_pass'] + $val['sort1_no'];
		$data_info[$key]['sort1_perc'] = $data_info[$key]['sort1_total'] ? ceil(($val['sort1_pass']/$data_info[$key]['sort1_total'])*100) : 0;

		$data_info[$key]['sort2_total'] = $val['sort2_pass'] + $val['sort2_no'];
		$data_info[$key]['sort2_perc'] = $data_info[$key]['sort2_total'] ? ceil(($val['sort2_pass']/$data_info[$key]['sort2_total'])*100) : 0;

		$data_info[$key]['remark_total'] = $val['remark_pass'] + $val['remark_no'];
		$data_info[$key]['remark_perc'] = $data_info[$key]['remark_total'] ? ceil(($val['remark_pass']/$data_info[$key]['remark_total'])*100) : 0;
	}
}


//下载报表
if($actiontype == 'exportcsv'){
	$data = $lastym."月,封面图质检通过率,室内图质检通过率,户型图质检通过率,外景图质检通过率，描述图质检通过率
	";

	if(is_array($data_info) && !empty($data_info)){
		foreach($data_info as $key=>$val){
			$surface_perc = $val['surface_perc'] ?  $val['surface_perc'].'%' : '--';
			$sort0_perc = $val['sort0_perc'] ?  $val['sort0_perc'].'%' : '--';
			$sort1_perc = $val['sort1_perc'] ?  $val['sort1_perc'].'%' : '--';
			$sort2_perc = $val['sort2_perc'] ?  $val['sort2_perc'].'%' : '--';
			$remark_perc = $val['remark_perc'] ?  $val['remark_perc'].'%' : '--';
			$data .= $val['admin'].','.$surface_perc.','.$sort2_perc.','.$sort0_perc.','.$sort1_perc.','.$remark_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("house_statistic/daily_qa_audit"));
include_once(Template("footer"));