<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.*,com.csc.library.system.*,com.csc.library.session.*,com.csc.library.utilities.*,java.text.DecimalFormat,com.csc.library.database.*"%>
<%@page import="java.util.*,java.io.*,java.sql.*"%>
<%@ include file="../CHECKPROFILE.jsp" %>
<%
	response.setHeader("Cache-Control","must-revalidate");
	response.setContentType("application/vnd.ms-excel; UTF-8");
	response.setHeader("Content-Disposition", "inline; filename=" + "export.xls");

  CheckNull chk = new CheckNull();
	CscCalendar c = new CscCalendar();
	UProfile up = null;

	if (session !=null){
		up = (UProfile)session.getAttribute("userprofile");
	}
  DecimalFormat dmfm1 = new DecimalFormat("#,##0.00");

	String cmd = chk.chkNullString(request.getParameter("__cmd"));
	String bu1id =chk.chkNullString(request.getParameter("__bu1"));
	String bu2id =chk.chkNullString(request.getParameter("__bu2"));
	String bu3id =chk.chkNullString(request.getParameter("__bu3"));
	String bu4id =chk.chkNullString(request.getParameter("__bu4"));
	String bu5id =chk.chkNullString(request.getParameter("__bu5"));
	String apsassessy =chk.chkNullString(request.getParameter("__employeeid"));
	String apsid =chk.chkNullString(request.getParameter("__apsid"));
	String isprocess =chk.chkNullString(request.getParameter("__isprocess"));
	String apsyear =chk.chkNullString(request.getParameter("__apsyear"));
	String filter = chk.chkNullString(request.getParameter("__filter"));

	DbRecord dbrec = new InitialRecord(up).getDbRecord("memployee");
	dbrec.setColumn("*");
%>

<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/DATEINPUT.js'></SCRIPT>
<SCRIPT TYPE='text/JavaScript' SRC='../JS/VIEWCALENDAR.js'></SCRIPT>
<script language="javascript">setLang('<%=uprofile.get("lang")%>');</script>
<style>
	.num {
	  mso-number-format:General;
	}
	.format_text{
	  mso-number-format:"\@";/*force text*/
	}
</style>
</head>
<%
String helpReturn="";
if(request.getParameter("__helpReturn")!=null){
	helpReturn=request.getParameter("__helpReturn");
}
String fieldSearch="";
if(request.getParameter("__fieldSearch")!=null){
	fieldSearch=request.getParameter("__fieldSearch");
}
%>
<body leftmargin="0" topmargin="0">
<form name="cscform" method="post" action="APSR010.jsp">


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

<%//=screen.InitialVariable()%>

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

<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__screen" value="APSR010">
<input type="hidden" name="__help" value="">
<input type="hidden" name="__goPage" value="">
<input type="hidden" name="__language" value="<%=up.get("lang")%>">
<input type="hidden" name="__orderBy" value="<%=request.getParameter("__orderBy")%>">
<input type="hidden" name="__helpReturn" value="<%=helpReturn%>">
<input type="hidden" name="__fieldSearch" value="<%=fieldSearch%>">
<input type="hidden" name="__helpName" value="<%=request.getParameter("__helpName")%>">
<input type="hidden" name="__pageCall" value="<%=request.getParameter("__screen")%>">
<input type="hidden" name="__fixCon" value="<%=request.getParameter("__fixCon")%>">
<input type="hidden" name="__astype" value="AP10">
<input type="hidden" name="__export" value="">
<input type="hidden" name="__filter" value="<%=request.getParameter("__filter")%>">

<script language="javascript">getInputFormatDate()</script>

<br>
<table class="maxsize" border="1" cellpadding="0" cellspacing="1" cols=11 bgcolor="#CCCCCC">
      <tr>
        <td class="row1" rowspan=2><div align="center" swlang code="SW000193">ลำดับที่</div></td>
        <td class="row1" rowspan=2><div align="center" swlang code="SW000274">รหัสพนักงาน</div></td>
        <td class="row1" rowspan=2><div align="center" swlang code="SW001984">ชื่อพนักงาน</div></td>
				<td class="row1" rowspan=2><div align="center" swlang code="SW007358">สถานที่ทำงาน</div></td>
        <td class="row1" rowspan=2><div align="center"><b><%=dbrec.getField("bu4").getDescription()%></b></div></td>
        <td class="row1" rowspan=2><div align="center" swlang code="SW000057">ตำแหน่ง</div></td>
				<td class="row1" rowspan=2><div align="center" swlang code="SW011749">วันที่เริ่มทำงาน</div></td>
        <td class="row1" rowspan=2><div align="center" swlang code="SW000739">อายุงาน</div></td>
        <td class="row1" colspan=2><div align="center" swlang code="SW012602">ส่วนที่ 1</div></td>
        <td class="row1" colspan=2><div align="center" swlang code="SW012603">ส่วนที่ 2</div></td>
        <td class="row1" colspan=2><div align="center" swlang code="SW012628">ส่วนที่ 3</div></td>
        <td class="row1" colspan=2><div align="center" swlang code="SW012629">ส่วนที่ 4</div></td>
        <td class="row1" rowspan=2><div align="center" swlang code="SW000068">คะแนนรวม</div></td>
        <td class="row1" rowspan=2><div align="center" swlang code="SW000069">เกรด</div></td>
      </tr>
      <tr>
        <td class="row1" ><div align="center">คะแนนเต็ม</div></td>
        <td class="row1" ><div align="center">คะแนนได้</div></td>
        <td class="row1" ><div align="center">คะแนนเต็ม</div></td>
        <td class="row1" ><div align="center">คะแนนได้</div></td>
        <td class="row1" ><div align="center">คะแนนเต็ม</div></td>
        <td class="row1" ><div align="center">คะแนนได้</div></td>
        <td class="row1" ><div align="center">คะแนนเต็ม</div></td>
        <td class="row1" ><div align="center">คะแนนได้</div></td>
      </tr>
      <%
        int seq = 0;
        double scoreop1 = 0;
        double scoreop2 = 0;
        double scoreop3 = 0;
        double scoreop4 = 0;
        double totalscore = 0;
        String grade = "C";
        String apsid2 = "";
        int fullscoreop1 = 0;
        int fullscoreop2 = 0;
        int fullscoreop3 = 0;
        int fullscoreop4 = 0;

        DbInquiry inqtap = new InitialInquiry(up).getDbInquiry("tapstran");
        DbInquiry inqemp = new InitialInquiry(up).getDbInquiry("memployee");
        DbInquiry inqbu4 = new InitialInquiry(up).getDbInquiry("mbu4");
        DbInquiry inqpos = new InitialInquiry(up).getDbInquiry("mposition");
        DbInquiry inqkpi = new InitialInquiry(up).getDbInquiry("mkpiscore");
				DbInquiry inqworkarea = new InitialInquiry(up).getDbInquiry("mworkarea");

        inqkpi.setColumn("*");

        inqemp.setColumn("*");
        inqemp.putChild(inqbu4);
        inqemp.putChild(inqpos);
				inqemp.putChild(inqworkarea);

        //out.print(filter);

        inqtap.setColumn("*");
        inqtap.setFilter(filter);
        inqtap.setOrderBy("apsassessy");
        inqtap.putChild(inqemp);
        inqtap.refresh();
        while(inqtap.next()){
          seq++;

          scoreop1 = (chk.chkNullStringToDouble(inqtap.getString("apsscore1")) + chk.chkNullStringToDouble(inqtap.getString("apsscore3")) + chk.chkNullStringToDouble(inqtap.getString("apsscore2")) + chk.chkNullStringToDouble(inqtap.getString("apsscore4"))) /2 ;
          scoreop2 = (chk.chkNullStringToDouble(inqtap.getString("apsscore5")) + chk.chkNullStringToDouble(inqtap.getString("apsscore_last"))) /2 ;
          scoreop3 = (chk.chkNullStringToDouble(inqtap.getString("apssumscore3")) + chk.chkNullStringToDouble(inqtap.getString("apssumscore4"))) /2 ;
          scoreop4 = chk.chkNullStringToDouble(inqtap.getString("other1"));

          totalscore = scoreop1 + scoreop2 + scoreop3 + scoreop4;

          if(totalscore >= 85){
            grade = "A";
          }else if(totalscore >= 80){
            grade = "A-";
          }else if(totalscore >= 75){
            grade = "B";
          }else if(totalscore >= 65){
            grade = "B-";
          }else if(totalscore < 65){
            grade = "C";
          }

          apsid2 = inqtap.getString("apsid");

          if(apsid2.indexOf("LOW1")>-1){

            inqkpi.setFilter("kpisid ='OP1'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop1 = chk.chkNullStringToInt(inqkpi.getString("score_low1"));

            inqkpi.setFilter("kpisid ='OP2'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop2 = chk.chkNullStringToInt(inqkpi.getString("score_low1"));

            inqkpi.setFilter("kpisid ='OP3'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop3 = chk.chkNullStringToInt(inqkpi.getString("score_low1"));

            inqkpi.setFilter("kpisid ='OP4'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop4 = chk.chkNullStringToInt(inqkpi.getString("score_low1"));

          }else if(apsid2.indexOf("LOW2")>-1){

            inqkpi.setFilter("kpisid ='OP1'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop1 = chk.chkNullStringToInt(inqkpi.getString("score_low2"));

            inqkpi.setFilter("kpisid ='OP2'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop2 = chk.chkNullStringToInt(inqkpi.getString("score_low2"));

            inqkpi.setFilter("kpisid ='OP3'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop3 = chk.chkNullStringToInt(inqkpi.getString("score_low2"));

            inqkpi.setFilter("kpisid ='OP4'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop4 = chk.chkNullStringToInt(inqkpi.getString("score_low2"));

          }else if(apsid2.indexOf("UP1")>-1){

            inqkpi.setFilter("kpisid ='OP1'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop1 = chk.chkNullStringToInt(inqkpi.getString("score_up1"));

            inqkpi.setFilter("kpisid ='OP2'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop2 = chk.chkNullStringToInt(inqkpi.getString("score_up1"));

            inqkpi.setFilter("kpisid ='OP3'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop3 = chk.chkNullStringToInt(inqkpi.getString("score_up1"));

            inqkpi.setFilter("kpisid ='OP4'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop4 = chk.chkNullStringToInt(inqkpi.getString("score_up1"));

          }else if(apsid2.indexOf("UP2")>-1){

            inqkpi.setFilter("kpisid ='OP1'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop1 = chk.chkNullStringToInt(inqkpi.getString("score_up2"));

            inqkpi.setFilter("kpisid ='OP2'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop2 = chk.chkNullStringToInt(inqkpi.getString("score_up2"));

            inqkpi.setFilter("kpisid ='OP3'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop3 = chk.chkNullStringToInt(inqkpi.getString("score_up2"));

            inqkpi.setFilter("kpisid ='OP4'");
            inqkpi.refresh();
            inqkpi.next();
            fullscoreop4 = chk.chkNullStringToInt(inqkpi.getString("score_up2"));

          }

      %>
      <tr>
        <td><center><%=seq%></center></td>
        <td><center><%=inqtap.getString("apsassessy")%></center></td>
        <td><%=inqtap.getString("memployee","fullname")%></td>
				<td><%=inqtap.getString("mworkarea","tdesc")%></td>
        <td><%=inqtap.getString("mbu4","tdesc")%></td>
        <td><%=inqtap.getString("mposition","tdesc")%></td>
				<td><%=new CscCalendar(inqtap.getString("memployee","startdate")).getDDMMYYYY()%></td>
        <td><%=inqtap.getString("memployee","empworkages")%></td>
        <td><center><b><%=fullscoreop1%></b></center></td>
        <td><center><%=dmfm1.format(scoreop1)%></center></td>
        <td><center><b><%=fullscoreop2%></b></center></td>
        <td><center><%=dmfm1.format(scoreop2)%></center></td>
        <td><center><b><%=fullscoreop3%></b></center></td>
        <td><center><%=dmfm1.format(scoreop3)%></center></td>
        <td><center><b><%=fullscoreop4%></b></center></td>
        <td><center><%=dmfm1.format(scoreop4)%></center></td>
        <td><center><%=dmfm1.format(totalscore)%></center></td>
        <td><center><b><%=grade%></b></center></td>
      </tr>

      <%
        }
      %>
  </table>
</form>
</body>
</html>
