<%--
  - FileName   : conPurWarrPopup.jsp
  - Author(s)  : ok
  - Date       : 2014.07.24
  - Copyright  : Copyright (c) 2013 www.udapsoft.co.kr, Inc.
  - 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.*" %>
<%@ page import="kr.co.hsnc.common.util.Formatter"%>
<%@ 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" />
<%
    ctx.init(request, response);
    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    String event = storage.getEvent();
    //System.out.println("Outside params : " + event);
    
    RowSet WarrGofficeComboList = CommCodeManager.getCodeRowsetStatic("GUARORGAN", "SUBSTR(CHG_CODE01,1,1)", "1");    

    ValueObject contPurWarr = storage.getValueObject("WarrContInfo");		//보증정보
    ValueObject attFile = storage.getValueObject("attFileList");	//첨부파일
    
    String check1 = "";
    String check2 = "";
     if("Y".equals(contPurWarr.get("GUAR_ONOFF_YN"))){
    	check1 = "checked";
    }else{
    	check2 = "checked";
    }
    
    String sWarrGubun = params.get("warrGubun");
    String sWonWarr = params.get("wonWarr");
%>
<SCRIPT language="JavaScript">
var	sGuarOnoffYn	=	"<%=contPurWarr.get("GUAR_ONOFF_YN")%>";
var	sContStatus	=	"<%=contPurWarr.get("CONTSTATUS")%>";
var sPreqStatusCd = "<%=params.get("PreqStatusCd")%>";		//하자이행 현재 상태	(10이 완료, 04결재중)
var sPayStatusCd = "<%=contPurWarr.get("PAYSTATUS")%>";		//선급금 현재 상태	(10이 완료, 04결재중)

	function _onReady(){
		jQuery("#btnSave").click(function() {
		
			//필수 입력항목 check
		//	alert(save());
			if(save()){
				var f = document.form1;
				jQuery("#fevent").val("FORM_SAVE");
				submitXmlRequest("/portal/guar/contPurWarrPopup_form.screen", "FORM_SAVE", f, "SUCCESS");	
			}
		}); 
		
		jQuery("#btnTrans").click(function() {
			
			//필수 입력항목 check
			//	alert(save());
				if(save()){
					var f = document.form1;
					jQuery("#fevent").val("FORM_SAVE");
					submitXmlRequest("/portal/guar/contPurWarrPopup_form.screen", "FORM_SAVE", f, "SUCCESS");	
				}
			
		});		

		jQuery("#btnAgain").click(function() {
			
			//필수 입력항목 check
			//	alert(save());
				if(save()){
					var f = document.form1;
					jQuery("#fevent").val("FORM_SAVE");
					submitXmlRequest("/portal/guar/contPurWarrPopup_form.screen", "FORM_SAVE", f, "SUCCESS");	
				}
			
		});		
		
		jQuery("#btnDel").click(function() {
			if(confirm("정말로 보증정보를 삭제 하시겠습니까?")){
				//	보증정보 삭제
				var f = document.form1;
				jQuery("#fevent").val("FORM_DELETE");
				submitXmlRequest("/portal/guar/contPurWarrPopup_form.screen", "FORM_DELETE", f, "SUCCESS");
			}
		
		});

	}

	function doResult(resultObj) {
		try {
			
			if( resultObj.getRequestEvent() == "FORM_SAVE" ) {
				if( resultObj.getSuccess() ) {				
					alert("저장되었습니다.");		
				}else {
					
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
			
			if( resultObj.getRequestEvent() == "GET_DATA" ) {
				
				if( resultObj.getSuccess() ) {
					
				}else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
			
			if( resultObj.getRequestEvent() == "FORM_DELETE" ) {
				if( resultObj.getSuccess() ) {				
					alert("정상적으로 처리 되었습니다.");
					
				}else {
					
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}			
		}
		catch(errorObject) {
	        showErrorDlg("doResult()", errorObject);
		}
	}

	function calendar(thisDayObj){
		dlgCalendar(thisDayObj);
	}		
	//첨부파일   
	function doAttachFile(obj,No) {
		var editFile = "";
		 if(obj==''){
			alert("After you have saved, you can attach a file.");
		}
		else if(obj != ''){
			if(document.form1.guarStatus.value != "02"){editFile="N";}else{editFile="Y";}
			viewFileListNew("GUARCONT_PUR_5_<%=params.get("warrSeq")%>", obj.value, document.form1.p_AttachFileGuar1, editFile, "cont/purchase/<%=params.get("purContModId")%>/guar", "contPurWarrPopup");
		} 		
	} 
	function searchData(){
		
		var f = document.form1;
		jQuery("#fevent").val("GET_DATA");
		submitXmlRequest("/portal/payment/contPurWarrPopup_form.screen", "GET_DATA", f, "VALUEOBJECT");
	}

	function inputDataSet(){
		
		if(jQuery("#guarOrganCode option:selected").val() == "99"){	//기타
			
			document.getElementById("warrGofficeEtc").style.display	=	"";
			jQuery("#warrGofficeEtc").attr("readonly",false);
			jQuery("#warrGofficeEtc").css({'background-color' : '#ffffff'});
			jQuery("#warrGofficeEtc").css({'border' : '1px solid #595a5a'});

		}else{
			document.getElementById("warrGofficeEtc").style.display	=	"none";
			jQuery("#warrGofficeEtc").attr("readonly",true);
			jQuery("#warrGofficeEtc").css({'background-color' : '#dedede'});
			jQuery("#warrGofficeEtc").css({'border' : '1px solid #bcbcbc'});
			
		}
	}
	
	function checkOnOff(chk){
		if(chk=='Y'){
			document.getElementById("offTableInfo").style.display="none";
			sGuarOnoffYn = "Y";
			showHideTable(true);
		}else{
			document.getElementById("offTableInfo").style.display="";
			sGuarOnoffYn = "N";
			showHideTable(false);
		}
	}
	
	
	/**********************************************
	발행구분에 따른 입력 내용 보이기, 안보이기
	**********************************************/
	function	showHideTable(bShow)
	{	
		var	form				=	document.form1;
	
		var	sWarrGubun			=	form.warrGubun.value;			//	보증종류
		var	sGuarStatus			=	form.guarStatus.value;		//	보증상태
		var	sGuarOrganCode		=	form.guarOrganCode.value;	//	기관코드
		
		//title 및 변경구분 세팅
		var	sTitle	=	"";
		var	sTitle2	=	"";
		var	sText	=	"";
		
		if( '<%=params.get("validYn")%>' == 'Y' ){
			document.getElementById("offTableInfo").style.display		=	"";
			document.getElementById("btnSave").style.display		=	"";
	
			if(sGuarStatus == "02")
			{
				document.getElementById("btnDel").style.display		=	"none";
			}else
			{
				document.getElementById("btnDel").style.display		=	"";
			}
	
			if(sGuarOrganCode == "99")
			{
				document.getElementById("warrGofficeEtc").style.display	=	"";
			}else
			{
				document.getElementById("warrGofficeEtc").style.display	=	"none";
			}
			//계약 완료일 경우 버튼 안보이게 처리
			if((sContStatus == "50") || (sPreqStatusCd == "04") || (sPreqStatusCd == "10") || (sPayStatusCd == "04") || (sPayStatusCd == "10"))
			{
				document.getElementById("btnDel").style.display		=	"none";
				document.getElementById("btnSave").style.display	=	"none";
			}
			
		}
		
		sTitle	=	"오프라인 ";

		form.guarOrganCode.disabled	=	false;
		
		sTitle2	=	"하자이행증권";
		sText	=	"하자이행보증서";
		
		// 제목 타이틀
	//	document.getElementById("li_title").innerHTML			=	sTitle + sTitle2;
		/*	발행구분 radio 활성, 비활성	*/
										/* 변경 구분이 단축/감액일경우는 오프라인 설청후  radio 비활성        :: 조달에서 팝업 띄울때 오프라인 설정후 ]*/ 
	//sContStatus 향후 이부분은 수정 필요

		if((sGuarStatus == "08") || (sGuarStatus == "09"))
		{
			document.getElementById("dateStart").disabled	=	true;
			document.getElementById("dateEnd").disabled	=	true;
			document.getElementById("paperDate").disabled	=	true;
			document.getElementById("warrWgno").disabled		=	true;
			document.getElementById("guarOrganCode").disabled		=	true;
			document.getElementById("warrWamt").disabled		=	true;
			document.getElementById("btnCalendar1").style.display	=	"none";
			document.getElementById("btnCalendar2").style.display	=	"none";
			document.getElementById("btnCalendar3").style.display	=	"none";
		}else{
			document.getElementById("warrWgno").readOnly  =	false;
			document.getElementById("warrWamt").readOnly  =	false;			
		}
	}	

	
	
	/********************************
		보증정보 저장
	********************************/
	function save()
	{
		var	form	=	document.form1;

		if(form.guarOrganCode.value == ""){
			alert("보증기관을 선택하세요");
			form.guarOrganCode.focus();
			return false;
		}
		
		if(sGuarOnoffYn == "Y"){	  // 온라인인 경우	
			var wOldGuarOrganCode = form.OldGuarOrganCode;
		
			if(form.guarOrganCode.selectedIndex==3){
				alert("온라인 보증서 발급시 전문건설공제 조합 또는 서울보증보험을 선택해 주시기 바랍니다.")
				form.guarOrganCode.focus();
				return false;
			}
			if((form.guarOrganCode.selectedIndex==2) && (wOldGuarOrganCode.value=="") && (form.MOD_NO.value!="0")) {
				alert("온라인 보증서 발급을 서울 보증서로 발급시 변경계약에 대한 보증서는 당초 보증서를 온라인으로 서울 보증서로 발급 받은 상태에서만 가능합니다.\n\n아닐경우 오프란인으로 처리 해 주시기 바랍니다.")
				form.guarOrganCode.focus();
				return false;
			}		
			if((wOldGuarOrganCode.value!="") && (wOldGuarOrganCode.value!=form.guarOrganCode.selectedIndex)){
				alert("온라인 보증에 대해서 변경 사항에 대해서는 당초 보증 기관과 동일하게 선택해 주세요.");
				return false;
			}
			
			form.guarStatus.value = "05";
			if(confirm("해당보증기관에 계약정보를 전송하시겠습니까?"))	return true;		
			
		}else{											// 오프라인인 경우	
			if(form.guarOrganCode.value == "99"){
				if(!form.warrGofficeEtc.value){
					alert("보증기관명을 입력하세요");
					form.warrGofficeEtc.focus();
					return false;
				}
			}else{
				var	iIndex	=	form.guarOrganCode.selectedIndex;
				var	sText		=	form.guarOrganCode[iIndex].text;
				form.warrGofficeEtc.value	=	sText;
			}
				
			var wgno 	= form.warrWgno;
			var wamt 	= form.warrWamt;
			var wfrom 	= form.dateStart; 
			var wto 	= form.dateEnd;
			var wppd 	= form.paperDate; 
			var wsize	= form.p_AttachFileGuar1;
			
			if(wgno.value == ""){
				alert('증권번호를 입력하세요.');
				wgno.focus();
				return false;
			}			
			if(wfrom.value.length <8){
				alert('보증시작일을 입력하세요');
				wfrom.focus();
				return false;
			}		
			if(wto.value.length <8){
				alert('보증종료일을 입력하세요');
				wto.focus();
				return false;
			}		
			if(wfrom.value > wto.value){
				alert('보증종료일이 시작일보다 빠릅니다.');
				wto.focus();
				return false;
			}
			if(wamt.value == "0" || wamt.value == ""){
				alert('보증금액을 입력하세요.');
				wamt.focus();
				return false;
			}
			if(wppd.value.length <8){
				alert('발급일을 입력하세요');
				wppd.focus();
				return false;
			}		
			if(wsize.value == null || wsize.value == "0" || wsize.value == ""){
				alert('첨부파일을 선택하세요.');							
				return false;
			}
			form.guarStatus.value = "09";
				
			if(confirm("보증정보를 저장하시겠습니까?"))	 return true;
			
		}		
	}
</SCRIPT>
<STYLE>
BODY {
	padding : 0 0 0 0;
}
</STYLE>
<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="purContModId" id="purContModId" value="<%=params.get("purContModId") %>">	<!-- 보증증권 ID -->
<INPUT type="hidden" name="warrGubun" id="warrGubun" value="<%=params.get("warrGubun") %>">			<!-- 보증증권 구분 -->
<INPUT type="hidden" name="warrSeq" id="warrSeq" value="<%=params.get("warrSeq") %>">				<!-- 보증증권 일련번호 -->
<INPUT type="hidden" name="viewDiv" id="viewDiv" value="PAYREQ">			<!-- 화면구분 -->
<INPUT type="hidden" name="grtreqNo" id="grtreqNo" value="<%=contPurWarr.get("GRTREQNO") %>">			<!-- 원계약번호 -->
<INPUT type="hidden" name="causeCode" id="causeCode" value="10">			<!--변경면구분 -->
<INPUT type="hidden" name="guarStatus" id="guarStatus" value="<%=contPurWarr.get("GUAR_STATUS") %>">			<!--보증 상태 -->
<INPUT type="hidden" name="PUR_CONT_ID" id="PUR_CONT_ID" value="<%=contPurWarr.get("PUR_CONT_ID") %>">			<!--계약서 ID -->
<INPUT type="hidden" name="MOD_NO" id="MOD_NO" value="<%=contPurWarr.get("MOD_NO") %>">			<!--계약 변경차수 -->
<INPUT type="hidden" name="OldGuarOrganCode" id="OldGuarOrganCode" value="<%=contPurWarr.get("OldGuarOrganCode") %>">			<!--이전 계약 기관 -->

<INPUT type="hidden" name="prepayId" id="prepayId" value="<%=params.get("prepayId") %>">			<!-- 보증일련번호 -->


	<!-- 제목 및 버튼 -->
<table  id="t1" width="100%" border="0" cellspacing="0" cellpadding="0" class="ftit_table">
	<colgroup>
		<col width="200" />
		<col width="*" />
	</colgroup>
	<tr>
	   <td align="right">
			<span class="btnSearch center" style="display:none" id="btnSave"><a>저장</a></span>
			<span class="btnSearch center" style="display:none" id="btnDel"><a>삭제</a></span>
	   </td>
   	</tr>
</table>
   	
<!-- 상세 정보 -->   	
<TABLE cellspacing="1" cellpadding="0" class="search_table" style="margin-top:10px;">
	<colgroup>
		<col width="140" />
		<col width="*" />
	</colgroup>
	<TR height="25"> 
		<TH class="search_table_title required" style="text-align: left;">발행방법</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:7px">
			오프라인
			<input type="hidden" name="guarOnOffYn" value="N">
		</TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">발행구분</TH>
		<TD class="search_table_data"  style="text-align:left;padding-left:5px">&nbsp;<%= InputText.get("warrGubunNm", contPurWarr.get("WARR_GUBUN_NM"), 60, 30, "class=input_blank, readOnly=white, string, left, tabIndex=-1", "string") %></TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title required" style="text-align: left;">보증기관명</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:5px">&nbsp;<%= HTMLMaker.getSelectTag(WarrGofficeComboList, "DETAILCD", "DETAILNM", "guarOrganCode", "width:35%;height=18;' onChange='inputDataSet();", "<option value=''>선택</option>", contPurWarr.get("GUAR_ORGAN_CODE")) %>
		<%= InputText.get("warrGofficeEtc", contPurWarr.get("WARR_GOFFICE"), 30, 40, "string, left, readOnly", "string") %>
		</TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">변경구분</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:5px">&nbsp;<%= InputText.get("xxxxxxxx", contPurWarr.get("CAUSECODE_NM"), 60, 30, "class=input_blank, readOnly=white, string, left, tabIndex=-1", "string") %></TD>
	</TR>
</TABLE>

<TABLE cellspacing="1" cellpadding="0" class="search_table" id="offTableInfo" name="offTableInfo" style="margin-top:10px;display:none">
	<colgroup>
		<col width="140" />
		<col width="*" />
	</colgroup>
	<TR height="25"> 
		<TH class="search_table_title" style="text-align: left;">증권번호</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:5px">&nbsp;<%= InputText.get("warrWgno", contPurWarr.get("WARR_WGNO"), 60, 38, "class=input, readonly, string, left", "string") %></TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">보증기간</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:5px">&nbsp;<%= InputText.get("dateStart", Formatter.formatDate(contPurWarr.get("WARR_SDATE"), "-"), 20, 10, "Center, date, PerSize, readonly", "date", "") %>
			<A href="JavaScript:calendar('dateStart');"><IMG src="/img/buyer/btn/bt_calender.gif" alt="달력" border="0" align="absmiddle" id="btnCalendar1"></A>
				~
			<%= InputText.get("dateEnd", Formatter.formatDate(contPurWarr.get("WARR_EDATE"), "-"), 20, 10, "Center, date, PerSize, readonly", "date", "") %>
			<A href="JavaScript:calendar('dateEnd');"><IMG src="/img/buyer/btn/bt_calender.gif" alt="달력" border="0" align="absmiddle" id="btnCalendar2"></A>
		</TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title" style="text-align:left;">보증금액</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:5px">&nbsp;<%= InputText.get("warrWamt", Formatter.formatCurrency(contPurWarr.get("WARR_WAMT")), 60, 14, "class=input, readonly, byteChk ,number, right", "number") %>
			<INPUT type="hidden" name="warrWrate" id="warrWrate" value="<%=contPurWarr.get("WARR_WRATE") %>">	<!-- 보증율 -->
		</TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">발급일</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:5px">&nbsp;<%= InputText.get("paperDate", Formatter.formatDate(contPurWarr.get("PAPERDATE"), "-"), 29, 10, "Center, date, PerSize, readonly", "date", "") %>
			<A href="JavaScript:calendar('paperDate');"><IMG src="/img/buyer/btn/bt_calender.gif" alt="달력" border="0" align="absmiddle" id="btnCalendar3"></A>
		</TD>
	</TR>
	<TR height="25" <%=params.get("validYn").equals("N")?"style='display:none;'":"" %>>
		<TH class="search_table_title" style="text-align: left;">첨부파일</TH>
		<TD class="search_table_data" style="text-align:left;padding-left:5px">&nbsp;<TEXTAREA name="p_AttachFileGuar1" id="p_AttachFileGuar1" style="width:85%;height:80px" rows="1" class="input" readOnly><%=attFile.get("fileRow") %></TEXTAREA>
			<IMG id='search_spot_button' onClick="doAttachFile(document.form1.purContModId,1);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
		</TD>
	</TR>				
</TABLE>

<%
	//서울 보증 온라인일경우 신청 번호를 보여준다.
	if((contPurWarr.get("GUAR_ONOFF_YN").equals("Y")) && (contPurWarr.get("GUAR_ORGAN_CODE").equals("2"))){
		//신청 대기일경웅에는 안보여준다.
		if(!contPurWarr.get("GUAR_STATUS").equals("04")){
			String I_CONTSEQ = contPurWarr.get("MOD_NO");
			String I_GRTSEQ = params.get("warrSeq");
			if(I_CONTSEQ.length()==1){
				I_CONTSEQ = "0" + contPurWarr.get("MOD_NO");
			}
			if(I_GRTSEQ.length()==1){
				I_GRTSEQ = "0" + I_GRTSEQ;
			}
%>
<TABLE cellspacing="1" cellpadding="0" class="search_table"  style="margin-top:10px;">
	<colgroup>
		<col width="140" />
		<col width="*" />
	</colgroup>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">서울보증신청번호</TH>
		<TD class="search_table_data"  style="text-align:left;padding-left:5px">&nbsp;<%= contPurWarr.get("GRTREQNO") +"-"+ I_CONTSEQ + contPurWarr.get("GRTTYPE")+ I_GRTSEQ%></TD>
	</TR>
</TABLE>
<%
		}
	}
	//반송일 경우 반송 사유를 보여준다.
	if(contPurWarr.get("GUAR_STATUS").equals("10")){
%>
<TABLE cellspacing="1" cellpadding="0" class="search_table"  style="margin-top:10px;">
	<colgroup>
		<col width="140" />
		<col width="*" />
	</colgroup>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">보증상태</TH>
		<TD class="search_table_data"  style="text-align:left;padding-left:5px">&nbsp;<%= contPurWarr.get("GUAR_STATUS_NM")%></TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">반송사유</TH>
		<TD class="search_table_data"  style="text-align:left;padding-left:5px">&nbsp;<%= contPurWarr.get("REJECTMENT")%></TD>
	</TR>
	<TR height="25">
		<TH class="search_table_title" style="text-align: left;">처리방법</TH>
		<TD class="search_table_data"  style="text-align:left;padding-left:5px">&nbsp;해당 보증사에 확인을 해주시기 바랍니다.</TD>
	</TR>
</TABLE>
<%
	}
	//반송사유 끝
%>
</FORM>
<script>
	checkOnOff('<%=contPurWarr.get("GUAR_ONOFF_YN")%>');
	if( '<%=params.get("validYn")%>' != 'Y' ){
		alert('유효하지 않은 접근입니다. 팝업창을 다시 띄워주시기 바랍니다.');
	}
</script>