Package org.openbravo.erpCommon.utility.reporting

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


    documentIds = strDocumentId.split(",");
    if (log4j.isDebugEnabled())
      log4j.debug("Number of documents selected: " + documentIds.length);
    multiReports = (documentIds.length > 1);   
    reports = (Map<String, Report>) vars.getSessionObject(sessionValuePrefix + ".Documents");
    final ReportManager reportManager = new ReportManager(this, globalParameters.strFTPDirectory,
        strReplaceWithFull, globalParameters.strBaseDesignPath,
        globalParameters.strDefaultDesignPath, globalParameters.prefix, multiReports);
   
    if (vars.commandIn("PRINT")) {
      archivedReports = false;
      // Order documents by Document No.
      if (multiReports)
        documentIds = orderByDocumentNo(documentType, documentIds);
      /*
       * 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.");
            }
View Full Code Here

TOP

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

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.