<%@ 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");
	request.setCharacterEncoding("UTF-8");
%>
<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="/bap/statistics/eaibzwkdstcd/bjobBzwkDstcdListupMan.json" />';
	var url_view  = '<c:url value="/bap/statistics/eaibzwkdstcd/bjobBzwkDstcdListupMan.view" />';
	var url_excel = '<c:url value="/bap/statistics/eaibzwkdstcd/bjobBzwkDstcdListupMan.excel" />';
	
	function init(callback) {
		$.ajax({
			type : "POST",
			url:url,
			dataType:"json",
			data:{cmd: 'LIST_INIT_COMBO'},
			success:function(json){
				new makeOptions("CODE","NAME").setObj($("select[name=searchBjobBzwkDstcd]")).setNoValueInclude(true).setNoValue('','<%=localeMessage.getString("combo.all")%>').setData(json.bjobBzwkDstcd).rendering();
				new makeOptions("CODE","NAME").setObj($("select[name=searchOsidInstiDstcd]")).setNoValueInclude(true).setNoValue('','<%=localeMessage.getString("combo.all")%>').setData(json.osidInstiDstcd).rendering();
				putSelectFromParam();
				if (typeof callback === 'function') {
					callback();
				}
				
				// 검색기능을 활성화하면 업무구분에 따라 기관리스트가 변경 안됨
				//setSearchable("searchBjobBzwkDstcd");
				//setSearchable("searchOsidInstiDstcd");
			},
			error:function(e){
				alert(e.responseText);
			}
		});
	}
	
	function statusFormat (cellvalue){
		if ( cellvalue == 'T' ){
			return '<%=localeMessage.getString("transactionListup.nomal")%>';
		}else if ( cellvalue == 'Q' ) {
			return '<%=localeMessage.getString("transactionListup.standBy")%>';
		}else if ( cellvalue == 'C' ) {
			return '<%=localeMessage.getString("transactionListup.CustomerStop")%>';
		}else if ( cellvalue == 'N' ) {
			return '<%=localeMessage.getString("transactionListup.noFile")%>';
		}else if ( cellvalue == 'S' ) {
			return '<span style="color:blue"><%=localeMessage.getString("transactionListup.start")%></span>';
		}else if ( cellvalue == 'E' ) {
			return '<span style="color:red"><%=localeMessage.getString("transactionListup.errEnd")%></span>';
		}
		return "";
	}
	
	function sendRecvFormat (cellvalue){
		if ( cellvalue == 'S' ){
			return '<%=localeMessage.getString("transactionListup.send")%>';
		}else if ( cellvalue == 'R' ){
			return '<%=localeMessage.getString("transactionListup.recv")%>';
		}
		return cellvalue;
	}
	
	function detail(){
		
		var start = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"");
		var end = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"");
		
		$("input[name=searchStartTime]").val(start);
		$("input[name=searchEndTime]").val(end);
		
		if ( $("select[name=searchFrameWorkGb]").val() == '7' ) {
			if ( start != end ) {
				alert("NDM 거래조회기간은 1일을 넘을 수 없습니다.");
				return;
			}
		}
		
		var postData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
		postData["startNum"] = 0;
		postData["endNum"] = $("select[name=searchCount]").val();
		postData["searchDistCd"] = $("select[name=searchDistCd]").val();
		$("#grid").setGridParam({ url:url,postData: postData }).trigger("reloadGrid");
	} 
	 
	$(document).ready(function() {	
	
		$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").inputmask("yyyy-mm-dd",{'autoUnmask':true});
	
		var searchStartYYYYMMDD = "${param.searchStartYYYYMMDD}";
		var searchEndYYYYMMDD   = "${param.searchEndYYYYMMDD}";
	
		if ( searchStartYYYYMMDD == null || searchStartYYYYMMDD == ''){
			$("input[name=searchStartYYYYMMDD]").val(getToday());
		}
		
		if ( searchEndYYYYMMDD == null || searchEndYYYYMMDD == ''){
			$("input[name=searchEndYYYYMMDD]").val(getToday());
		}
		
		$("select[name=searchBjobBzwkDstcd]").change(function(){
			$.ajax({  
			    type : "POST",
			    url:url,
			    dataType:"json",
			    data:{ cmd: 'LIST_ORGN_COMBO',
			           bjobBzwkDstcd : $(this).val()
			         },
			    success:function(json){
			    	$("select[name=searchOsidInstiDstcd] option").remove();
			    	new makeOptions("CODE","NAME").setObj($("select[name=searchOsidInstiDstcd]")).setNoValueInclude(true).setNoValue('','<%=localeMessage.getString("combo.all")%>').setData(json.osidInstiDstcd).rendering();
			    }
			});
		});
		
		$('#grid').jqGrid({
			datatype : "json",
			mtype : 'POST',
			colNames : [ 'UUID',
			             'SUBUUID',
			             '프레임웍구분',
			             '<%=localeMessage.getString("transactionListup.bzwkdName")%>',
                      '<%=localeMessage.getString("transactionListup.osidInst")%>',
			             '<%=localeMessage.getString("transactionListup.fileName")%>',
			             '<%=localeMessage.getString("transactionListup.fileSize")%>',
			             '<%=localeMessage.getString("transactionListup.sendStatus")%>',
			             '<%=localeMessage.getString("transactionListup.jobType")%>',
			             '<%=localeMessage.getString("transactionListup.tranStartTime")%>',
			             '<%=localeMessage.getString("transactionListup.tranEndTime")%>'
			              ],
			colModel : [ { name : 'BJOBDMNDMSGID'     , align : 'left'   , hidden:true },
			             { name : 'BJOBDMNDSUBMSGID'  , align : 'left'   , hidden:true },
						 { name : 'FRAMEWORKGB'           , align : 'center' , width:40  ,
						   formatter: function (cellvalue) {
						                 if ( cellvalue == 'AD' ) {
						                 	return 'AXWAY(대외)';
			                              } else if ( cellvalue == 'AN' ) {
							                 	return 'AXWAY(내부)';
			                              } else if ( cellvalue == 'NDM' ) {
							                 	return 'NDM(내부/대외)';
			                              } else {
			                               	return cellvalue.trim();
			                              }
		                          }
						 },
			             { name : 'BJOBBZWKNAME'      , align : 'left'   , width:'70' },
			             { name : 'OSIDINSTINAME'     , align : 'left'   , width:'70' },
						 { name : 'SNDRCVFILENAME'    , align : 'left'   , width:'150' },
						 { name : 'SNDRCVFILESIZE'    , align : 'right'   , width:'70'  , formatter: 'integer'},
						 { name : 'THISSTGEPRCSSRSULTCD'  , align : 'center' , width:40  ,
							  formatter: function (cellvalue) {
							                 if ( cellvalue == 'E' ) {
							                 	return '<span style="color:red">에러</span>';
			                                 } else if ( cellvalue == 'C' ) {
			 				                 	return '<span style="color:blue">전송성공</span>';
			                                 } else if ( cellvalue == 'P' ) {
			 				                 	return '<span style="color:green">진행중</span>';
			                                 } else {
			                                  	return cellvalue.trim();
			                                 }
			                              }
						},
						{ name : 'SNDRCV'             , align:'center' , width:40   ,
							  formatter: function (cellvalue) {
							                 if ( cellvalue == 'S' ) {
							                 	return '송신';
			                                 } else if ( cellvalue == 'R' ) {
							                 	return '수신';
			                                 } else {
			                                  	return '';
			                                 }
			                              }
							},
						{ name : 'FILETRSMTSTARTHMS'  , align:'center' , width:80 , formatter: timeStampFormat },
						{ name : 'FILETRSMTENDHMS'    , align:'center' , width:80 , formatter: timeStampFormat }
			              ],
			jsonReader : {
				repeatitems : false
			},
			height : 500,
			autowidth : true,
			viewrecords : true,
			//rownumbers:true,
			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){
				resizeJqGridWidth('grid','content_middle','1000');
          }
		});
		
		resizeJqGridWidth('grid','content_middle','1000');
		
		$("#btn_search").click(function(){
			detail();
		});
		
		$("input[name^=search]").keydown(function(key){
			if (key.keyCode == 13){
				$("#btn_search").click();
			}
		});
		
		$("#btn_download").click(function(event) {
	        event.stopPropagation(); // Do not propagate the event.
			gridToExcelSubmit(url_excel,"LIST_GRID_TO_EXCEL",$("#grid"),$("#ajaxForm"),"주제별 상위거래",null);
	        
			return false;
		});	
		
		buttonControl();
		init(detail);
		
		$("#startDatepicker").datepicker();
		$("#endDatepicker").datepicker();
	});
	 
	</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" id="content_middle">
			<div class="search_wrap">
				<img src="<c:url value="/img/btn_download.png" />" alt="" id="btn_download" level="W" />
				<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />	
			</div>
			<div class="title"><%=localeMessage.getString("transactionListup.title")%></div>
			
			<table class="search_condition" cellspacing=0;>
				<tbody>
					<tr>
						<!-- 거래기간 -->
						<th style="width:100px;"><%=localeMessage.getString("transactionListup.tranPeriod")%></th>
						<td colspan="3">
							<input type="text" name="searchStartYYYYMMDD" id="startDatepicker" maxlength="10" value="${param.searchStartYYYYMMDD}" size="10" style="width:80px;"> ~ 
							<input type="text" name="searchEndYYYYMMDD" id="endDatepicker" maxlength="10" value="${param.searchEndYYYYMMDD}" size="10" style="width:80px;">
							<input type="hidden" name="searchStartTime" value="20170201">
							<input type="hidden" name="searchEndTime" value="20170201">
						</td>
						<!-- 송수신구분 -->
						<th style="width:100px;"><%=localeMessage.getString("transactionStatus.jobType")%></th>
						<td style="width:200px;">
							<div class="select-style">
								<select type="text" name="searchProcessType" value="${param.searchProcessType}">
									<option value="A"><%=localeMessage.getString("combo.all")%></option>
									<option value="S"><%=localeMessage.getString("transactionStatus.send")%></option>
									<option value="R"><%=localeMessage.getString("transactionStatus.recv")%></option>
								</select>
							</div>
						</td>
						<!-- 전송상태 -->
						<th style="width:100px;"><%=localeMessage.getString("transactionStatus.sendStatus")%></th>
						<td style="width:200px;">
							<div class="select-style">
								<select name="searchThisStgePrcssRsultCd" value="${param.searchThisStgePrcssRsultCd}">
									<option value="">전체</option>
									<option value="T">정상</option>
									<option value="E">에러</option>
									<option value="P">전송중</option>
								</select>
							</div>
						</td>
						<th style="width:100px;"><%=localeMessage.getString("transactionListup.fileName")%></th>
						<td style="width:200px;">
							<input type="text" name="searchBjobTranDstcdName" value="${param.searchBjobTranDstcdName}" />
						</td>						
					</tr>
					<tr>
						<th style="width:100px;"><%=localeMessage.getString("transactionTrace.frameworkdst")%></th>
						<td style="width:200px;">
							<div class="select-style">	
								<select name="searchFrameWorkGb" value="${param.searchFrameWorkGb}">
									<option value="2">전체</option>
									<option value="1">F/W</option>
									<option value="3">NDM(F)</option>
									<option value="5">AXWAY(대외)</option>
									<option value="6">AXWAY(내부)</option>
									<option value="7">NDM(내부/대외)</option>
								</select>
							</div><!-- end.select-style -->									
						</td>
                  <th style="width:100px;"><%=localeMessage.getString("transactionListup.bzwkdName")%></th>
						<td style="width:200px;">
							<div class="select-style">	
								<select type="text" name="searchBjobBzwkDstcd" value="${param.searchBjobBzwkDstcd}">
								</select>
							</div><!-- end.select-style -->									
						</td>	
						<th style="width:100px;"><%=localeMessage.getString("transactionListup.osidInst")%></th>
						<td style="width:200px;">
							<div class="select-style">
								<select type="text" name="searchOsidInstiDstcd" value="${param.searchOsidInstiDstcd}">
								</select>
							</div>
						</td>						
						<th style="width:100px;"><%=localeMessage.getString("transactionListup.orderbyType")%></th>
						<td style="width:200px;">
							<div class="select-style">
								<select name="searchDistCd" id="searchDistCd" readonly="readonly" >
									<option value="fileSize">파일크기</option>
									<option value="procTime">거래소요시간</option>
								</select>
							</div>
						</td>
 						<th style="width:100px;">조회건수</th>
						<td style="width:200px;">
							<div class="select-style">
								<select type="text" name="searchCount" value="${param.searchCount}">
									<option value="10">10</option>
									<option value="20">20</option>
								</select>
							</div>
						</td>						
					</tr>					
				</tbody>
			</table>
			
			<table id="grid" ></table>
			<!-- <div id="pager"></div> -->	
			
		</div><!-- end content_middle -->
	</div><!-- end right_box -->				
</body>	
</html>

