The report show total sales on each country. All sale data pulled from databases will be grouped by country and sum the sale for each. Later, the report use GeoChart
to better visualize total sales on each country as you can see above. Detail sale amount is put under Table
below. The table supports paging which is very suitable when we have a long list of data.
<?php
require_once "SalesByCountry.php";
$report = new SalesByCountry;
$report->run()->render();
<?php
require_once "../../../load.koolreport.php";
use \koolreport\processes\CalculatedColumn;
use \koolreport\processes\ColumnMeta;
class SalesByCountry extends \koolreport\KoolReport
{
public function settings()
{
return array(
"dataSources"=>array(
"automaker"=>array(
"connectionString"=>"mysql:host=localhost;dbname=automaker",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
)
)
);
}
public function setup()
{
$this->src('automaker')
->query("
select customers.country,sum(orderdetails.quantityOrdered*orderdetails.priceEach) as amount
from orders
join orderdetails on orderdetails.orderNumber = orders.orderNumber
join customers on customers.customerNumber = orders.customerNumber
group by customers.country
")
->pipe(new CalculatedColumn(array(
"tooltip"=>"'{country} : $'.number_format({amount})",
)))
->pipe(new ColumnMeta(array(
"tooltip"=>array(
"type"=>"string",
)
)))
->pipe($this->dataStore("sales"));
}
}
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\GeoChart;
?>
<div class='report-content'>
<div class="text-center">
<h1>Sales By Country</h1>
<p class="lead">The report show total sales on each countries</p>
</div>
<?php
GeoChart::create(array(
"dataStore"=>$this->dataStore("sales"),
"columns"=>array(
"country"=>array(
"label"=>"Country"
),
"amount"=>array(
"label"=>"Sales",
"type"=>"number",
"prefix"=>"$"
)
),
"width"=>"100%",
"options"=>array(
"showTooltip"=> true,
"showInfoWindow"=> true
)
));
?>
<?php
Table::create(array(
"dataStore"=>$this->dataStore("sales")->sort(array("amount"=>"desc")),
"columns"=>array(
"country"=>array(
"label"=>"Country"
),
"amount"=>array(
"label"=>"Amount",
"type"=>"number",
"prefix"=>"$",
)
),
"paging"=>array(
"pageSize"=>10,
),
"cssClass"=>array(
"table"=>"table table-bordered table-striped"
)
));
?>
</div>