<%--
  - Author(s)  : Woo Seokjin
  - Date       : 2015.01.09
  - Description: PayMentTerm 조회
  --%>
  
<%@ 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.udapsoft.common.code.*" %>
<%@ page import="com.udapsoft.waf.common.util.DateUtil"%>
<%@ 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 = storage.getUser();
    
	String statusSheetComboListText 	   = (String)storage.getObject("selectText");
	String statusSheetComboListValue 	   = (String)storage.getObject("selectValue");

    RowSet payGroup = storage.getRowSet("PAYGROUPLIST");
    String payGroup_cd="";
	String payGroup_name="";
	
	for(int i=0;i<payGroup.size();i++){
		if(i+1<payGroup.size()){
			payGroup_cd = payGroup_cd+(payGroup.getRow(i).get("CODE"))+"|";
			payGroup_name = payGroup_name+(payGroup.getRow(i).get("NAME"))+"|";
		}else{
			payGroup_cd = payGroup_cd+(payGroup.getRow(i).get("CODE"));
			payGroup_name = payGroup_name+(payGroup.getRow(i).get("NAME"));
		}
    }
	
	RowSet payTermsAll = storage.getRowSet("PAYTERMSALL");
    String payTermsAll_cd="";
	String payTermsAll_name="";
	
	for(int i=0;i<payTermsAll.size();i++){
		if(i+1<payTermsAll.size()){
			payTermsAll_cd = payTermsAll_cd+(payTermsAll.getRow(i).get("CODE"))+"|";
			payTermsAll_name = payTermsAll_name+(payTermsAll.getRow(i).get("NAME"))+"|";
		}else{
			payTermsAll_cd = payTermsAll_cd+(payTermsAll.getRow(i).get("CODE"));
			payTermsAll_name = payTermsAll_name+(payTermsAll.getRow(i).get("NAME"));
		}
    }
	
	ValueObject defaultDate = DateUtil.getDefaultPeriod();
	String defaultDt = defaultDate.get("START_DATE");
	defaultDt=defaultDt.substring(0,7);
	
%>
<script language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	var right_name = "<%=user.get("RIGHT_NAME")%>";
	
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		 
		gridInit(sheet1);
		
		/**
		 *	Application Initialize
		 */
		
		$("#btnSearch").click(function() {
			if($("#allSearch").is(":checked")){
				$("#allSearchFlag").val("true");
			}else{
				$("#allSearchFlag").val("");
			}
			
			$("#fevent").val("SHEET_SELECT");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/PayMentList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
		});		
		$("#p_dept_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);	if(keycode == 8){$("#p_dept_cd").val("");$("#p_dept_nm").val("");}});
		$("#p_cont_status").change(function(){$("#btnSearch").click();});
		$("#p_build_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);if(keycode == 13)$("#btnSearch").click();});
		$("#p_dealer_nm").keydown(function (event){var keycode = (event.keyCode ? event.keyCode : event.which);if(keycode == 13)$("#btnSearch").click();});
		$("#btnSearch").click();
		$("#dataClear").click(function(){$("#payDt").val("");});
		
		$("#btnSave").click(function() {
			if(!sheet1.IsDataModified()) {
				alert("수정된 내역이 없습니다.");
				return;
			} else {
				if (confirm("수정 하시겠습니까?") == true){
					for(i=0;i<sheet1.RowCount();i++){
						if(sheet1.GetCellValue(i,"STATUS")=="U"&&((sheet1.GetCellValue(i,"PAYMENT_TERMS")=="")||(sheet1.GetCellValue(i,"PAY_GROUP")==""))){
							alert("빈 정보가 있습니다.");
							sheet1.SetSelectRow(i);
							return;
						}	
					}
					$("#fevent").val("UPDATE_DATA");
					var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/PayMentList_sheet.screen";
					var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
					alert("수정 되었습니다.");
				}else{   //취소
					alert("취소 되었습니다.");
				    return;
				}

			}
		});
		
		
		
		autoResize();
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, MergeSheet:msHeaderOnly, Page:100};
		init_sheet.Cols = [
		       			{Header:'Del',						Type:"DelCheck",		SaveName:"DEL_CHECK", 				Width:50, 		Align:"Center",		Hidden:"True"},
		    			{Header:'Status',					Type:"Status", 			SaveName:"STATUS", 					Width:0, 		Align:"Center", 	Edit:"false",		Hidden:"True"},
		    			{Header:'부서|부서',						Type:"Text", 			SaveName:"DEPT_CD", 				Width:0, 		Align:"Center", 	Edit:"false",		Hidden:"True"},
		    			{Header:'현장명|현장명',						Type:"Text", 			SaveName:"DEPT_NAME", 				Width:150, 		Align:"Left", 		Edit:"false"},
		    			{Header:'계약번호|계약번호',					Type:"Text", 			SaveName:"ORD_DOC_NO",				Width:150, 		Align:"Left", 		Edit:"false"},
		    			{Header:'계약명|계약명',						Type:"Text", 			SaveName:"CST_DOC_NAME", 			Width:200,		Align:"Left", 		Edit:"false"},
		    			{Header:'업체명|업체명',						Type:"Text", 			SaveName:"MEMBER_NAME", 			Width:150, 		Align:"Left", 		Edit:"false"},
		    			{Header:'통화|통화',						Type:"Text", 			SaveName:"CURRENCY_GB", 			Width:50, 		Align:"Center", 	Edit:"false"},
		    			{Header:'계약금액|계약금액',					Type:"Text", 			SaveName:"ORD_SUPPLY_AMT", 			Width:130, 		Align:"Right", 		Edit:"false"},
		    			{Header:'청구금액|청구금액',					Type:"Text", 			SaveName:"CUR_REQ_AMT", 			Width:130, 		Align:"Right", 		Edit:"false"},
		    			{Header:'증빙일자|증빙일자',					Type:"Text", 			SaveName:"TAX_DY", 					Width:100, 		Align:"Center",		Edit:"false",		Format:"####-##-##"},
		    			{Header:'세금계산서\n발행방법|세금계산서\n발행방법',			Type:"Combo", 			SaveName:"TAX_METHOD_CD", 			Width:100, 		Align:"Center", 	Edit:"false",		ComboText:"역발행|순발행|Invoice", ComboCode:"1|2|3"},
		    			{Header:'대금\n상태|대금\n상태',						Type:"Combo", 			SaveName:"REQ_STATUS", 				Width:80, 		Align:"Center", 	Edit:"false",		ComboText:"<%=statusSheetComboListText%>", ComboCode:"<%=statusSheetComboListValue%>"},
		    			{Header:'계약|PAY GROUP',			Type:"Combo", 			SaveName:"CONT_PAY_GROUP", 			Width:100, 		Align:"Center", 	Edit:"false",		ComboText:"<%=payGroup_name%>", ComboCode:"<%=payGroup_cd%>"},
		    			{Header:'계약|PAYMENT TERMS',		Type:"Combo", 			SaveName:"CONT_PAYMENT_TERMS", 		Width:150,  	Align:"Center", 	Edit:"false",		ComboText:"<%=payTermsAll_name%>", ComboCode:"<%=payTermsAll_cd%>"},
		    			{Header:'계약|PAYMENT TERMS NAME',	Type:"Text", 			SaveName:"CONT_PAYMENT_TERMS_NAME", Width:100, 		Align:"Center", 	Edit:"false",		Hidden:"True"},
		    			{Header:'대금|PAY GROUP',				Type:"Combo", 			SaveName:"PAY_GROUP", 				Width:100, 		Align:"Center", 	Edit:"false",		ComboText:"<%=payGroup_name%>", ComboCode:"<%=payGroup_cd%>"},
		    			{Header:'대금|PAYMENT TERMS',			Type:"Combo", 			SaveName:"PAYMENT_TERMS", 			Width:120,  	Align:"Center", 	Edit:"false",		ComboText:"<%=payTermsAll_name%>", ComboCode:"<%=payTermsAll_cd%>"},
		    			{Header:'대금|PAYMENT TERMS NAME',		Type:"Text", 			SaveName:"PAYMENT_TERMS_NAME",  	Width:150, 		Align:"Center", 	Edit:"false",		Hidden:"True"},
		    			{Header:'PUR_CONT_MOD_ID|PUR_CONT_MOD_ID',			Type:"Text", 			SaveName:"PUR_CONT_MOD_ID",  		Width:150, 		Align:"Center", 	Edit:"false",		Hidden:"True"}
		    			
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetImageList(1,"/img/buyer/btn/btn_write.gif");
		sheetName.SetActionMenu("ExcelDown");
		setGridSize();
	}

	
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	function sheet1_OnSelectMenu(Text, Code) {
		  // text 또는 code값으로 Action수행
		switch(Text) {
	         case "ExcelDown":
	        	 excelDown();
	            break; 
		}
	}	
	
	/**
	 *	IBSheet Event Change
	 */	
	function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH){
		if(Col=="16"||Col=="17"){
			comboInit(Row, Col, Value);
		}
	}
	
	function sheet1_OnChange(Row, Col, Value, OldValue, RaiseFlag){
		if(Col=="16"||Col=="17"){
			comboInit(Row, Col, Value);
		}
	}
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {sheet1.FitColWidth();}


	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
		
	}

	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	
	function comboInit(Row, Col, Value){
		<%
		String[] strArr={"01", "02", "11", "21", "22", "23", "30", "41", "42", "43", "55", "61", "71", "72", "73", "74", "91"};

		for(int i=0;i<strArr.length;i++){
			%>
			<%-- if(Value==<%=strArr[i]%>){
				var info = {"ComboCode":"<%=params.get("PAYTERMSLIST_"+strArr[i]+"_cd")%>","ComboText":"<%=params.get("PAYTERMSLIST_"+strArr[i]+"_name")%>"};
				sheet1.CellComboItem(Row,"PAYMENT_TERMS",info);
			}--%>
			if(sheet1.GetCellValue(Row,"PAY_GROUP")==<%=strArr[i]%>){
				var info = {"ComboCode":"<%=params.get("PAYTERMSLIST_"+strArr[i]+"_cd")%>","ComboText":"<%=params.get("PAYTERMSLIST_"+strArr[i]+"_name")%>"};
				sheet1.CellComboItem(Row,"PAYMENT_TERMS",info);
			}else if(sheet1.GetCellValue(Row,"PAY_GROUP")==""){
				var info = {"ComboCode":"","ComboText":" "};
				sheet1.CellComboItem(Row,"PAYMENT_TERMS",info);
			}
			<%
		}
		%>
	}
	
	function checkAuthority(){
		if((right_name=="ADMIN NEW"||right_name=="TREASURY")){
			$("#btnSave").show();
		}
	}
	
	function excelDown() {
		if(sheet1.RowCount() == 0) {
			alert("내역이 없습니다.");
			return;
		}
		var params = { FileName : "PayMentList.xls",  SheetName : "PayMentList", SheetDesign:0, Merge:1, DownCols:"DEPT_NAME|ORD_DOC_NO|CST_DOC_NAME|MEMBER_NAME|CURRENCY_GB|ORD_SUPPLY_AMT|CUR_REQ_AMT|TAX_DY"+
				"|TAX_METHOD_CD|REQ_STATUS|CONT_PAY_GROUP|CONT_PAYMENT_TERMS|PAY_GROUP|PAYMENT_TERMS", TitleText:"구매_계약별 대금 Payment Terms", UserMerge:"0,0,1,14", AutoSizeColumn:1  } ;
		sheet1.Down2Excel(params);
	}
	
	
	document.body.onresize = addEvent( document.body.onresize, "autoResize()");
</script>


<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="PUR_CONT_MOD_ID" value="">
<INPUT type='hidden' name="allSearchFlag" value="">

<div align="left" id="title">
	<ul>
		<li>계약별 대금 Payment Terms</li>
	</ul>
</div> 

<!-- 검색조건 시작 -->
<table id="search-table" class="search-form-table">
	<colgroup>
		<col width="100" />
		<col width="480" />
		<col width="100" />
		<col width="*" />
		<col width="100" />
	</colgroup>
  <tr height="25"> 
  	<th>현장</th>
   	<td>
  		<%=InputText.getSiteCodeNew("p_dept_cd", "p_dept_nm", "", user, params.get("p_dept_cd"), params.get("p_dept_nm"))%>
	</td>
  	<th>계약명</th>
   	<td>
   		<INPUT type="text" name="p_build_nm" class="input" value="<%= params.get("p_build_nm") %>" style="width:90%"> 
	</td>
	<td class="button" rowspan="2">
		<span class="btnSearch center" id="btnSearch"><a href="javascript:void(0);">검색</a></span>
		<span class="btnSearch center" id="btnSave" style="display: none"><a href="javascript:void(0);">저장</a></span>
	</td>	
  </tr>
  <tr>
	<th>증빙년월</th>
    <td> 
		<%= InputText.get("payDt", defaultDt, 10, 50, "hangule,center, desc=증빙일자,ReadOnly") %>
		<IMG name="start_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('payDt');">
		<IMG name="dataClear" id="dataClear" src="/img/buyer/button/bt_eraser1.gif" border="0" align="absmiddle" style="cursor:pointer;">
    </td>
    <th>모두 조회</th>
    <td> 
		<input type="checkbox" id="allSearch">
    </td>
  </tr>
</table>
</form>

<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 400px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '400px');</script>
</div>