Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
Hi David.
Here is my php code:
protected function defaultParamValues()
{
return array(
"dateRange" => array(
date("Y-m-d H:i:s", strtotime('- 1 month')),
date("Y-m-d H:i:s", strtotime('+ 1 day')),
),
"clients" => array(),
"offers" => array(),
);
}
protected function bindParamsToInputs()
{
return array(
"dateRange" => "dateRange",
"clients" => "clients",
"offers" => "offers",
);
}
function setup()
{
$params = array(
":startDate" => $this->params["dateRange"][0],
":endDate" => $this->params["dateRange"][1],
);
if($this->params["clients"]!=array())
{
$params[":clients"] = $this->params["clients"];
}
if($this->params["offers"]!=array())
{
$params[":offers"] = $this->params["offers"];
}
$sql = $this->buildSql();
$this->src('pgsql')
->query($sql)
->params($params)
->pipe(new Pivot(array(
"dimensions" => array(
"column" => "",
"row" => "client, offer, name",
),
"aggregates" => array(
"sum" => "init_count_balance, count_income, count_outcome, final_count_balance, init_summ_balance, summ_income, summ_outcome, final_summ_balance"
),
)))
->pipe($this->dataStore('deptsoffers'));
$this->src('pgsql')
->query('SELECT id, name FROM clients')
->pipe($this->dataStore('clients'));
$this->src('pgsql')
->query('SELECT id, name FROM offers')
->pipe($this->dataStore('offers'));
Here is sample data:
but in this case everything working fine:
but when database return NULL i am having {{other}}
Hi Dimitry,
By default, if a row is processed by Pivot ($row) with certain defined fields and the row doesn't contain a field (for example: "client"), Pivot will assign value "{{other}}" for that $row["client"]. In the end the "client" field will include distinct values like "Company A", "Company B",... and "{{other}}" for all the null $row["client"].
If you want to avoid the case when all values are "{{other}}", it's best to filter out totally null rows with either Filter or Map process so that no null row is processed by Pivot. Let us know if you need any help with filtering null rows. Thanks!
Hi Dimitry,
To filter out totally null rows, please try the following code:
->pipe(new \koolreport\processes\Map([
'{value}' => function ($row) {
$isAllNull = true;
foreach ($row as $v)
if (isset($v))
$isAllNull = false;
if (! $isAllNull)
return $row;
},
]))
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo