<%--
  - Author(s)  : Kim Myung Ho
  - Date       : 2014.08.11
  - Description: 계약결과 리스트
  --%>
  
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
    ctx.init(request, response);
    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    ValueObject user = storage.getUser();
    
    RowSet contKindCode = storage.getRowSet("contKindCode");
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		gridInit(sheet1);
		
		/**
		 *	Application Initialize
		 */
		$("#btnSearch").click(function() {
			if(jQuery("#p_dept_cd").val() == "" && jQuery("#p_build_nm").val() == "" && jQuery("#p_dealer_nm").val() == "" 	
			&& (jQuery("#ContFromDt").val() == "" || jQuery("#ContToDt").val() == "")){
					alert("검색조건을 최소 1개 이상 입력하십시요.");
					return;
				}
			
			jQuery("#fevent").val("SHEET_SELECT");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/outside/ContResultList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
		});	
		$("#p_dept_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);	if(keycode == 8){$("#p_dept_cd").val("");$("#p_dept_nm").val("");}});
		$("#p_cont_status").change(function(){$("#btnSearch").click();});
		$("#p_build_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);if(keycode == 13)$("#btnSearch").click();});
		$("#p_dealer_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);if(keycode == 13)$("#btnSearch").click();});
		$("#dataClear").click(function(){$("#ContFromDt").val("");$("#ContToDt").val("");});
		jQuery("#btnExcel").click(function() {
			if(sheet1.RowCount() == 0) {
				alert("내역이 없습니다.");
				return;
			}
			var params = { FileName : "ContResultList.xls",  SheetName : "ContResultList", SheetDesign:0, Merge:1, DownCols:"SUB_CONT_MOD_ID|DEPT_NAME|CON_DOC_NO|MOD_NO|BUILD_NAME|CON_SUPPLY_AMT|CON_CUR_CD|MEMBER_NAME"+
					"|CON_DATE|WORK_START_END_DATE|INSUR_YN1|INSUR_YN|TEMPLATE_NAME|STATUS_CD", TitleText:"외주_계약결과", UserMerge:"0,0,1,14", AutoSizeColumn:1  } ;
			sheet1.Down2Excel(params);
		});

		autoResize();
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:100};
		<%-- if("<%= user.get("RIGHT_NAME")%>" == "OUTSIDE" || "<%= user.get("RIGHT_NAME")%>" == "ADMIN NEW" ){ --%>
			init_sheet.Cols = [
		       			{Header:'Del',				Type:"DelCheck",		SaveName:"DEL_CHECK", 			Width:50, 		Align:"Center",		Hidden:"True"},
		    			{Header:'Status',			Type:"Status", 			SaveName:"STATUS", 				Width:0, 		Align:"Center",		Hidden:"True"},
		    			{Header:'계약번호',				Type:"Text", 			SaveName:"SUB_CONT_MOD_ID", 	Width:0, 		Align:"Center",		Hidden:"True"},
		    			{Header:'현장명',				Type:"Text", 			SaveName:"DEPT_NAME", 			Width:200, 		Align:"Left" , 		Edit:"false"},
		    			{Header:'계약번호',				Type:"Text", 			SaveName:"CON_DOC_NO",			Width:120, 		Align:"Left", 		Edit:"false"},
		    			{Header:'변경차수',				Type:"Text", 			SaveName:"MOD_NO", 				Width:50,		Align:"Center" , 	Edit:"false"},
		    			{Header:'☞계약명',				Type:"Text", 			SaveName:"BUILD_NAME", 			Width:200, 		Align:"Left" , 		Edit:"false",	Cursor:"pointer"},
		    			{Header:'계약금액(VAT별도)',		Type:"Text", 			SaveName:"CON_SUPPLY_AMT", 		Width:80, 		Align:"right",		Edit:"false"},
		    			{Header:'통화구분',				Type:"Text", 			SaveName:"CON_CUR_CD", 			Width:50, 		Align:"Center" , 	Edit:"false"},
		    			{Header:'업체명',				Type:"Text", 			SaveName:"MEMBER_NAME", 		Width:100, 		Align:"Left" , 		Edit:"false"},
		    			{Header:'자료',				Type:"Image", 			SaveName:"IMG_GB", 				Width:50, 		Align:"Center" , 	Edit:"false",	Cursor:'pointer'},
		    			{Header:'계약id',				Type:"Text", 			SaveName:"SUB_CONT_ID", 		Width:50, 		Align:"Center" , 	Hidden:"True"},
		    			{Header:'계약일자',				Type:"Text", 			SaveName:"CON_DATE", 			Width:80, 		Align:"Center" , 	Edit:"false"},
		    			{Header:'계약기간',				Type:"Text", 			SaveName:"WORK_START_END_DATE", Width:120, 		Align:"Center", 	Edit:"false"},
		    			{Header:'상태',				Type:"Combo", 			SaveName:"STATUS_CD", 			Width:80, 		Align:"center", 	Edit:"false",	ComboText:"계약완료", ComboCode:"50",		Hidden:"True"},
		    			{Header:'지급보증',			Type:"Text", 			SaveName:"INSUR_YN1", 		Width:50,  	Align:"center", 		Edit:"false"},//, Hidden:"True"
		    			{Header:'고용보험',			Type:"Text", 			SaveName:"INSUR_YN", 			Width:50,  	Align:"center", 		Edit:"false"},
		    			{Header:'보험인수',			Type:"Text", 			SaveName:"INSURANCE_YN", 		Width:50,  	Align:"center", 		Edit:"false", Hidden:"True"},
		    			{Header:'계약서종류',			Type:"Text", 			SaveName:"TEMPLATE_NAME", 		Width:100,  	Align:"Left", 		Edit:"false",	Cursor:"pointer"},
		    			{Header:'계약서코드',			Type:"Text", 			SaveName:"TEMPLATE_CD", 		Width:80, 		Align:"Center",		Hidden:"True"},
		    			{Header:'계약서변경여부',			Type:"Text", 			SaveName:"CHG_CONT_YN", 		Width:80, 		Align:"Center",		Hidden:"True"},
		    			
			];
		/* }
		else
		{
			init_sheet.Cols = [
				       			{Header:'Del',				Type:"DelCheck",		SaveName:"DEL_CHECK", 			Width:50, 		Align:"Center",		Hidden:"True"},
				    			{Header:'Status',			Type:"Status", 			SaveName:"STATUS", 				Width:0, 		Align:"Center",		Hidden:"True"},
				    			{Header:'계약번호',				Type:"Text", 			SaveName:"SUB_CONT_MOD_ID", 	Width:0, 		Align:"Center",		Hidden:"True"},
				    			{Header:'현장명',				Type:"Text", 			SaveName:"DEPT_NAME", 			Width:200, 		Align:"Left" , 		Edit:"false"},
				    			{Header:'계약번호',				Type:"Text", 			SaveName:"CON_DOC_NO",			Width:120, 		Align:"Left", 		Edit:"false"},
				    			{Header:'변경차수',				Type:"Text", 			SaveName:"MOD_NO", 				Width:50,		Align:"Center" , 	Edit:"false"},
				    			{Header:'☞계약명',				Type:"Text", 			SaveName:"BUILD_NAME", 			Width:200, 		Align:"Left" , 		Edit:"false",	Cursor:"pointer"},
				    			{Header:'계약금액(VAT별도)',		Type:"Text", 			SaveName:"CON_SUPPLY_AMT", 		Width:80, 		Align:"right",		Edit:"false"},
				    			{Header:'통화구분',				Type:"Text", 			SaveName:"CON_CUR_CD", 			Width:50, 		Align:"Center" , 	Edit:"false"},
				    			{Header:'업체명',				Type:"Text", 			SaveName:"MEMBER_NAME", 		Width:100, 		Align:"Left" , 		Edit:"false"},
				    			{Header:'계약id',				Type:"Text", 			SaveName:"SUB_CONT_ID", 		Width:50, 		Align:"Center" , 	Hidden:"True"},
				    			{Header:'계약일자',				Type:"Text", 			SaveName:"CON_DATE", 			Width:80, 		Align:"Center" , 	Edit:"false"},
				    			{Header:'계약기간',				Type:"Text", 			SaveName:"WORK_START_END_DATE", Width:80, 		Align:"Center", 	Edit:"false"},
				    			{Header:'상태',				Type:"Combo", 			SaveName:"STATUS_CD", 			Width:80, 		Align:"center", 	Edit:"false",	ComboText:"계약완료", ComboCode:"50",		Hidden:"True"},
				    			{Header:'지급보증',			Type:"Text", 			SaveName:"INSUR_YN1", 		Width:50,  	Align:"center", 		Edit:"false"},//, Hidden:"True"
				    			{Header:'고용보험',			Type:"Text", 			SaveName:"INSUR_YN", 			Width:50,  	Align:"center", 		Edit:"false"},
				    			{Header:'보험인수',			Type:"Text", 			SaveName:"INSURANCE_YN", 		Width:50,  	Align:"center", 		Edit:"false", Hidden:"True"},
				    			{Header:'계약서종류',			Type:"Text", 			SaveName:"TEMPLATE_NAME", 		Width:100,  	Align:"Left", 		Edit:"false",	Cursor:"pointer"},
				    			{Header:'계약서코드',			Type:"Text", 			SaveName:"TEMPLATE_CD", 		Width:80, 		Align:"Center",		Hidden:"True"},
				    			{Header:'계약서변경여부',			Type:"Text", 			SaveName:"CHG_CONT_YN", 		Width:80, 		Align:"Center",		Hidden:"True"},
				    			
				];
		} */

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetImageList(1,"/img/buyer/button/bt_search_right.gif");
		sheetName.SetActionMenu("ExcelDown");
		setGridSize();
	}
	/*
	IBSheet Event : Mouse Right Menu
	*/
	function sheet1_OnSelectMenu(Text, Code) {
		  // text 또는 code값으로 Action수행
		switch(Text) {
	         case "ExcelDown":
	        	jQuery("#btnExcel").click();
	            break; 
		}
	}	
	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
	    	sheet1.SetColFontColor("BUILD_NAME", "#0000ff");
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	IBSheet Event: Click
	 */
	function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 if(Row == 0)return;
		 if ((sheet1.ColSaveName(Col) == "TEMPLATE_NAME") || (sheet1.ColSaveName(Col) == "BUILD_NAME")) {
				var status = sheet1.GetCellValue(Row,8);
				$("#SUB_CONT_MOD_ID").val(sheet1.GetCellValue(Row, "SUB_CONT_MOD_ID"));
				$("#TEMPLATE_CD").val(sheet1.GetCellValue(Row, "TEMPLATE_CD"));
				$("#ChgCont").val(sheet1.GetCellValue(Row, "CHG_CONT_YN"));
				$("#TEMPLATE_NAME").val(sheet1.GetCellValue(Row, "TEMPLATE_NAME"));
				$("#fevent").val("FORM_SELECT");
				$("#form1").attr("action", "/cont/outside/ContResult.screen");
				$("#form1").attr("target", "_self");
				$("#form1").attr("method", "get");
				$("#form1").submit();
			}else if(sheet1.ColSaveName(Col) == "IMG_GB"){
				var job_div = "O";
				var popUrl = "/payment/outside/PayItemOutDashBoardPop.screen?job_div="+job_div+"&sModule=LM&subContId="+sheet1.GetCellValue(Row, "SUB_CONT_ID")+"&job_auth=<%= user.get("RIGHT_NAME")%>";
				//CellValue(Row, "SUB_CONT_ID") = '7098';
				job_div = "O";
				var popOption = "width=800, height=600, resizable=no, scrollbars=yes, status=no;";
				window.open(popUrl,"",popOption);
	 		}
	 }
	/**
	 *	IBSheet Event Change
	 */	
	function sheet1_OnChange(Row, Col, Value, OldValue, RaiseFlag) { 
		var comboValue = sheet1.GetCellValue(Row,12);
		if(comboValue != "" ){
			sheet1.SetCellImage(Row ,13, "/img/buyer/button/bt_save_item.gif");
			return;
		}		
	}
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {sheet1.FitColWidth();}


	//자동로그인 기능
	function f_gologin(login_id,login_pw){
		var f = document.form1;
		if('<%= user.get("ACCT_TYPE_CODE")%>' != "ADMIN"){
			dlgAlert("User who logged in as administrator only can do automatic log-in.");
			return;
		}
	
		f.login_id.value = login_id;
		f.login_pw.value = login_pw;
	
		if( !submitXmlRequest("/sign_on_check", "", document.form1) ) {
			alert("Log-in is being processed.");
		};
		
	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
		
	}

	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	document.body.onresize = addEvent( document.body.onresize, "autoResize()");
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>

<form id="form1" name="form1" method="post" modular:type="search">
<INPUT type="hidden" name="fevent" id="fevent" value="">
<INPUT type="hidden" name="SUB_CONT_MOD_ID" value="">
<INPUT type="hidden" name="TEMPLATE_CD" value="">
<INPUT type='hidden' name="ChgCont">
<INPUT type='hidden' name="acct_id" value="<%= params.get("acct_id") %>">
<INPUT type='hidden' name="p_cont_status" value="50">
<INPUT type='hidden' name="TEMPLATE_NAME" value="">

<div align="left" id="title">
	<ul>
		<li>외주_계약결과</li>
	</ul>
</div> 

<!-- 검색조건 시작 -->
<table id="search-table" class="search-form-table">
	<colgroup>
		<col width="100" />
		<col width="*" />
		<col width="100" />
		<col width="*" />
		<col width="100" />
	</colgroup>
  <tr height="25"> 
  	<th>현장</th>
   	<td>
  		<%=InputText.getSiteCodeNew("p_dept_cd", "p_dept_nm", "", user, params.get("p_dept_cd"), params.get("p_dept_nm"))%>
	</td>
  	<th>계약명</th>
   	<td>
   		<INPUT type="text" name="p_build_nm" class="input" value="<%= params.get("p_build_nm") %>" style="width:90%"> 
	</td>
	<td class="button" rowspan="3">
		<span class="btnSearch center" id="btnSearch"><a href="javascript:void(0);">검색</a></span>
		<span class="btnSearch center" id="btnExcel"><a href="javascript:void(0);">엑셀</a></span>
	</td>	
  </tr>
  <tr>
    <th>업체명</th>
    <td> 
       <INPUT type="text" name="p_dealer_nm" class="input" value="<%= params.get("p_dealer_nm") %>" style="width:90%"> 
    </td>
    <th>계약기간</th>
    <td> 
		<%= InputText.get("ContFromDt", params.get("ContFromDt"), 10, 50, "hangule,center, desc=계약일자,ReadOnly") %>
		<IMG name="start_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('ContFromDt');">
					~
		<%= InputText.get("ContToDt", params.get("ContToDt"), 10, 50, "hangule,center, desc=계약일자,ReadOnly") %>
		<IMG name="start_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('ContToDt');">
		<IMG name="dataClear" id="dataClear" src="/img/buyer/button/bt_eraser1.gif" border="0" align="absmiddle" style="cursor:pointer;">
    </td>    
  </tr>
  <tr>
    <th>계약서종류</th>
    <td colspan=3> 
       <%= HTMLMaker.getSelectTag(contKindCode, "TEMPLATE_CD", "TEMPLATE_NAME" , "cont_Kind_Code", "style='width:28%;height=18;'", "<OPTION value=''>-- 전체 --</OPTION>", params.get("cont_Kind_Code"), 0) %>
	</td>
  </tr>
</table>
</form>


<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 400px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '400px');</script>
</div>