<%--
  - FileName   : purchaseRequestList.jsp
  - Author(s)  : ok
  - Date       : 2014.07.28
  - Copyright  : Copyright (c) 2014 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.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.util.Formatter"%>

<%@ 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();
	
	//검색조건 현장 설정
	String initSearchDeptCd = params.get("searchDeptCd");
	String initSearchDeptNm = params.get("searchDeptNm");
	
	//검색조건 작성일
	//String  initSearchDateStart = params.get("searchDateStart");
    //String  initSearchDateEnd = params.get("searchDateEnd");
	
    String pageDiv = params.get("pageDiv");	//1:조달 2:포탈
    
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		/**
		 *	IBSheet object initialize
		 */
		gridInit(sheet1);
		
	
		/**
		 *	Application Initialize
		 */
		
		jQuery("#btnCreate").click(function() {
			
			if(sheet1.RowCount("U") == 0){
				alert("신규생성할 대금대상건을 선택하세요.");
				return;
			}
			
 			if (confirm("대금 정보를 생성 하시겠습니까?")) {
				jQuery("#fevent").val("SAVE_DATA");
				
				var url = Modular.model.PageContext.CONTEXT_ROOT + "/payment/purchase/PurchaseRequestList_sheet.screen";
				var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
			}
		}); 
		
		jQuery("#btnClose").click(function() {
			//setTimeout(function(){parent.searchAccDeptClose(null);},100);
			parent.PurchaseRequestPopupClose();
		}); 

		jQuery("#btnSearch").click(function() {
			searchData();
		}); 
		
		pageinit();
		
	}
	
	function pageinit(){
		
		//검색조건의 작성일 일자 설정
		setSearchDate();
		
		//데이터 조회
		searchData();
		
		//1:조달, 2:포탈
		if(jQuery("#pageDiv").val() == "2"){
			sheet1.SetColHidden(5, 1);	//업체명 숨김
		}
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30, MergeSheet:msHeaderOnly};
		init_sheet.Cols = [
		    			{Header:'상태',				Type:"Status", 			SaveName:"STATUS", 						Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'선택',				Type:"CheckBox",		SaveName:"CHECKBOX", 					Width:40, 	Align:"Center"},
		    			{Header:'현장코드',			Type:"Text", 			SaveName:"DEPT_CD",						Width:50, 	Align:"Left",	Hidden:"True"},
		    			{Header:'현장명',			Type:"Text", 			SaveName:"DEPT_NAME",					Width:110, 	Align:"Left"},
		    			{Header:'계약명',			Type:"Text", 			SaveName:"CST_DOC_NAME",				Width:110, 	Align:"Left"},
		    			{Header:'업체명',			Type:"Text", 			SaveName:"CORP_KOR",					Width:110, 	Align:"Left"},
		    			{Header:'통화',				Type:"Text", 			SaveName:"CURRENCY_GB", 				Width:40, 	Align:"Center"},
		    			{Header:'지급차수',			Type:"Text", 			SaveName:"DEPOSIT_SEQ", 				Width:40, 	Align:"Center"},
		    			{Header:'계약금액',			Type:"Int", 			SaveName:"ORD_SUPPLY_AMT", 				Width:80, 	Align:"Right", Format:"#,##0"},
		    			{Header:'금회청구액',			Type:"Int", 			SaveName:"CUR_ACMP_APPLYAMT",		 	Width:80, 	Align:"Right", Format:"#,##0"},
		    			{Header:'청구잔액',			Type:"Int", 			SaveName:"REMAINDER_ACMP_SUPPLYAMT", 	Width:80, 	Align:"Right", Format:"#,##0"},
		    			{Header:'지급율',			Type:"Int", 			SaveName:"CUR_ACMP_PERCENT", 			Width:40, 	Align:"Right", Format:"##0.0"},
		    			{Header:'PUR_CONT_ID',		Type:"Text", 			SaveName:"PUR_CONT_ID", 				Width:80, 	Align:"Center", Hidden:"True"},
		    			{Header:'PUR_CONT_MOD_ID',	Type:"Text", 			SaveName:"PUR_CONT_MOD_ID",				Width:80, 	Align:"Center", Hidden:"True"},
		    			{Header:'DIV',				Type:"Text", 			SaveName:"DIV", 						Width:80, 	Align:"Center", Hidden:"True"}	//1:토건, 2:플랜트, 3:설치
		];

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

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

	
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	IBSheet Event: Save End(IBSheet 데이터 저장 CallBack)
	 */
	function sheet1_OnSaveEnd(code, msg) {
	    if(code >= 0) {
	    	//alert("신규로 대금건이 생성되었습니다. \n\n 외주_기성현황에서 확인 하실수 있습니다.");
	    	alert("신규 대금건이 생성되었습니다.");
	    } else {
	    	
	    	alert("생성실패 하였습니다.");
        }
	    //searchData();
	    searchClose();
	}
	
	/**
	 *	IBSheet Event: Click
	 */
	function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 //masterSheetRow = Row;
	}
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	/**
	 *	IBSheet Event: DBLCLICK
	 */
	function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {

	}
	
	function doKeyPress() {
	    if( event.keyCode == 13 ) {
	    	jQuery("#btnSearch").click();
	    }
	}	
	
	function calendar(thisDayObj){
		dlgCalendar(thisDayObj);
		
	}		
	
	function searchData(){

		jQuery("#fevent").val("GET_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/payment/purchase/PurchaseRequestList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, ""); 

	}

	function searchClose(){
		parent.PurchaseRequestPopupClose();
	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
	}
	
	//검색 조건에 작성일 일자 설정
	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);	
	    } */
	}
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<BODY>
<form id="form1" name="form1" method="post" modular:type="search">
	<INPUT type="hidden" name="fevent" id="fevent" value="">
	<INPUT type="hidden" name="pageDiv" id="pageDiv" value="<%=params.get("pageDiv")%>">	<!-- //1:조달 2:포탈  -->
	<INPUT type="hidden" name="userCorpId" id="userCorpId" value="<%=user.get("CORP_ID")%>">
	
	<!-- 프로그램 제목 -->
<!-- 	<div align="left" id="title">
		<ul>
			<li>대금 신청대상</li>
		</ul>
	</div>  -->
	
	<!-- 검색조건 영역 : 시작 -->
	<table class="search-form-table" style="width: 100%">
		<colgroup>
			<col width="8%" />
			<col width="35%" />
			<col width="8%" />
			<col width="*" />
			<col width="25%" />
		</colgroup>
		<TR height="25"> 
		<!-- 검색조건 타이틀 1 -->
			<%
				if(pageDiv.equals("1")){	//1:조달
			%>
			<th>현장</th>
			<td colspan="3">
					<%=InputText.getSiteCode("searchDeptCd", "searchDeptNm", "", user, initSearchDeptCd, initSearchDeptNm)%>
			</td>					
			<%
				}else{
			%>
			<th>계약명</th>
			<td colspan="3">
				<input name="searchCstNm" class="input" id="searchCstNm" type="text" style="width: 50%; value=""/>
			</td>					
			<%
				}
			%>

<%-- 			<td>
				<%= InputText.get("searchDateStart", initSearchDateStart, 28, 10, "Center, date, PerSize, readonly", "date", "") %>
				<a href="JavaScript:calendar('searchDateStart');"><img src="/img/supplier/template/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>
				&nbsp;~&nbsp;
				<%= InputText.get("searchDateEnd", initSearchDateEnd, 29, 10, "Center, date, PerSize, readonly", "date", "") %>
				<a href="JavaScript:calendar('searchDateEnd');"><img src="/img/supplier/template/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>
			</td> --%>			
			<TD class="button">      
				<!-- 검색버튼 영역 : 시작 -->
    			<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>
				<!-- <span class="btnSearch center"><a href="javascript:void(0);" id="btnClose">닫기</a></span> -->
 				<!-- 검색버튼 영역 : 종료 -->  
   			</TD>
  		</TR>
	</TABLE>
	<!-- 검색조건 영역 : 종료 -->

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