src/Controller/EmbajadorParticipanteController.php line 89

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Embajadores;
  4. use App\Entity\Nominapago;
  5. use App\Entity\Agenda;
  6. use App\Entity\ColegioParticipante;
  7. use App\Entity\Dependencia;
  8. use App\Entity\EmbajadorParticipante;
  9. use App\Form\EmbajadorParticipanteType;
  10. use App\Form\EmbajadorParticipanteeditType;
  11. use App\Form\EditarMontoPagoType;
  12. use App\Service\Mensajes;
  13. use App\Form\EmbajadorParticipante2Type;
  14. use App\Form\EmbajadorParticipanterolType;
  15. use App\Repository\EmbajadorParticipanteRepository;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use App\Service\QRConfirmacionService;
  22. use App\Service\CapacidadService;
  23. /**
  24.  * @Route("/embajador/participante")
  25.  */
  26. class EmbajadorParticipanteController extends AbstractController
  27. {
  28.     /**
  29.      * @Route("/", name="app_embajador_participante_index", methods={"GET"})
  30.      */
  31.     public function index(EmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  32.     {
  33.         return $this->render('embajador_participante/index.html.twig', [
  34.             'embajador_participantes' => $embajadorParticipanteRepository->findAll(),
  35.         ]);
  36.     }
  37.     /**
  38.      * @Route("/pagadas", name="app_embajador_participante_pagadas", methods={"GET"})
  39.      */
  40.     public function pagadas(EmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  41.     {
  42.         $entityManager $this->getDoctrine()->getManager();
  43.         $nominas $entityManager->getRepository(Nominapago::class)->findAll();
  44.         return $this->render('embajador_participante/pagadas.html.twig', [
  45.             'embajador_participantes' => $embajadorParticipanteRepository->findByNomina($nominas),
  46.         ]);
  47.     }
  48.     /**
  49.      * @Route("/agregar", name="app_embajador_participante_new", methods={"GET", "POST"})
  50.      */
  51.     public function agregarRequest $requestEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  52.     {
  53.         $entityManager $this->getDoctrine()->getManager();
  54.         $embajadorParticipante = new EmbajadorParticipante();
  55.         $form $this->createForm(EmbajadorParticipante2Type::class, $embajadorParticipante);
  56.         $form->handleRequest($request);
  57.         $hoy = new \DateTime('now');
  58.         if ($form->isSubmitted() && $form->isValid()) {
  59.             $embajadorParticipante->setEstado("seleccionado");
  60.             $embajadorParticipante->setFecha($hoy);
  61.             $embajadorParticipante->setTipo("regular");
  62.             $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  63.             return $this->redirectToRoute('app_embajador_participante_pagos');
  64.         }
  65.         return $this->renderForm('embajador_participante/nuevo.html.twig', [
  66.             'form' => $form,
  67.         ]);
  68.     }
  69.     /**
  70.      * @Route("/postularrol/{id}", name="app_embajador_participante_newrol", methods={"GET", "POST"})
  71.      */
  72.     public function postularrol($idRequest $requestEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  73.     {
  74.         $user $this->getUser();
  75.         $entityManager $this->getDoctrine()->getManager();
  76.         $embajadorParticipante = new EmbajadorParticipante();
  77.         $agenda $entityManager->getRepository(Agenda::class)->findOneById($id);
  78.         $embajador $entityManager->getRepository(Embajadores::class)->findOneBy(['correo' => $user->getUserIdentifier()]);
  79.         if (!$embajador || strtolower(trim($embajador->getEstado() ?? '')) === 'no vigente') {
  80.             return $this->redirectToRoute('agenda_index_estudiante');
  81.         }
  82.         $entityManager $this->getDoctrine()->getManager();
  83.         $cadena $agenda->getRoles();
  84.         // Parsear roles en formato "rol:monto,rol:monto"
  85.         $rolesArray explode(','$cadena);
  86.         $opciones = [];
  87.         $rolesConMontos = []; // Array para pasar a la vista con formato legible
  88.         foreach ($rolesArray as $rolCompleto) {
  89.             $partes explode(':'trim($rolCompleto));
  90.             if (!empty($partes[0])) {
  91.                 $nombreRol trim($partes[0]);
  92.                 $monto = isset($partes[1]) ? intval(trim($partes[1])) : 0;
  93.                 $opciones[] = $nombreRol;
  94.                 $rolesConMontos[] = [
  95.                     'nombre' => $nombreRol,
  96.                     'monto' => $monto
  97.                 ];
  98.             }
  99.         }
  100.         $opciones array_combine($opciones$opciones);
  101.         $embajadorParticipante = new EmbajadorParticipante();
  102.         $form $this->createForm(EmbajadorParticipanterolType::class, $embajadorParticipante, [
  103.             'opciones' => $opciones,
  104.         ]);
  105.         $form->handleRequest($request);
  106.         $hoy = new \DateTime('now');
  107.         if ($form->isSubmitted() && $form->isValid()) {
  108.             $embajadorParticipante->setEstado("pendiente seleccion");
  109.             $embajadorParticipante->setFecha($hoy);
  110.             $embajadorParticipante->setAgenda($agenda);
  111.             $embajadorParticipante->setEmbajadores($embajador);
  112.             
  113.             // Asignar monto según el rol seleccionado
  114.             $rolSeleccionado $embajadorParticipante->getRol();
  115.             if ($rolSeleccionado && $agenda->getRoles()) {
  116.                 $rolesArray explode(','$agenda->getRoles());
  117.                 foreach ($rolesArray as $rolCompleto) {
  118.                     $partes explode(':'trim($rolCompleto));
  119.                     if (count($partes) >= && trim($partes[0]) === $rolSeleccionado) {
  120.                         $embajadorParticipante->setMonto(intval(trim($partes[1])));
  121.                         break;
  122.                     }
  123.                 }
  124.             }
  125.             $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  126.             return $this->redirectToRoute('agenda_index_estudiante');
  127.         }
  128.         return $this->renderForm('embajador_participante/nuevorol.html.twig', [
  129.             'form' => $form,
  130.             'agenda' => $agenda,
  131.             'rolesConMontos' => $rolesConMontos,
  132.         ]);
  133.     }
  134.     /**
  135.      * @Route("/new/{id}", name="app_embajador_participante_newbyagenda", methods={"GET", "POST"})
  136.      */
  137.     public function new($idRequest $requestEmbajadorParticipanteRepository $embajadorParticipanteRepositoryQRConfirmacionService $qrServiceCapacidadService $capacidadService): Response
  138.     {
  139.         $entityManager $this->getDoctrine()->getManager();
  140.         $embajadorParticipante = new EmbajadorParticipante();
  141.         
  142.         $agenda $entityManager->getRepository(Agenda::class)->findOneById($id);
  143.         
  144.         // Parsear roles de la agenda para el formulario
  145.         $rolesOpciones = [];
  146.         if ($agenda->getRoles()) {
  147.             $rolesArray explode(','$agenda->getRoles());
  148.             foreach ($rolesArray as $rolCompleto) {
  149.                 $partes explode(':'trim($rolCompleto));
  150.                 if (!empty($partes[0])) {
  151.                     $nombreRol trim($partes[0]);
  152.                     $monto = isset($partes[1]) ? intval(trim($partes[1])) : 0;
  153.                     // Formato: "Nombre del Rol ($monto)" => "Nombre del Rol"
  154.                     $rolesOpciones[$nombreRol ' ($' number_format($monto0',''.') . ')'] = $nombreRol;
  155.                 }
  156.             }
  157.         }
  158.         
  159.         $form $this->createForm(EmbajadorParticipanteType::class, $embajadorParticipante, [
  160.             'roles_opciones' => $rolesOpciones
  161.         ]);
  162.         $form->handleRequest($request);
  163.         
  164.         $colegios $entityManager->getRepository(ColegioParticipante::class)->findByAgenda($agenda->getId());
  165.         $embajadores $entityManager->getRepository(EmbajadorParticipante::class)->findByAgenda($agenda->getId());
  166.         // dependencias + optional filter
  167.         $dependencias $entityManager->getRepository(Dependencia::class)->findAll();
  168.         $selectedDep $request->query->getInt('dependencia') ?: null;
  169.         if ($selectedDep) {
  170.             $colegios array_values(array_filter($colegios, function($cp) use ($selectedDep) {
  171.                 $col $cp->getColegio();
  172.                 return $col && $col->getDependencia() && $col->getDependencia()->getId() == $selectedDep;
  173.             }));
  174.         }
  175.         // Obtener todos los embajadores para el autocomplete
  176.         $todosEmbajadores $entityManager->getRepository(Embajadores::class)->findAll();
  177.         $embajadoresJson = [];
  178.         foreach ($todosEmbajadores as $emb) {
  179.             $embajadoresJson[] = [
  180.                 'id'     => $emb->getId(),
  181.                 'nombre' => $emb->getNombre(),
  182.                 'rut'    => $emb->getRut(),
  183.                 'correo' => $emb->getCorreo(),
  184.                 'carrera'=> $emb->getCarrera(),
  185.             ];
  186.         }
  187.         if ($form->isSubmitted() && $form->isValid()) {
  188.             // VALIDAR QUE EL EMBAJADOR NO ESTÉ YA AGREGADO A ESTA AGENDA
  189.             $embajadorSeleccionado $embajadorParticipante->getEmbajadores();
  190.             $yaExiste $embajadorParticipanteRepository->findOneBy([
  191.                 'agenda' => $agenda,
  192.                 'embajadores' => $embajadorSeleccionado
  193.             ]);
  194.             
  195.             if ($yaExiste) {
  196.                 $this->addFlash('error''El embajador ' $embajadorSeleccionado->getNombre() . ' ya está agregado a esta agenda.');
  197.                 return $this->redirectToRoute('app_embajador_participante_newbyagenda', array('id' => $agenda->getId()));
  198.             }
  199.             
  200.             $embajadorParticipante->setAgenda($agenda);
  201.             $embajadorParticipante->setEstado("postulante"); // Cambiado de "seleccionado" a "postulante"
  202.             $embajadorParticipante->setTipo("regular");
  203.             $embajadorParticipante->setFecha(new \DateTime('now'));
  204.             
  205.             // Asignar monto según el rol seleccionado
  206.             $rolSeleccionado $embajadorParticipante->getRol();
  207.             if ($rolSeleccionado && $agenda->getRoles()) {
  208.                 $rolesArray explode(','$agenda->getRoles());
  209.                 foreach ($rolesArray as $rolCompleto) {
  210.                     $partes explode(':'trim($rolCompleto));
  211.                     if (count($partes) >= && trim($partes[0]) === $rolSeleccionado) {
  212.                         $embajadorParticipante->setMonto(intval(trim($partes[1])));
  213.                         break;
  214.                     }
  215.                 }
  216.             }
  217.             // VALIDAR CAPACIDAD ANTES DE ASIGNAR
  218.             if ($agenda->getCapacidadMaxima() && !$capacidadService->hayCapacidadDisponible($agenda1)) {
  219.                 $this->addFlash('error''El evento "' $agenda->getTitulo() . '" ha alcanzado su capacidad máxima. No se puede agregar más embajadores.');
  220.                 return $this->redirectToRoute('app_embajador_participante_newbyagenda', array('id' => $agenda->getId()));
  221.             }
  222.             $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  223.             
  224.             // Generar código QR para el embajador participante
  225.             $qrService->asignarCodigoQR($embajadorParticipante);
  226.             
  227.             // INCREMENTAR CONTADOR DE CAPACIDAD
  228.             if ($agenda->getCapacidadMaxima()) {
  229.                 $capacidadService->registrarInscripcion($agenda1);
  230.             }
  231.             
  232.             $entityManager->flush();
  233.             $this->addFlash('success''Embajador agregado exitosamente como postulante.');
  234.             return $this->redirectToRoute('app_embajador_participante_newbyagenda', array('id' => $agenda->getId()));
  235.         }
  236.         $hoy = new \DateTime('now');
  237.         $desde = new \DateTime('now');
  238.         $hasta =  $hoy->modify('+7 days');
  239.         $anioInicio = new \DateTime((new \DateTime())->format('Y') . '-01-01 00:00:00');
  240.         $anioFin    = new \DateTime((new \DateTime())->format('Y') . '-12-31 23:59:59');
  241.         return $this->renderForm('embajador_participante/new.html.twig', [
  242.             'embajador_participante' => $embajadorParticipante,
  243.             'form' => $form,
  244.             'colegio_participantes' => $colegios,
  245.             'colegios' => $colegios,
  246.             'agenda'=>$agenda,
  247.             'embajadores'=>$embajadores,
  248.             'embajadores_json' => json_encode($embajadoresJson),
  249.             'desde' => $desde,
  250.             'hasta' => $hasta,
  251.             'anio_inicio' => $anioInicio,
  252.             'anio_fin'    => $anioFin,
  253.             'dependencias' => $dependencias,
  254.             'selected_dependencia' => $selectedDep,
  255.         ]);
  256.     }
  257.     /**
  258.      * @Route("/export-postulantes/{id}", name="app_embajador_participante_export_postulantes", methods={"GET"})
  259.      */
  260.     public function exportPostulantes($id): Response
  261.     {
  262.         $entityManager $this->getDoctrine()->getManager();
  263.         $agenda $entityManager->getRepository(Agenda::class)->findOneById($id);
  264.         
  265.         if (!$agenda) {
  266.             throw $this->createNotFoundException('Agenda no encontrada');
  267.         }
  268.         
  269.         // Obtener todos los postulantes
  270.         $embajadores $entityManager->getRepository(EmbajadorParticipante::class)->findByAgenda($agenda->getId());
  271.         
  272.         // Filtrar solo pendientes y rechazados
  273.         $postulantes array_filter($embajadores, function($embajador) {
  274.             return $embajador->getEstado() == "pendiente seleccion" || $embajador->getEstado() == "rechazado";
  275.         });
  276.         
  277.         // Crear el Excel
  278.         $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  279.         $sheet $spreadsheet->getActiveSheet();
  280.         
  281.         // Configurar encabezados
  282.         $sheet->setTitle('Postulantes');
  283.         $sheet->setCellValue('A1''Nombre');
  284.         $sheet->setCellValue('B1''RUT');
  285.         $sheet->setCellValue('C1''Correo');
  286.         $sheet->setCellValue('D1''Carrera');
  287.         $sheet->setCellValue('E1''Estado Embajador');
  288.         $sheet->setCellValue('F1''Tags');
  289.         $sheet->setCellValue('G1''Rol Postulado');
  290.         $sheet->setCellValue('H1''Estado Postulación');
  291.         $sheet->setCellValue('I1''Celular');
  292.         
  293.         // Estilo para encabezados
  294.         $headerStyle = [
  295.             'font' => ['bold' => true'color' => ['rgb' => 'FFFFFF']],
  296.             'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID'startColor' => ['rgb' => '4472C4']],
  297.             'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER],
  298.         ];
  299.         $sheet->getStyle('A1:I1')->applyFromArray($headerStyle);
  300.         
  301.         // Llenar datos
  302.         $row 2;
  303.         foreach ($postulantes as $embajadorParticipante) {
  304.             $embajador $embajadorParticipante->getEmbajadores();
  305.             
  306.             // Tags
  307.             $tags = [];
  308.             foreach ($embajador->getTags() as $tag) {
  309.                 $tags[] = $tag->getNombre();
  310.             }
  311.             $tagsStr implode(', '$tags);
  312.             
  313.             $sheet->setCellValue('A' $row$embajador->getNombre());
  314.             $sheet->setCellValue('B' $row$embajador->getRut());
  315.             $sheet->setCellValue('C' $row$embajador->getCorreo());
  316.             $sheet->setCellValue('D' $row$embajador->getCarrera());
  317.             $sheet->setCellValue('E' $row$embajador->getEstado());
  318.             $sheet->setCellValue('F' $row$tagsStr);
  319.             $sheet->setCellValue('G' $row$embajadorParticipante->getRol());
  320.             $sheet->setCellValue('H' $row$embajadorParticipante->getEstado());
  321.             $sheet->setCellValue('I' $row$embajador->getCelular());
  322.             
  323.             $row++;
  324.         }
  325.         
  326.         // Auto-ajustar ancho de columnas
  327.         foreach (range('A''I') as $col) {
  328.             $sheet->getColumnDimension($col)->setAutoSize(true);
  329.         }
  330.         
  331.         // Crear el archivo Excel
  332.         $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
  333.         $fileName 'Postulantes_' $agenda->getId() . '_' date('Y-m-d') . '.xlsx';
  334.         
  335.         // Crear respuesta con el archivo
  336.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  337.         $writer->save($temp_file);
  338.         
  339.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  340.     }
  341.     /**
  342.      * @Route("/export-anual/{anio}", name="app_embajador_participante_export_anual", methods={"GET"})
  343.      */
  344.     public function exportAnual(int $anio): Response
  345.     {
  346.         $em $this->getDoctrine()->getManager();
  347.         $inicio = new \DateTime($anio '-01-01');
  348.         $fin    = new \DateTime($anio '-12-31');
  349.         $participantes $em->createQueryBuilder()
  350.             ->select('ep')
  351.             ->from(EmbajadorParticipante::class, 'ep')
  352.             ->join('ep.agenda''a')
  353.             ->join('ep.embajadores''e')
  354.             ->where('a.fecha BETWEEN :inicio AND :fin')
  355.             ->andWhere('ep.estado IN (:estados)')
  356.             ->setParameter('inicio'$inicio)
  357.             ->setParameter('fin'$fin)
  358.             ->setParameter('estados', ['Confirmado''Realizado''En pago'])
  359.             ->orderBy('e.nombre''ASC')
  360.             ->getQuery()
  361.             ->getResult();
  362.         $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  363.         $sheet $spreadsheet->getActiveSheet();
  364.         $sheet->setTitle('Participaciones ' $anio);
  365.         // Encabezados
  366.         $headers = ['Nombre''RUT''Correo''Carrera''Fecha Actividad''Lugar''Tipo Actividad''Rol''Monto''Estado Pago'];
  367.         foreach ($headers as $i => $h) {
  368.             $sheet->setCellValueByColumnAndRow($i 11$h);
  369.         }
  370.         $headerStyle = [
  371.             'font' => ['bold' => true'color' => ['rgb' => 'FFFFFF']],
  372.             'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID'startColor' => ['rgb' => '4472C4']],
  373.             'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER],
  374.         ];
  375.         $sheet->getStyle('A1:J1')->applyFromArray($headerStyle);
  376.         // Datos
  377.         $row 2;
  378.         foreach ($participantes as $ep) {
  379.             $emb    $ep->getEmbajadores();
  380.             $agenda $ep->getAgenda();
  381.             $tipo   $agenda && $agenda->getTipoAgenda() ? $agenda->getTipoAgenda()->getNombre() : '';
  382.             $fecha  $agenda && $agenda->getFecha() ? $agenda->getFecha()->format('d-m-Y') : '';
  383.             $lugar  $agenda $agenda->getLugar() : '';
  384.             $sheet->setCellValueByColumnAndRow(1,  $row$emb $emb->getNombre() : '');
  385.             $sheet->setCellValueByColumnAndRow(2,  $row$emb $emb->getRut()    : '');
  386.             $sheet->setCellValueByColumnAndRow(3,  $row$emb $emb->getCorreo() : '');
  387.             $sheet->setCellValueByColumnAndRow(4,  $row$emb $emb->getCarrera(): '');
  388.             $sheet->setCellValueByColumnAndRow(5,  $row$fecha);
  389.             $sheet->setCellValueByColumnAndRow(6,  $row$lugar);
  390.             $sheet->setCellValueByColumnAndRow(7,  $row$tipo);
  391.             $sheet->setCellValueByColumnAndRow(8,  $row$ep->getRol());
  392.             $sheet->setCellValueByColumnAndRow(9,  $row$ep->getMonto());
  393.             $sheet->setCellValueByColumnAndRow(10$row$ep->getPagado() ? 'Pagado' 'Pendiente');
  394.             $row++;
  395.         }
  396.         foreach (range(110) as $col) {
  397.             $sheet->getColumnDimensionByColumn($col)->setAutoSize(true);
  398.         }
  399.         $writer   = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
  400.         $fileName 'Participacion_Embajadores_' $anio '.xlsx';
  401.         $tmpFile  tempnam(sys_get_temp_dir(), 'emb_');
  402.         $writer->save($tmpFile);
  403.         return $this->file($tmpFile$fileNameResponseHeaderBag::DISPOSITION_ATTACHMENT);
  404.     }
  405.     /**
  406.      * @Route("/{id}", name="app_embajador_participante_show", methods={"GET"}, requirements={"id"="\d+"})
  407.      */
  408.     public function show(EmbajadorParticipante $embajadorParticipante): Response
  409.     {
  410.         return $this->render('embajador_participante/show.html.twig', [
  411.             'embajador_participante' => $embajadorParticipante,
  412.         ]);
  413.     }
  414.     /**
  415.      * @Route("/{id}/edit", name="app_embajador_participante_edit", methods={"GET", "POST"})
  416.      */
  417.     public function edit(Request $requestEmbajadorParticipante $embajadorParticipanteEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  418.     {
  419.         $cadena $embajadorParticipante->getAgenda()->getRoles();
  420.         
  421.         // Parsear roles en formato "rol:monto,rol:monto"
  422.         $rolesArray explode(','$cadena);
  423.         $opciones = [];
  424.         foreach ($rolesArray as $rolCompleto) {
  425.             $partes explode(':'trim($rolCompleto));
  426.             if (!empty($partes[0])) {
  427.                 $nombreRol trim($partes[0]);
  428.                 $opciones[] = $nombreRol;
  429.             }
  430.         }
  431.         $opciones array_combine($opciones$opciones);
  432. $msj2 "Has sido seleccionado para la actividad ".$embajadorParticipante->getAgenda()->getTipoAgenda()->getNombre().", el día ".date_format($embajadorParticipante->getAgenda()->getFecha(),"d/m/Y").", en ".$embajadorParticipante->getAgenda()->getLugar();
  433.  
  434. $msj "Hola,<br><br>
  435.  
  436. Has sido seleccionado para la actividad <strong>".$embajadorParticipante->getAgenda()->getTipoAgenda()->getNombre()."</strong>, el día <strong>".date_format($embajadorParticipante->getAgenda()->getFecha(),"d/m/Y")."</strong>, en <strong>".$embajadorParticipante->getAgenda()->getLugar()."</strong> con el rol: <strong>".$embajadorParticipante->getRol()."</strong><br><br>
  437.  
  438. ".$embajadorParticipante->getAgenda()->getTipoAgenda()->getCuerpo()."<br><br>
  439.  
  440. Para más detalles de la actividad puedes revisar la plataforma Delfy.<br><br>
  441.  
  442. Saludos cordiales";
  443.      //   $embajadorParticipante->setCorreo($msj);
  444.         // El monto ahora se asigna según el rol seleccionado (está en roles como "rol:monto")
  445.         // Si no tiene monto, se deja null o se asigna después según el rol
  446.         
  447.         // Crear mapa de roles con montos para JavaScript
  448.         $rolesConMontos = [];
  449.         $rolesArray explode(','$cadena);
  450.         foreach ($rolesArray as $rolCompleto) {
  451.             $partes explode(':'trim($rolCompleto));
  452.             if (count($partes) >= 2) {
  453.                 $nombreRol trim($partes[0]);
  454.                 $monto intval(trim($partes[1]));
  455.                 $rolesConMontos[$nombreRol] = $monto;
  456.             }
  457.         }
  458.         $form $this->createForm(EmbajadorParticipanteeditType::class, $embajadorParticipante, [
  459.             'opciones' => array_combine($opciones$opciones),
  460.         ]);
  461.         $form->handleRequest($request);
  462.         if ($form->isSubmitted() && $form->isValid()) {
  463.             $embajadorParticipante->setEstado("seleccionado");
  464.             $embajadorParticipante->setTipo("regular");
  465.             
  466.             // Asignar monto según el rol seleccionado si no tiene monto
  467.             $rolSeleccionado $embajadorParticipante->getRol();
  468.             if ($rolSeleccionado && $embajadorParticipante->getAgenda()->getRoles()) {
  469.                 $rolesArray explode(','$embajadorParticipante->getAgenda()->getRoles());
  470.                 foreach ($rolesArray as $rolCompleto) {
  471.                     $partes explode(':'trim($rolCompleto));
  472.                     if (count($partes) >= && trim($partes[0]) === $rolSeleccionado) {
  473.                         // Solo actualizar si no tiene monto o si es diferente
  474.                         if (!$embajadorParticipante->getMonto()) {
  475.                             $embajadorParticipante->setMonto(intval(trim($partes[1])));
  476.                         }
  477.                         break;
  478.                     }
  479.                 }
  480.             }
  481.             $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  482.             
  483.             // Detectar qué botón se presionó
  484.             $action $request->request->get('action');
  485.             
  486.             if ($action === 'save_and_send') {
  487.                 // Redirigir a la página de envío de correo
  488.                 return $this->redirectToRoute('app_embajador_participante_correo', ['id' => $embajadorParticipante->getId()]);
  489.             } else {
  490.                 // Solo guardar, redirigir a la lista de embajadores
  491.                 $this->addFlash('success''Embajador seleccionado correctamente (sin envío de correo)');
  492.                 return $this->redirectToRoute('app_embajador_participante_newbyagenda', ['id' => $embajadorParticipante->getAgenda()->getId()]);
  493.             }
  494.         }
  495.         return $this->renderForm('embajador_participante/edit.html.twig', [
  496.             'embajador_participante' => $embajadorParticipante,
  497.             'form' => $form,
  498.             'msj2' => $msj2,
  499.             'roles_montos_json' => json_encode($rolesConMontos),
  500.         ]);
  501.     }
  502.     /**
  503.      * @Route("/borrar/{id}", name="app_embajador_participante_delete", methods={"GET", "POST"})
  504.      */
  505.     public function delete(Request $requestEmbajadorParticipante $embajadorParticipanteEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  506.     {
  507.         if ($this->isGranted('ROLE_ADMIN')) {
  508.             $id $embajadorParticipante->getAgenda()->getId();
  509.             //if ($this->isCsrfTokenValid('delete'.$embajadorParticipante->getId(), $request->request->get('_token'))) {
  510.             $embajadorParticipanteRepository->remove($embajadorParticipantetrue);
  511.             //}
  512.             return $this->redirectToRoute('app_embajador_participante_newbyagenda', array('id' => $id));
  513.         }
  514.     }
  515.     /**
  516.      * @Route("/postular/{id}", name="app_embajador_participante_postular", methods={"GET", "POST"})
  517.      */
  518.     public function postular($idRequest $requestEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  519.     {
  520.         $user $this->getUser();
  521.         $entityManager $this->getDoctrine()->getManager();
  522.         $embajadorParticipante = new EmbajadorParticipante();
  523.         $agenda $entityManager->getRepository(Agenda::class)->findOneById($id);
  524.         $embajador $entityManager->getRepository(Embajadores::class)->findOneBy(['correo' => $user->getUserIdentifier()]);
  525.         if (!$embajador || strtolower(trim($embajador->getEstado() ?? '')) === 'no vigente') {
  526.             return $this->redirectToRoute('agenda_index_estudiante');
  527.         }
  528.         $embajadorparticipante $entityManager->getRepository(EmbajadorParticipante::class)->findOneBy(array('agenda'=>$agenda'embajadores'=>$embajador));
  529.         if($embajadorparticipante){
  530.             return $this->redirectToRoute('agenda_index_estudiante');
  531.         }
  532.         $embajadorParticipante->setAgenda($agenda);
  533.         $embajadorParticipante->setEmbajadores($embajador);
  534.         // El monto ahora se obtiene del rol seleccionado (formato "rol:monto" en agenda->roles)
  535.         // Se asignará después cuando se seleccione el rol específico
  536.         $embajadorParticipante->setEstado("pendiente seleccion");
  537.         $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  538.         return $this->redirectToRoute('agenda_index_estudiante');
  539.     }
  540.     /**
  541.      * @Route("/cambioestado/{id}/{estado}", name="app_embajador_participante_estado", methods={"GET", "POST"})
  542.      */
  543.     public function cancelar($estadoRequest $requestEmbajadorParticipante $embajadorParticipanteEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  544.     {
  545.         if ($this->isGranted('ROLE_ADMIN')) {
  546.             $id $embajadorParticipante->getAgenda()->getId();
  547.         $embajadorParticipante->setEstado($estado);
  548.             $embajadorParticipante->setTipo(null);
  549.         $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  550.         return $this->redirectToRoute('app_embajador_participante_newbyagenda', array('id' => $id));
  551.         }
  552.     }
  553.     /**
  554.      * @Route("rechazar/{id}/{estado}", name="app_embajador_participante_rechazar", methods={"GET", "POST"})
  555.      */
  556.     public function rechazar($estadoRequest $requestEmbajadorParticipante $embajadorParticipanteEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  557.     {
  558.         if ($this->isGranted('ROLE_ADMIN')) {
  559.             $id2 $embajadorParticipante->getEmbajadores()->getId();
  560.             $embajadorParticipante->setEstado($estado);
  561.             $embajadorParticipante->setTipo(null);
  562.             $embajadorParticipante->setNomina(null);
  563.             $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  564.             return $this->redirectToRoute('app_embajador_participante_pagar', array( 'id' => $id2));
  565.         }
  566.     }
  567.     /**
  568.      * @Route("sacardepago/{id}/", name="app_embajador_participante_quitarnomina", methods={"GET", "POST"})
  569.      */
  570.     public function sacardepagoRequest $requestEmbajadorParticipante $embajadorParticipanteEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  571.     {
  572.         if ($this->isGranted('ROLE_ADMIN')) {
  573.             $id2 $embajadorParticipante->getEmbajadores()->getId();
  574.             $embajadorParticipante->setEstado("seleccionado");
  575.             $embajadorParticipante->setNomina(null);
  576.             $embajadorParticipanteRepository->add($embajadorParticipantetrue);
  577.             return $this->redirectToRoute('app_embajador_participante_pagar', array( 'id' => $id2));
  578.         }
  579.     }
  580.     /**
  581.      * @Route("agregarpago/{pago}/{id}", name="app_embajador_participante_agregarpago", methods={"GET", "POST"})
  582.      */
  583.     public function agregarpago($id$pago): Response
  584.     {
  585.         $entityManager $this->getDoctrine()->getManager();
  586.         $nomina $entityManager->getRepository(Nominapago::class)->findOneById($pago);
  587.         $embajadorParticipante $entityManager->getRepository(EmbajadorParticipante::class)->findOneById($id);
  588.         if ($this->isGranted('ROLE_ADMIN')) {
  589.             $id2 $embajadorParticipante->getEmbajadores()->getId();
  590.             $embajadorParticipante->setNomina($nomina);
  591.             $embajadorParticipante->setEstado("En pago");
  592.             $entityManager->flush();
  593.             return $this->redirectToRoute('app_embajador_participante_pagar', array( 'id' => $id2));
  594.         }
  595.     }
  596.     /**
  597.      * @Route("/pagos", name="app_embajador_participante_pagos", methods={"GET"})
  598.      */
  599.     public function pagos(EmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  600.     {
  601.         $qbx $this->getDoctrine()->getManager()->createQueryBuilder()
  602.             ->select('count(ep) as cantidad, sum(ep.monto) as monto, em.nombre as nombre, em.id as id, em.rut as rut, em.correo as correo, em.carrera as carrera')
  603.             ->from(EmbajadorParticipante::class, 'ep')
  604.             ->leftJoin(Embajadores::class, 'em''WITH''ep.embajadores = em.id')
  605.             ->leftJoin(Agenda::class, 'a''WITH''ep.agenda = a.id')
  606.             ->andWhere('a.estadoAgenda = :estadoa or ep.agenda is null')
  607.             ->andWhere('ep.estado = :estado')
  608.             ->andWhere('ep.tipo != :tipo')
  609.             ->setParameter('estado'"seleccionado")
  610.             ->setParameter('estadoa'"2")
  611.             ->setParameter('tipo'"tp")
  612.             ->groupBy('em.id')
  613.             ;
  614.         $embajadores $qbx->getQuery()->getResult();
  615.         return $this->render('embajador_participante/pagos.html.twig', [
  616.             'embajador_participantes' => $embajadores,
  617.         ]);
  618.     }
  619.     /**
  620.      * @Route("/pagar/{id}", name="app_embajador_participante_pagar", methods={"GET", "POST"})
  621.      */
  622.     public function pagar($idEmbajadorParticipanteRepository $embajadorParticipanteRepositoryRequest $request): Response
  623.     {
  624.         $qbx $this->getDoctrine()->getManager()->createQueryBuilder()
  625.             ->select('ep')
  626.             ->from(EmbajadorParticipante::class, 'ep')
  627.             ->leftJoin(Embajadores::class, 'em''WITH''ep.embajadores = em.id')
  628.             ->leftJoin(Agenda::class, 'a''WITH''ep.agenda = a.id')
  629.             ->andWhere('ep.estado = :estado')
  630.             ->andWhere('em.id = :id')
  631.             ->andWhere('em.id = :id')
  632.             ->andWhere('a.estadoAgenda = :estadoa or ep.agenda is null')
  633.             ->setParameter('estado'"seleccionado")
  634.             ->setParameter('estadoa'"2")
  635.             ->setParameter('id'$id)
  636.         ;
  637.         $embajadores $qbx->getQuery()->getResult();
  638.         $pagos $this->getDoctrine()->getManager()->createQueryBuilder()
  639.             ->select('n')
  640.             ->from(Nominapago::class, 'n')
  641.             ->leftJoin(Embajadores::class, 'em''WITH''n.embajador = em.id')
  642.             ->andWhere('em.id = :id')
  643.             ->andWhere('n.estado IN (:estados)')
  644.             ->setParameter('id'$id)
  645.             ->setParameter('estados', ['pendiente''Emitida'])
  646.             ->getQuery()
  647.             ->getResult()
  648.         ;
  649.         $nominas $this->getDoctrine()->getManager()->createQueryBuilder()
  650.             ->select('n')
  651.             ->from(Nominapago::class, 'n')
  652.             ->leftJoin(Embajadores::class, 'em''WITH''n.embajador = em.id')
  653.             ->andWhere('em.id = :id')
  654.             ->setParameter('id'$id)
  655.             ->orderBy('n.id''DESC')
  656.             ->getQuery()
  657.             ->getResult()
  658.         ;
  659.         $form $this->createForm(EditarMontoPagoType::class);
  660.         $form->handleRequest($request);
  661.         if ($form->isSubmitted() && $form->isValid()) {
  662.             $id_embajador_participante $form->get('id')->getData();
  663.             $entityManager $this->getDoctrine()->getManager();
  664.             $embajador_participante $entityManager->getRepository(EmbajadorParticipante::class)->findOneById($id_embajador_participante);
  665.             $monto $form->get('monto')->getData();
  666.             $embajador_participante->setMonto($monto);
  667.             $observacion $form->get('observacion')->getData();
  668.             $embajador_participante->setObservacion($observacion);
  669.             $entityManager->persist($embajador_participante);
  670.             $entityManager->persist($embajador_participante);
  671.             $entityManager->flush();
  672.             return $this->redirectToRoute('app_embajador_participante_pagar', array('id' => $id));
  673.         }
  674.         return $this->render('embajador_participante/pagar.html.twig', [
  675.             'embajador_participantes' => $embajadores,
  676.             'id' => $id,
  677.             'pagos' => $pagos,
  678.             'nominas' => $nominas,
  679.             'form' => $form->createView(),
  680.         ]);
  681.     }
  682.     /**
  683.      * @Route("pagosbyuser/{id}", name="app_embajador_participante_pagosbyuser", methods={"GET"})
  684.      */
  685.     public function pagosbyuser($idEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  686.     {
  687.         $entityManager $this->getDoctrine()->getManager();
  688.         $embajador $entityManager->getRepository(Embajadores::class)->findOneById($id);
  689.         $actividades $embajadorParticipanteRepository->findBy(array('embajadores'=>$embajador'pagado'=>0));
  690.         return $this->render('embajador_participante/pagosbyuser.html.twig', [
  691.             'embajador_participantes' => $actividades,
  692.         ]);
  693.     }
  694.     /**
  695.      * @Route("/pagos2", name="app_embajador_participante_pagos2", methods={"GET", "POST"})
  696.      */
  697.     public function pagos2(Request $requestEmbajadorParticipanteRepository $embajadorParticipanteRepository, \App\Service\Mensajes $mensajes): Response
  698.     {
  699.         $entityManager $this->getDoctrine()->getManager();
  700.         
  701.         // Obtener todas las agendas para el selector
  702.         $agendas $entityManager->getRepository(Agenda::class)
  703.             ->createQueryBuilder('a')
  704.             ->orderBy('a.fecha''DESC')
  705.             ->getQuery()
  706.             ->getResult();
  707.         $embajadoresData = [];
  708.         $agendaSeleccionada null;
  709.         // Si se seleccionó una agenda
  710.         if ($request->isMethod('POST') && $request->request->has('agenda_id') && !$request->request->has('generar_nominas')) {
  711.             $agendaId $request->request->get('agenda_id');
  712.             $agendaSeleccionada $entityManager->getRepository(Agenda::class)->find($agendaId);
  713.             
  714.             if ($agendaSeleccionada) {
  715.                 // Obtener embajadores de esa agenda que no están pagados
  716.                 // Solo incluir estado: Realizado (evento ya ejecutado)
  717.                 $embajadoresData $entityManager->getRepository(EmbajadorParticipante::class)
  718.                     ->createQueryBuilder('ep')
  719.                     ->leftJoin('ep.embajadores''e')
  720.                     ->where('ep.agenda = :agenda')
  721.                     ->andWhere('ep.pagado = 0 OR ep.pagado IS NULL')
  722.                     ->andWhere('ep.estado = :estadoRealizado')
  723.                     ->andWhere('e.id IS NOT NULL')
  724.                     ->setParameter('agenda'$agendaSeleccionada)
  725.                     ->setParameter('estadoRealizado''Realizado')
  726.                     ->orderBy('e.nombre''ASC')
  727.                     ->getQuery()
  728.                     ->getResult();
  729.             }
  730.         }
  731.         // Si se está generando nóminas masivas
  732.         if ($request->isMethod('POST') && $request->request->has('generar_nominas')) {
  733.             $seleccionados $request->request->all('embajador');
  734.             $montos $request->request->all('monto');
  735.             $enviarCorreos $request->request->get('enviar_correos'false);
  736.             
  737.             if (empty($seleccionados)) {
  738.                 $this->addFlash('error''Debe seleccionar al menos un embajador');
  739.                 return $this->redirectToRoute('app_embajador_participante_pagos2');
  740.             }
  741.             
  742.             $nominasCreadas 0;
  743.             $correosEnviados 0;
  744.             
  745.             // Agrupar por embajador
  746.             $embajadoresPorPersona = [];
  747.             foreach ($seleccionados as $embajadorParticipanteId) {
  748.                 $embajadorPart $embajadorParticipanteRepository->find($embajadorParticipanteId);
  749.                 if ($embajadorPart && $embajadorPart->getEmbajadores()) {
  750.                     $embajadorId $embajadorPart->getEmbajadores()->getId();
  751.                     if (!isset($embajadoresPorPersona[$embajadorId])) {
  752.                         $embajadoresPorPersona[$embajadorId] = [
  753.                             'embajador' => $embajadorPart->getEmbajadores(),
  754.                             'actividades' => []
  755.                         ];
  756.                     }
  757.                     $embajadoresPorPersona[$embajadorId]['actividades'][] = [
  758.                         'participante' => $embajadorPart,
  759.                         'monto' => isset($montos[$embajadorParticipanteId]) ? (float)$montos[$embajadorParticipanteId] : 0
  760.                     ];
  761.                 }
  762.             }
  763.             
  764.             // Crear una nómina por cada embajador
  765.             foreach ($embajadoresPorPersona as $datos) {
  766.                 $embajador $datos['embajador'];
  767.                 $actividades $datos['actividades'];
  768.                 
  769.                 // Crear nómina
  770.                 $nominapago = new Nominapago();
  771.                 $nominapago->setFecha(new \DateTime());
  772.                 $nominapago->setEstado('pendiente');
  773.                 $nominapago->setEmbajador($embajador);
  774.                 $nominapago->setEnviado(0);
  775.                 
  776.                 $entityManager->persist($nominapago);
  777.                 
  778.                 $montoTotal 0;
  779.                 
  780.                 // Asignar actividades a la nómina
  781.                 foreach ($actividades as $actividadData) {
  782.                     $participante $actividadData['participante'];
  783.                     $monto $actividadData['monto'];
  784.                     
  785.                     $participante->setMonto($monto);
  786.                     $participante->setNomina($nominapago);
  787.                     $participante->setEstado('En pago');
  788.                     
  789.                     $entityManager->persist($participante);
  790.                     
  791.                     $montoTotal += $monto;
  792.                 }
  793.                 
  794.                 $entityManager->flush();
  795.                 $nominasCreadas++;
  796.                 
  797.                 // Enviar correo si está marcado
  798.                 if ($enviarCorreos && $montoTotal 0) {
  799.                     try {
  800.                         $this->enviarCorreoSolicitudBoleta($nominapago$montoTotal$mensajes);
  801.                         $nominapago->setEnviado(1);
  802.                         // $nominapago->setFechaEnvio(new \DateTime()); // Deshabilitado - columna no existe en producción
  803.                         $nominapago->setEstado('Emitida');
  804.                         $entityManager->flush();
  805.                         $correosEnviados++;
  806.                     } catch (\Exception $e) {
  807.                         // Log error pero continuar
  808.                     }
  809.                 }
  810.             }
  811.             
  812.             $mensaje "Se crearon {$nominasCreadas} nómina(s) exitosamente.";
  813.             if ($enviarCorreos) {
  814.                 $mensaje .= " Se enviaron {$correosEnviados} correo(s) de solicitud de boleta.";
  815.             }
  816.             
  817.             $this->addFlash('success'$mensaje);
  818.             return $this->redirectToRoute('app_nominapago_index');
  819.         }
  820.         return $this->render('embajador_participante/pagos2.html.twig', [
  821.             'agendas' => $agendas,
  822.             'agenda_seleccionada' => $agendaSeleccionada,
  823.             'embajadores' => $embajadoresData,
  824.         ]);
  825.     }
  826.     
  827.     /**
  828.      * Enviar correo de solicitud de boleta
  829.      */
  830.     private function enviarCorreoSolicitudBoleta(Nominapago $nominapagofloat $monto, \App\Service\Mensajes $mensajes): void
  831.     {
  832.         // Intentar usar plantilla de base de datos
  833.         $plantillaCorreo $this->container->get(PlantillaCorreoService::class);
  834.         
  835.         $variables = [
  836.             'nombre' => $nominapago->getEmbajador()->getNombre(),
  837.             'monto' => number_format($monto0',''.'),
  838.             'razon_social' => 'Pontificia Universidad Católica de Chile',
  839.             'rut' => '81.698.900-0',
  840.             'direccion' => 'Avda. Libertador Bernardo O\'Higgins N 340, Santiago',
  841.         ];
  842.         
  843.         try {
  844.             $correoData $plantillaCorreo->procesarPlantilla('solicitud_boleta'$variables);
  845.             
  846.             if ($correoData) {
  847.                 // Usar plantilla de la base de datos
  848.                 $asunto $correoData['asunto'];
  849.                 $mensaje $correoData['cuerpo'];
  850.             } else {
  851.                 // Fallback al mensaje básico
  852.                 $asunto 'Solicitud de Boleta - Pago Embajador';
  853.                 $mensaje 'Estimado/a ' $nominapago->getEmbajador()->getNombre() . ',
  854. Junto con saludar y esperando te encuentres muy bien, te escribimos para solicitar la boleta de los trabajos realizados. Para poder dar inicio al procesamiento de tu pago, necesitamos que subas la boleta en formato PDF al sistema Delfy.
  855. A continuación, te dejamos los datos con los que debes completar la boleta en el sitio del SII:
  856. Razón Social: Pontificia Universidad Católica de Chile
  857. RUT: 81.698.900-0
  858. Dirección: Avda. Libertador Bernardo O\'Higgins N 340, Santiago
  859. Monto: $' number_format($monto0',''.') . '
  860. Una vez que inicies sesión con tu usuario en Delfy, debes buscar en el menú lateral la pestaña "Boletas y pagos" y ahí seleccionar la opción de boletas pendientes por subir.
  861. Para que podamos procesarlo es necesario que el documento que subas a Delfy esté en formato PDF, el que puedes descargar directamente desde el sitio del SII al generar tu boleta. Además, el nombre del archivo debe seguir el siguiente formato "Nombre Completo – N° Boleta" (Por ejemplo "Vivian Avalos – 150")
  862. Saludos cordiales,
  863. Equipo de Difusión UC';
  864.             }
  865.             
  866.             $mensajes->enviar5Mensaje(
  867.                 $nominapago->getEmbajador()->getCorreo(),
  868.                 'vivian.avalos@uc.cl',
  869.                 $asunto,
  870.                 $mensaje
  871.             );
  872.         } catch (\Exception $e) {
  873.             // Si falla, usar mensaje básico
  874.             $asunto 'Solicitud de Boleta - Pago Embajador';
  875.             $cuerpo 'Estimado/a ' $nominapago->getEmbajador()->getNombre() . ',
  876. Junto con saludar, te informamos que se ha generado una nómina de pago por un total de $' number_format($monto0',''.') . '.
  877. Para procesar tu pago, necesitamos que subas tu boleta de honorarios en formato PDF a través de la plataforma.
  878. Datos para generar la boleta en el SII:
  879. Razón Social: Pontificia Universidad Católica de Chile
  880. RUT: 81.698.900-0
  881. Dirección: Avda. Libertador Bernardo O\'Higgins N 340, Santiago
  882. Monto: $' number_format($monto0',''.') . '
  883. Saludos cordiales,
  884. Equipo de Difusión UC';
  885.             
  886.             $mensajes->enviar5Mensaje(
  887.                 $nominapago->getEmbajador()->getCorreo(),
  888.                 'vivian.avalos@uc.cl',
  889.                 $asunto,
  890.                 $cuerpo
  891.             );
  892.         }
  893.     }
  894.     /**
  895.      * @Route("/borrar2/{id}", name="app_embajador_participante_delete_byuser", methods={"GET", "POST"})
  896.      */
  897.     public function deletebyuser(Request $requestEmbajadorParticipante $embajadorParticipanteEmbajadorParticipanteRepository $embajadorParticipanteRepository): Response
  898.     {
  899.         $user $this->getUser();
  900.         if ($this->isGranted('ROLE_ESTUDIANTE') and $user->getId() == $embajadorParticipante->getEmbajadores()->getId()) {
  901.             $id $embajadorParticipante->getAgenda()->getId();
  902.             //if ($this->isCsrfTokenValid('delete'.$embajadorParticipante->getId(), $request->request->get('_token'))) {
  903.             $embajadorParticipanteRepository->remove($embajadorParticipantetrue);
  904.             //}
  905.             return $this->redirectToRoute('agenda_index_estudiante');
  906.         }
  907.     }
  908.     /**
  909.      * @Route("/correo/{id}", name="app_embajador_participante_correo", methods={"GET", "POST"})
  910.      */
  911.     public function newferiasolicitudMensajes $mensajes$idRequest $requestEmbajadorParticipante $embajadorParticipante): Response
  912.     {
  913.         $entityManager $this->getDoctrine()->getManager();
  914. if($embajadorParticipante->getCorreo()){
  915.     $msj $embajadorParticipante->getCorreo();
  916. } else {
  917.     $msj=
  918.         "Hola,<br><br>
  919.  
  920. Has sido seleccionado para la actividad <strong>".$embajadorParticipante->getAgenda()->getTipoAgenda()->getNombre()."</strong>, el día <strong>".date_format($embajadorParticipante->getAgenda()->getFecha(),"d/m/Y")."</strong>, en <strong>".$embajadorParticipante->getAgenda()->getLugar()."</strong> con el rol: <strong>".$embajadorParticipante->getRol()."</strong><br><br>
  921.  
  922. ".$embajadorParticipante->getAgenda()->getTipoAgenda()->getCuerpo()."<br><br>
  923.  
  924. Para más detalles de la actividad puedes revisar la plataforma Delfy.<br><br>
  925.  
  926. Saludos cordiales";
  927. }
  928.         $mensajes->enviar2Mensaje($embajadorParticipante->getEmbajadores()->getCorreo(),"vivian.avalos@uc.cl""Actividad asignada"$msj);
  929.         $embajadorParticipante->setEnviado(True);
  930.         $entityManager->persist($embajadorParticipante);
  931.         $entityManager->flush();
  932.         return $this->redirectToRoute('app_embajador_participante_newbyagenda', array('id' => $embajadorParticipante->getAgenda()->getId()));
  933.     }
  934. }