<%--
  - FileName   : OutSupplierCompList.jsp
  - Author(s)  : Sung Min Lee
  - Date       : 2014.06.17
  -
  - Description: 협력업체평가현황
  --%>
  

<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.util.DateUtil"%>
<%@ 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();
    
  //검색조건 현장 설정
  	String initSearchDeptCd = params.get("searchDeptCd");
  	String initSearchDeptNm = params.get("searchDeptNm");
  	
  	String sToday = DateUtil.getSystemDate().substring(0,8);
   
  	String delHidden = ", Hidden:\"True\"";	
	if( user.get("RIGHT_NAME").equals("ADMIN NEW")) {	//관리자만 삭제버튼 보이도록(2021.03.30)
		delHidden = "";
	}	
%>
<script type="text/javascript" src="/js/creditEvaluationPop.js"></script>
<script language="javascript">
	/*예약함수*/
	var sheet1 = new ibsheetObject();
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	
	$(document).on("keyup", "input:text", function(e) {
	    if($(this).attr("numberOnly") == "true")
        {
	        $(this).val( $(this).val().replace(/[^0-9]/gi,"") );
        }
	    
	    if (e.keyCode == 13)
        {
	        $.searchList();
        }
	    
	});
	
	
	$.gridInit = function(sheetName)
	{
		
		var init_sheet = {};
		
		init_sheet.Cfg = {SearchMode:2, Page:30, MergeSheet:msHeaderOnly};
		init_sheet.Cols = [
									{Header:"Status",											Type:"Status", 		SaveName:"STATUS", 					Width:0, 		Align:"Center", 	 Hidden:"True"},
									{Header:"DOC_CD",										Type:"Text", 			SaveName:"DOC_CD",					Width:0,	 		Align:"Center", 	Hidden:"True"},
									{Header:"CORP_ID",										Type:"Text", 			SaveName:"CORP_ID",					Width:0,	 		Align:"Center", 	Hidden:"True"},
									{Header:"DEPT_CD",										Type:"Text", 			SaveName:"DEPT_CD",					Width:0,	 		Align:"Center", 	Hidden:"True"},
									{Header:"ADM_YEAR",										Type:"Text", 			SaveName:"ADM_YEAR",				Width:0,	 		Align:"Center", 	Hidden:"True"},
									{Header:"현장명",											Type:"Text", 			SaveName:"DEPT_NAME",				Width:220, 		Align:"Left"		 	},
									{Header:"계약명",											Type:"Text", 			SaveName:"BUILD_NAME",				Width:220, 		Align:"Left"		 	},
									{Header:"업체명",											Type:"Text", 			SaveName:"CORP_KOR",					Width:220, 		Align:"Left"		 	},
									{Header:"시작일",											Type:"Text", 			SaveName:"START_WORK_DATE",					Width:100, 		Align:"Center"		 	},
									{Header:"종료일",											Type:"Text", 			SaveName:"END_WORK_DATE",					Width:100, 		Align:"Center"		 	},
									{Header:"평가자",											Type:"Text", 			SaveName:"USER_NAME",				Width:100, 		Align:"Center" 		},
									{Header:"평가자ID",										Type:"Text", 			SaveName:"APPR_BY_ID",				Width:100, 		Align:"Center", 	Hidden:"True"},
									{Header:"☞준공평가점수",								Type:"Text", 			SaveName:"APPR_TOT_RATE",		Width:70, 		Align:"Center"		},
									{Header:"평가등급",										Type:"Text", 			SaveName:"ITEM_STD_CD",			Width:70, 		Align:"Center" 		},
									{Header:"평가결과",										Type:"Text", 			SaveName:"STATUS_CODE",			Width:70, 		Align:"Center" 		},
									{Header:"평가차수",										Type:"Text", 			SaveName:"ARR_ID",						Width:100, 		Align:"Center", 	Hidden:"True"},
									{Header:"평가일자",										Type:"Text", 			SaveName:"APPR_DY",					Width:100, 		Align:"Center"},
									{Header:'평가삭제',				Type:"Image", 			SaveName:"IMG_GB", 				Width:100, 		Align:"Center" , 	Edit:"false",	Cursor:'pointer'	<%=delHidden%>}
		                   		];
		
		
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheet1, init_sheet);
		sheet1.SetDataAutoTrim(0);
		sheet1.SetImageList(1,"/img/buyer/btn/btn_del.gif");
		sheet1.SetEditable(false);
		
		sheet1.SetDataLinkMouse("APPR_TOT_RATE", 1);
		sheet1.SetColFontColor("APPR_TOT_RATE", "#0000ff");
		
		sheet1.SetDataLinkMouse("CREDIT_GRADE", 1);
		sheet1.SetColFontColor("CREDIT_GRADE", "#0000ff");
		
		sheet1.SetDataLinkMouse("CASH_GRADE", 1);
		sheet1.SetColFontColor("CASH_GRADE", "#0000ff");
		
		sheet1.FitColWidth();
		
		
		
		var obj = { Format: "Ymd", X:300, Y:600, CallBack: "Test" };
		
	}
	
	
	$(function(){
	    
	    $.searchList = function()
		{
			$("#fevent").val("GET_LIST");
			
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/supplier/outside/OutSupplierCompList_sheet.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, $("#form1"), 30, "");
		}
	    
	    
	    $("#btn_search").click(function(){
		    $.searchList();
		});
	    
	    
	    $("#btn_excel").click(function(){
	        var params = {FileName:"협력업체 평가현황.xls",SheetName:"협력업체 평가현황",Merge:1,SheetDesign:1, HiddenColumn:1 };
	        sheet1.Down2Excel (params);
	    });
	});
	
	
	$(document).ready(function(){
		
	    $.gridInit(sheet1);
		//$.searchList();
		
		autoResize();
		
	});
	
	
	function sheet1_OnSearchEnd(code, message)
	{
	    sheet1.FitColWidth();
	}
	
	
	
	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	
	
	
	
	function doResult(resultObj) {
	    
		try {
		    
			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>");
				    
				    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;
					
				} 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>");
				    
				    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;
				}
				else 
				{
                    dlgErrorMsg(resultObj);
                }
			}
			else if(resultObj.getRequestEvent() == "GET_CREADIT_REG_CHK")
		    {
			    document.form1.isSubmit = false;
			    
			    var url = resultObj.getValueObject().get("returnUrl");
			    
			    window.open(url, "pop", "width=1024,height=600, resizable=yes, scrollbars=yes");
		    }
			else if(resultObj.getRequestEvent() == "GET_CREADIT_REG_CHK2")
		    {
			    document.form1.isSubmit = false;
			    
			    var url = resultObj.getValueObject().get("return_url");
	            var open = window.open('',"go_ksrm","width=900,height=600,scrollbar=auto");
	            var f = document.form1;
	            
	            f.action = url;
	            f.target = "go_ksrm";
	            f.method = "post";
	            f.submit();
		    }
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	
	
	
	/**
	 *	IBSheet Event: DBLCLICK
	 */
	 function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		var f = document.form1;
		var year_std = sheet1.GetCellValue(Row, "ADM_YEAR");  
		if (sheet1.ColSaveName(Col) == "APPR_TOT_RATE") 
		{
		    var reportInfo = new ReportInfo();
		    
		    if(sheet1.GetCellValue(Row, "APPR_TOT_RATE").trim() != "" )
	        {
		    	if(sheet1.GetCellValue(Row, "DOC_CD").trim() == "12" )
		        {
		    		reportInfo.title = "협력업체 현장평가표(공사)";
		    		if (year_std == "2022"){
		    			reportInfo.reportName = "/report/mrd/buyer/supplier/outside/OutSuppFixApprReport_2022.mrd";
		    		}else{
				        reportInfo.reportName = "/report/mrd/buyer/supplier/outside/OutSuppFixApprReport.mrd";
		    		}
		        }
		    	else
		    	{
		    		reportInfo.title = "협력업체 현장평가표(설계,인허가)";
					if (year_std == "2022"){
						reportInfo.reportName = "/report/mrd/buyer/supplier/outside/OutSuppFixApprReport16_2022.mrd";
		    		}else{
				        reportInfo.reportName = "/report/mrd/buyer/supplier/outside/OutSuppFixApprReport16.mrd";
		    		}
		    	}
		        
		        
		        reportInfo.width = 1000;                         	// Default: 1024
		        reportInfo.height = 700;                         	// Default: 768

		        
		        reportInfo.set(sheet1.GetCellValue(Row, "CORP_ID"));    	// $1
		        reportInfo.set(sheet1.GetCellValue(Row, "ARR_ID"));    	// $2
		        reportInfo.set(sheet1.GetCellValue(Row, "APPR_DY").substring(0,4));	// $3
		        reportInfo.set(sheet1.GetCellValue(Row, "ADM_YEAR"));    	// $4
		        reportInfo.showPopup();
	        }
		}
// 		else if (sheet1.ColSaveName(Col) == "APPR_TOT_RATE2") {
// 		    var reportInfo = new ReportInfo();
		    
// 		    if(sheet1.GetCellValue(Row, "APPR_TOT_RATE2").trim() != "" )
// 	        {
// 		        reportInfo.title = "협력업체 현장평가표";    
// 		        reportInfo.reportName = "/report/mrd/buyer/supplier/outside/OutSuppFixApprReport.mrd";
		        
		        
// 		        reportInfo.width = 1000;                         	// Default: 1024
// 		        reportInfo.height = 700;                         	// Default: 768

		        
// 		        reportInfo.set(sheet1.GetCellValue(Row, "CORP_ID"));    	// $1
// 		        reportInfo.set(sheet1.GetCellValue(Row, "ARR_ID"));    	// $2
// 		        reportInfo.set(sheet1.GetCellValue(Row, "APPR_DY").substring(0,4)); 
// 		        reportInfo.showPopup();
// 	        }
// 		}
		else if (sheet1.ColSaveName(Col) == "CREDIT_GRADE" || sheet1.ColSaveName(Col) == "CASH_GRADE"  )
		{
		    var code = sheet1.GetCellValue(Row, "CREDIT_CORP_CD");
	        var reg_no = sheet1.GetCellValue(Row, "CORP_REG_NO");
	        
	        /*
	        	이크레더블 : E
	        	서울신용평가 : S
	        	나이스디앤비 : N
	        	한국기업데이터 : K
	        	나이스평가정보:M
	        */
	        if(code == "E")
            {
	            var u = "2d2d424547494e204349504845522d2d313131310000000b3030303030303030eef0492ff42855bbffb697d670d4e3d109dafed98f4d7900293e8d4b9c1dcebd28eb9d58fd4c815c4d4829f1415fdfb730302d2d454e44204349504845522d2d";
	            var p = "2d2d424547494e204349504845522d2d313131310000000830303030303030301bb8ae01f161a326e30cc8d45f3844afd1bd2d39f5da22e9405f40dff013966445d4ea4029f89ad1385c4624cf679cc230302d2d454e44204349504845522d2d";
	            var i = reg_no; //협력업체사업자번호
	            var k = ""; //협력업체법인번호
	            
	            var m ='3';
	            var link ='http://www.esrm.co.kr/esrm/SrmplusLogin?u='+ u +'&p='+ p +'&i='+ i +'&k='+ k +'&c=7&m='+ m +'&g=2';
	            var features ='height=768, width=1024, status=no, scrollbars=auto, resizable=yes';
	            window.open(link, 'watchwin', features);  
            }
	        else if(code == "S")
            {
	            var  link = "http://www.bizrating.co.kr/url/urlPage.do?param1=ZXRlY2g=&param2=YWV0ZWNo&param3=" + reg_no;
	            window.open(link, "pop", "width=975,height=600, resizable=yes, scrollbars=yes");
            }
	        else if(code == "N")
            {
	            var f = document.form1;
	            
	            $("#p_corp_reg_no").val(reg_no);
		        $("#fevent").val("GET_CREADIT_REG_CHK");
		        
	            submitXmlRequest("/supplier/purchase/PuSupplierList_form.screen", "GET_CREADIT_REG_CHK", f, "VALUEOBJECT");
            }
	        else if(code == "K")
            {
	            
	            var f = document.form1;
	            
	            $("#p_corp_reg_no").val(reg_no);
		        $("#fevent").val("GET_CREADIT_REG_CHK2");
		        
	            submitXmlRequest("/supplier/purchase/PuSupplierList_form.screen", "GET_CREADIT_REG_CHK2", f, "VALUEOBJECT");
	            
            }
	        else if(code == "M")
            {
	        	var vnk = "<%= sToday%>" * 677; 
	        	var  link = "http://service.ecredit.co.kr/p01/A0001M001.nice?bizno=" + reg_no + "&eid=ETECENC&nk=" + vnk;
	            window.open(link, "pop", "width=975,height=600, resizable=yes, scrollbars=yes");
	            
            }
		}else if (sheet1.ColSaveName(Col) == "IMG_GB")
		{
			var status = sheet1.GetCellValue(Row,8);
			$("#DOC_CD").val(sheet1.GetCellValue(Row, "DOC_CD"));
			$("#CORP_ID").val(sheet1.GetCellValue(Row, "CORP_ID"));
			$("#ARR_ID").val(sheet1.GetCellValue(Row, "ARR_ID"));
			$("#DEPT_CD").val(sheet1.GetCellValue(Row, "DEPT_CD"));
			
			if (confirm("준공평가 삭제 하시겠습니까")){
				submitXmlRequest("/test/ModStatusList_form.screen", "DEL_OUT_COMP_APPR", f);
			}
		}
	 }
	
	 function doResult(resultObj) {
			try {
				document.form1.isSubmit = false;
				
				if( resultObj.getRequestEvent() == "DEL_OUT_COMP_APPR") {
					if( resultObj.getSuccess() ) 
					{
						alert("삭제되었습니다.");
						jQuery("#btn_search").click();
					}else{
						alert("오류발생");
					}
				}
			}
			catch(errorObject) {
				showErrorDlg("doResult()", errorObject);
			}
	}
	
	 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="p_user_sabun" value="">
<INPUT type="hidden" name="DOC_CD" value="">
<INPUT type="hidden" name="CORP_ID" value="">
<INPUT type="hidden" name="ARR_ID" value="">	
<INPUT type="hidden" name="DEPT_CD" value="">
<input type="hidden" name="ADM_YEAR" value="">

<div align="left" id="title">
	<ul>
    	<li>외주_협력업체 준공평가현황</li>
   	</ul>
</div>

<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" id="search-table">
	<!-- 검색조건 영역 : 시작 -->
	<tr>
		<td height="1">
			<table cellspacing="1" cellpadding="0" class="search-form-table">
				<col width="10%">
				<col width="30%">
				<col width="10%">
				<col width="30%">
				<col width="20%">
				
				<tr height="25"> 
    			<!-- 검색조건 타이틀 1 -->
    				<th>
    					현장명
    				</th>
   					<td>
   						<%=InputText.getSiteCodeNew("searchDeptCd", "searchDeptNm", "", user, initSearchDeptCd, initSearchDeptNm)%>
   						<%if( user.get("RIGHT_NAME").equals("SITE_CONT") ){%>
							 <IMG id='_btn_clear' onClick="dlgClearNew('searchDeptCd', 'searchDeptNm')" src='/img/buyer/button/bt_eraser1.gif' border='0' align='absmiddle' alt='[초기화]' style='cursor:pointer;'>
						<%}%>
					</td>
    				<th>
        				계약명
    				</th>
    				<td>
    					<input type="text" name="build_name" id="build_name" style="width: 86%;" value="<%=params.get("build_name")%>"/>
    				</td>
				    <td rowspan="2" class="button" 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_excel">엑셀</a></span>
            			<!-- 검색버튼 영역 : 종료 -->  
    				</td>
  				</tr>

  				<tr height="25"> 
    				<!-- 검색조건 타이틀 1 -->
	    			<th>
	        			업체명
	    			</th>
    				<td>
      					<input type="text" name="corp_kor" id="corp_kor" style="width: 36%;"  value="<%=params.get("corp_kor")%>"/>
    				</td>
    				<th>
	        			평가기준년도
	    			</th>
					<td>
  						<select name="APPR_SEL" id="APPR_SEL" style="width: 40%;" class="input_select" height=18>
  							<option value=''>--전체--</option>
  							<option value="A" <%=params.get("APPR_SEL").equals("A") ? "selected=\"selected\" " : "" %>>신규평가기준</option>
  							<option value="B" <%=params.get("APPR_SEL").equals("B") ? "selected=\"selected\" " : "" %>>이전평가기준</option>
  						</select>
					</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%; height: 100%; margin-top: 5px;">
	<!-- 데이터 영역 : 시작 -->
	<!-- ibsheet7 그리드 생성 -->
		<script>createIBSheet("sheet1","100%", "250px");</script>
	<!-- 데이터 영역 : 종료 -->
</div>