<%@page contentType="text/html; charset=UTF-8" language="java" %>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*,java.util.*"%>
<%@page import="com.csc.library.utilities.CscCalendar,com.csc.library.entry.HelpEntry,com.csc.library.system.*"%>
<%@page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*,com.csc.library.formula.FormulaString"  %>
<%@ include file="../CHECKPROFILE.jsp" %>
<%@page import="java.text.DecimalFormat"  %>
<% request.setCharacterEncoding("UTF-8"); %>
<jsp:useBean id="EMV" class="com.csc.library.system.Task" scope="page" />
<jsp:setProperty name="EMV" property="appname" value="empview" />
<%
	EMV.setChannel(request, response);	
	ThaiUtilities thaicode=new ThaiUtilities();
	CheckNull chk = new CheckNull();
	String empID = thaicode.ASCII2Unicode(chk.chkNullString(request.getParameter("__empID")));
	String empName = thaicode.ASCII2Unicode(chk.chkNullString(request.getParameter("__empName")));
	String month = chk.chkNullString(request.getParameter("__monthid"));
	String year = chk.chkNullString(request.getParameter("__yearid"));
	CscCalendar startDate = new CscCalendar("01-"+month+"-"+year);
	CscCalendar endDate = new CscCalendar(startDate.getEndDateOfMonth()+"-"+month+"-"+year);
	HelpEntry screen = (HelpEntry)EMV.process("HelpEntry", "EMP_WORKINGTIMEHELP"); 	
	screen.inq.setFilter("employeeid = '"+empID+"' and (dateid between '"+startDate.getYYYYMMDD()+"' and '"+endDate.getYYYYMMDD()+"')");
	//screen.inq.refresh();	
	//screen.nextRec();
	screen.process();
	
	CscCalendar cs = new CscCalendar();
	DecimalFormat df = new DecimalFormat("0.00");
	DecimalFormat df2 = new DecimalFormat("00.00");
	FormulaString fs = new FormulaString();
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myHR">
<html>
<title>Employee View</title>
	<head>
		<link rel="stylesheet" href="<%=request.getContextPath()%>/CSS/font-awesome.css">
		<link rel="stylesheet" type="text/css" href="../CSS/Bootstrap/css/bootstrap.css" />
		<link rel="stylesheet" type="text/css" href="../CSS/EMPVIEW_LAYOUT.min.css" />
		
		<script type="text/javascript" src="../JS/EVENTS.js"></script>
		<script type="text/javascript" src="../JS/DDMENU.js"></script>
		<script type="text/javascript" src="../JS/UTILITIES.js"></script>
		<script type="text/javascript" src="../JS/ACTIVE_OBJECT.js"></script>
		<script type="text/javascript" src="../JS/SCREEN.js"></script>
		<script type="text/javascript" src="../JS/jquery-2.1.3.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>
			setLang('<%=screen.getUProfile().get("lang")%>');
			var swap = new swaplang();
            var titlename = swap.swap2String("SW011251");
			setPageTitle(titlename);
	
		</script>
	</head>
	
	<body>
		<div class="bg-com"></div>
			<div class="container csc-content">
				<form name="cscform" class="form-horizontal" method="post">
					<input type="hidden" name="__screen"  value="EMV_WORKINGTIME">
					<input type="hidden" name="__fixCon" value="<%=request.getParameter("__fixCon")%>">
					<input type="hidden" name="__cmd"  value="">
					<input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>">
					<input type="hidden" name="__companyid" value='<%=screen.getUProfile().get("companyid")%>'>
					<input type="hidden" name="__employeeid" value="<%=request.getParameter("__empID")%>">
					<input type="hidden" name="__referPage" value="">
					<input type="hidden" name="__childFilter">
					<input type="hidden" name="__gorec">
					<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
					<script language="javascript">initToolTips();</script> 
					
					<div class="csc-block-white">
						<div class="center">
							<h4><label swlang code='SW011251'>Working Time History Detail</label> <label swlang code='SW001838'>of</label> <label swlang code='SW000307'>Employee</label> : <%=empID%>&nbsp;&nbsp;<%=empName %> </h4>
						</div>
						<div class="container csc-content">
							<table class="table table-head table-hover table-bordered table-title-left table-content-center">
								<thead>
									<tr>
										<th class="table-title" colspan=15 >
											<%
												if (startDate!=null && !startDate.equals("") && endDate!=null && !endDate.equals("")) {
													if (screen.getUProfile().get("lang").equals("tha")) {
														out.println(startDate.getThaiFull()+" - "+endDate.getThaiFull());
													} else {
														out.println(startDate.getEngFull()+" - "+endDate.getEngFull());
													}
												} 
											%>
										</th>
									</tr>
									<tr>
										<th swlang code='SW000002'>Date</th> 
										<th swlang code='SW000262'>Day</th>  
										<th swlang code='SW001815'>Working Time</th>  
										<th swlang code='SW001822'>SwipeTime</th>  
										<th swlang code='SW000367'>Day Type</th>  
										<th swlang code='SW000055'>Late</th>  
										<th swlang code='SW000056'>Absent</th>  
										<th swlang code='SW000299'>Leave</th>  
										<th swlang code='SW000301'>OT</th> 
										<th swlang code='SW001882'>OT1</th> 
										<th swlang code='SW001883'>OT5</th> 
										<th swlang code='SW001884'>OT2</th> 
										<th swlang code='SW001885'>OT3</th> 
										<th swlang code='SW001886'>Work</th>  
										<th swlang code='SW001887'>Other</th> 
									</tr>
								</thead>
								<tbody>
									<%
										HashMap hmHoliday = new HashMap();
										try {
											DbInquiry inqHoliday = new InitialInquiry(screen.getUProfile()).getDbInquiry();
											inqHoliday.setSchemaName(screen.getUProfile().getSchemaName());
											inqHoliday.initMyTable("Mholiday1", "", "");
											inqHoliday.setColumn("*");
														
											DbInquiry inqTime = new InitialInquiry(screen.getUProfile()).getDbInquiry();
											inqTime.setSchemaName(screen.getUProfile().getSchemaName());
											inqTime.initMyTable("Mtime0", "", "");
											inqTime.setColumn("*");
											inqTime.putChild(inqHoliday);					
											
											DbInquiry inqEmp = new InitialInquiry(screen.getUProfile()).getDbInquiry();
											inqEmp.setSchemaName(screen.getUProfile().getSchemaName());
											inqEmp.initMyTable("Memployee", "employeeid='"+request.getParameter("__empID")+"'", "");
											inqEmp.setColumn("*");
											inqEmp.putChild(inqTime);								
											inqEmp.refresh();
											while (inqEmp.next()) {
																		inqEmp.referLangOn();
												DbInquiry childTime =  (DbInquiry) inqEmp.getChild("Mtime0");
												DbInquiry child = (DbInquiry) childTime.getChild("Mholiday1");
												do {
													CscCalendar cHol = new CscCalendar(child.getString("hdate"));
													hmHoliday.put(cHol.getDDMMYYYY(), child.getString("tdesc"));
												} while (child.next());
											}
										} catch (Exception e) {}
										//out.println(hmHoliday);
									%>       
									<%
										String holiday = "";
										CscTime ct_late = new CscTime();
										CscTime ct_absent = new CscTime();
										CscTime ct_leave = new CscTime();
										CscTime ct_ot = new CscTime();
										CscTime ct_ot1 = new CscTime();
										CscTime ct_ot5 = new CscTime();
										CscTime ct_ot2 = new CscTime();
										CscTime ct_ot3 = new CscTime();
										CscTime ct_work = new CscTime();
										while (screen.nextRec()) {	
																screen.referLangOn();
											DbRecord rec = screen.inq.getCurrentDbRecord();
											CscCalendar cDate = new CscCalendar(rec.getString("dateid"));
											String day = "", cFont  = "";
											if (((String) screen.getUProfile().get("lang")).equalsIgnoreCase("THA")) { //แสดงวันจันทร์ , อังคาร, พุธ เป็นต้น
												day = cDate.getDOWTHI(); 
											} else day = cDate.getDOWENG(); 
											if (rec.getString("eventgrp").equals("H")) {
												cFont = "week";
											} else if (rec.getString("eventgrp").equals("I")) {
												cFont = "holiday";
												String tmp = ((String) hmHoliday.get(cDate.getDDMMYYYY()));
												if (tmp==null) tmp="";
												holiday += cDate.getDDMMYYYY()+" "+tmp+", ";
											} else if (rec.getString("eventgrp").equals("J")) {
												cFont = "absent";
											}				
									%>
									<tr>
										<td class="<%=cFont%>"><%=cDate.getDDMMYYYY()%></td>
										<td class="<%=cFont%>"><%=day%></td>
										<td class="<%=cFont%>"><%=df2.format(rec.getDouble("c_tm_bg"))%> - <%=df2.format(rec.getDouble("c_tm_en"))%></td>
										<td class="<%=cFont%>">
											<%
												String time_in = "";
												String time_out = "";
												if (rec.getString("forget_in").equals("1")) {
													time_in = "__-__";
												} else time_in = df2.format(rec.getDouble("m_tm_bg"));
												if (rec.getString("forget_out").equals("1")) {
													time_out = "__-__";
												} else time_out = df2.format(rec.getDouble("m_tm_en"));
												out.println(time_in+" - "+time_out);
											%>
										</td>
										<td class="<%=cFont%>">
											<%
												String lv_type = (String) screen.getString("meventgrp","tdesc");
												if (lv_type==null ||  lv_type.equals("null"))  {
													out.println();
												} else { 
													if (rec.getString("eventgrp").equals("I")) {
														if (hmHoliday.get(cDate.getDDMMYYYY())!=null) {
															out.println(hmHoliday.get(cDate.getDDMMYYYY()));
														} else out.println(lv_type);
													} else out.println(lv_type);
												}
											%>
											<%/* if (rec.getString("eventgrp").equals("H") || rec.getString("eventgrp").equals("I")) { */%>
												<!-- <script language="javascript">swapLang('Holiday')</script> -->
											<%/* } else { 
												out.println(screen.getString("meventgrp","tdesc"));
											 }*/ %>
										</td>
										<td class="<%=cFont%>">
											<% 
												if (rec.getDouble("lt")>0) { 
													ct_late.add(rec.getDouble("lt"));
													out.println(df.format(rec.getDouble("lt")));
												} 
											%> 
										</td>
										<td class="<%=cFont%>">
											<% 
												if (rec.getString("eventgrp").equals("J") && rec.getDouble("m_lv")>0) { 
													ct_absent.add(rec.getDouble("m_lv"));
													out.println(df.format(rec.getDouble("m_lv")));
												} 
											%>
										</td>
										<td class="<%=cFont%>">
											<% 
												if (!rec.getString("eventgrp").equals("J") && rec.getDouble("m_lv")>0) { 
													ct_leave.add(rec.getDouble("m_lv"));
													out.println(df.format(rec.getDouble("m_lv")));
												} 
											%>
										</td>
										<td class="<%=cFont%>">
											<% 
												if (rec.getDouble("ac_ot")>0) { 
													ct_ot.add(rec.getDouble("ac_ot"));
													out.println(df.format(rec.getDouble("ac_ot")));
												} 
											%> 
										</td>
										<td class="<%=cFont%>">
											<% 
												if (rec.getDouble("ot1")>0) { 
													ct_ot1.add(rec.getDouble("ot1"));
													out.println(df.format(rec.getDouble("ot1")));
												} 
											%> 
										</td>
										<td class="<%=cFont%>">
											<% 
												//nuiss edit 15/10/2551
												//กำหนดตัวแปร ผิดนิดเดียว เอา ct_ot1 มารับ แก้เป็น ct_ot5
												if (rec.getDouble("ot5")>0) { 
													ct_ot5.add(rec.getDouble("ot5"));
													out.println(df.format(rec.getDouble("ot5")));
												} 
											%> 
										</td>
										<td class="<%=cFont%>">
											<% 
												if (rec.getDouble("ot2")>0) { 
													ct_ot2.add(rec.getDouble("ot2"));
													out.println(df.format(rec.getDouble("ot2")));
												} 
											%> 
										</td>
										<td class="<%=cFont%>">
											<% 
												if (rec.getDouble("ot3")>0) { 
													ct_ot3.add(rec.getDouble("ot3"));
													out.println(df.format(rec.getDouble("ot3")));
												} 
											%> 
										</td>
										<td class="<%=cFont%>">
											<% 
												if (rec.getDouble("hour_d")>0) { 
													ct_work.add(rec.getDouble("hour_d"));
													out.println(df.format(rec.getDouble("hour_d")));
												} 
											%> 
										</td>
										<td class="<%=cFont%>">
											<% if (rec.getDouble("unused1")>0) { %>
											<span class="status-default"></span>
											<% } %>
											<% if (rec.getDouble("unused2")>0) { %>
											<span class="status-wait"></span>
											<% } %>
											<% if (rec.getDouble("unused3")>0) { %>
											<span class="status-notapprove"></span>
											<% } %>
											<% if (rec.getDouble("unused4")>0) { %>
											<span class="status-timeover"></span>
											<% } %>
											<% if (rec.getDouble("unused5")>0) { %>
											<span class="status-approve"></span>
											<% } %>
										</td>
									</tr>
									<%
										} //while (screen.inq.next()) 
									%> 
									<tr>  <!-- Display Summary -->
										<td class="result-right" colspan="5" swlang code='SW000024'>Total</td>
										<td class="result"><%=(ct_late.getFloat()==0)?"":df.format(ct_late.getFloat())%></td>
										<td class="result"><%=(ct_absent.getFloat()==0)?"":df.format(ct_absent.getFloat())%></td>
										<td class="result"><%=(ct_leave.getFloat()==0)?"":df.format(ct_leave.getFloat())%></td>
										<td class="result"><%=(ct_ot.getFloat()==0)?"":df.format(ct_ot.getFloat())%></td>
										<td class="result"><%=(ct_ot1.getFloat()==0)?"":df.format(ct_ot1.getFloat())%></td>
										<td class="result"><%=(ct_ot5.getFloat()==0)?"":df.format(ct_ot5.getFloat())%></td>
										<td class="result"><%=(ct_ot2.getFloat()==0)?"":df.format(ct_ot2.getFloat())%></td>
										<td class="result"><%=(ct_ot3.getFloat()==0)?"":df.format(ct_ot3.getFloat())%></td>
										<td class="result"><%=(ct_work.getFloat()==0)?"":df.format(ct_work.getFloat())%></td>
										<td class="result"> </td>
									</tr>
									<%
										String color1 = "", color2 = "", color3= "", color4 = "", color5 = "";
										try {
											color1 = (String) StaticConfig.getConfigCompany(screen.getUProfile(), "ta1021");
											color2 = (String) StaticConfig.getConfigCompany(screen.getUProfile(), "ta1022");
											color3 = (String) StaticConfig.getConfigCompany(screen.getUProfile(), "ta1023");
											color4 = (String) StaticConfig.getConfigCompany(screen.getUProfile(), "ta1024");
											color5 = (String) StaticConfig.getConfigCompany(screen.getUProfile(), "ta1025");
										} catch (Exception e) {}
									%>
									<!--tr>
										<td class="table-title" colspan="15">
											<div class="list-status">
												<span class="status-timeover"><%=color1%>,</span>      
												<span class="status-wait"><%=color2%>,</span>			
												<span class="status-notapprove"><%=color3%>,</span>		
												<span class="status-default"><%=color4%>,</span>		
												<span class="status-approve"><%=color5%></span>			
											</div>
										</td>
									</tr-->
									<tr>
										<td class="table-title" colspan="15"><label><%=holiday%></label></td>
									</tr>
								</tbody>
							</table>
							<div class="center">
								<a class="btn btn-primary" swlang code="SW012104" onclick="javascript:window.close()">Close</a>
							</div>
						</div>
					</div>
				</form>
			</div>
	</body>
</html>