List of usage examples for com.lowagie.text Element ALIGN_RIGHT
int ALIGN_RIGHT
To view the source code for com.lowagie.text Element ALIGN_RIGHT.
Click Source Link
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
public int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colHeader, String[] widths, String[] align, String[] xtype, Document document) throws ServiceException { try {/*from www .jav a 2s . c o m*/ java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); PdfPTable table; float[] tcol; tcol = new float[colHeader.length + 1]; tcol[0] = 40; for (int i = 1; i < colHeader.length + 1; i++) { tcol[i] = Float.parseFloat(widths[i - 1]); } table = new PdfPTable(colHeader.length + 1); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); PdfPCell h2 = new PdfPCell( new Paragraph(fontFamilySelector.process("No.", FontContext.TABLE_HEADER, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); PdfPCell h1 = null; for (int hcol = stcol; hcol < colwidth2.length; hcol++) { h1 = new PdfPCell(new Paragraph( fontFamilySelector.process(colHeader[hcol], FontContext.TABLE_HEADER, tColor))); h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { h2 = new PdfPCell(new Paragraph( fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_DATA, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); JSONObject temp = store.getJSONObject(row); for (int col = 0; col < colwidth2.length; col++) { String str = temp.optString((colwidth2[col]), ""); try { if (xtype.length > 0) { str = formatValue(temp.optString((colwidth2[col]), ""), xtype[col]); } } catch (Exception e) { } Paragraph para = new Paragraph(fontFamilySelector.process(str, FontContext.TABLE_DATA, tColor)); h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); if (!align[col].equals("right") && !align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); } else if (align[col].equals("right")) { h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); } else if (align[col].equals("left")) { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } table.addCell(h1); } } document.add(table); document.newPage(); } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.addTable", e); } return stpcol; }
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
private PdfPCell calculateDiscount(double disc, KWLCurrency cur) throws SessionExpiredException { PdfPCell cell = null;//from w w w. j a v a 2s.c o m if (disc == 0) { cell = new PdfPCell(new Paragraph(fontFamilySelector.process("--", FontContext.NOTE_TEXT))); } else { cell = new PdfPCell(new Paragraph( fontFamilySelector.process(currencyRender(String.valueOf(disc), cur), FontContext.TABLE_DATA))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(15); cell.setPadding(5); } return cell; }
From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java
License:Open Source License
public void createInvoicePdf(Document document, int mode, Map<String, Object> DataInfo, Company com, DateFormat formatter, String currencyid, JSONArray productDetails, String preText, String postText, String baseUrl) throws DocumentException, JSONException { // mode 1 = quotation try {//from w w w .j a v a 2 s .co m KWLCurrency currencyObj = (KWLCurrency) hibernateTemplate.load(KWLCurrency.class, currencyid); config = new com.krawler.utils.json.base.JSONObject(DataInfo.get("config").toString()); PdfPTable tab2 = null; PdfPTable tab3 = null; PdfPTable mainTable = new PdfPTable(1); mainTable.setWidthPercentage(100); String invno = ""; String theader = ""; double quotationDisc = 0; double quotationtaxamount = 0; String quotationtaxname = ""; double totalAmount = 0; double quotationtaxpercent = 0; Date entryDate = null; String customerName = ""; String shipTo = ""; String memo = ""; // itr = idresult.getEntityList().iterator(); if (mode == 1) { theader = "Quotation"; invno = DataInfo.containsKey("invno") ? DataInfo.get("invno").toString() : ""; entryDate = DataInfo.containsKey("entrydate") ? (Date) DataInfo.get("entrydate") : new Date(); customerName = DataInfo.containsKey("customername") ? DataInfo.get("customername").toString() : ""; shipTo = DataInfo.containsKey("address") ? DataInfo.get("address").toString() : ""; memo = DataInfo.containsKey("memo") ? DataInfo.get("memo").toString() : ""; quotationDisc = DataInfo.containsKey("quotationdisc") ? Double.parseDouble(DataInfo.get("quotationdisc").toString()) : 0; quotationtaxamount = DataInfo.containsKey("quotationtax") ? Double.parseDouble(DataInfo.get("quotationtax").toString()) : 0; quotationtaxname = DataInfo.containsKey("quotationtaxname") ? DataInfo.get("quotationtaxname").toString() : ""; quotationtaxpercent = DataInfo.containsKey("quotationtaxpercent") ? Double.parseDouble(DataInfo.get("quotationtaxpercent").toString()) : 0; totalAmount = DataInfo.containsKey("totalamount") ? Double.parseDouble(DataInfo.get("totalamount").toString()) : 0; } String company[] = new String[4]; company[0] = com.getCompanyName(); company[1] = com.getAddress(); company[2] = com.getEmailID(); company[3] = com.getPhoneNumber(); PdfPTable table1 = new PdfPTable(2); table1.setWidthPercentage(100); table1.setWidths(new float[] { 50, 50 }); tab2 = new PdfPTable(1); PdfPCell invCell = null; invCell = createCell(theader, FontContext.TABLE_HEADER, Element.ALIGN_RIGHT, 0, 5); tab2.addCell(invCell); PdfPCell cel2 = new PdfPCell(tab2); cel2.setBorder(0); table1.addCell(cel2); PdfPCell mainCell11 = new PdfPCell(table1); mainCell11.setBorder(0); mainCell11.setPadding(10); mainTable.addCell(mainCell11); PdfPTable userTable2 = new PdfPTable(2); userTable2.setWidthPercentage(100); userTable2.setWidths(new float[] { 60, 40 }); tab3 = getCompanyInfo(company); PdfPTable tab4 = new PdfPTable(2); tab4.setWidthPercentage(100); tab4.setWidths(new float[] { 30, 70 }); PdfPCell cell2 = createCell(theader + " No.", FontContext.TABLE_HEADER, Element.ALIGN_LEFT, 0, 5); tab4.addCell(cell2); // String invno = mode != StaticValues.AUTONUM_BILLINGINVOICE ? inv.getInvoiceNumber() : inv1.getBillingInvoiceNumber(); cell2 = createCell(": " + invno, FontContext.SMALL_TEXT, Element.ALIGN_LEFT, 0, 5); tab4.addCell(cell2); cell2 = createCell("DATE ", FontContext.SMALL_TEXT, Element.ALIGN_LEFT, 0, 5); tab4.addCell(cell2); cell2 = createCell(": " + formatter.format(entryDate), FontContext.SMALL_TEXT, Element.ALIGN_LEFT, 0, 5); tab4.addCell(cell2); PdfPCell cell1 = new PdfPCell(tab3); cell1.setBorder(0); userTable2.addCell(cell1); cel2 = new PdfPCell(tab4); cel2.setBorder(0); userTable2.addCell(cel2); PdfPCell mainCell12 = new PdfPCell(userTable2); mainCell12.setBorder(0); mainCell12.setPadding(10); mainTable.addCell(mainCell12); PdfPTable tab5 = new PdfPTable(2); tab5.setWidthPercentage(100); tab5.setWidths(new float[] { 50, 50 }); PdfPCell cell3 = createCell("To, ", FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 5); tab5.addCell(cell3); cell3 = createCell("", FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 0); tab5.addCell(cell3); // cell3 = createCell("", fontRegularNormal, Element.ALIGN_LEFT, 0, 0); // tab5.addCell(cell3); cell3 = createCell(customerName, FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 5); tab5.addCell(cell3); cell3 = createCell("", FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 0); tab5.addCell(cell3); cell3 = createCell(shipTo, FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 5); tab5.addCell(cell3); PdfPCell mainCell14 = new PdfPCell(tab5); mainCell14.setBorder(0); //mainCell14.setPadding(10); mainTable.addCell(mainCell14); getHtmlCell(preText.trim(), mainTable, baseUrl); getHtmlCell("<br>", mainTable, baseUrl); getHtmlCell("<br>", mainTable, baseUrl); String[] header = { "S.No.", "PRODUCT", "DESCRIPTION", "QUANTITY", "UNIT PRICE", "DISCOUNT", "TAX", "LINE TOTAL" }; PdfPTable table = getBlankTable(); PdfPCell invcell = null; for (int i = 0; i < header.length; i++) { invcell = new PdfPCell( new Paragraph(fontFamilySelector.process(header[i], FontContext.TABLE_HEADER))); invcell.setHorizontalAlignment(Element.ALIGN_CENTER); invcell.setBackgroundColor(Color.LIGHT_GRAY); invCell.setBorder(0); invcell.setPadding(3); table.addCell(invcell); } addTableRow(mainTable, table); //Break table after adding header row table = getBlankTable(); String prodName = ""; String subtotal = ""; String quantity = ""; String rate = ""; String description = ""; String discount = ""; String prodtax = ""; int index = 0; double total = 0; for (int cnt = 0; cnt < productDetails.length(); cnt++) { JSONObject productInfo = productDetails.getJSONObject(cnt); prodName = productInfo.getString("productname"); description = productInfo.getString("description"); quantity = productInfo.getString("quantity"); rate = productInfo.getString("orderrate"); subtotal = productInfo.getString("amount"); discount = productInfo.getString("prdiscountamount"); prodtax = productInfo.getString("taxamount"); invcell = createCell((++index) + ".", FontContext.TABLE_DATA, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); invcell = createCell(prodName, FontContext.TABLE_DATA, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); invcell = createCell(description, FontContext.TABLE_DATA, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); invcell = createCell(quantity, FontContext.TABLE_DATA, Element.ALIGN_CENTER, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); invcell = createCell(currencyRender(rate, currencyObj), FontContext.TABLE_DATA, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); invcell = createCell(currencyRender(subtotal, currencyObj), FontContext.TABLE_DATA, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); invcell = createCell(currencyRender(prodtax, currencyObj), FontContext.TABLE_DATA, Element.ALIGN_CENTER, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); invcell = createCell(currencyRender(subtotal, currencyObj), FontContext.TABLE_DATA, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5); table.addCell(invcell); total += Double.valueOf(subtotal); addTableRow(mainTable, table); //Break table after adding detail's row table = getBlankTable(); } for (int j = 0; j < 98; j++) { invcell = new PdfPCell(new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)));//fontRegularBold)); invcell.setHorizontalAlignment(Element.ALIGN_CENTER); invcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT); table.addCell(invcell); } addTableRow(mainTable, table); //Break table after adding extra space table = getBlankTable(); cell3 = createCell("SUB TOTAL", FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, Rectangle.TOP, 5); cell3.setColspan(7); table.addCell(cell3); cell3 = createCell(currencyRender(String.valueOf(total), currencyObj), FontContext.TABLE_DATA, Element.ALIGN_RIGHT, 15, 5); table.addCell(cell3); cell3 = createCell("DISCOUNT(-)", FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, 0, 5); cell3.setColspan(7); table.addCell(cell3); cell3 = calculateDiscount(quotationDisc, currencyObj); table.addCell(cell3); StringBuffer taxNameStr = new StringBuffer(); if (!StringUtil.isNullOrEmpty(quotationtaxname)) { taxNameStr.append(quotationtaxname); taxNameStr.append(" "); taxNameStr.append(quotationtaxpercent); taxNameStr.append("% (+)"); } else { taxNameStr.append("TAX (+)"); } cell3 = createCell(taxNameStr.toString(), FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, 0, 5); cell3.setColspan(7); table.addCell(cell3); cell3 = createCell(currencyRender(String.valueOf(quotationtaxamount), currencyObj), FontContext.TABLE_DATA, Element.ALIGN_RIGHT, 15, 5); table.addCell(cell3); cell3 = createCell("TOTAL", FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, 0, 5); cell3.setColspan(7); table.addCell(cell3); cell3 = createCell(currencyRender(String.valueOf(totalAmount), currencyObj), FontContext.TABLE_DATA, Element.ALIGN_RIGHT, 15, 5); table.addCell(cell3); addTableRow(mainTable, table); String netinword = EnglishNumberToWordsOjb.convert(Double.parseDouble(String.valueOf(totalAmount)), currencyObj); String currencyname = currencyObj.getName(); cell3 = createCell("Amount (in words) : " + currencyname + " " + netinword + " Only.", FontContext.HEADER_NOTE, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP, 5); PdfPTable table2 = new PdfPTable(1); table2.addCell(cell3); PdfPCell mainCell62 = new PdfPCell(table2); mainCell62.setBorder(0); mainCell62.setPadding(10); mainTable.addCell(mainCell62); PdfPTable helpTable = new PdfPTable(new float[] { 8, 92 }); helpTable.setWidthPercentage(100); Phrase phrase1 = fontFamilySelector.process("Memo: ", FontContext.NOTE_TEXT); Phrase phrase2 = fontFamilySelector.process(memo, FontContext.TABLE_DATA);//fontRegularBold); PdfPCell pcell1 = new PdfPCell(phrase1); PdfPCell pcell2 = new PdfPCell(phrase2); pcell1.setBorder(0); pcell1.setPadding(10); pcell1.setPaddingRight(0); pcell2.setBorder(0); pcell2.setPadding(10); helpTable.addCell(pcell1); helpTable.addCell(pcell2); PdfPCell mainCell61 = new PdfPCell(helpTable); mainCell61.setBorder(0); mainTable.addCell(mainCell61); getHtmlCell("<br>", mainTable, baseUrl); getHtmlCell("<br>", mainTable, baseUrl); getHtmlCell(postText.trim(), mainTable, baseUrl); document.add(mainTable); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java
License:Open Source License
public int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2, String[] colHeader, String[] widths, String[] align, Document document, HttpServletRequest request) throws ServiceException { try {/*from w ww . ja va2 s .co m*/ DateFormat formatter = authHandlerDAOObj.getUserDateFormatter( sessionHandlerImpl.getDateFormatID(request), sessionHandlerImpl.getTimeZoneDifference(request), true); DateFormat frmt = authHandler.getDateFormatter(request); String currencyid = sessionHandlerImpl.getCurrencyID(request); int mode = Integer.parseInt(request.getParameter("get")); double totalCre = 0; double totalDeb = 0; java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); // fontSmallRegular.setColor(tColor); PdfPTable table; float[] tcol; tcol = new float[colHeader.length + 1]; tcol[0] = 40; for (int i = 1; i < colHeader.length + 1; i++) { tcol[i] = Float.parseFloat(widths[i - 1]); } table = new PdfPTable(colHeader.length + 1); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); PdfPCell h2 = new PdfPCell(new Paragraph( (new Phrase(fontFamilySelector.process("No.", FontContext.FOOTER_NOTE, tColor))))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); PdfPCell h1 = null; for (int hcol = stcol; hcol < colwidth2.length; hcol++) { String headerStr = StringUtil.serverHTMLStripper(colHeader[hcol]); if (align[hcol].equals("currency") && !colHeader[hcol].equals("")) { String currency = currencyRender("", currencyid); h1 = new PdfPCell(new Paragraph((new Phrase(fontFamilySelector .process(headerStr + "(" + currency + ")", FontContext.FOOTER_NOTE, tColor))))); } else { h1 = new PdfPCell(new Paragraph( (new Phrase(fontFamilySelector.process(headerStr, FontContext.FOOTER_NOTE, tColor))))); } h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); for (int row = strow; row < stprow; row++) { h2 = new PdfPCell( new Paragraph(fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_DATA))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); JSONObject temp = store.getJSONObject(row); if (mode == 116 || mode == 117) { totalCre = totalCre + Double .parseDouble(temp.getString("c_amount") != "" ? temp.getString("c_amount") : "0"); totalDeb = totalDeb + Double .parseDouble(temp.getString("d_amount") != "" ? temp.getString("d_amount") : "0"); } for (int col = 0; col < colwidth2.length; col++) { Paragraph para = null; String rowCurrencyId = temp.has("currencyid") ? temp.getString("currencyid") : currencyid; if (align[col].equals("currency") && !temp.getString(colwidth2[col]).equals("")) { String currency = currencyRender(temp.getString(colwidth2[col]), currencyid); para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA)); } else if (align[col].equals("rowcurrency") && !temp.getString(colwidth2[col]).equals("")) { String withCurrency = currencyRender(temp.getString(colwidth2[col]), rowCurrencyId); para = new Paragraph(fontFamilySelector.process(withCurrency, FontContext.TABLE_DATA)); } else if (align[col].equals("date") && !temp.getString(colwidth2[col]).equals("")) { try { String d1 = formatter.format(frmt.parse(temp.getString(colwidth2[col]))); para = new Paragraph(fontFamilySelector.process(d1, FontContext.TABLE_DATA)); } catch (Exception ex) { para = new Paragraph(fontFamilySelector.process(temp.getString(colwidth2[col]), FontContext.TABLE_DATA)); } } else if (colwidth2[col].equals("taxrate") || colwidth2[col].equals("permargin") && !colHeader[col].equals("")) { para = new Paragraph(fontFamilySelector.process( htmlPercentageRender(temp.getString(colwidth2[col]), true), FontContext.TABLE_DATA)); } else { if (colwidth2[col].equals("invoiceno")) { para = new Paragraph(fontFamilySelector.process(temp.getString("no").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("invoicedate")) { para = new Paragraph(fontFamilySelector.process(temp.getString("date").toString(), FontContext.TABLE_DATA)); } else if ((temp.isNull(colwidth2[col])) && !(colwidth2[col].equals("invoiceno")) && !(colwidth2[col].equals("invoicedate"))) { para = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("c_date")) { para = new Paragraph(fontFamilySelector.process(formatter.format( frmt.parse(temp.getString("c_date").toString() == "" ? temp.getString("d_date") : temp.getString("c_date"))), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("c_accountname")) { para = new Paragraph( fontFamilySelector.process( temp.getString("c_accountname").toString() == "" ? temp.getString("d_accountname").toString() : temp.getString("c_accountname").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("c_entryno")) { para = new Paragraph( fontFamilySelector.process( temp.getString("c_entryno").toString() == "" ? temp.getString("d_entryno").toString() : temp.getString("c_entryno").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_date")) { para = new Paragraph(fontFamilySelector.process(formatter.format( frmt.parse(temp.getString("d_date").toString() == "" ? temp.getString("c_date") : temp.getString("d_date"))), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_accountname")) { para = new Paragraph( fontFamilySelector.process( temp.getString("d_accountname").toString() == "" ? temp.getString("c_accountname").toString() : temp.getString("d_accountname").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_entryno")) { para = new Paragraph( fontFamilySelector.process( temp.getString("d_entryno").toString() == "" ? temp.getString("c_entryno").toString() : temp.getString("d_entryno").toString(), FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("perioddepreciation")) { double adj = temp.getDouble("perioddepreciation") - temp.getDouble("firstperiodamt"); String currency = currencyRender("" + adj, currencyid); if (adj < 0.0001) { para = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)); } else { para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA)); } } else if (colHeader[col].equals("Opening Balance") || colHeader[col].equals("Asset Value")) { String currency = currencyRender("" + Math.abs(temp.getDouble("openbalance")), currencyid); para = new Paragraph(fontFamilySelector.process(currency, FontContext.TABLE_DATA)); } else { if (colHeader[col].equals("Opening Balance Type")) { double bal = Double.parseDouble(temp.getString(colwidth2[col])); String str = bal == 0 ? "" : (bal < 0 ? "Credit" : "Debit"); if (str.equals("")) str = "N/A"; para = new Paragraph(fontFamilySelector.process(str, FontContext.TABLE_DATA)); } else { para = new Paragraph(fontFamilySelector.process( temp.getString(colwidth2[col]).toString(), FontContext.TABLE_DATA)); } } } h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); if (align[col].equals("currency") || align[col].equals("rowcurrency") || colwidth2[col].equals("taxrate") || colwidth2[col].equals("permargin")) { h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); } else if (align[col].equals("date")) { h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); } else { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } table.addCell(h1); } } if (mode == 116 || mode == 117) { Paragraph para1 = null; PdfPCell h3 = null; String totCr = ""; String totDb = ""; h3 = new PdfPCell(new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA))); if (config.getBoolean("gridBorder")) { h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT); } else { h3.setBorder(0); } h3.setPadding(4); h3.setBorderColor(Color.GRAY); h3.setBackgroundColor(Color.lightGray); h3.setHorizontalAlignment(Element.ALIGN_CENTER); h3.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h3); para1 = new Paragraph(fontFamilySelector.process("Total", FontContext.REPORT_TITLE)); h3 = new PdfPCell(para1); if (config.getBoolean("gridBorder")) { h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h3.setBorder(0); } h3.setPadding(4); h3.setBorderColor(Color.GRAY); h3.setBackgroundColor(Color.LIGHT_GRAY); h3.setHorizontalAlignment(Element.ALIGN_LEFT); h3.setVerticalAlignment(Element.ALIGN_LEFT); table.addCell(h3); for (int col = 1; col < colwidth2.length; col++) { if (colwidth2[col].equals("c_amount")) { totCr = currencyRender(String.valueOf(totalCre), currencyid); para1 = new Paragraph(fontFamilySelector.process(totCr, FontContext.TABLE_DATA)); } else if (colwidth2[col].equals("d_amount")) { totDb = currencyRender(String.valueOf(totalDeb), currencyid); para1 = new Paragraph(fontFamilySelector.process(totDb, FontContext.TABLE_DATA)); } else { para1 = new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)); } h3 = new PdfPCell(para1); if (config.getBoolean("gridBorder")) { h3.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h3.setBorder(0); } h3.setPadding(4); h3.setBorderColor(Color.GRAY); h3.setBackgroundColor(Color.LIGHT_GRAY); h3.setHorizontalAlignment(Element.ALIGN_RIGHT); h3.setVerticalAlignment(Element.ALIGN_RIGHT); table.addCell(h3); } } document.add(table); document.newPage(); } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.addTable", e); } return stpcol; }
From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java
License:Open Source License
public int addGroupableTable(JSONObject groupingConfig, String groupByField, String groupHeaderText, int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] dataIndexArr, String[] colHeader, String[] widths, String[] align, Document document, HttpServletRequest request) throws ServiceException { try {//from ww w .j a va 2 s . c o m String groupSummaryField = groupingConfig.getString("groupSummaryField"); String groupSummaryText = groupingConfig.getString("groupSummaryText"); String reportSummaryField = groupingConfig.getString("reportSummaryField"); String reportSummaryText = groupingConfig.getString("reportSummaryText"); DateFormat formatter = authHandlerDAOObj.getUserDateFormatter( sessionHandlerImpl.getDateFormatID(request), sessionHandlerImpl.getTimeZoneDifference(request), true); DateFormat frmt = authHandler.getDateFormatter(request); String currencyid = sessionHandlerImpl.getCurrencyID(request); java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16)); java.awt.Color gsBGColor = new Color(Integer.parseInt("E5E5E5", 16)); java.awt.Color rsBGColor = new Color(Integer.parseInt("808080", 16)); // fontRegular.setColor(tColor); PdfPTable table; float[] tcol; tcol = new float[colHeader.length + 1]; tcol[0] = 40; for (int i = 1; i < colHeader.length + 1; i++) { tcol[i] = Float.parseFloat(widths[i - 1]); } table = new PdfPTable(colHeader.length + 1); table.setWidthPercentage(tcol, document.getPageSize()); table.setSpacingBefore(15); PdfPCell h2 = new PdfPCell( new Paragraph(fontFamilySelector.process("No.", FontContext.TABLE_HEADER, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOX); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(h2); PdfPCell h1 = null; for (int hcol = stcol; hcol < dataIndexArr.length; hcol++) { if (align[hcol].equals("currency") && !colHeader[hcol].equals("")) { String currency = currencyRender("", currencyid); h1 = new PdfPCell(new Paragraph(fontFamilySelector .process(colHeader[hcol] + "(" + currency + ")", FontContext.TABLE_HEADER, tColor))); } else { h1 = new PdfPCell(new Paragraph( fontFamilySelector.process(colHeader[hcol], FontContext.TABLE_HEADER, tColor))); } h1.setHorizontalAlignment(Element.ALIGN_CENTER); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOX); } else { h1.setBorder(0); } h1.setBorderColor(Color.GRAY); h1.setPadding(4); table.addCell(h1); } table.setHeaderRows(1); String groupName = "", rowCurrency = ""; Double subTotal = 0.0; Double grandTotal = 0.0; int rowSpan = 0; for (int row = strow; row < stprow; row++) { rowSpan++; JSONObject rowData = store.getJSONObject(row); if (row == 0) { groupName = rowData.getString(groupByField); rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid; subTotal = 0.0; addGroupRow(groupHeaderText + ": " + groupName, currencyid, table, dataIndexArr); } if (!groupName.equalsIgnoreCase(rowData.getString(groupByField))) { addSummaryRow(groupSummaryText + groupName + " ", subTotal, rowCurrency, table, dataIndexArr, false, gsBGColor); groupName = rowData.getString(groupByField); rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid; addGroupRow(groupHeaderText + ": " + groupName, currencyid, table, dataIndexArr); subTotal = 0.0; rowSpan = 1; } subTotal += Double.parseDouble(rowData.getString(groupSummaryField)); grandTotal += Double.parseDouble(rowData.getString(reportSummaryField)); rowCurrency = rowData.has("currencyid") ? rowData.getString("currencyid") : currencyid; h2 = new PdfPCell(new Paragraph( fontFamilySelector.process(String.valueOf(row + 1), FontContext.TABLE_HEADER, tColor))); if (config.getBoolean("gridBorder")) { h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h2.setBorder(0); } h2.setPadding(4); h2.setBorderColor(Color.GRAY); h2.setHorizontalAlignment(Element.ALIGN_CENTER); h2.setVerticalAlignment(Element.ALIGN_CENTER); table.addCell(h2); for (int col = 0; col < dataIndexArr.length; col++) { String cellData = null; if (align[col].equals("currency") && !rowData.getString(dataIndexArr[col]).equals("")) { cellData = currencyRender(rowData.getString(dataIndexArr[col]), rowData.getString("currencyid")); } else if (align[col].equals("date") && !rowData.getString(dataIndexArr[col]).equals("")) { try { cellData = formatter.format(frmt.parse(rowData.getString(dataIndexArr[col]))); } catch (Exception ex) { cellData = rowData.getString(dataIndexArr[col]); } } else { cellData = rowData.getString(dataIndexArr[col]); } Paragraph para = new Paragraph( fontFamilySelector.process(cellData, FontContext.TABLE_HEADER, tColor)); h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); if (!align[col].equals("currency") && !align[col].equals("date")) { h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); } else if (align[col].equals("currency")) { h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); } else if (align[col].equals("date")) { h1.setHorizontalAlignment(Element.ALIGN_CENTER); h1.setVerticalAlignment(Element.ALIGN_CENTER); } table.addCell(h1); } } if (rowSpan > 0) { addSummaryRow(groupSummaryText + groupName + " ", subTotal, rowCurrency, table, dataIndexArr, false, gsBGColor); } addSummaryRow(reportSummaryText, grandTotal, currencyid, table, dataIndexArr, false, rsBGColor); document.add(table); document.newPage(); } catch (Exception e) { throw ServiceException.FAILURE("exportDAOImpl.addTable", e); } return stpcol; }
From source file:com.krawler.spring.exportFunctionality.exportMPXDAOImpl.java
License:Open Source License
public void addSummaryRow(String summeryText, double subTotal, String currencyid, PdfPTable table, String[] dataIndexArr, boolean addBlankRow, java.awt.Color bgColor) throws JSONException, SessionExpiredException { Paragraph para = new Paragraph(fontFamilySelector.process(summeryText, FontContext.TABLE_HEADER)); PdfPCell h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.TOP | PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else {/* w ww. ja v a 2 s . c o m*/ h1.setBorder(PdfPCell.TOP); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); h1.setColspan(dataIndexArr.length); h1.setBackgroundColor(bgColor); table.addCell(h1); String withCurrency = currencyRender(Double.toString(subTotal), currencyid); para = new Paragraph(fontFamilySelector.process(withCurrency, FontContext.TABLE_HEADER)); h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.TOP | PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(PdfPCell.TOP); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); h1.setHorizontalAlignment(Element.ALIGN_RIGHT); h1.setVerticalAlignment(Element.ALIGN_RIGHT); h1.setBackgroundColor(bgColor); table.addCell(h1); if (addBlankRow) { para = new Paragraph(fontFamilySelector.process(" ", FontContext.TABLE_HEADER)); h1 = new PdfPCell(para); if (config.getBoolean("gridBorder")) { h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); } else { h1.setBorder(0); } h1.setPadding(4); h1.setBorderColor(Color.GRAY); h1.setHorizontalAlignment(Element.ALIGN_LEFT); h1.setVerticalAlignment(Element.ALIGN_LEFT); h1.setColspan(dataIndexArr.length + 1); table.addCell(h1); } }
From source file:com.krawler.spring.hrms.payroll.payslip.ExportPayslipController.java
License:Open Source License
public ModelAndView exportPDF(HttpServletRequest request, HttpServletResponse response) { JSONObject jsonResp = new JSONObject(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = null;/*from w w w . ja va 2s. c o m*/ try { Company company = (Company) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.Company", sessionHandlerImplObj.getCompanyid(request)); int i = 0; DecimalFormat decfm = new DecimalFormat("#,##0.00"); Date d2 = null; Date d3 = null; int days = 0; boolean showborder = true; if (!StringUtil.isNullOrEmpty(request.getParameter("showborder"))) { showborder = Boolean.parseBoolean(request.getParameter("showborder")); } SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy"); String stDate = request.getParameter("stdate").replace("/", "-"); String endDate = request.getParameter("enddate").replace("/", "-"); d2 = sdf.parse(stDate); d3 = sdf.parse(endDate); days = getWorkingDays(request.getParameter("stdate").replace("/", "-"), request.getParameter("enddate").replace("/", "-"), company.getCompanyID()); String historyid = ""; List<Payhistory> lst = exportPayslipDAO.getPayhistory(request.getParameter("empid"), d2, d3); ; if (lst != null && lst.size() == 0) { throw new Exception("Exception occured"); } else if (lst != null && lst.size() > 0) { String currSymbol = getCurrencySymbol(request, false); masterDB.Payhistory payhistory = (masterDB.Payhistory) lst.get(0); historyid = payhistory.getHistoryid(); double unpaidleaves = payhistory.getUnpaidleaves(); Document document = new Document(PageSize.A4, 15, 15, 15, 15); writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage(request)); document.open(); String userid = request.getParameter("empid"); User userinfo = payhistory.getUserID(); Useraccount ua = (Useraccount) kwlCommonTablesDAOObj .getObject("com.krawler.common.admin.Useraccount", userinfo.getUserID()); String uname = userinfo.getLastName() != null ? userinfo.getLastName() : ""; String empid = getUserCode(ua, company.getCompanyID()); String department = payhistory.getDepartment(); String designation = getUserDesignation(ua); String bankacc = ua.getAccno() != null ? ua.getAccno() : ""; Empprofile empprof = null; String epf = ""; String dateofjoin = ""; try { empprof = (Empprofile) kwlCommonTablesDAOObj.getObject("com.krawler.hrms.ess.Empprofile", userid); epf = StringUtil.isNullOrEmpty(empprof.getPfno()) ? "" : empprof.getPfno(); dateofjoin = empprof.getJoindate() != null ? empprof.getJoindate().toString() : ""; } catch (Exception ex) { epf = ""; } PdfPTable mainTable = new PdfPTable(1); mainTable.setWidthPercentage(100); PdfPTable table1 = new PdfPTable(3); table1.setWidthPercentage(100); table1.setWidths(new float[] { 40, 40, 20 }); PdfPTable userTable1 = new PdfPTable(1); String cmpid = AuthHandler.getCompanyid(request); userTable1.setHorizontalAlignment(Element.ALIGN_MIDDLE); userTable1.setWidthPercentage(10); PdfPCell cell11 = null; PdfPCell cell1x = new PdfPCell( new Paragraph(fontFamilySelector.process(" ", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN))); cell1x.setBorder(0); userTable1.addCell(cell1x); try { String imgPath = StorageHandler.GetProfileImgStorePath() + cmpid + ".png"; if (StringUtil.isStandAlone()) { imgPath = URLUtil.getPageURL(request, "").concat(ProfileImageServlet.defaultCompanyImgPath); } Image img = Image.getInstance(imgPath); cell11 = new PdfPCell(img); cell11.setPaddingLeft(5); } catch (Exception e) { cell11 = new PdfPCell(new Paragraph(fontFamilySelector .process(AuthHandler.getCompanyName(request), FontContext.TABLE_BOLD_TIMES_NEW_ROMAN))); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); } if (cell11 != null) { cell11.setBorder(0); userTable1.addCell(cell11); } PdfPCell cell1 = new PdfPCell( new Paragraph(fontFamilySelector.process("", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN))); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setBorder(0); userTable1.addCell(cell1); PdfPTable userTable2 = new PdfPTable(1); userTable2.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getCompanyName(), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); cell.setPaddingTop(15); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph( fontFamilySelector.process(company.getCity(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getAddress(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph( fontFamilySelector.process(company.getState(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getZipCode(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.payslip.period.params", new Object[] { request.getParameter("stdate"), request.getParameter("enddate") }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); PdfPTable userTable3 = new PdfPTable(1); userTable3.setWidthPercentage(100); PdfPCell cell2 = new PdfPCell( new Paragraph(fontFamilySelector.process("", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell2.setHorizontalAlignment(Element.ALIGN_LEFT); cell2.setBorder(0); userTable1.addCell(cell2); PdfPCell mainCell11 = new PdfPCell(userTable1); if (!showborder) { mainCell11.setBorder(0); } else { mainCell11.setBorder(Rectangle.LEFT); } table1.addCell(mainCell11); PdfPCell mainCell13 = new PdfPCell(userTable2); mainCell13.setBorder(0); table1.addCell(mainCell13); PdfPCell mainCell15 = new PdfPCell(userTable3); if (!showborder) { mainCell15.setBorder(0); } else { mainCell15.setBorder(Rectangle.RIGHT); } table1.addCell(mainCell15); PdfPCell mainCell12 = new PdfPCell(new Paragraph("")); if (!showborder) { mainCell12.setBorder(0); } else { mainCell12.setBorder(Rectangle.LEFT); } table1.addCell(mainCell12); PdfPCell mainCell14 = new PdfPCell(new Paragraph("")); mainCell14.setBorder(0); table1.addCell(mainCell14); PdfPCell mainCell16 = new PdfPCell(new Paragraph("")); if (!showborder) { mainCell16.setBorder(0); } else { mainCell16.setBorder(Rectangle.RIGHT); } table1.addCell(mainCell16); PdfPCell mainCell1 = new PdfPCell(table1); if (!showborder) { mainCell1.setBorder(0); } else { mainCell1.setBorder(1); } mainTable.addCell(mainCell1); // __________________________________________________________________________ PdfPTable table2 = new PdfPTable(4); table2.setWidthPercentage(100); table2.setWidths(new float[] { 20, 30, 20, 30 }); PdfPCell h11 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.employee.code", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h11.setHorizontalAlignment(Element.ALIGN_LEFT); h11.setPadding(5); if (!showborder) { h11.setBorder(0); } table2.addCell(h11); PdfPCell h12 = new PdfPCell(new Paragraph( fontFamilySelector.process("" + empid, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h12.setHorizontalAlignment(Element.ALIGN_LEFT); h12.setPadding(5); if (!showborder) { h12.setBorder(0); } table2.addCell(h12); PdfPCell h13 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h13.setHorizontalAlignment(Element.ALIGN_LEFT); h13.setPadding(5); if (!showborder) { h13.setBorder(0); } table2.addCell(h13); PdfPCell h14 = new PdfPCell(new Paragraph(fontFamilySelector .process(userinfo.getFirstName() + " " + uname, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h14.setHorizontalAlignment(Element.ALIGN_LEFT); h14.setPadding(5); if (!showborder) { h14.setBorder(0); } table2.addCell(h14); PdfPCell h21 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.department", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h21.setHorizontalAlignment(Element.ALIGN_LEFT); h21.setPadding(5); if (!showborder) { h21.setBorder(0); } table2.addCell(h21); PdfPCell h22 = new PdfPCell(new Paragraph( fontFamilySelector.process(department, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h22.setHorizontalAlignment(Element.ALIGN_LEFT); h22.setPadding(5); if (!showborder) { h22.setBorder(0); } table2.addCell(h22); PdfPCell h33 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.designation", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h33.setHorizontalAlignment(Element.ALIGN_LEFT); h33.setPadding(5); if (!showborder) { h33.setBorder(0); } table2.addCell(h33); PdfPCell h34 = new PdfPCell(new Paragraph( fontFamilySelector.process(designation, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h34.setHorizontalAlignment(Element.ALIGN_LEFT); h34.setPadding(5); if (!showborder) { h34.setBorder(0); } table2.addCell(h34); PdfPCell h43 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.bank.ac.no", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h43.setHorizontalAlignment(Element.ALIGN_LEFT); h43.setPadding(5); if (!showborder) { h43.setBorder(0); } table2.addCell(h43); PdfPCell h44 = new PdfPCell(new Paragraph( fontFamilySelector.process(bankacc, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h44.setHorizontalAlignment(Element.ALIGN_LEFT); h44.setPadding(5); if (!showborder) { h44.setBorder(0); } table2.addCell(h44); PdfPCell h61 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.working.days", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h61.setHorizontalAlignment(Element.ALIGN_LEFT); h61.setPadding(5); if (!showborder) { h61.setBorder(0); } table2.addCell(h61); PdfPCell h62 = new PdfPCell(new Paragraph(fontFamilySelector.process(String.valueOf(days), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h62.setHorizontalAlignment(Element.ALIGN_LEFT); h62.setPadding(5); if (!showborder) { h62.setBorder(0); } table2.addCell(h62); PdfPCell h63 = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.e.p.f", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h63.setHorizontalAlignment(Element.ALIGN_LEFT); h63.setPadding(5); if (!showborder) { h63.setBorder(0); } table2.addCell(h63); PdfPCell h64 = new PdfPCell( new Paragraph(fontFamilySelector.process(epf, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h64.setHorizontalAlignment(Element.ALIGN_LEFT); h64.setPadding(5); if (!showborder) { h64.setBorder(0); } table2.addCell(h64); PdfPCell h65 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.common.DateofJoining", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h65.setHorizontalAlignment(Element.ALIGN_LEFT); h65.setPadding(5); if (!showborder) { h65.setBorder(0); } table2.addCell(h65); PdfPCell h66 = new PdfPCell(new Paragraph( fontFamilySelector.process(dateofjoin, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); h66.setHorizontalAlignment(Element.ALIGN_LEFT); h66.setPadding(5); if (!showborder) { h66.setBorder(0); } table2.addCell(h66); for (int y = 0; y < 2; y++) { PdfPCell h71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { h71.setBorder(0); } else { h71.setBorder(Rectangle.LEFT); } table2.addCell(h71); for (i = 0; i < 2; i++) { h71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h71.setHorizontalAlignment(Element.ALIGN_LEFT); h71.setBorder(0); table2.addCell(h71); } h71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); h71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { h71.setBorder(0); } else { h71.setBorder(Rectangle.RIGHT); } table2.addCell(h71); } PdfPCell mainCell2 = new PdfPCell(table2); if (!showborder) { mainCell2.setBorder(0); } else { mainCell2.setBorder(1); } mainTable.addCell(mainCell2); PdfPTable table3main = new PdfPTable(1); table3main.setWidthPercentage(100); PdfPTable table7main = new PdfPTable(1); table7main.setWidthPercentage(100); PdfPTable table31 = new PdfPTable(4); table31.setWidthPercentage(100); table31.setWidths(new float[] { 30, 20, 30, 20 }); PdfPTable table41 = new PdfPTable(2); table41.setWidthPercentage(100); table41.setWidths(new float[] { 50, 50 }); //*************************************************************************************************************** PdfPCell s11 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.Earnings", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s11.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s11.setBorder(0); } else { s11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } s11.setPadding(5); table31.addCell(s11); PdfPCell s12 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s12.setHorizontalAlignment(Element.ALIGN_RIGHT); s12.setPadding(5); if (!showborder) { s12.setBorder(0); } else { s12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } table31.addCell(s12); PdfPCell s14 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.Deduction", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s14.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s14.setBorder(0); } else { s14.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } s14.setPadding(5); table31.addCell(s14); PdfPCell s15 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s15.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s15.setBorder(0); } else { s15.setBorder(Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM); } s15.setPadding(5); table31.addCell(s15); int Wcount = 0; float taxtotal = 0; List<Historydetail> lst1 = exportPayslipDAO.getHistorydetail(historyid, "Wages", "Basic"); List<Historydetail> list = exportPayslipDAO.getHistorydetailNotType(historyid, "Wages", "Basic"); if (list != null) { lst1.addAll(list); } List<Historydetail> lst2 = exportPayslipDAO.getHistorydetail(historyid, "Taxes"); CompanyPreferences cp = hrmsCommonDAOObj.getCompanyPreferences(company.getCompanyID()); int financialMonth = cp.getFinancialmonth(); Calendar c1 = Calendar.getInstance(); c1.setTime(d3); c1.set(Calendar.MONTH, financialMonth); c1.set(Calendar.DATE, 1); Date d = c1.getTime(); Date DOJ = new java.util.Date(empprof.getJoindate().getTime()); if (d3.before(d)) { int currentYear = c1.get(Calendar.YEAR) - 1; c1.set(Calendar.YEAR, currentYear); d = c1.getTime(); } if (DOJ.after(d)) { c1.setTime(DOJ); c1.set(Calendar.DATE, 1); d = c1.getTime(); } List<Historydetail> lst3 = exportPayslipDAO.getHistorydetail(historyid, "Deduction"); int size = lst1.size() > (lst2.size() + lst3.size()) ? lst1.size() : lst2.size() + lst3.size(); float wagetotal = 0; double totalYTDEarning = 0, totalYTDDeduction = 0; for (i = 0; i < size; i++) { masterDB.Historydetail hd = null; if (i < lst1.size()) { hd = (masterDB.Historydetail) lst1.get(i); PdfPCell s21 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s21.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s21.setBorder(0); } else { s21.setBorder(Rectangle.LEFT); } s21.setPadding(5); table31.addCell(s21); BigDecimal bd = new BigDecimal(hd.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s22 = new PdfPCell( new Paragraph(fontFamilySelector.process(String.valueOf(decfm.format(newamount)), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s22.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s22.setBorder(0); } else { s22.setBorder(Rectangle.LEFT); } s22.setPadding(5); table31.addCell(s22); List<Historydetail> lstw = exportPayslipDAO.getHistorydetail(request.getParameter("empid"), d, d3, hd.getType()); double wageAmt = 0; masterDB.Historydetail hd1 = null; for (int y = 0; y < lstw.size(); y++) { hd1 = (masterDB.Historydetail) lstw.get(y); wageAmt += Double.parseDouble(hd1.getAmount()); } wagetotal = wagetotal + Float.parseFloat(hd.getAmount()); totalYTDEarning = totalYTDEarning + wageAmt; Wcount++; } else { for (int j = 0; j < 2; j++) { PdfPCell s21 = new PdfPCell(new Paragraph( fontFamilySelector.process("", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s21.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s21.setBorder(0); } else { s21.setBorder(Rectangle.LEFT); } s21.setPadding(5); table31.addCell(s21); } } if (i < lst2.size()) { hd = (masterDB.Historydetail) lst2.get(i); PdfPCell s24 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s24.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s24.setBorder(0); } else { s24.setBorder(Rectangle.LEFT); } s24.setPadding(5); table31.addCell(s24); BigDecimal bd = new BigDecimal(hd.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector .process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); } s25.setPadding(5); table31.addCell(s25); List<Historydetail> lstw1 = exportPayslipDAO.getHistorydetail(request.getParameter("empid"), d, d3, hd.getType()); double taxAmt = 0; masterDB.Historydetail hd2 = null; for (int y = 0; y < lstw1.size(); y++) { hd2 = (masterDB.Historydetail) lstw1.get(y); taxAmt += Double.parseDouble(hd2.getAmount()); } taxtotal = taxtotal + Float.parseFloat(hd.getAmount()); totalYTDDeduction = totalYTDDeduction + taxAmt; } else { if (i - lst2.size() < lst3.size()) { hd = (masterDB.Historydetail) lst3.get(i - lst2.size()); PdfPCell s24 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); if (hd.getType().equals("Unpaid_leaves")) { s24 = new PdfPCell(new Paragraph( fontFamilySelector.process(hd.getType() + "(" + unpaidleaves + ")", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); } s24.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s24.setBorder(0); } else { s24.setBorder(Rectangle.LEFT); } s24.setPadding(5); table31.addCell(s24); BigDecimal bd = new BigDecimal(hd.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector .process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); ; } s25.setPadding(5); table31.addCell(s25); List<Historydetail> lstw2 = exportPayslipDAO .getHistorydetail(request.getParameter("empid"), d, d3, hd.getType()); masterDB.Historydetail hd3 = null; double deductAmt = 0; for (int y = 0; y < lstw2.size(); y++) { hd3 = (masterDB.Historydetail) lstw2.get(y); deductAmt += Double.parseDouble(hd3.getAmount()); } taxtotal = taxtotal + Float.parseFloat(hd.getAmount()); totalYTDDeduction = totalYTDDeduction + deductAmt; } else { for (int j = 0; j < 2; j++) { PdfPCell s21 = new PdfPCell(new Paragraph( fontFamilySelector.process("", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s21.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s21.setBorder(0); } else { s21.setBorder(Rectangle.LEFT + Rectangle.RIGHT); } s21.setPadding(5); table31.addCell(s21); } } } } PdfPCell s91 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.total.earnings", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s91.setHorizontalAlignment(Element.ALIGN_BASELINE); s91.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s91.setBorder(0); } else { s91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s91.setPadding(5); table31.addCell(s91); BigDecimal bd = new BigDecimal(String.valueOf(wagetotal)); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); double newamount = bd.doubleValue(); PdfPCell s92 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s92.setHorizontalAlignment(Element.ALIGN_BASELINE); s92.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s92.setBorder(0); } else { s92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s92.setPadding(5); table31.addCell(s92); PdfPCell s94 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.total.deductions", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); s94.setHorizontalAlignment(Element.ALIGN_BASELINE); s94.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s94.setBorder(0); } else { s94.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s94.setPadding(5); table31.addCell(s94); bd = new BigDecimal(String.valueOf(taxtotal)); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); newamount = bd.doubleValue(); PdfPCell s95 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s95.setHorizontalAlignment(Element.ALIGN_BASELINE); s95.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s95.setBorder(0); } else { s95.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } s95.setPadding(5); table31.addCell(s95); for (int y = 0; y < 2; y++) { PdfPCell he71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); he71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { he71.setBorder(0); } else { he71.setBorder(Rectangle.LEFT); } table31.addCell(he71); for (i = 0; i < 2; i++) { he71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); he71.setHorizontalAlignment(Element.ALIGN_LEFT); he71.setBorder(0); table31.addCell(he71); } he71 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); he71.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { he71.setBorder(0); } else { he71.setBorder(Rectangle.RIGHT); } table31.addCell(he71); } List<Historydetail> lst4 = exportPayslipDAO.getHistorydetail(historyid, "Employer Contribution"); double ectotal = 0; PdfPCell ec11 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.EmployerContribution", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); ec11.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { ec11.setBorder(0); } else { ec11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } ec11.setPadding(5); table41.addCell(ec11); PdfPCell ec12 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); ec12.setHorizontalAlignment(Element.ALIGN_RIGHT); ec12.setPadding(5); if (!showborder) { ec12.setBorder(0); } else { ec12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM + Rectangle.RIGHT); } table41.addCell(ec12); masterDB.Historydetail hd1 = null; for (i = 0; i < lst4.size(); i++) { hd1 = (masterDB.Historydetail) lst4.get(i); PdfPCell s24 = new PdfPCell(new Paragraph( fontFamilySelector.process(hd1.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s24.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { s24.setBorder(0); } else { s24.setBorder(Rectangle.LEFT); } s24.setPadding(5); table41.addCell(s24); bd = new BigDecimal(hd1.getAmount()); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); newamount = bd.doubleValue(); ectotal = ectotal + newamount; PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); } s25.setPadding(5); table41.addCell(s25); } PdfPCell se91 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.total.contribution", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); se91.setHorizontalAlignment(Element.ALIGN_BASELINE); se91.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { se91.setBorder(0); } else { se91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM); } se91.setPadding(5); table41.addCell(se91); bd = new BigDecimal(String.valueOf(ectotal)); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); newamount = bd.doubleValue(); PdfPCell se92 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN))); se92.setHorizontalAlignment(Element.ALIGN_BASELINE); se92.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { se92.setBorder(0); } else { se92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM + Rectangle.RIGHT); } se92.setPadding(5); table41.addCell(se92); PdfPCell Cell31 = new PdfPCell(table31); if (!showborder) { Cell31.setBorder(0); } else { Cell31.setBorder(1); } table3main.addCell(Cell31); PdfPCell mainCell4 = new PdfPCell(table3main); if (!showborder) { mainCell4.setBorder(0); } else { mainCell4.setBorder(1); } mainTable.addCell(mainCell4); PdfPCell Cell41 = new PdfPCell(table41); if (!showborder) { Cell41.setBorder(0); } else { Cell41.setBorder(1); } table7main.addCell(Cell41); PdfPCell mainCell44 = new PdfPCell(table7main); if (!showborder) { mainCell44.setBorder(0); } else { mainCell44.setBorder(1); } mainTable.addCell(mainCell44); //*************************************************************************************************************** PdfPTable table4 = new PdfPTable(2); table4.setWidthPercentage(100); for (i = 0; i < 4; i++) { PdfPCell i33 = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i33.setHorizontalAlignment(Element.ALIGN_CENTER); if (!showborder) { i33.setBorder(0); } else { i33.setBorder(Rectangle.LEFT + Rectangle.RIGHT); } table4.addCell(i33); } PdfPCell i31 = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.netpay", null, RequestContextUtils.getLocale(request)) + " ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i31.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { i31.setBorder(0); } else { i31.setBorder(Rectangle.LEFT + Rectangle.TOP); } i31.setPadding(5); table4.addCell(i31); double netpay = 0; netpay = wagetotal - taxtotal; netpay = Math.round(netpay); String amount = numberFormatter((double) netpay, currSymbol); PdfPCell i33 = new PdfPCell( new Paragraph(fontFamilySelector.process(amount, FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i33.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { i33.setBorder(0); } else { i31.setBorder(Rectangle.RIGHT); } i33.setPadding(5); table4.addCell(i33); PdfPCell i32 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.in.words", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i32.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { i32.setBorder(0); } else { i31.setBorder(Rectangle.LEFT); } i32.setPadding(5); table4.addCell(i32); EnglishNumberToWords enw = new EnglishNumberToWords(request, messageSource); String netinword = enw.convert(netpay); PdfPCell i34 = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.only", new Object[] { getCurrencyName(request), netinword }, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); i34.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { i34.setBorder(0); } else { i31.setBorder(Rectangle.RIGHT); } i34.setPadding(5); table4.addCell(i34); PdfPCell mainCell5 = new PdfPCell(table4); if (!showborder) { mainCell5.setBorder(0); } else { mainCell5.setBorder(1); } mainTable.addCell(mainCell5); document.add(new Paragraph("\n\n")); PdfPTable table5 = new PdfPTable(2); table5.setWidthPercentage(80); cell = new PdfPCell(new Paragraph("___________________________")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); cell = new PdfPCell(new Paragraph("___________________________")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); cell = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.employee.signature", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); cell = new PdfPCell( new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.payroll.manager.signature", null, RequestContextUtils.getLocale(request)), FontContext.SMALL_BOLD_TIMES_NEW_ROMAN))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); document.add(mainTable); document.close(); } String filename = "Employee_Payslip.pdf"; if (!StringUtil.isNullOrEmpty(request.getParameter("reportname"))) { String temp = request.getParameter("reportname"); filename = temp.lastIndexOf(".pdf") >= 0 ? temp : temp + ".pdf"; } response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setContentType("application/octet-stream"); response.setContentLength(baos.size()); response.getOutputStream().write(baos.toByteArray()); jsonResp.put("valid", true); jsonResp.put("data", ""); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (response.getOutputStream() != null) { response.getOutputStream().flush(); response.getOutputStream().close(); } } catch (IOException e) { e.printStackTrace(); } writer.close(); } return new ModelAndView("jsonView", "model", jsonResp.toString()); }
From source file:com.krawler.spring.hrms.payroll.salaryslip.ExportSalarySlipService.java
License:Open Source License
public PdfPCell getSalaryDetails(User user, Empprofile empprofile, Useraccount useraccount, Company company, PayrollHistory payrollHistory, DateFormat sdf, int border, HttpServletRequest request) { PdfPTable mainTable = new PdfPTable(1); PdfPCell mainCell = null;/*from w w w. ja v a2s . c om*/ try { String currencySymbol = getCurrencySymbol(request, false); int paddingTop = 2; int paddingBottom = 2; double net = 0; double earningAmount = 0; double deductionAmount = 0; String val = null; String accno = useraccount != null ? useraccount.getAccno() : " "; accno = StringUtil.isNullOrEmpty(accno) ? " " : accno; mainTable.setWidths(new float[] { 100 }); PdfPTable mainTable1 = new PdfPTable(3); PdfPCell mainCell1 = null; mainTable1.setWidths(new float[] { 45, 10, 45 }); PdfPTable mainTable2 = new PdfPTable(3); PdfPCell mainCell2 = null; mainTable2.setWidths(new float[] { 45, 10, 45 }); //####################Earnings########################## PdfPTable leftTable1 = new PdfPTable(2); leftTable1.setWidths(new float[] { 60, 40 }); PdfPCell leftCell1 = null; leftTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.payments", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, 7, 7, border)); leftTable1.addCell( getPdfPCellInstance("( " + currencySymbol + " )", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, 7, 7, border)); List<ComponentResourceMappingHistory> list = hrmsPayrollDAOObj.getSalaryDetails(user.getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_EARNING, HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_OTHER_REMUNERATION); for (ComponentResourceMappingHistory crm : list) { val = currencyFormat.format(crm.getAmount()); earningAmount += currencyFormat.parse(val).doubleValue(); leftTable1.addCell(getPdfPCellInstance(crm.getComponent().getDescription(), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } leftCell1 = new PdfPCell(leftTable1); leftCell1.setBorder(border); mainTable1.addCell(leftCell1); PdfPTable leftTable2 = new PdfPTable(2); leftTable2.setWidths(new float[] { 60, 40 }); PdfPCell leftCell2 = null; leftTable2.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable2.addCell(getPdfPCellInstance("------------", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.subtotal", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable2.addCell(getPdfPCellInstance(currencyFormat.format(earningAmount), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftCell2 = new PdfPCell(leftTable2); leftCell2.setBorder(border); mainTable2.addCell(leftCell2); //####################Earnings########################## PdfPCell centerCell1 = new PdfPCell(); centerCell1.setBorder(border); mainTable1.addCell(centerCell1); PdfPCell centerCell2 = new PdfPCell(); centerCell2.setBorder(border); mainTable2.addCell(centerCell2); //####################Deductions And Tax########################## PdfPTable rigthTable1 = new PdfPTable(2); rigthTable1.setWidths(new float[] { 60, 40 }); PdfPCell rigthCell1 = null; rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Deduction", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, 7, 7, border)); rigthTable1.addCell( getPdfPCellInstance("( " + currencySymbol + " )", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, 7, 7, border)); list = hrmsPayrollDAOObj.getSalaryDetails(user.getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_DEDUCTION, null); for (ComponentResourceMappingHistory crm : list) { val = currencyFormat.format(crm.getAmount()); deductionAmount += currencyFormat.parse(val).doubleValue(); rigthTable1.addCell(getPdfPCellInstance(crm.getComponent().getDescription(), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } list = hrmsPayrollDAOObj.getSalaryDetails(user.getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_TAX, null); for (ComponentResourceMappingHistory crm : list) { val = currencyFormat.format(crm.getAmount()); deductionAmount += currencyFormat.parse(val).doubleValue(); rigthTable1.addCell(getPdfPCellInstance(crm.getComponent().getDescription(), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } //###############Unpaid Leaves START########## if (payrollHistory.getUnpaidleavesAmount() > 0) { val = currencyFormat.format(payrollHistory.getUnpaidleavesAmount()); deductionAmount += currencyFormat.parse(val).doubleValue(); rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Unpaidleaves", null, RequestContextUtils.getLocale(request)) + " (" + payrollHistory.getUnpaidleaves() + ")", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } //###############Unpaid Leaves START########## //###############Income Tax START########## if (payrollHistory.getIncometaxAmount() > 0) { val = currencyFormat.format(payrollHistory.getIncometaxAmount()); rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.income.tax", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); deductionAmount += currencyFormat.parse(val).doubleValue(); } //###############Income Tax END########## //###############EPF START################ Map<String, Double> map = getIncomTaxBenefits(request, payrollHistory.getUser().getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), payrollHistory); if (map != null && map.get("epf") != null && map.get("epf") > 0) { val = currencyFormat.format(map.get("epf")); rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.epf", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); deductionAmount += currencyFormat.parse(val).doubleValue(); } //###############EPF END################ rigthCell1 = new PdfPCell(rigthTable1); rigthCell1.setBorder(border); mainTable1.addCell(rigthCell1); PdfPTable rigthTable2 = new PdfPTable(2); rigthTable2.setWidths(new float[] { 60, 40 }); PdfPCell rigthCell2 = null; rigthTable2.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell(getPdfPCellInstance("------------", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.subtotal", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell(getPdfPCellInstance(currencyFormat.format(deductionAmount), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); net = earningAmount - deductionAmount; rigthTable2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.net", null, RequestContextUtils.getLocale(request)) + "(a/c:" + accno + ")", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell( getPdfPCellInstance(currencyFormat.format(net), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthCell2 = new PdfPCell(rigthTable2); rigthCell2.setBorder(border); mainTable2.addCell(rigthCell2); //####################Deductions And Tax########################## mainCell1 = new PdfPCell(mainTable1); mainCell1.setBorder(border); mainCell2 = new PdfPCell(mainTable2); mainCell2.setBorder(border); mainTable.addCell(mainCell1); mainTable.addCell(mainCell2); mainCell = new PdfPCell(mainTable); mainCell.setBorder(border); mainCell.setPaddingBottom(20); } catch (Exception e) { e.printStackTrace(); } return mainCell; }
From source file:com.prime.location.billing.InvoicedBillingManager.java
/** * Print invoice/*from w w w .j a v a2 s . co m*/ */ public void printInvoice() { try { //catch better your exceptions, this is just an example FacesContext context = FacesContext.getCurrentInstance(); Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f); String fileName = "PDFFile"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(pdf, baos); TableHeader event = new TableHeader(); event.setHeader("Header Here"); writer.setPageEvent(event); if (!pdf.isOpen()) { pdf.open(); } PdfPCell cell; PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 }); cell = new PdfPCell(new Paragraph("INVOICE", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); header.setTotalWidth(527); header.setLockedWidth(true); cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription())); cell.setColspan(2); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId())); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); cell = new PdfPCell( new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate()))); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); pdf.add(header); PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 }); table.setSpacingBefore(15f); table.setTotalWidth(527); table.setLockedWidth(true); //table.setWidths(new int[]{3, 1, 1}); table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY); table.addCell("Date"); table.addCell("Name"); table.addCell("Service"); table.addCell("Rate"); table.getDefaultCell().setBackgroundColor(null); cell = new PdfPCell(new Phrase("Total(US$): ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(3); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); // There are three special rows table.setHeaderRows(2); // One of them is a footer table.setFooterRows(1); Font f = FontFactory.getFont(FontFactory.HELVETICA, 10); //add remaining for (AgencyBilling billing : selectedInvoice.getBillings()) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setIndent(2); table.getDefaultCell().setFixedHeight(20); table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f)); table.addCell(new Phrase(billing.getPerson().getName(), f)); table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f)); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } pdf.add(table); writer.getAcroForm().setNeedAppearances(true); //document.add(new Phrase(TEXT)); //Keep modifying your pdf file (add pages and more) pdf.close(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception e) { //e.printStackTrace(); } }
From source file:com.prime.report.template.TableHeader.java
/** * Adds a header to every page// w w w.j a va 2 s . co m * * @param writer * @param document * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(4); try { table.setWidths(new int[] { 10, 11, 9, 1 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); Image img = Image.getInstance(logo); table.addCell(Image.getInstance(img)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase("New South West Facility Center", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, Color.BLACK))); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Page %d of", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } catch (IOException ex) { Logger.getLogger(TableHeader.class.getName()).log(Level.SEVERE, null, ex); } }