<%--
  - Author(s)  : Hyung min Son
  - Date       : 2014.07.22
  - Description: 외주_업체별기술문서
  --%>
  
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ 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.*" %>
<%@ page import="com.udapsoft.waf.common.util.Formatter2"%>
<%@ page import="com.udapsoft.waf.common.util.StringUtils"%>
<%@ 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();
    ValueObject Order = storage.getValueObject("Order");
    RowSet Tbe_info = storage.getRowSet("TBE_INFO");
%>
<SCRIPT language="JavaScript">
document.body.onresize = addEvent( document.body.onresize, "autoResize()");
	/*예약함수*/
	var sheet1 = new ibsheetObject();
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;

	function _onReady(){
		
		gridInit(sheet1);
		
		 $("#btn_back").click(function() {
				$("#fevent").val("FORM_SELECT");
				$("#form1").attr("action", "/bid/outside/TBECheck.screen");
				$("#form1").attr("target", "_self");
				$("#form1").attr("method", "post");
				$("#form1").submit();
		});
		 
		 
		 $("#btn_save").click(function() {//저장
				if(file_ck()){
					alert("문서를 선택해 주세요.");
					return;
				}
		 
				if (confirm("저장 하시겠습니까?")){
					$("#fevent").val("SAVE");
					var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/outside/TBECheckDetail_sheet.screen";
					Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), 30, "");
				}
		 });
		 
		 $("#btn_review").click(function() {//검토완료
				if(file_ck()){
					alert("문서를 선택해 주세요.");
					return;
				}
		 
				if (confirm("검토완료 처리 하시겠습니까?")){
					sheet_status_update("10");
					$("#fevent").val("REVIEW");
					var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/outside/TBECheckDetail_sheet.screen";
					Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), 30, "");
				}
		 });
		 
		 $("#btn_recall").click(function() {//재요청
				if(file_ck()){
					alert("문서를 선택해 주세요.");
					return;
				}

				if (confirm("재요청 처리 하시겠습니까?")){
					$("#TBE_STATUS_CD").val("02");
					$("#EDIT").val("N");
					sheet_status_update("02");
					$("#fevent").val("RECALL");
					var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/outside/TBECheckDetail_sheet.screen";
					Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), 30, "");
				}
		 });
		 
		 if( '<%=user.get("ACCT_ID")%>' != '<%=Order.get("EVAL_EMPID")%>'){
 			 $("#btn_review").hide();
 			 $("#btn_recall").hide();
 			 $("#btn_save").hide();
         }
		 doSearchSheet();
		 
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		init_sheet.Cols = [
						{Header:'요청차수',					Type:"Int", 			SaveName:"REQ_DEG", 						Width:40,		Align:"Center", Edit:false,	ColMerge:true},
		       			{Header:'선택',						Type:"CheckBox",		SaveName:"CHECK", 							Width:30, 		Align:"Center",	ColMerge:false},
		    			{Header:'Status',					Type:"Status", 		SaveName:"STATUS", 						Width:0, 		Align:"Center",	Hidden:"True",	ColMerge:false},
		    			{Header:'No.',						Type:"Seq", 			SaveName:"NO",								Width:0, 		Align:"Center",	Hidden:"True",	ColMerge:false},
		    			{Header:'문서명',					Type:"Text", 			SaveName:"DOC_NM", 						Width:200,		Align:"Left", Edit:false,	ColMerge:false},
		    			{Header:'파일명',					Type:"Text", 			SaveName:"FILE_NAME", 					Width:200, 		Align:"Left", Edit:false,	Cursor:"pointer",	ColMerge:false},
		    			{Header:'상태',						Type:"Text", 			SaveName:"STATUS_NM", 					Width:60, 		Align:"Center", Edit:false,	ColMerge:false},
		    			{Header:'문서요청일',				Type:"Text",		 	SaveName:"REG_DT", 						Width:80, 		Align:"Center", Edit:false,	ColMerge:false},
		    			{Header:'문서제출일',				Type:"Text", 			SaveName:"DOC_DT", 						Width:80, 		Align:"Center", Edit:false,	ColMerge:false},
		    			{Header:'비고',						Type:"Text", 			SaveName:"NOTI", 							Width:100, 		Align:"Left",	ColMerge:true},
		    			{Header:'STATUS_CD',			Type:"Text", 			SaveName:"STATUS_CD",					Width:0, 		Align:"Center",	Hidden:"True",		ColMerge:false},
		    			{Header:'EVAL_FILE_GB',		Type:"Text", 			SaveName:"EVAL_FILE_GB",				Width:0, 		Align:"Center",	Hidden:"True",		ColMerge:false},
		    			{Header:'EVAL_FILE_ID',		Type:"Text", 			SaveName:"EVAL_FILE_ID",				Width:0, 		Align:"Center",	Hidden:"True",		ColMerge:false},
		    			{Header:'FILE_PATH',			Type:"Text", 			SaveName:"FILE_PATH",					Width:0, 		Align:"Center",	Hidden:"True",		ColMerge:false},
		    			{Header:'REAL_FILE_NAME',	Type:"Text", 			SaveName:"REAL_FILE_NAME",			Width:0, 		Align:"Center",	Hidden:"True",		ColMerge:false},
		    			{Header:'FILE_ID',				Type:"Text", 			SaveName:"FILE_ID",						Width:0, 		Align:"Center",	Hidden:"True",		ColMerge:false},
		    			{Header:'TBE_STATUS_CD',	Type:"Text", 			SaveName:"TBE_STATUS_CD",			Width:0, 		Align:"Center",	Hidden:"True",		ColMerge:false}
		    			
		];
		init_sheet.HeaderMode = {Sort:0};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetMergeSheet(msFixedMerge);


		//sheetName.SizeMode(0);
		setGridSize();
	}
	
	/*
	 		체크된 문서가 있는지 확인.
	*/
	function file_ck(){
	 	var rowcnt = sheet1.RowCount();
		if(rowcnt> 0){
			for(var r=1; r < rowcnt+1; r++)
			{
				if(sheet1.GetCellValue(r,"CHECK") == "1"){
					return false;
				}
			}
		}
		return true;
	}
	
	function doSearchSheet(){
		$("#fevent").val("GET_FILE_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/outside/TBECheckDetail_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
	}
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	sheet1.SetRowMerge(2, true);
	    	setGridSize();
	    	var filedeg = Number(sheet1.GetCellValue(1,"REQ_DEG"));
	    	var rowcnt = sheet1.RowCount();
			if(rowcnt> 0){
				for(var r=1; r < rowcnt+1; r++)
				{
					sheet1.SetCellFontColor(r,"FILE_NAME", "#0000ff");
					if(filedeg > Number(sheet1.GetCellValue(r,"REQ_DEG"))){
						sheet1.SetRowEditable(r,false);	
					}
					if(sheet1.GetCellValue(r,"STATUS_CD")== "10" ||sheet1.GetCellValue(r,"STATUS_CD")== "02"){//검토완료 & 재요청 일경우 체크 불가능
						//sheet1.SetRowEditable(r,false);	 2015.3.12 완료된 문서 재검토 요청 가능.  	
					}
					if(sheet1.GetCellValue(r,"TBE_STATUS_CD")== "10" ){//검토완료 & 재요청 일경우 체크 불가능
						$("#btn_save").hide();
						$("#btn_review").hide();
						//$("#btn_recall").hide(); 2015.3.12 TBE완료전 완료된 문서재검토 요청 가능
					}
					
					//TBE완료되지 않은상태에서 완료문서 재요청 가능. 
					if ('<%=Order.get("UPPER_STATUS_CD")%>' == "10"){
					    $("#btn_recall").hide(); //2015.3.12 TBE완료전 완료된 문서재검토 요청 가능
					}
				}
			}
			//sheet1.SetDataRowMerge(true);
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	function sheet_status_update(status_cd){
		var rowcnt = sheet1.RowCount();
		if(rowcnt> 0){
			for(var r=1; r < rowcnt+1; r++)
			{
				if(sheet1.GetCellValue(r,"CHECK") == 1){
					sheet1.SetCellValue(r,"STATUS_CD",status_cd);
				}					
			}
		}
	}

	//첨부파일   
	function doAttachFile(obj,No) {
		 if(obj==''){
			 alert("After you have saved, you can attach a file.");
		}
		else if(obj != ''){ 
			if(No == 1){
				viewFileListNew('<%=Order.get("DOC_ETC_IN")%>', obj.value, document.form1.p_AttachFile1, "N", "BD-001");
			}else if(No == 2){
				viewFileListNew('<%=Order.get("DOC_ETC_OUT")%>', obj.value, document.form1.p_AttachFile2, "N", "BD-001");
			}
		} 
	}
	
	function sheet1_OnSaveEnd(code, msg)
	{
		var event = $("#fevent").val();
		if(code>= "0"){
			if(event == "SAVE"){
				alert("저장되었습니다.");
				doSearchSheet();
			}else if(event == "REVIEW"){
				alert("검토완료 되었습니다.");
				doSearchSheet();
			}else if(event == "RECALL"){
				alert("재요청 되었습니다.");
				doSearchSheet();
			}
		}else{
			alert("에러가 발생하였습니다.\n"+msg);
		}
	}
	
	/**
	 *	IBSheet Event: DBLCLICK
	 */
	 function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		 if(Row == 0)return;
		 if(Col == 5)
		 	fileDown(sheet1.GetCellValue(Row,"FILE_ID")); 
	 }
	
	 /**
	  * 첨부파일 예약 함수
	  */
	 function fileDown(file_id){
	 		var url="/common/file/FileDownloadServlet";
	  		url += "?file_id=" + file_id;
	  		
	  		window.open(url, "_fileDown", "toolbar=no, width=400, height=100, top=500, left=400, toolbar=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,target=new")
	 }
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}

	function autoResize(){
		var t1_height = document.getElementById("form-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		sheet1.SetSheetHeight(iframeHeight); 
	}	
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<form id="form1" name="form1" method="post" modular:type="search">
<!-- List Search -->
<INPUT type="hidden" name="P_BID_MASTER_NM" id="P_BID_MASTER_NM" value="<%=params.get("P_BID_MASTER_NM") %>">
<INPUT type="hidden" name="p_demanded_status" id="p_demanded_status" value="<%=params.get("p_demanded_status") %>">
<INPUT type="hidden" name="p_dept_nm" id="p_dept_nm" value="<%=params.get("p_dept_nm") %>">
<INPUT type="hidden" name="p_dept_cd" id="p_dept_cd" value="<%=params.get("p_dept_cd") %>">
<INPUT type="hidden" name="p_list" id="p_list" value="<%= params.get("p_list") %>">
<!-- List Search -->  
<INPUT type='hidden' name="fevent" id="fevent"  value="">
<INPUT type='hidden' name="VENDOR_CD" value="<%=Order.get("VENDOR_CD")%>">
<INPUT type='hidden' name="BID_NO" value="<%=Order.get("BID_NO")%>">
<INPUT type='hidden' name="BID_DEG" value="<%=Order.get("BID_DEG")%>">
<INPUT type='hidden' name="TBE_STATUS_CD" value="<%=Order.get("TBE_STATUS_CD")%>">
<INPUT type='hidden' name="EDIT" value="">
<table width="100%" id="title">
	<colgroup>
		<col width="*" />
		<col width="250" />
	</colgroup>
	<tr>
   		<th>
			<div align="left" id="title">
			    <ul><li>외주_업체별기술문서<font style="font-size:11px">(<%=Order.get("TBE_STATUS_NM")%>)</font></li></ul>
			</div>
   		</th>
   		<td align="right">
				<span class="btnSearch center"  id="btn_back"><a href="javascript:void(0);">이전</a></span>
   		</td>
  	</tr>
</table>

<div class="application-info">
	<div class="application-sub-title">
		<span class="title">업체정보</span>
	</div>
</div>

<TABLE class="form-table">
	<colgroup>
		<col width="150"/>
		<col width="21%">
		<col width="150"/>
		<col width="20%">
		<col width="160"/>
		<col/>
	</colgroup>
  <TR height="25">
    <TH>사업자번호</TH>
	<TD>
	  <%=StringUtils.getBizNo(Order.get("CORP_REG_NO"))%>
    </TD>
	<TH>업체명</TH>
	<TD colspan="3">
	 <%=Order.get("CORP_KOR")%>           
	</TD>
  </TR>


  <TR height="25">
	<TH>작성자</TH>
	<TD>
		<%=Order.get("REG_NM")%>
	</TD>
	<TH>연락처</TH>
	<TD>
		<%=Order.get("REG_TEL")%>
	</TD>
	<TH>이메일</TH>
	<TD>
		<%=Order.get("REG_EMAIL")%>
	</TD>
  </TR>
  
</table>
<table width="100%" style="padding-top:5px;">
	<colgroup>
		<col width="*" />
		<col width="250" />
	</colgroup>
	<tr>
   		<td align="right">
				<span class="btnSearch center"  id="btn_save"><a href="javascript:void(0);">저장</a></span>
				<span class="btnSearch center"  id="btn_review"><a href="javascript:void(0);">검토완료</a></span>
				<span class="btnSearch center"  id="btn_recall"><a href="javascript:void(0);">재요청</a></span>
   		</td>
  	</tr>
</table>

	<div id="sheet1_div" style="padding-top:5px;height: auto; min-height: 200px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '450px');</script>
	</div>
</form>