List of usage examples for com.lowagie.text.pdf PdfPCell setRowspan
public void setRowspan(int rowspan)
From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Builds the table for the crosstab/*from w ww. ja va 2 s . c om*/ * @param json the JSON representation of the crosstab * @param pdfDocument the pdf document that should contains the crosstab * @param numberFormat the formatter for the numbers * @throws JSONException * @throws BadElementException * @throws DocumentException */ public void export(JSONObject json, Document pdfDocument, DecimalFormat numberFormat) throws SerializationException, JSONException, BadElementException, DocumentException { logger.debug("IN: exporting the crosstab"); //prepare the crosstab for the export CrosstabExporterUtility.calculateDescendants(json); JSONObject columnsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_COLUMNS_HEADERS); JSONArray columnsRootChilds = columnsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); JSONObject rowsRoot = (JSONObject) json.get(CrossTab.CROSSTAB_JSON_ROWS_HEADERS); JSONArray rowsRootChilds = rowsRoot.getJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); JSONArray rowHeadersDescription = json.getJSONArray(CrossTab.CROSSTAB_JSON_ROWS_HEADER_TITLE); JSONArray data = (JSONArray) json.get(CrossTab.CROSSTAB_JSON_DATA); measureMetadata = new MeasureFormatter(json, numberFormat, "##,##0.00"); this.numberFormat = numberFormat; //build the matrix for the content dataMatrix = new Vector<List<PdfPCell>>(); buildDataMatrix(data); //number of headers lavels int rowsDepth = CrosstabExporterUtility.getDepth(rowsRoot); int columnsDepth = CrosstabExporterUtility.getDepth(columnsRoot); //build the table PdfPTable table = new PdfPTable(rowsDepth + dataMatrix.get(0).size()); //build the empty cell on the top left PdfPCell topLeftCell = new PdfPCell(new Phrase("")); topLeftCell.setRowspan(columnsDepth - 1);//-1 because of the title of the rows header topLeftCell.setColspan(rowsDepth); topLeftCell.setBorderColor(Color.WHITE); table.addCell(topLeftCell); List<PdfPCell> cells = new ArrayList<PdfPCell>(); //builds the headers int dataColumnNumber = ((JSONArray) data.get(0)).length(); cells.addAll(buildColumnsHeader(columnsRootChilds, rowHeadersDescription, dataColumnNumber)); cells.addAll(buildRowsHeaders(rowsRootChilds)); logger.debug("Addign the content"); //adds the headers for (int i = 0; i < cells.size(); i++) { table.addCell(cells.get(i)); } table.setWidthPercentage(100); pdfDocument.add(table); logger.debug("IN: exported the crosstab"); }
From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java
License:Mozilla Public License
/** * Builds the row headers. This method performs a depth first visit * of the row headers tree/*from w w w. j a va 2 s .c o m*/ * @param siblings: a level (L) of headers * @return the cells from level L to the leafs * @throws JSONException * @throws BadElementException */ private List<PdfPCell> buildRowsHeaders(JSONArray siblings) throws JSONException, BadElementException { JSONArray childs; List<PdfPCell> rowNodes = new ArrayList<PdfPCell>(); //For every node of the level.. for (int i = 0; i < siblings.length(); i++) { JSONObject aNode = (JSONObject) siblings.get(i); String text = (String) aNode.opt(Node.CROSSTAB_NODE_JSON_DESCRIPTION); if (text == null) { // in case of calculated fields text = (String) aNode.get(CrossTab.CROSSTAB_NODE_JSON_KEY); } int descendants = aNode.getInt(CrosstabExporterUtility.CROSSTAB_JSON_DESCENDANTS_NUMBER); PdfPCell cell = new PdfPCell(new Phrase(text, cellFont)); cell.setBackgroundColor(headersBackgroundColor); cell.setBorderColor(cellsBorderColor); if (descendants > 1) { cell.setRowspan(descendants); } //1) add the node name rowNodes.add(cell); //2) add the child node names childs = aNode.optJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS); if (childs != null && childs.length() > 0) { rowNodes.addAll(buildRowsHeaders(childs)); } else { rowNodes.addAll(dataMatrix.remove(0)); } } return rowNodes; }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col) throws BadElementException, IOException, SaveReportException { CellStyle style = model.getStyles(srcCell.getStyleId()); java.awt.Rectangle rect = model.getCellRect(row, col, true, true); float h = Math.round((float) Units.PT.setYPixels((int) rect.getHeight())); float w = Math.round((float) Units.PT.setXPixels((int) rect.getWidth())); PdfPCell pdfCell = null; if (srcCell.getPicture() != null) { java.awt.Image awtImage = srcCell.getPicture().getImage(); com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } else {//from w w w. jav a2s . co m String text = null; if (srcCell.getValue() instanceof CellValue<?>) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this, ReportBook.PDF)) { java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col); if (awtImage != null) { com.lowagie.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } } else { text = strWriter.getBuffer().toString(); } } else { if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) { pdfCell = new PdfPCell(); writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell); } else { text = model.getCellText(srcCell); } } if (pdfCell == null) { pdfCell = new PdfPCell(); } if (text != null && text.length() > 0) { com.lowagie.text.Font font; if (fonts.containsKey(style.getId())) { font = fonts.get(style.getId()); } else { font = getFontMapper().styleToPdf(style); fonts.put(style.getId(), font); } Paragraph p; if (font != null) { p = new Paragraph(text, font); } else { p = new Paragraph(text); } pdfCell.setPhrase(p); pdfCell.setPadding(1); pdfCell.setLeading(0f, 1.1f); } else { pdfCell.setPadding(0); } } pdfCell.setFixedHeight(h); pdfCell.setBackgroundColor(style.getBackground()); pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment())); pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment())); if (style.getAngle() != 0) { pdfCell.setRotation(roundAngle(style.getAngle())); } assignBorders(style, pdfCell); pdfCell.setNoWrap(!style.isWrapLine()); if (srcCell.getColSpan() > 0) { pdfCell.setColspan(srcCell.getColSpan() + 1); } if (srcCell.getRowSpan() > 0) { pdfCell.setRowspan(srcCell.getRowSpan() + 1); } return pdfCell; }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addBudgetByMogOne(Paragraph paragraph, PdfPTable table, StringBuffer budgetLabel, IPElement mog, int startYear, int endYear, BudgetType budgetType) { paragraph = new Paragraph(); budgetLabel = new StringBuffer(); paragraph.setFont(TABLE_BODY_FONT);//from ww w . j a va 2 s .c o m budgetLabel.append(mog.getProgram().getAcronym()); budgetLabel.append(" - MOG # "); budgetLabel.append(this.getMOGIndex(mog)); budgetLabel.append(": "); budgetLabel.append(mog.getDescription()); budgetLabel.append(" - " + budgetType.name().replace("_", "/")); paragraph.add(budgetLabel.toString()); this.addCustomTableCell(table, paragraph, Element.ALIGN_JUSTIFIED, BODY_TEXT_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); PdfPCell cell; // year paragraph = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setRowspan(2); this.addTableHeaderCell(table, cell); // % de amount paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.percentaje", new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setColspan(2); this.addTableHeaderCell(table, cell); // gender paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.gender", new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setColspan(2); this.addTableHeaderCell(table, cell); // amount (%) paragraph = new Paragraph("(%)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // amount (USD) paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // gender (%) paragraph = new Paragraph("(%)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // gender (USD) paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); double[] totalsByYear = { 0, 0 }; for (int year = startYear; year <= endYear; year++) { paragraph = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); this.addBudgetMogByYear(year, paragraph, table, mog, budgetType, totalsByYear); } // Totals paragraph = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); // total amount $ paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[0]), TABLE_BODY_BOLD_FONT); this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2); // total gender $ paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[1]), TABLE_BODY_BOLD_FONT); this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2); }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addBudgetPartner(ProjectPartner projectPartner, Paragraph paragraph, PdfPTable table, BudgetType budgetType, int startYear, int endYear) { PdfPCell cell; paragraph = new Paragraph( projectPartner.getInstitution().getComposedName() + " " + budgetType.name().replace("_", "/"), BODY_TEXT_BOLD_FONT);//from w w w .ja v a 2 s . co m this.addCustomTableCell(table, paragraph, Element.ALIGN_CENTER, BODY_TEXT_BOLD_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); // year paragraph = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setRowspan(2); this.addTableHeaderCell(table, cell); // amount paragraph = new Paragraph(this.getText("summaries.project.budget.overall.amount", new String[] { "" }) + budgetType.name().toString().replace("_", "/") + " (USD)", TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setRowspan(2); this.addTableHeaderCell(table, cell); // gender paragraph = new Paragraph(this.getText("summaries.project.budget.overall.gender", new String[] { "" }) + budgetType.name().toString().replace("_", "/"), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setColspan(2); this.addTableHeaderCell(table, cell); // gender (%) paragraph = new Paragraph("(%)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // gender (USD) paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); for (int year = startYear; year <= endYear; year++) { paragraph = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); this.addRowBudgetByPartners(paragraph, projectPartner.getInstitution(), year, table, budgetType); } // ************** Totals paragraph = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); // amount double value = this.budgetManager.calculateTotalCCAFSBudgetByInstitutionAndType(project.getId(), projectPartner.getInstitution().getId(), budgetType.getValue()); paragraph = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1); // gender value = this.budgetManager.calculateTotalGenderBudgetByInstitutionAndType(project.getId(), projectPartner.getInstitution().getId(), budgetType.getValue()); paragraph = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2); }
From source file:pruebareportes.rptEmpleadosSinMarcar.java
public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException { /**//from w w w. j av a 2 s .c om * 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); int diaMesInicio, diaMesFin; diaMesInicio = fechaInicioC.get(Calendar.DAY_OF_MONTH); diaMesFin = fechaFinC.get(Calendar.DAY_OF_MONTH); //Definir numero de columnas de dias // ArrayList<Integer> listaInt = new ArrayList<Integer>(); // Calendar fechaRegistro = Calendar.getInstance(); // for(RegistroAsistencia registro:registros){ // fechaRegistro.setTime(registro.getFecha()); // Integer diaRegistro = fechaRegistro.get(Calendar.DAY_OF_MONTH); // if(listaInt.contains(diaRegistro)!=true){ // if(diaRegistro>=diaMesInicio && diaRegistro<=diaMesFin){ // listaInt.add(diaRegistro); // } // } // } //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 = 1; PdfPTable tabla = new PdfPTable(nroColumnas); tabla.setWidthPercentage(100); //Asignamos los tamaos a las columnas // int[] widthColumna = new int[nroColumnas]; // for (int i = 0; i < nroColumnas; i++) { // if(i==0){ // widthColumna[i]=6; // }else if(i==(nroColumnas-1)){ // 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(1); 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-2); // tabla.addCell(h2); // // PdfPCell h3 = new PdfPCell(new Phrase("Total (minutos)",fontCabecera)); // h3.setHorizontalAlignment(3); // h3.setGrayFill(0.7f); // h3.setColspan(1); // h3.setRowspan(2); // tabla.addCell(h3); // PdfPCell diaColumna = new PdfPCell(); // for (int i = 0; i < (nroColumnas-2); i++) { // String celda = (listaInt.get(i).toString()); // diaColumna.setPhrase(new Phrase(celda,fontCabecera)); // diaColumna.setHorizontalAlignment(1); // tabla.addCell(diaColumna); // } Calendar cal = Calendar.getInstance(); List<Integer> conteoDias = new ArrayList<Integer>(); // for (int i = 0; i < dnis.size(); i++) { // // List<Empleado> listaEmpleado = new ArrayList<Empleado>(); // listaEmpleado = em.buscarXPatron(dnis.get(i)); // Empleado empleado = new Empleado(); // empleado = listaEmpleado.get(0); // BigDecimal totalTardanza= new BigDecimal(0.00); // PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getApellidoPaterno()+" "+empleado.getApellidoMaterno()+" "+empleado.getNombre(),fontCelda)); // celdaNombre.setHorizontalAlignment(0); // tabla.addCell(celdaNombre); // List<RegistroAsistencia> registrosDni = rg.buscarXEmpleadoXFecha2(dnis.get(i), fechaInicio, fechaFin); // System.out.println("Numero de registros: "+registrosDni.size()); // //// for (RegistroAsistencia registro : registrosDni) { //// cal.setTime(registro.getFecha()); //// for (int j = 0; j < listaInt.size(); j++) { //// if(cal.get(Calendar.DAY_OF_MONTH)==listaInt.get(j)){ //// if(registro.getMinTardanza()!=null){ //// int numero = registro.getMinTardanza().intValue(); //// String celda = ""+numero; //// celdaNombre.setPhrase(new Phrase(celda,fontCelda)); //// celdaNombre.setHorizontalAlignment(1); //// tabla.addCell(celdaNombre); //// totalTardanza = totalTardanza.add(registro.getMinTardanza()); //// }else{ //// String celda = "0.0"; //// celdaNombre.setPhrase(new Phrase(celda,fontCelda)); //// celdaNombre.setHorizontalAlignment(1); //// tabla.addCell(celdaNombre); //// } //// conteoDias.add(listaInt.get(j)); //// break; //// }else{ //// if(conteoDias.contains(listaInt.get(j))){ //// //// }else{ //// String celda = "n.r"; //// celdaNombre.setPhrase(new Phrase(celda,fontCelda)); //// celdaNombre.setHorizontalAlignment(1); //// tabla.addCell(celdaNombre); //// conteoDias.add(listaInt.get(j)); //// } //// } //// } //// } //// if(registrosDni.size()<(nroColumnas-2)){ //// int dfNumRegistros = (nroColumnas-2)-registrosDni.size(); //// for (int j = 0; j < dfNumRegistros; j++) { //// String celda = "n.r"; //// celdaNombre.setPhrase(new Phrase(celda,fontCelda)); //// celdaNombre.setHorizontalAlignment(1); //// tabla.addCell(celdaNombre); //// } //// } // // //// System.out.println("ConteoDias: "+conteoDias.size()); //// System.out.println("Total tardanzas: "+totalTardanza); //// conteoDias.clear(); //// String tardanzaTotal = totalTardanza.toString(); //// celdaNombre.setPhrase(new Phrase(tardanzaTotal,fontCelda)); //// celdaNombre.setHorizontalAlignment(1); //// tabla.addCell(celdaNombre); // } return tabla; }
From source file:pruebareportes.rptTardC.java
public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException { /**/*www . ja v a 2 s. c om*/ * 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); int diaMesInicio, diaMesFin; diaMesInicio = fechaInicioC.get(Calendar.DAY_OF_MONTH); diaMesFin = fechaFinC.get(Calendar.DAY_OF_MONTH); //Definir numero de columnas de dias ArrayList<Integer> listaInt = new ArrayList<Integer>(); Calendar fechaRegistro = Calendar.getInstance(); for (RegistroAsistencia registro : registros) { fechaRegistro.setTime(registro.getFecha()); Integer diaRegistro = fechaRegistro.get(Calendar.DAY_OF_MONTH); if (listaInt.contains(diaRegistro) != true) { if (diaRegistro >= diaMesInicio && diaRegistro <= diaMesFin) { listaInt.add(diaRegistro); } } } //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 = listaInt.size() + 2; PdfPTable tabla = new PdfPTable(nroColumnas); tabla.setWidthPercentage(100); //Asignamos los tamaos a las columnas int[] widthColumna = new int[nroColumnas]; for (int i = 0; i < nroColumnas; i++) { if (i == 0) { widthColumna[i] = 6; } else if (i == (nroColumnas - 1)) { 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 - 2); tabla.addCell(h2); PdfPCell h3 = new PdfPCell(new Phrase("Total (minutos)", fontCabecera)); h3.setHorizontalAlignment(3); h3.setGrayFill(0.7f); h3.setColspan(1); h3.setRowspan(2); tabla.addCell(h3); PdfPCell diaColumna = new PdfPCell(); for (int i = 0; i < (nroColumnas - 2); i++) { String celda = (listaInt.get(i).toString()); diaColumna.setPhrase(new Phrase(celda, fontCabecera)); diaColumna.setHorizontalAlignment(1); tabla.addCell(diaColumna); } Calendar cal = Calendar.getInstance(); List<Integer> conteoDias = new ArrayList<Integer>(); for (int i = 0; i < dnis.size(); i++) { List<Empleado> listaEmpleado = new ArrayList<Empleado>(); listaEmpleado = em.buscarXPatron(dnis.get(i)); Empleado empleado = new Empleado(); empleado = listaEmpleado.get(0); BigDecimal totalTardanza = new BigDecimal(0.00); PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno() + " " + empleado.getNombre(), fontCelda)); celdaNombre.setHorizontalAlignment(0); tabla.addCell(celdaNombre); List<RegistroAsistencia> registrosDni = rg.buscarXEmpleadoXFecha2(dnis.get(i), fechaInicio, fechaFin); System.out.println("Numero de registros: " + registrosDni.size()); if (!registrosDni.isEmpty()) { } for (RegistroAsistencia registro : registrosDni) { cal.setTime(registro.getFecha()); for (int j = 0; j < listaInt.size(); j++) { if (cal.get(Calendar.DAY_OF_MONTH) == listaInt.get(j)) { if (registro.getMinTardanza() != null) { int numero = registro.getMinTardanza().intValue(); String celda = "" + numero; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); totalTardanza = totalTardanza.add(registro.getMinTardanza()); } else { String celda = "0.0"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } conteoDias.add(listaInt.get(j)); break; } else { if (conteoDias.contains(listaInt.get(j))) { } else { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); conteoDias.add(listaInt.get(j)); } } } } if (registrosDni.size() < (nroColumnas - 2)) { int dfNumRegistros = (nroColumnas - 2) - registrosDni.size(); for (int j = 0; j < dfNumRegistros; j++) { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } } System.out.println("ConteoDias: " + conteoDias.size()); System.out.println("Total tardanzas: " + totalTardanza); conteoDias.clear(); String tardanzaTotal = totalTardanza.toString(); celdaNombre.setPhrase(new Phrase(tardanzaTotal, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } return tabla; }
From source file:pruebareportes.rptTardCx.java
public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException { /**//from w w w . j a va2s.co 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); 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 */ //agrege una columna mas (Descuento sin goce) int nroColumnas = listaInt.size() + 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]; for (int i = 0; i < nroColumnas; i++) { if (i == 0) { widthColumna[i] = 6; } else if (i == (nroColumnas - 1) || i == (nroColumnas - 2)) { 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 - 3); tabla.addCell(h2); PdfPCell h3 = new PdfPCell(new Phrase("Total (minutos)", 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("Descuento S/G", fontCabecera)); h4.setHorizontalAlignment(3); h4.setGrayFill(0.7f); h4.setColspan(1); h4.setRowspan(2); tabla.addCell(h4); PdfPCell diaColumna = new PdfPCell(); for (int i = 0; i < (nroColumnas - 3); i++) { String celda = (listaInt.get(i).toString()); diaColumna.setPhrase(new Phrase(celda, fontCabecera)); diaColumna.setHorizontalAlignment(1); tabla.addCell(diaColumna); } Calendar cal = Calendar.getInstance(); List<Integer> conteoDias = new ArrayList<>(); int diasDescuento = 0; double minDescuento = 0; for (int i = 0; i < dnis.size(); i++) { List<Empleado> listaEmpleado = new ArrayList<>(); listaEmpleado = em.buscarXPatron(dnis.get(i)); Empleado empleado; empleado = listaEmpleado.get(0); BigDecimal totalTardanza = new BigDecimal(0.00); PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno() + " " + empleado.getNombre(), fontCelda)); celdaNombre.setHorizontalAlignment(0); tabla.addCell(celdaNombre); List<RegistroAsistencia> registrosDni = rg.buscarXEmpleadoXFecha2(dnis.get(i), fechaInicio, fechaFin); System.out.println( "Numero de registros: " + registrosDni.size() + " Empleado: " + empleado.getApellidoPaterno() + " " + empleado.getApellidoPaterno() + " " + empleado.getNombre()); List<Integer> listaPermisos = new ArrayList<>(); if (!registrosDni.isEmpty()) { for (RegistroAsistencia registro : registrosDni) { //========================DESCUENTOS LICENCIAS================================================= AsignacionPermiso asignaciones = asp.buscarXDia(empleado.getNroDocumento(), registro.getFecha()); if (asignaciones != null) { System.out.println("Asignacion: " + asignaciones.getPermiso().toString()); Permiso permisoProcesar = asignaciones.getPermiso(); System.out.println("Tiene un permiso" + permisoProcesar.getMotivo()); if (permisoProcesar.getTipoPermiso().getTipoDescuento() == 'S') { if (permisoProcesar.getOpcion() == 'F') { if (!listaPermisos.contains(permisoProcesar.getId().intValue())) { Date fechaInicio1 = permisoProcesar.getFechaInicio(); Date fechaFin1 = permisoProcesar.getFechaFin(); if (fechaInicio1.compareTo(fechaFin1) < 0) { cal.setTime(fechaInicio1); int diaInicio = cal.get(Calendar.DAY_OF_MONTH); cal.setTime(fechaFin1); int diaFin = cal.get(Calendar.DAY_OF_MONTH); diasDescuento += diaFin - diaInicio + 1; } else if (fechaInicio1.compareTo(fechaFin1) == 0) { diasDescuento = 1; } listaPermisos.add(permisoProcesar.getId().intValue()); } } else { if (permisoProcesar.getOpcion() == 'H') { Date horaInicio1 = permisoProcesar.getHoraInicio(); Date horaFin1 = permisoProcesar.getHoraFin(); if (horaInicio1.compareTo(horaFin1) < 0) { minDescuento = permisoProcesar.getHoraFin().getTime() - permisoProcesar.getHoraInicio().getTime(); } } } } } else { System.out.println("No hay registros"); } //========================DESCUENTOS LICENCIAS================================================= cal.setTime(registro.getFecha()); for (int j = 0; j < listaInt.size(); j++) { if (cal.get(Calendar.DAY_OF_MONTH) == listaInt.get(j)) { if (registro.getMinTardanza() != null) { int numero = registro.getMinTardanza().intValue(); String celda = "" + numero; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); totalTardanza = totalTardanza.add(registro.getMinTardanza()); } else { String celda = "0.0"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } conteoDias.add(listaInt.get(j)); break; } else { if (conteoDias.contains(listaInt.get(j))) { } else { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); conteoDias.add(listaInt.get(j)); } } } } } else { for (Integer dia : listaInt) { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } } System.out.println("ConteoDias: " + conteoDias.size()); System.out.println("Total tardanzas: " + totalTardanza); conteoDias.clear(); //String tardanzaTotal = totalTardanza.toString(); String hora1 = ""; if (totalTardanza.intValue() < 60) { hora1 = totalTardanza.intValue() + " min"; } else if (totalTardanza.intValue() >= 60 && totalTardanza.intValue() < 480) { int resto = totalTardanza.intValue() % 60; int totalH = (totalTardanza.intValue() - resto) / 60; hora1 = totalH + " h " + resto + " min"; } else if (totalTardanza.intValue() >= 480) { int restoHoras = totalTardanza.intValue() % 480; int totalD = (totalTardanza.intValue() - 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); //Descuento int minutosT = diasDescuento * 480; int minutosTotal = (int) (minutosT + minDescuento); String hora = ""; if (minutosTotal < 60) { hora = minutosTotal + " min"; } else if (minutosTotal >= 60 && minutosTotal < 480) { int resto = minutosTotal % 60; int totalH = (minutosTotal - resto) / 60; hora = totalH + " h " + resto + " min"; } else if (minutosTotal >= 480) { int restoHoras = minutosTotal % 480; int totalD = (minutosTotal - 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); } return tabla; }
From source file:sms.ReportForms.java
public PdfPCell creatTextCellChart(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD)); p.add(text);/*from w ww . j a va2 s . co m*/ cell.addElement(p); cell.setRowspan(2); cell.setBorder(Rectangle.NO_BORDER); return cell; }
From source file:vistas.reportes.procesos.rptTardanzaTotal.java
public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException { /**// w w w . j ava 2 s . c om * 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; }