Sales By Country

The report show total sales on each countries

CountryAmount
USA $3,273,280
Spain $1,099,389
France $1,007,374
Australia $562,583
New Zealand $476,847
UK $436,947
Italy $360,617
Finland $295,149
Norway $270,846
Singapore $263,998
Denmark $218,995
Canada $205,912
Germany $196,471
Austria $188,540
Sweden $187,638
Japan $167,910
Switzerland $108,778
Belgium $100,069
Philippines $87,468
Ireland $49,898
Hong Kong $45,481

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 "../../../../koolreport/autoload.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>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport