Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions Controller/ReportBreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ protected function getDatosAgrupadosRef(array $data, array $keys): array
return $agrupados;
}

protected function getInformeComprasDataWhere(): string
protected function getInformeComprasDataWhere(bool $withLineAlias = true): string
{
$sql = '';

Expand Down Expand Up @@ -688,7 +688,14 @@ protected function getInformeComprasDataWhere(): string
}

if (!empty($this->variant->id())) {
$sql .= " AND l.referencia = " . $this->dataBase->var2str($this->variant->referencia);
if ($withLineAlias) {
$sql .= " AND l.referencia = " . $this->dataBase->var2str($this->variant->referencia);
} else {
$lineTable = $this->type === 'invoices' ? 'lineasfacturasprov' : 'lineasalbaranesprov';
$code = $this->type === 'invoices' ? 'idfactura' : 'idalbaran';
$sql .= " AND d." . $code . " IN (SELECT " . $code . " FROM " . $lineTable
. " WHERE referencia = " . $this->dataBase->var2str($this->variant->referencia) . ")";
}
}

return $sql;
Expand All @@ -704,7 +711,7 @@ protected function getInformeComprasDocumentData(): array
. " WHERE d.fecha >= " . $this->dataBase->var2str($this->desde)
. " AND d.fecha <= " . $this->dataBase->var2str($this->hasta)
. " AND d.idempresa = " . $this->dataBase->var2str($this->idempresa)
. $this->getInformeComprasDataWhere()
. $this->getInformeComprasDataWhere(false)
. " ORDER BY d.fecha ASC, d.hora ASC;";

return $this->dataBase->select($sql);
Expand All @@ -713,17 +720,14 @@ protected function getInformeComprasDocumentData(): array
protected function getInformeComprasNetoData(): array
{
$table = $this->type === 'invoices' ? 'facturasprov' : 'albaranesprov';
$line = $this->type === 'invoices' ? 'lineasfacturasprov' : 'lineasalbaranesprov';
$code = $this->type === 'invoices' ? 'idfactura' : 'idalbaran';
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In getInformeComprasNetoData(), the local variable $code is now unused (it’s computed but never referenced in the SQL after removing the JOIN). Removing it will avoid dead code and potential static analysis warnings; alternatively, if it’s intended for the variant filter, consider reusing/passing it instead of recomputing inside getInformeComprasDataWhere(false).

Suggested change
$code = $this->type === 'invoices' ? 'idfactura' : 'idalbaran';

Copilot uses AI. Check for mistakes.

$sql = "SELECT d.codproveedor, d.nombre, d.fecha, SUM(d.neto) as total"
$sql = "SELECT d.codproveedor, d.nombre, d.fecha, d.neto as total"
. " FROM " . $table . " d"
. " LEFT JOIN " . $line . " l ON d." . $code . " = l." . $code
. " WHERE d.fecha >= " . $this->dataBase->var2str($this->desde)
. " AND d.fecha <= " . $this->dataBase->var2str($this->hasta)
. " AND d.idempresa = " . $this->dataBase->var2str($this->idempresa)
. $this->getInformeComprasDataWhere()
. " GROUP BY d.codproveedor, d.nombre, d.fecha"
. $this->getInformeComprasDataWhere(false)
. " ORDER BY d.codproveedor ASC, d.fecha DESC;";

$data = $this->dataBase->select($sql);
Expand Down Expand Up @@ -761,7 +765,7 @@ protected function getInformeComprasUnidadesData(): array
return $this->getDatosAgrupadosRef($data, ['codproveedor', 'nombre']);
}

protected function getInformeVentasDataWhere(): string
protected function getInformeVentasDataWhere(bool $withLineAlias = true): string
{
$sql = '';
if (!empty($this->cliente->id())) {
Expand Down Expand Up @@ -809,7 +813,14 @@ protected function getInformeVentasDataWhere(): string
}

if (!empty($this->variant->id())) {
$sql .= " AND l.referencia = " . $this->dataBase->var2str($this->variant->referencia);
if ($withLineAlias) {
$sql .= " AND l.referencia = " . $this->dataBase->var2str($this->variant->referencia);
} else {
$lineTable = $this->type === 'invoices' ? 'lineasfacturascli' : 'lineasalbaranescli';
$code = $this->type === 'invoices' ? 'idfactura' : 'idalbaran';
$sql .= " AND d." . $code . " IN (SELECT " . $code . " FROM " . $lineTable
. " WHERE referencia = " . $this->dataBase->var2str($this->variant->referencia) . ")";
}
}

return $sql;
Expand All @@ -818,17 +829,13 @@ protected function getInformeVentasDataWhere(): string
protected function getInformeVentasNetoData(): array
{
$table = $this->type === 'invoices' ? 'facturascli' : 'albaranescli';
$line = $this->type === 'invoices' ? 'lineasfacturascli' : 'lineasalbaranescli';
$code = $this->type === 'invoices' ? 'idfactura' : 'idalbaran';

$sql = "SELECT d.codcliente, d.nombrecliente, d.fecha, SUM(d.neto) as total"
$sql = "SELECT d.codcliente, d.nombrecliente, d.fecha, d.neto as total"
. " FROM " . $table . " d"
. " LEFT JOIN " . $line . " l ON d." . $code . " = l." . $code
. " WHERE d.fecha >= " . $this->dataBase->var2str($this->desde)
. " AND d.fecha <= " . $this->dataBase->var2str($this->hasta)
. " AND d.idempresa = " . $this->dataBase->var2str($this->idempresa)
. $this->getInformeVentasDataWhere()
. " GROUP BY d.codalmacen, d.codcliente, d.nombrecliente, d.fecha"
. $this->getInformeVentasDataWhere(false)
. " ORDER BY d.codcliente ASC, d.fecha DESC;";

$data = $this->dataBase->select($sql);
Expand All @@ -843,16 +850,14 @@ protected function getInformeVentasNetoData(): array
protected function getInformeVentasDocumentData(): array
{
$table = $this->type === 'invoices' ? 'facturascli' : 'albaranescli';
$line = $this->type === 'invoices' ? 'lineasfacturascli' : 'lineasalbaranescli';
$code = $this->type === 'invoices' ? 'idfactura' : 'idalbaran';

$sql = "SELECT d." . $code . " as id, d.codigo, d.codcliente, d.nombrecliente, d.fecha, d.total"
. " FROM " . $table . " d"
. " LEFT JOIN " . $line . " l ON d." . $code . " = l." . $code
. " WHERE d.fecha >= " . $this->dataBase->var2str($this->desde)
. " AND d.fecha <= " . $this->dataBase->var2str($this->hasta)
. " AND d.idempresa = " . $this->dataBase->var2str($this->idempresa)
. $this->getInformeVentasDataWhere()
. $this->getInformeVentasDataWhere(false)
. " ORDER BY d.fecha ASC, d.hora ASC;";

return $this->dataBase->select($sql);
Expand Down
Loading