Example usage for com.itextpdf.text.pdf PdfPTable PdfPTable

List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable PdfPTable.

Prototype

public PdfPTable(final PdfPTable table) 

Source Link

Document

Constructs a copy of a PdfPTable.

Usage

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public PdfPTable informationBlock(String companyName, String portofDischarge, String finalDestination)
        throws IOException, BadElementException, DocumentException {
    table = new PdfPTable(1);
    table.setWidthPercentage(100f);//from w  ww .j ava 2 s  .  c  o m
    Font fontArialNormal = FontFactory.getFont("Courier", 12f, Font.NORMAL);
    Font fontArialBold = FontFactory.getFont("Courier", 12f, Font.BOLD);
    cell = new PdfPCell();
    cell.setBorder(0);
    p = new Paragraph(5f, "To Name : " + companyName + "- Voyage Notice", fontArialNormal);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    p = new Paragraph(25f, "Company : " + companyName + ", INC", fontArialNormal);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    p = new Paragraph(25f, "Voyage Port of Discharge (POD) : " + portofDischarge, fontArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    p = new Paragraph(9f, "Shipment Final Destination (FD) : " + finalDestination, fontArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);
    return table;
}

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public PdfPTable changesBlock(LclSsDetail lclSsDetail, LclExportNotiFicationForm lclExportNotiFicationForm)
        throws IOException, BadElementException, DocumentException, Exception {
    table = new PdfPTable(2);
    table.setWidthPercentage(100f);//from   w ww.  j a  va 2 s .  c  om
    Font fontArialNormal = FontFactory.getFont("Courier", 12f, Font.NORMAL);
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    p = new Paragraph(9f, "Voyage Information Was : ", fontArialNormal);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    Date changedDatetime = lclExportNotiFicationForm.getEnterDateTime() != null
            ? lclExportNotiFicationForm.getEnterDateTime()
            : new Date();
    p = new Paragraph(9f, "Changes As Of:  " + DateUtils.formatDate(changedDatetime, "MM/dd/yyyy"),
            fontArialNormal);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    cell.setBorderWidthBottom(0.6f);
    table.addCell(cell);
    if (lclSsDetail != null) {
        String stateValue = lclSsDetail.getDeparture().getStateId() != null
                ? lclSsDetail.getDeparture().getStateId().getCode()
                : "";
        String vessel = "", pier = "", portLrd = "", sail_date = "", eta_date = "", ss_line = "",
                ss_voyage = "";
        if (!"preview".equalsIgnoreCase(lclExportNotiFicationForm.getNoticeStatus())) {
            vessel = lclExportNotiFicationForm.getVessel() != null ? lclExportNotiFicationForm.getVessel() : "";
            portLrd = lclExportNotiFicationForm.getPortLrd() != null
                    && !"0".equalsIgnoreCase(lclExportNotiFicationForm.getPortLrd())
                            ? lclExportNotiFicationForm.getPortLrd()
                            : "";
            sail_date = lclExportNotiFicationForm.getSailDate() != null
                    ? DateUtils.formatDate(lclExportNotiFicationForm.getSailDate(), "MM/dd/yyyy")
                    : "";
            eta_date = lclExportNotiFicationForm.getEtaDate() != null
                    ? DateUtils.formatDate(lclExportNotiFicationForm.getEtaDate(), "MM/dd/yyyy")
                    : "";
            ss_line = lclExportNotiFicationForm.getSsLine() != null ? lclExportNotiFicationForm.getSsLine()
                    : "";
            ss_voyage = lclExportNotiFicationForm.getSsVoyage() != null
                    ? lclExportNotiFicationForm.getSsVoyage()
                    : "";
            pier = lclExportNotiFicationForm.getPier() != null ? lclExportNotiFicationForm.getPier()
                    .substring(0, lclExportNotiFicationForm.getPier().indexOf("(")) : "";
            pier = pier.replace("/", ", ");
        } else {
            vessel = CommonUtils.isNotEmpty(lclSsDetail.getSpReferenceName()) ? lclSsDetail.getSpReferenceName()
                    : "";
            portLrd = CommonUtils.isNotEmpty(lclSsDetail.getRelayLrdOverride())
                    ? lclSsDetail.getRelayLrdOverride().toString()
                    : "";
            sail_date = lclSsDetail.getStd() != null ? DateUtils.formatDate(lclSsDetail.getStd(), "MM/dd/yyyy")
                    : "";
            eta_date = lclSsDetail.getSta() != null ? DateUtils.formatDate(lclSsDetail.getSta(), "MM/dd/yyyy")
                    : "";
            ss_line = lclSsDetail.getSpAcctNo() != null ? lclSsDetail.getSpAcctNo().getAccountName() : "";
            ss_voyage = lclSsDetail.getSpReferenceNo() != null ? lclSsDetail.getSpReferenceNo() : "";
            pier = CommonUtils.isNotEmpty(lclExportNotiFicationForm.getPier()) ? lclExportNotiFicationForm
                    .getPier().substring(0, lclExportNotiFicationForm.getPier().indexOf("(")) : "";
            pier = lclSsDetail.getDeparture().getUnLocationName() + "," + stateValue;
        }

        table.addCell(allocateCell("Voy#...:" + lclSsDetail.getLclSsHeader().getScheduleNo(), true));
        table.addCell(allocateCell("Voy#...:" + lclSsDetail.getLclSsHeader().getScheduleNo(), false));

        table.addCell(allocateCell("Vessel Name..:" + vessel, true));
        table.addCell(allocateCell("Vessel Name..:" + lclSsDetail.getSpReferenceName(), false));

        table.addCell(allocateCell("Pier.........:" + pier, true));
        String changedCity = lclSsDetail.getDeparture().getUnLocationName() + ", " + stateValue;
        table.addCell(allocateCell("Pier.........:" + changedCity, false));
        String lrdOverride = null != lclSsDetail.getRelayLrdOverride()
                ? lclSsDetail.getRelayLrdOverride().toString()
                : "";
        table.addCell(allocateCell("Port LRD ....:" + portLrd, true));
        table.addCell(allocateCell("Port LRD ....:" + lrdOverride, false));

        table.addCell(allocateCell("Sail Date....:" + sail_date, true));
        table.addCell(allocateCell("Sail Date....:" + DateUtils.formatDate(lclSsDetail.getStd(), "MM/dd/yyyy"),
                false));

        table.addCell(allocateCell("ETA POD Date :" + eta_date, true));
        table.addCell(allocateCell("ETA POD Date :" + DateUtils.formatDate(lclSsDetail.getSta(), "MM/dd/yyyy"),
                false));
        ETA_FD = lclSsDetail.getSta();
        table.addCell(allocateCell("Line Name....:" + ss_line, true));
        table.addCell(allocateCell("Line Name....:" + lclSsDetail.getSpAcctNo().getAccountName(), false));

        table.addCell(allocateCell("SS Voyage#...:" + ss_voyage, true));
        table.addCell(allocateCell("SS Voyage#...:" + lclSsDetail.getSpReferenceNo(), false));

        table.addCell(allocateCell(" ", true));
        table.addCell(allocateCell(" ", false));
    }
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    cell.setBorderWidthTop(0.6f);
    table.addCell(cell);

    return table;
}

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public PdfPTable containerBlock(String companyName, String portofDischarge, LclFileNumber fileNumber,
        LclExportNotiFicationForm lclExportNotiFicationForm)
        throws IOException, BadElementException, DocumentException, Exception {
    table = new PdfPTable(2);
    table.setWidths(new float[] { 5f, 5f });
    table.setWidthPercentage(100f);//from  www . ja va 2s .  com
    Font fontArialBold = FontFactory.getFont("Courier", 10f, Font.BOLD);
    Font bigArialBold = FontFactory.getFont("Courier", 15f, Font.BOLD);
    cell = new PdfPCell();
    cell.setBorder(0);
    p = new Paragraph(9f, "Container# ", fontArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    p = new Paragraph(9f, "ETA-FINAL DESTINATION", bigArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    String containerNo = new LclExportsVoyageNotificationDAO()
            .getAllContainerNoFormVoyage(lclExportNotiFicationForm.getHeaderId().toString());
    p = new Paragraph(9f, "" + containerNo.replace(",", "\n"), fontArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    boolean isDrPicked = new ExportUnitQueryUtils().isPickedFile(fileNumber.getId());
    if (isDrPicked) {
        p = new Paragraph(9f, DateUtils.formatDate(ETA_FD, "MM/dd/yyyy") + " " + portofDischarge,
                fontArialBold);
    } else {
        String eta_date = DateUtils.formatDate(fileNumber.getLclBooking().getFdEta(), "MM/dd/yyyy");
        eta_date = eta_date != null ? eta_date : "";
        p = new Paragraph(9f, eta_date + " " + portofDischarge, fontArialBold);
    }
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(4);
    p = new Paragraph(90f, " ", fontArialBold);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(2);
    cell.setColspan(4);
    table.addCell(cell);

    return table;
}

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public PdfPTable reasonBlock(LclExportNotiFicationForm lclExportNotiFicationForm)
        throws IOException, BadElementException, DocumentException, Exception {
    User user = new UserDAO().findById(
            lclExportNotiFicationForm.getUserId() != null ? lclExportNotiFicationForm.getUserId().intValue()
                    : 0);//w w  w  . j av  a2s.c  om
    String userName = user != null ? user.getFirstName() : "";
    table = new PdfPTable(2);
    table.setWidthPercentage(100f);
    Font fontArialBold = FontFactory.getFont("Courier", 10f, Font.BOLD);
    Font fontArialNormal = FontFactory.getFont("Courier", 10f, Font.NORMAL);
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    p = new Paragraph(9f, "Reason:", fontArialBold);
    cell.addElement(p);
    table.addCell(cell);
    String voyageChangeReason = CommonUtils.isNotEmpty(lclExportNotiFicationForm.getVoyageReason())
            ? lclExportNotiFicationForm.getVoyageReason().toUpperCase()
            : "";
    String voyageComment = CommonUtils.isNotEmpty(lclExportNotiFicationForm.getVoyageComment())
            ? lclExportNotiFicationForm.getVoyageComment().toUpperCase()
            : "";
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    p = new Paragraph(9f, "" + voyageChangeReason + "\n" + voyageComment, fontArialNormal);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    p = new Paragraph(20f, "Changes Made By:" + userName, fontArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    p = new Paragraph(20f, "Contact#", fontArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    p = new Paragraph(7f, null != user ? user.getTelephone() : "", fontArialNormal);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    String notes = "";
    if ("preview".equalsIgnoreCase(lclExportNotiFicationForm.getNoticeStatus())) {
        notes = lclExportNotiFicationForm.getRemarks() != null
                ? lclExportNotiFicationForm.getRemarks().toUpperCase()
                : "";
    }
    p = new Paragraph(7f, "Notes:", fontArialBold);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    p = new Paragraph(7f, " " + notes, fontArialNormal);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    p = new Paragraph(10f, " ", fontArialNormal);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(1);
    cell.setColspan(2);
    table.addCell(cell);
    return table;
}

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public PdfPTable footerBlock() throws IOException, BadElementException, DocumentException, Exception {
    table = new PdfPTable(3);
    table.setWidthPercentage(100f);/*from w  ww.j  a v  a2s . com*/
    Font fontArialNormal = FontFactory.getFont("Courier", 10f, Font.NORMAL);
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    p = new Paragraph(9f, "Date:" + DateUtils.formatDate(new Date(), "MM/dd/yyyy"), fontArialNormal);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);

    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    p = new Paragraph(9f, "End Of Report", fontArialNormal);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(0);
    p = new Paragraph(9f, "Time :" + new Date().getHours() + ":" + new Date().getMinutes(), fontArialNormal);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    table.addCell(cell);
    return table;
}

From source file:com.grant.report.BillPdf.java

private void createTable(Paragraph preface) throws BadElementException, DocumentException {
    addEmptyLine(preface, 1);/* w  w w  .  ja v  a2 s .c o m*/
    PdfPTable table = new PdfPTable(6);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    PdfPCell c1 = new PdfPCell(new Phrase("Item Code"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Description"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Qty"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Unit"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Rate"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Amount"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    table.setHeaderRows(1);
    float[] columnWidths = new float[] { 15f, 30f, 10f, 10f, 10f, 15f };
    table.setWidths(columnWidths);

    ItemDAO dao = new ItemDAO();

    String itemName;
    String itemNo;
    String description;
    String outwards;
    String unitPrice;
    String amount;
    String unit;

    Vector<Vector<String>> data;
    data = dao.getStockOutTbl(invoNo);
    String s = data.get(0).get(1);
    for (int i = 0; i < data.size(); i++) {
        Vector<String> data2 = data.get(i);

        itemName = data.get(i).get(0);
        description = data.get(i).get(3);
        outwards = data.get(i).get(5);
        itemNo = data.get(i).get(1);
        unit = data.get(i).get(6);
        unitPrice = data.get(i).get(8);
        amount = data.get(i).get(9);

        table.addCell(itemNo);
        table.addCell(description);
        table.addCell(outwards);
        table.addCell(unit);
        table.addCell(unitPrice);
        table.addCell(amount);
    }
    preface.add(table);
}

From source file:com.horizzon.inventerium.ExportPdf.java

private static void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Buy Date"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/*from  www. j a va2  s . c  om*/

    c1 = new PdfPCell(new Phrase("Shopkeeper Name"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Quantity"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Amount"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Profit"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Payment Status"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    for (int i = 0; i < transaction_list_export.size(); i++) {

        HashMap<String, String> transactionlist = new HashMap<String, String>();
        transactionlist = transaction_list_export.get(i);

        table.addCell("" + transactionlist.get(T_DATE));

        int pos = find_Shopkeeper_id(transactionlist.get(USER_ID), shopkeeper_id_export);
        table.addCell("" + shopkeeper_name_export.get(pos));
        table.addCell(transactionlist.get(T_QTY));

        int am = Integer.parseInt(transactionlist.get(T_UNIT_PRICE))
                * Integer.parseInt(transactionlist.get(T_QTY));
        table.addCell("" + am);

        table.addCell("" + Integer.parseInt(transactionlist.get(T_UNIT_PRICE)) / 2);

        table.addCell(transactionlist.get(T_PAYMENT_STATUS));

    }
    subCatPart.add(table);

}

From source file:com.hris.payroll.reports.AdvancesReportPdf.java

public AdvancesReportPdf(int branchId, Date payrollDate, String reportType) {
    this.branchId = branchId;
    this.payrollDate = payrollDate;
    this.reportType = reportType;

    Document document = null;//from   w  ww.j a  va  2 s . c  om
    Rectangle pageSize = new Rectangle(318, 825);

    try {
        document = new Document(PageSize.A4.rotate(), 37, 37, 37, 37);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        document.open();

        int tradeId = cs.getTradeIdByBranchId(branchId);
        int corporateId = cs.getCorporateIdByTradeId(tradeId);

        Paragraph reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase(cs.getCorporateById(corporateId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Trade: " + cs.getTradeById(tradeId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Branch: " + cs.getBranchById(getBranchId()).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Advances Type: " + getReportType(), content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Payroll Period: " + CommonUtil.changeDateFormat(
                ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate()).getPayrollDate().toString()),
                content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Cut-off Date: "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodFrom().toString())
                + " - "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodTo().toString()),
                content));
        document.add(reportHeader);

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(3);
        //            table.setWidthPercentage(100);
        table.setTotalWidth(new float[] { 180, 120, 300 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        PdfPCell cellLabel = new PdfPCell();
        Paragraph parLabel = new Paragraph();
        parLabel.add(new Phrase("EMPLOYEE", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("AMOUNT", boldFont));
        parLabel.setAlignment(Element.ALIGN_RIGHT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("PARTICULARS", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setPaddingLeft(20);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        String middlename;
        double grandTotalAmount = 0;
        double subTotalAmount;
        int prCounter = 0;
        int advancesCounter;
        for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) {
            if (pr.getMiddlename().isEmpty() || pr.getMiddlename() == null) {
                middlename = "";
            } else {
                middlename = pr.getMiddlename().toUpperCase();
            }
            String employee = pr.getLastname().toUpperCase() + ", " + pr.getFirstname().toUpperCase() + " "
                    + middlename;
            subTotalAmount = 0;
            advancesCounter = 0;
            for (Advances a : as.findByPayroll(pr.getPayrollId(), getReportType())) {
                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                if (advancesCounter == 0) {
                    parLabel.add(new Phrase(employee, content));
                } else {
                    parLabel.add(new Phrase("", content));
                }
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(CommonUtil.formatNumValue(a.getAmount()), content));
                parLabel.setAlignment(Element.ALIGN_RIGHT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                subTotalAmount = subTotalAmount + a.getAmount();
                advancesCounter++;
                if (advancesCounter == as.findByPayroll(pr.getPayrollId(), getReportType()).size()) {
                    cellLabel.setBorder(Rectangle.BOTTOM);
                } else {
                    cellLabel.setBorder(Rectangle.NO_BORDER);
                }
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(a.getParticulars(), content));
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setPaddingLeft(20);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);
            }

            if (subTotalAmount != 0) {
                subTotal(table, subTotalAmount);
            }

            grandTotalAmount = grandTotalAmount + subTotalAmount;
            prCounter++;
        }

        grandTotal(table, grandTotalAmount);
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AdvancesReportPdf.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }

}

From source file:com.hris.payroll.reports.AdvancesSummaryReportPdf.java

public AdvancesSummaryReportPdf(int branchId, Date payrollDate) {
    this.branchId = branchId;
    this.payrollDate = payrollDate;

    Document document = null;/*from   w  ww .j a va2  s. c  o  m*/
    Rectangle pageSize = new Rectangle(318, 825);

    try {
        document = new Document(PageSize.A4.rotate(), 37, 37, 37, 37);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        document.open();

        int tradeId = cs.getTradeIdByBranchId(branchId);
        int corporateId = cs.getCorporateIdByTradeId(tradeId);

        Paragraph reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase(cs.getCorporateById(corporateId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Trade: " + cs.getTradeById(tradeId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Branch: " + cs.getBranchById(getBranchId()).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Advances Summary", content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Payroll Period: " + CommonUtil.changeDateFormat(
                ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate()).getPayrollDate().toString()),
                content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Cut-off Date: "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodFrom().toString())
                + " - "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodTo().toString()),
                content));
        document.add(reportHeader);

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(4);
        //            table.setWidthPercentage(100);
        table.setTotalWidth(new float[] { 180, 120, 130, 300 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        PdfPCell cellLabel = new PdfPCell();
        Paragraph parLabel = new Paragraph();
        parLabel.add(new Phrase("EMPLOYEE", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("AMOUNT", boldFont));
        parLabel.setAlignment(Element.ALIGN_RIGHT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("ADVANCES TYPE", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setPaddingLeft(20);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("PARTICULARS", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setPaddingLeft(20);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        String middlename;
        double grandTotalAmount = 0;
        double subTotalAmount;
        int prCounter = 0;
        int advancesCounter;
        for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) {
            if (pr.getMiddlename().isEmpty() || pr.getMiddlename() == null) {
                middlename = "";
            } else {
                middlename = pr.getMiddlename().toUpperCase();
            }
            String employee = pr.getLastname().toUpperCase() + ", " + pr.getFirstname().toUpperCase() + " "
                    + middlename;
            subTotalAmount = 0;
            advancesCounter = 0;
            for (Advances a : as.findByPayroll(pr.getPayrollId())) {
                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                if (advancesCounter == 0) {
                    parLabel.add(new Phrase(employee, content));
                } else {
                    parLabel.add(new Phrase("", content));
                }
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(CommonUtil.formatNumValue(a.getAmount()), content));
                parLabel.setAlignment(Element.ALIGN_RIGHT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                subTotalAmount = subTotalAmount + a.getAmount();
                advancesCounter++;
                if (advancesCounter == as.findByPayroll(pr.getPayrollId()).size()) {
                    cellLabel.setBorder(Rectangle.BOTTOM);
                } else {
                    cellLabel.setBorder(Rectangle.NO_BORDER);
                }
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(a.getAdvanceType(), content));
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setPaddingLeft(20);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(a.getParticulars(), content));
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setPaddingLeft(20);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);
            }

            if (subTotalAmount != 0) {
                subTotal(table, subTotalAmount);
            }

            grandTotalAmount = grandTotalAmount + subTotalAmount;
            prCounter++;
        }

        grandTotal(table, grandTotalAmount);
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AdvancesReportPdf.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.hris.payroll.reports.PayslipReportPDF.java

public PayslipReportPDF(int branchId, Date payrollDate) {
    this.branchId = branchId;
    this.payrollDate = payrollDate;

    Document document = null;/*from   w  ww .j a  va 2  s .c  om*/
    Rectangle pageSize = new Rectangle(318, 825);
    try {
        //            document = new Document(PageSize.A4, 50, 50, 48, 40);
        document = new Document(pageSize, 37, 37, 37, 37);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        document.open();

        PdfPTable mainTable = new PdfPTable(1);
        //            mainTable.setTotalWidth(new float[]{ 120, 120 });
        mainTable.setWidthPercentage(100);
        mainTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);
        //            mainTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //            mainTable.setLockedWidth(true);

        //            leftColumnTable(mainTable);
        //            rightColumnTable(mainTable);

        //            for(Employee e : es.findEmployeeByBranch(getBranchId())){
        for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) {
            document.add(leftColumnTable(pr, getPayrollDate()));
            document.newPage();
        }

    } catch (DocumentException ex) {
        Logger.getLogger(PayslipReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}