Search in sources :

Example 31 with JRException

use of net.sf.jasperreports.engine.JRException in project sic by belluccifranco.

the class FacturaServiceImpl method getReporteFacturaVenta.

@Override
public byte[] getReporteFacturaVenta(Factura factura) {
    ClassLoader classLoader = FacturaServiceImpl.class.getClassLoader();
    InputStream isFileReport = classLoader.getResourceAsStream("sic/vista/reportes/FacturaVenta.jasper");
    Map params = new HashMap();
    ConfiguracionDelSistema cds = configuracionDelSistemaService.getConfiguracionDelSistemaPorEmpresa(factura.getEmpresa());
    params.put("preImpresa", cds.isUsarFacturaVentaPreImpresa());
    String formasDePago = "";
    formasDePago = pagoService.getPagosDeLaFactura(factura.getId_Factura()).stream().map((pago) -> pago.getFormaDePago().getNombre() + " -").reduce(formasDePago, String::concat);
    params.put("formasDePago", formasDePago);
    if (factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_B) || factura.getTipoComprobante().equals(TipoDeComprobante.PRESUPUESTO)) {
        factura.setSubTotal_bruto(factura.getSubTotal());
        factura.setIva_105_neto(0);
        factura.setIva_21_neto(0);
    }
    params.put("facturaVenta", factura);
    if (factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_A) || factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_B) || factura.getTipoComprobante().equals(TipoDeComprobante.FACTURA_C)) {
        if (factura.getNumSerieAfip() != 0 && factura.getNumFacturaAfip() != 0) {
            params.put("nroComprobante", factura.getNumSerieAfip() + " - " + factura.getNumFacturaAfip());
        } else {
            params.put("nroComprobante", "");
        }
    } else {
        params.put("nroComprobante", factura.getNumSerie() + " - " + factura.getNumFactura());
    }
    params.put("logo", Utilidades.convertirByteArrayIntoImage(factura.getEmpresa().getLogo()));
    List<RenglonFactura> renglones = this.getRenglonesDeLaFactura(factura.getId_Factura());
    JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(renglones);
    try {
        return JasperExportManager.exportReportToPdf(JasperFillManager.fillReport(isFileReport, params, ds));
    } catch (JRException ex) {
        throw new ServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_reporte"), ex);
    }
}
Also used : JRException(net.sf.jasperreports.engine.JRException) ServiceException(sic.service.ServiceException) BusinessServiceException(sic.service.BusinessServiceException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ConfiguracionDelSistema(sic.modelo.ConfiguracionDelSistema) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) RenglonFactura(sic.modelo.RenglonFactura) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with JRException

use of net.sf.jasperreports.engine.JRException in project sic by belluccifranco.

the class PedidoServiceImpl method getReportePedido.

@Override
public byte[] getReportePedido(Pedido pedido) {
    ClassLoader classLoader = PedidoServiceImpl.class.getClassLoader();
    InputStream isFileReport = classLoader.getResourceAsStream("sic/vista/reportes/Pedido.jasper");
    Map params = new HashMap();
    params.put("pedido", pedido);
    params.put("logo", Utilidades.convertirByteArrayIntoImage(pedido.getEmpresa().getLogo()));
    List<RenglonPedido> renglones = this.getRenglonesDelPedido(pedido.getId_Pedido());
    JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(renglones);
    try {
        return JasperExportManager.exportReportToPdf(JasperFillManager.fillReport(isFileReport, params, ds));
    } catch (JRException ex) {
        throw new ServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_reporte"), ex);
    }
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) JRException(net.sf.jasperreports.engine.JRException) ServiceException(sic.service.ServiceException) BusinessServiceException(sic.service.BusinessServiceException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JRBeanCollectionDataSource(net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with JRException

use of net.sf.jasperreports.engine.JRException in project jgnash by ccavanaugh.

the class BaseDynamicJasperReport method createJasperPrint.

@SuppressWarnings("ConstantConditions")
protected final JasperPrint createJasperPrint(final AbstractReportTableModel model, final boolean formatForCSV) {
    logger.info(rb.getString("Message.ProcessingReportData"));
    DynamicReportBuilder drb = new DynamicReportBuilder();
    try {
        if (formatForCSV) {
            drb.setIgnorePagination(true);
        }
        final List<AbstractColumn> columns = new ArrayList<>();
        final int[] columnsToHide = model.getColumnsToHide();
        assignPageFormat(drb);
        drb.setHeaderHeight(getStyle(model.getColumnHeaderStyle(0), formatForCSV).getFont().getFontSize() * 2);
        drb.setDetailHeight(getBaseFontSize() * 2);
        logger.info("Creating column model for report");
        // create columns and add to the list
        for (int i = 0; i < model.getColumnCount(); i++) {
            if (Arrays.binarySearch(columnsToHide, i) >= 0) {
                // don't add any hidden columns
                continue;
            }
            if (model.getColumnStyle(i) != ColumnStyle.GROUP && model.getColumnStyle(i) != ColumnStyle.GROUP_NO_HEADER) {
                Style columnTypeStyle = getStyle(model.getColumnStyle(i), formatForCSV);
                Style columnHeaderStyle = getStyle(model.getColumnHeaderStyle(i), formatForCSV);
                int width = AWTFontUtilities.getStringWidth(model.getColumnPrototypeValueAt(i), getTypeFooterStyle());
                int hWidth = AWTFontUtilities.getStringWidth(model.getColumnName(i), columnHeaderStyle);
                if (hWidth > width) {
                    width = hWidth;
                }
                ColumnBuilder builder = ColumnBuilder.getNew();
                builder.setColumnProperty(COLUMN_PROPERTY + i, model.getColumnClass(i).getName());
                builder.setTitle(model.getColumnName(i));
                builder.setWidth(width);
                builder.setStyle(columnTypeStyle);
                builder.setHeaderStyle(columnHeaderStyle);
                builder.setTruncateSuffix("…");
                // set the format pattern for decimal values
                if (model.getColumnStyle(i) == ColumnStyle.AMOUNT_SUM || model.getColumnStyle(i) == ColumnStyle.BALANCE || model.getColumnStyle(i) == ColumnStyle.BALANCE_WITH_SUM || model.getColumnStyle(i) == ColumnStyle.BALANCE_WITH_SUM_AND_GLOBAL || model.getColumnStyle(i) == ColumnStyle.CROSSTAB_TOTAL) {
                    String pattern = CommodityFormat.getFullNumberPattern(model.getCurrency());
                    builder.setPattern(pattern);
                } else if (model.getColumnStyle(i) == ColumnStyle.PERCENTAGE) {
                    NumberFormat nf = ReportFactory.getPercentageFormat();
                    String pattern = ((DecimalFormat) nf).toPattern();
                    builder.setPattern(pattern);
                } else if (model.getColumnStyle(i) == ColumnStyle.QUANTITY) {
                    NumberFormat nf = ReportFactory.getQuantityFormat();
                    String pattern = ((DecimalFormat) nf).toPattern();
                    builder.setPattern(pattern);
                } else if (model.getColumnStyle(i) == ColumnStyle.SHORT_DATE) {
                    builder.setTextFormatter(DateUtils.getShortDateFormatter().toFormat());
                } else if (model.getColumnStyle(i) == ColumnStyle.TIMESTAMP) {
                    builder.setTextFormatter(DateUtils.getShortDateTimeFormatter().toFormat());
                } else if (model.getColumnStyle(i) == ColumnStyle.SHORT_AMOUNT) {
                    String pattern = CommodityFormat.getShortNumberPattern(model.getCurrency());
                    builder.setPattern(pattern);
                }
                if (model.isColumnFixedWidth(i) && !formatForCSV) {
                    builder.setFixedWidth(true);
                }
                columns.add(builder.build());
            } else if (model.getColumnStyle(i) == ColumnStyle.GROUP || model.getColumnStyle(i) == ColumnStyle.GROUP_NO_HEADER) {
                ColumnBuilder builder = ColumnBuilder.getNew();
                builder.setColumnProperty(COLUMN_PROPERTY + i, model.getColumnClass(i).getName());
                builder.setTitle(model.getColumnName(i));
                builder.setStyle(getTypeHeaderStyle());
                columns.add(builder.build());
            }
        }
        boolean group = false;
        boolean header = true;
        logger.info("Searching for report groups");
        // determine if a group needs to be created
        for (int i = 0; i < model.getColumnCount(); i++) {
            if (model.getColumnStyle(i) == ColumnStyle.GROUP) {
                group = true;
                break;
            } else if (model.getColumnStyle(i) == ColumnStyle.GROUP_NO_HEADER) {
                group = true;
                header = false;
                break;
            }
        }
        if (group) {
            // group columns
            logger.info("Building report groups");
            GroupBuilder gb = new GroupBuilder();
            gb.setDefaultHeaderVariableStyle(getTypeHeaderStyle());
            gb.setDefaultFooterVariableStyle(getTypeFooterStyle());
            for (int i = 0; i < columns.size(); i++) {
                if (model.getColumnStyle(i) == ColumnStyle.GROUP || model.getColumnStyle(i) == ColumnStyle.GROUP_NO_HEADER) {
                    gb.setCriteriaColumn((PropertyColumn) columns.get(i));
                } else if (model.getColumnStyle(i) == ColumnStyle.AMOUNT_SUM || model.getColumnStyle(i) == ColumnStyle.BALANCE_WITH_SUM || model.getColumnStyle(i) == ColumnStyle.BALANCE_WITH_SUM_AND_GLOBAL || model.getColumnStyle(i) == ColumnStyle.CROSSTAB_TOTAL) {
                    gb.addFooterVariable(columns.get(i), DJCalculation.SUM);
                }
            }
            if (header) {
                gb.setGroupLayout(GroupLayout.VALUE_IN_HEADER);
            } else {
                gb.setGroupLayout(GroupLayout.EMPTY);
            }
            // adds a group footer label if it is not null or zero length
            if (getGroupFooterLabel() != null && !getGroupFooterLabel().isEmpty()) {
                DJGroupLabel label = new DJGroupLabel(getGroupFooterLabel(), getTypeFooterStyle(), LabelPosition.LEFT);
                gb.setFooterLabel(label);
            }
            DJGroup group1 = gb.build();
            boolean global = false;
            for (int i = 0; i < columns.size(); i++) {
                final AbstractColumn c = columns.get(i);
                drb.addColumn(c);
                if (model.getColumnStyle(i) == ColumnStyle.BALANCE_WITH_SUM_AND_GLOBAL || model.getColumnStyle(i) == ColumnStyle.CROSSTAB_TOTAL) {
                    drb.addGlobalFooterVariable(c, DJCalculation.SUM, getTypeFooterStyle());
                    global = true;
                }
            }
            drb.addGroup(group1);
            if (global) {
                drb.setGrandTotalLegendStyle(getGlobalFooterStyle());
                drb.setGrandTotalLegend(getGrandTotalLegend());
            }
        } else {
            // no groups exist, just add the columns
            for (final AbstractColumn column : columns) {
                drb.addColumn(column);
            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
    buildTitle(drb);
    // use the full page width
    drb.setUseFullPageWidth(true);
    if (!formatForCSV) {
        final Style footerStyle = getPageFooterStyle();
        final int halfWidth = (int) (getPageFormat().getWidth() * .5);
        final AutoText date = new AutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER, HorizontalBandAlignment.LEFT, AutoText.PATTERN_DATE_DATE_TIME, halfWidth);
        date.setStyle(footerStyle);
        final AutoText pageNum = new AutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y, AutoText.POSITION_FOOTER, HorizontalBandAlignment.RIGHT, (byte) 0, 80, 50);
        pageNum.setStyle(footerStyle);
        drb.addAutoText(date);
        drb.addAutoText(pageNum);
    }
    logger.info(rb.getString("Message.CompilingReport"));
    DynamicReport dr = drb.build();
    logger.info(rb.getString("Message.ReportCompileComplete"));
    JRDataSource ds = new JRTableModelDataSource(model);
    JasperPrint jp = null;
    try {
        logger.info(rb.getString("Message.ReportCreateView"));
        jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds);
    } catch (final JRException e) {
        logger.log(Level.WARNING, "Exception", e);
        logger.warning(rb.getString("Message.ReduceFont"));
        displayError(rb.getString("Message.ReduceFont"));
    }
    return jp;
}
Also used : DJGroupLabel(ar.com.fdvs.dj.domain.DJGroupLabel) ClassicLayoutManager(ar.com.fdvs.dj.core.layout.ClassicLayoutManager) JRException(net.sf.jasperreports.engine.JRException) DynamicReport(ar.com.fdvs.dj.domain.DynamicReport) DecimalFormat(java.text.DecimalFormat) GroupBuilder(ar.com.fdvs.dj.domain.builders.GroupBuilder) AutoText(ar.com.fdvs.dj.domain.AutoText) JasperPrint(net.sf.jasperreports.engine.JasperPrint) ArrayList(java.util.ArrayList) JRDataSource(net.sf.jasperreports.engine.JRDataSource) DynamicReportBuilder(ar.com.fdvs.dj.domain.builders.DynamicReportBuilder) AbstractColumn(ar.com.fdvs.dj.domain.entities.columns.AbstractColumn) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRException(net.sf.jasperreports.engine.JRException) DJGroup(ar.com.fdvs.dj.domain.entities.DJGroup) Style(ar.com.fdvs.dj.domain.Style) JRTableModelDataSource(net.sf.jasperreports.engine.data.JRTableModelDataSource) ColumnBuilder(ar.com.fdvs.dj.domain.builders.ColumnBuilder) NumberFormat(java.text.NumberFormat)

Aggregations

JRException (net.sf.jasperreports.engine.JRException)33 JasperReport (net.sf.jasperreports.engine.JasperReport)8 File (java.io.File)7 InputStream (java.io.InputStream)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 JasperPrint (net.sf.jasperreports.engine.JasperPrint)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ArrayList (java.util.ArrayList)4 JRBeanCollectionDataSource (net.sf.jasperreports.engine.data.JRBeanCollectionDataSource)4 Containerable (com.evolveum.midpoint.prism.Containerable)3 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Map (java.util.Map)3 JasperDesign (net.sf.jasperreports.engine.design.JasperDesign)3 BusinessServiceException (sic.service.BusinessServiceException)3 ServiceException (sic.service.ServiceException)3 Item (com.evolveum.midpoint.prism.Item)2 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)2