<%@page contentType="text/html; charset=UTF-8"%>
<%@ page import = "com.csc.library.databean.workload.*"%>
<%@ page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*,java.util.*"  %>
<%@ page import="java.text.DecimalFormat" %>
<%
    com.csc.library.utilities.UProfile up=(com.csc.library.utilities.UProfile)session.getAttribute("userprofile");
    String users[]=request.getParameterValues("user_code");
    WorkloadReport    wr=new WorkloadReport(up);
    Vector v=wr.getWorkloadReport(users);
	DecimalFormat df = new DecimalFormat("0.00");
%>
<html>
<head>
<title>Workload Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript" type="text/JavaScript">
<!--
function Start(page) {
	OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no" );
}
function showGraph() {
  	document.cscform.action = "GRAPH.jsp";
        document.cscform.submit();
}
//-->
</script>
<link rel="stylesheet" href="CSS/PRINTPAGE.css" type="text/css">
<script language="JavaScript">
var linkset=new Array();
linkset[0]='<table width=\"75%\" border=\"0\" cellpadding=\"1\" cellspacing=\"2\">' 
linkset[0]+='<td  nowrap><font size="2"><a href="javascript:window.print()"><IMG SRC="IMAGES/ARROW.gif" WIDTH="12" HEIGHT="12" BORDER="0" HSPACE="0" VSPACE="0" >&nbsp;พิมพ์</a></font></td>' 
linkset[0]+='</table>'
</script>
<script language="JavaScript1.2" src="JS/PRINTPAGE.js"></script>
</head>
<body>
<div align="center"> </div>
<div align="center">
<form name="cscform" method="post" action="">
   

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

<%=screen.InitialVariable()%>

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

<div align="center">
      <table width="702" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="702" bgcolor="#336699" ><div align="right"><font color="#FFFFFF" size="2" face="MS Sans Serif, Tahoma, sans-serif"><strong>Workload
              Me</strong></font></div>
            <div align="right"></div></td>
        </tr>
      </table>
      <table width="705" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
        <tr>
          <td width="705" bgcolor="#FFFFFF"><div align="right">
              <%
                         StringBuffer concat_=new StringBuffer();
                          for( int i=0;i<users.length;i++) {
                          concat_.append("user_code="+users[i]+"&");
              %>
                         <input type="hidden" name="user_code" value="<%=users[i]%>">
              <%
                  }
                 concat_.deleteCharAt(concat_.indexOf("&"));
               %>
             <!-- <input type="button" name="Submit2" value="Print" onClick="Start('PRINTREPORT.jsp?<%= concat_.toString() %>')">-->
              <input type="button" name="Submit" value="Graph"  onClick="showGraph()">
              <font size="2" face="MS Sans Serif, Tahoma, sans-serif"></font></div></td>
        </tr>
      </table>
    </div>
      <div align="center">
    <%
      Workload wk=null;
      HashMap hm=null;
      Set s=null;
      Iterator it=null;
      String uname="";
	   int percent_total=0;
      boolean ishead=true;
      long total_amount=0;
      long total_MN=0,total_ME=0,total_ML=0;
      long total_SN=0,total_SE=0,total_SL=0;
      double percent_N=0,percent_E=0,percent_L=0;
      for( int i=0;i<v.size();i++ ){
        hm=(HashMap)v.get(i);
        s=hm.keySet();
        it=s.iterator();
    %>
      <table width="704" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" bgcolor="#000000" onMouseover="showmenu(event,linkset[0])" onMouseout="delayhidemenu()" >
        <tr bgcolor="#FFFFFF">
          <td width="30" rowspan="2" bgcolor="#CCCCCC" class="bottonc"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">order</font></strong></div></td>
          <td width="131" rowspan="2" bgcolor="#CCCCCC"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">User
              Name</font></strong></div></td>
          <td width="103" rowspan="2" bgcolor="#CCCCCC"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">Workflow
              Name</font></strong></div></td>
          <td width="42" rowspan="2" bgcolor="#CCCCCC"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">Amount</font></strong></div></td>
          <td height="15" colspan="2" bgcolor="#99FF00"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">Normal</font></strong></div></td>
          <td colspan="2" bgcolor="#FFFF00"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">Extension</font></strong></div></td>
          <td colspan="2" bgcolor="#FF0000"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">Late</font></strong></div></td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td width="59" height="15" bgcolor="#99FF00"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">MyWork</font></strong></div></td>
          <td width="63" bgcolor="#99FF00"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">ShareWork</font></strong></div></td>
          <td width="58" bgcolor="#FFFF00"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">MyWork</font></strong></div></td>
          <td width="64" bgcolor="#FFFF00"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">ShareWork</font></strong></div></td>
          <td width="61" bgcolor="#FF0000"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">MyWork</font></strong></div></td>
          <td width="71" bgcolor="#FF0000"><div align="center"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">ShareWork</font></strong></div></td>
        </tr>
        <%
        total_amount=0;
		total_MN=0;
		total_ME=0;
		total_ML=0;
        total_SN=0;
		total_SE=0;
		total_SL=0;
        while( it.hasNext() ){
        	wk=(Workload)hm.get(it.next());
          	if( !uname.equalsIgnoreCase(wk.getUser_name()) )
            		uname=wk.getUser_name();
		total_amount = total_amount + wk.getTotal();
        total_MN = total_MN + wk.getMyworkNormal();
        total_ME = total_ME + wk.getMyworkExtend();
        total_ML = total_ML + wk.getMyworkLate();
        total_SN = total_SN + wk.getShareworkNormal();
        total_SE = total_SE + wk.getShareworkExtend();
        total_SL = total_SL + wk.getShareworkLate();
        if( ishead ){
        %>
        <tr bgcolor="#FFFFFF">
          <td bgcolor="#F2F2F2"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= i+1 %></font></div></td>
          <td height="15" bgcolor="#F2F2F2"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= uname%></font></td>
          <td bgcolor="#F2F2F2"><div align="left"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getWf_name()%></font></div></td>
          <td bgcolor="#F2F2F2"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getTotal()%></font></div></td>
          <td bgcolor="#E8FFF3"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getMyworkNormal()%></font></div></td>
          <td bgcolor="#E8FFF3"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getShareworkNormal()%></font></div></td>
          <td bgcolor="#FFFFE6"><div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= wk.getMyworkExtend()%></font></font></div></td>
          <td bgcolor="#FFFFE6"><div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= wk.getShareworkExtend()%></font></font></div></td>
          <td bgcolor="#FFEAEA"><div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= wk.getMyworkLate()%></font></font></div></td>
          <td bgcolor="#FFEAEA"><div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= wk.getShareworkLate()%></font></font></div></td>
        </tr>
        <%
          ishead=false;
        }else{
        %>
        <tr bgcolor="#FFFFFF">
          <td bgcolor="#F2F2F2"><font size="1" face="MS Sans Serif, Tahoma, sans-serif">&nbsp;</font></td>
          <td height="15" bgcolor="#F2F2F2"></td>
          <td bgcolor="#F2F2F2"><div align="left"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getWf_name()%></font></div></td>
          <td bgcolor="#F2F2F2"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getTotal()%></font></div></td>
          <td bgcolor="#E8FFF3"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getMyworkNormal()%></font></div></td>
          <td bgcolor="#E8FFF3"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getShareworkNormal()%></font></div></td>
          <td bgcolor="#FFFFE6"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getMyworkExtend()%></font></div></td>
          <td bgcolor="#FFFFE6"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getShareworkExtend()%></font></div></td>
          <td bgcolor="#FFEAEA"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getMyworkLate()%></font></div></td>
          <td bgcolor="#FFEAEA"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= wk.getShareworkLate()%></font></div></td>
        </tr>
        <%
          }
        }
        ishead=true;
	    percent_total=100;
        if( total_amount <= 0 ){
          percent_N=0;
          percent_E=0;
          percent_L=0;
		  percent_total=0;
        }else{
			double tmn = total_MN;
			double tsn = total_SN;
          percent_N=((tmn+tsn)*100/total_amount);
		  double tme = total_ME;
		  double tse = total_SE;
          percent_E=((tme+tse)*100/total_amount);
		  double tml = total_ML;
		  double tsl = total_SL;
          percent_L=((total_ML+total_SL)*100/total_amount);
        }
        %>
        <tr bgcolor="#F2F2F2">
          <td height="15" colspan="3" bgcolor="#F2F2F2"><div align="right"><font size="1"><font face="MS Sans Serif, Tahoma, sans-serif">Total</font></font></div></td>
          <td><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= total_amount %></font></div></td>
          <td><div align="center"><font color="#000000" size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= total_MN %></font></div></td>
          <td><div align="center"><font color="#000000" size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= total_SN %></font></div></td>
          <td><div align="center"><font color="#000000" face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= total_ME%></font></font></div></td>
          <td><div align="center"><font color="#000000" face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= total_SE%></font></font></div></td>
          <td><div align="center"><font color="#000000" size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= total_ML%></font></div></td>
          <td><div align="center"><font color="#000000" face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= total_SL%></font></font></div></td>
        </tr>
        <tr bgcolor="#CCCCCC">
          <td height="15" colspan="3"><div align="right"><font size="1" face="MS Sans Serif, Tahoma, sans-serif">%Total</font></div></td>
          <td><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= percent_total+"%" %></font></div></td>
          <td colspan="2"><div align="center"><font size="1" face="MS Sans Serif, Tahoma, sans-serif"><%= df.format(percent_N) + "%" %></font></div></td>
          <td colspan="2"><div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= df.format(percent_E) + "%" %></font></font></div>
          <div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"></font></div></td>
          <td colspan="2"><div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"><font size="1"><%= df.format(percent_L) + "%" %></font></font></div>
          <div align="center"><font face="MS Sans Serif, Tahoma, sans-serif"></font></div></td>
        </tr>
      </table>
      <br>
      <%
      	}
      %>
    </div>
  
</form>
</div>
<div id="popmenu" class="menuskin" onMouseover="clearhidemenu();highlightmenu(event,'on')" onMouseout="highlightmenu(event,'off');dynamichide(event)"> 
</div>
</body>
</html>