TAR11127_PDF.jsp 21.3 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 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
<%@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 ;
}

%>