From bcad318d83172b251ac8b921392d6d330edfa393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20S=C3=A1nchez?= Date: Wed, 13 May 2026 20:15:39 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20a=C3=B1adir=20funcionalidad=20de=20impr?= =?UTF-8?q?esi=C3=B3n=20y=20totales=20en=20Modelo115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://facturascripts.com/roadmap/2880 - Se añadió un botón de impresión en la vista de Modelo115 si hay facturas disponibles. - Se implementó el cálculo de totales (neto, IVA, recargo, IRPF y total) en el controlador Modelo115. - Se creó la función printAction para manejar la exportación a PDF de los datos de Modelo115. - Se actualizaron las plantillas para mostrar los totales en la tabla de facturas. Archivos modificados: - Modelo115.html.twig - Modelo115.php --- Controller/Modelo115.php | 96 ++++++++++++++++++++++++++++++++++++++++ View/Modelo115.html.twig | 18 ++++++++ 2 files changed, 114 insertions(+) diff --git a/Controller/Modelo115.php b/Controller/Modelo115.php index aad486d..f7ea68d 100644 --- a/Controller/Modelo115.php +++ b/Controller/Modelo115.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\Modelo115 as LibModelo115; use FacturaScripts\Dinamic\Model\Ejercicio; use FacturaScripts\Dinamic\Model\Retencion; @@ -106,6 +107,101 @@ public function privateCore(&$response, $user, $permissions) $this->codretencion, $this->todeduct ); + + $totalNeto = 0.0; + $totalIva = 0.0; + $totalRecargo = 0.0; + $totalIrpf = 0.0; + $totalTotal = 0.0; + foreach ($this->result['invoices'] ?? [] as $invoice) { + $totalNeto += $invoice->neto; + $totalIva += $invoice->totaliva; + $totalRecargo += $invoice->totalrecargo; + $totalIrpf += $invoice->totalirpf; + $totalTotal += $invoice->total; + } + $this->result['totalNeto'] = $totalNeto; + $this->result['totalIva'] = $totalIva; + $this->result['totalRecargo'] = $totalRecargo; + $this->result['totalIrpf'] = $totalIrpf; + $this->result['totalTotal'] = $totalTotal; + + $action = $this->request->inputOrQuery('action', ''); + if ($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-115-180')); + + // resumen + $recipients = Tools::trans('number-recipients'); + $taxbase = Tools::trans('tax-base'); + $retentions = Tools::trans('retentions'); + $todeduct = Tools::trans('to-deduct'); + $result = Tools::trans('result'); + + $exportManager->addTablePage( + [$recipients, $taxbase, $retentions, $todeduct, $result], + [[ + $recipients => $this->result['numrecipients'], + $taxbase => Tools::money($this->result['taxbase']), + $retentions => Tools::money($this->result['retentions']), + $todeduct => Tools::money($this->result['todeduct']), + $result => Tools::money($this->result['result']), + ]] + ); + + // facturas + if (!empty($this->result['invoices'])) { + $invoice = Tools::trans('invoice'); + $supplier = Tools::trans('supplier'); + $net = Tools::trans('net'); + $taxes = Tools::trans('taxes'); + $surcharge = Tools::trans('surcharge'); + $retention = Tools::trans('retention'); + $total = Tools::trans('total'); + $date = Tools::trans('date'); + + $rows = []; + foreach ($this->result['invoices'] as $item) { + $rows[] = [ + $invoice => $item->codigo, + $supplier => $item->nombre, + $net => Tools::money($item->neto), + $taxes => Tools::money($item->totaliva), + $surcharge => Tools::money($item->totalrecargo), + $retention => Tools::money($item->totalirpf), + $total => Tools::money($item->total), + $date => $item->fecha, + ]; + } + $rows[] = [ + $invoice => '', + $supplier => Tools::trans('total'), + $net => Tools::money($this->result['totalNeto']), + $taxes => Tools::money($this->result['totalIva']), + $surcharge => Tools::money($this->result['totalRecargo']), + $retention => Tools::money($this->result['totalIrpf']), + $total => Tools::money($this->result['totalTotal']), + $date => '', + ]; + $exportManager->addTablePage( + [$invoice, $supplier, $net, $taxes, $surcharge, $retention, $total, $date], + $rows + ); + } + + $exportManager->show($this->response); } protected function getCurrentPeriod(): string diff --git a/View/Modelo115.html.twig b/View/Modelo115.html.twig index 5a15b6b..8d12e6b 100644 --- a/View/Modelo115.html.twig +++ b/View/Modelo115.html.twig @@ -67,6 +67,12 @@ + {% if fsc.result.invoices is not empty %} + + {% endif %} @@ -168,6 +174,18 @@ {% endfor %} + + + + {{ trans('total') }} + {{ money(fsc.result.totalNeto) }} + {{ money(fsc.result.totalIva) }} + {{ money(fsc.result.totalRecargo) }} + {{ money(fsc.result.totalIrpf) }} + {{ money(fsc.result.totalTotal) }} + + +