Skip to content

Commit 9da3804

Browse files
NeoRazorXclaude
andcommitted
WidgetSubcuenta filtra los ejercicios del modal por la empresa del modelo padre (cuando tiene idempresa) y migradas las consultas de DataBaseWhere a Where.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bc6e454 commit 9da3804

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

Core/Lib/Widget/WidgetSubcuenta.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919

2020
namespace FacturaScripts\Core\Lib\Widget;
2121

22-
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
2322
use FacturaScripts\Core\Lib\AssetManager;
2423
use FacturaScripts\Core\Request;
2524
use FacturaScripts\Core\Tools;
25+
use FacturaScripts\Core\Where;
2626
use FacturaScripts\Dinamic\Model\Ejercicio;
2727
use FacturaScripts\Dinamic\Model\Subcuenta;
2828

2929
class WidgetSubcuenta extends WidgetText
3030
{
31+
/** @var int|null */
32+
protected $idempresa;
33+
3134
/** @var string */
3235
public $match;
3336

@@ -43,6 +46,9 @@ public function edit($model, $title = '', $description = '', $titleurl = '')
4346
{
4447
$this->setValue($model);
4548

49+
// si el modelo tiene idempresa, lo usamos para filtrar los ejercicios del modal
50+
$this->idempresa = isset($model->idempresa) && !empty($model->idempresa) ? (int)$model->idempresa : null;
51+
4652
// obtenemos un nuevo ID cada vez
4753
$this->id = $this->getUniqueId();
4854

@@ -59,7 +65,7 @@ public function edit($model, $title = '', $description = '', $titleurl = '')
5965
$subcuenta = new Subcuenta();
6066
if (false === empty($this->value)) {
6167
$subcuenta->loadWhere([
62-
new DataBaseWhere($this->match, $this->value)
68+
Where::eq($this->match, $this->value)
6369
]);
6470
}
6571

@@ -97,27 +103,28 @@ public function subcuentas(string $query = '', string $codejercicio = '', string
97103
$list = [];
98104
$where = [];
99105

100-
// si no se especifica ejercicio, usamos el primero
106+
// si no se especifica ejercicio, usamos el primero (filtrado por empresa si la conocemos)
101107
if (empty($codejercicio)) {
102-
$ejercicios = Ejercicio::all([], ['codejercicio' => 'DESC'], 0, 1);
108+
$ejWhere = $this->idempresa ? [Where::eq('idempresa', $this->idempresa)] : [];
109+
$ejercicios = Ejercicio::all($ejWhere, ['codejercicio' => 'DESC'], 0, 1);
103110
if (!empty($ejercicios)) {
104111
$codejercicio = $ejercicios[0]->codejercicio;
105112
}
106113
}
107114

108115
// cargamos y añadimos la subcuenta seleccionada
109116
$model = new Subcuenta();
110-
if ($this->value && $model->loadWhere([new DataBaseWhere($this->match, $this->value)])) {
117+
if ($this->value && $model->loadWhere([Where::eq($this->match, $this->value)])) {
111118
$list[] = clone $model;
112-
$where[] = new DataBaseWhere($model->primaryColumn(), $model->id(), '<>');
119+
$where[] = Where::notEq($model->primaryColumn(), $model->id());
113120
}
114121

115122
if ($query) {
116-
$where[] = new DataBaseWhere('codsubcuenta|descripcion', $query, 'LIKE');
123+
$where[] = Where::like('codsubcuenta|descripcion', $query);
117124
}
118125

119126
if ($codejercicio) {
120-
$where[] = new DataBaseWhere('codejercicio', $codejercicio);
127+
$where[] = Where::eq('codejercicio', $codejercicio);
121128
}
122129

123130
switch ($sort) {
@@ -188,7 +195,7 @@ public function tableCell($model, $display = 'left')
188195
$subcuenta = new Subcuenta();
189196
if (false === empty($this->value)) {
190197
$subcuenta->loadWhere([
191-
new DataBaseWhere($this->match, $this->value)
198+
Where::eq($this->match, $this->value)
192199
]);
193200
}
194201

@@ -237,7 +244,8 @@ protected function renderModal(string $icon, string $label): string
237244
protected function renderExerciseFilter(): string
238245
{
239246
$options = [];
240-
$ejercicios = Ejercicio::all([], ['codejercicio' => 'DESC']);
247+
$where = $this->idempresa ? [Where::eq('idempresa', $this->idempresa)] : [];
248+
$ejercicios = Ejercicio::all($where, ['codejercicio' => 'DESC']);
241249
$first = true;
242250

243251
foreach ($ejercicios as $item) {

0 commit comments

Comments
 (0)