<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import="com.csc.library.entry.*" %>
<%@ page import="com.csc.library.utilities.*" %>
	
<%@ page contentType="text/html; charset=UTF-8" %>

<jsp:useBean id="ASR002" scope="page" class="com.csc.library.system.Task"/>
<% 
   ASR002.setChannel(request ,response);
   ReportEntry screen=null;
   screen=(ReportEntry)ASR002.process("ReportEntry",request.getParameter("__screen"));
   UProfile uf=screen.getUProfile();
   com.csc.library.report.ReportUDF rf=new com.csc.library.report.ReportUDF();
%>
<html>
<head>
<title>ReportOption</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"  type="text/css">
<link href="../CSS/bootstrap_csc_backend.css" rel="stylesheet"  type="text/css">
<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
<script type='text/javascript' src="../JS/bootstrap.js"></script>
<script language='javascript' src='../JS/SCREEN.js'></script>
<script language='javascript' src='../JS/jquery-2.1.3.min.js'></script>
<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
<script src="../JS/VIEWCALENDAR.js"></script>

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function back(){ 
	var whereCuz = "";
	with(document.cscform){ 
		chkfilter();
		var strStartDate=convertDate(__condition$startDate.value);
		var strEndDate=convertDate(__condition$endDate.value); 
		whereCuz = " (c_dt_bg >= '"+strStartDate+"' and c_dt_en <='"+strEndDate+"') "
		//whereCuz += " employeeid in ( select employeeid from memployee where ";

		var strWorkStartDate=convertDate(__condition$work_startDate.value);
		var strWorkEndDate=convertDate(__condition$work_endDate.value); 
		var strStatus = "";		
		var strResignStartDate=convertDate(__condition$resign_startDate.value);
		var strResignWorkEndDate=convertDate(__condition$resign_endDate.value);  

		if((__condition$chooseWorkDate.checked) || (__condition$chooseStatus.checked) || (__condition$chooseResignDate.checked) ){
			whereCuz += "and employeeid in ( select employeeid from memployee where ";
		}


		if(__condition$chooseWorkDate.checked){
			if(__condition$work_startDate.value=="" || __condition$work_startDate.value==""){
				alert("กรุณากรอกวันที่เริ่มต้น");
				__condition$work_startDate.focus()
				return;
			} 
			whereCuz+=" ( STARTDATE between '"+strWorkStartDate+"' and '"+strWorkEndDate+"' )";
			whereCuz+=" "+condition$operatorStartDate.value+" ";
		}
		if(__condition$chooseStatus.checked){			
			if(__condition$chooseWorkDate.checked && condition$operatorStartDate.value==""){
				alert("กรุณาเลือก Operator ด้านหลังวันเริ่มทำงาน"); 
				return;
			}
			
			$("input[name='__condition$status']").each(function() {
				if ($(this).prop('checked')) {	
					if(strStatus == ""){
						strStatus += "'" + $(this).val() + "'";
					}else{
						strStatus += ",'" + $(this).val() + "'";
					}					
				} 				
			});
			if(strStatus==""){
				alert("กรุณาเลือกสถานะ"); 
				return;
			} 
			whereCuz+=" ( STATUS in ("+strStatus+") )";
			whereCuz+=" "+condition$operatorStatus.value+" ";
		}
		if(__condition$chooseResignDate.checked){
			if(__condition$resign_startDate.value==""){
				alert("กรุณากรอกวันที่เริ่มต้น"); 
				__condition$chooseResignDate.focus()
				return;
			} 
			if(__condition$chooseWorkDate.checked && condition$operatorStartDate.value==""){
				alert("กรุณาเลือก Operator ด้านหลังวันเริ่มทำงาน"); 
				return;
			}
			if(__condition$chooseStatus.checked && condition$operatorStatus.value==""){
				alert("กรุณาเลือก Operator ด้านหลังสถานะ"); 
				return;
			}
			whereCuz+=" ( RESIGNDATE between '"+strResignStartDate+"' and '"+strResignWorkEndDate+"' )"; 
		}

		if((__condition$chooseWorkDate.checked) || (__condition$chooseStatus.checked) || (__condition$chooseResignDate.checked) ){
			whereCuz += " )";
		}
 
	} 	
	
	with(window.opener.document.cscform){ 
		__fixfilterttime_current1.value = whereCuz;
	}
	console.log("where = "+whereCuz);
	window.close();
}

	function chkfilter(){
		if( $("input[name='__condition$chooseWorkDate']").prop('checked')==false){
			$("select[name='condition$operatorStartDate']").val("");
		}
		if( ($("input[name='__condition$chooseWorkDate']").prop('checked')==true) && ($("input[name='__condition$chooseStatus']").prop('checked')==false)){ 
			$("select[name='condition$operatorStartDate']").val("");
		}
		if( $("input[name='__condition$chooseStatus']").prop('checked')==false){
			$("select[name='condition$operatorStatus']").val("");
		}
		if( ($("input[name='__condition$chooseStatus']").prop('checked')==true) && ($("input[name='__condition$chooseResignDate']").prop('checked')==false)){ 
			$("select[name='condition$operatorStatus']").val("");
		}
	}
 function convertDate(date){
	var tempDate = date.split("-");
	return tempDate[2]+"-"+tempDate[1]+"-"+tempDate[0];
}

//-->
</script>
 

</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif')">
<br>
<form name="cscform" method="post" >

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

<%=screen.InitialVariable()%>

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

<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__language" value ="<%=screen.getUProfile().get("lang")%>">
<script language="javascript">getInputFormatDate();</script>
<input type="hidden" name="__calendar">
  <div align="center" style='1px solid green'>
    <table  cellpadding="0"  cellspacing="0">
      <tr > 
        <td  class="header"> TAR002, 
		<script language="javascript">swapLang('Report Option');</script>&nbsp;</td>
      </tr>
      <tr > 
        <td  colspan="2"> 
          <div align="right"> 
            <table cellpadding="1" cellspacing="1" >
			  <tr> 
					<td class="blankspace" colspan="4"></td>
					<%
						CscCalendar cscStart = new CscCalendar(); 
						CscCalendar cscEnd= new CscCalendar(); 
						cscStart.setDate(23);
						cscStart.decMonth(1);
						cscEnd.setDate(22);
					%>
			  </tr> 
			  <tr>
					<td colspan="4" align="center"> 
						<script language="javascript">swapLang('Start Date');</script>&nbsp; 
 
								<input type="text"   onkeypress="chkIntegerOfDate(this.value)" onblur="chkInputDate2(this,__condition$endDate)" onkeyup="formatDate(this)" maxlength="10" size="10" name="__condition$startDate" value="<%=cscStart.getDDMMYYYY()%>"/> 
								<a onclick="viewCal('__condition$startDate')" onmouseover="MM_swapImage('Image1','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onmouseout="MM_swapImgRestore()" href="#">
									<img height="20" border="0" align="absmiddle" width="20" name="Image1" alt="Calendar" src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif"/>
								</a>
								-  
		  					<script language="javascript">swapLang("End Date");</script>
								<input type="text"  " onkeypress="chkIntegerOfDate(this.value)" onblur="chkInputDate2(__condition$startDate,this)" onkeyup="formatDate(this)" maxlength="10" size="10" name="__condition$endDate" value="<%=cscEnd.getDDMMYYYY()%>"/> 
							<a onclick="viewCal('__condition$endDate')" onmouseover="MM_swapImage('Image2','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onmouseout="MM_swapImgRestore()" href="#">
								<img height="20" border="0" align="absmiddle" width="20" name="Image2" alt="Calendar" src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif"/>
							</a>
					</td>
				</tr> 
				<tr>
					<td align="right">  
						<%=screen.getUProfile().get("lang").equals("tha")?"เลือก":"Choose"%>
					</td>
					<td> 
						&nbsp;
					</td>
					<td> 
						&nbsp;
						</a>
					</td> 
					<td align="center"> 
						 Operator
					</td> 
				</tr>
				<tr>
					<td width="10%" align="right">  
						<input type="checkbox" name="__condition$chooseWorkDate" value="1">
					</td>
					<td width="15%" > 
						<%=screen.getUProfile().get("lang").equals("tha")?"วันที่เข้างาน":"Work Date"%>&nbsp;  
					</td> 		
					<TD width="65%">
							<input type="text" onkeypress="chkIntegerOfDate(this.value)" onblur="chkInputDate2(this,__condition$work_endDate)" onkeyup="formatDate(this)" maxlength="10" size="10" name="__condition$work_startDate"/> 
								<a onclick="viewCal('__condition$work_startDate')" onmouseover="MM_swapImage('Image1','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onmouseout="MM_swapImgRestore()" href="#"><img height="20" border="0" align="absmiddle" width="20" name="Image1" alt="Calendar" src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif"/></a>
								- 
								<input type="text" onkeypress="chkIntegerOfDate(this.value)" onblur="chkInputDate2(__condition$work_startDate,this)" onkeyup="formatDate(this)" maxlength="10" size="10" name="__condition$work_endDate"/> 
							<a onclick="viewCal('__condition$work_endDate')" onmouseover="MM_swapImage('Image2','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onmouseout="MM_swapImgRestore()" href="#">
								<img height="20" border="0" align="absmiddle" width="20" name="Image2" alt="Calendar" src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif"/>
							</a>
					</TD>  
					<td width="10%" > 
						<SELECT name="condition$operatorStartDate" style="width:70px;">
							<option value=""></option>
							<option value="AND">AND</option>
							<option value="OR">OR</option> 
						</SELECT>
					</td>
				</tr>  
				<tr>
					<td align="right">  
						<input type="checkbox" name="__condition$chooseStatus" value="1">
					</td>
					<td> 
						<%=screen.getUProfile().get("lang").equals("tha")?"สถานะ ":"Status "%>&nbsp;  
					</td>
					<td> 						
						<%
						String empStatus[]=rf.getSystemCode("EMPLOYEE_STATUS",screen.getUProfile().get("lang"));
						String[] keyValue = null;
						for(int n=0;n<empStatus.length;n++){
							keyValue=empStatus[n].split(",");
						%>
						<input type="checkbox" name="__condition$status" value="<%=keyValue[0]%>"> <%=keyValue[1]%><br>	
						<%							
							}
						%>
					</td> 
					<td  > 
						<SELECT name="condition$operatorStatus" style="width:70px;">
							<option value=""></option>
							<option value="AND">AND</option>
							<option value="OR">OR</option> 
						</SELECT>
					</td> 
				</tr> 
				<tr>
					<td align="right">  
						<input type="checkbox" name="__condition$chooseResignDate" value="1">
					</td>
					<td> 
						<%=screen.getUProfile().get("lang").equals("tha")?"วันที่ลาออก ":"Resign Date "%>&nbsp;   
					</td>
					<td> 
						<input type="text"  onkeypress="chkIntegerOfDate(this.value)" onblur="chkInputDate2(this,__condition$resign_endDate)" onkeyup="formatDate(this)" maxlength="10" size="10" name="__condition$resign_startDate"/> 
								<a onclick="viewCal('__condition$resign_startDate')" onmouseover="MM_swapImage('Image1','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onmouseout="MM_swapImgRestore()" href="#"><img height="20" border="0" align="absmiddle" width="20" name="Image1" alt="Calendar" src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif"/></a>
								- 
								<input type="text" onkeypress="chkIntegerOfDate(this.value)" onblur="chkInputDate2(__condition$resign_startDate,this)" onkeyup="formatDate(this)" maxlength="10" size="10" name="__condition$resign_endDate"/> 
							<a onclick="viewCal('__condition$resign_endDate')" onmouseover="MM_swapImage('Image2','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)" onmouseout="MM_swapImgRestore()" href="#">
								<img height="20" border="0" align="absmiddle" width="20" name="Image2" alt="Calendar" src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif"/>
							</a>
					</td> 
					<td >  
						&nbsp;
					</td>
				</tr>
              <tr> 
                <td class="blankspace" colspan="2"></td>
              </tr>

							<tr>
								<td  class="buttonline" colspan="7"><div align="center">
									<button type="button" class="btn btn-primary width100" swlang code="SW013169" onClick="back();">OK</button>&nbsp;
									<button type="button" class="btn btn-primary width100" swlang code="SW006927" onClick="window.close();">CANCEL</button>
								</div>
								</td>
							</tr>
              <tr> 
                <td class="blankspace" colspan="4"></td>
              </tr>
            </table>
          </div>
		  </td>
      </tr>
      <tr bordercolor="0069B3"> 
        <td  class="bottom"></td>
      </tr>
    </table>
  </div>
<INPUT TYPE="hidden" NAME="__screen" VALUE="<%=request.getParameter("__screen")%>">
</form>
</body>
</html>