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

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

Introduction

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

Prototype

public void setWidthPercentage(float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addScreenShorts(Document doc, String text)
        throws BadElementException, IOException, DocumentException {

    Paragraph heading = new Paragraph("Screenshots",
            FontFactory.getFont("arial", 10, Font.UNDERLINE | Font.BOLDITALIC));
    heading.setSpacingAfter(12f);/*from w  ww  . ja  v a2  s.c o  m*/
    doc.add(heading);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(80);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    Image image = Image.getInstance("screen_shoot1.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot2.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot3.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot4.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot5.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    image = Image.getInstance("screen_shoot6.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    //      doc.add(new Paragraph("\n"));
    doc.add(table);
}

From source file:tk.diginspect.main.SoOFSignatories.java

public void createPDF() {
    doc = new Document(PageSize.A4);
    try {/*w w  w.j a  va 2  s . c  o  m*/
        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/RFO";
        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        String strFinalname, strFilename2, strFilenames;
        String filename = sp.getString("EstablishmentName", null);
        String strfilename = filename.replaceAll("\\W+", "-");
        String inspector = sp.getString("FDRO1", null);
        String inspby = inspector.replaceAll("\\W+", "-");
        File file = new File(dir, strfilename + "-" + strFile + "-" + inspby + ".pdf");

        strFilename2 = strfilename + "-" + strFile + "-" + inspby;
        strFilenames = strFilename2 + ".pdf";
        strFinalname = path + "/" + strFilenames;
        savePreferences("fileName", strFinalname);

        FileOutputStream fOut = new FileOutputStream(file);
        PdfWriter.getInstance(doc, fOut);
        doc.open();

        FDALetterhead();

        // General Info Table
        float[] table1columnWidths = { 1f, 1f, 1f, 1f };
        PdfPTable table1 = new PdfPTable(table1columnWidths);
        table1.setWidthPercentage(110f);
        table1.setSpacingAfter(20f);
        insertCell(table1, "INSPECTION REPORT", Element.ALIGN_CENTER, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "Name of Establishment", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("EstablishmentName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Plant/Office Address", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PlantOfficeAddress", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Warehouse Address", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("WarehouseAddress", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Owner", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Owner", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Telephone Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("TelNumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Fax No", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("FaxNumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Classification", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);

        String Classification = sp.getString("MainClass", null) + ", " + sp.getString("SecClass", null) + ", "
                + sp.getString("ThirdClass", null) + ", " + sp.getString("FourthClass", "");

        insertCell(table1, Classification, Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Product/s:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Products", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Manner of Notification", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Notification", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Purpose of Inspection", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("Inspection", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Registered Pharmacist / Authorized Representative / Person", Element.ALIGN_LEFT, 4,
                "#8EBAFF", 1, 0);
        insertCell(table1, "Name", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PharmacistName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Reg. No. (PRC-ID)", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcID", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Date Issued", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcDateIssued", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Validity", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PrcValidity", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Position", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("PharmacistPosition", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Person/s Interviewed", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("InterviewedName", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Position", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("InterviewedPosition", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "License to Operate", Element.ALIGN_LEFT, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTONumber", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Renewal", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTORenewalDate", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Validity", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("LTOValidity", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Payment of Appropriate Fee", Element.ALIGN_LEFT, 4, "#8EBAFF", 1, 0);
        insertCell(table1, "OR Number", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("ORNum", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Amount", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell(table1, "Php " + sp.getString("ORAmount", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "Date of Payment", Element.ALIGN_LEFT, 0, "#8EBAFF", 1, 0);
        insertCell(table1, sp.getString("ORDate", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 0);
        insertCell(table1, "RSN", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 1);
        insertCell(table1, sp.getString("RSN", "N/A"), Element.ALIGN_LEFT, 3, "#FFFFFF", 1, 1);
        doc.add(table1);

        footer();

        // 2nd Page
        doc.newPage();
        FDALetterhead();

        PdfPTable table2 = new PdfPTable(1);
        table2.setWidthPercentage(110f);
        table2.setSpacingAfter(20f);
        insertCell(table2, "Observation Findings:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 0);
        insertCell1(table2, sp.getString("ObservationFindings", ""), 1, 1, 600f);
        doc.add(table2);
        footer();

        // 3rd Page
        doc.newPage();
        FDALetterhead();

        PdfPTable table3 = new PdfPTable(1);
        table3.setWidthPercentage(110f);
        table3.setSpacingAfter(20f);

        insertCell(table3, "Directives:", Element.ALIGN_LEFT, 1, "#8EBAFF", 1, 1);

        nested(table3, 0.1f, 2f, R.string.directives1, sp.getBoolean("Directives1", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives2, sp.getBoolean("Directives2", false), Element.ALIGN_LEFT);
        nested(table3, 0.2f, 2f, R.string.directives3, sp.getBoolean("Directives3", false),
                Element.ALIGN_RIGHT);
        nested(table3, 0.2f, 2f, R.string.directives4, sp.getBoolean("Directives4", false),
                Element.ALIGN_RIGHT);
        nested(table3, 0.1f, 2f, R.string.directives5, sp.getBoolean("Directives5", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives6, sp.getBoolean("Directives6", false), Element.ALIGN_LEFT);
        nested(table3, 0.1f, 2f, R.string.directives7, sp.getBoolean("Directives7", false), Element.ALIGN_LEFT);

        String Directives8 = getResources().getString(R.string.directives8);
        PdfPCell cellDirectives8 = new PdfPCell(new Paragraph(Font.TIMES_ROMAN, Directives8));
        cellDirectives8.setPaddingLeft(50);
        cellDirectives8.setPaddingTop(5);
        cellDirectives8.setPaddingBottom(5);
        cellDirectives8.setPaddingRight(5);
        cellDirectives8.setBorderWidthTop(0);
        cellDirectives8.setBorderWidthBottom(0);
        table3.addCell(cellDirectives8);

        String Directives = sp.getString("Directives8", null);
        boolean Directives9 = false, Directives10 = false;
        if (Directives.equals(R.string.directives9)) {
            Directives9 = true;
            Directives10 = false;
        } else if (Directives.equals(R.string.directives10)) {
            Directives9 = false;
            Directives10 = true;
        } else {
            Directives9 = false;
            Directives10 = false;
        }

        nested(table3, 0.3f, 2f, R.string.directives9, Directives9, Element.ALIGN_RIGHT);
        nested(table3, 0.3f, 2f, R.string.directives10, Directives10, Element.ALIGN_RIGHT);

        insertCell(table3, "Inspected By:", Element.ALIGN_CENTER, 1, "#8EBAFF", 1, 0);

        PdfPTable signature1 = new PdfPTable(2);

        sig(signature1, "FDRO1");
        sig(signature1, "FDRO2");

        insertCell(signature1, sp.getString("FDRO1", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, sp.getString("FDRO2", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, "Food-Drug Regulation Officer", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Food-Drug Regulation Officer", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Date: " + dateStarted, Element.ALIGN_LEFT, 1, "#FFFFFF", 1, 0);
        insertCell(signature1, "Time: " + timeS, Element.ALIGN_LEFT, 1, "#FFFFFF", 1, 0);

        sig(signature1, "EstRep1");
        sig(signature1, "EstRep2");
        insertCell(signature1, sp.getString("EstRep1", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, sp.getString("EstRep2", null), Element.ALIGN_CENTER, 1, "#FFFFFF", 0, 0);
        insertCell(signature1, "Establishments Representative", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);
        insertCell(signature1, "Establishments Representative", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);

        PdfPCell nesthousing1 = new PdfPCell(signature1);
        table3.addCell(nesthousing1);

        doc.add(table3);
        footer();

        // 4th Page
        doc.newPage();
        FDALetterhead();
        PdfPTable table4 = new PdfPTable(1);
        table4.setWidthPercentage(110f);
        table4.setSpacingAfter(20f);

        insertCell(table4, "(FDA USE ONLY)", Element.ALIGN_CENTER, 1, "#8EBAFF", 1, 1);
        insertCell(table4, "Compliance Made by the Company", Element.ALIGN_LEFT, 1, "#FFFFFF", 0, 0);
        nested(table4, 0.1f, 2f, R.string.CAPA, false, Element.ALIGN_LEFT);
        nested(table4, 0.2f, 2f, R.string.Accepted, false, Element.ALIGN_RIGHT);
        nested(table4, 0.2f, 2f, R.string.NotAccepted, false, Element.ALIGN_RIGHT);
        insertCell(table4, "Recommendation (to Licensing) :", Element.ALIGN_LEFT, 1, "#FFFFFF", 0, 0);
        insertCell1(table4, "", 0, 0, 100f);

        PdfPTable signature2 = new PdfPTable(2);

        insertCell1(signature2, "", 0, 0, 50f);
        insertCell1(signature2, "", 0, 0, 50f);

        insertCell(signature2, "Print Name & Signature of FDRO/s", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);
        insertCell(signature2, "Date", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 0);

        insertCell(signature2, "Reviewed by:", Element.ALIGN_LEFT, 2, "#8EBAFF", 1, 1);

        insertCell1(signature2, "", 0, 0, 50f);
        insertCell1(signature2, "", 0, 0, 50f);

        insertCell(signature2, "Print Name & Signature of Team Leader/Supervisor", Element.ALIGN_CENTER, 1,
                "#FFFFFF", 1, 1);
        insertCell(signature2, "Date", Element.ALIGN_CENTER, 1, "#FFFFFF", 1, 1);

        PdfPCell nesthousing2 = new PdfPCell(signature2);
        table4.addCell(nesthousing2);

        doc.add(table4);
        footer();

    } catch (DocumentException de) {
        Log.e("PDFCreator", "DocumentException:" + de);
    } catch (FileNotFoundException e) {
        Log.e("PDFCreator", "ioException:" + e);
    } finally {
        doc.close();
    }
}

From source file:uk.ac.bbsrc.tgac.miso.core.data.decorator.itext.ITextProjectDecorator.java

License:Open Source License

public void buildReport() throws DocumentException {
    report = new Document();
    PdfWriter writer = PdfWriter.getInstance(report, stream);
    report.open();//from  w w  w. j  a v  a 2 s.c  om
    report.add(new Paragraph("Project Summary"));
    PdfContentByte cb = writer.getDirectContent();
    cb.setLineWidth(2.0f); // Make a bit thicker than 1.0 default
    cb.setGrayStroke(0.9f); // 1 = black, 0 = white
    float x = 72f;
    float y = 200f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    report.add(new Paragraph(project.getAlias()));
    report.add(new Paragraph(project.getDescription()));

    PdfPTable t = new PdfPTable(1);
    t.setHorizontalAlignment(Element.ALIGN_CENTER);
    t.setWidthPercentage(100f); // this would be the 100 from setHorizontalLine
    t.setSpacingAfter(5f);
    t.setSpacingBefore(0f);
    t.getDefaultCell().setUseVariableBorders(true);
    t.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    t.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    t.getDefaultCell().setBorder(Rectangle.BOTTOM); // This generates the line
    t.getDefaultCell().setBorderWidth(1f); // this would be the 1 from setHorizontalLine
    t.getDefaultCell().setPadding(0);
    t.addCell("");
    report.add(t);

    x = 72f;
    y = 100f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    if (project.getSamples().size() > 0) {
        report.add(new Paragraph("Samples"));
        for (Sample sample : project.getSamples()) {
            Paragraph sPara = new Paragraph(sample.getAlias(), FontFactory.getFont("Helvetica", 12, Font.BOLD));
            sPara.setIndentationLeft(20);
            report.add(sPara);
            report.add(new Paragraph(sample.getDescription()));
        }
    }

    report.close();
}

From source file:util.PDFconverter.java

public static void createPDF(String[] header, String[][] data, String path, String tittle,
        float[] columnWidths) {
    try {//ww w . java 2s .c  om
        Document doc = new Document();

        PdfWriter.getInstance(doc, new FileOutputStream(path));

        doc.open();
        doc.setPageSize(PageSize.A4);
        doc.setMargins(10, 10, 10, 10);
        Font litle = new Font(Font.COURIER, 7, Font.NORMAL);
        Font norm = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
        Font normBold = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
        Font TitleFont = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);

        doc.add(Chunk.NEWLINE);
        Paragraph judul = new Paragraph(tittle, TitleFont);
        judul.setAlignment(Element.ALIGN_CENTER);
        doc.add(judul);

        //          Paragraph tgl = new Paragraph("tanggal " + tanggal + "\n", TitleFont);            
        //          tgl.setAlignment(Element.ALIGN_CENTER);
        //          doc.add(tgl);
        doc.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(header.length);
        table.setWidthPercentage(100f);

        for (String head : header) {
            table.addCell(new PdfPCell(new Phrase(head, normBold)));
        }

        for (String[] obj : data) {
            for (int i = 0; i < header.length; i++) {
                table.addCell(new PdfPCell(new Phrase(obj[i], norm)));
            }

        }

        //float[] columnWidths = new float[] {10f, 20f, 30f, 10f};
        table.setWidths(columnWidths);

        doc.add(table);

        //            Paragraph stamp = new Paragraph(new Chunk("this report has generated with QCMS by " + System.getProperty("user.name") + " on " + new Date(), litle));
        //            stamp.setAlignment(Element.ALIGN_BOTTOM);
        //            stamp.setAlignment(Element.ALIGN_CENTER);
        //            doc.add(stamp);
        //
        //            Paragraph tanda = new Paragraph(new Chunk("Mengetahui,", norm));
        //            tanda.setSpacingBefore(100);
        //            tanda.setAlignment(Element.ALIGN_RIGHT);
        //            tanda.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(tanda);
        //
        //            Paragraph nama = new Paragraph(new Chunk("MANAGER Dept.RnQ", norm));
        //            nama.setSpacingBefore(30);
        //            nama.setAlignment(Element.ALIGN_RIGHT);
        //            nama.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(nama);
        doc.close();
    } catch (DocumentException | FileNotFoundException ex) {
        Logger.getLogger(PDFconverter.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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

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

    /**
     * Procesamiento para elaborar tabla con datos
     */
    int nroColumnas = 6;
    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] = 2;
    widthColumna[3] = 2;
    widthColumna[4] = 2;
    widthColumna[5] = 2;

    tabla.setWidths(widthColumna);

    //Definimos celdas iniciales
    Font fontCabecera = new Font(Font.HELVETICA, 8, Font.BOLD);
    Font fontCelda = new Font(Font.HELVETICA, 7);

    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("MARCACION ENTRADA", fontCabecera));
    h2.setHorizontalAlignment(1);
    h2.setGrayFill(0.7f);
    h2.setColspan(1);
    tabla.addCell(h2);

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

    //Agregado de columna de descuento sin goce
    PdfPCell h4 = new PdfPCell(new Phrase("OBSERVACION", fontCabecera));
    h4.setHorizontalAlignment(1);
    h4.setGrayFill(0.7f);
    h4.setColspan(1);
    tabla.addCell(h4);

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

    /**
     * Procesamiento de los datos para generar los registros de la entrada
     */
    for (String dni : dnis) {
        List<Marcacion> marcaciones = mc.buscarXFecha(dni, fechaInicio);
        String Asistencia = "";
        String Permiso = "";
        String Vacaciones = "";
        String marcacion = "";
        String condicion = "";
        System.out.println("DNI: " + dni);
        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()) {
                Marcacion primeraMarcacion = marcaciones.get(0);
                marcacion = primeraMarcacion.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(jornadaEmpleado.getTurnoHE()) == 0
                            || primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) < 0) {
                        Asistencia = "Asistencia Normal";
                    } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) < 0
                            && primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) > 0) {
                        Asistencia = "Tardanza";
                    } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) > 0) {
                        Asistencia = "Falta";
                    }
                } else {
                    Asistencia = "No tiene grupo horario";
                }
            } else {
                marcacion = "Sin marcacion";
                Asistencia = "Falta";
            }
        } else if (condicion.equals("EXONERADO")) {
            marcacion = "Sin marcacion";
            Asistencia = condicion;
        } else if (condicion.equals("DESIGNADO")) {
            marcacion = "Sin marcacion";
            Asistencia = condicion;
        } else if (condicion.equals("OTRA SEDE")) {
            marcacion = "Sin marcacion";
            Asistencia = condicion;
        } else {
            marcacion = "Sin marcacion";
            Asistencia = "Condicin sin especificar";
        }

        //Validacion de permiso
        //Procesar permisos con horas tbm si no encuentra permisos por fechas 
        AsignacionPermiso asignacionPermisoEmpleado = aspc.buscarXDia(dni, fechaInicio);
        if (asignacionPermisoEmpleado != null) {
            Permiso = asignacionPermisoEmpleado.getPermiso().getTipoPermiso().getNombre();
            Asistencia = "Permiso";
        } else {
            Permiso = "Sin permiso";
        }
        //Validacion de Vacaciones
        Vacacion vacacionEmpleado = vc.buscarXDia(dni, fechaInicio);
        if (vacacionEmpleado != null) {
            Vacaciones = ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaInicio()) + " al "
                    + ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaFin());
            Asistencia = "Vacaciones";
        } else {
            Vacaciones = "No tiene 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);
        //Hora Marcacion
        String celda = marcacion;
        celdaNombre.setPhrase(new Phrase(celda, 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);
    }
    return tabla;
}

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 {
    /**/*w w w.j  a v a 2  s  .  c  o m*/
     * 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   www . j  a  v a 2 s  .co  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;
}

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

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

    // Dias contados desde un inicio y fin fecha
    ArrayList<Integer> listaDias = new ArrayList<>();

    while (fechaInicioC.getTime().compareTo(fechaFinC.getTime()) <= 0) {
        if (!ReporteUtil.isDiaLaboral(fechaInicioC.getTime())) {
            fechaInicioC.add(Calendar.DATE, 1);
            continue;
        }
        listaDias.add(fechaInicioC.get(Calendar.DATE));
        fechaInicioC.add(Calendar.DATE, 1);
    }
    System.out.println("Numero de dias a agregar: " + listaDias.size());
    for (Integer listaDia : listaDias) {
        System.out.println("Dia numero: " + listaDia);
    }
    /**
     * Procesamiento para elaborar tabla con datos
     */
    //agrege una columna mas (Descuento sin goce)
    int nroColumnas = listaDias.size() + 5;
    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];
    for (int i = 0; i < nroColumnas; i++) {
        if (i == 0) {
            widthColumna[i] = 6;
        } else if (i == (nroColumnas - 1) || i == (nroColumnas - 2) || i == (nroColumnas - 3)
                || i == (nroColumnas - 4)) {
            widthColumna[i] = 2;
        } else {
            widthColumna[i] = 1;
        }
    }
    tabla.setWidths(widthColumna);
    //Definimos celdas iniciales
    Font fontCabecera = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Font fontCelda = new Font(Font.TIMES_ROMAN, 9);
    PdfPCell h1 = new PdfPCell(new Phrase("Nombre del empleado", fontCabecera));
    h1.setHorizontalAlignment(3);
    h1.setGrayFill(0.7f);
    h1.setRowspan(2);
    h1.setColspan(1);
    tabla.addCell(h1);

    PdfPCell h2 = new PdfPCell(new Phrase("Das Hbiles", fontCabecera));
    h2.setHorizontalAlignment(1);
    h2.setGrayFill(0.7f);
    h2.setColspan(nroColumnas - 5);
    tabla.addCell(h2);

    PdfPCell h3 = new PdfPCell(new Phrase("Minutos Tardanza", fontCabecera));
    h3.setHorizontalAlignment(3);
    h3.setGrayFill(0.7f);
    h3.setColspan(1);
    h3.setRowspan(2);
    tabla.addCell(h3);

    //Agregado de columna de descuento sin goce
    PdfPCell h4 = new PdfPCell(new Phrase("Faltas", fontCabecera));
    h4.setHorizontalAlignment(3);
    h4.setGrayFill(0.7f);
    h4.setColspan(1);
    h4.setRowspan(2);
    tabla.addCell(h4);

    PdfPCell h5 = new PdfPCell(new Phrase("Licencias S.G", fontCabecera));
    h5.setHorizontalAlignment(3);
    h5.setGrayFill(0.7f);
    h5.setColspan(1);
    h5.setRowspan(2);
    tabla.addCell(h5);

    PdfPCell h6 = new PdfPCell(new Phrase("Descuento Total", fontCabecera));
    h6.setHorizontalAlignment(3);
    h6.setGrayFill(0.7f);
    h6.setColspan(1);
    h6.setRowspan(2);
    tabla.addCell(h6);

    PdfPCell diaColumna = new PdfPCell();
    for (int i = 0; i < (nroColumnas - 5); i++) {
        String celda = (listaDias.get(i).toString());
        diaColumna.setPhrase(new Phrase(celda, fontCabecera));
        diaColumna.setHorizontalAlignment(1);
        tabla.addCell(diaColumna);
    }

    Calendar cal = Calendar.getInstance();
    List<ReporteAsistenciaBean> listaAsistencia = rac.analisisAsistencia(fechaInicio, fechaFin, dnis, false,
            false);
    List<Integer> conteoDias = new ArrayList<>();
    int minutosTarde = 0;
    int minutosDescuentoPermisos = 0;
    int diasDescuento = 0;
    boolean banderaNombre = true;

    PdfPCell celdaNombre = new PdfPCell();
    for (String dni : dnis) {
        List<ReporteAsistenciaBean> registrosDni = new ArrayList<>();
        for (ReporteAsistenciaBean registro : listaAsistencia) {
            if (dni.equals(registro.getDni())) {
                registrosDni.add(registro);
            }
        }

        for (ReporteAsistenciaBean registro : registrosDni) {
            if (banderaNombre) {
                if (dni.equals(registro.getDni())) {
                    celdaNombre.setPhrase(new Phrase(registro.getNombre(), fontCelda));
                    celdaNombre.setHorizontalAlignment(0);
                    tabla.addCell(celdaNombre);
                    banderaNombre = false;
                }
            }
            for (Integer dia : listaDias) {
                cal.setTime(registro.getFechaRegistro());
                if (cal.get(Calendar.DAY_OF_MONTH) == dia) {
                    if (!registro.getEstado().equals("FALTA")) {
                        if (registro.getMinTardanza() != null) {
                            int numero = registro.getMinTardanza();
                            String celda = "" + numero;
                            celdaNombre.setPhrase(new Phrase(celda, fontCelda));
                            celdaNombre.setHorizontalAlignment(1);
                            tabla.addCell(celdaNombre);
                            minutosTarde += registro.getMinTardanza();
                        }
                    } else if (registro.getEstado().equals("FALTA")) {
                        if (registro.getMinTardanza() != null) {
                            int numero = registro.getMinTardanza();
                            String celda = "" + numero;
                            celdaNombre.setPhrase(new Phrase(celda, fontCelda));
                            celdaNombre.setHorizontalAlignment(1);
                            tabla.addCell(celdaNombre);
                            diasDescuento += 1;
                        }
                    }

                    conteoDias.add(dia);
                    break;
                } else {
                    if (conteoDias.contains(dia)) {

                    } else {
                        String celda = "n.r";
                        celdaNombre.setPhrase(new Phrase(celda, fontCelda));
                        celdaNombre.setHorizontalAlignment(1);
                        tabla.addCell(celdaNombre);
                        conteoDias.add(dia);
                    }
                }
            }
        }

        //Minutos tarde
        String hora1 = "";
        if (minutosTarde < 60) {
            hora1 = minutosTarde + " min";
        } else if (minutosTarde >= 60 && minutosTarde < 480) {
            int resto = minutosTarde % 60;
            int totalH = (minutosTarde - resto) / 60;
            hora1 = totalH + " h " + resto + " min";
        } else if (minutosTarde >= 480) {
            int restoHoras = minutosTarde % 480;
            int totalD = (minutosTarde - restoHoras) / 480;
            int restoMinutos = restoHoras % 60;
            int totalH = (restoHoras - restoMinutos) / 60;
            hora1 = totalD + " d " + totalH + " h " + restoMinutos + " m";
        }
        celdaNombre.setPhrase(new Phrase(hora1, fontCelda));
        celdaNombre.setHorizontalAlignment(1);
        tabla.addCell(celdaNombre);
        //Dias con falta
        String hora2 = "";
        int minutosT = diasDescuento * 480;
        if (minutosT < 60) {
            hora2 = minutosT + " min";
        } else if (minutosT >= 60 && minutosT < 480) {
            int resto = minutosT % 60;
            int totalH = (minutosT - resto) / 60;
            hora2 = totalH + " h " + resto + " min";
        } else if (minutosT >= 480) {
            int restoHoras = minutosT % 480;
            int totalD = (minutosT - restoHoras) / 480;
            int restoMinutos = restoHoras % 60;
            int totalH = (restoHoras - restoMinutos) / 60;
            hora2 = totalD + " d " + totalH + " h " + restoMinutos + " m";
        }
        celdaNombre.setPhrase(new Phrase(hora2, fontCelda));
        celdaNombre.setHorizontalAlignment(1);
        tabla.addCell(celdaNombre);
        //Licencia sin goce
        minutosDescuentoPermisos = rac.minutosSinGocePorPermisos(dni, fechaInicio, fechaFin);

        String hora = "";
        if (minutosDescuentoPermisos < 60) {
            hora = minutosDescuentoPermisos + " min";
        } else if (minutosDescuentoPermisos >= 60 && minutosDescuentoPermisos < 480) {
            int resto = minutosDescuentoPermisos % 60;
            int totalH = (minutosDescuentoPermisos - resto) / 60;
            hora = totalH + " h " + resto + " min";
        } else if (minutosDescuentoPermisos >= 480) {
            int restoHoras = minutosDescuentoPermisos % 480;
            int totalD = (minutosDescuentoPermisos - restoHoras) / 480;
            int restoMinutos = restoHoras % 60;
            int totalH = (restoHoras - restoMinutos) / 60;
            hora = totalD + " d " + totalH + " h " + restoMinutos + " m";
        }
        celdaNombre.setPhrase(new Phrase(hora, fontCelda));
        celdaNombre.setHorizontalAlignment(1);
        tabla.addCell(celdaNombre);
        //Total
        String horaT = "";
        int tiempoTotal = minutosTarde + minutosT + minutosDescuentoPermisos;
        if (tiempoTotal < 60) {
            horaT = tiempoTotal + " min";
        } else if (tiempoTotal >= 60 && tiempoTotal < 480) {
            int resto = tiempoTotal % 60;
            int totalH = (tiempoTotal - resto) / 60;
            horaT = totalH + " h " + resto + " min";
        } else if (tiempoTotal >= 480) {
            int restoHoras = tiempoTotal % 480;
            int totalD = (tiempoTotal - restoHoras) / 480;
            int restoMinutos = restoHoras % 60;
            int totalH = (restoHoras - restoMinutos) / 60;
            horaT = totalD + " d " + totalH + " h " + restoMinutos + " m";
        }
        celdaNombre.setPhrase(new Phrase(horaT, fontCelda));
        celdaNombre.setHorizontalAlignment(1);
        tabla.addCell(celdaNombre);

        registrosDni.clear();
        banderaNombre = true;
        minutosTarde = 0;
        minutosDescuentoPermisos = 0;
        minutosT = 0;
        diasDescuento = 0;
    }
    return tabla;
}

From source file:wagwaan.reports.ActiveSuppliersPdf.java

public void generatePdf() {

    try {// w w  w.j  ava 2s .c  o m

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));
                ReportUtil.addCenteredTitlePage(docPdf, connectDB);

                String date = null;
                try {
                    java.sql.Statement st3 = connectDB.createStatement();
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");

                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Active Suppliers- Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(10);

                    int headerwidths[] = { 4, 6, 20, 11, 11, 10, 10, 10, 10, 9 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(5);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Active Suppliers");
                    table.addCell(phrase);
                    //                        table.getDefaultCell().setColspan(4);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);

                    phrase = new Phrase("#", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Suplier ID", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Supplier Names", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Address", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Phone No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Email", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Bank Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Account No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Branch Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Reg. Date", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        /*Statement s=connectDB.createStatement();
                        ResultSet r=s.executeQuery("SELECT  sum(ord.price*quantity_received) total  FROM st_receiving_issuing REV, stock_orders ord, stock_items itm "
                            + "where receiving_no='"+issue+"' and itm.item_code=ord.item_code and itm.item_code=rev.item_code");*/

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "select supplier_id, supplier_names, address, phone_no, email_address, bank_name, account_no, "
                                        + "branch_name, date_registered from stock_suppliers where active=true order by 1, 2");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(9), "-"), pFontHeader1);
                            table.addCell(phrase);
                            count++;
                        }

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.BlackListedSuppPdf.java

public void generatePdf() {

    try {/* w w w  . j  a v  a  2 s.  c om*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                String date = null;
                try {
                    java.sql.Statement st3 = connectDB.createStatement();
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("BlackListed Suppliers- Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(10);

                    int headerwidths[] = { 4, 6, 20, 11, 11, 10, 10, 10, 10, 9 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(5);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("BlackListed Suppliers");
                    table.addCell(phrase);
                    //                        table.getDefaultCell().setColspan(4);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);

                    phrase = new Phrase("#", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Suplier ID", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Supplier Names", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Address", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Phone No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Email", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Bank Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Account No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Branch Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Reg. Date", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        /*Statement s=connectDB.createStatement();
                        ResultSet r=s.executeQuery("SELECT  sum(ord.price*quantity_received) total  FROM st_receiving_issuing REV, stock_orders ord, stock_items itm "
                            + "where receiving_no='"+issue+"' and itm.item_code=ord.item_code and itm.item_code=rev.item_code");*/

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "select supplier_id, supplier_names, address, phone_no, email_address, bank_name, account_no, "
                                        + "branch_name, date_registered from stock_suppliers where active=false order by 1, 2");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(9), "-"), pFontHeader1);
                            table.addCell(phrase);
                            count++;
                        }

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}