<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.*,com.csc.library.utilities.*"%>
<%@page import="com.csc.library.session.*"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Random" %>
<%@page import="java.text.DecimalFormat" %>
<%@page import="com.csc.library.dwr.ManageOTIDS_dwr"%>
<%@page import="com.csc.library.database.StaticConfig" %>
<%@page import="com.csc.library.database.*"%>
<%@ include file="../CHECKPROFILE.jsp" %>
<%response.setHeader("X-XSS-Protection","0");%>
<jsp:useBean id="CREATEGROUPHELP" class="com.csc.library.system.Task" scope="page"/>


<%
	String helpReturn="";
	if( request.getParameter("__helpReturn") != null ){
		helpReturn=request.getParameter("__helpReturn");
	}

	CheckNull chkNull = new CheckNull();
	//String weekid = chkNull.chkNullString(request.getParameter("__weekid"));
	//String curotreq = chkNull.chkNullString(request.getParameter("__curotreq"));
	String step_id = chkNull.chkNullString(request.getParameter("__step_id"));

	CREATEGROUPHELP.setChannel(request, response);
	HelpEntry screen = (HelpEntry) CREATEGROUPHELP.process("HelpEntry","MTIME2_TEMP_IMPORTHELP");
	screen.setMaxLine(2000);
	screen.process();

	screen.referLangOff();

	/* get ot limit per week */
	HashMap hm = (HashMap)StaticConfig.globalData.get(screen.getUProfile().getDbName());
	String otperweek  = (String) hm.get("TAOTMAX");
	String isvalid = "0";	/* status for allow submit form */
	String isview = "0";

	String boss = request.getParameter("__boss");
	//out.print("<br>boss : "+boss);

//	String Subordinate = getSubordinate(boss,screen.getUProfile());
	String listEmp = getEmployeeid(boss,screen.getUProfile());
	//out.print("<br>Subordinate : "+Subordinate);

%>

<%!
		public String getSubordinate(String bossid,UProfile screenSingle){
			String data=",";
			try{
				String sql=" select * from MSUPERVISOR where SUPERVISOR like '%"+bossid+"%' ";
				String dbName = screenSingle.getDbName();
				String tableName = "mbranch";
				DataSet ds = new DataSet(sql,dbName,tableName);
				ds.setFetchAll(false);
				ds.initConnection(screenSingle);
				while(ds.next()){
					data += ds.getString("employeeid")+",";
				}	
			}catch(Exception e){
				return ",";
			}
			return data;
		}

		public String getEmployeeid(String empid,UProfile screenSingle){
			String data=",";
			try{
				String sql=" select * from memployee where status in ('A','S','T','V') ";
				String dbName = screenSingle.getDbName();
				String tableName = "memployee";
				DataSet ds = new DataSet(sql,dbName,tableName);
				ds.setFetchAll(false);
				ds.initConnection(screenSingle);
				while(ds.next()){
					data += ds.getString("employeeid")+",";
				}
			}catch(Exception e){
				return ",";
			}
			return data;
		}
%>

<HTML ng-app="myHR">
	<HEAD>
		<TITLE>myNOTE : Business Process Management Service</TITLE>
		<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
		
		<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/jquery-2.1.3.min.js"></script>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/MYNOTE_SCREEN.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/SCREEN.js'></SCRIPT>
        <script type='text/javascript' src='/hr/dwr/interface/SearchDWR.js'></script>
        <script type='text/javascript' src='/hr/dwr/engine.js'></script>
        <script type='text/javascript' src='/hr/dwr/util.js'></script>
        <script type='text/javascript' src='/hr/dwr/interface/Createemployeelist_dwr.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")%>');</SCRIPT>
		
		<script type="text/javascript">	
			
			var horizontal_offset="9px" //horizontal offset of hint box from anchor link

			/////No further editting needed

			var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
			var ie=document.all
			var ns6=document.getElementById&&!document.all

			function getposOffset(what, offsettype){
			var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
			var parentEl=what.offsetParent;
			while (parentEl!=null){
			totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
			parentEl=parentEl.offsetParent;
			}
			return totaloffset;
			}

			function iecompattest(){
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
			}

			function clearbrowseredge(obj, whichedge){
			var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
			if (whichedge=="rightedge"){
			var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
			dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
			if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
			}
			else{
			var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
			dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
			if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
			}
			return edgeoffset
			}

			function showhint(menucontents, obj, e, tipwidth){
			if ((ie||ns6) && document.getElementById("hintbox")){
			dropmenuobj=document.getElementById("hintbox")
			dropmenuobj.innerHTML=menucontents
			dropmenuobj.style.left=dropmenuobj.style.top=-500
			if (tipwidth!=""){
			dropmenuobj.widthobj=dropmenuobj.style
			dropmenuobj.widthobj.width=tipwidth
			}
			dropmenuobj.x=getposOffset(obj, "left")
			dropmenuobj.y=getposOffset(obj, "top")
			dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
			dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
			dropmenuobj.style.visibility="visible"
			obj.onmouseout=hidetip
			}
			}

			function hidetip(e){
			dropmenuobj.style.visibility="hidden"
			dropmenuobj.style.left="-500px"
			}

			function createhintbox(){
			var divblock=document.createElement("div")
			divblock.setAttribute("id", "hintbox")
			document.body.appendChild(divblock)
			}

			if (window.addEventListener)
			window.addEventListener("load", createhintbox, false)
			else if (window.attachEvent)
			window.attachEvent("onload", createhintbox)
			else if (document.getElementById)
			window.onload=createhintbox
		
			$(function(){
				var $table = $('.table');
				//Make a clone of our table
				var $fixedColumn = $table.clone().insertBefore($table).addClass('fixed-column');

				//Remove everything except for first column
				$fixedColumn.find('th:not(.fixed),td:not(.fixed)').remove();

				//Match the height of the rows to that of the original table's
				$fixedColumn.find('tr').each(function (i, elem) {
					//$(this).height($table.find('tr:eq(' + i + ')').height());
				});
			});
			
			

		</script>
		
		<style>
			.wd-sm{
				min-width:60px !important;
			}
			.wd-md{
				min-width:110px !important;
			}
			.wd-xs{
				min-width:160px !important;
			}
			.wd-day{
				min-width:20px !important;
			}
						
			.table-responsive>.fixed-column {
				position: absolute;
				display: inline-block;
				border-right: 1px solid #ddd;
				width: 50%;
			}
			th {
				height: 60px;
			}
			
		</style>
		
	</HEAD>
	<BODY>
	
		<form name="cscform" class="form-horizontal" method="post" action="CREATEGROUPHELP.jsp">
			<INPUT TYPE="hidden" NAME="__screen" VALUE="CREATEGROUPHELP">
			<INPUT TYPE="hidden" NAME="__cmd" VALUE="">
			<INPUT TYPE="hidden" NAME="__help" VALUE="">
			<INPUT TYPE="hidden" NAME="__goPage" VALUE="">
			<INPUT TYPE="hidden" NAME="__orderBy" VALUE="<%=request.getParameter("__orderBy")%>">
			<INPUT TYPE="hidden" NAME="__helpReturn" VALUE="<%=helpReturn%>">
			<INPUT TYPE="hidden" NAME="__helpName" VALUE="<%=request.getParameter("__helpName")%>">
			<INPUT TYPE="hidden" NAME="__pageCall" VALUE="<%=request.getParameter("__pageCall")%>">
			<INPUT TYPE="hidden" NAME="__fixCon" VALUE="<%=request.getParameter("__fixCon")%>">
            <INPUT TYPE="hidden" NAME="__GROUPNAME" VALUE="<%=request.getParameter("__GROUPNAME")%>">
            <INPUT TYPE="hidden" NAME="__weekid" VALUE="<%//=weekid%>">
			<input type="hidden" id="__isRed" name="__isRed" value="0">
			
			
			<div class="table-responsive">
				<table class="table table-head table-bordered table-title-left table-content-center">
					<thead>
						<tr>
							<th class="fixed wd-sm" swlang code='SW000193'>Seq</th> 
							<th class="fixed wd-xs" swlang code='SW000019'>Status</th>
							<th class="fixed wd-sm" swlang code='SW000800'>Month</th>
							<th class="fixed wd-sm" swlang code='SW000717'>Year</th>
							<th class="fixed wd-md" swlang code='SW000274'>Employee ID</th>
							<th class="fixed wd-xs" swlang code='SW002160'>Name Lastname</th>
							<th class="fixed wd-md" swlang code='SW000261'>Shift Pattern</th>
							<th class="fixed wd-sm" swlang code='SW008607'>shift</th>
							<th class="wd-day">1</th>
							<th class="wd-day">2</th>
							<th class="wd-day">3</th>
							<th class="wd-day">4</th>
							<th class="wd-day">5</th>
							<th class="wd-day">6</th>
							<th class="wd-day">7</th>
							<th class="wd-day">8</th>
							<th class="wd-day">9</th>
							<th class="wd-day">10</th>
							<th class="wd-day">11</th>
							<th class="wd-day">12</th>
							<th class="wd-day">13</th>
							<th class="wd-day">14</th>
							<th class="wd-day">15</th>
							<th class="wd-day">16</th>
							<th class="wd-day">17</th>
							<th class="wd-day">18</th>
							<th class="wd-day">19</th>
							<th class="wd-day">20</th>
							<th class="wd-day">21</th>
							<th class="wd-day">22</th>
							<th class="wd-day">23</th>
							<th class="wd-day">24</th>
							<th class="wd-day">25</th>
							<th class="wd-day">26</th>
							<th class="wd-day">27</th>
							<th class="wd-day">28</th>
							<th class="wd-day">29</th>
							<th class="wd-day">30</th>
							<th class="wd-day">31</th>
						</tr>
					</thead>
					<tbody>
						<%
							//String empid = "";
							//String rawdata = "";
							int num = 1;
							//String otreq = "";
							//DecimalFormat dc = new DecimalFormat("#0.00");

							ManageOTIDS_dwr mngot = new ManageOTIDS_dwr();
							//if(step_id.equals("0")){
								//mngot.addExtraReqOT(curotreq);
							//}
							mngot.setUProfile(screen.getUProfile());
							//		int isFound = -1;
							int isFoundEmp = -1;
							if(screen.getInquiry().recCount() > 0){
								while(screen.nextRec())	{
							//		isFound = Subordinate.indexOf(screen.getString("time0id"));
									isFoundEmp = listEmp.indexOf(screen.getString("employeeid"));
									//empid = screen.getString("employeeid");
									//otreq = mngot.getReqOTTotal(empid, weekid);
									//rawdata = mngot.getHint();

									/* if over limit set valid status to 1 (can't submit form) */
									/*if(Float.parseFloat(otreq) > Float.parseFloat(otperweek)) { 
										isvalid = "1";
									}*/
									String holiday = "";

									if(!screen.getString("status").equals("1") && !screen.getString("status").equals("5") && !screen.getString("status").equals("6")){
										holiday = "dayoff";
						%>
						<script type="text/javascript">document.cscform.__isRed.value = "1";</script>
						<%
							}
							String status = screen.getInquiry().getCurrentDbRecord().getSystemCode("status");
							if(screen.getString("status").equals("5") || screen.getString("status").equals("6")){
								status = "ผ่าน";
							}
							if(screen.getString("status").equals("8")){
								status = "ไม่สามารถแก้ไขเวลาของเดือนก่อนได้";
							}
							//	if(isFound==-1){
							//		status = "ไม่อยู่ในสายบังคับบัญชา";
							//	}
								if(isFoundEmp==-1){
									status = "ไม่มีรหัสพนักงานในระบบ";
								}
						%>
						<tr>
							<td class="<%=holiday%> fixed wd-sm"><%=num++%><%//=screen.getString("status")%></td>
							<td class="<%=holiday%> fixed wd-xs"><%=status%><%//=screen.getString("status")%></td> 
							<td class="<%=holiday%> fixed wd-sm"><%=screen.getString("monthid")%></td>
							<td class="<%=holiday%> fixed wd-sm"><%=screen.getString("yearid")%></td>
							<td class="<%=holiday%> fixed wd-md"><%=screen.getString("employeeid")%></td>
							<td class="<%=holiday%> fixed wd-xs"><%=screen.getString("MEMPLOYEE","FULLNAME")%></td>
							<td class="<%=holiday%> fixed wd-md"><%=screen.getString("time0id")%></td>
							<td class="<%=holiday%> fixed wd-sm"><%=screen.getString("groupid")%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time01"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time02"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time03"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time04"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time05"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time06"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time07"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time08"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time09"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time10"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time11"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time12"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time13"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time14"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time15"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time16"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time17"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time18"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time19"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time20"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time21"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time22"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time23"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time24"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time25"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time26"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time27"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time28"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time29"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time30"+screen.getString("groupid")))%></td>
							<td class="<%=holiday%> wd-day"><%=(screen.getString("time31"+screen.getString("groupid")))%></td>
						</tr>
						<%		
								}
							isview= "1";
							}else{
						%>
						<tr>
							<td class="table-title fixed" colspan="39" swlang code='SW012209'>Not Found Data</td>
						</tr>
						<%
							}
						%>
					</tbody>
				</table> 
			</div>
			<input type="hidden" id="__wf__view" name="__wf__view" value="<%=isview%>">
		</form>
	</BODY>
</HTML>