<%@ 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);
%>
<script>
	var gCategoryJSON 		= null;
	var rawData = <%= category%>;				// 서버로부터 JSON 표현식 받기
	gCategoryJSON = eval( rawData );			// JSON객체를 만들어 global 변수에 저장

 	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 채우기
		//jQuery('#payment_terms_id').attr('disabled', 'true');
	}
	
	// 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
			}
			
/* 			if(jQuery("#payTerms").val() == row.CODE){
				elSel.options[i].selected = true; 
			} */
		}
	}	
	/**
	 * 집행내역코드 검색(공무)
	 */
	function popSearchPayItem()
	{
		var win_id = "_searchPayItemPopup";
		var link = "/cont/outside/payItemCodePopup.screen";
		    link += "?pop_win_id="+win_id;
		    link += "&gb=SUB";
		    link += "&req=0";
		    link += "&site=" + document.form1.dept_cd.value;
		fLayerPop(win_id, link, 600,400, '', '', 'NO');

	}
	 //f.dept_cd, f.pay_item, f.cost_code, f.cost_type, f.estdesc, '', f.estamt
	function SearchPayItemClose(result){
		if(result != null){
			$("#pay_item").val(result[0]);
			$("#cost_code").val(result[1]);
			$("#cost_type").val(result[2]);
			$("#estdesc").val(result[3]);

			//obj_estamt.value = result[4];
		}
		fLayerPopClose('_searchPayItemPopup');
	}		
	 
	function gubSave(div){

		if(div == '0'){	//분계유형저장
			
			var pKey = jQuery("#payreqId").val();
			var f = document.form1;
			jQuery("#fevent").val("SAVE_GUA");
			jQuery("#pKey").val(pKey);
			
			//분계유형 저장 
			if (confirm("분계유형을 저장 하시겠습니까?")) {
				submitXmlRequest("/payment/purchase/PayItem_form.screen", "SAVE_GUA", f, "SUCCESS");
			}
			
		}else if(div == '1'){	//세금계산서저장

			var pKey = jQuery("#payreqId").val();
			var f = document.form1;
			jQuery("#fevent").val("SAVE_SEGUM");
			jQuery("#pKey").val(pKey);
			
			//세금계산서정보 저장 
			if (confirm("세금계산서정보을 저장 하시겠습니까?")) {
				submitXmlRequest("/payment/purchase/PayItem_form.screen", "SAVE_SEGUM", f, "SUCCESS");
			}			
		}
	}	 
	 
</script>
	<INPUT type="hidden" name="pKey" id="pKey" value="">
<!-- 분개유형 -->
<div class="application-info  magT10">
	<div class="application-sub-title">
		<span class="title">분개유형</span>
	</div>
	<div class="application-location">
		<span id="spanGubSave" class="btnSearch center" style="display: none"><a href="javascript:void(0);" onclick="gubSave('0');" id="btnGubSave">분개유형저장</a></span>
	</div>
</div>
<TABLE class="form-table">
	<colgroup>
		<col width="13%" />
		<col width="20%"/>
		<col width="13%" />
		<col width="20%"/>
		<col width="13%" />
		<col width="*" />
	</colgroup>
  <TR height="25"> 
    <TH>분개유형</TH>
	<%-- <TD><%= ContCodeManager.getCcsifSelectCodeList("SUB_ACCT_GB", "acct_gb", "width:100%;", "", ContInfo.get("acct_gb")) %></TD> --%>	<!-- 외주 분계유형 -->
	<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("proof_cd", "width:100%;", "onchange=chProofCd(this);", "", ContInfo.get("GUA_GB"), "Y") %></TD>
	<TH>PAY GROUP</TH>
	<input type="hidden" id="payTerms" name="payTerms" value="<%=ContInfo.get("PAYMENT_TERMS")%>">
	<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">
		<SELECT class='input_select' id='payment_terms_id' name='payment_terms_id' style='width:20%;'>
		</SELECT>
	</TD> 
	<%-- <TH>집행유형</TH>
	<TD colspan="3">
		<%= InputText.get("payItemNm", ContInfo.get("PAY_ITEM_NM"), 80, 30, "class=input_blank, readOnly=white, string, left, perSize, tabIndex=-1", "string") %>
	</TD> 	 --%>
  </TR> 	
</TABLE>
<script>
	changePaymentTerms(document.form1.pay_group);
	setSelect(document.form1.payment_terms_id, '<%= ContInfo.get("payment_terms") %>');
	setSelect(document.form1.proof_cd, '<%= ContInfo.get("GUA_GB") %>');
	setSelect(document.form1.payTerms, '<%= ContInfo.get("PAY_GROUP") %>');
</script>
