<%--
  - Author(s)  : Kim Myung HO
  - Date       : 2014.07.07
  - Description: 계약 작성
  --%>
  
<%@page import="java.sql.Clob"%>
<%@ 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.util.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.config.WAFConfig" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<%@ page import="kr.co.hsnc.common.util.Formatter"%>
<%@ page import="kr.co.udapsoft.ebid.buyer.common.file.FileManager"%>
<%@page import="java.net.URLEncoder"%>

<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();

    ValueObject ContInfo = storage.getValueObject("ContInfo");
    String RTN_REASON = "";
    boolean rtn = false;
    if(ContInfo.get("RTN_REASON").length() > 0){
    	RTN_REASON = ContInfo.get("RTN_REASON");
    	rtn = true;
    }

    /*계약서식 정보 START*/
    ValueObject templateInfo = storage.getValueObject("template");
    /*계약서식 정보 END*/
    
    /*보증 상세 정보*/
    ValueObject WarrContInfo = storage.getValueObject("WarrContInfo");
    
%>
<LINK href="/css/cont/cont_style.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/js/cont/cont_util.js"></script>
<script language="javascript" src="/js/cont/lib.validate.js"></script>
<SCRIPT language="JavaScript">
/*예약함수*/
	function _onReady(){
		/**
		 *	Application Initialize
		 */
			jQuery("#btnSignOk").click(function() {
				if (confirm("서명  하시겠습니까?")){
					SignData();
				}
			});
			jQuery("#btnEditCall").click(function() {
				if (confirm("수정 요청  하시겠습니까?")){
					var win_id = "editcall_pop";			
					var link = "/portal/cont/EditCallReasonPopup.screen";
					link += "?pop_win_id="+win_id+"&SUB_CONT_MOD_ID="+$("#SUB_CONT_MOD_ID").val();
					fLayerPop(win_id, link, 600,180, '','', 'NO');
				}
			});
	} 
	
	//자동로그인 기능
	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 goListProc(){
		 var f = document.form1;
		f.fevent.value ="";
	    f.action = "/portal/cont/PayGuarList.screen";
	    f.target = "_self";
	    f.submit();
	}

	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "SIGN_OK") {
				if( resultObj.getSuccess() ) {
					alert("서명이 정상적으로 처리 되었습니다.")
					goListProc();
				} else {
					dlgErrorMsg(resultObj);
				}
			}

			if( resultObj.getRequestEvent() == "EDIT_CALL") {
				if( resultObj.getSuccess() ) {
					alert("수정 요청이 처리 되었습니다.");
 					goListProc();
				}
				else {
					dlgErrorMsg(resultObj);
				}
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	//수정요청 팝업 종료후 액션
	function EditCallReasonClose(returnValue){
		if(returnValue == null){
			fLayerPopClose('editcall_pop');
		}else{
			if(returnValue[0] == 0){
				fLayerPopClose('editcall_pop');
				goListProc();
			}
		}
	}

	
	//첨부파일   
	function doAttachFileDiv(obj) {
		 if(obj==''){
			alert("저장을 한 후 파일을 첨부할 수 있습니다.");
		}
		else if(obj != ''){ 
			viewFileListNew('SUB_CONT_MOD_ID', obj.value, document.getElementById("attach_file_view"), "N", "cont/outside/<%=ContInfo.get("SUB_CONT_MOD_ID")%>");
		} 
	}
	/**
	 * 첨부파일 예약 함수
	 */
	function fileDown(file_id){
			var url="/common/file/FileDownloadServlet";
	 		url += "?file_id=" + file_id;
	 		
	 		window.open(url, "_fileDown", "toolbar=no, width=400, height=100, top=500, left=400, toolbar=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,target=new")
	}	

	function doAttachFilePop(obj, No, fObj, fileGB, fileDir) {
		var editFile = "";
		 if(obj==''){
			alert("After you have saved, you can attach a file.");
		}
		else if(obj != ''){ 
			if(fObj.guarStatus.value != "02"){editFile="N";}else{editFile="Y";}
			viewFileListNew(fileGB, obj.value, fObj.p_AttachFileGuar1, editFile, fileDir, "contOutWarrPopup");
		} 
	} 
	
	//보증정보팝업 호출
	function popContWarr(wG, wSeq, wCauseCd) {
		
		var win_id = "contOutWarrPopup";			
		var param = "";
		var param = "?subContModId=" + jQuery("#SUB_CONT_MOD_ID").val();
		var param = param + "&warrGubun=" + wG;
		var param = param + "&warrSeq=" + wSeq;
		var param = param + "&causeCode=" + wCauseCd;
		var param = param + "&viewDiv=CONT";
		var param = param + "&pop_win_id=" + win_id;
		var param = param + "&laborChk=" + jQuery("#LABORCheck").val();
		
		var url = "/portal/guar/contOutWarrPopup.screen"+param;
		
		fLayerPop(win_id, url, 560, 350, '','', 'YES');
	}	
	//보증정보팝업 종료후 액션
	function popContWarrClose(returnValue){
		if(returnValue == null){
			fLayerPopClose('contOutWarrPopup');
		}else{
			fLayerPopClose('contOutWarrPopup');
			location.reload();
		}
	}

</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="<%= params.get("fevent") %>">
<INPUT type="hidden" name="acct_id" value="<%= params.get("acct_id") %>">
<!-- 검색 조건 시작 -->
<INPUT type="hidden" name="p_dept_nm" value="<%= params.get("p_dept_nm") %>">
<INPUT type="hidden" name="p_cont_status" value="<%=params.get("p_cont_status")%>">
<INPUT type="hidden" name="ContFromDt" value="<%=params.get("ContFromDt")%>">
<INPUT type="hidden" name="ContToDt" value="<%=params.get("ContToDt")%>">
<INPUT type="hidden" name="p_build_nm" value="<%= params.get("p_build_nm") %>">
<!-- 검색 조건끝 -->

<INPUT type="hidden" name="CONT_STATUS" value="<%=ContInfo.get("CONT_STATUS")%>">
<INPUT type="hidden" name="SUB_CONT_MOD_ID" value="<%=ContInfo.get("SUB_CONT_MOD_ID")%>">
<INPUT type="hidden" name="O_CORP_ID" value="<%=ContInfo.get("O_CORP_ID")%>">
<INPUT type="hidden" name="C_VENDCD" value="<%=ContInfo.get("C_VENDCD")%>">

<!-- 계약서PDF정보  START-->
<INPUT type="hidden" name="TEMPLATE_CD" value="<%=ContInfo.get("TEMPLATE_CD") %>">
<INPUT type="hidden" name="CON_DOC_NO" value="<%=ContInfo.get("CON_DOC_NO") %>">
<INPUT type="hidden" name="MOD_NO" value="<%=ContInfo.get("MOD_NO") %>">
<INPUT type="hidden" name="PDF_FILE_CNT" value="1">
<!-- 계약서PDF정보  END-->

<!--서명 데이터 정보  START-->
<INPUT type='hidden' name="CONT_SIGNDATA" value="">
<INPUT type='hidden' name="CONT_SIGNDN" value="">
<INPUT type='hidden' name="signeddata" value="">

<INPUT type='hidden' name="WARR_SEQ" value="<%= params.get("WARR_SEQ") %>">
<INPUT type='hidden' name="PAGE_SEQ" value="<%= templateInfo.get("PAGE_SEQ") %>">
<INPUT type='hidden' name="CONT_HASH" value="<%= templateInfo.get("CONT_HASH") %>">
	<!-- 제목 및 버튼 -->
   	<table width="100%">
		<colgroup>
			<col width="500" />
			<col width="*" />
		</colgroup>
	<tr>
	   	<th>
		   <div align="left" id="title">
		    <ul>
		     <li>외주_하도급 대금 지급 소멸/수령확인</li>
		    </ul>
		   </div>
	   </th>
	   <td align="right">
			<%
				if(templateInfo.get("STATUS_CD").equals("20")){
			%>
			<span class="btnSearch center" id="btnSignOk"><a href="javascript:void(0);">서명</a></span>
			<!-- span class="btnSearch center" id="btnEditCall"><a href="javascript:void(0);">수정요청</a></span -->
			<%
				}
			%>
			<span class="btnSearch center" id="btnList"><a href="javascript:goListProc();">목록</a></span>
	   </td>
   	</tr>
   	</table>


<!-- 계약 정보 : 시작 -->
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">기본정보</span>
	</div>
	<div class="application-location">
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="130px" />
		<col width="23%"/>
		<col width="130px" />
		<col width="23%"/>
		<col width="130px" />
		<col width="23%"/>
	</colgroup>
  <TR height="25"> 
    <TH style="text-align: left;">현장명</TH>
	<TD colspan="3"><%=ContInfo.get("DEPT_NAME")%></TD>
	<TH style="text-align: left;">전자계약 여부</TH>
	<TD><%=ContInfo.get("ELEC_CON_YN").equals("Y") ? "온라인" : "오프라인" %></TD>	
  </TR>
	
  <TR height="25"> 
	<TH style="text-align: left;">계약명</TH>
	<TD colspan="5"><%=ContInfo.get("BUILD_NAME")%></TD>
  </TR>	
</TABLE>

<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">당사정보(원사업자) </span>
	</div>
	<div class="application-location">
	<%if (!templateInfo.get("O_SIGN_DATE").equals("")){%> 
		서명일시 : <%= templateInfo.get("O_SIGN_DATE") %> 
	<%}%>		
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="130px" />
		<col width="23%"/>
		<col width="130px" />
		<col width="23%"/>
		<col width="130px" />
		<col width="23%"/>
	</colgroup>
  <TR height="25"> 
	<TH style="text-align: left;">업체명</TH>
	<TD><%=ContInfo.get("O_MEMBER_NAME")%></TD>   
	<TH style="text-align: left;">주소</TH>
	<TD><%=ContInfo.get("O_ADDRESS")%></TD> 
	<TH style="text-align: left;">대표자명</TH>
	<TD><%=ContInfo.get("O_BOSS_NAME")%></TD> 	
  </TR>
  <TR height="25"> 
	<TH style="text-align: left;">담당부서</TH>
	<TD><%=ContInfo.get("O_DIVISION")%></TD>    
	<TH style="text-align: left;">담당자명</TH>
	<TD>
	  <%=ContInfo.get("O_USER_NAME")%>
 	</TD>         
	<TH style="text-align: left;">직급</TH>
	<TD><%=ContInfo.get("O_POSITION")%></TD>
  </TR>
  <TR height="25"> 
	<TH style="text-align: left;">담당자 연락처</TH>
	<TD><%=ContInfo.get("O_TEL_NUM")%></TD>
 	<TH style="text-align: left;">담당자 HP</TH>
	<TD><%=ContInfo.get("O_HP")%></TD>
	<TH style="text-align: left;">담당자 EMAIL</TH>
	<TD><%=ContInfo.get("O_EMAIL")%></TD> 	
  </TR>  
  <!-- 계약정보 : 종료 -->
</table>
   
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">계약업체정보(수급 사업자) </span>
	</div>
	<div class="application-location">
	<%if (!templateInfo.get("C_SIGN_DATE").equals("")){%> 
		서명일시 : <%= templateInfo.get("C_SIGN_DATE") %> 
	<%}%>
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="130px" />
		<col width="23%"/>
		<col width="130px" />
		<col width="23%"/>
		<col width="130px" />
		<col width="23%"/>
	</colgroup>
  <TR height="25"> 
	<TH style="text-align: left;">업체명</TH>
	<TD><%=ContInfo.get("C_MEMBER_NAME")%></TD>    
	<TH style="text-align: left;">주소</TH>
	<TD><%=ContInfo.get("C_ADDRESS")%></TD>  
	<TH style="text-align: left;">대표자명</TH>
	<TD><%=ContInfo.get("C_BOSS_NAME")%></TD> 	
  </TR>
  <TR height="25"> 
	<TH style="text-align: left;">담당부서</TH>
	<TD><%=ContInfo.get("C_DIVISION")%></TD>        
	<TH style="text-align: left;">담당자명</TH>
	<TD><%=ContInfo.get("C_USER_NAME")%></TD>          
	<TH style="text-align: left;">직급</TH>
	<TD><%=ContInfo.get("C_POSITION")%></TD>
  </TR>
  <TR height="25"> 
	<TH style="text-align: left;">담당자 연락처</TH>
	<TD><%=ContInfo.get("C_TEL_NUM")%></TD>
 	<TH style="text-align: left;">담당자 HP</TH>
	<TD><%=ContInfo.get("C_HP")%></TD>
	<TH style="text-align: left;">담당자 EMAIL</TH>
	<TD><%=ContInfo.get("C_EMAIL") %></TD> 	
  </TR>  
  <!-- 계약정보 : 종료 -->
</table>
<%if ((!ContInfo.get("MODI_REQ_REASON").equals("")) && (ContInfo.get("STATUS_CD").equals("40"))){	//수정 요청 내용이 있을경우 %>
<div class="application-info magT15">
	<div class="application-sub-title">
		<span class="title">수정요청 사유</span>
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="120" />
		<col width="*" />
	</colgroup>
  <TR height="25">
  	<TH style="text-align: left;">사유</TH>
	<TD><%=ContInfo.get("MODI_REQ_REASON") %></TD>
  </TR>
  <TR height="25">
  	<TH style="text-align: left;">요청일</TH>
	<TD><%=ContInfo.get("MODI_REQ_DT") %></TD>
  </TR>
 </TABLE>
 <% } %>
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">계약정보</span>
	</div>
	<div class="application-location">

	</div>
</div>

<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:1px solid black;padding-top:5px">
	<tr>
		<td align="center" bgcolor="#efefef">
		<table width="770px" border="0" cellspacing="0" cellpadding="0">
			<tr>
			  <td style="text-align:center;">
			  		<input type="hidden" name="template_seq" value="<%=templateInfo.get("SEQ")%>">
			  		<input type="hidden" name="template_name" value="<%=templateInfo.get("TEMPLATE_NAME")%>">
			  		<input type="hidden" name="template_style" value="<%=templateInfo.get("TEMPLATE_STYLE")%>">
			  		<input type="hidden" name="option_yn" value="<%=templateInfo.get("OPTION_YN")%>">
					<span class="tab_on" id="tab_<%=templateInfo.get("SEQ")%>" onClick="tabView(<%=templateInfo.get("SEQ")%>)">
						<input type="hidden" name="check_yn_<%=templateInfo.get("SEQ")%>" value="A">
						<%=templateInfo.get("TEMPLATE_NAME")%>
					</span>
			  </td>
			</tr>
		</table>
			<div id="__html" style="width:770px;border:1px solid black;padding:10px 10px 10px 10px;background-color:#FFFFFF;text-align:left;" >
				<%
	  				String template_html = ClobUtils.getClob((Clob)templateInfo.getObject("TEMPLATE_HTML")); 
	  				String divHidden = templateInfo.get("SEQ").equals("0")?"":"none";
		  		%>
		  		<div style="display:<%=divHidden%>; padding-top: 10px;overflow:hidden;overflow-y:auto;<%=templateInfo.get("TEMPLATE_STYLE") %>" id="__html_<%=templateInfo.get("SEQ")%>">
				<%= template_html%>
			</div>
			<br>
		</td>
	</tr>
</table>			

<div class="application-info magT15">
	<div class="application-sub-title">
		<span class="title">계약서류</span>
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="120" />
		<col width="*" />
	</colgroup>
  <TR height="25">
  	<TH style="text-align: left;">자동생성</TH>
	<TD>
		<table width="100%">
    		<colgroup>
	    		<col width="100%" />
    		</colgroup>		
			<TR height="25">
				<TD>
					<div id="auto_attach_file_view" class="attach_file_view">
						<ul>
						<li><a href="/common/file/FileDownloadServlet?mode=fpDown&filePath=/cont/<%=templateInfo.get("FILE_PATH")%>&fileName=<%=URLEncoder.encode(templateInfo.get("TEMPLATE_NAME"), "UTF-8") +"."+ templateInfo.get("FILE_EXT")%>&fileRealName=<%=templateInfo.get("UNIQUE_FILE_NAME")%>"><%=templateInfo.get("TEMPLATE_NAME")%> (<%=templateInfo.get("FILE_SIZE").trim() %>)</a></li>
						</ul>
					</div>
				</TD>
			</TR>
		</TABLE>		
	</TD>	
  </TR>
 </TABLE>
 
</form>

<!-- =========사인 요청 상태이후 (20)에는 입력을 받지 못하게 처리 (김명호 : 2014-07-21)============== -->
<script>
//window.addEventListener("onload",convertHtml)
window.onload = function() {  
	convertHtml();
};	
	
function convertHtml(){
	if(!document.getElementById("__html"))return;
	var elements = document.getElementById("__html").getElementsByTagName("input");
	for(var i = 0; i < elements.length; i++){
		var element = elements[i];
		setDisabled(element);
	}
	var elements = document.getElementById("__html").getElementsByTagName("textarea");
	for(var i = 0; i < elements.length; i++){
		var element = elements[i];
		element.className = "input_readonly";
		element.readOnly = true;
	}
	var elements = document.getElementById("__html").getElementsByTagName("img");
	for(var i = 0; i < elements.length; i++){
		var element = elements[i];
		element.style.display="none";
	}
	/*협력사에서 안보이는 부분숨기는 처리*/
	var elements = getElementsByClass("cl_no_view");
	for(var i = 0; i < elements.length; i++){
		var element = elements[i];
		element.style.display="none";
	}
}
</script>

<!-- ------------------서명 요청 처리 로직-------- -->
<SCRIPT LANGUAGE="JavaScript">
<!--
function SignData()
{

	var VendorCd = document.form1.C_VENDCD.value;
	var sOrgnData = $("#CONT_HASH").val();
	
	unisign.SignDataNVerifyVID( sOrgnData, null, VendorCd, function( resultObject ) {
		if( !resultObject || resultObject.resultCode != 0 ){
			if( resultObject.resultCode == '14208'){
				alert("주민번호/사업자번호를 확인할 수 없는 인증서입니다.");
			} else if( resultObject.resultCode == '999'){
				alert("사용자 DN 선택이 취소 되었습니다.");
			} else {
				alert( resultObject.resultMessage);
			}
			
			return ;
		}
		
		var signeddata = resultObject.signedData;
		var userdn = resultObject.certAttrs.subjectName;
		
		$("#CONT_SIGNDATA").val(signeddata);
		$("#CONT_SIGNDN").val(userdn);

		alert("신원확인 성공");
		var f = document.form1;
		jQuery("#fevent").val("SIGN_OK");
		submitXmlRequest("/portal/cont/PayGuarDetail_form.screen", "SIGN_OK", f);
	});
	 
}
//-->
</SCRIPT>
<FRAME src="" name="main" width="1" height="1" style="display:none;"></FRAMESET>
<!-- 전자인증 모듈 //-->
<br/><br/>

<!-- 전자인증 모듈 설정 //-->
<link rel="stylesheet" type="text/css" href="/CrossCert/CC_WSTD_home/unisignweb/rsrc/css/certcommon.css?v=1" />
<script type="text/javascript" src="/CrossCert/CC_WSTD_home/unisignweb/js/unisignwebclient.js?v=1"></script>
<script type="text/javascript" src="/CrossCert/UniSignWeb_Multi_Init_Nim.js?v=1"></script>
<!-- 전자인증 모듈 설정 //-->