<!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.text.DateFormat" %>
<%@ 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.Simmapplicant_his_gson" %>
<%@ page import="com.csc.library.utilities.gsonmapping.*" %>
<%
	CheckNull chk = new CheckNull();
	CscCalendar c = new CscCalendar();
	ReportUDF udf = new ReportUDF();
	UProfile up = null;
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	if (session !=null){
		up = (UProfile)session.getAttribute("userprofile");
	}

	String lang = up.get("lang");
	String request_date = chk.chkNullString(request.getParameter("__request_date"));
	String request_date2 = chk.chkNullString(request.getParameter("__request_date2"));
	String jobid = chk.chkNullString(request.getParameter("__job"));
	String job_desc = chk.chkNullString(request.getParameter("__job_desc"));
	String cmd = chk.chkNullString(request.getParameter("__cmd"));
	String isprocess =chk.chkNullString(request.getParameter("__isprocess"));
	String filter = "1=1";

	if(!jobid.equals("")){
		filter += " AND JOBID='"+jobid+"'";
	}
	if(!request_date.equals("") && !request_date2.equals("")){
		// filter += " AND APPLICANTDATE BETWEEN '"+c.setCscCalendar(submitdate).getYYYYMMDD()+"' AND '"+c.setCscCalendar(submitdate2).getYYYYMMDD()+"'";
		filter += " AND requestid in (select requestid from mrequest where request_date BETWEEN '"+c.setCscCalendar(request_date).getYYYYMMDD()+"' AND '"+c.setCscCalendar(request_date2).getYYYYMMDD()+"')";
	}

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

<html ng-app="myHR">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
		<link href="../CSS/bootstrap.css" rel="stylesheet">
		<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 type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
		<script src="../JS/bootstrap.min.js"></script>
		<script type="text/javascript" src="../JS/angular-1.3.15/angular.js"></script>
		<script type="text/javascript" src="../JS/ANGULAR/SCREEN_ANGULAR.js"></script>
		<script language="javascript">setLang('<%=up.get("lang")%>');</script>
		<script language="JavaScript" type="text/JavaScript">

			function GoExport(){
				with(document.cscform){
					// alert(__filter.value);
					var param = "RCR025_EXP.jsp?__filter="+__filter.value;
					window.open(param);
				}
			}

			function GoProcess(){
				with( document.cscform){
          __cmd.value = "search"
          __isprocess.value = "1"
          submit();
				}
			}

			function goHelp(helpName,inputName){
				var helpReturn;
				var fixcon;

				if(inputName=="__job"){
					helpReturn = inputName+":jobcodeid,"+inputName+"_desc:tdesc";
				}
				fixcon="";
				linkHelp_Return(helpName,helpReturn,fixcon);
			}

			$(function() {
		    	  $('#export').click(function() {
		    		  GoExport();
		    	  });

		    	  $('#search').click(function() {
		    		  GoProcess();
		    	  });
			});

		</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="RCR025.jsp">
			<!----------BEGIN CSC INITIAL ZONE ------------------------>
			<%//=screen.InitialVariable()%>
			<!----------END CSC INITIAL ZONE -------------------------->
			<input type="hidden" name="__cmd" value="">
			<input type="hidden" name="__screen" value="RCR025">
			<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="__isprocess" value="0">
			<input type="hidden" name="__filter" value="<%=filter%>">
			<input type="hidden" name="__calendar" value="">
			<script language="javascript">getInputFormatDate()</script>

			<br>
			<div align="center">
				<table class="large" cellpadding="0"  cellspacing="1"  >
					<tr>
						<td  colspan=2 class="header">RCR025,สถานะใบขออัตรากำลัง</td>
					</tr>
					<tr>
						<td colspan=2>
							<table border="0" cellpadding="0" cellspacing="1"   align="center" class="largest">
								<tr>
									<td colspan=2 class="blankspace"></td>
								</tr>
								<tr>
									<td width="40%" align="right"><%=lang.equalsIgnoreCase("tha")?"วันที่ร้องขอ":"Request Date"%></td>
									<td style="text-align: left;">
										<input type="text" id="request_date" name="__request_date" value="<%=request_date%>" size="15" maxlength="10" onkeypress="chkIntegerOfDate(this.value,event);" onkeyup="sysIsEdit();formatDate(this);" onblur="chkInputDate(this);" onfocus="this.select();">
										<a href="javascript:;" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onClick="viewCal('request_date')"><img src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" alt="Calendar" name="Image1" width="20" height="20" border="0" style="vertical-align: middle"></a>
										-
											<input type="text" id="request_date2" name="__request_date2" value="<%=request_date2%>" size="15" maxlength="10" onkeypress="chkIntegerOfDate(this.value,event);" onkeyup="sysIsEdit();formatDate(this);" onblur="chkInputDate(this);" onfocus="this.select();">
											<a href="javascript:;" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image2','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onClick="viewCal('request_date2')"><img src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" alt="Calendar" name="Image2" width="20" height="20" border="0" style="vertical-align: middle"></a>
									</td>
								</tr>
								<tr>
								  <td class='wd-40' align="right" swlang code='SW012911'>job &nbsp; </td>
								  <td><input type="text" name="__job" size="15" value="<%=jobid%>">
									<a href="javascript:goHelp('MJOBCODEHELP','__job')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('imgjob','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="Help" name="imgjob"  border="0" align="absmiddle"></a>
									<input name="__job_desc" type="text" id="__job_desc" value="<%=job_desc%>" size="50" readonly="">      </td>
								</tr>
								<tr>
									<td colspan=2 class="blankspace"></td>
								</tr>
								<tr>
									<td colspan="2" style="text-align: center;">
										<div id="search" class="btn btn-primary btn-sm" style="padding-top: 2px;">
											 Search
										</div>&nbsp;&nbsp;
										<%
											if(isprocess.equals("1")){
										%>
										<div id="export" class="btn btn-primary btn-sm" style="padding-top: 2px;">
											 Export
										</div>
										<%
											}
										%>
									</td>
								</tr>
							</table>

							<%
								if(isprocess.equals("1")){
							%>
							<table class="maxsize table table-bordered " border="1" cellpadding="0" cellspacing="1" cols=10 bgcolor="#CCCCCC">
								</tr>
									<td class="row1 center" colspan='21'>รายงานสรุปการสรรหาพนักงาน</td>
								</tr>
								<tr>
									<td class="row1 center">TR</td>
									<td class="row1 center">RR</td>
									<td class="row1 center">D/M/Y</td>
									<td class="row1 center">Request Date</td>
									<td class="row1 center">Position</td>
									<td class="row1 center">Div.</td>
									<td class="row1 center">Reason</td>
									<td class="row1 center">พนักงานทดแทน</td>
									<td class="row1 center">KPI</td>
									<td class="row1 center">ชื่อผู้สมัคร</td>
									<td class="row1 center">Start Working date</td>
									<td class="row1 center">Signing date</td>
									<td class="row1 center">Total date</td>
									<td class="row1 center">KPI</td>
									<td class="row1 center">Total KPI</td>
									<td class="row1 center">Result</td>
									<td class="row1 center">Recruiter</td>
									<td class="row1 center">Channel</td>
									<td class="row1 center">Level</td>
									<td class="row1 center">Remark</td>
									<td class="row1 center">Status</td>
								</tr>
								<%
									String startwork = "";
									DbInquiry inqpre = new InitialInquiry(up).getDbInquiry("mprefix");
									DbInquiry inqcan = new InitialInquiry(up).getDbInquiry("Simmapplicant_his_gson");
									DbInquiry inqrequest = new InitialInquiry(up).getDbInquiry("mrequest");
									DbInquiry inqjob = new InitialInquiry(up).getDbInquiry("mjobcode");
									DbInquiry inqbu1 = new InitialInquiry(up).getDbInquiry("mbu1");
									DbInquiry inqsourcejob = new InitialInquiry(up).getDbInquiry("msourcejob");
									DbInquiry inqemp = new InitialInquiry(up).getDbInquiry("memployee");
									DbInquiry inqsubstitute = new InitialInquiry(up).getDbInquiry("msubstitute");

									inqcan.setColumn("*");
									inqcan.putChild(inqjob);
									inqcan.putChild(inqemp);
									inqjob.putChild(inqbu1);
									inqrequest.putChild(inqsubstitute);
									inqsubstitute.putChild(inqemp);
									inqcan.setFilter(filter);
									inqcan.refresh();





									while(inqcan.next()){
										startwork = "";
										Simmapplicant_his_gson simmapplicant_his_gson = (Simmapplicant_his_gson) inqcan.getCurrentDbRecord();

										inqpre.setFilter("prefixid = '"+simmapplicant_his_gson.mapplicant_his_resumePersonal.prefixid+"'");
										inqpre.refresh();
										inqpre.next();

										inqsourcejob.setFilter("sourcejobid = '"+simmapplicant_his_gson.mapplicant_his_resumeOther.sourcejob+"'");
										inqsourcejob.refresh();
										inqsourcejob.next();

										inqjob.setFilter("jobcodeid = '"+inqcan.getString("jobid")+"'");
										inqjob.refresh();
										inqjob.next();

										inqrequest.setFilter("requestid = '"+inqcan.getString("requestid")+"'");
										inqrequest.refresh();
										inqrequest.next();

										out.print("");


								%>
								<tr>

								<%
								String emp_type = "";
								String emp_type2 = "";

								String status1 = "";
								String status2 = "";

								String Result = "";

								String signing_date = "";
								String date = "";
								String tyotal_kpi = "";
								String Remark = "";

								String doc_date = c.setCscCalendar(inqrequest.getString("doc_date")).getYYYYMMDDHHMMSS();
								String lastdate = c.setCscCalendar(inqrequest.getString("lastdate")).getYYYYMMDDHHMMSS();

									Date start = df.parse(doc_date);
									Date end = df.parse(lastdate);

									long diff = end.getTime() - start.getTime();

									int dayDiff = (int) (diff / (24 * 60 * 60 * 1000));
									int hourDiff = (int) (diff / (60 * 60 * 1000) % 24);
									int minuteDiff = (int) (diff / (60 * 1000) % 60);
									int secondDiff = (int) (diff / 1000 % 60);

									// System.out.println("Day Diff = " + dayDiff);
									// System.out.println("Hour Diff = " + hourDiff);
									// System.out.println("Minute Diff = " + minuteDiff);
									// System.out.println("Second Diff = " + secondDiff);


									if(inqrequest.getString("emp_type").equals("1")){
										emp_type += " ";
										emp_type2 += "Y";
									}else {
										emp_type += "Y";
										emp_type2 += " ";
									}

									if(inqrequest.getString("subrequest").equals("0")){
										status1 = "New";
									}else if(inqrequest.getString("subrequest").equals("1")){
										status1 = "Replace";
									}

									if(inqrequest.getString("req_status").equals("2")){
										status2 = "Searching";
									}else if(inqrequest.getString("req_status").equals("3")){
										status2 = "Hired";
									}else if(inqrequest.getString("req_status").equals("4")){
										status2 = "ยกเลิก";
									}

									if( (inqrequest.getString("req_status").equals("4") && inqcan.getString("employeeid").equals("0")) || (inqrequest.getString("req_status").equals("4") && (!inqcan.getString("employeeid").equals("0"))) ){
										Result += " ";
									} else if(!inqrequest.getString("req_status").equals("4") && inqcan.getString("employeeid").equals("0")) {
										Result += "No";
									}else if (!inqrequest.getString("req_status").equals("4") && !inqcan.getString("employeeid").equals("0")){
										Result += "Yes";
									}else{
										Result += " ";
									}

								%>
									<td class="center"><%=emp_type%></td>
									<td class="center"><%=emp_type2%></td>
									<td class="center"><%=inqrequest.getString("requestid")%></td>
									<td class="center"><%=c.setCscCalendar(inqrequest.getString("approvedate")).getDDMMYYYY()%></td>
									<td class="center"><%=inqjob.getString("tdesc")%></td>
									<td class="center"><%=inqbu1.getString("tdesc")%></td>
									<td class="center"><%=status1%></td>
									<td class="center"><%=inqsubstitute.getString("memployee","fullname")%></td>
									<td class="center"><%=dayDiff%></td>
									<td class='center'><%=inqpre.getString("tdesc")+simmapplicant_his_gson.mapplicant_his_resumePersonal.fname.tha+" "+simmapplicant_his_gson.mapplicant_his_resumePersonal.lname.tha%></td>
									<td class="center"><%=c.setCscCalendar(inqrequest.getString("doc_date")).getDDMMYYYY()%></td>
									<td class="center"></td>
									<td class="center"></td>
									<td class="center"><%=dayDiff%></td>
									<td class="center"></td>
									<td class="center"><%=Result%></td>
									<td class="center"></td>
									<td class="center"><%=inqsourcejob.getString("tdesc")%></td>
									<td class="center"><%=inqjob.getString("jobcode_level")%></td>
									<td class="center"></td>
									<td class="center"><%=status2%></td>
								</tr>
								<%
									}
								%>
							</table>
							<%
								}
							%>
						</td>
					</tr>
					<tr>
						<td colspan=2 class="blankspace"></td>
					</tr>
					<tr>
						<td colspan=2 class="blankspace"></td>
					</tr>
					<tr bordercolor="0069B3">
						<td colspan=2 class="bottom"></td>
					</tr>
				</table>
			</div>
		</form>
	</body>
</html>