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.gp.cong.logisoft.lcl.report.FreightInvoiceLclPdfCreator.java
public void createImportFreightPdf(String realPath, String unitSsId, String fileId, String fileNumber, String outputFileName, String documentName, String voyNotiemailId, User loginUser) throws Exception { ImportPortConfigurationDAO importPortConfigurationDAO = new ImportPortConfigurationDAO(); LclUnitSsDispoDAO lclUnitSsDispoDAO = new LclUnitSsDispoDAO(); LclUnitSsDAO lclUnitSsDAO = new LclUnitSsDAO(); LclRemarksDAO lclRemarksDAO = new LclRemarksDAO(); LclBookingPieceDAO lclBookingPieceDAO = new LclBookingPieceDAO(); String trmname = ""; String trmAddress = ""; String trmZip = ""; String customerPo = ""; String unitNo = ""; String masterBl = ""; StringBuilder originValues = new StringBuilder(); StringBuilder destinationValues = new StringBuilder(); String subHouseBl = ""; String amsHouseBl = ""; String shipName = ""; String consName = ""; String notyName = ""; String forwName = ""; String billToParty = ""; String billToPartyAc = ""; Date pickUpDate = null;// w w w. j av a 2 s . com Date vesselEtd = null; String billToPartyAcctName = ""; StringBuilder consAddress = new StringBuilder(); LclBooking lclBooking = new LCLBookingDAO().findById(Long.valueOf(fileId)); shipName = null != lclBooking.getShipAcct() ? lclBooking.getShipContact().getCompanyName() : ""; consName = null != lclBooking.getConsAcct() ? lclBooking.getConsContact().getCompanyName() : ""; notyName = null != lclBooking.getNotyAcct() ? lclBooking.getNotyContact().getCompanyName() : ""; forwName = null != lclBooking.getFwdAcct() ? lclBooking.getFwdAcct().getAccountName() : ""; billToParty = null != lclBooking.getBillToParty() ? lclBooking.getBillToParty() : ""; if (billToParty.equalsIgnoreCase("C")) { billToPartyAc = null != lclBooking.getConsAcct() ? lclBooking.getConsAcct().getAccountno() : ""; billToPartyAcctName = null != lclBooking.getConsAcct() ? lclBooking.getConsContact().getCompanyName() : ""; } else if (billToParty.equalsIgnoreCase("A")) { billToPartyAc = null != lclBooking.getSupAcct() ? lclBooking.getSupAcct().getAccountno() : ""; billToPartyAcctName = null != lclBooking.getSupAcct() ? lclBooking.getSupAcct().getAccountName() : ""; } else if (billToParty.equalsIgnoreCase("N")) { billToPartyAc = null != lclBooking.getNotyAcct() ? lclBooking.getNotyAcct().getAccountno() : ""; billToPartyAcctName = null != lclBooking.getNotyAcct() ? lclBooking.getNotyContact().getCompanyName() : ""; } else if (billToParty.equalsIgnoreCase("T")) { billToPartyAc = null != lclBooking.getThirdPartyAcct() ? lclBooking.getThirdPartyAcct().getAccountno() : ""; billToPartyAcctName = null != lclBooking.getThirdPartyAcct() ? lclBooking.getThirdPartyAcct().getAccountName() : ""; } originValues.append(lclUtils.getConcatenatedOriginByUnlocation(lclBooking.getPortOfLoading())); destinationValues.append(lclUtils.getConcatenatedOriginByUnlocation(lclBooking.getPortOfDestination())); if (lclBooking.getTerminal() != null) { RefTerminal terminal = new TerminalDAO() .findByTerminalNo(String.valueOf(lclBooking.getTerminal().getTrmnum())); trmname = null != terminal ? terminal.getTerminalLocation() : ""; if (trmname.equalsIgnoreCase("IMPRTS LOS ANGELES")) { trmname = "Los Angeles"; } trmAddress = null != terminal ? terminal.getAddres1() : ""; trmZip = null != terminal ? terminal.getZipcde() : ""; } customerPo = new Lcl3pRefNoDAO().getCustomerPo(fileId); CustAddress custAddress = new CustAddressDAO().findByAccountNo(billToPartyAc); if (custAddress != null) { consAddress.append(billToPartyAcctName).append("\n"); consAddress.append(custAddress.getAddress1()).append("\n"); consAddress.append(custAddress.getCity1()).append(" ").append(custAddress.getState()).append(" ") .append(custAddress.getZip()); } List<LclBookingPiece> lclBookingPiece = lclBookingPieceDAO.findByProperty("lclFileNumber.id", Long.parseLong(fileId)); LclFileNumber lclFileNumber = new LclFileNumberDAO().getByProperty("id", Long.parseLong(fileId)); if (lclBookingPiece != null && !lclBookingPiece.isEmpty() && CommonUtils.isNotEmpty(lclBookingPiece.get(0).getLclBookingPieceUnitList())) { unitNo = lclBookingPiece.get(0).getLclBookingPieceUnitList().get(0).getLclUnitSs().getLclUnit() .getUnitNo(); masterBl = lclBookingPiece.get(0).getLclBookingPieceUnitList().get(0).getLclUnitSs().getLclUnit() .getLclUnitSsManifestList().get(0).getMasterbl(); vesselEtd = lclBookingPiece.get(0).getLclBookingPieceUnitList().get(0).getLclUnitSs().getLclSsHeader() .getLclSsDetailList().get(0).getSta(); } Boolean isSegregationFlag = new LclBookingSegregationDao().isCheckedSegregationDr(Long.parseLong(fileId)); if (isSegregationFlag) { amsHouseBl = new LclBookingImportAmsDAO().getAmsNo(fileId); } else { amsHouseBl = new LclBookingImportAmsDAO().getAmsNoGroup(fileId); } if (lclFileNumber.getLclBookingImport() != null) { subHouseBl = lclFileNumber.getLclBookingImport().getSubHouseBl(); pickUpDate = lclFileNumber.getLclBookingImport().getPickupDateTime(); } PdfPCell cell = new PdfPCell(); PdfPTable mainTable = makeTable(2); mainTable.setWidthPercentage(100f); PdfPTable clientPTable = new PdfPTable(5); clientPTable.setWidthPercentage(100f); clientPTable.setWidths(new float[] { 25, 25, 17, 11, 22 }); clientPTable.setKeepTogether(true); cell = makeCell("BILL TO ACCOUNT NO.", Element.ALIGN_LEFT, headingFontSize8, 0, Color.decode("#c5d9f1")); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); clientPTable.addCell(cell); cell = makeCell("" + billToPartyAc, Element.ALIGN_LEFT, blackFontForFclAr, 0); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); clientPTable.addCell(cell); cell = makeCell("INVOICE NO.", Element.ALIGN_CENTER, headingFontSize8, 0, Color.decode("#c5d9f1")); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); clientPTable.addCell(cell); cell = makeCell("DATE", Element.ALIGN_CENTER, headingFontSize8, 0, Color.decode("#c5d9f1")); cell.setBorderWidthTop(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthBottom(0.06f); clientPTable.addCell(cell); cell = makeCell("BILLING TM", Element.ALIGN_CENTER, headingFontSize8, 0, Color.decode("#c5d9f1")); cell.setBorderWidthTop(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthRight(0.06f); cell.setBorderWidthBottom(0.06f); clientPTable.addCell(cell); cell = makeCell("" + consAddress.toString(), Element.ALIGN_LEFT, blackFontForFclAr, 0); cell.setColspan(2); cell.setMinimumHeight(20f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); clientPTable.addCell(cell); //INVOICE NO cell = makeCell(fileNumber, Element.ALIGN_CENTER, blackFontForFclBl, 0); clientPTable.addCell(cell); //DATE String acctNumber = checkPayment(billToPartyAc); if (!acctNumber.equals("noCredit")) { if (CommonFunctions.isNotNull(acctNumber) && !acctNumber.equals("") && pickUpDate != null) { cell = makeCell(DateUtils.formatStringDateToAppFormatMMM(pickUpDate), Element.ALIGN_CENTER, blackFontForFclBl, 0); } else if (pickUpDate == null && vesselEtd != null) { cell = makeCell(DateUtils.formatStringDateToAppFormatMMM(vesselEtd), Element.ALIGN_CENTER, blackFontForFclBl, 0); } else { cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0); } } else if (acctNumber.equals("noCredit") && vesselEtd != null) { cell = makeCell(DateUtils.formatStringDateToAppFormatMMM(vesselEtd), Element.ALIGN_CENTER, blackFontForFclBl, 0); } else { cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0); } cell.setBorderWidthLeft(0.06f); clientPTable.addCell(cell); //BILLING TM cell = makeCell(trmname, Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setBorderWidthLeft(0.06f); clientPTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(2); clientPTable.addCell(cell); cell = makeCell("CUSTOMER REF NO.", Element.ALIGN_CENTER, headingFontSize8, 0, Color.decode("#c5d9f1")); cell.setColspan(3); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); clientPTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(2); clientPTable.addCell(cell); //CUSTOMER REF NO. cell = makeCell(customerPo, Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setColspan(3); cell.setMinimumHeight(15f); cell.setBorderWidthLeft(0.06f); clientPTable.addCell(cell); cell = new PdfPCell(); cell.addElement(clientPTable); cell.setColspan(5); cell.setBorder(0); cell.setPadding(0f); cell.setBorderWidthRight(0.06f); cell.setBorderWidthLeft(0.06f); mainTable.addCell(cell); PdfPTable othersTable = makeTable(4); othersTable.setWidthPercentage(100f); othersTable.setWidths(new float[] { 25, 25, 25, 25 }); cell = makeCell("CONTAINER NO.", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); cell = makeCell("ECI SHIPMENT FILE NO.", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); cell = makeCell("ORIGIN", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); cell = makeCell("DESTINATION", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthTop(0.06f); othersTable.addCell(cell); //CONTAINER NO cell = makeCell("" + unitNo, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); //ECI SHIPMENT FILE NO cell = makeCell("IMP-" + fileNumber, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); //ORIGIN cell = makeCell("" + originValues, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); //DESTINATION cell = makeCell("" + destinationValues, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); cell = makeCell("MBL / AWB NUMBER", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setColspan(2); cell.setBorderWidthRight(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); othersTable.addCell(cell); cell = makeCell("AMS HOUSE BL", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setBorderWidthRight(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); othersTable.addCell(cell); cell = makeCell("SUB HOUSE BL", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); othersTable.addCell(cell); //MBL / AWB NUMBER cell = makeCell("" + masterBl, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(2); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); //amsHouseBl cell = makeCell(amsHouseBl, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); //subHouseBl cell = makeCell(subHouseBl, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); cell = makeCell("SHIPPER", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setColspan(2); cell.setBorderWidthRight(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); othersTable.addCell(cell); cell = makeCell("FORWARDER", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setColspan(2); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); othersTable.addCell(cell); //SHIPPER cell = makeCell(shipName, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(2); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); //FORWARDER cell = makeCell(forwName, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(2); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); cell = makeCell("CONSIGNEE", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setColspan(2); cell.setBorderWidthRight(0.06f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); othersTable.addCell(cell); cell = makeCell("NOTIFY PARTY", Element.ALIGN_CENTER, blackBoldFontSize6, 0, Color.decode("#c5d9f1")); cell.setColspan(2); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); othersTable.addCell(cell); //CONSIGNEE cell = makeCell(consName, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(2); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); //NOTIFY PARTY cell = makeCell(notyName, Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(2); cell.setMinimumHeight(20f); cell.setBorderWidthRight(0.06f); othersTable.addCell(cell); cell = new PdfPCell(); cell.setColspan(2); cell.addElement(othersTable); cell.setBorder(0); cell.setPadding(0f); cell.setBorderWidthRight(0.06f); cell.setBorderWidthLeft(0.06f); mainTable.addCell(cell); Font boldHeadingFon = FontFactory.getFont("Arial", 7f, Font.BOLD); Paragraph p = null; PdfPTable othersTable1 = makeTable(5); othersTable1.setWidthPercentage(100f); othersTable1.setWidths(new float[] { 2f, 1f, 4f, 1.3f, 1.3f }); //marks cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); p = new Paragraph(7f, "MARKS AND NUMBERS", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); othersTable1.addCell(cell); //no of pkgs cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "NO.OF.PKGS", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); othersTable1.addCell(cell); //desc cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "DESCRIPTION OF PACKAGES AND GOODS", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); othersTable1.addCell(cell); //grossweight cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "GROSS WEIGHT", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); othersTable1.addCell(cell); //measure cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "MEASURE", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); othersTable1.addCell(cell); // List<LclBookingPiece> lclBookingPiecesList = null; // lclBookingPiecesList = lclBookingPieceDAO.findByProperty("lclFileNumber.id", Long.parseLong(fileId)); if (lclBookingPiece != null && lclBookingPiece.size() > 0) { for (LclBookingPiece lclBookingPieces : lclBookingPiece) { //MARKS AND NUMBERS cell = new PdfPCell(); cell.setBorder(0); if (lclBookingPieces != null && lclBookingPieces.getMarkNoDesc() != null && !lclBookingPieces.getMarkNoDesc().equals("")) { p = new Paragraph(7f, "" + lclBookingPieces.getMarkNoDesc().toUpperCase(), blackNormalCourierFont8f); } else { p = new Paragraph(7f, "", blackNormalCourierFont8f); } p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); //NO.OF.PKGS cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); if (lclBookingPieces != null && lclBookingPieces.getBookedPieceCount() != null && lclBookingPieces.getPackageType().getAbbr01() != null) { p = new Paragraph(7f, "" + lclBookingPieces.getBookedPieceCount() + " " + lclBookingPieces.getPackageType().getAbbr01(), blackNormalCourierFont8f); } else { p = new Paragraph(7f, "", blackNormalCourierFont8f); } p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); //DESCRIPTION OF PACKAGES AND GOODS cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); if (lclBookingPieces != null && lclBookingPieces.getPieceDesc() != null && !lclBookingPieces.getPieceDesc().equals("")) { p = new Paragraph(7f, "" + lclBookingPieces.getPieceDesc().toUpperCase(), blackNormalCourierFont8f); } else { p = new Paragraph(7f, "", blackNormalCourierFont8f); } p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); //grossweight cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); if (lclBookingPieces != null && lclBookingPieces.getBookedWeightMetric() != null) { p = new Paragraph(7f, "" + lclBookingPieces.getBookedWeightMetric() + " KGS", blackNormalCourierFont8f); } else { p = new Paragraph(7f, "", blackNormalCourierFont8f); } p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); //measure cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); if (lclBookingPieces != null && lclBookingPieces.getBookedVolumeMetric() != null) { p = new Paragraph(7f, "" + lclBookingPieces.getBookedVolumeMetric() + " CBM", blackNormalCourierFont8f); } else { p = new Paragraph(7f, "", blackNormalCourierFont8f); } p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); //2nd cell cell = new PdfPCell(); cell.setBorder(0); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); //3rd cell cell = new PdfPCell(); cell.setBorder(0); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "", blackNormalCourierFont8f); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); if (lclBookingPieces != null && lclBookingPieces.getBookedWeightImperial() != null) { p = new Paragraph(7f, "" + lclBookingPieces.getBookedWeightImperial() + " LBS", blackNormalCourierFont8f); } else { p = new Paragraph(7f, "", blackNormalCourierFont8f); } p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthLeft(0.6f); if (lclBookingPieces != null && lclBookingPieces.getBookedVolumeImperial() != null) { p = new Paragraph(7f, "" + lclBookingPieces.getBookedVolumeImperial() + " CFT", blackNormalCourierFont8f); } else { p = new Paragraph(7f, "", blackNormalCourierFont8f); } p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); othersTable1.addCell(cell); } } cell = new PdfPCell(); cell.setColspan(5); cell.addElement(othersTable1); cell.setBorder(0); cell.setPadding(0f); cell.setBorderWidthRight(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthTop(0.06f); mainTable.addCell(cell); PdfPTable chargesTable = makeTable(4); chargesTable.setWidthPercentage(100.5f); chargesTable.setWidths(new float[] { 45, 35, 5, 15 }); cell = makeCell("DESCRIPTION", Element.ALIGN_CENTER, headingFont, 0, Color.decode("#c5d9f1")); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); cell.setBorderWidthBottom(0.06f); cell.setColspan(2); chargesTable.addCell(cell); cell = makeCell("CHARGES", Element.ALIGN_CENTER, headingFont, 0, Color.decode("#c5d9f1")); cell.setColspan(2); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); chargesTable.addCell(cell); NumberFormat number = new DecimalFormat("###,###,##0.00"); String code = ""; // double totalCharges = 0.00; double lateFee = 0.00; double payAmount = 0.00; int chargeCount = 0; double total = 0.00; String[] billToPartyA; billToPartyA = new String[] { "C", "N", "T" }; List<String> billtoPartyList = Arrays.asList(billToPartyA); List<BookingChargesBean> lclBookingAcList = null; lclBookingAcList = new LclCostChargeDAO().findBybookingAcId(fileId, billtoPartyList); for (int j = 0; j < lclBookingAcList.size(); j++) { chargeCount++; BookingChargesBean lclBookingAc = (BookingChargesBean) lclBookingAcList.get(j); String codeDesc = ""; code = CommonUtils.isNotEmpty(lclBookingAc.getChargeCode()) ? lclBookingAc.getChargeCode() : ""; codeDesc = new GenericCodeDAO().getGenericCodeDesc(code); if (CommonUtils.isNotEmpty(lclBookingAc.getChargeCode())) { // String desc = lclBookingAc.getChargeCode().toUpperCase(); cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl); cell.setBorderWidthRight(0.0f); } if (chargeCount == 1) { cell.setBorderWidthTop(0.0f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthLeft(0.0f); cell.setBorderWidthBottom(0.0f); } else { cell.setBorderWidthRight(0.0f); cell.setBorderWidthLeft(0.0f); cell.setBorderWidthBottom(0.0f); } chargesTable.addCell(cell); if (CommonUtils.isNotEmpty(codeDesc)) { cell = makeCell("" + codeDesc, Element.ALIGN_LEFT, blackFontForFclBl, 0.06f); cell.setBorderWidthLeft(0.0f); } else { cell = makeCell("" + code, Element.ALIGN_LEFT, blackFontForFclBl, 0.06f); cell.setBorderWidthLeft(0.0f); } if (chargeCount == 1) { cell.setBorderWidthTop(0.0f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); } else { cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); } chargesTable.addCell(cell); cell = makeCell("$", Element.ALIGN_CENTER, blackFontForFclBl, 0.06f);//3 if (chargeCount == 1) { cell.setBorderWidthTop(0.0f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); } else { cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); } chargesTable.addCell(cell); cell = makeCell(number.format(lclBookingAc.getTotalAmt().doubleValue()), Element.ALIGN_RIGHT, blackFontForFclBl, Rectangle.BOX);//4 if (chargeCount == 1) { cell.setBorderWidth(0.0f); } else { cell.setBorderWidthLeft(0.0f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); } chargesTable.addCell(cell); total = total + lclBookingAc.getTotalAmt().doubleValue(); } for (int i = 0; i < (14 - chargeCount); i++) { // chargesTable.addCell(makeCellLeftNoBorderFclBL("")); // chargesTable.addCell(makeCellRightNoBorderFclBL("")); cell = makeCell("", Element.ALIGN_LEFT, blackFontForFclBl, 0.06f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); cell.setBorderWidthLeft(0.0f); chargesTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0.06f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); cell.setBorderWidthLeft(0.0f); chargesTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0.06f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); chargesTable.addCell(cell); cell = makeCell("", Element.ALIGN_RIGHT, blackFontForFclBl, 0.06f); cell.setBorderWidthLeft(0.0f); cell.setBorderWidthRight(0.0f); cell.setBorderWidthBottom(0.0f); cell.setMinimumHeight(10f); chargesTable.addCell(cell); } cell = makeCell("", Element.ALIGN_LEFT, blackFontForFclBl, 0); cell.setBorderWidthTop(0.06f); chargesTable.addCell(cell); cell = makeCell("INVOICE TOTAL", Element.ALIGN_CENTER, blackFontForFclBl, 0); // cell.setPaddingLeft(-15f); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthRight(0.06f); chargesTable.addCell(cell); cell = makeCell("$", Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); chargesTable.addCell(cell); cell = makeCell(number.format(total), Element.ALIGN_RIGHT, blackFontForFclBl, 0);//4 cell.setBorderWidthTop(0.06f); cell.setBorderWidthBottom(0.06f); chargesTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setColspan(4); chargesTable.addCell(cell); chargesTable.setKeepTogether(true); cell = new PdfPCell(); cell.setColspan(2); cell.addElement(chargesTable); cell.setBorder(0); cell.setBorderWidthRight(0.06f); cell.setBorderWidthLeft(0.06f); mainTable.addCell(cell); // payAmount = total; // String acctNumber = checkPayment(billToPartyAc); boolean lateFeeFlag = false; TradingPartnerBC tradingPartnerBC = new TradingPartnerBC(); TradingPartner tradingPartner = null; // SimpleDateFormat simpDate = new SimpleDateFormat("dd-MMM-yyyy"); PdfPTable paidTable = makeTable(6); paidTable.setWidthPercentage(100.5f); paidTable.setWidths(new float[] { 30, 15, 25, 10, 5, 15 }); if (CommonFunctions.isNotNull(acctNumber) && !acctNumber.equals("") && !acctNumber.equals("noCredit")) { tradingPartner = tradingPartnerBC.findTradingPartnerById(acctNumber); if (CommonFunctions.isNotNullOrNotEmpty(tradingPartner.getAccounting())) { for (Iterator accountingList = tradingPartner.getAccounting().iterator(); accountingList .hasNext();) { CustomerAccounting customerAccounting = (CustomerAccounting) accountingList.next(); if (null != customerAccounting.getLclApplyLateFee() && customerAccounting.getLclApplyLateFee().equals("on")) { lateFeeFlag = true; } break; } } } cell = makeCell("ARRIVAL DATE", Element.ALIGN_CENTER, headingFontSize8, 0, Color.decode("#c5d9f1")); cell.setBorderWidthTop(0.06f); cell.setBorderWidthRight(0.06f); cell.setBorderWidthBottom(0.06f); paidTable.addCell(cell); SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy"); String outDate = ""; String crtDate = ""; if (vesselEtd != null) { //vessel arrivalDate outDate = sdf.format(vesselEtd); } cell = makeCell("", Element.ALIGN_LEFT, blackFontForFclBl, 0); paidTable.addCell(cell); CustomerAccounting customerAccounting = new CustomerAccountingDAO().findByProperty("accountNo", billToPartyAc); if (customerAccounting != null && (customerAccounting.getCreditRate() != null && (CommonUtils.isNotEmpty(outDate)) && !acctNumber.equals("noCredit"))) { Calendar c = Calendar.getInstance(); // c.setTime(new Date(outDate)); // Removed Deprecated Warning c.setTime(sdf.parse(outDate)); // Now use previous date. if ((customerAccounting.getCreditRate().getCodedesc()).equalsIgnoreCase("Net 7 Days")) { c.add(Calendar.DATE, 7); crtDate = sdf.format(c.getTime());// Adding 7 days } else if ((customerAccounting.getCreditRate().getCodedesc()).equalsIgnoreCase("Net 15 Days")) { c.add(Calendar.DATE, 15); crtDate = sdf.format(c.getTime());// Adding 15 days } else if ((customerAccounting.getCreditRate().getCodedesc()).equalsIgnoreCase("NET 21 DAYS")) { c.add(Calendar.DATE, 21); crtDate = sdf.format(c.getTime());// Adding 21 days } else if ((customerAccounting.getCreditRate().getCodedesc()).equalsIgnoreCase("Net 30 Days")) { c.add(Calendar.DATE, 30); crtDate = sdf.format(c.getTime());// Adding 30 days } else if ((customerAccounting.getCreditRate().getCodedesc()).equalsIgnoreCase("Net 45 Days")) { c.add(Calendar.DATE, 45); crtDate = sdf.format(c.getTime());// Adding 45 days } else if ((customerAccounting.getCreditRate().getCodedesc()).equalsIgnoreCase("Net 60 Days")) { c.add(Calendar.DATE, 60); crtDate = sdf.format(c.getTime());// Adding 60 days } } if (lateFeeFlag) { lateFee = total * 0.015; // 1.5percent calculate payAmount = total + lateFee; cell = makeCell("LATE FEE IF NOT PAID BY - " + crtDate, Element.ALIGN_LEFT, blackFontForFclBl, 0); cell.setColspan(2); cell.setBorderWidthTop(0.06f); cell.setBorderWidthLeft(0.06f); paidTable.addCell(cell); cell = makeCell("$", Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setBorderWidthTop(0.06f); cell.setBorderWidthLeft(0.06f); paidTable.addCell(cell); cell = makeCell(number.format(lateFee), Element.ALIGN_RIGHT, blackFontForFclBl, 0); cell.setBorderWidthTop(0.06f); paidTable.addCell(cell); cell = makeCell(outDate, Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setMinimumHeight(10f); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthRight(0.06f); paidTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0); paidTable.addCell(cell); cell = makeCell("PAY THIS AMOUNT IF NOT PAID BY DUE DATE", Element.ALIGN_LEFT, blackFontForFclBl, 0); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthTop(0.06f); cell.setColspan(2); paidTable.addCell(cell); cell = makeCell("$", Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthTop(0.06f); paidTable.addCell(cell); cell = makeCell(number.format(payAmount), Element.ALIGN_RIGHT, blackFontForFclBl, 0); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthTop(0.06f); paidTable.addCell(cell); } else { // String dueDate = ""; // if(arRedInvoice.getDueDate() != null){ // SimpleDateFormat sdfa = new SimpleDateFormat("dd-MMM-yyyy"); // dueDate = sdfa.format(arRedInvoice.getDueDate()); // } // cell = makeCell(!"".equals(dueDate) ? "PAY THIS AMOUNT IF NOT PAID BY - " + dueDate : "PLEASE PAY THIS AMOUNT",Element.ALIGN_LEFT, blackFontForFclBl, 0); cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setColspan(4); paidTable.addCell(cell); cell = makeCell(outDate, Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setMinimumHeight(10f); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthRight(0.06f); paidTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0); paidTable.addCell(cell); cell = makeCell("PLEASE PAY THIS AMOUNT - " + crtDate, Element.ALIGN_LEFT, blackFontForFclBl, 0); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthTop(0.06f); cell.setColspan(2); paidTable.addCell(cell); cell = makeCell("$", Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthTop(0.06f); paidTable.addCell(cell); cell = makeCell(number.format(total), Element.ALIGN_RIGHT, blackFontForFclBl, 0); cell.setBorderWidthBottom(0.06f); cell.setBorderWidthTop(0.06f); paidTable.addCell(cell); } cell = makeCell("", Element.ALIGN_CENTER, blackFontForFclBl, 0); cell.setColspan(5); paidTable.addCell(cell); //paidTable.setKeepTogether(true); cell = new PdfPCell(); cell.setColspan(2); cell.addElement(paidTable); cell.setBorder(0); cell.setBorderWidthRight(0.06f); cell.setBorderWidthLeft(0.06f); mainTable.addCell(cell); ///end of description & charges // String paymentStatment = ""; // paymentStatment = checkPayment(arRedInvoice); PdfPTable commandTable = new PdfPTable(1); commandTable.setWidthPercentage(100); cell = makeCell("", Element.ALIGN_CENTER, headingFont, Rectangle.NO_BORDER); commandTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, headingFont, Rectangle.NO_BORDER); commandTable.addCell(cell); if (customerAccounting != null && (customerAccounting.getCreditRate() != null && (CommonUtils.isNotEmpty(outDate)))) { if ((customerAccounting.getCreditRate().getCodedesc()).equalsIgnoreCase("Due Upon Receipt")) { cell = makeCell("INVOICE IS PAYABLE UPON RECEIPT", Element.ALIGN_CENTER, blackFontForFclBl, 0, Color.decode("#FFFF00")); commandTable.addCell(cell); } else { cell = makeCell("INVOICE PAYABLE ON OR BEFORE " + (crtDate), Element.ALIGN_CENTER, new Font(Font.HELVETICA, 10, Font.BOLDITALIC, Color.BLACK), Rectangle.NO_BORDER); commandTable.addCell(cell); } } else { cell = makeCell("INVOICE IS PAYABLE UPON RECEIPT", Element.ALIGN_CENTER, blackFontForFclBl, 0, Color.decode("#FFFF00")); commandTable.addCell(cell); } // if (lateFeeFlag == false) {//if(paymentStatment.equals("noCredit") || lateFeeFlag == false){ // cell = makeCell("INVOICE IS PAYABLE UPON RECEIPT OR INVOICE PAYABLE WITHIN 30 DAYS FROM DEPARTURE/ARRIVAL DATE", Element.ALIGN_LEFT, blackFontForFclBl, 0, Color.decode("#FFFF00")); // commandTable.addCell(cell); // } else { // cell = makeCell("", Element.ALIGN_CENTER, headingFont, Rectangle.NO_BORDER); // commandTable.addCell(cell); // } cell = makeCell("", Element.ALIGN_CENTER, headingFont, Rectangle.NO_BORDER); commandTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, headingFont, Rectangle.NO_BORDER); commandTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, headingFont, Rectangle.NO_BORDER); commandTable.addCell(cell); cell = makeCell("", Element.ALIGN_CENTER, headingFont, Rectangle.NO_BORDER); commandTable.addCell(cell); cell = new PdfPCell(); cell.setColspan(2); cell.addElement(commandTable); cell.setBorder(0); cell.setBorderWidthRight(0.06f); cell.setBorderWidthLeft(0.06f); cell.setExtraParagraphSpace(10f); mainTable.addCell(cell); PdfPTable bankDetailsTable = makeTable(4); bankDetailsTable.setWidthPercentage(100f); bankDetailsTable.setWidths(new float[] { 3f, 1f, 4f, 2.6f }); // // SystemRulesDAO systemRulesDAO = new SystemRulesDAO(); // String eftBank = systemRulesDAO.getSystemRulesByCode("EFTBank"); // String eftBankAddress = systemRulesDAO.getSystemRulesByCode("EFTBankAddress"); // String eftABANo = systemRulesDAO.getSystemRulesByCode("EFTABANo"); // String eftAcctName = systemRulesDAO.getSystemRulesByCode("EFTAcctName"); // String eftAccountNo = systemRulesDAO.getSystemRulesByCode("EFTAccountNo"); // CompanyModel company = systemRulesDAO.getCompanyDetails(); //PAYMENT METHODS cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthRight(0.6f); cell.setBorderWidthTop(0.6f); p = new Paragraph(7f, "PAYMENT METHODS", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); bankDetailsTable.addCell(cell); // Empty cell = makeCell("", Element.ALIGN_CENTER, blackBoldFontSize6, 0); cell.setColspan(3); cell.setBorderWidthBottom(0.06f); bankDetailsTable.addCell(cell); //Via Check cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "Via Check", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); bankDetailsTable.addCell(cell); //Via ACH or Wire Transfer cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "Via ACH or Wire Transfer", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); bankDetailsTable.addCell(cell); //Credit Card Payments cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.6F); cell.setBorderWidthLeft(0.6f); p = new Paragraph(7f, "Credit Card Payments", boldHeadingFon); p.setAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(Color.decode("#c5d9f1")); cell.addElement(p); bankDetailsTable.addCell(cell); // Via Check Details cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthRight(0.06f); cell.setBorderWidthBottom(0.06f); cell.setColspan(2); p = new Paragraph(10f, "PLEASE REMIT PAYMENT TO", boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, companyName, boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); String creditStatusDomain = ""; if (null != customerAccounting && null != customerAccounting.getCreditStatus()) {//no credit creditStatusDomain = customerAccounting.getCreditStatus().getCodedesc(); if (!("No Credit").equalsIgnoreCase(creditStatusDomain)) { p = new Paragraph(10f, "2401 N.W. 69TH STREET", boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, "Miami, FL 33147", boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); bankDetailsTable.addCell(cell); } else { p = new Paragraph(10f, "" + trmAddress, boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, "" + trmname + " " + trmZip, boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); bankDetailsTable.addCell(cell); } } //Via ACH or Wire Transfer Details cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthRight(0.06f); p = new Paragraph(10f, "Bank: " + company.getBankName(), boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, company.getBankAddress(), boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, "ABA: " + company.getBankAbaNumber(), boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, "ACCT: " + companyName, boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, "ACCOUNT NO: " + company.getBankAccountNumber(), boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); bankDetailsTable.addCell(cell); //Credit Card Payments Details cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthRight(0.06f); p = new Paragraph(10f, "If paying via Credit card", boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, " Please go to:", boldHeadingFon); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); p = new Paragraph(10f, webSite, fileNoFont); p.setAlignment(Element.ALIGN_LEFT); cell.addElement(p); bankDetailsTable.addCell(cell); cell = new PdfPCell(); cell.setColspan(4); cell.addElement(bankDetailsTable); cell.setBorder(0); cell.setPadding(0f); cell.setBorderWidthRight(0.06f); cell.setBorderWidthLeft(0.06f); cell.setBorderWidthBottom(0.06f); mainTable.addCell(cell); document.add(mainTable); }
From source file:com.kahlon.guard.controller.DocumentManager.java
/** * * @param document/*from www . j ava 2 s . c om*/ */ public void preProcessPDF(Object document) { try { BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false); Document pdf = (Document) document; pdf.setPageSize(PageSize.A4); pdf.setMargins(5f, 5f, 10f, 5f); // headers and footers must be added before the document is opened HeaderFooter footer = new HeaderFooter(new Phrase("page: ", new Font(bf_courier)), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); pdf.setFooter(footer); // HeaderFooter header = new HeaderFooter( // new Phrase("This is a header without a page number", new Font(bf_courier)), false); // header.setAlignment(Element.ALIGN_CENTER); // pdf.setHeader(header); pdf.open(); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); pdf.add(Image.getInstance(logo)); Person person = context.getSelectedPerson().getDisplayPerson(); String name = FacesMessageUtil.getMessage("person.name") + " : " + person.getName(); String age = FacesMessageUtil.getMessage("person.age") + " : " + Integer.toString(person.getAge()); String gender = FacesMessageUtil.getMessage("person.gender") + " : " + person.getGender().getDescription(); String race = FacesMessageUtil.getMessage("person.ethnicity") + " : " + person.getEthnicity().getDescription(); Person rootPerson = person.getRootPerson(); PersonImage imgp = imageService.getLastestPersonImage(rootPerson.getId()); Image imgb = Image.getInstance(imgp.getContent()); imgb.scaleToFit(100, 120); PdfPTable headerTable = new PdfPTable(2); PdfPTable personTable = new PdfPTable(1); personTable.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase(name)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(age)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(gender)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(race)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); BarcodePDF417 pdf417 = new BarcodePDF417(); pdf417.setText(Integer.toString(person.getId())); Image img = pdf417.getImage(); img.scalePercent(150, 60 * pdf417.getYHeight()); cell = new PdfPCell(img); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(15); personTable.addCell(cell); cell.addElement(personTable); headerTable.addCell(cell); cell = new PdfPCell(imgb); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(cell); headerTable.setSpacingAfter(15); pdf.add(headerTable); LineSeparator lineSeparator = new LineSeparator(); lineSeparator.setPercentage(82); pdf.add(lineSeparator); Paragraph space = new Paragraph(); space.add(""); space.setSpacingAfter(15); pdf.add(space); } catch (IOException e) { logger.log(Level.INFO, e.getMessage()); } catch (BadElementException e) { logger.log(Level.INFO, e.getMessage()); } catch (DocumentException e) { logger.log(Level.INFO, e.getMessage()); } catch (Exception e) { logger.log(Level.INFO, e.getMessage()); } }
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private int alignment(String value) { String[] e = parse(value);/*w w w.j a v a2 s .c om*/ if (e[0] != null) { if (e[0].equals(LEFT)) { return Element.ALIGN_LEFT; } if (e[0].equals(RIGHT)) { return Element.ALIGN_RIGHT; } } return Element.ALIGN_CENTER; }
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private void createFootings(String footing) throws DocumentException { String[] cols = footing.split(ReportProcessor.ALIGN_DELIMITER, 3); float[] colSizes = new float[] { 25, 50, 25 }; footerTable = new PdfPTable(colSizes); footerTable.setWidthPercentage(getHeadingWidth()); int count = 0; for (String c : cols) { PdfPCell c1 = new PdfPCell(new Phrase(value(c), font)); c1.setBorder(Rectangle.NO_BORDER); int alignment = Element.ALIGN_CENTER; if (count == 0) { alignment = Element.ALIGN_LEFT; } else if (count == 2) { alignment = Element.ALIGN_RIGHT; }//from ww w . ja v a 2 s.c om c1.setHorizontalAlignment(alignment); setCellPadding(c1); footerTable.addCell(c1); count++; } }
From source file:com.khs.report.writer.ReportPDFWriter.java
License:Apache License
private void createHeading(String heading) throws DocumentException { String[] cols = heading.split(ReportProcessor.ALIGN_DELIMITER, 3); PdfPTable table = new PdfPTable(cols.length); table.setWidthPercentage(getHeadingWidth()); int count = 0; for (String c : cols) { PdfPCell c1 = new PdfPCell(new Phrase(value(c), font)); c1.setBorder(Rectangle.NO_BORDER); int alignment = Element.ALIGN_CENTER; if (count == 0) { alignment = Element.ALIGN_LEFT; } else if (count == 2) { alignment = Element.ALIGN_RIGHT; }//www . ja v a 2s . c o m c1.setHorizontalAlignment(alignment); setCellPadding(c1); table.addCell(c1); count++; } document.add(table); }
From source file:com.krawler.esp.handlers.PdfGenHandler.java
License:Open Source License
public static ByteArrayOutputStream getInvoiceForm1(String invoice) { ByteArrayOutputStream os = null; try {/* w ww.jav a2s . c o m*/ os = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4, 15, 15, 15, 15); PdfWriter writer = PdfWriter.getInstance(document, os); Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font10 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK); HeaderFooter temp = new HeaderFooter(new Phrase( String.format("Note: This is a computer generated document and does not require signature"), font7), false); temp.setAlignment(Element.ALIGN_CENTER); document.setFooter(temp); document.open(); JSONObject jbj = new JSONObject(invoice); String currency = ""; com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items"); String ids[] = { "name", "address", "invoiceno", "paymentdate" }; String uinfo[] = new String[ids.length]; for (int i = 0; i < uinfo.length; i++) { uinfo[i] = jbj.getString(ids[i]); } PdfPTable tableinfo = new PdfPTable(1); PdfPTable table = new PdfPTable(2); Font font1 = FontFactory.getFont("Helvetica", 24, Font.BOLD, Color.BLACK); String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png"; PdfPCell cell1 = null; try { Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } catch (Exception e) { cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png"; Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableinfo.addCell(cell1); tableinfo = addspace(1, tableinfo); tableinfo = addspace(4, tableinfo); cell1 = new PdfPCell(new Paragraph("INVOICE", font10)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableinfo.addCell(cell1); tableinfo = addspace(2, tableinfo); table = addspace(1, table); // cell1 = new PdfPCell(new Paragraph(uinfo[uinfo.length - 1],font9)); // cell1.setBorder(0); // cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // tableinfo.addCell(cell1); // tableinfo = addspace(1, tableinfo); // tableinfo = addspace(2, tableinfo); cell1 = new PdfPCell(tableinfo); cell1.setBorder(0); table.addCell(cell1); PdfPTable tb = new PdfPTable(1); document.add(new Paragraph("\u00a0")); tableinfo = addspace(1, tableinfo); Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK); Font font2 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK); //Font font3 = FontFactory.getFont("Helvetica", 8, Font.ITALIC, Color.BLACK); Font font11 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); PdfPCell c1 = null; c1 = new PdfPCell(new Paragraph("Bill To :", font2)); c1.setBorder(0); tb.addCell(c1); for (int i = 0; i < 2; i++) { PdfPCell c = null; if (i == 0) c = new PdfPCell(new Paragraph(uinfo[i], font11)); else c = new PdfPCell(new Paragraph(uinfo[i])); //c.(20); c.setBorder(0); tb.addCell(c); } PdfPCell c = new PdfPCell(tb); c.setBorder(0); table.addCell(c); PdfPTable tb1 = new PdfPTable(1); for (int i = 2; i < 4; i++) { PdfPTable nested1 = new PdfPTable(3); c = new PdfPCell(); c.setBorder(0); c.setPaddingRight(5); nested1.addCell(c); c = new PdfPCell(new Paragraph(invoiceheadings[i], font)); c.setBorder(0); nested1.addCell(c); c = new PdfPCell(new Paragraph(uinfo[i], font2)); c.setBorder(0); c.setHorizontalAlignment(Element.ALIGN_RIGHT); //c.setPaddingLeft(5); nested1.addCell(c); c = new PdfPCell(nested1); c.setBorder(0); tb1.addCell(c); } PdfPCell c2 = new PdfPCell(tb1); c2.setBorder(0); table.addCell(c2); PdfPTable tb2 = new PdfPTable(new float[] { 60, 40 }); /* for (int i = 6; i < 7; i++) { PdfPTable tb3 = new PdfPTable(2);//new float[]{20, 40}); tb3.setWidths(new int[]{1, 3}); c2 = new PdfPCell(new Paragraph(invoiceheadings[i], font)); c2.setBorder(0); tb3.addCell(c2); c2 = new PdfPCell(new Paragraph(uinfo[i])); c2.setBorder(0); tb3.addCell(c2); c2 = new PdfPCell(tb3); c2.setBorder(0); c2.setHorizontalAlignment(Element.ALIGN_LEFT); tb2.addCell(c2); tb2 = addspace(1, tb2); } */ PdfPTable maintable = new PdfPTable(1); c2 = new PdfPCell(table); c2.setBorder(0); maintable.addCell(c2); maintable = addspace(0, maintable); c2 = new PdfPCell(tb2); c2.setBorder(0); maintable.addCell(c2); document.add(maintable); //for (int i = 0; i < 2; i++) { document.add(new Paragraph("\u00a0")); //} String[] colwidth2 = { "Subscription date", "Description", "Rate ($/Project)", "Amount ($)" }; PdfPTable table1 = new PdfPTable(4); table1.setWidths(new float[] { 2, 3, 1, 1 }); for (int i = 0; i < colwidth2.length; i++) { PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font)); cell.setBorder(0); if (i != 1) { cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); } if (i == 3) { cell.setBorderWidthLeft(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } cell.setBorderWidthTop(1); cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f)); cell.setBorderWidthBottom(1); cell.setPaddingBottom(5); cell.setPaddingTop(5); table1.addCell(cell); } //table1.setHeaderRows(1); double d = 0; String[] di = { "billdate", "description", "rate", "amount" }; java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); for (int i = 0; i < gridinfo.length(); i++) { currency = "USD";//gridinfo.getJSONObject(i).getString("currency"); PdfPCell cell = null; for (int j = 0; j < di.length; j++) { if (j == 3) { cell = new PdfPCell(new Paragraph( df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(di[j]))), font2)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell = new PdfPCell(new Paragraph(gridinfo.getJSONObject(i).getString(di[j]), font2)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } cell.setBorder(0); if (j != 1) { cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); } if (j == 3) { cell.setBorder(0); cell.setBorderWidthRight(1); } cell.setPaddingTop(10); cell.setFixedHeight(100); table1.addCell(cell); } d += Double.parseDouble(gridinfo.getJSONObject(i).getString(di[3])); } PdfPCell cell = null; cell = new PdfPCell(new Paragraph(" ", font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(0); table1.addCell(cell); cell = new PdfPCell(new Paragraph(" ", font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(0); table1.addCell(cell); cell = new PdfPCell(new Paragraph(" Total", font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(0); cell.setPaddingBottom(5); table1.addCell(cell); cell = new PdfPCell(new Paragraph(" " + df.format(d), font)); cell.setBorder(0); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table1.addCell(cell); EnglishDecimalFormat f1 = new EnglishDecimalFormat(); if (currency.equals("USD")) { cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font)); } else { cell = new PdfPCell(new Paragraph(CurrencyConvert(currency, d), font)); } cell.setColspan(4); cell.setBorder(0); //cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table1.addCell(cell); document.add(table1); document.add(new Paragraph("\u00a0")); PdfPTable inst = new PdfPTable(1); // for (int i = 0; i < Inst1.length; i++) { // c2 = new PdfPCell(new Paragraph(Inst1[i])); // c2.setBorder(0); // inst.addCell(c2); // } document.add(inst); document.close(); writer.close(); os.close(); } // catch (ConfigurationException ex) { // Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); // } catch (JSONException ex) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception exp) { Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, exp); } return os; }
From source file:com.krawler.esp.handlers.PdfGenHandler.java
License:Open Source License
public static ByteArrayOutputStream getReceiptAcc1(String ackrecp) { ByteArrayOutputStream os = null; try {// w w w. j av a2 s. c o m os = new ByteArrayOutputStream(); JSONObject jbj = new JSONObject(ackrecp); com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items"); String ginfo[] = new String[gridinfo.length() * 2]; String ids[] = { "name", "receiptno", "paymentdate", "address" }; String currency = "USD"; // String address = jbj.getString("address"); String uinfo[] = new String[ids.length]; for (int i = 0; i < uinfo.length; i++) { uinfo[i] = jbj.getString(ids[i]); } Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK); Font font1 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK); Font font3 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); //Font font4 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK); Font font10 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK); Font font11 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK); Font font12 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK); Document document1 = new Document(PageSize.A4, 15, 15, 15, 15); PdfWriter writer = PdfWriter.getInstance(document1, os); HeaderFooter temp = new HeaderFooter(new Phrase( String.format("Note: This is a computer generated document and does not require signature"), font7), false); temp.setAlignment(Element.ALIGN_CENTER); document1.setFooter(temp); document1.open(); PdfPTable tableHinfo = new PdfPTable(1); PdfPTable table = new PdfPTable(1); font3.setStyle(Font.UNDERLINE); String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png"; PdfPCell cell1 = null; try { Image img = Image.getInstance(cnxt); // img.scalePercent(90); cell1 = new PdfPCell(img); } catch (Exception e) { cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png"; Image img = Image.getInstance(cnxt); cell1 = new PdfPCell(img); } cell1.setBorder(0); cell1.setPaddingTop(18); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(1, tableHinfo); tableHinfo = addspace(4, tableHinfo); cell1 = new PdfPCell(new Paragraph("RECEIPT", font1)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); tableHinfo.addCell(cell1); tableHinfo = addspace(0, tableHinfo); // cell1 = new PdfPCell(new Paragraph(uinfo[4], font11)); // cell1.setBorder(0); // cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); // tableHinfo.addCell(cell1); document1.add(tableHinfo); PdfPTable tableUinfo = new PdfPTable(1); cell1 = new PdfPCell(new Paragraph(receiptheading[0], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[0], font10)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[3], font11)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); tableUinfo.addCell(cell1); document1.add(new Paragraph("\u00a0")); tableUinfo = addspace(1, tableUinfo); String hed[] = { "", "Receipt No : ", "Date : ", "" }; PdfPTable tableDinfo = new PdfPTable(1); //tableDinfo.setTotalWidth(100); for (int j = 1; j < 3; j++) { PdfPTable nested1 = new PdfPTable(3); cell1 = new PdfPCell(); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(hed[j], font)); cell1.setBorder(0); nested1.addCell(cell1); cell1 = new PdfPCell(new Paragraph(uinfo[j], font12)); cell1.setBorder(0); cell1.setHorizontalAlignment(Element.ALIGN_RIGHT); nested1.addCell(cell1); cell1 = new PdfPCell(nested1); cell1.setBorder(0); tableDinfo.addCell(cell1); } PdfPTable container = new PdfPTable(2); cell1 = new PdfPCell(tableUinfo); cell1.setBorder(0); cell1.setPaddingBottom(15); container.addCell(cell1); cell1 = new PdfPCell(tableDinfo); cell1.setBorder(0); container.addCell(cell1); document1.add(container); PdfPTable table1 = new PdfPTable(2); String[] colwidth2 = { "Invoice No.", "Amount Paid($)" }; for (int i = 0; i < colwidth2.length; i++) { PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font)); if (i == 1) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f)); cell.setPaddingBottom(5); cell.setBorderWidthRight(1); cell.setBorderWidthTop(1); table1.addCell(cell); } table1.setHeaderRows(1); double d = 0; colwidth2 = new String[] { "invoicenum", "amount" }; java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); for (int i = 0; i < gridinfo.length(); i++) { for (int j = 0; j < colwidth2.length; j++) { PdfPCell cell = null; if (j == 1) { cell = new PdfPCell(new Paragraph( df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j]))), font12)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorderWidthLeft(0); } else { cell = new PdfPCell( new Paragraph(gridinfo.getJSONObject(i).getString(colwidth2[j]), font12)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthLeft(1); } //cell.setMinimumHeight(25); cell.setBorderWidthRight(1); cell.setPaddingTop(5); cell.setFixedHeight(100); table1.addCell(cell); if (j == colwidth2.length - 1) { d += Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j])); } } } // EnglishDecimalFormat f1 = new EnglishDecimalFormat(); PdfPCell cell = new PdfPCell(new Paragraph("", font)); cell.setBorderWidthBottom(1); cell.setBorderWidthRight(0); cell.setBorderWidthLeft(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table1.addCell(cell); cell = new PdfPCell(new Paragraph("Total " + df.format(d), font)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); //cell.setPaddingBottom(15); cell.setPaddingLeft(15); cell.setPaddingBottom(5); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(0); cell.setBorderWidthRight(1); table1.addCell(cell); PdfPTable table3 = new PdfPTable(1); cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font)); //cell.setPaddingBottom(15); cell.setBorder(0); cell.setColspan(4); cell.setBorderWidthBottom(1); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); cell.setPaddingBottom(5); table3.addCell(cell); document1.add(table1); document1.add(table3); document1.add(new Paragraph("\u00a0")); cell = new PdfPCell(new Paragraph(String.format( "All payments are non-refundable and non-transferable. \nThis Receipt is valid subject to clearance of the payments."), font11)); //cell.setPaddingLeft(5); cell.setBorder(0); table.addCell(cell); // String delFlag = jbj.getString("delflag"); // if(delFlag.compareTo("2")==0){ // BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); // PdfContentByte cb = writer.getDirectContentUnder(); // cb.saveState(); // cb.setColorFill(Color.BLACK); // cb.beginText(); // cb.setFontAndSize(bf, 48); // cb.showTextAligned(Element.ALIGN_CENTER, "Canceled Payment", document1.getPageSize().getWidth() / 2, document1.getPageSize().getHeight() / 2, 45); // cb.endText(); // cb.restoreState(); // } document1.add(table); document1.close(); writer.close(); os.close(); } catch (Exception e) { System.out.println(e); } return os; }
From source file:com.krawler.esp.servlets.ExportLeavePdfServlet.java
License:Open Source License
private ByteArrayOutputStream createLeaveForm(String cname, HttpServletRequest request, Session session, boolean isEmm) throws JSONException, SessionExpiredException, ParseException { String companyid = AuthHandler.getCompanyid(request); Company com = (Company) session.get(Company.class, companyid); String from = ""; String to = ""; String formTitle = "Absence Leave Form"; int i = 0;//from ww w.j a v a 2s . com SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); DecimalFormat decfm = new DecimalFormat("#,##0.00"); Date d2 = null; Date d3 = null; Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); String month = ""; 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, session, companyid); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = null; try { String empname = ""; String design = ""; String historyid = ""; String net = ""; String name = ""; String wtot = ""; String dtot = ""; String ttot = ""; Date generatedOn = null; DateFormat monthformat = new SimpleDateFormat("MMMM"); DateFormat monthformat2 = new SimpleDateFormat("MMMM dd yyyy"); Query query = null; // if (request.getParameter("flagpdf").equals("datewise")) { // query = session.createQuery("from masterDB.Payhistory t where t.userID.userID=:empid and t.paymonth=:month"); // query.setString("empid", request.getParameter("empid")); // query.setString("month", month); // } // if (request.getParameter("flagpdf").equals("monthwise")) { // month = request.getParameter("month"); // query = session.createQuery("from masterDB.Payhistory t where t.userID.userID=:empid and t.paymonth=:month"); // query.setString("empid", request.getParameter("empid")); // query.setString("month", request.getParameter("month")); // } query = session.createQuery( "from masterDB.Payhistory t where t.userID.userID=:empid and t.paycyclestart=:paycyclestart and t.paycycleend=:paycycleend"); query.setString("empid", request.getParameter("empid")); query.setDate("paycyclestart", d2); query.setDate("paycycleend", d3); String currSymbol = ""; String curid = AuthHandler.getCurrencyID(request); Query queryx = session.createQuery("from KWLCurrency where currencyID=:curid"); queryx.setString("curid", curid); KWLCurrency curncy = (KWLCurrency) queryx.uniqueResult(); String currsym = curncy.getHtmlcode(); String currname = curncy.getName(); try { char a1 = (char) Integer.parseInt(currsym, 16); currSymbol = Character.toString(a1); } catch (Exception e) { currSymbol = currsym; } List lst = (List) query.list(); if (lst.size() == 0) { throw new Exception("Exception occured"); } if (lst.size() > 0) { masterDB.Payhistory wage = (masterDB.Payhistory) lst.get(0); empname = wage.getName(); design = wage.getDesign(); historyid = wage.getHistoryid(); net = String.format("%.2f", Float.valueOf(wage.getNet().trim()).floatValue()); name = wage.getName(); wtot = wage.getWagetot(); ttot = wage.getTaxtot(); dtot = wage.getDeductot(); double unpaidleaves = wage.getUnpaidleaves(); generatedOn = wage.getGeneratedon(); String gen = monthformat2.format(generatedOn); String startdate = monthformat2.format(wage.getCreatedon()); String enddate = monthformat2.format(wage.getCreatedfor()); 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"); query = session.createQuery("from com.krawler.common.admin.User as t where t.userID=:empid "); query.setString("empid", userid); lst = (List) query.list(); com.krawler.common.admin.User userinfo = (com.krawler.common.admin.User) lst.get(0); Useraccount ua = (Useraccount) session.get(Useraccount.class, userinfo.getUserID()); String uname = userinfo.getLastName() != null ? userinfo.getLastName() : ""; String empid = ""; if (ua.getEmployeeIdFormat() == null) { empid = ua.getEmployeeid() == null ? "" : hrmsManager.getEmpidFormatEdit(session, request, ua.getEmployeeid()); } else { HashMap<String, Object> requestParams = new HashMap<String, Object>(); requestParams.put("standardEmpId", hrmsManager.getEmpidFormatEdit(session, request, ua.getEmployeeid())); requestParams.put("employeeIdFormat", ua.getEmployeeIdFormat()); empid = hrmsManager.getNewEmployeeIdFormat(requestParams); } String department = wage.getDepartment(); String designation = getUserDesignation(ua); String bankacc = ua.getAccno() != null ? ua.getAccno() : ""; Empprofile empprof = null; String epf = ""; String dateofjoin = ""; try { empprof = (Empprofile) session.get(Empprofile.class, 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); imgPath = "images/logo1.gif"; String cmpid = AuthHandler.getCompanyid(request); ServletContext sc = getServletContext(); userTable1.setHorizontalAlignment(Element.ALIGN_MIDDLE); userTable1.setWidthPercentage(10); PdfPCell cell11 = null; PdfPCell cell1x = new PdfPCell(new Paragraph(" ", fontMediumBold)); cell1x.setBorder(0); userTable1.addCell(cell1x); try { Image img = Image.getInstance(StorageHandler.GetProfileImgStorePath() + cmpid + ".png"); cell11 = new PdfPCell(img); cell11.setPaddingLeft(5); } catch (Exception e) { cell11 = new PdfPCell(new Paragraph(AuthHandler.getCompanyName(request), fontTblLargeBold)); cell11.setHorizontalAlignment(Element.ALIGN_CENTER); } if (cell11 != null) { cell11.setBorder(0); userTable1.addCell(cell11); } PdfPCell cell1 = new PdfPCell(new Paragraph("", fontMediumBold)); 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(com.getCompanyName(), fontMediumBold)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); cell.setPaddingTop(15); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(com.getCity(), fontSmallRegular)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(com.getAddress(), fontSmallRegular)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(com.getState(), fontSmallRegular)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(com.getZipCode(), fontSmallRegular)); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(0); userTable2.addCell(cell); cell = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.payslip.period.params", new Object[] { request.getParameter("stdate"), request.getParameter("enddate") }, RequestContextUtils.getLocale(request)), fontSmallBold)); 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("", fontSmallBold)); 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(messageSource.getMessage("hrms.common.employee.code", null, RequestContextUtils.getLocale(request)), fontSmallBold)); h11.setHorizontalAlignment(Element.ALIGN_LEFT); h11.setPadding(5); if (!showborder) { h11.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h11); PdfPCell h12 = new PdfPCell(new Paragraph("" + empid, fontSmallRegular)); h12.setHorizontalAlignment(Element.ALIGN_LEFT); h12.setPadding(5); if (!showborder) { h12.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h12); PdfPCell h13 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)), fontSmallBold)); h13.setHorizontalAlignment(Element.ALIGN_LEFT); h13.setPadding(5); if (!showborder) { h13.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h13); PdfPCell h14 = new PdfPCell(new Paragraph(userinfo.getFirstName() + " " + uname, fontSmallRegular)); h14.setHorizontalAlignment(Element.ALIGN_LEFT); h14.setPadding(5); if (!showborder) { h14.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h14); PdfPCell h21 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.department", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); h21.setHorizontalAlignment(Element.ALIGN_LEFT); h21.setPadding(5); if (!showborder) { h21.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h21); PdfPCell h22 = new PdfPCell(new Paragraph(department, fontSmallRegular)); h22.setHorizontalAlignment(Element.ALIGN_LEFT); h22.setPadding(5); if (!showborder) { h22.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h22); PdfPCell h33 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.designation", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); h33.setHorizontalAlignment(Element.ALIGN_LEFT); h33.setPadding(5); if (!showborder) { h33.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h33); PdfPCell h34 = new PdfPCell(new Paragraph(designation, fontSmallRegular)); h34.setHorizontalAlignment(Element.ALIGN_LEFT); h34.setPadding(5); if (!showborder) { h34.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h34); PdfPCell h43 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.bank.ac.no", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); h43.setHorizontalAlignment(Element.ALIGN_LEFT); h43.setPadding(5); if (!showborder) { h43.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h43); PdfPCell h44 = new PdfPCell(new Paragraph(bankacc, fontSmallRegular)); h44.setHorizontalAlignment(Element.ALIGN_LEFT); h44.setPadding(5); if (!showborder) { h44.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h44); PdfPCell h61 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.working.days", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); h61.setHorizontalAlignment(Element.ALIGN_LEFT); h61.setPadding(5); if (!showborder) { h61.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h61); PdfPCell h62 = new PdfPCell(new Paragraph(String.valueOf(days), fontSmallRegular)); h62.setHorizontalAlignment(Element.ALIGN_LEFT); h62.setPadding(5); if (!showborder) { h62.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h62); PdfPCell h63 = new PdfPCell(new Paragraph( messageSource.getMessage("hrms.common.e.p.f", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); h63.setHorizontalAlignment(Element.ALIGN_LEFT); h63.setPadding(5); if (!showborder) { h63.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h63); PdfPCell h64 = new PdfPCell(new Paragraph(epf, fontSmallRegular)); h64.setHorizontalAlignment(Element.ALIGN_LEFT); h64.setPadding(5); if (!showborder) { h64.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h64); PdfPCell h65 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.DateofJoining", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); h65.setHorizontalAlignment(Element.ALIGN_LEFT); h65.setPadding(5); if (!showborder) { h65.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h65); PdfPCell h66 = new PdfPCell(new Paragraph(dateofjoin, fontSmallRegular)); h66.setHorizontalAlignment(Element.ALIGN_LEFT); h66.setPadding(5); if (!showborder) { h66.setBorder(0); } // else{ // mainCell1.setBorder(1); // } table2.addCell(h66); for (int y = 0; y < 2; y++) { PdfPCell h71 = new PdfPCell(new Paragraph(" ", fontTblMediumBold)); 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(" ", fontTblMediumBold)); h71.setHorizontalAlignment(Element.ALIGN_LEFT); h71.setBorder(0); table2.addCell(h71); } h71 = new PdfPCell(new Paragraph(" ", fontTblMediumBold)); 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[]{20,15,15,20,15,15}); table31.setWidths(new float[] { 30, 20, 30, 20 }); PdfPTable table41 = new PdfPTable(2); table41.setWidthPercentage(100); //table31.setWidths(new float[]{20,15,15,20,15,15}); table41.setWidths(new float[] { 50, 50 }); //*************************************************************************************************************** PdfPCell s11 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.Earnings", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), fontTblMediumBold)); s12.setHorizontalAlignment(Element.ALIGN_RIGHT); s12.setPadding(5); if (!showborder) { s12.setBorder(0); } else { s12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); } table31.addCell(s12); // PdfPCell s13 = new PdfPCell(new Paragraph("Year to Date", fontTblMediumBold)); // s13.setHorizontalAlignment(Element.ALIGN_RIGHT); // s13.setBorder(Rectangle.LEFT + Rectangle.BOTTOM); // s13.setPadding(5); // table31.addCell(s13); PdfPCell s14 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.Deduction", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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); // PdfPCell s16 = new PdfPCell(new Paragraph("Year to Date", fontTblMediumBold)); // s16.setHorizontalAlignment(Element.ALIGN_RIGHT); // s16.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.BOTTOM); // s16.setPadding(5); // table31.addCell(s16); int Wcount = 0; float taxtotal = 0; Query queryw = session.createQuery( "from masterDB.Historydetail t where t.payhistory.userID=:userid and createdfor >=:stdate and createdfor <=:enddate and t.type =:type"); Query basicquery1 = session.createQuery( "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name and t.type=:type "); basicquery1.setString("historyid", historyid); basicquery1.setString("name", "Wages"); basicquery1.setString("type", "Basic"); List lst1 = (List) basicquery1.list(); Query query1 = session.createQuery( "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name and t.type<>:type order by t.amount"); query1.setString("historyid", historyid); query1.setString("name", "Wages"); query1.setString("type", "Basic"); lst1.addAll((List) query1.list()); Query query2 = session.createQuery( "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name order by t.amount"); query2.setString("historyid", historyid); query2.setString("name", "Taxes"); List lst2 = (List) query2.list(); CompanyPreferences comp = (CompanyPreferences) session.get(CompanyPreferences.class, cmpid); int financialMonth = comp.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(); } Query query3 = session.createQuery( "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name order by t.amount"); query3.setString("historyid", historyid); query3.setString("name", "Deduction"); List lst3 = (List) query3.list(); 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(hd.getType(), fontSmallRegular)); 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(String.valueOf(decfm.format(newamount)), fontSmallRegular)); s22.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s22.setBorder(0); } else { s22.setBorder(Rectangle.LEFT); } s22.setPadding(5); table31.addCell(s22); queryw.setString("userid", request.getParameter("empid")); queryw.setTimestamp("stdate", d); queryw.setTimestamp("enddate", d3); queryw.setString("type", hd.getType()); List lstw = (List) queryw.list(); 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()); } // PdfPCell s23 = new PdfPCell(new Paragraph(String.valueOf(decfm.format(wageAmt)), fontSmallRegular)); // s23.setHorizontalAlignment(Element.ALIGN_RIGHT); // s23.setBorder(Rectangle.LEFT); // s23.setPadding(5); // table31.addCell(s23); wagetotal = wagetotal + Float.parseFloat(hd.getAmount()); totalYTDEarning = totalYTDEarning + wageAmt; Wcount++; } else { for (int j = 0; j < 2; j++) { PdfPCell s21 = new PdfPCell(new Paragraph("", fontSmallRegular)); 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(hd.getType(), fontSmallRegular)); 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(decfm.format(newamount), fontSmallRegular)); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); } s25.setPadding(5); table31.addCell(s25); queryw.setString("userid", request.getParameter("empid")); queryw.setTimestamp("stdate", d); queryw.setTimestamp("enddate", d3); queryw.setString("type", hd.getType()); List lstw1 = (List) queryw.list(); 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()); } // PdfPCell s26 = new PdfPCell(new Paragraph(decfm.format(taxAmt), fontSmallRegular)); // s26.setHorizontalAlignment(Element.ALIGN_RIGHT); // s26.setBorder(Rectangle.RIGHT + Rectangle.LEFT); // s26.setPadding(5); // table31.addCell(s26); 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(hd.getType(), fontSmallRegular)); if (hd.getType().equals("Unpaid_leaves")) { s24 = new PdfPCell( new Paragraph(hd.getType() + "(" + unpaidleaves + ")", fontSmallRegular)); } 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(decfm.format(newamount), fontSmallRegular)); s25.setHorizontalAlignment(Element.ALIGN_RIGHT); if (!showborder) { s25.setBorder(0); } else { s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT); ; } s25.setPadding(5); table31.addCell(s25); queryw.setString("userid", request.getParameter("empid")); queryw.setTimestamp("stdate", d); queryw.setTimestamp("enddate", d3); queryw.setString("type", hd.getType()); List lstw2 = (List) queryw.list(); 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()); } // PdfPCell s26 = new PdfPCell(new Paragraph(decfm.format(deductAmt), fontSmallRegular)); // s26.setHorizontalAlignment(Element.ALIGN_RIGHT); // s26.setBorder(Rectangle.RIGHT + Rectangle.LEFT); // s26.setPadding(5); // table31.addCell(s26); taxtotal = taxtotal + Float.parseFloat(hd.getAmount()); totalYTDDeduction = totalYTDDeduction + deductAmt; } else { // if(i-lst2.size()-lst3.size() < lst4.size()){ // hd = (masterDB.Historydetail) lst4.get(i-lst2.size()-lst3.size()); // PdfPCell v24 = new PdfPCell(new Paragraph(hd.getType(), fontSmallRegular)); // v24.setHorizontalAlignment(Element.ALIGN_LEFT); // v24.setBorder(Rectangle.LEFT); // v24.setPadding(5); // table31.addCell(v24); // // BigDecimal bd = new BigDecimal(hd.getAmount()); // bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); // double newamount = bd.doubleValue(); // // PdfPCell s25 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular)); // s25.setHorizontalAlignment(Element.ALIGN_RIGHT); // s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);; // s25.setPadding(5); // table31.addCell(s25); // }else{ for (int j = 0; j < 2; j++) { PdfPCell s21 = new PdfPCell(new Paragraph("", fontSmallRegular)); 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(messageSource.getMessage("hrms.payroll.total.earnings", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(decfm.format(newamount), fontSmallRegular)); 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 s93 = new PdfPCell(new Paragraph(decfm.format(totalYTDEarning), fontSmallRegular)); // s93.setHorizontalAlignment(Element.ALIGN_BASELINE); // s93.setHorizontalAlignment(Element.ALIGN_RIGHT); // s93.setBorder(Rectangle.LEFT + Rectangle.TOP); // s93.setPadding(5); // table31.addCell(s93); PdfPCell s94 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.total.deductions", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(decfm.format(newamount), fontSmallRegular)); 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); // PdfPCell s96 = new PdfPCell(new Paragraph(decfm.format(totalYTDDeduction), fontSmallRegular)); // s96.setHorizontalAlignment(Element.ALIGN_BASELINE); // s96.setHorizontalAlignment(Element.ALIGN_RIGHT); // s96.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.TOP); // s96.setPadding(5); // table31.addCell(s96); for (int y = 0; y < 2; y++) { PdfPCell he71 = new PdfPCell(new Paragraph(" ", fontTblMediumBold)); 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(" ", fontTblMediumBold)); he71.setHorizontalAlignment(Element.ALIGN_LEFT); he71.setBorder(0); table31.addCell(he71); } he71 = new PdfPCell(new Paragraph(" ", fontTblMediumBold)); he71.setHorizontalAlignment(Element.ALIGN_LEFT); // he71.setBorder(Rectangle.RIGHT); if (!showborder) { he71.setBorder(0); } else { he71.setBorder(Rectangle.RIGHT); } table31.addCell(he71); } Query query4 = session.createQuery( "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name order by t.amount"); query4.setString("historyid", historyid); query4.setString("name", "Employer Contribution"); List lst4 = (List) query4.list(); double ectotal = 0; PdfPCell ec11 = new PdfPCell( new Paragraph(messageSource.getMessage("hrms.payroll.EmployerContribution", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(hd1.getType(), fontSmallRegular)); 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(decfm.format(newamount), fontSmallRegular)); 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(messageSource.getMessage("hrms.payroll.total.contribution", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(decfm.format(newamount), fontSmallRegular)); 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(" ", fontTblMediumBold)); 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(messageSource.getMessage("hrms.payroll.netpay", null, RequestContextUtils.getLocale(request)) + " ", fontTblMediumBold)); 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(currSymbol+String.valueOf((int)netpay+".00"), fontSmallRegular)); PdfPCell i33 = new PdfPCell(new Paragraph(amount, fontTblMediumBold)); // PdfPCell i33 = new PdfPCell(new Paragraph("Rs 13,350.00", fontTblMediumBold)); 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(messageSource.getMessage("hrms.payroll.in.words", null, RequestContextUtils.getLocale(request)), fontTblMediumBold)); i32.setHorizontalAlignment(Element.ALIGN_LEFT); if (!showborder) { i32.setBorder(0); } else { i31.setBorder(Rectangle.LEFT); } i32.setPadding(5); table4.addCell(i32); int netpayi = (int) netpay; // String netinword = EnglishNumberToWords.convert(Long.parseLong(String.valueOf(netpayi))); String netinword = "";//new EnglishNumberToWords(request).convert(netpay); PdfPCell i34 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.only", new Object[] { currname, netinword }, RequestContextUtils.getLocale(request)), fontTblMediumBold)); 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(messageSource.getMessage("hrms.payroll.employee.signature", null, RequestContextUtils.getLocale(request)), fontSmallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); cell = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.manager.signature", null, RequestContextUtils.getLocale(request)), fontSmallBold)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table5.addCell(cell); document.add(mainTable); // document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n")); // document.add(table5); document.close(); } return baos; } catch (Exception ex) { ex.printStackTrace(); return null; } finally { writer.close(); } }
From source file:com.krawler.esp.servlets.ExportMPXServlet.java
License:Open Source License
private static void addComponyLogo(Document d) throws ConfigurationException, DocumentException { PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_RIGHT); table.setWidthPercentage(50);// ww w . j a va 2 s . co m PdfPCell cell = null; try { imgPath = com.krawler.esp.utils.ConfigReader.getinstance().get("platformURL") + "b/" + companySubDomain + "/images/store/?company=true"; // imgPath="http://192.168.0.141:8080/dp_dev/b/Demo/images/store/?company=true"; Image img = Image.getInstance(imgPath); cell = new PdfPCell(img); } catch (Exception e) { cell = new PdfPCell(new Paragraph(companyName, fontBig)); } cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); table.setSpacingAfter(10); d.add(table); }
From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java
License:Open Source License
private static void addComponyLogo(Document d, HttpServletRequest request) throws ConfigurationException, DocumentException { PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100);/*from w w w . java2s. c o m*/ PdfPCell cell = null; try { imgPath = com.krawler.esp.utils.ConfigReader.getinstance().get("platformURL") + "b/" + companySubDomain + "/images/store/?company=true"; // imgPath="http://192.168.0.141:8080/dp_dev/b/Demo/images/store/?company=true"; Image img = Image.getInstance(imgPath); cell = new PdfPCell(img); } catch (Exception e) { cell = new PdfPCell(new Paragraph(companyName, fontBig)); } cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); PdfPCell cell2 = new PdfPCell(new Paragraph(ProjectName.toUpperCase(), FontFactory.getFont("Helvetica", 15, Font.BOLD, Color.BLACK))); cell2.setBorderWidth(0); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell2); d.add(table); }