List of usage examples for com.itextpdf.text.pdf PdfPCell setBorder
public void setBorder(final int border)
From source file:IPDGES.ConcentForm.java
private void formatCellBorder(PdfPCell cell, int h) { cell.setFixedHeight(h); cell.setBorder(0); }
From source file:itext_result.Main.java
private int developScreeningSheet() { new SwingWorker<Object, Object>() { String filename;/* ww w . j a va2 s. c o m*/ @Override protected void done() { // ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); } public PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException { BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(Barcode.EAN8); barcode.setCode(code); PdfPCell cell = new PdfPCell( barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true); cell.setPadding(10); return cell; } class ImageContent implements PdfPTableEvent { protected com.itextpdf.text.Image content; public ImageContent(com.itextpdf.text.Image content) { this.content = content; } public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { try { PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS]; float x = widths[3][1] + 10; float y = heights[3] - 10 - content.getScaledHeight(); content.setAbsolutePosition(x, y); canvas.addImage(content); } catch (DocumentException e) { throw new ExceptionConverter(e); } } } @Override protected Object doInBackground() throws Exception { // System.err.println(" Roll No Received ....." + rollno); Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("12345" + ".pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.A5); doc.setMargins(15f, 15f, 15f, 15f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); //DONE BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.EAN8); Barcode128 code128 = new Barcode128(); code128.setCode(String.valueOf("123456")); Barcode128 code128_jacket = new Barcode128(); code128_jacket.setCode(String.valueOf("10345")); codeEAN.setCode(String.valueOf("123456")); com.itextpdf.text.Image imageEAN = code128.createImageWithBarcode(cb, null, null); // imageEAN.scalePercent(10f); //464f, 725f // imageEAN.setAbsolutePosition(474f, 662f); int i = 1; while (i <= pageno) { doc.newPage(); // cb.addImage(imageRight); // cb.addImage(imageEAN); i++; } com.itextpdf.text.Image carcode = code128_jacket.createImageWithBarcode(cb, null, null); carcode.scaleAbsolute(100f, 35f); carcode.setAbsolutePosition(500f, 600f); writer.addDirectImageSimple(carcode); // cb.addImage(carcode); com.itextpdf.text.Image carcode2 = code128.createImageWithBarcode(cb, null, null); carcode2.scaleAbsolute(100f, 35f); carcode2.setAbsolutePosition(450f, 760f); writer.addDirectImageSimple(carcode2); // cb.addImage(carcode2); Image image1 = Image.getInstance("jklogo.gif"); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(99); table.addCell(image1); doc.add(table); table = new PdfPTable(4); table.setWidthPercentage(99); float[] columnWidths = { 6, 2 }; PdfPTable CandidateTable = new PdfPTable(columnWidths); Font f = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); Font fsmall = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); PdfPCell rollno = new PdfPCell(new Phrase("Roll No# " + String.valueOf("123456"), fsmall)); PdfPCell cname = new PdfPCell(new Phrase("Name #" + String.valueOf("John Doe"), fsmall)); // DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // String today = formatter.format(cInfo.getDob()); PdfPCell dob = new PdfPCell(new Phrase("DOB#" + String.valueOf("12-03-1989"), fsmall)); PdfPCell fname = new PdfPCell(new Phrase("F/H Name #" + String.valueOf("Big John"), fsmall)); PdfPCell type = new PdfPCell(new Phrase("Total Time #" + String.valueOf("350.00"), fsmall)); // String scrtoday = formatter.format(cInfo.getScreeningdate()); // System.out.println("Today : " + today); PdfPCell scrdate = new PdfPCell(new Phrase("Laps #" + String.valueOf("4"), fsmall)); PdfPCell cell = new PdfPCell(new Phrase(" ", fsmall)); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); dob.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); fname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); type.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); scrdate.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); CandidateTable.addCell(rollno); CandidateTable.addCell(cell); CandidateTable.addCell(cname); CandidateTable.addCell(cell); CandidateTable.addCell(dob); CandidateTable.addCell(cell); PdfPTable CandidateOtherTable = new PdfPTable(columnWidths); CandidateOtherTable.addCell(fname); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(scrdate); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(type); CandidateOtherTable.addCell(cell); PdfPCell race_start_time = new PdfPCell(new Phrase("Start Time :XX-XX-XX ", fsmall)); PdfPCell race_end_time = new PdfPCell(new Phrase("End Time :XX-XX-XX", fsmall)); PdfPCell race_total_time = new PdfPCell(new Phrase("Total Time : 350.00 ", fsmall)); race_start_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_end_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_total_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); PdfPTable CandidateRaceDetails = new PdfPTable(columnWidths); CandidateRaceDetails.addCell(race_start_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_end_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_total_time); CandidateRaceDetails.addCell(cell); PdfPTable tablewith3cells = new PdfPTable(3); //1 St Col for Roll No Name and DOB tablewith3cells.addCell(CandidateTable); //2 nd Col for Father Name sCREEning Date Gurkha tablewith3cells.addCell(CandidateOtherTable); //3rd Col for Barcode to be Printed tablewith3cells.addCell(CandidateRaceDetails); // Setting the Width here to 101 tablewith3cells.setWidthPercentage(99); doc.add(tablewith3cells); PdfPTable userArea = new PdfPTable(1); userArea.setWidthPercentage(99); userArea.addCell(" \n \n Congratulations \n \n "); doc.add(userArea); PdfPTable footerCSBC = new PdfPTable(2); footerCSBC.setWidthPercentage(99); PdfPCell height_box = new PdfPCell(new Phrase("Height \n\n\n", f)); height_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_box = new PdfPCell(new Phrase("Chest \n\n\n", f)); chest_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_exp_box = new PdfPCell(new Phrase("Chest Exp \n\n\n", f)); chest_exp_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell pushup_box = new PdfPCell(new Phrase("Pushup \n\n\n", f)); pushup_box.setBorder(com.itextpdf.text.Rectangle.BOX); //CSignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); // ASignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); footerCSBC.addCell(height_box); footerCSBC.addCell(chest_box); footerCSBC.addCell(chest_exp_box); footerCSBC.addCell(pushup_box); doc.add(footerCSBC); float[] columnWidths_ForBarcode = { 6, 3 }; PdfPTable terminalinfo = new PdfPTable(columnWidths_ForBarcode); // terminalinfo.setWidthPercentage(99); String computername = InetAddress.getLocalHost().getHostName(); System.out.println(computername); PdfPCell pcname = new PdfPCell(new Phrase("\t Jacket \n\n ", f)); String UserMatchScore = "\t Barcode\n\n"; PdfPCell score = new PdfPCell(new Phrase(UserMatchScore, f)); PdfPCell barcode = new PdfPCell(carcode2); PdfPCell jacketnumber = new PdfPCell(carcode); pcname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); score.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); barcode.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); jacketnumber.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); terminalinfo.addCell(score); terminalinfo.addCell(pcname); terminalinfo.addCell(barcode); terminalinfo.addCell(jacketnumber); doc.add(terminalinfo); PdfPCell eula_notice = new PdfPCell(new Phrase(" ", f)); eula_notice.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable eula_notice_table = new PdfPTable(1); eula_notice_table.setWidthPercentage(25); eula_notice_table.addCell(eula_notice); doc.add(eula_notice_table); } catch (Exception e) { System.err.println(e.getMessage()); // ConsoleMsg(e.getMessage()); } finally { doc.close(); doc.close(); doc.close(); } //ConsoleMsg("PDF... GENERATED"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); return 0; }
From source file:jsimpresos.ConexionCorteCaja.java
public void crearPdf(int idCorte) { try {//from w ww . ja va2 s. c om String query1 = "select * from detalleabono where idcorte=?"; PreparedStatement st = this.getConexion().prepareStatement(query1); st.setInt(1, idCorte); ResultSet rs = st.executeQuery(); ArrayList<Abono> abonos = new ArrayList(); while (rs.next()) { abonos.add(new Abono(rs.getInt(1), rs.getDouble(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getInt(6))); } String query2 = "select * from transaccionesmiembro where idcorte=?"; PreparedStatement st2 = this.getConexion().prepareStatement(query2); st2.setInt(1, idCorte); ResultSet rs2 = st2.executeQuery(); ArrayList<TransaccionesMiembro> transaccionesMiembro = new ArrayList(); while (rs2.next()) { transaccionesMiembro.add(new TransaccionesMiembro(rs2.getInt(1), rs2.getString(2), rs2.getDouble(3), rs2.getString(4), rs2.getInt(5))); } String query3 = "select * from cortesdecaja where idcorte =?"; PreparedStatement st3 = this.getConexion().prepareStatement(query3); st3.setInt(1, idCorte); ResultSet rs3 = st3.executeQuery(); String fecha = ""; while (rs3.next()) { fecha = Fechas.convertirFecha(rs3.getString(2)); } ArrayList<Abono> abonosEfectivo = new ArrayList(); ArrayList<Abono> abonosTarjeta = new ArrayList(); ArrayList<TransaccionesMiembro> recargasSaldo = new ArrayList(); ArrayList<TransaccionesMiembro> transaccionesPaypal = new ArrayList(); ArrayList<TransaccionesMiembro> registrosCliente = new ArrayList(); for (int i = 0; i < abonos.size(); i++) { String tipo = abonos.get(i).getTipoPago(); switch (tipo) { case "Efectivo": abonosEfectivo.add(abonos.get(i)); break; case "Tarjeta": abonosTarjeta.add(abonos.get(i)); break; } } for (int i = 0; i < transaccionesMiembro.size(); i++) { String tipo = transaccionesMiembro.get(i).getMovimiento(); switch (tipo) { case "Recarga": recargasSaldo.add(transaccionesMiembro.get(i)); break; case "Paypal": transaccionesPaypal.add(transaccionesMiembro.get(i)); break; case "Registro": registrosCliente.add(transaccionesMiembro.get(i)); break; } } int mayorEfectivo; if (abonosEfectivo.size() >= recargasSaldo.size() && abonosEfectivo.size() >= registrosCliente.size()) { mayorEfectivo = abonosEfectivo.size(); } else { if (recargasSaldo.size() >= registrosCliente.size()) { mayorEfectivo = recargasSaldo.size(); } else { mayorEfectivo = registrosCliente.size(); } } int mayorOtros; if (abonosTarjeta.size() >= transaccionesPaypal.size()) { mayorOtros = abonosTarjeta.size(); } else { mayorOtros = transaccionesPaypal.size(); } Document documento = new Document(); FileOutputStream ficheroPdf; try { File carpeta = new File("C:\\archivosPuntoDeVenta"); if (!carpeta.exists()) { carpeta.mkdir(); } ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/corte.pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 0, 0); documento.open(); PdfPTable tabla = new PdfPTable(8); tabla.setWidths(new float[] { 20, 10, 10, 20, 10, 10, 20, 10 }); tabla.setWidthPercentage(100); PdfPCell celdaVacia = new PdfPCell(new Paragraph(" ")); celdaVacia.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda1 = new PdfPCell(new Paragraph("Corte de caja del da " + fecha, FontFactory.getFont("Arial", 12, Font.BOLD))); celda1.setColspan(3); celda1.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda1); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda2 = new PdfPCell( new Paragraph("Transacciones en efectivo: ", FontFactory.getFont("Arial", 11, Font.BOLD))); celda2.setColspan(3); celda2.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda2); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda3 = new PdfPCell( new Paragraph("Abonos en efectivo", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda3); PdfPCell celda4 = new PdfPCell(new Paragraph("Monto", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda4); tabla.addCell(celdaVacia); PdfPCell celda5 = new PdfPCell( new Paragraph("Recargas de saldo", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda5); tabla.addCell(celda4); tabla.addCell(celdaVacia); PdfPCell celda6 = new PdfPCell( new Paragraph("Registro de clientes", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda6); tabla.addCell(celda4); double totalAbonosEfectivo = 0; double totalRecargasSaldo = 0; double totalRegistrosCliente = 0; for (int i = 0; i <= mayorEfectivo; i++) { if (abonosEfectivo.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Abono a la nota " + abonosEfectivo.get(i).getId(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + abonosEfectivo.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalAbonosEfectivo += abonosEfectivo.get(i).getMonto(); } else { if (abonosEfectivo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalAbonosEfectivo, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (recargasSaldo.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Recarga al cliente " + recargasSaldo.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + recargasSaldo.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalRecargasSaldo += recargasSaldo.get(i).getMonto(); } else { if (recargasSaldo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalRecargasSaldo, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (registrosCliente.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Registro del cliente " + registrosCliente.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + registrosCliente.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalRegistrosCliente += registrosCliente.get(i).getMonto(); } else { if (recargasSaldo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalRegistrosCliente, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } } PdfPCell celda9 = new PdfPCell(new Paragraph( "Total de pagos en efectivo: $" + (totalAbonosEfectivo + totalRecargasSaldo + totalRegistrosCliente), FontFactory.getFont("Arial", 9, Font.BOLD))); celda9.setBorder(Rectangle.NO_BORDER); celda9.setColspan(8); tabla.addCell(celda9); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda10 = new PdfPCell( new Paragraph("Otras transacciones: ", FontFactory.getFont("Arial", 11, Font.BOLD))); celda10.setColspan(3); celda10.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda10); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda11 = new PdfPCell( new Paragraph("Abonos con tarjeta", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda11); PdfPCell celda12 = new PdfPCell( new Paragraph("Monto", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda12); tabla.addCell(celdaVacia); PdfPCell celda13 = new PdfPCell( new Paragraph("Paypal", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda13); tabla.addCell(celda12); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); double totalAbonosTarjeta = 0; double totalPaypal = 0; for (int i = 0; i <= mayorOtros; i++) { if (abonosTarjeta.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Abono a la nota " + abonosTarjeta.get(i).getId(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + abonosTarjeta.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalAbonosTarjeta += abonosTarjeta.get(i).getMonto(); } else { if (abonosTarjeta.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalAbonosTarjeta, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (transaccionesPaypal.size() > i) { PdfPCell celda7 = new PdfPCell(new Paragraph( "Recarga con Paypal al cliente " + transaccionesPaypal.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + transaccionesPaypal.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalPaypal += transaccionesPaypal.get(i).getMonto(); } else { if (transaccionesPaypal.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalPaypal, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } documento.add(tabla); documento.close(); abrirPDF(); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "Error al generar el pdf"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al guardar pdf"); } } catch (SQLException ex) { System.out.println(ex.getMessage()); JOptionPane.showMessageDialog(null, "Error al conectar a la base de datos"); } }
From source file:jsimpresos.ConexionNotas.java
public void generarPdf(int idNota, String nombre, int cuenta) { Document documento = new Document(); Nota nota = this.getNotaPorId(idNota); FileOutputStream ficheroPdf;/*from ww w . j a v a2 s.com*/ try { File carpeta = new File("C:\\archivosPuntoDeVenta"); if (!carpeta.exists()) { carpeta.mkdir(); } ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 0, 0); documento.open(); Image foto = Image.getInstance("c:/archivosPuntoDeVenta/logo.JPG"); foto.scaleToFit(80, 90); PdfPTable tabla = new PdfPTable(5); tabla.setWidths(new float[] { 13, 12, 25, 25, 25 }); tabla.setWidthPercentage(100); PdfPCell celda = new PdfPCell(); celda.addElement(foto); celda.setBorder(Rectangle.NO_BORDER); celda.setRowspan(6); tabla.addCell(celda); PdfPCell celda2 = new PdfPCell( new Paragraph("NOTA DE PEDIDO", FontFactory.getFont("Arial", 15, Font.BOLD))); System.out.println(nota.getUsuario()); celda2.setColspan(3); celda2.setUseAscender(true); celda2.setBorder(Rectangle.NO_BORDER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); tabla.addCell(celda2); PdfPCell celdaFecha = new PdfPCell(new Paragraph("Fecha: " + nota.getFecha())); celdaFecha.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdaFecha); PdfPCell celda3 = new PdfPCell(new Phrase("Calle del Rayo y 2 de Abril 31a. Col. centro, Parral, Chih.", FontFactory.getFont("Arial", 7, Font.BOLD, BaseColor.RED))); celda3.setColspan(2); celda3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda3); PdfPCell celda4 = new PdfPCell(new Phrase("Tel. 5230073 y 6271034745", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.RED))); celda4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda4); Paragraph p = new Paragraph("No. " + nota.getIdNota(), FontFactory.getFont("Arial", 13, Font.BOLD, BaseColor.RED)); PdfPCell celda5 = new PdfPCell(); celda5.setUseAscender(true); celda5.setVerticalAlignment(Element.ALIGN_MIDDLE); celda5.setHorizontalAlignment(Element.ALIGN_MIDDLE); celda5.addElement(p); tabla.addCell(celda5); PdfPCell celdanueva = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva.setBorder(Rectangle.NO_BORDER); celdanueva.setColspan(4); tabla.addCell(celdanueva); PdfPCell celdanueva1 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva1.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva1); PdfPCell celdanueva2 = new PdfPCell( new Phrase("Datos del cliente", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva2.setBorder(Rectangle.NO_BORDER); celdanueva2.setColspan(3); tabla.addCell(celdanueva2); PdfPCell celdanueva3 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva3); if (nota.getCliente() == null) { PdfPCell celda6 = new PdfPCell( new Phrase("Cliente: " + nota.getNombres() + " " + nota.getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } else { PdfPCell celda6 = new PdfPCell(new Phrase( "Cliente: " + nota.getCliente().getNombres() + " " + nota.getCliente().getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getCliente().getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getCliente().getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } PdfPTable tabla2 = new PdfPTable(4); tabla2.setWidths(new float[] { 10, 70, 15, 15 }); tabla2.setWidthPercentage(99.5f); PdfPCell celda21 = new PdfPCell( new Phrase("Cantidad", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda21); PdfPCell celda22 = new PdfPCell( new Phrase("Artculo", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda22); PdfPCell celda23 = new PdfPCell( new Phrase("Precio unitario", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda23); PdfPCell celda24 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda24); double total = 0; for (int i = 0; i < 6; i++) { if (i < nota.getArticulos().size()) { PdfPCell celda25 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getCantidad() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda25); PdfPCell celda26 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getServicio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda26); PdfPCell celda27 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getPrecio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda27); PdfPCell celda28 = new PdfPCell(new Phrase( (nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio()) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda28); total += nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio(); } else { PdfPCell celda29 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); } } PdfPTable tabla3 = new PdfPTable(4); tabla3.setWidths(new float[] { 55, 25, 15, 15 }); tabla3.setWidthPercentage(99.5f); PdfPCell celda31 = new PdfPCell(new Phrase("Observaciones: " + nota.getObservaciones(), FontFactory.getFont("Arial", 9, BaseColor.BLACK))); celda31.setRowspan(4); tabla3.addCell(celda31); PdfPCell celda32 = new PdfPCell(new Phrase( "Suma recibida de abono : " + nota.getAbonos().get(nota.getAbonos().size() - 1).getMonto(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda32.setRowspan(4); tabla3.addCell(celda32); PdfPCell celda33 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda33); PdfPCell celda34 = new PdfPCell( new Phrase(total + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda34); PdfPCell celda35 = new PdfPCell( new Phrase("Total abonado", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda35); double totalAbonado = 0; for (int i = 0; i < nota.getAbonos().size(); i++) { totalAbonado += nota.getAbonos().get(i).getMonto(); } PdfPCell celda36 = new PdfPCell( new Phrase(totalAbonado + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda36); PdfPCell celda37 = new PdfPCell( new Phrase("Saldo actual", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda37); PdfPCell celda38 = new PdfPCell(new Phrase((total - totalAbonado) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda38); PdfPCell celda39 = new PdfPCell( new Phrase("Fecha entrega", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda39); PdfPCell celda40 = new PdfPCell(new Phrase(nota.getFechaEntrega(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda40); PdfPTable tabla4 = new PdfPTable(3); tabla4.setWidths(new float[] { 30, 30, 30 }); tabla4.setWidthPercentage(99.5f); PdfPCell celda41 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda41.setBorder(Rectangle.NO_BORDER); celda41.setColspan(3); tabla4.addCell(celda41); PdfPCell celda42 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda42.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda42); PdfPCell celda43 = new PdfPCell(new Phrase("Firma de conformidad del cliente: ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda43.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda43); PdfPCell celda44 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda44.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda44); tabla4.addCell(celda41); tabla4.addCell(celda41); tabla4.addCell(celda41); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.close(); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (FileNotFoundException ex) { // JOptionPane.showMessageDialog(null, "Error con el pdf"); // System.out.println(ex.getMessage()); cuenta++; generarPdf(idNota, "nota", cuenta); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al guardar pdf"); System.out.println(ex.getMessage()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error con el pdf"); } }
From source file:lk.score.androphsy.report.ReportPdf.java
License:Open Source License
private void createTableRowFormat(Paragraph preface, String feature) { try {/*from w w w .jav a 2 s.c o m*/ String query = ""; Connection conn = new ConnectDb().getConnection(); Statement stmt = conn.createStatement(); if (feature == "CaseInfo") { query = "SELECT case_id AS 'Case ID', case_name AS 'Case Name', investigator_id AS 'Investigatort', IFNULL(analyst_id, '') as 'Analyst' " + "FROM Androspy_Case " + "WHERE case_id = " + AndrospyMain.gb_CaseId; } else if (feature == "DeviceBasicInfo") { query = "SELECT IFNULL(device_name, '') AS 'Device Name', IFNULL(model, '') AS 'Model', IFNULL(manufacturer, '') AS 'Manufacturer', IFNULL(os, '') AS OS, IFNULL(build_number, '') AS 'Build Number', IFNULL(sw_number, '') AS 'Software Number', IFNULL(serial_no,'') As 'Serial No'" + " FROM Androspy_Device" + " WHERE case_id = " + AndrospyMain.gb_CaseId + " AND device_id = " + AndrospyMain.gb_DeviceId; } System.out.println(query); ResultSet rs = stmt.executeQuery(query); ResultSetMetaData rsmeta = rs.getMetaData(); int colcount = rsmeta.getColumnCount(); PdfPTable pdftable = new PdfPTable(2); while (rs.next()) { for (int i = 1; i <= colcount; i++) { String value = rs.getString(i).equals(null) ? "" : rs.getString(i); PdfPCell c1 = new PdfPCell(new Phrase(rsmeta.getColumnLabel(i) + ":")); PdfPCell c2 = new PdfPCell(new Phrase(value)); c1.setBorder(Rectangle.NO_BORDER); c2.setBorder(Rectangle.NO_BORDER); pdftable.addCell(c1); pdftable.addCell(c2); } } preface.add(pdftable); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Login.ventas.fproyectos.java
/** * Creates new form cliente/*from ww w . j a va 2 s .c o m*/ * @param user */ public fproyectos(Login user) { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); @SuppressWarnings("MismatchedReadAndWriteOfArray") String[] fecha = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }; initComponents(); Calendar rightNow = Calendar.getInstance(); int ccyy = rightNow.get(Calendar.YEAR); int month = rightNow.get(Calendar.MONTH); setSize(d.width, d.height - 95); this.usuario = user; add(f); f.setLocation(jPanel1.getX(), jPanel1.getY()); add(f3); f3.setLocation(jPanel1.getX(), jPanel1.getY()); add(f4); f4.setLocation(jPanel1.getX(), jPanel1.getY()); add(f5); f5.setLocation(jPanel1.getX(), jPanel1.getY()); add(f2); f2.setLocation(jPanel1.getX(), jPanel1.getY()); f2.getjButton1().addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { ServiceHb helper = new ServiceHb(); helper.iniciarTransaccion(); Fcomisiones fc = helper.getFcomisiones(idcliente, idinstalacion); if (helper.getFcomisiones(idcliente, idinstalacion) == null) { fc = new Fcomisiones(); Calendar d = Calendar.getInstance(); fc.setFecha(new java.sql.Date(d.getTime().getTime())); fc.setClientes( (Clientes) helper.obtenerObjeto(Clientes.class, Integer.parseInt(idcliente))); fc.setInstalacion((Instalacion) helper.obtenerObjeto(Instalacion.class, Integer.parseInt(idinstalacion))); fc.setRentabilidad(f2.getjLabel20().getText()); fc.setValor1(f2.getjLabel11().getText().substring(2, f2.getjLabel11().getText().length())); fc.setValor2(f2.getjLabel2().getText().substring(3, f2.getjLabel2().getText().length())); fc.setDiferido(f2.getjLabel4().getText()); fc.setDias(numeroinstala); helper.crearObjeto(fc); helper.confirmarTransaccion(); helper.cerrarSesion(); JOptionPane.showMessageDialog(null, "Comision prepara con fecha " + Funcion.DateFormatSql(d.getTime())); } else { Calendar d = Calendar.getInstance(); fc.setFecha(new java.sql.Date(d.getTime().getTime())); fc.setRentabilidad(f2.getjLabel20().getText()); fc.setValor1(f2.getjLabel11().getText().substring(2, f2.getjLabel11().getText().length())); fc.setValor2(f2.getjLabel2().getText().substring(3, f2.getjLabel2().getText().length())); fc.setDiferido(f2.getjLabel4().getText()); fc.setDias(numeroinstala); helper.actualizarObjeto(fc); helper.confirmarTransaccion(); helper.cerrarSesion(); JOptionPane.showMessageDialog(null, "Actualizado / Comision prepara con fecha " + Funcion.DateFormatSql(d.getTime())); } } catch (Exception io) { System.out.println(io); } } }); f2.getjButton2().addMouseListener(new java.awt.event.MouseAdapter() { @Override @SuppressWarnings("UseSpecificCatch") public void mouseClicked(MouseEvent e) { float ancho = 0; try { Document documento = new Document(PageSize.A4, 0, 0, 0, 0); ancho = documento.getPageSize().getWidth() - 100; FileOutputStream ficheroPdf; PdfWriter writer = null; PdfWriter writer2 = null; String direccion = ""; Calendar now2 = Calendar.getInstance(); try { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //Mostrar la ventana para abrir archivo y recoger la respuesta //En el parmetro del showOpenDialog se indica la ventana // al que estar asociado. Con el valor this se asocia a la // ventana que la abre. int respuesta = chooser.showOpenDialog(null); String cadena = ""; if (respuesta == JFileChooser.APPROVE_OPTION) { direccion = chooser.getSelectedFile().getAbsolutePath(); } Calendar d = Calendar.getInstance(); ficheroPdf = new FileOutputStream(direccion + "/" + idcliente + idinstalacion + ".pdf"); writer = PdfWriter.getInstance(documento, ficheroPdf); } catch (IOException ex) { System.out.println(ex.toString()); } ServiceHb helper = null; try { List<Productos> lt = null; helper = new ServiceHb(); helper.iniciarTransaccion(); PdfPTable tabla; PdfPCell casilla; PdfPTable salto = null; PdfPCell celda; Font fontpersonalizado = FontFactory.getFont("ARIAL", 7, Font.BOLD); Font fontpersonalizado2 = FontFactory.getFont("ARIAL", 7, Font.NORMAL); documento.open(); PdfContentByte canvas = writer.getDirectContent(); fondos(documento, canvas); //Materiales double total = 0; double total2 = 0; double total3 = 0; double total4 = 0; double total5 = 0; tabla = new PdfPTable(6); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); celda = new PdfPCell(new Paragraph("ADQUISICION DE MATERIALES")); celda.setColspan(6); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); float pagina = documento.getPageSize().getHeight() - 140; final float max = pagina; pagina = pagina - tabla.getRow(0).calculateHeights(); if (ltart != null) { Object nuevo2[] = { "FECHA", "DETALLE", "CANT.", "PRECIO", "SUBTOTAL", "TOTAL DIARIO" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; double diario = 0; int turno = 0; for (int i = 0; i < ltart.size(); i++) { turno = 0; fact = helper.getFacturafecha(ltart.get(i).getIdfactura()); String fecha = ""; if (fact != null) { fecha = Funcion.DateFormatSql(fact.getFecha()); } if ((i + 1) == ltart.size()) { diario = diario + Double.parseDouble(ltart.get(i).getTotal()); turno = 1; } else { fact2 = helper.getFacturafecha(ltart.get(i + 1).getIdfactura()); String fecha2 = ""; if (fact2 != null) { fecha2 = Funcion.DateFormatSql(fact2.getFecha()); if (fecha.equalsIgnoreCase(fecha2)) { diario = diario + Double.parseDouble(ltart.get(i).getTotal()); } else { diario = diario + Double.parseDouble(ltart.get(i).getTotal()); turno = 1; } } } String uni = "$ " + df.format(Double.parseDouble(ltart.get(i).getUnitario())) .replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(ltart.get(i).getTotal())).replace(",", "."); total = total + Double.parseDouble(ltart.get(i).getTotal()); if (turno == 0) { Object nuevo[] = { fecha, ltart.get(i).getDescripcion(), ltart.get(i).getCantidad(), uni, tot, "" }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); if (((String) obj).equalsIgnoreCase("")) { celda.setBorder(Rectangle.RIGHT); } celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } } else { Object nuevo[] = { fecha, ltart.get(i).getDescripcion(), ltart.get(i).getCantidad(), uni, tot, "$ " + df.format(diario).replace(",", ".") }; int va = 0; for (Object obj : nuevo) { va++; celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); if (va == 5) { celda.setBorder(Rectangle.BOTTOM); } celda.setColspan(1); celda.setBorderColor(new Color(195, 195, 195)); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } diario = 0; } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 11) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(6); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); pagina = max; tam = 0; } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell( new Paragraph("Adquisicin de Materiales", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(4); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); /*Parte 2*/ tabla = new PdfPTable(4); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1, 1 }); celda = new PdfPCell(new Paragraph("MANO DE OBRA TECNICOS")); celda.setColspan(4); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "CANT.", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; double diario = 0; int turno = 0; for (Ctepagar list1 : list) { if (list1.getDetalle().contains("ci:")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String[] cadena = desc.split(" "); String result = ""; int contador = 0; for (String n : cadena) { if (n.contains("ci:")) { result = result + ", "; contador++; } else { result = result + n + " "; } } result = result.substring(0, result.length() - 2); String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total2 = total2 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, result, "" + contador, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 90) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado2))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(4); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Mano de Obra Tcnicos", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(2); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total2).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph("TRANSPORTE")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; for (Ctepagar list1 : list) { if (list1.getDetalle().contains("Transporte")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String result = ""; String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total3 = total3 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, desc, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 50) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado2))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Transporte", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total3).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph("COMBUSTIBLE")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; for (Ctepagar list1 : list) { if (list1.getDetalle().contains("Combustible")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String result = ""; String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total4 = total4 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, desc, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 50) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Combustible", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total4).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); //Extras tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph("EXTRAS")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); if (list != null) { Object nuevo2[] = { "FECHA", "DETALLE", "SUBTOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(1).calculateHeights(); int tam = 0; for (Ctepagar list1 : list) { if (!list1.getDetalle().contains("Combustible") && !list1.getDetalle().contains("ci:") && !list1.getDetalle().contains("Transporte")) { String fecha = list1.getFecha(); String desc = list1.getDetalle(); String result = ""; String uni = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); String tot = "$ " + df.format(Double.parseDouble(list1.getValor())).replace(",", "."); total5 = total5 + Double.parseDouble(list1.getValor()); Object nuevo[] = { fecha, desc, tot }; for (Object obj : nuevo) { celda = new PdfPCell( new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } pagina = pagina - tabla.getRow(tam).getMaxHeights(); tam++; if (pagina < 50) { salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); documento.newPage(); fondos(documento, canvas); tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); pagina = max; tam = 0; } } } } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); celda = new PdfPCell(new Paragraph("Total", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Extra", new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("$ " + df.format(total5).replace(",", "."), new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); documento.add(tabla); documento.newPage(); fondos(documento, canvas); //Final Vendedor tabla = new PdfPTable(3); tabla.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); tabla.setTotalWidth(ancho); tabla.setLockedWidth(true); tabla.setWidths(new int[] { 1, 3, 1 }); celda = new PdfPCell(new Paragraph(nombrecliente)); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Paragraph("Venta")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_LEFT); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); pagina = documento.getPageSize().getHeight() - 140; pagina = pagina - tabla.getRow(0).calculateHeights(); Object nuevo2[] = { "FECHA", "DETALLE", "TOTAL" }; for (Object obj : nuevo2) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo3[] = { "", nombreinstalacion, totalinstalacion }; for (Object obj : nuevo3) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorderColor(new Color(195, 195, 195)); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } celda = new PdfPCell(new Paragraph("INVERSION", new Font(fontpersonalizado))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); Object nuevo4[] = { "Uso de Materiales", "", "$ " + df.format(total).replace(",", ".") }; for (Object obj : nuevo4) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo5[] = { "Mano de obra tcnicos", "", "$ " + df.format(total2).replace(",", ".") }; for (Object obj : nuevo5) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo6[] = { "Transporte", "", "$ " + df.format(total3).replace(",", ".") }; for (Object obj : nuevo6) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo7[] = { "Combustible", "", "$ " + df.format(total4).replace(",", ".") }; for (Object obj : nuevo7) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo71[] = { "Extras", "", "$ " + df.format(total5).replace(",", ".") }; for (Object obj : nuevo71) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo8[] = { "Total Inversin", "", "$ " + df.format(total + total2 + total3 + total4).replace(",", ".") }; for (Object obj : nuevo8) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado2))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } celda = new PdfPCell(new Paragraph("")); celda.setColspan(3); celda.setHorizontalAlignment(Element.ALIGN_LEFT); celda.setBorder(PdfPCell.NO_BORDER); tabla.addCell(celda); Object nuevo9[] = { "Utilidad del proyecto", "", "$ " + df.format(proyectoval - total - total2 - total3 - total4).replace(",", ".") }; for (Object obj : nuevo9) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setColspan(1); celda.setBorder(PdfPCell.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } Object nuevo10[] = { "Rentabilidad ", "", df.format(porcent).replace(",", ".") + " %" }; for (Object obj : nuevo10) { celda = new PdfPCell(new Paragraph((String) obj, new Font(fontpersonalizado))); celda.setBorder(PdfPCell.NO_BORDER); celda.setColspan(1); celda.setHorizontalAlignment(Element.ALIGN_CENTER); tabla.addCell(celda); } salto = new PdfPTable(1); casilla = new PdfPCell(new Phrase("", new Font(fontpersonalizado))); casilla.setMinimumHeight(90); casilla.setBorder(PdfPCell.NO_BORDER); salto.addCell(casilla); documento.add(salto); documento.add(tabla); /*Fin Parte 3*/ documento.close(); helper.cerrarSesion(); } catch (Exception ex) { documento.close(); } JOptionPane.showMessageDialog(null, "PDF Generado"); } catch (Exception io) { System.out.println(io); } } }); f.getjTable1().addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int row = f.getjTable1().getSelectedRow(); int col = f.getjTable1().getSelectedColumn(); if (col == 4) { f2.setVisible(true); f.setVisible(false); idcliente = f.getjTable1().getValueAt(row, 5).toString(); idinstalacion = f.getjTable1().getValueAt(row, 6).toString(); f2.getjLabel15().setText(f.getjTable1().getValueAt(row, 0).toString()); f2.getjLabel8().setText(f.getjTable1().getValueAt(row, 2).toString()); nombrecliente = f.getjTable1().getValueAt(row, 0).toString(); nombreinstalacion = f.getjTable1().getValueAt(row, 2).toString(); updateTablas up = new updateTablas(1); up.start(); } } }); f5.getjComboBox1().addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { DefaultTableModel temp2 = (DefaultTableModel) f5.getjTable2().getModel(); for (int i = temp2.getRowCount() - 1; i >= 0; i--) { temp2.removeRow(i); } f5.setComi(null); f5.setNinstalacion(""); f5.setNcliente(""); f5.setList(null); f5.setId(""); updateTablas up = new updateTablas(4); up.start(); } }); f3.getjTable1().addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int row = f3.getjTable1().getSelectedRow(); int col = f3.getjTable1().getSelectedColumn(); if (col == 6) { visible(f4); fcomisiones = f3.getjTable1().getValueAt(row, 6).toString(); try { ServiceHb helper = new ServiceHb(); helper.iniciarTransaccion(); Fcomisiones ft = (Fcomisiones) helper.obtenerObjeto(Fcomisiones.class, Integer.parseInt(fcomisiones)); numeroinstala = ft.getDias(); f4.setIdcliente("" + ft.getClientes().getId()); f4.setIdinstalacion("" + ft.getInstalacion().getId()); f4.getDiasint().setText(numeroinstala); helper.cerrarSesion(); } catch (Exception io) { } f4.getjLabel1().setText(fcomisiones); f4.getC1().setText(f3.getjTable1().getValueAt(row, 0).toString()); f4.getC2().setText(f3.getjTable1().getValueAt(row, 1).toString()); double campo1 = Double .parseDouble(f3.getjTable1().getValueAt(row, 3).toString().replace("$ ", "")); double campo2 = Double .parseDouble(f3.getjTable1().getValueAt(row, 4).toString().replace("-$ ", "")); f4.getC3().setText(f3.getjTable1().getValueAt(row, 3).toString()); f4.getC4().setText(f3.getjTable1().getValueAt(row, 4).toString()); f4.getC5().setText(f3.getjTable1().getValueAt(row, 5).toString()); f4.getC6().setText("$ " + df.format((campo1 - campo2)).replace(",", ".")); updateTablas up = new updateTablas(3); up.start(); } } }); setVisible(false); }
From source file:ManagementPackage.ServiceEnd.java
private void txtDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoneActionPerformed // TODO add your handling code here: Document doc = new Document(); try {/*from w w w. ja v a2s . co m*/ long time = new Date().getTime(); TransNo = "" + time; PdfWriter.getInstance(doc, new FileOutputStream("Invoices\\Invoices" + time + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(4); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Invoice/Money Receipt\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Paragraph("Transaction No: " + time, FontFactory.getFont(null, 10))); cell3.setColspan(2); cell3.setPaddingBottom(10); cell3.setPaddingTop(10); cell3.setBorder(2); cell3.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell3); PdfPCell cell4 = new PdfPCell( new Paragraph("Date: " + formatedDateTime, FontFactory.getFont(null, 10))); cell4.setColspan(3); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); //table.addCell("Sl No"); table.addCell("Product Name"); table.addCell("Rate"); table.addCell("Qty"); table.addCell("Amount (TK)"); String query = "select product_name, rate, qty, amount from temp_trans WHERE trans_by = '" + user + "'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { //String sl_no = rs.getString("sl_no"); String product_name = rs.getString("product_name"); String rate = rs.getString("rate"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); //table.addCell(sl_no); table.addCell(product_name); table.addCell(rate); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph(txtTotal.getText())); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph(txtAdjust.getText())); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Billed By: " + user)); celltxtTotalPaid.setColspan(2); //celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid0 = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid0.setColspan(1); celltxtTotalPaid0.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid0); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph(txtTotalPaid.getText())); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); savePermanently(); clearTempTable(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Invoices\\Invoices" + time + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ManagementPackage.Setting.java
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed // TODO add your handling code here: totalAdjustment = 0;//from w ww. j a va 2s .c o m totalTotalPaid = 0; total = 0; Document doc = new Document(); try { long time = new Date().getTime(); PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Daily" + time + " " + formatedDate + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(5); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Daily Report\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime)); cell4.setColspan(10); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); table.addCell("Transaction No"); table.addCell("Billed By"); table.addCell("Product Name"); table.addCell("Qty"); table.addCell("Amount (TK)"); String PrevTransNo = " "; String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date = '" + formatedDate + "'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { String NewTransNo = rs.getString("trans_no"); String product_name = rs.getString("product_name"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); String trans_by = rs.getString("trans_by"); total = total + Float.parseFloat(amount); if (PrevTransNo.equals(NewTransNo)) table.addCell(" "); else { table.addCell(NewTransNo); String query1 = "select adjustment, total_paid from paid_amount where trans_no = '" + NewTransNo + "'"; pst1 = con1.prepareStatement(query1); rs1 = pst1.executeQuery(); String adjustment = rs1.getString("adjustment"); String total_paid = rs1.getString("total_paid"); totalAdjustment = totalAdjustment + Float.parseFloat(adjustment); totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid); rs1.close(); pst1.close(); } PrevTransNo = rs.getString("trans_no"); table.addCell(trans_by); table.addCell(product_name); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total)); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment)); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid.setColspan(3); celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid)); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Reports\\Daily" + time + " " + formatedDate + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ManagementPackage.Setting.java
private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed // TODO add your handling code here: totalAdjustment = 0;/* w w w .ja v a 2 s . c o m*/ totalTotalPaid = 0; total = 0; Document doc = new Document(); try { long time = new Date().getTime(); PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Monthly" + time + " " + formatedDate + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(5); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Monthly Report\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime)); cell4.setColspan(10); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); table.addCell("Transaction No"); table.addCell("Billed By"); table.addCell("Product Name"); table.addCell("Qty"); table.addCell("Amount (TK)"); String PrevTransNo = " "; String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%" + month + "%'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { String NewTransNo = rs.getString("trans_no"); String product_name = rs.getString("product_name"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); String trans_by = rs.getString("trans_by"); total = total + Float.parseFloat(amount); if (PrevTransNo.equals(NewTransNo)) table.addCell(" "); else { table.addCell(NewTransNo); String query1 = "select adjustment, total_paid from paid_amount where trans_no = '" + NewTransNo + "'"; pst1 = con1.prepareStatement(query1); rs1 = pst1.executeQuery(); String adjustment = rs1.getString("adjustment"); String total_paid = rs1.getString("total_paid"); totalAdjustment = totalAdjustment + Float.parseFloat(adjustment); totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid); rs1.close(); pst1.close(); } PrevTransNo = rs.getString("trans_no"); table.addCell(trans_by); table.addCell(product_name); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total)); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment)); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid.setColspan(3); celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid)); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Reports\\Monthly" + time + " " + formatedDate + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ManagementPackage.Setting.java
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed // TODO add your handling code here: totalAdjustment = 0;// ww w .j a va 2s. co m totalTotalPaid = 0; total = 0; Document doc = new Document(); try { long time = new Date().getTime(); PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Yearly" + time + " " + formatedDate + ".pdf")); doc.open(); PdfPTable table = new PdfPTable(5); PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n", FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE))); cell1.setColspan(10); cell1.setPadding(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setBackgroundColor(BaseColor.BLACK); table.addCell(cell1); PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n")); cell21.setColspan(10); cell21.setBorder(2); cell21.setBorderColorLeft(BaseColor.WHITE); table.addCell(cell21); PdfPCell cell2 = new PdfPCell(new Paragraph("Yearly Report\n")); cell2.setColspan(10); cell2.setPadding(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell2); PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime)); cell4.setColspan(10); cell4.setPaddingBottom(10); cell4.setPaddingTop(10); cell4.setBorder(2); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); cell4.setBorderColorRight(BaseColor.WHITE); table.addCell(cell4); table.addCell("Transaction No"); table.addCell("Billed By"); table.addCell("Product Name"); table.addCell("Qty"); table.addCell("Amount (TK)"); String PrevTransNo = " "; String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%" + year + "%'"; try { pst = con.prepareStatement(query); rs = pst.executeQuery(); while (rs.next()) { String NewTransNo = rs.getString("trans_no"); String product_name = rs.getString("product_name"); String qty = rs.getString("qty"); String amount = rs.getString("amount"); String trans_by = rs.getString("trans_by"); total = total + Float.parseFloat(amount); if (PrevTransNo.equals(NewTransNo)) table.addCell(" "); else { table.addCell(NewTransNo); String query1 = "select adjustment, total_paid from paid_amount where trans_no = '" + NewTransNo + "'"; pst1 = con1.prepareStatement(query1); rs1 = pst1.executeQuery(); String adjustment = rs1.getString("adjustment"); String total_paid = rs1.getString("total_paid"); totalAdjustment = totalAdjustment + Float.parseFloat(adjustment); totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid); rs1.close(); pst1.close(); } PrevTransNo = rs.getString("trans_no"); table.addCell(trans_by); table.addCell(product_name); table.addCell(qty); PdfPCell cellAmount = new PdfPCell(new Paragraph(amount)); cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellAmount); } rs.close(); pst.close(); } catch (SQLException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell cellb = new PdfPCell(new Paragraph(" ")); cellb.setColspan(10); cellb.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cellb); // PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total")); celltxtTotal.setColspan(3); celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal); PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total)); celltxtTotal1.setColspan(2); celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotal1); PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment")); celltxtAdjust.setColspan(3); celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust); PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment)); celltxtAdjust1.setColspan(2); celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtAdjust1); PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid")); celltxtTotalPaid.setColspan(3); celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid); PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid)); celltxtTotalPaid1.setColspan(2); celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(celltxtTotalPaid1); doc.add(table); doc.close(); //JOptionPane.showMessageDialog(null, "Report Created!"); // open PDF file File file = new File("Reports\\Yearly" + time + " " + formatedDate + ".pdf"); if (file.toString().endsWith(".pdf")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file); else { Desktop desktop = Desktop.getDesktop(); desktop.open(file); } } catch (DocumentException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex); } }