Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void exportarFacturaText(String ruta, String archivo, Integer codF, BigDecimal toTales, String simMone) throws ClassNotFoundException, ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, IOException, Exception {
- Connection conexion;
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/erpcarbonstar?useSSL=false", "root", "10260429");
- HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
- response.setHeader("Content-Disposition", "attachment; filename=" + archivo);
- ServletOutputStream outstream = response.getOutputStream();
- Locale milocal = new Locale("en", "PE");
- this.totaligv = new BigDecimal("0");
- this.totales = new BigDecimal("0");
- int x = 1;
- this.session = HibernateUtil.getSessionFactory().openSession();
- parametroDao parDao = new parametroDaoImp();
- this.transaction = this.session.beginTransaction();
- this.parametro = parDao.obtenerDatosParametro(this.session, x);
- if (this.parametro.getIdParametro().equals(x) && this.parametro.getMonedaParametro1().equals(simMone)) {
- BigDecimal dividoigv = this.parametro.getImpuestoParametroDec().divide(new BigDecimal(100.0));
- BigDecimal igv = toTales.multiply(dividoigv);
- this.totaligv = igv;
- this.txtmonedas = this.parametro.getDesignacionParametro1();
- } else if (this.parametro.getIdParametro().equals(x) && this.parametro.getMonedaParametro2().equals(simMone)) {
- BigDecimal dividoigv = this.parametro.getImpuestoParametroDec().divide(new BigDecimal(100.0));
- BigDecimal igv = toTales.multiply(dividoigv);
- this.totaligv = igv;
- this.txtmonedas = this.parametro.getDesignacionParametro2();
- }
- this.totales = toTales.add(this.totaligv);
- DecimalFormat df = new DecimalFormat("######0.00");
- conversionMontoLetra numletra = new conversionMontoLetra();
- String montosletras = numletra.Convertir(df.format(this.totales), true);
- String txtmontosletras = "SON : " + montosletras + this.txtmonedas;
- //Se definen los parametros que el reporte necesita
- Map parameter = new HashMap();
- parameter.put("numerosfacturas", codF);
- parameter.put("igv", this.totaligv);
- parameter.put("totales", this.totales);
- parameter.put("montoletra", txtmontosletras);
- parameter.put(JRParameter.REPORT_LOCALE, milocal);
- parameter.put(JRTextExporterParameter.PAGE_WIDTH, 800);
- parameter.put(JRTextExporterParameter.PAGE_HEIGHT, 400);
- try {
- File file = new File(ruta);
- JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(file.getPath());
- JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameter, conexion);
- JRTextExporter exporter = new JRTextExporter();
- exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
- exporter.setExporterOutput(new SimpleWriterExporterOutput(outstream));
- exporter.exportReport();
- outstream.flush();
- outstream.close();
- } catch (JRException ex) {
- ex.printStackTrace(System.out);
- } finally {
- if (conexion != null) {
- try {
- conexion.close();
- } catch (SQLException ex) {
- ex.printStackTrace(System.out);
- }
- }
- }
- }
- public void verFacturaMatrixNavegadorPDF() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {
- int cf = this.numerofact;
- BigDecimal tt = this.toTaless;
- String mm = this.simmon;
- DecimalFormat serie = new DecimalFormat("000000");
- reporteFactura rFactura = new reporteFactura();
- FacesContext facesContext = FacesContext.getCurrentInstance();
- ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
- String ruta = servletContext.getRealPath("/Reportes/facturamatrixReport.jasper");
- String archivo = "FacturaNro" + serie.format(cf) + ".txt";
- //rFactura.verFacturaPDF(ruta, archivo, cf, tt, mm);
- rFactura.exportarFacturaText(ruta, archivo, cf, tt, mm);
- FacesContext.getCurrentInstance().responseComplete();
- }
- <h:outputText value=" "/>
- <h:commandLink id="reportefactura3" target="_blank" actionListener="#{facturaBean.pedirFactura(ft.numeroFactura, ft.totalVenta, ft.moneda.simboloMoneda)}"
- title="Imprimir en la impresora Matricial" action="#{facturaBean.verFacturaMatrixNavegadorPDF()}" >
- <h:graphicImage value="/resources/Imagenes/impresoramatricial.png" width="20" height="20"/>
- </h:commandLink>
Add Comment
Please, Sign In to add comment