<%@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.databean.Simtapstran, com.csc.library.session.InitialRecord"%>
<%@page import="com.csc.library.database.DataSet, com.csc.library.components.ListBox, com.csc.library.report.ReportUDF"%>
<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("apv"), screen.getUProfile().get("employeeid"));
	
	CscCalendar cDate = new CscCalendar();
	DbInquiry taps0 = new InitialInquiry(screen.getUProfile()).getDbInquiry("TAPSTRAN0");
	taps0.setColumn("apsid,apsperiodstart,apsperiodend");
	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+=")";}
	String desc ="tdesc";
	if(!screen.getUProfile().get("lang").equals("tha"))desc="edesc";
	
	String issearch = ck.chkNullString(request.getParameter("issearch"));
	String apv = ck.chkNullString(request.getParameter("apv"), screen.getUProfile().get("employeeid"));	
	String emp_position = ck.chkNullString(request.getParameter("emp_position"),"");
	String bu1 = ck.chkNullString(request.getParameter("bu1"),"");	
	String bu2 = ck.chkNullString(request.getParameter("bu2"),"");	
	String empid = ck.chkNullString(request.getParameter("empid"),"");
	String level = ck.chkNullString(request.getParameter("level"),"");
	String status =  ck.chkNullString(request.getParameter("status"),"all");
	String astid = ck.chkNullString(request.getParameter("astid"),"");
	
	String filter = "";
	if(issearch.equals("1")){
		String filter_emp = "";
		if(!emp_position.equals("")){	
			filter_emp += "and emp_position = '"+emp_position+"' ";
		}
		if(!bu1.equals("")){	
			filter_emp += "and bu1 = '"+bu1+"' ";
		}
		if(!bu2.equals("")){	
			filter_emp += "and bu2 = '"+bu2+"' ";
		}
		if(!empid.equals("")){	
			filter_emp += "and empid = '"+empid+"' ";
		}
		if(!filter_emp.equals("")){
			filter += " and apsassessy in (select employeeid from memployee where companyid = '"+screen.getUProfile().get("companyid")+"' "+filter_emp+")";
		}
	}
	
	String issave =  ck.chkNullString(request.getParameter("__issave"));
	String saveList =  ck.chkNullString(request.getParameter("__saveList"));
	if(issave.equals("1") && !saveList.equals("")){
		Simtapstran simtaptran= (Simtapstran)new InitialRecord(screen.getUProfile()).getDbRecord("Simtapstran");
		simtaptran.saveApproveList(saveList);
	}
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<link href="../CSS/bootstrap.css" rel="stylesheet"  type="text/css">
<link href="../CSS/bootstrap_csc_backend.css" rel="stylesheet"  type="text/css">
<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
<script type='text/javascript' src="../JS/bootstrap.js"></script>
<script  language="JavaScript" src="../JS/SCREEN.js"></script>

<script type='text/javascript' src='../JS/ICONSMENU.js'></script>
<script language='javascript' src='../JS/HOTKEY.js'></script>
<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>

<script language="JavaScript" type="text/JavaScript">

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=="emp_position" )
		helpReturn="emp_position:positionid,MPOSITION@TDESC";	
	 else if(inputName=="empid" )
		helpReturn="empid:employeeid,MEMPLOYEE@FULLNAME";			
	else if(inputName=="apv" )
		helpReturn="apv:employeeid,MEMPLOYEE@FNAME";			

	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){
		issearch.value="1";
		submit();
	}
}

function calAge(strDate){
	var currentYear = parseInt(new Date().getYear());
	var birthdateYear = parseInt(strDate.substring(6,10));
	var age = currentYear-birthdateYear;
	document.write(age);
}
function saveConfirm(){
	with(document.cscform){
		bCon=confirm(MyCode[3]);
		if (bCon==true)	{
			__saveList.value = "";
			var obj = document.getElementsByName("__approve");
			if(typeof obj!="undefined"){
				for(i=0; i<obj.length; i++){
					if(obj[i].checked){
						__saveList.value += ((__saveList.value != '')?",":"")+obj[i].value.replace('status', document.getElementById("__status:"+obj[i].value).value);
					}
				}
			}
			__issave.value = "1";
			submit();
		}
	}
}
function issave(){
	with(document.cscform){
		if(issave.value == '1'){
			alert(MyCode[18]);
		}
	}
}
function goASP(apsid,apsassessor,apsassessy,stat,lv){
	with(document.cscform){
		var isread = "0";
		var page = "../EMPVIEW/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");
	}
}
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style2 {color: #339933}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="cscform" method="post" action="APP_EMV_HR_T.jsp" >

		<input type="hidden" name="__screen"  value="APP_EMV_HR_T">
		<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%>">
		<input type="hidden" name="issearch" value="<%=issearch%>">
		<input type="hidden" name="__issave" value="">
		<input type="hidden" name="__saveList" value="">

<!----------BEGIN CSC INITIAL ZONE ------------------------><br>
  <div align="center">
	<table  cellpadding="0"  cellspacing="0" class="large">
		<tr >
			<td  class="header">APP_EMV_HR_T,&nbsp;<script language="JavaScript">swapLang("Edit Status and Result Assess");</script>&nbsp;</td>
		</tr>
		<tr >
			<td >					
				<table border="0" align="center" cellpadding="0" cellspacing="1" class="largest">
					<tr>
						<td width="20%"><div align="right"><script language="JavaScript">swapLang("Assessor");</script> *</div></td>
						<td width="80%">&nbsp;
                             <input type="text" name="apv"  value="<%=apv%>" size="15" />
                             <a href="javascript: goHelp('MEMPLOYEEHELP','apv');"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" width="20" height="20" border="0" align="absmiddle"  /></a> <span class="column-input">
                             <input name="MEMPLOYEE@FNAME" type="text" class="text" id="MEMPLOYEE@FNAME" size="40" readonly="readonly" value="<%=ck.chkNullString(request.getParameter("MEMPLOYEE@FNAME"),screen.getUProfile().get("fullname")) %>" />
                                </span>
						</td>
					</tr>
					<tr>
						<td ><div align="right"><script language="JavaScript">swapLang("Position");</script></div></td>
						<td >&nbsp;
							<input type="text" name="emp_position"  value="<%=emp_position%>" size="15" />&nbsp;<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="<%=ck.chkNullString(request.getParameter("MPOSITION@TDESC")) %>" />
							</span>														
						</td>
					</tr>
					<tr>
						<td><div align="right"><script language="JavaScript">swapLang("BU1");</script></div></td>
						<td >&nbsp;
							<input type="text" name="bu1"  value="<%=bu1%>" size="15" />  <a href="javascript: goHelp('MBU1HELP','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="<%=ck.chkNullString(request.getParameter("MBU1@TDESC")) %>" />
							</span>
						</td>
					</tr>
					<tr>
						<td><div align="right"><script language="JavaScript">swapLang("BU2");</script></div></td>
						<td >&nbsp;
							<input type="text" name="bu2"  value="<%=bu2%>" size="15" />  <a href="javascript: goHelp('MBU2HELP','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="<%=ck.chkNullString(request.getParameter("MBU2@TDESC")) %>" />
							</span>
						</td>
					</tr>
					<tr>
						<td><div align="right">ผู้ถูกประเมิน</div></td>
						<td >&nbsp;
							<input type="text" name="empid"  value="<%=empid%>" size="15" />  <a href="javascript: goHelp('MEMPLOYEEHELP','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="<%=ck.chkNullString(request.getParameter("MEMPLOYEE@FULLNAME")) %>" />
							</span>
						</td>
					</tr>
					<tr>
						<td><div align="right"><script language="JavaScript">swapLang("Assess LV");</script></div></td>
						<td >&nbsp;
							<select name="level">
								<option value=""	<%=(level.equals("")?"selected":"")%>><script language="JavaScript">swapLang("All");</script></option>
								<option value="1" <%=(level.equals("1")?"selected":"")%>><script language="JavaScript">swapLang("Assessor LV");</script>&nbsp;1</option>
								<option value="2" <%=(level.equals("2")?"selected":"")%>><script language="JavaScript">swapLang("Assessor LV");</script>&nbsp;2</option>
								<option value="3" <%=(level.equals("3")?"selected":"")%>><script language="JavaScript">swapLang("Assessor LV");</script>&nbsp;3</option>
								<option value="4" <%=(level.equals("4")?"selected":"")%>><script language="JavaScript">swapLang("Assessor LV");</script>&nbsp;4</option>
								<option value="5" <%=(level.equals("4")?"selected":"")%>><script language="JavaScript">swapLang("Assessor LV");</script>&nbsp;5</option>
							</select>
						</td>
					</tr>
					<%
						String sys_status[] = new ReportUDF().getSystemCode("APPSTATUS",screen.getUProfile().get("lang"));
					%>
					<tr>
						<td align="right"><script language="JavaScript">swapLang("Status");</script></td>
						<td >&nbsp;
							<select name="status">
								<option value="all" <%=(status.equals("all"))?"selected":""%>><script language="JavaScript">swapLang('All');</script></option>
								<%
									String sysstatus[] = new ReportUDF().getSystemCode("APPSTATUS",screen.getUProfile().get("lang"));
									for(int i=0;i<sysstatus.length;i++){
								%>
									<option value="<%=sysstatus[i].split(",")[0]%>"  <%=(status.equals(sysstatus[i].split(",")[0]))?" selected":""%>><%=sysstatus[i].split(",")[1]%></option>
								<%		
									}
								%>
							</select>
						</td>
					</tr>

					<tr>
						<td  class="buttonline" colspan="7"><div align="center">
							<button type="button" class="btn btn-primary width100" swlang code="SW013168" onClick="fixSearch();">SEARCH</button>&nbsp;
							<button type="button" class="btn btn-primary width100" swlang code="SW013175" onClick="saveConfirm();">SAVE</button>
						</div>
						</td>
					</tr>
					<!-- <tr>
						<td><div align="right">ประเภทการประเมิน</div></td>
						<td >&nbsp;
							<select name="astid">
								<option value=""><script language="JavaScript">swapLang('All');</script></option>
								<option value="AP10" <%=(astid.equals("AP10")?"selected":"")%> >ประเมิน KPI</option>
								<option value="AP30"   <%=(astid.equals("AP30")?"selected":"")%> >ประเมิน Competency</option>
							</select>&nbsp;&nbsp;<a href="javascript:fixSearch();"><img src="../IMAGES/BUTTON/SEARCH.gif"  border="0" align="middle" /></a> &nbsp;&nbsp;<a href="javascript:saveConfirm();"><img src="../IMAGES/BUTTON/SAVE.gif" border="0" align="middle" /></a>																		
						</td>
					</tr> -->
				</table>
			</td>
		</tr>
		<%
				String field[] = {"apsapprove1","apsapprove2","apsapprove3","apsapprove4","apsapprove5"};
				String field_status[] = {"apsappstatus1","apsappstatus2","apsappstatus3","apsappstatus4","apsappstatus5"};
				String field_desc[] = {"Level_1","Level_2","Level_3","Level_4","Level_5"};

				loop_lv : for(int i=0; issearch.equals("1") && i<field.length; i++){
					if(!level.equals("") && (Integer.parseInt(level)-1) != i){
						continue loop_lv;
					}
					if(!status.equals("") && !status.equals("all")){
						filter += " and "+field_status[i]+" = '"+status+"'";
					}
					if(!astid.equals("")){
						filter += " and astid = '"+astid+"'";
					}
					screen.inq.setFilter(dateExp+" and ("+field[i]+"='"+employeeid+"') "+filter+" and astid = 'AP10'");
					screen.inq.refresh();
					boolean hasdata = false;
					int j=0;
					for(; screen.nextRec(); j++){
						hasdata = true;
						if(j==0){
						%>
		<tr >
			<td>
				<table align="center" cellpadding="1" bgcolor="#666666" cellspacing="1" class="maxsize" colspan="6" border="0">
					<tr >
						<td colspan="8" class="title1"><b>
							<script language="JavaScript">swapLang("Assessor LV");</script>&nbsp;<%=i+1%></b>
						</td>
					</tr>
					<tr>
						<td width="5%" class="title1" align="center"><script language="javascript">swapLang('Select');</script></td>
						<td width="13%" class="title1" align="center"><script language="javascript">swapLang('Status');</script></td>
						<td width="20%" class="title1" align="center"><script language="javascript">swapLang('Name Surname');</script></td>
						<td width="15%" class="title1" align="center"><script language="javascript">swapLang('Position');</script></td>
						<td width="15%" class="title1" align="center"><script language="javascript">swapLang('BU1');</script></td>
						<td width="15%" class="title1" align="center"><script language="javascript">swapLang('BU2');</script></td>
						<td width="7%" class="title1" align="center"><script language="javascript">swapLang('Service Year');</script></td>
						<!-- <td width="10%" class="title1" align="center"><script language="javascript">swapLang('Type');</script></td> -->
					</tr>
					<%
						}
					%>
					<tr> 
						<td align="center"><input type="checkbox" name="__approve" value="<%=screen.getDataLabel("APSID")+":"+screen.getDataLabel("APSASSESSY")+":"+screen.getDataLabel("APSASSESSOR")+":status:"+(i+1)%>"></td>
						<td>	
							<select name="__appstatus" id="<%="__status:"+screen.getDataLabel("APSID")+":"+screen.getDataLabel("APSASSESSY")+":"+screen.getDataLabel("APSASSESSOR")+":status:"+(i+1)%>">
								<%
									for(int s_i=0; s_i<sysstatus.length; s_i++){
								%>
									<option value="<%=sysstatus[s_i].split(",")[0]%>"  <%=(screen.getDataLabel(field_status[i]).equals(sysstatus[s_i].split(",")[0]))?" selected":""%>><%=sysstatus[s_i].split(",")[1]%></option>
								<%		
									}
								%>
							</select>
						</td>
						<td >
							<a href="javascript:goASP('<%=screen.getDataLabel("APSID")%>','<%=screen.getDataLabel("APSASSESSOR")%>','<%=screen.getDataLabel("APSASSESSY")%>','<%=screen.getDataLabel(field_status[i])%>','<%=(i+1)%>');"><%=screen.getDataLabel("simemp","fullname")%></a>
						</td>
						<td >&nbsp;<%=screen.getDataLabel("mposition","tdesc")%></td>
						<td >&nbsp;<%=screen.getDataLabel("mbu1","tdesc")%></td>
						<td >&nbsp;<%=screen.getDataLabel("mbu2","tdesc")%></td>
					<%
						String[] y = screen.getDataLabel("simemp","empworkages").split(" ");	
					%>
						<td  align="center"><%=y[0] %>&nbsp;<script language="javascript">swapLang('Year');</script></td>
						<!-- <td ><%//=screen.getDataLabel("mastype","tdesc")%></td> -->
					</tr>
					<%
					}
					if(hasdata){
					%>
					<tr >
						<td colspan="8" align="right" class="inframe">
							<script language="JavaScript">swapLang("Total Assessor");</script>&nbsp;&nbsp;<%=j++%>&nbsp;<script language="JavaScript">swapLang("Man");</script>
						</td>
					</tr>
				</table>	
			</td>
		</tr>
					<%
					}
				}
				%>
			
		<tr>
			<td  class="bottom"></td>
		</tr>
    </table>
  </div>
	<input type="hidden" name="issave" value="<%=issave%>">
	<script language="JavaScript">issave();</script>
</form>
</body>
</html>
