KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Sub reports based on parameter from main report #3080

Open Martin Parkes opened this topic on on Jun 26, 2023 - 1 comments

Martin Parkes commented on Jun 26, 2023

This report was originally created using Crystal Reports and works very well. I’m wanting to convert this to Kool reports, but not sure how to do this.

The original report was grouped by the Black bar field (40248 | Scale Up 2, etc) and then subreports were created for both “non-mileage” and “mileage” data and a parameter value (a numerical value) was passed into the subreports that made sure the data matched the black bar.

All the data is coming from MySQL tables. I want to know if this type of report can be created in the same way to match the layout pretty much as it is now and if so how do I do this. Very new to Kool Reports so as much help as possible would be greatly appreciated.

Sebastian Morales commented on Jun 29, 2023

It is possible to create this type with KoolReport. First you get a list (an array) of black bar values. Then for each of the value retrieve 2 datastores. Finally in your report view loop through the values and show 2 tables for each. A pseudo code would be:

//MyReport.php
function setup()
{
    $this->blackBarValues = getBlackBarValues();
    foreach ($this->blackBarValues as $value) {
        $this->src("mysql")
        ->query(...) // build sql query or KoolReport pipe process according to $value
        ->pipe(...) 
        ...
        ->pipe($this->dataStore("datastore_mileage_" . $value));

        $this->src("mysql")
        ->query(...) // build sql query or KoolReport pipe process according to $value
        ->pipe(...) 
        ...
        ->pipe($this->dataStore("datastore_non_mileage_" . $value));
    }
}

//MyReport.view.php
    foreach ($this->blackBarValues as $value) {
        \koolreport\widgets\koolphp\Table::create(array(
            "dataSource" => $this->dataStore("datastore_mileage_" . $value),
            ...
        ));
        \koolreport\widgets\koolphp\Table::create(array(
            "dataSource" => $this->dataStore("datastore_non_mileage_" . $value),
            ...
        ));
    }

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None