Following is output
Following is dataset: around 204759 records total
-----NotesReport.php
<?php
namespace App\Reports;
use \koolreport\KoolReport;
use \koolreport\processes\Filter;
use \koolreport\processes\ColumnMeta;
use \koolreport\pivot\processes\Pivot;
class NotesReport extends \koolreport\KoolReport
{
use \koolreport\laravel\Friendship;
// By adding above statement, you have claim the friendship between two frameworks
// As a result, this report will be able to accessed all databases of Laravel
// There are no need to define the settings() function anymore
// while you can do so if you have other datasources rather than those
// defined in Laravel.
function setup()
{
$this->src('mysql')
->query("SELECT exo.name, ct.team_name, nr.user_name, date(nr.created_date) as created_date,
YEAR(nr.created_date)as year, MONTH(nr.created_date) as month,
DAY(nr.created_date) as day, QUARTER(nr.created_date)as quarter,
SUM(IF(nr.notes_type = 126, 1, 0)) AS candidate_added
FROM `notes_report` nr
LEFT JOIN company_teams ct ON nr.team_id = ct.id
LEFT JOIN es_xero_organisation exo ON exo.id = nr.organisation_id
GROUP BY exo.name, ct.team_name, nr.user_name, nr.created_date
ORDER BY exo.name, ct.team_name, nr.user_name
")
->pipe(new Filter(array(
array('name', '<', 'Am'),
array('year', '>', 2003),
)))
->pipe(new ColumnMeta(array(
"candidate_added"=>array(
'type' => 'number',
//"prefix" => "$",
),
)))
->pipe(new Pivot(array(
"dimensions"=>array(
"row" => "name, team_name, user_name",
),
"aggregates"=>array(
"sum"=>"candidate_added",
"count"=>"candidate_added"
)
)))
->pipe($this->dataStore('pivot'));
}
}
---- NotesReport.view.php
<?php
use \koolreport\pivot\widgets\PivotTable;
?>
<div class='report-content'>
<div class="text-center">
<h1>Sale Report</h1>
<p class="lead">
Summarize amount of sales and number of sales by three dimensions: customers, categories and products
</p>
</div>
<div>
<?php
$dataStore = $this->dataStore('pivot');
PivotTable::create(array(
'dataStore'=>$dataStore,
'rowDimension'=>'row',
'measures'=>array(
'candidate_added - sum',
'candidate_added - count',
),
'rowSort' => array(
'candidate_added - sum' => 'desc',
),
'rowCollapseLevels' => array(1),
'totalName' => 'All',
'width' => '100%',
'nameMap' => array(
'candidate_added - sum' => 'Total Candidates Added',
'candidate_added - count' => 'Number of Candidates',
),
));
?>
</div>
</div>