<%--
  - Author(s)  : Hyung min Son
  - Date       : 2014.06.18
  - Description: 발주의뢰 접수 대상건 조회
  --%>
  
<%@ 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="com.udapsoft.waf.common.util.Formatter2"%>
<%@ page import="com.udapsoft.waf.common.util.StringUtils"%>
<%@ page import="com.udapsoft.waf.common.ui.InitCombo" %>
<%@ 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();
    RowSet CorpRowSet = storage.getRowSet("CorpRowSet");
    ValueObject Order = storage.getValueObject("Order");
    String RTN_REASON = "";
    boolean rtn = false;
    

    if(Order.get("DEMANDED_STATUS").equals("5")){
    	RTN_REASON = Order.get("RTN_REASON");
    	rtn = true;
    }
    ValueObject filein = storage.getValueObject("OUTSOURCING_DEMANDED_INNER");
    ValueObject fileout = storage.getValueObject("OUTSOURCING_DEMANDED_OUTER");
    
    
	//공통코드
	CommCodeManager commCodeManager = new CommCodeManager();
	InitCombo initCombo = new InitCombo();

	initCombo.makeComboData(commCodeManager.getCodeRowSet("BID_SUPP_INFO_YN"), "NAME", "CODE");
	String BID_SUPP_INFO_CD = initCombo.getCode();
	String BID_SUPP_INFO_NM = initCombo.getCodeName();
	
    ValueObject sign_info = storage.getValueObject("SIGN_INFO");
	
	String gwurl	=	"http://gw.sgcenc.co.kr/";//WAFConfig.get("gw.url.address2");
%>
<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);
		doSearchSheet();
		/**
		 *	Application Initialize
		 */
		jQuery("#btn_list").click(function() {
			jQuery("#fevent").val("");
			jQuery("#form1").attr("action", "/bid/outside/OrderReqeustList.screen");
			jQuery("#form1").attr("target", "_self");
			jQuery("#form1").attr("method", "post");
			jQuery("#form1").submit();
		});
		jQuery("#ONBID_YN1").click(function() {
			jQuery("#ONBID_YN1").attr("checked",true);
			jQuery("#ONBID_YN2").attr("checked",false);
		});
		jQuery("#ONBID_YN2").click(function() {
			jQuery("#ONBID_YN1").attr("checked",false);
			jQuery("#ONBID_YN2").attr("checked",true);
		});
		
		//외주내역 팝업 2018.10.18
		jQuery("#btnItem").click(function() {			
			var win_id = "ItemPop";			
  
			var link = "/bid/outside/OrdItemPopup.screen";
			link += "?pop_win_id="+win_id+"&DEMANDED_ID="+$("#DEMANDED_ID").val();
			fLayerPop(win_id, link, 950,500, '','', 'NO');
		});	
		jQuery("#btn_receipt").click(function() {
			var status = "<%=Order.get("DEMANDED_STATUS")%>";
			if(status != 4){
				
				if(ck()){
					alert("[온라인 입찰 여부]는 필수 입니다.");
					return;
				}
				if($(':radio[name=ONBID_YN]:checked').val())
				{
					var InfoYn = false;					
					var rowcnt = sheet1.RowCount();
					if(rowcnt> 0){
						for(var r=0; r < rowcnt; r++)
						{
							if(sheet1.GetCellValue(r+1,"INFO_YN") != "Y"){
								InfoYn = true;
							}
						}
					}
					var	sConfirm	=	"";
					if($(':radio[name=ONBID_YN]:checked').val() == "Y")
					{
						if(InfoYn){
							sConfirm	=	"미가입된 업체가 있습니다.\n발주의뢰건을 접수하시겠습니까?\n접수후 온라인으로 입찰이 진행됩니다.";
						}else{
							sConfirm	=	"발주의뢰건을 접수하시겠습니까?\n접수후 온라인으로 입찰이 진행됩니다.";	
						}
						
					}else
					{
						if(InfoYn){
							sConfirm	=	"미가입된 업체가 있습니다.\n발주의뢰건을 접수하시겠습니까?\n접수후 오프라인으로 입찰이 진행됩니다.";
						}else{
							sConfirm	=	"발주의뢰건을 접수하시겠습니까?\n접수후 오프라인으로 입찰이 진행됩니다.";	
						}
						
					}
					if(!confirm(sConfirm))	return;
					
					var f = document.form1;
					jQuery("#DEMANDED_STATUS").val("4");//상태값 접수
					jQuery("#fevent").val("FROM_RECEIPT_UPDATE");
					var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/outside/OrderReqeust_sheet.screen";
					var result = Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), false);
				}
			}else{
				alert("접수된 발주 입니다.");
			}
		});
		
		jQuery("#btn_return").click(function() {
			if (confirm("반려 하시겠습니까?")){
				var win_id = "return_pop";			
				var link = "/bid/outside/RtnReasonPopup.screen";
				link += "?pop_win_id="+win_id+"&DEMANDED_ID="+$("#DEMANDED_ID").val();
				fLayerPop(win_id, link, 600,180, '','', 'NO');
			}
		});
		
		
		var status_cd = "<%=Order.get("DEMANDED_STATUS")%>";
		if(status_cd == 4 || status_cd == 5){
			$("#btn_receipt").hide();
			$("#btn_return").hide();
			$("#ONBID_YN1").attr("disabled",true);
			$("#ONBID_YN2").attr("disabled",true);
		}
	} 
	
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		init_sheet.Cols = [
			       			{Header:'Del',				Type:"DelCheck",		SaveName:"DEL_CHECK", 					Width:0, 			Align:"Center",	Hidden:"True"},
			    			{Header:'Status',			Type:"Status", 		SaveName:"STATUS", 						Width:0, 			Align:"Center",	Hidden:"True"},
			    			{Header:'No.',				Type:"Seq", 			SaveName:"NO",								Width:0, 			Align:"Center",	Hidden:"True"},
			    			{Header:'사업자번호',		Type:"Text", 			SaveName:"VENDOR_ID", 					Width:80, 			Align:"Center", Format:"SaupNo"},
			    			{Header:'업체명',			Type:"Text", 			SaveName:"VENDOR_NAME", 				Width:80, 			Align:"Left"},
			    			{Header:'상태',			Type:"Text", 			SaveName:"STATUS_NM", 				Width:80, 			Align:"Left"},
			    			{Header:'대표자명',			Type:"Text", 			SaveName:"PRE_NM", 						Width:80, 			Align:"Center"},
			    			{Header:'담당자명',			Type:"Text", 			SaveName:"CHARGE_NAME", 				Width:80, 			Align:"Center"},
			    			{Header:'핸드폰',			Type:"Text", 			SaveName:"CHARGE_TEL", 					Width:80, 			Align:"Center"},
			    			{Header:'이메일',			Type:"Text", 			SaveName:"CHARGE_EMAIL", 				Width:80, 			Align:"Left"},
			    			{Header:'추천사유',			Type:"Text", 			SaveName:"RECOMMEND_REASON", 		Width:80, 			Align:"Left"},
			    			{Header:'가입여부',			Type:"Combo", 		SaveName:"INFO_YN", 						Width:80, 			Align:"Center",	ComboText:"<%=BID_SUPP_INFO_NM%>", ComboCode:"<%=BID_SUPP_INFO_CD%>"}
			];
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		setGridSize();
	}
	
	function ck(){
		if($("#ONBID_YN1").attr("checked") == "checked"){
			return false;	
		}
		if($("#ONBID_YN2").attr("checked") == "checked"){
			return false;
		}
		return true;
	}
	
	function RtnReasonClose(returnValue){
		if(returnValue == null)
			setTimeout(function(){fLayerPopClose('return_pop');},100);
		
		if(returnValue[0] == 0){
			setTimeout(function(){fLayerPopClose('return_pop');},100);
			goListProc();
		}
	}
	
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
	    	for(var i=1;i <= sheet1.RowCount();i++){
	    		if(sheet1.GetCellValue(i,"INFO_YN") == "N"){
	    			sheet1.SetCellFontColor(i,10,"#FF0000");
	    		}else{
	    			sheet1.SetCellFontColor(i,10,"#0100FF");
	    		}
	    	}
	    	
	    	
		} else {
			//조회 에러 수행
			alert(message);
		}
	}
	
	function sheet1_OnSaveEnd(code, msg)
	{
		var event = $("#fevent").val();
		if(code >= "0"){
				alert("접수 되었습니다.");
				goRefreshProc("0");
		}else{
			alert("에러가 발생하였습니다.\n"+msg);
		}
	}
	
	function goRefreshProc(code){
		if(code == "0"){
			jQuery("#fevent").val("FORM_SELECT");
			jQuery("#form1").attr("action", "/bid/outside/OrderReqeust.screen");
			jQuery("#form1").attr("target", "_self");
			jQuery("#form1").attr("method", "post");
			jQuery("#form1").submit();
		}
	}
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	

	function goListProc(){
		 var f = document.form1;
		f.fevent.value ="";
	    f.action = "/bid/outside/OrderReqeustList.screen";
	    f.target = "_self";
	    f.submit();
	}
	
	function doSearchSheet(){
		jQuery("#fevent").val("GET_CORP_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/outside/OrderReqeust_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
	}
	
	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "FROM_RECEIPT_UPDATE") {
				if( resultObj.getSuccess() ) {
					alert("접수 되었습니다.");
					goRefreshProc();
				}
				else {
					dlgErrorMsg(resultObj);
				}
			}
			
			if( resultObj.getRequestEvent() == "GET_DEPT_LIST") {
				if( resultObj.getSuccess() ) {

				} else {
					dlgErrorMsg(resultObj);
				}
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	//첨부파일   
	function doAttachFile(obj,No) {
		var file_div = "bid/outside/"+"<%=Order.get("BID_NO")%>"+"/";
		var fileName = "<%=Order.get("DEMANDED_NO")%>" + "(" + "<%=Order.get("DEMANDED_TITLE")%>" + ")_";
		
		 if(obj==''){
			alert("After you have saved, you can attach a file.");
		}
		else if(obj != ''){ 
			if(No == 1){
				fileName += "내부자료";
				viewFileListNew("OUTSOURCING_DEMANDED_INNER", obj.value, document.form1.p_AttachFile1, "N", file_div, null, null, null, null, "Y", fileName);
			}else{
				fileName += "외부자료";
				viewFileListNew("OUTSOURCING_DEMANDED_OUTER", obj.value, document.form1.p_AttachFile2, "N", file_div, null, null, null, null, "Y", fileName);
			}
		} 
	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}

	function autoResize(){
		sheet1.SetSheetHeight(300); 
	}	
	
	function doSignFile(doc_id){
		//alert(doc_id);
		if(doc_id == ""){
			alert("결재 정보가 없습니다.");
			return;
		}
		var doc_chk = doc_id.substring(doc_id.length-3, doc_id.length);
		
		doc_chk = doc_chk * 1;
		
		var link = "";
		var year = "<%=sign_info.get("year") %>";
		if (year > "20151213"){
		 	link = "<%=gwurl%>upload_approval/TEC/doc/" + year.substr(0,4) + "/" + doc_chk + "/"+ doc_id+".mht";
		}
		else
		{
			link = "<%=gwurl%>upload_approval/TEC/doc/" + doc_chk + "/"+ doc_id+".mht";
		}
		
		//var popOption = "width=400, height=450, resizable=no, scrollbars=auto, status=no;";    //팝업창 옵션(optoin)
		
		window.open(link,"_viewDraft","");	
	}
	
</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_DEMANDED_TITLE" id="P_DEMANDED_TITLE" value="<%= params.get("P_DEMANDED_TITLE") %>">
<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") %>">
<!-- List Search -->    
    
<INPUT type="hidden" name="fevent" id="fevent" value="<%= params.get("fevent") %>">
<INPUT type="hidden" name="acct_id" value="<%= params.get("acct_id") %>">
<INPUT type="hidden" name="dept_nm" value="<%= params.get("dept_nm") %>">
<INPUT type="hidden" name="DEMANDED_STATUS" value="<%=Order.get("DEMANDED_STATUS")%>">
<INPUT type="hidden" name="DEMANDED_ID" value="<%=Order.get("DEMANDED_ID")%>">
<INPUT type="hidden" name="DEMANDED_KIND" value="<%=Order.get("DEMANDED_KIND")%>">
<INPUT type="hidden" name="BUSEO" value="<%= user.get("BUSEO")%>"><!-- 부서code -->
<INPUT type="hidden" name="BUSEO_NM" value="<%= Order.get("BUSEO_NM")%>"><!-- 부서NM -->
<!-- 반려사유 -->
<INPUT type="hidden" name="RTN_REASON" value="<%=Order.get("RTN_REASON")%>">
<INPUT type="hidden" name="job_Cd" value="<%= user.get("PSOSO")%>">
<INPUT type="hidden" name="buseo_Cd" value="<%= user.get("GRADE_CODE")%>">
<INPUT type="hidden" name="inner_remarks_val" value="<%= Order.get("inner_remarks")%>">
<INPUT type="hidden" name="outer_remarks_val" value="<%= Order.get("outer_remarks")%>">

<!-- 제목 및 버튼 -->
<table width="100%">
	<colgroup>
		<col width="500" />
		<col width="*" />
	</colgroup>
	<tr>
   		<th>
	   		<div align="left" id="title" >
 			  <ul><li>외주_발주의뢰접수 상세<font style="font-size:11px">(<%=Order.get("DEMANDED_STATUS_NM")%>)</font></li></ul>
			</div> 
   		</th>
   		<td align="right">
			<span class="btnSearch center"  id="btn_receipt"><a href="javascript:void(0);">접수</a></span>
			<span class="btnSearch center"  id="btn_return"><a href="javascript:void(0);">반려</a></span>
			<span class="btnSearch center" id="btnItem"><a href="javascript:void(0);">발주의뢰내역</a></span>
       		<span class="btnSearch center" id="btn_list"><a href="javascript:void(0);" >목록</a></span>
   		</td>
  	</tr>
</table>
<%if(rtn){ %>
<TABLE class="form-table">
	<colgroup>
		<col width="139"/>
		<col width="90%">
	</colgroup>
  <TR height="25">
	<TH>반려일자</TH>
	<TD><%=Order.get("RTN_DATE")%></TD> 
  </TR>
  <TR height="25">
    <TH>반려사유</TH>
	<TD><%=RTN_REASON%></TD>
  </TR>
</TABLE>
<%}%>

<div class="application-info magT15">
	<div class="application-sub-title">
		<span class="title">발주의뢰정보</span>
	</div>
</div>
<!-- 발주의뢰정보 : 시작 -->
<TABLE class="form-table">
	<colgroup>
		<col width="150"/>
		<col width="23%">
		<col width="150"/>
		<col width="23%">
		<col width="150"/>
		<col/>
	</colgroup>
  <TR height="25"> 
    <TH> 현장</TH>
	<TD><%=Order.get("dept_nm") %></TD>
	<TH> 발주의뢰번호</TH>
	<TD><a href="javascript:doSignFile('<%=sign_info.get("doc_id") %>');"><%=Order.get("DEMANDED_NO")%></a>
	</TD>
	<TH> 발주의뢰명</TH>
	<TD><%=Order.get("DEMANDED_TITLE")%></TD>
  </TR>
  <TR height="25"> 
	<TH> 발주의뢰일</TH>
	<TD><%= Order.get("DEMANDED_DATE")%></TD>
	<TH> 발주의뢰부서</TH>
	<TD><%= Order.get("BUSEO_NM")%></TD>
	<TH> 발주의뢰자</TH>
	<TD><%= Order.get("EMP_NM")%></TD> 	
  </TR>
  <TR height="25"> 
	<TH> 접수자(접수일자)</TH>
	<TD><%=Order.get("RECEIPT_NM") %><%if(!Order.get("RECEIPT_DATE").isEmpty()){ %>(<%=Order.get("RECEIPT_DATE") %>)<%} %></TD>
	<TH>통화구분</TH>
	<TD><%= Order.get("CURRENCY_GB") %></TD>
	<TH> Pay Item</TH>
	<TD><%= Order.get("PAY_ITEM_NM") %></TD> 	
  </TR> 	
   <TR height="25"> 
	<TH> 도급금액 (원)</TH>
	<TD><%= Formatter2.currency(Order.get("CONT_AMT"),0) %></TD>
	<TH> 실행금액 (원)</TH>
	<TD><%=Formatter2.currency(Order.get("ACT_AMT"),0) %></TD>
	<TH> 도급대비 실행율(%)</TH>
	<TD><%= Order.get("ACT_RATE")%></TD> 	
  </TR>

  <TR height="25"> 
	<TH class="required"> 온라인 입찰 여부</TH>
	<TD> 
		<LABEL for="ONBID_YN1"><INPUT id="ONBID_YN1" type="radio" name="ONBID_YN" value="Y" <%=Order.get("ONBID_YN").equals("Y") ? "checked=\"checked\"" : "" %>>온라인</LABEL>
		<LABEL for="ONBID_YN2"><INPUT id="ONBID_YN2" type="radio" name="ONBID_YN" value="N" <%=Order.get("ONBID_YN").equals("N") ? "checked=\"checked\"" : "" %>>오프라인</LABEL>
	</TD>
	<TH> 견적설명회 여부</TH>
	<TD><%= Order.get("SITEDESC_FLAG")%></TD>
	<TH> 견적설명회 일시</TH>
	<TD><%=Order.get("SITEDESCDATE")%></TD> 	
  </TR>
  <TR height="25"> 
	<TH> 견적설명회 담당자</TH>
	<TD><%= Order.get("SITEDESC_CRG_NM")%></TD>
	<TH> 견적설명회 담당자</br>전화번호</TH>
	<TD><%= Order.get("SITEDESCTELNO") %></TD>
	<TH> 견적설명회 담당자</br>E-Mail</TH>
	<TD><%= Order.get("SITEDESCEMAIL") %></TD> 	
  </TR>
  <TR height="25"> 
	<TH> 견적설명회 장소</TH>
	<TD><%=Order.get("SITEDESCPLACE") %></TD>
	<TH> TBE 여부/일자</TH>
	<TD><%=Order.get("TBE_FLAG").equals("Y") ? "예" : "아니오"%>  / <%= Order.get("TBE_DATE") %></TD>
	<TH> 공사구분</TH>
	<TD><%=Order.get("PAY_DIV").equals("1") ? "플랜트" : "일반건물"%></TD>
	
  </TR>
  <TR height="25"> 
	<TH> 공사기간</TH>
	<TD><%=Order.get("DELI_START_DT") %> <%if(!Order.get("DELI_START_DT").isEmpty()||!Order.get("DELI_END_DT").isEmpty()){ %>~<%} %> <%= Order.get("DELI_END_DT") %></TD>
	<TH> 공사장소</TH>
	<TD><%= Order.get("DELI_END_PLACE") %></TD>
 	<TH> 공종</TH>
	<TD><%= Order.get("OUT_ITEM_NM") %></TD>
  </TR>  
  <!-- 발주의뢰정보 : 종료 -->
</table>
&nbsp;&nbsp;
<TABLE class="form-table">
	<colgroup>
		<col width="150"/>
		<col width="150"/>
		<col width="29%"/>
		<col width="150"/>
		<col/>
	</colgroup>
  <TR height="25"> 
    <TH> 특이사항 내부</TH>
	<TD colspan="2" style="vertical-align: top"><%=StringUtils.cvtHTML(Order.get("INNER_REMARKS"))%></TD>
	<TH> 특이사항 외부</TH>
	<TD style="vertical-align: top"><%=StringUtils.cvtHTML(Order.get("OUTER_REMARKS"))%></TD>
  </TR>
  <TR height="100"> 
    <TH> 내부자료</TH>
	<TD colspan="2">
	<TEXTAREA name="p_AttachFile1" id="p_AttachFile1" style="width:85%;height:80px" rows="1" class="input" readOnly><%=filein.get("OUTSOURCING_DEMANDED_INNER") %></TEXTAREA>
	<IMG id='search_spot_button' onClick="doAttachFile(document.form1.DEMANDED_ID,1);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
    </TD>
	<TH> 외부자료</TH>
	<TD>
	<TEXTAREA name="p_AttachFile2" id="p_AttachFile2" style="width:85%;height:80px" rows="1" class="input" readOnly><%=fileout.get("OUTSOURCING_DEMANDED_OUTER") %></TEXTAREA>
	<IMG id='search_spot_button' onClick="doAttachFile(document.form1.DEMANDED_ID,2);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
	</TD>
  </TR>   
</TABLE>

<div class="application-info magT10">
	<div class="application-sub-title">
		<span class="title">견적대상업체</span>
	</div>
	<div class="application-location">
	</div>
</div>

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

