<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.UIManager, com.csc.library.utilities.CheckNull"%>
<%@page import="com.csc.library.entry.HelpEntry, com.csc.library.utilities.CscCalendar"%>
<%@page import="com.csc.library.session.DbInquiry, com.csc.library.session.InitialInquiry"%>
<%@page import="com.csc.library.database.DataSet, com.csc.library.components.ListBox"%>
<jsp:useBean id="APP_EMV005_1" class="com.csc.library.system.Task" scope="page" />
<% 
	
	APP_EMV005_1.setChannel(request, response);
	HelpEntry screen = (HelpEntry) APP_EMV005_1.process("HelpEntry","APP_EMV_HR");
	CheckNull ck = new CheckNull(); 
	String employeeid = ck.chkNullString(request.getParameter("__employeeid"), screen.getUProfile().get("employeeid"));
	String filter = "";
	CscCalendar cDate = new CscCalendar();
	DbInquiry taps0 = new InitialInquiry(screen.getUProfile()).getDbInquiry("TAPSTRAN0");
	taps0.setColumn("apsid,apsperiodstart,apsperiodend");

	String f1="apsenddate >= '"+cDate.getYYYYMMDD()+"' and apsstartdate <= '"+cDate.getYYYYMMDD()+"'  and astid = 'AP10'";
	//taps0.setFilter(f1);
	taps0.setFilter(f1);
	taps0.refresh();
	String dateExp = "apsid=''";
	while(taps0.next()){
		if(taps0.recNo()==1){
			dateExp = "(apsid='"+taps0.getString("apsid")+"'";
		}else{
			dateExp +=" OR apsid='"+taps0.getString("apsid")+"' ";
		}
	}	
	if(!dateExp.equals("apsid=''")){dateExp+=")";}

	//((Simtapstran_kkb1)screen.inq.getCurrentDbRecord()).approveConfirm();	

	String desc ="tdesc";
	if(!screen.getUProfile().get("lang").equals("tha"))desc="edesc";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template-emv-main.dwt.jsp" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Employee View</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- InstanceBeginEditable name="head" -->
<!-- Begin CSS Links -->
<link rel="stylesheet" type="text/css" href="../CSS/DDMENU.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_DEFAULT.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_LAYOUT.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_LAYOUT_TWO.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_TEXT.css" />
<!-- End CSS Links -->
<!-- Begin Scripts -->
<script language="JavaScript"  type="text/javascript"src="../JS/EVENTS.js"></script>
<script language="JavaScript"  type="text/javascript" src="../JS/UTILITIES.js"></script>
<script language="JavaScript"  type="text/javascript"src="../JS/ACTIVE_OBJECT.js"></script>
<!-- Begin script for Dropdown Menu -->
<!-- DO NOT EDIT -->
<script language="JavaScript"  type="text/javascript" src="../JS/DDMENU.js"></script>
<!--[if lt IE 7]><script language="JavaScript" type="text/javascript" src="../JS/IEHOVER-FIX.js"></script><![endif]-->
<!-- DO NOT EDIT -->
<!-- End script for Dropdown Menu -->
<script language="JavaScript"  type="text/javascript" src="../JS/SCREEN.js"></script>
<script language="JavaScript"  type="text/javascript" src="../JS/HOTKEY.js"></script>

<!-- End Scripts -->
<!-- Begin Head -->
<!-- End Head -->
<script type="text/javascript">
setLang("<%=screen.getUProfile().get("lang")%>");
function goHelp(helpName,inputName){
	var helpReturn;
	var temp_fixCon;
	if(inputName=="__bu1" )
		helpReturn="__bu1:bu1id,MBU1@TDESC";
	 else if(inputName=="__bu2" )
		helpReturn="__bu2:bu2id,MBU2@TDESC";	
	 else if(inputName=="__bu3" )
		helpReturn="__bu3:bu3id,MBU3@TDESC";	
	temp_fixCon = document.cscform.__fixCon.value;
	document.cscform.__fixCon.value="";
	linkHelp_Return(helpName,helpReturn);
	
	document.cscform.__fixCon.value=temp_fixCon;
	
	
}
function fixSearch(){
	with(document.cscform){
		__shown.value="1";
		submit();
	}
}
function goConfirm(){
	with(document.cscform){
		__status.value="A";
		__cmd.value="ack";		
		submit();
	
	}
}

function goReturn(){
	with(document.cscform){
		__status.value="R";	
		__cmd.value="ack";		
		submit();
	}
}
function goCheck(emp_group,fieldName){
		with(document.cscform){
			var param="AS004_2C1.jsp?__emp_group="+emp_group+"&__fieldName="+fieldName+"&__bu1="+__bu1.value+"&__bu2="+__bu2.value;	
			win = window.open(param,"AS004_2C1","left=150,top=150,width=600,height=400,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
		}
}
function goASP(apsid,apsassessor,apsassessy,status,lv){
	with(document.cscform){
		if(status=='Q'){
			alert("ยังไม่สามารถประเมินได้");
		}else{
			var isread = (status=='A')?"1":"0";
			var page = (lv=='0')?"APP_EMV707":"APP_EMV707";
			var param=page+".jsp?apsid="+apsid+"&apsassessor="+apsassessor+"&apsassessy="+apsassessy+"&bpage="+__screen.value+"&ass_level="+lv+"&bu1=&bu2=&isread="+isread;	
			window.open(param,"Assess_Pages","left=150,top=150,width=750,height=750,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
		}
	}
}
function calAge(strDate){
	var currentYear = parseInt(new Date().getYear());
	var birthdateYear = parseInt(strDate.substring(6,10));
	var age = currentYear-birthdateYear;
	document.write(age);
}	
function clearAll(){
   with(document.cscform){
   		emp_position.disabled='disabled';
	   submit();
   }
}

function checkAll(){
		with(document.cscform){
			for(i=0;i<elements.length;i++){
					if(elements[i].type=="checkbox")
							elements[i].checked=true;
			}//end for
		}//end with
	}//end function
	function decheckAll(){
		with(document.cscform){
			for(i=0;i<elements.length;i++){
					if(elements[i].type=="checkbox")
							elements[i].checked=false;
			}//end for
		}//end with
	}//end function
//-->
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style2 {color: #339933}
-->
</style>
<!-- InstanceEndEditable -->
</head>
<body>
<div id="wrapper">
  <div id="header"><!-- InstanceBeginEditable name="header" -->
    <jsp:include page="EMV_HEADER.jsp" flush="true" />
    <!-- InstanceEndEditable -->  </div>
  <div id="topnav"><!-- InstanceBeginEditable name="top_navigation" -->
    <jsp:include page="EMV_TOPMENU.jsp" flush="true" />
    <!-- InstanceEndEditable -->  </div>
  <div id="container">
    <div id="sidebar"><!-- InstanceBeginEditable name="side_bar" -->
      <jsp:include page="EMV_SIDEBAR.jsp" flush="true" />
      <!-- InstanceEndEditable -->    </div>
    <div id="content"><!-- InstanceBeginEditable name="main_content" -->
    	<jsp:include page="EMV_HELPBAR.jsp" flush="true" />
      <!-- Begin Main Content -->
      <div class="content">
        <form name="cscform" method="post" action="APP_EMV_HR.jsp">
		<input type="hidden" name="__screen"  value="APP_EMV_HR">
		<input type="hidden" name="__help" value="">
		<input type="hidden" name="__cmd"  value="">
		<input type="hidden" name="__language" value ="<%=screen.getUProfile().get("lang")%>"> 
		<input type="hidden" name="__fixCon" value="">
		<input type="hidden" name="__shown" value="<%=ck.chkNullString(request.getParameter("__shown"),"")%>">
		<input type="hidden" name="__employeeid" value="<%=employeeid%>">
				<div class="content-box">
					<div class="content-header">
						<h2>
							<script language="JavaScript">swapLang("Search Condition")</script>
						</h2>
					</div>
					<table width="100%" border="0" cellpadding="0" cellspacing="1" class="table-content-list">
						<% 
							String tdesc = (screen.getUProfile().get("lang").equals("tha"))?"tdesc":"edesc";
							DataSet condition = new DataSet();
							condition.setDbName((String)screen.getUProfile().get("dbname"));
						%>
							<tr>
							  <td class="column-header-right">ผู้ประเมิน</td>
							  <td class="column-text"><%String app = ck.chkNullString(request.getParameter("app"),"");	%></td>
					  </tr>
							<tr>
								<td class="column-header-right"><script language="JavaScript">swapLang("Position");</script></td>
								<td class="column-text">
								<%String emp_position = ck.chkNullString(request.getParameter("emp_position"),"");	%>
									<input type="text" name="emp_position"  value="<%=emp_position%>" size="15" />  <a href="javascript: goHelp('MPOSITIONHELP','emp_position');"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" width="20" height="20" border="0" align="absmiddle"  /></a>
									<span class="column-input">
									<input name="MPOSITION@TDESC" type="text" class="text" id="MPOSITION@TDESC" size="40" readonly="readonly" value="<%=chk.chkNullString(request.getParameter("MPOSITION@TDESC")) %>" />
									</span>														</td>
							</tr>
							<tr>
								<td class="column-header-right"><script language="JavaScript">swapLang("BU1");</script></td>
							  <td class="column-text">
								<%String bu1 = ck.chkNullString(request.getParameter("bu1"),"");	%>
									<input type="text" name="bu1"  value="<%=bu1%>" size="15" />  <a href="javascript: goHelp('MBU1','bu1');"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" width="20" height="20" border="0" align="absmiddle"  /></a>
									<span class="column-input">
									<input name="MBU1@TDESC" type="text" class="text" id="MBU1@TDESC" size="40" readonly="readonly" value="<%=chk.chkNullString(request.getParameter("MBU1@TDESC")) %>" />
									</span>														
							</td>
							</tr>
						
							<tr>
								<td class="column-header-right"><script language="JavaScript">swapLang("BU2");</script></td>
								<td class="column-text">
								<%String bu2 = ck.chkNullString(request.getParameter("bu2"),"");	%>
									<input type="text" name="bu2"  value="<%=bu2%>" size="15" />  <a href="javascript: goHelp('MBU2','bu2');"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" width="20" height="20" border="0" align="absmiddle"  /></a>
									<span class="column-input">
									<input name="MBU2@TDESC" type="text" class="text" id="MBU2@TDESC" size="40" readonly="readonly" value="<%=chk.chkNullString(request.getParameter("MBU2@TDESC")) %>" />
									</span>	</td>
							</tr>

						<%String empid = ck.chkNullString(request.getParameter("empid"),"");	%>
							<tr>
								<td class="column-header-right">ผู้ถูกประเมิน</td>
								<td class="column-text">
								<input type="text" name="empid"  value="<%=empid%>" size="15" />  <a href="javascript: goHelp('MEMPLOYEE','empid');"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" width="20" height="20" border="0" align="absmiddle"  /></a>
									<span class="column-input">
									<input name="MEMPLOYEE@FULLNAME" type="text" class="text" id="MEMPLOYEE@FULLNAME" size="40" readonly="readonly" value="<%=chk.chkNullString(request.getParameter("MEMPLOYEE@FULLNAME")) %>" />
									</span>	</td>
							</tr>
							<tr>
								<td class="column-header-right"><script language="JavaScript">swapLang("Assess Level");</script></td>
								<td class="column-text">
									<select name="level">
									<%String level = ck.chkNullString(request.getParameter("level"),"");	%>
										<option value=""  <%=(level.equals("")?"selected":"")%>  >ทั้งหมด</option>
										<option value="1" <%=(level.equals("1")?"selected":"")%>  ><script language="JavaScript">swapLang("Assess");</script><script language="JavaScript">swapLang("Level 1");</script></option>
										<option value="2" <%=(level.equals("2")?"selected":"")%>  ><script language="JavaScript">swapLang("Assess");</script><script language="JavaScript">swapLang("Level 2");</script></option>
										<option value="3" <%=(level.equals("3")?"selected":"")%>  ><script language="JavaScript">swapLang("Assess");</script><script language="JavaScript">swapLang("Level 3");</script></option>
										<option value="4" <%=(level.equals("4")?"selected":"")%>  ><script language="JavaScript">swapLang("Assess");</script><script language="JavaScript">swapLang("Level 4");</script></option>
									</select>								</td>
							</tr>
							<tr>
								<td class="column-header-right"><script language="JavaScript">swapLang("Status");</script></td>
								<td class="column-text">
									<select name="status">
									<%String status = ck.chkNullString(request.getParameter("status"),"");	%>
										<option value="ALL" <%=(status.equals("ALL")?"selected":"")%> >ทั้งหมด</option>
										<option value=""   <%=(status.equals("")?"selected":"")%> >ยังไม่ประเมิน</option>
										<option value="W" <%=(status.equals("W")?"selected":"")%>>รอยืนยัน</option>
										<option value="A" <%=(status.equals("A")?"selected":"")%>>ประเมินแล้ว</option>
									</select>
									&nbsp;&nbsp;<a href="javascript:search();"><img src="../IMAGES/EMPVIEW/BUTTON/SEARCH.gif" align="middle" /></a> <img src="../IMAGES/EMPVIEW/BUTTON/SEARCHALL.gif" width="108" height="23" align="middle" /> 								</td>
							</tr>
						</table>
		  </div>
					<div class="content-box">
						<div class="content-header">
							<h2>	
								<script language="JavaScript">swapLang("Apprisal Information")</script>
							</h2>
						</div>
				<%

				String field[] = {"apsapprove1","apsapprove2","apsapprove3","apsapprove4"};
				String field_status[] = {"apsappstatus1","apsappstatus2","apsappstatus3","apsappstatus4"};
				String field_desc[] = {"Level_1","Level_2","Level_3","Level_4"};
				int running = 0;

				if(!level.equals("")){
				 	field[0] = "apsapprove"+level;						
				}			
				if(!emp_position.equals("")){
					filter=" emp_position ='"+emp_position+"' ";
				}
				if(!bu1.equals("")){
					if(filter.equals(""))
						filter=" bu1 ='"+bu1+"' ";
					else	
						filter+=" and bu1 ='"+bu1+"' ";
				}			
				if(!bu2.equals("")){
					if(filter.equals(""))
						filter=" bu2 ='"+bu2+"' ";
					else	
						filter+=" and bu2 ='"+bu2+"' ";
				}							
				
				if(!empid.equals("")){
					filter=" apsassessy ='"+empid+"' ";
				}		
				
				
				if(!filter.equals("")){filter = " and ( "+filter+")";}

				for(int i=0; i<field.length; i++, running = 0){
					screen.inq.setFilter(dateExp+" AND ("+field[i]+"='"+employeeid+"') "+filter);
					screen.inq.refresh();
					boolean hasdata = false;
					while(screen.nextRec()){
						hasdata = true;
						if(screen.inq.recNo()==1){
						%>
							<div class="content-header">
								<div align="left">
									&nbsp;<script language="JavaScript">swapLang('<%=field[i]%>')</script>
								</div>
							</div>
							<table width="100%" border="0" cellpadding="0" cellspacing="1" class="table-content-list">           
								<tr>
								<td width="32" class="column-header">เลือก</td>
								  <td width="73" class="column-header"><script language="javascript">swapLang('Status');</script></td>
								 
								  <td width="199" class="column-header"><script language="javascript">swapLang('Assessy');</script></td>
								  <td width="136" class="column-header"><script language="javascript">swapLang('Position');</script></td>
								  <td width="120" class="column-header">สายงาน</td>
									
									 <td width="111" class="column-header">ฝ่าย</td>
								  <td width="54" class="column-header"><script language="javascript">swapLang('Service Year');</script></td>
									
								</tr>
						<%
						}
						%>
								<tr>
								<td class="column-text-center" ><label>
								  <input type="checkbox" name="__runno:<%=screen.getDataLabel("runno")%>:apsapprove<%=i+1%>" value="<%=screen.getDataLabel("runno")%>" />
								</label></td>
									<td class="column-text-center" >
									<%
									running++;
										if((screen.getDataLabel(field_status[i]).equals(""))||(screen.getDataLabel(field_status[i]).equals("Q"))||(screen.getDataLabel(field_status[i]).equals("R"))){
									%>			
										<span class="style1"><%=screen.inq.getCurrentDbRecord().getSystemCode(field_status[i])%></span>
									<%
										}else{
											if(screen.getDataLabel(field_status[i]).equals("A")){
									%>
											<span class="style2"><%=screen.inq.getCurrentDbRecord().getSystemCode(field_status[i])%></span>
									<%
											}else{
									%>
										<%=screen.inq.getCurrentDbRecord().getSystemCode(field_status[i])%>
									<%
											}
										}
									%>
									</td>
									
									<td class="column-text"><a href="javascript:goASP('<%=screen.getDataLabel("APSID")%>','<%=screen.getDataLabel("APSASSESSOR")%>','<%=screen.getDataLabel("APSASSESSY")%>','<%=screen.getDataLabel(field_status[i])%>','<%=field[i].substring(field[i].length()-1)%>');"><%=screen.getDataLabel("simemp","fullname")%></a>
									</td>
										<td class="column-text"><%=screen.getDataLabel("mposition","tdesc")%></td>
									<td class="column-text"><%=screen.getDataLabel("mbu1","tdesc")%></td>
								
									<td class="column-text-center"><%=screen.getDataLabel("mbu2","tdesc")%></td>
									<%
										String[] y = screen.getDataLabel("simemp","empworkages").split(" ");	
									%>
									<td class="column-text-center"><%=y[0] %> ปี</td>
									
								</tr>
						<%
					}
					if(hasdata){
					%>
						<tr>
								<td class="column-text-center"  colspan="6"><div align="right">จำนวนผู้ถูกประเมิน <%=running%> คน</div></td>
								<td class="column-text-center">&nbsp;</td>
						</tr>
							</table>
						
					<%
					}
					if(!level.equals("")){
				 	 		break;
					}		
				}
				%>
			</div>
        </form>
      </div>
	          <p align="center"><A href="javascript:checkAll();"><img src="../IMAGES/EMPVIEW/BUTTON/SELECT.gif" width="80" height="23" align="middle" /></A>&nbsp; <A href="javascript:decheckAll();"><img src="../IMAGES/EMPVIEW/BUTTON/DESELECT.gif" width="80" height="23" align="middle" /></A>&nbsp; <img src="../IMAGES/EMPVIEW/BUTTON/CONF_KPI.gif" width="144" height="23" align="middle" /></p>
      <!-- End Main Content -->
      <!-- InstanceEndEditable -->    </div>
  </div>
  <div id="footer"><!-- InstanceBeginEditable name="footer" -->
    <jsp:include page="EMV_FOOTER.jsp" flush="true" />
    <!-- InstanceEndEditable -->  </div>
</div>
</body>
<!-- InstanceEnd --></html>
