KoolReport's Forum

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

Undefined variable: toFormat return "new Date #787

Closed paulo opened this topic on on Apr 8, 2019 - 5 comments

paulo commented on Apr 8, 2019

Hi, I hope someone can help me with this. Thanks in advance.

I am trying to use the timeline chart format, but I am getting: ""Undefined variable: toFormat (View: C:\dev-test\laravel\resources\views\report.blade.php)"" It seems the code is breaking on the line:

if ($date) {
    return "new Date(" . \DateTime::createFromFormat($format, $value)->format($toFormat) . ")";
}

The setup is very straight forward, returning just a name and dates from Mysql.

 $this->src('mysql')
            ->query("
            select  concat(Prefix, ' ' ,name) as name, startDate, endDate   
            from tours   
            where startDate  >= CURDATE()      
        ")
            ->pipe($this->dataStore("toursTimeline"));

In the view, I tried with

 "dataStore" => $this->dataStore('toursTimeline'),

and

"dataSource" => $this->dataStore("toursTimeline"),

to see if it made any difference. But I was still getting the same error.

both startDate and endDate are defined as dates in MySQL.

Thank you

KoolReport commented on Apr 10, 2019

In your timeline, please try this

Timeline::create(array(
 "dataStore" => $this->dataStore('toursTimeline'),
"columns"=>array(
    "name",
    "startDate"=>array(
        "type"=>"date",
    ),
    "endDate"=>array(
        "type"=>"date",
    ),
)
))
KoolReport commented on Apr 10, 2019

Could you please help to go to line 50 and replace the whole method newClientDate() in \koolreport\widgets\google\Timeline.php with this new one:

    protected function newClientDate($value, $meta)
    {
        $format = Utility::get($meta, "format");
        $type = Utility::get($meta, "type");
        switch ($type) {
        case "date":
            $format = $format?$format:"Y-m-d";
            $toFormat = "Y,(n-1),d";
            break;
        case "time":
            $format = $format?$format:"H:i:s";
            $toFormat = "0,0,0,H,i,s";
            break;
        case "datetime":
        default:
            $format = $format?$format:"Y-m-d H:i:s";
            $toFormat = "Y,(n-1),d,H,i,s";
            break;
        }
        //The (n-1) above is because in Javascript, month start from 0 to 11
        $date = \DateTime::createFromFormat($format, $value);

        if ($date) {
            return "new Date(" . \DateTime::createFromFormat($format, $value)->format($toFormat) . ")";
        }
        return "null";
    }

Let me know if it works.

paulo commented on Apr 15, 2019

yes, changing directly inside of vendor code worked. Is there an 'official' patch for this fix ? thanks

KoolReport commented on Apr 15, 2019

It will be available in the next release.

paulo commented on Apr 15, 2019

ok, thank you !

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