Skip to content

Commit 3fa0100

Browse files
Daniel Fernández GiménezCopilot
andcommitted
4612: mejora la carga de valores en EditServicioAT y EditTrabajoAT para usar la agrupación en el widgetSelect
Co-authored-by: Copilot <copilot@github.com>
1 parent 2221dda commit 3fa0100

3 files changed

Lines changed: 81 additions & 10 deletions

File tree

Controller/EditServicioAT.php

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is part of Servicios plugin for FacturaScripts
45
* Copyright (C) 2020-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
@@ -26,10 +27,14 @@
2627
use FacturaScripts\Core\Tools;
2728
use FacturaScripts\Core\Where;
2829
use FacturaScripts\Dinamic\Lib\ServiceToInvoice;
30+
use FacturaScripts\Dinamic\Model\Agente;
31+
use FacturaScripts\Dinamic\Model\Almacen;
2932
use FacturaScripts\Dinamic\Model\CategoriaAT;
3033
use FacturaScripts\Dinamic\Model\ServicioAT;
3134
use FacturaScripts\Dinamic\Model\TipoAT;
3235
use FacturaScripts\Dinamic\Model\TrabajoAT;
36+
use FacturaScripts\Dinamic\Model\User;
37+
use Google\Service\Connectors\Tool;
3338

3439
/**
3540
* Description of EditServicioAT
@@ -203,7 +208,7 @@ protected function createViewsInvoices(string $viewName = 'ListFacturaCliente'):
203208
'label' => 'make-invoice'
204209
]);
205210
}
206-
211+
207212
public function createViewLogs(string $viewName = 'ListServicioATLog'): void
208213
{
209214
$this->addListView($viewName, 'ServicioATLog', 'history', 'fa-solid fa-history')
@@ -298,6 +303,11 @@ protected function loadData($viewName, $view)
298303
switch ($viewName) {
299304
case $mainViewName:
300305
parent::loadData($viewName, $view);
306+
$this->loadUserValues($viewName, 'user');
307+
$this->loadUserValues($viewName, 'assigned');
308+
$this->loadAgentValues($viewName, 'agent');
309+
$this->loadWarehouseValues($viewName);
310+
301311
if (false === $view->model->exists()) {
302312
$view->model->codalmacen = $this->user->codalmacen;
303313
$view->model->idempresa = $this->user->idempresa;
@@ -345,7 +355,8 @@ protected function loadData($viewName, $view)
345355
$where = [Where::eq('idservice', $idservicio)];
346356
$view->loadData('', $where);
347357
// Remove checks if the service has no categories and checks.
348-
if ($viewName === 'EditServicioCheckAT'
358+
if (
359+
$viewName === 'EditServicioCheckAT'
349360
&& isset($this->views['EditServicioCategoriaAT'])
350361
&& $this->views['EditServicioCategoriaAT']->count === 0
351362
&& $this->views['EditServicioCheckAT']->count === 0
@@ -359,6 +370,9 @@ protected function loadData($viewName, $view)
359370
$orderBy = ['fechainicio' => 'DESC', 'horainicio' => 'DESC', 'idtrabajo' => 'DESC'];
360371
$view->loadData('', $where, $orderBy);
361372
$this->loadStatusWorkValues($viewName, $view);
373+
$this->loadUserValues($viewName, 'user');
374+
$this->loadAgentValues($viewName, 'agent');
375+
362376
if ($view->count > 0) {
363377
$this->addButton('EditTrabajoAT', [
364378
'action' => 'auto-quantity',
@@ -383,6 +397,25 @@ protected function loadData($viewName, $view)
383397
}
384398
}
385399

400+
protected function loadAgentValues(string $viewName, string $columnName): void
401+
{
402+
$column = $this->tab($viewName)->columnForName($columnName);
403+
if (empty($column) || $column->widget->getType() !== 'select') {
404+
return;
405+
}
406+
407+
$customValues = [];
408+
foreach (Agente::all() as $agent) {
409+
$customValues[] = [
410+
'value' => $agent->codagente,
411+
'title' => $agent->nombre,
412+
'group' => empty($agent->fechabaja) ? Tools::trans('enabled') : Tools::trans('disabled')
413+
];
414+
}
415+
416+
$column->widget->setValuesFromArray($customValues, false, true, 'value', 'title', 'group');
417+
}
418+
386419
protected function loadStatusWorkValues(string $viewName, BaseView $view): void
387420
{
388421
$column = $this->views[$viewName]->columnForName('action');
@@ -396,6 +429,44 @@ protected function loadStatusWorkValues(string $viewName, BaseView $view): void
396429
}
397430
}
398431

432+
protected function loadUserValues(string $viewName, string $columnName): void
433+
{
434+
$column = $this->tab($viewName)->columnForName($columnName);
435+
if (empty($column) || $column->widget->getType() !== 'select') {
436+
return;
437+
}
438+
439+
$customValues = [];
440+
foreach (User::all() as $user) {
441+
$customValues[] = [
442+
'value' => $user->nick,
443+
'title' => $user->nick,
444+
'group' => $user->enabled ? Tools::trans('enabled') : Tools::trans('disabled')
445+
];
446+
}
447+
448+
$column->widget->setValuesFromArray($customValues, false, true, 'value', 'title', 'group');
449+
}
450+
451+
protected function loadWarehouseValues(string $viewName): void
452+
{
453+
$column = $this->tab($viewName)->columnForName('warehouse');
454+
if (empty($column) || $column->widget->getType() !== 'select') {
455+
return;
456+
}
457+
458+
$customValues = [];
459+
foreach (Almacen::all() as $warehouse) {
460+
$customValues[] = [
461+
'value' => $warehouse->codalmacen,
462+
'title' => $warehouse->nombre,
463+
'group' => $warehouse->activo ? Tools::trans('enabled') : Tools::trans('disabled')
464+
];
465+
}
466+
467+
$column->widget->setValuesFromArray($customValues, true, true, 'value', 'title', 'group');
468+
}
469+
399470
protected function makeDeliveryNoteAction(): bool
400471
{
401472
if (false === $this->permissions->allowUpdate) {

XMLView/EditServicioAT.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
* This file is part of Servicios plugin for FacturaScripts
4-
* Copyright (C) 2020-2023 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2020-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Lesser General Public License as
@@ -89,22 +89,22 @@
8989
<group name="more" numcolumns="12">
9090
<column name="user" order="100">
9191
<widget type="select" fieldname="nick">
92-
<values source="users" fieldcode="nick" fieldtitle="nick"/>
92+
<values/>
9393
</widget>
9494
</column>
9595
<column name="assigned" order="110">
9696
<widget type="select" fieldname="asignado">
97-
<values source="users" fieldcode="nick" fieldtitle="nick"/>
97+
<values/>
9898
</widget>
9999
</column>
100100
<column name="agent" titleurl="ListAgente" order="120">
101101
<widget type="select" fieldname="codagente" onclick="EditAgente">
102-
<values source="agentes" fieldcode="codagente" fieldtitle="nombre"/>
102+
<values/>
103103
</widget>
104104
</column>
105105
<column name="warehouse" titleurl="ListAlmacen" order="130">
106106
<widget type="select" fieldname="codalmacen" onclick="EditAlmacen" required="true">
107-
<values source="almacenes" fieldcode="codalmacen" fieldtitle="nombre"/>
107+
<values/>
108108
</widget>
109109
</column>
110110
<column name="company" display="none" order="140">

XMLView/EditTrabajoAT.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
* This file is part of Servicios plugin FacturaScripts
4-
* Copyright (C) 2020-2024 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2020-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Lesser General Public License as
@@ -43,12 +43,12 @@
4343
</column>
4444
<column name="user" order="160">
4545
<widget type="select" fieldname="nick">
46-
<values source="users" fieldcode="nick" fieldtitle="nick"/>
46+
<values/>
4747
</widget>
4848
</column>
4949
<column name="agent" titleurl="ListAgente" order="170">
5050
<widget type="select" fieldname="codagente" onclick="EditAgente">
51-
<values source="agentes" fieldcode="codagente" fieldtitle="nombre"/>
51+
<values/>
5252
</widget>
5353
</column>
5454
<column name="observations" numcolumns="12" order="180">

0 commit comments

Comments
 (0)