<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>

<%
// PayGroup_PaymentTerms Mapping Object 구하기 
ContCodeManager payGroupMappingUtil = new ContCodeManager();
storage.addObject("category", payGroupMappingUtil.getJSONNotation());
String category = (String)storage.getObject("category");
//System.out.println(category);

String pay_div = null;
%>
<script>
	var right_name = "<%=user.get("RIGHT_NAME")%>";
	var gCategoryJSON 		= null;
	var rawData = <%= category%>;				// 서버로부터 JSON 표현식 받기
	gCategoryJSON = eval( rawData );			// JSON객체를 만들어 global 변수에 저장

	function checkAuthority(){
		if((right_name=="ADMIN NEW"||right_name=="TREASURY")){
			$("#btnSavePayItem").show();
		}
	}
	
 	function changePaymentTerms(selObj) {
		var ct = getCategory(selObj.value);	// JSON 객체에서 해당하는 PAYMENT TERMS 데이타 꺼내기
		if (!ct) {
			dlgAlert('오류가 발생하였습니다.<br>전산실로 연락주세요.');
			 return false;
		}
		injectSelect(document.getElementById("payment_terms_id"), ct);			// PAYMENT TERMS Select Box 채우기
	}
	
	// JSON 객체에서 해당하는 PAYMENT TERMS 데이타 꺼내기
	function getCategory(payGroup) {
		return gCategoryJSON.paymentTerms[payGroup];	
	}

	//직군 데이타를  Select Box에 주입
	function injectSelect(elSel, rows) {
		elSel.length = 0;	// clear
		
		for (var i=0; i<rows.length; i++) {
			var row = rows[i];
			var elOptNew = document.createElement('option');
			elOptNew.value = row.CODE;		// 코드
			elOptNew.text = row.NAME;		// 명칭
			try {
				elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
			} catch(ex) {
				elSel.add(elOptNew); // IE only
			}
		}
		//2015.8.13 계약서 작성시 PaymentTerms 공백. 반드시 확인하고 저장하도록 유도.
		var elOptNew = document.createElement('option');
		elOptNew.value = '';		// 코드
		elOptNew.text = '';		// 명칭
		try {
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		} catch(ex) {
			elSel.add(elOptNew); // IE only
		}
	}	
	/**
	 * 집행내역코드 검색(공무)
	 */
	function popSearchPayItem()
	{
		var win_id = "_searchPayItemPopup";
		var link = "/cont/outside/payItemCodePopup.screen";
		    link += "?pop_win_id="+win_id;
		    link += "&gb=PUR";
		    link += "&req=0";
		    <%if (finalYn=="Y"){ %>
		    link += "&site=" + document.form1.r_dept_cd.value;
		    <%}else{ %>	
		    link += "&site=" + document.form1.dept_cd.value;
		    <%} %>
		fLayerPop(win_id, link, 600,400, '', '', 'NO');

	}
	 	 
</script>
<!-- 분개유형 -->
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">분개유형</span>
	</div>
	<div class="application-location" style="padding-bottom:5px;">
	    <%if (isViewWrite=="V"){ %>
	    <span class="btnSearch center" id="btnSavePayItem" style="display:none;"><a href="javascript:void(0);">분개유형저장</a></span>
	    <%} %>	
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="120px" />
		<col width="24%"/>
		<col width="120px" />
		<col width="24%"/>
		<col width="120px" />
		<col/>
	</colgroup>
  <TR height="25"> 
    <TH>분개유형</TH>
	<TD><%= ContCodeManager.getCcsifSelectCodeList("PUR-ACCT_GB", "acct_gb", "width:100%;", "", ContInfo.get("acct_gb"), ContInfo.get("dept_cd"), ContInfo.get("pay_div")) %></TD>
	<TH>증빙종류</TH>
	<TD><%= ContCodeManager.getProofCdSelectTag("gua_gb", "width:100%;", "", "", ContInfo.get("gua_gb"), "Y") %></TD>
	<TH>PAY GROUP</TH>
	<TD><%= ContCodeManager.getPayGroupSelectTag("pay_group", "width:100%;", "onchange=changePaymentTerms(this);", "", ContInfo.get("pay_group"), ContInfo.get("ac_unit_cd")) %></TD> 	
  </TR>
  <TR height="25"> 
	<TH>PAYMENT TERMS</TH>
	<TD colspan="5">
	    <INPUT type="hidden" name="dept_cd" value="<%=ContInfo.get("dept_cd") %>">
		<INPUT type="hidden" name="r_dept_cd" value="<%=ContInfo.get("r_dept_cd") %>">
		<SELECT id='payment_terms_id' name='payment_terms' style='width:20%;' class='input_select'></SELECT> 
	</TD> 
	 
  </TR> 	
</TABLE>
<script>
	changePaymentTerms(document.form1.pay_group);
	setSelect(document.form1.payment_terms, '<%= ContInfo.get("payment_terms") %>');
</script>
