Example usage for com.lowagie.text.pdf PdfPTable setHeaderRows

List of usage examples for com.lowagie.text.pdf PdfPTable setHeaderRows

Introduction

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

Prototype

public void setHeaderRows(int headerRows) 

Source Link

Document

Sets the number of the top rows that constitute the header.

Usage

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void printMeasures(Measures measures, Section section)
        throws org.dom4j.DocumentException, DocumentException {

    PdfPTable versioningTable = new PdfPTable(2);
    formatTable(versioningTable);/*w  ww  .  java 2s. c  o  m*/
    versioningTable.getDefaultCell().setColspan(2);
    versioningTable
            .addCell(new Phrase(super.getTextProperty("general.versioning_information"), Style.TITLE_FONT));
    versioningTable.addCell(measures.getVersion());
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd - HH:mm:ss");
    versioningTable.addCell(df.format(measures.getDate()));

    PdfPTable measuresTable = new PdfPTable(2);
    formatTable(measuresTable);

    Iterator<String> it = measures.getMeasuresKeys().iterator();
    measuresTable.addCell(new Phrase(super.getTextProperty("general.metric"), Style.TITLE_FONT));
    measuresTable.addCell(new Phrase(super.getTextProperty("general.value"), Style.TITLE_FONT));
    boolean colorEnabled = true;
    while (it.hasNext()) {
        String measureKey = it.next();
        if (colorEnabled) {
            measuresTable.getDefaultCell().setGrayFill(0.9f);
            colorEnabled = false;
        } else {
            measuresTable.getDefaultCell().setGrayFill(1);
            colorEnabled = true;
        }
        if (!measureKey.equals("ccn_classes_count_distribution")
                && !measureKey.equals("ccn_classes_percent_distribution")) {
            measuresTable.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
            measuresTable.addCell(super.getTextProperty("metrics." + measureKey));
            measuresTable.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
            measuresTable.addCell(measures.getMeasure(measureKey).getFormatValue());
        }
    }
    measuresTable.setHeaderRows(1);
    section.add(versioningTable);
    section.add(measuresTable);

}

From source file:org.unitime.timetable.webutil.PdfWebTable.java

License:Open Source License

/**
 * Prints pdf table. By default does not split table across
 * page boundaries //from  ww  w. j  a va 2  s . c  om
 * @param ordCol
 * @param keepTogether true does not split table across pages
 * @return
 */
public PdfPTable printPdfTable(int ordCol, boolean keepTogether) {
    PdfPTable table = new PdfPTable(getNrColumns());
    table.setWidthPercentage(100);
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setBorderWidth(0);
    table.setSplitRows(false);
    table.setKeepTogether(keepTogether);

    boolean asc = (ordCol == 0 || iAsc == null || iAsc.length <= Math.abs(ordCol) - 1 ? true
            : iAsc[Math.abs(ordCol) - 1]);
    if (ordCol < 0)
        asc = !asc;

    widths = new float[iColumns];
    for (int i = 0; i < iColumns; i++)
        widths[i] = 0f;

    String lastLine[] = new String[Math.max(iColumns, (iHeaders == null ? 0 : iHeaders.length))];

    if (iHeaders != null) {
        for (int i = 0; i < iColumns; i++) {
            if (isFiltered(i))
                continue;
            PdfPCell c = createCell();
            c.setBorderWidthBottom(1);
            float width = addText(c, iHeaders[i] == null ? "" : iHeaders[i], true);
            widths[i] = Math.max(widths[i], width);
            String align = (iAlign != null ? iAlign[i] : "left");
            if ("left".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_LEFT);
            if ("right".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if ("center".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(c);
        }
        table.setHeaderRows(1);
    }
    if (ordCol != 0) {
        Collections.sort(iLines, new WebTableComparator(Math.abs(ordCol) - 1, asc));
    }
    for (int el = 0; el < iLines.size(); el++) {
        WebTableLine wtline = (WebTableLine) iLines.elementAt(el);
        String[] line = wtline.getLine();
        boolean blank = iBlankWhenSame;
        for (int i = 0; i < iColumns; i++) {
            if (isFiltered(i))
                continue;
            if (blank && line[i] != null && !line[i].equals(lastLine[i]))
                blank = false;
            PdfPCell c = createCell();
            float width = addText(c, blank || line[i] == null ? "" : line[i], false);
            widths[i] = Math.max(widths[i], width);
            String align = (iAlign != null ? iAlign[i] : "left");
            if ("left".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_LEFT);
            if ("right".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if ("center".equals(align))
                c.setHorizontalAlignment(Element.ALIGN_CENTER);
            applyPdfStyle(c, wtline, (el + 1 < iLines.size() ? (WebTableLine) iLines.elementAt(el + 1) : null),
                    ordCol);
            table.addCell(c);
            lastLine[i] = line[i];
        }
    }

    try {
        if (getNrFilteredColumns() < 0) {
            table.setWidths(widths);
        } else {
            float[] x = new float[getNrColumns()];
            int idx = 0;
            for (int i = 0; i < iColumns; i++) {
                if (isFiltered(i))
                    continue;
                x[idx++] = widths[i];
            }
            table.setWidths(x);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return table;
}

From source file:org.webguitoolkit.ui.util.export.PDFTableExport.java

License:Apache License

/**
 * @param table//from w  ww.ja  v a  2s. co  m
 * @param footer
 * @param header
 * @return
 */
public PdfPTable pdfExport(Table table) {
    TableExportOptions exportOptions = table.getExportOptions();
    boolean showOnlyDisplayed = exportOptions.isShowOnlyDisplayedColumns();
    Font headfont = new Font(Font.UNDEFINED, Font.DEFAULTSIZE, Font.BOLD);

    Font bodyfont = new Font(exportOptions.getPdfFontSize(), exportOptions.getPdfFontSize(), Font.NORMAL);
    if (exportOptions.getPdfFontColour() != null) {
        Color fontColor = exportOptions.getPdfFontColour();
        bodyfont.setColor(fontColor);
        headfont.setColor(fontColor);
    }

    List<ITableColumn> columns = getTableColumns(showOnlyDisplayed, table);
    int columnCount = 0;
    for (int i = 0; i < columns.size(); i++) {
        TableColumn c = (TableColumn) columns.get(i);
        //hide select checkbox column
        if (!c.isExporatble())
            continue;

        columnCount++;

    }
    PdfPTable resulttable = new PdfPTable(columnCount);
    resulttable.setWidthPercentage(100f);

    if (StringUtils.isNotEmpty(exportOptions.getTableHeadline())) {
        PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableHeadline()));
        cell.setColspan(columns.size());
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);
    }

    for (int i = 0; i < columns.size(); i++) {
        TableColumn c = (TableColumn) columns.get(i);
        // hide select checkbox column
        if (!c.isExporatble())
            continue;

        String cellData = TextService.getString(c.getTitle());
        if (cellData.contains("<br/>") || cellData.contains("<br>")) {
            cellData = cellData.replaceAll("<br\\/>", "\\/");
            cellData = cellData.replaceAll("<br>", "\\/");
        }
        PdfPCell cell = new PdfPCell(new Paragraph((cellData), headfont));
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);

    }

    List tabledata = table.getDefaultModel().getFilteredList();
    if (tabledata.isEmpty()) {
        for (int i = 0; i < columns.size(); i++) {
            resulttable.addCell(new PdfPCell((new Phrase(""))));
        }
    }

    for (Iterator it = tabledata.iterator(); it.hasNext();) {
        DataBag dbag = (DataBag) it.next();
        for (int i = 0; i < columns.size(); i++) {
            TableColumn tableColumn = (TableColumn) columns.get(i);
            if (!tableColumn.isExporatble())
                continue;
            logger.debug("property: " + tableColumn.getProperty());
            IColumnRenderer renderer = tableColumn.getRenderer();
            Converter converter = tableColumn.getConverter();

            addObjectCell(bodyfont, resulttable, dbag, tableColumn, renderer, converter);
        }
    }

    if (StringUtils.isNotEmpty(exportOptions.getTableFooter())) {
        PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableFooter()));
        cell.setColspan(columnCount);
        cell.setBackgroundColor(Color.lightGray);
        resulttable.addCell(cell);
    }

    resulttable.setHeaderRows(1);
    return resulttable;

}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

private void addLabCategory(String header) throws DocumentException {

    float[] mainTableWidths = { 5f, 3f, 1f, 3f, 2f, 4f, 2f };
    PdfPTable table = new PdfPTable(mainTableWidths);
    table.setHeaderRows(3);
    table.setWidthPercentage(100);/*  www.  j a v a 2 s .c  om*/

    PdfPCell cell = new PdfPCell();
    // category name
    cell.setPadding(3);
    cell.setPhrase(new Phrase("  "));
    cell.setBorder(0);
    cell.setColspan(7);
    table.addCell(cell);
    cell.setBorder(15);
    cell.setPadding(3);
    cell.setColspan(2);
    cell.setPhrase(new Phrase(header.replaceAll("<br\\s*/*>", "\n"), new Font(bf, 12, Font.BOLD)));
    table.addCell(cell);
    cell.setPhrase(new Phrase("  "));
    cell.setBorder(0);
    cell.setColspan(5);
    table.addCell(cell);

    // table headers
    cell.setColspan(1);
    cell.setBorder(15);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(new Color(210, 212, 255));
    cell.setPhrase(new Phrase("Test Name(s)", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Result", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Abn", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Reference Range", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Units", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Date/Time Completed", boldFont));
    table.addCell(cell);
    cell.setPhrase(new Phrase("Status", boldFont));
    table.addCell(cell);

    // add test results
    int obrCount = handler.getOBRCount();
    int linenum = 0;
    cell.setBorder(12);
    cell.setBorderColor(Color.BLACK); // cell.setBorderColor(Color.WHITE);
    cell.setBackgroundColor(new Color(255, 255, 255));

    if (handler.getMsgType().equals("MEDVUE")) {

        //cell.setBackgroundColor(getHighlightColor(linenum));
        linenum++;
        cell.setPhrase(new Phrase(handler.getRadiologistInfo(), boldFont));
        cell.setColspan(7);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        cell.setPaddingLeft(100);
        cell.setColspan(7);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setPhrase(new Phrase(handler.getOBXComment(1, 1, 1).replaceAll("<br\\s*/*>", "\n"), font));
        table.addCell(cell);

    } else {
        for (int j = 0; j < obrCount; j++) {
            boolean obrFlag = false;
            int obxCount = handler.getOBXCount(j);
            for (int k = 0; k < obxCount; k++) {
                String obxName = handler.getOBXName(j, k);

                if (!handler.getOBXResultStatus(j, k).equals("TDIS")) {

                    // ensure that the result is a real result
                    if ((!handler.getOBXResultStatus(j, k).equals("DNS") && !obxName.equals("")
                            && handler.getObservationHeader(j, k).equals(header))
                            || (handler.getMsgType().equals("EPSILON")
                                    && handler.getOBXIdentifier(j, k).equals(header) && !obxName.equals(""))
                            || (handler.getMsgType().equals("PFHT") && !obxName.equals("")
                                    && handler.getObservationHeader(j, k).equals(header))) { // <<-- DNS only needed for
                        // MDS messages
                        String obrName = handler.getOBRName(j);

                        // add the obrname if necessary
                        if (!obrFlag && !obrName.equals("") && !(obxName.contains(obrName) && obxCount < 2)) {
                            // cell.setBackgroundColor(getHighlightColor(linenum));
                            linenum++;
                            cell.setPhrase(new Phrase(obrName, boldFont));
                            cell.setColspan(7);
                            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                            table.addCell(cell);
                            cell.setColspan(1);
                            obrFlag = true;
                        }

                        // add the obx results and info
                        Font lineFont = new Font(bf, 8, Font.NORMAL,
                                getTextColor(handler.getOBXAbnormalFlag(j, k)));
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(new Phrase((obrFlag ? "   " : "") + obxName, lineFont));
                        table.addCell(cell);
                        cell.setPhrase(new Phrase(handler.getOBXResult(j, k).replaceAll("<br\\s*/*>", "\n"),
                                lineFont));
                        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        table.addCell(cell);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setPhrase(new Phrase(
                                (handler.isOBXAbnormal(j, k) ? handler.getOBXAbnormalFlag(j, k) : "N"),
                                lineFont));
                        table.addCell(cell);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(new Phrase(handler.getOBXReferenceRange(j, k), lineFont));
                        table.addCell(cell);
                        cell.setPhrase(new Phrase(handler.getOBXUnits(j, k), lineFont));
                        table.addCell(cell);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setPhrase(new Phrase(handler.getTimeStamp(j, k), lineFont));
                        table.addCell(cell);
                        cell.setPhrase(new Phrase(handler.getOBXResultStatus(j, k), lineFont));
                        table.addCell(cell);

                        if (!handler.getMsgType().equals("PFHT")) {
                            // add obx comments
                            if (handler.getOBXCommentCount(j, k) > 0) {
                                // cell.setBackgroundColor(getHighlightColor(linenum));
                                linenum++;
                                cell.setPaddingLeft(100);
                                cell.setColspan(7);
                                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                                for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) {

                                    cell.setPhrase(new Phrase(
                                            handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"),
                                            font));
                                    table.addCell(cell);

                                }
                                cell.setPadding(3);
                                cell.setColspan(1);
                            }
                        }
                        // if (DNS)
                    } else if ((handler.getMsgType().equals("EPSILON")
                            && handler.getOBXIdentifier(j, k).equals(header) && obxName.equals(""))
                            || (handler.getMsgType().equals("PFHT") && obxName.equals("")
                                    && handler.getObservationHeader(j, k).equals(header))) {
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setColspan(7);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(
                                new Phrase(handler.getOBXResult(j, k).replaceAll("<br\\s*/*>", "\n"), font));
                        table.addCell(cell);
                        cell.setPadding(3);
                        cell.setColspan(1);

                    }
                    if (handler.getMsgType().equals("PFHT") && !handler.getNteForOBX(j, k).equals("")
                            && handler.getNteForOBX(j, k) != null) {
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setColspan(7);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        cell.setPhrase(
                                new Phrase(handler.getNteForOBX(j, k).replaceAll("<br\\s*/*>", "\n"), font));
                        table.addCell(cell);
                        cell.setPadding(3);
                        cell.setColspan(1);

                        if (handler.getOBXCommentCount(j, k) > 0) {
                            // cell.setBackgroundColor(getHighlightColor(linenum));
                            linenum++;
                            cell.setPaddingLeft(100);
                            cell.setColspan(7);
                            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                            for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) {

                                cell.setPhrase(new Phrase(
                                        handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"), font));
                                table.addCell(cell);

                            }
                            cell.setPadding(3);
                            cell.setColspan(1);
                        }
                    }
                } else {
                    if (handler.getOBXCommentCount(j, k) > 0) {
                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setColspan(7);
                        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                        for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) {

                            cell.setPhrase(new Phrase(
                                    handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"), font));
                            table.addCell(cell);

                        }
                        cell.setPadding(3);
                        cell.setColspan(1);
                    }
                } // if (!handler.getOBXResultStatus(j, k).equals("TDIS"))

            }

            if (!handler.getMsgType().equals("PFHT")) {
                // add obr comments
                if (handler.getObservationHeader(j, 0).equals(header)) {
                    cell.setColspan(7);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    for (int k = 0; k < handler.getOBRCommentCount(j); k++) {
                        // the obrName should only be set if it has not been
                        // set already which will only have occured if the
                        // obx name is "" or if it is the same as the obr name
                        if (!obrFlag && handler.getOBXName(j, 0).equals("")) {
                            // cell.setBackgroundColor(getHighlightColor(linenum));
                            linenum++;

                            cell.setPhrase(new Phrase(handler.getOBRName(j), boldFont));
                            table.addCell(cell);
                            obrFlag = true;
                        }

                        // cell.setBackgroundColor(getHighlightColor(linenum));
                        linenum++;
                        cell.setPaddingLeft(100);
                        cell.setPhrase(
                                new Phrase(handler.getOBRComment(j, k).replaceAll("<br\\s*/*>", "\n"), font));
                        table.addCell(cell);
                        cell.setPadding(3);
                    }
                    cell.setColspan(1);
                }
            }
        } // for (j)

    } // if (isMEDVUE)

    document.add(table);

}

From source file:questions.tables.TableHeaderAlternateBackground.java

public static void main(String[] args) {
    // step 1: creation of a document-object
    Document document = new Document(PageSize.A4.rotate());
    try {//from   ww  w.ja va  2 s.co m
        // step 2:
        // we create a writer
        PdfWriter.getInstance(
                // that listens to the document
                document,
                // and directs a PDF-stream to a file
                new FileOutputStream(RESULT));
        // step 3: we open the document
        document.open();
        // step 4: we add a table to the document
        PdfPTable datatable = new PdfPTable(10);
        datatable.setTableEvent(new AlternateBackground());
        int headerwidths[] = { 10, 24, 12, 12, 7, 7, 7, 7, 7, 7 };
        datatable.setWidths(headerwidths);
        datatable.setWidthPercentage(100);
        datatable.getDefaultCell().setPadding(5);

        // The header starts with a cell that spans 10 columns
        PdfPCell cell = new PdfPCell(new Phrase("Administration - System Users Report",
                FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(2);
        cell.setColspan(10);
        cell.setBackgroundColor(Color.YELLOW);
        cell.setUseDescender(true);
        datatable.addCell(cell);
        // We need 4 cells with rowspan 2
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setBackgroundColor(Color.YELLOW);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell("User Id");
        datatable.addCell("Name\nAddress");
        datatable.addCell("Company");
        datatable.addCell("Department");
        datatable.getDefaultCell().setBackgroundColor(null);
        // we use a nested table to fake this
        PdfPTable permissions = new PdfPTable(6);
        permissions.getDefaultCell().setBackgroundColor(Color.YELLOW);
        permissions.getDefaultCell().setBorderWidth(2);
        permissions.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        permissions.getDefaultCell().setColspan(6);
        permissions.addCell("Permissions");
        permissions.getDefaultCell().setColspan(1);
        permissions.addCell("Admin");
        permissions.addCell("Data");
        permissions.addCell("Expl");
        permissions.addCell("Prod");
        permissions.addCell("Proj");
        permissions.addCell("Online");
        PdfPCell permission = new PdfPCell(permissions);
        permission.setColspan(6);
        datatable.addCell(permission);
        // this is the end of the table header
        // as far as PdfPTable is concerned there are 2 rows in the header
        datatable.setHeaderRows(2);

        // we add the data to the table
        datatable.getDefaultCell().setBorderWidth(1);
        for (int i = 1; i < 50; i++) {
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            datatable.addCell("myUserId");
            datatable.addCell("Person " + i);
            datatable.addCell("No Name Company");
            datatable.addCell("D" + i);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            for (int j = 0; j < 6; j++)
                datatable.addCell(Math.random() > .5 ? "Yes" : "No");
        }
        document.add(datatable);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}

From source file:vistas.reportes.procesos.rptAsistenciaTotal.java

public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin, boolean isSelectedComp,
        boolean isSelectedHoraM, String tipo) throws DocumentException {
    /**//from  w w w . j a  v  a2s.c  om
     * Procesamiento para info para generar tablas
     */
    /**
     * Procesamiento para elaborar tabla con datos
     */
    int nroColumnas;
    if (isSelectedComp) {
        nroColumnas = 9;
    } else {
        nroColumnas = 8;
    }
    if (tipo == "P") {
        nroColumnas -= 2;
    }
    //int nroColumnas = 8;
    PdfPTable tabla = new PdfPTable(nroColumnas);
    tabla.setWidthPercentage(100);
    //Asignamos los tamaos a las columnas 
    //MOdifique para tomar en cuenta la nueva columna de dewscuento
    int[] widthColumna = new int[nroColumnas];
    if (tipo == "P") {
        widthColumna[0] = 1;
        widthColumna[1] = 1;
        widthColumna[2] = 1;
        widthColumna[3] = 1;
        widthColumna[4] = 2;
        widthColumna[5] = 1;
        if (isSelectedComp) {
            widthColumna[6] = 1;
        }
    } else {
        widthColumna[0] = 1;
        widthColumna[1] = 4;
        widthColumna[2] = 1;
        widthColumna[3] = 1;
        widthColumna[4] = 1;
        widthColumna[5] = 1;
        widthColumna[6] = 2;
        widthColumna[7] = 1;
        if (isSelectedComp) {
            widthColumna[8] = 1;
        }
    }

    tabla.setWidths(widthColumna);

    //Definimos celdas iniciales
    Font fontCabecera = new Font(Font.HELVETICA, 8, Font.BOLD);
    Font fontCelda = new Font(Font.HELVETICA, 7);
    //        HeaderFooter cabecera = new HeaderFooter(new Phrase("This is a header."), false);
    //        cabecera.

    if (tipo != "P") {
        PdfPCell h0 = new PdfPCell(new Phrase("DNI", fontCabecera));
        h0.setHorizontalAlignment(1);
        h0.setGrayFill(0.7f);
        h0.setColspan(1);
        tabla.addCell(h0);

        PdfPCell h1 = new PdfPCell(new Phrase("NOMBRE EMPLEADO", fontCabecera));
        h1.setHorizontalAlignment(1);
        h1.setGrayFill(0.7f);
        h1.setColspan(1);
        tabla.addCell(h1);
    }

    PdfPCell h2 = new PdfPCell(new Phrase("FECHA", fontCabecera));
    h2.setHorizontalAlignment(1);
    h2.setGrayFill(0.7f);
    h2.setColspan(1);
    tabla.addCell(h2);

    PdfPCell h3 = new PdfPCell(new Phrase("MARC. ENTR.", fontCabecera));
    h3.setHorizontalAlignment(1);
    h3.setGrayFill(0.7f);
    h3.setColspan(1);
    tabla.addCell(h3);

    PdfPCell h4 = new PdfPCell(new Phrase("MARC. SAL.", fontCabecera));
    h4.setHorizontalAlignment(1);
    h4.setGrayFill(0.7f);
    h4.setColspan(1);
    tabla.addCell(h4);

    PdfPCell h5 = new PdfPCell(new Phrase("ESTADO", fontCabecera));
    h5.setHorizontalAlignment(1);
    h5.setGrayFill(0.7f);
    h5.setColspan(1);
    tabla.addCell(h5);

    PdfPCell h6 = new PdfPCell(new Phrase("OBSERV.", fontCabecera));
    h6.setHorizontalAlignment(1);
    h6.setGrayFill(0.7f);
    h6.setColspan(1);
    tabla.addCell(h6);

    PdfPCell h7 = new PdfPCell(new Phrase("PER. VAC", fontCabecera));
    h7.setHorizontalAlignment(1);
    h7.setGrayFill(0.7f);
    h7.setColspan(1);
    tabla.addCell(h7);

    if (isSelectedComp) {
        PdfPCell h8 = new PdfPCell(new Phrase("COMPENSA", fontCabecera));
        h8.setHorizontalAlignment(1);
        h8.setGrayFill(0.7f);
        h8.setColspan(1);
        tabla.addCell(h8);
    }
    //Hacemos que la primera fila sea la cabecera
    tabla.setHeaderRows(1);
    /**
     * Procesamiento de los datos para generar los registros de la entrada
     */

    Calendar calC = Calendar.getInstance();
    for (String dni : dnis) {
        Calendar iterador = Calendar.getInstance();
        iterador.setTime(fechaInicio);
        while (iterador.getTime().compareTo(fechaFin) <= 0) {
            Date fecha = iterador.getTime();
            //Descartar si es sabado o domingo
            System.out.println("Dni: " + dni + " Fecha: " + fecha.toString());
            Empleado empleado = ec.buscarPorDni(dni);
            boolean isFeriado = false;
            String feriado = "";
            //Para inicio de contrato
            if (empleado.getFechaInicioContrato().compareTo(fecha) <= 0) {
                System.out.println("OK");
            } else {
                iterador.add(Calendar.DATE, 1);
                continue;
            }
            /**
             * Generacion de permiso por onomastico
             */
            if (isOnosmatico(fecha, empleado)) {
                Calendar fechaPermisoOno = Calendar.getInstance();
                fechaPermisoOno.setTime(fecha);

                while (fc.buscarXDia(fechaPermisoOno.getTime()) != null) {
                    fechaPermisoOno.add(Calendar.DATE, 1);
                }
                while (!ReporteUtil.isDiaLaboral(fechaPermisoOno.getTime())) {
                    fechaPermisoOno.add(Calendar.DATE, 1);
                }
                if (ReporteUtil.isDiaLaboral(fechaPermisoOno.getTime())) {
                    //busca onomastico
                    if (aspc.buscarXDiaOnosmatico(dni, fechaPermisoOno.getTime()) != null) {
                        System.out.println("Hay cumpleaosd d_d");
                    } else {
                        System.out.println("Crear Cumple");
                        crearOnomastico(fechaPermisoOno.getTime(), empleado);
                    }
                }
            } else {
                System.out.println("No cumple");
            }

            if (!ReporteUtil.isDiaLaboral(fecha)) {
                iterador.add(Calendar.DATE, 1);
                continue;
            }
            if (fc.buscarXDia(fecha) != null) {
                isFeriado = true;
                feriado = fc.buscarXDia(fecha).getNombre();
            }
            //Marcaciones del dia a procesar
            List<Marcacion> marcaciones = mc.buscarXFecha(dni, fecha);
            String Asistencia = "";
            String Permiso = "";
            String Vacaciones = "";
            String marcacion = "";
            String marcacion2 = "";
            String condicion = "";
            String compensacion = "";
            Marcacion primeraMarcacion = new Marcacion();
            Marcacion ultimaMarcacion = new Marcacion();

            List<EmpleadoOpcionInfo> infoEmpleado = eoc.buscarTodos(Integer.parseInt(dni));
            if (!infoEmpleado.isEmpty()) {
                if (infoEmpleado.get(0).getSFieldValue5().equals("0")
                        || infoEmpleado.get(0).getSFieldValue5().equals("")
                        || infoEmpleado.get(0).getSFieldValue5().equals(" ")) {
                    condicion = "NORMAL";
                } else if (infoEmpleado.get(0).getSFieldValue5().equals("1")) {
                    condicion = "Exonerado";
                } else if (infoEmpleado.get(0).getSFieldValue5().equals("2")) {
                    condicion = "Designado";
                } else if (infoEmpleado.get(0).getSFieldValue5().equals("3")) {
                    condicion = "Otra sede";
                }
            } else {
                condicion = "Sin dato";
            }
            System.out.println("Condicion: " + condicion);
            //Datos de horario, jornada, empleado
            List<DetalleGrupoHorario> detallesGrupos = dc.buscarXEmpleado(empleado);
            if (condicion.equals("NORMAL")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    if (marcaciones.size() > 1) {
                        ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                        marcacion2 = ultimaMarcacion.getHora().toString();
                    } else {
                        marcacion2 = "---";
                    }
                    //ultimaMarcacion = marcaciones.get(marcaciones.size()-1);
                    /**
                     *Codigo para el manejo de asignaciones de horario
                     */

                    if (!detallesGrupos.isEmpty()) {
                        DetalleGrupoHorario detalleGrupoEmpleado = detallesGrupos.get(0);

                        List<AsignacionHorario> asignaciones = ashc
                                .buscarXGrupo(detalleGrupoEmpleado.getGrupoHorario());
                        //List<AsignacionHorario> asignacionesHorario = ashc.bus
                        List<AsignacionHorario> asignacionesHorarios = ashc.buscarXEmpleadosXAll(dni, fecha);
                        //Declaramos la variable asighorario q usaremos
                        /**
                         * Vemos si tiene una asignacion horario en particular para asignar la jornada q le corresponde, sino la tiene se asigna la jornada por 
                         * defecto del grupo horario general
                         */
                        AsignacionHorario asignacionEmpleado;
                        if (!asignacionesHorarios.isEmpty()) {
                            asignacionEmpleado = asignacionesHorarios.get(0);
                        } else {
                            asignacionEmpleado = asignaciones.get(0);
                        }
                        //AsignacionHorario asignacionEmpleado = asignaciones.get(0);
                        Horario horarioEmpleado = asignacionEmpleado.getHorario();
                        Jornada jornadaEmpleado = horarioEmpleado.getJornada();

                        //Validacion de asistencia
                        if (ultimaMarcacion.getHora() != null) {
                            if (!isSelectedHoraM) {
                                marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                            }
                            if (primeraMarcacion.getHora().compareTo(ultimaMarcacion.getHora()) < 0) {
                                if ((primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) == 0
                                        || primeraMarcacion.getHora()
                                                .compareTo(jornadaEmpleado.getTurnoHE()) < 0)
                                        && (ultimaMarcacion.getHora()
                                                .compareTo(jornadaEmpleado.getTurnoHS()) == 0
                                                || ultimaMarcacion.getHora()
                                                        .compareTo(jornadaEmpleado.getTurnoHS()) > 0)) {
                                    Asistencia = " ";
                                    //marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                } else if (primeraMarcacion.getHora()
                                        .compareTo(jornadaEmpleado.getTardanzaHE()) < 0
                                        && primeraMarcacion.getHora()
                                                .compareTo(jornadaEmpleado.getTurnoHE()) > 0) {
                                    Asistencia = "TARDANZA";
                                    //marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                } else if (primeraMarcacion.getHora()
                                        .compareTo(jornadaEmpleado.getTardanzaHE()) > 0
                                        && ultimaMarcacion.getHora()
                                                .compareTo(jornadaEmpleado.getTurnoHS()) < 0) {
                                    Asistencia = "FALTA";
                                    //Cambio hasta tener directiva
                                    //Asistencia = "TARDANZA";
                                } else if (primeraMarcacion.getHora()
                                        .compareTo(jornadaEmpleado.getTardanzaHE()) < 0
                                        && ultimaMarcacion.getHora()
                                                .compareTo(jornadaEmpleado.getTurnoHS()) < 0) {
                                    System.out.println("Hora de salida jornada: "
                                            + jornadaEmpleado.getTurnoHS().toString());
                                    Asistencia = "FALTA";
                                    //Cambio hasta tener directiva
                                    //Asistencia = "TARDANZA";
                                } else if (primeraMarcacion.getHora()
                                        .compareTo(jornadaEmpleado.getTardanzaHE()) < 0
                                        && ultimaMarcacion.getHora()
                                                .compareTo(jornadaEmpleado.getTurnoHS()) > 0) {
                                    //Asistencia = "Falta";
                                    //Cambio hasta tener directiva
                                    Asistencia = "TARDANZA";
                                    //marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                } else if (primeraMarcacion.getHora()
                                        .compareTo(jornadaEmpleado.getTardanzaHE()) > 0
                                        && ultimaMarcacion.getHora()
                                                .compareTo(jornadaEmpleado.getTurnoHS()) > 0) {
                                    //Asistencia = "Falta";
                                    //Cambio hasta tener directiva
                                    Asistencia = "TARDANZA";
                                    //marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                }
                                //Para la compensacion
                                if (isSelectedComp) {
                                    if (ultimaMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHS()) > 0) {
                                        calC.setTime(ultimaMarcacion.getHora());
                                        int horaUM = calC.get(Calendar.HOUR_OF_DAY);
                                        int minUM = calC.get(Calendar.MINUTE);
                                        calC.setTime(jornadaEmpleado.getTurnoHS());
                                        int horaHS = calC.get(Calendar.HOUR_OF_DAY);
                                        int minHS = calC.get(Calendar.MINUTE);
                                        System.out.println("Horas: " + " " + horaUM + " " + minUM + " " + horaHS
                                                + " " + minHS);
                                        if (horaUM > horaHS) {
                                            if (minUM > minHS) {
                                                compensacion = "" + (horaUM - horaHS) + " H";
                                            } else {
                                                compensacion = (horaUM - (horaHS + 1)) + " H";
                                            }
                                        } else {
                                            compensacion = "0 H";
                                        }
                                    }
                                }
                            } else {
                                Asistencia = "FALTA";
                            }
                        } else {
                            Asistencia = "FALTA";
                        }
                        if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHS()) >= 0) {
                            marcacion2 = primeraMarcacion.getHora().toString();
                            marcacion = "---";
                        } else {
                            marcacion = primeraMarcacion.getHora().toString();
                        }

                    } else {
                        Asistencia = "No tiene grupo horario";
                    }
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = "FALTA";
                }
            } else if (condicion.equals("Exonerado")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                    //marcacion = primeraMarcacion.getHora().toString();
                    //marcacion2 = ultimaMarcacion.getHora().toString();
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion.toUpperCase();
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion.toUpperCase();
                }
            } else if (condicion.equals("Designado")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                    //marcacion = primeraMarcacion.getHora().toString();
                    //marcacion2 = ultimaMarcacion.getHora().toString();
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion.toUpperCase();
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion.toUpperCase();
                }
            } else if (condicion.equals("Otra sede")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                    //marcacion = primeraMarcacion.getHora().toString();
                    //marcacion2 = ultimaMarcacion.getHora().toString();
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion.toUpperCase();
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion.toUpperCase();
                }
            } else {
                marcacion = "---";
                marcacion2 = "---";
                Asistencia = "Condicin sin especificar".toUpperCase();
            }

            //Validacion de permiso
            //Procesar permisos con horas tbm si no encuentra permisos por fechas 
            AsignacionPermiso asignacionPermisoEmpleadoDia = aspc.buscarXDia(dni, fecha);
            Calendar horaESinCero = Calendar.getInstance();
            Calendar horaFSinCero = Calendar.getInstance();
            if (primeraMarcacion.getHora() != null) {
                horaESinCero.setTime(primeraMarcacion.getHora());
                horaESinCero.set(Calendar.SECOND, 0);
            }
            if (ultimaMarcacion.getHora() != null) {
                horaFSinCero.setTime(ultimaMarcacion.getHora());
                horaFSinCero.set(Calendar.SECOND, 0);
            }

            AsignacionPermiso asigPerEntrada = aspc.buscarOnlyHora(dni, horaESinCero.getTime(), fecha);
            AsignacionPermiso asigPerSalida = aspc.buscarOnlyHora(dni, horaFSinCero.getTime(), fecha);
            if (asignacionPermisoEmpleadoDia != null) {
                Permiso = asignacionPermisoEmpleadoDia.getPermiso().getDocumento().toUpperCase();
                Asistencia = asignacionPermisoEmpleadoDia.getPermiso().getTipoPermiso().getNombre()
                        .toUpperCase();
            } else if (asigPerEntrada != null) {
                Permiso = asigPerEntrada.getPermiso().getDocumento().toUpperCase();
                Asistencia = asigPerEntrada.getPermiso().getTipoPermiso().getNombre().toLowerCase();
            } else if (asigPerSalida != null) {
                Permiso = asigPerSalida.getPermiso().getDocumento().toUpperCase();
                Asistencia = asigPerSalida.getPermiso().getTipoPermiso().getNombre().toUpperCase();
            } else {
                Permiso = "";
            }
            //Validacion de Vacaciones
            Vacacion vacacionEmpleado = vc.buscarXDia(dni, fecha);
            if (vacacionEmpleado != null) {
                Vacaciones = ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaInicio()) + " al "
                        + ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaFin());
                Asistencia = "VACACIONES";
                Permiso = vacacionEmpleado.getDocumento().toUpperCase();
            } else {
                Vacaciones = "";
            }
            if (isFeriado) {
                Asistencia = feriado;
            }
            PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getNroDocumento(), fontCelda));
            celdaNombre.setMinimumHeight(15f);
            if (tipo != "P") {
                //DNI
                celdaNombre.setHorizontalAlignment(1);
                tabla.addCell(celdaNombre);
                //Nombre
                String celda0 = empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno() + " "
                        + empleado.getNombre();
                celdaNombre.setPhrase(new Phrase(celda0, fontCelda));
                celdaNombre.setHorizontalAlignment(0);
                tabla.addCell(celdaNombre);
            }
            //Fecha
            String celdaA = ReporteUtil.obtenerFechaFormateada(fecha, "/");
            celdaNombre.setPhrase(new Phrase(celdaA, fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);
            //Hora Marcacion de entrada
            String celda = marcacion;
            celdaNombre.setPhrase(new Phrase(celda, fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);
            //Hora Marcacion de Salida
            String celdaM = marcacion2;
            celdaNombre.setPhrase(new Phrase(celdaM, fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);
            //Asistencia
            String celda1 = Asistencia;
            celdaNombre.setPhrase(new Phrase(celda1, fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);
            //Permiso
            String celda2 = Permiso;
            celdaNombre.setPhrase(new Phrase(celda2, fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);
            //Vacacion
            String celda3 = Vacaciones;
            celdaNombre.setPhrase(new Phrase(celda3, fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);
            //Compensacion
            if (isSelectedComp) {
                String celda4 = compensacion;
                celdaNombre.setPhrase(new Phrase(celda4, fontCelda));
                celdaNombre.setHorizontalAlignment(1);
                tabla.addCell(celdaNombre);
            }
            iterador.add(Calendar.DATE, 1);
        }
    }
    return tabla;
}

From source file:vistas.reportes.procesos.rptFaltas.java

public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException {
    /**/*from ww w  . ja v a 2  s  .  c o m*/
     * Procesamiento para info para generar tablas
     */
    Calendar fechaInicioC = Calendar.getInstance();
    Calendar fechaFinC = Calendar.getInstance();
    fechaInicioC.setTime(fechaInicio);
    fechaFinC.setTime(fechaFin);

    int diaMesInicio, diaMesFin;
    diaMesInicio = fechaInicioC.get(Calendar.DAY_OF_MONTH);
    diaMesFin = fechaFinC.get(Calendar.DAY_OF_MONTH);

    // Dias contados desde un inicio y fin fecha
    ArrayList<Integer> listaInt = new ArrayList<>();
    for (int i = diaMesInicio; i <= diaMesFin; i++) {
        listaInt.add(i);
    }
    //Ordenamos arraylist
    int indice, menor, aux;
    for (int i = 0; i < listaInt.size(); i++) {
        menor = listaInt.get(i);
        indice = i;
        aux = 0;
        for (int j = i + 1; j < listaInt.size(); j++) {
            aux = listaInt.get(j);
            indice = aux < menor ? j : indice;
            menor = aux < menor ? aux : menor;
        }
        listaInt.set(indice, listaInt.get(i));
        listaInt.set(i, menor);
    }
    /**
     * Procesamiento para elaborar tabla con datos
     */
    int nroColumnas = 3;
    PdfPTable tabla = new PdfPTable(nroColumnas);
    tabla.setWidthPercentage(100);
    //Asignamos los tamaos a las columnas 
    //MOdifique para tomar en cuenta la nueva columna de dewscuento
    int[] widthColumna = new int[nroColumnas];

    widthColumna[0] = 1;
    widthColumna[1] = 5;
    widthColumna[2] = 1;
    //widthColumna[8]=1;

    tabla.setWidths(widthColumna);

    //Definimos celdas iniciales
    Font fontCabecera = new Font(Font.HELVETICA, 8, Font.BOLD);
    Font fontCelda = new Font(Font.HELVETICA, 7);
    //        HeaderFooter cabecera = new HeaderFooter(new Phrase("This is a header."), false);
    //        cabecera.
    PdfPCell h0 = new PdfPCell(new Phrase("DNI", fontCabecera));
    h0.setHorizontalAlignment(1);
    h0.setGrayFill(0.7f);
    h0.setColspan(1);
    tabla.addCell(h0);

    PdfPCell h1 = new PdfPCell(new Phrase("NOMBRE EMPLEADO", fontCabecera));
    h1.setHorizontalAlignment(1);
    h1.setGrayFill(0.7f);
    h1.setColspan(1);
    tabla.addCell(h1);

    PdfPCell h2 = new PdfPCell(new Phrase("FECHA", fontCabecera));
    h2.setHorizontalAlignment(1);
    h2.setGrayFill(0.7f);
    h2.setColspan(1);
    tabla.addCell(h2);

    //        PdfPCell h8 = new PdfPCell(new Phrase("COMPENSA",fontCabecera));
    //        h8.setHorizontalAlignment(1);
    //        h8.setGrayFill(0.7f);
    //        h8.setColspan(1);
    //        tabla.addCell(h8);
    //        
    tabla.setHeaderRows(1);
    /**
     * Procesamiento de los datos para generar los registros de la entrada
     */

    Calendar cal = Calendar.getInstance();
    Calendar calC = Calendar.getInstance();
    for (String dni : dnis) {
        //cal.setTime(fechaInicio);
        for (int i = 0; i < listaInt.size(); i++) {
            cal.setTime(fechaInicio);
            int diaMarcacion = cal.get(Calendar.DAY_OF_MONTH) + i;
            System.out.println("Iterador: " + i + " Dni: " + dni);
            cal.set(Calendar.DAY_OF_MONTH, diaMarcacion);
            //Descartar si es sabado o domingo
            if (!ReporteUtil.isDiaLaboral(cal.getTime())) {
                continue;
            }
            //Marcaciones del dia a procesar
            List<Marcacion> marcaciones = mc.buscarXFecha(dni, cal.getTime());
            String Asistencia = "";
            String Permiso = "";
            String Vacaciones = "";
            String marcacion = "";
            String marcacion2 = "";
            String condicion = "";
            String compensacion = "";
            Marcacion primeraMarcacion = new Marcacion();
            Marcacion ultimaMarcacion = new Marcacion();
            Empleado empleado = ec.buscarPorDni(dni);

            List<EmpleadoOpcionInfo> infoEmpleado = eoc.buscarTodos(Integer.parseInt(dni));
            if (!infoEmpleado.isEmpty()) {
                if (infoEmpleado.get(0).getSFieldValue5().equals("0")
                        || infoEmpleado.get(0).getSFieldValue5().equals("")
                        || infoEmpleado.get(0).getSFieldValue5().equals(" ")) {
                    condicion = "NORMAL";
                } else if (infoEmpleado.get(0).getSFieldValue5().equals("1")) {
                    condicion = "Exonerado";
                } else if (infoEmpleado.get(0).getSFieldValue5().equals("2")) {
                    condicion = "Designado";
                } else if (infoEmpleado.get(0).getSFieldValue5().equals("3")) {
                    condicion = "Otra sede";
                }
            } else {
                condicion = "Sin dato";
            }
            System.out.println("Condicion: " + condicion);
            //Datos de horario, jornada, empleado
            List<DetalleGrupoHorario> detallesGrupos = dc.buscarXEmpleado(empleado);
            if (condicion.equals("NORMAL")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                    marcacion = primeraMarcacion.getHora().toString();
                    marcacion2 = ultimaMarcacion.getHora().toString();

                    if (!detallesGrupos.isEmpty()) {
                        DetalleGrupoHorario detalleGrupoEmpleado = detallesGrupos.get(0);
                        List<AsignacionHorario> asignaciones = ashc
                                .buscarXGrupo(detalleGrupoEmpleado.getGrupoHorario());
                        AsignacionHorario asignacionEmpleado = asignaciones.get(0);
                        Horario horarioEmpleado = asignacionEmpleado.getHorario();
                        Jornada jornadaEmpleado = horarioEmpleado.getJornada();

                        //Validacion de asistencia
                        if (primeraMarcacion.getHora().compareTo(ultimaMarcacion.getHora()) < 0) {
                            if ((primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) == 0
                                    || primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) < 0)
                                    && (ultimaMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHS()) == 0
                                            || ultimaMarcacion.getHora()
                                                    .compareTo(jornadaEmpleado.getTurnoHS()) > 0)) {
                                Asistencia = "Asistencia Normal";
                                marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                continue;
                            } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) < 0
                                    && primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) > 0) {
                                Asistencia = "Tardanza";
                                marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                continue;
                                //Marco falta en entrada y marco antes de tiempo salida
                            } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) > 0
                                    && ultimaMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHS()) < 0) {
                                Asistencia = "Falta";
                                continue;
                                //Marco tarde entrada y marco antes de tiempo salida
                            } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) < 0
                                    && ultimaMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHS()) < 0) {
                                Asistencia = "Falta";
                                continue;
                                //Marco tarde entrada y marco antes de tiempo salida??
                            } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) < 0
                                    && ultimaMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHS()) > 0) {
                                Asistencia = "Falta";
                                marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                continue;
                                //Marco falta en la entrada y marco antes de tiempo salida
                            } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) > 0
                                    && ultimaMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHS()) > 0) {
                                Asistencia = "Falta";
                                marcacion2 = jornadaEmpleado.getTurnoHS().toString();
                                continue;
                            }
                        } else {
                            Asistencia = "Falta";

                        }
                    } else {
                        Asistencia = "No tiene grupo horario";
                        if (primeraMarcacion.getHora().compareTo(ultimaMarcacion.getHora()) < 0) {
                            continue;
                        }
                    }
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = "Falta";
                }
            } else if (condicion.equals("Exonerado")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                    //marcacion = primeraMarcacion.getHora().toString();
                    //marcacion2 = ultimaMarcacion.getHora().toString();
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion;
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion;
                }
                break;
            } else if (condicion.equals("Designado")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                    //marcacion = primeraMarcacion.getHora().toString();
                    //marcacion2 = ultimaMarcacion.getHora().toString();
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion;
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion;
                }
                break;
            } else if (condicion.equals("Otra sede")) {
                if (!marcaciones.isEmpty()) {
                    primeraMarcacion = marcaciones.get(0);
                    ultimaMarcacion = marcaciones.get(marcaciones.size() - 1);
                    //marcacion = primeraMarcacion.getHora().toString();
                    //marcacion2 = ultimaMarcacion.getHora().toString();
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion;
                } else {
                    marcacion = "---";
                    marcacion2 = "---";
                    Asistencia = condicion;
                }
                break;
            } else {
                marcacion = "---";
                marcacion2 = "---";
                Asistencia = "Condicin sin especificar";
            }

            //Validacion de permiso
            //Procesar permisos con horas tbm si no encuentra permisos por fechas 
            AsignacionPermiso asignacionPermisoEmpleadoDia = aspc.buscarXDia(dni, cal.getTime());
            Calendar horaESinCero = Calendar.getInstance();
            Calendar horaFSinCero = Calendar.getInstance();
            if (primeraMarcacion.getHora() != null) {
                horaESinCero.setTime(primeraMarcacion.getHora());
                horaESinCero.set(Calendar.SECOND, 0);
            }
            if (ultimaMarcacion.getHora() != null) {
                horaFSinCero.setTime(ultimaMarcacion.getHora());
                horaFSinCero.set(Calendar.SECOND, 0);
            }

            AsignacionPermiso asigPerEntrada = aspc.buscarOnlyHora(dni, horaESinCero.getTime(), cal.getTime());
            AsignacionPermiso asigPerSalida = aspc.buscarOnlyHora(dni, horaFSinCero.getTime(), cal.getTime());
            if (asignacionPermisoEmpleadoDia != null) {
                Permiso = asignacionPermisoEmpleadoDia.getPermiso().getTipoPermiso().getNombre().toLowerCase();
                Asistencia = "Permiso";
                continue;
            } else if (asigPerEntrada != null) {
                Permiso = asigPerEntrada.getPermiso().getTipoPermiso().getNombre().toLowerCase();
                Asistencia = "Permiso";
                continue;
            } else if (asigPerSalida != null) {
                Permiso = asigPerSalida.getPermiso().getTipoPermiso().getNombre().toLowerCase();
                Asistencia = "Permiso";
                continue;
            } else {
                Permiso = "";
            }
            //Validacion de Vacaciones
            Vacacion vacacionEmpleado = vc.buscarXDia(dni, cal.getTime());
            if (vacacionEmpleado != null) {
                Vacaciones = ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaInicio()) + " al "
                        + ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaFin());
                Asistencia = "Vacaciones";
                continue;
            } else {
                Vacaciones = "";
            }
            //DNI
            PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getNroDocumento(), fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);
            //Nombre
            String celda0 = empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno() + " "
                    + empleado.getNombre();
            celdaNombre.setPhrase(new Phrase(celda0, fontCelda));
            celdaNombre.setHorizontalAlignment(0);
            tabla.addCell(celdaNombre);
            //Fecha
            String celdaA = ReporteUtil.obtenerFechaFormateada(cal.getTime(), "/");
            celdaNombre.setPhrase(new Phrase(celdaA, fontCelda));
            celdaNombre.setHorizontalAlignment(1);
            tabla.addCell(celdaNombre);

        }
    }
    return tabla;
}