TAR11127_EXP.jsp 15.7 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.*,com.csc.library.system.*,com.csc.library.session.*,com.csc.library.utilities.*,java.text.DecimalFormat,com.csc.library.database.*,com.csc.library.timeattendance.*,com.csc.library.databean.*"%>
<%@page import="java.util.*,java.io.*,java.sql.*"%>
<%@ include file="../CHECKPROFILE.jsp" %>
<%
	response.setHeader("Cache-Control","must-revalidate");
	response.setContentType("application/vnd.ms-excel; UTF-8");
	response.setHeader("Content-Disposition", "inline; filename=" + "export.xls");
	CheckNull chk = new CheckNull();
	CscCalendar c = new CscCalendar();
		
	DecimalFormat dmfm1 = new DecimalFormat("#,##0.00");
	DecimalFormat dmfm2 = new DecimalFormat("#,###");

	CscCalendar now = new CscCalendar();
	String cmd = chk.chkNullString(request.getParameter("__cmd"));
	String time0 = chk.chkNullString(request.getParameter("time0"));
	String start_date = chk.chkNullString(request.getParameter("startdate"),now.getDDMMYYYY());
	String end_date = chk.chkNullString(request.getParameter("enddate"),now.getDDMMYYYY());
	CscCalendar start_date2 = new CscCalendar(start_date);
	CscCalendar end_date2 = new CscCalendar(end_date);
	String f_start_date = start_date2.getYYYYMMDD();
	String f_end_date =  end_date2.getYYYYMMDD();
	String bu1id =chk.chkNullString(request.getParameter("__bu1"));
	String bu2id =chk.chkNullString(request.getParameter("__bu2"));
	String bu3id =chk.chkNullString(request.getParameter("__bu3"));
	String bu4id =chk.chkNullString(request.getParameter("__bu4"));
	String bu5id =chk.chkNullString(request.getParameter("__bu5"));
	String shift =chk.chkNullString(request.getParameter("__shift"));
	String type1 =chk.chkNullString(request.getParameter("type1"));
	String type2 =chk.chkNullString(request.getParameter("type2"));
	String type3 =chk.chkNullString(request.getParameter("type3"));
	String employeeid =chk.chkNullString(request.getParameter("__employeeid"));
	String emptype =chk.chkNullString(request.getParameter("__emp_type"));
	String branch =chk.chkNullString(request.getParameter("__branch"));
	String salatype =chk.chkNullString(request.getParameter("__salatype"));
	String filter = "1=1";
	String view = chk.chkNullString(request.getParameter("__view"));
	if( !bu1id.equals("") ){
		 filter += " and me.BU1 = '"+ bu1id+ "'";
	}
	if( !bu2id.equals("") ){
		 filter += " and me.BU2 = '"+ bu2id+ "'";
	}
	if( !bu3id.equals("") ){
		 filter += " and me.BU3 = '"+ bu3id+ "'";
	}
	if( !bu4id.equals("") ){
		 filter += " and me.BU4 = '"+ bu4id+ "'";
	}
	if( !bu5id.equals("") ){
		 filter += " and me.BU5 = '"+ bu5id+ "'";
	}
	if( !shift.equals("") ){
		 filter += " and t1.TIME0ID = '"+ shift+ "'";
	}
	if( !employeeid.equals("") ){
		 filter += " and t1.employeeid = '"+ employeeid+ "'";
	}
	if( !emptype.equals("") ){
		 filter += " and me.emp_type = '"+ emptype+ "'";
	}
	if( !branch.equals("") ){
		 filter += " and t1.branch = '"+ branch+ "'";
	}
	if( !salatype.equals("") ){
		 filter += " and t1.salatype = '"+ salatype+ "'";
	}
	if( type1.equals("1")&&type2.equals("")&&type3.equals("") ){
		 filter += " and t1.EVENTGRP='T'";
	}else if( type1.equals("")&&type2.equals("1")&&type3.equals("") ){
		 filter += " and t1.EVENTGRP='J'";
	}else if( type1.equals("")&&type2.equals("")&&type3.equals("1") ){
		 filter += " and t1.EVENTGRP in ('ANL','LML','MLL','SCL')";
	}else if( type1.equals("1")&&type2.equals("1")&&type3.equals("") ){
		 filter += " and t1.EVENTGRP in ('T','J')";
	}else if( type1.equals("1")&&type2.equals("")&&type3.equals("1") ){
		 filter += " and t1.EVENTGRP in ('T','ANL','LML','MLL','SCL')";
	}else if( type1.equals("")&&type2.equals("1")&&type3.equals("1") ){
		 filter += " and t1.EVENTGRP in ('J','ANL','LML','MLL','SCL')";
	}else if( type1.equals("1")&&type2.equals("1")&&type3.equals("1") ){
		 filter += " and t1.EVENTGRP in ('T','J','ANL','LML','MLL','SCL')";
	}
	filter += " and t1.DATEID between '" + f_start_date + "' and '" +f_end_date+"'";
%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- <link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<link href="../CSS/bootstrap.css" rel="stylesheet"> -->
<script src="../JS/jquery-1.11.3.min.js"></script>
 <script src="../JS/bootstrap.min.js"></script>
<script language="JavaScript" src="../JS/SCREEN.js"></script>
<SCRIPT TYPE='text/JavaScript' SRC='../JS/DATEINPUT.js'></SCRIPT>
<SCRIPT TYPE='text/JavaScript' SRC='../JS/VIEWCALENDAR.js'></SCRIPT>
<script language="javascript">setLang('<%=uprofile.get("lang")%>');</script>
<script language="JavaScript" type="text/JavaScript">

function goHelp(helpName,inputName){
	var helpReturn;
	 if(inputName=="__bu1" ){
		 	
		helpReturn="__bu1:bu1id,__bu1_desc:tdesc";
		
	}else if(inputName=="__bu2" ){
	
        helpReturn="__bu2:bu2id,__bu2_desc:tdesc";
	}else if(inputName=="__bu3" ){
		helpReturn="__bu3:bu3id,__bu3_desc:tdesc";
	}else if(inputName=="__bu4" ){
		helpReturn="__bu4:bu4id,__bu4_desc:tdesc";
	}else if(inputName=="__bu5" ){
		helpReturn="__bu5:bu5id,__bu5_desc:tdesc";
	}else if(inputName=="__employeeid" ){
		helpReturn="__employeeid:employeeid,__employeeid_desc:fullname";
	}else if(inputName=="__shift" ){
		helpReturn="__shift:time0id,__shift_desc:tdesc";
	}
	linkHelp_Return(helpName, helpReturn);
}

function GoExport(){
	with(document.cscform){
	//alert(__filter.value);
	var param = "PSRN001_EXP.jsp?allbranch="+allbranch.value+"&branch="+branch.value+"&startdate="+startdate.value+"&enddate="+enddate.value;
	window.open(param);

	}
}

function GoPrint(){
	with(document.cscform){
	var param = "PSRN001_PDF.jsp?allbranch="+allbranch.value+"&branch="+branch.value+"&startdate="+startdate.value+"&enddate="+enddate.value;
	window.open(param);
		submit();
	}
}
function GoView(){
	with(document.cscform){
		__view.value = "1"
		submit();
	}
}

function checkBox(){
	with(document.cscform){
		if(allbranch.checked==true){
			allbranch.value=" and BRANCH in (select branchid from MBRANCH) ";
			//alert(allbranch.value);
		}else{
			allbranch.value="";
			//alert(allbranch.value);
		}
	}
}

$(function() {
	$('#export').click(function() {
		GoExport();
	});
	
	$('#preview').click(function() {
		 GoView();
	});
	
	$('#print').click(function() {
		GoPrint();
	});
	
	});



</script>
<style>
	.table-condensed > tbody > tr > td {
		padding: 4px;
		border: 0px solid #ddd;
	}
	img[height="20"] {
		padding: 0px;
	}
	.table-bordered th {
		color: #ffffff;
		text-align: center;
		vertical-align: middle;
		background-color: #336699;
	}
	.eiei {
		overflow: scroll;
		height: 100%;
	}
</style>
</head>
<body leftmargin="0" topmargin="0">
	<form name="cscform" method="post">
		<input type="hidden" name="__language" value="<%=uprofile.get("lang")%>%>">
		<input type="hidden" name="__fixCon" value="">
		<input type="hidden" name="__cmd" value="">
		<input type="hidden" name="__view" value="">
		<input type="hidden" name="__screen" value="TAR11127">
		<input type="hidden" name="__goPage" value ="">
		<input type="hidden" name="__employeeid" value="">
		<input type="hidden" name="__companyid" value="<%=uprofile.get("companyid")%>">
		<input type="hidden" name="__orderBy" value="">
		<input type="hidden" name="__empview" value="">
		<input type="hidden" name="__calendar" value="">
		<input type="hidden" name="__filter" value="">
		<input type="hidden" name="__shift" value="<%=chk.chkNullString(request.getParameter("__shift"))%>">
		<input type="hidden" name="__bu1" value="<%=chk.chkNullString(request.getParameter("__bu1"))%>">
		<input type="hidden" name="__bu2" value="<%=chk.chkNullString(request.getParameter("__bu2"))%>">
		<input type="hidden" name="__bu3" value="<%=chk.chkNullString(request.getParameter("__bu3"))%>">
		<input type="hidden" name="__bu4" value="<%=chk.chkNullString(request.getParameter("__bu4"))%>">
		<input type="hidden" name="__bu5" value="<%=chk.chkNullString(request.getParameter("__bu5"))%>">
		<input type="hidden" name="startdate" value="<%=chk.chkNullString(request.getParameter("__startdate"))%>">
		<input type="hidden" name="enddate" value="<%=chk.chkNullString(request.getParameter("enddate"))%>">
		<input type="hidden" name="type1" value="<%=chk.chkNullString(request.getParameter("type1"))%>">
		<input type="hidden" name="type2" value="<%=chk.chkNullString(request.getParameter("type2"))%>">
		<input type="hidden" name="type3" value="<%=chk.chkNullString(request.getParameter("type3"))%>">
		<script language="javascript">getInputFormatDate();</script>

		
		<%
		String temp ="";
		String sql = "select  me.BU3 as bu3id, b3.EDESC as bu3 from TTIME_CURRENT1 t1 left join MEMPLOYEE me on t1.EMPLOYEEID=me.EMPLOYEEID left join MPREFIX mpr on me.EMP_PREFIX=mpr.PREFIXID left join MBU3 b3 on me.BU3 = b3.BU3ID left join MBU4 b4 on me.BU4 = b4.BU4ID left join MEVENTGRP1 mev on t1.EVENTGRP = mev.EVENTGRPID where "+ filter +" group by   me.BU3,b3.EDESC";
		//out.print(filter);
		try{
			DataSet ds = new DataSet(sql,uprofile.get("dbname"),"TTIME_CURRENT1");
			ds.initConnection(uprofile);
			while (ds.next()) {
				String bu3dedc = chk.chkNullString(ds.getString("bu3"));
				String bu3 = ds.getString("bu3id");
		%>
				<br>
				<div align="left"><b>แผนก&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=bu3dedc%><b></div>
				<table border="1" >
					<thead>
						<tr>
							<th style="vertical-align: middle;"><div style="width: 50px;"></div></th>
							<th style="vertical-align: middle;"><div style="width: 100px;">รหัสพนักงาน</div></th>
							<th style="vertical-align: middle;"><div style="width: 400px;">ชื่อ - นามสกุล</div></th>
							<th style="vertical-align: middle;"><div style="width: 600px;">ชื่อหน่วยงาน</div></th>
							<th style="vertical-align: middle;"><div style="width: 100px;">วันที่</div></th>
							<th style="vertical-align: middle;"><div style="width: 100px;">กะการทำงาน/<div></th>
							<th style="vertical-align: middle;"><div style="width: 100px;">เวลารูดเข้า</div></th>
							<th style="vertical-align: middle;"><div style="width: 100px;">สถานะ</div></th>
							<th style="vertical-align: middle;"><div style="width: 100px;">ลา</div></th>
							<th style="vertical-align: middle;"><div style="width: 200px;">หมายเหตุ</div></th>
						</tr>
					</thead>
					<tbody>
		<%
			int no = 1;
			int countEmp = 0;
			int countWork = 0;
			int countLeave = 0;
			String tempEmp ="";
			String tempWork ="";
			String tempLeave ="";
			String sql2 = "select me.employeeid,mpr.TDESC+me.FNAME+' '+me.LNAME as name,b3.EDESC as bu3,b4.EDESC as bu4,t1.DATEID,t1.TIME0ID,t1.M_TM_BG,t1.M_TM_EN,case t1.LV_TY when 'J' then 'ขาดงาน' when 'T' then  'ทำงาน' else '' end as STATUS,case t1.EVENTGRP when 'J' then '' when 'H' then '' when 'T' then '' else mev.TDESC end as EVENTGRP,t1.REMARK,me.time0 as 'time0' from TTIME_CURRENT1 t1 left join MEMPLOYEE me on t1.EMPLOYEEID=me.EMPLOYEEID left join MPREFIX mpr on me.EMP_PREFIX=mpr.PREFIXID left join MBU3 b3 on me.BU3 = b3.BU3ID left join MBU4 b4 on me.BU4 = b4.BU4ID left join MEVENTGRP1 mev on t1.EVENTGRP = mev.EVENTGRPID where me.bu3='"+bu3+"' and "+ filter +" order by me.bu3,me.bu4,t1.employeeid,t1.dateid,me.time0";
			//out.print(sql2);
				DataSet ds2 = new DataSet(sql2,uprofile.get("dbname"),"Memployee");
				ds2.initConnection(uprofile);
				while (ds2.next()) {
					Shift shift1 = new Shift();
					if(!tempEmp.equals(chk.chkNullString(ds2.getString("name")))){
						tempEmp = chk.chkNullString(ds2.getString("name"));
						countEmp++;
					}
					if(chk.chkNullString(ds2.getString("status")).equals("ทำงาน")&&!tempWork.equals(chk.chkNullString(ds2.getString("name")))){
						tempWork = chk.chkNullString(ds2.getString("name"));
						countWork++;
					}else if(chk.chkNullString(ds2.getString("status")).equals("ขาดงาน")&&!tempLeave.equals(chk.chkNullString(ds2.getString("name")))){
						tempLeave = chk.chkNullString(ds2.getString("name"));
						countLeave++;
					}
					CscCalendar date1 = new CscCalendar(chk.chkNullString(ds2.getString("dateid"))); 
					String date2 = date1.getDD()+"/"+date1.getMM()+"/"+date1.getYear();
					shift1 = getShift(date1,uprofile,chk.chkNullString(ds2.getString("time0")),chk.chkNullString(ds2.getString("employeeid")));
					String getRemark = getChShift(chk.chkNullString(ds2.getString("dateid")),uprofile,chk.chkNullString(ds2.getString("employeeid")));
					String remark = "";
					if(!getRemark.equals("")){
						remark="กะเดิม "+getRemark;
					}
					
		%>
						<tr>
							<td align="center"><%=no%></td>
							<td align="left"><%=chk.chkNullString(ds2.getString("employeeid"))%></td>
							<td align="left"><%=chk.chkNullString(ds2.getString("name"))%></td>
							<td align="center"><%=chk.chkNullString(ds2.getString("bu4"))%></td>
							<td align="center"><%=date2%></td>
							<td align="center"><%=shift1==null?"":shift1.getTimeCode()%></td>
							<td align="center"><%=chk.chkNullString(ds2.getString("m_tm_bg"))%></td>
							<td align="center"><%=chk.chkNullString(ds2.getString("status"))%></td>
							<td align="center"><%=chk.chkNullString(ds2.getString("eventgrp"))%></td>
							<td align="center"><%=remark%></td>
						</tr>
		<%
				no++;
				}
		%>
						<tr>
							<td align="center"></td>
							<td align="center"></td>
							<td align="left">Sub Total</td>
							<td align="left">หนักงานทั้งหมด <%=countEmp%> คน</td>
							<td align="center"></td>
							<td align="left">มาทำงาน <%=countWork%> คน</td>
							<td align="center"></td>
							<td align="center"></td>
							<td align="center" colspan="2">ขาด <%=countLeave%> คน</td>
						</tr>
					</tbody>
				</table>
		<%
				
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
		%>
	</form>
</body>

</html>
<%!
private Shift getShift(CscCalendar shdate,UProfile up,String time0id,String empid){
	try {
			DbRecord empRec = null;
			DbInquiry inq_emp = new InitialInquiry(up).getDbInquiry("MEMPLOYEE");
			inq_emp.setColumn("*");
			inq_emp.setFilter("employeeid='"+empid+"'");
			inq_emp.refresh();
			if (inq_emp.recCount() > 0) {
				while(inq_emp.next()){
					empRec = inq_emp.getCurrentDbRecord().cloneRecord(true);
				}
			}
			Mtime0 mt = (Mtime0) new InitialRecord(up).getDbRecord("Mtime0");
			mt.set("time0id", time0id);
			mt.set("companyid", (String) up.get("companyid"));
			mt.setColumn("*");
			mt.setEmpRec(empRec);
			if(mt.search() == 1){
				WorkingShift wst = mt.genWorkingShift(new CscCalendar(shdate.getYYYYMMDD()), new CscCalendar(shdate.getYYYYMMDD()), "true");
				wst.setEmprec(empRec);
				wst.setUProfile(up);
				wst.adjust();   
				wst.createLink();
				
				DayShift ds = (DayShift) wst.get(shdate.getYYYYMMDD());
				Iterator it = ds.keySet().iterator();
				
				if(it.hasNext()){
					Shift sh = (Shift) ds.get((String) it.next());
					if(sh != null){
						return sh ;
					}
				}
				
			}
		}catch(Exception e){
			MyLog.debug("!! Can not find shift on " + shdate);
		}
		return null ;
}
private String getChShift(String date,UProfile up,String empid){
	String shift = "";
	CheckNull chk = new CheckNull();
	CscCalendar date2 = new CscCalendar(date);
	try {
		int count = 0;
		DbInquiry inq = new InitialInquiry(up).getDbInquiry("TCHANGESHIFT_NSTDA");
		inq.setColumn("*");
		inq.setFilter("employeeid='"+empid+"'  ");
		inq.refresh();
		if (inq.recCount() > 0) {
			while(inq.next()){
				CscCalendar st = new CscCalendar(chk.chkNullString(inq.getString("start_date")));
				CscCalendar en = new CscCalendar(chk.chkNullString(inq.getString("end_date")));
				if(date2.afterEqualsDate(st)&&date2.beforeEqualsDate(en)){
					shift = chk.chkNullString(inq.getString("old_shift"));
				}
			}
		}
	}catch(Exception e){}
	return shift ;
}

%>