<%--
  - FileName   : StockSchedulePurchaseList.jsp
  - Author     : gyeongmo an
  - Date       : 2014.07.15
  - 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="com.udapsoft.waf.common.util.*" %>
<%@ page import="kr.co.udapsoft.common.util.*" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import ="java.text.SimpleDateFormat" %>
<%@ page import="com.udapsoft.waf.common.util.DateUtil" %>
<%@ page import ="java.util.Date" %>
<%@ 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 user = ctx.getUser();
	ValueObject params = storage.getParams();
%>

<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_SCHEDULE_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/warehouse/purchase/StockSchedulePurchaseList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
		});
		
		jQuery("#btnCancel").click(function() {
	    	if (!sheet1.IsDataModified()){
				alert("취소할 내역이 없습니다.");
	    		return;
			}
		
	    	jQuery("#fevent").val("SAVE_SCHEDULE_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/warehouse/purchase/StockSchedulePurchaseList_form.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
		});

		jQuery("#btnExcel").click(function() {
			if(sheet1.RowCount() == 0) {
				alert("내역이 없습니다.");
				return;
			}
			var params = { FileName : "StockSchedulePurchaseList.xls",  SheetName : "StockSchedulePurchaseList", SheetDesign:0, Merge:1, DownCols:"scheduleno|dept_nm|ord_doc_no|cst_doc_name|corp_nm|"+
					"material_cd|material_name|matl_spec|unit_kind|scheduledate|schedule_qty|item_qty|temp_qty|rmnr_qty|confirm_yn", TitleText:"입고계획관리", UserMerge:"0,0,1,15", AutoSizeColumn:1  } ;
			sheet1.Down2Excel(params);
		});
		
		
		$("#dataClear2").click(function(){$("#p_schedule_date").val("");});
		
		sheet1.SetActionMenu("ExcelDown");
		
		autoResize();
		
		jQuery("#btnSearch").click();
	}
	
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10};
		init_sheet.Cols = [
		    			{Header:'상태',			Type:"Status", 			SaveName:"status", 			Width:0, 	Align:"Center",	Hidden:"True"},
		    			{Header:'계획번호2',				Type:"Text", 			SaveName:"scheduleno2",				Width:110, 	Align:"Center", Edit:"false", Hidden:"True"},
		       			{Header:'선택',				Type:"CheckBox",		SaveName:"check", 		Width:60, 	Align:"Center"},
		    			{Header:'계획번호',				Type:"Text", 			SaveName:"scheduleno",				Width:110, 	Align:"Center", Edit:"false"},
		    			{Header:'현장',		Type:"Text", 			SaveName:"dept_nm", 		Width:150,	Align:"Left", Edit:"false"},
		    			{Header:'계약번호',			Type:"Text", 			SaveName:"ord_doc_no", 		Width:150, 	Align:"Left", Edit:"false"},
		    			{Header:'계약명',			Type:"Text", 			SaveName:"cst_doc_name", 		Width:200, 	Align:"Left", Edit:"false"},
		    			{Header:'업체명',		Type:"Text",	 		SaveName:"corp_nm", 		Width:150, 	Align:"Left", Edit:"false"},
		    			{Header:'자재코드',		Type:"Text", 			SaveName:"material_cd", 		Width:80, 	Align:"Center", Edit:"false"},
		    			{Header:'자재명',			Type:"Text", 			SaveName:"material_name", 		Width:150, 	Align:"Left", Edit:"false"},
		    			{Header:'규격',		Type:"Text", 			SaveName:"matl_spec", 		Width:150, 	Align:"Left", Edit:"false"},
		    			{Header:'단위',			Type:"Text", 			SaveName:"unit_kind", 			Width:50, 	Align:"Center", Edit:"false"},
		    			{Header:'입고예정일',		Type:"Date", 			SaveName:"scheduledate", 	Width:80, 	Align:"Center", Edit:"false"},
		    			{Header:'입고계획량',			Type:"Float", 			SaveName:"schedule_qty", 			Width:80, 	Align:"Right", Edit:"false", PointCount:2},
		    			{Header:'계약수량',		Type:"Float", 			SaveName:"item_qty", 		Width:80, 	Align:"Right", Edit:"false", PointCount:2},
		    			{Header:'기입고량',			Type:"Float", 			SaveName:"temp_qty", 		Width:80, 	Align:"Right", Edit:"false", PointCount:2},
		    			{Header:'잔량',			Type:"Float", 			SaveName:"rmnr_qty", 		Width:80, 	Align:"Right", Edit:"false", PointCount:2},
		    			{Header:'완료여부',			Type:"Text", 			SaveName:"confirm_yn", 		Width:50, 	Align:"Center", Edit:"false"}
		];
	
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetMergeSheet(msPrevColumnMerge);
		
		//setGridSize();
	}
	
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
		} else {
			alert(message);
		}
	}

	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	function sheet1_OnBeforeCheck(Row, Col) { 
		var scheduleNo = sheet1.GetCellValue(Row, "scheduleno");
		var checkValue = 0;
		
		if(sheet1.GetCellValue(Row, "check") == 0){
			checkValue = 1;
		}else{
			checkValue = 0;
		}
		
		for(var i = 1; i <= sheet1.LastRow(); i++){
			if (i != Row){
				if(scheduleNo == sheet1.GetCellValue(i, "scheduleno")){
					sheet1.SetCellValue(i, "check", checkValue);
				}
			}
		}		
	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		//sheet1.FitColWidth();
		autoResize();
	}

	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 30;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		sheet1.SetSheetHeight(iframeHeight); 
	}
	
	function sheet1_OnSaveEnd(code, msg) {
	    /* 
		if(code >= 0) {
	    	alert("취소 성공");
			document.form1.isSubmit = false;
			jQuery("#btnSearch").click();
	    } else {
	    	alert("취소 실패");
	    	//alert(msg);
        }
	     */
	    if(code == -1) {
	    	alert("취소 성공");
			document.form1.isSubmit = false;
			jQuery("#btnSearch").click();
	    } else {
	    	alert(msg);
        }
	}		
	
	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="350" />
			<col width="100" />
			<col width="150" />
			<col width="100" />
			<col width="*" />
			<col width="250" />
		</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("p_schedule_date", DateUtil.formatDateTime(DateUtil.getToday(), "yyyyMMdd", "yyyy-MM"), 10, 50, "hangule,center, desc=입고년월,ReadOnly") %>
				<IMG name="p_schedule_date_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('p_schedule_date');">
				<IMG name="dataClear2" id="dataClear2" src="/img/buyer/button/bt_eraser1.gif" border="0" align="absmiddle" style="cursor:pointer;">
			</td>
			<th>완료여부</th>
			<td>
				<SELECT id='p_confirm_yn' name='p_confirm_yn' style='width:100px;height=18;'><OPTION value=''>-- 전체 --</OPTION><OPTION value='Y'>완료<OPTION value='N'>미완료</SELECT>
			</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="btnCancel">취소</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>