TAR11129_EXP.jsp 15 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
<!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.*"%>
<%@ page import="java.util.*,java.io.*,java.sql.*"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Date" %>
<%@ 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 dmfm = new DecimalFormat("0.00");

	UProfile mypro = null;

	if (session !=null){
		mypro = (UProfile)session.getAttribute("userprofile");
	}

	DecimalFormat dmfm1 = new DecimalFormat("#,##0.00");
	DecimalFormat dmfm2 = new DecimalFormat("#,###");

	CscCalendar now = new CscCalendar();
	SimpleDateFormat df = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
	GregorianCalendar gc= new GregorianCalendar();

	//String month = chk.chkNullString(request.getParameter("__month"));
	//String year = chk.chkNullString(request.getParameter("__year"));
	//String end_date = chk.chkNullString(request.getParameter("__end_date"),now.getDDMMYYYY());
	String cmd = chk.chkNullString(request.getParameter("__cmd"));
	//CscCalendar calendar = new CscCalendar();
	//int year2 =  Integer.parseInt(calendar.getEngYYYY());
	String branch = chk.chkNullString(request.getParameter("__comid"));
	String start_date = chk.chkNullString(request.getParameter("__start_date"),now.getDDMMYYYY());
	String end_date = chk.chkNullString(request.getParameter("__end_date"),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 branchid =chk.chkNullString(request.getParameter("__branch"));
	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 salatype =chk.chkNullString(request.getParameter("__salatype"));
	String employeeid =chk.chkNullString(request.getParameter("__employeeid"));
	String emptype =chk.chkNullString(request.getParameter("__emp_type"));
	//String filter = "1=1";
	String filter = chk.chkNullString(request.getParameter("__filter"));
	String reportfilter = "1=1";

	DbInquiry dbssec = new InitialInquiry(uprofile).getDbInquiry("ssecurity");
	dbssec.setColumn("*");
	dbssec.setFilter("employeeid = '"+uprofile.get("employeeid")+"' AND isviewall ='1'");
	dbssec.refresh();

//	filter += " and t1.DATEID between '" + f_start_date + "' and '" +f_end_date+"' order by t1.employeeid,t1.dateid,t1.sequence";
//	reportfilter += " and DATEID between '" + f_start_date + "' and '" +f_end_date+"'";

	DbRecord dbrec = new InitialRecord(mypro).getDbRecord("memployee");
	dbrec.setColumn("*");

	//************** Start Export Report *************************
	ThaiUtilities th = new ThaiUtilities();
	UProfile uf = uprofile;
	String reportPath = new InitialEnvironment("GLOBAL").getValue("report-path");
	String dbName = uf.getDbName();
	String comname = uf.get("companyname");
	String comTname = th.ASCII2Unicode(uf.get("com_tname"));
	String comEname = uf.get("com_ename");
	String companyid = uf.get("companyid");
	String userId = uf.getUserId();
	String app_name = uf.get("appname");
	String schemaName = uf.getSchemaName();
	String password = uf.getPassword();
	String userlevel = uf.getLevel();
	String format_date = uf.get("formatdate");
	String lang = uf.get("lang").toUpperCase();
	String ufullname = uf.get("fullname");
	String bu1desc = dbrec.getField("bu1").getDescription();
	String bu2desc = dbrec.getField("bu2").getDescription();
	String bu3desc = dbrec.getField("bu3").getDescription();
	String bu4desc = dbrec.getField("bu4").getDescription();
	String bu5desc = dbrec.getField("bu5").getDescription();

	//************** End Export Report *************************
%>

<html ng-app="myHR">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- <link href="../CSS/TISCO.css" rel="stylesheet" type="text/css"> -->
</head>
<%
String helpReturn="";
if(request.getParameter("__helpReturn")!=null){
	helpReturn=request.getParameter("__helpReturn");
}
String fieldSearch="";
if(request.getParameter("__fieldSearch")!=null){
	fieldSearch=request.getParameter("__fieldSearch");
}
%>
<body leftmargin="0" topmargin="0">
<form name="cscform" method="post" action="TAR11129.jsp">


<!----------BEGIN CSC INITIAL ZONE ------------------------>

<%//=screen.InitialVariable()%>

<!----------END CSC INITIAL ZONE -------------------------->

<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__screen" value="TAR11129">
<input type="hidden" name="__help" value="">
<input type="hidden" name="__goPage" value="">
<input type="hidden" name="__language" value="<%=uprofile.get("lang")%>">
<input type="hidden" name="__orderBy" value="<%=request.getParameter("__orderBy")%>">
<input type="hidden" name="__helpReturn" value="<%=helpReturn%>">
<input type="hidden" name="__fieldSearch" value="<%=fieldSearch%>">
<input type="hidden" name="__helpName" value="<%=request.getParameter("__helpName")%>">
<input type="hidden" name="__pageCall" value="<%=request.getParameter("__screen")%>">
<input type="hidden" name="__fixCon" value="<%=request.getParameter("__fixCon")%>">
<input type="hidden" name="__export" value="">
<input type="hidden" name="__calendar" value="">
<input type="hidden" name="__filter" value="<%=filter%>">
<%if(true){%>
			<table border="0" cellpadding="0" cellspacing="1" bgcolor="">
				<tr bgcolor="#FFFFFF">
					<td colspan="11"><div align="center"><b>รายงานการบันทึกชั่วโมงการทำงานล่วงเวลา/ ขาดงานและะการลาที่ไม่จ่ายค่าจ้าง และค่ากะดึก</b></div></td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td colspan="11"><div align="center"><b>ช่วงวันที่ <%=new CscCalendar(request.getParameter("__start_date")).getDDMMYYYY()%> ถึง <%=new CscCalendar(request.getParameter("__end_date")).getDDMMYYYY()%></b></div></td>
				</tr>
			</table>
			<table border="1" cellpadding="0" cellspacing="1" bgcolor="">
				<tr bgcolor="#0099FF">
					<td class="" rowspan="2" width="10%"><div align="center"><b>ลำดับ</b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b>รหัสพนักงาน</b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b>ชื่อพนักงาน</b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b>สถานะ</b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b><%=dbrec.getField("bu4").getDescription()%></b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b><%=dbrec.getField("bu5").getDescription()%></b></div></td>
					<td class="" colspan="3" width="30%"><div align="center"><b><%=lang.equals("THA")?"จำนวนชั่วโมง OT (ชั่วโมง)":"OT Hours (Hours)"%></b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b><%=lang.equals("THA")?"ขาดงาน(ชั่วโมง)":"Absent"%></b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b><%=lang.equals("THA")?"ลาไม่จ่ายค่าจ้าง (ชั่วโมง)":"Leave Without Pay (Hours)"%></b></div></td>
					<td class="" rowspan="2" width="10%"><div align="center"><b><%=lang.equals("THA")?"ค่ากะ (บาท)":"Night Shift (Baht)"%></b></div></td>
				</tr>
				<tr bgcolor="#0099FF">
					<td class=""><div align="center"><b>OT 1</b></div></td>
					<td class=""><div align="center"><b>OT 1.5</b></div></td>
					<td class=""><div align="center"><b>OT 3</b></div></td>
				</tr>

				<%
				int i=1;
				String empid ="";
				String fullname = "";
				String bu4 = "";
				String bu5 = "";
				String status = "";
				String ot1 = "";
				String ot5 = "";
				String ot3 = "";
				String absent = "";
				String leave = "";
				String unused = "";
				String st_date = new CscCalendar(request.getParameter("__start_date")).getYYYYMMDD();
				String en_date = new CscCalendar(request.getParameter("__end_date")).getYYYYMMDD();

				Double sum_ot1 = 0.0;
				Double sum_ot5 = 0.0;
				Double sum_ot3 = 0.0;
				Double sum_absent = 0.0;
				Double sum_leave = 0.0;
				Double sum_unused = 0.0;

				Boolean isShow = true;
				Boolean isResign = true;
				
				StringBuffer sql = new StringBuffer();
				sql.append("select t1.EMPLOYEEID ");
				sql.append(",dbo.min_to_time(SUM(dbo.time_to_min(t1.OT1))) as OT1 ");
				sql.append(",dbo.min_to_time(SUM(dbo.time_to_min(t1.OT5))) as OT5 ");
				sql.append(",dbo.min_to_time(SUM(dbo.time_to_min(t1.OT3))) as OT3 ");
				sql.append(",(select dbo.min_to_time(SUM(dbo.time_to_min(M_LV))) as M_LV from TTIME_CURRENT1 where EMPLOYEEID=t1.EMPLOYEEID and EVENTGRP='J' and DATEID between '"+st_date+"' and '"+en_date+"') as ABSENT ");
				sql.append(",(select dbo.min_to_time(SUM(dbo.time_to_min(M_LV))) as M_LV from TTIME_CURRENT1 where EMPLOYEEID=t1.EMPLOYEEID and LV_TY in (select EVENTGRPID from MEVENTGRP1 where BRANCHID=e.BRANCHID and ISPAY='0') and DATEID between '"+st_date+"' and '"+en_date+"') as LEAVE ");
				sql.append(",SUM(t1.UNUSED1) as UNUSED1 ");
				sql.append(",SUM(t1.UNUSED2) as UNUSED2 ");
				sql.append(",SUM(t1.UNUSED3) as UNUSED3 ");
				sql.append(",SUM(t1.UNUSED4) as UNUSED4 ");
				sql.append(",SUM(t1.UNUSED5) as UNUSED5 ");
				sql.append(",SUM(t1.UNUSED6) as UNUSED6 ");
				sql.append(",SUM(t1.UNUSED7) as UNUSED7 ");
				sql.append(",SUM(t1.UNUSED8) as UNUSED8 ");
				sql.append(",SUM(t1.UNUSED9) as UNUSED9 ");
				sql.append(",SUM(t1.UNUSED10) as UNUSED10 ");
				sql.append("from TTIME_CURRENT1 t1 ");
				sql.append("left join MEMPLOYEE e on t1.EMPLOYEEID=e.EMPLOYEEID ");
				sql.append("left join MPREFIX p on e.EMP_PREFIX=p.PREFIXID ");
				sql.append("left join MEMPL_STATUS s on e.STATUS=s.STATUSCODE ");
				sql.append("left join MBU5 b5 on t1.BU5=b5.BU5ID ");
				sql.append("left join MBU4 b4 on t1.BU4=b4.BU4ID ");
				sql.append("where t1.DATEID between '"+st_date+"' and '"+en_date+"' "+filter);
					sql.append(" group by t1.EMPLOYEEID,e.BRANCHID; ");

			//	out.print(sql.toString());
				String tableName = "ttime_current1";
				DataSet ds = new DataSet(sql.toString(), dbName, tableName);
				ds.initConnection(uprofile);
					DbInquiry empdata = new InitialInquiry(uprofile).getDbInquiry("memployee");
					empdata.setColumn("*");
					while(ds.next()){
						empid = chk.chkNullString(ds.getString("employeeid"));
						empdata.setFilter("employeeid = '"+empid+"'");
						empdata.refresh();
						empdata.next();
						fullname = empdata.getString("fullname");
						status = empdata.getString("statusname");
						bu4 = empdata.getString("bu4name");
						bu5 = empdata.getString("bu5name");
						ot1 = dmfm.format(chk.chkNullStringToDouble(ds.getString("ot1")));
						ot5 = dmfm.format(chk.chkNullStringToDouble(ds.getString("ot5")));
						ot3 = dmfm.format(chk.chkNullStringToDouble(ds.getString("ot3")));
						absent = dmfm.format(chk.chkNullStringToDouble(ds.getString("absent")));
						leave = dmfm.format(chk.chkNullStringToDouble(ds.getString("leave")));
						unused = dmfm.format(chk.chkNullStringToDouble(ds.getString("unused1")));

					if(chk.chkNullStringToDouble(ds.getString("ot1"))>0 || chk.chkNullStringToDouble(ds.getString("ot5"))>0 || chk.chkNullStringToDouble(ds.getString("ot3"))>0 || chk.chkNullStringToDouble(ds.getString("absent"))>0 || chk.chkNullStringToDouble(ds.getString("leave"))>0  || chk.chkNullStringToDouble(ds.getString("unused1"))>0){
						isShow = true;
					}else{
						isShow = false;
					}
					
					if(chk.chkNullString(ds.getString("status")).equals("Y") && chk.chkNullStringToDouble(ds.getString("ot1"))==0 && chk.chkNullStringToDouble(ds.getString("ot5"))==0 && chk.chkNullStringToDouble(ds.getString("ot3"))==0){
						isResign = false;
					}else{
						isResign = true;
					}

					if(isShow && isResign){
						sum_ot1 += TimeToDec(ot1);
						sum_ot5 += TimeToDec(ot5);
						sum_ot3 += TimeToDec(ot3);
						sum_absent += TimeToDec(absent);
						sum_leave += TimeToDec(leave);
						sum_unused += Double.parseDouble(unused);
				%>
				<tr bgcolor="#FFFFFF">
					<td nowrap ><div align="center"><%=i%></div></td>
					<td nowrap ><div align="center"><%=empid%></div></td>
					<td nowrap ><div align=""><%=fullname%></div></td>
					<td nowrap ><div align="center"><%=status%></div></td>
					<td nowrap ><div align=""><%=bu4%></div></td>
					<td nowrap ><div align=""><%=bu5%></div></td>
					<td nowrap ><div align="center"><%=dmfm.format(TimeToDec(ot1))%></div></td>
					<td nowrap ><div align="center"><%=dmfm.format(TimeToDec(ot5))%></div></td>
					<td nowrap ><div align="center"><%=dmfm.format(TimeToDec(ot3))%></div></td>
					<td nowrap ><div align="center"><%=dmfm.format(TimeToDec(absent))%></div></td>
					<td nowrap ><div align="center"><%=dmfm.format(TimeToDec(leave))%></div></td>
					<td nowrap ><div align="center"><%=unused%></div></td>
				</tr>
				<%	
						i++;	
					}
				}
				ds.closeConnection();
				%>
				<tr bgcolor="#FFFFFF">
					<td nowrap colspan="6"><div align="center"><b>Total</b></div></td>
					<td nowrap ><div align="center"><%=dmfm1.format(sum_ot1)%></div></td>
					<td nowrap ><div align="center"><%=dmfm1.format(sum_ot5)%></div></td>
					<td nowrap ><div align="center"><%=dmfm1.format(sum_ot3)%></div></td>
					<td nowrap ><div align="center"><%=dmfm1.format(sum_absent)%></div></td>
					<td nowrap ><div align="center"><%=dmfm1.format(sum_leave)%></div></td>
					<td nowrap ><div align="center"><%=dmfm1.format(sum_unused)%></div></td>
				</tr>
         </table>
	 <%!
		private String chkMySecurity(String p_status,String p_field,String p_data){
			String mfilter = "";
			if (p_status.equalsIgnoreCase("1")){
				mfilter =" AND "+p_field+" NOT IN (";
			}else if (p_status.equalsIgnoreCase("0")){
				mfilter = " AND "+p_field+" IN (";
			}

			String mdata[] = p_data.split(",");

			for (int i=0;i<mdata.length; i++){
				mfilter += "'"+mdata[i]+"',";
			}

			mfilter = mfilter.substring(0,mfilter.length()-1);
			mfilter += ")";

			return mfilter;
		}

		private Double TimeToDec(String string) {
			try{
				String output = "0.00";
				String arr[] = string.split("\\.");
				Integer min = (int) (Integer.parseInt(arr[1])/0.6);
				output = arr[0]+"."+min;
				return Double.parseDouble(output);
			}catch (Exception e){  
				return 0.0;
			}
		}
	 %>
	<%}
	%>
</form>
</body>
</html>