  <%--
  - FileName   : ContractClose.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="com.udapsoft.waf.common.ui.InitCombo" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="kr.co.udapsoft.common.code.CommCodeManager" %>
<%@ 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 event   		   = storage.getEvent();	
	
	//공통코드
	CommCodeManager commCodeManager = new CommCodeManager();
	InitCombo initCombo = new InitCombo();

	initCombo.makeComboData(commCodeManager.getCodeRowSet("PUR_CONT_STATUS"), "CODE", "NAME");
	String statusSheetComboListText = initCombo.getCode();
	String statusSheetComboListValue = initCombo.getCodeName();
%>
<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/ContractClose_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	});
	
	jQuery("#btnSave").click(function() {
		if(!sheet1.IsDataModified()) {
			alert("수정된 내역이 없습니다.");
			return;
		} else {
			jQuery("#fevent").val("UPDATE_DATA");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/warehouse/purchase/ContractClose_sheet.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 : "ContractClose.xls",  SheetName : "ContractClose", SheetDesign:0, Merge:1, 
				DownCols:"dept_name|ord_doc_no|cst_doc_name|ord_con_date|item_qty|item_price|item_amt|stock_qty|stock_pri|stock_amt|ent_cls_status|pur_cont_close_remark"
				, TitleText:"계약 물량 관리", UserMerge:"0,0,1,12", AutoSizeColumn:1  } ;
		sheet1.Down2Excel(params);
	});
	
	$("#dataClear2").click(function(){$("#sYmdSt").val("");$("#sYmdEd").val("");});
	
	sheet1.SetActionMenu("ExcelDown");

	jQuery("#btnSearch").click();
	
	autoResize();
}

function gridInit(sheetName){
	var init_sheet = {};
	init_sheet.Cfg = {SearchMode:2, Page:10, MergeSheet:msPrevColumnMerge + msHeaderOnly};
	init_sheet.Cols = [
	       			{Header:'상태|상태',				Type:"Status",		SaveName:"status", 		Width:0, 	Align:"Center",	Hidden:"True"},
	    			{Header:'현장|현장',			Type:"Text", 			SaveName:"dept_name", 			Width:100, 	Align:"Left", Edit:"false"},
	    			{Header:'계약번호|계약번호',			Type:"Text", 			SaveName:"ord_doc_no", 			Width:100, 	Align:"Left", Edit:"false"},
	    			{Header:'계약명|계약명',				Type:"Text", 			SaveName:"cst_doc_name",				Width:250, 	Align:"Left", Edit:"false"},
	    			{Header:'계약일자|계약일자',		Type:"Date", 			SaveName:"ord_con_date", 		Width:70,	Align:"Center", Edit:"false"},
	    			{Header:'계약|수량',			Type:"Float", 			SaveName:"item_qty", 		Width:70, 	Align:"Right", Edit:"false", Format:"Float", EditLen:14, PointCount:2},
	    			{Header:'계약|단가',			Type:"Int", 			SaveName:"item_price", 		Width:70, 	Align:"Right", Edit:"false", EditLen:14, PointCount:2},
	    			{Header:'계약|금액',		Type:"Int",	 		SaveName:"item_amt", 		Width:70, 	Align:"Right", Edit:"false", EditLen:14, PointCount:2},
	    			{Header:'납품|수량',		Type:"Float", 			SaveName:"stock_qty", 		Width:70, 	Align:"Right", Edit:"false", Format:"Float", EditLen:14, PointCount:2},
	    			{Header:'납품|단가',			Type:"Int", 			SaveName:"stock_pri", 		Width:70, 	Align:"Right", Edit:"false", EditLen:14, PointCount:2},
	    			{Header:'납품|금액',		Type:"Int", 			SaveName:"stock_amt", 		Width:70, 	Align:"Right", Edit:"false", EditLen:14, PointCount:2},
	    			{Header:'진행상태|진행상태',			Type:"Combo", 			SaveName:"ent_cls_status", 			Width:70, 	Align:"Center", ComboText:"<%=statusSheetComboListText%>", ComboCode:"<%=statusSheetComboListValue%>"},
	    			{Header:'강제종결사유|강제종결사유',		Type:"Text", 			SaveName:"pur_cont_close_remark", 	Width:60, 	Align:"Left", EditLen:100},
	    			{Header:'H_발주계약ID|H_발주계약ID',			Type:"Text", 			SaveName:"pur_cont_id", 			Width:0, 	Align:"Center",	Hidden:"True"}
	    		];

	init_sheet.HeaderMode = {Sort:1};
	IBS_InitSheet(sheetName, init_sheet);
	sheetName.SetDataAutoTrim(0);
	//sheetName.SetEditable(false);
	
	setGridSize();
}

function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {
    	setGridSize();
	} else {
		alert(message);
	}
}

function sheet1_OnSaveEnd(code, msg) {
    if(code >= 0) {
    	alert("저장했습니다.");
    } else {
    	alert(msg);
    }
    	jQuery("#btnSearch").click();
}


/**
 *	IBSheet size setting
 */
function setGridSize() {
	sheet1.FitColWidth();
}

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" id="fevent" 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="350" />
			<col width="100" />
			<col width="350" />
			<col width="100" />
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr>
			<th>현장</th>
			<td>
		   		<%=InputText.getSiteCodeNew("dept_cd", "dept_nm", "", user, params.get("dept_cd"), params.get("dept_nm"))%>
			</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>
				<%= CommCodeManager.getSelectCodeList("PUR_CONT_STATUS", "s_pur_cont_status", "width:90px;height=18px;", "<OPTION value=''>-- 전체 --</OPTION>", params.get("pur_cont_status"), "") %>
			</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="btnSave">저장</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>
