<%--
  - FileName   : PartialMaterialSearchPopup.jsp
  - Author(s)  : gyeongmo an
  - Date       : 2014.08.13
  - Description: 부분 자재 조회
  --%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="kr.co.hsnc.common.sql.RowSet" %>
<%@ page import="kr.co.hsnc.common.util.ValueObject" %>
<%@ page import="com.udapsoft.waf.system.*" %>
<%@ page import="com.udapsoft.waf.common.*" %>
<%@ page import="kr.co.udapsoft.common.*" %>
<%@ page import="com.udapsoft.waf.common.ui.HTMLMaker" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.util.DateUtil" %>

<%@ 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();
    String user_id = user.get("ACCT_ID");
    String userName = user.get("user_name");

    ValueObject params     = storage.getParams();
    String fevent           = storage.getEvent();
    
    //String updDate = DateUtil.formatDateTime(DateUtil.getToday(), "yyyyMMdd", "yyyyMMdd");
    String updDate = DateUtil.getToday();
%>

<SCRIPT language="JavaScript">
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

    function _onReady(){
		gridInit(sheet1);

		jQuery("#btnAdd").click(function() {
			var rowIndex = sheet1.DataInsert(-1);
			sheet1.SetCellValue(rowIndex, "upd_by", '<%=userName%>');
			sheet1.SetCellValue(rowIndex, "upd_date", '<%=updDate%>');
			sheet1.SetCellValue(rowIndex, "shipping_detail_id", '<%=params.get("shipping_detail_id")%>');
			sheet1.SetCellValue(rowIndex, "shipping_id", '<%=params.get("shipping_id")%>');
			sheet1.SetCellValue(rowIndex, "material_cd", '<%=params.get("material_cd")%>');
			sheet1.SetCellValue(rowIndex, "ship_no", '<%=params.get("ship_no")%>');
		});
		
		jQuery("#btnSave").click(function() {
			jQuery("#fevent").val("SAVE_PARTIAL_MATERIAL_SHEET");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/PartialMaterialSearch_sheet.screen";
			var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
		});
		
		jQuery("#btnClose").click(function() {
			setTimeout(function(){parent.PartialMaterialSearch(null);},100);
		});
		
		search();
	}
    
    function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		init_sheet.Cols = [
			       			{Header:'status',	Type:"Status",	SaveName:"status",		Width:0, 	Align:"Center", Hidden:"True"},
			       			{Header:'Del',	Type:"DelCheck",	SaveName:"del_check",		Width:50, 	Align:"Center"},
			       			{Header:'No',	Type:"Seq",	SaveName:"",		Width:50, 	Align:"Center", Edit:"false"},
			    			{Header:'Update User',	Type:"Text",	SaveName:"upd_by",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			    			{Header:'Update Date',	Type:"Date",	SaveName:"upd_date",		Width:100, 	Align:"Center", Edit:"false"},
			    			{Header:'SRN No',	Type:"Text",	SaveName:"ship_no",		Width:100, 	Align:"Center", Edit:"false"},
			    			{Header:'Partial Name',	Type:"Text",	SaveName:"partial_name",		Width:200, 	Align:"Left"},
			    			{Header:'Partial Qty',	Type:"Float",	SaveName:"partial_qty",		Width:150, 	Align:"Right"},
			    			{Header:'Remarks',	Type:"Text",	SaveName:"partial_text",		Width:280, 	Align:"Left"},
			       			{Header:'partial_no',	Type:"Text",	SaveName:"partial_line",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'shipping_id',	Type:"Text",	SaveName:"shipping_id",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'material_cd',	Type:"Text",	SaveName:"material_cd",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'shipping_detail_id',	Type:"Text",	SaveName:"shipping_detail_id",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'s_status',	Type:"Text",	SaveName:"s_status",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"}
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		setGridSize();
	}
 
 	function setGridSize() {
		sheet1.FitColWidth();
	}
 

    function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	for(var i=0; i<sheet1.LastRow(); i++) {
				if(sheet1.GetCellValue(i+1, "s_status") == "9") {
					sheet1.SetRowEditable(i+1, false);
				}
			}
	    	
	    	setGridSize();
		} else {
			//조회 에러 수행
			alert("조회실패");
		}
	}
    
    function search() {
    	jQuery("#fevent").val("GET_PARTIAL_MATERIAL");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/PartialMaterialSearch_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
    }
    
    function sheet1_OnSaveEnd(code, msg) {
        if(code >= 0) {
        	alert("저장 성공");
        } else {
        	alert("저장실패");
        }
        search();
    }

    
</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="">
<INPUT type="hidden" name="shipping_detail_id" value=<%=params.get("shipping_detail_id")%>>
<INPUT type="hidden" name="shipping_id" value=<%=params.get("shipping_id") %>>
<INPUT type="hidden" name="material_cd" value=<%=params.get("material_cd") %>>
<INPUT type="hidden" name="pur_cont_id" value=<%=params.get("pur_cont_id") %>>
<INPUT type="hidden" name="status" value=<%=params.get("status") %>>
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="150" />
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr>
			<th>Material Name</th>
			<td>
				<%= InputText.get("material_name", params.get("material_name"), 80, 50, "hangule, PerSize, readOnly") %>
			</td>
			<td class="button">
				<%
					if(!params.get("status").equals("9")) {
				%>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnAdd">Add</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSave">Save</a></span>
				
				<%
					}
				%>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnClose">Close</a></span>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 360px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '360px');</script>
	</div>
	
</FORM>



