KoolReport's Forum

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

Daterange Input issue #3340

Open pargibay opened this topic on on Sep 19 - 11 comments

pargibay commented on Sep 19

Hi, I have a problem with the input package.

Since I upgraded the package to the new version, the system only shows an empty report.

I tried to show data binding and it is fine. If I revert to a previous version, the report is fine.

Regards

pargibay commented on Sep 19

i'm running php 8.2, maybe it is a problem?

Sebastian Morales commented on Sep 20

Would you pls post your code as well as screenshots of your inputs binding value after submitting?

pargibay commented on Sep 20

Hello Sebastián,

This is the report:

<?php

// Require autoload.php from koolreport library
require APPPATH."../vendor/autoload.php";

//Define the class
class Contribution extends \koolreport\KoolReport
{
    use \koolreport\codeigniter\Friendship;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;

     protected function defaultParamValues()
    {
        return array(
            "dateRange"=>array(
                date("Y-m-01"),
                date("Y-m-d")
            ),
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "dateRange"=>"dateRangeInput",
        );
    }
    public function settings()
    {
        $db=config('Database')->default;
        return [
            "dataSources"=>[
                "default"=>[
                    'host' => $db['hostname'],
                    'username' => $db['username'],
                    'password' => $db['password'],
                    'dbname' => $db['database'],
                    'charset' => 'utf8',  
                    'class' => "\koolreport\datasources\MySQLDataSource"  
                ],
            ]
        ];
    }
    public function setup()
    {
var_dump($this->params["dateRange"]);
        $this->src('default')
        ->query("SELECT 
        s.specie familia,
        m.Presentacion, 
        SUM(c.Kg) AS tn, 
        SUM(c.Valor) AS valor, 
        p.Precio,
        p.Moneda,
        p.Peso,
        SUM(c.cf) AS cf,
        SUM(c.cmp) AS cmp,
        SUM(c.Valor-c.cf-c.cmp) AS margen,
        SUM(c.Valor-c.cf-c.cmp)*100/SUM(c.Valor) AS margenkg
        FROM 
        TBLcostes c JOIN
        maestropescado m ON c.Codigo=m.Codigo JOIN
        precio p ON p.Codigo=m.Codigo JOIN
        species s ON s.id=m.species
        WHERE
        p.Fecha BETWEEN :start AND :end AND 
        c.Fecha BETWEEN :start AND :end AND 
        c.company=1
        GROUP BY
        m.Codigo,
        s.id, 
        p.Precio,
        p.Moneda,
        p.Peso") 
        ->params(array(
    ":start" => $this->params["dateRange"][0],
    ":end"   => $this->params["dateRange"][1]
        ))
        ->pipe($this->dataStore('contribution'));

        var_dump($this->dataStore('contribution')->toArray()); //verificación de fecha


///producto intermedio
        $this->src('default')
        ->query("SELECT 
        s.specie familia, 
        SUM(p.PRMATPR*p.Kgs*c.SolEur)/SUM(p.Kgs) AS coste
        FROM 
        TBLpreciomp p JOIN
        cambio c JOIN
        maestropescado m ON m.Codigo=p.Codigo JOIN
        species s ON s.id=m.species
        WHERE 
        p.Fecha BETWEEN :start AND :end AND
        company=1
        GROUP BY
        s.id") 
        ->params(array(
            ":start"=>$this->params["dateRange"][0],
            ":end"=>$this->params["dateRange"][1]
        ))
        ->pipe($this->dataStore('MPprecio'));

    }
}

And the view:

<?php
    //MyReport.view.php
    use \koolreport\inputs\Select2;
    use \koolreport\clients\Bootstrap;   
    use \koolreport\inputs\DateRangePicker;
    use \koolreport\widgets\koolphp\Table;
?>
<div class="report-content">
    <div class="text-center">
        <h1>Informe de aportación</h1>
        <p class="lead">Selecciona el rango de fechas</p>
    </div>
    <form method="post">
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                <?php
                DateRangePicker::create(array(
                    "name"=>"dateRangeInput"
                ))
                ?>
                </div>
                <div class="form-group text-center">
                    <button class="btn btn-success"><i class="glyphicon glyphicon-refresh"></i> Actualizar</button>
                </div>
            </div>
        </div>
    </form>
<?php
echo "<h1>Informe de aportación</h1>";
if($this->dataStore("contribution")->countData()>0)
    {
    echo "<h2>Compra de MP</h2>";
    Table::create(array(
        "dataSource"=>$this->dataStore('MPprecio'),
        "sorting"=>array(
            "familia"=>"asc"
        ),
        "columns"=>array(
            "familia",
            "coste"=>[
                "label"=>"Precio de compra",
                "cssStyle"=>"text-align:right",
                "formatValue"=>function($value,$row){
                        return number_format($value,2)." PEN/kg";
                    }],

        ),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));

    echo "<h2>Aportación por familia</h2>";
    Table::create(array(
        "dataSource"=>$this->dataStore('contribution'),
        "grouping"=>array(
            "familia"=>array(
                "calculate"=>array(
                    "{sumTn}"=>array("sum","tn"),
                    "{sumValor}"=>array("sum","valor"),
                    "{sumCf}"=>array("sum","cf"),
                    "{sumCmp}"=>array("sum","cmp"),
                    "{sumMargen}"=>array("sum","margen"),
                    "{avgMargen}" => function($store) {
                        $valor = $store->sum("valor");
                        if ($valor == 0) {
                            $avg = 0; // Si el denominador es 0, establecer $avg en 0
                        } else {
                            $avg = $store->sum("margen") * 100 / $valor;
                        }
                        return number_format($avg, 2) . " %";
                    },
                    //"{avgAvance}"=>function ($value,$row){return $row['sumRealmes']/$row['sumPto'];}
                ),
                "top"=>"<td><b>{familia}</b></td>",
                "bottom"=>"<td><b>Total {familia}</b></td><td><b>{sumTn}</b></td><td><b>{sumValor}</b></td><td><b></b></td><td><b>{sumCf}</b></td><td><b>{sumCmp}</b></td><td><b>{sumMargen}</b></td><td><b>{avgMargen}</b></td>",
            ),
        ),
        "sorting"=>array(
            "familia"=>"desc",
            "Presentacion"=>"asc"
        ),
        "showFooter"=>true,
        "columns"=>array(
            "Presentacion"=>[
                "footerText"=>"<b>Total</b>"],
            "tn"=>[
                "cssStyle"=>"text-align:right",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"],
            "valor"=>[
                "label"=>"Valor (€)",
                "cssStyle"=>"text-align:right",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"],
            "Precio"=>[
                "label"=>"Precio U (FOB)",
                "cssStyle"=>"text-align:right",
                "formatValue"=>function($value,$row){
                    return number_format($value,2)." ".$row['Moneda']."/".$row['Peso'];
                    },
                "footer",
                "footerText"=>"<b>n/a</b>"
                ],
            "cf"=>[
                "label"=>"Coste Fab. (€)",
                "cssStyle"=>"text-align:right",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"],
            "cmp"=>[
                "label"=>"Coste MP (€)",
                "cssStyle"=>"text-align:right",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"],
            "margen"=>[
                "label"=>"Margen (€)",
                "cssStyle"=>"text-align:right",
                "footer"=>"sum",
                "footerText"=>"<b>@value</b>"],
            "margenkg"=>[
                "label"=>"Margen",
                "cssStyle"=>"text-align:right",
                "formatValue" => function($value, $row) {
                return number_format($value, 2) . " %";
            },
            "footer" => function($dataStore) {
                $sumMargen = $dataStore->sum("margen");
                $sumTn = $dataStore->sum("tn");
                $margenKg = ($sumTn != 0) ? $sumMargen / $sumTn : 0;
                return number_format($margenKg, 2);
            },
                "footerText"=>"<b>@value</b> "],
        ),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));

}else{
    ?>
        <div class="alert alert-warning">
            <i class="glyphicon glyphicon-info-sign"></i> Lo sentimos. No hay datos para mostrar en las fechas seleccionadas.
        </div>
<?php    
    }
?>
</div>

Thank you

Regards

Sebastian Morales commented on Sep 23

I haven't seen a problem with the daterange values. If you see no data, pls test your sql query with daterange parameters replaced by its values.

pargibay commented on Sep 23

Hello Sebastian, When i set the date in the query (without bind params) the query works fine. I don't know what I can do, I tried to revert back to the update and it works, but I would like to have the update. Regards

Sebastian Morales commented on Sep 24

Ah I just realize you use MySQLDataSource class, which has a bug when binding multiple parameters in some cases. We have just released KoolReport 6.6.0 which fixes this issue. You can update the koolreport/core package to version 6.6.0 or use another class such as PDODataSource to see if it helps.

pargibay commented on Sep 24

Hello Sebastian. is it possible update to the 6.6.0 version? i tried but the last version avaliable is 6.5.0 (with composer) regards

Sebastian Morales commented on Sep 25

If you run composer require koolreport/pro 6.6.0 or koolreport/core 6.6.0 what is exactly the error message?

pargibay commented on Sep 25

Hello Sebastian,

This is the error message:

 composer require koolreport/pro 6.6.0
./composer.json has been updated
Running composer update koolreport/pro
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires koolreport/pro 6.6.0 (exact version match: 6.6                     .0 or 6.6.0.0), found koolreport/pro[4.0.0, ..., 4.7.1, 5.0.0, ..., 5.16.2, 6.0.                     0, ..., 6.5.0] but it does not match the constraint.

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and re                     movals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their orig                     inal content.

Regards

Sebastian Morales commented on Sep 26

Do you have a permanent license or normal Pro license which only allows free updates for 1 year since the buy time?

pargibay commented on Sep 26

Hello Sebastian,

i generate a new token and it's working, i could get the new version. Now the report is working fine.

Thank you!

Regards

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
bug
help needed
solved

Inputs