List of usage examples for com.itextpdf.text.pdf PdfPCell setPaddingTop
public void setPaddingTop(float paddingTop)
From source file:generatepayslipbyaccz.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . j av a2 s . com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException { // setting the content type response.setContentType("application/pdf"); try { HttpSession session = request.getSession(); if (session.getAttribute("username") != null) { // Get the text that will be added to the PDF String month = request.getParameter("month"); String year = request.getParameter("year"); String id = request.getParameter("empid"); // System.out.println(id); // String text = request.getParameter("text"); // if (text == null || text.trim().length() == 0) { // text = "You didn't enter any text."; // } //String id="Ultimate01"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", ""); PreparedStatement ps = con.prepareStatement("SELECT * from employee where id=?"); ps.setString(1, id); // ps.setString(2, pass); PreparedStatement ps1 = con .prepareStatement("SELECT * from payslip where employeeid=? and month=? and year=?"); ps1.setString(1, id); ps1.setString(2, month); ps1.setString(3, year); PreparedStatement ps2 = con .prepareStatement("SELECT * from `leave` where employeeid=? and month=? and year=?"); ps2.setString(1, id); ps2.setString(2, month); ps2.setString(3, year); ResultSet rs2 = ps2.executeQuery(); rs2.next(); ResultSet rs = ps.executeQuery(); rs.next(); ResultSet rs1 = ps1.executeQuery(); if (rs1.next() == false) { response.sendRedirect("generatepayslipbyaccz.jsp?id=Payslip of " + month + "/" + year + " is not generated OR Record of this Payslip is not available in our Database"); } // step 1 //System.out.println("sssssssssssssssssss"); Document document = new Document(); // step 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11); Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD); Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD); Font font4 = new Font(Font.FontFamily.HELVETICA, 10); Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font font6 = new Font(Font.FontFamily.HELVETICA, 12); //font1.setColor(BaseColor.WHITE); BaseColor myColor = WebColors.getRGBColor("#F78181"); BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA"); //step 3 document.open(); // step 3.5 PdfPTable table1 = new PdfPTable(3); // 1 columns. PdfPCell cell00 = new PdfPCell(new Paragraph("Payslip\nFEB-2015", font2)); cell00.setBorder(PdfPCell.NO_BORDER); cell00.setPaddingTop(18); PdfPCell cell01 = new PdfPCell(new Paragraph("")); cell01.setBorder(PdfPCell.NO_BORDER); Image image = Image.getInstance("cc.jpg"); PdfPCell cell0 = new PdfPCell(image, true); cell0.setBorder(PdfPCell.NO_BORDER); // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT); //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA")); table1.addCell(cell00); table1.addCell(cell01); table1.addCell(cell0); // table1.addCell(cell1); // table.addCell(cell2); // table.addCell(cell3); table1.setWidthPercentage(100); table1.setSpacingAfter(2f); //table1.setSpacingBefore(20f); //table1.setSpacingAfter(10f); document.add(table1); // table1.setWidthPercentage(100); PdfPTable table2 = new PdfPTable(6); // 3 columns. table2.setWidthPercentage(100); PdfPCell cell11 = new PdfPCell(new Paragraph( rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4) + " " + rs.getString(5), font0)); cell11.setColspan(6); //cell11.setBorder(PdfPCell.NO_BORDER); cell11.setLeading(10f, 0f); cell11.setBorderWidth(1f); cell11.setPadding(4); cell11.setBackgroundColor(myColor1); PdfPCell cell12 = new PdfPCell(new Paragraph("Employee Details", font1)); cell12.setColspan(2); cell12.setBorderWidth(1f); cell12.setLeading(10f, 0f); cell12.setPadding(4); cell12.setBackgroundColor(myColor); PdfPCell cell13 = new PdfPCell(new Paragraph("Payment & Leave Details", font1)); cell13.setColspan(2); cell13.setLeading(10f, 0f); cell13.setPadding(4); cell13.setBorderWidth(1f); cell13.setBackgroundColor(myColor); // cell11.setLeading(15f, 1.5f); PdfPCell cell14 = new PdfPCell(new Paragraph("Location Details", font1)); cell14.setColspan(2); cell14.setLeading(10f, 0f); cell14.setPadding(4); cell14.setBorderWidth(1f); cell14.setBackgroundColor(myColor); // PdfPTable nestedTable1 = new PdfPTable(2); // nestedTable1.addCell(new Paragraph("Emp No.")); // nestedTable1.addCell(new Paragraph("379666")); // cell41.addElement(nestedTable1); table2.addCell(cell11); table2.addCell(cell12); table2.addCell(cell13); table2.addCell(cell14); PdfPCell cell15 = new PdfPCell(new Paragraph("Emp ID.", font3)); //cell15.setLeading(10f, 0f); cell15.setPadding(3); cell15.setBorderWidth(1f); cell15.setBackgroundColor(myColor1); PdfPCell cell16 = new PdfPCell(new Paragraph(rs.getString(1), font4)); // cell16.setLeading(10f, 0f); cell16.setPadding(3); cell16.setBorderWidth(1f); cell16.setBackgroundColor(myColor1); PdfPCell cell17 = new PdfPCell(new Paragraph("Bank Name", font3)); //cell17.setLeading(10f, 0f); cell17.setPadding(3); cell17.setBorderWidth(1f); cell17.setBackgroundColor(myColor1); PdfPCell cell18 = new PdfPCell(new Paragraph(rs.getString(11), font4)); //cell18.setLeading(10f, 0f); cell18.setPadding(3); cell18.setBorderWidth(1f); cell18.setBackgroundColor(myColor1); PdfPCell cell19 = new PdfPCell(new Paragraph("Location", font3)); //cell19.setLeading(10f, 0f); cell19.setPadding(3); cell19.setBorderWidth(1f); cell19.setBackgroundColor(myColor1); PdfPCell cell20 = new PdfPCell(new Paragraph(rs.getString(13), font4)); //cell20.setLeading(10f, 0f); cell20.setPadding(3); cell20.setBorderWidth(1f); cell20.setBackgroundColor(myColor1); table2.addCell(cell15); table2.addCell(cell16); table2.addCell(cell17); table2.addCell(cell18); table2.addCell(cell19); table2.addCell(cell20); PdfPCell cell21 = new PdfPCell(new Paragraph("Dsgn.", font3)); //cell21.setLeading(10f, 0f); cell21.setPadding(3); cell21.setBorderWidth(1f); cell21.setBackgroundColor(myColor1); PdfPCell cell22 = new PdfPCell(new Paragraph(rs.getString(9), font4)); // cell22.setLeading(10f, 0f); cell22.setPadding(3); cell22.setBorderWidth(1f); cell22.setBackgroundColor(myColor1); PdfPCell cell23 = new PdfPCell(new Paragraph("Acc No.", font3)); //cell23.setLeading(10f, 0f); cell23.setPadding(3); cell23.setBorderWidth(1f); cell23.setBackgroundColor(myColor1); int accno = Integer.parseInt(rs.getString(12)); String accno1[] = new String[4]; for (int i = 0; i < 4; i++) { accno1[i] = Integer.toString(accno % 10); accno /= 10; } PdfPCell cell24 = new PdfPCell(new Paragraph( "XXXXXXX" + accno1[3] + "" + accno1[2] + "" + accno1[1] + "" + accno1[0], font4)); //cell24.setLeading(10f, 0f); cell24.setPadding(3); cell24.setBorderWidth(1f); cell24.setBackgroundColor(myColor1); PdfPCell cell25 = new PdfPCell(new Paragraph("Base Br.", font3)); //cell25.setLeading(10f, 0f); cell25.setPadding(3); cell25.setBorderWidth(1f); cell25.setBackgroundColor(myColor1); PdfPCell cell26 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell26.setLeading(10f, 0f); cell26.setPadding(3); cell26.setBorderWidth(1f); cell26.setBackgroundColor(myColor1); table2.addCell(cell21); table2.addCell(cell22); table2.addCell(cell23); table2.addCell(cell24); table2.addCell(cell25); table2.addCell(cell26); PdfPCell cell27 = new PdfPCell(new Paragraph("Grade", font3)); //cell27.setLeading(10f, 0f); cell27.setPadding(3); cell27.setBorderWidth(1f); cell27.setBackgroundColor(myColor1); PdfPCell cell28 = new PdfPCell(new Paragraph("C2", font4)); // cell28.setLeading(10f, 0f); cell28.setPadding(3); cell28.setBorderWidth(1f); cell28.setBackgroundColor(myColor1); PdfPCell cell29 = new PdfPCell(new Paragraph("Days paid", font3)); //cell29.setLeading(10f, 0f); cell29.setPadding(3); cell29.setBorderWidth(1f); cell29.setBackgroundColor(myColor1); PdfPCell cell30 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt(5)), font4)); //cell30.setLeading(10f, 0f); cell30.setPadding(3); cell30.setBorderWidth(1f); cell30.setBackgroundColor(myColor1); PdfPCell cell31 = new PdfPCell(new Paragraph("Depute Br.", font3)); //cell31.setLeading(10f, 0f); cell31.setPadding(3); cell31.setBorderWidth(1f); cell31.setBackgroundColor(myColor1); PdfPCell cell32 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell32.setLeading(10f, 0f); cell32.setPadding(3); cell32.setBorderWidth(1f); cell32.setBackgroundColor(myColor1); table2.addCell(cell27); table2.addCell(cell28); table2.addCell(cell29); table2.addCell(cell30); table2.addCell(cell31); table2.addCell(cell32); PdfPCell cell33 = new PdfPCell(new Paragraph("PAN", font3)); //cell33.setLeading(10f, 0f); cell33.setPadding(3); cell33.setBorderWidth(1f); cell33.setBackgroundColor(myColor1); PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E", font4)); // cell34.setLeading(10f, 0f); cell34.setPadding(3); cell34.setBorderWidth(1f); cell34.setBackgroundColor(myColor1); PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance", font3)); //cell35.setLeading(10f, 0f); cell35.setPadding(3); cell35.setBorderWidth(1f); cell35.setBackgroundColor(myColor1); // PdfPCell cell36 = new PdfPCell(new Paragraph("EL X SL X CL X",font4)); PdfPCell cell36 = new PdfPCell(new Paragraph( "EL " + rs2.getInt(1) + " SL " + rs2.getInt(2) + " CL " + rs2.getInt(3), font4)); //cell36.setLeading(10f, 0f); cell36.setPadding(3); cell36.setBorderWidth(1f); cell36.setBackgroundColor(myColor1); PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON", font3)); //cell37.setLeading(10f, 0f); cell37.setPadding(3); cell37.setBorderWidth(1f); cell37.setBackgroundColor(myColor1); PdfPCell cell38 = new PdfPCell(new Paragraph("2616141", font4)); //cell38.setLeading(10f, 0f); cell38.setPadding(3); cell38.setBorderWidth(1f); cell38.setBackgroundColor(myColor1); table2.addCell(cell33); table2.addCell(cell34); table2.addCell(cell35); table2.addCell(cell36); table2.addCell(cell37); table2.addCell(cell38); table2.setSpacingAfter(12f); document.add(table2); PdfPTable table3 = new PdfPTable(5); // 5 columns. table3.setWidthPercentage(100); PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings", font1)); cell39.setLeading(10f, 0f); cell39.setPadding(4); cell39.setBorderWidth(1f); cell39.setBackgroundColor(myColor); PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)", font1)); cell40.setLeading(10f, 0f); cell40.setPadding(4); cell40.setBorderWidth(1f); cell40.setBackgroundColor(myColor); PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)", font1)); cell41.setLeading(10f, 0f); cell41.setPadding(4); cell41.setBorderWidth(1f); cell41.setBackgroundColor(myColor); PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions", font1)); cell42.setLeading(10f, 0f); cell42.setPadding(4); cell42.setBorderWidth(1f); cell42.setBackgroundColor(myColor); PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)", font1)); cell43.setLeading(10f, 0f); cell43.setPadding(4); cell43.setBorderWidth(1f); cell43.setBackgroundColor(myColor); table3.addCell(cell39); table3.addCell(cell40); table3.addCell(cell41); table3.addCell(cell42); table3.addCell(cell43); String[] sal = new String[10]; sal[0] = "Basic Salary"; sal[1] = "House Rent Allowance"; sal[2] = "Medical Allowance"; sal[3] = "Travelling Allowance"; sal[4] = "Personal Allowance"; sal[5] = "City Allowance"; sal[6] = "Performance Pay"; sal[7] = "Provident Fund"; sal[8] = "Professional Tax"; sal[9] = "Extra Leaves"; Float[] val = new Float[10]; val[0] = rs1.getFloat(4); val[1] = 6000.00f; val[2] = 1000.00f; val[3] = 1000.00f; val[4] = val[0] / 2; val[5] = 1000.00f; val[6] = val[4]; val[7] = val[0] * 12 / 100; val[8] = 0.00f; if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) { val[8] = (val[0] + val[4] + val[6]) / 10; } val[9] = 0.0f; if (rs2.getInt(1) < 0) val[9] -= (rs2.getInt(1) * val[0]) / 30; if (rs2.getInt(2) < 0) val[9] -= rs2.getInt(2) * val[0] / 30; if (rs2.getInt(3) < 0) val[9] -= rs2.getInt(3) * val[0] / 30; for (int i = 0; i < 7; i++) { PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i], font3)); //cell27.setLeading(10f, 0f); cell44.setPadding(3); cell44.setBorderWidth(1f); cell44.setBackgroundColor(myColor1); PdfPCell cell45 = new PdfPCell(new Paragraph("", font4)); // cell45.setLeading(10f, 0f); cell45.setPadding(3); cell45.setBorderWidth(1f); cell45.setBackgroundColor(myColor1); PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(), font3)); //cell46.setLeading(10f, 0f); cell46.setHorizontalAlignment(Element.ALIGN_RIGHT); cell46.setPadding(3); cell46.setBorderWidth(1f); cell46.setBackgroundColor(myColor1); table3.addCell(cell44); table3.addCell(cell45); table3.addCell(cell46); if (i == 0 || i == 1 || i == 2) { PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7 + i], font4)); //cell47.setLeading(10f, 0f); cell47.setPadding(3); cell47.setBorderWidth(1f); cell47.setBackgroundColor(myColor1); table3.addCell(cell47); PdfPCell cell48 = new PdfPCell(new Paragraph(val[i + 7].toString(), font3)); //cell48.setLeading(10f, 0f); cell48.setHorizontalAlignment(Element.ALIGN_RIGHT); cell48.setPadding(3); cell48.setBorderWidth(1f); cell48.setBackgroundColor(myColor1); table3.addCell(cell48); } else { PdfPCell cell47 = new PdfPCell(new Paragraph("", font4)); cell47.setBorder(PdfPCell.NO_BORDER); cell47.setBorderWidthRight(1f); cell47.setColspan(2); table3.addCell(cell47); } } PdfPCell cell48 = new PdfPCell(new Paragraph("", font4)); //cell48.setBorder(PdfPCell.NO_BORDER); cell48.setColspan(3); table3.addCell(cell48); PdfPCell cell49 = new PdfPCell(new Paragraph("", font4)); //cell49.setBorder(PdfPCell.NO_BORDER); cell49.setColspan(2); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)", font3)); //cell27.setLeading(10f, 0f); cell50.setColspan(2); cell50.setPadding(3); cell50.setBorderWidth(1f); cell50.setBackgroundColor(myColor1); table3.addCell(cell50); float a = 0.0f; for (int i = 0; i < 7; i++) { a += val[i]; } PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a), font3)); //cell27.setLeading(10f, 0f); cell55.setPadding(3); cell55.setHorizontalAlignment(Element.ALIGN_RIGHT); cell55.setBorderWidth(1f); cell55.setBackgroundColor(myColor1); table3.addCell(cell55); PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions", font3)); //cell27.setLeading(10f, 0f); //cell51.setColspan(3); cell51.setPadding(3); cell51.setBorderWidth(1f); cell51.setBackgroundColor(myColor1); table3.addCell(cell51); float b = val[7] + val[8] + val[9]; PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b), font3)); //cell27.setLeading(10f, 0f); //cell56.setColspan(3); cell56.setPadding(3); cell56.setHorizontalAlignment(Element.ALIGN_RIGHT); cell56.setBorderWidth(1f); cell56.setBackgroundColor(myColor1); table3.addCell(cell56); table3.setSpacingAfter(12f); document.add(table3); PdfPTable table4 = new PdfPTable(5); // 2 columns. table4.setWidthPercentage(100); PdfPCell cell54 = new PdfPCell(new Paragraph("", font3)); cell54.setBorder(PdfPCell.NO_BORDER); cell54.setColspan(3); table4.addCell(cell54); PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay", font5)); cell52.setLeading(10f, 0f); // cell52.setBorder(PdfPCell.ALIGN_CENTER); cell52.setHorizontalAlignment(Element.ALIGN_LEFT); cell52.setVerticalAlignment(Element.ALIGN_CENTER); cell52.setPadding(6f); cell52.setBorderWidth(1f); cell52.setBackgroundColor(myColor); table4.addCell(cell52); PdfPCell cell53 = new PdfPCell(new Paragraph("" + (a - b), font6)); cell53.setLeading(10f, 0f); cell53.setPadding(6f); cell53.setHorizontalAlignment(Element.ALIGN_CENTER); cell53.setVerticalAlignment(Element.ALIGN_CENTER); cell53.setBorderWidth(1f); table4.addCell(cell53); document.add(table4); // step 4 // document.add(new Paragraph(String.format( // "You have submitted the following text using the %s method:%s", // request.getMethod(),uname))); // document.add(new Paragraph(text)); // step 5 document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } else { response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first"); } } catch (Exception e) { // throw new IOException(e.getMessage()); System.out.println(e); System.out.println("sssssssssssssssssss"); } }
From source file:generatepayslip.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . ja va 2 s . com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException { // setting the content type response.setContentType("application/pdf"); try { HttpSession session = request.getSession(); if (session.getAttribute("username") != null) { // Get the text that will be added to the PDF String month = request.getParameter("month"); String year = request.getParameter("year"); String id = (String) session.getAttribute("id"); // System.out.println(id); // String text = request.getParameter("text"); // if (text == null || text.trim().length() == 0) { // text = "You didn't enter any text."; // } //String id="Ultimate01"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", ""); PreparedStatement ps = con.prepareStatement("SELECT * from employee where id=?"); ps.setString(1, id); // ps.setString(2, pass); PreparedStatement ps1 = con .prepareStatement("SELECT * from payslip where employeeid=? and month=? and year=?"); ps1.setString(1, id); ps1.setString(2, month); ps1.setString(3, year); // PreparedStatement ps2 = con.prepareStatement("SELECT * from leave "); PreparedStatement ps2 = con .prepareStatement("SELECT * from `leave` where employeeid=? and month=? and year=?"); ps2.setString(1, id); ps2.setString(2, month); ps2.setString(3, year); // ResultSet rs = ps.executeQuery(); rs.next(); ResultSet rs1 = ps1.executeQuery(); ResultSet rs2 = ps2.executeQuery(); rs2.next(); if (rs1.next() == false) { response.sendRedirect("generatepayslip.jsp?id=Payslip of " + month + "/" + year + " is not generated OR Record of this Payslip is not available in our Database"); } // step 1 //System.out.println("sssssssssssssssssss"); Document document = new Document(); // step 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11); Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD); Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD); Font font4 = new Font(Font.FontFamily.HELVETICA, 10); Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font font6 = new Font(Font.FontFamily.HELVETICA, 12); //font1.setColor(BaseColor.WHITE); BaseColor myColor = WebColors.getRGBColor("#F78181"); BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA"); //step 3 document.open(); // step 3.5 PdfPTable table1 = new PdfPTable(3); // 1 columns. PdfPCell cell00 = new PdfPCell(new Paragraph("Payslip\nFEB-2015", font2)); cell00.setBorder(PdfPCell.NO_BORDER); cell00.setPaddingTop(18); PdfPCell cell01 = new PdfPCell(new Paragraph("")); cell01.setBorder(PdfPCell.NO_BORDER); Image image = Image.getInstance("cc.jpg"); PdfPCell cell0 = new PdfPCell(image, true); cell0.setBorder(PdfPCell.NO_BORDER); // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT); //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA")); table1.addCell(cell00); table1.addCell(cell01); table1.addCell(cell0); // table1.addCell(cell1); // table.addCell(cell2); // table.addCell(cell3); table1.setWidthPercentage(100); table1.setSpacingAfter(2f); //table1.setSpacingBefore(20f); //table1.setSpacingAfter(10f); document.add(table1); // table1.setWidthPercentage(100); PdfPTable table2 = new PdfPTable(6); // 3 columns. table2.setWidthPercentage(100); PdfPCell cell11 = new PdfPCell(new Paragraph((String) session.getAttribute("username"), font0)); cell11.setColspan(6); //cell11.setBorder(PdfPCell.NO_BORDER); cell11.setLeading(10f, 0f); cell11.setBorderWidth(1f); cell11.setPadding(4); cell11.setBackgroundColor(myColor1); PdfPCell cell12 = new PdfPCell(new Paragraph("Employee Details", font1)); cell12.setColspan(2); cell12.setBorderWidth(1f); cell12.setLeading(10f, 0f); cell12.setPadding(4); cell12.setBackgroundColor(myColor); PdfPCell cell13 = new PdfPCell(new Paragraph("Payment & Leave Details", font1)); cell13.setColspan(2); cell13.setLeading(10f, 0f); cell13.setPadding(4); cell13.setBorderWidth(1f); cell13.setBackgroundColor(myColor); // cell11.setLeading(15f, 1.5f); PdfPCell cell14 = new PdfPCell(new Paragraph("Location Details", font1)); cell14.setColspan(2); cell14.setLeading(10f, 0f); cell14.setPadding(4); cell14.setBorderWidth(1f); cell14.setBackgroundColor(myColor); // PdfPTable nestedTable1 = new PdfPTable(2); // nestedTable1.addCell(new Paragraph("Emp No.")); // nestedTable1.addCell(new Paragraph("379666")); // cell41.addElement(nestedTable1); table2.addCell(cell11); table2.addCell(cell12); table2.addCell(cell13); table2.addCell(cell14); PdfPCell cell15 = new PdfPCell(new Paragraph("Emp ID.", font3)); //cell15.setLeading(10f, 0f); cell15.setPadding(3); cell15.setBorderWidth(1f); cell15.setBackgroundColor(myColor1); PdfPCell cell16 = new PdfPCell(new Paragraph(rs.getString(1), font4)); // cell16.setLeading(10f, 0f); cell16.setPadding(3); cell16.setBorderWidth(1f); cell16.setBackgroundColor(myColor1); PdfPCell cell17 = new PdfPCell(new Paragraph("Bank Name", font3)); //cell17.setLeading(10f, 0f); cell17.setPadding(3); cell17.setBorderWidth(1f); cell17.setBackgroundColor(myColor1); PdfPCell cell18 = new PdfPCell(new Paragraph(rs.getString(11), font4)); //cell18.setLeading(10f, 0f); cell18.setPadding(3); cell18.setBorderWidth(1f); cell18.setBackgroundColor(myColor1); PdfPCell cell19 = new PdfPCell(new Paragraph("Location", font3)); //cell19.setLeading(10f, 0f); cell19.setPadding(3); cell19.setBorderWidth(1f); cell19.setBackgroundColor(myColor1); PdfPCell cell20 = new PdfPCell(new Paragraph(rs.getString(13), font4)); //cell20.setLeading(10f, 0f); cell20.setPadding(3); cell20.setBorderWidth(1f); cell20.setBackgroundColor(myColor1); table2.addCell(cell15); table2.addCell(cell16); table2.addCell(cell17); table2.addCell(cell18); table2.addCell(cell19); table2.addCell(cell20); PdfPCell cell21 = new PdfPCell(new Paragraph("Dsgn.", font3)); //cell21.setLeading(10f, 0f); cell21.setPadding(3); cell21.setBorderWidth(1f); cell21.setBackgroundColor(myColor1); PdfPCell cell22 = new PdfPCell(new Paragraph(rs.getString(9), font4)); // cell22.setLeading(10f, 0f); cell22.setPadding(3); cell22.setBorderWidth(1f); cell22.setBackgroundColor(myColor1); PdfPCell cell23 = new PdfPCell(new Paragraph("Acc No.", font3)); //cell23.setLeading(10f, 0f); cell23.setPadding(3); cell23.setBorderWidth(1f); cell23.setBackgroundColor(myColor1); int accno = Integer.parseInt(rs.getString(12)); String accno1[] = new String[4]; for (int i = 0; i < 4; i++) { accno1[i] = Integer.toString(accno % 10); accno /= 10; } PdfPCell cell24 = new PdfPCell(new Paragraph( "XXXXXXX" + accno1[3] + "" + accno1[2] + "" + accno1[1] + "" + accno1[0], font4)); //cell24.setLeading(10f, 0f); cell24.setPadding(3); cell24.setBorderWidth(1f); cell24.setBackgroundColor(myColor1); PdfPCell cell25 = new PdfPCell(new Paragraph("Base Br.", font3)); //cell25.setLeading(10f, 0f); cell25.setPadding(3); cell25.setBorderWidth(1f); cell25.setBackgroundColor(myColor1); PdfPCell cell26 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell26.setLeading(10f, 0f); cell26.setPadding(3); cell26.setBorderWidth(1f); cell26.setBackgroundColor(myColor1); table2.addCell(cell21); table2.addCell(cell22); table2.addCell(cell23); table2.addCell(cell24); table2.addCell(cell25); table2.addCell(cell26); PdfPCell cell27 = new PdfPCell(new Paragraph("Grade", font3)); //cell27.setLeading(10f, 0f); cell27.setPadding(3); cell27.setBorderWidth(1f); cell27.setBackgroundColor(myColor1); PdfPCell cell28 = new PdfPCell(new Paragraph("C2", font4)); // cell28.setLeading(10f, 0f); cell28.setPadding(3); cell28.setBorderWidth(1f); cell28.setBackgroundColor(myColor1); PdfPCell cell29 = new PdfPCell(new Paragraph("Days paid", font3)); //cell29.setLeading(10f, 0f); cell29.setPadding(3); cell29.setBorderWidth(1f); cell29.setBackgroundColor(myColor1); PdfPCell cell30 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt(5)), font4)); //cell30.setLeading(10f, 0f); cell30.setPadding(3); cell30.setBorderWidth(1f); cell30.setBackgroundColor(myColor1); PdfPCell cell31 = new PdfPCell(new Paragraph("Depute Br.", font3)); //cell31.setLeading(10f, 0f); cell31.setPadding(3); cell31.setBorderWidth(1f); cell31.setBackgroundColor(myColor1); PdfPCell cell32 = new PdfPCell(new Paragraph("CC - Ahmedabad", font4)); //cell32.setLeading(10f, 0f); cell32.setPadding(3); cell32.setBorderWidth(1f); cell32.setBackgroundColor(myColor1); table2.addCell(cell27); table2.addCell(cell28); table2.addCell(cell29); table2.addCell(cell30); table2.addCell(cell31); table2.addCell(cell32); PdfPCell cell33 = new PdfPCell(new Paragraph("PAN", font3)); //cell33.setLeading(10f, 0f); cell33.setPadding(3); cell33.setBorderWidth(1f); cell33.setBackgroundColor(myColor1); PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E", font4)); // cell34.setLeading(10f, 0f); cell34.setPadding(3); cell34.setBorderWidth(1f); cell34.setBackgroundColor(myColor1); PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance", font3)); //cell35.setLeading(10f, 0f); cell35.setPadding(3); cell35.setBorderWidth(1f); cell35.setBackgroundColor(myColor1); PdfPCell cell36 = new PdfPCell(new Paragraph( "EL " + rs2.getInt(1) + " SL " + rs2.getInt(2) + " CL " + rs2.getInt(3), font4)); // PdfPCell cell36 = new PdfPCell(new Paragraph("EL "+rs2.getInt(2),font4)); //cell36.setLeading(10f, 0f);rs2.getInt(1) cell36.setPadding(3); cell36.setBorderWidth(1f); cell36.setBackgroundColor(myColor1); PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON", font3)); //cell37.setLeading(10f, 0f); cell37.setPadding(3); cell37.setBorderWidth(1f); cell37.setBackgroundColor(myColor1); PdfPCell cell38 = new PdfPCell(new Paragraph("2616141", font4)); //cell38.setLeading(10f, 0f); cell38.setPadding(3); cell38.setBorderWidth(1f); cell38.setBackgroundColor(myColor1); table2.addCell(cell33); table2.addCell(cell34); table2.addCell(cell35); table2.addCell(cell36); table2.addCell(cell37); table2.addCell(cell38); table2.setSpacingAfter(12f); document.add(table2); PdfPTable table3 = new PdfPTable(5); // 5 columns. table3.setWidthPercentage(100); PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings", font1)); cell39.setLeading(10f, 0f); cell39.setPadding(4); cell39.setBorderWidth(1f); cell39.setBackgroundColor(myColor); PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)", font1)); cell40.setLeading(10f, 0f); cell40.setPadding(4); cell40.setBorderWidth(1f); cell40.setBackgroundColor(myColor); PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)", font1)); cell41.setLeading(10f, 0f); cell41.setPadding(4); cell41.setBorderWidth(1f); cell41.setBackgroundColor(myColor); PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions", font1)); cell42.setLeading(10f, 0f); cell42.setPadding(4); cell42.setBorderWidth(1f); cell42.setBackgroundColor(myColor); PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)", font1)); cell43.setLeading(10f, 0f); cell43.setPadding(4); cell43.setBorderWidth(1f); cell43.setBackgroundColor(myColor); table3.addCell(cell39); table3.addCell(cell40); table3.addCell(cell41); table3.addCell(cell42); table3.addCell(cell43); String[] sal = new String[10]; sal[0] = "Basic Salary"; sal[1] = "House Rent Allowance"; sal[2] = "Medical Allowance"; sal[3] = "Travelling Allowance"; sal[4] = "Personal Allowance"; sal[5] = "City Allowance"; sal[6] = "Performance Pay"; sal[7] = "Provident Fund"; sal[8] = "Professional Tax"; sal[9] = "Extra Leaves"; Float[] val = new Float[10]; val[0] = rs1.getFloat(4); val[1] = 6000.00f; val[2] = 1000.00f; val[3] = 1000.00f; val[4] = val[0] / 2; val[5] = 1000.00f; val[6] = val[4]; val[7] = val[0] * 12 / 100; val[8] = 0.00f; if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) { val[8] = (val[0] + val[4] + val[6]) / 10; } val[9] = 0.0f; if (rs2.getInt(1) < 0) val[9] -= (rs2.getInt(1) * val[0]) / 30; if (rs2.getInt(2) < 0) val[9] -= rs2.getInt(2) * val[0] / 30; if (rs2.getInt(3) < 0) val[9] -= rs2.getInt(3) * val[0] / 30; for (int i = 0; i < 7; i++) { PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i], font3)); //cell27.setLeading(10f, 0f); cell44.setPadding(3); cell44.setBorderWidth(1f); cell44.setBackgroundColor(myColor1); PdfPCell cell45 = new PdfPCell(new Paragraph("", font4)); // cell45.setLeading(10f, 0f); cell45.setPadding(3); cell45.setBorderWidth(1f); cell45.setBackgroundColor(myColor1); PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(), font3)); //cell46.setLeading(10f, 0f); cell46.setHorizontalAlignment(Element.ALIGN_RIGHT); cell46.setPadding(3); cell46.setBorderWidth(1f); cell46.setBackgroundColor(myColor1); table3.addCell(cell44); table3.addCell(cell45); table3.addCell(cell46); if (i == 0 || i == 1 || i == 2) { PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7 + i], font4)); //cell47.setLeading(10f, 0f); cell47.setPadding(3); cell47.setBorderWidth(1f); cell47.setBackgroundColor(myColor1); table3.addCell(cell47); PdfPCell cell48 = new PdfPCell(new Paragraph(val[i + 7].toString(), font3)); //cell48.setLeading(10f, 0f); cell48.setHorizontalAlignment(Element.ALIGN_RIGHT); cell48.setPadding(3); cell48.setBorderWidth(1f); cell48.setBackgroundColor(myColor1); table3.addCell(cell48); } else { PdfPCell cell47 = new PdfPCell(new Paragraph("", font4)); cell47.setBorder(PdfPCell.NO_BORDER); cell47.setBorderWidthRight(1f); cell47.setColspan(2); table3.addCell(cell47); } } PdfPCell cell48 = new PdfPCell(new Paragraph("", font4)); //cell48.setBorder(PdfPCell.NO_BORDER); cell48.setColspan(3); table3.addCell(cell48); PdfPCell cell49 = new PdfPCell(new Paragraph("", font4)); //cell49.setBorder(PdfPCell.NO_BORDER); cell49.setColspan(2); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)", font3)); //cell27.setLeading(10f, 0f); cell50.setColspan(2); cell50.setPadding(3); cell50.setBorderWidth(1f); cell50.setBackgroundColor(myColor1); table3.addCell(cell50); float a = 0.0f; for (int i = 0; i < 7; i++) { a += val[i]; } PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a), font3)); //cell27.setLeading(10f, 0f); cell55.setPadding(3); cell55.setHorizontalAlignment(Element.ALIGN_RIGHT); cell55.setBorderWidth(1f); cell55.setBackgroundColor(myColor1); table3.addCell(cell55); PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions", font3)); //cell27.setLeading(10f, 0f); //cell51.setColspan(3); cell51.setPadding(3); cell51.setBorderWidth(1f); cell51.setBackgroundColor(myColor1); table3.addCell(cell51); float b = val[7] + val[8] + val[9]; PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b), font3)); //cell27.setLeading(10f, 0f); //cell56.setColspan(3); cell56.setPadding(3); cell56.setHorizontalAlignment(Element.ALIGN_RIGHT); cell56.setBorderWidth(1f); cell56.setBackgroundColor(myColor1); table3.addCell(cell56); table3.setSpacingAfter(12f); document.add(table3); PdfPTable table4 = new PdfPTable(5); // 2 columns. table4.setWidthPercentage(100); PdfPCell cell54 = new PdfPCell(new Paragraph("", font3)); cell54.setBorder(PdfPCell.NO_BORDER); cell54.setColspan(3); table4.addCell(cell54); PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay", font5)); cell52.setLeading(10f, 0f); // cell52.setBorder(PdfPCell.ALIGN_CENTER); cell52.setHorizontalAlignment(Element.ALIGN_LEFT); cell52.setVerticalAlignment(Element.ALIGN_CENTER); cell52.setPadding(6f); cell52.setBorderWidth(1f); cell52.setBackgroundColor(myColor); table4.addCell(cell52); PdfPCell cell53 = new PdfPCell(new Paragraph("" + (a - b), font6)); cell53.setLeading(10f, 0f); cell53.setPadding(6f); cell53.setHorizontalAlignment(Element.ALIGN_CENTER); cell53.setVerticalAlignment(Element.ALIGN_CENTER); cell53.setBorderWidth(1f); table4.addCell(cell53); document.add(table4); // step 4 // document.add(new Paragraph(String.format( // "You have submitted the following text using the %s method:%s", // request.getMethod(),uname))); // document.add(new Paragraph(text)); // step 5 document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } else { response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first"); } } catch (Exception e) { // throw new IOException(e.getMessage()); System.out.println(e); System.out.println("sssssssssssssssssss"); } }
From source file:generatereportbyaccz.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a v a2s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException { // setting the content type response.setContentType("application/pdf"); try { HttpSession session = request.getSession(); if (session.getAttribute("username") != null) { // Get the text that will be added to the PDF String month = request.getParameter("month"); String year = request.getParameter("year"); //String id=request.getParameter("empid"); // System.out.println(id); // String text = request.getParameter("text"); // if (text == null || text.trim().length() == 0) { // text = "You didn't enter any text."; // } //String id="Ultimate01"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", ""); PreparedStatement ps = con .prepareStatement("SELECT SUM(basicsalary) as sum1 FROM payslip where month=? and year=?"); ps.setString(1, month); ps.setString(2, year); System.out.println("hey1"); PreparedStatement ps1 = con.prepareStatement( "SELECT COUNT(DISTINCT employeeid) as emps FROM payslip where month=? and year=?"); ps1.setString(1, month); ps1.setString(2, year); System.out.println("hey1"); ResultSet rs = ps.executeQuery(); //System.out.println(rs.getInt(1)); rs.next(); // System.out.println(rs.getInt("sum1")); ResultSet rs1 = ps1.executeQuery(); rs1.next(); if (rs.getFloat("sum1") == 0.0 && rs1.getFloat("emps") == 0.0) { response.sendRedirect("generatereportbyaccz.jsp?id=Report of " + month + "/" + year + " is not generated OR Record of this Report is not available in our Database"); } // step 1 Float[] val = new Float[9]; val[0] = rs.getFloat("sum1"); val[1] = 6000.00f * rs1.getFloat("emps"); val[2] = 1000.00f * rs1.getFloat("emps"); val[3] = 1000.00f * rs1.getFloat("emps"); val[4] = val[0] / 2; val[5] = 1000.00f * rs1.getFloat("emps"); val[6] = val[4]; val[7] = val[0] * 12 / 100; val[8] = 0.00f; if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) { val[8] = (val[0] + val[4] + val[6]) / 10; } //System.out.println("sssssssssssssssssss"); Document document = new Document(); // step 2 ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11); Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD); Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD); Font font4 = new Font(Font.FontFamily.HELVETICA, 10); Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font font6 = new Font(Font.FontFamily.HELVETICA, 12); //font1.setColor(BaseColor.WHITE); BaseColor myColor = WebColors.getRGBColor("#F78181"); BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA"); //step 3 document.open(); // step 3.5 PdfPTable table1 = new PdfPTable(3); // 1 columns. // table1.setWidthPercentage(75); PdfPCell cell00 = new PdfPCell(new Paragraph("Monthly Payroll Summary\nFEB-2015", font2)); cell00.setBorder(PdfPCell.NO_BORDER); cell00.setPaddingTop(18); cell00.setColspan(2); Image image = Image.getInstance("cc.jpg"); PdfPCell cell0 = new PdfPCell(image, true); cell0.setBorder(PdfPCell.NO_BORDER); // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT); //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA")); table1.addCell(cell00); // table1.addCell(cell0); table1.addCell(cell0); // table1.addCell(cell1); // table.addCell(cell2); // table.addCell(cell3); table1.setWidthPercentage(100); table1.setSpacingAfter(8f); //table1.setSpacingBefore(20f); //table1.setSpacingAfter(10f); document.add(table1); // table1.setWidthPercentage(100); PdfPTable table21 = new PdfPTable(2); // 3 columns. table21.setWidthPercentage(100); PdfPCell cell151 = new PdfPCell(new Paragraph("Total Number of Employees", font3)); //cell15.setLeading(10f, 0f); cell151.setPadding(3); cell151.setBorderWidth(1f); cell151.setBackgroundColor(myColor1); PdfPCell cell161 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt("emps")), font4)); // cell16.setLeading(10f, 0f); cell161.setPadding(3); cell161.setBorderWidth(1f); cell161.setBackgroundColor(myColor1); table21.addCell(cell151); table21.addCell(cell161); table21.setSpacingAfter(12f); document.add(table21); PdfPTable table2 = new PdfPTable(2); // 3 columns. table2.setWidthPercentage(100); PdfPCell cell15 = new PdfPCell(new Paragraph("Total Basic Salary", font3)); //cell15.setLeading(10f, 0f); cell15.setPadding(3); cell15.setBorderWidth(1f); cell15.setBackgroundColor(myColor1); PdfPCell cell16 = new PdfPCell(new Paragraph(Float.toString(val[0]), font4)); // cell16.setLeading(10f, 0f); cell16.setPadding(3); cell16.setBorderWidth(1f); cell16.setBackgroundColor(myColor1); PdfPCell cell17 = new PdfPCell(new Paragraph("Total House Rent Allowance", font3)); //cell17.setLeading(10f, 0f); cell17.setPadding(3); cell17.setBorderWidth(1f); cell17.setBackgroundColor(myColor1); PdfPCell cell18 = new PdfPCell(new Paragraph(Float.toString(val[1]), font4)); //cell18.setLeading(10f, 0f); cell18.setPadding(3); cell18.setBorderWidth(1f); cell18.setBackgroundColor(myColor1); PdfPCell cell19 = new PdfPCell(new Paragraph("Total Medical Allowance", font3)); //cell19.setLeading(10f, 0f); cell19.setPadding(3); cell19.setBorderWidth(1f); cell19.setBackgroundColor(myColor1); PdfPCell cell20 = new PdfPCell(new Paragraph(Float.toString(val[2]), font4)); //cell20.setLeading(10f, 0f); cell20.setPadding(3); cell20.setBorderWidth(1f); cell20.setBackgroundColor(myColor1); table2.addCell(cell15); table2.addCell(cell16); table2.addCell(cell17); table2.addCell(cell18); table2.addCell(cell19); table2.addCell(cell20); PdfPCell cell21 = new PdfPCell(new Paragraph("Total Travelling Allowance", font3)); //cell21.setLeading(10f, 0f); cell21.setPadding(3); cell21.setBorderWidth(1f); cell21.setBackgroundColor(myColor1); PdfPCell cell22 = new PdfPCell(new Paragraph(Float.toString(val[3]), font4)); // cell22.setLeading(10f, 0f); cell22.setPadding(3); cell22.setBorderWidth(1f); cell22.setBackgroundColor(myColor1); PdfPCell cell23 = new PdfPCell(new Paragraph("Total Personal Allowance", font3)); //cell23.setLeading(10f, 0f); cell23.setPadding(3); cell23.setBorderWidth(1f); cell23.setBackgroundColor(myColor1); PdfPCell cell24 = new PdfPCell(new Paragraph(Float.toString(val[4]), font4)); //cell24.setLeading(10f, 0f); cell24.setPadding(3); cell24.setBorderWidth(1f); cell24.setBackgroundColor(myColor1); PdfPCell cell25 = new PdfPCell(new Paragraph("Total City Allowance", font3)); //cell25.setLeading(10f, 0f); cell25.setPadding(3); cell25.setBorderWidth(1f); cell25.setBackgroundColor(myColor1); PdfPCell cell26 = new PdfPCell(new Paragraph(Float.toString(val[5]), font4)); //cell26.setLeading(10f, 0f); cell26.setPadding(3); cell26.setBorderWidth(1f); cell26.setBackgroundColor(myColor1); table2.addCell(cell21); table2.addCell(cell22); table2.addCell(cell23); table2.addCell(cell24); table2.addCell(cell25); table2.addCell(cell26); PdfPCell cell27 = new PdfPCell(new Paragraph("Total Performance Pay", font3)); //cell27.setLeading(10f, 0f); cell27.setPadding(3); cell27.setBorderWidth(1f); cell27.setBackgroundColor(myColor1); PdfPCell cell28 = new PdfPCell(new Paragraph(Float.toString(val[6]), font4)); // cell28.setLeading(10f, 0f); cell28.setPadding(3); cell28.setBorderWidth(1f); cell28.setBackgroundColor(myColor1); table2.addCell(cell27); table2.addCell(cell28); table2.setSpacingAfter(12f); document.add(table2); PdfPTable table3 = new PdfPTable(2); // 3 columns. table3.setWidthPercentage(100); PdfPCell cell271 = new PdfPCell(new Paragraph("Final Total amount paid by company", font3)); //cell27.setLeading(10f, 0f); cell271.setPadding(3); cell271.setBorderWidth(1f); cell271.setBackgroundColor(myColor1); PdfPCell cell281 = new PdfPCell(new Paragraph(Float.toString(val[6]), font4)); // cell28.setLeading(10f, 0f); cell281.setPadding(3); cell281.setBorderWidth(1f); cell281.setBackgroundColor(myColor1); PdfPCell cell29 = new PdfPCell(new Paragraph("Total Provident Fund Collected", font3)); //cell29.setLeading(10f, 0f); cell29.setPadding(3); cell29.setBorderWidth(1f); cell29.setBackgroundColor(myColor1); PdfPCell cell30 = new PdfPCell(new Paragraph(Float.toString(val[7]), font4)); //cell30.setLeading(10f, 0f); cell30.setPadding(3); cell30.setBorderWidth(1f); cell30.setBackgroundColor(myColor1); PdfPCell cell31 = new PdfPCell(new Paragraph("Total Professional Tax Collected", font3)); //cell31.setLeading(10f, 0f); cell31.setPadding(3); cell31.setBorderWidth(1f); cell31.setBackgroundColor(myColor1); PdfPCell cell32 = new PdfPCell(new Paragraph(Float.toString(val[8]), font4)); //cell32.setLeading(10f, 0f); cell32.setPadding(3); cell32.setBorderWidth(1f); cell32.setBackgroundColor(myColor1); table3.addCell(cell271); table3.addCell(cell281); table3.addCell(cell29); table3.addCell(cell30); table3.addCell(cell31); table3.addCell(cell32); table3.setSpacingAfter(12f); document.add(table3); /* PdfPCell cell33 = new PdfPCell(new Paragraph("PAN",font3)); //cell33.setLeading(10f, 0f); cell33.setPadding(3); cell33.setBorderWidth(1f); cell33.setBackgroundColor(myColor1); PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E",font4)); // cell34.setLeading(10f, 0f); cell34.setPadding(3); cell34.setBorderWidth(1f); cell34.setBackgroundColor(myColor1); PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance",font3)); //cell35.setLeading(10f, 0f); cell35.setPadding(3); cell35.setBorderWidth(1f); cell35.setBackgroundColor(myColor1); PdfPCell cell36 = new PdfPCell(new Paragraph("EL X SL X CL X",font4)); //cell36.setLeading(10f, 0f); cell36.setPadding(3); cell36.setBorderWidth(1f); cell36.setBackgroundColor(myColor1); PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON",font3)); //cell37.setLeading(10f, 0f); cell37.setPadding(3); cell37.setBorderWidth(1f); cell37.setBackgroundColor(myColor1); PdfPCell cell38 = new PdfPCell(new Paragraph("2616141",font4)); //cell38.setLeading(10f, 0f); cell38.setPadding(3); cell38.setBorderWidth(1f); cell38.setBackgroundColor(myColor1); table2.addCell(cell33); table2.addCell(cell34); table2.addCell(cell35); table2.addCell(cell36); table2.addCell(cell37); table2.addCell(cell38); */ /* PdfPTable table3 = new PdfPTable(5); // 5 columns. table3.setWidthPercentage(100); PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings",font1)); cell39.setLeading(10f, 0f); cell39.setPadding(4); cell39.setBorderWidth(1f); cell39.setBackgroundColor(myColor); PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)",font1)); cell40.setLeading(10f, 0f); cell40.setPadding(4); cell40.setBorderWidth(1f); cell40.setBackgroundColor(myColor); PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)",font1)); cell41.setLeading(10f, 0f); cell41.setPadding(4); cell41.setBorderWidth(1f); cell41.setBackgroundColor(myColor); PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions",font1)); cell42.setLeading(10f, 0f); cell42.setPadding(4); cell42.setBorderWidth(1f); cell42.setBackgroundColor(myColor); PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)",font1)); cell43.setLeading(10f, 0f); cell43.setPadding(4); cell43.setBorderWidth(1f); cell43.setBackgroundColor(myColor); table3.addCell(cell39); table3.addCell(cell40); table3.addCell(cell41); table3.addCell(cell42); table3.addCell(cell43); String[] sal = new String[9]; sal[0]="Basic Salary"; sal[1]="House Rent Allowance"; sal[2]="Medical Allowance"; sal[3]="Travelling Allowance"; sal[4]="Personal Allowance"; sal[5]="City Allowance"; sal[6]="Performance Pay"; sal[7]="Provident Fund"; sal[8]="Professional Tax"; Float[] val = new Float[9]; val[0]=rs1.getFloat(4); val[1]=6000.00f; val[2]=1000.00f; val[3]=1000.00f; val[4]=val[0]/2; val[5]=1000.00f; val[6]=val[4]; val[7]=val[0]*12/100; val[8]=0.00f; if((val[0]+val[4]+val[6])*12>250000.00f) { val[8]=(val[0]+val[4]+val[6])/10; } for(int i=0;i<7;i++) { PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i],font3)); //cell27.setLeading(10f, 0f); cell44.setPadding(3); cell44.setBorderWidth(1f); cell44.setBackgroundColor(myColor1); PdfPCell cell45 = new PdfPCell(new Paragraph("",font4)); // cell45.setLeading(10f, 0f); cell45.setPadding(3); cell45.setBorderWidth(1f); cell45.setBackgroundColor(myColor1); PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(),font3)); //cell46.setLeading(10f, 0f); cell46.setHorizontalAlignment(Element.ALIGN_RIGHT); cell46.setPadding(3); cell46.setBorderWidth(1f); cell46.setBackgroundColor(myColor1); table3.addCell(cell44); table3.addCell(cell45); table3.addCell(cell46); if(i==0 || i==1) { PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7+i],font4)); //cell47.setLeading(10f, 0f); cell47.setPadding(3); cell47.setBorderWidth(1f); cell47.setBackgroundColor(myColor1); table3.addCell(cell47); PdfPCell cell48 = new PdfPCell(new Paragraph(val[i+7].toString(),font3)); //cell48.setLeading(10f, 0f); cell48.setHorizontalAlignment(Element.ALIGN_RIGHT); cell48.setPadding(3); cell48.setBorderWidth(1f); cell48.setBackgroundColor(myColor1); table3.addCell(cell48); } else { PdfPCell cell47 = new PdfPCell(new Paragraph("",font4)); cell47.setBorder(PdfPCell.NO_BORDER); cell47.setBorderWidthRight (1f); cell47.setColspan(2); table3.addCell(cell47); } } PdfPCell cell48 = new PdfPCell(new Paragraph("",font4)); //cell48.setBorder(PdfPCell.NO_BORDER); cell48.setColspan(3); table3.addCell(cell48); PdfPCell cell49 = new PdfPCell(new Paragraph("",font4)); //cell49.setBorder(PdfPCell.NO_BORDER); cell49.setColspan(2); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); table3.addCell(cell48); table3.addCell(cell49); PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)",font3)); //cell27.setLeading(10f, 0f); cell50.setColspan(2); cell50.setPadding(3); cell50.setBorderWidth(1f); cell50.setBackgroundColor(myColor1); table3.addCell(cell50); float a = 0.0f; for(int i=0;i<7;i++) {a+=val[i];} PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a),font3)); //cell27.setLeading(10f, 0f); cell55.setPadding(3); cell55.setHorizontalAlignment(Element.ALIGN_RIGHT); cell55.setBorderWidth(1f); cell55.setBackgroundColor(myColor1); table3.addCell(cell55); PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions",font3)); //cell27.setLeading(10f, 0f); //cell51.setColspan(3); cell51.setPadding(3); cell51.setBorderWidth(1f); cell51.setBackgroundColor(myColor1); table3.addCell(cell51); float b = val[7]+val[8]; PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b),font3)); //cell27.setLeading(10f, 0f); //cell56.setColspan(3); cell56.setPadding(3); cell56.setHorizontalAlignment(Element.ALIGN_RIGHT); cell56.setBorderWidth(1f); cell56.setBackgroundColor(myColor1); table3.addCell(cell56); table3.setSpacingAfter(12f); document.add(table3); PdfPTable table4 = new PdfPTable(5); // 2 columns. table4.setWidthPercentage(100); PdfPCell cell54 = new PdfPCell(new Paragraph("",font3)); cell54.setBorder(PdfPCell.NO_BORDER); cell54.setColspan(3); table4.addCell(cell54); PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay",font5)); cell52.setLeading(10f, 0f); // cell52.setBorder(PdfPCell.ALIGN_CENTER); cell52.setHorizontalAlignment(Element.ALIGN_LEFT); cell52.setVerticalAlignment(Element.ALIGN_CENTER); cell52.setPadding(6f); cell52.setBorderWidth(1f); cell52.setBackgroundColor(myColor); table4.addCell(cell52); PdfPCell cell53 = new PdfPCell(new Paragraph(""+(a-b),font6)); cell53.setLeading(10f, 0f); cell53.setPadding(6f); cell53.setHorizontalAlignment(Element.ALIGN_CENTER); cell53.setVerticalAlignment(Element.ALIGN_CENTER); cell53.setBorderWidth(1f); table4.addCell(cell53); document.add(table4); */ // step 4 // document.add(new Paragraph(String.format( // "You have submitted the following text using the %s method:%s", // request.getMethod(),uname))); // document.add(new Paragraph(text)); // step 5 document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // the contentlength response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } else { response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first"); } } catch (Exception e) { // throw new IOException(e.getMessage()); System.out.println(e); System.out.println("sssssssssssssssssss"); } }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPTable createOrderButton(Model model) throws IOException, BadElementException { final Chunk chunk = new Chunk("Order on taconic.com", iTextUtil.getFontButton()); chunk.setAction(//from ww w.j a va 2s . c om new PdfAction("http://www.taconic.com/start-an-order?modelNumber=" + model.getModelNumber())); final PdfPCell cell = cell(new Phrase(chunk)); cell.setBackgroundColor(iTextUtil.getTaconicRed()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingTop(5); cell.setPaddingBottom(8); final PdfPTable button = new PdfPTable(new float[] { 80f, 20f }); button.addCell(cell(new Phrase(" "), 2)); button.addCell(cell); button.addCell(cell(new Phrase(" "))); button.addCell(cell(new Phrase(" "), 2)); return button; }
From source file:com.bougsid.printers.PrintMission.java
public void printMission(Mission mission) { Document document = new Document(PageSize.A4); try {/*from w w w.j a v a 2s .c om*/ File downloadDir = new File(msg.getMessage("application.mission.downloaddir")); if (!downloadDir.exists()) { downloadDir.mkdir(); } System.out.println("Dir =" + downloadDir.getPath()); PdfWriter.getInstance(document, new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf")); document.open(); Paragraph p = new Paragraph(); p.setSpacingAfter(60); document.add(p); //header Paragraph paragraph = new Paragraph( msg.getMessage("mission.pdf.school") + " " + mission.getIdMission() + " ", DEFAULT_FONT); Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); paragraph.add(phrase); paragraph.setSpacingAfter(50); document.add(paragraph); //title PdfPTable table = new PdfPTable(1); table.setWidthPercentage(40); PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"), FontFactory.getFont(FontFactory.HELVETICA, 18))); cell.setBorderWidth(1); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(40); document.add(table); //content table = new PdfPTable(2); table.setWidthPercentage(100); //line 1 cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 2 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 3 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); if (mission.getEntreprise() != null) { //line 4 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 5 cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); } //line 6 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); p = new Paragraph(); p.setFont(DEFAULT_FONT); for (Ville ville : mission.getVilles()) { p.add(ville.getNom() + "\n"); } cell = new PdfPCell(p); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 7 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 8 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 9 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); switch (mission.getTransportType()) { case PERSONNEL: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Accompagnement: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " " + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName() + " " + msg.getMessage("mission.pdf.accomp.voitue") + " " + mission.getAccompEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Service: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; default: { cell = new PdfPCell(new Paragraph( ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"), DEFAULT_FONT)); } } cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); table.setSpacingAfter(40); document.add(table); //note document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT)); //signature if (mission.getEmploye().getGrade().getType() == GradeType.DG) { } else { Employe dir = employeService.getDG(); if (dir != null) paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); paragraph.setSpacingBefore(40); document.add(paragraph); paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph); } } catch (DocumentException ex) { ex.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } document.close(); // try { // Desktop.getDesktop().open(new File("./order.pdf")); // } catch (IOException ex) { // JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier"); // } }
From source file:com.deadormi.servlet.CreaPdfServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww . ja v a 2s. c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getQueryString(); Integer gruppo_id = Integer.parseInt(url.substring(url.indexOf("=") + 1, url.length())); List<Utente> iscritti = null; List<Post> posts = null; Gruppo gruppo = null; Utente utente = null; String imageUrl = null; String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); try { iscritti = UtenteController.getUserByGroupId(request, gruppo_id); gruppo = GruppoController.getGruppoById(request, gruppo_id); } catch (SQLException ex) { log.error(ex); } // step 1: creation of a document-object Document document = new Document(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); String incipit = "Report del " + CurrentDate.getCurrentDate() + "\n"; Paragraph pIncipit = new Paragraph(incipit, FontFactory.getFont(FontFactory.HELVETICA, 14, BaseColor.BLACK)); pIncipit.setAlignment(Element.ALIGN_CENTER); pIncipit.setSpacingAfter(10); document.add(pIncipit); String title = "Gruppo " + gruppo.getNome(); Paragraph pTitle = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 18, BaseColor.BLUE)); pTitle.setAlignment(Element.ALIGN_CENTER); pTitle.setSpacingAfter(40); document.add(pTitle); PdfPCell labelNome = new PdfPCell(new Paragraph("Nome utente")); PdfPCell labelNumPost = new PdfPCell(new Paragraph("Num. post")); PdfPCell labelData = new PdfPCell(new Paragraph("Data ultimo post")); labelNome.setBorder(Rectangle.NO_BORDER); labelNumPost.setBorder(Rectangle.NO_BORDER); labelData.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < iscritti.size(); i++) { utente = iscritti.get(i); try { posts = PostController.getPostByGruppoIdAndUserId(request, gruppo_id, utente.getId_utente()); } catch (SQLException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } if (utente.getNome_avatar() != null) { imageUrl = baseUrl + request.getContextPath() + AVATAR_RESOURCE_PATH + "/" + utente.getId_utente() + "_" + utente.getNome_avatar(); ; } else { imageUrl = baseUrl + request.getContextPath() + "/res/images/user_avatar.png"; } Image image = Image.getInstance(new URL(imageUrl)); image.scaleToFit(50, 50); PdfPTable table = new PdfPTable(3); PdfPCell cellAvatar = new PdfPCell(image); cellAvatar.setHorizontalAlignment(Element.ALIGN_CENTER); cellAvatar.setBorder(Rectangle.NO_BORDER); cellAvatar.setRowspan(3); PdfPCell cellNome = new PdfPCell(new Paragraph(utente.getUsername() + "")); cellNome.setBorder(Rectangle.NO_BORDER); PdfPCell cellNumPost = new PdfPCell(new Paragraph(posts.size() + "")); cellNumPost.setBorder(Rectangle.NO_BORDER); //L'ultimo sempre il piu recente siccome la query ORDER BY data_creazione PdfPCell cellData; if (posts.size() != 0) { cellData = new PdfPCell(new Paragraph(posts.get(posts.size() - 1).getData_creazione())); } else { cellData = new PdfPCell(new Paragraph("N/A")); } cellData.setBorder(Rectangle.NO_BORDER); PdfPCell cellVoidBottom = new PdfPCell(new Paragraph(" ")); cellVoidBottom.setBorder(Rectangle.BOTTOM); cellVoidBottom.setPaddingBottom(10); cellVoidBottom.setColspan(3); PdfPCell cellVoidTop = new PdfPCell(new Paragraph(" ")); cellVoidTop.setBorder(Rectangle.NO_BORDER); cellVoidTop.setPaddingTop(10); cellVoidTop.setColspan(3); table.addCell(cellVoidTop); table.addCell(cellAvatar); table.addCell(labelNome); table.addCell(cellNome); table.addCell(labelNumPost); table.addCell(cellNumPost); table.addCell(labelData); table.addCell(cellData); table.addCell(cellVoidBottom); document.add(table); } document.close(); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "inline; filename=ahahah.pdf"); OutputStream os = response.getOutputStream(); baos.writeTo(os); os.flush(); os.close(); } catch (DocumentException ex) { Logger.getLogger(CreaPdfServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.gp.cong.logisoft.lcl.report.LclAllBLPdfCreator.java
public PdfPTable bodySection() throws Exception { String exportRefRemarks = ""; String routingInsRemarks = ""; String InsStatement = ""; StringBuilder pierValues = new StringBuilder(); String[] remarkTypes = { REMARKS_TYPE_ROUTING_INSTRU, REMARKS_TYPE_EXPORT_REF }; List remarks = new LclRemarksDAO().getRemarksByTypes(lclbl.getFileNumberId(), remarkTypes); for (Object row : remarks) { Object[] col = (Object[]) row; if (col[1].toString().equalsIgnoreCase("Export Reference")) { exportRefRemarks = col[0].toString(); }/*from w w w . j av a 2 s. co m*/ if (col[1].toString().equalsIgnoreCase("Routing Instruction")) { routingInsRemarks = col[0].toString(); } } String bill_type = lclbl.getBillingType(); billingType = bill_type.equalsIgnoreCase("P") ? "** FREIGHT PREPAID **" : bill_type.equalsIgnoreCase("C") ? "** FREIGHT COLLECT **" : bill_type.equalsIgnoreCase("B") && "Y".equalsIgnoreCase(printPpdBlBothKey) ? "** FREIGHT PREPAID **" : "** FREIGHT COLLECT **"; billType = bill_type.equalsIgnoreCase("P") ? "PPD" : bill_type.equalsIgnoreCase("C") ? "COL" : "BOTH"; LclSsDetail bookedOrPickedVoy = null; ExportVoyageSearchModel pickedDetails = new LclUnitSsDAO() .getPickedVoyageByVessel(lclBooking.getFileNumberId(), "E"); if (pickedDetails != null && CommonUtils.isNotEmpty(pickedDetails.getUnitSsId())) { LclUnitSs lclUnitSs = new LclUnitSsDAO().findById(Long.parseLong(pickedDetails.getUnitSsId())); bookedOrPickedVoy = lclUnitSs.getLclSsHeader().getVesselSsDetail(); unitNumber = lclUnitSs.getLclUnit().getUnitNo(); voyageNumber = lclUnitSs.getLclSsHeader().getScheduleNo(); sealOut = CommonUtils.isNotEmpty(lclUnitSs.getSUHeadingNote()) ? lclUnitSs.getSUHeadingNote().toUpperCase() : ""; } else { bookedOrPickedVoy = null != lclbl.getBookedSsHeaderId() ? lclbl.getBookedSsHeaderId().getVesselSsDetail() : null; } StringBuilder carrierName = new StringBuilder(); if (bookedOrPickedVoy != null) { sailDate = DateUtils.formatStringDateToAppFormatMMM(bookedOrPickedVoy.getStd()); sailDateFormat = DateUtils.formatDateToMMMMDDYYYY(bookedOrPickedVoy.getStd()); ladenSailDateRemarks = "\nLaden On Board:" + sailDate; if (CommonFunctions.isNotNull(bookedOrPickedVoy.getSpReferenceName())) { carrierName.append(bookedOrPickedVoy.getSpReferenceName()).append(" "); } if (CommonUtils.isNotEmpty(bookedOrPickedVoy.getTransMode())) { carrierName.append(bookedOrPickedVoy.getTransMode()).append(". "); } if (CommonUtils.isNotEmpty(bookedOrPickedVoy.getSpReferenceNo())) { carrierName.append(bookedOrPickedVoy.getSpReferenceNo()); } pierValues.append(bookedOrPickedVoy.getDeparture().getUnLocationName()); if (null != bookedOrPickedVoy.getDeparture().getStateId()) { pierValues.append("/").append(bookedOrPickedVoy.getDeparture().getStateId().getCode()); } } Paragraph p = null; table = new PdfPTable(2); table.setWidthPercentage(100f); table.setWidths(new float[] { 5.3f, 4.7f }); PdfPCell bCell = null; bCell = new PdfPCell(); bCell.setBorder(0); bCell.setPadding(0f); bCell.setBorderWidthBottom(0.06f); bCell.setBorderWidthTop(0.06f); bCell.setBorderWidthRight(0.06f); PdfPTable bTable = new PdfPTable(2); bTable.setWidths(new float[] { 5f, 4f }); bTable.setWidthPercentage(100f); bTable.addCell(makeCellLeftTopNoBorderFont("SHIPPER/EXPORTER", -0.5f, 0.8f, blackBoldFont65)); PdfPCell shCell = new PdfPCell(); shCell.setBorder(0); shCell.setColspan(2); shCell.setPadding(0f); shCell.setPaddingLeft(4f); shCell.setBorderWidthBottom(0.06f); shCell.setFixedHeight(65f); String shipperDetails = lclUtils.getConcatenatedAccountDetails(lclbl.getShipContact()); if (CommonUtils.isNotEmpty(shipperDetails)) { p = new Paragraph(11f, "" + shipperDetails.toUpperCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(15f); } else { p = new Paragraph(8f, "", totalFontQuote); shCell.setPadding(35f); } shCell.addElement(p); bTable.addCell(shCell); //consignee bTable.addCell(makeCellLeftTopNoBorderFont("CONSIGNEE", -0.5f, 0.8f, blackBoldFont65)); //consignee Values PdfPCell cvCell = new PdfPCell(); cvCell.setBorder(0); cvCell.setColspan(2); cvCell.setPadding(0f); cvCell.setPaddingLeft(4f); cvCell.setBorderWidthBottom(0.06f); cvCell.setFixedHeight(65f); String consDetails = lclUtils.getConcatenatedAccountDetails(lclbl.getConsContact()); if (CommonUtils.isNotEmpty(consDetails)) { p = new Paragraph(11f, "" + consDetails.toUpperCase(), totalFontQuote); p.setSpacingAfter(15f); p.setAlignment(Element.ALIGN_LEFT); } else { p = new Paragraph(8f, "", totalFontQuote); cvCell.setPadding(30f); } cvCell.addElement(p); bTable.addCell(cvCell); //Notify bTable.addCell(makeCellLeftTopNoBorderFont("NOTIFY PARTY", -0.5f, 0.8f, blackBoldFont65)); //consignee Values PdfPCell nvCell = new PdfPCell(); nvCell.setBorder(0); nvCell.setColspan(2); nvCell.setPadding(0f); nvCell.setPaddingLeft(4f); nvCell.setBorderWidthBottom(0.06f); nvCell.setFixedHeight(70f); String notyDetails = lclUtils.getConcatenatedAccountDetails(lclbl.getNotyContact()); if (CommonUtils.isNotEmpty(notyDetails)) { p = new Paragraph(11f, "" + notyDetails.toUpperCase(), totalFontQuote); p.setSpacingAfter(25f); p.setAlignment(Element.ALIGN_LEFT); } else { p = new Paragraph(8f, "", totalFontQuote); nvCell.setPadding(40f); } nvCell.addElement(p); bTable.addCell(nvCell); //place of receipt PdfPCell prCell = new PdfPCell(); prCell.setBorder(0); prCell.setPaddingLeft(-0.9f); prCell.setPaddingTop(-0.2f); p = new Paragraph(7f, "PLACE OF RECEIPT", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); prCell.addElement(p); bTable.addCell(prCell); /* Pier Logic */ String pier = "N".equalsIgnoreCase(printPierPol) ? ("N".equalsIgnoreCase(printPierPol) && !"N".equalsIgnoreCase(hblPierOverRideKey)) ? hblPierOverRideKey : pierValues.toString() : ""; /* POL Logic */ String pol = ""; if ("Y".equalsIgnoreCase(printPierPol)) { if ("N".equalsIgnoreCase(hblPierOverRideKey)) { pol = pierValues.toString(); } else { pol = hblPierOverRideKey; } } else { pol = !"N".equalsIgnoreCase(hblPolOverRideKey) ? hblPolOverRideKey : polValues; } Boolean checkBlInsurance = new LclBlAcDAO().checkBlInsurance(lclbl.getFileNumberId(), INSURANCE_CHARGE_CODE); if (checkBlInsurance && "Y".equalsIgnoreCase(printBlInsuranceKey)) { InsStatement = LoadLogisoftProperties.getProperty("InsuranceChargeComment"); } PdfPCell pierCell = new PdfPCell(); pierCell.setBorder(0); pierCell.setBorderWidthLeft(0.06f); pierCell.setPaddingTop(-0.2f); p = new Paragraph(7f, "PIER", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); pierCell.addElement(p); bTable.addCell(pierCell); //place of receipt values PdfPCell prvCell = new PdfPCell(); prvCell.setBorder(0); prvCell.setBorderWidthBottom(0.06f); if (lclBooking.getPooPickup()) { LclBookingPad lclBookingPad = lclBooking.getLclFileNumber().getLclBookingPadList().get(0); String pickUp_city = lclBookingPad.getPickUpCity().replaceAll("/", ","); pickUp_city = pickUp_city.substring(pickUp_city.indexOf("-") + 1, pickUp_city.length()); p = new Paragraph(7f, "" + pickUp_city.toUpperCase(), totalFontQuote); } else { StringBuilder placeofReceipt = new StringBuilder(); if (null != lclbl.getPortOfOrigin()) { placeofReceipt.append(lclbl.getPortOfOrigin().getUnLocationName()); if (CommonFunctions.isNotNull(lclbl.getPortOfOrigin().getStateId()) && CommonFunctions.isNotNull(lclbl.getPortOfOrigin().getStateId().getCode())) { placeofReceipt.append(",").append(lclbl.getPortOfOrigin().getStateId().getCode()); } } p = new Paragraph(7f, "" + placeofReceipt.toString().toUpperCase(), totalFontQuote); } p.setSpacingAfter(5f); p.setSpacingBefore(5f); p.setAlignment(Element.ALIGN_LEFT); prvCell.addElement(p); bTable.addCell(prvCell); //pier values PdfPCell piervCell = new PdfPCell(); piervCell.setBorder(0); piervCell.setBorderWidthLeft(0.06f); piervCell.setBorderWidthBottom(0.06f); p = new Paragraph(7f, "" + pier, totalFontQuote); p.setSpacingAfter(5f); p.setSpacingBefore(5f); p.setAlignment(Element.ALIGN_LEFT); piervCell.addElement(p); bTable.addCell(piervCell); //exporting carrier PdfPCell ecCell = new PdfPCell(); ecCell.setBorder(0); ecCell.setPaddingLeft(-0.5f); ecCell.setPaddingTop(-0.2f); p = new Paragraph(7f, "EXPORTING CARRIER (Vessel) (Flag)", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); ecCell.addElement(p); bTable.addCell(ecCell); //portof loading PdfPCell portCell = new PdfPCell(); portCell.setBorder(0); portCell.setPaddingTop(-0.2f); portCell.setBorderWidthLeft(0.06f); p = new Paragraph(7f, "PORT OF LOADING", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); portCell.addElement(p); bTable.addCell(portCell); //exporting values PdfPCell exvCell = new PdfPCell(); exvCell.setBorder(0); exvCell.setFixedHeight(15f); exvCell.setBorderWidthBottom(0.06f); p = new Paragraph(7f, "" + carrierName.toString().toUpperCase(), totalFontQuote); p.setSpacingAfter(5f); p.setSpacingBefore(5f); p.setAlignment(Element.ALIGN_LEFT); exvCell.addElement(p); bTable.addCell(exvCell); //port of loading values PdfPCell portvCell = new PdfPCell(); portvCell.setBorder(0); portvCell.setBorderWidthLeft(0.06f); portvCell.setBorderWidthBottom(0.06f); p = new Paragraph(7f, "" + pol.toUpperCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); portvCell.addElement(p); bTable.addCell(portvCell); //sea port of discharge PdfPCell seaCell = new PdfPCell(); seaCell.setBorder(0); seaCell.setPaddingLeft(-0.5f); seaCell.setPaddingTop(-0.2f); p = new Paragraph(7f, "SEA PORT OF DISCHARGE", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); seaCell.addElement(p); bTable.addCell(seaCell); //finalde PdfPCell finalCell = new PdfPCell(); finalCell.setBorder(0); finalCell.setBorderWidthLeft(0.06f); finalCell.setPaddingTop(-0.2f); p = new Paragraph(7f, "FINAL DELIVERY TO", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); finalCell.addElement(p); bTable.addCell(finalCell); //sea values PdfPCell seavCell = new PdfPCell(); seavCell.setBorder(0); seavCell.setFixedHeight(25f); // seavCell.setBorderWidthBottom(0.06f); p = new Paragraph(7f, "" + podValues.toUpperCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); seavCell.addElement(p); bTable.addCell(seavCell); //fina deliver values String finalDest = !fdOverride.equalsIgnoreCase("N") ? fdOverride : (agencyInfo != null && CommonUtils.isNotEmpty(agencyInfo[2])) ? agencyInfo[2] : blUtils.getBLConcatenatedFinalDestination(lclbl); PdfPCell finalvCell = new PdfPCell(); finalvCell.setBorder(0); finalvCell.setBorderWidthLeft(0.06f); p = new Paragraph(7f, !finalDest.equalsIgnoreCase(podValues) ? "" + finalDest.toUpperCase() : "", totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); finalvCell.addElement(p); bTable.addCell(finalvCell); bCell.addElement(bTable); table.addCell(bCell); //2column cell = new PdfPCell(); cell.setBorder(0); cell.setPadding(0f); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthTop(0.06f); PdfPTable pTable = new PdfPTable(2); pTable.setWidths(new float[] { 4f, 2f }); pTable.setWidthPercentage(100f); PdfPCell nCell = null; nCell = new PdfPCell(); nCell.setBorder(0); nCell.setPaddingTop(0.2f); p = new Paragraph(7f, "DOCUMENT NO", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); nCell.addElement(p); pTable.addCell(nCell); nCell = new PdfPCell(); nCell.setBorder(0); nCell.setPaddingTop(0.2f); p = new Paragraph(7f, "PAGE : " + ++page_count, blackBoldFont65); p.setAlignment(Element.ALIGN_RIGHT); nCell.addElement(p); pTable.addCell(nCell); String consolidateNumber = new LclConsolidateDAO() .getConsolidatesFileNumbers(lclbl.getLclFileNumber().getId().toString()); consolidateNumber = null == consolidateNumber ? lclbl.getLclFileNumber().getFileNumber() : lclbl.getLclFileNumber().getFileNumber() + "," + consolidateNumber; PdfPCell dvCell = new PdfPCell(); dvCell.setBorder(0); dvCell.setColspan(2); dvCell.setBorderWidthBottom(0.06f); dvCell.setPaddingLeft(8f); dvCell.setPaddingBottom(5f); dvCell.setPaddingTop(2f); p = new Paragraph(8f, "" + consolidateNumber.toUpperCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); dvCell.addElement(p); pTable.addCell(dvCell); PdfPCell eCell = new PdfPCell(); eCell.setBorder(0); eCell.setPaddingTop(0.2f); eCell.setColspan(2); p = new Paragraph(7f, "EXPORT REFERENCE", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); eCell.addElement(p); pTable.addCell(eCell); PdfPCell evCell = new PdfPCell(); evCell.setBorder(0); evCell.setColspan(2); evCell.setBorderWidthBottom(0.06f); evCell.setPaddingLeft(8f); evCell.setFixedHeight(35f); exportRefRemarks = exportRefRemarks + ("EXPORT".equalsIgnoreCase(ladenSailDateOptKey) ? ladenSailDateRemarks : "") + ("EXPORT".equalsIgnoreCase(printTermsTypeKey) ? termsType1 : ""); if (exportRefRemarks != null && !exportRefRemarks.equals("")) { p = new Paragraph(10f, "" + exportRefRemarks, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); } else { p = new Paragraph(8f, "", contentBLNormalFont); } evCell.addElement(p); pTable.addCell(evCell); PdfPCell fCell = new PdfPCell(); fCell.setBorder(0); fCell.setColspan(2); fCell.setPaddingTop(0.2f); p = new Paragraph(7f, "FORWARDING AGENT-REFERENCES", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); fCell.addElement(p); pTable.addCell(fCell); //forwarding avlues PdfPCell fvCell = new PdfPCell(); fvCell.setBorder(0); fvCell.setColspan(2); fvCell.setPaddingLeft(3f); fvCell.setPaddingTop(2f); fvCell.setBorderWidthBottom(0.06f); fvCell.setFixedHeight(65f); if (null != lclbl.getFwdAcct() && !lclbl.getFwdAcct().getAccountName().equalsIgnoreCase("NO FRT. FORWARDER ASSIGNED")) { boolean forwarderAcctFlag = new LCLBlDAO() .getFreightForwardAcctStatus(lclbl.getFwdAcct().getAccountno()); String fwdDetails = lclUtils.getConcatenatedAccountDetails(lclbl.getFwdContact()); if (CommonUtils.isNotEmpty(fwdDetails) && !forwarderAcctFlag) { p = new Paragraph(11f, "" + fwdDetails.toUpperCase(), totalFontQuote); p.setSpacingAfter(15f); p.setAlignment(Element.ALIGN_LEFT); } else { p = new Paragraph(8f, "", totalFontQuote); fvCell.setPadding(25f); } fvCell.addElement(p); pTable.addCell(fvCell); } else { p = new Paragraph(8f, "", totalFontQuote); fvCell.setBorderWidthBottom(0.06f); pTable.addCell(fvCell); } //pointoforigin PdfPCell pCell = new PdfPCell(); pCell.setBorder(0); pCell.setColspan(2); pCell.setPaddingTop(0.2f); p = new Paragraph(7f, "POINT AND COUNTRY OF ORIGIN", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); pCell.addElement(p); pTable.addCell(pCell); //point avlues PdfPCell pvCell = new PdfPCell(); pvCell.setBorder(0); pvCell.setColspan(2); pvCell.setPaddingLeft(8f); pvCell.setPaddingBottom(5f); pvCell.setPaddingTop(2f); pvCell.setFixedHeight(20f); pvCell.setBorderWidthBottom(0.06f); if (lclbl.getPointOfOrigin() != null) { p = new Paragraph(9f, "" + lclbl.getPointOfOrigin(), totalFontQuote); pvCell.addElement(p); } p.setAlignment(Element.ALIGN_LEFT); pTable.addCell(pvCell); //domes PdfPCell doCell = new PdfPCell(); doCell.setBorder(0); doCell.setColspan(2); doCell.setPaddingTop(0.2f); p = new Paragraph(7f, "DOMESTIC ROUTING/EXPORT INSTRUCTIONS", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); doCell.addElement(p); pTable.addCell(doCell); //point avlues PdfPCell dovCell = new PdfPCell(); dovCell.setBorder(0); dovCell.setColspan(2); dovCell.setPaddingLeft(8f); dovCell.setBorderWidthBottom(0.06f); dovCell.setFixedHeight(45f); routingInsRemarks = routingInsRemarks + ("ROUTING".equalsIgnoreCase(ladenSailDateOptKey) ? ladenSailDateRemarks : "") + ("ROUTING".equalsIgnoreCase(printTermsTypeKey) ? termsType1 : ""); if (routingInsRemarks != null && !"".equalsIgnoreCase(routingInsRemarks)) { p = new Paragraph(10f, "" + routingInsRemarks, totalFontQuote); p.setSpacingAfter(10f); p.setAlignment(Element.ALIGN_LEFT); } else { p = new Paragraph(8f, "", contentBLNormalFont); dovCell.setPadding(15f); } dovCell.addElement(p); pTable.addCell(dovCell); //addito PdfPCell adCell = new PdfPCell(); adCell.setBorder(0); adCell.setColspan(2); adCell.setPaddingTop(0.2f); p = new Paragraph(7f, "ADDITIONAL DOCUMENT NUMBERS", blackBoldFont65); p.setAlignment(Element.ALIGN_LEFT); adCell.addElement(p); pTable.addCell(adCell); //add values PdfPCell advCell = new PdfPCell(); advCell.setBorder(0); advCell.setColspan(2); advCell.setPadding(10f); p = new Paragraph(7f, InsStatement, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); advCell.addElement(p); pTable.addCell(advCell); cell.addElement(pTable); table.addCell(cell); return table; }
From source file:com.gp.cong.logisoft.lcl.report.LclAllBLPdfCreator.java
public PdfPTable commodityValues() throws DocumentException, ParseException, Exception { Paragraph p = null;//www . jav a 2 s . c o m table = new PdfPTable(2); table.setWidthPercentage(100f); table.setWidths(new float[] { 5f, 3.2f }); cell = new PdfPCell(); cell.setBorder(2); cell.setBorderWidthTop(0.6f); cell.setBorderWidthRight(0.6f); cell.setBorderWidthBottom(0f); if (isFirst_page) { cell.addElement(appendChargesAndCommodity()); isFirst_page = false; } else { cell.setFixedHeight(100f); } table.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthTop(0.6f); cell.addElement(appendDescComments()); table.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); PdfPTable fileAndLogo = new PdfPTable(2); fileAndLogo.setWidthPercentage(100f); fileAndLogo.setWidths(new float[] { 4f, 2f }); PdfPCell file = new PdfPCell(); file.setBorder(0); String blNumbering = new LCLBlDAO().getExportBlNumbering(lclbl.getLclFileNumber().getId().toString()); p = new Paragraph(16f, "B/L# " + blNumbering, blackBoldFont14); file.setPaddingTop(-6f); file.addElement(p); fileAndLogo.addCell(file); String companyLogo = LoadLogisoftProperties.getProperty( "ECU".equalsIgnoreCase(ruleName) ? "application.image.logo" : "application.image.econo.logo"); Image img = Image.getInstance(servletPath + companyLogo); img.scalePercent(25); file = new PdfPCell(img); file.setBorder(0); file.setBorder(Rectangle.NO_BORDER); file.setHorizontalAlignment(Element.ALIGN_LEFT); file.setVerticalAlignment(Element.ALIGN_LEFT); file.setBorder(0); fileAndLogo.addCell(file); cell.addElement(fileAndLogo); table.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); table.addCell(cell); return table; }
From source file:com.gp.cong.logisoft.lcl.report.LclAllBLPdfCreator.java
public PdfPTable appendChargesAndCommodity() throws Exception { LclBlAcDAO lclBlAcDAO = new LclBlAcDAO(); List<LclBlPiece> lclBlPiecesList = lclbl.getLclFileNumber().getLclBlPieceList(); List<LclBlAc> chargeList = lclBlAcDAO.getLclCostByFileNumberAsc(lclbl.getFileNumberId()); PdfPTable chargeTable = new PdfPTable(6); PdfPCell chargeCell = null; chargeTable.setWidths(new float[] { 3.8f, 1.5f, .8f, 3.8f, 1.5f, .8f }); chargeTable.setWidthPercentage(100f); Paragraph p = null;//from w w w .j av a 2s . c o m this.total_ar_amount = 0.00; this.total_ar_col_amount = 0.00; this.total_ar_ppd_amount = 0.00; List<LinkedHashMap<String, PdfPCell>> listChargeMap = null; LinkedHashMap<String, PdfPCell> chargeMap = null; if ("BOTH".equalsIgnoreCase(billType)) { listChargeMap = this.getTotalChargesList(chargeList, lclBlPiecesList); } else { chargeMap = this.getTotalCharges(chargeList, lclBlPiecesList); } LclBlAc blAC = lclBlAcDAO.manualChargeValidate(lclbl.getFileNumberId(), "OCNFRT", false); if (lclBlPiecesList != null && lclBlPiecesList.size() > 0 && blAC != null) { BigDecimal CFT = BigDecimal.ZERO, LBS = BigDecimal.ZERO; LclBlPiece lclBlPiece = (LclBlPiece) lclBlPiecesList.get(0); if (blAC.getRatePerUnitUom() != null) { CFT = blAC.getRatePerUnitUom().equalsIgnoreCase("FRV") ? blAC.getRatePerVolumeUnit() : BigDecimal.ZERO; LBS = blAC.getRatePerUnitUom().equalsIgnoreCase("FRW") ? blAC.getRatePerWeightUnit() : BigDecimal.ZERO; } if (CFT != BigDecimal.ZERO || LBS != BigDecimal.ZERO) { StringBuilder cbmValues = new StringBuilder(); if (CFT != BigDecimal.ZERO && lclBlPiece.getActualVolumeImperial() != null) { cbmValues.append(NumberUtils .convertToThreeDecimalhash(lclBlPiece.getActualVolumeImperial().doubleValue())); } if (LBS != BigDecimal.ZERO && lclBlPiece.getActualWeightImperial() != null) { cbmValues.append(NumberUtils .convertToThreeDecimalhash(lclBlPiece.getActualWeightImperial().doubleValue())); } if (null != blAC.getArAmount() && blAC.getArAmount().toString().equalsIgnoreCase(OCNFRT_Total)) { if (CFT == BigDecimal.ZERO) { cbmValues.append(" LBS @ ").append(LBS).append(" PER 100 LBS @ ") .append(blAC.getArAmount()); } else { cbmValues.append(" CFT @ ").append(CFT).append(" PER CFT @").append(blAC.getArAmount()); } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(6); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(6); p = new Paragraph(2f, "" + cbmValues.toString().toUpperCase(), totalFontQuote); p.add(new Paragraph(2f, null != lclBlPiece && null != lclBlPiece.getCommodityType() ? " Commodity# " + lclBlPiece.getCommodityType().getCode() : " Commodity#", totalFontQuote)); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } } } this.OCNFRT_Total = ""; LinkedHashMap<String, PdfPCell> left_chargeMap = new LinkedHashMap<String, PdfPCell>(); LinkedHashMap<String, PdfPCell> right_chargeMap = new LinkedHashMap<String, PdfPCell>(); if ("BOTH".equalsIgnoreCase(billType) && listChargeMap != null && !listChargeMap.isEmpty()) { if (listChargeMap.size() > 1) { if (listChargeMap.get(0).size() > 6 || listChargeMap.get(1).size() > 6) { chargeMap = new LinkedHashMap<String, PdfPCell>(); chargeMap.putAll(listChargeMap.get(0)); chargeMap.putAll(listChargeMap.get(1)); int count = 0, size = chargeMap.size() / 2 <= 6 ? 6 : chargeMap.size() / 2; for (String key : chargeMap.keySet()) { if (count++ < size) { left_chargeMap.put(key, chargeMap.get(key)); } else { right_chargeMap.put(key, chargeMap.get(key)); } } } else { left_chargeMap.putAll(listChargeMap.get(0)); right_chargeMap.putAll(listChargeMap.get(1)); } } else { int count = 0, size = listChargeMap.get(0).size() / 2 <= 6 ? 6 : listChargeMap.get(0).size() / 2; for (String key : listChargeMap.get(0).keySet()) { if (count++ < size) { left_chargeMap.put(key, listChargeMap.get(0).get(key)); } else { right_chargeMap.put(key, listChargeMap.get(0).get(key)); } } } } else if (chargeMap != null && !chargeMap.isEmpty()) { int count = 0, size = chargeMap.size() / 2 <= 6 ? 6 : chargeMap.size() / 2; for (String key : chargeMap.keySet()) { if (count++ < size) { left_chargeMap.put(key, chargeMap.get(key)); } else { right_chargeMap.put(key, chargeMap.get(key)); } } } if (!left_chargeMap.isEmpty()) { String chargeDesc = null; PdfPTable innner_chargeTable = new PdfPTable(2); innner_chargeTable.setWidthPercentage(100f); PdfPCell inner_chargeCell = null; chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setBorderWidthRight(0.6f); chargeCell.setPadding(0); innner_chargeTable = new PdfPTable(2); innner_chargeTable.setWidths(new float[] { 5f, 3f }); if (!left_chargeMap.isEmpty()) { for (String key : left_chargeMap.keySet()) { inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell.setPaddingLeft(-15); chargeDesc = key.substring(key.indexOf("#") + 1, key.indexOf("$")); inner_chargeCell.addElement(new Paragraph(7f, "" + chargeDesc, totalFontQuote)); innner_chargeTable.addCell(inner_chargeCell); inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell = left_chargeMap.get(key); innner_chargeTable.addCell(inner_chargeCell); } } chargeCell.addElement(innner_chargeTable); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setPadding(0); innner_chargeTable = new PdfPTable(2); innner_chargeTable.setWidths(new float[] { 5f, 3f }); if (!left_chargeMap.isEmpty()) { for (String key : right_chargeMap.keySet()) { inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell.setPaddingLeft(-15); chargeDesc = key.substring(key.indexOf("#") + 1, key.indexOf("$")); inner_chargeCell.addElement(new Paragraph(7f, "" + chargeDesc, totalFontQuote)); innner_chargeTable.addCell(inner_chargeCell); inner_chargeCell = new PdfPCell(); inner_chargeCell.setBorder(0); inner_chargeCell = right_chargeMap.get(key); innner_chargeTable.addCell(inner_chargeCell); } } chargeCell.addElement(innner_chargeTable); chargeTable.addCell(chargeCell); } else { this.total_ar_amount = 0.00; this.total_ar_ppd_amount = 0.00; this.total_ar_col_amount = 0.00; } String acctNo = ""; String billToParty = ""; if (CommonFunctions.isNotNull(lclbl.getBillToParty()) && CommonUtils.isNotEmpty(lclbl.getBillToParty())) { if (lclbl.getBillToParty().equalsIgnoreCase("T") && CommonFunctions.isNotNull(lclbl.getThirdPartyAcct())) { billToParty = "THIRD PARTY"; acctNo = lclbl.getThirdPartyAcct().getAccountno(); } else if (lclbl.getBillToParty().equalsIgnoreCase("S") && CommonFunctions.isNotNull(lclbl.getShipAcct())) { billToParty = "SHIPPER"; acctNo = lclbl.getShipAcct().getAccountno(); } else if (lclbl.getBillToParty().equalsIgnoreCase("F") && CommonFunctions.isNotNull(lclbl.getFwdAcct())) { billToParty = "FORWARDER"; acctNo = lclbl.getFwdAcct().getAccountno(); } else if (lclbl.getBillToParty().equalsIgnoreCase("A") && CommonFunctions.isNotNull(lclbl.getAgentAcct())) { billToParty = "AGENT"; if (lclBooking.getBookingType().equals("T") && lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo() != null) { acctNo = lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo().getAccountno(); } else if (lclBooking.getAgentAcct() != null) { acctNo = lclBooking.getAgentAcct().getAccountno(); } else { acctNo = lclbl.getAgentAcct().getAccountno(); } } } if ("BOTH".equalsIgnoreCase(billType)) { if (this.total_ar_ppd_amount != 0.00 || this.total_ar_col_amount != 0.00) { if (this.total_ar_ppd_amount != 0.00) { if (CommonFunctions.isNotNullOrNotEmpty(ppdBillToSet) && ppdBillToSet.size() == 1) { for (String billTo : ppdBillToSet) { arBillToParty = billTo; break; } if (arBillToParty.equalsIgnoreCase("T")) { billToParty = "THIRD PARTY"; acctNo = null != lclbl.getThirdPartyAcct() ? lclbl.getThirdPartyAcct().getAccountno() : acctNo; } else if (arBillToParty.equalsIgnoreCase("S")) { acctNo = null != lclbl.getShipAcct() ? lclbl.getShipAcct().getAccountno() : acctNo; billToParty = "SHIPPER"; } else if (arBillToParty.equalsIgnoreCase("F")) { billToParty = "FORWARDER"; acctNo = null != lclbl.getFwdAcct() ? lclbl.getFwdAcct().getAccountno() : acctNo; } } else { acctNo = null; } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(2); p = new Paragraph(7f, "T O T A L (USA)", totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(4); chargeCell.setBorder(0); if (null != acctNo) { p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_ppd_amount) + " PPD " + billToParty + "-" + acctNo, totalFontQuote); } else { p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_ppd_amount) + " PPD ", totalFontQuote); } p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } if (this.total_ar_col_amount != 0.00) { String colAcctNo = ""; if (lclBooking.getBookingType().equals("T") && lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo() != null) { colAcctNo = lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo() .getAccountno(); } else if (lclBooking.getAgentAcct() != null) { colAcctNo = lclBooking.getAgentAcct().getAccountno(); } else if (lclbl.getAgentAcct() != null) { colAcctNo = lclbl.getAgentAcct().getAccountno(); } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(2); if (this.total_ar_ppd_amount == 0.00) { p = new Paragraph(7f, "T O T A L (USA)", totalFontQuote); } else { p = new Paragraph(7f, "", totalFontQuote); } p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(4); chargeCell.setBorder(0); p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_col_amount) + " COL AGENT-" + colAcctNo, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } NumberFormat numberFormat = new DecimalFormat("###,###,##0.000"); if (this.total_ar_ppd_amount != 0.00) { String totalString1 = numberFormat.format(this.total_ar_ppd_amount).replaceAll(",", ""); int indexdot = totalString1.indexOf("."); String beforeDecimal = totalString1.substring(0, indexdot); String afterDecimal = totalString1.substring(indexdot + 1, totalString1.length()); chargeCell = new PdfPCell(); chargeCell.setColspan(6); chargeCell.setBorder(0); p = new Paragraph(7f, "" + ConvertNumberToWords.convert(Integer.parseInt(beforeDecimal)) + " DOLLARS AND " + StringUtils.removeEnd(afterDecimal, "0") + " CENTS", totalFontQuote); chargeCell.setHorizontalAlignment(Element.ALIGN_CENTER); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } if (this.total_ar_col_amount != 0.00) { String totalString1 = numberFormat.format(this.total_ar_col_amount).replaceAll(",", ""); int indexdot = totalString1.indexOf("."); String beforeDecimal = totalString1.substring(0, indexdot); String afterDecimal = totalString1.substring(indexdot + 1, totalString1.length()); chargeCell = new PdfPCell(); chargeCell.setColspan(6); chargeCell.setBorder(0); p = new Paragraph(7f, "" + ConvertNumberToWords.convert(Integer.parseInt(beforeDecimal)) + " DOLLARS AND " + StringUtils.removeEnd(afterDecimal, "0") + " CENTS", totalFontQuote); chargeCell.setHorizontalAlignment(Element.ALIGN_CENTER); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } } } else if (this.total_ar_amount != 0.00) { chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(2); chargeCell.setPaddingTop(8f); p = new Paragraph(7f, "T O T A L (USA)", totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(4); chargeCell.setBorder(0); chargeCell.setPaddingTop(8f); p = new Paragraph(7f, "$" + NumberUtils.convertToTwoDecimal(this.total_ar_amount) + " " + billType + " " + billToParty + "-" + acctNo, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); NumberFormat numberFormat = new DecimalFormat("###,###,##0.000"); String totalString1 = numberFormat.format(this.total_ar_amount).replaceAll(",", ""); int indexdot = totalString1.indexOf("."); String beforeDecimal = totalString1.substring(0, indexdot); String afterDecimal = totalString1.substring(indexdot + 1, totalString1.length()); chargeCell = new PdfPCell(); chargeCell.setColspan(6); chargeCell.setBorder(0); p = new Paragraph(7f, "" + ConvertNumberToWords.convert(Integer.parseInt(beforeDecimal)) + " DOLLARS AND " + StringUtils.removeEnd(afterDecimal, "0") + " CENTS", totalFontQuote); chargeCell.setHorizontalAlignment(Element.ALIGN_CENTER); chargeCell.addElement(p); chargeTable.addCell(chargeCell); } chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(4); p = new Paragraph(5f, "" + sailDateFormat, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(5); chargeCell.setBorder(0); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setColspan(3); chargeCell.setBorder(0); chargeCell.setRowspan(3); String fdPodValue = null; if (agencyInfo != null && CommonUtils.isNotEmpty(agencyInfo[2])) { fdPodValue = agencyInfo[2]; } else if (CommonFunctions.isNotNull(lclbl.getFinalDestination()) && CommonFunctions.isNotNull(lclbl.getFinalDestination().getCountryId()) && CommonFunctions.isNotNull(lclbl.getFinalDestination().getCountryId().getCodedesc())) { fdPodValue = lclbl.getFinalDestination().getUnLocationName() + "," + lclbl.getFinalDestination().getCountryId().getCodedesc(); } p = new Paragraph(7f, fdPodValue != null ? fdPodValue.toUpperCase() : podValues.toUpperCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); p = new Paragraph(5f, "UNIT# " + unitNumber, headingblackBoldFont); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setPaddingTop(2f); p = new Paragraph(5f, "SEAL# " + sealOut, headingblackBoldFont); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); chargeCell = new PdfPCell(); chargeCell.setBorder(0); chargeCell.setColspan(3); chargeCell.setPaddingTop(2f); p = new Paragraph(5f, "CONTROL-VOY# " + voyageNumber, totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); chargeCell.addElement(p); chargeTable.addCell(chargeCell); String emailId = ""; StringBuilder agentDetails = new StringBuilder(); //Agent Details String agentAcctNo = ""; if ("Y".equalsIgnoreCase(altAgentKey)) { agentAcctNo = CommonUtils.isNotEmpty(altAgentValue) ? altAgentValue : ""; } else if (lclbl.getAgentAcct() != null) { agentAcctNo = (agencyInfo != null && CommonUtils.isNotEmpty(agencyInfo[0])) ? agencyInfo[0] : lclbl.getAgentAcct().getAccountno(); } if (CommonUtils.isNotEmpty(agentAcctNo)) { CustAddress custAddress = new CustAddressDAO().findPrimeContact(agentAcctNo); if (CommonFunctions.isNotNull(custAddress)) { if (CommonFunctions.isNotNull(custAddress.getAcctName())) { agentDetails.append(custAddress.getAcctName()).append(" "); } if (CommonFunctions.isNotNull(custAddress.getPhone())) { agentDetails.append("Phone: ").append(custAddress.getPhone()).append("\n"); } else { agentDetails.append("\n"); } if (CommonFunctions.isNotNull(custAddress.getCoName())) { agentDetails.append(custAddress.getCoName()).append("\n"); } if (CommonFunctions.isNotNull(custAddress.getAddress1())) { agentDetails.append(custAddress.getAddress1().replace(", ", "\n")).append("\n"); } if (CommonFunctions.isNotNull(custAddress.getCity1())) { agentDetails.append(custAddress.getCity1()); } if (CommonFunctions.isNotNull(custAddress.getState())) { agentDetails.append(" ").append(custAddress.getState()); } if (CommonFunctions.isNotNull(custAddress.getEmail1())) { emailId = custAddress.getEmail1(); } } } BigDecimal PrintInvoiceValue = null; if (lclbl.getPortOfDestination() != null) { boolean schnum = new LCLPortConfigurationDAO().getSchnumValue(lclbl.getPortOfDestination().getId()); if (schnum) { BigDecimal printInvoice = lclbl.getInvoiceValue(); Long fileId = lclbl.getFileNumberId(); if (!CommonUtils.isEmpty(printInvoice) && !CommonUtils.isEmpty(fileId)) { PrintInvoiceValue = printInvoice; } } } chargeCell = new PdfPCell(); chargeCell.setBorder(2); chargeCell.setColspan(6); chargeCell.setPadding(0f); PdfPTable agent_Contact_Table = new PdfPTable(3); agent_Contact_Table.setWidthPercentage(100f); agent_Contact_Table.setWidths(new float[] { 2.3f, 1.7f, 1.8f }); PdfPCell agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setBorderWidthTop(1f); agent_Contact_cell.setBorderWidthLeft(1f); agent_Contact_cell.setBorderWidthBottom(0.06f); agent_Contact_cell.setBorderWidthRight(1f); p = new Paragraph(7f, "To Pick Up Freight Please Contact: ", blackContentNormalFont); p.setAlignment(Element.ALIGN_LEFT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setColspan(2); agent_Contact_cell.setBorderWidthTop(1f); agent_Contact_cell.setPaddingBottom(2f); p = new Paragraph(7f, "Email: " + emailId.toLowerCase(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setColspan(2); agent_Contact_cell.setBorder(0); agent_Contact_cell.setBorderWidthLeft(1f); p = new Paragraph(7f, "" + agentDetails.toString(), totalFontQuote); p.setAlignment(Element.ALIGN_LEFT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setPaddingTop(27f); p = new Paragraph(7f, "" + agentAcctNo, totalFontQuote); p.setAlignment(Element.ALIGN_RIGHT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); agent_Contact_cell = new PdfPCell(); agent_Contact_cell.setBorder(0); agent_Contact_cell.setColspan(3); agent_Contact_cell.setBorderWidthLeft(1f); StringBuilder builder = new StringBuilder(); builder.append(PrintInvoiceValue != null ? "Value of Goods:USD $" + PrintInvoiceValue : ""); p = new Paragraph(3f, "" + builder.toString(), totalFontQuote); p.setAlignment(Element.ALIGN_RIGHT); agent_Contact_cell.addElement(p); agent_Contact_Table.addCell(agent_Contact_cell); chargeCell.addElement(agent_Contact_Table); chargeTable.addCell(chargeCell); return chargeTable; }
From source file:com.hris.payroll.reports.PayslipReportPDF.java
private PdfPTable leftColumnTable(PayrollRegister pr, Date payrollDate) throws DocumentException { PdfPTable table = new PdfPTable(3); table.setTotalWidth(new float[] { 120, 20, 103 }); table.setWidthPercentage(100);/*from ww w . jav a 2 s . c o m*/ table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setLockedWidth(true); PdfPCell cellTitle = new PdfPCell(); cellTitle.setColspan(3); Paragraph parTitle = new Paragraph(); parTitle.add(new Phrase("Payslip: ", header)); parTitle.setAlignment(Element.ALIGN_CENTER); cellTitle.addElement(parTitle); cellTitle.setBorder(cellBorder); table.addCell(cellTitle); PdfPCell cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); Paragraph parLabel = new Paragraph(); parLabel.add( new Phrase("Payroll Date: " + CommonUtil.convertDateFormat(getPayrollDate().toString()), content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // PdfPCell cellValue = new PdfPCell(); // cellValue.setUseAscender(true); // Paragraph parValue = new Paragraph(); // parValue.add(new Phrase(CommonUtil.convertDateFormat(getPayrollDate().toString()), content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); parLabel = new Paragraph(); parLabel.add( new Phrase( "Cut-off Date: " + CommonUtil.changeDateFormat(pr.getAttendancePeriodFrom().toString()) + " - " + CommonUtil.changeDateFormat(pr.getAttendancePeriodTo().toString()), content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // PdfPCell cellValue = new PdfPCell(); // cellValue.setUseAscender(true); // Paragraph parValue = new Paragraph(); // parValue.add(new Phrase(CommonUtil.convertDateFormat(pr.getAttendancePeriodFrom().toString())+" - "+CommonUtil.convertDateFormat(pr.getAttendancePeriodFrom().toString()), content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); parLabel = new Paragraph(); String middlename; if (pr.getMiddlename() == null || pr.getMiddlename().isEmpty()) { middlename = " "; } else { middlename = String.valueOf(pr.getMiddlename().toUpperCase().charAt(0)) + ". "; } String name = pr.getLastname().toUpperCase() + ", " + pr.getFirstname().toUpperCase() + " " + middlename; parLabel.add(new Phrase("Employee Name: " + name, content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // cellValue = new PdfPCell(); //// cellValue.setUseAscender(true); // parValue = new Paragraph(); // parValue.add(new Phrase(pr.getLastname().toUpperCase()+", "+pr.getFirstname().toUpperCase()+" "+pr.getMiddlename().toUpperCase().charAt(0)+".", employeeName)); //// parValue.add(new Phrase("NAME", content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); parLabel = new Paragraph(); String position = (ephs.findByEmployee(pr.getEmployeeId()).getPosition() == null) ? "N/A" : ephs.findByEmployee(pr.getEmployeeId()).getPosition().toUpperCase(); parLabel.add(new Phrase("POSITION: " + position, smallerFont)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // cellValue = new PdfPCell(); // cellValue.setUseAscender(true); // parValue = new Paragraph(); // parValue.add(new Phrase(CommonUtil.convertDateFormat(new Date().toString()), content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); // cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("Monthly/Daily Rate: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); PdfPCell cellValue = new PdfPCell(); // cellValue.setUseAscender(true); Paragraph parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getRate()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("Half-month Rate: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getHalfMonthSalary()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Overtime: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getOvertimePay())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Holiday Premium: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double premium = (pr.getLegalHolidayPay() + pr.getSpecialHolidayPay()) - (pr.getTotalLatesHolidayDeduction() + pr.getTotalUndertimeHolidayDeduction()); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(premium)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Working Day-off: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getWorkingDayOffPay())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Night Differential: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getNightDifferential())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Absences/Lates/Undertime: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double alu = pr.getAbsences() + pr.getTotalLatesDeduction() + pr.getTotalUndertimeDeduction(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(alu)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("GROSS PAY: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getGrossPay())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Allowances: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(" ", content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("COLA: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getColaAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Meal Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getMealAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("AFL: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getAllowanceForLiquidation()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Transportation Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); cellLabel.setColspan(2); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getTransportationAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Housing Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getOtherAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Communications Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getCommunicationAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("TOTAL PAY: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double totalPay = pr.getGrossPay() + pr.getCommunicationAllowance() + pr.getTransportationAllowance() + pr.getColaAllowance() + pr.getPerDiemAllowance() + pr.getMealAllowance() + pr.getOtherAllowance() + pr.getAllowanceForLiquidation(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(totalPay)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("DEDUCTIONS: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(" ", content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("SSS Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getSss())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("PHIC Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getPhic())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("HDMF Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getHdmf())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Withholoding Taxes: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getTax())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("SSS Loan: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "sss loan"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("HDMF Loan: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "hdmf loan"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Additional HDMF Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase( String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces( as.findAdvancesTotalAmount(pr.getPayrollId(), "additional HDMF contribution"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("PAG-IBIG 2: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "pag-ibig ii"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Advances to O/E: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(" ", content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Cash Bond: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash bond"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Cash Advance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash advance"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Lending: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "lending"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Jewelry: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "jewelry"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Staffhouse: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "staffhouse"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Hotel and Restaurant Charges: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase( String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces( as.findAdvancesTotalAmount(pr.getPayrollId(), "hotel and restaurant charges"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Cash Shortages: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash shortages"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Employee Charges: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "employee charges"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("ATM Initial Deposit: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "atm initial deposit"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Others__________________: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double otherCharges = as.findAdvancesTotalAmount(pr.getPayrollId(), "advances to o/e") + as.findAdvancesTotalAmount(pr.getPayrollId(), "other charges"); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(otherCharges)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("TOTAL DEDUCTIONS:", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double totalDeductions = as.findAdvancesTotalAmount(pr.getPayrollId()) + pr.getTax() + pr.getPhic() + pr.getHdmf() + pr.getSss(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(totalDeductions)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("NET PAY:", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double netPay = CommonUtil.roundOffToTwoDecimalPlaces(totalPay - totalDeductions); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(netPay)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase("Adjustments:", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getAdjustments())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); // parLabel.add(new Phrase("_____________________________", content)); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); // parValue.add(new Phrase(String.valueOf(totalPay - totalDeductions), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase("TOTAL AMOUNT TO BE RECEIVED:", smallFont)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(netPay + pr.getAdjustments())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); // cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase("Prepared By: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); // cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); // cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase("Conforme: ", content)); parValue.setAlignment(Element.ALIGN_LEFT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ int userId = ubas.findUserByBranch(getBranchId()); String employeeId = us.findEmployeeIdByUserId(userId); Employee e = es.findEmployeeById(employeeId); String payrollClerkMiddlename; if (e.getMiddlename() == null || e.getMiddlename().isEmpty()) { payrollClerkMiddlename = " "; } else { payrollClerkMiddlename = String.valueOf(e.getMiddlename().toUpperCase().charAt(0)) + ". "; } String payrollClerk = e.getFirstname().toUpperCase() + " " + payrollClerkMiddlename + e.getLastname().toUpperCase(); String employeeMiddlename; if (pr.getMiddlename() == null || pr.getMiddlename().isEmpty()) { employeeMiddlename = " "; } else { employeeMiddlename = String.valueOf(pr.getMiddlename().toUpperCase().charAt(0)) + ". "; } String employee = pr.getFirstname().toUpperCase() + " " + employeeMiddlename + pr.getLastname().toUpperCase(); cellLabel = new PdfPCell(); cellLabel.setPaddingTop(30); parLabel = new Paragraph(); parLabel.add(new Phrase(payrollClerk, smallerFont)); parLabel.setAlignment(Element.ALIGN_CENTER); cellLabel.addElement(parLabel); cellLabel.setBorder(Rectangle.BOTTOM); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setPaddingTop(30); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_CENTER); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setPaddingTop(30); parValue = new Paragraph(); parValue.add(new Phrase(employee, smallerFont)); parValue.setAlignment(Element.ALIGN_CENTER); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.BOTTOM); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); // parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Payroll Clerk", content)); parLabel.setAlignment(Element.ALIGN_CENTER); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); parLabel = new Paragraph(); // parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase("Employee", content)); parValue.setAlignment(Element.ALIGN_CENTER); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); return table; }