KoolReport's Forum

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

Issue with Date input binding #2486

Closed iWorQ Systems opened this topic on on Dec 8, 2021 - 8 comments

iWorQ Systems commented on Dec 8, 2021

I am trying to use 3 different Date pickers on 3 separate charts, and I am having an issue getting the parameters set up correctly.

My Code:

<?php

// Require autoload.php from koolreport library
require_once "../vendor/autoload.php";


// //Specify some data processes that will be used to process
use koolreport\processes\Group;
use koolreport\processes\Sort;
use koolreport\processes\Limit;
use koolreport\processes\ColumnRename;

//Define the class
class MyReport2 extends \koolreport\KoolReport
{
    use \koolreport\clients\Bootstrap;
    use \koolreport\amazing\Theme;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    
    protected function defaultParamValues()
    {
        $year = date("Y") . '-01-01 00:00:00';
        $today = date("Y-m-d") . ' 23:59:59';
        return array(
            "permitTypeDate"=>array(
                $year,
                $today
            ),
            "permitStatusDate"=>array(
                $year,
                $today
            ),
            "purchaseDate"=>array(
                $year,
                $today
            ),
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "permitTypeDate"=>"permitTypeDate",
            "permitStatusDate"=>"permitStatusDate",
            "purchaseDate"=>"purchaseDate",
        );
    }

    public function settings()
    {
        return array(
            "dataSources" => array(
                "automaker" => array(
                    'connectionString' => 'sqlsrv:Server=' . getenv("DB_HOST") . ';Database=' . getenv("DB_NAME") . '',
                    'username' => getenv("DB_USER"),
                    'password' => getenv("DB_PASS"),
                ),
            )
        );
    }

When I try to run this I get an error that states, 0Cannot use object of type Permit as array ../vendor/koolreport/inputs/Bindable.phpline 29

I am not sure what is going on and could use some help in this situation

KoolReport commented on Dec 8, 2021

Do you have any Permit object that input into report like this?

$report = new MyReport2($permitObject);
iWorQ Systems commented on Dec 8, 2021

Ah yes that was indeed the issue, but now I am having an issue with the actual dateRangepickers I want to be able to update the sql call for the given chart whenever the date is changed. When I try to use the clientEvents nothing seems to happen when I change the dates. I was just wondering what I would actually need to do for this to work. here is my .view file

<?php

    use koolreport\widgets\koolphp\Table;
    use koolreport\datagrid\DataTables;
    use \koolreport\widgets\google\DonutChart;
    use \koolreport\widgets\google\ColumnChart;
    use \koolreport\inputs\DateRangePicker;
    use \koolreport\amazing\AmazingTheme;



?>
<div class="report-content">
    <div class="text-center">
    </div>
    <div class = "row">
        <div class="col-md-4" style='background-color:#fafafa'> 
            <div class="form-group">
            <?php
            DateRangePicker::create(array(
                "name"=>"permitTypeDate",
                "clientEvents"=>array(
                    "change"=>"function(e){
                        console.log(e.date);
                        console.log(e.oldDate);
                    }",
                )
            ));
            ?>
            </div>
            <div class="form-group">
                <?php
                DonutChart::create(array(
                    "title"=>"Permit Types",
                    "dataSource" => $this->dataStore('permitType'),
                    "columns"=>array(
                        "permittypename",
                        "totalPermitType"=>array(
                            "type"=>"number",
                        )
                    )
                ));
                ?>
            </div>
        </div>
        <div class="col-md-4" style='background-color:#fafafa'>
        <div class="form-group">
        <?php
            DateRangePicker::create(array(
                "name"=>"permitStatusDate",
                "clientEvents"=>array(
                    "change"=>"function(e){
                        console.log(e.date);
                        console.log(e.oldDate);
                    }",
                )
            ));
        ?>
        </div>
        <div class="form-group">
        <?php
        DonutChart::create(array(
            "title"=>"Permit Status",
            "dataSource" => $this->dataStore('permitStatus'),
            "columns"=>array(
                "statusname",
                "totalPermitStatus"=>array(
                    "type"=>"number",
                )
            )
        ));
        ?>
        </div>
        </div>
        <div class="col-md-4" style='background-color:#fafafa'>
        <div class="form-group">
        <?php
        DateRangePicker::create(array(
            "name"=>"PaymentDate",
            "clientEvents"=>array(
                "change"=>"function(e){
                    console.log(e.date);
                    console.log(e.oldDate);
                }",
            )
        ));
        ?>
        </div>
        <div class="form-group">
        <?php
        ColumnChart::create(array(
            "title"=>"Payments By Month",
            "dataSource"=>$this->dataStore('PaymentDate'),
            "columns"=>array(
                "month",
                "total"=>array("label"=>"total","type"=>"number","prefix"=>"$"),
            )
        ));
        ?>
        </div>
    </div>
</div>
KoolReport commented on Dec 8, 2021

Let try to change the "change" to "apply" event. Let see if it works.

iWorQ Systems commented on Dec 8, 2021

Ok so that gives me the values, how do I update the charts/query?

KoolReport commented on Dec 8, 2021

You need to put those date range picker inside a form, add a submit button. When the form is submitted to server, those value from pickers will be bound to params of report, and you use those params to change your query. Please see our input examples for more details.

iWorQ Systems commented on Dec 8, 2021

So there is no way that when a Date is changed that we can run the submit through that?

iWorQ Systems commented on Dec 9, 2021

We got it all figured out thanks for your time!

KoolReport commented on Dec 10, 2021

That's great!

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
solved

Inputs