Skip to content

Visual Report Writer and The Web (VII)

In this seventh blog about Visual Report Writer and the Web, we look at the next report available on the Live Demo website (European Server, USA server) named Inventory Stock Levels. If this is the first blog you read, I encourage you to read the six other blogs (1: The Solution, 2: Invoices Report, 3: The Cleanup, 4: The CustomerList, 5: The OrderList, and 6: The Credit and Balances Overview). Between the fourth and the fifth blog, we have been able to release the Alpha I version of Visual Report Writer 3.0 and the 2.1+ Library only setup. The latter is needed to make web reporting using the 17.1 DataFlex Web Framework easy and to look like at the demo website.

The Report

The report uses the DataFlex embedded database, the same database used for the WebOrder example that comes with Visual DataFlex 17.1. The tables invt and vendor are used for the report. The report groups the inventory data per vendor, sorted by name. The specialties in this report include a calculated column that contains the result of the inventory unit price times the number on hand. This value is not shown in the report; it is suppressed in the details section. The field's content is used for a sum operation in the group footer and the report footer. The report footer can be suppressed via a parameter in the report, which can be set from integration. Another specialty is the use of a barcode font to convert the item_id into a barcode. The font used is named C39HrP24DlTt. If you install this font on your web server, you need to reboot the server to make it active.

The Integration

For the integration, we create two cWebView components. One view creates a PDF when you browse through the vendors and allows you to suppress the report footer, while the second component directly shows the report without filtering on vendor or allowing report footer suppression.

The Overview

First, take a look at the overview implementation. This is the cWebView that immediately shows the full report. While Visual Report Writer is fast (this also depends on the number of simultaneous accesses and the speed of hardware and internet connections), it should not be used when the amount of data is so large that a huge number of pages is generated or when filters should be really applied. Web server access should be short and not time-consuming. Users don't want to wait a long time. In this case, it is fine; the report is only 3 pages long.

Note the difference between the report display in Chrome and Firefox. In Chrome, your barcode is shown; in Firefox (version 20), it does not show. Firefox reads the PDF and converts it to HTML, and while the barcode font is stored in the PDF, it does not make use of it. In Firefox, the report display is slower too.

The report start is triggered by the OnShow event of the cWebView component. So, each time you open the view, the report is built and shown in an iFrame control.

Procedure OnShow
    Forward Send OnShow

    Send GenerateReport of oReport
End_Procedure
End_Object

The report generating code is similar to that of other reports that create a PDF file.

Object oWebMainPanel is a cWebPanel
    Object oReport is a cVRWReport
        Set psReportName to "320 Inventory Stock levels per Vendor.vrw"

        Procedure GenerateReport
            String sReportId sFile sUrl
            VRWPDFExportOptions PDFExportOptions
            Boolean bCanceled

            Get OpenReport to sReportId
            If (sReportId <> "") Begin
                Get DefaultPDFExportOptions to PDFExportOptions
                Set pPDFExportOptions to PDFExportOptions
                Get ReportCacheFileName ".pdf" to sFile
                If (sFile <> "") Begin
                    Send ExportReport C_vrwPDF sFile
                    Get pbCanceled to bCanceled
                    If (not (bCanceled)) Begin
                        Get DownloadURL of ghoWebResourceManager sFile to sUrl
                        If (sUrl <> "") Begin
                            WebSet psUrl of oViewer to sUrl
                        End
                    End
                End
                Send CloseReport sReportId
            End
        End_Procedure
    End_Object

    Object oViewer is a cWebIFrame
       Set pbFillHeight to True
       Set pbShowBorder to True
    End_Object
End_Object

Per Vendor

In the second cWebView component that uses the same report, the generation of the report results is triggered from an OnPostFind event in the vendor data dictionary object, similar to what is done in the Credit and Balances report view.

Object oVendor_DD is a cVendorDataDictionary
    Procedure OnPostFind Integer eMessage Boolean bFound
        Boolean bSyncing

        Forward Send OnPostFind eMessage bFound

        Get AppSynching of ghoWebApp to bSyncing
        If (not (bSyncing)) Begin
            Send GenerateReport of oReport
        End
    End_Procedure
End_Object

The special code in this view is the use of a parameter in the report. The view has a checkbox (cWebCheckbox) that lets the user indicate if the report footer should be suppressed or not. The status of this checkbox is read in the OnInitializeReport event of the cVRWReport object.

Procedure OnInitializeReport
    Boolean bSuppress
    Integer iParameter

    Get GetChecked of oSuppressFooterSection to bSuppress
    Get ParameterIdByName C_USEMAINVRWREPORTID 'SuppressFooter' to iParameter
    Set psParameterValue C_USEMAINVRWREPORTID iParameter to bSuppress
    Send SetFilters
End_Procedure

The filtering is done by taking the value of the vendor ID cWebForm object and adding it as a filter to the report using the AddFilter message.

Procedure SetFilters
    Integer iVendorId

    WebGet psValue of oVendorID to iVendorId

    Send RemoveAllFilters C_USEMAINVRWREPORTID
    If (iVendorId <> 0) Begin
        Send AddFilter C_USEMAINVRWREPORTID "{Vendor.Id}" C_VRWEqual iVendorId
    End
End_Procedure

This blog was again written to show you the power behind Visual Report Writer and the Web and how easy it is to implement and integrate the reports. Make sure your customers get to know the product and deliver nice-looking reports for integration.