<%--
  - Author(s)  : mklee
  - Date       : 2016.12.12
  - Description: 인지세 팝업
  --%>

<%@page import="monfox.toolkit.snmp.agent.modules.SnmpV2Mib.SysOREntry"%>
<%@page import="monfox.toolkit.snmp.agent.modules.SnmpV2Mib.SysOREntry"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="kr.co.udapsoft.common.*" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="com.udapsoft.waf.system.*" %>
<%@ page import="com.udapsoft.waf.common.*" %>
<%@ page import="com.udapsoft.waf.common.ui.HTMLMaker" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.util.ValueObject" %>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.sql.RowSet" %>
<%@ page import="kr.co.hsnc.common.sql.util.*" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="kr.co.udapsoft.ebid.buyer.common.file.FileManager"%>

<%-- <%@ 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 = ctx.getUser();
	
	ValueObject ContInfo = storage.getValueObject("VALUEOBJECT");
	String p_stamp_duty_id = "";
	String p_move = params.get("p_move");
	String p_issue_gb = params.get("p_issue_gb"); 
	String p_who = params.get("p_who");
	
	if (p_move.equals("M")){
		p_stamp_duty_id = params.get("p_stamp_duty_id");
	}else{
		p_stamp_duty_id = ContInfo.get("stamp_duty_id"); 
	}
		
	String p_corp_name = ContInfo.get("corp_name"); 
	String p_corp_reg_no = ContInfo.get("corp_reg_no"); 
	String p_cont_no = ContInfo.get("cont_no"); 
	String p_mod_no = ContInfo.get("mod_no"); 
	String p_cont_name = ContInfo.get("cont_name"); 
	String p_currency_gb = ContInfo.get("currency_gb"); 
	String p_cont_amt = ContInfo.get("cont_amt"); 
	String p_cont_mod_id = ContInfo.get("cont_mod_id");  
	     
	RowSet CODE911 = storage.getRowSet("CODE911");
    RowSet dutyIssueRow = CommCodeManager.getCodeRowsetStatic("STAMP_DUTY_ISSUE_GB", "CHG_CODE01", "Y");
    RowSet exchangeRow = CommCodeManager.getCodeRowsetStatic("911");   
%>

<%@ page contentType="text/html; charset=utf-8" %>
<SCRIPT language="JavaScript">
	
	function doPageInit() {
		if("<%=p_move%>" == "I"){
			if ("<%=p_who%>" == "P") {
				jQuery("#p_stamp_duty_issue").val("20"); 
			}
		}
		else{
			var f = document.form1;
			$("#p_stamp_duty_issue").val("<%=ContInfo.get("STAMP_DUTY_ISSUE_GB")%>");
			$("#p_corp_name").val("<%=ContInfo.get("CORP_NAME")%>");
			$("#p_corp_reg_no").val("<%=ContInfo.get("CORP_REG_NO")%>");
			$("#p_stamp_duty_no").val("<%=ContInfo.get("STAMP_DUTY_NO")%>");
			$("#p_cont_no").val("<%=ContInfo.get("CONT_NO")%>");
			$("#p_mod_no").val("<%=ContInfo.get("MOD_NO")%>");
			$("#p_cont_name").val("<%=ContInfo.get("CONT_NAME")%>");
			$("#p_cont_amt").val("<%=ContInfo.get("CONT_AMT")%>");
			$("#p_currency_gb").val("<%=ContInfo.get("CURRENCY_GB")%>");
			$("#p_stamp_duty_tax").val("<%=ContInfo.get("STAMP_DUTY_TAX")%>");
			$("#p_stamp_duty_date").val("<%=ContInfo.get("STAMP_DUTY_DATE")%>");
			$("#p_remark").val("<%=ContInfo.get("REMARK")%>");
		} 
		
		//계약금액 포커스 탈출시 통화구분에 맞춰서 소수점 자리를 맞춘다.
	 	jQuery("#p_stamp_duty_no").blur(function () {
			if ( stringByteSize4UTF($("#p_stamp_duty_no").val()) > 50 ) {
		    	alert("한글은 16자 영문,숫자는 50자 까지만 입력 가능합니다.");
		    	jQuery("#p_stamp_duty_no").focus();
		    	return;
		    }
		});
	
		jQuery("#p_remark").blur(function () {
			if ( stringByteSize4UTF($("#p_remark").val()) > 500 ) {
		    	alert("한글은 166자 영문,숫자는 500자 까지만 입력 가능합니다.");
		    	jQuery("#p_remark").focus();
		    	return;
		    }
		});
		
		jQuery("#p_stamp_duty_issue").change(function () {
			if ("<%=p_who%>" == "P" && jQuery("#p_stamp_duty_issue").val() != "20")
			{
				alert("협력사만 선택 가능합니다.");
				jQuery("#p_stamp_duty_issue").val("20");
				jQuery("#p_stamp_duty_issue").focus();
		    	return;
			}
		});
		
		

	}

	function doSave(){
		if (jQuery("#p_stamp_duty_id").val() != "0"){
			doUpdate();
			return;
		}
		
		if (jQuery("#p_stamp_duty_issue").val() == "")
		{
			alert("발행주체 선택은 필수 입니다.");
			jQuery("#p_stamp_duty_issue").val("20");
			jQuery("#p_stamp_duty_issue").focus();
	    	return;
		}
		 
		if(jQuery("#p_stamp_duty_no").val() == ""){
			alert("고유식별번호 입력은 필수 입니다. ");
			jQuery("#p_stamp_duty_no").focus();
			return ;
		}
		
		if(jQuery("#p_stamp_duty_no").val() == ""){
			alert("고유식별번호 입력은 필수 입니다. ");
			jQuery("#p_stamp_duty_no").focus();
			return ;
		}
		
		if(jQuery("#p_stamp_duty_tax").val() == "" || jQuery("#p_stamp_duty_tax").val() == 0){
			alert("인지세액 입력은 필수 입니다. ");
			jQuery("#p_stamp_duty_tax").focus();
			return ;
		}
		
		if(jQuery("#p_stamp_duty_date").val() == ""){
			alert("발행일자 입력은 필수 입니다. ");
			jQuery("#p_stamp_duty_date").focus();
			return ;
		}
		
		/* if(jQuery("#attach_file_view_stamp li").length == 0){
			alert("인지세사본 첨부는 필수 입니다.");
			return;
		} */

		if(confirm("저장하시겠습니까?")){
			var f = document.form1;
			submitXmlRequest("/cont/outside/stampDutyPop_form.screen", "INSERT_DATA", f);
		}
	} 
	
	function doUpdate(){
		if (jQuery("#p_stamp_duty_issue").val() == "")
		{
			alert("발행주체 선택은 필수 입니다.");
			jQuery("#p_stamp_duty_issue").val("20");
			jQuery("#p_stamp_duty_issue").focus();
	    	return;
		}
		
		if(jQuery("#p_stamp_duty_no").val() == ""){
			alert("고유식별번호 입력은 필수 입니다. ");
			jQuery("#p_stamp_duty_no").focus();
			return;
		}
		
		if(jQuery("#p_stamp_duty_tax").val() == "" || jQuery("#p_stamp_duty_tax").val() == 0){
			alert("인지세액 입력은 필수 입니다. ");
			jQuery("#p_stamp_duty_tax").focus();
			return;
		}
		
		if(jQuery("#p_stamp_duty_date").val() == ""){
			alert("발행일자 입력은 필수 입니다. ");
			jQuery("#p_stamp_duty_date").focus();
			return;
		}
		
		/*if(jQuery("#attach_file_view_stamp li").length == 0){
			alert("인지세사본 첨부는 필수 입니다.");
			return;
		}*/
	
		if(confirm("수정하시겠습니까 ?")){
			var f = document.form1;
			submitXmlRequest("/cont/outside/stampDutyPop_form.screen", "UPDATE_DATA", f);
		}
	} 
	
	function doCancle() {
		closeSearch();
	}
	
	function doDel() {
		if(confirm("삭제하시겠습니까?")){
			var f = document.form1;
			submitXmlRequest("/cont/outside/stampDutyPop_form.screen", "DELETE_DATA", f);
		}
	}
	
	function closeSearch(){
		parent.stampDutyPopClose();
		winClose();
	}
	
	
	function doChange(){
		<% 
		     for(int i=0;i < CODE911.size();i++){
			   ValueObject Vo = RowSetUtility.getValueObject(CODE911.getRow(i));
		%>
				if($("#p_currency_gb").val() == "<%=Vo.get("DETAILCD")%>"){
					jQuery("#digit").val("<%=Vo.get("CHG_CODE01")%>");
				}
		<%}%>
	}
	
	

	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "INSERT_DATA") {
				if( resultObj.getSuccess() ) {
					alert("저장이 완료되었습니다.");
					closeSearch();
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
			if( resultObj.getRequestEvent() == "UPDATE_DATA") {
				if( resultObj.getSuccess() ) {
					alert("수정이 완료되었습니다.");
					closeSearch();
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
			if( resultObj.getRequestEvent() == "DELETE_DATA") {
				if( resultObj.getSuccess() ) {
					alert("삭제이 완료되었습니다.");
					closeSearch();
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
			if( resultObj.getRequestEvent() == "BEFORE_ATTACH") {
				if( resultObj.getSuccess()) {  //p_stamp_duty_id 확인
					//첨부파일등록 
				    var STAMP_DUTY_ID = resultObj.getMessage();
				    jQuery("#p_stamp_duty_id").val(STAMP_DUTY_ID);
				    
					var modify = 'Y';
					
					parent.doAttachStampFilePop('SUB_STAMP_DUTY', STAMP_DUTY_ID, document.getElementById("attach_file_view_stamp"), modify, "cont/outside/stamp/"+STAMP_DUTY_ID, "", "", "", "N");
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}			
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	function doAttachStampFile(obj){
		var STAMP_DUTY_ID = jQuery("#p_stamp_duty_id").val();
		
		//인지세 정보 저장후 첨부파일 등록
		if (STAMP_DUTY_ID == "0") {
			if(jQuery("#p_stamp_duty_no").val() == ""){
				alert("고유식별번호 입력은 필수 입니다. ");
				jQuery("#p_stamp_duty_no").focus();
				return ;
			}
			
			if(jQuery("#p_stamp_duty_tax").val() == "" || jQuery("#p_stamp_duty_tax").val() == 0){
				alert("인지세액 입력은 필수 입니다. ");
				jQuery("#p_stamp_duty_tax").focus();
				return ;
			}
			
			if(jQuery("#p_stamp_duty_date").val() == ""){
				alert("발행일자 입력은 필수 입니다. ");
				jQuery("#p_stamp_duty_date").focus();
				return ;
			}

			var f = document.form1;
			jQuery("#fevent").val("BEFORE_ATTACH");
			submitXmlRequest("/cont/outside/stampDutyPop_form.screen", "BEFORE_ATTACH", f);			
		}else{
			var modify = 'Y';
			if ("<%=p_move%>" == "N"){
				modify ='N'
			}
			parent.doAttachStampFilePop('SUB_STAMP_DUTY', STAMP_DUTY_ID, document.getElementById("attach_file_view_stamp"), modify, "cont/outside/stamp/"+STAMP_DUTY_ID, "", "", "", "N");
			
		} 
	}
	
	/**
	 * 첨부파일 예약 함수
	 */
	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 stampDesc()
	{
		var win_id = "_stampPopup";
		var link = "/cont/purchase/stampDescPopup.screen";
		    link += "?pop_win_id="+win_id;
		fLayerPop(win_id, link, 400,210, '', '', 'NO');
	}
	
	document.body.onload = doPageInit;

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

<FORM name="form1" method="post">

<INPUT type="hidden" name="digit"           id="digit"           value="">
<INPUT type="hidden" name="p_move"          id="p_move"          value="<%=p_move%>">
<INPUT type="hidden" name="p_stamp_duty_id" id="p_stamp_duty_id" value="<%=p_stamp_duty_id%>">
<INPUT type="hidden" name="p_corp_name"     id="p_corp_name"     value="<%=p_corp_name%>">
<INPUT type="hidden" name="p_corp_reg_no"   id="p_corp_reg_no"   value="<%=p_corp_reg_no%>">
<INPUT type="hidden" name="p_cont_no"       id="p_cont_no"       value="<%=p_cont_no%>">
<INPUT type="hidden" name="p_mod_no"        id="p_mod_no"        value="<%=p_mod_no%>">
<INPUT type="hidden" name="p_cont_name"     id="p_cont_name"     value="<%=p_cont_name%>">
<INPUT type="hidden" name="p_currency_gb"   id="p_currency_gb"   value="<%=p_currency_gb%>">
<INPUT type="hidden" name="p_cont_amt"      id="p_cont_amt"      value="<%=p_cont_amt%>">
<INPUT type="hidden" name="p_cont_mod_id"   id="p_cont_mod_id"   value="<%=p_cont_mod_id%>"> 

 

<TABLE class="screen_title_table">
  <TR height="2"><TD colspan="2"></TD>
  </TR>
  <TR height="25"><TD>
  	<!-- 제목 및 버튼 -->
   	<table id="t1" width="100%" class="ftit_table">
		<colgroup>
			<col width="*" />
			<col width="150" />
		</colgroup>
	<tr>
	   	<th>
	   </th>
	   <td align="right">
	    <%if (!p_move.equals("N")) {%>
		   	<%if(p_move.equals("I")){%>
				<span class="btnSearch center"><a href="javascript:doSave();">저장</a></span>
		   	<%}else{%>
				<span class="btnSearch center"><a href="javascript:doUpdate();">수정</a></span>
				<span class="btnSearch center"><a href="javascript:doDel();">삭제</a></span>
		   	<%}%>
				<span class="btnSearch center"><a href="javascript:doCancle();">취소</a></span>			 
		<%}%>
	   </td>
   	</tr>
   	</table>
    </TD>
  </TR>
  <tr>
  <td>

<!-- 버튼 영역 : 시작 -->



<!-- 발주의뢰정보 : 시작 -->
<TABLE  class="form-table">
	<colgroup>
		<col width="150" />
		<col width="270" />
		<col width="100" />
		<col width="*" />
	</colgroup>
	<TR height="25"> 
	   <TH class=" required">발행주체</TH>
	   <TD colspan="3"> 
	   &nbsp;<%= HTMLMaker.getSelectTag(dutyIssueRow, "DETAILCD", "DETAILNM", "p_stamp_duty_issue", "width:150px;height=18;", "<option value=''>선택</option>", "") %> 
	   </TD>
	</TR>
	<TR height="25"> 
	   <TH class=" required">고유식별번호</TH>
	   <TD colspan="3"> 
	   &nbsp;<%= InputText.get("p_stamp_duty_no", "", 35, 50, "required,persize,string") %>
	   </TD>
	</TR>
	<TR height="25"> 
	   <TH class=" required">인지세액</TH>
	   <TD colspan="3"> 
	   &nbsp;<%= InputText.get("p_stamp_duty_tax", "", 35, 12, "Number,Right,required,persize,string","float") %> 원
	   </TD>
	</TR>
	<TR height="25"> 
	   <TH class=" required">발행일자</TH>
	   <TD  colspan="3"> 
	   &nbsp;<%= InputText.get("p_stamp_duty_date","" , 13, 10, "center,desc=발행일자,readOnly") %>
			<IMG name="calendar_sitedescdate" id="calendar_sitedescdate" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('p_stamp_duty_date');">
	   </TD>
	</TR>
	<TR height="25"> 
	   <TH >비고</TH>
	   <TD colspan="3"> 
	   &nbsp;<%= InputText.get("p_remark", "", 90, 250, "required,persize,string") %>
	   <!-- <input type="text" name="p_remark" id="p_remark" value="" style="width: 250px;" /> -->
	   </TD>
	</TR>
    <TR height="25"> 
       <TH class=" required">인지세사본<a href="javascript:stampDesc()"><IMG src='/img/buyer/button/q.gif' align="absmiddle"></a></TH>
	   <TD colspan="3"> 
	   	<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", p_stamp_duty_id) %>
		</div>
		<div style="text-align: right;">
			<IMG id='search_spot_button_stamp' onClick="doAttachStampFile(document.form1.p_stamp_duty_id);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
		</div>
       </TD>
    </TR>
</TABLE>
  </td>
  </tr>
</TABLE>
</FORM>
