<%--
  - FileName   : PuSuppPlanApprPop.jsp
  - Author(s)  : lsm
  -
  --%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="kr.co.hsnc.common.util.ValueObject" %>
<%@ page import="kr.co.hsnc.common.sql.RowSet" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="com.udapsoft.waf.common.util.StringUtils" %>
<%@ 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();
    
	RowSet getApprSrdList = storage.getRowSet("getApprSrdList");
	
	ValueObject vo = storage.getValueObject("getAppr");
	
	
	String yyyymmdd = (new java.text.SimpleDateFormat ("yyyy년 MM월 dd일")).format (new java.util.Date());
	String appr_date = (new java.text.SimpleDateFormat ("yyyyMMdd")).format (new java.util.Date());
%>


 <script type="text/javascript">
 
 	$(function(){
 	    
 	   $(window).load(function () {
 	        $(".gubun").each(function () {
 	            var rows = $(".gubun:contains('" + $(this).text() + "')");
 	            if (rows.length > 1) {
 	                rows.eq(0).attr("rowspan", rows.length);
 	                rows.not(":eq(0)").remove(); 
 	            }
 	        });
 	    });
 	   
 	   $(':radio[name^=test_]').click(function(){
 		   var grade = ['A', 'B', 'C', 'D', 'E'];
 		   var i = this.name.split('test_')[1]; 
 		   var index = $(':radio[name="test_' + i + '"]').index($(this));

 		   $("#result_" + i).text($(this).val() + "점");
           $("#chkResultCd_" + i).val(grade[index]);
 	   }); 	  
		
		$("#btn_close").click(function(){
			parent.fLayerPopClose('PlanApprPop'); 
			//window.close();
		});
		
		$("#btn_save").click(function(){
		    
		    var f = document.form1;
		    
		    <%-- if("<%=params.get("P_CHARGE_CD")%>" == "C" &&  $("#APPR_NOTE").val().length < 1 ) {
		 		alert("담당자 의견은 필수입니다. ");
		 		return  ;
		 	}  --%>  
		    $("#fevent").val("GET_SAVE");		 	   
		 	   if(confirm("저장하시겠습니까?"))
		 	   {
		 		  jQuery("#gubun").val("1");
				  submitXmlRequest("/payment/purchase/PuSuppPlanApprPopSave.screen", "GET_SAVE", f);
				}
		    
		});
		
		$(".icon_x").click(function(){
			parent.fLayerPopClose('PlanApprPop');
		    //window.close();
		});
		
		$("#btnAppReq").click(function(){
		    
		    var f = document.form1;
		    
		    <%-- if("<%=params.get("P_CHARGE_CD")%>" == "C" &&  $("#APPR_NOTE").val().length < 1 ) {
		 		alert("담당자 의견은 필수입니다. ");
		 		return  ;
		 	}  --%>  
		    $("#fevent").val("GET_SAVE");		 	   		 	   
		 	   if(confirm("확정하시겠습니까?"))
		 	   {	
		 		  jQuery("#gubun").val("2");
				  submitXmlRequest("/payment/purchase/PuSuppPlanApprPopSave.screen", "GET_SAVE", f);
				}		    
		});
		
		$(".icon_x").click(function(){
		    window.close();
		});
 	    
 	});
 	
 	
 	
 	$(document).ready(function(){
 		if(<%=params.get("p_plan_appr_chk_empno")%> != <%=params.get("user_id") %>){ 
 	    	jQuery("#btn_save").hide();
 	    	jQuery("#btnAppReq").hide();
 	    }
 		
 		if(<%=params.get("p_plan_appr_status")%> == "02"){ 
 	    	jQuery("#btn_save").hide();
 	    	jQuery("#btnAppReq").hide();
 	    }
 		
 	    if(<%=params.get("p_plan_appr_status")%> == "02" && "<%=params.get("P_CHARGE_CD")%>" == "S"){  //2016.5.11 완료상태에서 구매담당자 수정가능. 
 	    	jQuery("#save").hide();
 	    }else{
 	    	jQuery("#save").show();
 	    }
 		
 		//2016.4.21
 		if("<%=params.get("P_CHARGE_CD")%>" == "C"){
 			jQuery("#WRITE_NO").val("<%=params.get("user_id")%>");
	    	jQuery("#WRITE_NM").val("<%=params.get("user_nm")%>");
 		}
 		//else{
	    //	$(':radio[name="test_5"]').attr("disabled", true);
	    //}  
 		
 	    for(i=0; i < <%=getApprSrdList.size()%>; i++)
        {
 	       var index = $(':radio[name="test_'+i+'"]').index($(':radio[name="test_'+i+'"]:checked')) +1;
 	       if(index != 0)
           {
 	          if($(':radio[name="test_'+i+'"]:checked'))
 	 	       {
 	 	           $("#result_"+i+"").text($(':radio[name="test_'+i+'"]:checked').val() + "점");
 	 				
 	 	           if(index == "1")
 	               {
 	 	              $("#chkResultCd_"+i).val("A");
 	               }
 	 	           else if(index == "2")
 	               {
 	 	              $("#chkResultCd_"+i).val("B");
 	               }
 	 	           else if(index == "3")
 	               {
 	 	              $("#chkResultCd_"+i).val("C");
 	               }
 	 	           else if(index == "4")
 	               {
 	 	              $("#chkResultCd_"+i).val("D");
 	               }
 	 	           else if(index == "5")
 	               {
 	 	              $("#chkResultCd_"+i).val("E");
 	               }
 	 	        }
       		}
 	      
        }
 	    
 	});
 	
 	function doResult(resultObj) {
 		var f = document.form1;
 		
 		try 
 		{
 		   document.form1.isSubmit = false;
 		   
 		   if($("#fevent").val() == "GET_SAVE")
 		   {
 		      if (resultObj.getSuccess())	
 		      {
 		          alert("평가표 저장이 완료되었습니다.");
 		         window.close();  //2016.4.25 중복저장 오류 제거
 		          //winClose(); 
 		      }
 		      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="gubun" id="gubun" value="">
<input type=hidden name="payreq_id" id="payreq_id" value="<%=params.get("p_payreq_id") %>" />
<input type=hidden name="corp_id" id="corp_id" value="<%=params.get("p_corp_id") %>" />
<input type="hidden" name="corp_no" id="corp_no" value="<%=params.get("corp_no") %>" />
<input type="hidden" name="dept_cd" id="dept_cd" value="<%=params.get("p_dept_cd") %>" />
<input type="hidden" name="dept_nm" id="dept_nm" value="<%=params.get("dept_nm") %>" />
<input type="hidden" name="doc_cd" id="doc_cd" value="<%=params.get("doc_cd") %>" />
<input type="hidden" name="user_id" id="user_id" value="<%=params.get("user_id") %>" />
<input type="hidden" name="user_nm" id="user_nm" value="<%=params.get("user_nm") %>" />  <!--2016.4.20 현재작성자정보 저장  -->
<input type="hidden" name="user_id_before" id="user_id_before" value="<%=params.get("user_id_before") %>" />
<input type="hidden" name="user_nm_before" id="user_nm_before" value="<%=params.get("user_nm_before") %>" />  <!--2016.4.20 현재작성자정보 저장  -->

<input type="hidden" name="ord_doc_no" id="ord_doc_no" value="<%=params.get("p_ord_doc_no") %>" />
<input type="hidden" name="cont_id" id="cont_id" value="<%=params.get("p_pur_cont_id") %>" />
<input type="hidden" name="listSize" id="listSize" value="<%=getApprSrdList.size() %>" />
<input type="hidden" name="appr_date" id="appr_date" value="<%=appr_date %>" />


<input type="hidden" name="WRITE_NO" id="WRITE_NO" value="<%=vo.get("WRITE_NO") %>" />
<input type="hidden" name="WRITE_NM" id="WRITE_NM" value="<%=vo.get("WRITE_NM") %>" /><!--2016.4.21 본사담당자 평가 내용 저장  -->
<input type="hidden" name="CHARGE_CD" id="CHARGE_CD" value="<%=params.get("P_CHARGE_CD") %>" /><!--2016.4.21 본사담당자C,현장담당자S 구분  -->

<input type="hidden" name="arr_id" id="arr_id" value="<%=vo.get("arr_id") %>" />
<input type="hidden" name="p_status" id="p_status" value="<%=params.get("p_status")%>" />


 
<div style="width: 100%; text-align: center; margin-top: 10px; margin-bottom: 15px;" >
	<span style="font-size: 15px; font-weight: bold;">기자재 공급업체 설계평가표</span>
</div>

<table cellspacing="0" cellpadding="0" border="1" bordercolordark="#FFFFF" bordercolorlight="#d2d2d2" class="input_table" style="width: 100%;">
<col width="7%">
<col width="7%">
<col width="26%">
<col width="7%">
<col width="7%">
<col width="7%">
<col width="7%">
<col width="7%">
<col width="7%">
<col width="7%">
<!-- <col width="*"> -->

	<%-- <tr style="height: 23px;">
		<td class="insert_table_title" style="text-align: center;">공사번호</td>
		<td colspan="2" style="text-align: center;"></td>
		<td class="insert_table_title" style="text-align: center; text-indent : 0px;">공사기간</td>
		<td colspan="6" style="text-align: center;"></td>
	</tr>
	<tr style="height: 23px;">
		<td class="insert_table_title" style="text-align: center;">공 사 명</td>
		<td colspan="2" style="text-align: center;"></td>
		<td class="insert_table_title" style="text-align: center; text-indent : 0px;">작 성 일</td>
		<td colspan="6" style="text-align: center;"><%=params.get("dt_before")%></td>
	</tr>
	<tr style="height: 23px;">
		<td class="insert_table_title" style="text-align: center;">도급업체명</td>
		<td colspan="2" style="text-align: center;"><%=params.get("corp_kor") %>	</td>
		<td class="insert_table_title" style="text-align: center; text-indent : 0px;">작 성 자</td>
		<td colspan="6" style="text-align: center;"><%=params.get("user_nm_before") %></td>
	</tr> --%>
	<div style="width: 100%; vertical-align: middle; float: left; text-align: left; padding-bottom: 8px;" >
		평가자 : <%=params.get("user_nm_before") %>
	</div>
 
	<div style="width: 100%; vertical-align: middle; float: left; text-align: left; padding-bottom: 8px;"  >
		평가일 : <%=params.get("dt_before")%>
	</div>
	
	<div style="width: 100%; vertical-align: middle; float: left; text-align: left; padding-bottom: 8px;"  >
		업체명 : <%=params.get("corp_kor") %>	
	</div>
	<tr style="height: 23px;">
		<td class="insert_table_title" style="text-align: center;">구      분</td>
		<td colspan="2" class="insert_table_title" style="text-align: center;">평  가  항  목</td>	
		<td class="insert_table_title" style="text-align: center;">배당점수</td>	
		<td class="insert_table_title" style="text-align: center;">평가점수</td>
		<td class="insert_table_title" style="text-align: center;">A</td>
		<td class="insert_table_title" style="text-align: center;">B</td>
		<td class="insert_table_title" style="text-align: center;">C</td>
		<td class="insert_table_title" style="text-align: center;">D</td>
		<td class="insert_table_title" style="text-align: center;">E</td>
	</tr>
	
	<% 
		String chk = "";
		int idx = 0;
		int sum_stock_rate = 0;
		int all_sum_stock_rate = 0;
		String appr_cd = "";
		for(int i=0; i < getApprSrdList.size(); i++)
		{
    %>
    
    <tr>
        <td class="insert_table_title gubun" style="text-indent: 0px;"><%=getApprSrdList.getRow(i).get("GUBUN_1") %></td>
   		<%-- <td class="insert_table_title gubun" style="text-indent: 0px;"><%=getApprSrdList.getRow(i).get("GUBUN_2") %></td> --%>
   		<td colspan="2" class="insert_table_title gubun" style="text-indent: 0px; text-align: left;"><%=getApprSrdList.getRow(i).get("GUBUN_3") %></td>
   		<td class="insert_table_title" style="text-align: center; text-indent: 0px;"><%=getApprSrdList.getRow(i).get("STOCK_RATE") %></td>
   		<td style="text-align: center; text-indent: 0px;">
   			<div id="result_<%=i%>">0</div>
   			<div style="display: none;"><input type="text" name="appr_cd_<%=i %>" id="appr_cd_<%=i %>"  value="<%=getApprSrdList.getRow(i).get("APPR_CD") %>" /></div>
   			<div style="display: none;"><input type="text" name="chkResultCd_<%=i %>" id="chkResultCd_<%=i %>"  value="" /></div>
   		</td>
   	    <td style="text-align: center; text-indent: 0px;"><input type="radio" name="test_<%=i %>" id="test_<%=i %>" value="<%=getApprSrdList.getRow(i).get("A_RATE").replace("점", "") %>" <%=getApprSrdList.getRow(i).get("A_RATE").replace("점", "").equals(getApprSrdList.getRow(i).get("APPR_RATE")) ? "checked=\"checked\" " : ""%> /><div>(<%=getApprSrdList.getRow(i).get("A_RATE") %>)</div></td>
   		<td style="text-align: center; text-indent: 0px;"><input type="radio" name="test_<%=i %>" id="test_<%=i %>" value="<%=getApprSrdList.getRow(i).get("B_RATE").replace("점", "") %>" <%=getApprSrdList.getRow(i).get("B_RATE").replace("점", "").equals(getApprSrdList.getRow(i).get("APPR_RATE")) ? "checked=\"checked\" " : ""%> /><div>(<%=getApprSrdList.getRow(i).get("B_RATE") %>)</div></td>
   		<td style="text-align: center; text-indent: 0px;"><input type="radio" name="test_<%=i %>" id="test_<%=i %>" value="<%=getApprSrdList.getRow(i).get("C_RATE").replace("점", "") %>" <%=getApprSrdList.getRow(i).get("C_RATE").replace("점", "").equals(getApprSrdList.getRow(i).get("APPR_RATE")) ? "checked=\"checked\" " : ""%> /><div>(<%=getApprSrdList.getRow(i).get("C_RATE") %>)</div></td>
   		<td style="text-align: center; text-indent: 0px;"><input type="radio" name="test_<%=i %>" id="test_<%=i %>" value="<%=getApprSrdList.getRow(i).get("D_RATE").replace("점", "") %>" <%=getApprSrdList.getRow(i).get("D_RATE").replace("점", "").equals(getApprSrdList.getRow(i).get("APPR_RATE")) ? "checked=\"checked\" " : ""%> /><div>(<%=getApprSrdList.getRow(i).get("D_RATE") %>)</div></td>
   		<td style="text-align: center; text-indent: 0px;"><input type="radio" name="test_<%=i %>" id="test_<%=i %>" value="<%=getApprSrdList.getRow(i).get("E_RATE").replace("점", "") %>" <%=getApprSrdList.getRow(i).get("E_RATE").replace("점", "").equals(getApprSrdList.getRow(i).get("APPR_RATE")) ? "checked=\"checked\" " : ""%> /><div>(<%=getApprSrdList.getRow(i).get("E_RATE") %>)</div></td>
   	</tr>
   	
   	
   	<%
		   	all_sum_stock_rate += sum_stock_rate;
			sum_stock_rate = 0;
			 idx++;
		}%>
	
	<%	
   	if (params.get("P_CHARGE_CD").equals("C")) {%>
   	<TR  style="height: 23px;" >
		<TD class="insert_table_title"  style="text-align: center;"  colspan="2">특 기 사 항</TD>
	    <TD style="text-align: left;" colspan="8">&nbsp;<input type="text"   class="input byteChk ctrlTarget"  style="width: 98%;" name="APPR_NOTE" id="APPR_NOTE" value="<%=vo.get("APPR_NOTE") %>" /></TD>
    </TR>
    </table>
	<%} else
	{%>
		</table><input type="hidden" name="APPR_NOTE" id="APPR_NOTE" value="<%=vo.get("APPR_NOTE")%>" /> 
	<%} %>
	


<div style="width: 100%; text-align: center; margin-top: 20px;">
	<span id="save" name="save" class="btnSearch center"><a href="javascript:void(0);" id="btn_save">저장</a></span>
	<span id="confirm" name="confirm" class="btnSearch center"><a href="javascript:void(0);" id="btnAppReq">확정</a></span>
	<span id="close" name="close" class="btnSearch center"><a href="javascript:void(0);" id="btn_close">닫기</a></span>	
</div>
 
</form>