<%--
  - Author(s)  : 최훈석
  - Date       : 2022.11.08
  - Description: 서약서
  --%>
  
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.ui.InitCombo" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.udapsoft.common.code.CommCodeManager" %>
<%-- <%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" /> --%>
<%
	

	//CommCodeManager commCodeManager = new CommCodeManager();
	
	RowSet proGbRow = CommCodeManager.getCodeRowsetStatic("PROMISE_DOC_TYPE");

	InitCombo initCombo2 = new InitCombo();
	initCombo2.makeComboData(CommCodeManager.getCodeRowsetStatic("PROMISE_DOC_TYPE", "CHG_CODE01", "Y"), "DETAILNM", "DETAILCD");
	/* initCombo.makeComboData(commCodeManager.getCodeRowSet("STAMP_DUTY_ISSUE_GB"), "NAME", "CODE"); */
	String PROMISE_DOC_CD = initCombo2.getCode();
	String PROMISE_DOC_NM = initCombo2.getCodeName();
	
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet3;
	var sheet3Row;
	var sheet3PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	/* function _onReady(){
		
	} */
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit3(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10};
		init_sheet.Cols = [
		       			{Header:'Del',				Type:"DelCheck",		SaveName:"DEL_CHECK", 			Width:30, 		Align:"Center"},
		       			{Header:'Status',			Type:"Status", 			SaveName:"STATUS", 				Width:0, 		Align:"Center", Hidden:"true"},
		    			{Header:'서약서ID',			Type:"Text", 			SaveName:"PROMISE_DOC_ID", 		Width:0, 		Align:"Center", Hidden:"true"},
		    			{Header:'서약서종류',			Type:"Combo", 			SaveName:"PROMISE_DOC_TYPE_GB",	Width:80, 		Align:"Center",	ComboText:"<%=PROMISE_DOC_NM%>", ComboCode:"<%=PROMISE_DOC_CD%>"},
		    			{Header:'비고',				Type:"Text", 			SaveName:"REMARK", 				Width:150, 		Align:"Left", 	EditLen:"500"},
		    			{Header:'☞사본',			Type:"Text", 			SaveName:"FILE_YN", 			Width:30, 		Align:"center", Edit:"false",	Cursor:'pointer'},
		    			{Header:'FILE_ID',			Type:"Text", 			SaveName:"FILE_ID", 			Width:0, 		Align:"center", Hidden:"true"},
		]; 

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetImageList(1,"/img/buyer/button/bt_change.gif");
		if(jQuery("#STATUS_CD").val() == '50'){
			sheet3.SetEditable(0);
		}
		//sheetName.SetActionMenu("ExcelDown");
		setGridSize3();
	}
	
	function doSearchPromise() {
		jQuery("#fevent").val("FORM_PROMISE_SELECT");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/PromiseList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet3, url, jQuery("#form1"), 30, "");
	}
	function doSavePromise() {
		jQuery("#fevent").val("SAVE_PROMISE_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/PromiseList_sheet.screen";
		Modular.view.IBSheet7.doSave(sheet3, url, jQuery("#form1"), false);
	}
	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet3_OnSearchEnd(code, message) {
		var info = {Type: "Image"};

		if(code == 0) {
	    	setGridSize3();
			sheet3.SetColFontColor("FILE_YN", "#0000ff");
	    
	    	for(i=1; i <= sheet3.RowCount(); i++){
				if(sheet3.GetCellValue(i, "FILE_ID")!=""){
					sheet3.InitCellProperty(i, "FILE_YN", info);
				}
			}
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	function sheet3_OnSaveEnd(code, msg) {
	    if(code >= 0) {
	    	if(jQuery("#save_gb").val() != 'Y'){
	    		alert("서약서가 정상적으로 처리 되었습니다.");
	    	}
	    } else {
	    	//alert(msg);
	    	alert("서약서 등록에 실패 하였습니다.");
        }
	    doSearchPromise();
	}
	
	/**
	 *	IBSheet Event Change
	 */	
	function sheet3_OnChange(Row, Col, Value, OldValue, RaiseFlag) { 
		if (sheet3.ColSaveName(Col) == "REMARK") {
			if(stringByteSize4UTF(sheet3.GetCellValue(Row, "REMARK")) > 500){
				alert("비고는 500자까지 입력하실 수 있습니다.");
				sheet3.SetCellValue(Row, "REMARK", "");
				return;
			}
		}
	}
	
	/*
	IBSheet Event : Mouse Right Menu
	*/
	function sheet3_OnSelectMenu(Text, Code) {
		  // text 또는 code값으로 Action수행
		switch(Text) {
	         case "ExcelDown":
	        	jQuery("#btnExcel").click();
	            break; 
		}
	}	
	
	function sheet3_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 if(Row == 0)return;
		 if (sheet3.ColSaveName(Col) == "FILE_YN") {
			 
			 if(sheet3.GetCellValue(Row, "PROMISE_DOC_ID")=='' || sheet3.GetCellValue(Row, "STATUS")=="I" || sheet3.GetCellValue(Row, "STATUS")=="U"){
					alert("입력한 내용을 저장을 한 후 파일을 첨부할 수 있습니다.");
				} 
			else{ 
				var PROMISE_DOC_ID = sheet3.GetCellValue(Row, "PROMISE_DOC_ID")
				var modify = 'Y';
				if(jQuery("#STATUS_CD").val() =='50' || jQuery("#p_promise_gb").val() == '00'){
					modify ='N'
				}
				viewFileListNew2('PUR_PROMISE_DOC', PROMISE_DOC_ID, "", modify, "cont/purchase/promise/"+PROMISE_DOC_ID, "", "", "", "N");
			} 
	     }
	 }

	 function viewFileListNew2(fileGB, id, obj, isModify, isDrectory, iframeID, user_filename, file_size, multi_yn) {
	 	
	 	var win_id = "_promiseFileList";
	 	var link = "/common/file/FileListNew.screen";
	 	    link += "?pop_win_id="+win_id;
	 	    link += "&file_gb=" + fileGB;
	 	    link += "&id=" + id;
	 	    
	 	    if( obj.id != null )
	 		    link += "&obj_id=" + obj.id;
	 	    if( iframeID != null )
	 	    	link += "&iframeID=" + iframeID;
	 	    
	 		if( isModify != null )
	 			link += "&is_modify=" + isModify;
	 		if( isDrectory != null )
	 			link += "&sys_gb=" + isDrectory;	    
	 		if( file_size != null )
	 			link += "&file_size=" + file_size;	    
	 		if( multi_yn != null )
	 			link += "&multi_yn=" + multi_yn;	    
	 		if( user_filename != null )
	 			link += "&user_filename=" + encodeURIComponent(user_filename);	 
	 	
	 		 
	 	fLayerPop(win_id, link, 750,430, '', '', 'NO', '200');
	 }
	
	 function fLayerPopClose(layerID){
		 var	oNode	=	document.getElementById(layerID);
		if(oNode != null)
		{
			$('#'+layerID+ '_divcontent').empty();
			$('#'+layerID).bPopup().close();
			document.body.removeChild(oNode);
		}
		
		 if(layerID == "_promiseFileList"){
			 doSearchPromise();
		 }
	 }
	 
	function promiseRowCheck() {
		for(i=1; i <= sheet3.RowCount(); i++){
			if(sheet3.GetCellValue(i, "STATUS")!="R"){
				alert("서약서중 저장되지 않은 행이 존재합니다.");
				return false;
			}
		}
		return true;
	}
	 
	function promise_gb_chg() {
		if(jQuery("#p_promise_gb").val()=="00"||jQuery("#p_promise_gb").val()==""){
			jQuery("#btnPromiseAdd").hide();
		}else{
			jQuery("#btnPromiseAdd").show();	
		}
	}
	
	/* function stampDesc()
	{
		var win_id = "_stampPopup";
		var link = "/cont/purchase/stampDescPopup.screen";
		    link += "?pop_win_id="+win_id;
		fLayerPop(win_id, link, 400,210, '', '', 'NO');
	} */
	function downPromiseFile(){
		var url="/common/file/FileDownloadServlet?mode=fpDown";
		url += "&mode=fpDown";
		url += "&filePath=/promiseDoc";
		url += "&fileName=" + encodeURI("서약서 양식.zip");
		url += "&fileRealName=promise_doc.zip";
		
		document.getElementById("fileDown").src=url;
	}
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize3() {sheet3.FitColWidth();}
	
	document.body.onresize = addEvent( document.body.onresize, "setGridSize3()"); 
</SCRIPT>




<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">서약서</span><font color="red"></font> <a href="javascript:downPromiseFile()"><IMG src='/img/buyer/button/bt_change.gif' align="absmiddle"></a>
	</div>
</div>
<!-- 검색조건 시작 -->
<table id="search-table" class="search-form-table">
  <tr height="25"> 
  	<td>서약서 구분:&nbsp;&nbsp;<%= HTMLMaker.getSelectTag(proGbRow, "CODE", "NAME", "p_promise_gb", "style='width:200px;' onChange='promise_gb_chg();'", "", ContInfo.get("STAMP_DUTY_GB")) %></td>
	<td class="button" align="right" style="text-align: center;width: 95px">
		<span class="btnSearch center" id="btnPromiseAdd" style="display: none;"><a href="javascript:void(0);">추가</a></span>
		<%-- <%if(isViewWrite != "W"){ %> --%>
		<span class="btnSearch center" id="btnSavePromise" ><a href="javascript:void(0);">저장</a></span>
		<%-- <%} %> --%>
	</td>	
  </tr>
</table>
<div id="sheet3_div" style="padding-top:5px; height: 157px; min-height: 157px; overflow: auto;">
<!-- <div id="sheet3_div" style="padding-top:5px; height: auto; min-height: 100px; overflow: auto;"> -->
	<script>createIBSheet('sheet3','100%', '157px');</script>
</div>
<iframe id="fileDown" name="fileDown" style="display:none"></iframe>
