<%--
  - FileName   : SuppJoinRequestList.jsp
  - Author(s)  : Sung Min Lee
  - Date       : 2014.06.24
  -
  - 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.*" %>
<%@ 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();
    String event = storage.getEvent();
    

    RowSet materialKindCodeLv1 = new RowSetImpl();
	RowSet materialKindCodeLv2 = new RowSetImpl();
	RowSet materialKindCodeLv3 = new RowSetImpl();
	
	String bid_kind = storage.get("BID_KIND");
	String menu = storage.get("MENU");
    String out_item_cd = storage.get("OUT_ITEM_CD");
    String material_gb = storage.get("MATERIAL_GB");
%>
<script type="text/javascript">
<!--
	/*예약함수*/
	var sheet1 = new ibsheetObject();
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	var outitemcd = "<%=out_item_cd%>";
	var Lv1 = outitemcd.substring(0,2);
	var Lv2 = outitemcd.substring(0,4);
	var Lv3 = outitemcd.substring(0,6);
	
	$(document).on("keyup", "input:text[numberOnly]", function() {$(this).val( $(this).val().replace(/[^0-9]/gi,"") );});
	
	$(document).ready(function(){
	    
		var init_sheet = {};
		
		init_sheet.Cfg = {SearchMode:2, Page:30, MergeSheet:msHeaderOnly};
		init_sheet.Cols = [
									{Header:"Status",				Type:"Status", 		SaveName:"STATUS", 			Width:10, 	Align:"Center",  Hidden:"True"},
									{Header:"선택",				Type:"CheckBox", 	SaveName:"CHECK",				Width:25, 	Align:"Center", ColMerge:"False"},
									{Header:"CORP_ID",			Type:"Text", 			SaveName:"CORP_ID",			Width:100, 	Align:"Center", Edit:"False", Hidden:"True"},
									{Header:"사업자번호",		Type:"Text", 			SaveName:"CORP_REG_NO",	Width:40, 	Align:"Center", Edit:"False", Format:"SaupNo"},
									{Header:"업체명",				Type:"Text", 			SaveName:"CORP_KOR", 		Width:60, 	Align:"Left", Edit:"False", ToolTip:1},
									{Header:"의견",				Type:"Text", 			SaveName:"COMMENT", 		Width:60, 	Align:"Left", Edit:"False", ToolTip:1},
									{Header:"대표자명",			Type:"Text", 			SaveName:"REP_NAME", 		Width:50, 	Align:"Center", Edit:"False"},
									{Header:"담당자명",			Type:"Text", 			SaveName:"USER_NAME", 		Width:50, 	Align:"Center", Edit:"False", ColMerge:"False"},
									{Header:"핸드폰",				Type:"Text", 			SaveName:"H_PHON", 			Width:50, 	Align:"Center", Edit:"False", ColMerge:"False"},
									{Header:"연락처",				Type:"Text", 			SaveName:"TEL_NUM", 			Width:50, 	Align:"Center", Edit:"False", Hidden:"True", ColMerge:"False"},
									{Header:"이메일",				Type:"Text", 			SaveName:"EMAIL", 				Width:60, 	Align:"Left", Edit:"False", ColMerge:"False"},
									{Header:"평가점수",			Type:"Text", 			SaveName:"APPR_TOT_RATE", 		Width:30, 	Align:"Center", Edit:"False", Hidden:"True", ColMerge:"False"},
									{Header:"입찰여부",			Type:"Text", 			SaveName:"VALID_BID_YN_NM",		Width:30, 	Align:"Center", Edit:"False", Hidden:"True", ColMerge:"False"},
									{Header:"VALID_BID_YN",		Type:"Text", 			SaveName:"VALID_BID_YN", 		Width:40, 	Align:"Center", Edit:"False", Hidden:"True", ColMerge:"False"},
									{Header:"IN_OUT_DIV",		Type:"Text", 			SaveName:"IN_OUT_DIV", 			Width:40, 	Align:"Center", Edit:"False", Hidden:"True", ColMerge:"False"},
		                   		];
		
		
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheet1, init_sheet);
		sheet1.SetDataAutoTrim(0);
// 		sheet1.SetEditable(true);
		//sheet1.SetMergeSheet(msAll);
// 		sheet1.SetMergeSheet(msPrevColumnMerge);
		sheet1.SetDataLinkMouse("CORP_REG_NO");		
		sheet1.SetDataLinkMouse("COMMENT", 1);
		sheet1.SetColFontColor("COMMENT", "#0000ff");
		
		sheet1.FitColWidth();
		
		var bidkind = "<%=bid_kind%>";
		var menu = "<%=menu%>";
		
		if(bidkind.length > 0){
			$("#corp_status").val(bidkind);
			submitXmlRequest("/common/corp/SuppChoicePop_form.screen", "GET_MATL_KIND_CODE_LV1", document.form1, "ROWSET");			
			$("#corp_status").attr("disabled","disabled");
		}
		
		if(menu.length > 0){
			$("#menu_type").val(menu);			
		}
	});
	
	

	$(function(){
		
		$("#btn_search").click(function(){
			$("#fevent").val("GET_CORP_LIST");
			
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/common/corp/SuppChoicePop_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, $("#form1"), 30, "");
		});
		
		$("#corp_no").keydown(function (event)
		{
			var keycode = (event.keyCode ? event.keyCode : event.which);
			if(keycode == 13)$("#btn_search").click();
		});
		
		$("#corp_name").keydown(function (event)
		{
			var keycode = (event.keyCode ? event.keyCode : event.which);
			if(keycode == 13)$("#btn_search").click();
		});
		
		$("#btn_close").click(function(){
		    parent.fLayerPopClose("corp");
		});
		
		
		$("#corp_status").change(function(){
		    var f = document.form1;

		    $("#material_Kind_Code_Lv2").empty().data("options"); 
		    $("#material_Kind_Code_Lv2").append("<option value=''>-- 전체 --</option>");
		    
		    $("#material_Kind_Code_Lv3").empty().data("options"); 
		    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
		    
		    submitXmlRequest("/common/corp/SuppChoicePop_form.screen", "GET_MATL_KIND_CODE_LV1", f, "ROWSET");
		    
		});
		
		
		
		
		$("#material_Kind_Code_Lv1").change(function(){
		    
		    
		    var f = document.form1;
		    
		    if($("#material_Kind_Code_Lv1").val().trim() == "")
		    {
			    $("#material_Kind_Code_Lv2").empty().data("options"); 
			    $("#material_Kind_Code_Lv2").append("<option value=''>-- 전체 --</option>");
			    
			    $("#material_Kind_Code_Lv3").empty().data("options"); 
			    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
		    }
			else
			{
			    $("#fevent").val("GET_MATL_KIND_CODE_LV2");
			    
			    $("#materiallevel").val("2");
			    $("#materialgroup").val($("#material_Kind_Code_Lv1").val());
			    
			    submitXmlRequest("/common/corp/SuppChoicePop_form.screen", "GET_MATL_KIND_CODE_LV2", f, "ROWSET");
			}
		    $("#btn_search").click();
		});
		
		$("#material_Kind_Code_Lv2").change(function(){
		    
		    var f = document.form1;
		    
		    if($("#material_Kind_Code_Lv2").val().trim() == "")
		    {
			    $("#material_Kind_Code_Lv3").empty().data("options"); 
			    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
		    }
		    else
		    {
		        $("#fevent").val("GET_MATL_KIND_CODE_LV3");
			    $("#materiallevel").val("3");
			    $("#materialgroup").val($("#material_Kind_Code_Lv2").val());
			    
			    submitXmlRequest("/common/corp/SuppChoicePop_form.screen", "GET_MATL_KIND_CODE_LV3", f, "ROWSET");
		    }    
		});
		
		
		
		
		$("#btn_select").click(function(){
		    
		    var len = sheet1.LastRow();
		    
		    var corp_id		= new Array;
	     	var corp_reg_no	= new Array;
	     	var corp_kor = new Array;
	     	var rep_name = new Array;
	     	var user_name = new Array;
	     	var tel_num = new Array;
	     	var h_phon = new Array;
	     	var email = new Array;
	     	var in_out_div = new Array;
		    
	     	var idx = 0;
     	   if(len>=1)
     	   {
     	      for(var i=1; i<=len; i++)
  	    	  {
  		      	if(sheet1.GetCellValue(i,"CHECK") == "1")
  	   			{
  		            corp_id[idx] = sheet1.GetCellValue(i, "CORP_ID");
  		          	corp_reg_no[idx] = sheet1.GetCellValue(i, "CORP_REG_NO");
  		          	corp_kor[idx] = sheet1.GetCellValue(i, "CORP_KOR");
  		        	rep_name[idx] = sheet1.GetCellValue(i, "REP_NAME");
  		        	user_name[idx] = sheet1.GetCellValue(i, "USER_NAME");
  		        	tel_num[idx] = sheet1.GetCellValue(i, "TEL_NUM");
  		        	h_phon[idx] = sheet1.GetCellValue(i, "H_PHON");
  		        	email[idx] = sheet1.GetCellValue(i, "EMAIL");
  		        	in_out_div[idx] = sheet1.GetCellValue(i, "IN_OUT_DIV");
  		        	idx++;
  	   			}
  		      	
  	    	  }
     	      
     	     var returnValue = new Array(corp_id, corp_reg_no, corp_kor, rep_name, user_name, tel_num, h_phon, email, in_out_div);
     	     
//      	     parent.resultFuntion(returnValue);
				window.parent.$.test(returnValue);
				//parent.fLayerPopClose("corp");
     	   }
		});
		
		
// 		$.test('qwe');		
	});

	
	/*
	function sheet1_OnClick(Row, Col)
	{
	    var s_name = sheet1.ColSaveName(Col);
	    alert(sheet1.GetCellValue(i,"CHECK"));
	    
	    if(s_name == "CORP_REG_NO")
	    {
	        $("#fevent").val("GET_DETAIL");
	        $("#p_corp_id").val(sheet1.GetCellValue(Row, "CORP_ID"));
	        $("#p_charge_seq").val(sheet1.GetCellValue(Row, "CHARGE_SEQ"));
	        
	        $("#form1").attr("action", "/supplier/purchase/SuppJoinRequest.screen");
			$("#form1").attr("target", "_self");
			$("#form1").attr("method", "post");
			$("#form1").submit();
	    }
	}
	*/
	/**
	 *	IBSheet Event: Search End(IBSheet 데이터 조회 CallBack)
	 */
	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	sheet1.FitColWidth();
	    	
	    	if($("#corp_status").val() == "P"){
	    		if($("#menu_type").val() != "QUOT"){
	    			sheet1.SetColHidden("APPR_TOT_RATE",0);
		    		sheet1.SetColHidden("VALID_BID_YN_NM",0);	
	    		}
	    	}
	    } else {
			//조회 에러 수행
			alert(message);
		}
	}

	function sheet1_OnDblClick(Row, Col, Value)
	{
		var s_name = sheet1.ColSaveName(Col);
		
		if(s_name == "COMMENT") {
        	dlgAlert(sheet1.GetCellValue(Row, "COMMENT"));
	    }
	}
	
	function doResult(resultObj) {
		
		try {
		    if ( resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV1" ) 
			{
		        if ( resultObj.getSuccess() == true ) 
				{
					var rowSet	= resultObj.getRowSet();
				    
				    $("#material_Kind_Code_Lv1").empty().data("options"); 
				    $("#material_Kind_Code_Lv1").append("<option value=''>-- 전체 --</option>");
				    
				    if($("#corp_status").val() == "P")
				    {
				        for ( var i = 0; i < rowSet.getRowSize(); i++ )	
					    {
					        $("#material_Kind_Code_Lv1").append("<option value='"+rowSet.getColValue( i, 0 )+"'> " + rowSet.getColValue( i, 1 )+"</option>");
						}
				    }
				    else
				    {
				        for ( var i = 0; i < rowSet.getRowSize(); i++ )	
					    {
					        $("#material_Kind_Code_Lv1").append("<option value='"+rowSet.getColValue( i, 0 )+"'>" + rowSet.getColValue( i, 1 )+"</option>");
						}
				    }    
				    
				    document.form1.isSubmit = false;
				    if($("#corp_status").val() == "O"){
				    	if(Lv1.length > 0){
					    	$("#material_Kind_Code_Lv1").val(Lv1);
					    	$("#material_Kind_Code_Lv1").change();
					    	//$("#material_Kind_Code_Lv1").attr("disabled","disabled");
				    	}
				    }else{
				    	<%--2017.12.19 구매 전체조회 요청  
				    	if("<%=material_gb%>".length > 0){
					    	$("#material_Kind_Code_Lv1").val("<%=material_gb%>");
					    	$("#material_Kind_Code_Lv1").change();
					    	//$("#material_Kind_Code_Lv1").attr("disabled","disabled");
				    	} --%>
				    }
				} else {
                    dlgErrorMsg(resultObj);
                }
			}
		    else if ( resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV2" ) 
			{
				if ( resultObj.getSuccess() == true ) 
				{
				    var rowSet	= resultObj.getRowSet();
				    
				    $("#material_Kind_Code_Lv2").empty().data("options"); 
				    $("#material_Kind_Code_Lv2").append("<option value=''>-- 전체 --</option>");
				    
				    if($("#corp_status").val() == "P")
				    {
				        for ( var i = 0; i < rowSet.getRowSize(); i++ )	
					    {
					        $("#material_Kind_Code_Lv2").append("<option value='"+rowSet.getColValue( i, 0 )+"'> " + rowSet.getColValue( i, 1 )+"</option>");
						}
				    }
				    else
				    {
				        for ( var i = 0; i < rowSet.getRowSize(); i++ )	
					    {
					        $("#material_Kind_Code_Lv2").append("<option value='"+rowSet.getColValue( i, 0 )+"'>" + rowSet.getColValue( i, 1 )+"</option>");
						}
				    }
				  
				    document.form1.isSubmit = false;
				    if($("#corp_status").val() == "O"){
					    if(Lv2.length > 0){
					    	$("#material_Kind_Code_Lv2").val(Lv2);
					    	$("#material_Kind_Code_Lv2").change();
					    	$("#material_Kind_Code_Lv2").attr("disabled","disabled");
					    }
				    }
				} else {
                    dlgErrorMsg(resultObj);
                }
			}
			else if ( resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV3" ) 
			{
				if ( resultObj.getSuccess() == true ) 
				{
				    var rowSet	= resultObj.getRowSet();
				    
				    $("#material_Kind_Code_Lv3").empty().data("options"); 
				    $("#material_Kind_Code_Lv3").append("<option value=''>-- 전체 --</option>");
				    
				    if($("#corp_status").val() == "P")
				    {
				        for ( var i = 0; i < rowSet.getRowSize(); i++ )	
					    {
					        $("#material_Kind_Code_Lv3").append("<option value='"+rowSet.getColValue( i, 0)+"'> " + rowSet.getColValue( i, 1 )+"</option>");
						}
				    }
				    else
				    {
				        for ( var i = 0; i < rowSet.getRowSize(); i++ )	
					    {
					        $("#material_Kind_Code_Lv3").append("<option value='"+rowSet.getColValue( i, 0 )+"'>" + rowSet.getColValue( i, 1 )+"</option>");
						}
				    }
				    
					document.form1.isSubmit = false;
					if($("#corp_status").val() == "O"){
					    if(Lv3.length > 0){
					    	$("#material_Kind_Code_Lv3").val(Lv3);
					    	$("#material_Kind_Code_Lv3").attr("disabled","disabled");
					    }
					}
				}
				else 
				{
                    dlgErrorMsg(resultObj);
                }
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
//-->
</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="p_corp_id" id="p_corp_id" value="" />
<input type="hidden" name="p_charge_seq" id="p_charge_seq" value="" />
<input type="hidden" name="job_div" id="job_div" value="<%=params.get("job_div") %>" />
<input type="hidden" name="materialgroup" id="materialgroup" value=""/>
<input type="hidden" name="menu_type" id="menu_type" value=""/>


<table border="0" cellspacing="0" cellpadding="0" width="100%" style="height: auto;">
	<!-- 검색조건 영역 : 시작 -->
	<tr>
		<td height="1">
			<table cellspacing="1" cellpadding="0" class="search-form-table">
				<col width="11%">
				<col width="15%">
				<col width="10%">
				<col width="49%">
				<col width="15%">
				
				<tr height="25"> 
    			<!-- 검색조건 타이틀 1 -->
    				<th>
    					사업자번호
    				</th>
   					<td>
  						<input type="text" name="corp_no" id="corp_no" maxlength="10" numberOnly="true" style="width: 90%;" value=""/>
					</td>
    				<th>
        				검색어
    				</th>
    				<td>
    					<select name="search_gb" id="search_gb" style="width: 29%; height=18;">							
							<option value="2">업체명</option>
							<option value="1">업체명+의견</option>
							<option value="3">의견</option>
						</select>    				
    					<input type="text" name="corp_name" id="corp_name" style="width: 59%;"  value=""/>
    				</td>
				    <td rowspan="3" style="text-align: center;"> 
			         	<!-- 검색버튼 영역 : 시작 -->
			         	<span class="btnSearch center"><a href="javascript:void(0);" id="btn_search">검색</a></span>
			         	<span class="btnSearch center"><a href="javascript:void(0);" id="btn_select">선택</a></span>
			         	<!-- <span class="btnSearch center"><a href="javascript:void(0);" id="btn_close">닫기</a></span> -->
            			<!-- 검색버튼 영역 : 종료 -->  
    				</td>
  				</tr>

  				<tr height="25"> 
    				<!-- 검색조건 타이틀 1 -->
	    			<th>
	        			구분
	    			</th>
    				<td>
      				<select name="corp_status" id="corp_status" style="width: 103px;">
      		   					<option value="">전체</option>
		      					<option value="P">구매</option>
		      					<option value="O">외주</option>
		      				</select>
    				</td>
    				<th>
	        			상태
	    			</th>
    				<td>
							<%= HTMLMaker.getSelectTag(materialKindCodeLv1, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv1", "style='width:29%;height=18;'", "<OPTION value=''>-- 전체 --</OPTION>", "", 0) %>
							<%= HTMLMaker.getSelectTag(materialKindCodeLv2, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv2", "style='width:29%;height=18;'", "<OPTION value=''>-- 전체 --</OPTION>", "", 0) %>
							<%= HTMLMaker.getSelectTag(materialKindCodeLv3, "materialgroup", "materialgroupname" , "material_Kind_Code_Lv3", "style='width:29%;height=18;'", "<OPTION value=''>-- 전체 --</OPTION>", "", 0) %>
    				</td>
    			</tr>
			</table>
		</td>
	</tr>
	<!-- 검색조건 영역 : 종료 -->

	<!-- 검색조건 영역, 테이터 영역 구분 여백 : 시작 -->
	<tr>
		<td height="1">
			<table border="0" cellspacing="0" cellpadding="0" class="search_data_div_height">
				<tr>
					<td>
					</td>				
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>

<div style="width: 100%;">
	<!-- 데이터 영역 : 시작 -->
	<!-- ibsheet7 그리드 생성 -->
		<script>createIBSheet("sheet1","100%", "300px");</script>
	<!-- 데이터 영역 : 종료 -->
</div>


	