<%--
  - FileName   : BidHistoryList.jsp
  - Author(s)  : mklee
  - Date       : 2016.03.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 outItemTag1 = storage.getRowSet("outItemTag1");
	RowSet outItemTag2 = storage.getRowSet("outItemTag2");
	RowSet outItemTag3 = storage.getRowSet("outItemTag3");
	RowSet DeptName = storage.getRowSet("DeptName");
	
	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();
	
		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/outside/BidHistoryDeptList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, ""); 
		});
		
         jQuery("#btnDept").click(function() {
        	var win_id = "_searchUserPopup";
     		var link = "/bid/outside/dlgBidHistoryDeptPop.screen";
     		    link += "?pop_win_id="+win_id;
     		    link += "&BASECD=BID_HIS_DEPT&fevent=DEPTPOP";
     		
     		fLayerPop(win_id, link, 700,400, '', '', 'NO');
		});
	
		pageinit();
		
	}
	function SearchUserClose(result){
		setTimeout(function(){fLayerPopClose('_searchUserPopup');},100);
	}
	
	function pageinit(){
		//jQuery("#btnSearch").click();
	}
	
	function gridInit(sheetName){
		var init_sheet = {};
		var dept_name = ['','','','','','','','','','','','','','','','','','','',''];
		
		<% if(DeptName.size() > 0){
			for(int i=0; i < DeptName.size();i++){%>
			      dept_name[<%=i%>] = "<%=DeptName.getRow(i).get("DEPT_NM")%>";
			<%}
	    }%>
	
		init_sheet.Cfg = {SearchMode:2, MergeSheet:msHeaderOnly, Page:30};
		init_sheet.Cols = [
		    			{Header:'공종명|공종명',			    Type:"Text", 	SaveName:"ITEM_NAME",		Width:130, 	Align:"Left"},
		    			{Header:'업체명|업체명',			    Type:"Text", 	SaveName:"VENDOR_NAME",		Width:100, 	Align:"Left"},
		    			{Header:dept_name[0]+'|입찰금액',     Type:"Floot", 	SaveName:"AMT1", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[0]+'|실행대비',	    Type:"Floot",	SaveName:"RATE1",		    Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[1]+'|입찰금액',		Type:"Floot",	SaveName:"AMT2", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[1]+'|실행대비',		Type:"Floot",	SaveName:"RATE2",		    Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[2]+'|입찰금액',		Type:"Floot",	SaveName:"AMT3", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[2]+'|실행대비',		Type:"Floot",	SaveName:"RATE3",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[3]+'|입찰금액',		Type:"Floot",	SaveName:"AMT4", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[3]+'|실행대비',		Type:"Floot",	SaveName:"RATE4",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[4]+'|입찰금액',		Type:"Floot",	SaveName:"AMT5", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[4]+'|실행대비',		Type:"Floot",	SaveName:"RATE5",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[5]+'|입찰금액',		Type:"Floot",	SaveName:"AMT6", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[5]+'|실행대비',		Type:"Floot",	SaveName:"RATE6",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[6]+'|입찰금액',		Type:"Floot",	SaveName:"AMT7", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[6]+'|실행대비',		Type:"Floot",	SaveName:"RATE7",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[7]+'|입찰금액',		Type:"Floot",	SaveName:"AMT8", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[7]+'|실행대비',		Type:"Floot",	SaveName:"RATE8",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[8]+'|입찰금액',		Type:"Floot",	SaveName:"AMT9", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[8]+'|실행대비',		Type:"Floot",	SaveName:"RATE9",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[9]+'|입찰금액',		Type:"Floot",	SaveName:"AMT10", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[9]+'|실행대비',		Type:"Floot",	SaveName:"RATE10",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[10]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT11", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[10]+'|실행대비',	Type:"Floot", 	SaveName:"RATE11",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[11]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT12", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[11]+'|실행대비',	Type:"Floot", 	SaveName:"RATE12",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[12]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT13", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[12]+'|실행대비',	Type:"Floot", 	SaveName:"RATE13",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[13]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT14", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[13]+'|실행대비',	Type:"Floot", 	SaveName:"RATE14",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[14]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT15", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[14]+'|실행대비',	Type:"Floot", 	SaveName:"RATE15",		    Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[15]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT16", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[15]+'|실행대비',	Type:"Floot", 	SaveName:"RATE16",		    Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[16]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT17", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[16]+'|실행대비',	Type:"Floot", 	SaveName:"RATE17",		    Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[17]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT18", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[17]+'|실행대비',	Type:"Floot", 	SaveName:"RATE18",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[18]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT19", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[18]+'|실행대비',	Type:"Floot", 	SaveName:"RATE19",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[19]+'|입찰금액',	Type:"Floot", 	SaveName:"AMT20", 			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:dept_name[19]+'|실행대비',	Type:"Floot", 	SaveName:"RATE20",			Width:50, 	Align:"Right", Format:"#,##0.00"},
		    			{Header:'낙찰여부1|1',				Type:"Text",	SaveName:"SUCC_YN1",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부2|2',				Type:"Text",	SaveName:"SUCC_YN2",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부3|3',				Type:"Text",	SaveName:"SUCC_YN3",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부4|4',				Type:"Text",	SaveName:"SUCC_YN4",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부5|5',				Type:"Text",	SaveName:"SUCC_YN5",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부6|6',				Type:"Text",	SaveName:"SUCC_YN6",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부7|7',				Type:"Text",	SaveName:"SUCC_YN7",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부8|8',				Type:"Text",	SaveName:"SUCC_YN8",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부9|9',				Type:"Text",	SaveName:"SUCC_YN9",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부10|10',				Type:"Text", 	SaveName:"SUCC_YN10",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부11|11',				Type:"Text", 	SaveName:"SUCC_YN11",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부12|12',				Type:"Text", 	SaveName:"SUCC_YN12",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부13|13',				Type:"Text", 	SaveName:"SUCC_YN13",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부14|14',				Type:"Text", 	SaveName:"SUCC_YN14",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부15|15',				Type:"Text", 	SaveName:"SUCC_YN15",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부16|16',				Type:"Text", 	SaveName:"SUCC_YN16",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부17|17',				Type:"Text", 	SaveName:"SUCC_YN17",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부18|18',				Type:"Text", 	SaveName:"SUCC_YN18",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부19|19',				Type:"Text", 	SaveName:"SUCC_YN19",		Width:30, 	Align:"Right",  Hidden:"True" },
		    			{Header:'낙찰여부20|20',				Type:"Text", 	SaveName:"SUCC_YN20",		Width:30, 	Align:"Right",  Hidden:"True" },
		    					
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		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();
	    	var rowcnt = sheet1.RowCount();
	    	if(rowcnt > 0){
				for(var r=2; r < rowcnt+2; r++)
				{
					for (var i=1; i<=20; i++){
						if(sheet1.GetCellValue(r,"SUCC_YN" + (i).toString()) == "Y" ){
							sheet1.SetCellFontColor(r, "AMT" + (i).toString(), "#EF0B0B");
							sheet1.SetCellFontColor(r, "RATE" + (i).toString(), "#EF0B0B");
						}
				    }
				}
			}
		} 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_Unitcd.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 doChangeOutItemCd1() {
		document.form1.item_depth.value = "2";
		document.form1.item_cd.value = document.form1.outItemTag1.value;
		submitXmlRequest("/bid/outside/BidHistoryList_process.screen", "GET_OUT_ITEM_CD2", document.form1, "VALUEOBJECT");
	}

	// 공종 두번째 SELECT BOX onChange 이벤트
	function doChangeOutItemCd2() {
		document.form1.item_depth.value = "3";
		document.form1.item_cd.value = document.form1.outItemTag2.value;
		submitXmlRequest("/bid/outside/BidHistoryList_process.screen", "GET_OUT_ITEM_CD3", document.form1, "VALUEOBJECT");
	}
	
	function doResult(resultObj) {
		var f = document.form1;
		
		try {
			if (resultObj.getRequestEvent() == "GET_OUT_ITEM_CD2") {
				if ( resultObj.getSuccess() == true ) {
					var vo = resultObj.getValueObject();
					injectSelect(vo, document.form1.outItemTag2,"item_name","item_cd");
					document.form1.isSubmit = false;
					if(f.outItemTag1.value == "") {
						while(document.form1.outItemTag2.options.length > 1) {
							document.form1.outItemTag2.remove(1);
						}
					}
					
					// 소분류 select box clear
					while(document.form1.outItemTag3.options.length > 1) {
						document.form1.outItemTag3.remove(1);
					}
				} else {
		            dlgErrorMsg(resultObj);
		        }
			}
			else if (resultObj.getRequestEvent() == "GET_OUT_ITEM_CD3") {
				if ( resultObj.getSuccess() == true ) {
					var vo = resultObj.getValueObject();
					injectSelect(vo, document.form1.outItemTag3,"item_name","item_cd");
					
					if(f.outItemTag2.value == "") {
						while(document.form1.outItemTag3.options.length > 1) {
							document.form1.outItemTag3.remove(1);
						}
					}
					
					document.form1.isSubmit = false;
				} else {
		            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="100px">
			<col width="35%">
			<col width="100px">
			<col/>
			<col width="200px">
		</colgroup>	
		<TR>
			<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:#,##0.00nter;" 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>		
			<th>공사구분</th>
			<td>
			    <%=CommCodeManager.getSelectCodeSearchList("BID_GB_CD","pay_div","height=18;width:80px;","<option value=''>--전체--</option>",params.get("pay_div"),"","DETAILCD") %>	
			</td>	
   			<TD class="button" rowspan="2">      
   				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
   				<span class="btnSearch center"><a href="javascript:void(0);" id="btnDept">현장등록</a></span>
			</TD>
		</TR>
  		<TR>
			<TH>업체명</TH>
			<TD colspan="1">
				<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>
				<%= HTMLMaker.getSelectTag(outItemTag1, "item_cd", "item_name", "outItemTag1", "style='width:30%;height=18;' onChange='javascript:doChangeOutItemCd1();'", "<option value=''>--전체--</option>", "") %>
				&nbsp;
				<%= HTMLMaker.getSelectTag(outItemTag2, "item_cd", "item_name" , "outItemTag2", "style='width:30%;height=18;' onChange='javascript:doChangeOutItemCd2();'", "<OPTION value=''>-- 전체 --</OPTION>", "") %>
				&nbsp;
				<%= HTMLMaker.getSelectTag(outItemTag3, "item_cd", "item_name" , "outItemTag3", "style='width:30%;height=18;'", "<OPTION value=''>-- 전체 --</OPTION>", "") %>
			</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>