<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>录题工作量统计</title>
<%@ include file="../common/top.jsp"%>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />

<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/validator.js"></script>
<style>
.stat-table{border-collapse:collapse;border:none;}
.stat-table th{border:solid #c9c9c9 1px;padding:2px 2px 2px 2px;text-align: center;padding: 4px 6px 4px 6px;}
.stat-table td{border:solid #c9c9c9 1px;padding:2px 2px 2px 2px;text-align: left;padding: 4px 6px 4px 6px;}
</style>
<script type="text/javascript">
function doStat(){
	var startTime = toDate($("input[name='startTime']").val());
	var endTime = toDate($("input[name='endTime']").val());
	if(startTime == null){
		$.messager.alert('提示', "请输入正确的日期，格式：yyyy-mm-dd", 'error',function(){
			$('#startTime').datebox("showPanel");
		});
		return false;
	}
	if(endTime == null){
		$.messager.alert('提示', "请输入正确的日期，格式：yyyy-mm-dd", 'error',function(){
			$('#endTime').datebox("showPanel");
		});
		return false;
	}
	if(startTime.getTime() > endTime.getTime()){
		$.messager.alert('提示', "开始日期不能大于结束日期", 'error',function(){
			$('#startTime').datebox("showPanel");
		});
		return false;
	}
	return true;
}

function doExport(){
	var startTime = toDate($("input[name='startTime']").val());
	var endTime = toDate($("input[name='endTime']").val());
	if(startTime == null){
		$.messager.alert('提示', "请输入正确的日期，格式：yyyy-mm-dd", 'error',function(){
			$('#startTime').datebox("showPanel");
		});
		return false;
	}
	if(endTime == null){
		$.messager.alert('提示', "请输入正确的日期，格式：yyyy-mm-dd", 'error',function(){
			$('#endTime').datebox("showPanel");
		});
		return false;
	}
	if(startTime.getTime() > endTime.getTime()){
		$.messager.alert('提示', "开始日期不能大于结束日期", 'error',function(){
			$('#startTime').datebox("showPanel");
		});
		return false;
	}
	$(document).mask('正在生成报表文件，请稍等...');
	$.ajax({
		type : "POST",
		url : "${ctx}/business/exportInputStat",
		data : {
			"startTime":$("input[name='startTime']").val(),
			"endTime":$("input[name='endTime']").val()
			}, 
		success : function(res) {
			$(document).unmask();
			if(res.flag=='success'){
				$("#downloadForm").attr("action","${ctx}/attachment/download/" + res.att.id);
				$("#downloadForm").submit();
			}else{
				$.messager.alert('提示', "生成报表文件失败，原因:" + res.msg, 'error');
			}
		}
	});
	return false;
}

function toDate(str){     
    if(str.length!=0){
    	var reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/
    	var result = str.match(reg);
    	if(result != null){
    		var year = result[1] - 0;
    		var month = result[2] - 0;
    		var day = result[3] - 0;
    		var d = new Date(year, month-1, day);
            if(d.getFullYear() == year && (d.getMonth() + 1) == month && d.getDate() == day){
            	return d;
            }
    	}
	}
	return null;
}
</script>
</head>
<body style="margin: 10px;">
<div>
<form action="${ctx}/business/inputStat" method="post">
开始时间：<input type="text" name="startTime" id="startTime" class="easyui-datebox" placeholder="yyyy-mm-dd" style="width: 120px;" maxlength="10" value="${param.startTime}"/>
至
结束时间：<input type="text" name="endTime" id="endTime" class="easyui-datebox" placeholder="yyyy-mm-dd" style="width: 120px;" maxlength="10" value="${param.endTime}"/>
<input type="submit" value="统计" style="width: 80px;height: 30px;" onclick="return doStat();"/>
<input type="button" value="导出" style="margin-left:20px; width: 80px;height: 30px;" onclick="return doExport();"/>
</form>
</div>
<c:if test="${statInputQuestByCourse != null}">
<div id="tt" class="easyui-tabs" style="margin-top: 20px;">
<div title="按照课程统计结果" style="padding:10px;">
<table border="0" class="stat-table">
<tr>
	<th>课程代码</th>
	<th>课程名称</th>
	<th>题型名称</th>
	<th>数量</th>
	<th>草稿</th>
	<th>审核通过</th>
	<th>审核拒绝</th>
	<th>终审通过</th>
	<th>终审拒绝</th>
	<th>总计</th>
</tr>
<c:forEach items="${statInputQuestByCourse}" var="stat" varStatus="s">
<c:forEach items="${stat.typeNums}" var="typeNum" varStatus="status">
<tr>
<c:if test="${s.last}">
	<td colspan="4">总计：</td>
</c:if>
<c:if test="${!s.last}">
	<c:if test="${status.first}">
		<td rowspan="${fn:length(stat.typeNums)}">${stat.courseCode}</td>
		<td rowspan="${fn:length(stat.typeNums)}">${stat.courseName}</td>
	</c:if>
		<td>${typeNum.typeName}</td>
		<td style="text-align: right;">${typeNum.num}</td>
</c:if>
<c:if test="${status.first}">
	<td style="text-align: right;" rowspan="${fn:length(stat.typeNums)}">${stat.draftNum}</td>
	<td style="text-align: right;" rowspan="${fn:length(stat.typeNums)}">${stat.approvedNum}</td>
	<td style="text-align: right;" rowspan="${fn:length(stat.typeNums)}">${stat.rejectedNum}</td>
	<td style="text-align: right;" rowspan="${fn:length(stat.typeNums)}">${stat.finalApprovedNum}</td>
	<td style="text-align: right;" rowspan="${fn:length(stat.typeNums)}">${stat.finalRejectedNum}</td>
	<td style="text-align: right;" rowspan="${fn:length(stat.typeNums)}">${stat.sum}</td>
</c:if>
</tr>
</c:forEach>
</c:forEach>
</table>
</div>
<div title="按照录入员统计结果" style="padding:10px;">
<table border="0" class="stat-table">
<tr>
	<th>姓名</th>
<c:forEach items="${statInputQuestByInputer[0].dateStrList}" var="date">
	<th>${date}</th>
</c:forEach>
	<th>总计</th>
</tr>
<c:forEach items="${statInputQuestByInputer}" var="stat" begin="1">
<tr>
	<td>${stat.userName}</td>
<c:forEach items="${stat.dataStrNumMap}" var="entry">
	<td style="text-align: right;">${entry.value}</td>
</c:forEach>
	<td style="text-align: right;">${stat.sum}</td>
</tr>
</c:forEach>
</table>
</div>
</div>
</c:if>

<div style="display: none;">
	<form id="downloadForm" action="#">
	</form>
</div>
</body>
</html>