Пример #1
0
  public DynamicReport buildReport() throws Exception {

    DynamicReportBuilder drb = new DynamicReportBuilder();
    Integer margin = new Integer(20);
    drb.setTitle("November" + getYear() + " sales report") // defines the title of the report
        .setSubtitle(
            "The items in this report correspond "
                + "to the main products: DVDs, Books, Foods and Magazines")
        .setTitleHeight(new Integer(30))
        .setSubtitleHeight(new Integer(20))
        .setDetailHeight(new Integer(15))
        .setLeftMargin(margin)
        .setRightMargin(margin)
        .setTopMargin(margin)
        .setBottomMargin(margin)
        .setColumnsPerPage(new Integer(1))
        .setColumnSpace(new Integer(5));

    Style style1 = new Style("style1");
    style1.setFont(Font.ARIAL_MEDIUM_BOLD);
    style1.setHorizontalAlign(HorizontalAlign.CENTER);
    drb.addStyle(style1);

    Style style2 = Style.createBlankStyle("style2", "style1");
    style2.setTextColor(Color.BLUE);
    drb.addStyle(style2);

    AbstractColumn columnState =
        ColumnBuilder.getNew()
            .setColumnProperty("state", String.class.getName())
            .setTitle("State")
            .setWidth(new Integer(85))
            .setStyle(style1)
            .build();

    AbstractColumn columnBranch =
        ColumnBuilder.getNew()
            .setColumnProperty("branch", String.class.getName())
            .setTitle("Branch")
            .setWidth(new Integer(85))
            .setStyle(style2)
            .build();

    drb.addColumn(columnBranch);
    drb.addColumn(columnState);

    DJGroup g1 =
        new GroupBuilder()
            .setCriteriaColumn((PropertyColumn) columnBranch)

            //		.setGroupLayout(GroupLayout.DEFAULT)
            .setGroupLayout(GroupLayout.DEFAULT_WITH_HEADER)
            .build();
    drb.addGroup(g1);

    drb.setUseFullPageWidth(true);

    DynamicReport dr = drb.build();
    return dr;
  }
  protected void addColumns(DynamicReportBuilder reportBuilder, List<AbstractColumn> cols) {

    for (AbstractColumn col : cols) {
      System.out.println(col.toString());

      reportBuilder.addColumn(col);
    }
  }
Пример #3
0
 @SuppressWarnings("rawtypes")
 private static DynamicReportBuilder geraColunasRelatorio(
     DynamicReportBuilder relatorioBuilder, Class<Entidade> classeEntidadeRelatorio) {
   for (Field campo : classeEntidadeRelatorio.getDeclaredFields()) {
     ColunaRelatorio colunaRelatorio = campo.getAnnotation(ColunaRelatorio.class);
     if (colunaRelatorio == null) {
       continue;
     }
     relatorioBuilder.addColumn(geraColuna(campo, colunaRelatorio));
   }
   return relatorioBuilder;
 }
  @FXML
  private void eventReporteVentas(ActionEvent event) throws JRException, ParseException {

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(18, Font._FONT_VERDANA, true));
    titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
    Style amountStyle = new Style();
    amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    Style oddRowStyle = new Style();
    oddRowStyle.setBorder(Border.NO_BORDER());
    // Color veryLightGrey = new Color(230,230,230);
    // oddRowStyle.setBackgroundColor(veryLightGrey);
    oddRowStyle.setTextColor(new Color(112, 112, 112));
    oddRowStyle.setFont(new Font(12, Font._FONT_ARIAL, true));
    oddRowStyle.setTransparency(ar.com.fdvs.dj.domain.constants.Transparency.OPAQUE);
    oddRowStyle.setPaddingTop(2);
    oddRowStyle.setPaddingBottom(2);
    // Style HeaderStyle = new Style();
    // HeaderStyle.setFont(new Font(12,Font._FONT_ARIAL,true));

    int cont = 0;
    int cont3 = 0;
    String selecCampo = "";
    for (int i = 0; i < cb.length; i++) {
      if (cb[i].isSelected()) {
        cont++;
      }
    }
    for (int i = 0; i < group.length; i++) {
      if (group[i].isSelected()) {
        cont3++;
      }
    }

    int ancho = 580 / (cont + 1);
    ArrayList<AbstractColumn> colum = new ArrayList<>();
    AbstractColumn nombres[];
    int pun = 0;

    String fecha1 = checkInDatePicker.getValue().toString();
    String fecha2 = checkInDatePicker2.getValue().toString();

    SimpleDateFormat formateador = new SimpleDateFormat("yyyy-MM-dd");
    Date fechaDate1 = formateador.parse(fecha1);
    Date fechaDate2 = formateador.parse(fecha2);
    System.out.println("fecha1: " + fecha1);
    System.out.println("Fecha2: " + fecha2);

    if (cont != 0) {
      if (fechaDate1.before(fechaDate2) || fechaDate1.equals(fechaDate2)) {
        nombres = new AbstractColumn[cont];

        for (int i = 0; i < cb.length; i++) {
          if (cb[i].isSelected()) {
            if (i == 4 || i == 6) {
              nombres[pun] =
                  ColumnBuilder.getNew()
                      .setColumnProperty(cb[i].getId(), Integer.class.getName())
                      .setTitle(cb[i].getText())
                      .setWidth(ancho)
                      .setPattern("$ 0.00") // defines a pattern to apply to the values swhown (uses
                      // TextFormat)
                      // .setStyle(amountStyle)		//special style for this column (align right)
                      .setHeaderStyle(oddRowStyle)
                      .build();
              pun++;

            } else {
              nombres[pun] =
                  ColumnBuilder.getNew()
                      .setColumnProperty(cb[i].getId(), String.class.getName())
                      .setTitle(cb[i].getText())
                      .setWidth(ancho)
                      .setHeaderStyle(oddRowStyle)
                      .build();
              pun++;
            }
            if (cont3 != 0 && i == 6) {
              if (selecCampo.equals("")) {
                selecCampo = " sum(ventas.`total`) AS 'ventas.total' ";
              } else {
                selecCampo += " , sum(ventas.`total`) AS 'ventas.total' ";
              }
            } else {

              if (selecCampo.equals("")) {
                selecCampo = camposQuery[i];
              } else {
                selecCampo += "," + camposQuery[i];
              }
            }
          }
        }
        DynamicReportBuilder drb = new DynamicReportBuilder();
        DynamicReport dr = null;
        for (int i = 0; i < pun; i++) {
          drb.addColumn(nombres[i]);
        }
        Calendar c = Calendar.getInstance();
        String dia = Integer.toString(c.get(Calendar.DATE)) + "/";
        dia += Integer.toString(c.get(Calendar.MONTH) + 1) + "/";
        dia += Integer.toString(c.get(Calendar.YEAR));
        drb
            // .addGroups(2)
            .addImageBanner("./img/umaiSystem.png", 70, 70, ImageBanner.ALIGN_RIGHT)
            .setTitle("Reporte de ventas ")
            .setTitleStyle(titleStyle)
            .setSubtitle("Fecha de creacion: " + dia)
            .setDetailHeight(15)
            .setMargins(30, 20, 30, 15)
            .setPrintBackgroundOnOddRows(false)
            .setUseFullPageWidth(true)
            .setColumnsPerPage(1);

        String grupos = "";
        int cont2 = 0;
        for (int i = 0; i < group.length; i++) {
          if (group[i].isSelected()) {
            if (grupos.equals("")) {
              grupos = group[i].getId();
            } else {
              grupos += "," + group[i].getId();
            }

            cont2++;
          }
        }
        String Rango = " where ventas.fechaVenta Between '" + fecha1 + "' and '" + fecha2 + "'  ";

        String sql;
        if (cont2 != 0) {
          sql =
              " SELECT "
                  + selecCampo
                  + " FROM\n"
                  + "  `ventas` ventas  INNER JOIN `clientes` ON clientes.`idCli` = ventas.`idCli`\n"
                  + "     INNER JOIN `usuarios` usuarios ON ventas.`idUsu` = usuarios.`idUsu` "
                  + Rango
                  + " GROUP BY "
                  + grupos
                  + " ORDER BY ventas.idVenta ";
        } else {
          sql =
              " SELECT "
                  + selecCampo
                  + " FROM\n"
                  + "  `ventas` ventas  INNER JOIN `clientes` ON clientes.`idCli` = ventas.`idCli`\n"
                  + "  INNER JOIN `usuarios` usuarios ON ventas.`idUsu` = usuarios.`idUsu` "
                  + Rango
                  + " ORDER BY ventas.idVenta ";
        }
        System.out.println("sql: " + sql);

        Connection conexion = null;
        // conexion=Helpers.db.db.conn;
        conexion = Helpers.db.getDbCon().conn;

        drb.setQuery(sql, DJConstants.QUERY_LANGUAGE_SQL);
        dr = drb.build(); // Finally build the report!
        //       JasperPrint jp=DynamicJasperHelper.generateJasperPrint(dr,new
        // ClassicLayoutManager(),ds);
        JasperPrint jp =
            DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), conexion, null);

        JasperViewer.viewReport(jp, false); // finally display the report report
        System.out.println(sql);
      } else {
        AlertBox.display("Error", "Rango de fechas no valido");
      }
    } else {
      AlertBox.display("Error", "Debe seleccionar minimo 1 campo");
    }
  }
Пример #5
0
  public DynamicReport buildReport() throws Exception {

    Style detailStyle = new Style();
    Style headerStyle = new Style();
    headerStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
    headerStyle.setBorder(Border.PEN_2_POINT());
    headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
    headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(18, Font._FONT_VERDANA, true));
    Style importeStyle = new Style();
    importeStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    Style oddRowStyle = new Style();
    oddRowStyle.setBorder(Border.NO_BORDER());
    oddRowStyle.setBackgroundColor(Color.LIGHT_GRAY);
    oddRowStyle.setTransparency(Transparency.OPAQUE);

    DynamicReportBuilder drb = new DynamicReportBuilder();
    int margin = 20;
    drb.setTitleStyle(titleStyle)
        .setTitle("November" + getYear() + " sales report") // defines the title of the report
        .setSubtitle(
            "The items in this report correspond "
                + "to the main products: DVDs, Books, Foods and Magazines")
        .setDetailHeight(new Integer(15))
        .setLeftMargin(margin)
        .setMargins(margin, margin, margin, margin)
        //				.setPrintBackgroundOnOddRows(true)
        .setPrintColumnNames(false)
        .setOddRowBackgroundStyle(oddRowStyle);

    AbstractColumn columnState =
        ColumnBuilder.getNew()
            .setColumnProperty("state", String.class.getName())
            .setTitle("State")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnBranch =
        ColumnBuilder.getNew()
            .setColumnProperty("branch", String.class.getName())
            .setTitle("Branch")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnaProductLine =
        ColumnBuilder.getNew()
            .setColumnProperty("productLine", String.class.getName())
            .setTitle("Product Line")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnaItem =
        ColumnBuilder.getNew()
            .setColumnProperty("item", String.class.getName())
            .setTitle("Item")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnCode =
        ColumnBuilder.getNew()
            .setColumnProperty("id", Long.class.getName())
            .setTitle("ID")
            .setWidth(new Integer(40))
            .setStyle(importeStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnaQuantity =
        ColumnBuilder.getNew()
            .setColumnProperty("quantity", Long.class.getName())
            .setTitle("Quantity")
            .setWidth(new Integer(80))
            .setStyle(importeStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnAmount =
        ColumnBuilder.getNew()
            .setColumnProperty("amount", Float.class.getName())
            .setTitle("Amount")
            .setWidth(new Integer(90))
            .setPattern("$ 0.00")
            .setStyle(importeStyle)
            .setHeaderStyle(headerStyle)
            .build();

    GroupBuilder gb1 = new GroupBuilder();

    //		 define the criteria column to group by (columnState)
    DJGroup g1 =
        gb1.setCriteriaColumn((PropertyColumn) columnState)
            .addFooterVariable(
                columnAmount,
                DJCalculation
                    .SUM) // tell the group place a variable footer of the column "columnAmount"
                          // with the SUM of allvalues of the columnAmount in this group.
            .addFooterVariable(
                columnaQuantity, DJCalculation.SUM) // idem for the columnaQuantity column
            .setGroupLayout(
                GroupLayout
                    .DEFAULT_WITH_HEADER) // tells the group how to be shown, there are
                                          // manyposibilities, see the GroupLayout for more.
            .build();

    GroupBuilder gb2 =
        new GroupBuilder(); // Create another group (using another column as criteria)
    DJGroup g2 =
        gb2.setCriteriaColumn(
                (PropertyColumn)
                    columnBranch) // and we add the same operations for the columnAmount and
            .addFooterVariable(columnAmount, DJCalculation.SUM) // columnaQuantity columns
            .addFooterVariable(columnaQuantity, DJCalculation.SUM)
            .build();

    drb.addColumn(columnState);
    drb.addColumn(columnBranch);
    drb.addColumn(columnaProductLine);
    drb.addColumn(columnaItem);
    drb.addColumn(columnCode);
    drb.addColumn(columnaQuantity);
    drb.addColumn(columnAmount);

    drb.addGroup(g1); // add group g1
    //		drb.addGroup(g2); // add group g2

    drb.setUseFullPageWidth(true);

    DJChartBuilder cb = new DJChartBuilder();
    DJChart chart =
        cb.setType(DJChart.BAR_CHART)
            .setOperation(DJChart.CALCULATION_SUM)
            .setColumnsGroup(g1)
            .addColumn(columnAmount)
            .addColumn(columnaQuantity)
            .setPosition(DJChartOptions.POSITION_HEADER)
            .setShowLabels(true)
            .build();

    drb.addChart(chart); // add chart

    DynamicReport dr = drb.build();

    return dr;
  }