From 3257ad0a14315914b4f831ccdcd0300891aefd0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20S=C3=A1nchez?= Date: Mon, 10 Aug 2026 12:53:59 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20a=C3=B1adir=20m=C3=B3dulo=20de=20encabe?= =?UTF-8?q?zado=20contable=20y=20controlador=20de=20edici=C3=B3n=20de=20as?= =?UTF-8?q?iento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Se ha creado el archivo AccountingHeaderHTMLMod.php que implementa la interfaz AccountingModInterface. - Se ha añadido la clase EditAsiento.php para manejar la edición de asientos. - Se han modificado Init.php para cargar el nuevo módulo y controlador. - Se ha añadido la función de asignación de proyecto en el módulo contable. Estos cambios permiten una mejor gestión de los proyectos en los asientos contables. --- Extension/Controller/EditAsiento.php | 27 ++++++++ Extension/XMLView/EditAsiento.xml | 12 ---- Init.php | 3 + Mod/AccountingHeaderHTMLMod.php | 100 +++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 12 deletions(-) create mode 100644 Extension/Controller/EditAsiento.php delete mode 100644 Extension/XMLView/EditAsiento.xml create mode 100644 Mod/AccountingHeaderHTMLMod.php diff --git a/Extension/Controller/EditAsiento.php b/Extension/Controller/EditAsiento.php new file mode 100644 index 0000000..f8cea69 --- /dev/null +++ b/Extension/Controller/EditAsiento.php @@ -0,0 +1,27 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +namespace FacturaScripts\Plugins\Proyectos\Extension\Controller; + +use FacturaScripts\Plugins\Proyectos\Extension\Traits\ProjectControllerSalesPurchases; + +class EditAsiento +{ + use ProjectControllerSalesPurchases; +} diff --git a/Extension/XMLView/EditAsiento.xml b/Extension/XMLView/EditAsiento.xml deleted file mode 100644 index 1c63766..0000000 --- a/Extension/XMLView/EditAsiento.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/Init.php b/Init.php index 87d731d..9c805c7 100644 --- a/Init.php +++ b/Init.php @@ -19,6 +19,7 @@ namespace FacturaScripts\Plugins\Proyectos; +use FacturaScripts\Core\Lib\AjaxForms\AccountingHeaderHTML; use FacturaScripts\Core\Lib\AjaxForms\PurchasesHeaderHTML; use FacturaScripts\Core\Lib\AjaxForms\SalesHeaderHTML; use FacturaScripts\Core\Base\DataBase; @@ -66,6 +67,7 @@ public function init(): void $this->loadExtension(new Extension\Controller\DocumentStitcher()); $this->loadExtension(new Extension\Controller\EditAlbaranCliente()); $this->loadExtension(new Extension\Controller\EditAlbaranProveedor()); + $this->loadExtension(new Extension\Controller\EditAsiento()); $this->loadExtension(new Extension\Controller\EditCliente()); $this->loadExtension(new Extension\Controller\EditFacturaCliente()); $this->loadExtension(new Extension\Controller\EditFacturaProveedor()); @@ -88,6 +90,7 @@ public function init(): void $this->loadExtension(new Extension\Model\Stock()); $this->loadExtension(new Extension\Model\FacturaProgramada()); + AccountingHeaderHTML::addMod(new Mod\AccountingHeaderHTMLMod()); PurchasesHeaderHTML::addMod(new Mod\PurchasesHeaderHTMLMod()); SalesHeaderHTML::addMod(new Mod\SalesHeaderHTMLMod()); diff --git a/Mod/AccountingHeaderHTMLMod.php b/Mod/AccountingHeaderHTMLMod.php new file mode 100644 index 0000000..3e62143 --- /dev/null +++ b/Mod/AccountingHeaderHTMLMod.php @@ -0,0 +1,100 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +namespace FacturaScripts\Plugins\Proyectos\Mod; + +use FacturaScripts\Core\Contract\AccountingModInterface; +use FacturaScripts\Core\Tools; +use FacturaScripts\Dinamic\Model\Asiento; +use FacturaScripts\Dinamic\Model\Proyecto; +use FacturaScripts\Dinamic\Lib\AssetManager; + +/** + * Description of AccountingHeaderHTMLMod + * + * @author Esteban Sánchez + */ +class AccountingHeaderHTMLMod implements AccountingModInterface +{ + public function apply(Asiento &$model, array $formData): void + { + } + + public function applyBefore(Asiento &$model, array $formData): void + { + $model->idproyecto = isset($formData['idproyecto']) && $formData['idproyecto'] ? $formData['idproyecto'] : null; + } + + public function assets(): void + { + $route = Tools::config('route'); + AssetManager::add('js', $route . '/Dinamic/Assets/JS/AutocompleteProject.js'); + } + + public function newBtnFields(): array + { + return []; + } + + public function newFields(): array + { + return ['proyecto']; + } + + public function renderField(Asiento $model, string $field): ?string + { + if ($field === 'proyecto') { + return self::proyecto($model); + } + + return null; + } + + private static function proyecto(Asiento $model): string + { + $value = ''; + $project = new Proyecto(); + if ($model->idproyecto && $project->load($model->idproyecto)) { + $value = $project->idproyecto . ' | ' . $project->nombre; + } + + $html = '
' + . '' . Tools::trans('project') . '' + . '
' + . ''; + + if ($model->editable && $model->idproyecto) { + $html .= ''; + } else { + $html .= '' + . '' + . ''; + } + + $disabled = $model->editable ? '' : 'disabled'; + $html .= '' + . '' + . '' + . '
' + . '
'; + return $html; + } +}