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

    String event = storage.getEvent();
//    System.out.println("event ======== : " + ContInfo.get("DOC_ETC_IN"));
    
   // RowSet CorpRowSet = storage.getRowSet("CorpRowSet");
    ValueObject ContInfo = storage.getValueObject("ContInfo");

    /*계약서식 정보 */
    RowSet template = storage.getRowSet("template");

    /*계약서식 FILE */
	RowSet autofile_list = storage.getRowSet("AUTOFILE_LIST");    
    
    /*보증 정보 LIst */
	RowSet warrList = storage.getRowSet("warrList");    
    
    /*보증 발급 완료된 갯수 */
	RowSet warrCount = storage.getRowSet("warrCount");    
    
%>
<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(){
		/* STAMP_DUTY, PROMISE_DOC 인클루드 페이지 기능 */
		gridInit2(sheet2);
		gridInit3(sheet3);
		doSearchStamp();
		doSearchPromise();
		
		//2016.12.5 증권면제 목록표기 제외. 
		if ("<%=ContInfo.get("MOD_NO")%>"!="0") {
		if (document.form1.chgContChk7.checked == true){
			<% if(warrList.size() > 0) {%>
			    var obj = eval("document.getElementById('guar_div')");
			    obj.style.display = "none";
		    <% } %>
		}
		}
					
	 	
		if(jQuery("#STATUS_CD").val() == '20' && jQuery("#p_issue_gb").val() == '20' ){
			jQuery("#p_issue_gb").attr("disabled",true);
			jQuery("#p_promise_gb").attr("disabled",false);
			jQuery("#btnAdd").show();
			jQuery("#btnSaveStamp").show();
			jQuery("#btnPromiseAdd").show();
			jQuery("#btnSavePromise").show();
		}else{
			jQuery("#p_issue_gb").attr("disabled",true);
			jQuery("#btnAdd").hide();
			jQuery("#btnSaveStamp").hide();	
			jQuery("#btnPromiseAdd").hide();
			jQuery("#btnSavePromise").hide();
		}
		
		jQuery("#btnAdd").click(function() {
			var win_id = "_StampDutyPop";
			var link = "/cont/outside/stampDutyPop.screen";
			    link += "?pop_win_id="+win_id
			    link += "&p_move=I"
			    link += "&p_cont_mod_id="+"<%=ContInfo.get("SUB_CONT_MOD_ID")%>"
			    link += "&p_who=P";
			    
			fLayerPop(win_id, link, 700,250, '', '', 'NO');
			/*2016.12.14 인지세수정 
			var rowIdx = sheet2.DataInsert(-1);
			sheet2.SetCellValue(rowIdx, "STAMP_DUTY_ISSUE_GB", "20");*/
		});
		
		jQuery("#btnPromiseAdd").click(function() {
			var rowIdx = sheet3.DataInsert(-1);
			if(jQuery("#p_promise_gb").val()=="10"){
				sheet3.SetCellValue(rowIdx, "PROMISE_DOC_TYPE_GB", "10");
			}else{
				sheet3.SetCellValue(rowIdx, "PROMISE_DOC_TYPE_GB", "20");
			}
		});
		
		jQuery("#btnSaveStamp").click(function() {
			
			for(i=1; i <= sheet2.RowCount(); i++){
				if(sheet2.GetCellValue(i, "STATUS")!="D"){
					if(sheet2.GetCellValue(i, "STAMP_DUTY_NO")==""){
						alert(i+"행의 고유식별번호가 없습니다.");
						return false;
					}
					if(sheet2.GetCellValue(i, "STAMP_DUTY_TAX")=="" || sheet2.GetCellValue(i, "STAMP_DUTY_TAX")<=0){
						alert(i+"행의 인지세가 없거나 인지세가 0보다 작거나 같습니다.\n인지세는 0보다 커야합니다.");
						return false;
					}
					if(sheet2.GetCellValue(i, "STAMP_DUTY_DATE")==""){
						alert(i+"행의 발행일자가 없습니다.");
						return false;
					}
				}
			}
			
			if (confirm("저장하시겠습니까?")) {
				jQuery("#fevent").val("SAVE_STAMP_LIST");
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/outside/StampList_sheet.screen";
				var result = Modular.view.IBSheet7.doSave(sheet2, url, jQuery("#form1"), false);
			}
		}); 
		
		jQuery("#btnSavePromise").click(function() {
			
			if(jQuery('#p_promise_gb').val() == '00' && sheet3.GetTotalRows() != 0 ){
				for(i=1; i <= sheet3.RowCount(); i++){
					if(sheet3.GetCellValue(i, "STATUS")!="D"){
						alert("서약서를 미발행으로 등록하려면\n서약서가 등록되어있거나 등록해서는 안됩니다.\n서약서를 삭제하여 주십시오.");
						return;
					}
				}
			}
			
			if (confirm("저장하시겠습니까?")) {
				doSavePromise();
			}
			
		});
		
		/**
		 *	Application Initialize
		 */
		jQuery("#btnSignOk").click(function() {
			//var stampMsg = '서명  하시겠습니까?';
			if(jQuery('#p_issue_gb').val() == '00' && sheet2.GetTotalRows() != 0 ){
				alert("인지세 발급 구분이 미발행일시 등록 된 인지세가 없어야 합니다. 삭제하여 주십시오.");
				return;
			}else{
				//2016.12.2 수정. 변경계약 면제 체크된 경우 처리
				var f = document.form1;
				
				if ("<%=ContInfo.get("MOD_NO")%>"=="0") {
					if(<%=warrCount.size() %>!=<%=warrList.size() %>){
						alert("해당 보증서의 진행 상태가 모두 발급 완료 상태일때 서명을 진행 하실수 있습니다.");
						return;
					}
				}
				else{
					//변경계약 && 변경계약 합의서  (자유서식(변경)은 모두 오프라인. 이 페이지 오픈될수가 없음) 
					if (f.chgContChk7.checked == false){
						if(<%=warrCount.size() %>!=<%=warrList.size() %>){
							alert("해당 보증서의 진행 상태가 모두 발급 완료 상태일때 서명을 진행 하실수 있습니다.");
							return;
						}
					}
				}
				
				<%-- if(<%=warrCount.size() %>!=<%=warrList.size() %>){
					alert("해당 보증서의 진행 상태가 모두 발급 완료 상태일때 서명을 진행 하실수 있습니다.");
					return;
				}  --%>
			    
				if(!stampDutyRowCheck()){
					return;
				}
				
				if( !stampDutyCheck() ) {
					return;
				}
				
				if(!promiseRowCheck()){
					return;
				}
				
				if(!promiseCheck()){
					return;
				}
				
				if(jQuery('#p_issue_gb').val() != '00' && sheet2.GetTotalRows() == 0){
					alert("등록 된 인지세가 없습니다.");
					return;
				}else if( jQuery('#p_issue_gb').val() != '00' && sheet2.GetTotalRows() != 0 ){	
					
					var ordAmt = parseInt(jQuery('#con_amt').val().replace(/,/gi,""));
					var stampDutyTax = sheet2.GetCellValue(sheet2.LastRow(), "STAMP_DUTY_TAX");
					
					if( ordAmt <= 10000000 ){
						if( stampDutyTax != 0 ) {
							alert("계약금액에 따른 인지세가 틀립니다.\n\n1천만원 이하 : 0원\n\n서명  하시겠습니까?");
							//stampMsg = '계약금액에 따른 인지세가 틀립니다.\n\n1천만원 이하 : 0원\n\n서명  하시겠습니까?';
						}
					}else if( ordAmt > 10000000 && ordAmt <= 30000000 ) {
						if( stampDutyTax != 20000 ) {
							alert("계약금액에 따른 인지세가 틀립니다.\n\n1천만원 초과 ~ 3천만원이하 : 2만원\n\n서명  하시겠습니까?");
							//stampMsg = '계약금액에 따른 인지세가 틀립니다.\n\n1천만원 초과 ~ 3천만원이하 : 2만원\n\n서명  하시겠습니까?';
						}
					}else if( ordAmt > 30000000 && ordAmt <= 50000000 ) {
						if( stampDutyTax != 40000 ) {
							alert("계약금액에 따른 인지세가 틀립니다.\n\n3천만원 초과 ~ 5천만원이하 : 4만원\n\n서명  하시겠습니까?");
							//stampMsg = '계약금액에 따른 인지세가 틀립니다.\n\n3천만원 초과 ~ 5천만원이하 : 4만원\n\n서명  하시겠습니까?';
						}
					}else if( ordAmt > 50000000 && ordAmt <= 100000000 ) {
						if( stampDutyTax != 70000 ) {
							alert("계약금액에 따른 인지세가 틀립니다.\n\n5천만원 초과 ~ 1억원이하 : 7만원\n\n서명  하시겠습니까?");
							//stampMsg = '계약금액에 따른 인지세가 틀립니다.\n\n5천만원 초과 ~ 1억원이하 : 7만원\n\n서명  하시겠습니까?';
						}
					}else if( ordAmt > 100000000 && ordAmt <= 1000000000 ) {
						if( stampDutyTax != 150000 ) {
							alert("계약금액에 따른 인지세가 틀립니다.\n\n1억원 초과 ~ 10억원이하 : 15만원\n\n서명  하시겠습니까?");
							//stampMsg = '계약금액에 따른 인지세가 틀립니다.\n\n1억원 초과 ~ 10억원이하 : 15만원\n\n서명  하시겠습니까?';
						}
					}else if( ordAmt > 1000000000 ) {
						if( stampDutyTax != 350000 ) {
							alert("계약금액에 따른 인지세가 틀립니다.\n\n10억원 초과 : 35만원\n\n서명  하시겠습니까?");
							//stampMsg = '계약금액에 따른 인지세가 틀립니다.\n\n10억원 초과 : 35만원\n\n서명  하시겠습니까?';
						}
					}
				}
			}
		
			if("<%=ContInfo.get("MOD_NO")%>"=="0"){
				openPopUpCont();
			}else{
				openPopUpChgCont();
			}
			//sign
		});	
		
		jQuery("#btnEditCall").click(function() {
		<%if(warrList.size() > 0) {%>
			if(<%=warrCount.size() %>==<%=warrList.size() %>){
				alert("모든 보증서가 발급 완료 상태일때는 수정 요청을 하실수 없습니다.");
				return;
			}
		<% } %>
		
			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 ="";
		<%if (params.get("p_cont_status").equals("50")){%>
	    f.action = "/portal/cont/SuppContResultList.screen";
	    <%}else{%>
	    f.action = "/portal/cont/SuppContList.screen";
	    <%}%>		
	    f.target = "_self";
	    f.submit();
	}

	//외주내역 팝업 2018.10.18
	function goItemPop() {	
		var win_id = "ItemPop";			

		var link = "/cont/outside/ContItemPopup.screen";
		link += "?pop_win_id="+win_id+"&sub_cont_mod_id="+"<%=ContInfo.get("SUB_CONT_MOD_ID")%>"+"&digit="+"<%=ContInfo.get("SOSUNUM")%>"+"&edit_yn=N";
		fLayerPop(win_id, link, 950,500, '','', 'NO');
	}	

	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") || (fObj.guarStatus.value == "04")){editFile="Y";}else{editFile="N";}
			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 + "&wonWarr=" + jQuery("#WON_WARR").val();
		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();
		}
	}

	<%-- function doAttachStampFile(obj){
		if(obj.value==''){
			alert("저장을 한 후 파일을 첨부할 수 있습니다.");
		}
		else if(obj != ''){ 
			viewFileListNew('SUB_STAMP_DUTY', obj.value, document.getElementById("attach_file_view_stamp"), "Y", "cont/outside/stamp/<%=ContInfo.get("SUB_CONT_MOD_ID")%>", "_stampFile", "", "", "N");
		}
	} --%>
	
	function stampDutyCheck(){
		
		for(i=1; i <= sheet2.RowCount(); i++){
			if(sheet2.GetCellValue(i, "STATUS")!="D"){
				if(sheet2.GetCellValue(i, "STAMP_DUTY_NO")==""){
					alert("인지세 "+i+"행의 고유식별번호가 없습니다.");
					return false;
				}
				if(sheet2.GetCellValue(i, "STAMP_DUTY_TAX")=="" || sheet2.GetCellValue(i, "STAMP_DUTY_TAX")<=0){
					alert("인지세 "+i+"행의 인지세가 없거나 인지세가 0보다 작거나 같습니다.\n인지세는 0보다 커야합니다.");
					return false;
				}
				if(sheet2.GetCellValue(i, "STAMP_DUTY_DATE")==""){
					alert("인지세 "+i+"행의 발행일자가 없습니다.");
					return false;
				}
				if(sheet2.GetCellValue(i, "FILE_ID")==""){
					alert("인지세 "+i+"행의 인지세사본이 없습니다.");
					return false;
				}
			}
		}
		return true;
	} 

	function promiseCheck(){
		for(i=1; i <= sheet3.RowCount(); i++){
			var sText = sheet3.GetComboInfo(i, "PROMISE_DOC_TYPE_GB", "Text");
			var sCode = sheet3.GetComboInfo(i, "PROMISE_DOC_TYPE_GB", "Code");
			var arrText = sText.split("|");
			var arrCode = sCode.split("|");

			if(sheet3.GetCellValue(i, "STATUS")!="D"){
				if(sheet3.GetCellValue(i, "FILE_ID")==""){
					for(j=0; j<arrCode.length; j++){
						if(sheet3.GetCellValue(i, "PROMISE_DOC_TYPE_GB")==arrCode[j]){
							alert(i+"행의 "+arrText[j]+" 사본이 없습니다.");
							break;
						}
					}
					//alert(i+"행의 "+sheet3.GetCellValue(i, "PROMISE_DOC_TYPE_GB")+" 사본이 없습니다.");
					return false;
				}
			}
		}
		return true;
	}

	function openPopUpChgCont() {	//변경계약 팝업
		var url = "/html/portal_chgcont_note_popup.html";
		fLayerPop("popup",url,640,395,'','', 'NO');
	}

	function openPopUpCont() {		//당초계약 팝업
		var url = "/html/portal_cont_note_popup.html";
		fLayerPop("popup",url,640,655,'','', 'NO');
	}
	
	$.check = function(returnValue){//팝업 후 서명처리
		if(returnValue==true){
			var stampMsg = '서명  하시겠습니까?';
			fLayerPopClose('popup');
			if (confirm(stampMsg)){
				SignData();
			}
			//submit
		}
	}
	
</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="STATUS_CD" value="<%=ContInfo.get("STATUS_CD")%>">
<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="<%=template.size()%>">
<INPUT type="hidden" name="TRUE_RANDOM" value="<%=ContInfo.get("TRUE_RANDOM") %>">
<!-- 계약서PDF정보  END-->

<INPUT type="hidden" name="WON_WARR" value="<%=params.get("WON_WARR") %>">
<!--서명 데이터 정보  START-->
<INPUT type='hidden' name="CONT_HASH" value="<%=ContInfo.get("CONT_HASH") %>">
<INPUT type='hidden' name="CONT_SIGNDATA" value="">
<INPUT type='hidden' name="CONT_SIGNDN" value="">
<INPUT type='hidden' name="signeddata" value="">

<%-- <INPUT type="hidden" id="stamp_duty_issue_gb" name="stamp_duty_issue_gb" value="<%=ContInfo.get("STAMP_DUTY_ISSUE_GB") %>">
<INPUT type="hidden" id="STAMP_DUTY_ID" name="STAMP_DUTY_ID" value="<%=ContInfo.get("STAMP_DUTY_ID") %>"> --%>

	<!-- 제목 및 버튼 -->
   	<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(ContInfo.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="btnItem"><a href="javascript:goItemPop();">계약내역</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>
<%@ include file="/jsp/ko_KR/supplier/portal/cont/SuppStampDuty.jsp" %>
<%@ include file="/jsp/ko_KR/supplier/portal/cont/SuppPromiseDocList.jsp" %>
<%-- 
<%
if( ContInfo.get("STAMP_DUTY_ISSUE_GB").equals("20") ){
%>
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">인지세(협력사) </span> <font color="red">※ 전자문서 계약자가 인지세무(과소) 납부시 가산세가 300% 부가됨</font> <a href="javascript:downStampFile()"><IMG src='/img/buyer/button/bt_change.gif' align="absmiddle"></a>
	</div>
</div>
	<%
	if ( ContInfo.get("STATUS_CD").equals("20") ) {
	%>
<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><%= InputText.get("stamp_duty_no", ContInfo.get("STAMP_DUTY_NO"), 97, 50, "desc=고유식별번호,persize,hangule") %></TD>   
	<TH style="text-align: left;">인지세액 <a href="javascript:stampDesc()"><IMG src='/img/buyer/button/q.gif' align="absmiddle"></a></TH>
	<TD><%= InputText.get("stamp_duty_tax", Formatter2.currency(ContInfo.getDouble("STAMP_DUTY_TAX"), 0), 97, 20, "desc=인지세액,persize,Number,right","number") %></TD> 
	<TH style="text-align: left;">발행일자</TH>
	<TD>
		<%= InputText.get("stamp_duty_date", Formatter2.formatDate(ContInfo.get("STAMP_DUTY_DATE"), "-"), 30, 10, "Center, date, PerSize, readonly", "date", "") %>
		<A href="JavaScript:dlgCalendar('stamp_duty_date');" id="stampCalImg"><IMG src="/img/supplier/template/bt_calender.gif" alt="달력" border="0" align="absmiddle"></A>
	</TD> 	
  </TR>
  <TR height="25"> 
	<TH style="text-align: left;">인지세사본</TH>
	<TD>
		<div id="attach_file_view_stamp" class="attach_file_view" style="width:80%; text-overflow:ellipsis; white-space: nowrap; overflow: hidden; float: left;">
			<%=FileManager.getFileListForDiv("SUB_STAMP_DUTY", ContInfo.get("SUB_CONT_MOD_ID")) %>
		</div>
		<div style="text-align: right;">
			<IMG id='search_spot_button_stamp' onClick="doAttachStampFile(document.form1.SUB_CONT_MOD_ID,1);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
		</div>
	</TD>    
	<TH style="text-align: left;">비고</TH>
	<TD colspan="3">
		<%= InputText.get("remark", ContInfo.get("REMARK"), 97, 500, "desc=비고,persize,hangule") %>
 	</TD>         
  </TR>
</table>
	<%
	}else {
	%>
<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("STAMP_DUTY_NO") %></TD>   
	<TH style="text-align: left;">인지세액</TH>
	<TD><%= Formatter2.currency(ContInfo.getDouble("STAMP_DUTY_TAX"), 0) %></TD> 
	<TH style="text-align: left;">발행일자</TH>
	<TD>
		<%= Formatter2.formatDate(ContInfo.get("STAMP_DUTY_DATE"), "-") %>
	</TD> 	
  </TR>
  <TR height="25"> 
	<TH style="text-align: left;">인지세사본</TH>
	<TD>
		<div id="attach_file_view_stamp" class="attach_file_view">
			<%=FileManager.getFileListForDiv("SUB_STAMP_DUTY", ContInfo.get("SUB_CONT_MOD_ID")) %>
		</div>
	</TD>    
	<TH style="text-align: left;">비고</TH>
	<TD colspan="3">
		<%= ContInfo.get("REMARK") %>
 	</TD>         
  </TR>
</table>
	<%
	}
}
%>
 --%>
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">당사정보(원사업자) </span>
	</div>
	<div class="application-location">
	<%if (!ContInfo.get("O_SIGN_DATE").equals("")){%> 
		서명일시 : <%= ContInfo.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 (!ContInfo.get("C_SIGN_DATE").equals("")){%> 
		서명일시 : <%= ContInfo.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;">
			  		<%
			  			for(int i = 0 ; i < template.size(); i ++){
			  		%>
			  		<input type="hidden" name="template_seq" value="<%=template.getRow(i).get("SEQ")%>">
			  		<input type="hidden" name="template_name" value="<%=template.getRow(i).get("TEMPLATE_NAME")%>">
			  		<input type="hidden" name="template_style" value="<%=template.getRow(i).get("TEMPLATE_STYLE")%>">
			  		<input type="hidden" name="option_yn" value="<%=template.getRow(i).get("OPTION_YN")%>">
			  		<%	if(i==0){ %>
					<span class="tab_on" id="tab_<%=template.getRow(i).get("SEQ")%>" onClick="tabView(<%=template.getRow(i).get("SEQ")%>)">
						<input type="hidden" name="check_yn_<%=template.getRow(i).get("SEQ")%>" value="A">
						<%=template.getRow(i).get("TEMPLATE_NAME")%>
					</span>&nbsp;
					<%	}else{ %>
					<span class="tab_off" id="tab_<%=template.getRow(i).get("SEQ")%>" onClick="tabView(<%=template.getRow(i).get("SEQ")%>)">
						<%if(template.getRow(i).get("OPTION_YN").equals("A")){%>
						<input type="hidden" name="check_yn_<%=template.getRow(i).get("SEQ")%>" value="A">
						<%}else if(template.getRow(i).get("OPTION_YN").equals("Y")){ %>
						<input type="checkbox" name="check_yn_<%=template.getRow(i).get("SEQ")%>" value="Y" <%if(template.getRow(i).get("CHECK_YN").equals("Y")){%>checked="checked"<%}%>>
						<%} %>
						<%=template.getRow(i).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;" >
				<%
			  			for(int i = 0 ; i < template.size(); i ++){
			  				String template_html = ClobUtils.getClob((Clob)template.getRow(i).getObject("TEMPLATE_HTML")); 
			  				String divHidden = template.getRow(i).get("SEQ").equals("0")?"":"none";
		  		%>
		  		<div style="display:<%=divHidden%>; padding-top: 10px;overflow:hidden;overflow-y:auto;<%=template.getRow(i).get("TEMPLATE_STYLE") %>" id="__html_<%=template.getRow(i).get("SEQ")%>">
				<%= template_html%>
				</div>
				<%} %>
			</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>
	<%
		for(int i=0;i<autofile_list.size();i++){
	%>
					<li><a href="/common/file/FileDownloadServlet?mode=fpDown&filePath=/cont/<%=autofile_list.getRow(i).get("FILE_PATH")%>&fileName=<%=URLEncoder.encode(autofile_list.getRow(i).get("FILE_NAME"), "UTF-8") +"."+ autofile_list.getRow(i).get("FILE_EXT")%>&fileRealName=<%=autofile_list.getRow(i).get("UNIQUE_FILE_NAME")%>"><%=i+1%> : <%=autofile_list.getRow(i).get("FILE_NAME")%> (<%=autofile_list.getRow(i).get("FILE_SIZE").trim() %>)</a></li>
	<%
		}	
	%>
					</ul>
				</div>
			</TD>
		</TR>
		</TABLE>		
	</TD>	
  </TR>
  <TR height="25">
  	<TH style="text-align: left;"> 직접첨부</TH>
	<TD>
    	<table width="100%">
    		<colgroup>
	    		<col width="50%" />
				<col width="50%" />
    		</colgroup>
    		<tr>
    		<td>
			    <div id="attach_file_view" class="attach_file_view">
			    <!-- 첨부 파일 화면에 바로보일때 사용 -->
			    <%=FileManager.getFileListForDiv("SUB_CONT_MOD_ID", ContInfo.get("SUB_CONT_MOD_ID")) %>
			    </div>
    		</td>
    		<td>
    			<!-- IMG id='search_spot_button' onClick="doAttachFileDiv(document.form1.SUB_CONT_MOD_ID,1);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;' -->
    		</td>
    		</tr>
    	</table>		
 	</TD>
  </TR>
 </TABLE>
 
<%
	/*
		보증 목록을  include 시킴 (2014-10-17) 김명호
	*/	
	if(warrList.size() > 0) {
%>
<div style="display:" id="guar_div"><!--2016.12.5 증권면제  -->
<%@ include file="/jsp/ko_KR/supplier/portal/common/guar/guarOutList.jsp" %>
</div>				
<%
	}
%>

</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;
		
		alert("신원확인 성공");
		$("#CONT_SIGNDATA").val(signeddata);
		$("#CONT_SIGNDN").val(userdn);

		var f = document.form1;
		jQuery("#fevent").val("SIGN_OK");
		submitXmlRequest("/portal/cont/SuppContDetail_form.screen", "SIGN_OK", f);	
	});
	 
}

//-->

</SCRIPT>
<FRAME src="" name="main" width="1" height="1" style="display:none;"></FRAMESET>
<!-- 전자인증 모듈 //-->
<br/><br/>
<script>
</script>
<iframe id="fileDown" name="fileDown" style="display:none"></iframe>


<!-- 전자인증 모듈 설정 //-->
<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>
<!-- 전자인증 모듈 설정 //-->