KoolReport's Forum

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

Please help with CalculatedColumn #958

Closed Eugene opened this topic on on Jul 2, 2019 - 2 comments

Eugene commented on Jul 2, 2019

Hi Koolreport,

something is going wrong in my code but i cannot find the reason

1.I have 2 datasources

The first is based on the sql query

$this->src('quinos')
            ->query($query)
            ->params($query_params)
            ->saveTo($fromsql)
            ->pipe($this->dataStore('stock'));

The second gets data from the CSV file

$this->src('fact')
                ->saveTo($fromcsv)
                ->pipe($this->dataStore('from_csv'));

The CSV file looks like this

name,fact
Bintang 330,54
Heineken,16

After that I use the Join process and it works ok

$join = new Join($fromsql, $fromcsv, array("name" => "name"));

After that i tried to do the following:

$join->pipe(new CalculatedColumn(array(
                "diff" => "{fact}-{balance}", //'balance' is the field from sql query
                "diff_proc" =>"0",
            )))
                ->pipe($this->dataStore("joined_stock"));

And get a PHP error message:

PHP Parse error:  syntax error, unexpected '--' (T_DEC) in .../koolreport/core/src/processes/CalculatedColumn.php(136) : eval()'d code on line 1

If i keep "diff" => "{fact}", only I also get error message

My next step - trying to use functions but why the examples above don't work correctly?

KoolReport commented on Jul 3, 2019

The root of formular "{fact}-{balance}" is that it try to replace {fact} and {balance} with real value and then use eval() to calculate. However, in some cases, if your data contain NULL for example, it will generate empty string on {fact} or {balance} which will case issue for eval() function. Better you use calculated function.

Eugene commented on Jul 3, 2019

Calculated function works. Thanks

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