KoolReport's Forum

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

No Data Available in Table #2981

Open AhmedHaroon opened this topic on on Feb 10, 2023 - 9 comments

AhmedHaroon commented on Feb 10, 2023

KoolReport with CI4:

local env: Windows 10, XAMPP

server env (both staging and live): Ubuntu, MySQL Server

created a report, it was working fine on local and server both. when add code to store dateRange in session variables, it is working fine on Local environment, but on staging server it is showing nothing but page with:

1) $this->dataStore("result")

2) No data available in table

note: in an another report, added same functionality and it was working fine (thanks to @Sebastian Morales) but here it is not working. definitely i made mistake but failed to find yet what's wrong. please help.

my code and screenshot below for reference.

CustomerSummary.php:

<?php
namespace App\reports;

// we have copied below file in root path of our app 
require_once ROOTPATH . "load.koolreport.php";

use \koolreport\KoolReport;
use \koolreport\processes\Sort;
use \koolreport\processes\Map;
use \koolreport\processes\Limit;
use \koolreport\processes\Filter;
use \koolreport\cube\processes\Cube;
use \koolreport\pivot\processes\Pivot;

class CustomerSummary extends \koolreport\KoolReport
{
    //use \koolreport\bootstrap4\Theme;
    use \koolreport\amazing\Theme;
    use \koolreport\codeigniter\Friendship;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;
    use \koolreport\excel\BigSpreadsheetExportable;

    protected function defaultParamValues()
    {
        $start = isset($_SESSION["startDate"]) ? $_SESSION["startDate"] : date("2022-12-01");
        $end = isset($_SESSION["startDate"]) ? $_SESSION["endDate"] : date("2022-12-01");
        return array(
            "dateRange"=>array($start ,$end),
            "customers"=>NULL,
        );
    }

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

    function setup()
    {
        $_SESSION["startDate"] = $this->params["dateRange"][0];
        $_SESSION["endDate"] = $this->params["dateRange"][1];
        $this->src("default")
        ->query("SELECT DATE(order_date) AS order_date, user_id, customer_name, rides,rider_charges, order_total FROM customer_summary WHERE
                    user_id = ".($this->params["customers"] == '' ? 'user_id' : ':customers')."
                    AND
                    order_date >= :startDate
                    AND
                    order_date <= :endDate")
        ->params(array(
            ":startDate"=>$this->params["dateRange"][0],
            ":endDate"=>$this->params["dateRange"][1],
            ":customers"=>$this->params["customers"],
        ))
        ->pipe(Sort::process([
            "order_date"=>"desc"
        ]))
        ->pipe($this->dataStore("result"));
        $this->src("default")->query("
            SELECT DISTINCT 
                user_id,
                customer_name
            FROM
                customer_summary
            ORDER BY customer_name
        ")
        ->pipe($this->dataStore("customers"));
    }
}

### Screenshot:

regards

cfsinc commented on Feb 10, 2023

There is something maybe out of order in your html. Post CustomerSummary.view.php code also.

Also post the phpmyadmin return of your mysql code too or a var_dump showing the return of query information. That will show your code produces a result and I had what you are seeing happen to me one day when I was adjusting my report.view.php code and did not have my layout right at one point in the adjustment.

Keep in mind the more detail you post the easier it will be on here to get an answer. I have noticed many people ask questions similar without posting all code involved neatly on here. You post your view of the report but only the logic code and not the view of the report code so thats why it most like does not have. a response yet. Not enough information.

Also you are using codeigniter so there is a lot of info that maybe missing here to determine your problem.

AhmedHaroon commented on Feb 13, 2023

@cfsinc thank you for your reply.

already mentioned in my OP " it was working fine on local and server both."

the problem start when added / modified the code to implement session variables for dateRange in CustomerSummary.php.

in my both reports OrderSummary and CustomerSummary i didn't change any thing in report.view.php , as per your instruction, i am posting the CustomerSummary.view.php code here to review. ( posting complete code as not sure which part is important for this purpose. )

CustomerSummary.view.php

<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\inputs\DateRangePicker;
use \koolreport\inputs\Select2;

?>

<style>
    .amazing {
        width: 40%;
    }
    .select2 {
        width: 100% !important;
    }

    .sidebar {
        background: #ffffff !important;
    }
</style>
<div class='report-content'>
<br />
    <div class="text-center">
        <h2>Customer Summary</h2>
        <a href="<?php echo base_url(); ?>/Customersummarypdf/DownloadPDF" class="btn btn-primary">Download PDF</a>
        <a href="<?php echo base_url(); ?>/Customersummarypdf/DownloadExcel" class="btn btn-primary">Download Excel</a>
    </div>
    <br />
    
    <form method="post">
        <div class="row">
            <div class="col-md-8 offset-md-2">
                <div class="form-group" style="display: flex; flex-direction: row; flex-wrap: nowrap; align-content: center; justify-content: center; align-items: center; margin-bottom: 1rem;">
                    <?php
                        DateRangePicker::create(array(
                            "name"=>"dateRange",
                            "format"=>"YYYY-MM-DD"
                        ))
                    ?>
                <strong>Select Customer</strong>
                <?php
                Select2::create(array(
                    "name"=>"customers",
                    "dataStore"=>$this->dataStore("customers"),
                    "defaultOption"=>array(
                        "All"=>NULL
                    ),
                    "dataBind"=>array(
                        "text"=>"customer_name",
                        "value"=>"user_id",
                    ),
                    "attributes"=>array(
                        "class"=>"form-control",
                    )
                ));
                ?>

                <div class="form-group text-center" style="margin-left: 1rem;margin-bottom: 0rem;">
                    <button class="btn btn-success"><i class="glyphicon glyphicon-refresh"></i> Load</button>
                </div>
            </div>
        </div>
    </form>
    </div>

    <?php
    if($this->dataStore("result")->countData()>0)
    {
    Table::create(array(
        "dataStore"=>$this->dataStore("result"),
        "cssClass"=>array(
            "table"=>"table table-bordered"
        ),
        "showFooter"=>true,
        "options"=>array(
            "paging"=>true,
        ),
        "columns"=>array(
            
            "order_date"=>array(
                "cssStyle"=>"text-align:center",
                "label"=>"Order Date",
            ),
            "user_id"=>array(
                "label"=>"Customer ID",
                "type"=>"number",
            ),
            "customer_name"=>array(
                "label"=>"Customer Name",
                "footerText"=>"<b>Total</b>"
            ),
            "rides"=>array(
                "cssStyle"=>"text-align:right",
                "label"=>"Rides",
                "type"=>"number",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"
            ),
            "rider_charges"=>array(
                "cssStyle"=>"text-align:right",
                "label"=>"DC",
                "type"=>"number",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"
            ),
            "order_total"=>array(
                "cssStyle"=>"text-align:right",
                "label"=>"GMV",
                "type"=>"number",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"
            ),
        ),
        "paging"=>array(
            "pageSize"=>10,
        ),
    ));
    }
    else
    {
    ?>
        <div class="alert alert-warning">
            <i class="glyphicon glyphicon-info-sign"></i> Sorry, we found no orders.
        </div>
    <?php    
    }
    ?>
</div>

regards

Sebastian Morales commented on Feb 14, 2023

I think there was a mistake with this line:

        $end = isset($_SESSION["startDate"]) ? $_SESSION["endDate"] : date("2022-12-01");

With $start == $end, it's most likely no data would be returned. Pls change "startDate" to "endDate":

        $end = isset($_SESSION["endDate"]) ? $_SESSION["endDate"] : date("2022-12-01");
AhmedHaroon commented on Feb 14, 2023

@Sebastian Morales , thanks to correct me for mistake.

i modified report and deployed for staging server but getting same as above screenshot.

if there is no data for the dataRange, it should show as below not as above screenshot. ( below is previous report modified as per your instruction to store dateRange in session variables )

regards

Sebastian Morales commented on Feb 14, 2023

Pls comment out these two lines and let us know the result with screenshots:

        // $_SESSION["startDate"] = $this->params["dateRange"][0]; // comment out this
        // $_SESSION["endDate"] = $this->params["dateRange"][1]; // comment out this
AhmedHaroon commented on Feb 14, 2023

@Sebastian Morales

after commenting out these lines it is showing same as previous.

.

regards

Sebastian Morales commented on Feb 15, 2023

Replace your report view content with a string like "Hello world". If the output is still data dump, remove content of your report class until "Hello world" appears in output. If you can not see it, check your report class and view file names. Can try to delete and create those files again to see if it makes a difference.

AhmedHaroon commented on Feb 15, 2023

hi @Sebastian Morales thanks for your passion to guide us.

i modified CustomerSummary.php, remarked for parameter "customers" where it was... and now it is showing report page normally on staging. ( i removed from CustomerSummary.php but NOT yet from CustomerSummary.view.php ) , when enter dateRange and press Load button now it is not showing data, nothing happened. don't know what is the problem here, please check my code & screenshot below and advise.

CustomerSummary.php

<?php
namespace App\reports;

require_once ROOTPATH . "load.koolreport.php";

use \koolreport\KoolReport;
use \koolreport\processes\Sort;
use \koolreport\processes\Map;
use \koolreport\processes\Limit;
use \koolreport\processes\Filter;
use \koolreport\cube\processes\Cube;
use \koolreport\pivot\processes\Pivot;
use \koolreport\processes\TimeBucket;

class CustomerSummary extends \koolreport\KoolReport
{
    //use \koolreport\bootstrap4\Theme;
    use \koolreport\amazing\Theme;
    use \koolreport\codeigniter\Friendship;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;
    use \koolreport\excel\BigSpreadsheetExportable;

    protected function defaultParamValues()
    {
        $start = isset($_SESSION["startDate"]) ? $_SESSION["startDate"] : date("2022-12-01");
        $end = isset($_SESSION["endDate"]) ? $_SESSION["endDate"] : date("2022-12-01");
        return array(
            "dateRange"=>array($start ,$end),
            // "customers"=>NULL,
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "dateRange"=>"dateRange",
            // "customers"=>"customers",
        );
    }

    function setup()
    {
        $_SESSION["startDate"] = $this->params["dateRange"][0];
        $_SESSION["endDate"] = $this->params["dateRange"][1];
        $this->src("default")
        ->query("SELECT DATE(order_date) AS order_date, user_id, customer_name, rides,rider_charges, order_total FROM customer_summary WHERE
                    order_date >= :startDate
                    AND
                    order_date <= :endDate")
        ->params(array(
            ":startDate"=>$this->params["dateRange"][0],
            ":endDate"=>$this->params["dateRange"][1],
            // ":customers"=>$this->params["customers"],
        ))
        ->pipe(Sort::process([
            "order_date"=>"desc"
        ]))
        ->pipe($this->dataStore("result"));

        $this->src("default")->query("
            SELECT DISTINCT 
                user_id,
                customer_name
            FROM
                customer_summary
            ORDER BY customer_name
        ")
        ->pipe($this->dataStore("customers"));
    }
    //  user_id = ".($this->params["customers"] == '' ? 'user_id' : ':customers')." AND
}

CustomerSummary.view.php

<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\inputs\DateRangePicker;
use \koolreport\inputs\Select2;

?>
<style>
    .amazing {
        width: 40%;
    }
    .select2 {
        width: 100% !important;
    }

    .sidebar {
        background: #ffffff !important;
    }
</style>
<div class='report-content'>
    <br />
    <div class="text-center">
        <h2>Customer Summary</h2>
        <a href="<?php echo base_url(); ?>/Customersummarypdf/DownloadPDF" class="btn btn-primary">Download PDF</a>
        <a href="<?php echo base_url(); ?>/Customersummarypdf/DownloadExcel" class="btn btn-primary">Download Excel</a>
    </div>
    <br />
    
    <form method="post">
        <div class="row">
            <div class="col-md-8 offset-md-2">
                <div class="form-group" style="display: flex; flex-direction: row; flex-wrap: nowrap; align-content: center; justify-content: center; align-items: center; margin-bottom: 1rem;">
                    <?php
                        DateRangePicker::create(array(
                            "name"=>"dateRange",
                            "format"=>"YYYY-MM-DD"
                        ))
                    ?>
                <strong>Select Customer</strong>
                <?php
                Select2::create(array(
                    "name"=>"customers",
                    "dataStore"=>$this->dataStore("customers"),
                    "defaultOption"=>array(
                        "All"=>NULL
                    ),
                    "dataBind"=>array(
                        "text"=>"customer_name",
                        "value"=>"user_id",
                    ),
                    "attributes"=>array(
                        "class"=>"form-control",
                    )
                ));
                ?>

                <div class="form-group text-center" style="margin-left: 1rem;margin-bottom: 0rem;">
                    <button class="btn btn-success"><i class="glyphicon glyphicon-refresh"></i> Load</button>
                </div>
            </div>
        </div>
    </form>
    </div>

    <?php
    if($this->dataStore("result")->countData()>0)
    {
    Table::create(array(
        "dataStore"=>$this->dataStore("result"),
        "cssClass"=>array(
            "table"=>"table table-bordered"
        ),
        "showFooter"=>true,
        "options"=>array(
            "paging"=>true,
        ),
        "columns"=>array(
            
            "order_date"=>array(
                "cssStyle"=>"text-align:center",
                "label"=>"Order Date",
            ),
            "user_id"=>array(
                "label"=>"Customer ID",
                "type"=>"number",
            ),
            "customer_name"=>array(
                "label"=>"Customer Name",
                "footerText"=>"<b>Total</b>"
            ),
            "rides"=>array(
                "cssStyle"=>"text-align:right",
                "label"=>"Rides",
                "type"=>"number",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"
            ),
            "rider_charges"=>array(
                "cssStyle"=>"text-align:right",
                "label"=>"DC",
                "type"=>"number",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"
            ),
            "order_total"=>array(
                "cssStyle"=>"text-align:right",
                "label"=>"GMV",
                "type"=>"number",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"
            ),
        ),
        "paging"=>array(
            "pageSize"=>10,
        ),
    ));
    }
    else
    {
    ?>
        <div class="alert alert-warning">
            <i class="glyphicon glyphicon-info-sign"></i> Sorry, we found no orders.
        </div>
    <?php    
    }
    ?>
</div>

Screenshot:

.

regards

AhmedHaroon commented on Feb 16, 2023

@Sebastian Morales

now CustomerSummary is working fine on both Local and Staging, after some more testing, we will upload to Live server. created new files.

thank you all especially Sebastian Morales to help me.

CustomerSummary.php

<?php
namespace App\reports;

require_once ROOTPATH . "load.koolreport.php";

use \koolreport\KoolReport;
use \koolreport\processes\Sort;
use \koolreport\processes\Map;
use \koolreport\processes\Limit;
use \koolreport\processes\Filter;
use \koolreport\cube\processes\Cube;
use \koolreport\pivot\processes\Pivot;
use \koolreport\processes\TimeBucket;

class CustomerSummary extends \koolreport\KoolReport
{
    //use \koolreport\bootstrap4\Theme;
    use \koolreport\amazing\Theme;
    use \koolreport\codeigniter\Friendship;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;
    use \koolreport\excel\BigSpreadsheetExportable;

    protected function defaultParamValues()
    {
        $start = isset($_SESSION["startDate"]) ? $_SESSION["startDate"] : date("2022-12-01");
        $end = isset($_SESSION["endDate"]) ? $_SESSION["endDate"] : date("2022-12-01");
        return array(
            "dateRange"=>array($start ,$end),
            "customers"=>NULL,
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "dateRange",
            "customers",
        );
    }
    // 
    function setup()
    {
        $_SESSION["startDate"] = $this->params["dateRange"][0];
        $_SESSION["endDate"] = $this->params["dateRange"][1];
        $_SESSION["customers"] = $this->params["customers"];
        $this->src("default")
        ->query("SELECT DATE(order_date) AS order_date, user_id, customer_name, rides,rider_charges, order_total  
        FROM customer_summary 
         WHERE
            user_id = ".($this->params["customers"] == '' ? 'user_id' : ':customers')."
            AND
            order_date >= :startDate
            AND
            order_date <= :endDate")
        ->params(array(
            ":startDate"=>$this->params["dateRange"][0],
            ":endDate"=>$this->params["dateRange"][1],
            ":customers"=>$this->params["customers"]
        ))
        ->pipe(Sort::process([
            "order_date"=>"desc"
        ]))
        ->pipe($this->dataStore("result"));

        $this->src("default")->query("
            SELECT DISTINCT 
                user_id,
                customer_name
            FROM
                customer_summary
            ORDER BY customer_name
        ")
        ->pipe($this->dataStore("customerslov"));
    }
}

CustomerSummary.view.php

<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\inputs\DateRangePicker;
use \koolreport\inputs\Select2;

?> 
<style>
    .amazing {
        width: 40%;
    }
    .select2 {
        width: 100% !important;
    }

    .sidebar {
        background: #ffffff !important;
    }
</style>
<div class='report-content'>
    <br />
    <div class="text-center">
        <h2>Customer Summary</h2>
        <a href="<?php echo base_url(); ?>/Customersummarypdf/DownloadPDF" class="btn btn-primary">Download PDF</a>
        <a href="<?php echo base_url(); ?>/Customersummarypdf/DownloadExcel" class="btn btn-primary">Download Excel</a>
    </div>
    <br />
    
    <form method="post">
        <div class="row">
            <div class="col-md-8 offset-md-2">
                <div class="form-group" style="display: flex; flex-direction: row; flex-wrap: nowrap; align-content: center; justify-content: center; align-items: center; margin-bottom: 1rem;">
                    <?php
                        DateRangePicker::create(array(
                            "name"=>"dateRange",
                            "format"=>"YYYY-MM-DD"
                        ))
                    ?>
                <strong>Select Customer</strong>
                <?php
                Select2::create(array(
                    "name"=>"customers",
                    "dataStore"=>$this->dataStore("customerslov"),
                    "defaultOption"=>array(
                        "All"=>NULL
                    ),
                    "dataBind"=>array(
                        "text"=>"customer_name",
                        "value"=>"user_id",
                    ),
                    "attributes"=>array(
                        "class"=>"form-control",
                    )
                ));
                ?>
                <div class="form-group text-center" style="margin-left: 1rem;margin-bottom: 0rem;">
                    <button class="btn btn-success"><i class="glyphicon glyphicon-refresh"></i> Load</button>
                </div>
            </div>
        </div>
    </form>
    </div>
    </div>

    </script>
    <?php
    // echo '<pre>';
    // print_r($this->dataStore("result"));
    // die;
    if($this->dataStore("result")->countData()>0)
    {
        Table::create(array(
            "dataStore"=>$this->dataStore("result"),
            "cssClass"=>array(
                "table"=>"table table-bordered"
            ),
            "showFooter"=>true,
            "options"=>array(
                "paging"=>true,
            ),
            "columns"=>array(
                
                "order_date"=>array(
                    "cssStyle"=>"text-align:center",
                    "label"=>"Order Date",
                ),
                "user_id"=>array(
                    "label"=>"Customer ID",
                    "type"=>"number",
                ),
                "customer_name"=>array(
                    "label"=>"Customer Name",
                    "footerText"=>"<b>Total</b>"
                ),
                "rides"=>array(
                    "cssStyle"=>"text-align:right",
                    "label"=>"Rides",
                    "type"=>"number",
                    "footer"=>"sum",
                    "footerText"=>"<b>@value</b>"
                ),
                "rider_charges"=>array(
                    "cssStyle"=>"text-align:right",
                    "label"=>"DC",
                    "type"=>"number",
                    "footer"=>"sum",
                    "footerText"=>"<b>@value</b>"
                ),
                "order_total"=>array(
                    "cssStyle"=>"text-align:right",
                    "label"=>"GMV",
                    "type"=>"number",
                    "footer"=>"sum",
                    "footerText"=>"<b>@value</b>"
                ),
            ),
            "paging"=>array(
                "pageSize"=>10,
            ),
    ));
    }
    else
    {
    ?>
        <div class="alert alert-warning">
            <i class="glyphicon glyphicon-info-sign"></i> Sorry, we found no orders.
        </div>
    <?php    
    }
    ?>
</div>

Screenshot:

. .

regards

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
solved

None