TAR1121_PDF.jsp 20.4 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
<%@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="java.util.Locale"%>
<%@page import="java.util.Date" %>
<%@page import="java.util.GregorianCalendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@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 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, 159 , 36);
    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, 12);
	Font boldFont = new Font(bfHead, 12, Font.BOLD);
    Font fontHead = new Font(bfHead, 14);
	Font Head = new Font(bfHead, 14);
    Font boldHead = new Font(bfHead, 14, Font.BOLD);
	Font boldCom = new Font(bfHead, 24);
	//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;
	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 startMonth = chk.chkNullString(request.getParameter("startMonth"));
	String startYear = chk.chkNullString(request.getParameter("startYear"));
	String endMonth = chk.chkNullString(request.getParameter("endMonth"));
	String endYear = chk.chkNullString(request.getParameter("endYear"));
	String filter = chk.chkNullString(request.getParameter("__filter"),"1=1");
	UProfile uprofile = screen.getUProfile();
	 DecimalFormat df = new DecimalFormat("###,##0.00");

	 String pagelang = uprofile.get("lang");
	 String thacom = uprofile.get("com_tname");
	 String engcom = uprofile.get("com_ename");
	 String printnameeng = uprofile.get("efullname");
	 String printnameth = uprofile.get("tfullname");

	if(!bu1.equals("")){
		filter += " and me.bu1='"+bu1+"'";
	}
	if(!bu2.equals("")){
		filter += " and me.bu2='"+bu2+"'";
	}
	if(!bu3.equals("")){
		filter += " and me.bu3='"+bu3+"'";
	}
	if(!bu4.equals("")){
		filter += " and me.bu4='"+bu4+"'";
	}
	if(!bu5.equals("")){
		filter += " and me.bu5='"+bu5+"'";
	}
    if(screen.getInquiry().recCount() > 0) {
    	try{
			String sql="select me.bu4 as bu4id,b4.TDESC as bu4 from MEMPLOYEE me left join MBU4 b4 on me.BU4=b4.BU4ID where "+filter+" group by me.bu4,b4.TDESC";
			//out.print(sql.toString());
			DataSet ds = new DataSet(sql,screen.getUProfile().get("dbname"),"Memployee");
			ds.initConnection(screen.getUProfile());
			String tmpCase = "";
			String tmpBu = "";
			int no = 1;
			while (ds.next()) {
				PdfPTable detail = new PdfPTable(10);
				detail.setWidthPercentage(100);
				detail.setWidths(sizeColumn);
				PdfPCell cellDetail;
				
				statusData = true;
				String stDate = "01-"+startMonth+"-"+startYear;
				String enDate = "01-"+endMonth+"-"+endYear;
				CscCalendar st = new CscCalendar(stDate);
				CscCalendar en = new CscCalendar(enDate);
				
				String descEmp = "";

				if(pagelang.equals("eng")){
					descEmp = "Manpower Budget\n"
								+"Number of Resigned\n"
								+"Turnover rate(%)";
				}else{
					descEmp = "จำนวนพนักงานตามแผนกำลัง(คน)\n"
								+"จำนวนพนักงานลาออก(คน)\n"
								+"Turnover rate(%)";
				}
			
				cellDetail = new PdfPCell(new Phrase(ds.getString("bu4"), font));
				cellDetail.setPadding(padding);
				cellDetail.setPaddingTop(capHeight - fontSize + padding);
				cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
				cellDetail.setColspan(2);
				detail.addCell(cellDetail);
				
				cellDetail = new PdfPCell(new Phrase(descEmp, font));
				cellDetail.setPadding(padding);
				cellDetail.setPaddingTop(capHeight - fontSize + padding);
				cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
				detail.addCell(cellDetail);
				
				int x = 0;
				String EMP ="";
				String OUT ="";
				String SUM ="";
				String sumOUT = "";
				double totalEMP = 0.0;
				double totalOUT = 0.0;
				double count = 0;
				while(st.beforeEquals(en)){
					EMP = getEmp(String.valueOf(st.getYYYYMMDD()),chk.chkNullString(ds.getString("bu4id")),uprofile);
					OUT = getOut(String.valueOf(st.getYYYYMMDD()),chk.chkNullString(ds.getString("bu4id")),uprofile);
					if(!EMP.equals("0")){
						SUM = df.format(Double.parseDouble(OUT)/Double.parseDouble(EMP));
					}else{
						SUM = "0.00";
					}
					String desc = EMP+"\n"+OUT+"\n"+SUM+"%";
					cellDetail = new PdfPCell(new Phrase(desc, font));
					cellDetail.setPadding(padding);
					cellDetail.setPaddingTop(capHeight - fontSize + padding);
					cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
					detail.addCell(cellDetail);

					totalEMP+=Double.parseDouble(EMP);
					totalOUT+=Double.parseDouble(OUT);
					st.incMonth(1);
					x++;
					count++;
				}
				if(x!=6){
					while(x<6){
						cellDetail = new PdfPCell(new Phrase("", font));
						cellDetail.setPadding(padding);
						cellDetail.setPaddingTop(capHeight - fontSize + padding);
						cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
						detail.addCell(cellDetail);
						x++;
					}
				}
				String empTotal = df.format(totalEMP/count);
				String outTotal = df.format(totalOUT/count);
				if(totalEMP!=0.0){
					sumOUT = df.format((Double.parseDouble(String.valueOf(totalOUT))/Double.parseDouble(String.valueOf(totalEMP))));
				}else{
					sumOUT = "0.00";
				}

				String descTotal = empTotal+"\n"+outTotal+"\n"+sumOUT+"%";
						
				cellDetail = new PdfPCell(new Phrase(descTotal, 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();
		}
    }

			

    if(!statusData) {
      Paragraph p = new Paragraph("\n\n\nไม่พบข้อมูล",fontHead);
      p.setAlignment(Element.ALIGN_CENTER);
      document.add(p);
    }

    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,boldCom,startMonth,startYear,endMonth,endYear,pagelang,thacom,engcom,Head,printnameeng,printnameth).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[] {1.4f,1.6f,5.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f};
    private PdfPTable getHeaderTable(int x, int y,Font font,Font fontHead,Font boldHead,Font boldCom,String startMonth,String startYear,String endMonth,String endYear,String pagelang,String thacom,String engcom,Font Head,String printnameeng,String printnameth) {
      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");

		//BaseColor color = new BaseColor(red, green, blue);

		String stdate2 = "2"+startMonth+startYear;
		CscCalendar carr = new CscCalendar(stdate2);

		String endate2 = "2"+endMonth+endYear;
		CscCalendar caar = new CscCalendar(endate2);


		CscCalendar car = new CscCalendar();
		SimpleDateFormat dff = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
		GregorianCalendar gcc= new GregorianCalendar();
		

        PdfPTable detail = new PdfPTable(10);
        PdfPCell cellDetail;
        detail.setTotalWidth(800);
        detail.setWidths(sizeColumn);
        detail.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
		String header = "",hreport = "",hprintdate="",hprintby="",hrefer="",hpage="",printdate="",printby="",page="" ,period="" , to="";
		String refer = "RT4003";
		
		
			if(pagelang.equals("eng")){
				hreport = "Report Name :";
				hprintdate = "Print date :";
				hprintby = "Print by :";
				hrefer = "Ref #";
				hpage = "Page";
				header = "Staff Turn Over " +startYear ;
				printdate = car.getEngFull()+ " " + dff.format((Date)gcc.getTime());
				printby = printnameeng;
				page = x+"/"+y;
				period = "For Period of : ";
				to = car.getEngLongMonth(Integer.parseInt(startMonth)) +" "+carr.getEngYYYY()+" To "+car.getEngLongMonth(Integer.parseInt(endMonth))+" "+caar.getEngYYYY();

			}else{
				hreport = "รายงาน :";
				hprintdate = "วันที่พิมพ์ :";
				hprintby = "พิมพ์โดย :";
				hrefer = "อ้างอิง #";
				hpage = "หน้า";
				header = "รายงานสรุปการลาออกแยกตามแผนก ปี " +startYear ;
				printdate = "วัน"+car.getLongThiDOW()+"ที่ "+car.getDate()+ " " + car.getThaiLongMonth() + " พ.ศ. "+ car.getThaiYYYY() +" " +car.getHHMM() + " น.";
				printby = printnameth;
				page = x+"/"+y;
				period = "ช่วงวันที่ : ";
				to = startMonth+" "+startYear+" ถึง  "+endMonth+" "+endYear;

				to = car.getThaiLongMonth(Integer.parseInt(startMonth)) +" "+carr.getThaiYYYY()+" ถึง "+car.getThaiLongMonth(Integer.parseInt(endMonth))+" "+caar.getThaiYYYY();



			}
		
		if(pagelang.equals("eng")){
			cellDetail = new PdfPCell(new Phrase(String.format(engcom, x, y),boldCom));
		}else{
			cellDetail = new PdfPCell(new Phrase(String.format(thacom, x, y),boldCom));
		}
		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(String.format(hreport, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(header, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
		cellDetail.setColspan(9);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(hprintdate, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

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

		cellDetail = new PdfPCell(new Phrase(String.format(hrefer, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(refer, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(hprintby, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingBottom(padding+4f);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(printby, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingBottom(padding+4f);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
		cellDetail.setColspan(7);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(hpage, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingBottom(padding+4f);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(page, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingBottom(padding+4f);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(period, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
		cellDetail.setPaddingBottom(padding+4f);
        detail.addCell(cellDetail);

		cellDetail = new PdfPCell(new Phrase(String.format(to, x, y),Head));
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
		cellDetail.setBorder(Rectangle.NO_BORDER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
		cellDetail.setColspan(10);
        detail.addCell(cellDetail);


	

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

        if(pagelang.equals("eng")){
			cellDetail = new PdfPCell(new Phrase(String.format("Department", x, y),fontHead));
		}else{
			cellDetail = new PdfPCell(new Phrase(String.format("แผนก", x, y),fontHead));
		}
       
		cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
		cellDetail.setColspan(2);
        detail.addCell(cellDetail);
        
		if(pagelang.equals("eng")){
			cellDetail = new PdfPCell(new Phrase(String.format("Number of Employee", x, y),fontHead));
		}else{
			cellDetail = new PdfPCell(new Phrase(String.format("จำนวนพนักงาน(คน)", x, y),fontHead));
		}
        cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
		cellDetail.setPadding(padding);
		cellDetail.setPaddingTop(capHeight - fontSize + padding);
        detail.addCell(cellDetail);

		String stDate = "01-"+startMonth+"-"+startYear;
		String enDate = "01-"+endMonth+"-"+endYear;
		CscCalendar st = new CscCalendar(stDate);
		CscCalendar ed = new CscCalendar(enDate);
		
		int count = 0;
		while(st.beforeEquals(ed)){
			cellDetail = new PdfPCell(new Phrase(String.format(st.getEngShortMonth()+"-"+st.getEngYY(), x, y),fontHead));
			cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
			cellDetail.setPadding(padding);
			cellDetail.setPaddingTop(capHeight - fontSize + padding);
			detail.addCell(cellDetail);
			st.incMonth(1);
			count++;
		}
		if(count!=6){
			while(count<6){
				cellDetail = new PdfPCell(new Phrase(String.format("", x, y),fontHead));
				cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
				cellDetail.setPadding(padding);
				cellDetail.setPaddingTop(capHeight - fontSize + padding);
				detail.addCell(cellDetail);
				count++;
			}
		}
		
        cellDetail = new PdfPCell(new Phrase(String.format("Total", x, y),fontHead));
        cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
		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 String getEmp(String date,String bu4,UProfile up) {
	  String emp = "";
	  CscCalendar csc = new CscCalendar(date);
	  String month = csc.getYear()+"-"+csc.getMM();
	  String sql = "select COUNT(1) as emp from MEMPLOYEE  where RESIGNDATE > '"+month+"-31' and BU4 = '"+bu4+"' ";
	 try{
		
		DataSet ds = new DataSet(sql,up.get("dbname"),"Memployee");
		ds.initConnection(up);
		while (ds.next()) {
			emp = ds.getString("emp");
		}
		ds.closeConnection(); 
	}catch(Exception e) {
		e.printStackTrace();
	}
	return emp;
  }
  private String getOut(String date,String bu4,UProfile up) {
	  String emp = "";
	  CscCalendar csc = new CscCalendar(date);
	  String month = csc.getYear()+"-"+csc.getMM();
	  String sql = "select COUNT(1) as emp from MEMPLOYEE  where RESIGNDATE > '"+month+"-01' and RESIGNDATE <='"+month+"-31' and BU4 = '"+bu4+"' ";
	 try{
		
		DataSet ds = new DataSet(sql,up.get("dbname"),"Memployee");
		ds.initConnection(up);
		while (ds.next()) {
			emp = ds.getString("emp");
		}
		ds.closeConnection(); 
	}catch(Exception e) {
		e.printStackTrace();
	}
	return emp;
  }
%>
  </body>
</html>