koolphp / koolreport

This is an Open Source PHP Reporting Framework which you can use to write perfect data reports or to construct awesome dashboards using PHP
https://www.koolreport.com/
MIT License
226 stars 66 forks source link

Getting Error "Undefined offset: 0" when result is empty #17

Closed BernhardK91 closed 5 years ago

BernhardK91 commented 5 years ago

Hey there,

I am getting an "Undefined offset: 0"-Error when the result is empty. Is there a way to handle empty results?

Thank you in advance!

koolphp commented 5 years ago

May you post the whole error?

BernhardK91 commented 5 years ago

Good Morning and thank you for your fast response.

Here is the full error: Undefined offset: 0 (View: D:\Projekte\[...]\resources\views\crm\customer\overview.blade.php)

And here is the relevant code:

Table::create([
[...]
    "grouping"=>array(
        "AUFTRAG_NUMMER"=>array(
            "calculate"=>array(
                "{sumPrice}" => array("sum","TOTAL_PRICE"),
                "{AU}" => function($store) {
                    return "Auftrags-Nr. " . $store->data()[0]['AUFTRAG_NUMMER'] . " vom " .
                        date('d.m.Y',strtotime($store->data()[0]['AU_DATUM']));
                },
[...]
        ),
    ),
    'columns' => [
[...]
    ],
]);

Thank you in advance!

koolphp commented 5 years ago

It is actually a bug that we have fixed but have not released yet. The bug report was here.

Please download the new Table.tpl.php file and help us to replace the old file in \koolreport\src\widgets\koolphp" folder.

Table.tpl.zip

Let me know if it solves the issue.

BernhardK91 commented 5 years ago

I see I can handle the Undefined offset in my function like:

if(isset($store->data()[0])) {
    return "Auftrags-Nr. " . $store->data()[0]['AUFTRAG_NUMMER'] . " vom " .
        date('d.m.Y', strtotime($store->data()[0]['AU_DATUM']));
}
return "";

But when I do so, I am getting the following Error: Undefined variable: i in D:\Projekte\[...]\vendor\koolphp\koolreport\src\widgets\koolphp\Table.tpl.php

The dataStore is empty in that case, and I think that is the reason for that Error.

koolphp commented 5 years ago

Have you been able to replace the file? Does it work?

BernhardK91 commented 5 years ago

It is actually a bug that we have fixed but have not released yet. The bug report was here.

Please download the new Table.tpl.php file and help us to replace the old file in \koolreport\src\widgets\koolphp" folder.

Thank you very much! That fixed the "Undefined variable: i"-Issue. In combination with my error handling in the function that issue is completely solved!

Thanks a lot and Merry Christmas!

koolphp commented 5 years ago

Merry Christmas!