KoolReport's Forum

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

Issue with Missing JavaScript Assets for Multiple Reports in KoolReportIssue #3423

Open Alejandro Carmona opened this topic on on Mar 13 - 5 comments

Alejandro Carmona commented on Mar 13

I am experiencing an issue when trying to add a second report to my KoolReport application. The first report works fine, but when I add a second report, the required JavaScript assets (<script type='text/javascript' src='/koolreport_assets/…/KoolReport.js'></script>) are not being included in the page source. This results in a "broken" report where the JavaScript required for the report's functionality is missing.

Steps to Reproduce:

  1. Create and run the first report, which works fine and includes the required JavaScript.
  2. Add a second report to the same page or application. 3, When the page is rendered, the JavaScript for the second report is missing. No <script> tag for KoolReport.js is generated for the second report.

Error Message:

The JavaScript assets are not being generated for the second report, causing it to be broken. In the browser console, I see this error: "Uncaught ReferenceError: KoolReport is not defined"

And the report's features are not functioning as expected due to the missing assets.

I did the second using a copy of the first report, only adding a suffix to the different files projectsbysource.php is the original report, and the copy is named projectsbysourcedetail.php with the exact same code.

Sebastian Morales commented on Mar 13

Pls post the code of your application page that contains the first and seconds reports for us to fix the issue for you. Tks,

Alejandro Carmona commented on Mar 13

First Report

projectsbysource.php <?php

use \koolreport\KoolReport; use \koolreport\processes\Group; use \koolreport\processes\Sort;

class projectsbysource extends KoolReport {

use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
use \koolreport\export\Exportable;
use \koolreport\excel\ExcelExportable;

protected function defaultParamValues()
{
    return array(
        "dateRange" => array(
            date("2025-01-01 00:00:00"), // First day of the current month
            date("Y-m-t 23:59:59")   // Last day of the current month
        )
    );
}

protected function bindParamsToInputs()
{
    return array(
        "dateRange"
    );
}

function settings()
{
    return array(
        "dataSources"=>array(
            "restorepm"=>array(
                "connectionString"=>DATABASE_TYPE.":host=".DATABASE_HOST.";dbname=".DATABASE_NAME,
                "username"=>DATABASE_USER,
                "password"=>DATABASE_PASSWORD,
                "charset"=>"utf8"
            ),
        )
    ); 
}

protected function setup()
{
    $this->src('restorepm')
    ->query("SELECT s.source AS source_name, p.number AS project_number, p.created 
            FROM Projects p
            JOIN Sources s ON p.source_id = s.id
            WHERE p.created BETWEEN :start AND :end;")
    ->params(array(
        ":start"=>$this->params["dateRange"][0],
        ":end"=>$this->params["dateRange"][1]
    ))
    ->pipe(new Group(array(
        "by"=>"source_name",
        "count"=>"project_count"
    )))
    ->pipe(new Sort(array(
        "project_count"=>"desc"
    )))
    ->pipe($this->dataStore('projects_by_source'));
}

}

Second Report

projectsbysourcedetail.php <?php

use \koolreport\KoolReport; use \koolreport\processes\Group; use \koolreport\processes\Sort;

class projectsbysourceDetail extends KoolReport {

use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
use \koolreport\export\Exportable;
use \koolreport\excel\ExcelExportable;

protected function defaultParamValues()
{
    return array(
        "dateRange" => array(
            date("2025-01-01 00:00:00"), // First day of the current month
            date("Y-m-t 23:59:59")   // Last day of the current month
        )
    );
}

protected function bindParamsToInputs()
{
    return array(
        "dateRange"
    );
}

function settings()
{
    return array(
        "dataSources"=>array(
            "restorepm"=>array(
                "connectionString"=>DATABASE_TYPE.":host=".DATABASE_HOST.";dbname=".DATABASE_NAME,
                "username"=>DATABASE_USER,
                "password"=>DATABASE_PASSWORD,
                "charset"=>"utf8"
            ),
        )
    ); 
}

protected function setup()
{

// Set a unique name for the report
    $this->name = "my_unique_report_name";

    $this->src('restorepm')
    ->query("SELECT s.source AS source_name, p.number AS project_number, p.created 
            FROM Projects p
            JOIN Sources s ON p.source_id = s.id
            WHERE p.created BETWEEN :start AND :end;")
    ->params(array(
        ":start"=>$this->params["dateRange"][0],
        ":end"=>$this->params["dateRange"][1]
    ))
    ->pipe(new Group(array(
        "by"=>"source_name",
        "count"=>"project_count"
    )))
    ->pipe(new Sort(array(
        "project_count"=>"desc"
    )))
    ->pipe($this->dataStore('projects_by_source'));
}

}

Alejandro Carmona commented on Mar 13

First Page <div class="portlet portlet-boxed">

<div class="portlet-body">
<?php 

require_once APPLICATION . '/reports/koolreports/projectsbysource.php';
$report = new projectsbysource;
$report->run()->render();

?>
</div><!-- /.portlet-body -->

</div><!-- /.portlet portlet-boxed -->

Second Page <div class="portlet portlet-boxed">

<div class="portlet-body">
<?php 

require_once APPLICATION . '/reports/koolreports/projectsbysourcedetail.php';
$report = new projectsbysourceDetail;

$report->run();

// Render the report $report->render();

?>
</div><!-- /.portlet-body -->

</div><!-- /.portlet portlet-boxed -->

Alejandro Carmona commented on Mar 13

Also I noted that if I delete all the folders inside the folder koolreport_assets, If I access the second report, only two folder are recreated, if I access the first report, all folders are created, so this must be related to the assets generation.

How can I force the second report to create the assets?

Sebastian Morales commented on Mar 20

I notice that your second report's file name and class name are different case sensitively (one with detail, the other with Detail). If your application is on a case sensitive server (such as Linux) that could cause issues. Thus, pls try these tests:

1 . Change the file name and class name to be exactly the same

2 . Comment out the first report and use only the second report in your page and see if the js issue still happens

Let us know the results.

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