src/Admin/OperacionAdmin.php line 900

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Admin;
  4. use App\DTO\RelojPrecioCompraDTO;
  5. use App\Entity\CCAA;
  6. use App\Entity\EstadoOperacion;
  7. use App\Entity\Firmante;
  8. use App\Entity\Intercambio;
  9. use App\Entity\Operacion;
  10. use App\Entity\Provincia;
  11. use App\Entity\UnidadNegocio;
  12. use App\Entity\Usuario;
  13. use App\Enum\EstadoOperacionEnum;
  14. use App\Enum\IdiomaEnum;
  15. use App\Enum\TipoOperacionEnum;
  16. use App\Form\Type\HTMLType;
  17. use App\Form\Type\ScriptType;
  18. use App\Handler\Reloj\ActualizarPrecioCompra\ActualizarPrecioCompraRelojCommand;
  19. use App\Handler\Reloj\ActualizarPrecioCompra\ActualizarPrecioCompraRelojCommandHandler;
  20. use DateTime;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Sonata\AdminBundle\Admin\AbstractAdmin;
  23. use Sonata\AdminBundle\Datagrid\DatagridInterface;
  24. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  25. use Sonata\AdminBundle\Datagrid\ListMapper;
  26. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  27. use Sonata\AdminBundle\Form\FormMapper;
  28. use Sonata\AdminBundle\Form\Type\ModelListType;
  29. use Sonata\AdminBundle\Form\Type\Operator\EqualOperatorType;
  30. use Sonata\AdminBundle\Route\RouteCollectionInterface;
  31. use Sonata\AdminBundle\Show\ShowMapper;
  32. use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
  33. use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter;
  34. use Sonata\Form\Type\CollectionType;
  35. use Sonata\Form\Type\DatePickerType;
  36. use Sonata\Form\Type\DateRangePickerType;
  37. use Sonata\Form\Type\DateTimePickerType;
  38. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  39. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  40. use Symfony\Component\Form\Extension\Core\Type\CountryType;
  41. use Symfony\Component\Security\Core\Security;
  42. use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
  43. use Vich\UploaderBundle\Form\Type\VichFileType;
  44. final class OperacionAdmin extends AbstractAdmin
  45. {
  46.     public function __construct(
  47.         string $code,
  48.         string $class,
  49.         string $baseControllerName,
  50.         private Security $security,
  51.         private EntityManagerInterface $em,
  52.         private ActualizarPrecioCompraRelojCommandHandler $actualizarPrecioCompraRelojCommandHandler
  53.     ) {
  54.         parent::__construct($code$class$baseControllerName);
  55.         $this->setTranslationDomain('operacionAdmin');
  56.     }
  57.     public function configureRoutes(RouteCollectionInterface $collection): void
  58.     {
  59.         $collection->add('contract');
  60.         $collection->add('delivery');
  61.         $collection->add('proforma');
  62.         $collection->add('cancel-reloj');
  63.         $collection->add('upload-contract');
  64. //        $collection->add('card');
  65. //        $collection->add('send');
  66.         $collection->add('in-process');
  67.         $collection->add('processed');
  68.         $collection->add('confirmed');
  69.         $collection->add('settle');
  70.         $collection->add('finish');
  71.         $collection->add('cancel');
  72.         $collection->add('switch-valoracion');
  73.         $collection->add('control-unconfirmed');
  74.         parent::configureRoutes($collection);
  75.     }
  76.     protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
  77.     {
  78.         $query $this->em->getRepository(Operacion::class)->qbAllDetail();
  79.         return parent::configureQuery(new ProxyQuery($query));
  80.     }
  81.     public function configureExportFields(): array
  82.     {
  83.         return [
  84.             $this->getTranslator()->trans('export.operacion.idperseo', [], 'operacionAdmin') => 'IDperseo',
  85.             $this->getTranslator()->trans('export.operacion.valoracion_idperseo', [], 'operacionAdmin') => 'valoracionIDperseo',
  86.             $this->getTranslator()->trans('export.operacion.estado_nombre', [], 'operacionAdmin') => 'estadoKey',
  87.             $this->getTranslator()->trans('export.operacion.cliente', [], 'operacionAdmin') => 'clienteRazonSocial',
  88.             $this->getTranslator()->trans('export.operacion.canal', [], 'operacionAdmin') => 'canalNombre',
  89.             $this->getTranslator()->trans('export.operacion.fecha_en_tramitacion', [], 'operacionAdmin') => 'fechaEnTramitacion',
  90.             $this->getTranslator()->trans('export.operacion.fecha_tramitacion', [], 'operacionAdmin') => 'fechaTramitacion',
  91.             $this->getTranslator()->trans('export.operacion.fecha_confirmacion', [], 'operacionAdmin') => 'fechaConfirmacion',
  92.             $this->getTranslator()->trans('export.operacion.detalle_reloj_idperseo', [], 'operacionAdmin') => 'detalleRelojIDperseo',
  93.             $this->getTranslator()->trans('export.operacion.detalle_reloj_marca_nombre', [], 'operacionAdmin') => 'detalleRelojMarcaNombre',
  94.             $this->getTranslator()->trans('export.operacion.detalle_reloj_modelo1', [], 'operacionAdmin') => 'detalleRelojModelo1',
  95.             $this->getTranslator()->trans('export.operacion.detalle_reloj_ref1', [], 'operacionAdmin') => 'detalleRelojRef1',
  96.             $this->getTranslator()->trans('export.operacion.detalle_coste', [], 'operacionAdmin') => 'detalleCoste',
  97.             $this->getTranslator()->trans('export.operacion.detalle_precio_venta', [], 'operacionAdmin') => 'detallePrecioVenta',
  98.             $this->getTranslator()->trans('export.operacion.usuario_idperseo', [], 'operacionAdmin') => 'usuarioIDperseo',
  99.             $this->getTranslator()->trans('export.operacion.user_username', [], 'operacionAdmin') => 'userUsername',
  100.             $this->getTranslator()->trans('export.operacion.user_email', [], 'operacionAdmin') => 'userEmail',
  101.             $this->getTranslator()->trans('export.operacion.user_nombre', [], 'operacionAdmin') => 'userNombre',
  102.             $this->getTranslator()->trans('export.operacion.user_primer_apellido', [], 'operacionAdmin') => 'userPrimerApellido',
  103.             $this->getTranslator()->trans('export.operacion.user_segundo_apellido', [], 'operacionAdmin') => 'userSegundoApellido',
  104.         ];
  105.     }
  106.     protected function configureDefaultFilterValues(array &$filterValues): void
  107.     {
  108.         $filterValues = [
  109.             'estado' => [
  110.                 'type'  => EqualOperatorType::TYPE_EQUAL,
  111.                 'value' => [ EstadoOperacionEnum::ESTADO_EN_TRAMITACION,  EstadoOperacionEnum::ESTADO_TRAMITADA ]
  112.             ],
  113.         ];
  114.         parent::configureDefaultFilterValues($filterValues); // TODO: Change the autogenerated stub
  115.     }
  116.     protected function configureDefaultSortValues(array &$sortValues): void
  117.     {
  118.         parent::configureDefaultSortValues($sortValues);
  119.         $sortValues[DatagridInterface::PER_PAGE] = 50;
  120.         $sortValues[DatagridInterface::SORT_ORDER] = 'DESC';
  121.         $sortValues[DatagridInterface::SORT_BY] = 'operacion.estadofecha';
  122.     }
  123.     protected function configureDatagridFilters(DatagridMapper $filter): void
  124.     {
  125.         if(!@$_REQUEST['filter'][DatagridInterface::PER_PAGE]) $this->getDatagrid()->setValue(DatagridInterface::PER_PAGEnull50);
  126.         $choicesUsuarioS = [$this->em->getReference(Usuario::class, 0)];
  127.         //if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {
  128.             $choicesUsuarioS array_merge($choicesUsuarioS,
  129.                 $this->em->getRepository(Usuario::class)->findAll() ?? []);
  130.         /*} else {
  131.             $choicesUsuarioS = array_merge($choicesUsuarioS,
  132.                 $this->em->getRepository(Usuario::class)->getUsuariosByUnidadNegocio($this->security->getUser()->getUsuario()?->getUnidadNegocio()));
  133.         }*/
  134.         $filter
  135.             ->add('busqueda'CallbackFilter::class, [
  136.                 'label' => null,
  137.                 'attr' => [
  138.                     'class' => 'filter-to-navbar-left filter-to-navbar',
  139.                     'data-order' => '1',
  140.                     'placeholder' => 'filter.placeholder.busqueda',
  141.                 ],
  142.                 'callback' => function ($queryBuilder$alias$field$value) {
  143.                     if (!$value->hasValue()) {
  144.                         return;
  145.                     }
  146.                     $this->em->getRepository(Operacion::class)->cbFilter($queryBuilder$alias$field,
  147.                         $value);
  148.                     return true;
  149.                 },
  150.             ])
  151.             ->add('tipo'CallbackFilter::class, [
  152.                 'label' => false,
  153.                 'attr' => [
  154.                     'class' => 'filter-to-navbar-right filter-to-navbar',
  155.                     'data-order' => '1',
  156.                     'data-id' => 'filter-filters'
  157.                 ],
  158.                 'callback' => function ($queryBuilder$alias$field$value) {
  159.                     if (!$value->hasValue()) {
  160.                         return;
  161.                     }
  162.                     $this->em->getRepository(Operacion::class)->cbFilter($queryBuilder$alias$field$value);
  163.                     return true;
  164.                 },
  165.             ], [
  166.                 'field_type' => ChoiceType::class,
  167.                 'field_options' => [
  168.                     'choices' => array_keys(TipoOperacionEnum::getOperaciones()),
  169.                     'multiple' => true,
  170.                     'expanded' => true,
  171.                     'choice_label' => function ($choice$key$value) {
  172.                         return $this->getTranslator()->trans(TipoOperacionEnum::getOperacion($choice), [], 'enum');
  173.                     },
  174.                 ]
  175.             ])
  176.             ->add('estado'CallbackFilter::class, [
  177.                 'label' => false,
  178.                 'attr' => [
  179.                     'class' => 'filter-to-navbar-right filter-to-navbar',
  180.                     'data-order' => '2',
  181.                     'data-id' => 'filter-filters'
  182.                 ],
  183.                 'callback' => function ($queryBuilder$alias$field$value) {
  184.                     if (!$value->hasValue()) {
  185.                         return;
  186.                     }
  187.                     $this->em->getRepository(Operacion::class)->cbFilter($queryBuilder$alias$field$value);
  188.                     return true;
  189.                 },
  190.             ], [
  191.                 'field_type' => ChoiceType::class,
  192.                 'field_options' => [
  193.                     'choices' => array_keys(EstadoOperacionEnum::getEstados()),
  194.                     'multiple' => true,
  195.                     'expanded' => true,
  196.                     'choice_label' => function ($choice$key$value) {
  197.                         return $this->getTranslator()->trans(EstadoOperacionEnum::getEstado($choice), [], 'enum');
  198.                     },
  199.                 ]
  200.             ])
  201.         ;
  202.         $filter
  203.             ->add('usuario'CallbackFilter::class, [
  204.                 'label' => false,
  205.                 'attr' => [
  206.                     'data-order' => '1',
  207.                 ],
  208.                 'callback' => function ($queryBuilder$alias$field$value) {
  209.                     if (!$value->hasValue()) {
  210.                         return;
  211.                     }
  212.                     $this->em->getRepository(Operacion::class)->cbFilter($queryBuilder$alias$field,
  213.                         $value);
  214.                     return true;
  215.                 },
  216.             ], [
  217.                 'field_type' => ChoiceType::class,
  218.                 'field_options' => [
  219.                     'choices' => $choicesUsuarioS,
  220.                     'multiple' => false,
  221.                     'expanded' => true,
  222.                     'choice_value' => function ($choice) {
  223.                         return $choice $choice->getId() : 0;
  224.                     },
  225.                     'choice_label' => function ($choice$key$value) {
  226.                         return $value != $choice->getUser()->getIniciales() : 'filter.operacion.usuarios.label.all';
  227.                     },
  228.                     'choice_attr' => function ($choice$key$value) {
  229.                         return [
  230.                             'selected' => $value == 0
  231.                         ];
  232.                     },
  233.                 ]
  234.             ])
  235.             ->add('fecha'CallbackFilter::class, [
  236.                 'label' => false,
  237.                 'attr' => [
  238.                     'data-order' => '2',
  239.                     'class' => 'filter-date-range'
  240.                 ],
  241.                 'field_type' => DateRangePickerType::class,
  242.                 'field_options' => [
  243.                     'field_options_start' => [
  244.                         'label' => false,
  245.                         'format' => 'dd/MM/yyyy',
  246.                         'attr' => ['placeholder' => 'filter.operacion.placeholder.fecha_start']
  247.                     ],
  248.                     'field_options_end' => [
  249.                         'label' => false,
  250.                         'format' => 'dd/MM/yyyy',
  251.                         'attr' => ['placeholder' => 'filter.operacion.placeholder.fecha_end']
  252.                     ]
  253.                 ],
  254.                 'callback' => function ($queryBuilder$alias$field$value) {
  255.                     if (!$value->hasValue()) {
  256.                         return;
  257.                     }
  258.                     $this->em->getRepository(Operacion::class)->cbFilter($queryBuilder$alias$field,
  259.                         $value);
  260.                     return true;
  261.                 }
  262.             ])
  263.         ;
  264.     }
  265.     protected function configureListFields(ListMapper $list): void
  266.     {
  267.         $this->setTranslationDomain('operacionAdmin');
  268.         $list
  269.             ->add('IDperseo'null, [
  270.                 'label' => 'list.operacion.label.idperseo',
  271.                 'header_style' => 'width: 95px',
  272.                 'template' => 'admin/CRUD/Operacion/list_field_identifier_idperseo.html.twig',
  273.             ])
  274.             /*->add('valoracionIDperseo', null, [
  275.                 'label' => 'list.operacion.label.valoracion_idperseo',
  276.                 'header_style' => 'width: 110px',
  277.                 'sortable' => true,
  278.                 'sort_field_mapping' => ['fieldName' => 'valoracionIDperseo'],
  279.                 'sort_parent_association_mappings' => [],
  280.                 'template' => 'admin/CRUD/Operacion/list_field_identifier_valoracion_idperseo.html.twig',
  281.             ])*/
  282.             ->add('tipo'null, [
  283.                 'label' => 'list.operacion.label.tipo',
  284.                 'header_style' => 'width: 75px',
  285.                 'sortable' => true,
  286.                 'sort_field_mapping' => ['fieldName' => 'tipo'],
  287.                 'sort_parent_association_mappings' => [],
  288.             ])
  289.             ->add('estadoFecha''datetime', [
  290.                 'label' => 'list.operacion.label.estado_fecha',
  291.                 'header_style' => 'width: 90px;word-break: break-word;',
  292.                 'format' => 'd/m/Y',
  293.                 'sortable' => true,
  294.                 'sort_field_mapping' => ['fieldName' => 'estadoFecha'],
  295.                 'sort_parent_association_mappings' => [],
  296.             ])
  297.             ->add('estadoNombre''trans', [
  298.                 'label' => 'list.operacion.label.estado',
  299.                 'header_style' => 'width: 110px',
  300.                 'translationDomain' => 'enum',
  301.                 'collapse' => [
  302.                     // height in px
  303.                     'height' => 20,
  304.                     // content of the "read more" link
  305.                     'more' => '[+]',
  306.                     // content of the "read less" link
  307.                     'less' => '[-]',
  308.                 ],
  309.                 'sortable' => true,
  310.                 'sort_field_mapping' => ['fieldName' => 'estadoNombre'],
  311.                 'sort_parent_association_mappings' => [],
  312.             ])
  313. //            ->add('detalleRelojIDperseo', null, [
  314. //                'label' => 'list.operacion.label.detalle_reloj_idreloj',
  315. //                'header_style' => 'width: 110px',
  316. //                'sortable' => true,
  317. //                'sort_field_mapping' => ['fieldName' => 'detalleRelojIDperseo'],
  318. //                'sort_parent_association_mappings' => [],
  319. //                'template' => 'admin/CRUD/Operacion/list_field_identifier_detalle_reloj_idperseo.html.twig',
  320. //            ])
  321.             ->add('detalleRelojCodigo'null, [
  322.                 'label' => 'list.operacion.label.detalle_reloj_codigo',
  323.                 'header_style' => 'width: 90px',
  324.                 'sortable' => true,
  325.                 'sort_field_mapping' => ['fieldName' => 'detalleRelojCodigo'],
  326.                 'sort_parent_association_mappings' => [],
  327.                 'template' => 'admin/CRUD/Operacion/list_field_identifier_detalle_reloj_codigo.html.twig',
  328.             ])
  329.             ->add('detalleRelojMarcaNombre'null, [
  330.                 'label' => 'list.operacion.label.detalle_reloj_marca',
  331.                 'header_style' => 'min-width: 75px',
  332.                 'collapse' => [
  333.                     // height in px
  334.                     'height' => 20,
  335.                     // content of the "read more" link
  336.                     'more' => '[+]',
  337.                     // content of the "read less" link
  338.                     'less' => '[-]',
  339.                 ],
  340.                 'sortable' => true,
  341.                 'sort_field_mapping' => ['fieldName' => 'detalleRelojMarcaNombre'],
  342.                 'sort_parent_association_mappings' => [],
  343.                 'template' => 'admin/CRUD/list_field_collapse.html.twig',
  344.             ])
  345.             ->add('detalleRelojModelos'null, [
  346.                 'label' => 'list.operacion.label.detalle_reloj_modelos',
  347.                 'header_style' => 'min-width: 75px',
  348.                 'collapse' => [
  349.                     // height in px
  350.                     'height' => 20,
  351.                     // content of the "read more" link
  352.                     'more' => '[+]',
  353.                     // content of the "read less" link
  354.                     'less' => '[-]',
  355.                 ],
  356.                 'sortable' => true,
  357.                 'sort_field_mapping' => ['fieldName' => 'detalleRelojModelo1'],
  358.                 'sort_parent_association_mappings' => [],
  359.                 'template' => 'admin/CRUD/list_field_collapse.html.twig',
  360.             ])
  361.             ->add('detalleRelojRef1'null, [
  362.                 'label' => 'list.operacion.label.detalle_reloj_ref1',
  363.                 'header_style' => 'width: 75px',
  364.                 'collapse' => [
  365.                     // height in px
  366.                     'height' => 20,
  367.                     // content of the "read more" link
  368.                     'more' => '[+]',
  369.                     // content of the "read less" link
  370.                     'less' => '[-]',
  371.                 ],
  372.                 'sortable' => true,
  373.                 'sort_field_mapping' => ['fieldName' => 'detalleRelojRef1'],
  374.                 'sort_parent_association_mappings' => [],
  375.                 'template' => 'admin/CRUD/list_field_collapse.html.twig',
  376.             ])
  377.             ->add('detallePrecioCoste'null, [
  378.                 'label' => 'list.operacion.label.detalle_precio_coste',
  379.                 'header_style' => 'width: 90px;word-break: break-word;',
  380.                 'sortable' => true,
  381.                 'sort_field_mapping' => ['fieldName' => 'detallePrecioCoste'],
  382.                 'sort_parent_association_mappings' => [],
  383.                 'template' => 'admin/CRUD/list_field_currency.html.twig',
  384.             ])
  385.             ->add('detallePrecioVenta'null, [
  386.                 'label' => 'list.operacion.label.detalle_precio_venta',
  387.                 'header_style' => 'width: 90px;word-break: break-word;',
  388.                 'sortable' => true,
  389.                 'sort_field_mapping' => ['fieldName' => 'detallePrecioVenta'],
  390.                 'sort_parent_association_mappings' => [],
  391.                 'template' => 'admin/CRUD/list_field_currency.html.twig',
  392.             ])
  393.             ->add('clienteRazonSocial'null, [
  394.                 'label' => 'list.operacion.label.cliente',
  395.                 //'header_style' => 'width: 150px',
  396.                 'collapse' => [
  397.                     // height in px
  398.                     'height' => 20,
  399.                     // content of the "read more" link
  400.                     'more' => '[+]',
  401.                     // content of the "read less" link
  402.                     'less' => '[-]',
  403.                 ],
  404.                 'sortable' => true,
  405.                 'sort_field_mapping' => ['fieldName' => 'clienteRazonSocial'],
  406.                 'sort_parent_association_mappings' => [],
  407.                 'template' => 'admin/CRUD/list_field_collapse.html.twig',
  408.             ])
  409.             ->add('canalNombre'null, [
  410.                 'label' => 'list.operacion.label.canal',
  411.                 'header_style' => 'width: 90px',
  412.                 'sortable' => true,
  413.                 'sort_field_mapping' => ['fieldName' => 'canalNombre'],
  414.                 'sort_parent_association_mappings' => [],
  415.             ])
  416.         ;
  417.     }
  418.     protected function configureFormFields(FormMapper $form): void
  419.     {
  420.         $this->setTranslationDomain('operacionAdmin');
  421.         $object $this->getSubject();
  422.         if(!$object->getId())
  423.         {
  424.             $estado $this->em->getRepository(EstadoOperacion::class)->findOneBy(['key' => EstadoOperacionEnum::ESTADO_EN_TRAMITACION]);
  425.             $object->setEstado($estado);
  426.         }
  427.         $mappedCliente $object->getCliente()?->getId() ? true false;
  428.         $compras $object?->getCompra()?->getDetalle();
  429.         $ventas $object?->getVenta()?->getDetalle();
  430.         $idioma IdiomaEnum::IDIOMA_ES;
  431.         $fecha = new DateTime();
  432.         $user $this->security->getUser();
  433.         $usuario $user?->getUsuario();
  434.         $unidadNegocio $usuario?->getUnidadNegocio();
  435.         $estadoOperacion $object?->getEstado()?->getKey();
  436.         if ($unidadNegocio) {
  437.             $unidadNegocio $this->em
  438.                 ->getRepository(UnidadNegocio::class)
  439.                 ->find($unidadNegocio->getId());
  440.         }
  441.         if ($usuario) {
  442.             $usuario $this->em
  443.                 ->getRepository(Usuario::class)
  444.                 ->find($usuario->getId());
  445.         }
  446.         $classGestionVentaMoreInfo = ($object->getTipo() === TipoOperacionEnum::OPERACION_GESTION &&
  447.             $estadoOperacion &&
  448.             ($estadoOperacion === EstadoOperacionEnum::ESTADO_CONFIRMADA || $estadoOperacion === EstadoOperacionEnum::ESTADO_FINALIZADA)
  449.         ) ? 'more-info-fechas' '';
  450.         $classAccessAdmin $this->security->isGranted('ROLE_SUPER_ADMIN') ? 'access-admin' '';
  451.         $updateDataInfoSend $this->isUpdateDataInfoSend();
  452.         $classNoBlockFechaEnTramitacion $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_EN_TRAMITACION 'no-block' 'readonly';
  453.         $classNoBlockFechaTramitada in_array($object->getEstado()?->getKey(), [ EstadoOperacionEnum::ESTADO_EN_TRAMITACIONEstadoOperacionEnum::ESTADO_TRAMITADA ]) ? 'no-block' 'readonly';
  454.         $classNoBlockFechaConfirmada in_array($object->getEstado()?->getKey(), [ EstadoOperacionEnum::ESTADO_TRAMITADAEstadoOperacionEnum::ESTADO_CONFIRMADA ]) ? 'no-block' 'readonly';
  455.         $classOperacionExportacion $object->getExportacion() ? 'operacion-exportacion' '';
  456.         $form
  457.             ->with('with_operacion', [
  458.                 'label' => false,
  459.                 'class' => $this->isReadonly() ? 'col-md-12 with readonly' 'col-md-12'
  460.             ])
  461.             ->add('IDperseo'null, [
  462.                 'label' => false,
  463.                 'translation_domain' => 'operacionAdmin',
  464.                 'required' => false,
  465.                 'disabled' => true,
  466.                 'attr' => [
  467.                     'placeholder' => 'form.operacion.placeholder.id_perseo',
  468.                 ],
  469.                 /*], [
  470.                     'more_info' => [
  471.                         'data-input-field' => 'info_valoracion',
  472.                         'data-input-field-value' => $this->getSubject()->getInfoValoracion()
  473.                     ]*/
  474.             ])
  475.         ;
  476.         if($object->getId() && $object->getValoracion()) {
  477.             $form
  478.                 ->add('valoracion.IDperseo'null, [
  479.                     'label' => false,
  480.                     'translation_domain' => 'operacionAdmin',
  481.                     'required' => false,
  482.                     'disabled' => true,
  483.                     'attr' => [
  484.                         'placeholder' => 'form.operacion.placeholder.valoracion.id_perseo',
  485.                     ],
  486.                 ]);
  487.         }
  488.         $form
  489.             ->add('fecha'DateTimePickerType::class, [
  490.                 'label' => false,
  491.                 'translation_domain' => 'operacionAdmin',
  492.                 //'disabled' => true,
  493.                 'format' => 'dd-MM-yyyy HH:mm',
  494.                 'data' => $object->getFecha() ? $object->getFecha() : $fecha,
  495.                 'attr' => [
  496.                     'readonly' => true,
  497.                     'placeholder' => 'form.operacion.placeholder.fecha',
  498.                 ],
  499.                 'row_attr' => [
  500.                     'class' => 'readonly',
  501.                 ]
  502.             ])
  503.             ->add('unidadNegocio'null, [
  504.                 'label' => false,
  505.                 'translation_domain' => 'operacionAdmin',
  506.                 //'disabled' => true,
  507.                 'placeholder' => 'form.operacion.placeholder.unidad_negocio',
  508.                 'data' => $object->getUnidadNegocio() ? $object->getUnidadNegocio() : $unidadNegocio,
  509.                 'choice_attr' => function ($val$key$index)
  510.                 {
  511.                     return $val?->getColor() ? [
  512.                         'data-color' => $val->getColor(),
  513.                         'style' => 'color: ' $val->getColor() . ';',
  514.                     ] : [];
  515.                 },
  516. //                'attr' => [
  517. //                    'readonly' => true,
  518. //                ],
  519.                 'row_attr' => [
  520.                     'class' => 'color-unidad-negocio',
  521.                 ]
  522.             ])
  523.             ->add('usuario'null, [
  524.                 'label' => false,
  525.                 'translation_domain' => 'operacionAdmin',
  526.                 //'disabled' => true,
  527.                 'placeholder' => 'form.operacion.placeholder.usuario',
  528.                 'data' => $object->getUsuario() ? $object->getUsuario() : $usuario,
  529.                 'attr' => [
  530.                     'readonly' => true,
  531.                 ],
  532.                 'row_attr' => [
  533.                     'class' => 'readonly',
  534.                 ]
  535.             ])
  536.             ->add('canal'ModelListType::class, [
  537.                 'label' => false,
  538.                 'attr' => [
  539.                     'data-max_length' => 15
  540.                 ],
  541.                 'row_attr' => [
  542.                     'class' => 'display-model-list-type create-display-none control-block-unblock-fields'
  543.                 ],
  544.                 'btn_delete' => false,
  545.             ], [
  546.                 'placeholder' => 'form.operacion.placeholder.canal',
  547.                 'link_parameters' => [
  548.                     'nav_prometeo' => true,
  549.                     'model_list_type' => 'canal',
  550.                     'action_create_not_list' => false,
  551.                 ]
  552.             ])
  553.             ->add('cliente'ModelListType::class, [
  554.                 'label' => false,
  555.                 'data_class' => null,//Cliente::class,
  556.                 'data' => $object->getId() ? $object->getCliente() : null,
  557.                 'attr' => [
  558.                     'data-max_length' => 24
  559.                 ],
  560.                 'row_attr' => [
  561.                     'class' => "display-model-list-type create-display-none $classAccessAdmin control-block-unblock-fields"
  562.                 ],
  563.                 'btn_delete' => false,
  564.             ], [
  565.                 'placeholder' => 'form.operacion.placeholder.cliente',
  566.                 'link_parameters' => [
  567.                     'nav_prometeo' => true,
  568.                     'model_list_type' => 'cliente',
  569.                     'action_create_not_list' => false,
  570.                 ]
  571.             ])
  572.             ->add('tipoCliente'null, [
  573.                 'label' => 'form.operacion.label.tipo_cliente',
  574.                 'translation_domain' => 'operacionAdmin',
  575.                 'row_attr' => [
  576.                     'class' => 'control-block-unblock-fields'
  577.                 ]
  578.             ])
  579.             ->add('exportacion'null, [
  580.                 'label' => 'form.operacion.label.exportacion',
  581.                 'translation_domain' => 'operacionAdmin',
  582.                 'row_attr' => [
  583.                     'class' => 'control-block-unblock-fields'
  584.                 ]
  585.             ])
  586.             ->add('comentario'null, [
  587.                 'label' => false,
  588.                 'translation_domain' => 'operacionAdmin',
  589.                 'attr' => [
  590.                     'placeholder' => 'form.operacion.placeholder.comentario'
  591.                 ],
  592.                 'row_attr' => [
  593.                     'class' => $object?->getComentario() ? 'more-info more-info-modal' 'more-info more-info-modal empty',
  594.                     'more_info_class' => 'more-info-input-wrap more-info-input-wrap-modal more-info-input-wrap-right',
  595.                 ],
  596.             ])
  597.             ->add('idioma'ChoiceType::class, [
  598.                 'label' => false,
  599.                 'translation_domain' => 'operacionAdmin',
  600.                 'placeholder' => 'form.operacion.placeholder.idioma',
  601.                 'choices' => array_flip(IdiomaEnum::getIdiomas()),
  602.                 'data' => $object->getIdioma() ? $object->getIdioma() : $idioma,
  603.                 'choice_label' => function ($choice$key$value) {
  604.                     return $this->getTranslator()->trans(IdiomaEnum::getIdioma($choice), [], 'enum');
  605.                 },
  606.             ])
  607.             ->end()
  608.             ->with('with_cliente', [
  609.                 'label' => false,
  610.                 'class' => 'col-md-12 with readonly'
  611.             ])
  612.                 ->add('cliente.razonSocial'null, [
  613.                     'label' => false,
  614.                     'mapped' => $mappedCliente,
  615.                     'disabled' => true,
  616.                     'translation_domain' => 'operacionAdmin',
  617.                     'attr' => [
  618.                         'placeholder' => 'form.operacion.placeholder.cliente.razon_social'
  619.                     ]
  620.                 ])
  621.                 ->add('cliente.identificacion'null, [
  622.                     'label' => false,
  623.                     'mapped' => $mappedCliente,
  624.                     'disabled' => true,
  625.                     'translation_domain' => 'operacionAdmin',
  626.                     'attr' => [
  627.                         'placeholder' => 'form.operacion.placeholder.cliente.identificacion'
  628.                     ]
  629.                 ])
  630.                 ->add('cliente.direccion'null, [
  631.                     'label' => false,
  632.                     'mapped' => $mappedCliente,
  633.                     'disabled' => true,
  634.                     'translation_domain' => 'operacionAdmin',
  635.                     'attr' => [
  636.                         'placeholder' => 'form.operacion.placeholder.cliente.direccion'
  637.                     ]
  638.                 ])
  639.                 ->add('cliente.cp'null, [
  640.                     'label' => false,
  641.                     'mapped' => $mappedCliente,
  642.                     'disabled' => true,
  643.                     'translation_domain' => 'operacionAdmin',
  644.                     'attr' => [
  645.                         'placeholder' => 'form.operacion.placeholder.cliente.cp'
  646.                     ]
  647.                 ])
  648.                 ->add('cliente.ciudad'null, [
  649.                     'label' => false,
  650.                     'mapped' => $mappedCliente,
  651.                     'disabled' => true,
  652.                     'translation_domain' => 'operacionAdmin',
  653.                     'attr' => [
  654.                         'placeholder' => 'form.operacion.placeholder.cliente.ciudad'
  655.                     ]
  656.                 ])
  657.                 ->add('cliente.provincia'EntityType::class, [
  658.                     'label' => false,
  659.                     'mapped' => $mappedCliente,
  660.                     'disabled' => true,
  661.                     'class' => Provincia::class,
  662.                     'placeholder' => 'form.operacion.placeholder.cliente.provincia'
  663.                 ])
  664.                 ->add('cliente.ccaa'EntityType::class, [
  665.                     'label' => false,
  666.                     'mapped' => $mappedCliente,
  667.                     'disabled' => true,
  668.                     'class' => CCAA::class,
  669.                     'placeholder' => 'form.operacion.placeholder.cliente.ccaa'
  670.                 ])
  671.                 ->add('cliente.pais'CountryType::class, [
  672.                     'label' => false,
  673.                     'mapped' => $mappedCliente,
  674.                     'disabled' => true,
  675.                     'placeholder' => 'form.operacion.placeholder.cliente.pais',
  676.                     'translation_domain' => 'operacionAdmin',
  677.                 ])
  678.                 ->add('cliente.telefono'null, [
  679.                     'label' => false,
  680.                     'mapped' => $mappedCliente,
  681.                     'disabled' => true,
  682.                     'translation_domain' => 'operacionAdmin',
  683.                     'attr' => [
  684.                         'placeholder' => 'form.operacion.placeholder.cliente.telefono'
  685.                     ]
  686.                 ])
  687.                 ->add('cliente.email'null, [
  688.                     'label' => false,
  689.                     'mapped' => $mappedCliente,
  690.                     'disabled' => true,
  691.                     'translation_domain' => 'operacionAdmin',
  692.                     'attr' => [
  693.                         'placeholder' => 'form.operacion.placeholder.cliente.email'
  694.                     ]
  695.                 ])
  696.                 ->add('cliente.entidadBancaria'null, [
  697.                     'label' => false,
  698.                     'mapped' => $mappedCliente,
  699.                     'disabled' => true,
  700.                     'translation_domain' => 'operacionAdmin',
  701.                     'attr' => [
  702.                         'placeholder' => 'form.operacion.placeholder.cliente.entidad_bancaria'
  703.                     ]
  704.                 ])
  705.                 ->add('cliente.iban'null, [
  706.                     'label' => false,
  707.                     'mapped' => $mappedCliente,
  708.                     'disabled' => true,
  709.                     'translation_domain' => 'operacionAdmin',
  710.                     'attr' => [
  711.                         'placeholder' => 'form.operacion.placeholder.cliente.iban'
  712.                     ]
  713.                 ])
  714.                 ->add('cliente.swift'null, [
  715.                     'label' => false,
  716.                     'mapped' => $mappedCliente,
  717.                     'disabled' => true,
  718.                     'translation_domain' => 'operacionAdmin',
  719.                     'attr' => [
  720.                         'placeholder' => 'form.operacion.placeholder.cliente.swift'
  721.                     ]
  722.                 ])
  723.                 ->add('cliente.identificacionFrontal'HTMLType::class, [
  724.                     'label' => false,
  725.                     'mapped' => false,//$mappedCliente,
  726.                     'translation_domain' => 'operacionAdmin',
  727.                     'attr' => [
  728.                         'placeholder' => 'form.operacion.placeholder.cliente.identificacion_frontal'
  729.                     ],
  730.                     'row_attr' => [
  731.                         'class' => 'no-block',
  732.                     ],
  733.                     'template' => 'admin/cliente/imagen.html.twig'
  734.                 ])
  735.                 ->add('cliente.identificacionTrasera'HTMLType::class, [
  736.                     'label' => false,
  737.                     'mapped' => false,//$mappedCliente,
  738.                     'translation_domain' => 'operacionAdmin',
  739.                     'attr' => [
  740.                         'placeholder' => 'form.operacion.placeholder.cliente.identificacion_trasera'
  741.                     ],
  742.                     'row_attr' => [
  743.                         'class' => 'no-block',
  744.                     ],
  745.                     'template' => 'admin/cliente/imagen.html.twig'
  746.                 ])
  747.             ->end()
  748.             ->with('with_resume', [
  749.                 'label' => false,
  750.                 'class' => $this->isReadonly() ? 'col-md-12 with readonly' 'col-md-12'
  751.             ])
  752.             ->add('fechaTramitacion'DatePickerType::class, [
  753.                 'label' => false,
  754.                 'translation_domain' => 'operacionAdmin',
  755.                 'format' => 'dd-MM-yyyy',
  756.                 'row_attr' => [
  757.                     'class' => "control-fechas-resumen $classNoBlockFechaEnTramitacion control-block-unblock-fields",
  758.                 ],
  759.                 'attr' => [
  760.                     'placeholder' => 'form.operacion.placeholder.fecha_tramitacion',
  761.                     'data-control_fecha_title' => null,
  762.                     'data-control_fecha_message' => null//$this->getTranslator()->trans('message.control.fecha.valoraciones_relojes.fecha_enviada', [], 'operacionAdmin'),
  763.                 ]
  764.             ])
  765.             ->add('fechaTramitada'DatePickerType::class, [
  766.                 'label' => false,
  767.                 'translation_domain' => 'operacionAdmin',
  768.                 'format' => 'dd-MM-yyyy',
  769.                 'row_attr' => [
  770.                     'class' => "control-fechas-resumen $classNoBlockFechaTramitada control-block-unblock-fields",// readonly',
  771.                     //'style' => 'pointer-events: none;'
  772.                 ],
  773.                 'attr' => [
  774.                     //'readonly' => true,
  775.                     'placeholder' => 'form.operacion.placeholder.fecha_tramitada',
  776.                 ]
  777.             ])
  778.             ->add('fechaConfirmada'DatePickerType::class, [
  779.                 'label' => false,
  780.                 'translation_domain' => 'operacionAdmin',
  781.                 'format' => 'dd-MM-yyyy',
  782.                 'row_attr' => [
  783.                     'class' => "control-fechas-resumen $classNoBlockFechaConfirmada"//readonly',
  784.                     //'style' => 'pointer-events: none;'
  785.                 ],
  786.                 'attr' => [
  787. //                    'readonly' => true,
  788.                     'placeholder' => 'form.operacion.placeholder.fecha_confirmada',
  789.                 ]
  790.             ])
  791.             ->add('fechaCancelada'DatePickerType::class, [
  792.                 'label' => false,
  793.                 'translation_domain' => 'operacionAdmin',
  794.                 'format' => 'dd-MM-yyyy',
  795.                 'disabled' => true,
  796.                 'datepicker_use_button' => false,
  797.                 'attr' => [
  798.                     'placeholder' => 'form.operacion.placeholder.fecha_cancelada',
  799.                     'class' => 'bolder text-canceled'
  800.                 ]
  801.             ])
  802.             ->add('tipo'null, [
  803.                 'label' => false,
  804.                 'translation_domain' => 'operacionAdmin',
  805.                 'attr' => [
  806.                     'readonly' => true,
  807.                     'placeholder' => 'form.operacion.placeholder.tipo',
  808.                     'class' => 'bolder'
  809.                 ],
  810.             ])
  811.         ;
  812.         /*if($object->getEstado()?->getKey() !== EstadoOperacionEnum::ESTADO_EN_TRAMITACION &&
  813.             ($object->getTipo() === TipoOperacionEnum::OPERACION_COMPRA || $object->getTipo() === TipoOperacionEnum::OPERACION_PERMUTA)
  814.         ) {
  815.             $form
  816.                 ->add('contractSignedFile', VichFileType::class, [
  817.                     'label' => false,
  818.                     'translation_domain' => 'operacionAdmin',
  819.                     'required' => false,
  820.                     'allow_delete' => true,
  821.                     'download_uri' => true,
  822.                     'download_label' => 'label.download.contract_signed',
  823.                     'attr' => [
  824.                         'data-translation_domain' => 'operacionAdmin',
  825.                         'data-upload_label' => 'label.upload.contract_signed',
  826.                         'data-selector_file_original' => 'contractSigned',
  827.                         'data-title_file_delete' => null,
  828.                         'data-message_file_delete' => null,
  829.                         'class' => 'vich-file-load',
  830.                     ],
  831.                     'row_attr' => [
  832.                         'class' => (
  833.                             $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_EN_TRAMITACION ||
  834.                             $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_ASENTADA ||
  835.                             $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_CANCELADA) ? 'block' : 'no-block',
  836.                     ]
  837.                 ]);
  838.         }*/
  839.         $form
  840.             ->add('precioPagar'null, [
  841.                 'label' => false,
  842.                 'translation_domain' => 'operacionAdmin',
  843.                 'attr' => [
  844.                     'readonly' => true,
  845.                     'placeholder' => 'form.operacion.placeholder.precio_pagar',
  846.                     'class' => 'numeric currencies'
  847.                 ]
  848.             ])
  849.             ->add('scriptCalcularPrecioPagar'ScriptType::class, [
  850.                 'template' => 'SCRIPTS/Operacion/calcular_precio_pagar.html.twig'
  851.             ])
  852.             ->end()
  853.         ;
  854.         if ($object->getTipo() === TipoOperacionEnum::OPERACION_COMPRA || $object->getTipo() === TipoOperacionEnum::OPERACION_PERMUTA || $object->getTipo() === TipoOperacionEnum::OPERACION_GESTION) {
  855.             $form
  856.                 ->with('with_comerzia', [
  857.                     'label' => false,
  858.                     'class' => $this->isReadonly() ? 'col-md-12 with readonly' 'col-md-12'
  859.                 ])
  860.                 ->add('intercambio'null, [
  861.                     'label' => false,
  862.                     'placeholder' => 'form.operacion.placeholder.intercambio',
  863.                     'translation_domain' => 'operacionAdmin',
  864.                     'attr' => [
  865.                         'class' => 'control-select-option-active'
  866.                     ],
  867.                     'query_builder' => $this->em->getRepository(Intercambio::class)->qbIntercambioContratoIdioma($object->getTipo(), $object->getIdioma()),
  868.                     'choice_attr' => function ($choicestring $keymixed $value) {
  869.                         return [
  870.                             'readonly' => !$choice->isActive(),
  871.                             //      'title' => $choice->getEmail(),
  872.                         ];
  873.                     },
  874.                 ])
  875.                 ->add('firmante'Select2EntityType::class, [
  876.                     'label' => false,
  877.                     'placeholder' => 'form.operacion.placeholder.firmante',
  878.                     'translation_domain' => 'operacionAdmin',
  879.                     'class' => Firmante::class,
  880.                     'remote_route' => 'admin_app_firmante_getFirmantesByTipoIdioma',
  881.                     'remote_params' => [
  882.                         'idioma' => $object->getIdioma(),
  883.                         'tipo' => $object->getTipo(),
  884.                         'empresa' => $object->getUnidadNegocio()?->getEmpresa()?->getId()
  885.                     ],
  886.                     'multiple' => false,
  887.                     'scroll' => true,
  888.                     'data_class' => null,
  889.                     'minimum_input_length' => 0,
  890.                     'page_limit' => 30,
  891.                     'delay' => 250,
  892.                     'cache' => true,
  893.                     'allow_clear' => false,
  894.                     'attr' => [
  895.                         'class' => 'control-select-option-active',
  896.                         'data-parent' => 'idioma'
  897.                     ],
  898.                     //'query_builder' => $this->em->getRepository(Firmante::class)->qbFirmanteTipoIdioma($object->getTipo(), $object->getIdioma()),
  899.                     /*'choice_attr' => function ($choice, string $key, mixed $value) {
  900.                         return [
  901.                             'readonly' => !$choice->isActive(),
  902.                             //      'title' => $choice->getEmail(),
  903.                         ];
  904.                     },*/
  905.                 ])
  906.                 ->add('banco'null, [
  907.                     'label' => false,
  908.                     'placeholder' => 'form.operacion.placeholder.banco',
  909.                     'translation_domain' => 'operacionAdmin',
  910.                 ])
  911.                 ->add('comentarioContrato'null, [
  912.                     'label' => false,
  913.                     'translation_domain' => 'operacionAdmin',
  914.                     'attr' => [
  915.                         'placeholder' => 'form.operacion.placeholder.comentario_contrato'
  916.                     ]
  917.                 ])
  918.                 ->end();
  919.         }
  920.         //if($compras?->count()) {
  921.         $operacionStatus $object->getEstado()?->getKey();
  922.         $classUnblockBlock '';// $operacionStatus === EstadoOperacionEnum::ESTADO_TRAMITADA ? 'active-unblock-block' : '';
  923.         $classOperacionStatus $operacionStatus mb_strtolower("status-$operacionStatus") : '';
  924.         if($object->getTipo() !== TipoOperacionEnum::OPERACION_VENTA) {
  925.             $form
  926.                 ->with('with_detalle_compra', [
  927.                     'label' => false,
  928.                     'class' => "col-md-12 with $classUnblockBlock $classOperacionStatus $classOperacionExportacion " . ($this->isReadonly() || $object->isCompraGestion() ? 'readonly' '')
  929.                 ])
  930.                 ->add('compra.detalle'CollectionType::class, [
  931.                     'label' => false,
  932.                     'row_attr' => [
  933.                         'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.compra_detalle',
  934.                             [], 'operacionAdmin'),
  935.                         'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.compra_detalle',
  936.                             [], 'operacionAdmin'),
  937.                     ],
  938.                     'by_reference' => false,
  939.                     'btn_add' => $this->security->isGranted('ROLE_SUPER_ADMIN') || $object->isCompraGestion() ? 'link_add_operacion_compra_detalle' null,
  940.                     'type_options' => [
  941.                         'delete' => !$object->isCompraGestion() && $operacionStatus === EstadoOperacionEnum::ESTADO_EN_TRAMITACION && $this->security->isGranted('ROLE_SUPER_ADMIN')
  942.                     ],
  943.                 ], [
  944.                     'edit' => 'inline',
  945.                     'inline' => 'table',
  946.                     'attr' => [
  947.                         'class' => "table-operacion-compra-detalle table-view-card table-operacion-compra-detalle-view-card table-view-multiple-card $classGestionVentaMoreInfo"
  948.                     ],
  949.                     'admin_code' => 'admin.detalle_compra',
  950.                 ]);
  951.             if (!$object->isCompraGestion()) {
  952.                 $form
  953.                     ->add('scriptControlFechaVerificacion'ScriptType::class, [
  954.                         'template' => 'SCRIPTS/Operacion/control_fecha_verificacion.html.twig'
  955.                     ]);
  956.             }
  957.             if ($object->getTipo() === TipoOperacionEnum::OPERACION_GESTION) {
  958.                 $form
  959.                     ->add('scriptCancelarReloj'ScriptType::class, [
  960.                         'template' => 'SCRIPTS/Operacion/cancelar_reloj.html.twig'
  961.                     ]);
  962.             }
  963.             $form
  964.                 ->add('scriptControlRegimen'ScriptType::class, [
  965.                     'template' => 'SCRIPTS/Operacion/control_regimen.html.twig'
  966.                 ])
  967.                 ->add('scriptControlCosteImportacion'ScriptType::class, [
  968.                     'template' => 'SCRIPTS/Operacion/control_coste_importacion.html.twig'
  969.                 ])
  970.                 ->end();
  971.         }
  972.         //}
  973.        // if($venta->count()/* || !$object->getId()*/) {
  974.         if($object->getTipo() !== TipoOperacionEnum::OPERACION_GESTION && !$object->isCompraGestion()) {
  975.             $form
  976.                 ->with('with_detalle_venta', [
  977.                     'label' => false,
  978.                     'class' => $this->isReadonly() ? "col-md-12 with readonly $classOperacionStatus"col-md-12 $classOperacionStatus"
  979.                 ])
  980.                 ->add('venta.detalle'CollectionType::class, [
  981.                     'label' => false,
  982.                     'row_attr' => [
  983.                         'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.venta_detalle',
  984.                             [], 'operacionAdmin'),
  985.                         'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.venta_detalle',
  986.                             [], 'operacionAdmin'),
  987.                     ],
  988.                     'by_reference' => false,
  989.                     'btn_add' => $this->security->isGranted('ROLE_SUPER_ADMIN') ? 'link_add_operacion_venta_detalle' null,
  990.                     'type_options' => [
  991.                         'delete' => $operacionStatus === EstadoOperacionEnum::ESTADO_EN_TRAMITACION && $this->security->isGranted('ROLE_SUPER_ADMIN')
  992.                     ],
  993.                 ], [
  994.                     'edit' => 'inline',
  995.                     'inline' => 'table',
  996.                     'attr' => [
  997.                         'class' => 'table-operacion-venta-detalle table-view-card table-operacion-venta-detalle-view-card table-view-multiple-card'
  998.                     ],
  999.                     'admin_code' => 'admin.detalle_venta',
  1000.                 ])
  1001.                 ->add('scriptEventOnChange'ScriptType::class, [
  1002.                     'template' => 'SCRIPTS/DetalleVenta/reloj_event_on_change.html.twig'
  1003.                 ])
  1004.                 ->add('scriptControlFechaEnvio'ScriptType::class, [
  1005.                     'template' => 'SCRIPTS/Operacion/control_fecha_envio.html.twig'
  1006.                 ])
  1007.                 ->end();
  1008.             if (($object->getTipo() === TipoOperacionEnum::OPERACION_VENTA || $object->getTipo() === TipoOperacionEnum::OPERACION_PERMUTA/*&&
  1009.                 $object->getEstado()?->getKey() !== EstadoOperacionEnum::ESTADO_EN_TRAMITACION*/
  1010.             ) {
  1011.                 $classReadonly in_array$object->getEstado()?->getKey(), [EstadoOperacionEnum::ESTADO_EN_TRAMITACIONEstadoOperacionEnum::ESTADO_TRAMITADA] ) ? '' 'readonly';
  1012.                 $form
  1013.                     ->with('with_info_envio', [
  1014.                         'label' => false,
  1015.                         'class' => "col-md-12 with $classReadonly"
  1016.                     ])
  1017.                     ->add('venta.destinatario'null, [
  1018.                         'label' => false,
  1019.                         'translation_domain' => 'operacionAdmin',
  1020.                         'attr' => [
  1021.                             'placeholder' => 'form.operacion.placeholder.venta.destinatario'
  1022.                         ],
  1023.                         'data' => $updateDataInfoSend $object->getCliente()?->getRazonSocial() : $object->getVenta()->getDestinatario(),
  1024.                     ])
  1025.                     ->add('venta.destinatarioEmpresa'null, [
  1026.                         'label' => false,
  1027.                         'translation_domain' => 'operacionAdmin',
  1028.                         'attr' => [
  1029.                             'placeholder' => 'form.operacion.placeholder.venta.destinatario_empresa'
  1030.                         ]
  1031.                     ])
  1032.                     ->add('venta.direccionEnvioDireccion1'null, [
  1033.                         'label' => false,
  1034.                         'translation_domain' => 'operacionAdmin',
  1035.                         'attr' => [
  1036.                             'placeholder' => 'form.operacion.placeholder.venta.direccion_envio_direccion_1'
  1037.                         ],
  1038.                         'data' => $updateDataInfoSend $object->getCliente()?->getDireccion() : $object->getVenta()->getDireccionEnvioDireccion1(),
  1039.                     ])
  1040.                     ->add('venta.direccionEnvioDireccion2'null, [
  1041.                         'label' => false,
  1042.                         'translation_domain' => 'operacionAdmin',
  1043.                         'attr' => [
  1044.                             'placeholder' => 'form.operacion.placeholder.venta.direccion_envio_direccion_2'
  1045.                         ]
  1046.                     ])
  1047.                     ->add('venta.direccionEnvioCp'null, [
  1048.                         'label' => false,
  1049.                         'translation_domain' => 'operacionAdmin',
  1050.                         'attr' => [
  1051.                             'placeholder' => 'form.operacion.placeholder.venta.direccion_envio_cp'
  1052.                         ],
  1053.                         'data' => $updateDataInfoSend $object->getCliente()?->getCp() : $object->getVenta()->getDireccionEnvioCp(),
  1054.                     ])
  1055.                     ->add('venta.direccionEnvioCiudad'null, [
  1056.                         'label' => false,
  1057.                         'translation_domain' => 'operacionAdmin',
  1058.                         'attr' => [
  1059.                             'placeholder' => 'form.operacion.placeholder.venta.direccion_envio_ciudad'
  1060.                         ],
  1061.                         'data' => $updateDataInfoSend $object->getCliente()?->getCiudad() : $object->getVenta()->getDireccionEnvioCiudad(),
  1062.                     ])
  1063.                     ->add('venta.direccionEnvioRegion'null, [
  1064.                         'label' => false,
  1065.                         'translation_domain' => 'operacionAdmin',
  1066.                         'attr' => [
  1067.                             'placeholder' => 'form.operacion.placeholder.venta.direccion_envio_region'
  1068.                         ],
  1069.                         'data' => $updateDataInfoSend $object->getCliente()?->getRegion() : $object->getVenta()->getDireccionEnvioRegion(),
  1070.                     ])
  1071.                     ->add('venta.direccionEnvioPais'CountryType::class, [
  1072.                         'label' => false,
  1073.                         'translation_domain' => 'operacionAdmin',
  1074.                         'placeholder' => 'form.operacion.placeholder.venta.direccion_envio_pais',
  1075.                         'data' => $updateDataInfoSend $object->getCliente()?->getPais() : $object->getVenta()->getDireccionEnvioPais(),
  1076.                     ])
  1077.                     ->add('btn_copy_data_client'HTMLType::class, [
  1078.                         'label' => false,
  1079.                         'template' => 'admin/operacion/btn_copy_data_client.html.twig'
  1080.                     ])
  1081.                     ->end();
  1082.             }
  1083.         }
  1084.         //}
  1085. //            ->add('valoracionesRelojesSinStocks', CollectionType::class, [
  1086. //                'label' => false,
  1087. //                'row_attr' => [
  1088. //                    'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.valoraciones_relojes'),
  1089. ////                    'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.valoraciones_relojes'),
  1090. //                ],
  1091. //                'by_reference' => false,
  1092. //                'btn_add' => 'link_add_valoraciones_relojes_sin_stocks'
  1093. //            ], [
  1094. //                'edit' => 'inline',
  1095. //                'inline' => 'table',
  1096. //                'attr' => [
  1097. //                    'class' => 'table-valoraciones-relojes-sin-stocks table-view-card table-valoraciones-relojes-sin-stocks-view-card table-view-multiple-card'
  1098. //                ],
  1099. //                'admin_code' => 'admin.valoraciones_relojes_sin_stock',
  1100. //            ]);
  1101. //
  1102. //        if (!$this->isHidden()) {
  1103. //            $form
  1104. //                ->add('scriptDeleteImagen', ScriptType::class, [
  1105. //                    'template' => 'SCRIPTS/ValoracionesRelojesSinStock/delete_imagen.html.twig'
  1106. //                ])
  1107. //                ->add('scriptCalcularMargenPromocion', ScriptType::class, [
  1108. //                    'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_margen_promocion.html.twig'
  1109. //                ])
  1110. //                ->add('scriptCalcularMargenMinimo', ScriptType::class, [
  1111. //                    'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_margen_minimo.html.twig'
  1112. //                ])
  1113. //                ->add('scriptCalcularPrecioCosteTotal', ScriptType::class, [
  1114. //                    'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_precio_oferta.html.twig'
  1115. //                ])
  1116. //                ->add('scriptCalcularCostesEventOnChangePrecio', ScriptType::class, [
  1117. //                    'template' => 'SCRIPTS/ValoracionesRelojesSinStock/calcular_costes_event_on_change_precio.html.twig'
  1118. //                ])
  1119. //                ->add('scriptControlPrecioReferencia', ScriptType::class, [
  1120. //                    'template' => 'SCRIPTS/ValoracionesRelojesSinStock/control_precio_referencia.html.twig'
  1121. //                ])
  1122. //                ->add('scriptControlCostesTotal', ScriptType::class, [
  1123. //                    'template' => 'SCRIPTS/ValoracionesRelojesSinStock/control_costes_total.html.twig'
  1124. //                ]);
  1125. //        }
  1126. //
  1127. //        $form
  1128. //            ->add('valoracionesRelojesStocks', CollectionType::class, [
  1129. //                'label' => false,
  1130. //                'row_attr' => [
  1131. //                    'class' => 'hide',
  1132. //                    'data-title_modal_record_delete' => $this->getTranslator()->trans('title.modal.record.delete.valoraciones_relojes'),
  1133. //                    'data-message_modal_record_delete' => $this->getTranslator()->trans('message.modal.record.delete.valoraciones_relojes'),
  1134. //                ],
  1135. //                'by_reference' => false,
  1136. //                'btn_add' => 'link_add_valoraciones_relojes_stocks'
  1137. //            ], [
  1138. //                'edit' => 'inline',
  1139. //                'inline' => 'table',
  1140. //                'attr' => [
  1141. //                    'class' => 'table-valoraciones-relojes-stocks table-view-card table-valoraciones-relojes-stocks-view-card table-view-multiple-card table-view-carousel'
  1142. //                ],
  1143. //                'admin_code' => 'admin.valoraciones_relojes_stock',
  1144. //            ])
  1145. //            ->end()
  1146. //            ->with('with_resumen', [
  1147. //                'label' => false
  1148. //            ])
  1149. //            ->add('fechaEnviada', DatePickerType::class, [
  1150. //                'label' => false,
  1151. //                'placeholder' => 'form.operacion.placeholder.fecha_enviada',
  1152. //                'format' => 'dd-MM-yyyy',
  1153. //                'row_attr' => [
  1154. //                    'class' => 'control-fechas-resumen',
  1155. //                ],
  1156. //                'attr' => [
  1157. //                    'placeholder' => 'form.operacion.placeholder.fecha_enviada',
  1158. //                    'data-control_fecha_title' => null,
  1159. //                    'data-control_fecha_message' => $this->getTranslator()->trans('message.control.fecha.valoraciones_relojes.fecha_enviada'),
  1160. //                ]
  1161. //            ])
  1162. //            ->add('fechaAceptacion', DatePickerType::class, [
  1163. //                'label' => false,
  1164. //                'placeholder' => 'form.operacion.placeholder.fecha_aceptacion',
  1165. //                'format' => 'dd-MM-yyyy',
  1166. //                'row_attr' => [
  1167. //                    'class' => 'control-fechas-resumen readonly',
  1168. //                    //'style' => 'pointer-events: none;'
  1169. //                ],
  1170. //                'attr' => [
  1171. //                    'readonly' => true,
  1172. //                    'placeholder' => 'form.operacion.placeholder.fecha_aceptacion',
  1173. //                ]
  1174. //            ])
  1175. //            ->add('fechaRechazo', DatePickerType::class, [
  1176. //                'label' => false,
  1177. //                'placeholder' => 'form.operacion.placeholder.fecha_rechazo',
  1178. //                'format' => 'dd-MM-yyyy',
  1179. //                'row_attr' => [
  1180. //                    'class' => 'control-fechas-resumen readonly',
  1181. //                    //'style' => 'pointer-events: none;'
  1182. //                ],
  1183. //                'attr' => [
  1184. //                    'readonly' => true,
  1185. //                    'placeholder' => 'form.operacion.placeholder.fecha_rechazo',
  1186. //                ]
  1187. //            ])
  1188. //            ->add('fechaTramitacion', TextType::class, [
  1189. //                'label' => false,
  1190. //                'data' => $object->getFechaTramitacion()?->format('d-m-Y'),
  1191. //                'attr' => [
  1192. //                    'readonly' => true,
  1193. //                    'placeholder' => 'form.operacion.placeholder.fecha_tramitacion',
  1194. //                ]
  1195. //            ])
  1196. //            ->add('infoTramitacion', null, [
  1197. //                'label' => false,
  1198. //                'attr' => [
  1199. //                    'placeholder' => 'form.operacion.placeholder.info_tramitacion'
  1200. //                ],
  1201. //                'row_attr' => [
  1202. //                    'class' => 'more-info',
  1203. //                    'more_info_class' => 'more-info-input-wrap more-info-input-wrap-modal more-info-input-wrap-right',
  1204. //                ]
  1205. //            ])
  1206. //            ->add('precioPagar', null, [
  1207. //                'label' => false,
  1208. //                'attr' => [
  1209. //                    'readonly' => true,
  1210. //                    'placeholder' => 'form.operacion.placeholder.precio_pagar',
  1211. //                    'class' => 'numeric currencies'
  1212. //                ]
  1213. //            ])
  1214. //            ->add('scriptCalcularPrecioPagar', ScriptType::class, [
  1215. //                'template' => 'SCRIPTS/Valoracion/calcular_precio_pagar.html.twig'
  1216. //            ])
  1217. //            ->add('scriptRecalculosDeleteCollections', ScriptType::class, [
  1218. //                'template' => 'SCRIPTS/Valoracion/recalculos_delete_collections.html.twig'
  1219. //            ])
  1220. //            ->add('scriptControlFechasResumen', ScriptType::class, [
  1221. //                'template' => 'SCRIPTS/Valoracion/control_fechas_resumen.html.twig'
  1222. //            ])
  1223. //            ->end();
  1224.     }
  1225.     protected function configureShowFields(ShowMapper $show): void
  1226.     {
  1227.         $show
  1228.         ;
  1229.     }
  1230.     private function isReadonly()
  1231.     {
  1232.         $object $this->getSubject();
  1233.         return
  1234.             $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_CANCELADA ||
  1235. //            $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_TRAMITADA ||
  1236.             $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_ASENTADA ||
  1237.             $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_CONFIRMADA ||
  1238.             $object->getEstado()?->getKey() === EstadoOperacionEnum::ESTADO_FINALIZADA
  1239.         ;
  1240.     }
  1241.     private function isUpdateDataInfoSend(): bool
  1242.     {
  1243.         $venta $this->getSubject()?->getVenta();
  1244.         return (!$venta->getDestinatario() && !$venta->getDestinatarioEmpresa() && !$venta->getDireccionEnvioDireccion1() &&
  1245.             !$venta->getDireccionEnvioDireccion2() && !$venta->getDireccionEnvioCp() && !$venta->getDireccionEnvioCiudad() &&
  1246.             !$venta->getDireccionEnvioRegion() && !$venta->getDireccionEnvioPais()) &&
  1247.             in_array($this->getSubject()->getEstado()?->getKey(), [ EstadoOperacionEnum::ESTADO_EN_TRAMITACIONEstadoOperacionEnum::ESTADO_TRAMITADA]);
  1248.     }
  1249.     protected function preUpdate(object $object): void
  1250.     {
  1251.         parent::preUpdate($object);
  1252.         $detallesCompra $object->getCompra()?->getDetalle() ?? [];
  1253.         foreach ($detallesCompra as $detalle)
  1254.         {
  1255.             $reloj $detalle->getReloj();
  1256.             if(!$reloj) continue;
  1257.             $this->actualizarPrecioCompraRelojCommandHandler->__invoke(new ActualizarPrecioCompraRelojCommand(new RelojPrecioCompraDTO($reloj->getId(), $detalle->getPrecioCoste())));
  1258.         }
  1259.     }
  1260. }