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

<%	
		CheckNull ck = new CheckNull(); 
String sbu1,sbu2,sbu3,spos,ssor,sap1,sSwork,sEwork,sSage,sEage,sgro;  //apsapprove1
sbu1=ck.chkNullString(request.getParameter("__bu1"),"");
sbu2=ck.chkNullString(request.getParameter("__bu2"),"");
sbu3=ck.chkNullString(request.getParameter("__bu3"),"");
sgro=ck.chkNullString(request.getParameter("__gro"),"");
spos=ck.chkNullString(request.getParameter("__pos"),"");
ssor=ck.chkNullString(request.getParameter("__sor"),"");
sap1=ck.chkNullString(request.getParameter("__ap1"),"");


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(!sap1.equals(""))filter =filter+" and apsapprove1='"+sap1+"'";

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.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+=")";}
		String employeeid=screen.getUProfile().get("employeeid");
		if(!ck.chkNullString(request.getParameter("__employeeid"),"").equals("")){
				employeeid= request.getParameter("__employeeid");
		}
         screen.inq.setFilter(dateExp+" AND astid='AP10' and emp_group='"+ck.chkNullString(request.getParameter("__emp_group"),"")+"' and "+ck.chkNullString(request.getParameter("__appfield"),"")+"='"+employeeid+"'  "+filter);
       //  screen.process(); 	   
		 String fieldName = ck.chkNullString(request.getParameter("__fieldName"),"");
		 String group_desc = screen.getDataLabel("mgroup","tdesc");
		 HashMap box = new HashMap();
		 box.put("A1","0");
		 box.put("A2","0");
		 box.put("A3","0");
		 box.put("B1","0");
		 box.put("B2","0");
		 box.put("B3","0");
		 box.put("B4","0");
		 box.put("B5","0");
		 box.put("C1","0");
		 box.put("C2","0");
		 box.put("BLANK","0");
		 box.put("TOTAL","0");
			int temp=0;	
		 screen.inq.refresh();
		 while(screen.inq.next()){
			temp = Integer.parseInt((String)box.get("TOTAL"))+1;
			box.put("TOTAL",String.valueOf(temp));
			
			if(screen.inq.getString(fieldName).equals("") || screen.inq.getString(fieldName).equals("0")){
				temp = Integer.parseInt((String)box.get("BLANK"))+1;
				box.put("BLANK",String.valueOf(temp));			
			}else{
				if(box.get(screen.inq.getString(fieldName))!=null){
					temp = Integer.parseInt((String)box.get(screen.inq.getString(fieldName)))+1;			
					box.put(screen.inq.getString(fieldName),String.valueOf(temp));	
				}
			}

		 }
		 if(temp==0) box.put("TOTAL","1");
		 DecimalFormat dc = new DecimalFormat();
		 dc.applyPattern("#0.00");
		 int total = Integer.parseInt((String)box.get("TOTAL"));
		
%>
<!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 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(){
	alert();
}
function goCheck(emp_group,fieldName){
		with(document.cscform){
			var param="AS004_2C1.jsp?__emp_group="+emp_group+"&__fieldName="+fieldName;	
			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();}
		}
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="cscform" method="post" >
  

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

<%=screen.InitialVariable()%>

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

<input type="hidden"name="__screen"  value="AS004_2C1">
  <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="">
  <div align="center">
    <table  cellpadding="0"  cellspacing="0" class="medium">
      <tr >
        <td  class="header">AS004_2C1,การกระจายเกรตย่อย
          <!-- <script language="javascript">swapLang('');</script> -->
          &nbsp;</td>
      </tr>
      <tr >
        <td  colspan="2"><div align="center">
          <table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#666666" class="large">
            <tr>
              <td colspan="2"><strong>
                <script language="javascript">swapLang('Employee Group Code');</script>
                &nbsp;&nbsp;:&nbsp;&nbsp;<%=screen.getDataLabel("mgroup","tdesc")%></strong></td>
            </tr>
            <tr>
              <td class="title1" width="362"><div align="center">
                        <script language="javascript">swapLang('grade');</script>
                    </div></td>
              <td class="title1" width="577"><div align="center"><strong>%</strong></div></td>        
            </tr>
  
            <tr>
              <td><div align="center"><strong>A1</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("A1")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>     
            <tr>
              <td><div align="center"><strong>A2</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("A2")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>            
            <tr>
              <td><div align="center"><strong>A3</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("A3")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>                
            <tr>
              <td><div align="center"><strong>B1</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("B1")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>     
            <tr>
              <td><div align="center"><strong>B2</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("B2")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>            
            <tr>
              <td><div align="center"><strong>B3</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("B3")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>     
            <tr>
              <td><div align="center"><strong>B4</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("B4")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>   
            <tr>
              <td><div align="center"><strong>B5</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("B5")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>             
            <tr>
              <td><div align="center"><strong>C1</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("C1")); 			  	
			  %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>     
            <tr>
              <td><div align="center"><strong>C2</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("C2")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>            
            <tr>
              <td><div align="center"><strong>ยังไม่มีเกรด</strong></div></td>
              <% temp =Integer.parseInt((String)box.get("BLANK")); %>
              <td><div align="center"><strong><%=dc.format(((double)temp/total)*100)%></strong></div></td>             
            </tr>                                      
          </table>
        </div>        </td>
      </tr>
      <tr bordercolor="0069B3">
        <td  class="bottom"><%//=screen.inq.recCount()%><%//=screen.inq.getFilter()%></td>
      </tr>
    </table>
  </div>
</form>
</body>
</html>
