Customizing Reports

From WHMCS Documentation

All reports are in the /modules/reports/ directory and do not use encoding. This allows you to modify them.

Creating Reports

In addition to customizing the reports that ship with WHMCS, you can add your own custom reports to WHMCS's modular reporting system.

To create your own report, we recommend looking at the format of one of the current files from one of the stock reports. These are in /modules/reports.

  • The WHMCS-included reports are open source and you can copy the format from them for use in your custom report.
  • The report name you choose must be unique, all lowercase, and contain only letters and numbers (a–z, 0–9). It must start with a letter.
  • Upload your report to the /modules/reports directory and it will become accessible under Reports > More... or in the list at Reports > Reports.

Report Format

The format with some descriptions is as follows:

<?php

# The title of your report
$reportdata["title"] = "";

# The description of your report
$reportdata["description"] = "";

# Header text - this gets displayed above the report table of data
$reportdata["headertext"] = "";

# Report Table of Data Column Headings - should be an array of values
$reportdata["tableheadings"] = array("Column 1","Column 2","Column 3");

# Report Table Values - one of these lines for each row you want in the table
# should be an array of values to match the column headings
$reportdata["tablevalues"][] = array("Data 1","Data 2","Data 3");
$reportdata["tablevalues"][] = array("Data 1","Data 2","Data 3");
$reportdata["tablevalues"][] = array("Data 1","Data 2","Data 3");

# Report Footer Text - this gets displayed below the report table of data
$data["footertext"] = "";

Adding Google Charts

WHMCS uses the Google Charts API to generate graphical reports. To add a Google chart to a report, the drawChart function must be used. It accepts the following 5 parameters (in this order):

  • The type of chart you wish to use.
  • The data you wish to use.
  • The configuration that defines the chart's visual display (for example, color or legend position).
  • Height (defaults to 300px).
  • Width (defaults to 100%).

This example uses the drawChart function to create a pie chart:

$reportdata["headertext"] = $chart->drawChart('Pie', $chartdata, $args, '300px', '100%');