<%--
  - FileName   : prepaymentsList.jsp
  - Author(s)  : ok
  - Date       : 2014.08.20
  - Copyright  : Copyright (c) 2013 www.udapsoft.co.kr, Inc.
  - Description: 전자조달 구매_선급금 현황
--%>

<%@page import="com.udapsoft.waf.common.util.DateUtil"%>
<%@ 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();
    
    RowSet statusComboList = storage.getRowSet("statusComboList"); //상태 ComboList Data
  	
    //상태 sheetComboList Data
	String statusSheetComboListText 	   = (String)storage.getObject("selectText");
	String statusSheetComboListValue 	   = (String)storage.getObject("selectValue");
    //System.out.println(statusSheetComboListText);
    //System.out.println(statusSheetComboListValue);
    
    //신청구분
    String perpayReqDivComboListText 	   = (String)storage.getObject("selectText1");
	String perpayReqDivComboListValue 	   = (String)storage.getObject("selectValue1");
	
	//세금계산서 발행방법 구분
    String sTaxMethodComboListText 	   		= (String)storage.getObject("selectText2");
	String sTaxMethodComboListValue			= (String)storage.getObject("selectValue2");
	
    //System.out.println(perpayReqDivComboListText);
    //System.out.println(perpayReqDivComboListValue);
  
  	//초기 조회시 상태값을 신청대상 설정 
    String initStatusCd = params.get("searchStatusCd");
    if(initStatusCd == null || initStatusCd == ""){
    	initStatusCd = "";
    }

	String dept_cd = params.get("searchDeptCd");
	String dept_nm = params.get("searchDeptNm");
	
	String signDt_from = params.get("searchSignDt_from");
	String signDt_to = params.get("searchSignDt_to");
	
	
	ValueObject defaultDate = DateUtil.getDefaultPeriod();
	if("".equals(signDt_from)){
		//signDt_from = defaultDate.get("START_DATE");
	}
	if("".equals(signDt_to)){
		//signDt_to = defaultDate.get("END_DATE");
	}
	
  	//조회 계약명
    String  returnBuildName = params.get("searchBuildName");
    
%>
<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("#btnSearch").click(function() {
			
 			jQuery("#fevent").val("GET_DATA");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/payment/purchase/PrepaymentsList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, ""); 
			 
		});
		
		
		//신규등록
		jQuery("#btnCreate").click(function() {
			var win_id = "Prepayment";
			var link = "/payment/purchase/PrepayRequestList.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');
		});

		
		
		jQuery("#btnAdd").click(function() {
			var rowIdx = sheet1.DataInsert(-1);
		});
		
		jQuery("#dataClear1").click(function(){
			jQuery("#searchSignDt_from").val("");
			jQuery("#searchSignDt_to").val("");
		});
		
		autoResize();
		pageinit();
		
	}
	
	function pageinit(){
		jQuery("#btnSearch").click();
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		init_sheet.Cols = [
		    			{Header:'상태',					Type:"Status", 	SaveName:"STATUS", 				Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'현장명',				    Type:"Text", 	SaveName:"DEPT_NAME",			Width:120, 	Align:"Left"},
		    			{Header:'계약번호',			    Type:"Text",	SaveName:"CON_DOC_NO", 	        Width:80, 	Align:"Left"},
		    			{Header:'차수',	   		        Type:"Text",	SaveName:"MOD_NO",  	        Width:20, 	Align:"Center"},
		    			{Header:'☞계약명',				Type:"Text", 	SaveName:"BUILD_NAME",			Width:120, 	Align:"Left"},
		    			{Header:'업체명',			    	Type:"Text", 	SaveName:"CORP_KOR", 			Width:80, 	Align:"Left"},
		    			{Header:'공사기간',				Type:"Text", 	SaveName:"START_END_WORK_DATE", Width:80, 	Align:"Center"},
		    			{Header:'계약금액',				Type:"Int", 	SaveName:"CON_AMT", 			Width:45, 	Align:"Right", 	Format:"#,##0"},
		    			{Header:'계약선급액',				Type:"Int", 	SaveName:"ORG_AMT", 			Width:45, 	Align:"Right", 	Format:"#,##0"},
		    			{Header:'선급금액',				Type:"Int", 	SaveName:"PREPAY_AMT", 			Width:45, 	Align:"Right",	Format:"#,##0"},
		    			{Header:'신청금액',				Type:"Int", 	SaveName:"REQ_PREPAY_AMT", 		Width:45, 	Align:"Right",	Format:"#,##0"},
		    			{Header:'신청일자',				Type:"Text", 	SaveName:"SIGN_DT", 			Width:45, 	Align:"Center", Format:"Ymd"},
		    			{Header:'신청구분',				Type:"Combo", 	SaveName:"REQ_DIV_CD",	 		Width:45, 	Align:"Center",	ComboText:"<%=perpayReqDivComboListText%>", ComboCode:"<%=perpayReqDivComboListValue%>"},
		    			{Header:'세금계산서\n발행방법',	    Type:"Combo", 	SaveName:"TAX_METHOD_CD", 		Width:50, 	Align:"Center", ComboText:"<%=sTaxMethodComboListText%>", 	ComboCode:"<%=sTaxMethodComboListValue%>"},
		    			{Header:'상태',					Type:"Combo", 	SaveName:"STATUS_CD", 			Width:50, 	Align:"Center",	ComboText:"<%=statusSheetComboListText%>",	ComboCode:"<%=statusSheetComboListValue%>"},
		    			{Header:'SUB_CONT_MOD_ID',		Type:"Text",	SaveName:"SUB_CONT_MOD_ID", 	Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'CHG_DIV_CD',			Type:"Text",	SaveName:"CHG_DIV_CD", 	        Width:0, 	Align:"Center", Hidden:"True"}
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		sheetName.SetDataLinkMouse("BUILD_NAME", 1);
		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();
	    	sheet1.SetColFontColor("BUILD_NAME", "#0000ff");
	    	for(var i=1; i<sheet1.RowCount()+1; i++) {
		    	if (sheet1.GetCellValue(i, "PREPAY_AMT") != sheet1.GetCellValue(i, "ORG_AMT")) {
		    		sheet1.SetCellFontColor(i,"PREPAY_AMT", "#EB1E00");
		    	}
	        }
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	/**
	 *	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) {

		if (sheet1.ColSaveName(Col) == "BUILD_NAME") {	//계약명
			if(sheet1.GetCellValue(Row, "CHG_DIV_CD") == "Y"){			
	 			jQuery("#selectSubContModId").val(sheet1.GetCellValue(Row, "SUB_CONT_MOD_ID"));
				jQuery("#fevent").val("");
				//jQuery("#form1").attr("action", "/payment/purchase/PrepaymentsAdd.screen");2018.07.27
				jQuery("#form1").attr("action", "/payment/purchase/Prepayments.screen");
				jQuery("#form1").attr("target", "_self");
				jQuery("#form1").attr("method", "post");
				jQuery("#form1").submit();
			}else{
	 			jQuery("#selectSubContModId").val(sheet1.GetCellValue(Row, "SUB_CONT_MOD_ID"));
				jQuery("#fevent").val("");
				jQuery("#form1").attr("action", "/payment/purchase/Prepayments.screen");
				jQuery("#form1").attr("target", "_self");
				jQuery("#form1").attr("method", "post");
				jQuery("#form1").submit();
			    
			}
		}
	}
	
	
	
	function PurchaseRequestPopupClose(){
		//alert();
		setTimeout(function(){fLayerPopClose('Prepayment');},100);
		jQuery("#btnSearch").click();
	}
	
	
	function doKeyPress() {
	    if( event.keyCode == 13 ) {
	    	jQuery("#btnSearch").click();
	    }
	}	

	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); 
	}
	
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<BODY onresize="autoResize()" >

<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="selectSubContModId" id="selectSubContModId" value="">
	<INPUT type="hidden" name="selectPrepayId" id="selectPrepayId" value="">	
	<INPUT type="hidden" name="resultListDiv" id="resultListDiv" value="1">

	<!-- 프로그램 제목 -->
	<div align="left" id="title">
		<ul>
			<li>구매_선급금현황</li>
		</ul>
	</div> 

	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100px">
			<col width="35%">
			<col width="100px">
			<col/>
			<col width="200px">
		</colgroup>
		<TR>
			<TH>현장</TH>
			<TD>
				<%-- <%=InputText.getSiteCode("searchDeptCd", "dept_nm", "", user, dept_cd, dept_nm)%> --%>
				<%=InputText.getSiteCodeNew("searchDeptCd", "searchDeptNm", "", user, dept_cd, dept_nm)%>
			</TD>
			<th>신청일자</th>
			<td>
				<%= InputText.get("searchSignDt_from", signDt_from, 10, 50, "hangule,center, desc=신청일,ReadOnly") %>
				<IMG name="start_img" id="calender_from" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('searchSignDt_from');"> 
				~
				<%= InputText.get("searchSignDt_to", signDt_to, 10, 50, "hangule,center, desc=신청일,ReadOnly") %>
				<IMG name="start_img" id="calender_from" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('searchSignDt_to');">
				<IMG name="dataClear1" id="dataClear1" src="/img/buyer/button/bt_eraser1.gif" border="0" align="absmiddle" style="cursor:pointer;">
			</td>			
   			<TD class="button" rowspan="3">      
   				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
   				<span class="btnSearch center" id="spanBtnCreate" ><a href="javascript:void(0);" id="btnCreate">선급금 추가 생성</a></span>
			</TD>
		</TR>
  		<TR>
			<TH>계약명</TH>
			<TD colspan="1">
				<INPUT type="text" id="searchBuildName" name="searchBuildName" value="<%=returnBuildName %>" maxlength="50" class="input" style="IME-MODE : active; width:90%;"  desc='계약명' onKeyPress="doKeyPress();">
			</TD>
			<TH>상태</TH>
    		<TD>
				<%=HTMLMaker.getSelectTag(statusComboList, "DETAILCD", "DETAILNM", "searchStatusCd", "width:30%;height=18;", "<option value=''>--전체--</option>", initStatusCd) %>
    		</TD>					
   		</TR>
   		<TR>
			<TH>업체명</TH>
			<TD colspan="3">
				<INPUT type="text" id="searchCorp" name="searchCorp" value="" maxlength="50" class="input" style="IME-MODE : active; width:42%;"  desc='업체명' onKeyPress="doKeyPress();">
			</TD>
   		</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>
</body>