<%--
  - Author(s)  : chj
  - Date       : 2015-02-24
  - Description: 분할발주 업체선정
  --%>
  
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.system.*" %>
<%@ page import="com.udapsoft.waf.common.*" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.util.StringUtils"%>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.udapsoft.common.*" %>
<%@ page import="kr.co.udapsoft.ebid.buyer.common.file.FileManager"%>
<%@ 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 user       = ctx.getUser();
    ValueObject params     = storage.getParams();
    String event           = storage.getEvent();
    String BID_NO =   (String) storage.get("BID_NO");
	String BID_DEG =   (String) storage.get("BID_DEG");
	String pop_win_id =   (String) storage.get("pop_win_id");
    ValueObject divCont = storage.getValueObject("divCont");
    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    System.out.println(divCont);
    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
%>

<SCRIPT language="JavaScript">
	
	function _onReady(){
		gridInit(sheet1);
		
		jQuery("#btn_search").click(function(){
			doSearchSheet();
		});
		
		jQuery("#btn_save").click(function(){
			jQuery("#fevent").val("SAVE_VENDOR_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/purchase/DivContPop_sheet.screen";
			Modular.view.IBSheet7.doSave(sheet1, url, jQuery("#form1"), 30, "");
		});
		
		doSearchSheet();
	}
	
	/**
	 *	IBSheet object initialize
	 */
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:30 , MergeSheet:msHeaderOnly};
		init_sheet.Cols = [
		    			{Header:'상태|상태',								Type:"Status", 			SaveName:"STATUS", 				Width:100, 		Align:"Right",   Edit:false, Hidden:true},
		    			{Header:'자재코드|자재코드',							Type:"Text", 			SaveName:"MATERIAL_CD", 		Width:100, 		Align:"Right",   Edit:false, Hidden:true},
		    			{Header:'자재명|자재명',							Type:"Text", 			SaveName:"MATERIAL_NM", 		Width:150,		Align:"Left",    Edit:false},
		    			{Header:'규격|규격',								Type:"Text", 			SaveName:"MATERIAL_SPEC", 		Width:120,		Align:"Left",    Edit:false},
		    			{Header:'단위|단위',								Type:"Text", 			SaveName:"UNIT_KIND", 			Width:80, 		Align:"Center",  Edit:false},
		    			{Header:'견적의뢰수량|견적의뢰수량',					Type:"Float", 			SaveName:"ESTI_QTY", 			Width:100, 		Align:"Right",   Edit:false},
		    			{Header:'잔량|잔량',								Type:"Float", 			SaveName:"REMAIN_QTY", 			Width:100, 		Align:"Right",   Edit:false, CalcLogic:"|ESTI_QTY|-|V1_SELECT_QTY|-|V2_SELECT_QTY|-|V3_SELECT_QTY|-|V4_SELECT_QTY|-|V5_SELECT_QTY|"},
		    			{Header: '<%=divCont.get("V1")%>'+'|선정수량',		Type:"Float",	 		SaveName:"V1_SELECT_QTY", 		Width:70, 		Align:"Right",   Edit:true, PointCount:2},
		    			{Header:'<%=divCont.get("V1")%>'+'|단가',			Type:"Float", 			SaveName:"V1_UNIT_COST", 		Width:100, 		Align:"Right",   Edit:false, PointCount:'<%=divCont.get("V1_POINT")%>'},
		    			{Header:'<%=divCont.get("V1")%>'+'|금액',			Type:"Float", 			SaveName:"V1_SELECT_AMT", 		Width:100, 		Align:"Right",   Edit:false, CalcLogic:"|V1_SELECT_QTY|*|V1_UNIT_COST|", PointCount:'<%=divCont.get("V1_POINT")%>'},
		    			{Header:'<%=divCont.get("V2")%>'+'|선정수량',		Type:"Float", 			SaveName:"V2_SELECT_QTY", 		Width:70, 		Align:"Right",   Edit:true, PointCount:2},
		    			{Header:'<%=divCont.get("V2")%>'+'|단가',			Type:"Float", 			SaveName:"V2_UNIT_COST", 		Width:100, 		Align:"Right",   Edit:false, PointCount:'<%=divCont.get("V2_POINT")%>'},
		    			{Header:'<%=divCont.get("V2")%>'+'|금액',			Type:"Float", 			SaveName:"V2_SELECT_AMT", 		Width:100, 		Align:"Right",   Edit:false, CalcLogic:"|V2_SELECT_QTY|*|V2_UNIT_COST|", PointCount:'<%=divCont.get("V2_POINT")%>'},
		    			{Header:'<%=divCont.get("V3")%>'+'|선정수량',		Type:"Float", 			SaveName:"V3_SELECT_QTY", 		Width:70, 		Align:"Right",   Edit:true, PointCount:2},
		    			{Header:'<%=divCont.get("V3")%>'+'|단가',			Type:"Float", 			SaveName:"V3_UNIT_COST", 		Width:100, 		Align:"Right",   Edit:false, PointCount:'<%=divCont.get("V3_POINT")%>'},
		    			{Header:'<%=divCont.get("V3")%>'+'|금액',			Type:"Float", 			SaveName:"V3_SELECT_AMT", 		Width:100, 		Align:"Right",   Edit:false, CalcLogic:"|V3_SELECT_QTY|*|V3_UNIT_COST|", PointCount:'<%=divCont.get("V3_POINT")%>'},
		    			{Header:'<%=divCont.get("V4")%>'+'|선정수량',		Type:"Float", 			SaveName:"V4_SELECT_QTY", 		Width:70, 		Align:"Right",   Edit:true, PointCount:2},
		    			{Header:'<%=divCont.get("V4")%>'+'|단가',			Type:"Float", 			SaveName:"V4_UNIT_COST", 		Width:100, 		Align:"Right",   Edit:false, PointCount:'<%=divCont.get("V4_POINT")%>'},
		    			{Header:'<%=divCont.get("V4")%>'+'|금액',			Type:"Float", 			SaveName:"V4_SELECT_AMT", 		Width:100, 		Align:"Right",   Edit:false, CalcLogic:"|V4_SELECT_QTY|*|V4_UNIT_COST|", PointCount:'<%=divCont.get("V4_POINT")%>'},
		    			{Header:'<%=divCont.get("V5")%>'+'|선정수량',		Type:"Float", 			SaveName:"V5_SELECT_QTY", 		Width:70, 		Align:"Right",   Edit:true, PointCount:2},
		    			{Header:'<%=divCont.get("V5")%>'+'|단가',			Type:"Float", 			SaveName:"V5_UNIT_COST", 		Width:100, 		Align:"Right",   Edit:false, PointCount:'<%=divCont.get("V5_POINT")%>'},
		    			{Header:'<%=divCont.get("V5")%>'+'|금액',			Type:"Float", 			SaveName:"V5_SELECT_AMT", 		Width:100, 		Align:"Right",   Edit:false, CalcLogic:"|V5_SELECT_QTY|*|V5_UNIT_COST|", PointCount:'<%=divCont.get("V5_POINT")%>'},
		    			{Header:'업체1|업체1',								Type:"Text", 			SaveName:"V1_VENDOR_CD", 		Width:100, 		Align:"Right",   Edit:false, Hidden:true},
		    			{Header:'업체2|업체2',								Type:"Text", 			SaveName:"V2_VENDOR_CD", 		Width:100, 		Align:"Right",   Edit:false, Hidden:true},
		    			{Header:'업체3|업체3',								Type:"Text", 			SaveName:"V3_VENDOR_CD", 		Width:100, 		Align:"Right",   Edit:false, Hidden:true},
		    			{Header:'업체4|업체4',								Type:"Text", 			SaveName:"V4_VENDOR_CD", 		Width:100, 		Align:"Right",   Edit:false, Hidden:true},
		    			{Header:'업체5|업체5',								Type:"Text", 			SaveName:"V5_VENDOR_CD", 		Width:100, 		Align:"Right",   Edit:false, Hidden:true},
		    			
		];
		init_sheet.HeaderMode = {Sort:1,HeaderCheck:false};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheet1.SetEditable(true);
	}
	/*시트 조회*/
	function doSearchSheet(){
		$("#fevent").val("GET_VENDOR_LIST");
		var url = Modular.model.PageContext.CONTEXT_ROOT + "/bid/purchase/DivContPop_sheet.screen";
		Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 30, "");
	}
	
	
	/*시트 조회후 로직*/
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	if("<%=divCont.get("V1")%>" == ""){
	    		sheet1.SetColEditable("V1_SELECT_QTY",false);
	    	}
	    	if("<%=divCont.get("V2")%>" == ""){
	    		sheet1.SetColEditable("V2_SELECT_QTY",false);
	    	}
	    	if("<%=divCont.get("V3")%>" == ""){
	    		sheet1.SetColEditable("V3_SELECT_QTY",false);
	    	}
	    	if("<%=divCont.get("V4")%>" == ""){
	    		sheet1.SetColEditable("V4_SELECT_QTY",false);
	    	}
	    	if("<%=divCont.get("V5")%>" == ""){
	    		sheet1.SetColEditable("V5_SELECT_QTY",false);
	    	}
	    	
	    	//sheet1.FitColWidth();
		} else {
			alert(message);
		}
	}
	
	/*시트 저장후 로직*/
	function sheet1_OnSaveEnd(code, msg)
	{
		if(code>= "0"){
			alert("저장되었습니다.");
		}else{
			alert("에러가 발생 하였습니다.\n" + msg);
		}
		
	}
	
	/*시트 validation 이벤트*/
 	function sheet1_OnChange(Row, Col, Value) {
		var sSaveName = sheet1.ColSaveName(Col);
		 if (sSaveName == "V1_SELECT_QTY") {
			 if(sheet1.GetCellValue(Row, "REMAIN_QTY") < 0){
				 alert("잔여가 0보다 적으면 안됩니다.");
			 }
		 }else if(sSaveName == "V2_SELECT_QTY"){
			 if(sheet1.GetCellValue(Row, "REMAIN_QTY") < 0){
				 alert("잔여가 0보다 적으면 안됩니다.");
			 }
		 }else if(sSaveName == "V3_SELECT_QTY"){
			 if(sheet1.GetCellValue(Row, "REMAIN_QTY") < 0){
				 alert("잔여가 0보다 적으면 안됩니다.");
			 }
		}else if(sSaveName == "V4_SELECT_QTY"){
			 if(sheet1.GetCellValue(Row, "REMAIN_QTY") < 0){
				 alert("잔여가 0보다 적으면 안됩니다.");
			 }
		}else if(sSaveName == "V5_SELECT_QTY"){
			 if(sheet1.GetCellValue(Row, "REMAIN_QTY") < 0){
				 alert("잔여가 0보다 적으면 안됩니다.");
			 }
		}
	} 
 	
	function sheet1_OnValidation(Row, Col, Value) {
		 if(sheet1.GetCellValue(Row, "REMAIN_QTY") < 0){
			 alert("잔여가 0보다 적으면 안됩니다.");
			 sheet1.ValidateFail(1);
		 }
	}
		 
 

		 

	
</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="BID_NO" value="<%=BID_NO%>">
<INPUT type='hidden' name="BID_DEG" value="<%=BID_DEG%>">
<INPUT type='hidden' name="V1_CD" value="<%=divCont.get("V1_CD")%>">
<INPUT type='hidden' name="V2_CD" value="<%=divCont.get("V2_CD")%>">
<INPUT type='hidden' name="V3_CD" value="<%=divCont.get("V3_CD")%>">
<INPUT type='hidden' name="V4_CD" value="<%=divCont.get("V4_CD")%>">
<INPUT type='hidden' name="V5_CD" value="<%=divCont.get("V5_CD")%>">
<TABLE class="screen_title_table">
  <TR height="2"><TD colspan="2"></TD>
  </TR>
  <TR height="25"><TD>
  	<!-- 제목 및 버튼 -->
   	<table id="t1" width="100%" class="ftit_table">
		<colgroup>
			<col width="*" />
			<col width="150" />
		</colgroup>
	<tr>
	   	<th align="left">기술검토 상태 :</th>
	   <td align="right">
	        <span class="btnSearch center" id="btn_search"><a href="javascript:void(0);" id="btnSearch">조회</a></span>
	        <span class="btnSearch center" id="btn_save"><a href="javascript:void(0);" id="btn_save">저장</a></span>
	   </td>
   	</tr>
   	</table>
    </TD>
  </TR>
  </TABLE>
	<div id="sheet1_div" style="padding-top:5px;height: auto; min-height: 450px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '450px');</script>
	</div>
</form>

