Package org.openbravo.erpCommon.utility.reporting

Examples of org.openbravo.erpCommon.utility.reporting.Report


      /*
       * PRINT option will print directly to the UI for a single report. For multiple reports the
       * documents will each be saved individually and the concatenated in the same manner as the
       * saved reports. After concatenating the reports they will be deleted.
       */
      Report report = null;
      JasperPrint jasperPrint = null;
      Collection<JasperPrint> jrPrintReports = new ArrayList<JasperPrint>();
      final Collection<Report> savedReports = new ArrayList<Report>();
      for (int i = 0; i < documentIds.length; i++) {
        String documentId = documentIds[i];
        report = buildReport(response, vars, documentId, reportManager, documentType,
            Report.OutputTypeEnum.PRINT);
     
        try {
          jasperPrint = reportManager.processReport(report, vars);
          jrPrintReports.add(jasperPrint);
        } catch (final ReportingException e) {
          advisePopUp(request, response, "Report processing failed",
              "Unable to process report selection");
          log4j.error(e.getMessage());
          e.getStackTrace();
        }
        savedReports.add(report);
        if (multiReports) {
          reportManager.saveTempReport(report, vars);
        }
      }
      printReports(response, jrPrintReports, savedReports);
    } else if (vars.commandIn("ARCHIVE")) {
      // Order documents by Document No.
    //System.out.println("I am ARCHIVE");
      if (multiReports)
        documentIds = orderByDocumentNo(documentType, documentIds);

      /*
       * ARCHIVE will save each report individually and then print the reports in a single printable
       * (concatenated) format.
       */
      archivedReports = true;
      Report report = null;
      final Collection<Report> savedReports = new ArrayList<Report>();
      for (int index = 0; index < documentIds.length; index++) {
        String documentId = documentIds[index];
        report = buildReport(response, vars, documentId, reportManager, documentType,
            OutputTypeEnum.ARCHIVE);
        buildReport(response, vars, documentId, reports, reportManager);
        try {
          reportManager.processReport(report, vars);
        } catch (final ReportingException e) {
          log4j.error(e);
        }
        reportManager.saveTempReport(report, vars);
        savedReports.add(report);
      }
      printReports(response, null, savedReports);
    } else {
      if (vars.commandIn("DEFAULT")) {       
        reports = new HashMap<String, Report>();
        for (int index = 0; index < documentIds.length; index++) {
          final String documentId = documentIds[index];    
          if (log4j.isDebugEnabled())
            log4j.debug("Processing document with id: " + documentId);

          try {
            final Report report = new Report(this, documentType, documentId, vars.getLanguage(),
                "default", multiReports, OutputTypeEnum.DEFAULT);
            reports.put(documentId, report);

            final String senderAddress = EmailData.getSenderAddress(this, vars.getClient(), report
                .getOrgId());
            boolean moreThanOnesalesRep = checks.get("moreThanOnesalesRep").booleanValue();

            if (request.getServletPath().toLowerCase().indexOf("print.html") == -1) {
              if ("".equals(senderAddress) || senderAddress == null) {
                final OBError on = new OBError();
                on.setMessage(Utility.messageBD(this, "No sender defined: Please go to client "
                    + "configuration to complete the email configuration", vars.getLanguage()));
                on.setTitle(Utility
                    .messageBD(this, "Email Configuration Error", vars.getLanguage()));
                on.setType("Error");
                final String tabId = vars.getSessionValue("inpTabId");
                vars.getStringParameter("tab");
                vars.setMessage(tabId, on);
                vars.getRequestGlobalVariable("inpTabId", "AttributeSetInstance.tabId");
                printPageClosePopUpAndRefreshParent(response, vars);
                throw new ServletException("Configuration Error no sender defined");
              }
            }

            // check the different doc typeId's if all the selected
            // doc's
            // has the same doc typeId the template selector should
            // appear
            if (!differentDocTypes.containsKey(report.getDocTypeId())) {
              differentDocTypes.put(report.getDocTypeId(), report.getTemplate());
            }
          } catch (final ReportingException exception) {
            throw new ServletException(exception);
          }

        }

        vars.setSessionObject(sessionValuePrefix + ".Documents", reports);

        if (request.getServletPath().toLowerCase().indexOf("print.html") != -1)
          createPrintOptionsPage(request, response, vars, documentType,
              getComaSeparatedString(documentIds), reports);
        else
          createEmailOptionsPage(request, response, vars, documentType,
              getComaSeparatedString(documentIds), reports, checks);

      } else if (vars.commandIn("ADD")) {
        if (request.getServletPath().toLowerCase().indexOf("print.html") != -1)
          createPrintOptionsPage(request, response, vars, documentType,
              getComaSeparatedString(documentIds), reports);
        else {
          final boolean showList = true;
          createEmailOptionsPage(request, response, vars, documentType,
              getComaSeparatedString(documentIds), reports, checks);
        }

      } else if (vars.commandIn("DEL")) {
        final String documentToDelete = vars.getStringParameter("idToDelete");
        final Vector<Object> vector = (Vector<Object>) request.getSession().getAttribute("files");
        request.getSession().setAttribute("files", vector);

        seekAndDestroy(vector, documentToDelete);
        createEmailOptionsPage(request, response, vars, documentType,
            getComaSeparatedString(documentIds), reports, checks);

      } else if (vars.commandIn("EMAIL")) {
        int nrOfEmailsSend = 0;
        for (final PocData documentData : pocData) {
          getEnvironentInformation(pocData, checks);
          final String documentId = documentData.documentId;
          if (log4j.isDebugEnabled())
            log4j.debug("Processing document with id: " + documentId);

          final Report report = buildReport(response, vars, documentId, reportManager,
              documentType, OutputTypeEnum.EMAIL);

          // if there is only one document type id the user should be
          // able to choose between different templates
          if (differentDocTypes.size() == 1) {
            final String templateId = vars.getRequestGlobalVariable("templates", "templates");
            try {
              final TemplateInfo usedTemplateInfo = new TemplateInfo(this, report.getDocTypeId(),
                  report.getOrgId(), vars.getLanguage(), templateId);
              report.setTemplateInfo(usedTemplateInfo);
            } catch (final ReportingException e) {
              throw new ServletException("Error trying to get template information", e);
            }
          }
          if (report == null)
            throw new ServletException(Utility.messageBD(this, "NoDataReport", vars.getLanguage())
                + documentId);
          // Check if the document is not in status 'draft'
          if (!report.isDraft()) {
            // Check if the report is already attached
            if (!report.isAttached()) {
              // get the Id of the entities table, this is used to
              // store the file as an OB attachment
              final String tableId = ToolsData.getTableId(this, report.getDocumentType()
                  .getTableName());

              // If the user wants to archive the document
              if (vars.getStringParameter("inpArchive").equals("Y")) {
                // Save the report as a attachment because it is
                // being transferred to the user
                try {
                  reportManager.createAttachmentForReport(this, report, tableId, vars);
                } catch (final ReportingException exception) {
                  throw new ServletException(exception);
                }
              } else {
                reportManager.saveTempReport(report, vars);
              }
            } else {
              if (log4j.isDebugEnabled())
                log4j.debug("Document is not attached.");
            }
            final String senderAddress = EmailData.getSenderAddress(this, vars.getClient(), report
                .getOrgId());
            sendDocumentEmail(report, vars, request.getSession().getAttribute("files"),
                documentData, senderAddress, checks);
            nrOfEmailsSend++;
          }
View Full Code Here


      os = response.getOutputStream();
      response.setContentType("application/pdf");

      if (!multiReports && !archivedReports) {
        for (Iterator<Report> iterator = reports.iterator(); iterator.hasNext();) {
          Report report = iterator.next();
          filename = report.getFilename();
        }
        response.setHeader("Content-disposition", "attachment" + "; filename=" + filename);
        for (Iterator<JasperPrint> iterator = jrPrintReports.iterator(); iterator.hasNext();) {
          JasperPrint jasperPrint = (JasperPrint) iterator.next();
          JasperExportManager.exportReportToPdfStream(jasperPrint, os);
View Full Code Here

    try {
      int pageOffset = 0;
      // ArrayList master = new ArrayList();
      int f = 0;
      String filename = "";
      Report outFile = null;
      if (reports.length == 1)
        filename = reports[0].getFilename();
      Document document = null;
      PdfCopy writer = null;
      while (f < reports.length) {
        if (filename == null || filename.equals("")) {
          outFile = reports[f];
          if (multiReports) {
            filename = outFile.getTemplateInfo().getReportFilename();
            filename = filename.replaceAll("@our_ref@", "");
            filename = filename.replaceAll("@cus_ref@", "");
            filename = filename.replaceAll(" ", "_");
            filename = filename.replaceAll("-", "");
            filename = filename + ".pdf";
          } else {
            filename = outFile.getFilename();
          }
        }
        response.setHeader("Content-disposition", "attachment" + "; filename=" + filename);
        // we create a reader for a certain document
        PdfReader reader = new PdfReader(reports[f].getTargetLocation());
View Full Code Here

  }

  private Report buildReport(HttpServletResponse response, VariablesSecureApp vars,
      String strDocumentId, final ReportManager reportManager, DocumentType documentType,
      OutputTypeEnum outputType) {
    Report report = null;
    if (strDocumentId != null) {
      strDocumentId = strDocumentId.replaceAll("\\(|\\)|'", "");
    }
    try
      report = new Report(this, documentType, strDocumentId, vars.getLanguage(), "default",
          multiReports, outputType);
    } catch (final ReportingException e) {
      log4j.error(e);
    } catch (final ServletException e) {
      log4j.error(e);
View Full Code Here

      String strDocumentId, Map<String, Report> reports, final ReportManager reportManager)
      throws ServletException, IOException {
    final String documentId = vars.getStringParameter("inpDocumentId");
    if (strDocumentId != null)
      strDocumentId = strDocumentId.replaceAll("\\(|\\)|'", "");
    final Report report = reports.get(strDocumentId);
    if (report == null)
      throw new ServletException(Utility.messageBD(this, "NoDataReport", vars.getLanguage())
          + documentId);
    // Check if the document is not in status 'draft'
    if (!report.isDraft() && !report.isAttached() && vars.commandIn("ARCHIVE")) {
      // TODO: Move the table Id retrieval into the DocumentType
      // getTableId method!
      // get the Id of the entities table, this is used to store the
      // file as an OB attachment
      final String tableId = ToolsData.getTableId(this, report.getDocumentType().getTableName());

      if (log4j.isDebugEnabled())
        log4j.debug("Table " + report.getDocumentType().getTableName() + " has table id: "
            + tableId);
      // Save the report as a attachment because it is being
      // transferred to the user
      try {
        reportManager.createAttachmentForReport(this, report, tableId, vars);
View Full Code Here

      if (!salesRepMap.containsKey(salesRep)) {
        salesRepMap.put(salesRep, documentData);
      }

      final Report report = reports.get(documentData.documentId);
      // All ids of documents in draft are passed to the web client
      if (report.isDraft()) {
        if (draftDocumentIds.length() > 0)
          draftDocumentIds += ",";
        draftDocumentIds += report.getDocumentId();
        allTheDocsCompleted = false;
      }

      // Fill the report location
      final String reportFilename = report.getContextSubFolder() + report.getFilename();
      documentData.reportLocation = request.getContextPath() + "/" + reportFilename
          + "?documentId=" + documentData.documentId;
      if (log4j.isDebugEnabled())
        log4j.debug(" Filling report location with: " + documentData.reportLocation);

      if (onlyOneAttachedDoc) {
        attachedContent.setDocName(report.getFilename());
        attachedContent.setVisible("checkbox");
        cloneVector.add(attachedContent);
      }

    }
View Full Code Here

  private boolean moreThanOneLenguageDefined(Map<String, Report> reports) throws ReportingException {
    Iterator itRep = reports.values().iterator();
    Map lenguages = new HashMap<String, String>();
    while (itRep.hasNext()) {
      Report report = (Report) itRep.next();
      lenguages.put(report.getEmailDefinition().getLanguage(), report.getEmailDefinition()
          .getLanguage());
    }
    return ((lenguages.values().size() > 1) ? true : false);
  }
View Full Code Here

TOP

Related Classes of org.openbravo.erpCommon.utility.reporting.Report

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.