KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Question about drilldown and multiselect #358

Open michele opened this topic on on Jul 11, 2018 - 10 comments

michele commented on Jul 11, 2018

I have a drilldown report with multiselect. For the first selection all is working fine, but clicking on year column [No data available in chart] is displayed, because (i think) multiselect values are not passed.

<?php

class SalesByZones extends \koolreport\KoolReport
{

    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;



    protected function defaultParamValues()
    {
        return array(
            "categories" => array(
                "0"
            ),
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "categories"=>"categories",
        );
    }


    public function settings()
    {
        return array(
            "dataSources"=>array(
                "sales"=>array(
                    "connectionString"=>"",
                    "username"=>"",
                    "password"=>"",
                    "charset"=>"utf8"
                )
            )
        );
    }

    function setup()
    {
        $node = $this->src('sales')
            ->query("SELECT * FROM services WHERE company_id=".CURRENT_LOGIN_COMPANY_ID." AND is_product=0 AND zone_number>0")

            ->pipe($this->dataStore('categories'));
    }


}

michele commented on Jul 11, 2018
<?php
use \koolreport\drilldown\DrillDown;
use \koolreport\processes\CopyColumn;
use \koolreport\processes\DateTimeFormat;
use \koolreport\widgets\google\ColumnChart;
//use \koolreport\chartjs\ColumnChart;
use \koolreport\inputs\MultiSelect;

?>

    <div class="text-center">

    </div>
    <hr/>
    <form method="post">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">

                <div class="form-group">
                    <?php
                    MultiSelect::create(array(
                        "name"=>"categories",
                        "dataStore"=>$this->dataStore("categories"),
                        "dataBind"=>array(
                            "text"=>"service_name",
                            "value"=>"id",
                        ),
                        "attributes"=>array(
                            "class"=>"form-control",
                            "size"=>20,
                        )
                    ));
                    ?>
                </div>
                <div class="form-group text-center">
                    <button class="btn btn-success"><i class="glyphicon glyphicon-refresh"></i> Genera</button>
                </div>
            </div>
        </div>
    </form>

    <hr/>
<?php
DrillDown::create(array(
    "name"=>"saleDrillDown",
    "title"=>"Report Zone",
    "btnBack"=>true,
    "dataSource"=>(
    $this->src('sales')
        ->query("SELECT s.zone_number, DATE(appointment_date) AS adate FROM appointments a join services s on s.id=a.service_id WHERE a.service_id IN (:categories) AND a.status='paid'")
        ->params(array(
            ":categories"=>$this->params["categories"][0]
        ))
        ->pipe(new CopyColumn(array(
            "year"=>"adate",
            "month"=>"adate",
            "day"=>"adate",
        )))
        ->pipe(new DateTimeFormat(array(
            "year"=>"Y",
            "month"=>"m",
            "day"=>"d",
        )))
    ),
    "calculate"=>array(
        "sum"=>"zone_number"
    ),
    "levels"=>array(
        array(
            "groupBy"=>"year",
            "widget"=>array(ColumnChart::class,array(
                "columns"=>array("year","zone_number"=>array(
                    "label"=>"Zone",
                    "suffix"=>' zone'
                )),
                "colorScheme"=>array("#3b9b00"),
            )),
            "title"=>"All Years",
        ),
        array(
            "groupBy"=>"month",
            "widget"=>array(ColumnChart::class,array(
                "columns"=>array("month","zone_number"=>array(
                    "label"=>"Zone",
                    "suffix"=>' zone'
                )),
                "colorScheme"=>array("#af17b5"),
            )),
            "title"=>function($params)
            {
                return "Year ".$params["year"];
            },
        ),
        array(
            "groupBy"=>"day",
            "widget"=>array(ColumnChart::class,array(
                "columns"=>array("day","zone_number"=>array(
                    "label"=>"Zone",
                    "suffix"=>' zone'
                )),
                "colorScheme"=>array("#e0dc00"),
            )),
            "title"=>function($params)
            {
                return date('F', mktime(0, 0, 0, $params["month"], 10));
            },
        ),
    ),
));
?>
michele commented on Jul 17, 2018

Please, i need answer on this topic. Thanks

michele commented on Jul 31, 2018

Support is dead?

KoolReport commented on Aug 1, 2018

We are so sorry for missing your topics. That's bad and can not be excused. Let me read your code and give answer to you asap,

KoolReport commented on Aug 1, 2018

You do this in the DrillDown:

DrillDown::create(array(
    ...
    "scope"=>array(
        "categories"=>$this->params["categories"]
    )
))

This will make the "categories" parameter persistent during ajax post back of DrillDown.

Again! We are sorry for our late reply.

michele commented on Aug 7, 2018

Sorry, tested but not working

[No data available in chart]

michele commented on Aug 13, 2018

Please, answer this, thanks a lot

KoolReport commented on Aug 14, 2018

Dear Michele, is there any error show?

michele commented on Aug 14, 2018

No errors

KoolReport commented on Aug 15, 2018

I read again my answer and I found that an important information was missing, so here I post the code again:

DrillDown::create(array(
    "scope"=>array(
        "categories"=>$this->params["categories"]
    ),
    "dataSource"=>function($scope)
    {
        return  $this->src("sales")
                ->query("SELECT s.zone_number, DATE(appointment_date) AS adate FROM appointments a join services s on s.id=a.service_id WHERE a.service_id IN (:categories) AND a.status='paid'")
                ->params(array(
                    ":categories"=>$scope['categories']
                ))
                ->pipe(new CopyColumn(array(
                    "year"=>"adate",
                    "month"=>"adate",
                    "day"=>"adate",
                )))
                ->pipe(new DateTimeFormat(array(
                    "year"=>"Y",
                    "month"=>"m",
                    "day"=>"d",
                )));                
    },
    ...
));

As you may see from above code, beside the set the scope, the dataSource will take a function with $scope as parameter. The function will return a pipe of process as before. The only difference is to use $scope["categories"] instead of $this->params["categories"] when assigning parameter to the sql.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

DrillDown