List of usage examples for com.itextpdf.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
From source file:ro.nextreports.engine.exporter.PdfExporter.java
License:Apache License
private void writeHeader(PdfPTable datatable) { if (bean.getReportLayout().isHeaderOnEveryPage()) { int headerNo = bean.getReportLayout().getHeaderBand().getRowCount(); if (headerNo > 0) { datatable.setHeaderRows(headerNo); }//from w w w. java 2 s. co m } }
From source file:se.inera.intyg.rehabstod.service.export.pdf.PdfExportServiceImpl.java
License:Open Source License
private PdfPTable createSjukfallTable(List<SjukfallEnhet> sjukfallList, Urval urval, boolean showPatientId, boolean showSrsRisk) throws DocumentException { // Setup column widths (relative to each other) PdfPTable table = createTableColumns(urval, showPatientId, showSrsRisk); table.setWidthPercentage(100.0f);//from w w w. ja v a 2 s . c o m table.getDefaultCell().setBackgroundColor(TABLE_HEADER_BASE_COLOR); table.getDefaultCell().setBorderColor(TABLE_HEADER_BASE_COLOR); table.getDefaultCell().setNoWrap(true); table.getDefaultCell().setPadding(3f); table.getDefaultCell().setPaddingLeft(2f); addCell(table, TABLEHEADER_NR, PdfExportConstants.TABLE_HEADER_FONT); if (showPatientId) { addCell(table, TABLEHEADER_PERSONNUMMER, PdfExportConstants.TABLE_HEADER_FONT); } addCell(table, TABLEHEADER_ALDER, PdfExportConstants.TABLE_HEADER_FONT); if (showPatientId) { addCell(table, TABLEHEADER_NAMN, PdfExportConstants.TABLE_HEADER_FONT); } addCell(table, TABLEHEADER_KON, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_NUVARANDE_DIAGNOS, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_STARTDATUM, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_SLUTDATUM, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_SJUKSKRIVNINGSLANGD, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_ANTAL, PdfExportConstants.TABLE_HEADER_FONT); addCell(table, TABLEHEADER_SJUKSKRIVNINGSGRAD, PdfExportConstants.TABLE_HEADER_FONT); if (Urval.ALL.equals(urval)) { addCell(table, TABLEHEADER_NUVARANDE_LAKARE, PdfExportConstants.TABLE_HEADER_FONT); } if (showSrsRisk) { addCell(table, TABLEHEADER_SRS_RISK, PdfExportConstants.TABLE_HEADER_FONT); } // Set cell styles for the non-header cells following hereafter table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY); table.getDefaultCell().setNoWrap(false); table.getDefaultCell().setPadding(2f); table.setHeaderRows(1); int rowNumber = 1; for (SjukfallEnhet is : sjukfallList) { if (rowNumber % 2 == 0) { table.getDefaultCell().setBackgroundColor(TABLE_EVEN_ROW_COLOR); } else { table.getDefaultCell().setBackgroundColor(TABLE_ODD_ROW_COLOR); } addCell(table, String.valueOf(rowNumber)); if (showPatientId) { addCell(table, getPersonnummerColumn(is)); } addCell(table, is.getPatient().getAlder()); if (showPatientId) { addCell(table, is.getPatient().getNamn()); } addCell(table, is.getPatient().getKon().getDescription()); addCell(table, getCompoundDiagnoseText(is, showPatientId)); addCell(table, is.getStart() != null ? YearMonthDateFormatter.print(is.getStart()) : "?"); addCell(table, is.getSlut() != null ? YearMonthDateFormatter.print(is.getSlut()) : "?"); addCell(table, getlangdText(is)); addCell(table, is.getIntyg()); addCell(table, getGrader(is)); if (Urval.ALL.equals(urval)) { addCell(table, is.getLakare().getNamn()); } if (showSrsRisk) { addCell(table, getRiskKategoriDesc(is.getRiskSignal())); } rowNumber++; } return table; }
From source file:Servlets.PDF.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); Document document = new Document(PageSize.A4, 50, 50, 50, 50); try {/*from w ww.j a v a2s.c om*/ //obtengo datos de cliente, reserva y total String rreserva = request.getParameter("reserva"); String rcliente = request.getParameter("cliente"); String rtotal = request.getParameter("total"); //String rtipo = request.getParameter("esProv"); // Obtener datos de cliente e items de reserva DtUsuario dtu = getDtUsuario(rcliente); String nombre = dtu.getNombre(); String apellido = dtu.getApellido(); String servicios = ""; String promos = ""; java.util.List<DtItemReserva> dtItems = listarItems(Integer.parseInt(rreserva)).getItems(); Iterator<DtItemReserva> iter = dtItems.iterator(); DtItemReserva dtItem; // Crear y abrir documento String HomeDeUSuario = System.getProperty("user.home"); String ruta = HomeDeUSuario + "/Factura Reserva " + rreserva + ".pdf"; FileOutputStream archivo = new FileOutputStream(ruta); PdfWriter writer = PdfWriter.getInstance(document, archivo); document.open(); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); String fecha = dateFormat.format(date); // Agregar marcador inicial // Crear y agregar prrafo simple Paragraph paragraph1 = new Paragraph(); Image imagen = Image.getInstance("http://localhost:8084/Help4TravelingWeb/img/logo-icon2.png"); imagen.scaleAbsolute(200f, 200f); imagen.setAbsolutePosition(10, 650); imagen.setSpacingAfter(20); paragraph1.add(imagen); document.add(paragraph1); //fecha Paragraph fecha1 = new Paragraph(fecha); //encabezado Paragraph futuros = new Paragraph("Futuros Tecnologos SRL"); Paragraph rut = new Paragraph("RUT 123456789012"); Paragraph direccion = new Paragraph(" Av. Gral. Rivera 3629"); Paragraph telefono = new Paragraph(" Tel: 555-5412"); Paragraph nombre_empresa = new Paragraph(" Help4Travelling"); //datos cliente String nombrecliente = nombre.toUpperCase() + " " + apellido.toUpperCase(); String direccioncliente = " "; String rutcliente = "consumidor final".toUpperCase(); Paragraph cliente = new Paragraph("Cliente: " + nombrecliente); Paragraph dircliente = new Paragraph("Direccion: " + direccioncliente); Paragraph rutcli = new Paragraph("RUT: " + rutcliente); //datos boleta String factura = rreserva; Paragraph tipodoc = new Paragraph("Contado"); Paragraph Nfac = new Paragraph(" N " + factura); //alineaciones //fecha fecha1.setAlignment(Element.ALIGN_RIGHT); //encabezado futuros.setAlignment(Element.ALIGN_CENTER); rut.setAlignment(Element.ALIGN_CENTER); direccion.setAlignment(Element.ALIGN_CENTER); telefono.setAlignment(Element.ALIGN_CENTER); //nombre empresa nombre_empresa.setAlignment(Element.ALIGN_LEFT); nombre_empresa.setSpacingBefore(10); nombre_empresa.setSpacingAfter(30); //datos de boleta tipodoc.setAlignment(Element.ALIGN_RIGHT); Nfac.setAlignment(Element.ALIGN_RIGHT); document.add(fecha1); document.add(futuros); document.add(rut); document.add(direccion); document.add(telefono); document.add(nombre_empresa); document.add(tipodoc); document.add(Nfac); document.add(cliente); document.add(dircliente); document.add(rutcli); PdfPTable tabla = new PdfPTable(4); tabla.setSpacingBefore(25); tabla.setSpacingAfter(25); //creo encabezado de tabla PdfPCell codigo = new PdfPCell(new Phrase("Proveedor".toUpperCase())); PdfPCell descripcion = new PdfPCell(new Phrase("descripcion".toUpperCase())); PdfPCell ecantidad = new PdfPCell(new Phrase("cantidad".toUpperCase())); PdfPCell eprecio = new PdfPCell(new Phrase("precio".toUpperCase())); tabla.setHeaderRows(1); tabla.setWidthPercentage(100f); //alineamos las frases del cabezal codigo.setHorizontalAlignment(Element.ALIGN_CENTER); descripcion.setHorizontalAlignment(Element.ALIGN_CENTER); ecantidad.setHorizontalAlignment(Element.ALIGN_CENTER); eprecio.setHorizontalAlignment(Element.ALIGN_CENTER); //agrego cabezal de tabla tabla.addCell(codigo); tabla.addCell(descripcion); tabla.addCell(ecantidad); tabla.addCell(eprecio); //obtengo datos de la reserva para imprimir las distintas rows while (iter.hasNext()) { dtItem = iter.next(); Integer cantidad = dtItem.getCantidad(); String oferta = dtItem.getOferta().getNombre(); String precio; String proveedor; if (existeServicio(oferta)) { proveedor = getNkProveedorServicio(oferta); DtServicio dts = getDtServicio(oferta, proveedor); precio = String.valueOf(dts.getPrecio()); } else { proveedor = getNkProveedorPromocion(oferta); DtPromocion dtp = getDTPromocion(oferta, proveedor); precio = dtp.getDescuento(); } /* String item = "<li>Nombre: <em>" + oferta + "</em>" + " - Cantidad: <em>" + cantidad + "</em>" + " - $:<em>" + precio + "</em>" + " - Proveedor: <em>" + proveedor + "</em></li>";*/ //creo encabezado de tabla PdfPCell iproveedor = new PdfPCell(new Phrase(proveedor.toUpperCase())); PdfPCell icantidad = new PdfPCell(new Phrase(cantidad.toString())); PdfPCell iprecio = new PdfPCell(new Phrase(precio.toUpperCase())); tabla.setHeaderRows(1); //alineamos las frases del cabezal iproveedor.setHorizontalAlignment(Element.ALIGN_CENTER); icantidad.setHorizontalAlignment(Element.ALIGN_CENTER); iprecio.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(iproveedor); if (existeServicio(oferta)) { PdfPCell idescripcion = new PdfPCell(new Phrase("servicio: " + oferta)); idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(idescripcion); } else { PdfPCell idescripcion = new PdfPCell(new Phrase("Promo: " + oferta)); idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(idescripcion); } tabla.addCell(icantidad); tabla.addCell(iprecio); } /* // las distintas rows de los articulos tabla.addCell(proveedor); tabla.addCell(oferta); tabla.addCell(cantidad); tabla.addCell(precio); */ //el ulimo de la tabla que da el total PdfPCell celdaFinal = new PdfPCell(new Paragraph("")); PdfPCell celdaTotal = new PdfPCell(new Paragraph("total:")); PdfPCell celdaPrecioTotal = new PdfPCell(new Paragraph(rtotal)); // Indicamos cuantas columnas ocupa la celda celdaFinal.setColspan(2); celdaTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); celdaPrecioTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celdaFinal); tabla.addCell(celdaTotal); tabla.addCell(celdaPrecioTotal); document.add(tabla); document.close(); if (request.getParameter("dispositivo").equals("true")) response.sendRedirect("Movil.Reservas.jsp"); else response.sendRedirect("Usuario.jsp"); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:Servlets.ReportsServlet.java
public PdfPTable reports(String lotnum, String reportName, float cSize) { //specify column widths float[] columnWidths = { .12f, .14f, .18f, .25f, .08f, .1f, .1f, .1f, .15f, cSize }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); //PdfPTable table = new PdfPTable(10); // set table width a percentage of the page width table.setWidthPercentage(100f);//from w ww. j a va 2 s. co m switch (reportName) { case "IT Report": try { /* IT REPORT GENERATION BLOCK */ //insert column headings insertCell(table, "IT GP No", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "TR No and IT Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farmer's Name\n and ID", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Ref No.\n (New and Old)", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Size", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Trees Cut ", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Expected Trees ", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Treated Area", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "IT Grant Payable", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Remarks", Element.ALIGN_CENTER, 1, bfBold8); table.setHeaderRows(1); ResultSet rs = manager.PDFdemos(lotnum); float totalFarmsSize = 0; int totalTreesCut = 0; int totalExpectedTrees = 0; float totalTreatedArea = 0; float totalITGrantPayabe = 0; //Populating Feilds while (rs.next()) { insertCell(table, rs.getString(7), Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, rs.getString(8), rs.getDate(9) + "", Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(5), rs.getString(6), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, rs.getString(1), rs.getString(11), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, String.format("%.2f", rs.getFloat(2)) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getInt(3) + "", Element.ALIGN_LEFT, 1, bf8); int itExpectedTrees = (int) (rs.getFloat(4) * 1100); insertCell(table, itExpectedTrees + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(4)) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(10)) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, " ", Element.ALIGN_RIGHT, 1, bf8); totalFarmsSize = totalFarmsSize + rs.getFloat(2); totalTreesCut = totalTreesCut + rs.getInt(3); totalExpectedTrees = totalExpectedTrees + itExpectedTrees; totalTreatedArea = totalTreatedArea + rs.getFloat(4); totalITGrantPayabe = totalITGrantPayabe + rs.getFloat(10); } insertCell(table, manager.totalFarms(lotnum) + " treated farms Totals", Element.ALIGN_RIGHT, 4, bfBold8); insertCell(table, String.format("%.2f", totalFarmsSize) + "", Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, totalTreesCut + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalExpectedTrees + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalTreatedArea) + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalITGrantPayabe) + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, " ", Element.ALIGN_CENTER, 1, bfBold8); } //Try ends here catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } break; case "TR Report": try { /* TR REPORT GENERATION BLOCK */ //insert column headings insertCell(table, "IT GP No", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "TR No and IT Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farmer's Name", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Ref No.\n (New and Old)", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Size", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Trees Cut ", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Expected Trees ", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "Estimated Trees", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "Treated Area", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "TR Payable", Element.ALIGN_CENTER, 1, bfBold8small); table.setHeaderRows(1); ResultSet rs = manager.TRReportPDF(lotnum); float totalFarmsSize = 0; int totalTreesCut = 0; int totalExpectedTrees = 0; float totalTreatedArea = 0; float totalITGrantPayabe = 0; int totalEstimated = 0; //Populating Feilds while (rs.next()) { insertCell(table, rs.getString(7), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(8), rs.getDate(9) + "", Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(6), Element.ALIGN_LEFT, 1, bfBold8small); insertCell(table, rs.getString(1), rs.getString(11), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, String.format("%.2f", rs.getFloat(2)) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getInt(3) + "", Element.ALIGN_LEFT, 1, bf8); int trExpected = (int) (rs.getFloat(4) * 1100); insertCell(table, trExpected + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getInt(5) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(4)) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, String.format("%.2f", rs.getFloat(10)) + "", Element.ALIGN_RIGHT, 1, bf8); totalFarmsSize += rs.getFloat(2); totalTreesCut += rs.getInt(3); totalExpectedTrees += trExpected; totalEstimated += rs.getInt(5); totalTreatedArea += rs.getFloat(4); totalITGrantPayabe += rs.getFloat(10); } insertCell(table, manager.totalFarms(lotnum) + " treated farms Totals", Element.ALIGN_RIGHT, 4, bfBold8); insertCell(table, String.format("%.2f", totalFarmsSize) + "", Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, totalTreesCut + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalExpectedTrees + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalEstimated + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, totalTreatedArea + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalITGrantPayabe) + "", Element.ALIGN_CENTER, 1, bfBold8small); } //Try ends here catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } break; case "RP Report": break; case "Rehab Report": break; default: break; //Switch ends here } return table; }
From source file:Servlets.ReportsServlet.java
public PdfPTable reports(String rehLot) { //specify column widths float[] columnWidths = { .2f, .18f, .2f, .4f, .3f, .2f, .2f, .2f, .2f, .15f, .2f }; //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); //PdfPTable table = new PdfPTable(10); // set table width a percentage of the page width table.setWidthPercentage(100f);//from w w w.j a va2s . com try { //insert column headings insertCell(table, "TR Voucher No", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "TR Date", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Farmer's Name", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Farm number", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Contractor ", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Farmer's Size", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Cocoa Condition", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Treated Area", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "No of Trees Cut", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "Exp Trees", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "TR Payable", Element.ALIGN_LEFT, 1, bfBold8); table.setHeaderRows(1); //Merge cells to input title ie. Region names // insertCell(table, "Bawdua", Element.ALIGN_CENTER, 10, bfBold12); ResultSet rs = manager.PDFRehab(rehLot); float totalFarmSizeReh = 0; float totalTreatedAreaReh = 0; float totalTRpayableReh = 0; int totalExpectedTreesReh = 0; int totalNumberOfTrees = 0; while (rs.next()) { try { insertCell(table, rs.getString(6), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(18), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(4) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(1), rs.getString(13), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(15), Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getFloat(7) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getString(17), rs.getString(16), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getFloat(8) + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getInt(11) + "", Element.ALIGN_LEFT, 1, bf8); int Rehab_trExpected = (int) (rs.getFloat(7) * 1100); insertCell(table, Rehab_trExpected + "", Element.ALIGN_RIGHT, 1, bf8); insertCell(table, rs.getFloat(20) + "", Element.ALIGN_LEFT, 1, bf8); totalFarmSizeReh += rs.getFloat(7); totalTRpayableReh += rs.getFloat(20); totalTreatedAreaReh += rs.getFloat(8); totalNumberOfTrees += rs.getInt(11); totalExpectedTreesReh += Rehab_trExpected; } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } } insertCell(table, "Total Farms in the Region " + manager.allRehabFarms(rehLot), Element.ALIGN_LEFT, 4, bfBold8); // insertCell(table, rs.getString(18), Element.ALIGN_LEFT, 1, bf8); // insertCell(table, rs.getString(4) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, "TOTALS", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, String.format("%.2f", totalFarmSizeReh), Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, " ", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, String.format("%.2f", totalTreatedAreaReh), Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, totalNumberOfTrees + "", Element.ALIGN_LEFT, 1, bfBold8); insertCell(table, "" + totalExpectedTreesReh, Element.ALIGN_RIGHT, 1, bfBold8); insertCell(table, String.format("%.2f", totalTRpayableReh), Element.ALIGN_LEFT, 1, bfBold8); //Merge cells for Contractor area // insertCell(table, "Details of Tree Removal in favour of Contractor: " // + "Omenaaba Company Limited", Element.ALIGN_LEFT, 6, bfBold8); // // //Dummy data // insertCell(table, "10010", Element.ALIGN_RIGHT, 1, bf8); // insertCell(table, "ABC00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // // //Merge cells for District Total // insertCell(table, "District Total", Element.ALIGN_LEFT, 4, bfBold8); // // //Dummy data // insertCell(table, "10010", Element.ALIGN_RIGHT, 1, bf8); // insertCell(table, " ", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // // //Merge cells for Region Total // insertCell(table, "Region Total", Element.ALIGN_LEFT, 4, bfBold8); // // //Dummy data // insertCell(table, "10010", Element.ALIGN_RIGHT, 1, bf8); // insertCell(table, " ", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); // insertCell(table, "C00", Element.ALIGN_LEFT, 1, bf8); } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } return table; }
From source file:Servlets.ReportsServlet.java
public PdfPTable RPreport(String lotnum) { //specify column widths float[] columnWidths = { .18f, .18f, .25f, .27f, .1f, .1f, .12f, .1f, .15f, .1f, .1f, .1f, .1f, .1f, .1f, .1f, .15f };/*from w w w . j ava2 s. co m*/ //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); //PdfPTable table = new PdfPTable(10); // set table width a percentage of the page width table.setWidthPercentage(100f); try { /* Replanting REPORT GENERATION BLOCK */ //insert column headings insertCell(table, "RP GP No\nand RP Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "IT No \nand IT Date", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farmer's Name\n and ID", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Ref No.\n (New and Old)", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Farm Size", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, "Treated Area ", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "IT Grant Paid", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, "Area Repl", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { 3f, .1f, .1f, .1f }); insertCell(table, "Gross RP", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Seeds\nQty Prev Purch", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Seeds\nQty Supl Free", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Fert\nQty Alloc(Bags)", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Fert\nQty Purch", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Deduc's\nCost of Seed", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Deduc's\nCost of Fert Alloc", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Deduc's\nTotal Deduct", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, "Net RP Payable", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, 3f, .1f, .1f }); table.setHeaderRows(1); ResultSet rs = manager.PDFreplants(lotnum); float totalFsize = 0; float totalTarea = 0; float totalITPay = 0; float totalAreaRpl = 0; float totalGross = 0; int totalQpp = 0; int totalQsp = 0; int totalQsf = 0; int totalQalloc = 0; int totalQpurchase = 0; float totalCostSeed = 0; float totalCostFert = 0; float totalDeduct = 0; float totalNet = 0; //Populating Feilds while (rs.next()) { insertCell(table, rs.getString(10), rs.getString(11), Element.ALIGN_LEFT, 1, bfBold8, bf8); insertCell(table, rs.getString(7) + "\n" + rs.getString(8), Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getString(5), rs.getString(6), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, rs.getString(1), rs.getString(2), Element.ALIGN_LEFT, 1, bfBold8small, bf8); insertCell(table, rs.getFloat(3) + "", Element.ALIGN_LEFT, 1, bf8); insertCell(table, rs.getFloat(4) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(9) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(12) + "", Element.ALIGN_CENTER, 1, bf8, borderA = new float[] { 3f, .1f, .1f, .1f }); insertCell(table, rs.getFloat(15) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(19) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(13) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(20) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getInt(18) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(21) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(14) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(16) + "", Element.ALIGN_CENTER, 1, bf8); insertCell(table, rs.getFloat(17) + "", Element.ALIGN_CENTER, 1, bf8, borderB = new float[] { .1f, 3f, .1f, .1f }); totalFsize = totalFsize + rs.getFloat(3); totalTarea = totalTarea + rs.getFloat(4); totalITPay = totalITPay + rs.getFloat(9); totalAreaRpl = totalAreaRpl + rs.getFloat(12); totalGross = totalGross + rs.getFloat(15); totalQpp = totalQpp + rs.getInt(19); totalQsf = totalQsf + rs.getInt(13); totalQalloc = totalQalloc + rs.getInt(14); totalQpurchase = totalQpurchase + rs.getInt(18); totalCostSeed = totalCostSeed + rs.getFloat(21); totalCostFert = totalCostFert + rs.getFloat(20); totalDeduct = totalDeduct + rs.getFloat(16); totalNet = totalNet + rs.getFloat(17); } //Totals insertCell(table, manager.totalFarmsReplant(lotnum) + " Replanted Farms Totals", Element.ALIGN_RIGHT, 4, bfBold8); insertCell(table, String.format("%.2f", totalFsize) + "", Element.ALIGN_CENTER, 1, bfBold8); insertCell(table, String.format("%.2f", totalTarea) + "", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, String.format("%.2f", totalITPay) + "", Element.ALIGN_CENTER, 1, bfBold8small); insertCell(table, String.format("%.2f", totalAreaRpl) + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { 3f, .1f, .1f, .1f }); insertCell(table, String.format("%.2f", totalGross) + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQpp + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQsf + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalCostFert + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQpurchase + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalCostSeed + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalQalloc + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, totalDeduct + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, .1f, .1f, .1f }); insertCell(table, String.format("%.2f", totalNet) + "", Element.ALIGN_CENTER, 1, bfBold8small, borderA = new float[] { .1f, 3f, 3f, .1f }); } //Try ends here catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } return table; }
From source file:sipl.recursos.GenerarPDFGrafica.java
private void createTable(Section subCatPart) throws BadElementException { String p = Titulo.charAt(0) + ""; if (p.equals("P")) { ArrayList<Prestamo> prestamos = preDAO.getRangoFecha_prestamo(fecha1, fecha2); ArrayList<Material> materiales = matDAO.getMateriales(); if (rango.equals("Anho")) { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0;//from w w w .j ava 2 s . c o m } for (int i = 0; i < prestamos.size(); i++) { String[] P = prestamos.get(i).getMat().split(";"); for (String P1 : P) { for (int k = 0; k < materiales.size(); k++) { int c; if (T[k][0] == Integer.parseInt(P1)) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } } PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (prestamos.isEmpty()) { table.addCell("No hay prstamos en ese rango de fecha"); } else { ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } } table.addCell(""); table.addCell(""); table.addCell("Ao"); table.addCell("Cantidad Prstamos"); String[] f1 = fecha1.split("/"); int a = Integer.parseInt(f1[0]); String[] f2 = fecha2.split("/"); int b = Integer.parseInt(f2[0]); int dif = b - a; dif++; int tamY[][] = new int[dif][2]; for (int i = 0; i < dif; i++) { tamY[i][0] = a; a++; } for (int j = 0; j < dif; j++) { tamY[j][1] = 0; } for (int k = 0; k < prestamos.size(); k++) { int t = prestamos.get(k).getFecha_prestamo().get(Calendar.YEAR); for (int l = 0; l < dif; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < dif; i++) { if (tamY[i][1] > 0) { table.addCell("" + tamY[i][0]); table.addCell("" + tamY[i][1]); } } subCatPart.add(table); } else if (rango.equals("Mes")) { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0; } for (int i = 0; i < prestamos.size(); i++) { String[] P = prestamos.get(i).getMat().split(";"); for (String P1 : P) { for (int k = 0; k < materiales.size(); k++) { int c; if (T[k][0] == Integer.parseInt(P1)) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } } PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (prestamos.isEmpty()) { table.addCell("No hay prstamos en ese rango de fecha"); } else { ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } } table.addCell(""); table.addCell(""); table.addCell("Mes"); table.addCell("Cantidad Prstamos"); String[] meses = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; int tamY[][] = new int[12][2]; for (int i = 0; i < 12; i++) { tamY[i][0] = i; } for (int j = 0; j < 12; j++) { tamY[j][1] = 0; } for (int k = 0; k < prestamos.size(); k++) { int t = prestamos.get(k).getFecha_prestamo().get(Calendar.MONTH); for (int l = 0; l < 12; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 12; i++) { if (tamY[i][1] > 0) { table.addCell("" + meses[i]); table.addCell("" + tamY[i][1]); } } subCatPart.add(table); } else if (rango.equals("Dia")) { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0; } for (int i = 0; i < prestamos.size(); i++) { String[] P = prestamos.get(i).getMat().split(";"); for (String P1 : P) { for (int k = 0; k < materiales.size(); k++) { int c; if (T[k][0] == Integer.parseInt(P1)) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } } PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (prestamos.isEmpty()) { table.addCell("No hay prstamos en ese rango de fecha"); } else { ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } } table.addCell(""); table.addCell(""); table.addCell("Dia"); table.addCell("Cantidad Prstamos"); int tamY[][] = new int[32][2]; for (int i = 0; i < 32; i++) { tamY[i][0] = i; } for (int j = 0; j < 32; j++) { tamY[j][1] = 0; } for (int k = 0; k < prestamos.size(); k++) { int t = prestamos.get(k).getFecha_prestamo().get(Calendar.DAY_OF_MONTH); for (int l = 0; l < 32; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 32; i++) { if (tamY[i][1] > 0) { table.addCell("" + i); table.addCell("" + tamY[i][1]); } } subCatPart.add(table); } else if (rango.equals("Hora")) { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0; } for (int i = 0; i < prestamos.size(); i++) { String[] P = prestamos.get(i).getMat().split(";"); for (String P1 : P) { for (int k = 0; k < materiales.size(); k++) { int c; if (T[k][0] == Integer.parseInt(P1)) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } } PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (prestamos.isEmpty()) { table.addCell("No hay prstamos en ese rango de fecha"); } else { ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } } table.addCell(""); table.addCell(""); table.addCell("Hora"); table.addCell("Cantidad Prstamos"); int tamY[][] = new int[24][2]; for (int i = 0; i < 24; i++) { tamY[i][0] = i; } for (int j = 0; j < 24; j++) { tamY[j][1] = 0; } for (int k = 0; k < prestamos.size(); k++) { int t = prestamos.get(k).getFecha_prestamo().get(Calendar.HOUR_OF_DAY); for (int l = 0; l < 24; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 24; i++) { if (tamY[i][1] > 0) { table.addCell("" + i); table.addCell("" + tamY[i][1]); } } subCatPart.add(table); } } else if (p.equals("M")) { ArrayList<Multa> multas = mulDAO.getRangoFecha_multa(fecha1, fecha2); if (rango.equals("Anho")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Ao")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Multas")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (multas.isEmpty()) { table.addCell("No hay multas en ese rango de fecha"); } else { String[] f1 = fecha1.split("/"); int a = Integer.parseInt(f1[0]); String[] f2 = fecha2.split("/"); int b = Integer.parseInt(f2[0]); int dif = b - a; dif++; int tamY[][] = new int[dif][2]; int u = a; for (int i = 0; i < dif; i++) { tamY[i][0] = u; u++; } for (int j = 0; j < dif; j++) { tamY[j][1] = 0; } for (int k = 0; k < multas.size(); k++) { int t = multas.get(k).getFecha_multa().get(Calendar.YEAR); for (int l = 0; l < dif; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < dif; i++) { if (tamY[i][1] > 0) { table.addCell("" + tamY[i][0]); table.addCell("" + tamY[i][1]); } } } subCatPart.add(table); } else if (rango.equals("Mes")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Mes")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Multas")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (multas.isEmpty()) { table.addCell("No hay multas en ese rango de fecha"); } else { String[] meses = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; int tamY[][] = new int[12][2]; for (int i = 0; i < 12; i++) { tamY[i][0] = i; } for (int j = 0; j < 12; j++) { tamY[j][1] = 0; } for (int k = 0; k < multas.size(); k++) { int t = multas.get(k).getFecha_multa().get(Calendar.MONTH); for (int l = 0; l < 12; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 12; i++) { if (tamY[i][1] > 0) { table.addCell("" + meses[i]); table.addCell("" + tamY[i][1]); } } } subCatPart.add(table); } else if (rango.equals("Dia")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Da del mes")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Multas")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (multas.isEmpty()) { table.addCell("No hay multas en ese rango de fecha"); } else { int tamY[][] = new int[32][2]; for (int i = 0; i < 32; i++) { tamY[i][0] = i; } for (int j = 0; j < 32; j++) { tamY[j][1] = 0; } for (int k = 0; k < multas.size(); k++) { int t = multas.get(k).getFecha_multa().get(Calendar.DAY_OF_MONTH); for (int l = 0; l < 32; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 32; i++) { if (tamY[i][1] > 0) { table.addCell("" + i); table.addCell("" + tamY[i][1]); } } } subCatPart.add(table); } else if (rango.equals("Hora")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Hora del da")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Multas")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (multas.isEmpty()) { table.addCell("No hay multas en ese rango de fecha"); } else { int tamY[][] = new int[24][2]; for (int i = 0; i < 24; i++) { tamY[i][0] = i; } for (int j = 0; j < 24; j++) { tamY[j][1] = 0; } for (int k = 0; k < multas.size(); k++) { int t = multas.get(k).getFecha_multa().get(Calendar.HOUR_OF_DAY); for (int l = 0; l < 24; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 24; i++) { if (tamY[i][1] > 0) { table.addCell("" + i); table.addCell("" + tamY[i][1]); } } } subCatPart.add(table); } } else if (p.equals("D")) { ArrayList<Danho> danhos = danDAO.getRangoFecha_danhos(fecha1, fecha2); ArrayList<Material> materiales = matDAO.getMateriales(); if (rango.equals("Anho")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (danhos.isEmpty()) { table.addCell("No hay daos en ese rango de fecha"); } else { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0; } for (int i = 0; i < danhos.size(); i++) { int P = danhos.get(i).getMat().getCodigo(); for (int k = 0; k < materiales.size(); k++) { int c = 0; if (T[k][0] == P) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c = 0; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } c1 = new PdfPCell(new Phrase("Ao")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Daos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); String[] f1 = fecha1.split("/"); int a = Integer.parseInt(f1[0]); String[] f2 = fecha2.split("/"); int b = Integer.parseInt(f2[0]); int dif = b - a; dif++; int tamY[][] = new int[dif][2]; int u = a; for (int i = 0; i < dif; i++) { tamY[i][0] = u; u++; } for (int j = 0; j < dif; j++) { tamY[j][1] = 0; } for (int k = 0; k < danhos.size(); k++) { int t = danhos.get(k).getFecha_d().get(Calendar.YEAR); for (int l = 0; l < dif; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < dif; i++) { if (tamY[i][1] > 0) { table.addCell("" + tamY[i][0]); table.addCell("" + tamY[i][1]); } } c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); int tipoD[] = new int[3]; for (int i = 0; i < 3; i++) { tipoD[i] = 0; } for (int k = 0; k < danhos.size(); k++) { int cont; if (danhos.get(k).getEstado() == 0) { cont = tipoD[0]; cont++; tipoD[0] = cont; } else if (danhos.get(k).getEstado() == 1) { cont = tipoD[1]; cont++; tipoD[1] = cont; } else if (danhos.get(k).getEstado() == 2) { cont = tipoD[2]; cont++; tipoD[2] = cont; } } table.addCell("Daado"); table.addCell("" + tipoD[0]); table.addCell("Reparado"); table.addCell("" + tipoD[1]); table.addCell("Dado de Baja"); table.addCell("" + tipoD[2]); } subCatPart.add(table); } else if (rango.equals("Mes")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (danhos.isEmpty()) { table.addCell("No hay daos en ese rango de fecha"); } else { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0; } for (int i = 0; i < danhos.size(); i++) { int P = danhos.get(i).getMat().getCodigo(); for (int k = 0; k < materiales.size(); k++) { int c = 0; if (T[k][0] == P) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c = 0; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } c1 = new PdfPCell(new Phrase("Mes")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Daos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); String[] meses = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; int tamY[][] = new int[12][2]; for (int i = 0; i < 12; i++) { tamY[i][0] = i; } for (int j = 0; j < 12; j++) { tamY[j][1] = 0; } for (int k = 0; k < danhos.size(); k++) { int t = danhos.get(k).getFecha_d().get(Calendar.MONTH); for (int l = 0; l < 12; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 12; i++) { if (tamY[i][1] > 0) { table.addCell("" + meses[i]); table.addCell("" + tamY[i][1]); } } c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); int tipoD[] = new int[3]; for (int i = 0; i < 3; i++) { tipoD[i] = 0; } for (int k = 0; k < danhos.size(); k++) { int cont; if (danhos.get(k).getEstado() == 0) { cont = tipoD[0]; cont++; tipoD[0] = cont; } else if (danhos.get(k).getEstado() == 1) { cont = tipoD[1]; cont++; tipoD[1] = cont; } else if (danhos.get(k).getEstado() == 2) { cont = tipoD[2]; cont++; tipoD[2] = cont; } } table.addCell("Daado"); table.addCell("" + tipoD[0]); table.addCell("Reparado"); table.addCell("" + tipoD[1]); table.addCell("Dado de Baja"); table.addCell("" + tipoD[2]); } subCatPart.add(table); } else if (rango.equals("Dia")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (danhos.isEmpty()) { table.addCell("No hay daos en ese rango de fecha"); } else { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0; } for (int i = 0; i < danhos.size(); i++) { int P = danhos.get(i).getMat().getCodigo(); for (int k = 0; k < materiales.size(); k++) { int c = 0; if (T[k][0] == P) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c = 0; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } c1 = new PdfPCell(new Phrase("Da del mes")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Daos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); int tamY[][] = new int[32][2]; for (int i = 0; i < 32; i++) { tamY[i][0] = i; } for (int j = 0; j < 32; j++) { tamY[j][1] = 0; } for (int k = 0; k < danhos.size(); k++) { int t = danhos.get(k).getFecha_d().get(Calendar.DAY_OF_MONTH); for (int l = 0; l < 32; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 32; i++) { if (tamY[i][1] > 0) { table.addCell("" + i); table.addCell("" + tamY[i][1]); } } c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); int tipoD[] = new int[3]; for (int i = 0; i < 3; i++) { tipoD[i] = 0; } for (int k = 0; k < danhos.size(); k++) { int cont; if (danhos.get(k).getEstado() == 0) { cont = tipoD[0]; cont++; tipoD[0] = cont; } else if (danhos.get(k).getEstado() == 1) { cont = tipoD[1]; cont++; tipoD[1] = cont; } else if (danhos.get(k).getEstado() == 2) { cont = tipoD[2]; cont++; tipoD[2] = cont; } } table.addCell("Daado"); table.addCell("" + tipoD[0]); table.addCell("Reparado"); table.addCell("" + tipoD[1]); table.addCell("Dado de Baja"); table.addCell("" + tipoD[2]); } subCatPart.add(table); } else if (rango.equals("Hora")) { PdfPTable table = new PdfPTable(2); PdfPCell c1 = new PdfPCell(new Phrase("Categora Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (danhos.isEmpty()) { table.addCell("No hay daos en ese rango de fecha"); } else { int T[][] = new int[materiales.size()][2]; for (int i = 0; i < materiales.size(); i++) { T[i][0] = materiales.get(i).getCodigo(); T[i][1] = 0; } for (int i = 0; i < danhos.size(); i++) { int P = danhos.get(i).getMat().getCodigo(); for (int k = 0; k < materiales.size(); k++) { int c = 0; if (T[k][0] == P) { c = T[k][1]; c++; T[k][1] = c; k = materiales.size(); } } } ArrayList<Tipo_material> tm = tipDAO.getTipo_material(); int TM[][] = new int[tm.size()][2]; for (int i = 0; i < tm.size(); i++) { TM[i][0] = tm.get(i).getId(); TM[i][1] = 0; } for (int i = 0; i < T.length; i++) { int c = 0; Material mat = matDAO.getMaterial(T[i][0]); for (int j = 0; j < TM.length; j++) { if (TM[j][0] == mat.getTipo_mat().getId()) { c = TM[j][1]; c += T[i][1]; TM[j][1] = c; j = tm.size(); } } } for (int i = 0; i < TM.length; i++) { if (TM[i][1] > 0) { Tipo_material tip = tipDAO.getTipo_material(TM[i][0]); table.addCell("" + tip.getNombre()); table.addCell("" + TM[i][1]); } } c1 = new PdfPCell(new Phrase("Hora del da")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Daos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); int tamY[][] = new int[24][2]; for (int i = 0; i < 24; i++) { tamY[i][0] = i; } for (int j = 0; j < 24; j++) { tamY[j][1] = 0; } for (int k = 0; k < danhos.size(); k++) { Calendar cy = danhos.get(k).getFecha_d(); int t = danhos.get(k).getFecha_d().get(Calendar.HOUR_OF_DAY); for (int l = 0; l < 24; l++) { if (tamY[l][0] == t) { int cant = tamY[l][1]; cant++; tamY[l][1] = cant; } } } for (int i = 0; i < 24; i++) { if (tamY[i][1] > 0) { table.addCell("" + i); table.addCell("" + tamY[i][1]); } } c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); int tipoD[] = new int[3]; for (int i = 0; i < 3; i++) { tipoD[i] = 0; } for (int k = 0; k < danhos.size(); k++) { int cont; if (danhos.get(k).getEstado() == 0) { cont = tipoD[0]; cont++; tipoD[0] = cont; } else if (danhos.get(k).getEstado() == 1) { cont = tipoD[1]; cont++; tipoD[1] = cont; } else if (danhos.get(k).getEstado() == 2) { cont = tipoD[2]; cont++; tipoD[2] = cont; } } table.addCell("Daado"); table.addCell("" + tipoD[0]); table.addCell("Reparado"); table.addCell("" + tipoD[1]); table.addCell("Dado de Baja"); table.addCell("" + tipoD[2]); } subCatPart.add(table); } } }
From source file:sipl.recursos.GenerarPDFGrafica.java
private void createTable2(Section subCatPart) throws BadElementException { ArrayList<Multa> multas = mulDAO.getRangoFecha_multa(fecha1, fecha2); ArrayList<Usuario> usuarios = usuDAO.getUsuarios(); String codusuarios[] = new String[usuarios.size()]; int canMult[] = new int[usuarios.size()]; for (int i = 0; i < usuarios.size(); i++) { codusuarios[i] = usuarios.get(i).getCodigo(); canMult[i] = 0;//from w ww. java2 s .c om } for (int i = 0; i < multas.size(); i++) { for (int j = 0; j < usuarios.size(); j++) { if (codusuarios[j].equals(multas.get(i).getUsu().getCodigo())) { canMult[j]++; j = usuarios.size(); } } } PdfPTable table = new PdfPTable(4); PdfPCell c1 = new PdfPCell(new Phrase("Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellidos")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cantidad Multas")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); if (multas.isEmpty()) { table.addCell("No hay multas en ese rango de fecha"); } else { for (int i = 0; i < usuarios.size(); i++) { if (canMult[i] > 0) { Usuario usuario1 = usuDAO.getUsuario(codusuarios[i]); table.addCell("" + codusuarios[i]); table.addCell("" + usuario1.getNombre()); table.addCell("" + usuario1.getApellido()); table.addCell("" + canMult[i]); } } subCatPart.add(table); } }
From source file:sipl.recursos.GenerarPDFListar.java
private void createTable(Section subCatPart) { switch (Titulo) { case "Listar materiales": { ArrayList<Material> materiales = matDAO.getMateriales(); PdfPTable table = new PdfPTable(7); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from w w w .j a v a 2 s. c o m c1 = new PdfPCell(new Phrase("Tipo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Marca")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Serial")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado actual")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nro Inventario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Disp")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < materiales.size(); i++) { Material mat = materiales.get(i); table.addCell("" + mat.getCodigo()); table.addCell(mat.getTipo_mat().getNombre()); table.addCell(mat.getMarca()); table.addCell(mat.getSerial()); if (mat.getEstado() == 0) { table.addCell("Activo"); } else if (mat.getEstado() == 1) { table.addCell("Dado de Baja"); } else if (mat.getEstado() == 2) { table.addCell("Daado"); } else { table.addCell("Error"); } table.addCell(mat.getNum_inventario()); if (mat.getDisponibilidad() == 0) { table.addCell("Libre"); } else if (mat.getDisponibilidad() == 1) { table.addCell("Prestado"); } else if (mat.getDisponibilidad() == 2) { table.addCell("Reservado"); } else { table.addCell("Error"); } } subCatPart.add(table); break; } case "Listar usuarios": { ArrayList<Usuario> usuarios = usuDAO.getUsuarios(); PdfPTable table = new PdfPTable(6); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Telfono")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Correo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < usuarios.size(); i++) { Usuario usu = usuarios.get(i); table.addCell("" + usu.getCodigo()); table.addCell(usu.getNombre()); table.addCell(usu.getApellido()); table.addCell("" + usu.getTelefono()); table.addCell("" + usu.getCorreo()); if (usu.getEstado() == 0) { table.addCell("Activo"); } else if (usu.getEstado() == 1) { table.addCell("Inactivo"); } else if (usu.getEstado() == 2) { table.addCell("Con prstamo"); } else if (usu.getEstado() == 3) { table.addCell("Con reserva "); } else if (usu.getEstado() == 4) { table.addCell("Con multa"); } else { table.addCell("Error"); } } subCatPart.add(table); break; } case "Listar laboratorios": { ArrayList<Laboratorio> laboratorios = labDAO.getLaboratorios(); PdfPTable table = new PdfPTable(4); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Descripcin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Ubicacin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < laboratorios.size(); i++) { Laboratorio lab = laboratorios.get(i); table.addCell("" + lab.getCodigo()); table.addCell(lab.getNombre()); table.addCell(lab.getDescripcion()); table.addCell(lab.getUbicacion()); } subCatPart.add(table); break; } case "Listar reservas": { ArrayList<Reserva> reservas = resDAO.getReservas(); PdfPTable table = new PdfPTable(6); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo Reserva")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cdigo Materiales")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Reserva")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado Reserva")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < reservas.size(); i++) { Reserva res = reservas.get(i); if (res.getEstado() == 0) { table.addCell("" + res.getCodigo()); table.addCell(res.getUsu().getNombre()); table.addCell(res.getUsu().getApellido()); table.addCell(res.getMat()); Calendar cal1 = res.getFecha_reserva(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); if (res.getEstado() == 0) { table.addCell("Activo"); } else if (res.getEstado() == 1) { table.addCell("Inactivo"); } else { table.addCell("Error"); } } } subCatPart.add(table); break; } case "Listar multas": { ArrayList<Multa> multas = mulDAO.getMultas(); PdfPTable table = new PdfPTable(6); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Multa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado Multa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Tiempo Multa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < multas.size(); i++) { Multa mul = multas.get(i); if (mul.getEstado_multa() == 0) { table.addCell("" + mul.getUsu().getCodigo()); table.addCell(mul.getUsu().getNombre()); table.addCell(mul.getUsu().getApellido()); Calendar cal1 = mul.getFecha_multa(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); if (mul.getEstado_multa() == 0) { table.addCell("Activo"); } else if (mul.getEstado_multa() == 1) { table.addCell("Inactivo"); } else { table.addCell("Error"); } table.addCell("" + mul.getTiempo_multa()); } } subCatPart.add(table); break; } case "Listar prestamos": { ArrayList<Prestamo> prestamos = preDAO.getprestamos(); PdfPTable table = new PdfPTable(7); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo Prstamo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cdigo Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Prstamo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Devolucin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < prestamos.size(); i++) { Prestamo pre = prestamos.get(i); table.addCell("" + pre.getCodigo()); table.addCell(pre.getMat()); table.addCell(pre.getUsu().getNombre()); table.addCell(pre.getUsu().getApellido()); Calendar cal1 = pre.getFecha_prestamo(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); Calendar cal2 = pre.getFecha_devolucion(); String fecha1 = cal2.get(Calendar.YEAR) + "-"; int mes1 = cal2.get(Calendar.MONTH); mes1++; fecha1 += mes1 + "-"; fecha1 += cal2.get(Calendar.DAY_OF_MONTH); fecha1 += " " + cal2.get(Calendar.HOUR_OF_DAY); fecha1 += ":" + cal2.get(Calendar.MINUTE) + ":00"; table.addCell(fecha1); if (pre.getEstado() == 0) { table.addCell("Activo"); } else if (pre.getEstado() == 1) { table.addCell("Inactivo"); } else { table.addCell("Error"); } } subCatPart.add(table); break; } case "Listar Danho": { ArrayList<Danho> danhos = danDAO.getDanhos(); PdfPTable table = new PdfPTable(9); PdfPCell c1 = new PdfPCell(new Phrase("Descripcin Dao")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cdigo Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Descripcin Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Codigo Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellidos Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Dao")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Dao Reportado por")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < danhos.size(); i++) { Danho dan = danhos.get(i); table.addCell("" + dan.getDescripcion()); table.addCell("" + dan.getMat().getCodigo()); table.addCell(dan.getMat().getDescripcion()); table.addCell(dan.getUsu().getCodigo()); table.addCell(dan.getUsu().getNombre()); table.addCell(dan.getUsu().getApellido()); Calendar cal1 = dan.getFecha_d(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); table.addCell("" + dan.getUsu_rd().getNombre()); if (dan.getEstado() == 0) { table.addCell("Daado"); } else if (dan.getEstado() == 1) { table.addCell("Reparado"); } else if (dan.getEstado() == 2) { table.addCell("Dado de baja"); } else { table.addCell("Error"); } } subCatPart.add(table); break; } } }
From source file:sipl.recursos.GenerarPDFListarActivos.java
private void createTable(Section subCatPart) { switch (Titulo) { case "Listar materiales": { ArrayList<Material> materiales = matDAO.getMaterialesActivos(); PdfPTable table = new PdfPTable(7); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/* w ww . j av a 2 s .c om*/ c1 = new PdfPCell(new Phrase("Tipo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Marca")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Serial")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado actual")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nro Inventario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Disp")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < materiales.size(); i++) { Material mat = materiales.get(i); table.addCell("" + mat.getCodigo()); table.addCell(mat.getTipo_mat().getNombre()); table.addCell(mat.getMarca()); table.addCell(mat.getSerial()); if (mat.getEstado() == 0) { table.addCell("Activo"); } else if (mat.getEstado() == 1) { table.addCell("Dado de Baja"); } else if (mat.getEstado() == 2) { table.addCell("Daado"); } else { table.addCell("Error"); } table.addCell(mat.getNum_inventario()); if (mat.getDisponibilidad() == 0) { table.addCell("Libre"); } else if (mat.getDisponibilidad() == 1) { table.addCell("Prestado"); } else if (mat.getDisponibilidad() == 2) { table.addCell("Reservado"); } else { table.addCell("Error"); } } subCatPart.add(table); break; } case "Listar usuarios": { ArrayList<Usuario> usuarios = usuDAO.getUsuariosActivos(); PdfPTable table = new PdfPTable(6); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Telfono")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Correo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < usuarios.size(); i++) { Usuario usu = usuarios.get(i); table.addCell("" + usu.getCodigo()); table.addCell(usu.getNombre()); table.addCell(usu.getApellido()); table.addCell("" + usu.getTelefono()); table.addCell("" + usu.getCorreo()); if (usu.getEstado() == 0) { table.addCell("Activo"); } else if (usu.getEstado() == 1) { table.addCell("Inactivo"); } else if (usu.getEstado() == 2) { table.addCell("Con prstamo"); } else if (usu.getEstado() == 3) { table.addCell("Con reserva "); } else if (usu.getEstado() == 4) { table.addCell("Con multa"); } else { table.addCell("Error"); } } subCatPart.add(table); break; } case "Listar laboratorios": { ArrayList<Laboratorio> laboratorios = labDAO.getLaboratorios(); PdfPTable table = new PdfPTable(4); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Descripcin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Ubicacin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < laboratorios.size(); i++) { Laboratorio lab = laboratorios.get(i); table.addCell("" + lab.getCodigo()); table.addCell(lab.getNombre()); table.addCell(lab.getDescripcion()); table.addCell(lab.getUbicacion()); } subCatPart.add(table); break; } case "Listar reservas": { ArrayList<Reserva> reservas = resDAO.getReservasAct(); PdfPTable table = new PdfPTable(6); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo Reserva")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cdigo Materiales")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Reserva")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado Reserva")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < reservas.size(); i++) { Reserva res = reservas.get(i); if (res.getEstado() == 0) { table.addCell("" + res.getCodigo()); table.addCell(res.getUsu().getNombre()); table.addCell(res.getUsu().getApellido()); table.addCell(res.getMat()); Calendar cal1 = res.getFecha_reserva(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); if (res.getEstado() == 0) { table.addCell("Activo"); } else if (res.getEstado() == 1) { table.addCell("Inactivo"); } else { table.addCell("Error"); } } } subCatPart.add(table); break; } case "Listar multas": { ArrayList<Multa> multas = mulDAO.getMultasAct(); PdfPTable table = new PdfPTable(6); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Multa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado Multa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Tiempo Multa")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < multas.size(); i++) { Multa mul = multas.get(i); if (mul.getEstado_multa() == 0) { table.addCell("" + mul.getUsu().getCodigo()); table.addCell(mul.getUsu().getNombre()); table.addCell(mul.getUsu().getApellido()); Calendar cal1 = mul.getFecha_multa(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); if (mul.getEstado_multa() == 0) { table.addCell("Activo"); } else if (mul.getEstado_multa() == 1) { table.addCell("Inactivo"); } else { table.addCell("Error"); } table.addCell("" + mul.getTiempo_multa()); } } subCatPart.add(table); break; } case "Listar prestamos": { ArrayList<Prestamo> prestamos = preDAO.getprestamosActivos(); PdfPTable table = new PdfPTable(7); PdfPCell c1 = new PdfPCell(new Phrase("Cdigo Prstamo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cdigo Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellido Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Prstamo")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Devolucin")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < prestamos.size(); i++) { Prestamo pre = prestamos.get(i); if (pre.getEstado() == 0) { table.addCell("" + pre.getCodigo()); table.addCell(pre.getMat()); table.addCell(pre.getUsu().getNombre()); table.addCell(pre.getUsu().getApellido()); Calendar cal1 = pre.getFecha_prestamo(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); Calendar cal2 = pre.getFecha_devolucion(); String fecha1 = cal2.get(Calendar.YEAR) + "-"; int mes1 = cal2.get(Calendar.MONTH); mes1++; fecha1 += mes1 + "-"; fecha1 += cal2.get(Calendar.DAY_OF_MONTH); fecha1 += " " + cal2.get(Calendar.HOUR_OF_DAY); fecha1 += ":" + cal2.get(Calendar.MINUTE) + ":00"; table.addCell(fecha1); if (pre.getEstado() == 0) { table.addCell("Activo"); } else if (pre.getEstado() == 1) { table.addCell("Inactivo"); } else { table.addCell("Error"); } } } subCatPart.add(table); break; } case "Listar Danho": { ArrayList<Danho> danhos = danDAO.getDanhosActivos(); PdfPTable table = new PdfPTable(9); PdfPCell c1 = new PdfPCell(new Phrase("Descripcin Dao")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Cdigo Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Descripcin Material")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Codigo Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Nombre Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Apellidos Usuario")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Fecha Dao")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Dao Reportado por")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Estado")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < danhos.size(); i++) { Danho dan = danhos.get(i); table.addCell("" + dan.getDescripcion()); table.addCell("" + dan.getMat().getCodigo()); table.addCell(dan.getMat().getDescripcion()); table.addCell(dan.getUsu().getCodigo()); table.addCell(dan.getUsu().getNombre()); table.addCell(dan.getUsu().getApellido()); Calendar cal1 = dan.getFecha_d(); String fecha = cal1.get(Calendar.YEAR) + "-"; int mes = cal1.get(Calendar.MONTH); mes++; fecha += mes + "-"; fecha += cal1.get(Calendar.DAY_OF_MONTH); fecha += " " + cal1.get(Calendar.HOUR_OF_DAY); fecha += ":" + cal1.get(Calendar.MINUTE) + ":00"; table.addCell(fecha); table.addCell("" + dan.getUsu_rd().getNombre()); if (dan.getEstado() == 0) { table.addCell("Daado"); } else if (dan.getEstado() == 1) { table.addCell("Reparado"); } else if (dan.getEstado() == 2) { table.addCell("Dado de baja"); } else { table.addCell("Error"); } } subCatPart.add(table); break; } } }