src/Admin/ValoracionAdmin.php line 775

Open in your IDE?
  1. <?php
  2.     declare(strict_types=1);
  3.     namespace App\Admin;
  4.     use App\Entity\UnidadNegocio;
  5.     use App\Entity\Usuario;
  6.     use App\Entity\ValoracionesRelojes;
  7.     use App\Enum\EstadoValoracionEnum;
  8.     use App\Enum\IdiomaEnum;
  9.     use App\Form\Type\HTMLType;
  10.     use App\Form\Type\ScriptType;
  11.     use DateTime;
  12.     use Doctrine\ORM\EntityManagerInterface;
  13.     use Sonata\AdminBundle\Admin\AbstractAdmin;
  14.     use Sonata\AdminBundle\Datagrid\DatagridInterface;
  15.     use Sonata\AdminBundle\Datagrid\DatagridMapper;
  16.     use Sonata\AdminBundle\Datagrid\ListMapper;
  17.     use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  18.     use Sonata\AdminBundle\Form\FormMapper;
  19.     use Sonata\AdminBundle\Form\Type\ModelListType;
  20.     use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType;
  21.     use Sonata\AdminBundle\Route\RouteCollectionInterface;
  22.     use Sonata\AdminBundle\Show\ShowMapper;
  23.     use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
  24.     use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter;
  25.     use Sonata\Form\Type\CollectionType;
  26.     use Sonata\Form\Type\DatePickerType;
  27.     use Sonata\Form\Type\DateRangePickerType;
  28.     use Sonata\Form\Type\DateTimePickerType;
  29.     use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  30.     use Symfony\Component\Form\Extension\Core\Type\TextType;
  31.     use Symfony\Component\Security\Core\Security;
  32.     final class ValoracionAdmin extends AbstractAdmin
  33.     {
  34.         public function __construct(
  35.             string $code,
  36.             string $class,
  37.             string $baseControllerName,
  38.             private Security $security,
  39.             private EntityManagerInterface $em
  40.         ) {
  41.             parent::__construct($code$class$baseControllerName);
  42.         }
  43. //    public function configureActionButtons(array $buttonList, string $action, ?object $object = null): array
  44. //    {
  45. //        $buttonList['stats']['template'] = 'admin/Button/stats_button.html.twig';
  46. //        $buttonList['history']['template'] = 'admin/Button/history_button.html.twig';
  47. //        $buttonList['clone']['template'] = 'admin/Button/clone_button.html.twig';
  48. //        $buttonList['swap']['template'] = 'admin/Button/swap_button.html.twig';
  49. //        $buttonList['process']['template'] = 'admin/Button/in_process_button.html.twig';
  50. //        return parent::configureActionButtons($buttonList, $action, $object);
  51. //    }
  52.         public function configureRoutes(RouteCollectionInterface $collection): void
  53.         {
  54.             $collection->add('stats');
  55.             $collection->add('history');
  56.             $collection->add('clone');
  57.             $collection->add('swap');
  58.             $collection->add('in-process');
  59.             $collection->add('sales-management');
  60.             $collection->add('switch-operacion');
  61.             parent::configureRoutes($collection);
  62.         }
  63.         public function configureExportFields(): array
  64.         {
  65.             return [
  66.                 $this->getTranslator()->trans('export.valoracion.IDperseo') => 'valoracion.IDperseo',
  67.                 $this->getTranslator()->trans('export.valoracion.fecha') => 'valoracion.fechaString',
  68.                 $this->getTranslator()->trans('export.valoracion.unidad_negocio') => 'valoracion.unidadNegocio',
  69.                 $this->getTranslator()->trans('export.valoracion.usuario') => 'valoracion.usuario',
  70.                 $this->getTranslator()->trans('export.valoracion.canal') => 'valoracion.canal',
  71.                 $this->getTranslator()->trans('export.valoracion.cliente') => 'valoracion.cliente',
  72.                 $this->getTranslator()->trans('export.valoracion.tipo_cliente') => 'valoracion.tipoCliente',
  73.                 $this->getTranslator()->trans('export.valoracion.exportacion') => 'valoracion.exportacion',
  74.                 $this->getTranslator()->trans('export.valoracion.idioma') => 'valoracion.idioma',
  75.                 $this->getTranslator()->trans('export.valoracion.fecha_enviada') => 'valoracion.fechaEnviadaString',
  76.                 $this->getTranslator()->trans('export.valoracion.fecha_aceptacion') => 'valoracion.fechaAceptacionString',
  77.                 $this->getTranslator()->trans('export.valoracion.fecha_rechazo') => 'valoracion.fechaRechazoString',
  78.                 $this->getTranslator()->trans('export.valoracion.fecha_tramitacion') => 'valoracion.fechaTramitacionString',
  79.                 $this->getTranslator()->trans('export.valoracion.info_tramitacion') => 'valoracion.infoTramitacion',
  80.                 $this->getTranslator()->trans('export.valoracion.precio_pagar') => 'valoracion.precioPagar',
  81.                 $this->getTranslator()->trans('export.valoracion.info_valoracion') => 'valoracion.infoValoracion',
  82.                 $this->getTranslator()->trans('export.valoracion.relojes_sin_stock') => 'valoracion.exportValoracionesRelojesSinStock',
  83.                 $this->getTranslator()->trans('export.valoracion.relojes_stock') => 'valoracion.exportValoracionesRelojesStock',
  84.             ];
  85.         }
  86.         protected function configureDefaultSortValues(array &$sortValues): void
  87.         {
  88.             parent::configureDefaultSortValues($sortValues);
  89.             $sortValues[DatagridInterface::PER_PAGE] = 50;
  90.         }
  91.         protected function configureDefaultFilterValues(array &$filterValues): void
  92.         {
  93.             $filterValues = [
  94.                 'usuario' => [
  95.                     'type'  => EqualOperatorType::TYPE_EQUAL,
  96.                     'value' => 0
  97.                 ],
  98.                 'estado' => [
  99.                     'type'  => EqualOperatorType::TYPE_EQUAL,
  100.                     'value' => [EstadoValoracionEnum::ESTADO_ABIERTAEstadoValoracionEnum::ESTADO_ESPERAEstadoValoracionEnum::ESTADO_ACEPTADA]
  101.                 ]
  102.             ];
  103.             parent::configureDefaultFilterValues($filterValues);
  104.         }
  105.         protected function configureDatagridFilters(DatagridMapper $filter): void
  106.         {
  107.             if(!@$_REQUEST['filter'][DatagridInterface::PER_PAGE]) $this->getDatagrid()->setValue(DatagridInterface::PER_PAGEnull50);
  108.             //$existFilter = !empty($this->getRequest()->getSession()->get('admin.valoracion.filter.parameters'));
  109.             $choicesUsuarioS = [$this->em->getReference(Usuario::class, 0)];
  110.             if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {
  111.                 $choicesUsuarioS array_merge($choicesUsuarioS,
  112.                     $this->em->getRepository(Usuario::class)->findAll() ?? []);
  113.             } else {
  114.                 $choicesUsuarioS array_merge($choicesUsuarioS,
  115.                     $this->em->getRepository(Usuario::class)->getUsuariosByUnidadNegocio($this->security->getUser()->getUsuario()?->getUnidadNegocio()));
  116.             }
  117.             $filter
  118.                 ->add('busqueda'CallbackFilter::class, [
  119.                     'label' => false,
  120.                     'attr' => [
  121.                         'class' => 'filter-to-navbar-left filter-to-navbar',
  122.                         'data-order' => '1',
  123.                         'placeholder' => 'filter.placeholder.busqueda',
  124.                     ],
  125.                     'callback' => function ($queryBuilder$alias$field$value) {
  126.                         if (!$value->hasValue()) {
  127.                             return;
  128.                         }
  129.                         $this->em->getRepository(ValoracionesRelojes::class)->cbFilter($queryBuilder$alias$field,
  130.                             $value);
  131.                         return true;
  132.                     },
  133.                 ])
  134.                 ->add('estado'CallbackFilter::class, [
  135.                     'label' => false,
  136.                     'attr' => [
  137.                         'class' => 'filter-to-navbar-right filter-to-navbar',
  138.                         'data-order' => '2',
  139.                         'data-id' => 'filter-filters'
  140.                     ],
  141.                     'callback' => function ($queryBuilder$alias$field$value) {
  142.                         if (!$value->hasValue()) {
  143.                             return;
  144.                         }
  145.                         $this->em->getRepository(ValoracionesRelojes::class)->cbFilter($queryBuilder$alias$field,
  146.                             $value);
  147.                         return true;
  148.                     },
  149.                 ], [
  150.                     'field_type' => ChoiceType::class,
  151.                     'field_options' => [
  152.                         'choices' => array_keys(EstadoValoracionEnum::getEstados()),
  153.                         'multiple' => true,
  154.                         'expanded' => true,
  155.                         'choice_label' => function ($choice$key$value) {
  156.                             return EstadoValoracionEnum::getEstado($choice);
  157.                         },
  158.                         /*'choice_attr' => function ($choice, $key, $value) use ($existFilter){
  159.                             if (!$existFilter && !$this->getRequest()->get('filter') && in_array($value, [EstadoValoracionEnum::ESTADO_ABIERTA, EstadoValoracionEnum::ESTADO_ESPERA, EstadoValoracionEnum::ESTADO_ACEPTADA])) {
  160.                                 return [
  161.                                     'checked' => true
  162.                                 ];
  163.                             }
  164.                             return [];
  165.                         },*/
  166.                     ]
  167.                 ])
  168.                 ->add('usuario'CallbackFilter::class, [
  169.                     'label' => false,
  170.                     'attr' => [
  171.                         'class' => 'filter-to-navbar-right filter-to-navbar',
  172.                         'data-order' => '1',
  173.                         'data-id' => 'filter-usuario-filters'
  174.                     ],
  175.                     'callback' => function ($queryBuilder$alias$field$value) {
  176.                         if (!$value->hasValue()) {
  177.                             return;
  178.                         }
  179.                         $this->em->getRepository(ValoracionesRelojes::class)->cbFilter($queryBuilder$alias$field,
  180.                             $value);
  181.                         return true;
  182.                     },
  183.                 ], [
  184.                     'field_type' => ChoiceType::class,
  185.                     'field_options' => [
  186.                         'choices' => $choicesUsuarioS,
  187.                         'multiple' => false,
  188.                         'expanded' => true,
  189.                         'choice_value' => function ($choice) {
  190.                             return $choice $choice->getId() : 0;
  191.                         },
  192.                         'choice_label' => function ($choice$key$value) {
  193.                             return $value != $choice->getUser()->getIniciales() : 'filter.valoracion.usuarios.label.all';
  194.                         },
  195.                         /*'choice_attr' => function ($choice, $key, $value) {
  196.                             if(!$this->getRequest()->get('filter')) {
  197.                                 return [
  198.                                     'checked' => $value == 0
  199.                                 ];
  200.                             }
  201.                             return [];
  202.                         },*/
  203.                     ]
  204.                 ]);
  205. //        if($this->security->isGranted('ROLE_SUPER_ADMIN')) {
  206. //            $filter
  207. //                ->add('unidadNegocio', CallbackFilter::class, [
  208. //                    'label' => false,
  209. //                    'attr' => [
  210. //                        'data-order' => '1',
  211. //                        'class' => '',
  212. //                        'placeholder' => 'filter.valoracion.placeholder.unidad_negocio',
  213. //                    ],
  214. //                    'callback' => function($queryBuilder, $alias, $field, $value)
  215. //                    {
  216. //                        if (!$value->hasValue())  return;
  217. //
  218. //                        $this->em->getRepository(ValoracionesRelojes::class)->cbFilter($queryBuilder, $alias, $field, $value);
  219. //
  220. //                        return true;
  221. //                    }
  222. //                ]);
  223. //        }
  224.             $filter
  225.                 ->add('fecha'CallbackFilter::class, [
  226.                     'label' => false,
  227.                     'attr' => [
  228.                         'data-order' => '2',
  229.                         'class' => 'filter-date-range'
  230.                     ],
  231.                     'field_type' => DateRangePickerType::class,
  232.                     'field_options' => [
  233.                         'field_options_start' => [
  234.                             'label' => false,
  235.                             'attr' => ['placeholder' => 'filter.valoracion.placeholder.fecha_start']
  236.                         ],
  237.                         'field_options_end' => [
  238.                             'label' => false,
  239.                             'attr' => ['placeholder' => 'filter.valoracion.placeholder.fecha_end']
  240.                         ]
  241.                     ],
  242.                     'callback' => function ($queryBuilder$alias$field$value) {
  243.                         if (!$value->hasValue()) {
  244.                             return;
  245.                         }
  246.                         $this->em->getRepository(ValoracionesRelojes::class)->cbFilter($queryBuilder$alias$field,
  247.                             $value);
  248.                         return true;
  249.                     }
  250.                 ]);
  251.         }
  252.         protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
  253.         {
  254.             $filterBusquedaRequest $this->getRequest()->get('filter')['busqueda'] ?? [];
  255.             $filterBusquedaSession $this->getRequest()->getSession()->get('admin.valoracion.filter.parameters')['busqueda'] ?? [];
  256.             $hasFilterBusqueda = @$filterBusquedaRequest['value'] || @$filterBusquedaSession['value'];
  257.             $query $this->em->getRepository(ValoracionesRelojes::class)->qbQuery($this->security->getUser()?->getUsuario()?->getUnidadNegocio(), $hasFilterBusqueda,
  258.                 !$this->getRequest()->get('filter') && empty($this->getRequest()->getSession()->get('admin.valoracion.filter.parameters')));
  259.             return parent::configureQuery(new ProxyQuery($query));
  260.         }
  261.         protected function configureListFields(ListMapper $list): void
  262.         {
  263.             $list
  264.                 ->add('valoracion.IDperseo'null, [
  265.                     'label' => 'list.valoracion.label.id_perseo',
  266.                     'header_style' => 'width: 110px',
  267.                     'sortable' => true,
  268.                     'sort_field_mapping' => ['fieldName' => 'IDperseo'],
  269.                     'sort_parent_association_mappings' => [['fieldName' => 'valoracion']],
  270. //                    'modal-link' => true,
  271. //                    'modal-attr' => [
  272. //                        'data-modal_show_class' => 'valoracion',
  273. //                        'data-modal_show_title' => $this->getTranslator()->trans('list.valoracion.modal_show.title.id_perseo')
  274. //                    ],
  275.                     'template' => 'admin/CRUD/Valoracion/list_field_valoracion.html.twig'
  276.                 ])
  277.                 /*->add('valoracion.fecha', 'datetime', [
  278.                     'label' => 'list.valoracion.label.fecha',
  279.                     'header_style' => 'width: 90px',
  280.                     'format' => 'd/m/Y',
  281.                     'sortable' => true,
  282.                     'sort_field_mapping' => ['fieldName' => 'fecha'],
  283.                     'sort_parent_association_mappings' => [['fieldName' => 'valoracion']]
  284.                 ])*/
  285.                 ->add('valoracion.estado'null, [
  286.                     'identifier' => false,
  287.                     'label' => 'list.valoracion.label.estado',
  288.                     'header_style' => 'width: 75px',
  289.                     'template' => 'admin/CRUD/Valoracion/list_field_valoracion_estado.html.twig',
  290.                     'sortable' => true,
  291.                     'sort_field_mapping' => ['fieldName' => 'nombre'],
  292.                     'sort_parent_association_mappings' => [['fieldName' => 'valoracion'],['fieldName' => 'estado']]
  293.                 ])
  294.                 ->add('valoracion.estadoFecha''datetime', [
  295.                     'label' => 'list.valoracion.label.fecha_estado',
  296.                     'header_style' => 'width: 90px;word-break: break-word;',
  297.                     'format' => 'd/m/Y',
  298.                     'template' => 'admin/CRUD/Valoracion/list_field_valoracion_estado_fecha.html.twig'
  299.                 ])
  300.                 ->add('relojMarca'null, [
  301.                     'label' => 'list.valoracion.label.marca',
  302.                     'header_style' => 'width: 75px',
  303.                     'collapse' => [
  304.                         // height in px
  305.                         'height' => 20,
  306.                         // content of the "read more" link
  307.                         'more' => '[+]',
  308.                         // content of the "read less" link
  309.                         'less' => '[-]',
  310.                     ],
  311.                     'sortable' => true,
  312.                     'sort_field_mapping' => ['fieldName' => 'nombre'],
  313.                     'sort_parent_association_mappings' => [['fieldName' => 'relojMarca']],
  314.                     'template' => 'admin/CRUD/list_field_collapse.html.twig',
  315.                 ])
  316.                 ->add('relojModelo1'null, [
  317.                     'label' => 'list.valoracion.label.modelo1',
  318.                     //'associated_property' => 'relojModelo1',
  319.                     //'collapse' => true,
  320.                     'header_style' => 'width: 75px',
  321.                     'collapse' => [
  322.                         // height in px
  323.                         'height' => 20,
  324.                         // content of the "read more" link
  325.                         'more' => '[+]',
  326.                         // content of the "read less" link
  327.                         'less' => '[-]',
  328.                     ],
  329.                     'sortable' => true,
  330.                     'sort_field_mapping' => ['fieldName' => 'relojModelo1'],
  331.                     'sort_parent_association_mappings' => [],
  332.                     'template' => 'admin/CRUD/list_field_collapse.html.twig',
  333.                 ])
  334.                 ->add('relojRef1'null, [
  335.                     'label' => 'list.valoracion.label.ref1',
  336.                     'header_style' => 'width: 75px',
  337.                     'collapse' => [
  338.                         // height in px
  339.                         'height' => 20,
  340.                         // content of the "read more" link
  341.                         'more' => '[+]',
  342.                         // content of the "read less" link
  343.                         'less' => '[-]',
  344.                     ],
  345.                     'sortable' => true,
  346.                     'sort_field_mapping' => ['fieldName' => 'relojRef1'],
  347.                     'sort_parent_association_mappings' => [],
  348.                     'template' => 'admin/CRUD/list_field_collapse.html.twig',
  349.                 ])
  350.                 ->add('precioPromocion'null, [
  351.                     'label' => 'list.valoracion.label.precio_promocion',
  352.                     'header_style' => 'width: 90px',
  353.                     'sortable' => true,
  354.                     'sort_field_mapping' => ['fieldName' => 'precioPromocion'],
  355.                     'sort_parent_association_mappings' => [],
  356.                     'template' => 'admin/CRUD/list_field_currency.html.twig',
  357.                 ])
  358.                 ->add('margenDeseado'null, [
  359.                     'label' => 'list.valoracion.label.margen_deseado',
  360.                     'header_style' => 'width: 65px',
  361.                     'sortable' => true,
  362.                     'sort_field_mapping' => ['fieldName' => 'margenDeseado'],
  363.                     'sort_parent_association_mappings' => [],
  364.                     'template' => 'admin/CRUD/list_field_percent.html.twig'
  365.                 ])
  366.                 ->add('precioPagar'null, [
  367.                     'label' => 'list.valoracion.label.precio_pagar',
  368.                     'header_style' => 'width: 90px',
  369.                     'sortable' => true,
  370.                     'sort_field_mapping' => ['fieldName' => 'precioPagar'],
  371.                     'sort_parent_association_mappings' => [],
  372.                     'template' => 'admin/CRUD/list_field_currency.html.twig'
  373.                 ])
  374.                 ->add('valoracion.cliente'null, [
  375.                     'label' => 'list.valoracion.label.cliente',
  376.                     'header_style' => 'width: 75px',
  377.                     'modal-link' => true,
  378.                     'modal-attr' => [
  379.                         'data-modal_show_class' => 'cliente',
  380.                         'data-modal_show_title' => $this->getTranslator()->trans('list.valoracion.modal_show.title.cliente')
  381.                     ],
  382.                     'collapse' => [
  383.                         // height in px
  384.                         'height' => 20,
  385.                         // content of the "read more" link
  386.                         'more' => '[+]',
  387.                         // content of the "read less" link
  388.                         'less' => '[-]',
  389.                     ],
  390.                     'sortable' => true,
  391.                     'sort_field_mapping' => ['fieldName' => 'razonSocial'],
  392.                     'sort_parent_association_mappings' => [['fieldName' => 'valoracion'], ['fieldName' => 'cliente']],
  393.                     'template' => 'admin/CRUD/list_field_cliente.html.twig'
  394.                 ])
  395.                 ->add('valoracion.canal'null, [
  396.                     'label' => 'list.valoracion.label.canal',
  397.                     'header_style' => 'width: 80px',
  398.                     'sortable' => true,
  399.                     'sort_field_mapping' => ['fieldName' => 'nombre'],
  400.                     'sort_parent_association_mappings' => [['fieldName' => 'valoracion'], ['fieldName' => 'canal']],
  401.                 ]);
  402.             if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {
  403.                 $list
  404.                     ->add('valoracion.usuario'null, [
  405.                         'label' => 'list.valoracion.label.usuario',
  406.                         'header_style' => 'width: 75px',
  407.                         'route' => [
  408.                             'name' => 'edit'
  409.                         ],
  410.                         'modal-link' => true,
  411.                         'modal-attr' => [
  412.                             'data-modal_show_class' => 'usuario',
  413.                             'data-modal_show_title' => $this->getTranslator()->trans('list.valoracion.modal_show.title.usuario')
  414.                         ],
  415.                         'collapse' => [
  416.                             // height in px
  417.                             'height' => 20,
  418.                             // content of the "read more" link
  419.                             'more' => '[+]',
  420.                             // content of the "read less" link
  421.                             'less' => '[-]',
  422.                         ],
  423.                         'sortable' => true,
  424.                         'sort_field_mapping' => ['fieldName' => 'nombre'],
  425.                         'sort_parent_association_mappings' => [['fieldName' => 'valoracion'], ['fieldName' => 'usuario'], ['fieldName' => 'user']],
  426.                         'template' => 'admin/CRUD/list_field_collapse.html.twig',
  427.                     ]);
  428.             }
  429.             $list
  430.                 ->add(ListMapper::NAME_ACTIONSnull, [
  431.                     'header_style' => 'width: 75px',
  432.                     'actions' => [
  433. //                        'edit' => ['template' => 'admin/CRUD/Valoracion/action_edit.html.twig'],
  434.                         'show' => [
  435.                             'template' => 'admin/CRUD/Valoracion/action_show.html.twig',
  436.                             'link_parameters' => [
  437.                                 'modal-attr' => [
  438.                                     'data-modal_show_class' => 'valoracion',
  439.                                     'data-modal_show_title' => $this->getTranslator()->trans('list.valoracion.modal_show.title.id_perseo')
  440.                                 ]
  441.                             ]
  442.                         ],
  443.                     ],
  444.                 ]);
  445.         }
  446.         protected function configureFormFields(FormMapper $form): void
  447.         {
  448.             $object $this->getSubject();
  449.             $idioma IdiomaEnum::IDIOMA_ES;
  450.             $fecha = new DateTime('now');
  451.             $user $this->security->getUser();
  452.             $usuario $user?->getUsuario();
  453.             $unidadNegocio $usuario?->getUnidadNegocio();
  454.             $classAccessAdmin $this->security->isGranted('ROLE_SUPER_ADMIN') ? 'access-admin' '';
  455.             if ($unidadNegocio) {
  456.                 $unidadNegocio $this->em
  457.                     ->getRepository(UnidadNegocio::class)
  458.                     ->find($unidadNegocio->getId());
  459.             }
  460.             if ($usuario) {
  461.                 $usuario $this->em
  462.                     ->getRepository(Usuario::class)
  463.                     ->find($usuario->getId());
  464.             }
  465.             if (isset($_GET['modal'])) {
  466.                 $form
  467.                     ->add('fecha'DateTimePickerType::class, [
  468.                         'label' => false,
  469.                         'placeholder' => 'form.valoracion.placeholder.fecha',
  470.                         'disabled' => $this->isDisabled(),
  471.                         'format' => 'dd-MM-yyyy HH:mm',
  472.                         'attr' => [
  473.                             'placeholder' => 'form.valoracion.placeholder.fecha',
  474.                         ]
  475.                     ])
  476.                     ->add('fechaEnviada'DateTimePickerType::class, [
  477.                         'label' => false,
  478.                         'placeholder' => 'form.valoracion.placeholder.fecha_enviada',
  479.                         'disabled' => $this->isDisabled(),
  480.                         'format' => 'dd-MM-yyyy HH:mm',
  481.                         'attr' => [
  482.                             'placeholder' => 'form.valoracion.placeholder.fecha_enviada',
  483.                         ]
  484.                     ])
  485.                     ->add('fechaAceptacion'DateTimePickerType::class, [
  486.                         'label' => false,
  487.                         'placeholder' => 'form.valoracion.placeholder.fecha_aceptacion',
  488.                         'disabled' => $this->isDisabled(),
  489.                         'format' => 'dd-MM-yyyy HH:mm',
  490.                         'attr' => [
  491.                             'placeholder' => 'form.valoracion.placeholder.fecha_aceptacion',
  492.                         ]
  493.                     ])
  494.                     ->add('fechaRechazo'DateTimePickerType::class, [
  495.                         'label' => false,
  496.                         'placeholder' => 'form.valoracion.placeholder.fecha_rechazo',
  497.                         'disabled' => $this->isDisabled(),
  498.                         'format' => 'dd-MM-yyyy HH:mm',
  499.                         'attr' => [
  500.                             'placeholder' => 'form.valoracion.placeholder.fecha_rechazo',
  501.                             'class' => 'bolder text-canceled'
  502.                         ]
  503.                     ])
  504.                     ->add('fechaTramitacion'TextType::class, [
  505.                         'label' => false,
  506.                         'data' => $object->getFechaTramitacion()?->format('d-m-Y'),
  507.                         'attr' => [
  508.                             'placeholder' => 'form.valoracion.placeholder.fecha_tramitacion',
  509.                             'readonly' => true
  510.                         ]
  511.                     ])
  512.                     ->add('valoracionesRelojesSinStocks'CollectionType::class, [
  513.                         'label' => false,
  514.                         'row_attr' => [
  515.                             'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.valoraciones_relojes'),
  516.                             'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.valoraciones_relojes'),
  517.                         ],
  518.                         'by_reference' => true,
  519.                         'btn_add' => null,
  520.                         'type_options' => ['delete' => false],
  521.                     ], [
  522.                         'edit' => 'inline',
  523.                         'inline' => 'table',
  524.                         'attr' => [
  525.                             'class' => 'table-valoraciones-relojes-sin-stocks table-view-card table-valoraciones-relojes-sin-stocks-view-card table-view-multiple-card'
  526.                         ],
  527.                         'admin_code' => 'admin.valoraciones_relojes_sin_stock',
  528.                     ])
  529.                     ->add('valoracionesRelojesStocks'CollectionType::class, [
  530.                         'label' => false,
  531.                         'row_attr' => [
  532.                             'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.valoraciones_relojes'),
  533.                             'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.valoraciones_relojes'),
  534.                         ],
  535.                         'by_reference' => true,
  536.                         'btn_add' => null,
  537.                         'type_options' => ['delete' => false],
  538.                     ], [
  539.                         'edit' => 'inline',
  540.                         'inline' => 'table',
  541.                         'attr' => [
  542.                             'class' => 'table-valoraciones-relojes-stocks table-view-card table-valoraciones-relojes-stocks-view-card table-view-multiple-card table-view-carousel'
  543.                         ],
  544.                         'admin_code' => 'admin.valoraciones_relojes_stock',
  545.                     ])
  546. //                ->add('valoracionesRelojes', CollectionType::class, [
  547. //                    'label' => false,
  548. //                    'by_reference' => false,
  549. //                    'btn_add' => false,
  550. //                    'type_options' => ['delete' => false],
  551. //                ], [
  552. //                    'edit' => 'inline',
  553. //                    'inline' => 'table',
  554. //                    'attr' => [
  555. //                        'class' => 'table-view-card table-valoraciones-relojes-view-card display-collection-type table-view-multiple-card',
  556. //                    ],
  557. //                ])
  558.                     ->add('infoValoracion'null, [
  559.                         'label' => false,
  560.                         'disabled' => $this->isDisabled(),
  561.                         'attr' => [
  562.                             'placeholder' => 'form.valoracion.placeholder.info_valoracion',
  563.                         ]
  564.                     ])
  565.                     ->add('precioPagar'null, [
  566.                         'label' => false,
  567.                         'disabled' => $this->isDisabled(),
  568.                         'attr' => [
  569.                             'placeholder' => 'form.valoracion.placeholder.precio_pagar',
  570.                             'class' => 'numeric currencies'
  571.                         ]
  572.                     ])
  573.                 ;
  574.             } else {
  575.                 $form
  576.                     ->with('with_valoracion', [
  577.                         'label' => false
  578.                     ])
  579.                     ->add('IDperseo'null, [
  580.                         'label' => false,
  581.                         'required' => false,
  582.                         'disabled' => true,
  583.                         'attr' => [
  584.                             'placeholder' => 'form.valoracion.placeholder.id_perseo',
  585.                         ],
  586.                         /*], [
  587.                             'more_info' => [
  588.                                 'data-input-field' => 'info_valoracion',
  589.                                 'data-input-field-value' => $this->getSubject()->getInfoValoracion()
  590.                             ]*/
  591.                     ])
  592.                     ->add('fecha'DateTimePickerType::class, [
  593.                         'label' => false,
  594.                         'placeholder' => 'form.valoracion.placeholder.fecha',
  595.                         //'disabled' => true,
  596.                         'format' => 'dd-MM-yyyy HH:mm',
  597.                         'data' => $object->getFecha() ? $object->getFecha() : $fecha,
  598.                         'attr' => [
  599.                             'readonly' => true,
  600.                             'placeholder' => 'form.valoracion.placeholder.fecha',
  601.                         ],
  602.                         'row_attr' => [
  603.                             'class' => 'readonly',
  604.                         ]
  605.                     ])
  606.                     ->add('unidadNegocio'null, [
  607.                         'label' => false,
  608.                         //'disabled' => true,
  609.                         'placeholder' => 'form.valoracion.placeholder.unidad_negocio',
  610.                         'data' => $object->getUnidadNegocio() ? $object->getUnidadNegocio() : $unidadNegocio,
  611.                         'choice_attr' => function ($val$key$index)
  612.                         {
  613.                             return $val?->getColor() ? [
  614.                                 'data-color' => $val->getColor(),
  615.                                 'style' => 'color: ' $val->getColor() . ';',
  616.                             ] : [];
  617.                         },
  618.                         'row_attr' => [
  619.                             'class' => 'color-unidad-negocio'
  620.                         ]
  621.                         /*'attr' => [
  622.                             'readonly' => $this->isReadOnly(),
  623.                         ],
  624.                         'row_attr' => [
  625.                             'class' => $this->isReadOnly()?'readonly':'',
  626.                         ]*/
  627.                     ])
  628.                     ->add('usuario'null, [
  629.                         'label' => false,
  630.                         //'disabled' => true,
  631.                         'placeholder' => 'form.valoracion.placeholder.usuario',
  632.                         'data' => $object->getUsuario() ? $object->getUsuario() : $usuario,
  633.                         'attr' => [
  634.                             'readonly' => $this->isReadOnly(),
  635.                         ],
  636.                         'row_attr' => [
  637.                             'class' => $this->isReadOnly()?'readonly':'',
  638.                         ]
  639.                     ])
  640.                     ->add('canal'ModelListType::class, [
  641.                         'label' => false,
  642.                         'attr' => [
  643.                             'data-max_length' => 15
  644.                         ],
  645.                         'row_attr' => [
  646.                             'class' => 'display-model-list-type create-display-none'
  647.                         ],
  648.                         'btn_delete' => false,
  649.                     ], [
  650.                         'placeholder' => 'form.valoracion.placeholder.canal',
  651.                         'link_parameters' => [
  652.                             'nav_prometeo' => true,
  653.                             'model_list_type' => 'canal',
  654.                             'action_create_not_list' => false,
  655.                         ]
  656.                     ])
  657.                     ->add('cliente'ModelListType::class, [
  658.                         'label' => false,
  659.                         'attr' => [
  660.                             'data-max_length' => 24
  661.                         ],
  662.                         'row_attr' => [
  663.                             'class' => "display-model-list-type create-display-none $classAccessAdmin"
  664.                         ],
  665.                         'btn_delete' => false,
  666.                     ], [
  667.                         'placeholder' => 'form.valoracion.placeholder.cliente',
  668.                         'link_parameters' => [
  669.                             'nav_prometeo' => true,
  670.                             'model_list_type' => 'cliente',
  671.                             'action_create_not_list' => false,
  672.                         ]
  673.                     ])
  674.                     ->add('tipoCliente'null, [
  675.                         'label' => 'form.valoracion.label.tipo_cliente'
  676.                     ])
  677.                     ->add('exportacion'null, [
  678.                         'label' => 'form.valoracion.label.exportacion'
  679.                     ])
  680.                     ->add('infoValoracion'null, [
  681.                         'label' => false,
  682.                         'attr' => [
  683.                             'placeholder' => 'form.valoracion.placeholder.info_valoracion'
  684.                         ],
  685.                         'row_attr' => [
  686.                             'class' => $object?->getInfoValoracion() ? 'more-info more-info-modal' 'more-info more-info-modal empty',
  687.                             'more_info_class' => 'more-info-input-wrap more-info-input-wrap-modal more-info-input-wrap-right',
  688.                         ],
  689.                     ])
  690.                     ->add('idioma'ChoiceType::class, [
  691.                         'label' => false,
  692.                         'placeholder' => 'form.valoracion.placeholder.idioma',
  693.                         'choices' => array_flip(IdiomaEnum::getIdiomas()),
  694.                         'data' => $object->getIdioma() ? $object->getIdioma() : $idioma,
  695.                     ])
  696.                     ->end()
  697.                     /*->with('with_help_usuario', [
  698.                         'label' => 'form.valoracion.with_help_usuario',
  699.                     ])
  700.                         ->add('content', HTMLType::class, [
  701.                             'label' => false,
  702.                             'template' => 'admin/valoraciones/help_usuario.html.twig'
  703.                         ])
  704.                     ->end()*/
  705.                     ->with('with_valoraciones_relojes_sin_stock', [
  706.                         'label' => false//'form.valoracion.with_valoraciones_relojes_sin_stock.label',
  707.                         //'class' => 'with-collapse col-md-12'
  708.                     ])
  709.                     ->add('valoracionesRelojesSinStocks'CollectionType::class, [
  710.                         'label' => false,
  711.                         'row_attr' => [
  712.                             'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.valoraciones_relojes'),
  713.                             'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.valoraciones_relojes'),
  714.                         ],
  715.                         'by_reference' => false,
  716.                         'btn_add' => 'link_add_valoraciones_relojes_sin_stocks'
  717.                     ], [
  718.                         'edit' => 'inline',
  719.                         'inline' => 'table',
  720.                         'attr' => [
  721.                             'class' => 'table-valoraciones-relojes-sin-stocks table-view-card table-valoraciones-relojes-sin-stocks-view-card table-view-multiple-card'
  722.                         ],
  723.                         'admin_code' => 'admin.valoraciones_relojes_sin_stock',
  724.                     ])
  725.                     ->add('scriptEventOnChange'ScriptType::class, [
  726.                         'template' => 'SCRIPTS/ValoracionesRelojesSinStock/reloj_event_on_change.html.twig'
  727.                     ])
  728.                 ;
  729.                 if (!$this->isHidden()) {
  730.                     $form
  731.                         ->add('scriptDeleteImagen'ScriptType::class, [
  732.                             'template' => 'SCRIPTS/ValoracionesRelojesSinStock/delete_imagen.html.twig'
  733.                         ])
  734.                         ->add('scriptCalcularMargenPromocion'ScriptType::class, [
  735.                             'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_margen_promocion.html.twig'
  736.                         ])
  737.                         ->add('scriptCalcularMargenMinimo'ScriptType::class, [
  738.                             'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_margen_minimo.html.twig'
  739.                         ])
  740.                         ->add('scriptCalcularPrecioCosteTotal'ScriptType::class, [
  741.                             'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_precio_oferta.html.twig'
  742.                         ])
  743.                         ->add('scriptCalcularCostesEventOnChangePrecio'ScriptType::class, [
  744.                             'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_costes_event_on_change_precio.html.twig'
  745.                         ])
  746.                         ->add('scriptControlPrecioReferencia'ScriptType::class, [
  747.                             'template' => 'SCRIPTS/ValoracionesRelojesSinStock/control_precio_referencia.html.twig'
  748.                         ])
  749.                         ->add('scriptControlCostesTotal'ScriptType::class, [
  750.                             'template' => 'SCRIPTS/ValoracionesRelojesSinStock/control_costes_total.html.twig'
  751.                         ]);
  752.                 }
  753.                 $form
  754.                     ->end()
  755.                     ->with('with_valoraciones_relojes_stock', [
  756.                         'label' => null,//'form.valoracion.with_valoraciones_relojes_stock.label',
  757.                         'class' => 'hide col-md-12'//'with-collapse col-md-12'
  758.                     ])
  759.                     ->add('valoracionesRelojesStocks'CollectionType::class, [
  760.                         'label' => false,
  761.                         'row_attr' => [
  762. //                            'class' => 'hide',
  763.                             'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.valoraciones_relojes'),
  764.                             'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.valoraciones_relojes'),
  765.                         ],
  766.                         'by_reference' => false,
  767.                         'btn_add' => 'link_add_valoraciones_relojes_stocks'
  768.                     ], [
  769.                         'edit' => 'inline',
  770.                         'inline' => 'table',
  771.                         'attr' => [
  772.                             'class' => 'table-valoraciones-relojes-stocks table-view-card table-valoraciones-relojes-stocks-view-card table-view-multiple-card'
  773.                         ],
  774.                         'admin_code' => 'admin.valoraciones_relojes_stock',
  775.                     ])
  776.                     ->end()
  777.                     ->with('with_resumen', [
  778.                         'label' => false
  779.                     ])
  780.                     ->add('fechaEnviada'DatePickerType::class, [
  781.                         'label' => false,
  782.                         'placeholder' => 'form.valoracion.placeholder.fecha_enviada',
  783.                         'format' => 'dd-MM-yyyy',
  784.                         'row_attr' => [
  785.                             'class' => 'control-fechas-resumen',
  786.                         ],
  787.                         'attr' => [
  788.                             'placeholder' => 'form.valoracion.placeholder.fecha_enviada',
  789.                             'data-control_fecha_title' => null,
  790.                             'data-control_fecha_message' => $this->getTranslator()->trans('message.control.fecha.valoraciones_relojes.fecha_enviada'),
  791.                         ],
  792.                         'datepicker_options' => [
  793.                             'useCurrent' => false
  794.                         ]
  795.                     ])
  796.                     ->add('fechaAceptacion'DatePickerType::class, [
  797.                         'label' => false,
  798.                         'placeholder' => 'form.valoracion.placeholder.fecha_aceptacion',
  799.                         'format' => 'dd-MM-yyyy',
  800.                         'row_attr' => [
  801.                             'class' => 'control-fechas-resumen readonly',
  802.                             //'style' => 'pointer-events: none;'
  803.                         ],
  804.                         'attr' => [
  805.                             'readonly' => true,
  806.                             'placeholder' => 'form.valoracion.placeholder.fecha_aceptacion',
  807.                         ],
  808.                         'datepicker_options' => [
  809.                             'useCurrent' => false,
  810.                         ]
  811.                     ])
  812.                     ->add('fechaRechazo'DatePickerType::class, [
  813.                         'label' => false,
  814.                         'placeholder' => 'form.valoracion.placeholder.fecha_rechazo',
  815.                         'format' => 'dd-MM-yyyy',
  816.                         'row_attr' => [
  817.                             'class' => 'control-fechas-resumen bolder text-canceled',
  818.                             //'style' => 'pointer-events: none;'
  819.                         ],
  820.                         'attr' => [
  821.                             'readonly' => false,
  822.                             'placeholder' => 'form.valoracion.placeholder.fecha_rechazo',
  823.                         ],
  824.                         'datepicker_options' => [
  825.                             'useCurrent' => false,
  826.                         ]
  827.                     ])
  828.                     ->add('fechaTramitacion'TextType::class, [
  829.                         'label' => false,
  830.                         'disabled' => true,
  831.                         'data' => $object->getFechaTramitacion()?->format('d-m-Y'),
  832.                         'attr' => [
  833.                             'readonly' => true,
  834.                             'placeholder' => 'form.valoracion.placeholder.fecha_tramitacion',
  835.                         ]
  836.                     ])
  837.                     ->add('infoTramitacion'null, [
  838.                         'label' => false,
  839.                         'attr' => [
  840.                             'placeholder' => 'form.valoracion.placeholder.info_tramitacion'
  841.                         ],
  842.                         'row_attr' => [
  843.                             'class' => $object?->getInfoTramitacion() ? 'more-info more-info-modal' 'more-info more-info-modal empty',
  844.                             'more_info_class' => 'more-info-input-wrap more-info-input-wrap-modal more-info-input-wrap-right',
  845.                         ]
  846.                     ])
  847.                     ->add('precioPagar'null, [
  848.                         'label' => false,
  849.                         'attr' => [
  850.                             'readonly' => true,
  851.                             'placeholder' => 'form.valoracion.placeholder.precio_pagar',
  852.                             'class' => $object?->getPrecioPagar() < 'numeric currencies currency-negative' 'numeric currencies currency-positive'
  853.                         ]
  854.                     ])
  855.                     ->add('scriptCalcularPrecioPagar'ScriptType::class, [
  856.                         'template' => 'SCRIPTS/Valoracion/calcular_precio_pagar.html.twig'
  857.                     ])
  858.                     ->add('scriptRecalculosDeleteCollections'ScriptType::class, [
  859.                         'template' => 'SCRIPTS/Valoracion/recalculos_delete_collections.html.twig'
  860.                     ])
  861.                     ->add('scriptControlFechasResumen'ScriptType::class, [
  862.                         'template' => 'SCRIPTS/Valoracion/control_fechas_resumen.html.twig'
  863.                     ])
  864.                     ->end();
  865.             }
  866.         }
  867.         protected function configureShowFields(ShowMapper $show): void
  868.         {
  869.             $show
  870.                 ->add('id');
  871.         }
  872.         private function isReadOnly()
  873.         {
  874.             return !$this->security->isGranted('ROLE_SUPER_ADMIN');
  875.         }
  876.         private function isDisabled()
  877.         {
  878.             return isset($_GET['modal']);
  879.         }
  880.         private function isHidden()
  881.         {
  882.             return isset($_GET['modal']);
  883.         }
  884.     }