<%--
  - FileName   : BidHistoryList.jsp
  - Author(s)  : mklee
  - Date       : 2016.08.22
  - 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" %>
<%@ 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 materialKindCodeLv1 = storage.getRowSet("materialKindCodeLv1");
	RowSet materialKindCodeLv2 = new RowSetImpl();
	RowSet materialKindCodeLv3 = new RowSetImpl();
	
	java.util.Calendar curDate = java.util.Calendar.getInstance();
	java.util.Calendar tmpDate = java.util.Calendar.getInstance();
	java.text.SimpleDateFormat fmtDay = new java.text.SimpleDateFormat("yyyy-MM-dd");
	
	tmpDate.add ( tmpDate.YEAR, -1 ); 
	String signDt_from = fmtDay.format(tmpDate.getTime());  //1년전 
	String signDt_to = fmtDay.format(curDate.getTime()); // 오늘  
	
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){

		gridInit(sheet1);
		
		autoResize();
	
        var material_Kind_Code_Lv1 = "<%=params.get("material_Kind_Code_Lv1")%>";
		
		if(material_Kind_Code_Lv1.trim() != "")
	    {
		    $("#material_Kind_Code_Lv1").change();
	    } 
		
		jQuery("#btnSearch").click(function() {
			
 			if(Number(jQuery("#signDt_from").val().replace(/(\-|\:)/g, "")) > Number(jQuery("#signDt_to").val().replace(/(\-|\:)/g, ""))){
				alert("신청일자를 확인해주세요");
				return;
			}
 			
 			jQuery("#fevent").val("SHEET_SELECT");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/purchase/BidHistoryList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, ""); 
		});
		
	}
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		init_sheet.Cols = [
		    			{Header:'Bid_no',			    Type:"Text", 			SaveName:"BID_NO", 			Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'Bid_deg',				Type:"Text", 			SaveName:"BID_DEG",			Width:130, 	Align:"Left",   Hidden:"True"},
		    			{Header:'대표아이템',				Type:"Text", 			SaveName:"ITEM_NAME",		Width:150, 	Align:"Left"},
		    			{Header:'입찰명',  				Type:"Text", 			SaveName:"BID_MASTER_NM",	Width:130, 	Align:"Left"},
		    			{Header:'업체명',				    Type:"Text", 			SaveName:"VENDOR_NAME",		Width:100, 	Align:"Left"},
		    			{Header:'현장명',				    Type:"Text", 			SaveName:"DEPT_NM",         Width:130, 	Align:"Left"},
		    			{Header:'입찰금액',				Type:"Int", 			SaveName:"AMT", 			Width:50, 	Align:"Right", Format:"#,##0"},
		    			{Header:'실행대비',				Type:"Floot", 			SaveName:"ACT_RATE",		Width:30, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:'외주대비',				Type:"Floot", 			SaveName:"PUR_RATE",		Width:30, 	Align:"Right", Format:"#,##0.00", Hidden:"True"},
		    			{Header:'낙찰여부',				Type:"Text", 			SaveName:"SUCC_YN", 		Width:40, 	Align:"Center" },
		    			{Header:'입찰순위',				Type:"Text", 			SaveName:"RNK", 		    Width:50, 	Align:"Center" },
		    			{Header:'입찰상태',				Type:"Text", 			SaveName:"STATUS_NM", 		Width:80, 	Align:"Center" },
		];

		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;
		}
	}

	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
	    	sheet1.SetColFontColor("BUILD_NAME", "#0000ff");
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
	}

	/**
	 *	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 sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}
	
	function searchSite() {
		var win_id = "_searchSite";
		var link = "/lib/dlgSearchSpotDept.screen";
		    link += "?pop_win_id="+win_id;
			fLayerPop(win_id, link, 550,500, '', '', 'NO');
	}
	function searchSiteClose(result) {
		if( result == null ){
			document.form1.dept_cd.value = "";   //부서코드
			document.form1.dept_nm.value = "";   //부서명
		}else{
			document.form1.dept_cd.value = result[0];   //부서코드
			document.form1.dept_nm.value = result[1];   //부서명
		}
		fLayerPopClose('_searchSite');
	}

 	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); 
	}
	
	function selectChange(){
		jQuery("#btnSearch").click();
	}
	
 
	function level1change(){
	    var f = document.form1;
	    
	    if($("#material_Kind_Code_Lv1").val().trim() == "")
	    {
		    $("#material_Kind_Code_Lv2").empty().data("options"); 
		    $("#material_Kind_Code_Lv2").append("<option value=''>-- 전체 --</option>");
		    
		    $("#material_Kind_Code_Lv3").empty().data("options"); 
		    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
	    }
		else
		{
		    $("#fevent").val("GET_MATL_KIND_CODE_LV2");
		    
		    $("#materialgroup").val($("#material_Kind_Code_Lv1").val());
		    
		    $("#material_Kind_Code_Lv3").empty().data("options"); 
		    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
	 
		    submitXmlRequest("/bid/purchase/BidHistoryList_process.screen", "GET_MATL_KIND_CODE_LV2", f, "ROWSET");
		}
	}
	
	 function level2change(){
	    
	    var f = document.form1;
	    
	    if($("#material_Kind_Code_Lv2").val().trim() == "")
	    {
		    $("#material_Kind_Code_Lv3").empty().data("options"); 
		    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
		    
		    $.searchList();
	    }
	    else
	    {
	        $("#fevent").val("GET_MATL_KIND_CODE_LV3");
		    
		    $("#materiallevel").val("3");
		    $("#materialgroup").val($("#material_Kind_Code_Lv2").val());
		    
		    submitXmlRequest("/bid/purchase/BidHistoryList_process.screen", "GET_MATL_KIND_CODE_LV3", f, "ROWSET");
	    }    
	}
	
	
	function doResult(resultObj) {
		var f = document.form1;
		
		try {
			if ( resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV2" ) 
			{
				if ( resultObj.getSuccess() == true ) 
				{
				    var rowSet	= resultObj.getRowSet();
				    
				    $("#material_Kind_Code_Lv2").empty().data("options"); 
				    $("#material_Kind_Code_Lv2").append("<option value=''>-- 전체 --</option>");
				    
				    for ( var i = 0; i < rowSet.getRowSize(); i++ )	
				    {
				        $("#material_Kind_Code_Lv2").append("<option value='"+rowSet.getColValue( i, 0 )+"'>"+rowSet.getColValue( i, 1 ) + "</option>");
					}
				    
				    document.form1.isSubmit = false;
				    
				    var material_Kind_Code_Lv2 = "<%=params.get("material_Kind_Code_Lv2")%>";
				    
				    if(material_Kind_Code_Lv2.trim() != "")
			        {
				    	$("#material_Kind_Code_Lv2").val(material_Kind_Code_Lv2).attr("selected", "selected");
				        $("#material_Kind_Code_Lv2").change();
			        }
				    
					
				} else {
                    dlgErrorMsg(resultObj);
                }
			}
			else if ( resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV3" ) 
			{
				if ( resultObj.getSuccess() == true ) 
				{
				    var rowSet	= resultObj.getRowSet();
				    
				    $("#material_Kind_Code_Lv3").empty().data("options"); 
				    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
				    
				    for ( var i = 0; i < rowSet.getRowSize(); i++ )	
				    {
				        $("#material_Kind_Code_Lv3").append("<option value='"+rowSet.getColValue( i, 0)+"'>"+rowSet.getColValue( i, 1 ) + "</option>");
					}
				    
					document.form1.isSubmit = false;
					
					var material_Kind_Code_Lv3 = "<%=params.get("material_Kind_Code_Lv3")%>";
				    
				    if(material_Kind_Code_Lv3.trim() != "")
			        {
				        $("#material_Kind_Code_Lv3").val(material_Kind_Code_Lv3).attr("selected", "selected");
			        }
				    
				}
				else if(resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV3")
				{
                    dlgErrorMsg(resultObj);
                }
			}
			 
		}
		catch(errorObject) {
			    showErrorDlg("doResult()", errorObject);
		}
	}
	
	function injectSelect(vo, selectObj, code, value){
		var Code = vo.get(code);
		var Value = vo.get(value);
		var arrCd = Code.split('|');
		var arrValue = Value.split('|');

		while(selectObj.options.length){
			selectObj.remove(0);
		}
		
		var newOpt;
		newOpt = document.createElement('option');
		newOpt.text = "-- 전체 --";
		newOpt.value = "";
		selectObj.options.add(newOpt);
		
		if (arrCd == '') {
			selectObj.length = 1;
			
		} else {		
			for(var i = 0; i < arrCd.length; i++){
				newOpt = document.createElement('option');
				newOpt.text = arrCd[i];
				newOpt.value = arrValue[i];
				selectObj.options.add(newOpt);
			}
		}
	}
	
</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" id="item_cd" name="item_cd" value="">
    <input type="hidden" id="item_depth" name="item_depth" value="">

   	<div align="left" id="title">
    	<ul>
     		<li>구매_입찰이력</li>
    	</ul>
  	</div>

	<!-- 검색조건 영역 : 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="70px">
			<col width="25%">
			<col width="70px">
			<col width="15%">
			<col width="100px">
			<col/>
			<col width="100px">
		</colgroup>	
		<TR>
			<TH>현장</TH>
			<TD colspan=3>
			<%=InputText.getSiteCodeNew("dept_cd", "dept_nm", "", user, params.get("dept_cd"), params.get("dept_nm"))%>
			</TD>
			<th>입찰시작일자</th>
			<td>
				<%= InputText.get("signDt_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('signDt_from');">
				~
				<%= InputText.get("signDt_to", signDt_to, 10, 50, "hangule,center, desc=입찰시작일,ReadOnly") %>
				<IMG name="start_img" id="calender_to" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('signDt_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="2">      
   				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
			</TD>
		</TR>
  		<TR>
			<TH>업체명</TH>
			<TD >
				<INPUT type="text" id="searchCorp" name="searchCorp" value="" maxlength="50" class="input" style="IME-MODE : active; width:90%;"  desc='계약명' onKeyPress="doKeyPress();">
			</TD>
			<TH>입찰명</TH>
			<TD >
				<INPUT type="text" id="searchBid" name="searchBid" value="" maxlength="50" class="input" style="IME-MODE : active; width:90%;"  desc='입찰명' onKeyPress="doKeyPress();">
			</TD>
			<TH>대표ITEM</TH>
    		<TD>
    		  	<%= HTMLMaker.getSelectTag(materialKindCodeLv1, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv1", "style='width:28%;height=18;' onChange='javascript:level1change();'", "<OPTION value=''>-- 전체 --</OPTION>", params.get("material_Kind_Code_Lv1"), 0) %>
				<%= HTMLMaker.getSelectTag(materialKindCodeLv2, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv2", "style='width:28%;height=18;' onChange='javascript:level2change();'", "<OPTION value=''>-- 전체 --</OPTION>", params.get("material_Kind_Code_Lv2"), 0) %>
				<%= HTMLMaker.getSelectTag(materialKindCodeLv3, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv3", "style='width:28%;height=18;' ", "<OPTION value=''>-- 전체 --</OPTION>", params.get("material_Kind_Code_Lv3"), 0) %>
			</TD>					
   		</TR>
   	</TABLE>
	<!-- 검색조건 영역 : 종료 -->
	<img src="/img/com/blank.gif" height="5px" />
   <div align="right" id="bugase">
    	<ul>

    	</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>