  <%--
  - FileName   : InspectionList.jsp
  - Author     : gyeongmo an
  - Date       : 2014.08.29
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  - All rights reserved.
  - Description: Inspection
--%>
  
<%@ 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.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.udapsoft.common.code.CommCodeManager" %>

<%@ 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();
%>

<SCRIPT language="JavaScript">
/*예약함수*/
var sheet1;
var sheet1Row;
var sheet1PageNo = 1;
var sheet2;
var sheet2Row;
var sheet2PageNo = 1;
var pageLastRowIndex = 1;
var validationResult = false;
var filterShow = false;

function _onReady(){
	gridInit(sheet1);
	gridInit(sheet2);

	var f= document.form1;
	
	jQuery("#btnSearch").click(function() {
		if($('input[name="date_all"]').is(":checked") == true){
			 f.date_all_value.value = "Y";
		 } else {
			 f.date_all_value.value = "N";
		 }
		
		
		jQuery("#fevent").val("GET_INSPECTION_LIST1");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/InspectionList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
	});
	
	jQuery("#btnExcel").click(function(){
		var params = { FileName : "사용자관리.xls",  SheetName : "사용자관리", SheetDesign:1} ;
		sheet1.Down2Excel(params);
	});
	
	$("#dataClear2").click(function(){$("#sYmdSt").val("");$("#sYmdEd").val("");});
	
	autoResize();
	
	jQuery("#btnSearch").click();
}

function gridInit(sheetName){
	var init_sheet = {};
	init_sheet.Cfg = {SearchMode:2, Page:10, MergeSheet:msPrevColumnMerge + msHeaderOnly};
	
	if(sheetName.id == "sheet1") {
		init_sheet.Cols = [
			       			{Header:'status',	Type:"Status",	SaveName:"status",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'Discipline|Discipline',	Type:"Text",	SaveName:"discipline_nm",		Width:90, 	Align:"Center", Edit:"false"},
			    			{Header:'MR Number|MR Number',	Type:"Text",	SaveName:"mr_no",		Width:100, 	Align:"Center", Edit:"false"},
			    			{Header:'PO Number|PO Number',	Type:"Text",	SaveName:"ord_doc_no",		Width:200, 	Align:"Left", Edit:"false"},
			       			{Header:'PO Title|PO Title',	Type:"Text",	SaveName:"cst_doc_name",		Width:230, 	Align:"Left", Edit:"false"},
			       			{Header:'Vendor|Vendor',	Type:"Text",	SaveName:"corp_name",		Width:200, 	Align:"Left", Edit:"false"},
			       			{Header:'Inspection|Plan',	Type:"Date",	SaveName:"plan_dt",		Width:100, 	Align:"Center", Edit:"false"},
			       			{Header:'Inspection|Forecasting',	Type:"Date",	SaveName:"forecasting_dt",		Width:120, 	Align:"Center", Edit:"false"},
			       			{Header:'IRN|IRN',	Type:"Date",	SaveName:"irn_date",		Width:100, 	Align:"Center", Edit:"false"},
			       			{Header:'Final|Final',	Type:"Text",	SaveName:"final_flag",		Width:60, 	Align:"Center", Edit:"false"},
			       			{Header:'confirm|confirm',	Type:"Text",	SaveName:"inspection_end_flag",		Width:60, 	Align:"Center", Edit:"false"},
			       			{Header:'New|New',	Type:"Image",	SaveName:"add",		Width:50, 	Align:"Center"},
			       			{Header:'psr_id',	Type:"Text",	SaveName:"psr_id",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'corp_id',	Type:"Text",	SaveName:"corp_id",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'pur_cont_id',	Type:"Text",	SaveName:"pur_cont_id",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'demanded_id',	Type:"Text",	SaveName:"demanded_id",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'dept_cd',	Type:"Text",	SaveName:"dept_cd",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"}
		];
	} else {
		init_sheet.Cols = [
			       			{Header:'status',	Type:"Status",	SaveName:"status",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			       			{Header:'Date|Date',	Type:"Date",	SaveName:"inspection_date",		Width:50, 	Align:"Center", Edit:"false"},
			    			{Header:'Final|Final',	Type:"Text",	SaveName:"final_flag",		Width:30, 	Align:"Center", Edit:"false"},
			    			{Header:'Confirm|Confirm',	Type:"Text",	SaveName:"inspection_end_flag",		Width:30, 	Align:"Center", Edit:"false"},
			    			{Header:'Attatch|Attatch',	Type:"Image",	SaveName:"add",		Width:20, 	Align:"Center"},
			    			{Header:'inspection_no',	Type:"Text",	SaveName:"inspection_no",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"},
			    			{Header:'Remarks',	Type:"Text",	SaveName:"remarks",		Width:100, 	Align:"Center", Edit:"false", Hidden:"True"}
		];
	}

	init_sheet.HeaderMode = {Sort:1};
	IBS_InitSheet(sheetName, init_sheet);
	sheetName.SetDataAutoTrim(0);
	//setGridSize(sheetName);
	sheetName.SetImageList(0,"/img/buyer/btn/btn_write.gif");	
	sheetName.SetImageList(1,"/img/buyer/btn/bt_search_right.gif");	
}

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


function sheet1_OnSearchEnd(code, message) {
    if(code == 0) {
    	//setGridSize(sheet1);
	} else {
		//조회 에러 수행
		alert("조회실패1");
	}
    
    
    for(var i=sheet1.LastRow(); i>=1; i--) {
    	sheet1.SetCellValue(i, "add", 0);
    }
    
}
function sheet2_OnSearchEnd(code, message) {
    if(code == 0) {
    	//setGridSize(sheet2);
	} else {
		//조회 에러 수행
		alert("조회실패2");
	}
    
    for(var i=sheet2.LastRow(); i>=1; i--) {
    	sheet2.SetCellValue(i, "add", 1);
    }
}

function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) { 
	if(sheet1.ColSaveName(0, Col) == "add" && Row != 0) {
		var f= document.form1;

		jQuery("#fevent").val("REG_INSPECTION_DETAIL");
		 jQuery("#psr_id").val(sheet1.GetCellValue(Row, "psr_id"));
		 jQuery("#psr_activity_cd").val(sheet2.GetCellValue(1, "psr_activity_cd"));
		 jQuery("#corp_id").val(sheet1.GetCellValue(Row, "corp_id"));
		 jQuery("#corp_name").val(sheet1.GetCellValue(Row, "corp_name"));
		 jQuery("#mr_no").val(sheet1.GetCellValue(Row, "mr_no"));
		 jQuery("#po_no").val(sheet1.GetCellValue(Row, "ord_doc_no"));
		 jQuery("#po_description").val(sheet1.GetCellValue(Row, "mr_desc"));
		 jQuery("#pur_cont_id").val(sheet1.GetCellValue(Row, "pur_cont_id"));
		 jQuery("#demanded_id").val(sheet1.GetCellValue(Row, "demanded_id"));
		 jQuery("#dept_cd2").val(sheet1.GetCellValue(Row, "dept_cd"));
		 
		jQuery("#form1").attr("action", "/process/process/InspectionDetail.screen");
		jQuery("#form1").attr("target", "_self");
		jQuery("#form1").attr("method", "post");
		jQuery("#form1").submit();	
	} else {
		jQuery("#fevent").val("GET_INSPECTION_LIST2");
		jQuery("#psr_id").val(sheet1.GetCellValue(Row, "psr_id"));
		
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/process/process/InspectionList_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet2, url, jQuery("#form1"), 10, "");		
	}
}

function sheet2_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) { 
	
	if(sheet2.ColSaveName(0, Col) == "inspection_date") {
		var f= document.form1;

		jQuery("#fevent").val("GET_INSPECTION_DETAIL");
		 jQuery("#corp_name").val(sheet1.GetCellValue(sheet1.GetSelectRow(), "corp_name"));
		 jQuery("#mr_no").val(sheet1.GetCellValue(sheet1.GetSelectRow(), "mr_no"));
		 jQuery("#po_no").val(sheet1.GetCellValue(sheet1.GetSelectRow(), "ord_doc_no"));
		 jQuery("#po_description").val(sheet1.GetCellValue(sheet1.GetSelectRow(), "mr_desc"));
		 jQuery("#inspection_no").val(sheet2.GetCellValue(Row, "inspection_no"));
		 jQuery("#pur_cont_id").val(sheet1.GetCellValue(sheet1.GetSelectRow(), "pur_cont_id"));
		 jQuery("#demanded_id").val(sheet1.GetCellValue(sheet1.GetSelectRow(), "demanded_id"));
		 jQuery("#dept_cd2").val(sheet1.GetCellValue(sheet1.GetSelectRow(), "dept_cd"));
		 
		 
		jQuery("#form1").attr("action", "/process/process/InspectionDetail.screen");
		jQuery("#form1").attr("target", "_self");
		jQuery("#form1").attr("method", "post");
		jQuery("#form1").submit();	
	}  else if (sheet2.ColSaveName(0, Col) == "add") {
		
		
		doAttachFile(sheet2.GetCellValue(Row, "inspection_no"));
		
	}
}

//첨부파일   
function doAttachFile(value) {
	viewFileListNew('INSPECTION_DETAIL', value, "", "N", "progress/inspection");
}

function clearDiscipline() {
	var f= document.form1;
	f.p_discipline.value = "";
}

$(document).on("keyup", "input:text", function(e) {
    if (e.keyCode == 13)
    {
    	jQuery("#btnSearch").click();
    }
});

function sheet1_OnSmartResize(Width, Height) { 
	sheet1.FitColWidth();
	sheet2.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); 
sheet2.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">
<INPUT type="hidden" name="date_all_value">

<INPUT type="hidden" name="psr_id">
<INPUT type="hidden" name="psr_activity_cd">
<INPUT type="hidden" name="corp_id">
<INPUT type="hidden" name="corp_name">
<INPUT type="hidden" name="mr_no">
<INPUT type="hidden" name="po_no">
<INPUT type="hidden" name="po_description">
<INPUT type="hidden" name="inspection_no">
<INPUT type="hidden" name="pur_cont_id">
<INPUT type="hidden" name="demanded_id">
<INPUT type="hidden" name="dept_cd2">



<div align="left" id="title">
    <ul>
     <li>Inspection</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="80" />
			<col width="340" />
			<col width="120" />
			<col width="270" />
			<col width="80" />
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr>
			<th>Project</th>
			<td>
		   		<%=InputText.getSiteCode("dept_cd", "dept_nm", "", user, params.get("dept_cd"), params.get("dept_name"))%> 				
			</td>
			<th>Inspection Date</th>
			<td>
				<%= InputText.get("sYmdSt", params.get("sYmdSt"), 10, 50, "hangule,center, desc=Inspection Date,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;">
				<%--<INPUT type="checkbox" id="date_all" name="date_all" value="Y" <%=params.get("date_all").equals("Y") ? "checked=\"checked\"" : "" %>>--%>
			</td>
			<th>Discipline</th>
			<td>
				<%= CommCodeManager.getSelectCodeList("BAS_LVL02", "p_discipline", "width:80%;height=18px;", "<OPTION value=''>-- 전체 --</OPTION>", params.get("discipline"), "") %>
				<IMG id='_btn_clear' onClick="clearDiscipline();" src='/img/buyer/button/bt_eraser1.gif' border='0' align='absmiddle' alt='[초기화]' style='cursor:pointer;'>
			</td>
			<td class="button" rowspan="2">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">Search</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnExcel">Excel</a></span>
			</td>
		</tr>
		<tr>
			<th>MR No.</th>
			<td>
				<%= InputText.get("p_mr_no", "", 90, 50, "hangule, desc=MR No, PerSize") %>
			</td>
			<th>Vendor</th>
			<td colspan="3">
				<%= InputText.get("p_corp_name", params.get("p_corp_name"), 98, 50, "hangule, desc=corp name, PerSize") %>
			</td>
		</tr>
	</table>
	
	<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">
		<tr>
			<td width="85%">
				<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 400px; overflow: auto;">
					<script>createIBSheet('sheet1','99%', '400px');</script>
				</div>
			</td>
			<td width="15%">
				<div id="sheet2_div" style="padding-top:5px; height: auto; min-height: 400px; overflow: auto;">
					<script>createIBSheet('sheet2','100%', '400px');</script>
				</div>
			</td>
		</tr>
	</TABLE>
</form>

