|
1 | 1 | <?php |
2 | 2 | /** |
3 | 3 | * This file is part of FacturaScripts |
4 | | - * Copyright (C) 2013-2025 Carlos Garcia Gomez <carlos@facturascripts.com> |
| 4 | + * Copyright (C) 2013-2026 Carlos Garcia Gomez <carlos@facturascripts.com> |
5 | 5 | * |
6 | 6 | * This program is free software: you can redistribute it and/or modify |
7 | 7 | * it under the terms of the GNU Lesser General Public License as |
|
19 | 19 |
|
20 | 20 | namespace FacturaScripts\Core\Model\Base; |
21 | 21 |
|
22 | | -use FacturaScripts\Core\Where; |
23 | 22 | use FacturaScripts\Core\Tools; |
| 23 | +use FacturaScripts\Core\Where; |
24 | 24 | use FacturaScripts\Dinamic\Lib\BusinessDocumentGenerator; |
25 | 25 | use FacturaScripts\Dinamic\Model\DocTransformation; |
26 | 26 | use FacturaScripts\Dinamic\Model\EstadoDocumento; |
@@ -58,12 +58,19 @@ abstract class TransformerDocument extends BusinessDocument |
58 | 58 | */ |
59 | 59 | public $idestado; |
60 | 60 |
|
| 61 | + /** |
| 62 | + * Estado anterior del documento, del modelo EstadoDocumento. |
| 63 | + * |
| 64 | + * @var int|null |
| 65 | + */ |
| 66 | + public $idestado_ant; |
| 67 | + |
61 | 68 | /** |
62 | 69 | * Campos que se pueden modificar aunque el documento no sea editable. |
63 | 70 | * |
64 | 71 | * @var array |
65 | 72 | */ |
66 | | - private static $unlocked_fields = ['femail', 'idestado', 'numdocs', 'pagada']; |
| 73 | + private static $unlocked_fields = ['femail', 'idestado', 'idestado_ant', 'numdocs', 'pagada']; |
67 | 74 |
|
68 | 75 | /** |
69 | 76 | * Añade un campo a la lista de campos desbloqueados (editables aunque el documento no sea editable). |
@@ -238,6 +245,21 @@ public function getStatus(): EstadoDocumento |
238 | 245 | return $status; |
239 | 246 | } |
240 | 247 |
|
| 248 | + /** |
| 249 | + * Devuelve el modelo EstadoDocumento anterior de este documento. |
| 250 | + * |
| 251 | + * @return EstadoDocumento|null |
| 252 | + */ |
| 253 | + public function getPreviousStatus(): ?EstadoDocumento |
| 254 | + { |
| 255 | + if (empty($this->idestado_ant)) { |
| 256 | + return null; |
| 257 | + } |
| 258 | + |
| 259 | + $status = new EstadoDocumento(); |
| 260 | + return $status->load($this->idestado_ant) ? $status : null; |
| 261 | + } |
| 262 | + |
241 | 263 | /** |
242 | 264 | * Devuelve la lista de campos desbloqueados (editables aunque el documento no sea editable). |
243 | 265 | * |
@@ -342,6 +364,9 @@ protected function onChange(string $field): bool |
342 | 364 | return parent::onChange($field); |
343 | 365 | } |
344 | 366 |
|
| 367 | + // guardamos el estado anterior real antes del cambio |
| 368 | + $this->idestado_ant = $this->getOriginal('idestado'); |
| 369 | + |
345 | 370 | $status = $this->getStatus(); |
346 | 371 | if (empty($status->generadoc) || false === self::$document_generation) { |
347 | 372 | // actualizamos las líneas para actualizar el stock |
|
0 commit comments