<%--
  - FileName   : PlanStockList.jsp
  - Author     : gyeongmo an
  - Date       : 2014.08.05
  - 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);

	jQuery("#btnSearch").click(function() {
		jQuery("#fevent").val("GET_DATA_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/warehouse/purchase/PlanStockList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	});

	jQuery("#btnExcel").click(function() {
		if(sheet1.RowCount() == 0) {
			alert("내역이 없습니다.");
			return;
		}
		var params = { FileName : "PlanStockList.xls",  SheetName : "계획대비입고조회", SheetDesign:0, Merge:1, DownCols:"dept_nm|material_cd|material_name|material_spec|unit_nm|"+
				"wkdate|plan_qty|stock_qty|contrast_plan_stoc", TitleText:"계획대비 입고조회", UserMerge:"0,0,1,9", AutoSizeColumn:1  } ;
		sheet1.Down2Excel(params);
	});
	
	$("#dataClear2").click(function(){$("#sYmdSt").val("");$("#sYmdEd").val("");});
	
	sheet1.SetActionMenu("ExcelDown");
	
	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:"material_cd", 			Width:50, 	Align:"Center"},
	    			{Header:'자재명',				Type:"Text", 			SaveName:"material_name",				Width:150, 	Align:"Left"},
	    			{Header:'규격',		Type:"Text", 			SaveName:"material_spec", 		Width:120,	Align:"Left"},
	    			{Header:'단위',			Type:"Text", 			SaveName:"unit_nm", 		Width:30, 	Align:"Center"},
	    			{Header:'일자',			Type:"Date", 			SaveName:"wkdate", 		Width:50, 	Align:"Center"},
	    			{Header:'계획수량',		Type:"AutoSum",	 		SaveName:"plan_qty", 		Width:50, 	Align:"Right", PointCount:2},
	    			{Header:'입고수량',		Type:"AutoSum", 			SaveName:"stock_qty", 		Width:50, 	Align:"Right", PointCount:2},
	    			{Header:'계획대비 미입고수량',			Type:"AutoSum", 			SaveName:"contrast_plan_stoc", 		Width:70, 	Align:"Right", PointCount:2},
	    			{Header:'H_현장코드',		Type:"Text", 			SaveName:"dept_cd", 		Width:0, 	Align:"Center",	Hidden:"True"}
	];

	init_sheet.HeaderMode = {Sort:1};
	IBS_InitSheet(sheetName, init_sheet);
	sheetName.SetDataAutoTrim(0);
	sheetName.SetEditable(false);
	sheetName.SetMergeSheet(msPrevColumnMerge);
	
	var info = [{StdCol:"dept_nm", SumCols:"plan_qty|stock_qty|contrast_plan_stoc", CaptionCol:"dept_nm"}];
	sheet1.ShowSubSum(info);
	
	setGridSize();
}

function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {
    	setGridSize();
   		for(var i=1; i <= sheet1.LastRow(); i++){
   			if(sheet1.GetCellValue(i , "contrast_plan_stoc") <  0){
   				sheet1.SetCellFontColor(i, "contrast_plan_stoc", "#ff0000");
   			}
   		}
   	    
   		//소계 머지
    	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,6);
    		}
    	}
    	
    	//합계 머지
    	sheet1.SetCellText(sheet1.LastRow(), "dept_nm", "합     계");
		sheet1.SetMergeCell(sheet1.LastRow(), 0, 1, 6);
		sheet1.SetCellAlign(sheet1.LastRow(), 0, "Center");
		
    	setGridSize();
	} else {
		alert(message);
	}
}

function setGridSize() {
	sheet1.FitColWidth();
}

	function doKeyPress() {
	    if( event.keyCode == 13 ) {
	    	jQuery("#btnSearch").click();
	    }
	}
	
	function doSearchMaterialCode() {
		var win_id = "_search_material_cd";
		var link = "/lib/dlgSearchMaterialCd.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;
		}
	}
	
	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); 
	}
	
	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="80" />
			<col width="330" />
			<col width="80" />
			<col width="330" />
			<col width="80" />
			<col width="*" />
			<col width="130" />
		</colgroup>
		<tr>
			<th>현장</th>
			<td>
				<%=InputText.getSiteCodeNew("dept_cd", "dept_name", "", user, params.get("dept_cd"), params.get("dept_name"))%>
			</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');">
				<IMG name="dataClear2" id="dataClear2" src="/img/buyer/button/bt_eraser1.gif" border="0" align="absmiddle" style="cursor:pointer;">
			</td>
			<th>자재명</th>
			<td>
				<%= InputText.get("material_cd", "","", 15, 255, "class=input byteChk, perSize", "onkeypress=\"doKeyPress();\" onClick=\"\"") %>
				<%= InputText.get("material_nm", "","", 65, 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>
			<td class="button">
				<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>
	</table>
	<!-- 검색조건 종료 -->
<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 400px; overflow: auto;">
	<script>createIBSheet('sheet1','100%', '400px');</script>
</div>

</FORM>
