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
All Years

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 by month in that year. it is pretty straight-forward.

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\DrillDown;
    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
    DrillDown::create(array(
        "name"=>"saleDrillDown",
        "title"=>"Sale Report",
        "levels"=>array(
            array(
                "title"=>"All Years",
                "content"=>function($params,$scope)
                {
                    ColumnChart::create(array(
                        "dataSource"=>(
                            $this->src("automaker")->query("
                                SELECT YEAR(paymentDate) as year,sum(amount) as sale_amount 
                                FROM payments
                                GROUP BY year
                            ")
                        ),
                        "columns"=>array(
                            "year"=>array(
                                "type"=>"string",
                                "label"=>"Year",
                            ),
                            "sale_amount"=>array(
                                "label"=>"Sale Amount",
                                "prefix"=>"$",
                            )
                        ),
                        "clientEvents"=>array(
                            "itemSelect"=>"function(params){
                                saleDrillDown.next({year:params.selectedRow[0]});
                            }",
                        )
                    ));
                }
            ),
            array(
                "title"=>function($params,$scope)
                {
                    return "Year ".$params["year"];
                },
                "content"=>function($params,$scope)
                {
                    ColumnChart::create(array(
                        "dataSource"=>(
                            $this->src("automaker")->query("
                                SELECT MONTH(paymentDate) as month,sum(amount) as sale_amount 
                                FROM payments
                                WHERE YEAR(paymentDate)=:year
                                GROUP BY month
                            ")
                            ->params(array(
                                ":year"=>$params["year"]
                            ))
                        )
                        ,
                        "columns"=>array(
                            "month"=>array(
                                "type"=>"string",
                                "formatValue"=>function($value)
                                {
                                    return date('M', mktime(0, 0, 0, $value, 10));
                                }
                            ),
                            "sale_amount"=>array(
                                "label"=>"Sale Amount",
                                "prefix"=>"$",
                            )
                        ),
                        "clientEvents"=>array(
                            "itemSelect"=>"function(params){
                                saleDrillDown.next({month:params.selectedRow[0]});
                            }",
                        )
                    ));
                }        
            ),
            array(
                "title"=>function($params,$scope)
                {
                    return date('F', mktime(0, 0, 0, $params["month"], 10));
                },
                "content"=>function($params,$scope)
                {
                    ColumnChart::create(array(
                        "dataSource"=>(
                            $this->src("automaker")->query("
                                SELECT paymentDate, DAY(paymentDate) as day,sum(amount) as sale_amount 
                                FROM payments
                                WHERE 
                                    YEAR(paymentDate)=:year
                                    AND
                                    MONTH(paymentDate)=:month 
                                GROUP BY day
                            ")
                            ->params(array(
                                ":year"=>$params["year"],
                                ":month"=>$params["month"],
                            ))
                        ),
                        "columns"=>array(
                            "day"=>array(
                                "formatValue"=>function($value,$row){
                                    return date("F jS, Y",strtotime($row["paymentDate"]));
                                },
                            ),
                            "sale_amount"=>array(
                                "label"=>"Sale Amount",
                                "prefix"=>"$",
                            )
                        )
                    ));
                }                
            )
        ),
    ));
    ?> 
</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