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
27 changes: 27 additions & 0 deletions Extension/Controller/EditAsiento.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* This file is part of Proyectos plugin for FacturaScripts
* Copyright (C) 2026 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/

namespace FacturaScripts\Plugins\Proyectos\Extension\Controller;

use FacturaScripts\Plugins\Proyectos\Extension\Traits\ProjectControllerSalesPurchases;

class EditAsiento
{
use ProjectControllerSalesPurchases;
}
12 changes: 0 additions & 12 deletions Extension/XMLView/EditAsiento.xml

This file was deleted.

3 changes: 3 additions & 0 deletions Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());

Expand Down
100 changes: 100 additions & 0 deletions Mod/AccountingHeaderHTMLMod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* This file is part of Proyectos plugin for FacturaScripts
* Copyright (C) 2026 Carlos Garcia Gomez <carlos@facturascripts.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/

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 <esteban@factura.city>
*/
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 = '<div class="col-sm-6 col-md-4 col-lg-2">'
. '<a href="' . $project->url() . '">' . Tools::trans('project') . '</a>'
. '<div class="input-group">'
. '';

if ($model->editable && $model->idproyecto) {
$html .= '<button type="button" id="deleteProject" class="btn btn-warning">'
. '<i class="fa-solid fa-times" aria-hidden="true"></i>'
. '</button>';
} else {
$html .= '<span id="searchProject" class="input-group-text">'
. '<i class="fa-solid fa-search fa-fw"></i>'
. '</span>';
}

$disabled = $model->editable ? '' : 'disabled';
$html .= ''
. '<input type="hidden" name="idproyecto" value="' . $model->idproyecto . '">'
. '<input type="text" id="findProjectInput" class="form-control" value="' . $value . '" ' . $disabled . '/>'
. '</div>'
. '</div>';
return $html;
}
}