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

<%	CheckNull ck = new CheckNull(); 
        
  //       screen.process(); 
//String sbu1,sbu2,bu1desc,bu2desc;
//sbu1=ck.chkNullString(request.getParameter("__bu1"),"");
//sbu2=ck.chkNullString(request.getParameter("__bu2"),"");
String filter = "";
//if(!sbu1.equals(""))filter =" and bu1='"+sbu1+"'";
//else
//	bu1desc="";	
//if(!sbu2.equals(""))filter =filter+" and bu2='"+sbu2+"'";
//else
//	bu2desc="";

CscCalendar cDate = new CscCalendar();
DbInquiry taps0 = new InitialInquiry(screen.getUProfile()).getDbInquiry("TAPSTRAN0");
taps0.setColumn("apsid,apsperiodstart,apsperiodend");
String f1="apsperiodend >= '"+cDate.getYYYYMMDD()+"'   AND";
	f1+=" apsperiodstart <='"+cDate.getYYYYMMDD()+"'  ";
taps0.setFilter("");

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='AP30' AND (apsassessor='"+screen.getUProfile().get("employeeid")+"' OR  APSAPPROVE1='"+screen.getUProfile().get("employeeid")+"'  OR APSAPPROVE2='"+screen.getUProfile().get("employeeid")+"') "+filter);
	((Simtapstran_kkb1)screen.inq.getCurrentDbRecord()).approveConfirm();	
 String desc ="tdesc";
 if(!screen.getUProfile().get("lang").equals("tha"))desc="edesc";
// DataSet dsBu1 = new DataSet("Select Distinct APSASSESSOR,BU1 ,MBU1.TDESC AS TDESC, MBU1.EDESC AS EDESC from TAPSTRAN , MBU1 where TAPSTRAN.bu1=MBU1.bu1id and  APSASSESSOR='"+screen.getUProfile().get("employeeid")+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
//dsBu1.initConnection(screen.getUProfile());

// DataSet dsBu2 = new DataSet("Select Distinct APSASSESSOR,BU2,MBU2.TDESC AS TDESC, MBU2.EDESC AS EDESC from TAPSTRAN, MBU2 where TAPSTRAN.bu2=MBU2.bu2id and  APSASSESSOR='"+screen.getUProfile().get("employeeid")+"'",(String)screen.getUProfile().get("dbname"),"Tapstran");
//dsBu2.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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
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){
		__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");
			if(window.focus){win.focus();}
		}
}
function goASP(apsid,apsassessor,apsassessy,level,tid){
	with(document.cscform){		action="ASP705.jsp?apsid="+apsid+"&apsassessor="+apsassessor+"&apsassessy="+apsassessy+"&bpage="+__screen.value+"&ass_level="+level+"&isread=0"+"&astid="+tid;	
//	alert(action);
		submit();
	}

}
function goReASP(apsid,apsassessor,apsassessy,level,tid){
	with(document.cscform){		action="ASP705.jsp?apsid="+apsid+"&apsassessor="+apsassessor+"&apsassessy="+apsassessy+"&bpage="+__screen.value+"&ass_level="+level+"&isread=1"+"&astid="+tid;	
		submit();
	}

}
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style2 {color: #339933}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif')">
<form name="cscform" method="post" action="AS004_5.jsp" >
  

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

<%=screen.InitialVariable()%>

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

<input type="hidden"name="__screen"  value="AS004_5">
  <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="">
  <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="APSSTATUS">
  <input type="hidden" name="__returnfield" value="">
  <input type="hidden" name="__status" value="">
   <input type="hidden" name="__apsid" value="<%=ck.chkNullString(request.getParameter("__apsid"),"")%>">
  <br>
  <div align="center">
    <table width="99%"  cellpadding="0"  cellspacing="0" class="large">
      <tr>
        <td  class="header">AS004_5,ประเมินผลระดับที่ 1
          <!-- <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><%=screen.getUProfile().get("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 height="24"><div align="right"><%//=screen.getLabel("bu1")%>&nbsp;</div></td>
                <td colspan="4">             <select name="__bu1" id="select">
                    <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;&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">
                  <select name="__bu2" id="select">
                    <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 width="87">&nbsp;</td>
                <td colspan="4">&nbsp;</td>
              </tr>
              <tr>
                <td colspan="5"  class="blankspace"><% 
		int  recCount=0;
		int checkAPS=1;
	//	if(ck.chkNullString(request.getParameter("__shown"),"").equals("1")){
			
			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;
			String old_group,cur_group;
			String workage="";
			String sty="",fieldN="";
			boolean nextRec,end;
			recCount =screen.inq.recCount();
			DecimalFormat dc = new DecimalFormat();
			dc.applyPattern("#0.00");
			if(recCount>0){
				nextRec=true;
				end=true;
				while(end){
				 checkAPS=1;
		  %>      
                <table width="100%" height="0" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666" class="largest">
				  <!--tr>
                    <td colspan="7"><strong>&nbsp;&nbsp;<%//=screen.getLabel("bu1")%>:<%//=screen.getDataLabel("mbu1","tdesc")%></strong></td>
                    </tr-->
                  <tr>
                    <!--td class="title1" width="32"><div align="center">
                        <script language="javascript">swapLang('Select');</script>
                    </div></td-->     
  					<td class="title1" width="10%"><div align="center"><script language="javascript">swapLang('Status');</script></div></td>                                 
                    <!--td class="title1" width="46"><div align="center">
                        <script language="javascript">swapLang('Docno');</script>
                    </div></td>
                    <td class="title1" width="52"><div align="center">
                        <script language="javascript">swapLang('Score');</script>
                    </div></td>
                      <td class="title1" width="70"><div align="center">
                      <script language="javascript">swapLang('assessor');</script>
  &nbsp;1</div></td>
                    <td class="title1" width="74"><div align="center">
                      <script language="javascript">swapLang('assessor');</script>
  &nbsp;2</div></td>
					<td class="title1" width="74"><div align="center">
                      <script language="javascript">swapLang('assessor');</script>
  &nbsp;3</div>					  </td-->             
					 <td class="title1" width="5%"><div align="center">ลำดับที่</div></td>  
                    <td class="title1" width="25%"><div align="center"><script language="javascript">swapLang('assessy');</script></div></td>
					<td class="title1" width="15%"><div align="center"><%=screen.getLabel("bu1")%></div>
                    <td class="title1" width="15%"><div align="center"><script language="javascript">swapLang('division');</script></div></td>
                    <td class="title1" width="15%"><div align="center"><script language="javascript">swapLang('position');</script></div></td>
                    <td class="title1" width="15%"><div align="center"><script language="javascript">swapLang('Service Year');</script></div></td>
                  </tr>

              <%
				old_group = screen.inq.getString("bu1");	
			  	cur_group = screen.inq.getString("bu1");	
			  	nextRec=true;
	//			a_per=0;
	//			b_per=0;
	//			c_per=0;
	//			to_per=0;
			  	while(nextRec){
					
		/*				to_per++;
				if(screen.inq.getString("apsgrade").indexOf("A")>=0){
						a_per++;
					}else{
						if(screen.inq.getString("apsgrade").indexOf("B")>=0){
							b_per++;
						}else{
							if(screen.inq.getString("apsgrade").indexOf("C")>=0){
								c_per++;
							}
						}
					} */
			  %>
                  <tr>
                                      <!--td>
<%//if((screen.getDataLabel("APSSTATUS").equals("R")||screen.getDataLabel("APSSTATUS").equals("W"))&&(screen.getDataLabel("apsassessor").equals(screen.getUProfile().get("employeeid")))){%>                                       
                    <input type="checkbox" name="__ch<%//=(++running)%>:APSID:APSASSESSOR:APSASSESSY:APSASSSOURCE:APSASYSOURCE" value="<%//=screen.getDataLabel("APSID")+":"+screen.getDataLabel("APSASSESSOR")+":"+screen.getDataLabel("APSASSESSY")+":"+screen.getDataLabel("APSASSSOURCE")+":"+screen.getDataLabel("APSASYSOURCE")%>" id="__ch<%//=running++%>:APSID:APSASSESSOR:APSASSESSY:APSASSSOURCE:APSASYSOURCE">
                    <%//}else{%>
                  
<%//if(((screen.getDataLabel("APSAPPSTATUS1").equals("R"))||((screen.getDataLabel("APSSTATUS").equals("A"))))&&(!screen.getDataLabel("APSAPPSTATUS1").equals("A"))&&(screen.getDataLabel("APSAPPROVE1").equals(screen.getUProfile().get("employeeid"))) ){%>                    
                    <input type="checkbox" name="__ch<%//=(++running)%>:APSID:APSASSESSOR:APSASSESSY:APSASSSOURCE:APSASYSOURCE:APSSTATUS:APSAPPGRADE1" value="<%//=screen.getDataLabel("APSID")+":"+screen.getDataLabel("APSASSESSOR")+":"+screen.getDataLabel("APSASSESSY")+":"+screen.getDataLabel("APSASSSOURCE")+":"+screen.getDataLabel("APSASYSOURCE")+":"+screen.getDataLabel("APSSTATUS")+":"+screen.getDataLabel("APSAPPGRADE1")%>" id="__ch<%//=running++%>:APSID:APSASSESSOR:APSASSESSY:APSASSSOURCE:APSASYSOURCE:APSSTATUS:APSAPPGRADE1" align="absmiddle">
                    <%//}else{%>
                    <%//if((screen.getDataLabel("APSAPPSTATUS1").equals("A"))&&(screen.getDataLabel("APSAPPSTATUS2").equals("W"))&&(screen.getDataLabel("APSAPPROVE2").equals(screen.getUProfile().get("employeeid")))){%>
                    <input type="checkbox" name="__ch<%//=(++running)%>:APSID:APSASSESSOR:APSASSESSY:APSASSSOURCE:APSASYSOURCE" value="<%//=screen.getDataLabel("APSID")+":"+screen.getDataLabel("APSASSESSOR")+":"+screen.getDataLabel("APSASSESSY")+":"+screen.getDataLabel("APSASSSOURCE")+":"+screen.getDataLabel("APSASYSOURCE")%>" id="__ch<%//=running++%>:APSID:APSASSESSOR:APSASSESSY:APSASSSOURCE:APSASYSOURCE">
                    <%//}else{%>
                    &nbsp;
                    <%//}%>  
                    <%//}%>           


                    <%//}%>                           
                    
                    </td-->
                    <td><div align="center">
						 <%if(screen.getUProfile().get("employeeid").equals(screen.getDataLabel("apsapprove1"))){
					  				checkAPS=2;
									fieldN="apsappstatus1";
									if((screen.getDataLabel("apsappstatus1").equals(""))||(screen.getDataLabel("apsappstatus1").equals("0"))||(screen.getDataLabel("apsappstatus1").equals("R"))){
										sty="style1";
									}else{
										sty="style2";
									}
					  		}else{
								if(screen.getUProfile().get("employeeid").equals(screen.getDataLabel("apsapprove2"))){
					  				checkAPS=3;			
									fieldN="apsappstatus2";
									if((screen.getDataLabel("apsappstatus2").equals(""))||(screen.getDataLabel("apsappstatus2").equals("0"))||(screen.getDataLabel("apsappstatus1").equals("R"))){
										sty="style1";	
									}else{
										sty="style2";
									}
					  			}else{
					  				checkAPS=1;		
									fieldN="apsstatus";									if((screen.getDataLabel("apsstatus").equals(""))||(screen.getDataLabel("apsstatus").equals("0"))||(screen.getDataLabel("apsstatus").equals("R"))){
										sty="style1";
									}else{
										sty="style2";
									}
								}
							}
						%>									
					<%
						if(screen.getDataLabel(fieldN).equals("A")){%>
						 <span class="<%=sty%>"><%=screen.inq.getCurrentDbRecord().getSystemCode(fieldN)%></span>
						 <%}else{%>
							<%=screen.inq.getCurrentDbRecord().getSystemCode(fieldN)%>
						<%}
					 
						%></div>&nbsp;</td>                    
                    <!--td><div align="center"><%//=screen.getDataLabel("apsid")%></div></td>
                    <td><div align="center"><%//=screen.getDataLabel("mastype","tdesc")%></div></td>
       				<td><div align="center"><%//=screen.getDataLabel("memployee","fname")%></div></td>
                    <td><div align="center"><%//=screen.getDataLabel("v1memployee","fname")%></div></td>
                    <td><div align="center"><%//=screen.getDataLabel("v2memployee","fname")%></div></td-->                
                    <td><div align="center"><%=++running%></div></td>                    
                    <td>

					<%if((!screen.getDataLabel("APSSTATUS").equals("A"))&&(screen.getUProfile().get("employeeid").equals(screen.getDataLabel("apsassessor")))||(((screen.getDataLabel("APSSTATUS").equals("A"))&&(!screen.getDataLabel("APSAPPSTATUS1").equals("A")))&&(screen.getUProfile().get("employeeid").equals(screen.getDataLabel("apsapprove1")))) ||(((screen.getDataLabel("APSAPPSTATUS1").equals("A"))&&(!screen.getDataLabel("APSAPPSTATUS2").equals("A")))&&((screen.getUProfile().get("employeeid").equals(screen.getDataLabel("apsapprove2")))))  ){%>

                      <%="<A  href=\"javascript:goASP('"+screen.getDataLabel("APSID")+"','"+screen.getDataLabel("APSASSESSOR")+"','"+screen.getDataLabel("APSASSESSY")+"','" +checkAPS+"','"+screen.getDataLabel("ASTID")+"');\">"+screen.getDataLabel("simemp","fullname")+"</A>"%>
					<%}else{%>
					<%="<A  href=\"javascript:goReASP('"+screen.getDataLabel("APSID")+"','"+screen.getDataLabel("APSASSESSOR")+"','"+screen.getDataLabel("APSASSESSY")+"','" +checkAPS+"','"+screen.getDataLabel("ASTID")+"');\">"+screen.getDataLabel("simemp","fullname")+"</A>"%>
					<%}%>					
					
					
					
					
					</td>
                    
                    <td><%=screen.getDataLabel("mbu1","tdesc")%></td>
                    <td><%=screen.getDataLabel("mbu2","tdesc")%></td>
                    <td><%=screen.getDataLabel("mposition","tdesc")%></td>
                    <td align="center"><% workage=screen.getDataLabel("simemp","empworkages");				
							workage=workage.substring(0,workage.indexOf("เดือน")+5);
							out.print(workage);
							%></td>
             
                  </tr>
                 <%
				 	if(!screen.inq.next()){
						end=false;
						nextRec = false;
					}
					cur_group= screen.inq.getString("bu1");
				 	if(!cur_group.equals(old_group))nextRec = false;
				 } // while
				 %>
                  <!-- <tr>
                    <td colspan="5"><div align="right"><strong>รวมผล</strong></div></td>
                    <td colspan="7">
                      <div align="center"><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;</div></td>
                    </tr> -->
                </table>
                <%			
					
				} // while
			}// if
		//	}// if
				%></td>
              </tr>
                <tr>
                    <td colspan="11">&nbsp;</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:goConfirm();"><img src="../IMAGES/BUTTON/CONFIRM.gif" border="0"></a>&nbsp;&nbsp;
								    <a href="javascript:goReturn();"><img src="../IMAGES/BUTTON/RETURN.gif" border="0"></a></div>
        </div--> 
     <%//}%></td> 
      </tr>
      <tr bordercolor="0069B3">
        <td  class="bottom"></td>
      </tr>
    </table>
  </div>
 </form>
</body>
</html>
