PSRN001_PDF.jsp 26.9 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 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@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.*"%>
<%@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="java.text.SimpleDateFormat" %>
<%@page import="java.util.Locale" %>
<%@page import="java.util.Date" %>
<%@page import="java.util.GregorianCalendar" %>
<%@page import="com.csc.library.database.DataSet"%>
<%@page import="com.csc.library.session.InitialInquiry"%>
<%@page import="com.csc.library.session.InitialRecord"%>
<%@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.session.DbRecord"%>
<%@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" %>
<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>Report</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();

      DbInquiry op = new InitialInquiry(screen.getUProfile()).getDbInquiry("COLOPTION");
      op.setColumn("*");
      op.setFilter("optionid = '22' ");
      op.refresh();
      op.next();

      Map<Integer, Integer> linkmap = new LinkedHashMap<Integer, Integer>();
      for(int i=1;i<=6;i++){
        String chknum = op.getString("chk"+i);
        if(chknum.equals("1")){
          linkmap.put(i,Integer.valueOf(op.getString("col"+i)));
        }
      }

      ByteArrayOutputStream baos = new ByteArrayOutputStream();//72
      Document document = new Document(PageSize.A4.rotate(), 20, 22, 146, 36);

      if(linkmap.size()==0){
        document = new Document(PageSize.A4.rotate(), 20, 22, 134, 36);
        sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f};
      }else if(linkmap.size()==1){
        sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f,1.5f};
      }else if(linkmap.size()==2){
        sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f,1.5f,1.5f};
      }else if(linkmap.size()==3){
        sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f,1.5f,1.5f,1.5f};
      }else if(linkmap.size()==4){
        sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f,1.5f,1.5f,1.5f,1.5f};
      }else if(linkmap.size()==5){
        sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f,1.5f,1.5f,1.5f,1.5f,1.5f};
      }else if(linkmap.size()==6){
        sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f,1.5f,1.5f,1.5f,1.5f,1.5f,1.5f};
      }

      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, 10);
      Font fontHead = new Font(bfHead, 10);
      //fontHead.setStyle(Font.BOLD);
      Font fontContent = new Font(bfHead, 10);
      Font fontTitle = new Font(bfHead, 16);
      fontTitle.setStyle(Font.BOLD);

      // 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 cc = new CscCalendar();
      String branch = chk.chkNullString(request.getParameter("branch"));
      String branchDesc = chk.chkNullString(request.getParameter("MBRANCH@TDESC"));
      String startdate = chk.chkNullString(request.getParameter("startdate"), cc.getDDMMYYYY());
      String enddate = chk.chkNullString(request.getParameter("enddate"), cc.getDDMMYYYY());
      String allbranch = chk.chkNullString(request.getParameter("allbranch"));
      String filter = chk.chkNullString(request.getParameter("__filter"),"1=1");
      String bu1 = chk.chkNullString(request.getParameter("__bu1"));
      String bu2 = chk.chkNullString(request.getParameter("__bu2"));
      String bu3 = chk.chkNullString(request.getParameter("__bu3"));
      String bu4 = chk.chkNullString(request.getParameter("__bu4"));
      String bu5 = chk.chkNullString(request.getParameter("__bu5"));
      String workarea = chk.chkNullString(request.getParameter("__workarea"));
      CscCalendar st = new CscCalendar(startdate);
      CscCalendar en = new CscCalendar(enddate);
      if(!allbranch.equals("")){
        filter += allbranch;
      }

      if(!branch.equals("")){
        filter += " and branch = '"+branch+"'";
      }

      if(!bu1.equals("")){
        filter += " and bu1 = '"+bu1+"'";
      }

      if(!bu2.equals("")){
        filter += " and bu2 = '"+bu2+"'";
      }

      if(!bu3.equals("")){
        filter += " and bu3 = '"+bu3+"'";
      }

      if(!bu4.equals("")){
        filter += " and bu4 = '"+bu4+"'";
      }

      if(!bu5.equals("")){
        filter += " and bu5 = '"+bu5+"'";
      }

      if(!workarea.equals("")){
        filter += " and workarea = '"+workarea+"'";
      }
      if(!startdate.equals("")){
        filter += " and startdate between '"+st.getYYYYMMDD()+"' and '"+en.getYYYYMMDD()+"'";
      }

      boolean hasData = false;
      if(screen.getInquiry().recCount() > 0) {
        try{
          String DbType = screen.getUProfile().getDbType().toUpperCase();
          String strJoiner = "+";
          if(DbType.equals("PGSQL") || DbType.equals("ORACLE")){
            strJoiner = "||";
          }

          String sql="";
          if(screen.getUProfile().get("lang").equals("eng")){
      			 sql = "select me.EMPLOYEEID,pre.EDESC"+strJoiner+"me.EFNAME"+strJoiner+"' '"+strJoiner+"me.ELNAME as fullname,b1.EDESC as bu1,b2.EDESC as bu2,b3.EDESC as bu3,STARTDATE from MEMPLOYEE me left join MPREFIX pre on me.EMP_PREFIX = pre.PREFIXID left join MBU3 b3 on me.BU3 = b3.BU3ID left join MBU2 b2 on me.BU2 = b2.BU2ID left join MBU1 b1 on me.BU1 = b1.BU1ID where "+filter+" ORDER BY me.bu1,me.bu2,me.bu3,me.bu4,me.bu5";
      		}else{
      			 sql = "select me.EMPLOYEEID,pre.TDESC"+strJoiner+"me.FNAME"+strJoiner+"' '"+strJoiner+"me.LNAME as fullname,b1.TDESC as bu1,b2.TDESC as bu2,b3.TDESC as bu3,STARTDATE from MEMPLOYEE me left join MPREFIX pre on me.EMP_PREFIX = pre.PREFIXID left join MBU3 b3 on me.BU3 = b3.BU3ID left join MBU2 b2 on me.BU2 = b2.BU2ID left join MBU1 b1 on me.BU1 = b1.BU1ID where "+filter+" ORDER BY me.bu1,me.bu2,me.bu3,me.bu4,me.bu5";
      		}

          DataSet ds = new DataSet(sql.toString(),screen.getUProfile().get("dbname"),"Memployee");
          ds.initConnection(screen.getUProfile());
          int no = 1;
          int span = linkmap.size()+7;
          while (ds.next()) {
            hasData = true;
            CscCalendar stDate = new CscCalendar(chk.chkNullString(ds.getString("startdate")));
            CscCalendar test1 = new CscCalendar(chk.chkNullString(ds.getString("startdate")));
            CscCalendar test2 = new CscCalendar(chk.chkNullString(ds.getString("startdate")));
            CscCalendar test3 = new CscCalendar(chk.chkNullString(ds.getString("startdate")));
            CscCalendar test4 = new CscCalendar(chk.chkNullString(ds.getString("startdate")));
            String testWork1 = test1.incDate(60).getDDMMYYYY() ;
            String testWork2 = test2.incDate(85).getDDMMYYYY() ;
            String testWork3 = test3.incDate(90).getDDMMYYYY() ;
            String testWork4 = test4.incDate(119).getDDMMYYYY() ;

            PdfPTable detail = new PdfPTable(span);
            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(ds.getString("employeeid"), font));
            cellDetail.setPadding(padding);
            cellDetail.setPaddingTop(capHeight - fontSize + padding);
            cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
            detail.addCell(cellDetail);

            cellDetail = new PdfPCell(new Phrase(ds.getString("fullname"), font));
            cellDetail.setPadding(padding);
            cellDetail.setPaddingTop(capHeight - fontSize + padding);
            cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
            detail.addCell(cellDetail);

            cellDetail = new PdfPCell(new Phrase(ds.getString("bu1"), font));
            cellDetail.setPadding(padding);
            cellDetail.setPaddingTop(capHeight - fontSize + padding);
            cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
            detail.addCell(cellDetail);

            cellDetail = new PdfPCell(new Phrase(ds.getString("bu2"), font));
            cellDetail.setPadding(padding);
            cellDetail.setPaddingTop(capHeight - fontSize + padding);
            cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
            detail.addCell(cellDetail);

            cellDetail = new PdfPCell(new Phrase(ds.getString("bu3"), font));
            cellDetail.setPadding(padding);
            cellDetail.setPaddingTop(capHeight - fontSize + padding);
            cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
            detail.addCell(cellDetail);

            cellDetail = new PdfPCell(new Phrase(stDate.getDDMMYYYY(), font));
            cellDetail.setPadding(padding);
            cellDetail.setPaddingTop(capHeight - fontSize + padding);
            cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
            detail.addCell(cellDetail);

            for (Integer key : linkmap.keySet()){
              cellDetail = new PdfPCell(new Phrase(new CscCalendar(chk.chkNullString(ds.getString("startdate"))).incDate(linkmap.get(key)).getDDMMYYYY(), font));
              cellDetail.setPadding(padding);
              cellDetail.setPaddingTop(capHeight - fontSize + padding);
              cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
              detail.addCell(cellDetail);
            }

            document.add(detail);

            no++;
          }
          ds.closeConnection();
        } catch(Exception e) {
          e.printStackTrace();
        } finally {
          if(hasData){
            document.close();
          }
        }
      }


      if(hasData){
        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, fontHead, fontTitle, fontContent, startdate, enddate).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();
      }

      %>

      <%!
      String startdate = "";
      String enddate = "";
      String buDesc = "";

      private void setStartdate(String startdate) {
        this.startdate = startdate;
      }

      private void setEnddate(String enddate) {
        this.enddate = enddate;
      }

      private void setBuDesc(String buDesc) {
        this.buDesc = buDesc;
      }

      float[] sizeColumn = new float[] {0.6f,1.0f,2.6f,2.0f,2.0f,2.0f,1.5f,1.5f,1.5f,1.5f,1.5f};
      private PdfPTable getHeaderTable(int x, int y,Font font,Font fontHead,Font fontTitle,Font fontContent,String startdate,String enddate) {
        try{
          Phrase content = new Phrase("Blah blah blah", font);
          Float fontSize = content.getFont().getSize();
          Float capHeight = content.getFont().getBaseFont().getFontDescriptor(BaseFont.CAPHEIGHT, fontSize);
          Float padding = 3f;
          InitialEnvironment en = new InitialEnvironment("GLOBAL");
          String pathImage = en.getValue("EXCEL-DIR");

          DbRecord emp_rec = new InitialRecord(screen.getUProfile()).getDbRecord("memployee");
          DbInquiry op = new InitialInquiry(screen.getUProfile()).getDbInquiry("COLOPTION");
          op.setColumn("*");
          op.setFilter("optionid = '22' ");
          op.refresh();
          op.next();

          Map<Integer, Integer> linkmap = new LinkedHashMap<Integer, Integer>();
          for(int i=1;i<=6;i++){
            String chknum = op.getString("chk"+i);
            if(chknum.equals("1")){
              linkmap.put(i,Integer.valueOf(op.getString("col"+i)));
            }
          }
          int span = linkmap.size()+7;
          int srefer = linkmap.size() > 4 ? 2 : 1;
          CscCalendar calendar = new CscCalendar();
          SimpleDateFormat df = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
          GregorianCalendar gc= new GregorianCalendar();

          boolean langthai = screen.getUProfile().get("lang").equalsIgnoreCase("THA");
          String reportname = "", perioddate = "", printdate = "", printby = "", refer = "", page = "";
          if(langthai){
            reportname = "รายงาน :                รายงานรายชื่อพนักงานเข้าใหม่และการคำนวณ Probation";
            perioddate = "ช่วงวันที่ :               "+startdate+" ถึง "+enddate;
            printdate = "วันที่พิมพ์ :             วัน"+calendar.getLongThiDOW()+"ที่ "+calendar.getDate()+ " " + calendar.getThaiLongMonth() + " พ.ศ. "+ calendar.getThaiYYYY() +
            " " +calendar.getHHMM() + " น.";
            printby = "พิมพ์โดย :              "+screen.getUProfile().get("tfullname");
            refer = "อ้างอิง #    RPI2100";
            page = "หน้า          "+x+" / "+y;
          } else {
            reportname = "Report Name :         New Employee List And Probation Calulation Report";
            perioddate = "Period Date :           "+startdate+" To "+enddate;
            printdate = "Print Date :              "+calendar.getEngFull()+ " " + df.format((Date)gc.getTime());
            printby = "Print By :                 "+screen.getUProfile().get("efullname");
            refer = "Ref #    RPI2100";
            page = "Page          "+x+" / "+y;
          }

          PdfPTable detail = new PdfPTable(span);
          PdfPCell cellDetail;
          detail.setTotalWidth(800);
          detail.setWidths(sizeColumn);
          detail.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

          // ------------------ title detail ---------------------

          cellDetail = new PdfPCell(new Phrase(String.format(screen.getUProfile().get("companyname"), x, y),fontTitle));
          cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setColspan(span);
          cellDetail.setBorder(Rectangle.NO_BORDER);
          detail.addCell(cellDetail);

          // --------------- new line -----------------

          cellDetail = new PdfPCell(new Phrase(String.format(reportname, x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setColspan(span);
          cellDetail.setBorder(Rectangle.NO_BORDER);
          detail.addCell(cellDetail);

          // --------------- new line -----------------

          cellDetail = new PdfPCell(new Phrase(String.format(perioddate, x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setColspan(span);
          cellDetail.setBorder(Rectangle.NO_BORDER);
          detail.addCell(cellDetail);

          // --------------- new line -----------------

          cellDetail = new PdfPCell(new Phrase(String.format(printdate, x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setColspan(span-srefer);
          cellDetail.setBorder(Rectangle.NO_BORDER);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(refer, x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_RIGHT);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setColspan(srefer);
          cellDetail.setBorder(Rectangle.NO_BORDER);
          detail.addCell(cellDetail);

          // --------------- new line -----------------

          Float paddingbottom = 7.5f;

          cellDetail = new PdfPCell(new Phrase(String.format(printby, x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setPaddingBottom(paddingbottom);
          cellDetail.setColspan(span-srefer);
          cellDetail.setBorder(Rectangle.NO_BORDER);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(page, x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_RIGHT);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setPaddingBottom(paddingbottom);
          cellDetail.setColspan(srefer);
          cellDetail.setBorder(Rectangle.NO_BORDER);
          detail.addCell(cellDetail);

          // --------------- new line -----------------

          // ------------------ head detail ----------------------

          cellDetail = new PdfPCell(new Phrase(String.format(langthai?"ลำดับ":"No.", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setRowspan(2);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(langthai?"รหัสพนักงาน":"Employee ID", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setRowspan(2);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(langthai?"ชื่อ-นามสกุล":"Name-Surname", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setRowspan(2);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(emp_rec.getField("bu1").getDescription(), x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setRowspan(2);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(emp_rec.getField("bu2").getDescription(), x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setRowspan(2);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(emp_rec.getField("bu3").getDescription(), x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setRowspan(2);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format(langthai?"วันที่เริ่มงาน":"Start Date", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setRowspan(2);
          detail.addCell(cellDetail);

          int span2 = linkmap.size();

          cellDetail = new PdfPCell(new Phrase(String.format(langthai?"วันที่ครบกำหนดทดลองงาน":"Probation Date", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          cellDetail.setColspan(span2);
          detail.addCell(cellDetail);

          // หัวตาราง
          for (Integer key : linkmap.keySet()){
            String headcol = langthai?"ครบ "+linkmap.get(key)+" วัน":linkmap.get(key)+" Day(s)";

            cellDetail = new PdfPCell(new Phrase(String.format(headcol, x, y),fontHead));
            cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
            cellDetail.setPadding(padding);
            cellDetail.setPaddingTop(capHeight - fontSize + padding);
            detail.addCell(cellDetail);
          }
          /*

          cellDetail = new PdfPCell(new Phrase(String.format("ครบ 85 วัน", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format("ครบ 90 วัน", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          detail.addCell(cellDetail);

          cellDetail = new PdfPCell(new Phrase(String.format("ครบ 119 วัน", x, y),fontHead));
          cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
          cellDetail.setVerticalAlignment (Element.ALIGN_MIDDLE);
          cellDetail.setPadding(padding);
          cellDetail.setPaddingTop(capHeight - fontSize + padding);
          detail.addCell(cellDetail);
          */
          // --------------- new line -----------------

          return detail;
        }catch(Exception e){
          e.printStackTrace();
        }
        return null;
      }
      %>

      <%!
      HelpEntry screen;
      private void setHelpEntry(HelpEntry screen) {
        this.screen = screen;
      }

      private boolean chkBlank(String val) {
        return val.equals("")?true:false;
      }

      private boolean chkZero(String val) {
        return val.equals("0000000")?true:false;
      }

      private String getDescBu(String table, String bu, String buid) {
        String val = "";
        try {
          DbInquiry mbu = new InitialInquiry(screen.getUProfile()).getDbInquiry(table);
          mbu.setColumn("tdesc");
          mbu.clearOldCondition();
          mbu.setFilter(bu + "='"+ buid +"'");
          mbu.refresh();
          if (mbu.next()) {
            val = mbu.getString("tdesc");
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
        return val;
      }

      private String notZero(String val) {
        return Double.parseDouble(val) > 0? val: "";
      }

      private String notZeroTime(String val) {
        return val.equals("00:00:00")? "": val;
      }
      private String getDescPosition(String table, String po) {
        String val = "";
        try {
          DbInquiry mbu = new InitialInquiry(screen.getUProfile()).getDbInquiry(table);
          mbu.setColumn("tdesc");
          mbu.clearOldCondition();
          mbu.setFilter("positionid='"+ po +"'");
          mbu.refresh();
          if (mbu.next()) {
            val = mbu.getString("tdesc");
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
        return val;
      }
      %>
    </body>
  </html>