<!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"%>
<%@ page import="java.util.*,java.io.*,java.sql.*"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Date" %>
<%@ page import="com.csc.library.components.*" %>
<%@ page import="com.csc.library.report.ReportUDF" %>
<%@ page import="com.csc.api.recruit.*" %>
<%@ page import="com.csc.library.databean.Simmcandidatewithgson" %>
<%@ page import="com.csc.library.databean.Simmappointmentwithgson" %>
<%@ page import="com.csc.library.databean.Simmapplicanthisotherwithgson" %>
<%@ page import="com.csc.library.utilities.gsonmapping.*" %>
<%
	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();
	ReportUDF udf = new ReportUDF();
	UProfile up = null;

	if (session !=null){
		up = (UProfile)session.getAttribute("userprofile");
	}

	String lang = up.get("lang");
	String filter = chk.chkNullString(request.getParameter("__filter"));
	String filter2 = chk.chkNullString(request.getParameter("__filter2"));
	String cmd = chk.chkNullString(request.getParameter("__cmd"));

	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 language="javascript">setLang('<%=up.get("lang")%>');</script>

		<style>
			img[height="20"] {
				padding: 0px;
			}
			.center{
				text-align: center;
			}
			.wd-40{
				width:40%;
			}
		</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="RRC028.jsp">
			<!----------BEGIN CSC INITIAL ZONE ------------------------>
			<%/*=screen.InitialVariable()*/%>
			<!----------END CSC INITIAL ZONE -------------------------->
			<input type="hidden" name="__cmd" value="">
			<input type="hidden" name="__screen" value="RRC028">
			<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="__export" value="">
			<input type="hidden" name="__filter" value="<%=filter%>">

			<input type="hidden" name="__calendar" value="">
			<script language="javascript">getInputFormatDate()</script>
			<br>
			<table class="maxsize table table-bordered " border="1" cellpadding="0" cellspacing="1" cols=10 >
				<table class="maxsize table table-bordered " border="1" cellpadding="0" cellspacing="1" cols=19  >
				<tr>
					<td class="row1 center"style="text-align:center" colspan='19'><%=up.get("lang").equals("tha")?"รายงานสรุปการสรรหาพนักงานแบ่งตามสถานะการสมัคร":"Recruiting Summary by Application Status"%></td>
				</tr>
				<tr>
					<%-- <td class="row1 center"style="text-align:center"><%=up.get("lang").equals("tha")?"เลขที่ใบขออัตรากำลัง":"Request Date"%></td> --%>
					<td class="row1 center"style="text-align:center"><%=up.get("lang").equals("tha")?"วันที่ขอกำลังคน":"Request Date"%></td>
					<td class="row1 center"style="text-align:center"><%=up.get("lang").equals("tha")?"ตำแหน่ง":"Position"%></td>
					<td class="row1 center"style="text-align:center"><%=up.get("lang").equals("tha")?"เหตุผล":"Reason"%></td>
					<td class="row1 center"style="text-align:center"><%=up.get("lang").equals("tha")?"สถานะตำแหน่ง":"Position Status"%></td>
					<td class="row1 center"style="text-align:center"><%=up.get("lang").equals("tha")?"วันที่ปิดตำแหน่ง":"Closed position Date"%></td>
					<td class="row1 center"style="text-align:center">Blacklist</td>
					<td class="row1 center"style="text-align:center">No Show</td>
					<td class="row1 center"style="text-align:center">Got a job</td>
					<td class="row1 center"style="text-align:center">Not passed interview</td>
					<td class="row1 center"style="text-align:center">Rejected by candidate</td>
					<td class="row1 center"style="text-align:center">Passed Interview</td>
					<td class="row1 center"style="text-align:center">Hired</td>
					<td class="row1 center"style="text-align:center">Pre-screening</td>
					<td class="row1 center"style="text-align:center">1st Interview</td>
					<td class="row1 center"style="text-align:center">2nd Interview</td>
					<td class="row1 center"style="text-align:center">3rd Interview</td>
					<td class="row1 center"style="text-align:center">Comparing</td>
					<td class="row1 center"style="text-align:center">Offer Sent</td>
				</tr>
				<%
					int emp_pass = 0;
					int emp_left = 0;
					
					String emp_pass_name_list = "";
					String substitute_list = "";
					String startDate = "";

					DbInquiry inqmre = new InitialInquiry(up).getDbInquiry("mrequest");
					DbInquiry inqmbranch = new InitialInquiry(up).getDbInquiry("mbranch");
					DbInquiry inqmposition = new InitialInquiry(up).getDbInquiry("mposition");
					DbInquiry inqbu2 = new InitialInquiry(up).getDbInquiry("mbu2");
					DbInquiry inqbu3 = new InitialInquiry(up).getDbInquiry("mbu3");
					DbInquiry inqgrp = new InitialInquiry(up).getDbInquiry("meventgrpbranch");
					DbInquiry inqcan = new InitialInquiry(up).getDbInquiry("Simmcandidatewithgson");
					DbInquiry inqapp_his = new InitialInquiry(up).getDbInquiry("mapplicant_his");
					DbInquiry inqemp = new InitialInquiry(up).getDbInquiry("memployee");
					DbInquiry inqemp2 = new InitialInquiry(up).getDbInquiry("memployee");
					DbInquiry inqsubstitute = new InitialInquiry(up).getDbInquiry("msubstitute");
					DbInquiry inqjob = new InitialInquiry(up).getDbInquiry("mjobcode");
					DbInquiry inqjoblvl = new InitialInquiry(up).getDbInquiry("mjobcode_level");
					DbInquiry inqjobgrade0 = new InitialInquiry(up).getDbInquiry("mjobgrade0");
					DbInquiry inqdaytype = new InitialInquiry(up).getDbInquiry("meventgrpbranch");
					DbInquiry inqcandidate = new InitialInquiry(up).getDbInquiry("mcandidate");

					inqjob.putChild(inqjoblvl);
					inqjob.putChild(inqjobgrade0);
					inqmre.putChild(inqjob);
					inqjob.putChild(inqjoblvl);
					inqmre.putChild(inqmposition);
					inqmre.putChild(inqgrp);
					inqmre.putChild(inqdaytype);
					inqmre.putChild(inqcandidate);
					inqsubstitute.putChild(inqemp2);

					inqmre.setColumn("*");
					inqmre.setFilter(filter);
					inqmre.refresh();
					// out.print(inqmre.getFilter()+"</br>");
					inqapp_his.setColumn("*");
					inqemp.setColumn("*");
					inqmre.refresh();
					while(inqmre.next()){
						int[] count = new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
						emp_pass_name_list = "";
						startDate = "";
						substitute_list = "";
						RestMrequest api_mreq = new RestMrequest();
						api_mreq.setuProfile(up);
						emp_pass = chk.chkNullStringToInt(api_mreq.countHired(inqmre.getString("jobid"),inqmre.getString("requestid")));
						emp_left = chk.chkNullStringToInt(inqmre.getString("emp_num"))-emp_pass;

						inqcandidate.setFilter("jobid = '"+inqmre.getString("jobid")+"'  "+ filter2);
						inqcandidate.refresh();
						while(inqcandidate.next()){
							int zero =  1;
							for (zero = 1;zero < 15 ;zero++){
							if(inqcandidate.getString("status").equals(String.valueOf(zero)))
							{count[zero]++;}
							}
						}
						inqapp_his.setFilter("requestid = '"+inqmre.getString("requestid")+"' and employeeid != '0' ");
						inqapp_his.refresh();
						while(inqapp_his.next()){
							inqemp.setFilter("employeeid = '"+inqapp_his.getString("employeeid")+"'");
							inqemp.refresh();
							while(inqemp.next()){
								if(emp_pass_name_list.equals("")){
									emp_pass_name_list = inqemp.getString("fullname");
									startDate = c.setCscCalendar(inqemp.getString("startdate")).getDDMMYYYY();
								}else{
									emp_pass_name_list += ", "+inqemp.getString("fullname");
									startDate += ", "+c.setCscCalendar(inqemp.getString("startdate")).getDDMMYYYY();
								}
							}						
						}
				%>
				<tr>
					<%-- <td class='center'style="text-align:center"><%=inqmre.getString("requestid")%></td> --%>
					<td class='center'style="text-align:center"><%=c.setCscCalendar(inqmre.getString("approvedate")).getDDMMYYYY()%></td>				
					<td class='center'style="text-align:center"><%=inqmre.getString("mposition","tdesc")%></td>
					<td class='center'style="text-align:center"><%=udf.getSystemCode("type_reason",up.get("lang"),inqmre.getString("subrequest"))%></td>
					<td class='center'style="text-align:center"><%=udf.getSystemCode("reqstatus",up.get("lang"),inqmre.getString("req_status"))%></td>
					<td class='center'style="text-align:center"><%=inqmre.getString("lastdate")%></td>								
					<td class='center'style="text-align:center"><%=count[14]>0?count[14]:""%></td>
					<td class='center'style="text-align:center"><%=count[11]>0?count[11]:""%></td>
					<td class='center'style="text-align:center"><%=count[10]>0?count[10]:""%></td>								
					<td class='center'style="text-align:center"><%=count[2]>0?count[2]:""%></td>
					<td class='center'style="text-align:center"><%=count[13]>0?count[13]:""%></td>
					<td class='center'style="text-align:center"><%=count[1]>0?count[1]:""%></td>
					<td class='center'style="text-align:center"><%=count[9]>0?count[9]:""%></td>								
					<td class='center'style="text-align:center"><%=count[3]>0?count[3]:""%></td>
					<td class='center'style="text-align:center"><%=count[4]>0?count[4]:""%></td>
					<td class='center'style="text-align:center"><%=count[5]>0?count[5]:""%></td>
					<td class='center'style="text-align:center"><%=count[6]>0?count[6]:""%></td>
					<td class='center'style="text-align:center"><%=count[7]>0?count[7]:""%></td>
					<td class='center'style="text-align:center"><%=count[8]>0?count[8]:""%></td>
				</tr>
				<%
					}
				%>
			</table>
		</form>
	</body>
</html>