Guest User

Untitled

a guest
Jan 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. public void exportarFacturaText(String ruta, String archivo, Integer codF, BigDecimal toTales, String simMone) throws ClassNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, IOException, Exception {
  2. Connection conexion;
  3. Class.forName("com.mysql.jdbc.Driver").newInstance();
  4. conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/erpcarbonstar?useSSL=false", "root", "10260429");
  5. HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
  6. response.setHeader("Content-Disposition", "attachment; filename=" + archivo);
  7. ServletOutputStream outstream = response.getOutputStream();
  8.  
  9. Locale milocal = new Locale("en", "PE");
  10. this.totaligv = new BigDecimal("0");
  11. this.totales = new BigDecimal("0");
  12. int x = 1;
  13.  
  14. this.session = HibernateUtil.getSessionFactory().openSession();
  15. parametroDao parDao = new parametroDaoImp();
  16. this.transaction = this.session.beginTransaction();
  17.  
  18. this.parametro = parDao.obtenerDatosParametro(this.session, x);
  19. if (this.parametro.getIdParametro().equals(x) && this.parametro.getMonedaParametro1().equals(simMone)) {
  20. BigDecimal dividoigv = this.parametro.getImpuestoParametroDec().divide(new BigDecimal(100.0));
  21. BigDecimal igv = toTales.multiply(dividoigv);
  22. this.totaligv = igv;
  23. this.txtmonedas = this.parametro.getDesignacionParametro1();
  24. } else if (this.parametro.getIdParametro().equals(x) && this.parametro.getMonedaParametro2().equals(simMone)) {
  25. BigDecimal dividoigv = this.parametro.getImpuestoParametroDec().divide(new BigDecimal(100.0));
  26. BigDecimal igv = toTales.multiply(dividoigv);
  27. this.totaligv = igv;
  28. this.txtmonedas = this.parametro.getDesignacionParametro2();
  29. }
  30. this.totales = toTales.add(this.totaligv);
  31. DecimalFormat df = new DecimalFormat("######0.00");
  32. conversionMontoLetra numletra = new conversionMontoLetra();
  33. String montosletras = numletra.Convertir(df.format(this.totales), true);
  34. String txtmontosletras = "SON : " + montosletras + this.txtmonedas;
  35.  
  36. //Se definen los parametros que el reporte necesita
  37. Map parameter = new HashMap();
  38. parameter.put("numerosfacturas", codF);
  39. parameter.put("igv", this.totaligv);
  40. parameter.put("totales", this.totales);
  41. parameter.put("montoletra", txtmontosletras);
  42. parameter.put(JRParameter.REPORT_LOCALE, milocal);
  43. parameter.put(JRTextExporterParameter.PAGE_WIDTH, 800);
  44. parameter.put(JRTextExporterParameter.PAGE_HEIGHT, 400);
  45.  
  46. try {
  47. File file = new File(ruta);
  48.  
  49. JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(file.getPath());
  50. JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, conexion);
  51. JRTextExporter exporter = new JRTextExporter();
  52. exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
  53. exporter.setExporterOutput(new SimpleWriterExporterOutput(outstream));
  54. exporter.exportReport();
  55.  
  56. outstream.flush();
  57. outstream.close();
  58.  
  59. } catch (JRException ex) {
  60. ex.printStackTrace(System.out);
  61. } finally {
  62. if (conexion != null) {
  63. try {
  64. conexion.close();
  65. } catch (SQLException ex) {
  66. ex.printStackTrace(System.out);
  67. }
  68. }
  69. }
  70. }
  71.  
  72. public void verFacturaMatrixNavegadorPDF() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {
  73.  
  74. int cf = this.numerofact;
  75. BigDecimal tt = this.toTaless;
  76. String mm = this.simmon;
  77. DecimalFormat serie = new DecimalFormat("000000");
  78.  
  79. reporteFactura rFactura = new reporteFactura();
  80.  
  81. FacesContext facesContext = FacesContext.getCurrentInstance();
  82. ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
  83. String ruta = servletContext.getRealPath("/Reportes/facturamatrixReport.jasper");
  84. String archivo = "FacturaNro" + serie.format(cf) + ".txt";
  85.  
  86. //rFactura.verFacturaPDF(ruta, archivo, cf, tt, mm);
  87. rFactura.exportarFacturaText(ruta, archivo, cf, tt, mm);
  88. FacesContext.getCurrentInstance().responseComplete();
  89.  
  90. }
  91.  
  92. <h:outputText value=" "/>
  93. <h:commandLink id="reportefactura3" target="_blank" actionListener="#{facturaBean.pedirFactura(ft.numeroFactura, ft.totalVenta, ft.moneda.simboloMoneda)}"
  94. title="Imprimir en la impresora Matricial" action="#{facturaBean.verFacturaMatrixNavegadorPDF()}" >
  95. <h:graphicImage value="/resources/Imagenes/impresoramatricial.png" width="20" height="20"/>
  96. </h:commandLink>
Add Comment
Please, Sign In to add comment