<%--
  - FileName   : ContPriceSearch.jsp
  - Author(s)  : lee mi kyoung
  - Date       : 2016.6.24
  -
  - 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 = "blowfishj.*"%>   
<%@ page import = "java.text.SimpleDateFormat"%>    
<%@ page import="com.udapsoft.waf.common.util.DateUtil"%>                                                                                                                                                                                                         
<%@ page import = "java.util.Date"%>                                                                                                                                                                                                                         
<%@ page import = "java.util.*"%>  
<%@ 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();
	
	
	
	//검색조건 작성일
	String  initSearchDateStart = params.get("p_from_dt");
    String  initSearchDateEnd = params.get("p_to_dt");

	ValueObject defaultDate = DateUtil.getDefaultPeriod();
	if("".equals(initSearchDateStart)){
		initSearchDateStart = defaultDate.get("START_DATE");
	}
	if("".equals(initSearchDateEnd)){
		initSearchDateEnd = defaultDate.get("END_DATE");
	}
   
%>



<script type="text/javascript" src="/js/creditEvaluationPop.js"></script>
<script language="javascript">
	/*예약함수*/
	var sheet1 = new ibsheetObject();
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	
	$(document).on("keyup", "input:text", function(e) {
	    if($(this).attr("numberOnly") == "true")
        {
	        $(this).val( $(this).val().replace(/[^0-9]/gi,"") );
        }
	    
	    if (e.keyCode == 13)
        {
	        $.searchList();
        }
	    
	});
	
	
	$.gridInit = function(sheetName)
	{
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, MergeSheet:msHeaderOnly, Page:100};
		init_sheet.Cols = [
		       			{Header:'Del',					Type:"DelCheck",		SaveName:"DEL_CHECK", 				Width:50, 		Align:"Center",		Hidden:"True"},
		    			{Header:'Status',				Type:"Status", 			SaveName:"STATUS", 					Width:0, 		Align:"Center", 	Edit:"false", Hidden:"True"},
		    			{Header:'자재코드',				Type:"Text", 			SaveName:"MATERIAL_CD", 			Width:80, 		Align:"Left", 	    Edit:"false"},
		    			{Header:'자재명',					Type:"Text", 			SaveName:"ITEM_NAME", 				Width:150, 		Align:"Left", 		Edit:"false"},
		    			{Header:'규격',					Type:"Text", 			SaveName:"ITEM_SPEC",				Width:80, 		Align:"Left", 		Edit:"false"},
		    			{Header:'단위',					Type:"Text", 			SaveName:"ITEM_UNIT",				Width:80, 		Align:"Left", 		Edit:"false",Hidden:"True"},
		    			{Header:'계약명',					Type:"Text", 			SaveName:"CST_DOC_NAME", 			Width:200,		Align:"Left", 		Edit:"false"},
		    			{Header:'통화',					Type:"Text", 			SaveName:"CURRENCY_GB", 			Width:40, 		Align:"Center", 	Edit:"false"},
		    			{Header:'단가',					Type:"Text", 			SaveName:"ITEM_PRICE", 			    Width:80, 		Align:"Right", 	    Edit:"false"},
		    			{Header:'단가(KRW)',				Type:"Text", 			SaveName:"ITEM_PRICE_KRW", 			Width:80, 		Align:"Right", 		Edit:"false"},
		    			{Header:'업체명',					Type:"Text", 			SaveName:"MEMBER_NAME", 			Width:150, 		Align:"Left", 		Edit:"false"},
		    			{Header:'현장',					Type:"Text", 			SaveName:"DEPT_NAME", 				Width:150, 		Align:"Left",		Edit:"false"},
		    			{Header:'계약일',			        Type:"Text", 			SaveName:"ORD_CON_DATE", 			Width:70, 		Align:"Center", 	Edit:"false"},
		    			{Header:'계약번호',				Type:"Text", 			SaveName:"ORD_DOC_NO", 				Width:100, 		Align:"Center", 	Edit:"false",Hidden:"True"},
		    			{Header:'변경차수',			    Type:"Text", 			SaveName:"MOD_NO", 			        Width:70, 		Align:"Center", 	Edit:"false"},
		    			{Header:'PUR_CONT_ID',		    Type:"Text", 			SaveName:"PUR_CONT_ID",  	        Width:150, 		Align:"Center", 	Edit:"false",Hidden:"True"},
		    			{Header:'PUR_CONT_MOD_ID',		Type:"Text", 			SaveName:"PUR_CONT_MOD_ID",  		Width:150, 		Align:"Center", 	Edit:"false",Hidden:"True"}
		    			
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetActionMenu("ExcelDown");
		setGridSize();
	}
	
	
	$(function(){
		
		$("#btn_search").click(function(){
		    $.searchList();
		});
		
		$("#btn_excel").click(function(){
	        var params = {FileName:"계약단가현황.xls",SheetName:"계약단가현황",Merge:1,SheetDesign:1, HiddenColumn:1};
	        sheet1.Down2Excel (params);
	    });
		
		$.searchList = function()
		{
			$("#fevent").val("SHEET_SELECT");
			
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/cont/purchase/ContPriceSearch_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, $("#form1"), 30, "");
		}
		
		$("#material_Kind_Code_Lv1").change(function(){
		    
		    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");
			    
			    $("#materiallevel").val("2");
			    $("#materialgroup").val($("#material_Kind_Code_Lv1").val());
			    
			    $("#material_Kind_Code_Lv3").empty().data("options"); 
			    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
			    submitXmlRequest("/cont/purchase/ContPriceSearch_form.screen", "GET_MATL_KIND_CODE_LV2", f, "ROWSET");
			  }
		});
		
		$("#material_Kind_Code_Lv2").change(function(){
		    
		    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("/cont/purchase/ContPriceSearch_form.screen", "GET_MATL_KIND_CODE_LV3", f, "ROWSET");
		    }    
		});
		
		
		$("#material_Kind_Code_Lv3").change(function(){
		    $.searchList();
		}); 
		
	});
	
	
	
	
	$(document).ready(function(){
		
	    $.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();
	    }
		else
	    {
		    //$.searchList();
	    }
		
	});
	 
	function calendar(thisDayObj){
		dlgCalendar(thisDayObj);
	}
	
	function setGridSize() {sheet1.FitColWidth();}
	
	function sheet1_OnSelectMenu(Text, Code) {
		  // text 또는 code값으로 Action수행
		switch(Text) {
	         case "ExcelDown":
	        	 excelDown();
	            break; 
		}
	}	
	function excelDown() {
		if(sheet1.RowCount() == 0) {
			alert("내역이 없습니다.");
			return;
		}
		var params = { FileName : "ContPriceSearch.xls",  SheetName : "ContPriceSearch", SheetDesign:0, Merge:1, DownCols:"MATERIAL_CD|ITEM_NAME|ITEM_SPEC|ITEM_UNIT|CST_DOC_NAME|CURRENCY_GB|ITEM_PRICE"+
				"|ITEM_PRICE_KRW|MEMBER_NAME|DEPT_NAME|ORD_CON_DATE|ORD_DOC_NO|MOD_NO|PUR_CONT_ID|PUR_CONT_MOD_ID", TitleText:"구매단가조회", UserMerge:"0,0,1,15", AutoSizeColumn:1  } ;
		sheet1.Down2Excel(params);
	}
	
	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	
	
	function doResult(resultObj) {
		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();
			        }
				    
				    //$.searchList();
					
				} 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");
			        }
				    
				    //$.searchList();
				}
				else if(resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV3")
				{
                    dlgErrorMsg(resultObj);
                }
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	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">
<input type="hidden" name="fevent" id="fevent" value="">
<input type="hidden" name="materialgroup" id="materialgroup" value=""/>
 
<div align="left" id="title">
	<ul>
    	<li>계약단가조회</li> 
   	</ul>
</div> 
<!-- 검색조건 시작 -->
<table id="search-table" class="search-form-table">
	<colgroup>
		<col width="100" />
		<col width="480" />
		<col width="100" />
		<col width="*" />
		<col width="100" />
	</colgroup>
  <tr height="25"> 
  	<th>현장</th>
   	<td>
  		<%=InputText.getSiteCodeNew("p_dept_cd", "p_dept_nm", "", user, params.get("p_dept_cd"), params.get("p_dept_nm"))%>
	</td>
  	<th>계약명</th>
   	<td>
   		<INPUT type="text" name="p_cst_doc_name" class="input" value="<%= params.get("p_cst_doc_name") %>" style="width:90%"> 
	</td>
	<td class="button" rowspan="3">
		<span class="btnSearch center" id="btn_search"><a href="javascript:void(0);">검색</a></span>
		<span class="btnSearch center"><a href="javascript:void(0);" id="btn_excel">엑셀</a></span>
	</td>	
  </tr>
  <tr>
	<th>계약일</th>
    <td> 
		<%= InputText.get("p_from_dt", initSearchDateStart, 15, 50, "Center, date, PerSize, readonly", "date", "") %>
		<a href="JavaScript:calendar('p_from_dt');"><img src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>
		&nbsp;~&nbsp;
		<%= InputText.get("p_to_dt", initSearchDateEnd, 15, 50, "Center, date, PerSize, readonly", "date", "") %>
		<a href="JavaScript:calendar('p_to_dt');"><img src="/img/buyer/button/bt_calender.gif" alt="달력" border="0" align="absmiddle" /></a>
    </td>
    <th>업체명</th>
    <td> 
		<INPUT type="text" name="p_member_name" class="input" value="<%= params.get("p_member_name") %>" style="width:90%">
    </td>
  </tr>
  <tr>
	<th>자재분류</th>
    <td> 
        <%= HTMLMaker.getSelectTag(materialKindCodeLv1, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv1", "style='width:28%;height=18;'", "<OPTION value=''>-- 전체 --</OPTION>", params.get("material_Kind_Code_Lv1"), 0) %>
		<%= HTMLMaker.getSelectTag(materialKindCodeLv2, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv2", "style='width:28%;height=18;'", "<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>
    <th>자재명/규격</th>
    <td> 
        <INPUT type="text" name="p_item_name" class="input" value="<%= params.get("p_item_name") %>" style="width:65%">
		<INPUT type="text" name="p_item_spec" class="input" value="<%= params.get("p_item_spec") %>" style="width:25%">
    </td>
  </tr>
</table>
</form>

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