Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
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
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.
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
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo