<%@ 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/transaction/online/transactionStatus.json" />';
var url_view = '<c:url value="/onl/transaction/online/transactionStatus.view" />';
var url_excel= '<c:url value="/onl/transaction/online/transactionStatus.excel"/>';
var timer;
var recentYn="N";
function list(recentYn){
	
	var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
	postData["recentYn"] = recentYn;
	$("#grid").setGridParam({ url:url,postData: postData }).trigger("reloadGrid");
}
	
function refreshGrid(recentYn){
	
	timer = setInterval(function(){
		list(recentYn);
	},5000);
	
}	
	
	
$(document).ready(function() {	
	var gridPostData = getSearchForJqgrid("cmd", "LIST"); //jqgrid에서는 object 로 
	
	$('#grid').jqGrid({
		datatype : "json",
		mtype : 'POST',
		url : url,
		postData : gridPostData,
		colNames : [ 
		             '업무구분코드',
		             '<%= localeMessage.getString("eaiMsg.bizCodeName") %>',
		             '100',
		             '200',
		             '300',
		             '400',
		             '100',
		             '200',
		             '300',
		             '400',
		             '900',
		             '300',
		             '400',
		             '900',
		             'IF',
		             '<%= localeMessage.getString("tranStat.recv") %>',
		             '<%= localeMessage.getString("common.total") %>',
		              ],
		colModel : [ 
		             { name : 'BIZCODE'    , hidden : true },
		             { name : 'BIZNAME'    , align : 'left'    },
		             { name : 'P100'       , align : 'center'   , width:'50'	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'  },
		             { name : 'P200'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'P300'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'P400'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
                                           
		             { name : 'E100'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'E200'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'E300'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'E400'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'E900'       , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},

		             { name : 'E9300'      , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'E9400'      , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},
		             { name : 'E9900'      , align : 'center'   , width:'50'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'sum'},

		             { name : 'AVGEAI'     , align : 'center'   , width:'46'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'avg'},
		             { name : 'AVGPSV'     , align : 'center'   , width:'46'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'avg'},
		             { name : 'AVGTOTAL'   , align : 'center'   , width:'46'  	,formatter:'integer',formatoptions:{thousandsSeparator:","},summaryType:'avg'}

		              ],
		jsonReader : {
			repeatitems : false
		},
		footerrow:true,
		userDataOnFooter:true,
		rowNum: 10000,
		height : 480,
		viewrecords : true,
		autowidth: true,
		gridview: true,
		frozen:true,
		ondblClickRow : function(rowId) {
			var rowData = $(this).getRowData(rowId);
		    var key = rowData['BIZCODE'];
		    var url2 = url_view;
		    url2 += "?cmd=DETAIL";
		    url2 += '&menuId='+'${param.menuId}';
		    url2 += "&searchEaiBzwkDstcd="+key;
		    goNav(url2);
		},
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});
			}
		
		},			
	    loadComplete:function (d){
	    	//$("#grid").tuiTableRowSpan("0");
	    	var rowCnt = $('#grid').getGridParam("reccount");
	    	var colModel = $(this).getGridParam("colModel");
	    	for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});
				var propName = colModel[i].name;
				var summaryType = colModel[i].summaryType;
				var Total = $('#grid').jqGrid('getCol',propName,false,'sum');
				if(summaryType =='avg'){
					if(rowCnt == 0) 
						Total = 0;
					else
	    				Total = (Total/rowCnt).toFixed(3);		//avg를 바로 쓰면 row 수가 +1 되어 계산됨.
	    		}	
	    		eval("$('#grid').jqGrid('footerData','set',{BIZNAME:'합계', "+propName+":Total});");
	    	}
			
			//$(".ui-jqgrid-ftable tr:first").children("td").css("background-color", "#D4F4FA");	// td 배경색
			$(".ui-jqgrid-ftable tr:first").css("height", "30px");								// tr 높이
			$(".ui-jqgrid-ftable tr:first").css("font-size", "10pt");							// tr 글자 크기
			$(".ui-jqgrid-ftable td:eq(1)").css("text-align", "center");						// td 글자 정렬	    	

			//$(".ui-jqgrid-ftable").css('position','fixed');					// 소계 하단에 고정
			$(".ui-jqgrid-ftable").css('bottom','0');
			
	    },
        loadError: function (jqXHR, textStatus, errorThrown) {
        	if(jqXHR.status == 401) {
        		var location ='<%=request.getContextPath()%>/';
	        	comloadError(jqXHR, textStatus, errorThrown ,location);
	    	}
    	}	
		
	});
	$("#grid").jqGrid('setGroupHeaders', {
  		useColSpanStyle: true, 
  		groupHeaders:[
			{startColumnName: 'P100', numberOfColumns: 4, titleText: '<%= localeMessage.getString("tranStat.tranNo") %>'},
			{startColumnName: 'E100', numberOfColumns: 5, titleText: '<%= localeMessage.getString("tranStat.errNo") %>'},
			{startColumnName: 'E9300', numberOfColumns: 3, titleText: '<%= localeMessage.getString("tranStat.timeout") %>'},
			{startColumnName: 'AVGEAI', numberOfColumns: 3, titleText: '<%= localeMessage.getString("tranStat.avgTime") %>'}
  		]
	});
	
	$("#btn_10min").click(function(){
		$("#btn_10min").hide();
		$("#btn_search").show();
		recentYn ="Y";
		list(recentYn);
	});
	
	$("#btn_search").click(function(){
		//$("#btn_10min").show();
		//$("#btn_search").hide();
		if($("#recentYnVal").is(":checked")){ //최근10분여부
			recentYn="Y";
		}else{
			recentYn="N";
		}
		list(recentYn);
	});
	
	$("#btn_detail").click(function(){
	    var args = new Object();
	    args['userId'] = $("input[name=userId]").val();
	    
	    var url2 = url_view;
	    url2 += "?cmd=POPUP";
	    showModal(url2,args,470,740);
	});	
	$("#btn_initialize").click(function(){
		if(confirm("초기화 하시겠습니까?")){
			$.ajax({
				type : "POST",
				url:url,
				dataType:"json",
				data:{cmd: 'INITIALIZE',recentYn:recentYn},
				success:function(json){
					alert("성공하였습니다.");
				},
				error:function(e){
					alert(e.responseText);
				}
			});	
		}else{
			return false;
		}
				
		
	});	
	$("#btn_download").click(function(event) {
           event.stopPropagation(); // Do not propagate the event.
           // Create an object that will manage to download the file.
           var merge = new Array();
           merge.push(makeMerge("업무구분","0","1","0","0"));
           merge.push(makeMerge("구간별 처리건수","0","0","1","4"));
           merge.push(makeMerge("구간별 에러건수","0","0","5","9"));
           merge.push(makeMerge("타임아웃","0","0","10","12"));
           merge.push(makeMerge("평균처리시간(초)","0","0","13","15"));
           
		gridToExcelSubmit(url,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),"업무별 거래현황",merge);
		return false;
	});	
	
	$("#btn_excel").click(function(event) {
        event.stopPropagation(); // Do not propagate the event.
        var target = "excelDown" ; // iframe의 name
        var merge = new Array();
        merge.push(makeMerge("업무구분","0","1","0","0"));
        merge.push(makeMerge("구간별 처리건수","0","0","1","4"));
        merge.push(makeMerge("구간별 에러건수","0","0","5","9"));
        merge.push(makeMerge("타임아웃","0","0","10","12"));
        merge.push(makeMerge("평균처리시간(초)","0","0","13","15"));
		gridToExcelSubmit(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),'업무별 거래현황',merge);
		return false;
	});
	
	buttonControl();
	
	/* timer = setInterval(function(){
		list(recentYn);
	},5000); */
	
	//$("#btn_search").hide();
	
	//refresh 체크박스
	$("input:checkbox").on('click',function(){
		var refresh = $("#refresh").is(":checked");
		clearInterval(timer);
		
		if(refresh){ //refresh 설정
			if($("#recentYnVal").is(":checked")){ //최근10분여부
				refreshGrid("Y");
			}else{
				refreshGrid("N");
			}
		}
		
	});
	
	
});
 
</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">
					<input type="checkbox" id="refresh" value="Y" />&nbsp;<b>Auto Refresh</b>
					&nbsp;<input type="checkbox" id="recentYnVal" value="N"/>&nbsp;<b><%= localeMessage.getString("tranStat.rec10Min") %></b>&nbsp;&nbsp;
					<%-- <img src="<c:url value="/img/btn_10min.png" />" alt="" id="btn_10min" level="W" /> --%>
					<button type="button" class="cssbtn" id="btn_detail" level="R" ><i class="material-icons">details</i> <%= localeMessage.getString("button.detail") %></button>
					<button type="button" class="cssbtn" id="btn_excel" level="W" ><i class="material-icons">table_view</i> <%= localeMessage.getString("button.excel") %></button>
					<button type="button" class="cssbtn" id="btn_initialize" level="W" ><i class="material-icons">restart_alt</i> <%= localeMessage.getString("button.reset") %></button>
					<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_detail.png" />" alt="" id="btn_detail" level="R" /> --%>
<%-- 					<img src="<c:url value="/img/btn_excel.png" />" alt="" id="btn_excel" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_initialize.png" />" alt="" id="btn_initialize" level="W" /> --%>
<%-- 					<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />		 --%>
					<%-- <img id="btn_excel" src="<c:url value="/img/btn_excel.png"/>" level="W" status="DETAIL"/> --%>
				</div>
				<div class="title"><%= localeMessage.getString("tranStat.title") %><span class="tooltip"><%= localeMessage.getString("tranStat.tooltip") %></span></div>
				<ajax>
				<table id="grid" ></table>
				</ajax>
				<div id="pager"></div>
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
	<iframe name=excelDown width=0 height=0></iframe>
</html>

