<%@page import="com.csc.library.utility.DHMConvert"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.Iterator"%> <%@page import="java.util.Vector"%> <%@page import="java.util.LinkedHashMap"%> <%@page import="com.csc.library.report.ReportUDF"%> <%@page import="javax.servlet.jsp.jstl.sql.Result"%> <%@page import="java.io.FileOutputStream"%> <%@page import="com.csc.library.utilities.MyLog"%> <%@page import="java.io.OutputStream"%> <%@page import="java.io.ByteArrayOutputStream"%> <%@page import="java.net.URLDecoder"%> <%@page import="java.text.DecimalFormat"%> <%@page import="java.net.URLEncoder"%> <%@page import="java.util.HashMap"%> <%@page import="com.csc.library.database.DataSet"%> <%@page import="com.csc.library.session.InitialInquiry"%> <%@page import="com.csc.library.utilities.UProfile"%> <%@page import="com.csc.library.utilities.CscCalendar"%> <%@page import="com.csc.library.session.DbInquiry"%> <%@page import="com.csc.library.utilities.CheckNull"%> <%@page import="com.csc.library.entry.HelpEntry"%> <%@page import="com.itextpdf.text.*"%> <%@page import="com.itextpdf.text.pdf.*"%> <%@page import="java.io.ByteArrayOutputStream" %> <%@page import="com.csc.library.session.InitialEnvironment" %> <%@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 language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <jsp:useBean id="EMV" class="com.csc.library.system.Task" scope="page" /> <jsp:setProperty name="EMV" property="appname" value="EMPVIEW" /> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> Not found data <% EMV.setChannel(request, response); HelpEntry screen = (HelpEntry)EMV.process("HelpEntry", "MCOMPANYHELP"); screen.setMaxLine(-1); CheckNull chk = new CheckNull(); setHelpEntry(screen); screen.process(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4.rotate(), 20, 22, 10, 10); PdfWriter.getInstance(document, baos); document.open(); document.addTitle("Document Title"); BaseFont bf = BaseFont.createFont(application.getRealPath("FONTS/Cordia.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); BaseFont bfHead = BaseFont.createFont(application.getRealPath("FONTS/Cordia.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true); Font font = new Font(bf, 11); Font boldFont = new Font(bfHead, 11, Font.BOLD); Font fontHead = new Font(bfHead, 14); Font boldHead = new Font(bfHead, 16, Font.BOLD); //fontHead.setStyle(1); // ตัวหนา // set vlign middle Phrase content = new Phrase("Blah blah blah", font); Float fontSize = content.getFont().getSize(); Float capHeight = content.getFont().getBaseFont().getFontDescriptor(BaseFont.CAPHEIGHT, fontSize); Float padding = 5f; boolean statusData = false; 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+"'"; if(screen.getInquiry().recCount() > 0) { try{ 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(sql); DataSet ds = new DataSet(sql,screen.getUProfile().get("dbname"),"Memployee"); ds.initConnection(screen.getUProfile()); String tmpCase = ""; String tmpBu = ""; PdfPTable detail = new PdfPTable(10); detail.setWidthPercentage(100); detail.setWidths(sizeColumn); PdfPCell cellDetail; while (ds.next()) { String bu3dedc = chk.chkNullString(ds.getString("bu3")); String bu3 = ds.getString("bu3id"); cellDetail = new PdfPCell(new Phrase("แผนก "+bu3dedc, boldFont)); cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT); cellDetail.setBorder(Rectangle.NO_BORDER); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setColspan(10); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("รหัสพนักงาน", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("ชื่อ - นามสกุล", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("ชื่อหน่วยงาน", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("วันที่", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("กะการทำงาน", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("เวลารูดเข้า", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("สถานะ", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("ลา", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("หมายเหตุ", boldFont)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); // document.add(detail); 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,screen.getUProfile().get("dbname"),"Memployee"); ds2.initConnection(screen.getUProfile()); 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,screen.getUProfile(),chk.chkNullString(ds2.getString("time0")),chk.chkNullString(ds2.getString("employeeid"))); String getRemark = getChShift(chk.chkNullString(ds2.getString("dateid")),screen.getUProfile(),chk.chkNullString(ds2.getString("employeeid"))); String remark = ""; if(!getRemark.equals("")){ remark="กะเดิม "+getRemark; } /*PdfPTable detail = new PdfPTable(9); detail.setWidthPercentage(100); detail.setWidths(sizeColumn); PdfPCell cellDetail;*/ cellDetail = new PdfPCell(new Phrase(String.valueOf(no), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(chk.chkNullString(ds2.getString("employeeid")), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(chk.chkNullString(ds2.getString("name")), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(chk.chkNullString(ds2.getString("bu4")), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(date2, font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(shift1==null?"":shift1.getTimeCode(), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(chk.chkNullString(ds2.getString("m_tm_bg")), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(chk.chkNullString(ds2.getString("status")), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(chk.chkNullString(ds2.getString("eventgrp")), font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase(remark, font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); no++; } cellDetail = new PdfPCell(new Phrase("", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("Sub Total", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("หนักงานทั้งหมด "+countEmp+" คน", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("มาทำงาน "+countWork+" คน", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); detail.addCell(cellDetail); cellDetail = new PdfPCell(new Phrase("ขาด "+countLeave+" คน", font)); cellDetail.setPadding(padding); cellDetail.setPaddingTop(capHeight - fontSize + padding); cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER); cellDetail.setColspan(2); detail.addCell(cellDetail); } document.add(detail); ds.closeConnection(); } catch(Exception e) { e.printStackTrace(); } } document.close(); OutputStream os = response.getOutputStream(); // Create a reader PdfReader reader = new PdfReader(baos.toByteArray()); // Create a stamper PdfStamper stamper = new PdfStamper(reader,baos); // Loop over the pages and add a header to each page int n = reader.getNumberOfPages(); for (int i = 1; i <= n; i++) { //getHeaderTable(i, n, font, boldFont,boldHead).writeSelectedRows(0, -1, 20, 550, stamper.getOverContent(i)); //ไม่รู้ ซ้าย ขวา ล่าง } // Close the stamper stamper.close(); reader.close(); response.setHeader("Expires", "0"); response.setHeader("Cache-Control","must-revalidate, post-check=0 , pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream baos.writeTo(os); os.flush(); os.close(); %> <%! float[] sizeColumn = new float[] {0.5f,1.0f,2.5f,4.0f,1.0f,1.5f,1.0f,1.0f,1.0f,2.0f}; private PdfPTable getHeaderTable(int x, int y,Font font,Font fontHead,Font boldHead) { return null; } HelpEntry screen; private void setHelpEntry(HelpEntry screen) { this.screen = screen; } %> </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 ; } %>