Reports - making new ones

Hi,

I have adjusted the Invoice to fit regulations in Austria (and germany).

Now I want to add/adjust some reports, is there a similar wiki for that? How to debug in html, lists of available fields etc…

Regards,
Jan

I have adjusted the Invoice to fit regulations in Austria (and germany).

Have you considered the possibility of sharing them on the Templates & Themes category?

Now I want to add/adjust some reports, is there a similar wiki for that? How to debug in html, lists of available fields etc…

There is no information about the reports, quite possibly because that feature is underdeveloped in comparison with other (more urgent/more important) parts of the software. The good news are that this means the structure of the code is rather simple and that creating a new report is comparatively easy.

You will find all relevant files in the folder “application/modules/report”, in the subfolders,

  • “Controllers” contains the single file “Reports.php” in which there is a separate function for each report, e.g. public function sales_by_client()
  • “Models” contains also a single file, “Mdl_reports.php”, in which there is a separate function for each report, e.g. public function sales_by_client($from_date = null, $to_date = null).
  • “Views” on the contrary contains one file for each report, e.g. “sales_by_client_index.php”

Views

The files in the Views folder contain the HTML+PHP code that renders the simple web forms displayed by IP. Since you have been able to modify the somewhat more complex invoice template, you should have almost no problem to adapt the view files to your needs. I would suggest you start by copying the form that looks closer to the one you want, and that you then modify it.

Important: the name of the view file must match the name of its controller and model functions, otherwise they will not find each other.

Controllers

The file “Controllers/Report.php” contains the code that takes the decisions and processes the information. The code is arranged in a separate function for each report, and since all those functions do essentially the same, you will find that their share a fair amount of code. Again, this is to your advantage, since you can start by cloning the function that looks closer to your needs.

Essentially, this is what each controller function does:

  • When executed for the first time, it calls the file under “Views” to display the empty on-line form.
  • When the submit button in the on-line form is pressed, the controller-function calls its model-function in “Models/Mdl_reports.php” and passes to it the parameters entered in the on-line form.
  • Then, when the model-function returns an answer, the controller-function creates a new HTML page that contains the information, and then it converts it to PDF by calling pdf_create(). At this point, the PDF report is displayed on your browser.

Models

The file “Controllers/Report.php” contains the code to obtain and process the information needed to generate the report. This includes: querying the database to obtain the raw data needed for the report, then processing it to obtain the final data, and then arranging the information as needed for the report.

As you will notice, while the code in the controller and view files can be reused to a large extent, these functions are quite different from each other because each asks a different question to the database and because the processing of the raw data usually differs too and is specific for each particular report.

To build the queries you will need to know SQL/MySQL and the CodeIgniter Database class, in particular, Running Queries and Generating Query Results. On the other side, you can skip (or skim over) the sections about Database Configuration, Connecting to a Database, and Database Driver Reference since they are already handled by other parts of InvoicePlane.

If you can run PHPmyadmin or a similar application, I would recommend that you try building first your query using those tools, and that you translate them into CodeIgniter code once you get the results you want.

1 Like

Hi,

thanks for the really detailed description.
I can handle most except that I am not familiar with Codigniter. As I use IP, I will have to get some basic knowledge though.

After I documented it I will share, it should be usable for all, not only people that know their way in PHP etc.

Regards,
Jan