<!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.Simmapplicantwithgson" %>
<%@ page import="com.csc.library.databean.Simmappointmentwithgson" %>
<%@ page import="com.csc.library.databean.Simmapplicanthisotherwithgson" %>
<%@ page import="com.csc.library.utilities.gsonmapping.*" %>
<%
	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 submitdate = chk.chkNullString(request.getParameter("__submitdate"));
	String submitdate2 = chk.chkNullString(request.getParameter("__submitdate2"));
	String jobid = chk.chkNullString(request.getParameter("__job"));
	String job_desc = chk.chkNullString(request.getParameter("__job_desc"));
	String email = chk.chkNullString(request.getParameter("__email"));
	String fname = chk.chkNullString(request.getParameter("__fname"));
	String lname = chk.chkNullString(request.getParameter("__lname"));
	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(!email.equals("")){
		filter += " and email='"+email+"'";
	}
	if(!submitdate.equals("") && !submitdate2.equals("")){
		filter += " and applicantdate between '"+c.setCscCalendar(submitdate).getYYYYMMDD()+"' and '"+c.setCscCalendar(submitdate2).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 = "RRC027_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);
				}
				if(inputName=="__email"){
					helpReturn = inputName+":email,"+inputName+":fname,"+inputName+":lname";
					fixcon="";
					linkHelp_SendToReturn(helpName,helpReturn,fixcon);
				}


			}

			function linkHelp_SendToReturn(help,input){
				with( document.cscform ){
					var param = "MCANDIDATE_PERSONALNAME.jsp?__helpName="+help+"&__helpReturn="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value+"&__checkVerify=off&__langOn=off";
					window.open(param,"Help","left=150,top=150,width=530,height=370,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
				}
			}
			$(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="RRC027.jsp">
			<!----------BEGIN CSC INITIAL ZONE ------------------------>
			<%/*=screen.InitialVariable()*/%>
			<!----------END CSC INITIAL ZONE -------------------------->
			<input type="hidden" name="__cmd" value="">
			<input type="hidden" name="__screen" value="RRC027">
			<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="<%=request.getParameter("__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">RRC027, รายงานสรุปผลการสมัครงาน</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")?"วันที่ส่งใบสมัคร":"Submit Date"%></td>
									<td style="text-align: left;">
										<input type="text" id="submitdate" name="__submitdate" value="<%=submitdate%>" 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('submitdate')"><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="submitdate2" name="__submitdate2" value="<%=submitdate2%>" 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('submitdate2')"><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 class='wd-40' align="right" swlang code='SW006674'>List of Candidate &nbsp; </td>
								  <td><input type="text" name="__email" size="15" value="<%=email%>">
									<a href="javascript:goHelp('RRC027HELP','__email')" 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="__fname" type="text" id="__fname" value="<%=fname%>" size="22" readonly=""> 
										<input name="__lname" type="text" id="__lname" value="<%=lname%>" size="23" 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='11'><%=up.get("lang").equals("tha")?"รายงานสรุปผลการสมัครงาน":"Job Application Results Conclusion"%></td>
								</tr>
								<tr>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"ชื่อตำแหน่งที่ลงประกาศ":"Position Name"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"วันที่สมัคร":"Applied Date"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"ชื่อผู้สมัคร":"Applicant Name"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"แหล่งที่มา":"Channel"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"สถานะ":"Status"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"วันที่นัดสัมภาษณ์":"Appointment Date"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"เวลา":"Time"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"ชื่อผู้สัมภาษณ์":"Interviewer Name"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"คะแนนสอบ":"Test Score"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"หมายเหตุ":"Remark"%></td>
									<td class="row1 center"><%=up.get("lang").equals("tha")?"วันที่เริ่มงาน":"Employed Date"%></td>
								</tr>
								<%
									// >>>>>>>>>>>>  Current Zone  <<<<<<<<<<<<
									String committees = "";
									String isappointmentTH = "";
									String isappointmentEN = "";
									String jobTH = "";
									String jobEN = "";
									String dateinterview = "";
									String timestart = "";
									String timeend = "";
									String dateavailable = "";
									String emp_pass_name_list = "";
									String startDate = "";
									String ExamData = "0";
									String Fullname = "";
									String FullnameHis = "";
									int Point = 0;
									DbInquiry inqcan = new InitialInquiry(up).getDbInquiry("Simmcandidatewithgson");
									DbInquiry inqpre = new InitialInquiry(up).getDbInquiry("mprefix");
									DbInquiry inqpoint = new InitialInquiry(up).getDbInquiry("Simmappointmentwithgson");
									DbInquiry inqappointment = new InitialInquiry(up).getDbInquiry("mappointment");//get date and time
									DbInquiry inqrequest = new InitialInquiry(up).getDbInquiry("mrequest");
									DbInquiry inqjob = new InitialInquiry(up).getDbInquiry("mjobcode");
									DbInquiry inqsourcejob = new InitialInquiry(up).getDbInquiry("msourcejob");
									DbInquiry inqcom = new InitialInquiry(up).getDbInquiry("mcommittee");
									DbInquiry inqemp = new InitialInquiry(up).getDbInquiry("memployee");
									DbInquiry inqstat = new InitialInquiry(up).getDbInquiry("mstatus");
									DbInquiry inqapp_his = new InitialInquiry(up).getDbInquiry("mapplicant_his");
									inqcan.setColumn("*");

									inqcom.putChild(inqemp);

									inqcan.putChild(inqjob);
									inqcan.putChild(inqappointment);
									inqcan.putChild(inqrequest);
									inqcan.putChild(inqsourcejob);
									inqcan.putChild(inqpoint);
									inqcan.putChild(inqstat);

									inqcan.setFilter(filter);
									//out.print(filter);
									inqcan.refresh();
									
									while(inqcan.next()){
										committees = "";
										ExamData = "";
										Simmcandidatewithgson simmcandidatewithgson = (Simmcandidatewithgson) inqcan.getCurrentDbRecord();
										Simmappointmentwithgson simmappointmentwithgson = (Simmappointmentwithgson) inqpoint.getCurrentDbRecord();								 
								/*		for (McandidateJobrouter.JobRouter jobrouter : simmcandidatewithgson.mcandidateJobrouter.jobrouter) {    
											if(jobrouter.question != null){
												for (McandidateJobrouter.JobRouter.Question question : jobrouter.question){
													if(question.ansgroup.value != null ){
														ExamData += question.ansgroup.value;
														Point = Integer.valueOf(chk.chkNullString(ExamData,"0"));
													}
													if(question.ansgroup.choice != null){
														for (McandidateJobrouter.JobRouter.Question.AnsGroup.Choice choice : question.ansgroup.choice){	
														}  
													}	
												}
											}
										 }*/
										inqpre.setFilter("prefixid = '"+simmcandidatewithgson.mcandidatePersonal.prefixid+"'");
										inqpre.refresh();
										inqpre.next();

										inqsourcejob.setFilter("sourcejobid = '"+simmcandidatewithgson.mcandidateOther.sourcejob+"'");
										inqsourcejob.refresh();
										inqsourcejob.next();

										if(simmappointmentwithgson.mappointmentdetail != null){
											dateinterview = c.setCscCalendar(simmappointmentwithgson.mappointmentdetail.date).getDDMMYYYY();
											timestart = simmappointmentwithgson.mappointmentdetail.time.start;
											timeend = simmappointmentwithgson.mappointmentdetail.time.end;
											isappointmentTH = "มีการนัดหมายแล้ว";
											isappointmentEN = "Have an appointment";
										}else{
											dateinterview = "";
											timestart = "";
											timeend = "";
											isappointmentTH = "ยังไม่มีการนัดหมาย";
											isappointmentEN = "No appointments";
										}
										if(simmcandidatewithgson.mcandidatePersonal != null){
											dateavailable = c.setCscCalendar((simmcandidatewithgson.mcandidatePersonal.dateavailable).substring(0,10)).getDDMMYYYY();
										}else{
											dateavailable = "";
										}

										inqcom.setFilter("requestid = '"+inqpoint.getString("requestid")+"'");
										inqcom.refresh();
										while(inqcom.next()){
											if(committees.equals("")){
												committees = inqcom.getString("MEMPLOYEE","fullname");
											
											}else{
												committees += ", "+inqcom.getString("MEMPLOYEE","fullname");
											
											}
										}
										inqapp_his.setFilter("requestid = '"+inqrequest.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();
												}
											}
										}
									if(up.get("lang").equals("tha")){
										Fullname = inqpre.getString("tdesc")+ simmcandidatewithgson.mcandidatePersonal.fname.tha+" "+simmcandidatewithgson.mcandidatePersonal.lname.tha;
									}else{
										Fullname = inqpre.getString("edesc")+ simmcandidatewithgson.mcandidatePersonal.fname.eng+" "+simmcandidatewithgson.mcandidatePersonal.lname.eng;
									}
								%>
								<tr>
									<td class='center'><%=inqcan.getString("mjobcode","tdesc")%></td>	
									<td class='center'><%=c.setCscCalendar(inqcan.getString("APPLICANTDATE")).getDDMMYYYY()%></td> 
									<td class='center'><%=Fullname%></td>
									<td class='center'><%=up.get("lang").equals("tha")?inqsourcejob.getString("msourcejob","tdesc"):inqsourcejob.getString("msourcejob","edesc")%></td>
									<td class='center'><%=up.get("lang").equals("tha")?inqcan.getString("mstatus","tdesc"):inqcan.getString("mstatus","edesc")%></td> 
									<td class='center'><%=dateinterview%></td>
									<td class='center'><%=timestart%> - <%=timeend%></td> 
									<td class='center'><%=committees%></td>
									<td class='center'><%=Point%></td>
									<td class='center'><%=inqcan.getString("remark")%></td> 	
									<td class='center'><%=startDate%></td> 	
								</tr>
								<%
									}		
									// >>>>>>>>>>>>  History Zone  <<<<<<<<<<<<							
									DbInquiry inqapphis = new InitialInquiry(up).getDbInquiry("Simmapplicanthisotherwithgson");
									DbInquiry inqemp2 = new InitialInquiry(up).getDbInquiry("memployee");

									inqemp2.setColumn("*");
									inqapphis.putChild(inqjob);
									inqapphis.putChild(inqpoint);
									inqapphis.putChild(inqemp2);
									inqapphis.putChild(inqstat);
									inqcom.putChild(inqemp);
									inqapphis.setColumn("*");
									inqapphis.setFilter(filter);
									inqapphis.refresh();

									while(inqapphis.next()){
										Simmapplicanthisotherwithgson simmapplicanthisotherwithgson = (Simmapplicanthisotherwithgson) inqapphis.getCurrentDbRecord();
										Simmappointmentwithgson simmappointmentwithgson = (Simmappointmentwithgson) inqpoint.getCurrentDbRecord();
										committees ="";
										for (MapplicanthisJobrouter.JobRouter jobrouter : simmapplicanthisotherwithgson.mapplicanthisJobrouter.jobrouter) {    
											if(jobrouter.question != null){
												for (MapplicanthisJobrouter.JobRouter.Question question : jobrouter.question){							
													if(question.ansgroup.value != null ){
														ExamData = chk.chkNullString(question.ansgroup.value,"0");
														Point = Integer.valueOf(ExamData);
													}
													if(question.ansgroup.choice != null){
														for (MapplicanthisJobrouter.JobRouter.Question.AnsGroup.Choice choice : question.ansgroup.choice){	
														}  
												}
											}
										}
									}
									inqpre.setFilter("prefixid = '"+simmapplicanthisotherwithgson.mapplicanthisPersonal.prefixid+"'");
								    inqpre.refresh();
								    inqpre.next();

									inqsourcejob.setFilter("sourcejobid = '"+simmapplicanthisotherwithgson.mapplicanthisother.sourcejob+"'");
								    inqsourcejob.refresh();
								    inqsourcejob.next();

									if(simmappointmentwithgson.mappointmentdetail != null){
										dateinterview = c.setCscCalendar(simmappointmentwithgson.mappointmentdetail.date).getDDMMYYYY();
										isappointmentTH = "มีการนัดหมายแล้ว";
										isappointmentEN = "Have an appointment";
									}else{
										dateinterview = "";
										isappointmentTH = "ยังไม่มีการนัดหมาย";
										isappointmentEN = "No appointments";
									}

									inqcom.setFilter("requestid = '"+inqpoint.getString("requestid")+"'");
								    inqcom.refresh();
								    while(inqcom.next()){
								    	if(committees.equals("")){
								    		committees = inqcom.getString("MEMPLOYEE","fullname");
								    	}else{
								    		committees += ", "+inqcom.getString("MEMPLOYEE","fullname");
								    	}
								    }
										if(inqapphis.isFirst()){
								%>
								<tr>
									<td colspan='11'  style='background-color: #3399cc;color: black;'>ประวัติ</td>
								</tr>
								<%
									}
									if(up.get("lang").equals("tha")){
										FullnameHis = inqpre.getString("tdesc")+ simmapplicanthisotherwithgson.mapplicanthisPersonal.fname.tha+" "+simmapplicanthisotherwithgson.mapplicanthisPersonal.lname.tha;
									}else{
										FullnameHis = inqpre.getString("edesc")+ simmapplicanthisotherwithgson.mapplicanthisPersonal.fname.eng+" "+simmapplicanthisotherwithgson.mapplicanthisPersonal.lname.eng;
									}
								%>
								<tr>
									<td class='center'style="text-align:center"><%=up.get("lang").equals("tha")?inqcan.getString("mjobcode","tdesc"):inqcan.getString("mjobcode","edesc")%></td>	
									<td class='center'><%=c.setCscCalendar(inqapphis.getString("APPLICANTDATE")).getDDMMYYYY()%></td>
									<td class='center'><%=FullnameHis%></td>
									<td class='center'><%=up.get("lang").equals("tha")?inqsourcejob.getString("tdesc"):inqsourcejob.getString("edesc")%></td>
									<td class='center'><%=up.get("lang").equals("tha")?inqcan.getString("mstatus","tdesc"):inqcan.getString("mstatus","edesc")%></td> 
									<td class='center'><%=dateinterview%></td>
									<td class='center'><%=timestart%> - <%=timeend%></td> 		
									<td class='center'><%=committees%></td>
									<td class='center'><%=Point%></td>
									<td class='center'><%=inqapphis.getString("employeeid").equals("0")?inqapphis.getString("remark"):up.get("lang").equals("tha")?"ยืนยัน":"Confirm"%></td> 	
									<td class='center'><%=inqapphis.getString("employeeid").equals("0")?"":c.setCscCalendar(inqemp2.getString("startdate")).getDDMMYYYY()%></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>