Please these are the files.
Index file (RevQtr.php)
<?php
require_once "RevQuarters.php";
$salesYear = isset($_POST['salesYear']) ? $_POST['salesYear'] : array(2017, 2018, 2019, 2020, 2021, 2022);
$report = new RevQuarters(array(
'salesYear' => $salesYear
));
echo $report->run()->render(); ?>
Setup file (RevQuarters.php)
<?php
require_once "../load.koolreport.php";
use \koolreport\processes\ColumnMeta;
use \koolreport\processes\Limit;
use \koolreport\processes\Sort;
use \koolreport\processes\TimeBucket;
use \koolreport\processes\RemoveColumn;
use \koolreport\processes\OnlyColumn;
use \koolreport\processes\Filter;
use \koolreport\processes\ValueMap;
use \koolreport\cube\processes\Cube;
use \koolreport\core\Utility;
class RevQuarters extends koolreport\KoolReport
{
use \koolreport\export\Exportable;
use \koolreport\clients\Bootstrap;
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
function settings()
{
return array(
"dataSources" => array(
"dollarsales"=>array(
"connectionString"=>"mysql:host=localhost;dbname=mlnrgh",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
),
)
);
}
Protected function setup()
{
//$salesYear = $this->params['salesYear'];
$salesYear = isset($_POST['salesYear']) ?
$_POST['salesYear'] : array(2017, 2018, 2019, 2020, 2021, 2022);
$node=$this->src('dollarsales')
->query("SELECT QUARTER(DateDisbursed) as 'Q', YEAR(DateDisbursed) as 'Y', Region, Beneficiaries, Amount FROM revenuereturns")
->pipe(new ColumnMeta(array(
"Amount"=>array(
'type' => 'number',
"prefix" => "¢",
),
)))
->pipe(new ValueMap(array(
'Q' => array(
'{func}' => function ($value) {
return 'Q' . $value;
},
"{meta}" => array(
"type" => "string"
),
)
)));
$filters = array('or');
foreach ($salesYear as $year)
array_push($filters, array('Y', '=', ''.$year));
$node = $node->pipe(new Filter($filters));
$node->pipe($this->dataStore('salesFilter'));
$node->pipe(new Cube(array(
"row" => "Region",
"column" => "Q",
"sum" => "Amount"
)))
->pipe(new Sort(array(
'{{all}}' => 'asc'
)))
->pipe(new Limit(array(
20, 0
)))->pipe(new ColumnMeta(array(
"{{all}}"=>array(
"label"=>"Total",
),
"Region"=>array(
"label"=>"Region",
),
)))->saveTo($node2);
$node2->pipe($this->dataStore('salesQuarterProductName'));
$node2->pipe(new RemoveColumn(array(
"{{all}}"
)))
->pipe($this->dataStore('salesQuarterProductNameNoAll'));
$node2->pipe(new OnlyColumn(array(
'Region', "{{all}}"
)))->pipe($this->dataStore('salesQuarterProductNameAll'));
}
}
View Report file (RevQuarter.view.php)
<?php
use \koolreport\widgets\google;
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\ColumnChart;
use \koolreport\inputs\Select;
use \koolreport\clients\bootstrap;
?>
<div class="report-content">
<div class="text-center">
<h1>Revenue Summary by Regions</h1>
<p class="lead">
</p>
</div>
<?php
$salesYear = isset($_POST['salesYear']) ?
$_POST['salesYear'] : array(2017, 2018, 2019, 2020, 2021, 2022);
?>
<form method="post" class="text-center">
<div class="form-group">
<span style="margin-left:10px;">
<input id="y2017" type="checkbox" name="salesYear[]" value="2017"
<?php echo in_array(2017, $salesYear) ? 'checked' : '' ?> />
<label for="y2017">2017</label>
</span>
<span style="margin-left:10px;">
<input id="y2018" type="checkbox" name="salesYear[]" value="2018"
<?php echo in_array(2018, $salesYear) ? 'checked' : '' ?> />
<label for="y2018">2018</label>
</span>
<span style="margin-left:10px;">
<input id="y2019" type="checkbox" name="salesYear[]" value="2019"
<?php echo in_array(2019, $salesYear) ? 'checked' : '' ?> />
<label for="y2019">2019</label>
</span>
<span style="margin-left:10px;">
<input id="y2020" type="checkbox" name="salesYear[]" value="2020"
<?php echo in_array(2020, $salesYear) ? 'checked' : '' ?> />
<label for="y2020">2020</label>
</span>
<span style="margin-left:10px;">
<input id="y2021" type="checkbox" name="salesYear[]" value="2021"
<?php echo in_array(2021, $salesYear) ? 'checked' : '' ?> />
<label for="y2021">2021</label>
</span>
<span style="margin-left:10px;">
<input id="y2022" type="checkbox" name="salesYear[]" value="2022"
<?php echo in_array(2022, $salesYear) ? 'checked' : '' ?> />
<label for="y2022">2022</label>
</span>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
<button formaction="exportgood.php" class="btn btn-primary">Download PDF</button>
</div>
</form>
<?php
Table::create(array(
"dataStore" => $this->dataStore('salesQuarterProductName'),
));
?>
<div class='row'>
<div class="col-md-6">
<?php
google\BarChart::create(array(
"dataStore"=>$this->dataStore('salesQuarterProductNameNoAll'),
"options"=>array(
'title' => 'Barchart Showing Revenue by Regions',
'isStacked' => true
),
"width"=>'100%',
// 'height'=>'400px',
));
?>
</div>
<div class="col-md-6">
<?php
google\PieChart::create(array(
"dataStore"=>$this->dataStore('salesQuarterProductNameAll'),
"options"=>array(
'title' => 'Piechart Showing Revenue by Regions',
),
"width"=>'100%',
// 'height'=>'300px',
));
?>
</div>
</div>
</div>
Export Pdf file (RevQuartersPdf.view.php)
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\ColumnChart;
use \koolreport\widgets\google\PieChart;
?>
<html>
<body style="margin:0.5in 1in 0.5in 1in">
<link rel="stylesheet" href="../../assets/bootstrap3/bootstrap.min.css" />
<link rel="stylesheet" href="../../assets/bootstrap3/bootstrap-theme.min.css" />
<div class="page-header" style="text-align:right"><i>Revenue Summary</i></div>
<div class="page-footer" style="text-align:right">{pageNum}</div>
<hr/>
<div class="report-content">
<?php
$salesYear = isset($_POST['salesYear']) ?
$_POST['salesYear'] : array(2017, 2018, 2019, 2020, 2021, 2022);
$salesYearStr = implode(", ", $salesYear);
?>
<div class="text-center">
<h1>Revenue Summary By Regions <?php echo $salesYearStr; ?></h1>
</h1>
<p class="lead">
</p>
</div>
<?php
Table::create(array(
"dataStore" => $this->dataStore('salesQuarterProductName'),
//WHERE salesYear !checked;
));
?>
<div class='row'>
<div class="col-md-6">
<?php
ColumnChart::create(array(
"dataStore"=>$this->dataStore('salesQuarterProductNameNoAll'),
"options"=>array(
'title' => 'Barchart Showing Revenue by Regions',
'isStacked' => true
),
"width"=>'100%',
// 'height'=>'400px',
));
?>
</div>
<div class="col-md-6">
<?php
PieChart::create(array(
"dataStore"=>$this->dataStore('salesQuarterProductNameAll'),
"options"=>array(
'title' => 'Piechart Showing Revenue by Regions',
),
"width"=>'100%',
// 'height'=>'300px',
));
?>
</div>
</div>
</div>
</body>
</html>
Export File (exportgood.php)
<?php
require_once "RevQuarters.php";
$report = new RevQuarters;
$report->run()
->export('RevQuartersPdf')
->pdf(array(
"format"=>"A4",
"orientation"=>"portrait",
"zoom"=>2
))
->toBrowser("Rev_Quarters.pdf", true);