<%--
  - FileName   : PuSupplierApprList.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.*" %>
<%@ page import="kr.co.hsnc.common.config.WAFConfig"%>
<%@ 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 defaultDS = WAFConfig.get("waf.sql.Default.DS");

	//검색조건 현장 설정
  	String initSearchDeptCd = params.get("searchDeptCd");
  	String initSearchDeptNm = params.get("searchDeptNm");
   
  	String sToday = DateUtil.getSystemDate().substring(0,8);
%>
<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:"CORP_ID",										Type:"Text", 			SaveName:"CORP_ID",					Width:0,	 		Align:"Center", 	Hidden:"True"},
									{Header:"현장명",											Type:"Text", 			SaveName:"DEPT_NAME",				Width:220, 		Align:"Left"		 	},
									{Header:"☞계약명",										Type:"Text", 			SaveName:"CST_DOC_NAME",			Width:220, 		Align:"Left"		 	},
									{Header:"업체명",											Type:"Text", 			SaveName:"CORP_KOR",					Width:220, 		Align:"Left"		 	},
									{Header:"현장평가자",										Type:"Text", 			SaveName:"USER_NAME",				Width:60, 		Align:"Center" 		},
									{Header:"본사평가자",										Type:"Text", 			SaveName:"WRITE_NM",				Width:60, 		Align:"Center" 		},
									{Header:"평가자ID",										Type:"Text", 			SaveName:"APPR_BY_ID",				Width:100, 		Align:"Center", 	Hidden:"True"},
									{Header:"☞준공평가점수",								    Type:"Text", 			SaveName:"APPR_TOT_RATE",		Width:80, 		Align:"Center"		},
									{Header:"평가등급",										Type:"Text", 			SaveName:"ITEM_STD_CD",			Width:70, 		Align:"Center" 		},
									{Header:"공종",										    Type:"Text", 			SaveName:"ITEM_STD_NM",			Width:50, 		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", 	Hidden:"True"},
									{Header:"DOC_CD",										Type:"Text", 			SaveName:"DOC_CD",					Width:100, 		Align:"Center", 	Hidden:"True"},
									{Header:"DEPT_CD",										Type:"Text", 			SaveName:"DEPT_CD",					Width:100, 		Align:"Center", 	Hidden:"True"},
									{Header:"기준년도",										Type:"Text", 			SaveName:"ADM_YEAR",				Width:50, 		Align:"Center" },
									{Header:"PUR_CONT_ID",									Type:"Text", 			SaveName:"PUR_CONT_ID",					Width:100, 		Align:"Center", 	Hidden:"True"},
									{Header:"ORD_DOC_NO",									Type:"Text", 			SaveName:"ORD_DOC_NO",				Width:40, 		Align:"Center" , 	Hidden:"True"},
									{Header:"평가의견",									    Type:"Text", 			SaveName:"APPR_NOTE",				Width:150, 		Align:"Left"},
									{Header:"REGU_STATUS_CD",								Type:"Text", 			SaveName:"REGU_STATUS_CD",				Width:40, 		Align:"Left", 	Hidden:"True"}
									
									];
		
		
		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		
		sheet1.SetDataLinkMouse("APPR_TOT_RATE", 1);
		sheet1.SetColFontColor("APPR_TOT_RATE", "#0000ff");
		
		sheet1.SetDataLinkMouse("CST_DOC_NAME", 1);
		sheet1.SetColFontColor("CST_DOC_NAME", "#0000ff");
		
		sheet1.SetDataLinkMouse("CREDIT_GRADE", 1);
		sheet1.SetColFontColor("CREDIT_GRADE", "#0000ff");
		
		sheet1.SetDataLinkMouse("CASH_GRADE", 1);
		sheet1.SetColFontColor("CASH_GRADE", "#0000ff");
		
		sheetName.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/purchase/PuSupplierCompList_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(){
		setSearchDate();
	    $.gridInit(sheet1);
		//$.searchList();
		
		autoResize();
		
	});
	
	
	
	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 setSearchDate(){
	    
		var newDay = new Date( get_year(), get_month(), "");
	    var lastDay = newDay.getDate();
	    //var yyyymmbeginning = get_year() +'-'+ get_month() +'-'+ '01';
	    //var yyyymmlast	= get_year() +'-'+ get_month() +'-'+ lastDay;
	    var searchFromDate = get_year() +'-'+ '01';
	    var searchToDate   = get_year() +'-'+ get_month();
	    
	    jQuery('#searchFromDate').val(searchFromDate);
	    jQuery('#searchToDate').val(searchToDate);

	}
	 
	function doResult(resultObj) {
	    
		try {
		    
			if ( resultObj.getRequestEvent() == "GET_MATL_KIND_CODE_LV2" ) 
			{
				if ( resultObj.getSuccess() == true ) 
				{
				   
					
				} else {
                    dlgErrorMsg(resultObj);
                }
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	/**
	 *	IBSheet Event: DBLCLICK
	 */
	 function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		var f = document.form1;
		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") == "03")
	            {
		            reportInfo.title = "기자재공급업체 현장평가표(Manufacturer)";
		            if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2014")
		            {	reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport3.mrd";}
		            else if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2016")
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport3_2016.mrd";}
		            else if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2019")
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport3_2019.mrd";}		            
		            else if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2020")
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport3_2020.mrd";}
		            else
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport3_2023.mrd";}
		            reportInfo.set(sheet1.GetCellValue(Row, "CORP_ID"));    	// $1
			        reportInfo.set(sheet1.GetCellValue(Row, "ARR_ID"));    	// $2
			        reportInfo.set(sheet1.GetCellValue(Row, "DOC_CD"));    	// $3
			        reportInfo.set(sheet1.GetCellValue(Row, "APPR_DY").substring(0,4)); 
	            }
		        else if(sheet1.GetCellValue(Row, "DOC_CD") == "04")
	            {
		            reportInfo.title = "기자재공급업체 현장평가표(Agent)";
		            if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2014")
		            {	reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport4.mrd";}
		            else if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2016")
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport4_2016.mrd";}
		            else if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2019")
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport4_2019.mrd";}		            
		            else if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2020")
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport4_2020.mrd";}
		            else
		            {  reportInfo.reportName = "/report/mrd/buyer/supplier/purchase/PuSupplierReport4_2023.mrd";}
		            reportInfo.set(sheet1.GetCellValue(Row, "CORP_ID"));    	// $1
			        reportInfo.set(sheet1.GetCellValue(Row, "ARR_ID"));    	// $2
			        reportInfo.set(sheet1.GetCellValue(Row, "DOC_CD"));    	// $3
			        reportInfo.set(sheet1.GetCellValue(Row, "APPR_DY").substring(0,4));
	            }
		        
		        reportInfo.width = 1000;                         	// Default: 1024
		        reportInfo.height = 700;                         	// Default: 768
//	 	        reportInfo.reportOption = "/rf /rsn ["+f.defaultDS.value+"]"; 	             	// Default: '/rf'

		        
		        reportInfo.showPopup();
            }
		}
		else if (sheet1.ColSaveName(Col) == "CREDIT_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  link = "http://www.k-srm.co.kr/refbfautologin.do?acctp=J1&isSSL=&ID=ETEC& siteKey=kzCur4ryVY=&BZNO=" + reg_no;
	            window.open(link,"go_ksrm","width=900,height=600,scrollbar=auto");
            }
	        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) == "CST_DOC_NAME"){
		    var p_corp_id = sheet1.GetCellValue(Row, "CORP_ID");
		    var p_dept_cd = sheet1.GetCellValue(Row, "DEPT_CD");
		    var p_ord_doc_no = sheet1.GetCellValue(Row, "ORD_DOC_NO");
		    var p_pur_cont_id = sheet1.GetCellValue(Row, "PUR_CONT_ID");
		    var p_user_sabun = "<%=user.get("USER_SABUN")%>";
		    var p_status = sheet1.GetCellValue(Row, "REGU_STATUS_CD");
		    var argObj = new Object();
		    argObj.p_corp_id = p_corp_id;
		    argObj.p_dept_cd = p_dept_cd;
		    argObj.p_ord_doc_no = p_ord_doc_no;
		    argObj.p_pur_cont_id = p_pur_cont_id;
		    argObj.p_user_sabun = p_user_sabun;
		    argObj.P_CHARGE_CD = "C";
		    
		    argObj.title = '현장 평가표 생성';
		    
		    var dialogHeight = 440;
		    var dialogWeight = 900;
			if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2019"){  
				dialogHeight = 500;
			} else if(sheet1.GetCellValue(Row, "ADM_YEAR") == "2020"){  
				dialogHeight = 550;
			}else{
				dialogHeight = 650;
				dialogWeight = 1100;
			}		
			var win_id = "SuppFixApprPop";
			var url = "PuSuppFixApprPop.screen?p_corp_id="+p_corp_id+"&p_dept_cd="+p_dept_cd+"&p_pur_cont_id="+p_pur_cont_id+"&p_user_sabun="+p_user_sabun+"&p_status="+p_status+"&P_CHARGE_CD=C&sModule=LM";
			result = fLayerPop(win_id, url, dialogWeight,dialogHeight, '', '', 'NO');
			//result = window.showModalDialog(url, argObj,'dialogWidth:900px;dialogHeight:' + dialogHeight + 'px; center:yes; help:no; status:no; scroll:no; resizable:no');
			//$.searchList();
			
		}
	 }
	 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="materialgroup" id="materialgroup" value=""/>
<INPUT type="hidden" name="p_corp_reg_no" id="p_corp_reg_no" 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)%>
					</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>
		   				<%= InputText.get("searchFromDate", "", 10, 50, "hangule,center, desc=평가년월, ReadOnly") %>
						<IMG name="start_img" id="calender_from" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('searchFromDate');">
						~
						<%= InputText.get("searchToDate", "", 10, 50, "hangule,center, desc=평가년월, ReadOnly") %>
						<IMG name="start_img" id="calender_to" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgMCalendar('searchToDate');">
		    		</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>

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

</form>

