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>
2627use FacturaScripts \Core \Tools ;
2728use FacturaScripts \Core \Where ;
2829use FacturaScripts \Dinamic \Lib \ServiceToInvoice ;
30+ use FacturaScripts \Dinamic \Model \Agente ;
31+ use FacturaScripts \Dinamic \Model \Almacen ;
2932use FacturaScripts \Dinamic \Model \CategoriaAT ;
3033use FacturaScripts \Dinamic \Model \ServicioAT ;
3134use FacturaScripts \Dinamic \Model \TipoAT ;
3235use 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 ) {
0 commit comments