<%@page contentType="text/html; charset=TIS620" 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"  %>
<%@page import="com.csc.library.timeattendance.DayShift,com.csc.library.timeattendance.Shift,com.csc.library.timeattendance.WorkingShift"  %>
<%@page import="java.text.DecimalFormat"  %>
<% request.setCharacterEncoding("TIS620"); %>
<jsp:useBean id="EMV" class="com.csc.library.system.Task" scope="page" />
<jsp:setProperty name="EMV" property="appname" value="empview" />
<%
	CheckNull chk = new CheckNull();
	String emps = chk.chkNullString(request.getParameter("__empid"));
	
	EMV.setChannel(request, response);	
	HelpEntry screen = (HelpEntry) EMV.process("HelpEntry", "PI_SWIPETIMEHELP"); 

	screen.inq.setFilter("employeeid = '"+emps+"' ");
	screen.inq.refresh();	
	screen.nextRec();
	screen.referLangOn();
	CscCalendar cs=new CscCalendar();
	FormulaString fs = new FormulaString();
	DecimalFormat df = new DecimalFormat("0.00");
	DecimalFormat df2 = new DecimalFormat("00.00");

	String empID = EMV.getUProfile().getEmvEmpId();
	DbInquiry inqSwipeTime = new InitialInquiry(screen.getUProfile()).getDbInquiry();
	inqSwipeTime.initMyTable("Ttimetemp", "", "employeeid,swipedate,swipetime");
	inqSwipeTime.setColumn("*");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="../Templates/template-emv-main.dwt.jsp" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Employee View</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=TIS620" />
<!-- InstanceBeginEditable name="head" -->
<!-- Begin CSS Links -->
<link rel="stylesheet" type="text/css" href="../CSS/DDMENU.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_LAYOUT.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_DEFAULT.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_LAYOUT_TWO.css" />
<link rel="stylesheet" type="text/css" href="../CSS/EMV_TEXT.css" />
<style type="text/css">
<!--
font.holiday {
	color: #FF00FF;
	}
font.week {
	color: #FF0000;
	}
-->
</style>
<!-- End CSS Links -->
<!-- Begin Scripts -->
<!-- Begin script for Dropdown Menu -->
<!-- DO NOT EDIT -->
<script language="JavaScript" type="text/javascript" src="../JS/EVENTS.js"></script>
<script language="JavaScript" type="text/javascript" src="../JS/DDMENU.js"></script>
<!--[if lt IE 7]><script language="JavaScript" type="text/javascript" src="../JS/IEHOVER-FIX.js"></script><![endif]-->
<!-- DO NOT EDIT -->
<!-- End script for Dropdown Menu -->
<script language="JavaScript" type="text/javascript" src="../JS/UTILITIES.js"></script>
<script language="JavaScript" type="text/javascript" src="../JS/ACTIVE_OBJECT.js"></script>
<script language="JavaScript" type="text/javascript" src="../JS/SCREEN.js"></script>
<script language="JavaScript" type="text/javascript" src="../JS/DATEINPUT.js"></script>
<script language="JavaScript" type="text/javascript" src="../JS/VIEWCALENDAR.js"></script>
<script language="JavaScript">setLang('<%=screen.getUProfile().get("lang")%>');</script>

<!-- End Scripts -->
<!-- Begin Head -->
<style type="text/css">
#header {
 	background: #FFFFFF ;
}
</style>
<!-- End Head -->
<!-- InstanceEndEditable -->
</head>
<body>

    <!-- Begin Main Content -->
      <div class="content">
      <form name="cscform" method="post" action="PI_SWIPETIME.jsp">
        <input type="hidden" name="__cmd" value="">
        <input type="hidden" name="__screen"  value="PI_SWIPETIME"> 
        <input type="hidden" name="__help" value="">
        <input type="hidden" name="__helpReturn" value="">
        <input type="hidden" name="__helpName" value="">
        <input type="hidden" name="__pageCall" >
        <input type="hidden" name="__referPage" value="">
        <input type="hidden" name="__calendar">
        <script language="javascript">getInputFormatDate();</script>
        <input type="hidden" name="__companyid"  value="<%=screen.getUProfile().get("companyid")%>">
        <input type="hidden" name="__fixCon"  > 
        <input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>">
        <input type="hidden" name="__childFilter" >
        <input type="hidden" name="__empID" value="<%=screen.getString("employeeid")%>"> 
        <input type="hidden" name="__empName" value="<%=screen.getString("fullname")%>">   
        <input type="hidden" name="__empid"  value="<%=emps%>" > 


        <div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
		<script language="javascript">initToolTips();</script> 
          <div class="content-box2">
            <div class="content-header"><h2><script language="javascript">swapLang('Employee SwipeTime')</script></h2></div>
            	
                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table-search-condition">
                <tr>
               	  <td class="column-input">
                    &nbsp;<strong><script language="javascript">swapLang('Date')</script></strong>
					<% if (request.getParameter("date_start")==null) { %>									 
				  		<input name="date_start" type="text" value="<%="01-"+cs.getMM()+"-"+cs.getYear()%>" size="9" maxlength="10" onKeyup = "formatDate(this)" onBlur = "chkInputDate2(this,date_end)" onKeypress = "chkInteger()" onMouseOver="toolTip('วันเริ่มต้น(DDMMYYYY)')" onMouseOut="toolTip()">&nbsp;
				  	<% } else {%>
				   		<input name="date_start" type="text" value="<%=request.getParameter("date_start")%>" size="9" maxlength="10" onKeyup = "formatDate(this)" onBlur = "chkInputDate2(this,date_end)" onKeypress = "chkInteger()" onMouseOver="toolTip('วันเริ่มต้น(DDMMYYYY)')" onMouseOut="toolTip()">&nbsp;
<% }%>
				  		<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('calendar1','','../IMAGES/EMPVIEW/ICON_CALENDAR.gif',1)">
				  		<img src="../IMAGES/EMPVIEW/ICON_CALENDAR.gif" name="calendar1" width="20" height="20" border="0" align="absmiddle" onClick="viewCal('date_start')" alt="Calendar"></a>&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp; 
					<% if (request.getParameter("date_end")==null) { %>
				  		<input name="date_end" type="text" value="<%=cs.getDDMMYYYY()%>" size="9" maxlength="10" onKeyup = "formatDate(this)" onBlur = "chkInputDate2(date_start,this)" onKeypress = "chkInteger()" onMouseOver="toolTip('วันสิ้นสุด(DDMMYYYY)')" onMouseOut="toolTip()">&nbsp;
				   	<% } else {%>
				   		<input name="date_end" type="text" value="<%=request.getParameter("date_end")%>" size="9" maxlength="10" onKeyup = "formatDate(this)" onBlur = "chkInputDate2(date_start,this)" onKeypress = "chkInteger()" onMouseOver="toolTip('วันสิ้นสุด(DDMMYYYY)')" onMouseOut="toolTip()">&nbsp;
          <% }%>
			  		  <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('calendar2','','../IMAGES/EMPVIEW/ICON_CALENDAR.gif',1)">
			  		  <img src="../IMAGES/EMPVIEW/ICON_CALENDAR.gif" name="calendar2" width="20" height="20" border="0" align="absmiddle" onClick="viewCal('date_end')" alt="Calendar"></a>&nbsp;&nbsp;&nbsp;
				  	<a href="javascript:search();"><img src="../IMAGES/EMPVIEW/BUTTON/SEARCH.gif" width="60" height="23" border="0" align="absmiddle"></a>                    </td>
                </tr>
                </table>
                 
            	<table width="100%" border="0" cellpadding="0" cellspacing="1" class="table-content-list" >
<tr>
                	<td width="10%" class="column-header"><script language="javascript">swapLang('Date')</script></td>
                    <td width="7%" class="column-header"><script language="javascript">swapLang('Day')</script></td>
                    <td width="31%" class="column-header"><script language="javascript">swapLang('Working Time')</script></td>
                    <td width="30%" class="column-header"><script language="javascript">swapLang('SwipeTime')</script></td>
                    <td width="15%" class="column-header"><script language="javascript">swapLang('Day Type')</script></td>
                    <td width="7%" class="column-header" nowrap><script language="javascript">swapLang('Total')</script><br>(<script language="javascript">swapLang('HH MM')</script>)</td>
              	</tr>
                <%
					if (!screen.getDataLabel("employeeid").equals("")) {
						//out.println("employeeid -->> "+screen.getDataLabel("employeeid"));
						//out.println("if test  emp-->> "+screen.inq.getCurrentDbRecord().getParam().get("ws"));
						if (screen.inq.getCurrentDbRecord().getParam().get("ws")!=null) {
							WorkingShift pws = (WorkingShift) screen.inq.getCurrentDbRecord().getParam().get("ws");
							//out.println("-->> "+pws);
							HashMap hm = new HashMap();
							try {
								DbInquiry inq = new InitialInquiry(screen.getUProfile()).getDbInquiry();
								inq.setSchemaName(screen.getUProfile().getSchemaName());
								inq.initMyTable("Meventgrp", "", "");
								inq.setColumn("*");
								inq.refresh();
								inq.referLangOn();
								while (inq.next()) {
									DbRecord rec = inq.getCurrentDbRecord();
									hm.put(rec.getString("eventgrpid"), rec.getString("tdesc"));								
								}
							} catch (Exception e) {}
							
							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", "time0id='"+screen.getDataLabel("time0")+"'", "");
								inqTime.setColumn("*");
								inqTime.putChild(inqHoliday);								
								inqTime.refresh();
								inqTime.referLangOn();
								while (inqTime.next()) {
									DbRecord rec = inqTime.getCurrentDbRecord();
									DbInquiry child = (DbInquiry) inqTime.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);
				%>
                <%
							//ทำการหาข้อมูลการรูดบัตร
							CscCalendar c1 = new CscCalendar();
							CscCalendar c2 = new CscCalendar();
							if (request.getParameter("date_start")==null && request.getParameter("date_end")==null) { 
								c1 = new CscCalendar("01-"+cs.getMM()+"-"+cs.getYear());
								c1.decMonth(1);
								c2 = new CscCalendar(cs.getDDMMYYYY());
							} else {
								c1 = new CscCalendar(request.getParameter("date_start"));
								c2 = new CscCalendar(request.getParameter("date_end"));
							}
							MyHashMap hmSwipeTime = new MyHashMap();
							int count = 0;
							String tmpDate = "", swipeTime = "";
							inqSwipeTime.setFilter("employeeid='"+emps+"' and (swipedate between '"+c1.getYYYYMMDD()+"' and '"+c2.getYYYYMMDD()+"')");
							System.out.print("-->" + inqSwipeTime.getFilter());
							inqSwipeTime.refresh();
							while (inqSwipeTime.next()) {
								if (count==0 || tmpDate.equals(inqSwipeTime.getString("swipedate"))) {
									swipeTime += " , "+df.format(inqSwipeTime.getCurrentDbRecord().getDouble("swipetime"));
								} else {
									if (!tmpDate.equals("") && !swipeTime.equals("")) {
										CscCalendar d = new CscCalendar(tmpDate);
										hmSwipeTime.put(d.getDDMMYYYY(), swipeTime.substring(3, swipeTime.length()));
										swipeTime = " , "+df.format(inqSwipeTime.getCurrentDbRecord().getDouble("swipetime"));
									}
								}
								count++;
								tmpDate = inqSwipeTime.getString("swipedate");
							}
							if (!tmpDate.equals("") && !swipeTime.equals("")) {
								CscCalendar d = new CscCalendar(tmpDate);
								hmSwipeTime.put(d.getDDMMYYYY(), swipeTime.substring(3, swipeTime.length()));
							}				
				%>
				<%
						CscTime ot = new CscTime();
						CscTime leave = new CscTime();						
						CscTime working = new CscTime();
						CscTime working_total = new CscTime();
						String cFont = "";
						String tmp = "";
						int rows = 1;
						for (Iterator IT = pws.keySet().iterator(); IT.hasNext(); ) {
							String key = (String) IT.next();
							DayShift dShift = (DayShift) pws.get(key);
							rows = dShift.size();
							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";
								}

								if (sh.getDocType().equals("O") || sh.getDocType().equals("B") || sh.getDocType().equals("OM")) { //ทำการบวกชม ที่ทำโอที
									ot.add(sh.getAp_ot());
									working_total.add(sh.getAp_ot());
								} else if (sh.getDocType().equals("A") || sh.getDocType().equals("S")) { //ทำการบวกชม ที่ลา
									leave.add(sh.getLv());
								} else { 
									working.add(sh.getHour_d());
									working_total.add(sh.getHour_d());
								}
							%>
							<tr> 
								<%
									String date = "";
									if (tmp.equals(sh.getShiftDate().getDDMMYYYY())) {
										date = "";
									} else date = sh.getShiftDate().getDDMMYYYY();
								%>
								<% if (rows>1 && !date.equals("")) { %>
									<td class="column-text-center" rowspan="<%=rows%>"><font class="<%=cFont%>"><%=date%></font></td>
								<% } else if (rows==1) { %>
									<td class="column-text-center" rowspan="<%=rows%>"><font class="<%=cFont%>"><%=date%></font></td>
								<% } %>

								<%
									String day = "";
									if (tmp.equals(sh.getShiftDate().getDDMMYYYY())) {
										day = "";
									} else {
										if (((String) screen.getUProfile().get("lang")).equalsIgnoreCase("THA")) { //แสดงวันจันทร์ , อังคาร, พุธ เป็นต้น
											day = sh.getShiftDate().getDOWTHI(); 
										} else day = sh.getShiftDate().getDOWENG(); 
									}
								%>
								<% if (rows>1 && !date.equals("")) { %>
									<td class="column-text-center" rowspan="<%=rows%>"><font class="<%=cFont%>"><%=day%></font></td>
								<% } else if (rows==1) { %>
									<td class="column-text-center" rowspan="<%=rows%>"><font class="<%=cFont%>"><%=day%></font></td>
								<% } %>

								<td class="column-text-center"><font class="<%=cFont%>">
									<%=sh.getResult_c_dt_in().getDDMMYYYY()+" - "+df2.format(sh.getResult_c_dt_in().getCSCTime())+ " : "+
										sh.getResult_c_dt_out().getDDMMYYYY()+" - "+df2.format(sh.getResult_c_dt_out().getCSCTime())%>
								</font></td>
                                
                                <%	
									String txtSwipeTime = "";
									if (hmSwipeTime.containsKey(sh.getShiftDate().getDDMMYYYY())) {
										txtSwipeTime = hmSwipeTime.getString(sh.getShiftDate().getDDMMYYYY());
									} 
								%>
								<% if (rows>1 && !date.equals("")) { %>
									<td class="column-text" rowspan="<%=rows%>"><font class="<%=cFont%>"><%=txtSwipeTime%></font></td>
								<% } else if (rows==1) { %>
									<td class="column-text" rowspan="<%=rows%>"><font class="<%=cFont%>"><%=txtSwipeTime%></font></td>
			          <% } %>
                                
								<td class="column-text-center"><font class="<%=cFont%>">
									<%
										//out.println(sh.getEventGroup());
										if (sh.getTR_Type().indexOf("T")>-1 && (!sh.getDocType().equals("C") && !sh.getDocType().equals("E"))) {
											out.println();
										} else {
											if (sh.getEventGroup().equalsIgnoreCase("T"))	 { //ถ้าเป็นวันปกติ (T) ให้แสดงช่องว่าง
											out.println();
											} else	{ 
												String lv_type = (String) hm.get(sh.getEventGroup());
												if (lv_type==null ||  lv_type.equals("null"))  {
													out.println();
												} else { 
													if (sh.getEventGroup().equals("I")) {
														if (hmHoliday.get(sh.getShiftDate().getDDMMYYYY())!=null) {
															out.println(hmHoliday.get(sh.getShiftDate().getDDMMYYYY()));
														} else out.println(lv_type);
													} else out.println(lv_type);
												}
											}
										}
									%>
								</font></td>
								<td class="column-text-center"><font class="<%=cFont%>">
                                	<%
										if (sh.getHour_d()>0) {
											out.println(df.format(sh.getHour_d()));	
										} else if (sh.getLv()==0 && sh.getAp_ot()==0) { //ถ้า ชม ลา หรือ ชม โอที = 0 ให้แสดงช่องว่าง
											out.println();
										} else if (sh.getLv()>0) {
											out.println(df.format(sh.getLv()));	
										} else if (sh.getAp_ot()>0) {
											out.println(df.format(sh.getAp_ot()));	
										}
									%>
									<%//out.println(sh.getEventGroup());%>
									<%//out.println(sh.getDocType());%>
								</font></td>								
							 </tr>
							<%
									tmp = sh.getShiftDate().getDDMMYYYY();
							} //End for (Iterator IT1 = dShift.keySet().iterator(); IT1.hasNext(); )
						} //End for (Iterator IT = pws.keySet().iterator(); IT.hasNext(); )
						%>
                          <tr> 
							<td class="column-header-right" colspan="5"><script language="javascript">swapLang('Work Total')</script></td>
							<td class="column-header"><%=df.format(working.getFloat())%></td>
						  </tr>	
						 <tr> 
							<td class="column-header-right" colspan="5"><script language="javascript">swapLang('OT Total')</script></td>
							<td class="column-header"><%=df.format(ot.getFloat())%></td>
						  </tr>
						  <tr> 
							<td class="column-header-right" colspan="5"><script language="javascript">swapLang('Leave Total')</script></td>
							<td class="column-header"><%=df.format(leave.getFloat())%></td>
						  </tr>
                          <tr> 
							<td class="column-header-right" colspan="5"><script language="javascript">swapLang('Working Total')</script></td>
							<td class="column-header"><%=df.format(working_total.getFloat())%></td>
						  </tr>
                <%		
						} //End if (screen.inq.getCurrentDbRecord().getParam().get("ws")!=null)
					} //End if (!screen.getDataLabel("employeeid").equals("")) 
				%>     
            	</table>
        </form>
            <div class="content-footer"><img src="../IMAGES/SPACER.gif" width="3" height="3" /></div>
          </div>   
         
     
      <!-- End Main Content -->
      <!-- InstanceEndEditable -->    </div>
  </div>
  <!--<div id="footer"> InstanceBeginEditable name="footer" -->
  <!-- InstanceEndEditable  </div> -->
</div>
</body>
<!-- InstanceEnd --></html>