List of usage examples for com.lowagie.text Document open
boolean open
To view the source code for com.lowagie.text Document open.
Click Source Link
From source file:jm.Reporte.java
License:GNU General Public License
public void liquidaciones(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros, DataBase objDB) { //int sumarDesde = 6; //int num_sumas = cabTabla.length - sumarDesde; float sumas[] = new float[5]; float valor = 0; /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {//from ww w . j a v a2 s .com PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; String id_liquidacion_compra = ""; try { while (registros.next()) { tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 2; i <= 6; i++) { tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } valor = (registros.getString("subtotal") != null) ? registros.getFloat("subtotal") : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[0] = Float.parseFloat(this.formatoNumero.format(sumas[0])) + valor; valor = (registros.getString("subtotal_0") != null) ? registros.getFloat("subtotal_0") : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[1] = Float.parseFloat(this.formatoNumero.format(sumas[1])) + valor; valor = (registros.getString("iva_2") != null) ? registros.getFloat("iva_2") : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[2] = Float.parseFloat(this.formatoNumero.format(sumas[2])) + valor; id_liquidacion_compra = (registros.getString("id_liquidacion_compra") != null) ? registros.getString("id_liquidacion_compra") : ""; valor = 0; try { ResultSet rs = objDB.consulta( "select ret_impuesto_retenido from tbl_retencion_compra where id_factura_compra=" + id_liquidacion_compra + " and documento='l'"); if (rs.next()) { valor = (rs.getString("ret_impuesto_retenido") != null) ? rs.getFloat("ret_impuesto_retenido") : 0; rs.close(); } } catch (Exception e) { e.printStackTrace(); } tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[3] = Float.parseFloat(this.formatoNumero.format(sumas[3])) + valor; valor = (registros.getString("total_compra") != null) ? registros.getFloat("total_compra") : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[4] = Float.parseFloat(this.formatoNumero.format(sumas[4])) + valor; num++; } tbl_det.addCell(Addons.setCeldaPDF("TOTALES: ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, 6)); for (int j = 0; j < sumas.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(sumas[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void notasVenta(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros, DataBase objDB) {//from w w w. j a va2s . com //int sumarDesde = 6; //int num_sumas = cabTabla.length - sumarDesde; float sumas[] = new float[2]; float valor = 0; /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try { PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; String id_nota_venta_compra = ""; try { while (registros.next()) { tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 2; i <= 6; i++) { tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } id_nota_venta_compra = (registros.getString("id_nota_venta_compra") != null) ? registros.getString("id_nota_venta_compra") : ""; valor = 0; try { ResultSet rs = objDB.consulta( "select ret_impuesto_retenido from tbl_retencion_compra where id_factura_compra=" + id_nota_venta_compra + " and documento='v'"); if (rs.next()) { valor = (rs.getString("ret_impuesto_retenido") != null) ? rs.getFloat("ret_impuesto_retenido") : 0; rs.close(); } } catch (Exception e) { e.printStackTrace(); } tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[0] = Float.parseFloat(this.formatoNumero.format(sumas[0])) + valor; valor = (registros.getString("total_compra") != null) ? registros.getFloat("total_compra") : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[1] = Float.parseFloat(this.formatoNumero.format(sumas[1])) + valor; num++; } tbl_det.addCell(Addons.setCeldaPDF("TOTALES: ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, 6)); for (int j = 0; j < sumas.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(sumas[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void cierreCaja(HttpServletResponse response, int id_sucursal_sesion, String fecha, DataBase objDB) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {//ww w. j a v a 2s . c om PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); ResultSet ventas = objDB.consulta( "select vendedor,txt_forma_pago,sum(total) as total from vta_factura_venta where id_sucursal=" + id_sucursal_sesion + " and anulado=false and fecha_emision='" + fecha + "' group by vendedor,txt_forma_pago order by vendedor"); ResultSet retencion = null; PdfPTable tbl_det = new PdfPTable(new float[] { 70f, 40f, 120f }); try { String aux = ""; float ingresos = 0; float total_ingresos = 0; float efectivo = 0; float total_efectivo = 0; float ret = 0; float total_ret = 0; String vendedor = ""; String forma_pago = ""; float total = 0; tbl_det.addCell(Addons.setCeldaPDF("VENTAS", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, Color.cyan, 3, 3)); while (ventas.next()) { vendedor = ventas.getString("vendedor") != null ? ventas.getString("vendedor") : ""; forma_pago = ventas.getString("txt_forma_pago") != null ? ventas.getString("txt_forma_pago") : ""; total = ventas.getString("total") != null ? ventas.getFloat("total") : 0; if (aux.compareTo(vendedor) != 0) { if (aux.compareTo("") != 0) { tbl_det.addCell(Addons.setCeldaPDF(" TOTAL ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(ingresos), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" EN CAJA ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(efectivo - ret), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF( "___________________________________________________________________________________________________________", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0, 0, 3)); } tbl_det.addCell(Addons.setCeldaPDF(vendedor, Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 4, 3)); /* retenciones */ try { retencion = objDB.consulta( "select sum(R.ret_impuesto_retenido) as total from tbl_factura_venta as F inner join tbl_retencion_venta as R " + "on R.id_factura_venta=F.id_factura_venta where id_sucursal=" + id_sucursal_sesion + " and F.anulado=false and R.anulado=false and F.vendedor='" + vendedor + "' and ret_fecha_emision='" + fecha + "'"); if (retencion.next()) { ret = retencion.getString("total") != null ? retencion.getFloat("total") : 0; tbl_det.addCell(Addons.setCeldaPDF(" RETENCIONES ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(ret), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); ingresos += ret; total_ret += ret; } } catch (Exception ex) { } aux = vendedor; ingresos = 0; efectivo = 0; } ingresos += total; total_ingresos += total; if (forma_pago.compareTo("EFECTIVO") == 0) { efectivo += total; total_efectivo += total; //total_caja += total; } tbl_det.addCell(Addons.setCeldaPDF(" " + forma_pago, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); } tbl_det.addCell(Addons.setCeldaPDF(" TOTAL ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(ingresos), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" EN CAJA ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(efectivo - ret), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setFilaBlanco(3, 10)); /* gastos */ tbl_det.addCell(Addons.setCeldaPDF("PAGOS", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, Color.cyan, 3, 3)); String tipo_pago = ""; float total_efectivo_pago = 0; float total_egreso = 0; try { ResultSet pagos = objDB.consulta( "select txt_tipo_pago,sum(abono) as total from vta_factura_compra_pago as f inner join tbl_comprobante_egreso as C on F.id_comprobante_egreso=C.id_comprobante_egreso where C.id_sucursal=" + id_sucursal_sesion + " and fecha_pago='" + fecha + "' group by txt_tipo_pago"); while (pagos.next()) { tipo_pago = pagos.getString("txt_tipo_pago") != null ? pagos.getString("txt_tipo_pago") : ""; float pago = pagos.getString("total") != null ? pagos.getFloat("total") : 0; tbl_det.addCell(Addons.setCeldaPDF(" " + tipo_pago, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(pago), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); total_egreso += pago; if (tipo_pago.compareTo("EFECTIVO") == 0) { total_efectivo_pago += pago; //total_caja -= total; } } pagos.close(); } catch (Exception e) { } tbl_det.addCell(Addons.setFilaBlanco(3, 10)); tbl_det.addCell(Addons.setCeldaPDF("TOTALES", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, Color.cyan, 3, 3)); tbl_det.addCell(Addons.setCeldaPDF(" TOTAL VENTAS ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total_ingresos), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" TOTAL PAGOS ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total_egreso), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" TOTAL EN CAJA ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total_efectivo - total_ret - total_efectivo_pago), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); ventas.close(); retencion.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void ingresosPeriodos(HttpServletResponse response, ResultSet emisiones, ResultSet recaudos, ResultSet xcobrar, ResultSet instalaciones, ResultSet otros) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {/*from ww w .ja v a 2s .c o m*/ PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ float[] anchoTabla = new float[] { 25f, 15f, 15f, 15f, 15f, 15f, 20f }; document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); /*PdfPTable tbl_tit = new PdfPTable(1); tbl_tit.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_tit.addCell(Addons.setCeldaPDF("SERVIVIO DE INTERNET", Font.TIMES_ROMAN, 10, Font.NORMAL, Element.ALIGN_LEFT, 0)); document.add(tbl_tit);*/ document.add(Addons.setCabeceraTabla(new String[] { "PERIODO", "INSTALACIONES", "OTROS INGRESOS", "PRE-FACTURADO", "EMITIDO", "POR COBRAR", "SUMATORIA" }, anchoTabla)); String[][] mat_emisiones = DatosDinamicos.ResultSetToMatriz(emisiones); String[][] mat_recaudos = DatosDinamicos.ResultSetToMatriz(recaudos); String[][] mat_xcobrar = DatosDinamicos.ResultSetToMatriz(xcobrar); String[][] mat_instalaciones = DatosDinamicos.ResultSetToMatriz(instalaciones); String[][] mat_otros = DatosDinamicos.ResultSetToMatriz(otros); PdfPTable tbl_det = new PdfPTable(anchoTabla); int pos = -1; float suma = 0; String matriz = ""; for (int i = 0; i < mat_emisiones.length; i++) { if (matriz.compareTo(mat_emisiones[i][0]) != 0) { tbl_det.addCell(Addons.setCeldaPDF(mat_emisiones[i][0], Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1, 4, 7)); matriz = mat_emisiones[i][0]; } tbl_det.addCell(Addons.setCeldaPDF(mat_emisiones[i][1], Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); pos = DatosDinamicos.enMatrizSecuencialSucursal(mat_instalaciones, mat_emisiones[i][1], 1, mat_emisiones[i][0]); suma = Float.valueOf(pos != -1 ? mat_instalaciones[pos][2] : "0"); tbl_det.addCell(Addons.setCeldaPDF(pos != -1 ? mat_instalaciones[pos][2] : "0", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); pos = DatosDinamicos.enMatrizSecuencialSucursal(mat_otros, mat_emisiones[i][1], 1, mat_emisiones[i][0]); suma += Float.valueOf(pos != -1 ? mat_otros[pos][2] : "0"); tbl_det.addCell(Addons.setCeldaPDF(pos != -1 ? mat_otros[pos][2] : "0", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); tbl_det.addCell(Addons.setCeldaPDF(mat_emisiones[i][2], Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); pos = DatosDinamicos.enMatrizSecuencialSucursal(mat_recaudos, mat_emisiones[i][1], 1, mat_emisiones[i][0]); suma += Float.valueOf(pos != -1 ? mat_recaudos[pos][2] : "0"); tbl_det.addCell(Addons.setCeldaPDF(pos != -1 ? mat_recaudos[pos][2] : "0", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); pos = DatosDinamicos.enMatrizSecuencialSucursal(mat_xcobrar, mat_emisiones[i][1], 1, mat_emisiones[i][0]); tbl_det.addCell(Addons.setCeldaPDF(pos != -1 ? mat_xcobrar[pos][2] : "0", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); tbl_det.addCell(Addons.setCeldaPDF(Addons.redondear(String.valueOf(suma)), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void ingresosEgresos(HttpServletResponse response, int id_sucursal, String fecha, DataBase objDB, String banco, String caja) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {/*w w w . j av a2 s.c o m*/ PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); ResultSet ventas = objDB.consulta( "select CASE tipo_cobro WHEN 'e' THEN 'EFECTIVO' WHEN 'c' THEN 'CHEQUE' ELSE '' END AS txt_tipo_cobro," + "sum(total) as total from vta_comprobante_ingreso where id_sucursal=" + id_sucursal + " and anulado=false and fecha_actual='" + fecha + "' group by txt_tipo_cobro"); ResultSet retencion = null; PdfPTable tbl_det = new PdfPTable(new float[] { 130f, 40f, 60f }); try { float total_ingresos = 0; float total_efectivo = 0; float ret = 0; float total_ret = 0; String forma_pago = ""; float total = 0; tbl_det.addCell(Addons.setCeldaPDF("INGRESOS", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, Color.cyan, 3, 3)); while (ventas.next()) { forma_pago = ventas.getString("txt_tipo_cobro") != null ? ventas.getString("txt_tipo_cobro") : ""; total = ventas.getString("total") != null ? ventas.getFloat("total") : 0; total_ingresos += total; if (forma_pago.compareTo("EFECTIVO") == 0) { total_efectivo += total; } tbl_det.addCell(Addons.setCeldaPDF(" " + forma_pago, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); } /* retenciones */ try { retencion = objDB.consulta( "select sum(R.ret_impuesto_retenido) as total from tbl_factura_venta as F inner join tbl_retencion_venta as R " + "on R.id_factura_venta=F.id_factura_venta where id_sucursal=" + id_sucursal + " and F.anulado=false and R.anulado=false and ret_fecha_emision='" + fecha + "'"); if (retencion.next()) { ret = retencion.getString("total") != null ? retencion.getFloat("total") : 0; tbl_det.addCell(Addons.setCeldaPDF(" RETENCIONES ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(ret), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); total_ret += ret; } } catch (Exception ex) { } /*tbl_det.addCell(Addons.setCeldaPDF(" TOTAL ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(ingresos), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0));*/ tbl_det.addCell(Addons.setFilaBlanco(3, 10)); /* gastos */ tbl_det.addCell(Addons.setCeldaPDF("EGRESOS", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, Color.cyan, 3, 3)); String tipo_pago = ""; float total_efectivo_pago = 0; float total_egreso = 0; try { ResultSet pagos = objDB.consulta( "select CASE tipo_pago WHEN 'e' THEN 'EFECTIVO' WHEN 'c' THEN 'CHEQUE' ELSE '' END AS txt_tipo_pago,sum(total) as total " + "from tbl_comprobante_egreso where id_sucursal=" + id_sucursal + " and anulado=false and fecha_actual='" + fecha + "' group by txt_tipo_pago"); while (pagos.next()) { tipo_pago = pagos.getString("txt_tipo_pago") != null ? pagos.getString("txt_tipo_pago") : ""; float pago = pagos.getString("total") != null ? pagos.getFloat("total") : 0; tbl_det.addCell(Addons.setCeldaPDF(" " + tipo_pago, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(pago), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); total_egreso += pago; if (tipo_pago.compareTo("EFECTIVO") == 0) { total_efectivo_pago += pago; } } pagos.close(); } catch (Exception e) { } tbl_det.addCell(Addons.setFilaBlanco(3, 10)); tbl_det.addCell(Addons.setCeldaPDF("TOTALES", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, Color.cyan, 3, 3)); tbl_det.addCell(Addons.setCeldaPDF(" TOTAL INGRESOS ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total_ingresos), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" TOTAL EGRESOS ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total_egreso), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" INGRESOS - EGRESOS - RETENCIONES ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total_ingresos - total_egreso - total_ret), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" INGRESOS (EFECTIVO) - EGRESOS (EFECTIVO) - RETENCIONES ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(total_efectivo - total_efectivo_pago - total_ret), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); ventas.close(); retencion.close(); /* transferencias al banco */ try { tbl_det.addCell(Addons.setFilaBlanco(3, 10)); tbl_det.addCell(Addons.setCeldaPDF("COMPROBANTES DE DIARIO CON BANCOS", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 0, Color.cyan, 3, 3)); ResultSet diarios = objDB.consulta( "select distinct C.detalle, C.total from tbl_comprobante_diario as C inner join tbl_comprobante_diario_detalle as D " + "on C.id_comprobante_diario=D.id_comprobante_diario where C.id_sucursal=" + id_sucursal + " and C.anulado=false and fecha_actual='" + fecha + "' " + "and D.id_plan_cuenta in (" + banco + "," + caja + ")"); while (diarios.next()) { ret = diarios.getString("total") != null ? diarios.getFloat("total") : 0; tbl_det.addCell(Addons.setCeldaPDF( (diarios.getString("detalle") != null ? diarios.getString("detalle") : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(ret), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 0)); } diarios.close(); } catch (Exception ex) { } } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void tabular(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {//from ww w . j a v a2s .co m PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; int num2 = 1; String aux = ""; String columna1 = ""; float suma_parcial = 0; float suma_total = 0; float consumo = 0; int alineacion = Element.ALIGN_LEFT; try { while (registros.next()) { columna1 = (registros.getString(1) != null) ? registros.getString(1) : ""; if (aux.compareTo(columna1) != 0) { if (num > 1) { tbl_det.addCell(Addons.setCeldaPDF("SUBTOTAL: " + Addons.truncar(suma_parcial), Font.TIMES_ROMAN, 9, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, numCols + 2)); } tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1, 3, numCols + 1)); aux = columna1; suma_parcial = 0; num2 = 1; } tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 2; i <= numCols; i++) { alineacion = (i == numCols) ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT; tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, alineacion, 1)); } consumo = (registros.getString(numCols) != null) ? registros.getFloat(numCols) : 0; suma_parcial = Float.parseFloat(this.formatoNumero.format(suma_parcial)) + consumo; suma_total = Float.parseFloat(this.formatoNumero.format(suma_total)) + consumo; num++; num2++; } tbl_det.addCell(Addons.setCeldaPDF("SUBTOTAL: " + Addons.truncar(suma_parcial), Font.TIMES_ROMAN, 9, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, numCols + 2)); tbl_det.addCell(Addons.setCeldaPDF("TOTAL: " + Addons.truncar(suma_total), Font.TIMES_ROMAN, 10, Font.NORMAL, Element.ALIGN_RIGHT, 0, 5, numCols + 2)); registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void tabular(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros, int sumarDesde) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {/*from ww w.ja v a 2 s.c o m*/ PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; int num2 = 1; String aux = ""; String columna1 = ""; int num_sumas = cabTabla.length - sumarDesde; float suma_parcial[] = new float[num_sumas]; float suma_total[] = new float[num_sumas]; float valor[] = new float[num_sumas]; int pos = 0; try { while (registros.next()) { columna1 = (registros.getString(1) != null) ? registros.getString(1) : ""; pos = 0; if (aux.compareTo(columna1) != 0) { if (num > 1) { tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES: ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, sumarDesde)); for (int j = 0; j < suma_parcial.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); suma_parcial[j] = 0; } } tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1, 3, numCols + 2)); aux = columna1; num2 = 1; } tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 2; i <= numCols; i++) { if (i < sumarDesde) { tbl_det.addCell(Addons.setCeldaPDF( ((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } else { valor[pos] = (registros.getString(i) != null) ? registros.getFloat(i) : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor[pos]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); suma_parcial[pos] = Float.parseFloat(this.formatoNumero.format(suma_parcial[pos])) + valor[pos]; suma_total[pos] = Float.parseFloat(this.formatoNumero.format(suma_total[pos])) + valor[pos]; pos++; } } num++; num2++; } tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES: ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, sumarDesde)); for (int j = 0; j < suma_parcial.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); } tbl_det.addCell(Addons.setCeldaPDF("TOTALES: ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, sumarDesde)); for (int j = 0; j < suma_total.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_total[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void tabulares(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) {// w w w . ja v a 2 s .c om /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try { PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; int num2 = 1; String aux = ""; String columna1 = ""; float suma_parcial[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; float suma_total[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; float valor[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int pos = 0; try { while (registros.next()) { columna1 = (registros.getString(1) != null) ? registros.getString(1) : ""; pos = 0; if (aux.compareTo(columna1) != 0) { if (num > 1) { tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES: ", Font.TIMES_ROMAN, 9, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, 5)); for (int j = 0; j < suma_parcial.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); suma_parcial[j] = 0; } } tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1, 3, numCols + 1)); aux = columna1; num2 = 1; } tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 2; i <= numCols; i++) { if (i < 5) { tbl_det.addCell(Addons.setCeldaPDF( ((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } else { valor[pos] = (registros.getString(i) != null) ? registros.getFloat(i) : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor[pos]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); suma_parcial[pos] = Float.parseFloat(this.formatoNumero.format(suma_parcial[pos])) + valor[pos]; suma_total[pos] = Float.parseFloat(this.formatoNumero.format(suma_total[pos])) + valor[pos]; pos++; } } num++; num2++; } tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES: ", Font.TIMES_ROMAN, 9, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, 5)); for (int j = 0; j < suma_parcial.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); } tbl_det.addCell(Addons.setCeldaPDF("TOTALES: ", Font.TIMES_ROMAN, 10, Font.NORMAL, Element.ALIGN_RIGHT, 0, 5, 5)); for (int j = 0; j < suma_total.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_total[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void balanceComprobacion(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) {/*from w w w. j a va2 s. c om*/ /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 60); /*Izquierda, derecha, tope, pie */ try { double sum[] = new double[4]; PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTablaBalance(cabTabla, anchoTabla)); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; String valor = ""; int tipo_cuenta = 0; try { while (registros.next()) { tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); tbl_det.addCell(Addons.setCeldaPDF( ((registros.getString("codigo_cuenta") != null) ? registros.getString("codigo_cuenta") : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); tbl_det.addCell(Addons.setCeldaPDF( ((registros.getString("nombre_cuenta") != null) ? registros.getString("nombre_cuenta") : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); valor = (registros.getString("sum_debe") != null) ? registros.getString("sum_debe") : "0.00"; sum[0] += Double.valueOf(valor); tbl_det.addCell(Addons.setCeldaPDF(((Double.valueOf(valor) > 0) ? valor : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); valor = (registros.getString("sum_haber") != null) ? registros.getString("sum_haber") : "0.00"; sum[1] += Double.valueOf(valor); tbl_det.addCell(Addons.setCeldaPDF(((Double.valueOf(valor) > 0) ? valor : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); tipo_cuenta = (registros.getString("tipo_cuenta") != null) ? registros.getInt("tipo_cuenta") : 0; valor = (registros.getString("saldo_deudor") != null) ? registros.getString("saldo_deudor") : "0.00"; sum[2] += Double.valueOf(valor); tbl_det.addCell(Addons.setCeldaPDF(((tipo_cuenta == 0) ? valor : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); valor = (registros.getString("saldo_aceedor") != null) ? registros.getString("saldo_aceedor") : "0.00"; sum[3] += Double.valueOf(valor); tbl_det.addCell(Addons.setCeldaPDF(((tipo_cuenta == 1) ? valor : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); num++; } registros.close(); } catch (Exception e) { e.printStackTrace(); } tbl_det.addCell( Addons.setCeldaPDF("TOTALES", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1, 3, 3)); for (int i = 0; i < sum.length; i++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(Addons.redondear(sum[i])), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void balanceGeneral(HttpServletResponse response, ResultSet registros) { String datos[][] = Addons.calcularTotalesBalance(registros, 0, 0); Addons.ordenamientoQuicksort(datos, 0, datos.length - 1, 2); /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 60); /*Izquierda, derecha, tope, pie */ try {/*from w w w. java2 s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); int columnas = Addons.maxNivelCodigos(datos) + 2; float anchosCols[] = new float[columnas]; anchosCols[0] = 80f; anchosCols[1] = 200f; for (int i = 2; i < columnas; i++) { anchosCols[i] = 65f; } PdfPTable tbl_det = new PdfPTable(anchosCols); int numCols = 0; int nivel = 0; int k = 2; double sumPasPat = 0; double valor = 0; try { for (int i = 1; i < datos.length; i++) { valor = Addons.redondear(Double.valueOf(datos[i][4])); if (valor != 0) { nivel = Integer.parseInt(datos[i][5]); int fuente = Font.NORMAL; if (nivel == 1) { fuente = Font.BOLD; if (datos[i][3].toUpperCase().indexOf("PASIVO") >= 0 || datos[i][3].toUpperCase().indexOf("PATRIMONIO") >= 0) { sumPasPat += Double.valueOf(datos[i][4]); } } tbl_det.addCell(Addons.setCeldaPDF(datos[i][2], Font.TIMES_ROMAN, 8, fuente, Element.ALIGN_LEFT, 1)); tbl_det.addCell(Addons.setCeldaPDF(datos[i][3], Font.TIMES_ROMAN, 8, fuente, Element.ALIGN_LEFT, 1)); k = 2; numCols = columnas - 2 - nivel; for (int j = 0; j < numCols; j++) { tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, fuente, Element.ALIGN_LEFT, 1)); k++; } tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(Addons.redondear(valor)), Font.TIMES_ROMAN, 8, fuente, Element.ALIGN_RIGHT, 1)); k++; for (int j = k; j < columnas; j++) { tbl_det.addCell( Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 8, fuente, Element.ALIGN_LEFT, 1)); } } } registros.close(); } catch (Exception e) { e.printStackTrace(); } tbl_det.addCell(Addons.setCeldaPDF("TOTAL PASIVOS M?S PATRIMONIO ", Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_LEFT, 1, 3, columnas - 1)); tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(sumPasPat), Font.TIMES_ROMAN, 8, Font.BOLD, Element.ALIGN_RIGHT, 1)); document.add(tbl_det); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); document.add(new Paragraph(" ")); PdfPTable tbl_firmas = new PdfPTable(2); tbl_firmas.addCell( Addons.setCeldaPDF("GERENTE", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 0)); tbl_firmas.addCell( Addons.setCeldaPDF("CONTADOR", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 0)); document.add(tbl_firmas); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }