Sale By Time

This example shows how to setup a drill down report to see sale report by time.
Please click on the column of chart to go further down on details.

Sale Report

Drill down is another most used type of report in which data is summarized in a overall level and only going to detail when needed. For example in above example, we summarize sale data by year. By clicking into column of particular year, report will load detail summary sale data of that year in month. it is pretty straight-forward.

The LegacyDrillDown widget is designed for you to easily setup a drill down. You need to define a common SQL statement to pull the whole data. In each level of drilldown, you defined which column should be grouped and which widgets will be used to visualize data. In above example, the first level will use year as group column and ColumnChart as visualization widget. In the second level, we use the month as group column. The second level will also take into account the year selection in the first level.

For your information, the LegacyDrillDown is the former DrillDown. The new DrillDown widget has different settings.

More information of DrillDown package you may find in here.

<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
require_once "../../../load.koolreport.php";

class MyReport extends \koolreport\KoolReport
{
    function settings()
    {
        return array(
            "dataSources"=>array(
                "automaker"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=automaker",
                    "username"=>"root",
                    "password"=>"",
                    "charset"=>"utf8"
                ),
            )
        );
    }
}
<?php
    use \koolreport\drilldown\LegacyDrillDown;
    use \koolreport\processes\CopyColumn;
    use \koolreport\processes\DateTimeFormat;
    use \koolreport\widgets\google\ColumnChart;
?>
<div class="report-content">
    <div class="text-center">
        <h1>Sale By Time</h1>
        <p class="lead">
            This example shows how to setup a drill down report to see sale report
            by time.
            <br/>
            Please click on the column of chart to go further down on details.
        </p>
    </div>

    <?php
    LegacyDrillDown::create(array(
        "name"=>"saleDrillDown",
        "title"=>"Sale Report",
        "btnBack"=>true,
        "themeBase"=>"bs4",
        "dataSource"=>(
            $this->src('automaker')
            ->query("SELECT amount, paymentDate FROM payments")
            ->pipe(new CopyColumn(array(
                "year"=>"paymentDate",
                "month"=>"paymentDate",
                "day"=>"paymentDate",
            )))
            ->pipe(new DateTimeFormat(array(
                "year"=>"Y",
                "month"=>"m",
                "day"=>"d",
            )))
        ),
        "calculate"=>array(
            "sum"=>"amount"
        ),
        "levels"=>array(
            array(
                "groupBy"=>"year",
                "widget"=>array(ColumnChart::class,array(
                    "columns"=>array("year","amount"=>array(
                        "label"=>"Amount",
                        "prefix"=>'$'
                    )),
                    "colorScheme"=>array("#3b9b00"),
                )),
                "title"=>"All Years",
            ),
            array(
                "groupBy"=>"month",
                "widget"=>array(ColumnChart::class,array(
                    "columns"=>array("month","amount"=>array(
                        "label"=>"Amount",
                        "prefix"=>'$'
                    )),
                    "colorScheme"=>array("#af17b5"),
                )),
                "title"=>function($params)
                {
                    return "Year ".$params["year"];
                },
            ),
            array(
                "groupBy"=>"day",
                "widget"=>array(ColumnChart::class,array(
                    "columns"=>array("day","amount"=>array(
                        "label"=>"Amount",
                        "prefix"=>'$'
                    )),
                    "colorScheme"=>array("#e0dc00"),
                )),
                "title"=>function($params)
                {
                    return date('F', mktime(0, 0, 0, $params["month"], 10));
                },
            ),
        ),
    ));
    ?> 
</div>
amountpaymentDate
6,067 2004-10-19 00:00:00
14,571 2003-06-05 00:00:00
1,676 2004-12-18 00:00:00
14,191 2004-12-17 00:00:00
32,642 2003-06-06 00:00:00
33,348 2004-08-20 00:00:00
45,864 2003-05-20 00:00:00
82,261 2004-12-15 00:00:00
7,565 2003-05-31 00:00:00
44,895 2004-03-10 00:00:00

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 Get KoolReport Pro