<%--
  - FileName   : payRequestList.jsp
  - Author(s)  : ok
  - Date       : 2014.06.17
  - Copyright  : Copyright (c) 2013 www.udapsoft.co.kr, Inc.
  - Description: 대금신청현황
--%>

<%@ 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.udapsoft.common.code.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@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 event = storage.getEvent();
    
    RowSet statusComboList = storage.getRowSet("statusComboList"); //상태 ComboList Data

    //상태 sheetComboList Data
	String statusSheetComboListText 	   = (String)storage.getObject("selectText");
	String statusSheetComboListValue 	   = (String)storage.getObject("selectValue");
	
	//세금계산서 발행방법 구분
    String sTaxMethodComboListText 	   		= (String)storage.getObject("selectText1");
	String sTaxMethodComboListValue			= (String)storage.getObject("selectValue1");
	
	//검색조건 현장 설정
	String initSearchDeptCd = params.get("searchDeptCd");
	String initSearchDeptNm = params.get("searchDeptNm");
	//검색조건 계약명 설정
	String initSearchBuildName = params.get("searchBuildName");
	//검색조건 작성일
	String  initSearchDateStart = params.get("searchDateStart");
    String  initSearchDateEnd = params.get("searchDateEnd");
    //거래처명
    String initSearchCorp = params.get("searchCorp");
    
    //com.udapsoft.waf.common.util.DateUtil
	ValueObject defaultDate = DateUtil.getDefaultPeriod();
	if("".equals(initSearchDateStart)){
		initSearchDateStart = defaultDate.get("START_DATE");
	}
	if("".equals(initSearchDateEnd)){
		initSearchDateEnd = defaultDate.get("END_DATE");
	}
    
    //검색조건 상태 설정 
    String initStatusCd = params.get("searchStatusCd");
    if(initStatusCd == null || initStatusCd == ""){
    	initStatusCd = "";
    }

    
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		gridInit(sheet1);
		
		autoResize();
	
		//검색버튼
		jQuery("#btnSearch").click(function() {
  			jQuery("#fevent").val("GET_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/payment/purchase/PayRequestList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
		});

		//신규등록
		jQuery("#btnCreate").click(function() {
			var win_id = "PurchaseRequest";
			var link = "/payment/purchase/PurchaseRequestList.screen";
			    link += "?pop_win_id="+win_id;
			    link += "&searchDeptCd=" + jQuery("#searchDeptCd").val();
			    link += "&searchDeptNm=" + jQuery("#searchDeptNm").val();
			    //link += "&searchDateStart=" + jQuery("#searchDateStart").val();
			    //link += "&searchDateEnd=" + jQuery("#searchDateEnd").val();
			    link += "&pageDiv=1";	//1:조달, 2:포탈
			    fLayerPop(win_id, link, 980, 400, '', '', 'NO');
		});

		pageinit();
		
	}
	
	//시트 설정
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10, MergeSheet:msHeaderOnly};
		init_sheet.Cols = [
		       			//{Header:'☞삭제',					Type:"DelCheck",		SaveName:"DEL_CHECK", 			Width:50, 	Align:"Center",	Hidden:"True"},
		    			{Header:'상태|상태',									Type:"Status", 	SaveName:"STATUS", 				Width:0, 	Align:"Center",		Hidden:"True"},
		    			{Header:'현장명|현장명',								Type:"Text", 	SaveName:"DEPT_NAME",			Width:130, 	Align:"Left"},
		    			{Header:'계약번호|계약번호',							Type:"Text", 	SaveName:"ORD_DOC_NO", 			Width:110, 	Align:"Center"},
		    			{Header:'☞계약명|☞계약명',							Type:"Text", 	SaveName:"CST_DOC_NAME", 		Width:130,	Align:"Left"},
		    			{Header:'업체명|업체명',								Type:"Text", 	SaveName:"CORP_KOR", 			Width:100, 	Align:"Left"},
		    			{Header:'대금구분|대금구분',							Type:"Text",	SaveName:"PAY_DIV_NM", 			Width:45, 	Align:"Center"},
		    			{Header:'지급구분|지급구분',							Type:"Text", 	SaveName:"DEPOSIT_NM", 			Width:55, 	Align:"Center"},
		    			{Header:'증빙일자|증빙일자',							Type:"Text", 	SaveName:"REQ_DATE", 			Width:50, 	Align:"Center"},
		    			{Header:'통화|통화',									Type:"Text", 	SaveName:"CURRENCY_GB", 		Width:40, 	Align:"Center"},
						{Header:'계약금액|계약금액',							Type:"Int", 	SaveName:"ORD_AMT", 			Width:70, 	Align:"Right", 	Format:"#,##0"},
		    			{Header:'기성고|청구금',								Type:"Int", 	SaveName:"CURREQAMT", 			Width:70, 	Align:"Right", 	Format:"#,##0"},
		    			{Header:'기성고|선급공제',								Type:"Int", 	SaveName:"CUR_REQ_AMT", 		Width:70, 	Align:"Right", 	Format:"#,##0"},
		    			{Header:'기성고|누계',									Type:"Int", 	SaveName:"CUR_BEF_ACMP_AMT", 	Width:70, 	Align:"Right", 	Format:"#,##0"},
		    			{Header:'기성고|잔여',									Type:"Int", 	SaveName:"REMAINDER_ACMP_AMT", 	Width:70, 	Align:"Right", 	Format:"#,##0"},
		    			{Header:'누계\n지급율|누계\n지급율',					Type:"Float", 	SaveName:"CUR_ACMP_PERCENT", 	Width:40, 	Align:"Right", 	Format:"##0.0"},
		    			{Header:'세금계산서\n발행방법|세금계산서\n발행방법',	Type:"Combo",	SaveName:"TAX_METHOD_CD", 		Width:50, 	Align:"Center",	ComboText:"<%=sTaxMethodComboListText%>", 	ComboCode:"<%=sTaxMethodComboListValue%>"},
		    			{Header:'상태|상태',									Type:"Combo", 	SaveName:"REQ_STATUS", 			Width:60, 	Align:"Center", ComboText:"<%=statusSheetComboListText%>", ComboCode:"<%=statusSheetComboListValue%>"},
		    			{Header:'PUR_CONT_ID|PUR_CONT_ID',						Type:"Text", 	SaveName:"PUR_CONT_ID", 		Width:0, 	Align:"Left",	Hidden:"True"},
		    			{Header:'PAYREQ_ID',									Type:"Text", 	SaveName:"PAYREQ_ID", 			Width:0, 	Align:"Left",	Hidden:"True"}
		    			
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		sheetName.SetDataLinkMouse("CST_DOC_NAME", 1);
		sheetName.SetActionMenu("ExcelDown");
		setGridSize();
	}

	function sheet1_OnSelectMenu(Text, Code) {
		// text 또는 code값으로 Action수행
		switch(Text) {
			case "ExcelDown":
			sheetExcelDown(sheet1,$('li').html());
			break;
		}
	}

	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
	    	sheet1.SetColFontColor("CST_DOC_NAME", "#0000ff");
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	/**
	 *	IBSheet Event: DBLCLICK
	 */
	 function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 
		if (sheet1.ColSaveName(Col) == "CST_DOC_NAME") {
		    
			jQuery("#purContId").val(sheet1.GetCellValue(Row, "PUR_CONT_ID"));
			jQuery("#payreqId").val(sheet1.GetCellValue(Row, "PAYREQ_ID"));
			if(sheet1.GetCellValue(Row, "PAY_DIV_NM") == "계획분할"){
	 			jQuery("#fevent").val("");
				jQuery("#form1").attr("action", "/payment/purchase/PayInstallResult.screen");
				jQuery("#form1").attr("target", "_self");
				jQuery("#form1").attr("method", "post");
				jQuery("#form1").submit();
			}else if(sheet1.GetCellValue(Row, "PAY_DIV_NM") == "납품정산"){
	 			jQuery("#fevent").val("");
				jQuery("#form1").attr("action", "/payment/purchase/PayItemResult.screen");
				jQuery("#form1").attr("target", "_self");
				jQuery("#form1").attr("method", "post");
				jQuery("#form1").submit();
			}
		}
	 }

	//페이지 초기처리
	function pageinit(){
		//검색조건의 작성일 일자 설정
		setSearchDate();
	}
		
	//엔터키 검색 실행
	function doKeyPress() {
	    if( event.keyCode == 13 ) {
			$("#btnSearch").click();
	    }
	}	
		
	function doKeyPressEvent(param1, param2) {
	}
		
	//달력팝업	
	function calendar(thisDayObj){
		dlgCalendar(thisDayObj);
	}	
		
	//검색 조건에 작성일 일자 설정
	function setSearchDate(){
		    
		//검색조건 시작일 
		var startDate = get_year() +'-'+ get_month()  +'-'+ '01';
	    if(jQuery('#searchDateStart').val() == ""){
	    	jQuery('#searchDateStart').val(startDate);	
	    }
			
		//검색조건 종료일
		var nowYearMonth = new Date( get_year(), get_month(), "");
	    var lastDay = nowYearMonth.getDate();
		var endDate = get_year() +'-'+ get_month()  +'-'+ lastDay;
	    if(jQuery('#searchDateEnd').val() == ""){
	    	jQuery('#searchDateEnd').val(endDate);	
	    }
	}
		
	function PurchaseRequestPopupClose(){
		//alert();
		setTimeout(function(){fLayerPopClose('PurchaseRequest');},100);
		jQuery("#btnSearch").click();
	}

	
	//콜백함수
	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "GET_EHR_DATA" ) {
				if( resultObj.getSuccess() ) {
					alert("EHR Synchronize Complete");
					doSearch();
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}
		}
		catch(errorObject) {
	        showErrorDlg("doResult()", errorObject);
		}
	}
	
	//페이지 기본 등록 스크립트
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}
	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("bugase").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	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" style="width:100%;height:100%;">
	<INPUT type="hidden" name="fevent" id="fevent" value="">
	<INPUT type="hidden" name="purContId" id="purContId" value="">	<!-- 상세선택 key -->
	<INPUT type="hidden" name="payreqId" id="payreqId" value="">	<!-- 상세선택 key -->
	
   <div align="left" id="title">
    <ul>
     <li>구매_대금신청현황</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100px" />
			<col width="40%"/>
			<col width="100px" />
			<col/>
			<col width="150px" />
		</colgroup>
		<tr>
			<th>현장</th>
			<td>
				<%--<%=InputText.getSiteCode("searchDeptCd", "searchDeptNm", "", user, initSearchDeptCd, initSearchDeptNm)%> --%>
				<%=InputText.getSiteCodeNew("searchDeptCd", "searchDeptNm", "", user, initSearchDeptCd, initSearchDeptNm)%>
			</td>
			<th>계약명</th>
			<td>
				<INPUT type="text" id="searchBuildName" name="searchBuildName" value="<%=initSearchBuildName%>" maxlength="50" class="input" style="IME-MODE : active;width:95%;"   desc='계약명' onKeyPress="doKeyPress();">
			</td>			
			<td class="button" rowspan="3">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnCreate">신규등록</a></span>
			</td>			
		</tr>
		<tr>			
			<th>증빙일</th>
			<td>
				<%= InputText.get("searchDateStart", initSearchDateStart, 15, 50, "Center, date, PerSize, readonly", "date", "") %>
				<a href="JavaScript:calendar('searchDateStart');"><img src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>
				&nbsp;~&nbsp;
				<%= InputText.get("searchDateEnd", initSearchDateEnd, 15, 50, "Center, date, PerSize, readonly", "date", "") %>
				<a href="JavaScript:calendar('searchDateEnd');"><img src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>
			</td>			
			<th>상태</th>
			<td>
				<%= HTMLMaker.getSelectTag(statusComboList, "DETAILCD", "DETAILNM", "searchStatusCd", "width:50%;height=18;", "<option value=''>--전체--</option>", initStatusCd) %>
			</td>
		</TR>
   		<TR>
			<TH>업체명</TH>
			<TD colspan="3">
				<INPUT type="text" id="searchCorp" name="searchCorp" value="<%=initSearchCorp%>" maxlength="50" class="input" style="IME-MODE : active; width:42%;"  desc='업체명' onKeyPress="doKeyPress();">
			</TD>
   		</TR>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	<img src="/img/com/blank.gif" height="5px" />
   <div align="right" id="bugase">
    	<ul>
     		<li valign="bottom"><span style="color: red;">* 부가세별도</span></li>
    	</ul>
  	</div>	
	<div id="sheet1_div" style="padding-top:0px; height: auto; min-height: 350px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '350px');</script>
	</div>
</FORM>