Skip to content
Open
Show file tree
Hide file tree
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: 43 additions & 0 deletions Controller/ReportBreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace FacturaScripts\Plugins\Informes\Controller;

use FacturaScripts\Core\DataSrc\Empresas;
use FacturaScripts\Core\Model\Familia;
use FacturaScripts\Core\Template\Controller;
use FacturaScripts\Core\Tools;
use FacturaScripts\Core\Where;
Expand All @@ -33,6 +34,7 @@
use FacturaScripts\Dinamic\Model\FacturaCliente;
use FacturaScripts\Dinamic\Model\FacturaProveedor;
use FacturaScripts\Dinamic\Model\FormaPago;
use FacturaScripts\Dinamic\Model\Producto;
use FacturaScripts\Dinamic\Model\Proveedor;
use FacturaScripts\Dinamic\Model\Variante;

Expand Down Expand Up @@ -71,6 +73,9 @@ class ReportBreakdown extends Controller
/** @var string */
public $desde;

/** @var Familia */
public $family;

/** @var string */
public $format = 'screen';

Expand Down Expand Up @@ -439,6 +444,11 @@ protected function buildFilterExportRows(ExportManager $exportManager): void
$filterData[Tools::trans('product') . '/' . Tools::trans('variant')] = $this->variant->referencia;
}

// Filtro de familia
if (!empty($this->family->codfamilia)) {
$filterData[Tools::trans('family')] = $this->family->descripcion ?: $this->family->codfamilia;
}

// Convertimos el array asociativo a filas para la tabla
$filterHeader = Tools::trans('filter');
$valueHeader = Tools::trans('value');
Expand Down Expand Up @@ -738,6 +748,13 @@ protected function getDatosAgrupadosRef(array $data, array $keys): array
return $agrupados;
}

protected function getFamilyVariantsSql(): string
{
return "(SELECT v.referencia FROM " . Variante::tableName() . " v"
. " JOIN " . Producto::tableName() . " p ON v.idproducto = p.idproducto"
. " WHERE p.codfamilia = " . $this->db()->var2str($this->family->codfamilia) . ")";
}

protected function getInformeComprasDataWhere(bool $withLineAlias = true): string
{
$sql = '';
Expand Down Expand Up @@ -777,6 +794,17 @@ protected function getInformeComprasDataWhere(bool $withLineAlias = true): strin
}
}

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

return $sql;
}

Expand Down Expand Up @@ -886,6 +914,17 @@ protected function getInformeVentasDataWhere(bool $withLineAlias = true): string
}
}

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

return $sql;
}

Expand Down Expand Up @@ -1041,6 +1080,10 @@ protected function iniFilters(): void
$whereVariant = [Where::eq('referencia', $this->request()->input('refvariant'))];
$this->variant->loadWhere($whereVariant);

$this->family = new Familia();
$whereFamily = [Where::eq('codfamilia', $this->request()->input('codfamilia'))];
$this->family->loadWhere($whereFamily);

// filtros de ventas
$this->codpais = $this->request()->input('codpais');
$this->provincia = $this->request()->input('provincia', false);
Expand Down
6 changes: 6 additions & 0 deletions View/ReportBreakdown.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
</div>
</div>
</div>
<div class="col-sm-6 col-lg">
<div class="mb-3">
{{ forms.simpleSelect('codfamilia', 'codfamilia', fsc.family.codfamilia,
fsc.getSelectValues('familias', 'codfamilia', 'descripcion', true), trans('family')) }}
</div>
</div>
</div>

<ul class="nav nav-pills mt-3 mb-3" role="tablist">
Expand Down