How to print a Quote, Order or a Invoice to Word or PDF

2014-03-09
2014-07-14
  • ismet sener
    ismet sener
    2014-03-09

    Hi,

    I just installed OpenCRX, it works, there many features, but it is not very clear.
    How can I: print a Quote, Order or a Invoice to Word or PDF??

    Please help me.

    With Kind Regards,
    Ismet Sener

     
  • Rendering documents is not part of the core distribution of openCRX. Rendering is typically very customer-specific and as such these kind of functions should be put in custom projects.

    There are different ways (all require programming) to add functions such as "Print quote", "Print invoice". Probably the easiest way is to create a wizard (JSP) and add it to the menu of a quote / invoice. A wizard has full access to the openCRX API. It can therefore collect all required data and render a document.

    The ExportAccountsToXLS.jsp wizard can serve as a sample: The wizard collects a list of contacts and exports them as XLS. The same way one can render an RTF, PDF, a TEX file, etc.

     
    • ismet sener
      ismet sener
      2014-03-12

      Dear Werner,

      Can you explain me in detail how to do it? For example to print a Quote to PDF.
      Then I can do the rest by myself, copy/edit etc for Order, Invoice etc

      With kind regards,
      Ismet

       
  • ismet sener
    ismet sener
    2014-03-10

    Thank you for your reply,

    Can you explain me how I can render a PDF file?
    I like to print a invoice or a quote or a order

    If you explain me in detail how to print a Quote in pdf, I can do the rest
    by my self (order, invoice etc because i have some knowledge of IT)

     
  • ismet sener
    ismet sener
    2014-03-10

    I use at the moment sugarCRM, but now I have seen this OpenCRX, wow, I am very enthusiastic about it. OpenCRX, has a lot of functionlity en features. It is also diffecult, but once you know how to develop/change, then you can do a lot of things with it.

    So in very short time I will migrate from SugarCRM to OpenCRX.

     
  • I have added a wizard to the openCRX/Custom Sample project: see http://sourceforge.net/p/opencrx/opencrx2-custom-git/ci/master/tree/sample/src/data/org.opencrx.sample/wizards/en_US/SamplePrintQuote.jsp.

    • Download the JSP and copy it to the Tomcat expanded EAR directory ./apps/opencrx-core-CRX/opencrx-core-CRX/wizards/en_US/. Restart Tomcat.
    • The wizard registers in the quotes wizard menu.
    • When launched, the wizard renders the quote and displays a download link.
    • The quote is rendered as text only. Use a library such as iText or PDFBox to render a PDF instead. Probably the easiest solution is to render an XLS using Apache POI.
     
    • ismet sener
      ismet sener
      2014-03-14

      Thank you Werner,

      I managed to do it, it works , I downloaded the text only file from teh Quote Wizard.

      The further steps, printing to PDF, is not that easy for me.
      So i have to find out how to print to PDF or Word
      I do not know how to use iText, or PDFBox, or Apache POI

      I allready use iReport together with Jasperserver, I have build a many reports with iRpeort, so maybe I have to build custom reports with iReport, and connect these reports (.jrxml files) to the OpenCRX - Quote-Order-Invoice.

       
  • For database-based reporting I recommend to create dedicated views based on the tables / views of the openCRX database.

    On https://sourceforge.net/p/opencrx/opencrx2-custom-git/ci/master/tree/sample/src/sql/hsqldb-2/sample_views.sql I have posted two views sample_report_quote, sample_report_quote_item which deliver the same data as the SamplePrintQuote.jsp wizard. This should allow you to use tools such as iReport.

     
    • ismet sener
      ismet sener
      2014-07-09

      Dear Werner,
      Thank you for your answer.

      With this example, I can also make other views.

      I am now very happy with OpenCRX, I am still testing, but this is teh best CRM system I have seen/tested, with this system I can replace my current SugarCRM and my commercial Quoting software (QuoteWerks).

      If I make a report with iReport, how can I attach this .JRXML file to OpenCRX?
      Does OpenCRX has a Jasperreport connector so that it can print this .jrxml report directly from teh Quote-Order-Invoice module from OpenCRX?

      If I want to use iText or PDFBox, how I can do that, dou you have installation steps?

      I prefer to create reports with iReport and use that in OpenCRX,

      Kind Regards,
      Ismet

       
  • One possibility is to create a program which does something like this:

    • Render the report as PDF using Jasper
    • Attach the PDF as media to the contract
    • The user can then download the rendered PDF

    You can put the code into a JSP and register it as wizard with the standard GUI. Rendering is done when the user launches the wizard. Or you can write a standalone program which periodically checks for non-rendered contracts and does the rendering in the background.

    Hope the code below gives you some ideas.

    ...
    // Generate report
    String reportTemplateFilePath = ctx.getRealPath("./reports/myquote.jrxml");
    ByteArrayOutputStream reportStream = new ByteArrayOutputStream();
    JasperPrint jasperPrint;
    jasperReport = JasperCompileManager.compileReport(reportTemplateFilePath);
    Map<String, Object> reportParameters = new HashMap<>();
    jasperPrint = JasperFillManager.fillReport(jasperReport, reportParameters, getConnection());
    JRExporter exporter = new JRPdfExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, reportStream);
    exporter.exportReport();
    
    // Attach report as media to contract
    pm.currentTransaction().begin();
    org.opencrx.kernel.generic.jmi1.Media media = media = pm.newInstance(org.opencrx.kernel.generic.jmi1.Media.class);
    media.setContentMimeType("application/pdf");
    media.setContentName("myquote.jpg");
    contract.addMedia(
        Base.getInstance().getUidAsString(), 
        media
    );
    media.setContent(BinaryLargeObjects.valueOf(reportStream.getBytes()));
    pm.currentTransaction().commit();
    ...
    
    /**
        * Get database connection.
        * 
        * @param connectionUrl
        * @param userName
        * @param password
        * @return
        */
    protected Connection getConnection(
        String connectionUrl,
        String userName,
        String password
    ) {
        Connection connT = null;
        try {
            if(connectionUrl != null && connectionUrl.startsWith("java:")) {
                Context initialContext = new InitialContext();
                javax.sql.DataSource dsT = (javax.sql.DataSource)initialContext.lookup(connectionUrl);
                connT = dsT.getConnection();
            } else {
                try {
                    String driverName = org.opencrx.kernel.utils.DbSchemaUtils.getJdbcDriverName(connectionUrl);
                    Class.forName(driverName);
                } catch (Exception e) {
                    this.report.add("ERROR: Unable to load database driver (message=" + e.getMessage() + ")");
                }
                connT = DriverManager.getConnection(connectionUrl, userName, password);
            }
        } catch(Exception e) {
            this.report.add("ERROR: unable to get connection to database (message=" + e.getMessage() + ")");
        }
        return connT;
    }
    
     
  • ismet sener
    ismet sener
    2014-07-11

    Dear Werner,

    Thanks for your answer.
    Could you help me the steps.
    Suppose I Created a invoice report with iReport (invoice.jrxml)
    So that I can print from the invoice module in opencrx.

    I prefer to have several reports for the quote module, order module, and invoice module
    So that I can print directly from that module, the quote/order/invoice which is open (which I like to print)

    The reports in ireport I can create, I know also how to create several views in the Oencrx database.

    Then?
    what are the steps, to which location in opencrx I have to copy/paste the jasper report (invoice/order/quote .jrxml )
    What are the other steps?

    What I have to do with that code above?

    adhoc reports I can print from the jasperserver, so that is not a problem, I like to print the operational report righ from the opencrx module.

    Please help me, I am nearly finished with testing, the only issue is the reporting.
    then i will install and use OpenCRX
    and also stop with SugarCRM and a paid version of QuoteWerks

    With kind regards,
    Ismet

     
  • ismet sener
    ismet sener
    2014-07-14

    Hi Werner,

    I still not got is how to dot, excuse me.
    What I have to do with the code above (// Generate report..)
    What I have to do it?
    Is there something what I can read?

    Could you tell (if possible) the steps from a till z how to doit, rest I can do it.
    Fro exampel how to print from Quote Module the JasperReport.

    Regards,
    Ismet