<%--
  - Author(s)  : 김예진
  - Date       : 2015.02.01
  - 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 issueGbRow = CommCodeManager.getCodeRowsetStatic("STAMP_DUTY_ISSUE_GB");

	InitCombo initCombo = new InitCombo();
	initCombo.makeComboData(CommCodeManager.getCodeRowsetStatic("STAMP_DUTY_ISSUE_GB", "CHG_CODE01", "Y"), "DETAILNM", "DETAILCD");
	/* initCombo.makeComboData(commCodeManager.getCodeRowSet("STAMP_DUTY_ISSUE_GB"), "NAME", "CODE"); */
	String ISSUE_GB_CD = initCombo.getCode();
	String ISSUE_GB_NM = initCombo.getCodeName();
	
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet2;
	var sheet2Row;
	var sheet2PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit2(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:"STAMP_DUTY_ID", 		Width:0, 		Align:"Center", Hidden:"true"},
		    			{Header:'발행주체',			Type:"Combo", 			SaveName:"STAMP_DUTY_ISSUE_GB", Width:80, 		Align:"Center",	ComboText:"<%=ISSUE_GB_NM%>", ComboCode:"<%=ISSUE_GB_CD%>"},
		    			{Header:'고유식별번호',		Type:"Text", 			SaveName:"STAMP_DUTY_NO", 		Width:80,		Align:"Center"},
		    			{Header:'인지세액',			Type:"AutoSum", 		SaveName:"STAMP_DUTY_TAX", 		Width:60, 		Align:"Right"},
		    			{Header:'발행일자',			Type:"Date", 			SaveName:"STAMP_DUTY_DATE", 	Width:70, 		Align:"Center"},
		    			{Header:'비고',				Type:"Text", 			SaveName:"REMARK", 				Width:120, 		Align:"Left"},
		    			{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'){
			sheet2.SetEditable(0);
		}
		//sheetName.SetActionMenu("ExcelDown");
		setGridSize2();
	}
	
	function doSearchStamp() {
		jQuery("#fevent").val("FORM_SHEET_SELECT");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/portal/cont/StampList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet2, url, jQuery("#form1"), 30, "");
	}
	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet2_OnSearchEnd(code, message) {
		var info = {Type: "Image"};

		if(code == 0) {
	    	setGridSize2();
			sheet2.SetColFontColor("FILE_YN", "#0000ff");
			sheet2.SetCellValue(sheet2.LastRow(), "DEL_CHECK", "합  계");
	    	sheet2.SetMergeCell(sheet2.LastRow(), 0, 1, 5);
	    
	    	for(i=1; i <= sheet2.RowCount(); i++){
				if(sheet2.GetCellValue(i, "FILE_ID")!=""){
					sheet2.InitCellProperty(i, "FILE_YN", info);
				}
				if(jQuery("#STATUS_CD").val() != '50' && sheet2.GetCellValue(i, "STAMP_DUTY_ISSUE_GB")=="10"){
					sheet2.SetRowEditable(i,0);
				}
			}
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	function sheet2_OnSaveEnd(code, msg) {
	    if(code >= 0) {
	    	alert("정상적으로 처리 되었습니다.");
	    } else {
	    	//alert(msg);
	    	alert("처리에 실패 하였습니다.");
        }
	    doSearchStamp();
	}
	
	/*
	IBSheet Event : Mouse Right Menu
	*/
	function sheet2_OnSelectMenu(Text, Code) {
		  // text 또는 code값으로 Action수행
		switch(Text) {
	         case "ExcelDown":
	        	jQuery("#btnExcel").click();
	            break; 
		}
	}	
	
	/**
	 *	IBSheet Event Change
	 */	
	 function sheet2_OnChange(Row, Col, Value, OldValue, RaiseFlag) { 
			if (sheet2.ColSaveName(Col) == "STAMP_DUTY_NO") {
				if(stringByteSize4UTF(sheet2.GetCellValue(Row, "STAMP_DUTY_NO")) > 50){
					alert("고유식별번호는 50자까지 입력하실 수 있습니다.");
					return;
				}
			}
			if (sheet2.ColSaveName(Col) == "REMARK") {
				if(stringByteSize4UTF(sheet2.GetCellValue(Row, "REMARK")) > 500){
					alert("비고는 500자까지 입력하실 수 있습니다.");
					return;
				}
			}
			if (sheet2.ColSaveName(Col) == "STAMP_DUTY_ISSUE_GB") {
				if(sheet2.GetCellValue(Row, "STAMP_DUTY_ISSUE_GB") != '20'){
					alert("협력사만 선택 가능합니다.");
					sheet2.SetCellValue(Row, "STAMP_DUTY_ISSUE_GB", "20");
					return;
				}
			}
		}
	
	function sheet2_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 if(Row == 0)return;
		 if (sheet2.ColSaveName(Col) == "FILE_YN") {
			 
			if(sheet2.GetCellValue(Row, "STAMP_DUTY_ID")=='' || sheet2.GetCellValue(Row, "STATUS")=="I" || sheet2.GetCellValue(Row, "STATUS")=="U"){
				alert("입력한 내용을 저장을 한 후 파일을 첨부할 수 있습니다.");
				return;
			}
			else{ 
				var STAMP_DUTY_ID = sheet2.GetCellValue(Row, "STAMP_DUTY_ID")
				var modify = 'Y';
				if(jQuery("#STATUS_CD").val() == '50' || sheet2.GetCellValue(Row, "STAMP_DUTY_ISSUE_GB")=="10"){
					modify ='N'
				}
				viewFileListNew2('PUR_STAMP_DUTY', STAMP_DUTY_ID, "", modify, "portal/cont/stamp/"+STAMP_DUTY_ID, "", "", "", "N");
			} 
		
	     }
	 }
	
	 function viewFileListNew2(fileGB, id, obj, isModify, isDrectory, iframeID, user_filename, file_size, multi_yn) {
		 	
	 	var win_id = "_stampFileList";
	 	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 == "_stampFileList"){
			 doSearchStamp();
		 }
	 }

	 function stampDutyRowCheck() {
		for(i=1; i <= sheet2.RowCount(); i++){
			if(sheet2.GetCellValue(i, "STATUS")!="R"){
				alert("인지세중 저장되지 않은 행이 존재합니다.");
				return false;
			}
		}
		return true;
	}

			
	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 downStampFile(){
		var url="/common/file/FileDownloadServlet?mode=fpDown";
		url += "&filePath=/userMenual";
		url += "&fileName=" + encodeURI("전자문서에_대한_인지세_납부방법_등에_관한_고시_(전문).hwp");
		url += "&fileRealName=stamp_duty.hwp";
			
			//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")
			document.getElementById("fileDown").src=url;
	} 

	/**
	 *	IBSheet size setting
	 */
	function setGridSize2() {sheet2.FitColWidth();}

	document.body.onresize = addEvent( document.body.onresize, "setGridSize2()");
</SCRIPT>


<input type="hidden" name="p_issue_gb" id="p_issue_gb" value='<%=ContInfo.get("STAMP_DUTY_GB")%>'>
<div class="application-info  magT10" style="height:22px;">
	<div class="application-sub-title" >
		<!--2015.3.25 외주요구사항과 동일하게 처리  <span class="title">인지세</span><a href="javascript:stampDesc()"><IMG src='/img/buyer/button/q.gif' align="absmiddle"></a> <font color="red">※ 전자문서 계약자가 인지세무(과소) 납부시 가산세가 300% 부가됨</font> <a href="javascript:downStampFile()"><IMG src='/img/buyer/button/bt_change.gif' align="absmiddle"></a> -->
	    <span class="title">인지세<a href="javascript:downStampFile()"><IMG src='/img/buyer/button/q.gif' align="absmiddle"></a></span>&nbsp; <a href="http://www.e-revenuestamp.or.kr" target="_blank">전자수입인지사이트 바로가기(www.e-revenuestamp.or.kr)</a><font color="red">&nbsp;※ 전자문서 계약자가 인지세 무(과소)납부시 가산세가 300% 부가됨</font> <span class="btnSearch center" id="btnhelp" ><a href="javascript:stampDesc()">납부금액안내</a></span>
	</div>
	<div align="right">
		<span class="btnSearch center" id="btnAdd" style="display: none;"><a href="javascript:void(0);">추가</a></span>
		<span class="btnSearch center" id="btnSaveStamp" style="display: none;"><a href="javascript:void(0);">저장</a></span>
	</div>	
</div>
<div id="sheet2_div" style="padding-top:5px; height: 157px; min-height: 157px; overflow: auto;">
<!-- <div id="sheet2_div" style="padding-top:5px; height: auto; min-height: 100px; overflow: auto;"> -->
	<script>createIBSheet('sheet2','100%', '157px');</script>
</div>
<!-- <iframe id="fileDown" name="fileDown" style="display:none"></iframe> -->
