<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%
	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/creaStatisticsMan.json" />';
var url_view ='<c:url value="/onl/statistics/management/creaStatisticsMan.view" />';

function init()
{
	$.ajax({
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'LIST_INIT_COMBO'},
		success:function(json){
			new makeOptions("CODE","NAME").setObj($("select[name=STATCJOBCYCLDSTCD]")).setData(json.jobTypeCdRows).setFormat(codeName3OptionFormat).rendering();
		},
		error:function(e){
			alert(e.responseText);
		}
	});
}

$(document).ready(function() {
	init();
	
	var returnUrl = getReturnUrlForReturn();
	
	$("input[name=STATCJOBYMD]").inputmask("9999-99-99",{'autoUnmask':true});

	$("#btn_operate").click(function(){

		var searchJobTypeCd	= $("select[name=STATCJOBCYCLDSTCD]").val();
		var statisticsDt	= $("input[name=STATCJOBYMD]").val();
		var postData;
		
		if(statisticsDt == null)
		{
			statisticsDt = "";
		}
		
		if(statisticsDt == ""){
			alert("통계생성일을 입력해 주세요.");
			return false;
		}
		
		//날짜비교
		var statisticsDtCompare = statisticsDt.replace(/-/gi,"");
		var today = getToday();  //현재년월일
		
		//이번달이후 날짜는 안됨 
		var curMonth = today.substring(0,6); //현재년월
		var compareMonth = statisticsDtCompare.substring(0,6) //입력년월
		
		if (searchJobTypeCd == "D")
		{
			if(statisticsDtCompare >= today){
				alert("미래일자를 실행할수 없습니다");
				return;
			}else{
				postData = {service: searchJobTypeCd, day: statisticsDt, cmd: "INSERT_DAILY"};
			}
		}
		else if(searchJobTypeCd == "M")
		{
			if(compareMonth >= curMonth){
				alert("미래일자를 실행할수 없습니다");
				return;
			}else{
				postData = {service: searchJobTypeCd, month: statisticsDt, cmd: "INSERT_MONTHLY"};
			}
		}
		else if(searchJobTypeCd == "L"){
			if(statisticsDt >= today){
				alert("미래일자를 실행할수 없습니다");
				return;
			}else{
				postData = {service: searchJobTypeCd, date: statisticsDt, cmd: "INSERT_NEWLOG"};
			}
		}
		else
		{
			alert("작업구분을 선택해주세요.");
			return;
		}
		if(!confirm("통계자료를 생성하시겠습니까?")){
			return;
		}
		
		
		$.ajax({
			type : "POST",
			url:url,
			data:postData,
			success:function(args){
				alert("처리 되었습니다.");
				goNav(returnUrl);//LIST로 이동
			},
			error:function(e){
				var jdata = JSON.parse(e.responseText);
				alert(jdata.errorMsg);
			}
		});
	});
	
	$("input[name=STATCJOBYMD]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_operate").click();
		}
	});
	
	buttonControl();
	
});
 
</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">
					<button type="button" class="cssbtn" id="btn_operate" level="W" ><i class="material-icons">expand_circle_down</i> <%= localeMessage.getString("button.operate") %></button>
<%-- 					<img src="<c:url value="/img/btn_operate.png"/>" alt="" id="btn_operate" level="W" />										 --%>
				</div>
				<div class="title"><%= localeMessage.getString("creaStatis.title") %></div>
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th style="width:120px;"><%= localeMessage.getString("creaStatis.job") %></th>
							<td>
								<div class="select-style">
									<select name="STATCJOBCYCLDSTCD" value="">
									</select>
								</div><!-- end.select-style -->	
							</td>
							<th style="width:120px;"><%= localeMessage.getString("creaStatis.jobYmd") %></th>
							<td>
								<input type="text" name="STATCJOBYMD" maxlength="10">				
							</td>							
						</tr>						
					</tbody>
				</table>
				
				<!-- <table id="grid" ></table>
				<div id="pager"></div>				 -->
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

