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

//获取上个月日期
$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"];
 
 
//获取个人房源审核质检结果
$sql = "SELECT  dateline,sum(surface_pass) as surface_pass,sum(surface_no) as surface_no,sum(sort0_pass) as sort0_pass,sum(sort0_no) as sort0_no,sum(sort1_pass) as sort1_pass,sum(sort1_no) as sort1_no,sum(sort2_pass) as sort2_pass,sum(sort2_no) as sort2_no,sum(remark_pass) as remark_pass,sum(remark_no) as remark_no FROM `admin_house_qa_stat` WHERE dateline >='".$begin_date."' and dateline <='".$end_date."'   and admin='".$adminName."' group by dateline;";
$data_info = $dbback->GetAll($sql);
 // print_r($sql);die;
if(is_array($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 ;
	}
}
 // print_r($data_info);die;


//下载报表
if($actiontype == 'exportcsv'){
	$data = "日期,封面质检量,封面不通过量,封面通过率,室内质检量,室内不通过量,室内通过率,户型质检量,户型不通过量,户型通过率,外景质检量,外景不通过量,外景通过率,描述质检量,描述不通过量,描述通过率
	";
	if(is_array($data_info) && !empty($data_info)){
		foreach($data_info as $key=>$val){
			$surface_perc = $data_info[$key]['surface_perc'] ?  $data_info[$key]['surface_perc'].'%' : '--';
			$sort0_perc = $data_info[$key]['sort0_perc'] ?  $data_info[$key]['sort0_perc'].'%' : '--';
			$sort1_perc = $data_info[$key]['sort1_perc'] ?  $data_info[$key]['sort1_perc'].'%' : '--';
			$sort2_perc = $data_info[$key]['sort2_perc'] ?  $data_info[$key]['sort2_perc'].'%' : '--';
			$remark_perc = $data_info[$key]['remark_perc'] ?  $data_info[$key]['remark_perc'].'%' : '--';

			$data .= $val['dateline'].','.$val['surface_total'].','.$val['surface_no'].','.$surface_perc.','.$val['sort2_total'].','.$val['sort2_no'].','.$sort2_perc.','.$val['sort0_total'].','.$val['sort0_no'].','.$sort0_perc.','.$val['sort1_total'].','.$val['sort1_no'].','.$sort1_perc.','.$val[' remark_total'].','.$val['remark_no'].','.$remark_perc.',
			';
		}
	}
 //print_r($data_info);die;
	$mime_type = 'text/x-csv';
	header('Content-Type: ' . $mime_type);
    header("Content-Disposition: attachment; filename=我的单日房源图片质检报表".$adminName."-".$lastym.".csv");
    $actiontype = '';
    echo $data;
    exit();
}

 //引用模版文件
include_once(Template("header"));
include_once(Template("house_statistic/my_qa"));
include_once(Template("footer"));