<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*"%>
<%@page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*,com.csc.library.databean.*,com.csc.library.timeattendance.*"  %>
<%@page import="std.library.*,java.util.*,com.csc.library.report.ReportUDF"  %>
<jsp:useBean id="TAU177_HR" class="com.csc.library.system.Task" scope="page"/>
<jsp:useBean id="SwipeCard" class="com.csc.library.databean.Memployee_swipetime" scope="page"/>
<%
		TAU177_HR.setChannel(request, response);
		UIManager screen = (UIManager) TAU177_HR.process("SingleEntry", "TAU177");
		screen.referLangOn();
		CheckNull chkNull = new CheckNull();

		String emp = chkNull.chkNullString(request.getParameter("__employeeid"));
%>
<html ng-app="myHR">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/MENU.css" rel="stylesheet" type="text/css">
<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>
<style type=text/css>
	.holiday {
		color: #FF00FF !important;
	}
	.week {
		color: #FFA700 !important;
	}
</style>
<script type='text/javascript' src='../JS/SCREEN.js'></script>
<script src="../JS/angular-1.3.15/angular.js" type="text/javascript"></script>
<script src="../JS/ANGULAR/SCREEN_ANGULAR.js" type="text/javascript"></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/ICONSMENU.js'></script>
<script language="javascript">setLang('<%=screen.getUProfile().get("lang")%>');</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 goHelp(helpName,inputName) {
		var helpReturn;
		if (inputName=="__employeeid" ) {
			helpReturn="__employeeid:employeeid,MEMPLOYEE@FULLNAME";
		} //end if

		linkHelp_Return(helpName,helpReturn);
}//end function goHelp

function checkConfirm2(year,month,employeeid){
	with(document.cscform){
	__month.value=month;
	__year.value=year;
	//__employeeid.value=employeeid;
	}
}

function GoSave(){confirmSave();}

function GoUpdate(){
			update();

}

function GoDelete(){edelete();}

function GoSearch(){
	with(document.cscform){
		action="TAU177_HR.jsp";
		target="_self";
	}
	search();

}

function chkTime(obj){
	if(obj.value!=''){
		deldotTime(obj);
		if(obj.value==0){obj.value='0.00';}
		else if(obj.value.length==4){chkOverTime(obj);	}
		else if(obj.value.length==3){chkOverTime2(obj);	}
		else{alert(MyCode[186]);obj.select();}
	}
}

function openPopup(docid){
	with(document.cscform){
		action="TAU153.jsp";
		__help.value="__docid#"+docid+";";
		window.open("","Static","width=650px;height=300px");
		target="Static";
		submit();
	}
}

function openPopupWorkFlow(docid){
	with(document.cscform){
		action="TAU223.jsp";
		__help.value="__fscardid#"+docid+";";
		window.open("","Static","width=850px;height=300px");
		target="Static";
		submit();
	}
}

function openPopupBossFDCard(docid){
	with(document.cscform){
		action="TAU_BOSS_FORGETCARD.jsp";
		__help.value="__fscardid#"+docid+";";
		window.open("","Static","width=850px;height=500px");
		target="Static";
		submit();
	}
}

function setVisible(obj){
		for (x=0;x<obj.document.images.length;x++){
			//document.images[x].style.visibility="hidden";
			obj.document.images[x].style.display="none";
		}//end for

		with(obj.document.forms){
			for(i=0;i<elements.length;i++){
				if(elements[i].type=="text"  || elements[i].type=="textarea"){
					elements[i].disabled =true;
				}else if(elements[i].type=="radio"){
					elements[i].disabled=true;
				}else if(elements[i].type=="select-one"){
					elements[i].disabled=true;
				}else if(elements[i].type=="checkbox"){
					elements[i].disabled=true;
				}

			}//end for
		}//end with
		setTDheight( document.body );
}

function linkHelp(help,input){
	with(document.cscform){
		obj = eval("document.cscform."+input);
		if(obj.value==""){
				var param="PRU084.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value;
		}else{
				var param="PRU084.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value+"&__valueSearch="+obj.value;
		}
		//var param="PRU084.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value;
		__cmd.value = "";
		win = window.open(param,"Help","left=150,top=150,width=600,height=400,resizable=yes,scrollbars=yes,toolbar=no,status=yes");
		if(window.focus){win.focus();}
	}
}


</script>
<STYLE type=text/css>
	TABLE.nuissSize{
		width:750px;
	}
</STYLE>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
<script language="javascript">initToolTips();</script>

  <%
	String cmd = request.getParameter("__cmd");
  %>
  <div align="center">
<form name="cscform" method="post" action="TAU177_HR.jsp">


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

<%=screen.InitialVariable()%>

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

	<input type="hidden" name="__cmd"  value="<%=request.getParameter("__cmd")%>">
	<input type="hidden" name="__screen" value="TAU177_HR">
	<input type="hidden" name="__help" value="">
	<input type="hidden" name="__fixCon" value="">
  <input type="hidden" name="__companyid" value="<%=screen.getUProfile().get("companyid")%>">
	<input type="hidden" name="__notNull" value="<%=screen.getRequire()%>">
	<input type="hidden" name="__language" value ="<%=screen.getUProfile().get("lang")%>">
	<input type="hidden" name="__helpReturn" value="">
</script>
<BR>
    <table  cellpadding="0"  cellspacing="0">
      <tr >
        <td  class="header">TAU177_HR,
		<span swlang code="SW012768">Punch Time Of Month</span>&nbsp;</td>
      </tr>
      <tr >
        <td  colspan="2">
          <div align="center">
            <table  cellpadding="0" cellspacing="0" class='nuissSize'>
              <tr>
                <td colspan="2"  class="blankspace"></td>
              </tr>

              <tr>
                <td class="columnlabel" width="100"><strong><%=screen.getLabel("employeeid")%></strong>&nbsp;</td>
                <td><%=screen.getInput("employeeid")%><!--input type="text" name="__employeeid" value="<%//=screen.getDataLabel("employeeid")%>"   size="20"-->
                <input type="text" name="MEMPLOYEE@FULLNAME" value="<%=screen.getDataLabel("fullname")%>"  readonly size="40"></td>
              </tr>
<%

			CscCalendar csc= new CscCalendar();
			CscCalendar cscmonth= new CscCalendar();

		  int getyear=csc.getYear();
			int getmonth=cscmonth.getMonth();

			String month = chkNull.chkNullString(request.getParameter("__month"),String.valueOf(getmonth+1));
			String year = chkNull.chkNullString(request.getParameter("__year"),String.valueOf(getyear));

			String employeeid = request.getParameter("__employeeid");
			//out.print("<br>employeeid == "+employeeid);
			//out.print("<br>month == "+month);
			//out.print("<br>year == "+year);

			CscCalendar cs1 = new CscCalendar("01-"+month+"-"+year);
			//CscCalendar cs1 = new CscCalendar("01-01-2014");
			CscCalendar cs2 = new CscCalendar(cs1.getEndDateOfMonth()+"-"+month+"-"+year);
			//CscCalendar cs2 = new CscCalendar("31-01-2014");



			DataTable dtbSwipeCardEnv = SwipeCard.getSwipeCardEnv(screen.getUProfile()
																,employeeid,cs1.getYYYYMMDD()
																,cs2.getYYYYMMDD());
			Hashtable htbSwipeSource = new Hashtable();
			Hashtable htbSwipeRemark = new Hashtable();
			Hashtable htbSwipeDocid = new Hashtable();
			if(dtbSwipeCardEnv!=null){
				for(int row=1;row<=dtbSwipeCardEnv.rowCount();row++){
					String swipedate = dtbSwipeCardEnv.getItem(row,"swipedate").toString();
					String[] arrSwipetime= new String[2];
					String swipetime = dtbSwipeCardEnv.getItem(row,"swipetime").toString();
					if(swipetime.indexOf("\\.")<0){
						swipetime+=".00";
					}
					arrSwipetime = swipetime.split("\\.");
					String key = swipedate+"@"+((arrSwipetime[1].length()==1)?arrSwipetime[0]+"."+arrSwipetime[1]+"0":arrSwipetime[0]+"."+arrSwipetime[1]);
					String source =  "";
					String remark = "";
					if(dtbSwipeCardEnv.getItem(row,"source")!=null){
						 source = dtbSwipeCardEnv.getItem(row,"source").toString();
						 htbSwipeSource.put(key,source);
						 String docid ="";
						 if(source.equals("5")||source.equals("4")||source.equals("3")||source.equals("6")||source.equals("7")||source.equals("8")){
							docid = dtbSwipeCardEnv.getItem(row,"docid").toString();
							htbSwipeDocid.put(key,docid);
						 }
					}
					if(dtbSwipeCardEnv.getItem(row,"remark")!=null){
						 remark = dtbSwipeCardEnv.getItem(row,"remark").toString();
						 htbSwipeRemark.put(key,remark);
					}
				}//end for
			}//end if
%>
              <tr>
                <td class="columnlabel"><script language="javascript">swapLang("Month");</script>&nbsp;</td>
                <td >
              <select name="__month">
									<%
									//String[]months={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
									String[] months = new
									ReportUDF().getSystemCode("MONTHCODE",screen.getUProfile().get("lang"));
										for(int m = 0 ; m < 12 ; m++){

									 %>
								<option value="<%=m+1%>" <%if(m==getmonth){%>selected<%}%>><%=months[m].split(",")[1]%></option>
								<%  }  %>
              </select>

									&nbsp;&nbsp;<script language="javascript">swapLang("Year");</script>&nbsp;

								<select name="__year">
									<% for(int i = getyear-5; i < getyear+2; i++){ %>
										<option value="<%=i%>" <%if(getyear == i){%>selected<%}%>><%=i%></option>
									<% } %>
							  </select>

              		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-primary width100" swlang code="SW003537" onClick="GoSearch();">SUBMIT</button>
								</td>
              </tr>
              <tr >
                <td colspan="2" class="blankspace"></td>
              </tr>
              <tr >
                <td colspan="2" >

				<table border="0" cellpadding="0" cellspacing="0" class="inframe tablewithborder">
                  <tr>
                    <td align="center" class="row3"><strong><SCRIPT language="JavaScript">swapLang('Date');</SCRIPT></strong></td>
                    <td colspan="8" align="center" class="row3">
                      <strong><span swlang code="SW012768">Punch Time Of Month</span></strong></td>
                  </tr>
<%if (true){//if (month!=null && year!=null && employeeid!="" && cmd.equals("search")){%>
			<script language="javascript">checkConfirm2('<%=year%>','<%=month%>','<%=employeeid%>');</script>
<%
		if (screen.getRecord().getConfirmStatus()!=-5 && request.getParameter("__cmd") != null ) {
						DbRecord empRec = (DbRecord) new InitialRecord(screen.getUProfile()).getDbRecord("Memployee");
						empRec.setParam("rsc_skip", "true");
						empRec.setColumn("*");
						empRec.set("employeeid", emp);
						empRec.search();
//System.out.print("!! emp field list : " + empRec.getFieldList())
						Mtime0 recTime = (Mtime0) new InitialRecord(screen.getUProfile()).getDbRecord("Mtime0",false);
						recTime.setColumn("*");
						recTime.setEmpRec(empRec);
						screen.getRecord().putChild(recTime);
						screen.getRecord().search();

						WorkingShift ws = null;
						if (!screen.getRecord().getChild("Mtime0").getString("time0id").equals("")) {
							//recTime.setEmpRec(screen.getRecord().cloneRecord(false));
							ws = recTime.genWorkingShift(new CscCalendar(cs1.getYYYYMMDD()), new CscCalendar(cs2.getYYYYMMDD()),"true");
							ws.setUProfile(screen.getUProfile());
							ws.meargeWithShiftTrans(empRec, new CscCalendar(cs1.getYYYYMMDD()), new CscCalendar(cs2.getYYYYMMDD()));

							if (!ws.isEmpty()) {
								ws.setUProfile(screen.getUProfile());
								ws.setEmployeeid(screen.getRecord().getString("employeeid"));
							}
						}
			while (cs1.beforeEqualsDate(cs2)) {
				String cFont = "";
				if(ws.containsKey(cs1.getYYYYMMDD())){
					DayShift dShift = (DayShift)ws.get(cs1.getYYYYMMDD());
					for (Iterator IT1 = dShift.keySet().iterator(); IT1.hasNext(); ) {
						String key1 = (String) IT1.next();
						Shift sh = (Shift) dShift.get(key1);

						cFont = "";
						if (sh.getEventGroup().equals("H")) {
							cFont ="week";
						} else if (sh.getEventGroup().equals("I")) {
							cFont = "holiday";
						}
					}
				}
%>
               <tr>
                    <td align="center" class="forborder"><font class="<%=cFont%>"><%=cs1.getShortThiDOW()+"."%>&nbsp;<%=cs1.getDDMMYYYY()%></font></td>
<%
						for(int col=1;col<=8;col++){
							out.print("<td width='10%' align='center' class='forborder'>");
							String swipedate =cs1.getYYYYMMDD();
							String swipetime = screen.getDataLabel(cs1.getDDMMYYYY()+"_"+col);
							String key = swipedate+"@"+swipetime;

							FieldManager fm = screen.getRecord().getField(cs1.getDDMMYYYY()+"_"+col);
							PropertyField properties = (PropertyField)fm.getProperty().clone();
							String tmp = (String)properties.get("ONBLUR");
							if(tmp ==null) {
								properties.put("ONBLUR", "chkTime(this);");
							} else if(tmp.indexOf("chkTime(this)")==-1) {
								properties.put("ONBLUR", tmp +"chkTime(this);");
							}
							fm.setProperty(properties);

							if(htbSwipeSource.containsKey(key)){
								String data = chkNull.chkNullString(htbSwipeSource.get(key).toString(),"1");
								int source = Integer.parseInt(data);
								switch(source){
									case 3:
										String docid3 = htbSwipeDocid.get(key).toString();
										out.print("<input type='hidden' name='__"+ cs1.getDDMMYYYY()+"_"+col + "' value='" + swipetime +"' onblur='chkTime(this);'>");
										out.print("<a href=javascript:openPopup('"+docid3+"');>"+swipetime+"</a>");
										out.print("&nbsp;&nbsp;<img src='../IMAGES/Flag/20/blue_d.jpg'/>");
										break;
									case 4:
										String docid4 = htbSwipeDocid.get(key).toString();
										out.print("<input type='hidden' name='__"+ cs1.getDDMMYYYY()+"_"+col + "' value='" + swipetime +"' onblur='chkTime(this);'>");
										out.print("<a href=javascript:openPopupBossFDCard('"+docid4+"');>"+swipetime+"</a>");
										out.print("&nbsp;&nbsp;<img src='../IMAGES/Flag/20/red.jpg'/>");
										break;
									case 5:
										String docid5 = htbSwipeDocid.get(key).toString();
										out.print("<input type='hidden' name='__"+ cs1.getDDMMYYYY()+"_"+col + "' value='" + swipetime +"' onblur='chkTime(this);'>");
										out.print("<a href=javascript:openPopupWorkFlow('"+docid5+"');>"+swipetime+"</a>");
										out.print("&nbsp;&nbsp;<img src='../IMAGES/Flag/20/red.jpg'/>");
										break;
									case 6:
										String docid6 = htbSwipeDocid.get(key).toString();
										out.print("<input type='hidden' name='__"+ cs1.getDDMMYYYY()+"_"+col + "' value='" + swipetime +"' onblur='chkTime(this);'>");
										out.print("<a href=javascript:openPopupBossFDCard('"+docid6+"');>"+swipetime+"</a>");
										out.print("&nbsp;&nbsp;<img src='../IMAGES/Flag/20/blue.jpg'/>");
										break;
									case 7:
										String docid7 = htbSwipeDocid.get(key).toString();
										out.print("<input type='hidden' name='__"+ cs1.getDDMMYYYY()+"_"+col + "' value='" + swipetime +"' onblur='chkTime(this);'>");
										out.print("<a href=javascript:openPopupWorkFlow('"+docid7+"');>"+swipetime+"</a>");
										out.print("&nbsp;&nbsp;<img src='../IMAGES/Flag/20/green.jpg'/>");
										break;
									case 8:
										String docid8 = htbSwipeDocid.get(key).toString();
										out.print("<input type='hidden' name='__"+ cs1.getDDMMYYYY()+"_"+col + "' value='" + swipetime +"' onblur='chkTime(this);'>");
										out.print("<a href=javascript:openPopupWorkFlow('"+docid8+"');>"+swipetime+"</a>");
										out.print("&nbsp;&nbsp;<img src='../IMAGES/Flag/20/orange.jpg'/>");
										break;
									default:
										out.print(screen.getInput(cs1.getDDMMYYYY()+"_"+col));
										break;
								}//end sitch
							}else{
								out.print(screen.getInput(cs1.getDDMMYYYY()+"_"+col));
							}
							out.print("</td>");
						}//end col
%>
</tr>
<%
				cs1.incDate();
			}//end while
		}//end if
	}//end if
%>
             </table></td>
              </tr>
			  <tr>
			    <td colspan="2" class="blankspace">&nbsp;</td>
		      </tr>
			  <tr>
			  <td colspan="2"><div align="center"><button type="button" class="btn btn-primary width100" swlang code="SW013175" onClick="GoUpdate();">BACK</button></div></td>
			  </tr>
              <tr >
                <td colspan="2" class="blankspace"></td>
              </tr>
            </table>
			<table style='border:1px solid green;' class='nuissSize'>
				<tr><td  colspan='3' align='center'>*** คำอธิบาย ที่มาของข้อมูลการรูดบัตร ***<td></tr>
				<tr>
					<!-- <td><img src='../IMAGES/Flag/20/blue_d.jpg'></span>&nbsp;&nbsp;<font class="">ใบลงเวลาเป็นกลุ่มโดยฝ่ายบุคคล[3]</font></td> -->
					<td><img src='../IMAGES/Flag/20/red.jpg'></span>&nbsp;&nbsp;ใบแก้ไขเวลาการทำงาน (Workflow) [5]</td>
					<td><img src='../IMAGES/Flag/20/blue.jpg'></span>&nbsp;&nbsp;ใบลืมรูดบัตรโดยหัวหน้า [6]</td>
					<td><img src='../IMAGES/Flag/20/green.jpg'></span>&nbsp;&nbsp;ใบลืมรูดบัตร (HR)[7]</td>
					<td><img src='../IMAGES/Flag/20/orange.jpg'></span>&nbsp;&nbsp;ใบปฏิบัติงานนอกสถานที่ (Workflow)[8]</td>
				</tr>
			</table>
          </div></td>
      </tr>
      <tr>
        <td  class="bottom"></td>
      </tr>
      <tr>
        <td  class="bottom"></td>
      </tr>
    </table>


<!----------BEGIN CSC ENDING ZONE ------------------------>

<%=screen.endJSP()%>

<!----------END CSC ENDING ZONE -------------------------->

</FORM>
<br>
</body>
</html>