<%@ 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/statisticinfo/transactionStatisticMan.json" />';
var url_view  ='<c:url value="/onl/statistics/statisticinfo/transactionStatisticMan.view" />';
var url_excel ='<c:url value="/onl/statistics/statisticinfo/transactionStatisticMan.excel" />';


function detail(){
	var now = new Date();
	var month =now.getMonth() + 1;
	var endMonth = parseInt($("select[name=searchDate]").val());
	
	if(endMonth<10){
		endMonth='0'+endMonth
	}
	var searchDate = $("select[name=selectEndYear]").val()+endMonth;
	$("input[name=searchDateYYYYMM]").val(searchDate);

	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
	postData["searchDate"] = searchDate;
	
	$("#grid").setGridParam({ url:url,postData: postData ,page:1 }).trigger("reloadGrid");
}

function valueFormater(cellvalue, options, rowObject){
	if (cellvalue==null|| cellvalue==undefined) return "";
	
	var display = "";
	var idx = cellvalue.indexOf("(");
	
	if(idx > -1){
		var firstVal = cellvalue.substring(0,idx);
		var secondVal = cellvalue.substring(idx,cellvalue.length);
		firstVal = firstVal.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',');
		display = firstVal + secondVal;
	}else{
		display = cellvalue;
	}
	
	return display;
}	

function valueFormater2(cellvalue, options, rowObject){
	if (cellvalue==null|| cellvalue==undefined) return "";
	
	var display = "";
	var idx = cellvalue.indexOf("(");
	var idx2 = cellvalue.indexOf(")");
	
	if(idx > -1){
		var firstVal = cellvalue.substring(0,idx);
		var secondVal = cellvalue.substring(idx+1,idx2);
		var dateVal = "";
		if(secondVal.length == 8){
			dateVal=dateVal+secondVal.substring(0,4)+".";
			dateVal=dateVal+secondVal.substring(4,6)+".";
			dateVal=dateVal+secondVal.substring(6,8);
			dateVal = " (" + dateVal + ")";
		}else{
			dateVal = secondVal;
		}
		firstVal = firstVal.toString().replace(/\B(?=(\d{3})+(?!\d))/g,',');
		display = firstVal + dateVal;
	}else{
		display = cellvalue;
	}
	
	return display;
}	



$(document).ready(function() {
	var now = new Date();
	var month =now.getMonth();
	
	for(var y = now.getFullYear()-1; y<now.getFullYear(); y++){
		$("select[name=selectEndYear]").append("<option value='"+y+"'>"+y+"</option>");
	}
	$("select[name=selectEndYear]").append("<option value='"+now.getFullYear()+"' selected>"+now.getFullYear()+"</option>");
	$("select[name=searchDate]").val(month);
	
	var endMonth = parseInt($("select[name=searchDate]").val());
	if(endMonth<10){
		endMonth='0'+endMonth
	}
	var endDate = $("select[name=selectEndYear]").val()+endMonth;
	$("input[name=searchDateYYYYMM]").val(endDate);
	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	gridPostData["searchDate"] = endDate;
	
	//역대 최고치 추가
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,
		colNames:[
					 '<%= localeMessage.getString("tranStatMan.div")%>'
					,'<%= localeMessage.getString("tranStatMan.ser")%>'
					,'<%= localeMessage.getString("tranStatMan.laMon")%>'
					,'<%= localeMessage.getString("tranStatMan.thMon")%>'
					,'<%= localeMessage.getString("tranStatMan.grad")%>'
					,'<%= localeMessage.getString("tranStatMan.maxTPS")%>'
                  ],
		colModel:[
					{ name : 'GUBUN'		, align:'center'	,width:'30px' },
					{ name : 'SERVICE'		, align:'center'		,width:'40px'	},
					{ name : 'PREMM'		, align:'center'		,width:'80px'	, formatter: valueFormater},
					{ name : 'CURMM'		, align:'center'		,width:'80px'	, formatter: valueFormater},
					{ name : 'GRADIENT'		, align:'center'		,width:'80px'	, formatter: 'integer', formatoptions:{thousandsSeparator:","} },
					{ name : 'MAXTPS'		, align:'center'		,width:'80px'	, formatter: valueFormater2}
				],
				
        jsonReader: {
             repeatitems:false
        },
//         pager : $('#pager'),
// 		page : '${param.page}',
// 		rowNum : '${rmsDefaultRowNum}',
 	    height : '600',
		rowNum : 10000,
		autowidth: true,
		viewrecords: true,
		rowList : eval('[${rmsDefaultRowList}]'),
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
		},		
		loadComplete:function (d){
			$("#grid").tuiTableRowSpan("0");
		},
        loadError: function (jqXHR, textStatus, errorThrown) {
        	
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
        	
    	}
	});
	
	
	//resizeJqGridWidth('grid','content_middle','1680');
	
	$("#btn_search").click(function(){ 
		detail();
	});
	
	$("input[name^=search]").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});

	$("#btn_excel").click(function(event) {
        event.stopPropagation(); // Do not propagate the event.
        // Create an object that will manage to download the file.
        var target = "excelDown" ; // iframe의 name
        //(url,cmd,gridObj,formObject,fileName,merge)
		gridToExcelSubmit2(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'<%= localeMessage.getString("statisticsByCompany.titleDaily")%>');
		return false;
	});
	$("#startDatepicker").datepicker();
	$("#endDatepicker").datepicker();
	
	detail();
	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">
<%-- 					<img src="<c:url value="/img/btn_excel.png"/>" id="btn_excel" level="W"/> --%>
					<button type="button" class="cssbtn" id="btn_search" level="R" ><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %></button>		
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />					 --%>
				</div>
				<div class="title"><%= localeMessage.getString("tranStatMan.tPSStat")%></div>
				<form id="ajaxForm"  onsubmit="return false;">
					<table class="search_condition" cellspacing=0;>
						<tbody>
							<tr>
								<th style="width:180px;"><%= localeMessage.getString("tranStatMan.stanYearMon")%></th>
								<td width="600px">
									<select name="selectEndYear" style="padding: 2px;">
									</select>
									-
									<select name="searchDate" style="padding: 2px;">
										<c:forEach var="month" begin="1" end="12">
											<option value="${month}">${month } <%= localeMessage.getString("tranStatMan.mon")%></option>
										</c:forEach>
									</select>
									<input type="hidden" name="searchDateYYYYMM" value="">
								</td>		
							</tr>	
						</tbody>
					</table>
				</form>
				<table id="grid" ></table>
				<div id="pager"></div>				
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

