From 509ce2e62813367c80c6e386356a70cccab247f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20S=C3=A1nchez?= Date: Wed, 13 May 2026 19:29:45 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20a=C3=B1adir=20funcionalidad=20de=20impr?= =?UTF-8?q?esi=C3=B3n=20y=20totales=20en=20Modelo111?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Se agregó un botón de impresión en Modelo111.html.twig. - Se implementó el método printAction en Modelo111.php para manejar la impresión de datos. - Se calcularon y mostraron los totales de debe y haber en la tabla de resultados. --- Controller/Modelo111.php | 81 ++++++++++++++++++++++++++++++++++++++++ View/Modelo111.html.twig | 12 ++++++ 2 files changed, 93 insertions(+) diff --git a/Controller/Modelo111.php b/Controller/Modelo111.php index dc197e1..2eb2edc 100644 --- a/Controller/Modelo111.php +++ b/Controller/Modelo111.php @@ -22,6 +22,7 @@ use FacturaScripts\Core\Base\Controller; use FacturaScripts\Core\DataSrc\Ejercicios; use FacturaScripts\Core\Tools; +use FacturaScripts\Dinamic\Lib\ExportManager; use FacturaScripts\Dinamic\Lib\Modelo111 as LibModelo111; use FacturaScripts\Dinamic\Model\Empresa; @@ -92,10 +93,90 @@ public function privateCore(&$response, $user, $permissions) $this->ingresosPeriodoAnterior ); + $totalDebe = 0.0; + $totalHaber = 0.0; + foreach ($this->result['entryLines'] ?? [] as $line) { + $totalDebe += $line->debe; + $totalHaber += $line->haber; + } + $this->result['totalDebe'] = $totalDebe; + $this->result['totalHaber'] = $totalHaber; + $action = $this->request->inputOrQuery('action', ''); if ($action === 'download') { $this->downloadFile($response); + } elseif ($action === 'print') { + $this->printAction(); + } + } + + protected function printAction(): void + { + if (empty($this->result)) { + return; } + + $this->setTemplate(false); + + $exportManager = new ExportManager(); + $exportManager->newDoc('PDF', Tools::trans('model-111-190')); + + // resumen — las claves de las filas deben coincidir con los headers + $recipients = Tools::trans('number-recipients'); + $base = Tools::trans('withholding-base'); + $withholdings = Tools::trans('withholdings-made'); + $previous = Tools::trans('previous-period-income'); + $total = Tools::trans('total-to-enter'); + + $exportManager->addTablePage( + [$recipients, $base, $withholdings, $previous, $total], + [[ + $recipients => $this->result['numRecipients'], + $base => Tools::money($this->result['baseRetenciones']), + $withholdings => Tools::money($this->result['retencionesPracticadas']), + $previous => Tools::money($this->result['ingresosPeriodoAnterior']), + $total => Tools::money($this->result['totalIngresar']), + ]] + ); + + // asientos contables + if (!empty($this->result['entryLines'])) { + $entry = Tools::trans('accounting-entry'); + $subaccount = Tools::trans('subaccount'); + $counterpart = Tools::trans('counterpart'); + $concept = Tools::trans('concept'); + $debit = Tools::trans('debit'); + $credit = Tools::trans('credit'); + $date = Tools::trans('date'); + + $entryRows = []; + foreach ($this->result['entryLines'] as $line) { + $entryRows[] = [ + $entry => $line->numero, + $subaccount => $line->codsubcuenta, + $counterpart => $line->codcontrapartida, + $concept => $line->concepto, + $debit => Tools::money($line->debe), + $credit => Tools::money($line->haber), + $date => $line->fecha, + ]; + } + $entryRows[] = [ + $entry => '', + $subaccount => '', + $counterpart => '', + $concept => Tools::trans('total'), + $debit => Tools::money($this->result['totalDebe']), + $credit => Tools::money($this->result['totalHaber']), + $date => '', + ]; + $exportManager->addTablePage( + [$entry, $subaccount, $counterpart, $concept, $debit, $credit, $date], + $entryRows + ); + } + + $exportManager->show($this->response); } protected function getCurrentPeriod(): string diff --git a/View/Modelo111.html.twig b/View/Modelo111.html.twig index ab7f0a4..2cc2e0b 100644 --- a/View/Modelo111.html.twig +++ b/View/Modelo111.html.twig @@ -55,6 +55,10 @@ + {% endif %} @@ -221,6 +225,14 @@ {% endfor %} + + + {{ trans('total') }} + {{ money(fsc.result.totalDebe) }} + {{ money(fsc.result.totalHaber) }} + + +