From c10b704d352c8b742bac3f7d59ee4f123fbc5201 Mon Sep 17 00:00:00 2001 From: Pablo Ferrandez Roca Date: Fri, 31 Jul 2026 11:30:13 +0200 Subject: [PATCH] =?UTF-8?q?al=C3=B1adida=20la=20opci=C3=B3n=20de=20desgalo?= =?UTF-8?q?se=20por=20familia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/ReportBreakdown.php | 43 ++++++++++++++++++++++++++++++++++ View/ReportBreakdown.html.twig | 6 +++++ 2 files changed, 49 insertions(+) diff --git a/Controller/ReportBreakdown.php b/Controller/ReportBreakdown.php index fa6d352..79ae851 100644 --- a/Controller/ReportBreakdown.php +++ b/Controller/ReportBreakdown.php @@ -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; @@ -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; @@ -71,6 +73,9 @@ class ReportBreakdown extends Controller /** @var string */ public $desde; + /** @var Familia */ + public $family; + /** @var string */ public $format = 'screen'; @@ -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'); @@ -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 = ''; @@ -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; } @@ -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; } @@ -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); diff --git a/View/ReportBreakdown.html.twig b/View/ReportBreakdown.html.twig index 856e06b..4fa3911 100644 --- a/View/ReportBreakdown.html.twig +++ b/View/ReportBreakdown.html.twig @@ -88,6 +88,12 @@ +
+
+ {{ forms.simpleSelect('codfamilia', 'codfamilia', fsc.family.codfamilia, + fsc.getSelectValues('familias', 'codfamilia', 'descripcion', true), trans('family')) }} +
+