<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>

<script language="javascript" >
var url      ='<c:url value="/onl/statistics/management/downStatisticsMan.json" />';
var url_view ='<c:url value="/onl/statistics/management/downStatisticsMan.view" />';
var url_excel ='<c:url value="/onl/statistics/management/downStatisticsMan.file" />';

function init(){
	$.ajax({  
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT'},
		success:function(json){
			var msg = "양식이 등록되어있지 않습니다. /fsapp/eai/download/ 에 추가해주세요";
			if(json.MONTHLY){
				$("input[name=monthlyForm]").val(json.MONTHLY);	
			}else {
				$("input[name=monthlyForm]").val(msg);
			}
			if(json.DAILY){
				$("input[name=dailyForm]").val(json.DAILY);
			}else {
				$("input[name=dailyForm]").val(msg);
			}
			if(json.SVRSYS){
				$("input[name=svrSysForm]").val(json.SVRSYS);
			}else{
				$("input[name=svrSysForm]").val(msg);
			}
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}


$(document).ready(function() {
	init();
	var now = new Date();
	var month =now.getMonth() + 1;
	
	var beforeYear = now.getFullYear()-1;
	for(var y = now.getFullYear()-1; y<now.getFullYear(); y++){
		$("select[name^=year]").append("<option value='"+y+"'>"+y+"</option>");
	}
	$("select[name^=year]").append("<option value='"+now.getFullYear()+"' selected>"+now.getFullYear()+"</option>");
	var beforeMonth= now.getMonth();
	if(beforeMonth==0){
		beforeMonth=12;
		$("select[name^=year]").val(now.getFullYear()-1);
	}
	$("select[name^=month]").val(beforeMonth);
	$("select[name^=businessDay]").val(20);
	
	$("img[name^=btn_excel]").click(function(){
		if(!confirm("통계자료를 생성하시겠습니까?")){
			return;
		}
		var btnName = $(this).attr("name");
		var type = btnName.substr(btnName.length-1,1);
		var year = $("select[name=year"+type+"]").val();
		var month = $("select[name=month"+type+"]").val();
		
		var start = new Date(year,month-1,1);
		var end = new Date(year,month,0);
		var monthTmp = start.getMonth()+1;
		var dayTmp = start.getDate();
		if(month<10){
			month="0"+month;
		}
		if(dayTmp<10){
			dayTmp="0"+dayTmp;
		}
		var startDay = start.getFullYear()+month+dayTmp;
		var endDay = end.getFullYear()+""+month+end.getDate();
			
		
		excelDown(startDay,endDay,type);
	});
	buttonControl();
	
});
function excelDown(startDay,endDay,type){
	event.stopPropagation(); 
	var download_url = '<c:url value="/onl/statistics/management/downStatisticsMan.file" />?cmd=UPLOAD_REPORT_DOWN';
	download_url+='&searchStart='+startDay;
	download_url+='&searchEnd='+endDay;
	download_url+='&type='+type;
	download_url+='&bussinessDays='+$("input[name=bussinessDay]").val();
	location.href = download_url;
}
</script>
</head>
	<body>		
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li><a href="#">${rmsMenuPath}</a></li>					
				</ul>					
			</div><!-- end content_top -->
			<div class="content_middle">
				<div class="search_wrap">
				</div>
				<div class="title">통계자료 다운</div>
				<table class="search_condition" cellspacing=0; style="text-align:center;">
					<tbody>
						<tr>
							<th style="height:30px;">no.</th>
							<th style="height:30px;">양식등록여부</th>
							<th style="height:30px;">보고서명</th>
							<th style="height:30px;">날짜</th>
							<th style="height:30px;">제외할 영업일자</th>
							<th style="height:30px;">다운로드</th>
						</tr>
						<tr>
							<td>
								1
							</td>
							<td>
								<input type="text" name ="monthlyForm">
							</td>
							<td>
								금월 인프라 서버 EAI 데이터 처리 현황
							</td>
							<td>
								<select name="year1" style="padding: 2px;">
								</select>
								년
								<select name="month1" style="padding: 2px;">
									<c:forEach var="month" begin="1" end="12">
										<option value="${month}">${month }</option>
									</c:forEach> 
								</select>
								월
							</td>
							<td>
								<input type="text" name ="bussinessDay" placeholder="ex)20/10/01~02(목~금) -> 1,2">
							</td>
							<td>
								<img src="<c:url value="/img/btn_excel.png"/>"  name="btn_excel1" level="W" style="cursor: pointer;"/>
							</td>
						</tr>
						<tr>
							<td>
								2
							</td>
							<td>
								<input type="text" name ="dailyForm">
							</td>
							<td>
								인프라 서버 EAI 일자별 데이터 처리 현황
							</td>
							<td>
								<select name="year2" style="padding: 2px;">
								</select>
								년
								<select name="month2" style="padding: 2px;">
									<c:forEach var="month" begin="1" end="12">
										<option value="${month}">${month }</option>
									</c:forEach> 
								</select>
								월
							</td>
							<td>
							</td>
							<td>
								<img src="<c:url value="/img/btn_excel.png"/>" name="btn_excel2" level="W" style="cursor: pointer;"/>
							</td>
						</tr>
						<tr>
							<td>
								3
							</td>
							<td>
								<input type="text" name ="svrSysForm">
							</td>
							<td>
								EAI 서버 시스템
							</td>
							<td>
								<select name="year3" style="padding: 2px;">
								</select>
								년
								<select name="month3" style="padding: 2px;">
									<c:forEach var="month" begin="1" end="12">
										<option value="${month}">${month }</option>
									</c:forEach> 
								</select>
								월
							</td>
							<td>
								
							</td>
							<td>
								<img src="<c:url value="/img/btn_excel.png"/>" name="btn_excel3" level="W" style="cursor: pointer;"/>
							</td>
						</tr>						
					</tbody>
				</table>
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

