<%--
  - Author(s)  : Hyung min Son
  - Date       : 2014.07.02
  - Description: 구매_견적서작성
  --%>
  
<%@page import="monfox.toolkit.snmp.agent.modules.SnmpV2Mib.SysOREntry"%>
<%@ 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="com.udapsoft.waf.common.util.StringUtils" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ 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 file = storage.getValueObject(Order.get("FILE_GB"));
%>
<SCRIPT language="JavaScript">
	var sheet1 = new ibsheetObject();
	var sheet2 = new ibsheetObject();
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	var must_msg = "(은)는 필수 입력 항목입니다."; 
	function _onReady(){
		gridInit(sheet1);
		<%if(!"Y".equals(Order.get("DIV_PO_YN"))){ %>
		sheet1.SetSumValue(5,"합      계");
		<%}%>
		/**
		 *	Application Initialize
		 */
		 $("#btn_back").click(function() {
				$("#fevent").val("FORM_SELECT");
				$("#form1").attr("action", "/portal/bid/SuppBidResult.screen");
				$("#form1").attr("target", "_self");
				$("#form1").attr("method", "post");
				$("#form1").submit();
		});
		
		 $("#btn_signdata").click(function() {
			 if(makecheck()){
			 	fMakeItemInfo();
			 }
		});
		
		$("#btnExcelDown").click(function(){
			<%if("Y".equals(Order.get("DIV_PO_YN"))){ %>
				var params = { FileName : "(<%=Order.get("BID_NO")%>-<%=Order.get("BID_DEG")%>)견적서.xls",  SheetName : "(<%=Order.get("BID_NO")%>-<%=Order.get("BID_DEG")%>)견적서", SheetDesign:1 ,DownSum:false, DownCols:"MATERIAL_NAME|STD|UNIT_KIND|QTY|UNIT_COST"
					,	TitleText : "<%=Order.get("BID_MASTER_NM")%> 견적서 \r\n| |*단가 항목만 수정하여 업로드 바랍니다."
					,	UserMerge : "0,0,1,6 3,1,1,4"
				};
			<%}else{%>
				var params = { FileName : "(<%=Order.get("BID_NO")%>-<%=Order.get("BID_DEG")%>)견적서.xls",  SheetName : "(<%=Order.get("BID_NO")%>-<%=Order.get("BID_DEG")%>)견적서", SheetDesign:1 ,DownSum:false, DownCols:"MATERIAL_NAME|STD|UNIT_KIND|QTY|UNIT_COST|ROW_SUM_AMT"
					,	TitleText : "<%=Order.get("BID_MASTER_NM")%> 견적서 \r\n| |*단가 항목만 수정하여 업로드 바랍니다."
					,	UserMerge : "0,0,1,6 1,2,1,4"
					};
			<%}%>
			sheet1.Down2Excel(params);
		});
		doSearchSheet();
		
		<%if(!"Y".equals(Order.get("CURRENCY_GB_YN"))){%>
		$("#CURRENCY_GB").attr("disabled",true);
		<%}%>
		<%if(!"Y".equals(Order.get("DELIVERY_CONDITION_YN"))){%>
		$("#DELIVERY_CONDITION").attr("disabled",true);
		<%}%>
		$("#sheet2_div").hide();
	}

	function doSearchSheet(){
		$("#fevent").val("GET_ITEM_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/portal/bid/OutEstmWriteView_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
	}
	
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30};
		if(sheetName.id == "sheet1"){
			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:"MATERIAL_CD", 				Width:100, 			Align:"Left",			Hidden:"True"},
				    			{Header:'자재명',				Type:"Text", 			SaveName:"MATERIAL_NAME", 			Width:140, 			Align:"Left"},
				    			{Header:'규격',					Type:"Text", 			SaveName:"STD", 							Width:80, 			Align:"Left"},
				    			{Header:'단위',					Type:"Text", 			SaveName:"UNIT_KIND", 					Width:50, 			Align:"Center"},
				    			{Header:'수량',					Type:"Float", 			SaveName:"QTY", 							Width:50, 			Align:"Right"},
				    			{Header:'단가',					Type:"Float",			SaveName:"UNIT_COST", 					Width:80, 			Align:"Right",		PointCount:<%=Order.get("PointCount")%>},
				    			<%if(!"Y".equals(Order.get("DIV_PO_YN"))){ %>
				    			{Header:'금액',					Type:"AutoSum", 		SaveName:"ROW_SUM_AMT",			 	Width:80, 			Align:"Right", 	CalcLogic:"|QTY|*|UNIT_COST|",	PointCount:<%=Order.get("PointCount")%>}
				    			<%}%>
				    			
				];
		}
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetFocusEditMode(1);
		sheetName.SetEditEnterBehavior("down");
		sheetName.SetEditable(false);	
		setGridSize();
	}
	

	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
    		
    	/**
    	*		단가 계약일경우 모든 수량을 1로 변경
    	**/
    	<%if("Y".equals(Order.get("DIV_PO_YN"))){ %>
    	var GrowCount = sheet1.LastRow();
		 for(var	i=0; i < 	GrowCount; i++)
			{
				 sheet1.SetCellValue(i+1,"QTY",1);	
			}
    	<%}%>
		} else {
			//조회 에러 수행
			alert(message);
		}
		var GrowCount = sheet1.LastRow();
		var amt = sheet1.GetCellValue(GrowCount,"UNIT_COST");
		if(amt != ""){
			$("#TOT_AMT_CK").val(amt);
			var arrAmt = $("#TOT_AMT_CK").val().split(".");
			if(arrAmt.length > 1){
				$("#TOT_AMT").val(formatComma(amt,cost_point));
			}else{
				$("#TOT_AMT").val(amt);
				$("#TOT_AMT").val($("#TOT_AMT").val().split(/(?=(?:\d{3})+(?:\.|$))/g).join(','));
			}
		}
		
	    sheet1.FitColWidth();
	    
	    //크롬 문제 
	    if(sheet1.GetSheetWidth() > 450){
	    	sheet1.SetSheetWidth(450);
	    	sheet1.SetSheetWidth($("#sheettable").width());
	    	sheet1.FitColWidth();
	    }
	    autoResize();
	}
	/**
	 *	IBSheet Event: Click
	 */
	function sheet1_OnClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		//alert("Row :" + Row + "              Col : " +Col);	 
	 }
	
	/**
	 *	IBSheet size setting
	 */
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	function sheet1_OnChange(Row, Col, Value) {

	}
	
	 function numberFormat(num) {
		 var pattern = /(-?[0-9]+)([0-9]{3})/;
		 while(pattern.test(num)) {
			 num = num.replace(pattern,"$1,$2");
		 }
		 return num;
	 }
	 
	//첨부파일   
	function doAttachFile(obj) {
		if(obj==''){
			alert("After you have saved, you can attach a file.");
		}else if(obj != ''){ 
			viewFileListNew("<%=Order.get("FILE_GB")%>", obj.value, document.form1.p_AttachFile, "N", "bid/outside/<%=Order.get("BID_NO")%>/<%=Order.get("VENDOR_CD")%>/");
		} 
	}
	
	function doResult(resultObj) {

	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
	}
	

	function autoResize(){
		var setheight = $("#table_a").height() - $("#table_b").height() - 50;
		sheet1.SetSheetHeight(setheight);
		sheet1.SetSheetWidth($("#sheettable").width());
	}

		
	// radio 박스 체크
	function must_ck_radio(obj,name){
		var value   = $(':radio[name='+obj+']:checked').val();
		if(value == undefined){
			alert("["+name+"] 항목에 견적포함여부 혹은 수용여부를 선택해주세요.");
			var id = $(':radio[name='+obj+']').attr("id");
			$("#"+id).focus();
			return true;
		}
 		return false;
	}
	
	function AddZero(str){
		
		if((str+"").length==1){
			return "0"+str;
		}	
		return str;
	}
		
	function sheet1_OnSaveEnd(code, msg)
	{
		var event = $("#fevent").val();

	}

	
	function isEmptyVal( value ) {
		if(value.length == 0){
			return true;
		}
		if( value == "" ) {
			return true;
		}
		return false;
	}

	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">
<INPUT type='hidden' name="fevent" id="fevent"  value="">
<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="BID_NO" value="<%=Order.get("BID_NO")%>">
<INPUT type='hidden' name="BID_DEG" value="<%=Order.get("BID_DEG")%>">
<INPUT type='hidden' name="STATUS_CD" value="<%=Order.get("STATUS_CD")%>">
<INPUT type='hidden' name="VENDOR_CD" value="<%=user.get("CORP_ID")%>">
<INPUT type='hidden' name="FILE_GB" value="<%=Order.get("FILE_GB")%>">
<INPUT type='hidden' name="ATT_ID" value="<%=Order.get("ATT_ID")%>">
<INPUT type='hidden' name="ESTI_SIGNDATA" value="">
<INPUT type='hidden' name="sItemInfo" value="">
<INPUT type='hidden' name="signeddata" value="">

<table width="100%">
	<colgroup>
		<col width="*" />
		<col width="130" />
	</colgroup>
	<tr>
   		<th>
	   		<div align="left" id="title" >
 			  <ul><li>제출견적보기</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 magT10" >
	<div class="application-sub-title">
		<span class="title">견적정보</span>
	</div>
</div>
<TABLE class="form-table" style="margin-top:3px">
	<colgroup>
		<col width="160">
		<col/>
	</colgroup>
	<TR height="25"> 
		<TH style="text-align:left">사업자번호</TH>
		<TD><%=StringUtils.getBizNo(user.get("CORP_REG_NO")) %></TD>
	</TR>
	<TR height="25">     
		<TH style="text-align:left"> 업체명</TH>
		<TD><%=user.get("CORP_KOR")%></TD>
	</TR>
	<%if(!"Y".equals(Order.get("DIV_PO_YN"))){ %>
	<TR height="25"> 
		<TH style="text-align:left"> 견적합계금액</TH>
		<TD><%= Order.get("ESTI_TOT_AMT") %></TD>
	</TR>
	<%} %>
		<TR height="25"> 
		<TH style="text-align:left"> 견적제출기간</TH>
		<TD><%=Order.get("BID_FROM_DT")%> ~<%=Order.get("BID_TO_DT")%></TD>
		
	</TR>
	
	
</table>


<TABLE width="100%">
	<colgroup>
		<col width="50%">
		<col width="50%"/>
	</colgroup>
<tr><td valign="top"  rowspan="2" >
	<div class="application-info magT10" >
	<div class="application-sub-title">
		<span class="title">견적조건</span>
	</div>
</div>
<TABLE class="form-table" id="table_a" style="min-width:600px ">
	<colgroup>
		<col width="160">
		<col width="30%">
		<col/>
	</colgroup>
  <TR height="25"> 
	<TH style="text-align:left">견적통화</TH>
	<TD colspan="2"><%=Order.get("VIEW_CURRENCY_GB")%><%if("Y".equals(Order.get("CURRENCY_GB_YN"))){%>&nbsp;(견적의뢰 통화 : <%=Order.get("CURRENCY_GB_NM")%>) * 업체 변경가능<%} %></TD>
	
  </TR>
  <% if("Y".equals(Order.get("PBC_INSTALL_YN"))){ %>
	<TR height="25">
		<TH style="text-align:left">Installation</TH>
		<TD colspan="2">
			<%=Order.get("INSTALL_YN").equals("Y") ? "included" : "not included" %>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_COMMISS_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Spare parts for<br>Commissioning</TH>
		<TD colspan="2"><%=Order.get("COMMISS_YN").equals("Y") ? "included" : "not included" %>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_SPETOOL_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Special Tool</TH>
		<TD colspan="2"><%=Order.get("SPETOOL_YN").equals("Y") ? "included" : "not included" %>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_TEST_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Test & Inspection at<br>Fabrication shop</TH>
		<TD colspan="2"><%=Order.get("SPETOOL_YN").equals("Y") ? "included" : "not included" %>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_DOC_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Documentation</TH>
		<TD colspan="2"><%=Order.get("DOC_YN").equals("Y") ? "included" : "not included" %>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_PACK_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Packing cost</TH>
		<TD colspan="2"><%=Order.get("PACK_YN").equals("Y") ? "included" : "not included" %>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_LANDTRAN_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Inland Transportaion</TH>
		<TD colspan="2"><%=Order.get("LANDTRAN_YN").equals("Y") ? "included" : "not included" %>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("DELIVERY_CONDITION_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Delivery Condition</TH>
		<TD colspan="2"><%=Order.get("DELIVERY_CONDITION")%>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_FEE_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left">Supervision fee</TH>
		<TD colspan="2"><%=Order.get("FEE_NOTI")%>
		</TD>
	</TR>
	<%} if("Y".equals(Order.get("PBC_OPTION_YN"))){ %>
	<TR height="25">	
		<TH style="text-align:left"><%=Order.get("PBC_OPTION_COMMENT")%></TH>
		<TD colspan="2"><%=Order.get("OPTION_NOTI")%>
		</TD>
	</TR>
	<%} %>
	<TR height="25">	
		<TH style="text-align:left">Quotation No</TH>
		<TD colspan="2"><%=Order.get("QUOT_NO")%>
		</TD>
	</TR>
	<TR height="25">	
		<TH style="text-align:left">Payment Condition</TH>
		<TD><%=Order.get("PAYCONDI_YN").equals("Y") ? "accept" : "not accept" %>
		<%if(!Order.get("CBC_FIRST_RATE").isEmpty()){%><br>선급금 : <%=Order.get("CBC_FIRST_RATE") %>%(계약금액 기준)<%} %>
		<%if(!Order.get("CPC_MID_RATE").isEmpty()){%><br>중도금 : <%=Order.get("CPC_MID_RATE") %>%(계약금액 기준)<%} %>
		<%if(!Order.get("PBC_REST_RATE").isEmpty()){%><br>잔 금 &nbsp;&nbsp;: <%=Order.get("PBC_REST_RATE") %>%(계약금액 기준)<%} %>
		
		</TD>
		<TD><TEXTAREA name="PAYCONDI_NOT_NOTI" id="PAYCONDI_NOT_NOTI" style="width:91%;height:50px" rows="1" class="input" readOnly><%=Order.get("PAYCONDI_NOT_NOTI") %></TEXTAREA></TD>
	</TR>
	<TR height="25">	
		<TH style="text-align:left">Performance Bond</TH>
		<TD colspan="2"><%=Order.get("CONTFUL_RATE") %>%(계약금액 기준) <%=Order.get("CONTFUL_YN").equals("Y") ? "accept" : "not accept" %>
		<br/><TEXTAREA name="CONTFUL_NOT_NOTI" id="CONTFUL_NOT_NOTI" style="width:95%;height:30px" rows="1" class="input" readOnly><%=Order.get("CONTFUL_NOT_NOTI") %></TEXTAREA>
		</TD>
	</TR>
	<TR height="25">	
		<TH style="text-align:left">First Payment Bond</TH>
		<TD colspan="2">
		<%=Order.get("PBC_FRSTGUAR_RATE") %>%(계약금액 기준) <%=Order.get("FRSTGUAR_YN").equals("Y") ? "accept" : "not accept" %>
		 <br/><TEXTAREA name="FRSTGUAR_NOT_NOTI" id="FRSTGUAR_NOT_NOTI" style="width:95%;height:30px" rows="1" class="input" readOnly><%=Order.get("FRSTGUAR_NOT_NOTI") %></TEXTAREA>
		</TD>
	</TR>
	<TR height="25">	
		<TH style="text-align:left">Guarantee Bond</TH>
		<TD colspan="2"><%=Order.get("WARR_RATE") %>%(계약금액 기준) <%=Order.get("WARR_YN").equals("Y") ? "accept" : "not accept" %>
		 <br/><TEXTAREA name="WARR_NOT_NOTI" id="WARR_NOT_NOTI" style="width:95%;height:30px" rows="1" class="input" readOnly><%=Order.get("WARR_NOT_NOTI") %></TEXTAREA>
		</TD>
	</TR>
	<TR height="25">	
		<TH style="text-align:left">Guarantee Period</TH>
		<TD colspan="2">설치완료일로부터 <%=Order.get("CBC_DEFECT_DAY") %><%=Order.get("CBC_DERECT_TERM_NM") %>간 <%=Order.get("DEFECT_YN").equals("Y") ? "accept" : "not accept" %>
		 <br/><TEXTAREA name="DEFECT_NOT_NOTI" id="DEFECT_NOT_NOTI" style="width:95%;height:30px;" rows="1" class="input" readOnly><%=Order.get("DEFECT_NOT_NOTI") %></TEXTAREA>
		</TD>
	</TR>
	<TR height="50">	
		<TH style="text-align:left">OTHERS TO BE<br>CONFIRMED</TH>
		<TD colspan="2">
		 <TEXTAREA name="BID_CONDI_NOTI" id="BID_CONDI_NOTI" style="width:95%;height:30px" rows="1" class="input" readOnly><%=Order.get("BID_CONDI_NOTI") %></TEXTAREA>
		</TD>
  </TR>
</TABLE>
</TD>
<TD style="padding-left:5px;" valign="top">
	<table id=sheettable style="width:100%;height:25px;margin-top:-4px;">
		<colgroup>
			<col width="*" />
			<col width="200" />
		</colgroup>
		<tr heigth="25">
	   		<th>
	   		<div class="application-info magT10">
				<div class="application-sub-title">
					<span class="title">견적내역(부가세별도)</span>
				</div>
			</div>
	   		</th>
	   		<td align="right">
	       		<span class="btnSearch center" id="btnExcelDown"><a href="javascript:void(0);">Excel Down</a></span>
	   		</td>
	  	</tr>
	</table>
		<div id="sheet1_div" style="height: auto; min-height:100px;width:100%; overflow: auto;height:100%">
			<script>createIBSheet('sheet1','100%', '450px');</script>
		</div>
</TD>
</TR>
<TR><TD style="padding-left:5px;" valign="bottom" width="*">
<div class="application-info magT10" >
	<div class="application-sub-title">
		<span class="title">첨부파일</span>
	</div>
</div>
	<TABLE class="form-table" id="table_b">
		<colgroup>
			<col width="160">
			<col/>
		</colgroup>
	  <TR height="100"> 
		<TH style="text-align:left"> 첨부파일</TD>
		<TD>
		 <TEXTAREA name="p_AttachFile" id="p_AttachFile" style="width:85%;height:80px" rows="1" class="input" readOnly><%=file.get(Order.get("FILE_GB")) %></TEXTAREA>
		                    <IMG id='search_spot_button' onClick="doAttachFile(document.form1.DEMANDED_ID);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:pointer;'>
		</TD>
	  </TR>  
	</TABLE>
</TD>
</TR>
</TABLE>
</form>
</div>