<!DOCTYPE html>
<%@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"  %>
<%@page import="com.csc.library.timeattendance.DayShift,com.csc.library.timeattendance.Shift,com.csc.library.timeattendance.WorkingShift"  %>
<%@ 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);
	CheckNull chk = new CheckNull();
	String groupID = chk.chkNullString(request.getParameter("__subgroupid"));

	String empList = "";

	EmvHelpEntry screen = (EmvHelpEntry) EMV.process("EmvHelpEntry", "MG_WORKINGTIMEHELP");
	screen.inq.refresh();
	//screen.nextRec();

	while (screen.inq.next()) {
		empList += "'"+screen.inq.getString("employeeid")+"',";
	}
	if (!empList.equals("")) {
		empList =empList.substring(0, empList.length()-1);
	}
	//out.println("TOTAL ====>"+empList);
	CscCalendar c = new CscCalendar();
	FormulaString fs = new FormulaString();
	DecimalFormat df = new DecimalFormat("0.00");
	DecimalFormat df2 = new DecimalFormat("00.00");


	DbInquiry inqEmpTime = new InitialInquiry(screen.getUProfile()).getDbInquiry();
	inqEmpTime.initMyTable("Ttime_current1", "", "");
	inqEmpTime.setColumn("*");


%>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myHR">
	<head>

		<title>Employee View</title>

		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

		<style>
			.th-mini{
				padding-left:1px !important;
				padding-right:1px !important;
				font-size:14px !important;
				max-width:3px !important;
			}
			.th-nor{
				font-size:14px !important;
			}
			.table-title-mini{
				min-width:120px !important;
			}
			td{
				font-size:12px !important;
			}
		</style>

	</head>
	<body>
		<div class="bg-com"></div>
		<jsp:include page="EMV_HEADMENU.jsp" flush="true" />

		<script>
			setLang("<%=screen.getUProfile().get("lang")%>");
			var swap = new swaplang();
            var titlename = swap.swap2String("SW012476");
			setPageTitle(titlename);

			function goHelp(helpName,inputName){
				with(document.cscform){
					var helpReturn="";
					var fcon=__fixCon.value;
					var sub_value = "";
					if (inputName=="__subgroupid") {
						__fixCon.value = "employeeid='<%=EMV.getUProfile().get("employeeid")%>'";
						helpReturn = inputName+":groupid,__desc:edesc"
						linkHelp_Return(helpName,helpReturn);
					}
					__fixCon.value = "";
				}
			}

			function getMonthName(m){
				with(document.cscform){
					var monthName = "";
					var engMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
					var thaiMonth = new Array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
					if (__language.value=='tha') {
						monthName = thaiMonth[parseInt(m)-1];
					} else monthName = engMonth[parseInt(m)-1];
					//alert(m+" "+engDate);
					document.write(monthName);
				}
			}

			function GoSearch(){
				with(document.cscform){
					if (__subgroupid.value=="") {
						__desc.value = "";
					}
					search();
				}
			}

			function alertData(emp, msg) {
				var message = msg.replace(/<br>/g,"\n");
				alert(emp+"\n"+message);
			}

			function pageDesc(empCode, empName){
				with(document.cscform){
					window.open("EMP_WORKINGTIME.jsp?__cmd="+
						"&__monthid="+__monthid.value+"&__yearid="+__yearid.value+
						"&__empID="+empCode+"&__empName="+empName,
						"Memployee","left=150,top=100,width=1100,height=500,toolbar=no,status=yes,scrollbars=yes,resizable=yes"
					);
					//submit();
				}
			}
		</script>

		<section>
			<div class="container csc-content">
				<form name="cscform" class="form-horizontal" method="post" action="MG_WORKINGTIME.jsp">
					<%=screen.InitialVariable() %>
					<input type="hidden" name="__cmd" value="">
					<input type="hidden" name="__screen"  value="MG_WORKINGTIME">
					<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">
					<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" >
					<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
					<script>initToolTips();</script>

					<div class="csc-block">
						<div class="center">
							<h2 class="csc-block-head" swlang code='SW012476'>Working Time Detail</h2>
						</div>

						<div class="form-horizontal">
							<div class="row">
								<div class="form-group">
									<div class="col-md-2 col-sm-2 col-xs-2"></div>
									<div class="col-md-2 col-sm-2 col-xs-2">
										<label class="control-label label-right" swlang code='SW002085'>Subordinate Group </label>
									</div>

									<div class="col-md-2 col-sm-2 col-xs-2">
										<% if (request.getParameter("__subgroupid")!=null) { %>
										<div class="input-group">
											<input class="form-control" name="__subgroupid" type="text" value="<%=request.getParameter("__subgroupid")%>"/>
											<a class="input-group-addon" href="javascript:goHelp('MSUBORDINATE_GRPHELP','__subgroupid')">
												<i class="fa fa-search"></i>
											</a>
										</div>
										<% } else { %>
										<div class="input-group">
											<input class="form-control" name="__subgroupid" type="text" />
											<a class="input-group-addon" href="javascript:goHelp('MSUBORDINATE_GRPHELP','__subgroupid')">
												<i class="fa fa-search"></i>
											</a>
										</div>
										<% } %>
									</div>
									<div class="col-md-3 col-sm-3 col-xs-3">
										<% if (request.getParameter("__desc")!=null) { %>
										<input class="form-control" name="__desc" type="text" value="<%=request.getParameter("__desc")%>"/>
										<% } else { %>
										<input class="form-control" name="__desc" type="text" />
										<% } %>
									</div>
								</div>
							</div>

							<div class="row">
								<div class="form-group">
									<div class="col-md-2 col-sm-2 col-xs-2"></div>
									<div class="col-md-2 col-sm-2 col-xs-2">
										<label class="control-label label-right" swlang code='SW000800'>Month </label>
									</div>

									<div class="col-md-2 col-sm-2 col-xs-2">
										<select class="form-control" name="__monthid">
											<%
												String m = "";
												if (request.getParameter("__monthid")!=null) {
													m = request.getParameter("__monthid");
												} else {
													m =c.getMM();
												}
											%>
											<option value="01" <% if (m.equals("01")) { %> selected <%}%> swlang code='SW012039'>January</option>
											<option value="02" <% if (m.equals("02")) { %> selected <%}%> swlang code='SW001840'>February</option>
											<option value="03" <% if (m.equals("03")) { %> selected <%}%> swlang code='SW001841'>March</option>
											<option value="04" <% if (m.equals("04")) { %> selected <%}%> swlang code='SW001842'>April</option>
											<option value="05" <% if (m.equals("05")) { %> selected <%}%> swlang code='SW001843'>May</option>
											<option value="06" <% if (m.equals("06")) { %> selected <%}%> swlang code='SW001844'>June</option>
											<option value="07" <% if (m.equals("07")) { %> selected <%}%> swlang code='SW001845'>July</option>
											<option value="08" <% if (m.equals("08")) { %> selected <%}%> swlang code='SW012040'>August</option>
											<option value="09" <% if (m.equals("09")) { %> selected <%}%> swlang code='SW001847'>September</option>
											<option value="10" <% if (m.equals("10")) { %> selected <%}%> swlang code='SW012041'>October</option>
											<option value="11" <% if (m.equals("11")) { %> selected <%}%> swlang code='SW011910'>November</option>
											<option value="12" <% if (m.equals("12")) { %> selected <%}%> swlang code='SW001850'>December</option>
										</select>
									</div>
									<div class="col-md-1 col-sm-1 col-xs-1">
										<label class="control-label label-right" swlang code='SW000717'>Year</label>
									</div>

									<div class="col-md-2 col-sm-2 col-xs-2">
										<% if (request.getParameter("__yearid")!=null) { %>
										<input class="form-control" type="text" name="__yearid" value="<%=request.getParameter("__yearid")%>" size="5" maxlength="4" onkeypress="chkInteger()" onkeyup="formatYear(this)" onblur="chkTrueYear(this)">
										<% } else { %>
										<input class="form-control" type="text" name="__yearid" value="<%=c.getYear()%>" size="5" maxlength="4" onkeypress="chkInteger()" onkeyup="formatYear(this)" onblur="chkTrueYear(this)">
										<% }%>
									</div>
								</div>
							</div>
							<div class="center">
								<a class="btn btn-primary" swlang code="SW003537" href="javascript:GoSearch();">Search</a>
							</div>
						</div>
					</div>

					<div class="table-responsive">
						<table class="table table-head table-hover table-bordered table-title-left table-content-center">
							<thead>
								<% if (!empList.equals("")) { %>
								<%
									String month = request.getParameter("__monthid");
									String year = request.getParameter("__yearid");
									if (month==null || year==null || month.equals("") && year.equals("")) {
										CscCalendar cDate = new CscCalendar();
										month = cDate.getMM();
										year = String.valueOf(cDate.getYear());
									}

									if (month!=null && year!=null && !month.equals("") && !year.equals("")) {
										//out.println(">>>"+group+" >>>"+month+" >>>"+year);

										CscCalendar c1 = new CscCalendar("01"+"-"+month+"-"+year);
										int dayCount = c1.getEndDateOfMonth();
										double col_width = 64/dayCount;
										CscCalendar c2 = new CscCalendar(dayCount+"-"+month+"-"+year);
									%>
									<div align = "right" swlang code='SW013247'>unit : HH.MM</div>
								<tr>
									<th class="th-nor" swlang code="SW007745">Name Surname</th>
									<%
										String day;
										for (int i=1;i<=dayCount;i++ ) {
											if(i<=9){
												day="&nbsp;"+i;
											}else{

												day=""+i+"";
											}
									%>
									<th class="th-mini"><%=day%></th>
									<%
										}
									%>
									<th swlang code="SW000301">OT</th>
									<th swlang code="SW001859">LE</th>
								</tr>
							</thead>
							<tbody>
								<%
									CscCalendar mycalen = new CscCalendar();
									/*if (!chk.chkNullString(request.getParameter("__yearid"),"").equalsIgnoreCase("")){
										int param_year = Integer.parseInt(request.getParameter("__yearid"));
										mycalen.setYear(param_year);
									}

									if (!chk.chkNullString(request.getParameter("__monthid"),"").equalsIgnoreCase("")){
										int param_month = Integer.parseInt(request.getParameter("__monthid"));
										mycalen.setMonth(param_month);
									}*/

									mycalen.setDate(01);
									DbInquiry inqEmp = new InitialInquiry(screen.getUProfile()).getDbInquiry();
									inqEmp.initMyTable("Memployee", "employeeid in ("+empList+") AND (status ='A' OR status='V' OR (status='Y' AND resigndate>='"+mycalen.getYYYYMMDD()+"'))", "employeeid");
									inqEmp.setColumn("employeeid,companyid,fname,lname,efname,elname,emp_prefix,emp_level,time0,bu1,bu2,bu3,bu4,bu5");
									inqEmp.refresh();
									while (inqEmp.next()) {
										CscTime ctLEAVE = new CscTime(0);
										CscTime ctOT = new CscTime(0);
										DbRecord rec = inqEmp.getCurrentDbRecord();
										MyHashMap hmDate = new MyHashMap();
										String filter = "employeeid='"+rec.getString("employeeid")+"' "+
											" and (dateid between '"+c1.getYYYYMMDD()+"' and '"+c2.getYYYYMMDD()+"')";
										inqEmpTime.setFilter(filter);
										inqEmpTime.refresh();
										while (inqEmpTime.next()) {
											DbRecord recTime = inqEmpTime.getCurrentDbRecord();
											CscCalendar d = new CscCalendar(recTime.getString("dateid"));
											MyHashMap hm = new MyHashMap();
											hm.put("LATE", df.format(recTime.getDouble("lt")));
											hm.put("LEAVE", df.format(recTime.getDouble("m_lv")));
											hm.put("OT", df.format(recTime.getDouble("ac_ot")));
																		hm.put("LEAVE_TYPE", recTime.getString("lv_ty"));
																		hm.put("DOCTYPE", recTime.getString("doctype"));
											hm.put("EVENTGRP", recTime.getString("eventgrp"));
											hmDate.put(d.getDDMMYYYY(), hm);
										} //End while (inqEmpTime.next())

										String emp = rec.getString("employeeid")+" : "+rec.getString("fullname");
								%>
								<tr>
									<td class="table-title table-title-mini"><a href="javascript:pageDesc('<%=rec.getString("employeeid")%>','<%=rec.getString("fullname")%>')"><%=emp%></a></td>
									<%
										for (int i=1;i<=dayCount;i++ ) {
											String sign = "";
											String holiday = "";
											CscCalendar cLoop = new CscCalendar(i+"-"+month+"-"+year);
											if (hmDate.get(cLoop.getDDMMYYYY())!=null) {
												MyHashMap hLoop = (MyHashMap) hmDate.get(cLoop.getDDMMYYYY());
												if (hLoop.getString("DOCTYPE").equals("A")) {
													sign += "L";
													ctLEAVE.add(hLoop.getDouble("LEAVE"));
												}

												if (hLoop.getDouble("OT")>0) {
													sign += "O";
													ctOT.add(hLoop.getDouble("OT"));
												}

												if (hLoop.getString("EVENTGRP").equals("J")) {
													sign = "A";
												}

												if (hLoop.getString("LEAVE_TYPE").equals("T")) {
													holiday = "present";
												}

												if (hLoop.getString("EVENTGRP").equals("H")) {
													holiday = "dayoff";

												} else if (hLoop.getString("EVENTGRP").equals("I")) {
													holiday = "annual-holiday";
												}
											} else {
												sign = "*";
											}//end if
									%>
									<td class="<%=holiday%>"><%=sign%></td>
									<%
										}
									%>
									<td><%=ctOT.getFloat()%></td>
									<td><%=ctLEAVE.getFloat()%></td>
								</tr>
								<%
									} //End while (inqEmp.next())
								%>
								<%
									} //End if (group!=null && month!=null && year!=null && !group.equals("") && !month.equals("") && !year.equals(""))
								%>
								<%
									} //End if (!empList.equals(""))
								%>

								<tr>
									<td class="table-title" colspan=35>
										* = <label swlang code="SW002194">NO DATA</label>,
										L = <label swlang code="SW002189">LEAVE</label>,
										A = <label swlang code="SW001880">ABSENT</label>,
										O = <label swlang code="SW002191">OVERTIME</label>,
										<span class="highlight-present"></span> &nbsp;= <label swlang code="SW002188">PRESENT</label>,
										<span class="highlight-dayoff"></span> &nbsp;= <label swlang code="SW011611">DAY OFF</label>,
										<span class="highlight-holiday"></span> &nbsp;= <label swlang code="SW002193">ANNUAL HOLIDAY</label>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</form>
			</div>
			<a href="#top" id="top-button">
				<i class="fa fa-angle-up"></i>
				<div class="top-word">Back to top</div>
			</a>
		</section>
		<jsp:include page="FOOTER.jsp" flush="true" />
	</body>
</html>