<%--
  - FileName   : SuppStockList.jsp
  - Author     : gyeongmo an
  - Date       : 2014.07.31
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  - All rights reserved.
  - 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.*" %>
<%@ 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 fevent   	   = storage.getEvent();	
	
	RowSet stockGbRowSet = storage.getRowSet("stockGbRowSet");
	
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		gridInit(sheet1);
		var f = document.form1;
		
		jQuery("#btnSearch").click(function() {
			jQuery("#fevent").val("GET_DATA_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/supplier/portal/warehouse/SuppStockList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
		});
		
		jQuery("#btnExcel").click(function() {
			if(sheet1.RowCount() == 0) {
				alert("내역이 없습니다.");
				return;
			}
			var params = { FileName : "SuppStockList.xls",  SheetName : "협력업체 입고현황", SheetDesign:0, Merge:1, 
					DownCols:"dept_nm|pay_item|cst_doc_name|material_cd|material_name|material_spec|unit_kind_name|stock_date|stock_qty|remarks"
					, TitleText:"협력업체 입고 현황", UserMerge:"0,0,1,10", AutoSizeColumn:1  } ;
			sheet1.Down2Excel(params);
		});
		
		sheet1.SetActionMenu("ExcelDown");
		
		jQuery("#btnSearch").click();
		
		autoResize();	
	}
	
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10};
		init_sheet.Cols = [
		       			{Header:'현장',				Type:"Text",		SaveName:"dept_nm", 		Width:150, 	Align:"Left"},
		    			{Header:'거래처',			Type:"Text", 			SaveName:"vendor_name", 			Width:150, 	Align:"Left", Hidden:"True"},
		    			{Header:'Pay Item',				Type:"Text", 			SaveName:"pay_item",				Width:100, 	Align:"Center", Hidden:"True"},
		    			{Header:'Pay Desc',		Type:"Text", 			SaveName:"pay_item_desc", 		Width:100,	Align:"Center", Hidden:"True"},
		    			{Header:'계약명',			Type:"Text", 			SaveName:"cst_doc_name", 		Width:150, 	Align:"Left"},
		    			{Header:'자재코드',			Type:"Text", 			SaveName:"material_cd", 		Width:90, 	Align:"Center"},
		    			{Header:'자재명',		Type:"Text",	 		SaveName:"material_name", 		Width:120, 	Align:"Left"},
		    			{Header:'규격',		Type:"Text", 			SaveName:"material_spec", 		Width:50, 	Align:"Left"},
		    			{Header:'단위',			Type:"Text", 			SaveName:"unit_kind_name", 		Width:50, 	Align:"Center"},
		    			{Header:'일자',		Type:"Date", 			SaveName:"stock_date", 		Width:90, 	Align:"Center"},
		    			{Header:'수량',			Type:"AutoSum", 			SaveName:"stock_qty", 			Width:50, 	Align:"Right"},
		    			{Header:'비고',		Type:"Text", 			SaveName:"remarks", 	Width:150, 	Align:"Left"},
		    			{Header:'H_입고ID',		Type:"Text", 			SaveName:"stock_id", 	Width:100, 	Align:"Center", Hidden:"True"},
		    			{Header:'H_현장코드',		Type:"Text", 			SaveName:"dept_cd", 	Width:100, 	Align:"Center", Hidden:"True"},
		    			{Header:'H_거래처코드',		Type:"Text", 			SaveName:"vendor_cd", 	Width:100, 	Align:"Center", Hidden:"True"}
		];
	
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		
		var info = [{StdCol:"dept_nm", SumCols:"stock_qty", CaptionCol:"dept_nm"}];
    	sheet1.ShowSubSum(info);
    	
		setGridSize();
	}
	
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	
	    	//소계 머지
	    	var str = "";
	    	for(var i=1; i<sheet1.LastRow(); i++) {
	    		str = sheet1.GetCellText(i, "dept_nm");
	    		if(str.indexOf("소계:") > -1) {
	    			sheet1.SetCellAlign(i,0,"Center");
	    			sheet1.SetCellText(i, "dept_nm", "소   계 : ");
	    			sheet1.SetMergeCell(i,0,1,10);
	    		}
	    	}
	    	
	    	//합계 머지
	    	sheet1.SetCellText(sheet1.LastRow(), "dept_nm", "합     계");
			sheet1.SetMergeCell(sheet1.LastRow(), 0, 1, 10);
			sheet1.SetCellAlign(sheet1.LastRow(), 0, "Center");
			
	    	setGridSize();
		} else {
			//조회 에러 수행
			//alert(message);
			alert("조회 실패");
		}
	}
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	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("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		sheet1.SetSheetHeight(iframeHeight); 
	}
	
	function suppChoicePop(){
		var win_id = "corp";			
		var link = "/common/corp/SuppChoicePop.screen";
		fLayerPop(win_id, link, 800,400, '', '', 'NO');
	}
	
	$.test = function(resultVal)
	{
		var f=document.form1;
	 	f.corp_id.value = resultVal[0][0];
	 	f.corp_name.value = resultVal[2][0];
	};
	
	function doSearchMaterialCode() {
		var win_id = "_search_material_cd";
		var link = "/supplier/portal/common/lib/suppdlgSearchMaterialCd.screen";
		    link += "?pop_win_id="+win_id;
		fLayerPop(win_id, link, 800,400, '', '', 'NO');
	}
	
	function doSearchMaterialCodeClose(resultValue) {
		var f=document.form1;
		if(resultValue == null) {
			f.material_cd.value = "";
			f.material_nm.value = "";
		} else {
			f.material_cd.value = resultValue[0];
			f.material_nm.value = resultValue[1];
		}
		
		fLayerPopClose('_search_material_cd');
	}
	
	function sheet1_OnSelectMenu(Text, Code) {
		switch(Text) {
			case "ExcelDown":
				jQuery("#btnExcel").click();
			break;
		}
	}
	
	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" style="width:100%;height:100%;">
<INPUT type="hidden" name="fevent">

<div align="left" id="title">
    <ul>
     <li>협력업체 입고 현황</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="300" />
			<col width="100" />
			<col width="330" />
			<col width="100" />
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr>
			<th>현장</th>
			<td>
				<%= InputText.get("dept_name", params.get("dept_name"), 90, 50, "hangule, desc=현장명, PerSize") %>
			</td>
			<th>입고일자</th>
			<td>
				
				<%= InputText.get("sYmdSt", params.get("sYmdSt"), 10, 50, "hangule,center, desc=기간,ReadOnly") %>
				<IMG name="sYmdSt_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('sYmdSt');">
							~
				<%= InputText.get("sYmdEd", params.get("sYmdEd"), 10, 50, "hangule,center, desc=기간,ReadOnly") %>
				<IMG name="sYmdEd_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('sYmdEd');">
			</td>
			<th>입고유형</th>
			<td>
				<%= HTMLMaker.getSelectTag(stockGbRowSet, "DETAILCD", "DETAILNM", "stock_gb", "width:100px;height=18;", "") %>
			</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="btnExcel">엑셀</a></span>
			</td>
		</tr>
		<tr>
			<th>계약명</th>
			<td>
				<input type='text' id="cst_doc_name" name="cst_doc_name" class="input" style="width:90%" onkeypress="doKeyPress()">
			</td>
			<th>자재명</th>
			<td colspan="3">
				<%= InputText.get("material_cd", "","", 15, 255, "class=input byteChk, perSize", "onkeypress=\"doKeyPress();\" onClick=\"\"") %>
				<%= InputText.get("material_nm", "","", 37, 255, "class=input byteChk, perSize", "onkeypress=\"doKeyPress();\" onClick=\"\"") %>
				<IMG id='search_spot_button' onClick="doSearchMaterialCode();" src='/img/buyer/button/bt_search_right.gif' border='0' align='absmiddle' alt='[자재코드]' style='cursor:pointer;'>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	

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

