Here comes the code:
SalesByCountry.php
<?php
require_once "../../../../../koolreport/autoload.php";
use \koolreport\processes\CalculatedColumn;
use \koolreport\processes\ColumnMeta;
class SalesByCountry extends \koolreport\KoolReport
{
public function settings()
{
$config = include "../../../config.php";
return array(
"dataSources"=>array(
"automaker"=>$config["automaker"]
)
);
}
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"));
}
}
SalesByCountry.view.php
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\Map;
?>
<div class="text-center">
<h1>Sales By Country</h1>
<h4>The report show total sales on each countries</h4>
</div>
<hr/>
<?php
Map::create(array(
"dataStore"=>$this->dataStore("sales"),
"columns"=>array(
"country",
"tooltip"
),
"width"=>"100%",
"options"=>array(
"showTooltip"=> true,
"showInfoWindow"=> true
)
));
?>
<?php
Table::create(array(
"dataStore"=>$this->dataStore("sales"),
"columns"=>array(
"country"=>array(
"label"=>"Country"
),
"amount"=>array(
"label"=>"Amount",
"type"=>"number",
"prefix"=>"$",
)
)
));
?>
index.php
<?php
require_once "SalesByCountry.php";
$report = new SalesByCountry;
$report->run();
?>
<!DOCTYPE >
<html>
<head>
<title>Sales By Country</title>
<link rel="stylesheet" href="../../../assets/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="../../../assets/bootstrap/css/bootstrap.theme.min.css" />
<link rel="stylesheet" href="../../../assets/css/example.css" />
<script async defer src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_MAP_API_KEY&callback=initMap"
type="text/javascript"></script>
</head>
<body>
<div class="container box-container">
<?php $report->render();?>
</div>
</body>
</html>
Notice: In the index.php
, you need to put the GOOGLE_MAP_API_KEY, you need to acquire a key from Get API Key.
Hope that helps.