src/Controller/Mantenimiento/PedidoReparacionController.php line 237

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Mantenimiento;
  3. use App\Entity\Equipos\Maquinaria;
  4. use App\Entity\Mantenimiento\Departamento;
  5. use App\Entity\Mantenimiento\PedidoReparacion;
  6. use App\Entity\Mantenimiento\SectorPlanta;
  7. use App\Entity\Mantenimiento\SolicitantePedidoReparacion;
  8. use App\Form\Mantenimiento\PedidoReparacionType;
  9. use App\Repository\Mantenimiento\PedidoReparacionRepository;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Doctrine\ORM\EntityRepository;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  17. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  18. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  19. use Symfony\Component\Form\Extension\Core\Type\DateType;
  20. use Symfony\Component\Validator\Constraints\NotNull;
  21. use Knp\Snappy\Pdf;
  22. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  23. use Twig\Environment;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  25. use Symfony\Component\Form\FormError;
  26. use Symfony\Component\HttpFoundation\JsonResponse;
  27. /**
  28.  * @Route("/pedido/reparacion")
  29.  * @Security("is_granted('ROLE_INGRESO_ANOMALIAS') or is_granted('ROLE_CALIDAD')")
  30.  */
  31. class PedidoReparacionController extends AbstractController
  32. {
  33.     private $twig;
  34.     private $pdf;
  35.     public function __construct(Environment $twigPdf $pdf)
  36.     {
  37.         $this->twig $twig;
  38.         $this->pdf $pdf;
  39.     }
  40.     /**
  41.      * @Route("/", name="app_mantenimiento_pedido_reparacion_index", methods={"GET", "POST"})
  42.      */
  43.     public function index(Request $requestPedidoReparacionRepository $pedidoReparacionRepository): Response
  44.     {
  45.         $form $this->formFilterTreas();
  46.         if ($request->isMethod('POST')) 
  47.         {
  48.             $form->handleRequest($request);
  49.  
  50.             $data $form->getData();
  51.             return $this->render('mantenimiento/pedido_reparacion/index.html.twig', [
  52.                 'pedido_reparacions' => $pedidoReparacionRepository->pedidosReparacionUsuarioWithParameters($this->getUser(), $data),
  53.                 'form' => $form->createView()
  54.             ]);
  55.             
  56.         }
  57.         return $this->render('mantenimiento/pedido_reparacion/index.html.twig', [
  58.             'pedido_reparacions' => $pedidoReparacionRepository->pedidosReparacionUsuario($this->getUser()),
  59.             'form' => $form->createView()
  60.         ]);
  61.     }
  62.    /**
  63.      * @Route("/informe/tareas/from/{from}/to/{to}/sector/{sector}/depto/{dpto}/state/{state}/export", name="app_mantenimiento_pedido_reparacion_informe_tareas_export", methods={"GET", "POST"})
  64.      */
  65.     public function eportarInformeSenasa($from$to$sector$dpto$stateRequest $requestPedidoReparacionRepository $pedidoReparacionRepository, \Doctrine\ORM\EntityManagerInterface $entityManager): Response
  66.     {
  67.         $data = [
  68.             'desde' => (new \DateTime())->setTimestamp($from),
  69.             'hasta' => (new \DateTime())->setTimestamp($to),
  70.             'sector' => $sector == 'all' null $entityManager->getRepository(SectorPlanta::class)->find($sector),
  71.             'departamento' => $dpto == 'all' null $entityManager->getRepository(Departamento::class)->find($dpto),
  72.             'estado' => $state
  73.         ];
  74.        /* $pendientes = $pedidoReparacionRepository->pedidosReparacionUsuarioWithParametersAllPendiente($data);
  75.         $realizadosDiagramados =  $pedidoReparacionRepository->pedidosReparacionUsuarioWithParametersAll($data);
  76.         $pedido_reparacions = array_merge($pendientes, $realizadosDiagramados);
  77.         usort($pedido_reparacions, function($a, $b) {
  78.             return $a['fechaPedido'] <=> $b['fechaPedido'];
  79.         });*/
  80.         $pedido_reparacions $this->getPedidosFiltrados($data$pedidoReparacionRepository);
  81.         if ($data['estado'] != 'all'
  82.         {
  83.             $filtrados array_filter($pedido_reparacions, function($item) use ($data) {
  84.                                                                 return $item['estado'] === $data['estado'];
  85.                                                             });
  86.         }
  87.         $html $this->twig->render('mantenimiento/diagrama_tarea/pedidos.html.twig', [ 
  88.             'pedido_reparacions' => $filtrados ?? $pedido_reparacions,
  89.             'data' => $data
  90.         ]);
  91.         $filename sprintf('informe_pedidos_reparacion_%s_%s'$data['desde']->format('d_m_Y'), $data['hasta']->format('d_m_Y'));
  92.         return new PdfResponse(
  93.             $this->pdf->getOutputFromHtml($html, [
  94.                 'margin-top'    => 10,
  95.                 'margin-right'  => 10,
  96.                 'margin-bottom' => 10,
  97.                 'margin-left'   => 10,
  98.                 'encoding'      => 'utf-8',
  99.                 'page-size'     => 'A4',
  100.                 'orientation'   => 'Landscape',
  101.             ]),
  102.             $filename '.pdf'
  103.         );
  104.     }
  105.     private function getPedidosFiltrados($dataPedidoReparacionRepository $pedidoReparacionRepository)
  106.     {
  107.         $pendientes $pedidoReparacionRepository->getAllPedidosWithParameter($data);
  108.         $detalle = array();
  109.         foreach ($pendientes as $pedido
  110.         {
  111.             $id $pedido->getId();
  112.             $detalle[$id] = [
  113.                                 'detalle' => $pedido->getDetalle(),
  114.                                 'sector' => $pedido->getSector() ? $pedido->getSector()->getNombre() : '',
  115.                                 'departamento' => $pedido->getDepartamento() ? $pedido->getDepartamento()->getNombre() : '',
  116.                                 'fechaPedido' => $pedido->getFecha(),
  117.                                 'estado' => 'pen',
  118.                                 'diagramado' => 0,
  119.                                 'observaciones' => ''                      
  120.                             ];
  121.                 foreach ($pedido->getPedidosDiagramados() as $pedidoDiagramado
  122.                 {
  123.                     $diagrama $pedidoDiagramado->getDiagrama();
  124.                     if (!isset($detalle[$id]['realizada'])) //No se ha seteado el campo de realizada 
  125.                     {
  126.                         if ($diagrama->isProcesado())
  127.                         {
  128.                             $detalle[$id]['realizada'] = $pedidoDiagramado->isRealizada();
  129.                             if (!$pedidoDiagramado->isRealizada())
  130.                             {
  131.                                 unset($detalle[$id]['realizada']);
  132.                             }
  133.                                 
  134.                             $detalle[$id]['fecha'] = $diagrama->getFecha();
  135.                             $detalle[$id]['fechaDiagrama'] = $diagrama->getFecha();
  136.                             $detalle[$id]['estado'] = $pedidoDiagramado->isRealizada() ? 'rea' 'pen';
  137.                             $detalle[$id]['observaciones'] = $pedidoDiagramado->getObservacionReparacion();
  138.                         }
  139.                         else
  140.                         {
  141.                             $detalle[$id]['realizada'] = 0;
  142.                             $detalle[$id]['fechaDiagrama'] = $diagrama->getFecha();
  143.                             $detalle[$id]['estado'] = 'pen'//'pro';
  144.                             $detalle[$id]['estado'] = 'pen';
  145.                             $detalle[$id]['diagramado'] = 1;
  146.                         }                       
  147.                     }
  148.                     else
  149.                     {
  150.                         if ($detalle[$id]['realizada'] == 0//Si no se ha realizado
  151.                         {
  152.                             if ($diagrama->isProcesado())
  153.                             {
  154.                                 if ($pedidoDiagramado->isRealizada())
  155.                                 {
  156.                                     $detalle[$id]['realizada'] = $pedidoDiagramado->isRealizada();
  157.                                     $detalle[$id]['fecha'] = $diagrama->getFecha();
  158.                                     $detalle[$id]['fechaDiagrama'] = $diagrama->getFecha();
  159.                                     $detalle[$id]['estado'] = 'rea';
  160.                                     $detalle[$id]['observaciones'] = $pedidoDiagramado->getObservacionReparacion();
  161.                                 }
  162.                                 else
  163.                                 {
  164.                                     unset($detalle[$id]['realizada']);
  165.                                     $detalle[$id]['fecha'] = $diagrama->getFecha();
  166.                                     $detalle[$id]['fechaDiagrama'] = $diagrama->getFecha();
  167.                                     $detalle[$id]['estado'] = 'pen';    
  168.                                 }
  169.                             }
  170.                             else
  171.                             {
  172.                                 $detalle[$id]['realizada'] = 0;
  173.                                 $detalle[$id]['fechaDiagrama'] = $diagrama->getFecha();
  174.                                 $detalle[$id]['estado'] =  'pen'//'pro';
  175.                                 $detalle[$id]['estado'] = 'pen';
  176.                                 $detalle[$id]['diagramado'] = 1;
  177.                             }
  178.                         }
  179.                         
  180.                     }
  181.                 }
  182.             
  183.         }
  184.    
  185.         return $detalle;
  186.     }
  187.    /**
  188.      * @Route("/informe/tareas", name="app_mantenimiento_pedido_reparacion_informe_tareas", methods={"GET", "POST"})
  189.      */
  190.     public function informeSenasa(Request $requestPedidoReparacionRepository $pedidoReparacionRepository): Response
  191.     {
  192.         $form $this->formFilterInformes();
  193.         if ($request->isMethod('POST')) 
  194.         {
  195.             $form->handleRequest($request);
  196.             
  197.             if ($form->isValid()) 
  198.             {
  199.                 $data $form->getData();
  200.                 $url $this->generateUrl('app_mantenimiento_pedido_reparacion_informe_tareas_export', [
  201.                     'from' => $data['desde']->getTimestamp(),
  202.                     'to' => $data['hasta']->getTimestamp(),
  203.                     'sector' => $data['sector'] ? $data['sector']->getId() : 'all',
  204.                     'dpto' => $data['departamento'] ? $data['departamento']->getId() : 'all',
  205.                     'state' => $data['estado']
  206.                 ], 0);
  207.   
  208.              /*   $pendientes = $realizadosDiagramados = [];
  209.                 if ($data['estado'] == 'pen') 
  210.                 {
  211.                      //Representa todos los pedido de reparacion que no esten ni diagramados 
  212.                     $pendientes = $pedidoReparacionRepository->pedidosReparacionUsuarioWithParametersAllPendiente($data);
  213.                 }
  214.                 else
  215.                 {
  216.                    $realizadosDiagramados =  $pedidoReparacionRepository->pedidosReparacionUsuarioWithParametersAll($data);
  217.                    if ($data['estado'] == 'all') 
  218.                    {
  219.                         $pendientes = $pedidoReparacionRepository->pedidosReparacionUsuarioWithParametersAllPendiente($data);
  220.                    }
  221.                    
  222.                 }*/
  223.                 $pedido_reparacions $this->getPedidosFiltrados($data$pedidoReparacionRepository);
  224.                 if ($data['estado'] != 'all'
  225.                 {
  226.                     $filtrados array_filter($pedido_reparacions, function($item) use ($data) {
  227.                                                                         return $item['estado'] === $data['estado'];
  228.                                                                     });
  229.                 }
  230.                 //dd($pedido_reparacions);
  231.               //  $pedido_reparacions = array_merge($pendientes, $realizadosDiagramados);
  232.                 return $this->render('mantenimiento/pedido_reparacion/informe.html.twig', [
  233.                     'pedido_reparacions' => $filtrados ?? $pedido_reparacions,
  234.                     'form' => $form->createView(),  
  235.                     'url' => $url
  236.                 ]);
  237.             }
  238.             
  239.         }
  240.         return $this->render('mantenimiento/pedido_reparacion/informe.html.twig', [
  241.             'form' => $form->createView()
  242.         ]);
  243.     }
  244.     private function formFilterInformes()
  245.     {
  246.         $user $this->getUser();
  247.         $form $this->createFormBuilder()
  248.                      ->add('sector'EntityType::class, [
  249.                                 'class' => SectorPlanta::class,
  250.                                 'required' => false,
  251.                                 'placeholder' => 'Todos',
  252.                                 'choices' => $user->getAllSectoresActivos(),
  253.                                                     
  254.                             ])
  255.                      ->add('estado'ChoiceType::class, [
  256.                                 'choices'  => [
  257.                                     'Todos' => 'all',
  258.                                     'Pendientes' => 'pen',
  259.                                  //   'Programados' => 'pro',
  260. //                                    'Programados' => 'pro',
  261.                                     'Realizados' => 'rea',
  262.                                 ],
  263.                                 'data' => 'all',
  264.                             ])
  265.                      ->add('departamento'EntityType::class, [
  266.                                 'class' => Departamento::class,
  267.                                 'required' => false,
  268.                                 'placeholder' => 'Todos',
  269.                                 'choices' => $user->getDepartamentos()->toArray(),
  270.                             ])
  271.                      ->add('desde'DateType::class, [
  272.                                                         'widget' => 'single_text',
  273.                                                         'constraints' => [
  274.                                                             new NotNull(['message' => 'Este campo no puede estar vacío.']),
  275.                                                         ],
  276.                             ])
  277.                      ->add('hasta'DateType::class, [
  278.                                                         'widget' => 'single_text',
  279.                                                         'constraints' => [
  280.                                                             new NotNull(['message' => 'Este campo no puede estar vacío.']),
  281.                                                         ],
  282.                             ])
  283.                      ->getForm();
  284.         return $form;
  285.     }
  286.     private function formFilterTreas()
  287.     {
  288.         $user $this->getUser();
  289.         $form $this->createFormBuilder()
  290.                      ->add('realizado'ChoiceType::class, [
  291.                                 'choices'  => [
  292.                                     'Todas' => 'all',
  293.                                     'Si' => true,
  294.                                     'No' => false,
  295.                                 ],
  296.                                 'data' => 'all',
  297.                             ])
  298.                      ->add('diagramado'ChoiceType::class, [
  299.                                 'choices'  => [
  300.                                     'Todas' => 'all',
  301.                                     'Si' => true,
  302.                                     'No' => false,
  303.                                 ],
  304.                                 'data' => 'all',
  305.                             ])
  306.                      ->add('equipo'EntityType::class, [
  307.                                 'class' => Maquinaria::class,
  308.                                 'required' => false,
  309.                                 'placeholder' => 'Todos',
  310.                                 'query_builder' => function (EntityRepository $er) {
  311.                                                         return $er->createQueryBuilder('d')
  312.                                                                   ->join('d.sector''s')
  313.                                                                   ->andWhere('d.activo = true')
  314.                                                                   ->andWhere('s.active = true')
  315.                                                                   ->addOrderBy('s.nombre''ASC')
  316.                                                                   ->addOrderBy('d.nombre''ASC');
  317.                                                     },
  318.                                 'group_by' => function($choice$key$value) {
  319.                                                                                     if ($choice && $choice->getSector()) 
  320.                                                                                     {
  321.                                                                                         return $choice->getSector() . '';
  322.                                                                                     }
  323.                                                                                     return 'Sin sector';
  324.                                                                                 },
  325.                                                                            
  326.                             ])
  327.                      ->add('solicitante'EntityType::class, [
  328.                                 'class' => SolicitantePedidoReparacion::class,
  329.                                 'required' => false,
  330.                                 'placeholder' => 'Todos',
  331.                                 'query_builder' => function (EntityRepository $er) {
  332.                                                         return $er->createQueryBuilder('d')
  333.                                                                   ->andWhere('d.activo = true')
  334.                                                                   ->addOrderBy('d.nombre''ASC');
  335.                                                     },
  336.                                                                            
  337.                             ])
  338.                      ->add('sector'EntityType::class, [
  339.                                 'class' => SectorPlanta::class,
  340.                                 'required' => false,
  341.                                 'placeholder' => 'Todos',
  342.                                 'choices' => $user->getAllSectoresActivos(),
  343.                             ])
  344.                      ->add('desde'DateType::class, [
  345.                                                         'widget' => 'single_text',
  346.                                                         'data' => (new \DateTime())->modify('-1 day'),
  347.                             ])
  348.                      ->add('hasta'DateType::class, [
  349.                                                         'widget' => 'single_text',
  350.                                                         'data' => new \DateTime(),
  351.                             ])
  352.                      ->add('departamento'EntityType::class, [
  353.                                 'class' => Departamento::class,
  354.                                 'required' => false,
  355.                                 'placeholder' => 'Todos',
  356.                                 'choices' => $user->getAllDepartamentosActivos(),
  357.                             ])
  358.                      ->getForm();
  359.         return $form;
  360.     }
  361.     /**
  362.      * @Route("/new", name="app_mantenimiento_pedido_reparacion_new", methods={"GET", "POST"})
  363.      */
  364.     public function new(Request $requestPedidoReparacionRepository $pedidoReparacionRepository): Response
  365.     {
  366.         $pedidoReparacion = new PedidoReparacion();
  367.         $form $this->createForm(PedidoReparacionType::class, $pedidoReparacion, ['user' => $this->getUser()]);
  368.         $form->handleRequest($request);
  369.         if ($form->isSubmitted() && $form->isValid()) 
  370.         {
  371.             $uploadedFile $form->get('archivoImagen')->getData();
  372.             if ($uploadedFile
  373.             {
  374.                  $allowedMimeTypes = ['jpeg''JPG''JPEG''jpg''png''PNG','gif''GIF'];
  375.                  $extension $uploadedFile->getClientOriginalExtension();
  376.                 if (!in_array($extension$allowedMimeTypes)) 
  377.                 {
  378.                     $form->get('archivoImagen')->addError(new FormError('Tipo de archivo no permitido. Solo se aceptan JPEG, PNG y GIF.'));
  379.                     return $this->renderForm('mantenimiento/pedido_reparacion/new.html.twig', [
  380.                                                                                                 'pedido_reparacion' => $pedidoReparacion,
  381.                                                                                                 'form' => $form,
  382.                                                                                                 'dpto' => true
  383.                                                                                                 ]);
  384.                 }
  385.                 $originalFilename pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_FILENAME);
  386.                 $safeFilename transliterator_transliterate('Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()'$originalFilename);
  387.                 $extension $uploadedFile->getClientOriginalExtension();                
  388.                 $newFilename $safeFilename.'-'.uniqid().'.'.$extension// Usamos $extension aquí
  389.                 try 
  390.                 {
  391.                     $uploadedFile->move(
  392.                         $this->getParameter('ruta_imagenes_pedidos'), 
  393.                         $newFilename
  394.                     );
  395.                 } catch (\Exception $e) {
  396.                     // ...
  397.                 }
  398.                 $pedidoReparacion->setNombreArchivoImagen($newFilename);
  399.             }
  400.             
  401.             $pedidoReparacionRepository->add($pedidoReparaciontrue);
  402.             return $this->redirectToRoute('app_mantenimiento_pedido_reparacion_index', [], Response::HTTP_SEE_OTHER);
  403.         }
  404.         return $this->renderForm('mantenimiento/pedido_reparacion/new.html.twig', [
  405.             'pedido_reparacion' => $pedidoReparacion,
  406.             'form' => $form,
  407.             'dpto' => true
  408.         ]);
  409.     }
  410.     /**
  411.      * @Route("/{id}/modificar/{dpto}/departamento", name="app_mantenimiento_pedido_reparacion_change_depto", methods={"GET", "POST"})
  412.      */
  413.     public function modificarDepartamento(PedidoReparacion $pedidoReparacionDepartamento $dptoPedidoReparacionRepository $pedidoReparacionRepository): Response
  414.     {
  415.         try
  416.         {
  417.             $pedidoReparacion->setDepartamento($dpto);
  418.             $pedidoReparacionRepository->add($pedidoReparaciontrue);
  419.             return new JsonResponse(['ok' => true]);
  420.         }
  421.         catch (\Exception $e)
  422.         {
  423.             return new JsonResponse(['ok' => false'message' => $e->getMessage()]);
  424.         }
  425.     }
  426.     /**
  427.      * @Route("/{id}", name="app_mantenimiento_pedido_reparacion_show", methods={"GET", "POST"})
  428.      */
  429.     public function show(PedidoReparacion $pedidoReparacion): Response
  430.     {
  431.         return $this->render('mantenimiento/pedido_reparacion/show.html.twig', [
  432.             'pedido_reparacion' => $pedidoReparacion,
  433.         ]);
  434.     }
  435.     /**
  436.      * @Route("/{id}/diagramar", name="app_mantenimiento_pedido_reparacion_diagramar", methods={"GET", "POST"})
  437.      */
  438.     public function diagramar(Request $requestPedidoReparacion $pedidoReparacionPedidoReparacionRepository $pedidoReparacionRepository): Response
  439.     {
  440.         if (in_array($this->getUser()->getId(), [1,11]))
  441.         {
  442.             $form $this->createForm(PedidoReparacionType::class, $pedidoReparacion, ['user' => $this->getUser(), 'depto' => true ]);
  443.         }
  444.         else
  445.         {
  446.             $form $this->createForm(PedidoReparacionType::class, $pedidoReparacion);
  447.         }
  448.      
  449.         $form->handleRequest($request);
  450.         if ($form->isSubmitted() && $form->isValid()) {
  451.             $pedidoReparacionRepository->add($pedidoReparaciontrue);
  452.             return $this->redirectToRoute('app_mantenimiento_pedido_reparacion_index', [], Response::HTTP_SEE_OTHER);
  453.         }
  454.         return $this->renderForm('mantenimiento/pedido_reparacion/edit.html.twig', [
  455.             'pedido_reparacion' => $pedidoReparacion,
  456.             'form' => $form,
  457.         ]);
  458.     }
  459.     /**
  460.      * @Route("/{id}/edit", name="app_mantenimiento_pedido_reparacion_edit", methods={"GET", "POST"})
  461.      */
  462.     public function edit(Request $requestPedidoReparacion $pedidoReparacionPedidoReparacionRepository $pedidoReparacionRepository): Response
  463.     {
  464.         $form $this->createForm(PedidoReparacionType::class, $pedidoReparacion, ['user' => $this->getUser(), 'depto' => in_array($this->getUser()->getId(), [1,11]) ]);
  465.         $form->handleRequest($request);
  466.         if ($form->isSubmitted() && $form->isValid()) 
  467.         {
  468.             $uploadedFile $form->get('archivoImagen')->getData();
  469.             if ($uploadedFile
  470.             {
  471.                  $allowedMimeTypes = ['jpeg''JPG''JPEG''jpg''png''PNG','gif''GIF'];
  472.                  $extension $uploadedFile->getClientOriginalExtension();
  473.                 if (!in_array($extension$allowedMimeTypes)) 
  474.                 {
  475.                     $form->get('archivoImagen')->addError(new FormError('Tipo de archivo no permitido. Solo se aceptan JPEG, PNG y GIF.'));
  476.                     return $this->renderForm('mantenimiento/pedido_reparacion/new.html.twig', [
  477.                                                                                                 'pedido_reparacion' => $pedidoReparacion,
  478.                                                                                                 'form' => $form,
  479.                                                                                                 'dpto' => true
  480.                                                                                                 ]);
  481.                 }
  482.                 $originalFilename pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_FILENAME);
  483.                 $safeFilename transliterator_transliterate('Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()'$originalFilename);
  484.                 $extension $uploadedFile->getClientOriginalExtension();                
  485.                 $newFilename $safeFilename.'-'.uniqid().'.'.$extension// Usamos $extension aquí
  486.                 try 
  487.                 {
  488.                     $uploadedFile->move(
  489.                         $this->getParameter('ruta_imagenes_pedidos'), 
  490.                         $newFilename
  491.                     );
  492.                 } catch (\Exception $e) {
  493.                     // ...
  494.                 }
  495.                 $pedidoReparacion->setNombreArchivoImagen($newFilename);
  496.             }
  497.             $pedidoReparacionRepository->add($pedidoReparaciontrue);
  498.             return $this->redirectToRoute('app_mantenimiento_pedido_reparacion_index', [], Response::HTTP_SEE_OTHER);
  499.         }
  500.         return $this->renderForm('mantenimiento/pedido_reparacion/edit.html.twig', [
  501.             'pedido_reparacion' => $pedidoReparacion,
  502.             'form' => $form,
  503.             'dpto' => in_array($this->getUser()->getId(), [1,11]),
  504.         ]);
  505.     }
  506.     /** 
  507.      * @Route("/{id}/delete/pedido", name="app_mantenimiento_pedido_reparacion_delete", methods={"POST", "DELETE"})
  508.      */
  509.     public function delete(Request $requestPedidoReparacion $pedidoReparacionEntityManagerInterface $entityManager): Response
  510.     {
  511.         
  512.         try
  513.         {
  514.             $realizada 0;
  515.             foreach ($pedidoReparacion->getPedidosDiagramados() as $pedidoDiagramado
  516.             {
  517.                 if ($pedidoDiagramado->isRealizada())
  518.                 {
  519.                     $realizada++;
  520.                 }
  521.             }
  522.             if ($realizada 0)
  523.             {
  524.                 return $this->json(['ok' => false'message' => 'No se puede eliminar el pedido de reparación. El mismo ya ha sido marcado como realizado.']);
  525.             }
  526.             $pedidoReparacion->setEliminada(true);
  527.             $entityManager->flush();
  528.             //$pedidoReparacionRepository->remove($pedidoReparacion, true);
  529.             
  530.             return $this->json(['ok' => true]);
  531.         }
  532.         catch (\Exception $e)
  533.         {
  534.             return $this->json(['ok' => false'message' => 'No se ha podido eliminar el pedido de reparación. Posiblemente esté asociado a un organigrama.']);
  535.         }
  536.     }
  537. }