<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.databean.*,com.csc.library.session.*,com.csc.library.database.*,com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*,java.text.*"%>
<jsp:useBean id="AS004_2" class="com.csc.library.system.Task" scope="page" />
<%AS004_2.setChannel(request, response);%>
<%HelpEntry screen = (HelpEntry) AS004_2.process("HelpEntry","AS004_2_HR");%>

<%	CheckNull ck = new CheckNull(); 
String employeeid=screen.getUProfile().get("employeeid");
String fullname=screen.getUProfile().get("fullname");
if(!ck.chkNullString(request.getParameter("__employeeid"),"").equals("")){
	employeeid= request.getParameter("__employeeid");
	DbInquiry emp_full = new InitialInquiry(screen.getUProfile()).getDbInquiry("MEMPLOYEE");
	emp_full.setColumn("employeeid,prefix,fname,lname");
	emp_full.setFilter("employeeid='"+employeeid+"'");

	emp_full.refresh();
	emp_full.next();
	fullname = emp_full.getString("fullname");
}
int  total_c=0;
String sbu1,sbu2,sbu3,spos,ssor,sSwork,sEwork,sSage,sEage,sgro;  //APSASSESSOR
sbu1=ck.chkNullString(request.getParameter("__bu1"),"");
sbu2=ck.chkNullString(request.getParameter("__bu2"),"");
sbu3=ck.chkNullString(request.getParameter("__bu3"),"");
spos=ck.chkNullString(request.getParameter("__pos"),"");
ssor=ck.chkNullString(request.getParameter("__sor"),"");
sgro=ck.chkNullString(request.getParameter("__gro"),"");

sSwork=ck.chkNullString(request.getParameter("__startWorkAge"),"");
sEwork=ck.chkNullString(request.getParameter("__endWorkAge"),"");

sSage=ck.chkNullString(request.getParameter("__startAge"),"");
sEage=ck.chkNullString(request.getParameter("__endAge"),"");
ThaiUtilities thai = new ThaiUtilities();

String filter = "";
if(!sbu1.equals(""))filter =" and bu1='"+sbu1+"'";

if(!sbu2.equals(""))filter =filter+" and bu2='"+sbu2+"'";

if(!sbu3.equals(""))filter =filter+" and bu3='"+sbu3+"'";

if(!spos.equals(""))filter =filter+" and emp_position='"+spos+"'";

if(!ssor.equals(""))filter =filter+" and apsassessor='"+ssor+"'";
if(!sgro.equals(""))filter =filter+" and job in ( select jobcodeid from mjobcode where jobgroup='"+sgro+"') ";

CscCalendar sEworkDate = new CscCalendar(sEwork);
sEworkDate= sEworkDate.decMonth(sEworkDate.getMonth()+(12-sEworkDate.getMonth()));
 sEworkDate.setDate(sEworkDate.getDayInMonth());
sEwork =sEworkDate.getYYYYMMDD();
if((!sSwork.equals(""))&&(!sEwork.equals(""))){
	filter =filter+" and  APSASSESSY in (select employeeid from memployee where startdate <='"+sSwork+"'  and startdate >='"+sEwork+"' and  status='A') ";
}

CscCalendar sEageDate = new CscCalendar(sEage);
//sEageDate = sEageDate.incYear(1);
sEageDate= sEageDate.decMonth(sEageDate.getMonth()+(12-sEageDate.getMonth()));
 sEageDate.setDate(sEageDate.getDayInMonth());
sEage =sEageDate.getYYYYMMDD();
if((!sSage.equals(""))&&(!sEage.equals(""))){
		filter =filter+" and  APSASSESSY in (select employeeid from memployee where BIRTHDAY <='"+sSage+"'  and BIRTHDAY >='"+sEage+"'  and  status='A') ";
}

CscCalendar cDate = new CscCalendar();
DbInquiry taps0 = new InitialInquiry(screen.getUProfile()).getDbInquiry("TAPSTRAN0");
taps0.setColumn("apsid,apsstartdate,apsenddate");
String f1="apsenddate >= '"+cDate.getYYYYMMDD()+"'   AND";
	f1+=" apsstartdate <='"+cDate.getYYYYMMDD()+"'  ";
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+=")";}

screen.inq.setFilter(dateExp+"  AND astid='AP10' AND APSAPPROVE1='"+employeeid+"'"+filter);	
if(!ck.chkNullString(request.getParameter("__orderBy"),"").equals("")){
	screen.inq.setOrderBy(request.getParameter("__orderBy"));
}else{
	screen.inq.setOrderBy("emp_group,apsappstatus1,apsappgrade1,apsgrade,apssumscore DESC,cast(APSASSDESC as int)");
}
((Simtapstran_kkb)screen.inq.getCurrentDbRecord()).approveConfirm();		
 String desc ="tdesc";
 if(!screen.getUProfile().get("lang").equals("tha"))desc="edesc";
 DataSet dsBu1 = new DataSet("Select Distinct apsapprove1,BU1 ,MBU1.TDESC AS TDESC, MBU1.EDESC AS EDESC from TAPSTRAN , MBU1 where  "+dateExp+" and TAPSTRAN.astid='AP10' and TAPSTRAN.bu1=MBU1.bu1id and  apsapprove1='"+employeeid+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
// "032299"+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
dsBu1.initConnection(screen.getUProfile());

 DataSet dsBu2 = new DataSet("Select Distinct apsapprove1,BU2,MBU2.TDESC AS TDESC, MBU2.EDESC AS EDESC from TAPSTRAN, MBU2 where  "+dateExp+" and TAPSTRAN.astid='AP10' and TAPSTRAN.bu2=MBU2.bu2id and  apsapprove1='"+employeeid+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
//"032299"+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
dsBu2.initConnection(screen.getUProfile()); 


DataSet dsBu3 = new DataSet("Select Distinct apsapprove1,BU3,MBU3.TDESC AS TDESC, MBU3.EDESC AS EDESC from TAPSTRAN, MBU3 where  "+dateExp+" and TAPSTRAN.astid='AP10' and TAPSTRAN.bu3=MBU3.bu3id and  apsapprove1='"+employeeid+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
dsBu3.initConnection(screen.getUProfile());

DataSet dsGro = new DataSet("Select Distinct apsapprove1, MJOBGROUP.JOBGROUPID,MJOBGROUP.TDESC AS TDESC, MJOBGROUP.EDESC AS EDESC from TAPSTRAN, MJOBGROUP, MJOBCODE  where  "+dateExp+" and TAPSTRAN.astid='AP10' and  TAPSTRAN.JOB=MJOBCODE.JOBCODEID AND  MJOBCODE.JOBGROUP=MJOBGROUP.JOBGROUPID  AND   apsapprove1='"+employeeid+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
dsGro.initConnection(screen.getUProfile());

DataSet dsPos = new DataSet("Select Distinct apsapprove1,emp_position,POSITIONID,MPOSITION.TDESC AS TDESC, MPOSITION.EDESC AS EDESC from TAPSTRAN, MPOSITION where  "+dateExp+" and TAPSTRAN.astid='AP10' and TAPSTRAN.emp_position=MPOSITION.POSITIONID and  apsapprove1='"+employeeid+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
dsPos.initConnection(screen.getUProfile());


DataSet dsSor = new DataSet("Select Distinct apsapprove1,APSASSESSOR,MEMPLOYEE.FNAME AS TDESC, MEMPLOYEE.EFNAME AS EDESC from TAPSTRAN, MEMPLOYEE where  "+dateExp+" and TAPSTRAN.astid='AP10' and TAPSTRAN.APSASSESSOR=MEMPLOYEE.EMPLOYEEID and  apsapprove1='"+employeeid+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
dsSor.initConnection(screen.getUProfile());
%>
<!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">
<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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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";	
	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){
		chkDate(__workage1,__workage2,__startWorkAge,__endWorkAge);
		genDate(__workage1,__startWorkAge);
		genDate(__workage2,__endWorkAge); 

		chkDate(__age1,__age2,__startAge,__endAge);
		genDate(__age1,__startAge); 
		genDate(__age2,__endAge); 
			
		__shown.value="1";		
		submit();
	}
}
	function chAll(){
		with(document.cscform){
			for(i=0;i<elements.length;i++){
					if(elements[i].type=="checkbox"){
						if(elements[i].checked){
							var listData = elements[i].value.split(":");				
					//		alert(elements[i].value+"=========="+listData[5]);
							if((listData[6]=='')||(listData[5]=='0')){								
								return false;
							}

						}
					}
			}//end for
			return true;
		}//end with
	}//end function
function goConfirm(){
if(chAll()){
	with(document.cscform){
		__status.value="A";
		__cmd.value="ack";		
		submit();	
	}
}else{
	alert("ไม่สามารถยืนยันพนักงานที่ไม่มีเกรดได้");
}
}
function goReturn(){
	with(document.cscform){
		__status.value="R";	
		__cmd.value="ack";		
		submit();
	}
}
function goCheck(emp_group,fieldName){

	with(document.cscform){
		for(i=0;i<elements.length;i++){
				if(elements[i].name.indexOf("__lineg")>=0){				
					if(elements[i].options[elements[i].selectedIndex].value=="apsappgrade1:"){
						elements[i].disabled="disabled";
					}
				}
			}
		__status.value="W";
		__cmd.value="ack";	
		__gochk.value=emp_group+":"+fieldName;
		submit();
	}
}
function goCheck1(emp_group,fieldName){
		with(document.cscform){
			var param="AS004_2C1.jsp?__emp_group="+emp_group+"&__fieldName="+fieldName+"&__appfield="+"APSAPPROVE1&__bu1="+__bu1.value+"&__bu2="+__bu2.value+"&__bu3="+__bu3.value+"&__gro="+__gro.value+"&__pos="+__pos.value+"&__sor="+__sor.value+"&__startWorkAge="+__startWorkAge.value+"&__endWorkAge="+__endWorkAge.value+"&__startAge="+__startAge.value+"&__endAge="+__endAge.value+"&__employeeid="+__employeeid.value;			
	//		alert(param);
			win = window.open(param,"AS004_2C1","left=150,top=150,width=600,height=400,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
			if(window.focus){win.focus();}
		}
}
function goASP700(apsid,apsassessor,apsassessy){
	with(document.cscform){
		action="ASP700.jsp?apsid="+apsid+"&apsassessor="+apsassessor+"&apsassessy="+apsassessy+"&bpage="+__screen.value+"&ass_level=2&bu1="+__bu1.value+"&bu2="+__bu2.value+"&isread=0&order="+__orderBy.value+"&bu3="+__bu3.value+"&gro="+__gro.value+"&pos="+__pos.value+"&sor="+__sor.value+"&startWorkAge="+__startWorkAge.value+"&endWorkAge="+__endWorkAge.value+"&startAge="+__startAge.value+"&endAge="+__endAge.value;		
		__orderBy.value="";
		submit();
	}

}
function goReASP700(apsid,apsassessor,apsassessy){
	with(document.cscform){
		action="ASP700.jsp?apsid="+apsid+"&apsassessor="+apsassessor+"&apsassessy="+apsassessy+"&bpage="+__screen.value+"&ass_level=2&bu1="+__bu1.value+"&bu2="+__bu2.value+"&isread=1&order="+__orderBy.value+"&bu3="+__bu3.value+"&gro="+__gro.value+"&pos="+__pos.value+"&sor="+__sor.value+"&startWorkAge="+__startWorkAge.value+"&endWorkAge="+__endWorkAge.value+"&startAge="+__startAge.value+"&endAge="+__endAge.value;		
		__orderBy.value="";
		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 setOrder(field){
	with(document.cscform){
		for(i=0;i<elements.length;i++){
			if(elements[i].name.indexOf("__lineg")>=0){				
					if(elements[i].options[elements[i].selectedIndex].value=="apsappgrade1:"){
						elements[i].disabled="disabled";
					}
			}
		}
		__orderBy.value="EMP_GROUP,"+field;
		__status.value="W";
		__cmd.value="ack";	
		fixSearch();
	}
}
function chkBox(){
		with(document.cscform){
			for(i=0;i<elements.length;i++){
					if(elements[i].type=="checkbox"){
						if(elements[i].checked){														
								return true;	
						}
					}
			}//end for
			return false;
		}//end with
}//end function
function goConfirm1(){

	var returnVal = true;
	if(chkBox()){
			with(document.cscform){
				for(i=0;i<elements.length;i++){		
					if(elements[i].name.indexOf("__lineg")>=0){				
			//			alert(elements[i].name+'    '+elements[i].options[elements[i].selectedIndex].value);
					//	if(elements[i].options[elements[i].selectedIndex].value==""){
							
							elements[i].disabled="disabled";
		//				}
					}else{
						if(elements[i].name.indexOf("__apsappstatus1:")>=0){				
		//					if(elements[i].options[elements[i].selectedIndex].value==""){
		//					alert(elements[i].name);
								elements[i].disabled="disabled";
			//				}
						}			
					}
				}
			}
			
			goConfirm();	
	}else{
		alert("โปรดเลือกพนักงานก่อน");
	}
}
function genDate(obj,nameOut){	
	with(document.cscform){
	var sYear,sMonth,sDate;
		var nDate= new Date();
		var outDate= new Date();
		sDate= nDate.getDate();

		sMonth=nDate.getMonth()+1;
		sYear=nDate.getFullYear();
		var sAge = obj.value.split(".");
		if(sAge[1]>sMonth){
			sYear = sYear-1; 
			sMonth = (sMonth+12)-sAge[1];
			sYear = sYear-sAge[0] ;
			outDate.setFullYear(sYear,sMonth-1,1);	
		}else{
			if(sAge[1]==sMonth){
				sYear = sYear-1; 
				sYear = sYear-sAge[0] ;
				outDate.setFullYear(sYear,12,1);	
			}else{
				sMonth =sMonth-sAge[1];
				sYear = sYear-sAge[0] ;			
				outDate.setFullYear(sYear,sMonth,1);				
			}
		}
		sMonth=outDate.getMonth();
		if(sMonth<10)sMonth='0'+sMonth;
		nameOut.value=outDate.getFullYear()+'-'+sMonth+'-0'+outDate.getDate();		

	}
}
function chMonth(sInput){
	with(document.cscform){
		var data = sInput.value.split(".");
		if(data[1]>11){
			sInput.value=data[0]+"."+"0"+data[1];
			sInput.value=sInput.value.substring(0,sInput.value.length-1)	;	
		}
	}
}
function chkDate(start,end,setStart,senEnd){
	with(document.cscform){
		if(!((start.value=='0.00')&&(end.value=='0.00'))){
				chMonth(start);
				chMonth(end);				
				if(start.value==end.value){
					start.value='0.00';
				}
		}else{
			setStart.disabled='disabled';
			senEnd.disabled='disabled';
		}

	}
}
function chk(inbo,stat,grad){

	with(document.cscform){

			var stat_1="";
			var grad_1 ="";
			var chk=true;
	
						for(i=0;i<elements.length;i++){	
							if(elements[i].name==stat){ 
								if((elements[i].status1=='W')||(elements[i].status1=='R')||(elements[i].status1=='0')||(elements[i].status1=='A')||(elements[i].status1=='')){
										stat_1=elements[i].value;
										if(inbo.checked){
											elements[i].disabled='disabled';
										}else{
											elements[i].disabled='';
										}
					}		/*	else{
									alert("กรุณาให้คะแนนประเมิลผลก่อน");
									inbo.checked="";
									chk=false;
								} */
							} 
						if(elements[i].name==grad){
								if((elements[i].status1=='W')||(elements[i].status1=='R')||(elements[i].status1=='0')||(elements[i].status1=='A')||(elements[i].status1=='')){
							//			alert(elements[i].value);
										grad_1=elements[i].value.split(':')[1];
										if(inbo.checked){
											elements[i].disabled='disabled';
										}else{
											elements[i].disabled='';
										}
									
								}	/*	else{
										if(elements[i].status1!='A'){
											alert("กรุณาให้คะแนนประเมิลผลก่อน");
											inbo.checked="";
											chk=false;
										}  
								}*/
							}			
						}	
				if((chk)&&(inbo.checked)){						
						var tmp =inbo.value.split(':');
						var data='';
					//	alert(tmp.length);
						for(i=0;i<8;i++){
							if(i==tmp.length-4){
								data=data+stat_1+':';					
							}else{
								if(i==tmp.length-3){
								data=data+grad_1+':';
								}else{
									if(i==tmp.length-2){
										if(stat_1=='A'){
											data=data+'W:';					
										}else{
											data=data+'0:';	
										}
									}else{
										if((i==tmp.length-1)&&(stat_1=='A')){
										data=data+grad_1+':';
										}else{
											data=data+tmp[i]+':';
										}
									}
								}		
							}
						//	alert(data);
						}
						data = data.substring(0,data.length-1);
					//	alert(data);
					inbo.value=data;	
				} 
		}
	
}
function viewHis(grade,apsassessy){
	with(document.cscform){
		var page = "ASP705.jsp?apsassessy="+apsassessy+"&grade="+grade+"&bpage="+__screen.value+"&bu1="+__bu1.value+"&bu2="+__bu2.value;
		window.open(page,"viewhis","left=150,top=150,width=750,height=500,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
	}
}
</script>
</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="AS004_2_HR.jsp" >
  

<!----------BEGIN CSC INITIAL ZONE ------------------------>

<%=screen.InitialVariable()%>

<!----------END CSC INITIAL ZONE -------------------------->

<input type="hidden"name="__screen"  value="AS004_2_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="__orderBy" value="emp_group,apsappstatus1,apssumscore DESC,apsappstatus2,cast(APSASSDESC as int)"> -->
    <input type="hidden" name="__orderBy" value="<%=ck.chkNullString(request.getParameter("__orderBy"),"")%>">
  <input type="hidden" name="__tdesc" value="">
  <input type="hidden" name="__apsobjective" value="">
  <input type="hidden" name="__shown" value="<%=ck.chkNullString(request.getParameter("__shown"),"")%>">
      <input type="hidden" name="__updatefield" value="APSAPPSTATUS1">
  <input type="hidden" name="__returnfield" value="APSSTATUS">
  <input type="hidden" name="__status" value="">
  <input type="hidden" name="__employeeid" value="<%=ck.chkNullString(request.getParameter("__employeeid"),"")%>">
   <input type="hidden" name="__update" value="">  
<input type="hidden" name="__total_c" value="<%=total_c%>">
  <br>
  <div align="center">
    <table  cellpadding="0"  cellspacing="0" class="large">
      <tr >
        <td  class="header">AS004_2,ประเมินผลระดับที่ 2
          <!-- <script language="javascript">swapLang('Save score');</script> -->
        &nbsp;</td></tr>
      <tr >
        <td  colspan="2">
        
          <div align="center">
            <table align="center" cellpadding="0" cellspacing="0"  class="largest" >
              <tr>
                <td><div align="right"><strong><script language="javascript">swapLang('assessor');</script></strong>&nbsp;</div></td>
                <td width="273">&nbsp;<strong><%=fullname%></strong></td>
                <td width="289"><strong>จำนวนผู้ถูกประเมิน :&nbsp;&nbsp;<%=screen.inq.recCount()%></strong></td>
                <td width="186"><!--<strong>ประจำปี :</strong>&nbsp;&nbsp;<strong><%=screen.getDataLabel("TAPSTRAN0","APSPERIODSTART")%></strong> --></td>
                <td width="100">&nbsp;</td>
      </tr>
              <tr>
                <td><div align="right"><%=screen.getLabel("bu1")%>&nbsp;</div></td>
                <td colspan="4">&nbsp;
                  <select name="__bu1" id="bu1">
                    <option value=""></option>
                    <%while(dsBu1.next()){				
					%>
                    <option value="<%=dsBu1.getString("bu1")%>" <%=(sbu1.equals(dsBu1.getString("bu1")))?"selected":""%>><%=dsBu1.getString(desc)%></option>
                    <%}%>
                  </select>                  &nbsp;&nbsp;&nbsp;<a href="javascript:fixSearch();"><img src="../IMAGES/BUTTON/SEARCH.gif" border="0" align="absmiddle"></a></td>
              </tr>
              <tr>
                <td><div align="right"><%=screen.getLabel("bu2")%>&nbsp;</div></td>
                <td colspan="4">&nbsp; <select name="__bu2" id="__bu2">
                    <option value=""></option>
                    <%while(dsBu2.next()){				
					%>
                    <option value="<%=dsBu2.getString("bu2")%>" <%=(sbu2.equals(dsBu2.getString("bu2")))?"selected":""%>><%=dsBu2.getString(desc)%></option>
                    <%}%>
                  </select></td>
              </tr>
              <tr>
                <td><div align="right"><%=screen.getLabel("bu3")%>&nbsp;</div></td>
                <td colspan="4">&nbsp; <select name="__bu3" id="__bu3">
                    <option value=""></option>
                    <%while(dsBu3.next()){				
					%>
                    <option value="<%=dsBu3.getString("bu3")%>" <%=(sbu3.equals(dsBu3.getString("bu3")))?"selected":""%>><%=dsBu3.getString(desc)%></option>
                    <%}%>
                  </select></td>
              </tr>
			   <tr>
                <td><div align="right">ตำแหน่งตามหน้าที่&nbsp;</div></td>
                <td colspan="4">&nbsp; 
                  <select name="__gro" id="select">
                    <option value=""></option>
                    <%while(dsGro.next()){				
					%>
                    <option value="<%=dsGro.getString("jobgroupid")%>" <%=(sgro.equals(dsGro.getString("jobgroupid")))?"selected":""%>><%=dsGro.getString(desc)%></option>
                    <%}%>
                     </select></td>
              </tr>
              <tr>
                <td><div align="right"><%=screen.getLabel("emp_position")%>&nbsp;</div></td>
                <td colspan="4">&nbsp; <select name="__pos" id="__pos">
                    <option value=""></option>
                    <%while(dsPos.next()){				
					%>
                    <option value="<%=dsPos.getString("positionid")%>" <%=(spos.equals(dsPos.getString("positionid")))?"selected":""%>><%=dsPos.getString(desc)%></option>
                    <%}%>
                  </select></td>
              </tr>
              <tr>
                <td><div align="right"><script language="javascript">swapLang('assessor');</script>
                    &nbsp;1&nbsp;</div></td>
                <td colspan="4">&nbsp; <select name="__sor" id="__sor">
                    <option value=""></option>
                    <%while(dsSor.next()){				
					%>
                    <option value="<%=dsSor.getString("apsassessor")%>" <%=(ssor.equals(dsSor.getString("apsassessor")))?"selected":""%>><%=dsSor.getString(desc)%></option>
                    <%}%>
                  </select></td>
              </tr>
              <tr>
                <td width="87"><div align="right">&nbsp;อายุงาน</div></td>
                <td colspan="4">&nbsp;  <INPUT TYPE='text' Name='__workage1' id='__workage1' SIZE='6' MAXLENGTH='6' VALUE='<%=ck.chkNullString(request.getParameter("__workage1"),"0.00")%>'  onClick="" onChange=""  onKeyPress="checkWordNumber(this.value);" onKeyUp="sysIsEdit();checkComma(this,2);" dir="" onBlur="chkLengthFloat1(this,__workage2,90)" onFocus="callDelComma(this);" class="numeric" alt="อายุงาน" >&nbsp;-&nbsp;<INPUT TYPE='text' Name='__workage2'   id='__workage2' SIZE='6' MAXLENGTH='6' VALUE='<%=ck.chkNullString(request.getParameter("__workage2"),"0.00")%>'  onClick="" onChange=""  onKeyPress="checkWordNumber(this.value);" onKeyUp="sysIsEdit();checkComma(this,2);" dir="" onBlur="chkLengthFloat2(this,__workage1,90);" onFocus="callDelComma(this);" class="numeric" alt="อายุ"  >
                  <input type="hidden" name="__startWorkAge" id="__startWorkAge" value='<%=ck.chkNullString(request.getParameter("__startWorkAge"),"")%>'>
                <input type="hidden" name="__endWorkAge" id="__endWorkAge"  value='<%=ck.chkNullString(request.getParameter("__endWorkAge"),"")%>'> (YY.MM   ตัวอย่าง 1.11)</td>
              </tr>              
              <tr>
                <td width="87"><div align="right">&nbsp;อายุ</div></td>
                <td colspan="4">&nbsp;  <INPUT TYPE='text' Name='__age1' SIZE='6' MAXLENGTH='6' VALUE='<%=ck.chkNullString(request.getParameter("__age1"),"0.00")%>'  onClick="" onChange="javaScript:genDate(this,'__startWorkAge');"  onKeyPress="checkWordNumber(this.value);" onKeyUp="sysIsEdit();checkComma(this,2);" dir="" onBlur="chkLengthFloat1(this,__age2,90);" onFocus="callDelComma(this);" class="numeric" alt="อายุ"  >&nbsp;-&nbsp;<INPUT TYPE='text' Name='__age2' SIZE='6' MAXLENGTH='6' VALUE='<%=ck.chkNullString(request.getParameter("__age2"),"0.00")%>'  onClick="javaScript:genDate(this,'__endkAge');" onChange=""  onKeyPress="checkWordNumber(this.value);" onKeyUp="sysIsEdit();checkComma(this,2);" dir="" onBlur="chkLengthFloat2(this,__age1,90);" onFocus="callDelComma(this);" class="numeric" alt="อายุ"  >
                  <input type="hidden" name="__startAge" id="__startAge"  value='<%=ck.chkNullString(request.getParameter("__startAge"),"")%>'>
                <input type="hidden" name="__endAge" id="__endAge"  value='<%=ck.chkNullString(request.getParameter("__endAge"),"")%>'> (YY.MM  ตัวอย่าง  1.06)&nbsp;&nbsp;&nbsp;&nbsp;</td>
              </tr>
              
              <tr>
                <td width="87"><div align="right">&nbsp;เรียงลำดับ</div></td>
               <td colspan="4">&nbsp;  <INPUT TYPE="Button" name='xx' id='xx' onClick="javaScript:setOrder('APSGRADE,APSSUMSCORE DESC')"  value="เกรดลำดับ 1">&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<INPUT TYPE="Button" name='xx1' id='xx1' onClick="javaScript:setOrder('APSAPPGRADE1,APSSUMSCORE DESC')"  value="เกรดลำดับ 2"> </td>
              </tr>
              <tr>
                <td width="87">&nbsp;</td>
                <td colspan="4">&nbsp;</td>
              </tr>
              <tr>
                <td colspan="5"  class="blankspace"><% 
		int  recCount=0;
		if(ck.chkNullString(request.getParameter("__shown"),"").equals("1")){

			// screen.inq.setFilter("APSAPPROVE1='"+"032299"+"'"+filter);
			screen.inq.refresh();
			screen.inq.next();
		  	int running=0;
		  	double a_per,b_per,c_per,to_per;
			a_per=0.00;
			b_per=0.00;
			c_per=0.00;
			to_per=0.00;
  			double a_per_t,b_per_t,c_per_t,to_per_t;
			a_per_t=0.00;
			b_per_t=0.00;
			c_per_t=0.00;
			to_per_t=0.00;			
			String old_group,cur_group;
			String workage="";
			boolean nextRec,end;
			recCount =screen.inq.recCount();
			DecimalFormat dc = new DecimalFormat();
			dc.applyPattern("#0.00");
			String A,W,R, _0;
			if(recCount>0){
				nextRec=true;
				end=true;
				while(end){
		  %>      
                <table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666" class="largest">
                <tr>
                    <td colspan="16"><strong><script language="javascript">swapLang('Employee Group Code');</script>
                      &nbsp;&nbsp;:<%=screen.getDataLabel("mgroup","tdesc")%></strong></td>
                    </tr>
                  <tr>
                    <td class="title1" width="22"><div align="center">
                        ยืนยัน
                    </div></td>
                    <td class="title1" width="104"><div align="center">
                        <script language="javascript">swapLang('Status');</script>
                    </div></td>
                    <td class="title1" width="53"><div align="center">
                        <script language="javascript">swapLang('grade');</script>
                    </div></td>
                    <td class="title1" width="48"><div align="center">เรียงลำดับ</div></td>
                    <td class="title1" width="33"><div align="center">
                      <script language="javascript">swapLang('grade');</script>
                      ลำดับ&nbsp;1</div></td>
                    <td class="title1" width="35"><div align="center">
                        <script language="javascript">swapLang('Score');</script>
                    </div></td>
                    <td class="title1" width="48"><div align="center">                    
                      ประเมิน
                      &nbsp;1</div></td>
                    <td class="title1" width="52"><div align="center">เกรด <%if(!screen.getDataLabel("APSASYDESC").equals("")){
						out.print(screen.getDataLabel("APSASYDESC").split(",")[0]);
					}%> </div></td>
                    <td class="title1" width="141"><div align="center">
                        <script language="javascript">swapLang('assessy');</script>
                    </div></td>
                    <td class="title1" width="71"><div align="center">
                        <script language="javascript">swapLang('division');</script>
                    </div></td>
                    <td class="title1" width="64"><div align="center">
                        <script language="javascript">swapLang('position');</script>
                    </div></td>
                   
                    <td class="title1" width="20"><div align="center">
                        <script language="javascript">swapLang('Service Year');</script>
                    </div></td>
                     <td class="title1" width="20"><div align="center">อายุ</div></td>
                    <td class="title1" width="19"><div align="center">
                        <script language="javascript">swapLang('WorkHour Day');</script>
                    </div></td>
                    <td class="title1" width="17"><div align="center">
                        <script language="javascript">swapLang('V2U');</script>
                    </div></td>
					<td class="title1" width="56"><div align="center">
                        <!-- <script language="javascript">swapLang('');</script> -->
                    </div>วินัย</td>                    
                  </tr>

              <%
				old_group = screen.inq.getString("emp_group");	
			  	cur_group = screen.inq.getString("emp_group");	
			  	nextRec=true;
				a_per=0;
				b_per=0;
				c_per=0;
				to_per=0;
			  	while(nextRec){
					
					to_per++;
					to_per_t++;
					if(screen.inq.getString("apsappgrade1").indexOf("A")>=0){
						a_per++;
						a_per_t++;
					}else{
						if(screen.inq.getString("apsappgrade1").indexOf("B")>=0){
							b_per++;
							b_per_t++;
						}else{
							if(screen.inq.getString("apsappgrade1").indexOf("C")>=0){
								c_per++;
								c_per_t++;
							}
						}
					}
			  %>
                  <tr>
                    <td>
<%//if(((screen.getDataLabel("APSAPPSTATUS1").equals("R"))||((screen.getDataLabel("APSSTATUS").equals("A"))))&&(!screen.getDataLabel("APSAPPSTATUS1").equals("A"))){%>         <div align="center">           
                    <input type="checkbox" name="__ch<%=(++running)%>:APSID:APSASSESSOR:APSASSESSY:APSSTATUS:APSAPPSTATUS1:APSAPPGRADE1:APSAPPSTATUS2:APSAPPGRADE2" value="<%=screen.getDataLabel("APSID")+":"+screen.getDataLabel("APSASSESSOR")+":"+screen.getDataLabel("APSASSESSY")+":"+screen.getDataLabel("APSSTATUS")+":"+screen.getDataLabel("APSAPPSTATUS1")+":"+screen.getDataLabel("APSAPPGRADE1")+":"+screen.getDataLabel("APSAPPSTATUS2")+":"+screen.getDataLabel("APSAPPGRADE2")%>" id="__ch<%=running++%>:APSID:APSASSESSOR:APSASSESSY:APSSTATUS:APSAPPSTATUS1:APSAPPGRADE1:APSAPPSTATUS2:APSAPPGRADE2" align="absmiddle"   onChange="chk(this,'__apsappstatus1:<%=screen.getDataLabel("mbu1","bu1id")+":"+screen.getDataLabel("mbu2","bu2id")+":"+screen.getDataLabel("mbu3","bu3id")+":"+screen.inq.getString("emp_group")+":"+screen.inq.getString("APSASSESSY")+":"+screen.getDataLabel("runno") %>','__lineg:<%=screen.getDataLabel("mbu1","bu1id")+":"+screen.getDataLabel("mbu2","bu2id")+":"+screen.getDataLabel("mbu3","bu3id")+":"+screen.inq.getString("emp_group")+":"+screen.inq.getString("APSASSESSY")+":"+screen.getDataLabel("runno") %>')">
                    <%//}else{%>
                    &nbsp;
                    <%//}%>                </div>    </td>
                    <td><div align="center">	<%//if((screen.getDataLabel("apsappstatus1").equals(""))||(screen.getDataLabel("apsappstatus1").equals("0"))||(screen.getDataLabel("apsappstatus1").equals("R"))){%>
						<!--span class="style1"><%//=screen.inq.getCurrentDbRecord().getSystemCode("apsappstatus1")%></span-->
					<%//}else{
					//	if(screen.getDataLabel("apsappstatus1").equals("A")){%>
						 <!--span class="style2"><%//=screen.inq.getCurrentDbRecord().getSystemCode("apsappstatus1")%></span-->
						 <%//}else{%>
							<%//=screen.inq.getCurrentDbRecord().getSystemCode("apsappstatus1")%>
						<%//}
				//	 }
					 A=W=R=_0="";
					 	if(screen.getDataLabel("apsappstatus1").equals("A")){
							A="selected";
						}else
							if(screen.getDataLabel("apsappstatus1").equals("R")){
								R="selected";
					 }else
					 	if(screen.getDataLabel("apsappstatus1").equals("W")){
								W="selected";
						}else{
								_0="selected";
						}					 
						%>
                        <select name='__apsappstatus1:<%=screen.getDataLabel("mbu1","bu1id")+":"+screen.getDataLabel("mbu2","bu2id")+":"+screen.getDataLabel("mbu3","bu3id")+":"+screen.inq.getString("emp_group")+":"+screen.inq.getString("APSASSESSY")+":"+screen.getDataLabel("runno") %>'  id='__apsappstatus1:<%=screen.getDataLabel("mbu1","bu1id")+":"+screen.getDataLabel("mbu2","bu2id")+":"+screen.getDataLabel("mbu3","bu3id")+":"+screen.inq.getString("emp_group")+":"+screen.inq.getString("APSASSESSY")+":"+screen.getDataLabel("runno") %>'  status1='<%=screen.getDataLabel("APSAPPSTATUS1")%>'>
                          <option value='A'  <%=A%>>ประเมินแล้ว</option>
                          <option value='W' <%=W%>>รอยืนยัน</option>
                          <option value='R'   <%=R%> >ต้องประเมินใหม่</option>
                          <option value='0'   <%=_0%>>ยังไม่ประเมิน</option>
                        </select>
                    </div> </td>
                    <td><div align="center">

<%//if(((screen.getDataLabel("APSAPPSTATUS1").equals("R"))||((screen.getDataLabel("APSSTATUS").equals("A"))))&&(!screen.getDataLabel("APSAPPSTATUS1").equals("A"))){%>  

					<select name='__lineg:<%=screen.getDataLabel("mbu1","bu1id")+":"+screen.getDataLabel("mbu2","bu2id")+":"+screen.getDataLabel("mbu3","bu3id")+":"+screen.inq.getString("emp_group")+":"+screen.inq.getString("APSASSESSY")+":"+screen.getDataLabel("runno") %>' id='__lineg:<%=screen.getDataLabel("mbu1","bu1id")+":"+screen.getDataLabel("mbu2","bu2id")+":"+screen.getDataLabel("mbu3","bu3id")+":"+screen.inq.getString("emp_group")+":"+screen.inq.getString("APSASSESSY")+":"+screen.getDataLabel("runno") %>' status1='<%=screen.getDataLabel("APSAPPSTATUS1")%>' >	
<%
String  select =""; //selected
String  A1,A2,A3,B1,B2,B3,B4,B5,C1,C2;
A1=A2=A3=B1=B2=B3=B4=B5=C1=C2="";
	if(screen.getDataLabel("apsappgrade1").equals("A1")){
		A1="selected";
	}else
		if(screen.getDataLabel("apsappgrade1").equals("A2")){
		A2="selected";
	}else
		if(screen.getDataLabel("apsappgrade1").equals("A3")){
		A3="selected";
	}else	if(screen.getDataLabel("apsappgrade1").equals("B1")){
		B1="selected";
	}else
		if(screen.getDataLabel("apsappgrade1").equals("B2")){
		B2="selected";
	}else
		if(screen.getDataLabel("apsappgrade1").equals("B3")){
		B3="selected";
	}else
	if(screen.getDataLabel("apsappgrade1").equals("B4")){
		B4="selected";
	}else
		if(screen.getDataLabel("apsappgrade1").equals("B5")){
		B5="selected";
	}else
		if(screen.getDataLabel("apsappgrade1").equals("C1")){
		C1="selected";
	}else
	if(screen.getDataLabel("apsappgrade1").equals("C2"))
		C2="selected";

%>							
						<option value="apsappgrade1: "></option>                       
						<option value="apsappgrade1:A1"   <%=A1%> >A1</option>
						<option value="apsappgrade1:A2"  <%=A2%>  >A2</option>
						<option value="apsappgrade1:A3"  <%=A3%> >A3</option>
						<option value="apsappgrade1:B1"  <%=B1%>  >B1</option>
						<option value="apsappgrade1:B2"   <%=B2%>  >B2</option>
						<option value="apsappgrade1:B3"   <%=B3%>  >B3</option>
						<option value="apsappgrade1:B4"  <%=B4%>>B4</option>
						<option value="apsappgrade1:B5"  <%=B5%> >B5</option>
						<option value="apsappgrade1:C1"  <%=C1%> >C1</option>
						<option value="apsappgrade1:C2"   <%=C2%> >C2</option>
					</select>
<%//}else{%>					

	<%//if(screen.getDataLabel("apsappgrade1").indexOf(screen.getDataLabel("apsgrade"))<0){%>
					<!--span class="style1"><%//=screen.getDataLabel("apsappgrade1")%></span-->
					<%//}else{%>

						<%//=screen.getDataLabel("apsappgrade1")%>
					<%//}%>
<%//}%>
					</div></td>
                    <td><div align="center"><%=screen.getDataLabel("apsassdesc")%></div></td>
                    <td><div align="center"><%if(screen.getDataLabel("apsappgrade1").indexOf(screen.getDataLabel("apsgrade"))<0){%>
					<span class="style1"><%=screen.getDataLabel("apsgrade")%></span>
					<%}else{%>
						<%=screen.getDataLabel("apsgrade")%>
					<%}%>
					</div></td>
                    <td><div align="center"><%=screen.getDataLabel("apssumscore")%></div></td>	
                    <td><%=screen.inq.getChild("memployee").getString("fname")%></td>

                    <td><div align="center"><a href="javascript:viewHis('<%=screen.getDataLabel("apsasydesc")%>','<%=screen.getDataLabel("apsassessy")%>');"><%
						if(!screen.getDataLabel("APSASYDESC").equals("")){
						out.print(screen.getDataLabel("APSASYDESC").split(",")[1]);
					}%></a></div></td>
                    <td><%if((screen.getDataLabel("APSSTATUS").equals("A"))&&(!screen.getDataLabel("APSAPPSTATUS1").equals("A"))){%>
					<%="<A  href=\"javascript:goASP700('"+screen.getDataLabel("APSID")+"','"+screen.getDataLabel("APSASSESSOR")+"','"+screen.getDataLabel("APSASSESSY")+"');\">"+screen.getDataLabel("simemp","fullname")+"</A>"%>
					<%}else{%>
					<%="<A  href=\"javascript:goReASP700('"+screen.getDataLabel("APSID")+"','"+screen.getDataLabel("APSASSESSOR")+"','"+screen.getDataLabel("APSASSESSY")+"');\">"+screen.getDataLabel("simemp","fullname")+"</A>"%>
					<%}%></td>
                    <td><%=screen.getDataLabel("mbu2","tdesc")%></td>
                    <td><%=screen.getDataLabel("mposition","tdesc")%></td>                    
                    <td>					<%
						workage=screen.getDataLabel("simemp","empworkages");
						String[] y = workage.split(" ");	
					%>
                    <div align="center"><%=y[0]+"/"+y[2] %></div></td>
                    <td><script language="javascript">calAge("<%=screen.getDataLabel("simemp","birthday")%>");</script></td>
                    <td><div align="center"><%=screen.getDataLabel("other1")%></div></td>
                    <td><div align="center"><%=screen.getDataLabel("other2")%></div></td>
                    <td><div align="center"><%if(screen.getDataLabel("other3").equals("Y")){%>
                    <span class="style1"><%=screen.getDataLabel("other3")%></span>
                    <%}else{%>
                    <%=screen.getDataLabel("other3")%>
                    <%}%>
                    </div></td>
                  </tr>
                 <%
				 	if(!screen.inq.next()){
						end=false;
						nextRec = false;
					}
					cur_group= screen.inq.getString("emp_group");
				 	if(!cur_group.equals(old_group))nextRec = false;
				 } // while
				 %>
                         <tr>
                    <td colspan="6"><div align="right"><strong>จำนวนผู้ถูกประเมิน :&nbsp;&nbsp;<%=dc.format(to_per).replaceAll(".00", "")%> &nbsp;คน</strong></div></td>

                    <td><div align="right"><strong>รวมผล</strong></div></td>
                    <td colspan="9">
                      <div align="right"><strong>A&nbsp;=&nbsp;<%=dc.format((a_per/to_per)*100)%>&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;B&nbsp;=&nbsp;<%=dc.format((b_per/to_per)*100)%>&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;C&nbsp;=&nbsp;<%=dc.format((c_per/to_per)*100)%>&nbsp;%&nbsp;</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:goCheck('<%=old_group%>','apsappgrade1');"><img src="../IMAGES/BUTTON/CHECK.gif" alt="" border="0"></a></div></td>
                    </tr>
                </table>
                <%			
					
				} // while
			}// if
				%>
<!--table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666" class="largest">
                	<tr>
                    <td width="30%"><div align="right"><strong>จำนวนผู้ถูกประเมินทั้งหมด :&nbsp;&nbsp;<%//=dc.format(to_per_t).replaceAll(".00", "")%></strong></div></td>                     
                     <td width="15%"><div align="right"><strong>รวมผลทั้งหมด</strong></div></td>
                     <td width="55%"><div align="center"><strong>A&nbsp;=&nbsp;<%//=dc.format((a_per_t/to_per_t)*100)%>&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;B&nbsp;=&nbsp;<%//=dc.format((b_per_t/to_per_t)*100)%>&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;C&nbsp;=&nbsp;<%//=dc.format((c_per_t/to_per_t)*100)%>&nbsp;%&nbsp;</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>
                    </tr>
                  </table-->
                  <%		}// if%>                          
                </td>
              </tr>
            </table>
            <% if((ck.chkNullString(request.getParameter("__shown"),"").equals("1"))&&(recCount>0)){%>
<div align="center">								
								<!--a href="#" onClick="checkAll()"><img src="../IMAGES/BUTTON/SELECTALL.gif" border="0"></a>&nbsp;&nbsp;
								    <a href="#" onClick="decheckAll()"><img src="../IMAGES/BUTTON/DESELECTALL.gif" border="0"></a-->&nbsp;&nbsp;
								    <a href="javascript:goConfirm1();"><img src="../IMAGES/BUTTON/SAVE.gif" border="0"></a>&nbsp;&nbsp;
								    <!--a href="javascript:goReturn();"><img src="../IMAGES/BUTTON/ROUTE_BACK.gif" border="0"></a-->
								    <a href="javascript:alert();"><img src="../IMAGES/BUTTON/BACK.gif" border="0"></a></div>
        </div> <%}%></td> 
      </tr>
      <tr bordercolor="0069B3">
        <td  class="bottom"></td>
      </tr>
    </table>
  </div>
   <input type="hidden" name="__gochk" value="">
  <%
	  if(!ck.chkNullString(request.getParameter("__gochk")).equals("")){	  	
		  String[]   gochk = ck.chkNullString(request.getParameter("__gochk")).split(":");

			  %>
			  <script language="javascript">goCheck1('<%=gochk[0]%>','<%=gochk[1]%>');</script>
	  <%}%>
 </form>
</body>
</html>
