<%--
  - Author(s)  : Hoonseok choi
  - Date       : 2023.02.08
  - Description: 견적_계획 상세
  --%>
  
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@page import="kr.co.hsnc.common.config.WAFConfig"%>
<%@ 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"%>
<%@ page import="kr.co.udapsoft.common.util.Crosscert"%>
<%@ 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");
    ValueObject fileout = storage.getValueObject("DOC_ETC_OUT");
    ValueObject attid = storage.getValueObject("ATT_ID");
	
	String today = DateUtil.formatDateTime(DateUtil.getToday(), "yyyyMMdd", "yyyyMMdd");
	
    SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
    SimpleDateFormat sd2 = new SimpleDateFormat("yyyyMMddHHmm");
    String nowTime = sd.format(new Date());
    String to_yyyy = Order.get("QUOT_BID_TO_DT").substring(0, 4);
    String to_MM = Order.get("QUOT_BID_TO_DT").substring(5, 7);
    String to_dd = Order.get("QUOT_BID_TO_DT").substring(8, 10);
    String to_hh = Order.get("QUOT_BID_TO_DT").substring(11, 13);
    String to_mi = Order.get("QUOT_BID_TO_DT").substring(14, 16);
    String nowTime_yyyy = nowTime.substring(0, 4);
    String nowTime_MM = nowTime.substring(4, 6);
    String nowTime_dd = nowTime.substring(6, 8);
    SimpleDateFormat SeverTime = new SimpleDateFormat("yyyy-MM-dd");
    String str = SeverTime.format(new Date()); 
    to_MM = (Integer.valueOf(to_MM)-1)+""; // 전자조달과 동일하게 
    nowTime_MM = (Integer.valueOf(nowTime_MM)-1)+"";
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var must_msg = "(은)는 필수 입력 항목입니다."; 
	function _onReady(){
		//견적마감 이후 버튼 숨김..
		if("<%=Order.get("STATUS_CD")%>" == "10"){
			$("#btn_Save").hide();
			$("#btn_finish").hide();
		}else if("<%=Order.get("BID_STATUS_CD")%>" == "10"){
			$("#btn_Save").hide();
		}
		/**
		 *	Application Initialize
		 */
		 $("#btn_list").click(function() {
			jQuery("#fevent").val("");
			jQuery("#form1").attr("action", "/portal/quot/QuotPlanList.screen");
			jQuery("#form1").attr("target", "_self");
			jQuery("#form1").attr("method", "post");
			jQuery("#form1").submit();
		});
		 
		$("#btn_Save").click(function() {
			if(confirm("저장하시겠습니까?")){
    			if(save_must_ck()){
    				jQuery("#fevent").val("UPDATE_QUOT_DETAIL");
    				jQuery("#ESTI_TOT_AMT").val($("#ESTI_TOT_AMT").val().replace(/,/gi,""));
    				jQuery("#BID_STATUS_CD").val("01");
    				var f = document.form1;
					submitXmlRequest("/portal/quot/QuotPlan_form.screen", "UPDATE_QUOT_DETAIL", f);
    			}
    		}		
		});
		
		$("#btn_finish").click(function() {
			if(confirm("견적 제출하시겠습니까?")){
    			if(save_must_ck()){
    				jQuery("#fevent").val("FINISH_QUOT_DETAIL");
    				jQuery("#ESTI_TOT_AMT").val($("#ESTI_TOT_AMT").val().replace(/,/gi,""));
    				jQuery("#BID_STATUS_CD").val("10");
    				var f = document.form1;
					submitXmlRequest("/portal/quot/QuotPlan_form.screen", "FINISH_QUOT_DETAIL", f);
    			}
    		}		
		});
		
		$("#SITE_ATTEND_YN").val("<%=Order.get("SITE_ATTEND_YN")%>");
		
		 $("#SITE_ATTEND_YN").change(function() {
			 if($("#SITE_ATTEND_YN").val() == "N"){
					$("#SITE_ATTEND_TABLE").show();//불참 사유 숨김.
					$("#SITE_ATTEND_DIV").show();//불참 사유 숨김.
			 }else{
					$("#SITE_ATTEND_TABLE").hide();//불참 사유 숨김.
					$("#SITE_ATTEND_DIV").hide();//불참 사유 숨김.
			 }
		 });
		 $("#SITE_ATTEND_YN").change();
	}
	
	function save_must_ck(){
		if($("#SITE_ATTEND_YN").val() == ""){
			 alert("견적설명회 참석의사를 선택하세요");
			 $("#SITE_ATTEND_YN").focus();
			 return;
		 }else if($("#SITE_ATTEND_YN").val() == "Y"){
			 msg = "견적설명회에 참석하시겠습니까?";
			 if(must_ck_val("ESTI_TOT_AMT","견적금액"))return false;
		 }else if($("#SITE_ATTEND_YN").val() == "N"){
			 msg = "견적설명회에 불참하시겠습니까?";	 
			 if($("#SITE_ATTEND_REASON").val().length == 0){
				 alert("견적설명회 불참사유는 필수입니다.");
				 $("#SITE_ATTEND_REASON").focus();
				 return;
			 }
		 }
		
 		return true;
 	}
	
	// value 값 체크 
	function must_ck_val(obj,desc){
		if($("#"+obj).val().length == 0){
			if(desc.length> 0){
				alert(desc+must_msg);
			}else{
				alert($("#"+obj).attr("desc")+must_msg);
			}
			$("#"+obj).focus();
			return true;
		}
		return false;
	}
	

	
	//첨부파일   
	function doAttachFile(obj,No) {
		var file_div = "quot/outside/"+"<%=Order.get("QUOT_BID_NO")%>"+"/";
		var file_div2 = "quot/outside/"+"<%=Order.get("QUOT_BID_NO")%>"+"/"+"<%=Order.get("VENDOR_CD")%>"+"/";
		var upLoadFlg = "Y";
		if(<%=Order.get("STATUS_CD")%> == "10"){
			upLoadFlg = "N";
		}
		if(obj != ''){
			if(No == 1){
				var fileName = "견적자료";
				viewFileListNew("QUOT_FILE_OUT_"+obj.value, obj.value, document.form1.p_AttachFile, "N", file_div, null, null, null, null, "N", fileName);
			}else if(No == 2){
				var fileName = "첨부자료";
				viewFileListNew("QUOT_SUPP_"+"<%=Order.get("VENDOR_CD")%>"+obj.value, obj.value, document.form1.p_AttachFile2, upLoadFlg, file_div2, null, null, null, null, "N", fileName);
			}
		}
	}
	
	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "UPDATE_QUOT_DETAIL") {
				if( resultObj.getSuccess() ) {
					alert("저장 되었습니다.");
					reSearch();
				}
				else {
					dlgErrorMsg(resultObj);
				}
			}
			
			if( resultObj.getRequestEvent() == "FINISH_QUOT_DETAIL") {
				if( resultObj.getSuccess() ) {
					alert("견적 제출하였습니다.\n견적마감 전까지 제출이 가능합니다.");
					reSearch();
				}
				else {
					alert("외부자료를 등록하시기 바랍니다.");
					reSearch();
					//dlgErrorMsg(resultObj);
				}
			}
			
		} catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	function reSearch() {
		jQuery("#fevent").val("GET_QUOT_DETAIL");
		jQuery("#form1").attr("action", "QuotPlan.screen");
		jQuery("#form1").attr("target", "_self");
		jQuery("#form1").attr("method", "post");
		jQuery("#form1").submit();
	}
	
	function textareaResize(obj) {
	  obj.style.height = "80px";
	  obj.style.height = obj.scrollHeight+"px";
	}
	
	function dpTime2(){
	    var now = new Date();
	     hours = now.getHours();
	     minutes = now.getMinutes();
	     seconds = now.getSeconds();

	    var day2= new Date(<%=to_yyyy%>,<%=to_MM%>,<%=to_dd%>,<%=to_hh%>,<%=to_mi%>,00);
	    var day1= new Date(<%=nowTime_yyyy%>,<%=nowTime_MM%>,<%=nowTime_dd%>,hours,minutes,seconds);
	    var ms1 = Date.parse(day1);
	    // 두번째 날짜를 1/1000 값으로 환산
	    var ms2 = Date.parse(day2);
	    var sep = (ms2-ms1)/1000; // 두 날짜간의 시간차 (1/1000 초 이므로 초로 환산)
	    var min = 60;
	    var hour= min * 60;
	    var day = hour * 24;
	    var sd  = parseInt(sep/day);
	    var sh  = parseInt((sep%day)/hour);
	    var sm  = parseInt((sep%hour)/min);
	    var ss  = sep%min+1;			
	    var msg = "";
	    if(sd > 0){
	    	msg = sd+'일 '+sh+'시간 '+sm+'분 '+ss+'초 남았습니다. / 견적진행중';
	    }else if(sd <= 0){
	    	if(sh <= 0){
	    		if(sm <= 0){
	    			msg = "입찰마감";
	    		}else{
	    			msg = sm+'분 '+ss+'초 남았습니다. / 견적진행중';
	    		}
	    	}else{
	    		msg = sh+'시간 '+sm+'분 '+ss+'초 남았습니다. / 견적진행중';
	    	}
	    }else{
	    	msg = "견적마감";
	    }
	    document.getElementById('dpTime').innerHTML = msg;
	 }
		
	setInterval("dpTime2()",1000);
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>
<form id="form1" name="form1" method="post" modular:type="search">
<INPUT type='hidden' name="fevent" id="fevent"  value="">
<!-- List Search -->
<INPUT type="hidden" name="p_dept_nm" id="p_dept_nm" value="<%= Order.get("dept_nm") %>">
<INPUT type="hidden" name="p_dept_cd" id="p_dept_cd" value="<%= Order.get("dept_cd") %>">
<!-- List Search -->  
<INPUT type='hidden' name="QUOT_BID_NO" value="<%=Order.get("QUOT_BID_NO")%>">
<INPUT type='hidden' name="QUOT_BID_DEG" value="<%=Order.get("QUOT_BID_DEG")%>">
<INPUT type='hidden' name="STATUS_CD" value="<%=Order.get("STATUS_CD")%>">
<INPUT type='hidden' name="BID_STATUS_CD" value="<%=Order.get("BID_STATUS_CD")%>">
<INPUT type='hidden' name="VENDOR_CD" value="<%=Order.get("VENDOR_CD")%>">
<INPUT type="hidden" name="quot_id" value="<%= params.get("quot_id") %>">
<INPUT type='hidden' name="REQUEST_DEPT_CD" value="<%=Order.get("REQUEST_DEPT_CD")%>">
<INPUT type='hidden' name="SAVE" value="">

<INPUT type='hidden' name="ATT_ID" value="<%=Order.get("ATT_ID")%>">
<INPUT type='hidden' name="DOC_ETC_OUT" value="<%=Order.get("DOC_ETC_OUT")%>">
<!-- 제목 및 버튼 -->
<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("SUPP_STATUS_NM")%>)</font></li></ul>
			</div> 
   		</th>
   		<td align="right">
			<span class="btnSearch center"><a href="javascript:void(0);" id="btn_Save">저장</a></span>
			<span class="btnSearch center"><a href="javascript:void(0);" id="btn_finish">견적제출</a></span>
	        <span class="btnSearch center"><a href="javascript:void(0);" id="btn_list">목록</a></span>
   		</td>
  	</tr>
</table>

<!-- 발주의뢰정보 : 시작 -->
<div class="application-info magT15" id=SITE_ATTEND_DIV>
	<div class="application-sub-title">
		<span class="title">견적지원 불참사유</span>
	</div>
</div>
<TABLE class="form-table" id=SITE_ATTEND_TABLE>
	<colgroup>
		<col width="160"/>
		<col/>
	</colgroup>
  <TR height="25"> 
    <TH style="text-align:left">불참사유</TH>
	<TD><TEXTAREA name="SITE_ATTEND_REASON" id="SITE_ATTEND_REASON" style="width:99%;height:50px" rows="1" class="input" ><%=Order.get("SITE_ATTEND_REASON")%></TEXTAREA></TD>
  </TR>
 </TABLE>



<!-- 견적정보 : 시작 -->
<div class="application-info magT10">
	<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><%=Order.get("dept_nm") %></TD>
	<TH>견적번호</TH>
	<TD><%=Order.get("quot_bid_no") %></TD>
	<TH>견적명</TH>
	<TD><%=Order.get("QUOT_BID_MASTER_NM") %></TD>
  </TR>

  
  <TR height="25"> 
	<TH>견적의뢰일자</TH>
	<TD><%=Order.get("REQUEST_DATE") %></TD>
	<TH>견적의뢰부서</TH>
	<TD><%=Order.get("REQUEST_DEPT_NM") %></TD> 	
	<TH>견적의뢰자</TH>
	<TD><%=Order.get("REQUEST_MAN_NM") %></TD>
  </TR>
  
  <TR height="25"> 
	<TH>사업주</TH>
	<TD><%=Order.get("DEALER_NM") %></TD>
	<TH>CM/감리사</TH>
	<TD><%=Order.get("SUPERVISOR") %></TD> 	
	<TH>현장위치</TH>
	<TD><%=Order.get("WORK_PLACE") %></TD> 		
  </TR> 
  
  <TR height="25"> 
	<TH>공사기간</TH>
	<TD><%=Order.get("START_WORK_DATE") %>~<%=Order.get("END_WORK_DATE") %></TD>
	<TH>공사규모</TH>
	<TD><%=Order.get("WORK_SIZE") %></TD>
	<TH>공종</TH>
	<TD><%=Order.get("ITEM_NM") %></TD> 		
  </TR> 	
</TABLE>

<!-- 견적정보 : 시작 -->
<div class="application-info magT10">
	<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 colspan="3"><%=Order.get("QUOT_BID_FROM_DT") %>~<%=Order.get("QUOT_BID_TO_DT") %>&nbsp;<font color='red'><b>( <span id="dpTime"></span>)</b></font></TD>	
	<TH>견적유효기간</TH>
	<TD><%=Order.get("QUOT_VALIDATE") %></TD>
  </TR>
  
  <TR height="25"> 
  	<TH>견적담당자</TH>
	<TD><%=Order.get("QUOT_MAN_NM") %></TD>
	<TH>담당자 전화번호</TH>
	<TD><%=Order.get("QUOT_MAN_TELNO") %></TD>
	<TH>담당자 E-Mail</TH>
	<TD><%=Order.get("QUOT_MAN_EMAIL") %></TD> 	
  </TR>
  
  <TR height="25"> 
	<TH>담당자 FAX</TH>
	<TD><%=Order.get("QUOT_MAN_FAX") %></TD>
	<TH>견적설명회 일시</TH>
	<TD><%=Order.get("QUOT_SITEDESCDATE") %></TD>
	<TH>견적설명회 장소</TH>
	<TD><%=Order.get("QUOT_SITEDESCPLACE") %></TD>
  </TR>
  
  <TR height="25">
   	<TH style="background:#ffe1b5;text-align:center">참석의사</TD>
	<TD> 
		<select id="SITE_ATTEND_YN" >
			<option value="">- 선택 -</option>
			<option value="Y">참석</option>
			<option value="N">불참</option>
		</select>
	</TD> 
	
	<%
  	String		sitedescYn	=	"";
  	if(Order.get("SITEDESC_YN_NM").equals("불참"))
  	{
  		sitedescYn	=	"<font color='red'>"+Order.get("SITEDESC_YN_NM")+"</font>";
  	}
  	else
  	{
  		sitedescYn	=	"<font color='blue'>"+Order.get("SITEDESC_YN_NM")+"</font>";
  	}
    %>
	<TH style="background:#ffe1b5;text-align:center">참여상태</TD>
	<TD colspan="3"><B><%=sitedescYn%></B></TD>		
  </TR> 
</TABLE>

<div class="application-info magT20">
	<div class="application-sub-title">
		<span class="title">견적조건</span>
	</div>
</div>

<TABLE class="form-table" style="margin-top:5px">
	<colgroup>
		<col width="145"/>
		<col width="*"/>
		<col/>
	</colgroup>
  <TR height="100"> 
	<TH>특이사항</TH>
	<TD><%=StringUtils.cvtHTML(Order.get("OUTER_REMARKS")) %></TD>
  </TR>
  <TR height="100"> 
	<TH>견적자료</TH>
	<TD>
	<TEXTAREA name="p_AttachFile" id="p_AttachFile" style="width:85%;height:80px" rows="1" class="input" readOnly><%=fileout.get("DOC_ETC_OUT") %></TEXTAREA>
	                    <IMG id='search_spot_button' onClick="doAttachFile(document.form1.quot_id,1);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
	</TD>
  </TR>
  <TR height="10"> 
	<TH>대용량파일 link</TH>
	<%-- <TD><%=Order.get("URL_COL") %></TD>  --%>
	<TD><a href="<%=Order.get("URL_COL") %>" target="_blank"><%=Order.get("URL_COL") %></a></TD>
  </TR> 
</TABLE>
	
<div class="application-info magT20">
	<div class="application-sub-title">
		<span class="title">견적내역(부가세별도)</span>
	</div>
</div>

<TABLE class="form-table">  
	<colgroup>
		<col width="145"/>
		<col width="*"/>
		<col/>
	</colgroup>
  <TR height="25"> 
	<TH class="required">견적금액</TH>
	<TD><%= InputText.get("ESTI_TOT_AMT", Formatter2.currency(Order.get("ESTI_TOT_AMT"),0), 30, 15, "desc=견적금액,Number,right","Number") %>원</TD> 
  </TR>
  <TR>
	<TH>의견</TH>
	<TD>
	 	<textarea name="REMARK" id="REMARK" style="width:98%; height:80px; overflow-y:auto" maxlength="1000" class="input byteChk ctrlTarget" onkeyup="textareaResize(this)"><%=Order.get("REMARK")%></textarea>            
	</TD>
  </TR>
  <TR height="100"> 
	<TH class="required">첨부파일</TH>
	<TD>
	<TEXTAREA name="p_AttachFile2" id="p_AttachFile2" style="width:85%;height:80px" rows="1" class="input" readOnly><%=attid.get("ATT_ID") %></TEXTAREA>
	                    <IMG id='search_spot_button' onClick="doAttachFile(document.form1.quot_id,2);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
	</TD>
  </TR>
</TABLE>
	
</form>
