SugarCRM Reports Customizations

Assumptions:

  1. Goal is custom rendering of data on Report generation/views
  2. Data is text-based
  3. No pre-existing SugarWidgets will work
  4. Schema is fubar, so hard-coded widgets are necessary.

Salient Points:

  1. Render happens with this stack:
    • modules/Reports/index.php : template_reports_report()
    • modules/Reports/templates/templates_reports.php : template_list_view()
    • modules/Reports/templates/templates_list_view.php : template_list_row()
    • modules/Reports/templates/templates_list_view.php : line 386
  2. Actual render manipulation of a cell of data:
    1. modules/Reports/Reports.php : line 1692 – $display = $this->layout_manager->widgetDisplay($display_column);
    2. Above is dependent on definition of $display_column which is an attribute of the associative array $this->report_def ($this is an instance of Report)
      1. $report_def comes from the saved metadata contained in a SavedReport or is passed via POST from the preceding form.
      2. The targetted change in metadata is an attribute “widget_class” that pertains to a SugarWidgetField[class]. This can be leveraged to customize output.
        1. The trick is how to add that attribute on the fly?

So? how to?

The unfortunate structure of Reports requires hard-coded customizations to manipulate data display beyond the OOTB widget Sugar ships.

For in-browser Reports:

My field was of type “varchar” which corresponds to the widget found at: include/generic/SugarWidgets/SugarWidgetsFieldsvarchar.php.

The Reports code instantiates the widget class, feels for certain methods and calls those methods if found. The interesting one here is “displayList()“. It doesn’t exists in the OOTB widget, so I created a new method and populated with some seriously hacky code to manipulate my data as I needed.

For PDF Reports

You would think that given the mess that Reports is, it would try to keep its separate outputs as similar as possible and maybe emulate a MVC paradigm. Too much to hope for; presentation and content code are intermingled as if no thought to code upkeep was ever entertained. Bitching aside, the way to do it:

modules/Reports/templates/templates_pdf.php : template_listview_pdf()

Find the while() loop that iterates through the returned rows/columns and stuff the returned text into a multi-D array that is passed as metadata to the EzPDF class. Insert your logic hook based on whatever criteria in the while loop and profit.

For CSV Reports

Much like the PDF reports hack above, the solution is implemented within the while() loop:

modules/Reports/templates/templates_export.php : template_handle_export()

Advertisements