src/Controller/VacationsController.php line 3497

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Constants\VacationsConstants;
  4. use App\Entity\HalfDay;
  5. use App\Entity\HalfDayValidation;
  6. use App\Entity\User;
  7. use App\Entity\UserVacationsDescription;
  8. use App\Entity\UserVacationYearDay;
  9. use App\Entity\Vacations;
  10. use App\Entity\VacationsValidation;
  11. use App\Helper\DateHelper;
  12. use App\Helper\VacationsHelper;
  13. use App\Helper\EmailService;
  14. use Exception;
  15. use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
  16. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  17. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Swift_Mailer;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\HttpFoundation\RedirectResponse;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Response;
  25. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  26. use Psr\Log\LoggerInterface;
  27. use Symfony\Component\HttpFoundation\StreamedResponse;
  28. use Symfony\Contracts\Translation\TranslatorInterface;
  29. class VacationsController extends AbstractController
  30. {
  31.     private $translator;
  32.     public function __construct(TranslatorInterface $translator) {
  33.         $this->translator $translator;
  34.     }
  35.     
  36.     /**
  37.      * @Route("/vacations/description/create", name="vacations_create_descripction", methods={"POST"})
  38.      */
  39.     public function createVacationDescriptionAction(Request $request)
  40.     {
  41.         $description $request->request->get('vacationdescription');
  42. //        d($request, $description);
  43. //        exit();
  44.         if(!empty($description['title']) and !empty($description['days']))
  45.         {
  46.             try{
  47.                 $em $this->getDoctrine()->getManager();
  48.                 /* Obtengo usuario logueado */
  49.                 $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  50.                 $user_id $user_logueado->getId();
  51.                 $vacations = new UserVacationsDescription();
  52.                 $vacations->setTitle($description['title']);
  53.                 $vacations->setDays($description['days']);
  54.                 $vacations->setType($description['type']);
  55.                 $vacations->setUserId($description['userId']);
  56.                 $vacations->setYear($description['year']);
  57.                 $vacations->setCreatedId($user_id);
  58.                 $vacations->setUpdatedId($user_id);
  59.                 //Agregar dias al global de dias
  60.                 if (isset($description['sumar'])){
  61.                     $vacations->setOperate(1);
  62.                     $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  63.                         array(
  64.                             'userId' => $description['userId'],
  65.                             'year' => $description['year'],
  66.                         )
  67.                     );
  68.                     $yearactual date('Y');
  69.                     if (!empty($uservacationday)){
  70.                         $daysdata $uservacationday->getDays() + $description['days'];
  71.                         $halfdaydata $uservacationday->getHalfday() + $description['days'];
  72.                         if ($description['type'] == "vacations"){
  73.                             $uservacationday->setDays($daysdata);
  74.                         }
  75.                         if ($description['type'] == "afternoon"){
  76.                             $uservacationday->setHalfday($halfdaydata);
  77.                         }
  78.                         $uservacationday->setUpdatedId($user_id);
  79.                         $em->persist($uservacationday);
  80.                         if ($description['days'] != "0" AND $yearactual == $description['year'] ){
  81.                             $user $em->getRepository(User::class)->findOneById(
  82.                                 array(
  83.                                     "id" => $description['userId'],
  84.                                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  85.                                 )
  86.                             )
  87.                             ;
  88.                             if ($description['type'] == "vacations"){
  89.                                 $user->setVacations($daysdata);
  90.                             }
  91.                             if ($description['type'] == "afternoon"){
  92.                                 $user->setHalfDays($halfdaydata);
  93.                             }
  94.                             $em->persist($user);
  95.                         }
  96.                     }else{
  97.                         $uservacationday = new UserVacationYearDay();
  98.                         if ($description['type'] == "vacations"){
  99.                             $uservacationday->setDays($description['days']);
  100.                             $uservacationday->setHalfday('0');
  101.                         }
  102.                         if ($description['type'] == "afternoon"){
  103.                             $uservacationday->setDays('0');
  104.                             $uservacationday->setHalfday($description['days']);
  105.                         }
  106.                         $uservacationday->setYear($description['year']);
  107.                         $uservacationday->setCreatedId($user_id);
  108.                         $uservacationday->setUpdatedId($user_id);
  109.                         $em->persist($uservacationday);
  110.                         if ($description['days'] != "0" AND $yearactual == $description['year'] ){
  111.                             $user $em->getRepository(User::class)->findOneById(
  112.                                 array(
  113.                                     "id" => $description['userId'],
  114.                                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  115.                                 )
  116.                             )
  117.                             ;
  118.                             if ($description['type'] == "vacations"){
  119.                                 $user->setVacations($description['days']);
  120.                                 $user->setHalfDays('0');
  121.                             }
  122.                             if ($description['type'] == "afternoon"){
  123.                                 $user->setVacations('0');
  124.                                 $user->setHalfDays($description['days']);
  125.                             }
  126.                             $em->persist($user);
  127.                         }
  128.                     }
  129.                 }else{
  130.                     $vacations->setOperate(0);
  131.                 }
  132.                 $em->persist($vacations);
  133.                 $em->flush();
  134.                 $event 'The description of the holidays were created';
  135.                 $successMessage $this->translator->trans($event);
  136.                 $this->addFlash('mensaje'$successMessage);
  137. //                if(!empty($returnnew)){
  138. //                    $client->setReturnInvestment($returnnew);
  139. //                    $returninvestment = new ReturnInvestment();
  140. //                    $returninvestment->setName($returnnew);
  141. //                    $em->persist($returninvestment);
  142. //                    $em->flush();
  143. //                }
  144.             } catch (Exception $e){
  145.                 $event 'An error occurred: '.$e->getMessage();
  146.                 /* Para el usuario */
  147.                 $errorMessage $this->translator->trans($event);
  148.                 $this->addFlash('mensajeerror'$errorMessage);
  149.             }
  150.         }
  151.         return $this->redirectToRoute('summary_vacations_view_User', array(
  152.                 'id'=> $description['userId'],
  153.                 'year'=> $description['year']
  154.             )
  155.         );
  156.     }
  157.     /**
  158.      * @Route("/vacations/description/delete/{id}", name="user_vacations_description_deleted")
  159.      *
  160.      */
  161.     public function userDescriptionDeleteAction($idRequest $request)
  162.     {
  163.         $em $this->getDoctrine()->getManager();
  164.         $vacationsDay $em->getRepository('App\Entity\UserVacationsDescription')->findOneById($id);
  165.         $userId $vacationsDay->getUserid();
  166.         $year $vacationsDay->getYear();
  167.         if(!empty($vacationsDay)){
  168.             try{
  169.                 if ($vacationsDay->getOperate() == 1){
  170.                     $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  171.                         array(
  172.                             'userId' => $userId,
  173.                             'year' => $year,
  174.                         )
  175.                     );
  176.                     $daysdata $uservacationday->getDays() - $vacationsDay->getDays();
  177.                     $halfdaydata $uservacationday->getHalfday() - $vacationsDay->getDays();
  178.                     if ($vacationsDay->getType() == "vacations"){
  179.                         $uservacationday->setDays($daysdata);
  180.                     }
  181.                     if ($vacationsDay->getType() == "afternoon"){
  182.                         $uservacationday->setHalfday($halfdaydata);
  183.                     }
  184.                     $em->persist($uservacationday);
  185.                     $user $em->getRepository(User::class)->findOneBy(
  186.                         array(
  187.                             "id" => $userId,
  188.                             "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  189.                         )
  190.                     )
  191.                     ;
  192.                     if (!empty($user)){
  193.                         if ($vacationsDay->getType() == "vacations"){
  194.                             $user->setVacations($daysdata);
  195.                         }
  196.                         if ($vacationsDay->getType() == "afternoon"){
  197.                             $user->setHalfDays($halfdaydata);
  198.                         }
  199.                     }
  200.                     $em->persist($user);
  201.                 }
  202.                 $em->remove($vacationsDay);
  203.                 $em->flush();
  204.                 $event 'The Item has been deleted.';
  205.                 $successMessage $this->translator->trans($event);
  206.                 $this->addFlash('mensaje'$successMessage);
  207.             }catch (\Exception $e){
  208.                 $event 'An error occurred: '.$e->getMessage();
  209.                 /* Para el usuario */
  210.                 $errorMessage $this->translator->trans($event);
  211.                 $this->addFlash('mensajeerror'$errorMessage);
  212.             }
  213.         }
  214.         return $this->redirectToRoute('summary_vacations_view_User', array(
  215.                 'id'=> $userId,
  216.                 'year'=> $year
  217.             )
  218.         );
  219.     }
  220.     /**
  221.      * @Route("/vacations/create", name="vacations_create", methods={"POST"})
  222.      * 
  223.      * @param Request $request
  224.      * @param LoggerInterface $logger
  225.      * @param Swift_Mailer $mailer
  226.      * @return RedirectResponse
  227.      * @throws Exception
  228.      */
  229.     public function createAction(Request $requestLoggerInterface $loggerSwift_Mailer $mailer)
  230.     {
  231.         $usersActivesVacationsofOthers $request->request->get('usersActives');
  232.         if(!is_null($usersActivesVacationsofOthers)){
  233.             $usersActivesVacationsofOthers $usersActivesVacationsofOthers['users'];
  234.         }else{
  235.             $usersActivesVacationsofOthers = [$this->getUser()->getId()];
  236.         }
  237.         if(!empty($usersActivesVacationsofOthers)){
  238.             //Se dispone de un administrador solicitando vacaciones para uno o varios empleados
  239.             $description $request->request->get('description');
  240.             $requestedDaysUser$request->request->get('date');
  241.             /* Obtengo usuario logueado */
  242.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  243.             $user_id $user_logueado->getId();
  244.             $em $this->getDoctrine()->getManager();
  245.             $userAdmin $em->getRepository(User::class)->findOneById($user_id);
  246.             $description 'Creada por: '$userAdmin->getName().' '$userAdmin->getLastName().', '$description;
  247.             $requestedDays explode(',',$requestedDaysUser);
  248.             $yearActual date('Y');
  249.             foreach ($usersActivesVacationsofOthers as $loggerUserInID){
  250.                 $vacations = new Vacations();
  251.                 $loggerUserIn $em->getRepository(User::class)->findOneById($loggerUserInID);
  252.                 if(!empty($requestedDaysUser))
  253.                 {
  254.                     // ANTES DE GUARDAR DEBEMOS CONFIRMAR QUE PUEDE SOLICITAR LOS DIAS PRETENDIDOS CALCULANDO LA DIFERENCIA ENTRE DIAS TOTALES Y DIAS YA SOLICITADOS
  255.                     $vacations->setIdu($loggerUserInID);
  256.                     $vacations->setDescription($description);
  257.                     $vacations->setStatus(0);
  258.                     /* Gestión de eventos en Log */
  259.                     $user_lastname $loggerUserIn->getLastname();
  260.                     $user_name $loggerUserIn->getName();
  261.                     $user_email $loggerUserIn->getEmail();
  262.                     $user_rol $loggerUserIn->getRoles();
  263.                     $event_url $request->getPathInfo();
  264.                     $event_complete $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  265.                     $alreadyRequestedDay false;
  266.                     $numRequestedDay count($requestedDays);
  267.                     $requestedDay 0;
  268.                     while ($requestedDay $numRequestedDay && !$alreadyRequestedDay) {
  269.                         $requestedDayDate = new \DateTime($requestedDays[$requestedDay]);
  270.                         $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array(
  271.                                 'idu' => $loggerUserInID,
  272.                                 'date' =>$requestedDayDate
  273.                             )
  274.                         );
  275.                         $alreadyRequestedDay = !empty($vacationsDay);
  276.                         $requestedDay++;
  277.                     }
  278.                     if(!$alreadyRequestedDay){
  279.                         try
  280.                         {
  281.                             $em->persist($vacations);
  282.                             $em->flush();
  283.                             $idv $vacations->getId();
  284.                             foreach ($requestedDays as $requestedDay ) {
  285.                                 $requestedDayDate = new \DateTime($requestedDay);
  286.                                 $vacationBossValidation = new VacationsValidation();
  287.                                 $vacationBossValidation->setIdv($idv);
  288.                                 $vacationBossValidation->setIdu($loggerUserInID);
  289.                                 $vacationBossValidation->setDate($requestedDayDate);
  290.                                 $vacationBossValidation->setStatus(1); // Pending  // Se fija en true
  291.                                 $vacationBossValidation->setStatusBoss(1); // Pending // Se fija en true
  292.                                 $vacationBossValidation->setUpdatedId($loggerUserInID);
  293.                                 $em->persist($vacationBossValidation);
  294.                                 $em->flush();
  295.                                 $event 'The Vacations has been requested. ';
  296.                                 $successMessage $this->translator->trans($event);
  297.                                 $this->addFlash('mensajeholidays'$successMessage);
  298.                                 $logger->info($event_complete.' | '.$event);
  299.                                 // Se actualiza el numero de días disponibles (restadole 1)
  300.                                 $numApprovedDays 1;
  301.                                 $helper = new VacationsHelper($em);
  302.                                 $helper->updateApprovedDaysOfVacations($loggerUserInID$numApprovedDays);
  303.                                 // Se actualiza el numero de días disponibles (restadole 1)
  304.                             }
  305.                             $data = array();
  306.                             $vacations $em->getRepository(Vacations::class)->findOneBy(
  307.                                 array('id' => $idv))
  308.                             ;
  309.                             /**
  310.                              * @var User    $user
  311.                              */
  312.                             $user $em->getRepository(User::class)->findOneBy(
  313.                                 array(
  314.                                     "id" => $vacations->getIdu(),
  315.                                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  316.                                 )
  317.                             )
  318.                             ;
  319.                             /**
  320.                              * @var User    $teamLeader
  321.                              */
  322.                             $teamLeader $em->getRepository(User::class)->findOneBy(
  323.                                 array(
  324.                                     'team'=>$user->getTeam(),
  325.                                     'teamleader'=>VacationsConstants::IS_TEAM_LEADER,
  326.                                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  327.                                 )
  328.                             );
  329.                             if (!empty($teamLeader)){
  330.                                 $idTeamLeader $teamLeader->getId();
  331.                             } else {
  332.                                 $idTeamLeader null;
  333.                             }
  334.                             // This token is stored into the 'vacations' table since is linked to the idv
  335.                             $token md5(VacationsConstants::CR_JDEFrand() * time());
  336.                             $vacations->setToken($token);
  337.                             $em->persist($vacations);
  338.                             $em->flush();
  339.                             // Once we have stored the requested days, an email is sent to the team leader
  340.                             $emails = array();
  341.                             if(!empty($teamLeader)){
  342. //                                $emails = $teamLeader->getEmail();
  343.                                 $emails null;
  344.                             }else{
  345.                                 $adminEmails $em->getRepository(User::class)->findByRole(
  346.                                     array(
  347.                                         "role" => 'ROLE_ADMIN',
  348.                                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  349.                                     )
  350.                                 )
  351.                                 ;
  352.                                 $adminEmails null;
  353.                                 foreach($adminEmails as $adminEmail){
  354.                                     array_push($emails$adminEmail->getEmail());
  355.                                 }
  356.                             }
  357.                             /**
  358.                              * @var VacationsValidation $vacationsDay
  359.                              */
  360.                             $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  361.                             if (!empty($vacationsDay))
  362.                             {
  363.                                 $dataB = array();
  364.                                 /**
  365.                                  * @var VacationsValidation $vacationDay
  366.                                  */
  367.                                 foreach($vacationsDay as $vacationDay) {
  368.                                     $vacationDay->getStatus()?$status='Approved':$status='Rejected';
  369.                                     if(is_null($vacationDay->getStatus())){
  370.                                         $status='Pending';
  371.                                     }
  372.                                     $vacationDay->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  373.                                     if(is_null($vacationDay->getStatusBoss())){
  374.                                         $statusB='Pending';
  375.                                     }
  376.                                     $dataB[] = array(
  377.                                         'id' => $vacationDay->getId(),
  378.                                         'date' => $vacationDay->getDate(),
  379.                                         'status' => $status,
  380.                                         'statusBoss' => $statusB,
  381.                                     );
  382.                                 }
  383.                                 $data = array(
  384.                                     'idv' => $idv,
  385.                                     'days' =>$dataB,
  386.                                     'fullname'=>$user->getName().' '.$user->getLastName(),
  387.                                     'date'=>$vacations->getCreatedAt(),
  388.                                     'role'=>$user->getRole(),
  389.                                 );
  390.                             }
  391.                             $emailService = new EmailService();
  392.                             $emailsDelivered $emailService->sendHTMLEmail(
  393.                                 $emails//TO ADDRESS
  394.                                 'Solicitud de Vacaciones',
  395.                                 $this->renderView(
  396.                                     'vacations/vacations-email-report.html.twig',
  397.                                     array('data' => $data,
  398.                                         'token'=> $token,
  399.                                         'idTeamLeader' => $idTeamLeader,
  400.                                         'isBoss'=> false)
  401.                                 )
  402.                             )
  403.                             ;
  404.                         } catch (\Exception $e){
  405.                             $event 'An error occurred: '.$e->getMessage();
  406.                             /* Para el log */
  407.                             $logger->error($event_complete.' | '.$event);
  408.                             /* Para el usuario */
  409.                             $errorMessage $this->translator->trans($event);
  410.                             $this->addFlash('mensajeerror'$errorMessage);
  411.                         }
  412.                     }else{
  413.                         $event 'You can not select a duplicated day for '.$loggerUserIn->getName().' '.$loggerUserIn->getLastName();   // Se debe reflejar que empleado ya tiene uno de los dias seleccionados
  414.                         /* Para el log */
  415.                         $logger->error($event_complete.' | '.$event);
  416.                         /* Para el usuario */
  417.                         $errorMessage $this->translator->trans($event);
  418.                         $this->addFlash('mensajeerror'$errorMessage);
  419.                     }
  420. //                    return $this->redirectToRoute('summary_vacations_view_User', array(
  421. //                        'id'=> $loggerUserInID,
  422. //                        'year'=> $yearActual
  423. //                    ));
  424.                 }
  425.             }
  426.             if(empty($requestedDaysUser)){
  427.                 $errorMessage $this->translator->trans('Error, some fields are empty');
  428.                 $this->addFlash('mensajeerror'$errorMessage);
  429.             }
  430.             return $this->redirectToRoute('summary_vacations_view_User', array(
  431.                 'id'=> $userAdmin->getId(),
  432.                 'year'=> $yearActual
  433.             ));
  434.         }
  435.         $description $request->request->get('description');
  436.         $requestedDaysUser$request->request->get('date');
  437.         $requestedDays explode(',',$requestedDaysUser);
  438.         $vacations = new Vacations();
  439.         $em $this->getDoctrine()->getManager();
  440.         /* Obtengo usuario logueado */
  441.         $loggerUserIn $this->get('security.token_storage')->getToken()->getUser();
  442.         $loggerUserInID $loggerUserIn->getId();
  443.         $yearActual date('Y');
  444.         if(!empty($requestedDaysUser))
  445.         {
  446.             // ANTES DE GUARDAR DEBEMOS CONDIRMAR QUE PUEDE SOLICITAR LOS DIAS PRETENDIDOS CALCULANDO LA DIFERENCIA ENTRE DIAS TOTALES Y DIAS YA SOLICITADOS
  447.             $vacations->setIdu($loggerUserInID);
  448.             $vacations->setDescription($description);
  449.             $vacations->setStatus(0);
  450.             /* Gestión de eventos en Log */
  451.             $user_lastname $loggerUserIn->getLastname();
  452.             $user_name $loggerUserIn->getName();
  453.             $user_email $loggerUserIn->getEmail();
  454.             $user_rol $loggerUserIn->getRoles();
  455.             $event_url $request->getPathInfo();
  456.             $event_complete $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  457.             $alreadyRequestedDay false;
  458.             $numRequestedDay count($requestedDays);
  459.             $requestedDay 0;
  460.             while ($requestedDay $numRequestedDay && !$alreadyRequestedDay) {
  461.                 $requestedDayDate= new \DateTime($requestedDays[$requestedDay]);
  462.                 $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array(
  463.                         'idu' => $loggerUserInID,
  464.                         'date' =>$requestedDayDate
  465.                     )
  466.                 );
  467.                 $alreadyRequestedDay = !empty($vacationsDay);
  468.                 $requestedDay++;
  469.             }
  470.             if(!$alreadyRequestedDay){
  471.                 try
  472.                 {
  473.                     $em->persist($vacations);
  474.                     $em->flush();
  475.                     $idv=$vacations->getId();
  476.                     foreach ($requestedDays as $requestedDay ) {
  477.                         $requestedDayDate = new \DateTime($requestedDay);
  478.                         $vacationBossValidation=new VacationsValidation();
  479.                         $vacationBossValidation->setIdv($idv);
  480.                         $vacationBossValidation->setIdu($loggerUserInID);
  481.                         $vacationBossValidation->setDate($requestedDayDate);
  482.                         $vacationBossValidation->setStatus(null); // Pending
  483.                         $vacationBossValidation->setStatusBoss(null); // Pending
  484.                         $vacationBossValidation->setUpdatedId($loggerUserInID);
  485.                         $em->persist($vacationBossValidation);
  486.                         $em->flush();
  487.                         $event 'The Vacations has been requested. ';
  488.                         $successMessage $this->translator->trans($event);
  489.                         $this->addFlash('mensajeholidays'$successMessage);
  490.                         $logger->info($event_complete.' | '.$event);
  491.                     }
  492.                     // Se guarda la descripción en la tabla 'user_vacations_description'
  493. //                    $userVacationDescription = new UserVacationsDescription();
  494. //                    $userVacationDescription->setTitle($description);
  495. //                    $userVacationDescription->setDays(count($requestedDays));
  496. //                    $userVacationDescription->setType("vacations");
  497. //                    $userVacationDescription->setUserId($loggerUserInID);
  498. //                    $userVacationDescription->setOperate(0);
  499. //                    $userVacationDescription->setYear($yearActual);
  500. //                    $userVacationDescription->setCreatedId($loggerUserInID);
  501. //                    $userVacationDescription->setCreatedAt(new \DateTime('now'));
  502. //                    $userVacationDescription->setUpdatedId($loggerUserInID);
  503. //                    $userVacationDescription->setUpdatedAt(new \DateTime('now'));
  504. //                    $em->persist($userVacationDescription);
  505. //                    $em->flush();
  506.                     $data=array();
  507.                     $vacations=$em->getRepository(Vacations::class)->findOneBy(
  508.                         array('id' => $idv))
  509.                     ;
  510.                     /**
  511.                      * @var User    $user
  512.                      */
  513.                     $user=$em->getRepository(User::class)->findOneBy(
  514.                         array(
  515.                             "id" => $vacations->getIdu(),
  516.                             "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  517.                         )
  518.                     )
  519.                     ;
  520.                     /**
  521.                      * @var User    $teamLeader
  522.                      */
  523.                     $teamLeader=$em->getRepository(User::class)->findOneBy(
  524.                         array(
  525.                             'team'=>$user->getTeam(),
  526.                             'teamleader'=>VacationsConstants::IS_TEAM_LEADER,
  527.                             "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  528.                         )
  529.                     );
  530.                     $idTeamLeader $teamLeader->getId();
  531.                     // This token is stored into the 'vacations' table since is linked to the idv
  532.                     $token md5(VacationsConstants::CR_JDEFrand() * time());
  533.                     $vacations->setToken($token);
  534.                     $em->persist($vacations);
  535.                     $em->flush();
  536.                     // Once we have stored the requested days, an email is sent to the team leader
  537.                     $emails = array();
  538.                     if(!empty($teamLeader)){
  539.                         $emails=$teamLeader->getEmail();
  540.                     }else{
  541.                         $adminEmails $em->getRepository(User::class)->findByRole(
  542.                             array(
  543.                                 "role" => 'ROLE_ADMIN',
  544.                                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  545.                             )
  546.                         )
  547.                         ;
  548.                         foreach($adminEmails as $adminEmail){
  549.                             array_push($emails$adminEmail->getEmail());
  550.                         }
  551.                     }
  552.                     /**
  553.                      * @var VacationsValidation $vacationsDay
  554.                      */
  555.                     $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  556.                     if (!empty($vacationsDay))
  557.                     {
  558.                         $dataB = array();
  559.                         /**
  560.                          * @var VacationsValidation $vacationDay
  561.                          */
  562.                         foreach($vacationsDay as $vacationDay) {
  563.                             $vacationDay->getStatus()?$status='Approved':$status='Rejected';
  564.                             if(is_null($vacationDay->getStatus())){
  565.                                 $status='Pending';
  566.                             }
  567.                             $vacationDay->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  568.                             if(is_null($vacationDay->getStatusBoss())){
  569.                                 $statusB='Pending';
  570.                             }
  571.                             $dataB[] = array(
  572.                                 'id' => $vacationDay->getId(),
  573.                                 'date' => $vacationDay->getDate(),
  574.                                 'status' => $status,
  575.                                 'statusBoss' => $statusB,
  576.                             );
  577.                         }
  578.                         $data = array(
  579.                             'idv' => $idv,
  580.                             'days' =>$dataB,
  581.                             'fullname'=>$user->getName().' '.$user->getLastName(),
  582.                             'date'=>$vacations->getCreatedAt(),
  583.                             'role'=>$user->getRole(),
  584.                         );
  585.                     }
  586.                     $emailService = new EmailService();
  587.                     $emailsDelivered $emailService->sendHTMLEmail(
  588.                         $emails//TO ADDRESS
  589.                         'Solicitud de Vacaciones',
  590.                         $this->renderView(
  591.                             'vacations/vacations-email-report.html.twig',
  592.                             array('data' => $data,
  593.                                 'token'=> $token,
  594.                                 'idTeamLeader' => $idTeamLeader,
  595.                                 'isBoss'=> false)
  596.                         )
  597.                     )
  598.                     ;
  599.                 } catch (\Exception $e){
  600.                     $event 'An error occurred: '.$e->getMessage();
  601.                     /* Para el log */
  602.                     $logger->error($event_complete.' | '.$event);
  603.                     /* Para el usuario */
  604.                     $errorMessage $this->translator->trans($event);
  605.                     $this->addFlash('mensajeerror'$errorMessage);
  606.                 }
  607.             }else{
  608.                 $event 'You can not select a duplicated day';
  609.                 /* Para el log */
  610.                 $logger->error($event_complete.' | '.$event);
  611.                 /* Para el usuario */
  612.                 $errorMessage $this->translator->trans($event);
  613.                 $this->addFlash('mensajeerror'$errorMessage);
  614.             }
  615.             /* Fin Gestión de eventos en Log */
  616.             return $this->redirectToRoute('summary_vacations_view_User', array(
  617.                 'id'=> $loggerUserInID,
  618.                 'year'=> $yearActual
  619.             ));
  620.         }else{
  621.             $errorMessage $this->translator->trans('Error, some fields are empty');
  622.             $this->addFlash('mensajeerror'$errorMessage);
  623.         }
  624.         //exit();
  625.         //return $this->render('holidays/add-holidays.html.twig', array('form' => $form->createView()));
  626.         return $this->redirectToRoute('summary_vacations_view_User', array(
  627.             'id'=> $loggerUserInID,
  628.             'year'=> $yearActual
  629.         ));
  630.     }
  631.     /**
  632.      * @Route("/vacations/email/{idv}", name="vacations_email")
  633.      *
  634.      */
  635.     public function vacationsEmailAction($idvRequest $requestLoggerInterface $logger)
  636.     {
  637.         $em $this->getDoctrine()->getManager();
  638.         $data=array();
  639.         $vacations=$em->getRepository(Vacations::class)->findOneById($idv);
  640.         $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  641.         $user=$em->getRepository(User::class)->findOneBy(
  642.             array(
  643.                 "id" => $vacations->getIdu(),
  644.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  645.             )
  646.         )
  647.         ;
  648.         $vac_num=$user->getVacations();
  649.         if (!empty($vacationsDay))
  650.         {
  651.             foreach($vacationsDay as $itemB) {
  652.                 $itemB->getStatus()?$status='Approved':$status='Rejected';
  653.                 if(is_null($itemB->getStatus())){
  654.                     $status='Pending';
  655.                 }
  656.                 $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  657.                 if(is_null($itemB->getStatusBoss())){
  658.                     $statusB='Pending';
  659.                 }
  660.                 $dataB[] = array(
  661.                     'id' => $itemB->getId(),
  662.                     'date' => $itemB->getDate(),
  663.                     'status' => $status,
  664.                     'statusBoss' => $statusB,
  665.                 );
  666.             }
  667.             $data = array(
  668.                 'idv' => $idv,
  669.                 'days' =>$dataB,
  670.                 'fullname'=>$user->getName().' '.$user->getLastName(),
  671.                 'date'=>$vacations->getCreatedAt(),
  672.                 'role'=>$user->getRole()
  673.             );
  674.         }
  675.         return $this->render('vacations/vacations-email-report.html.twig',
  676.             array(
  677.                 'data'=>$data,
  678.             )
  679.         );
  680.     }
  681.     /**
  682.      * @Route("/vacations/userEmail/{idv}", name="vacations_user_email")
  683.      *
  684.      */
  685.     public function vacationsUserEmailAction($idvRequest $requestLoggerInterface $logger)
  686.     {
  687.         $em $this->getDoctrine()->getManager();
  688.         $data=array();
  689.         $vacations=$em->getRepository(Vacations::class)->findOneById($idv);
  690.         $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  691.         $user=$em->getRepository(User::class)->findOneById(
  692.             array(
  693.                 "id" => $vacations->getIdu(),
  694.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  695.             )
  696.         )
  697.         ;
  698.         $vac_num=$user->getVacations();
  699.         if (!empty($vacationsDay))
  700.         {
  701.             foreach($vacationsDay as $itemB) {
  702.                 $itemB->getStatus()?$status='Approved':$status='Rejected';
  703.                 if(is_null($itemB->getStatus())){
  704.                     $status='Pending';
  705.                 }
  706.                 $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  707.                 if(is_null($itemB->getStatusBoss())){
  708.                     $statusB='Pending';
  709.                 }
  710.                 $dataB[] = array(
  711.                     'id' => $itemB->getId(),
  712.                     'date' => $itemB->getDate(),
  713.                     'status' => $status,
  714.                     'statusBoss' => $statusB,
  715.                 );
  716.             }
  717.             $data = array(
  718.                 'idv' => $idv,
  719.                 'days' =>$dataB,
  720.                 'fullname'=>$user->getName().' '.$user->getLastName(),
  721.                 'date'=>$vacations->getCreatedAt(),
  722.                 'role'=>$user->getRole()
  723.             );
  724.         }
  725.         //d($data);
  726.         return $this->render('vacations/vacations-email-user-report.html.twig',
  727.             array(
  728.                 'data'=>$data,
  729.             )
  730.         );
  731.     }
  732.     /**
  733.      * @Route("/vacations/deleteBossEdit/{id}/{idu}", name="vacations_deleted_edit")
  734.      *
  735.      */
  736.     public function deleteBossAction($id$iduRequest $requestLoggerInterface $logger)
  737.     {
  738.         $em $this->getDoctrine()->getManager();
  739.         $vacationsDay $em->getRepository(VacationsValidation::class)->findOneById($id);
  740.         if (!empty($vacationsDay))
  741.         {
  742.             try{
  743.                 $em->remove($vacationsDay);
  744.                 $em->flush();
  745.             }
  746.             catch (\Exception $e){
  747.                 $event 'An error occurred: '.$e->getMessage();
  748.                 /* Para el log */
  749.                 $logger->error($event);
  750.                 /* Para el usuario */
  751.                 $errorMessage $this->translator->trans($event);
  752.                 $this->addFlash('mensajeholidayserror'$errorMessage);
  753.             }
  754.         }
  755.         $event 'The Item has been deleted.';
  756.         $successMessage $this->translator->trans($event);
  757.         $this->addFlash('mensajeholidays'$successMessage);
  758.         /* Fin Gestión de eventos en Log */
  759.         return $this->redirect('/vacations/edit/'.$idu.'/'.$vacationsDay->getIdv());
  760.     }
  761.     /**
  762.      * @Route("/vacations/deleteBoss/{id}/{idv}", name="vacations_deleted")
  763.      *
  764.      */
  765. //    public function deleteAction($id, Request $request, LoggerInterface $logger)
  766.     public function deleteAction($id,$idvRequest $requestLoggerInterface $logger)
  767.     {
  768.         $em $this->getDoctrine()->getManager();
  769.         $vacationsDay $em->getRepository(VacationsValidation::class)->findOneById($id);
  770.         if (!empty($vacationsDay))
  771.         {
  772.             try{
  773.                 $em->remove($vacationsDay);
  774.                 $em->flush();
  775.             }
  776.             catch (\Exception $e){
  777.                 $event 'An error occurred: '.$e->getMessage();
  778.                 /* Para el log */
  779.                 $logger->error($event);
  780.                 /* Para el usuario */
  781.                 $errorMessage $this->translator->trans($event);
  782.                 $this->addFlash('mensajeholidayserror'$errorMessage);
  783.             }
  784.         }
  785.         $event 'The Item has been deleted.';
  786.         $successMessage $this->translator->trans($event);
  787.         $this->addFlash('mensajeholidays'$successMessage);
  788.         /* Fin Gestión de eventos en Log */
  789.         return $this->redirect('/vacations/check/'.$idv);
  790.     }
  791.     /**
  792.      * @Route("/vacations/delete/{id}", name="user_vacations_deleted")
  793.      *
  794.      */
  795.     public function userDeleteAction($idRequest $requestLoggerInterface $logger)
  796.     {
  797.         $em $this->getDoctrine()->getManager();
  798.         $vacationsDay $em->getRepository(VacationsValidation::class)->findOneById($id);
  799.         if(!empty($vacationsDay)){
  800.             try{
  801.                 $em->remove($vacationsDay);
  802.                 $em->flush();
  803.             }catch (\Exception $e){
  804.                 $event 'An error occurred: '.$e->getMessage();
  805.                 /* Para el log */
  806.                 $logger->error($event);
  807.                 /* Para el usuario */
  808.                 $errorMessage $this->translator->trans($event);
  809.                 $this->addFlash('mensajeholidayserror'$errorMessage);
  810.             }
  811.         }
  812.         $event 'The Item has been deleted.';
  813.         $successMessage $this->translator->trans($event);
  814.         $this->addFlash('mensajeholidays'$successMessage);
  815.         /* Fin Gestión de eventos en Log */
  816.         return $this->redirect('/vacations/request');
  817.     }
  818. //    /**
  819. //     * @Route("/vacations/request/{id}", defaults={"id" = 0}, name="get_vacations_select")
  820. //     */
  821. //    public function vacationsRequestAction($id, Request $request)
  822. //    {
  823. //
  824. //        $approvedH=0;
  825. //        $pendingH=0;
  826. //        $rejectedH=0;
  827. //        $totalH=0;
  828. //        $em = $this->getDoctrine()->getManager();
  829. //
  830. //        $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  831. //        $user_role = $user_logueado->getRole();
  832. //        if ($user_role == "ROLE_ADMIN" && $id != 0){
  833. //            $user_id = $id;
  834. //        }else{
  835. //            $user_id = $user_logueado->getId();
  836. //        }
  837. //        $query_user = $em->getRepository(User::class)->findOneById($user_id);
  838. //
  839. //        $uservacationday = $em->getRepository('App\Entity\UserVacationYearDay')->findBy(
  840. //            array(
  841. //                'userId' => $user_id
  842. //            )
  843. //        );
  844. //        $datafull = array();
  845. //        foreach($uservacationday as $datos) {
  846. //            $vacations_total =  $datos->getDays();
  847. //            $halfDays_total =  $datos->getHalfday();
  848. //
  849. //            $emConfig = $em->getConfiguration();
  850. //            $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
  851. //
  852. //            $yearActual = $datos->getYear();
  853. //            $yearSiguiente = $yearActual +1;
  854. //
  855. //                $parameters = array(
  856. //                    'idu' => $user_id,
  857. //                    'dateActual'=>$yearActual,
  858. //
  859. //                );
  860. //                    $dql = 'SELECT p
  861. //                            FROM App:Vacations p
  862. //                            WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  863. //                            ORDER BY p.createdAt DESC
  864. //                          ';
  865. //                $query = $em->createQuery($dql)->setParameters($parameters);
  866. //                $vacations= $query->getResult();
  867. //
  868. //
  869. //                $approved=0;
  870. //                $pending=0;
  871. //                $rejected=0;
  872. //                $total=0;
  873. //                $data = array();
  874. //                if(!empty($vacations)){
  875. //                    foreach($vacations as $item) {
  876. //
  877. //                        $dataB = array();
  878. //                        $bossVal = $em->getRepository(VacationsValidation::class)->findBy(
  879. //                            array(
  880. //                                'idv'=>$item->getId()
  881. //                            )
  882. //                        );
  883. //                        if(!empty($bossVal)){
  884. //                            foreach($bossVal as $itemB) {
  885. //                                $total = $total + 1;
  886. //                                if(is_null($itemB->getStatus())){
  887. //                                    $status='Pending';
  888. //                                }else{
  889. //                                    if($itemB->getStatus() ==  true){
  890. //                                        $status='Approved';
  891. //                                    }elseif($itemB->getStatus() ==  false){
  892. //                                        $status='Rejected';
  893. //                                    }
  894. //                                }
  895. //                                if(is_null($itemB->getStatusBoss())){
  896. //                                    $statusB='Pending';
  897. //                                    $pending = $pending + 1;
  898. //                                }else{
  899. //                                    if($itemB->getStatusBoss() ==  true){
  900. //                                        $statusB='Approved';
  901. //                                        $approved = $approved + 1;
  902. //                                    }elseif($itemB->getStatusBoss() ==  false){
  903. //                                        $statusB='Rejected';
  904. //                                        $rejected = $rejected + 1;
  905. //                                    }
  906. //                                }
  907. //
  908. //                                $dataB[$yearActual] = array(
  909. //                                    'id' => $itemB->getId(),
  910. //                                    'idv' => $itemB->getIdv(),
  911. //                                    'date' => $itemB->getDate(),
  912. //                                    'status' => $status,
  913. //                                    'statusBoss' => $statusB,
  914. //                                );
  915. //                            }
  916. //                            $data[$yearActual] = array(
  917. //                                'idv' => $item->getId(),
  918. //                                'bossVal' =>$dataB,
  919. //                            );
  920. //                        }
  921. //
  922. //                    }
  923. //                }
  924. //
  925. //                $parametershd = array(
  926. //                    'idu' => $user_id,
  927. //                    'dateActual'=>$yearActual,
  928. //                );
  929. //
  930. //                $dqlhd = 'SELECT p
  931. //                            FROM App:HalfDay p
  932. //                            WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  933. //                            ORDER BY p.createdAt DESC
  934. //                          ';
  935. //                $queryhd = $em->createQuery($dqlhd)->setParameters($parametershd);
  936. //                $halfDay= $queryhd->getResult();
  937. //
  938. //
  939. //            $approvedH=0;
  940. //            $pending=0;
  941. //            $rejectedH=0;
  942. //            $pendingH=0;
  943. //            $totalH=0;
  944. //                $dataH=array();
  945. //                if(!empty($halfDay)){
  946. //                    foreach($halfDay as $item) {
  947. //
  948. //                        $em = $this->getDoctrine()->getManager();
  949. //                        $bossVal = $em->getRepository(HalfDayValidation::class)->findBy(
  950. //                            array(
  951. //                                'idv'=>$item->getId()
  952. //
  953. //                            )
  954. //                        );
  955. //
  956. //                        $dataBH=array();
  957. //                        foreach($bossVal as $itemB) {
  958. //
  959. //                            $itemB->getStatus()?$status='Approved':$status='Rejected';
  960. //                            if(is_null($itemB->getStatus())){
  961. //                                $status='Pending';
  962. //                            }
  963. //                            $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  964. //                            if(is_null($itemB->getStatusBoss())){
  965. //                                $statusB='Pending';
  966. //                            }
  967. //
  968. //                            if($itemB->getStatusBoss()==1){
  969. //                                $approvedH++;
  970. //                            }else{
  971. //                                is_null($itemB->getStatusBoss())?$pendingH++:$rejectedH++;
  972. //                            }
  973. //
  974. //                            $dataBH[$yearActual] = array(
  975. //                                'id' => $itemB->getId(),
  976. //                                'idv' => $itemB->getIdv(),
  977. //                                'date' => $itemB->getDate(),
  978. //                                'status' => $status,
  979. //                                'statusBoss' => $statusB,
  980. //                                'horario'=>$itemB->getHorario(),
  981. //                            );
  982. //                        }
  983. //
  984. //
  985. //                        $dataH[$yearActual] = array(
  986. //                            'idv' => $item->getId(),
  987. //                            'bossVal' =>$dataBH,
  988. //                        );
  989. //                    }
  990. //
  991. //                }
  992. //
  993. //            $totalH=$approvedH+$rejectedH+$pendingH;
  994. //
  995. //            $remaining = $vacations_total - $total;
  996. //            $remainingH = $halfDays_total - $approvedH;
  997. //            $datafull[$yearActual] = array(
  998. //                'year' => $yearActual,
  999. //                'data' => $data,
  1000. //                'dataHalfDay'=>$dataH,
  1001. //                'vacations'=>$vacations_total,
  1002. //                'approved'=>$approved,
  1003. //                'rejected'=>$rejected,
  1004. //                'remaining'=>$remaining,
  1005. //                'pending'=>$pending,
  1006. //                'total'=>$total,
  1007. //                'halfDays'=>$halfDays_total,
  1008. //                'approvedH'=>$approvedH,
  1009. //                'rejectedH'=>$rejectedH,
  1010. //                'remainingH'=>$remainingH,
  1011. //                'pendingH'=>$pendingH,
  1012. //                'totalH'=>$totalH,
  1013. //            );
  1014. //        }
  1015. //
  1016. //
  1017. //
  1018. //
  1019. //
  1020. ////        $query_user = $em->getRepository(User::class)->findOneById($user_id);
  1021. ////        $vacations_total =  $query_user->getVacations();
  1022. ////        $halfDays_total =  $query_user->getHalfDays();
  1023. //
  1024. ////        $emConfig = $em->getConfiguration();
  1025. ////        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
  1026. ////            $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
  1027. ////            $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
  1028. ////        $parameters = array(
  1029. ////            'idu' => $user_id,
  1030. ////            'dateActual'=>date("Y"),
  1031. ////        );
  1032. ////        $dql = 'SELECT p
  1033. ////                        FROM App:Vacations p
  1034. ////                        WHERE p.idu = :idu
  1035. ////                        AND YEAR(p.createdAt) = :dateActual
  1036. ////                        ORDER BY p.createdAt DESC
  1037. ////                      ';
  1038. //
  1039. //
  1040. //
  1041. ////       d($data,$dataH,$approvedH,$rejectedH,$pendingH,$totalH);
  1042. //        return $this->render('vacations/add-vacations.html.twig', array(
  1043. //            'userName' => $query_user->getName() . ' ' . $query_user->getLastName(),
  1044. ////            'data' => $data,
  1045. //            'datafull' => $datafull,
  1046. //            'idu'=>$user_id
  1047. //        ));
  1048. //    }
  1049.     /**
  1050.      * @Route("/vacations/request/{id}/{year}", defaults={"year" = 0}, name="summary_vacations_view_User")
  1051.      */
  1052.     public function vacationsRequestAdminAction($id$yearRequest $request)
  1053.     {
  1054.         if ($year=='0'){
  1055.             $yearActual date('Y');
  1056.         }else{
  1057.             $yearActual $year;
  1058.         }
  1059. //        exit();
  1060.         $approvedH=0;
  1061.         $pendingH=0;
  1062.         $rejectedH=0;
  1063.         $totalH=0;
  1064.         $em $this->getDoctrine()->getManager();
  1065.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1066.         $user_role $user_logueado->getRole();
  1067.         if ($user_role == "ROLE_ADMIN" && $id != 0){
  1068.             $user_id $id;
  1069.         }else{
  1070.             $user_id $user_logueado->getId();
  1071.         }
  1072.         $query_user $em->getRepository(User::class)->findOneBy(
  1073.             array(
  1074.                 "id" => $user_id,
  1075.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1076.             )
  1077.         )
  1078.         ;
  1079.         $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findBy(
  1080.             array(
  1081.                 'userId' => $user_id,
  1082.                 'year' => $yearActual,
  1083.             )
  1084.         );
  1085.         $datafull = array();
  1086.         $descriptionday = array();
  1087.         foreach($uservacationday as $datos) {
  1088.             $vacations_total =  $datos->getDays();
  1089.             $halfDays_total =  $datos->getHalfday();
  1090.             $emConfig $em->getConfiguration();
  1091.             $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  1092.             $yearSiguiente $yearActual +1;
  1093.             $parameters = array(
  1094.                 'idu' => $user_id,
  1095.                 'dateActual'=>$yearActual,
  1096.             );
  1097.             $dql 'SELECT p
  1098.                             FROM App:Vacations p
  1099.                             WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  1100.                             ORDER BY p.createdAt DESC
  1101.                           ';
  1102.             $query $em->createQuery($dql)->setParameters($parameters);
  1103.             $vacations$query->getResult();
  1104.             $approved=0;
  1105.             $pending=0;
  1106.             $rejected=0;
  1107.             $total=0;
  1108.             $data = array();
  1109.             if(!empty($vacations)){
  1110.                 foreach($vacations as $item) {
  1111.                     $dataB = array();
  1112.                     $bossVal $em->getRepository(VacationsValidation::class)->findBy(
  1113.                         array(
  1114.                             'idv'=>$item->getId()
  1115.                         )
  1116.                     );
  1117. //                        d($bossVal);
  1118.                     if(!empty($bossVal)){
  1119.                         foreach($bossVal as $itemB) {
  1120.                             $total $total 1;
  1121.                             if(is_null($itemB->getStatus())){
  1122.                                 $status='Pending';
  1123.                             }else{
  1124.                                 if($itemB->getStatus() ==  true){
  1125.                                     $status='Approved';
  1126.                                 }elseif($itemB->getStatus() ==  false){
  1127.                                     $status='Rejected';
  1128.                                 }
  1129.                             }
  1130.                             if(is_null($itemB->getStatusBoss())){
  1131.                                 $statusB='Pending';
  1132.                                 $pending $pending 1;
  1133.                             }else{
  1134.                                 if($itemB->getStatusBoss() ==  true){
  1135.                                     $statusB='Approved';
  1136.                                     $approved $approved 1;
  1137.                                 }elseif($itemB->getStatusBoss() ==  false){
  1138.                                     $statusB='Rejected';
  1139.                                     $rejected $rejected 1;
  1140.                                 }
  1141.                             }
  1142.                             $dataB[] = array(
  1143.                                 'id' => $itemB->getId(),
  1144.                                 'idv' => $itemB->getIdv(),
  1145.                                 'date' => $itemB->getDate(),
  1146.                                 'status' => $status,
  1147.                                 'statusBoss' => $statusB,
  1148.                             );
  1149.                         }
  1150.                         $data[] = array(
  1151.                             'idv' => $item->getId(),
  1152.                             'descripction' => $item->getDescription(),
  1153.                             'bossVal' =>$dataB,
  1154.                         );
  1155.                     }
  1156.                 }
  1157.             }
  1158.             $parametershd = array(
  1159.                 'idu' => $user_id,
  1160.                 'dateActual'=>$yearActual,
  1161.             );
  1162.             $dqlhd 'SELECT p
  1163.                             FROM App:HalfDay p
  1164.                             WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  1165.                             ORDER BY p.createdAt DESC
  1166.                           ';
  1167.             $queryhd $em->createQuery($dqlhd)->setParameters($parametershd);
  1168.             $halfDay$queryhd->getResult();
  1169.             $approvedH=0;
  1170.             $pending=0;
  1171.             $rejectedH=0;
  1172.             $pendingH=0;
  1173.             $totalH=0;
  1174.             $dataH=array();
  1175.             if(!empty($halfDay)){
  1176.                 foreach($halfDay as $item) {
  1177.                     $em $this->getDoctrine()->getManager();
  1178.                     $bossVal $em->getRepository(HalfDayValidation::class)->findBy(
  1179.                         array(
  1180.                             'idv'=>$item->getId()
  1181.                         )
  1182.                     );
  1183.                     $dataBH=array();
  1184.                     foreach($bossVal as $itemB) {
  1185.                         $itemB->getStatus()?$status='Approved':$status='Rejected';
  1186.                         if(is_null($itemB->getStatus())){
  1187.                             $status='Pending';
  1188.                         }
  1189.                         $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  1190.                         if(is_null($itemB->getStatusBoss())){
  1191.                             $statusB='Pending';
  1192.                         }
  1193.                         if($itemB->getStatusBoss()==1){
  1194.                             $approvedH++;
  1195.                         }else{
  1196.                             is_null($itemB->getStatusBoss())?$pendingH++:$rejectedH++;
  1197.                         }
  1198.                         $dataBH[] = array(
  1199.                             'id' => $itemB->getId(),
  1200.                             'idv' => $itemB->getIdv(),
  1201.                             'date' => $itemB->getDate(),
  1202.                             'status' => $status,
  1203.                             'statusBoss' => $statusB,
  1204.                             'horario'=>$itemB->getHorario(),
  1205.                         );
  1206.                     }
  1207.                     $dataH[] = array(
  1208.                         'idv' => $item->getId(),
  1209.                         'descripction' => $item->getDescription(),
  1210.                         'bossVal' =>$dataBH,
  1211.                     );
  1212.                 }
  1213.             }
  1214.             $uservacationdescripctionday $em->getRepository('App\Entity\UserVacationsDescription')->findBy(
  1215.                 array(
  1216.                     'userId' => $user_id,
  1217.                     'year' => $yearActual,
  1218.                 )
  1219.             );
  1220.             foreach($uservacationdescripctionday as $descvacauser) {
  1221.                 $descriptionday[$descvacauser->getType()][] = $descvacauser;
  1222.             }
  1223.             $totalH=$approvedH+$rejectedH+$pendingH;
  1224.             $remaining $vacations_total $approved;
  1225.             $remainingH $halfDays_total $approvedH;
  1226.             $datafull[$yearActual] = array(
  1227.                 'year' => $yearActual,
  1228.                 'data' => $data,
  1229.                 'dataHalfDay'=>$dataH,
  1230.                 'vacations'=>$vacations_total,
  1231.                 'approved'=>$approved,
  1232.                 'rejected'=>$rejected,
  1233.                 'remaining'=>$remaining,
  1234.                 'pending'=>$pending,
  1235.                 'total'=>$total,
  1236.                 'halfDays'=>$halfDays_total,
  1237.                 'approvedH'=>$approvedH,
  1238.                 'rejectedH'=>$rejectedH,
  1239.                 'remainingH'=>$remainingH,
  1240.                 'pendingH'=>$pendingH,
  1241.                 'totalH'=>$totalH,
  1242.                 'descriptionday'=>$descriptionday,
  1243.             );
  1244.         }
  1245.         $allActiveUsers $em->getRepository(User::class)->findBy(
  1246.             array(
  1247.                 'status' => 1
  1248.             )
  1249.         );
  1250.         return $this->render('vacations/view-user-vacations.html.twig', array(
  1251.             'userName' => $query_user->getName() . ' ' $query_user->getLastName(),
  1252.             'datafull' => $datafull,
  1253.             'idu'=>$user_id,
  1254.             'year'=>$yearActual,
  1255.             'allActiveUsers'=>$allActiveUsers,
  1256.         ));
  1257.     }
  1258.     /**
  1259.      * @Route("/vacations/activeusers", name="get_active_users")
  1260.      */
  1261.     public function activeUsersAction(Request $request) {
  1262.         $type $_POST['type'];
  1263.         $id $_POST['id'];
  1264.         $em $this->getDoctrine()->getManager();
  1265. //        $allActiveUsers = $em->getRepository(User::class)->findBy(
  1266. //            array(
  1267. //                'status' => 1
  1268. //            )
  1269. //        );
  1270.         $parameters = array(
  1271.             'status' => 1
  1272.         );
  1273.         $dql 'SELECT p
  1274.                         FROM App\Entity\User p
  1275.                         WHERE p.status = :status 
  1276.                         ORDER BY p.name ASC';
  1277.         $query $em->createQuery($dql)->setParameters($parameters);
  1278.         $allActiveUsers $query->getResult();
  1279.         foreach($allActiveUsers as $user){
  1280.             $datos[] = array(
  1281.                 "name" => $user->getName().' '.$user->getLastName(),
  1282.                 "selected" => '',
  1283.                 "id" => $user->getId(),
  1284.             );
  1285.         }
  1286.         $return = array(
  1287.             'users' => $datos,
  1288.         );
  1289.         $response = new JsonResponse($return);
  1290.         return $response;
  1291.     }
  1292.     /**
  1293.      * @Route("/vacations/vacationsofotehrs/{id}/{year}", defaults={"year" = 0}, name="vacations_of_otehrs")
  1294.      */
  1295.     public function vacationsOfOtehrsAction($id$yearRequest $request)
  1296.     {
  1297.         if ($year=='0'){
  1298.             $yearActual date('Y');
  1299.         }else{
  1300.             $yearActual $year;
  1301.         }
  1302. //        exit();
  1303.         $approvedH=0;
  1304.         $pendingH=0;
  1305.         $rejectedH=0;
  1306.         $totalH=0;
  1307.         $em $this->getDoctrine()->getManager();
  1308.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1309.         $user_role $user_logueado->getRole();
  1310.         if ($user_role == "ROLE_ADMIN" && $id != 0){
  1311.             $user_id $id;
  1312.         }else{
  1313.             $user_id $user_logueado->getId();
  1314.         }
  1315.         $query_user $em->getRepository(User::class)->findOneBy(
  1316.             array(
  1317.                 "id" => $user_id,
  1318.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1319.             )
  1320.         )
  1321.         ;
  1322.         $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findBy(
  1323.             array(
  1324.                 'userId' => $user_id,
  1325.                 'year' => $yearActual,
  1326.             )
  1327.         );
  1328.         $datafull = array();
  1329.         $descriptionday = array();
  1330.         foreach($uservacationday as $datos) {
  1331.             $vacations_total =  $datos->getDays();
  1332.             $halfDays_total =  $datos->getHalfday();
  1333.             $emConfig $em->getConfiguration();
  1334.             $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  1335.             $yearSiguiente $yearActual +1;
  1336.             $parameters = array(
  1337.                 'idu' => $user_id,
  1338.                 'dateActual'=>$yearActual,
  1339.             );
  1340.             $dql 'SELECT p
  1341.                             FROM App:Vacations p
  1342.                             WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  1343.                             ORDER BY p.createdAt DESC
  1344.                           ';
  1345.             $query $em->createQuery($dql)->setParameters($parameters);
  1346.             $vacations$query->getResult();
  1347.             $approved=0;
  1348.             $pending=0;
  1349.             $rejected=0;
  1350.             $total=0;
  1351.             $data = array();
  1352.             if(!empty($vacations)){
  1353.                 foreach($vacations as $item) {
  1354.                     $dataB = array();
  1355.                     $bossVal $em->getRepository(VacationsValidation::class)->findBy(
  1356.                         array(
  1357.                             'idv'=>$item->getId()
  1358.                         )
  1359.                     );
  1360. //                        d($bossVal);
  1361.                     if(!empty($bossVal)){
  1362.                         foreach($bossVal as $itemB) {
  1363.                             $total $total 1;
  1364.                             if(is_null($itemB->getStatus())){
  1365.                                 $status='Pending';
  1366.                             }else{
  1367.                                 if($itemB->getStatus() ==  true){
  1368.                                     $status='Approved';
  1369.                                 }elseif($itemB->getStatus() ==  false){
  1370.                                     $status='Rejected';
  1371.                                 }
  1372.                             }
  1373.                             if(is_null($itemB->getStatusBoss())){
  1374.                                 $statusB='Pending';
  1375.                                 $pending $pending 1;
  1376.                             }else{
  1377.                                 if($itemB->getStatusBoss() ==  true){
  1378.                                     $statusB='Approved';
  1379.                                     $approved $approved 1;
  1380.                                 }elseif($itemB->getStatusBoss() ==  false){
  1381.                                     $statusB='Rejected';
  1382.                                     $rejected $rejected 1;
  1383.                                 }
  1384.                             }
  1385.                             $dataB[] = array(
  1386.                                 'id' => $itemB->getId(),
  1387.                                 'idv' => $itemB->getIdv(),
  1388.                                 'date' => $itemB->getDate(),
  1389.                                 'status' => $status,
  1390.                                 'statusBoss' => $statusB,
  1391.                             );
  1392.                         }
  1393.                         $data[] = array(
  1394.                             'idv' => $item->getId(),
  1395.                             'descripction' => $item->getDescription(),
  1396.                             'bossVal' =>$dataB,
  1397.                         );
  1398.                     }
  1399.                 }
  1400.             }
  1401.             $parametershd = array(
  1402.                 'idu' => $user_id,
  1403.                 'dateActual'=>$yearActual,
  1404.             );
  1405.             $dqlhd 'SELECT p
  1406.                             FROM App:HalfDay p
  1407.                             WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  1408.                             ORDER BY p.createdAt DESC
  1409.                           ';
  1410.             $queryhd $em->createQuery($dqlhd)->setParameters($parametershd);
  1411.             $halfDay$queryhd->getResult();
  1412.             $approvedH=0;
  1413.             $pending=0;
  1414.             $rejectedH=0;
  1415.             $pendingH=0;
  1416.             $totalH=0;
  1417.             $dataH=array();
  1418.             if(!empty($halfDay)){
  1419.                 foreach($halfDay as $item) {
  1420.                     $em $this->getDoctrine()->getManager();
  1421.                     $bossVal $em->getRepository(HalfDayValidation::class)->findBy(
  1422.                         array(
  1423.                             'idv'=>$item->getId()
  1424.                         )
  1425.                     );
  1426.                     $dataBH=array();
  1427.                     foreach($bossVal as $itemB) {
  1428.                         $itemB->getStatus()?$status='Approved':$status='Rejected';
  1429.                         if(is_null($itemB->getStatus())){
  1430.                             $status='Pending';
  1431.                         }
  1432.                         $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  1433.                         if(is_null($itemB->getStatusBoss())){
  1434.                             $statusB='Pending';
  1435.                         }
  1436.                         if($itemB->getStatusBoss()==1){
  1437.                             $approvedH++;
  1438.                         }else{
  1439.                             is_null($itemB->getStatusBoss())?$pendingH++:$rejectedH++;
  1440.                         }
  1441.                         $dataBH[] = array(
  1442.                             'id' => $itemB->getId(),
  1443.                             'idv' => $itemB->getIdv(),
  1444.                             'date' => $itemB->getDate(),
  1445.                             'status' => $status,
  1446.                             'statusBoss' => $statusB,
  1447.                             'horario'=>$itemB->getHorario(),
  1448.                         );
  1449.                     }
  1450.                     $dataH[] = array(
  1451.                         'idv' => $item->getId(),
  1452.                         'descripction' => $item->getDescription(),
  1453.                         'bossVal' =>$dataBH,
  1454.                     );
  1455.                 }
  1456.             }
  1457.             $uservacationdescripctionday $em->getRepository('App\Entity\UserVacationsDescription')->findBy(
  1458.                 array(
  1459.                     'userId' => $user_id,
  1460.                     'year' => $yearActual,
  1461.                 )
  1462.             );
  1463.             foreach($uservacationdescripctionday as $descvacauser) {
  1464.                 $descriptionday[$descvacauser->getType()][] = $descvacauser;
  1465.             }
  1466.             $totalH=$approvedH+$rejectedH+$pendingH;
  1467.             $remaining $vacations_total $approved;
  1468.             $remainingH $halfDays_total $approvedH;
  1469.             $datafull[$yearActual] = array(
  1470.                 'year' => $yearActual,
  1471.                 'data' => $data,
  1472.                 'dataHalfDay'=>$dataH,
  1473.                 'vacations'=>$vacations_total,
  1474.                 'approved'=>$approved,
  1475.                 'rejected'=>$rejected,
  1476.                 'remaining'=>$remaining,
  1477.                 'pending'=>$pending,
  1478.                 'total'=>$total,
  1479.                 'halfDays'=>$halfDays_total,
  1480.                 'approvedH'=>$approvedH,
  1481.                 'rejectedH'=>$rejectedH,
  1482.                 'remainingH'=>$remainingH,
  1483.                 'pendingH'=>$pendingH,
  1484.                 'totalH'=>$totalH,
  1485.                 'descriptionday'=>$descriptionday,
  1486.             );
  1487.         }
  1488.         $allActiveUsers $em->getRepository(User::class)->findBy(
  1489.             array(
  1490.                 'status' => 1
  1491.             )
  1492.         );
  1493.         return $this->render('vacations/view-user-others-vacations.html.twig', array(
  1494.             'userName' => $query_user->getName() . ' ' $query_user->getLastName(),
  1495.             'datafull' => $datafull,
  1496.             'idu'=>$user_id,
  1497.             'year'=>$yearActual,
  1498.             'allActiveUsers'=>$allActiveUsers,
  1499.         ));
  1500.     }
  1501.     /**
  1502.      * @Route("/vacations/listTeamLeader", name="validate_vacations_list_team_leader")
  1503.      * @param Request $request
  1504.      * @return Response
  1505.      */
  1506.     public function vacationsTeamLeaderListAction(Request $request)
  1507.     {
  1508.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1509.         $user_id $user_logueado->getId();
  1510.         $em $this->getDoctrine()->getManager();
  1511.         $teamLeader $em->getRepository(User::class)->findOneById(
  1512.             array(
  1513.                 "id" => $user_id,
  1514.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1515.             )
  1516.         )
  1517.         ;
  1518.         $team=$teamLeader->getTeamLeader();
  1519.         $flag=1;
  1520.         $data = array();
  1521.         if($team){
  1522.             $users=$em->getRepository(User::class)->findBy(
  1523.                 array(
  1524.                     'team'=>$teamLeader->getTeam(),
  1525.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1526.                 )
  1527.             )
  1528.             ;
  1529.             $emConfig $em->getConfiguration();
  1530.             $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  1531.             foreach ($users  as $itemUsers){
  1532. //        $vacations = $em->getRepository(Vacations::class)->findBy(array('idu'=>$itemUsers->getId()));
  1533. //            $parameters = array(
  1534. //                'dateActual'=>date("Y"),
  1535. //                'userId'=>$itemUsers->getId(),
  1536. //            );
  1537. //            $dql = 'SELECT p
  1538. //                        FROM App:Vacations p
  1539. //                        WHERE YEAR(p.createdAt) = :dateActual
  1540. //                        AND p.idu = :userId
  1541. //                        ORDER BY p.createdAt DESC
  1542. //                      ';
  1543.                 // Enero dia 30
  1544.                 $yearActual date('Y');
  1545.                 $yearSiguiente $yearActual +1;
  1546.                 $parameters = array(
  1547.                     'idu' => $itemUsers->getId(),
  1548. //                'dateActual'=>$yearActual."-1-30",
  1549. //                'dateSiguiente'=>$yearSiguiente."-1-30",
  1550.                 );
  1551. //            $dql = 'SELECT p
  1552. //                        FROM App:Vacations p
  1553. //                        WHERE p.idu = :idu  AND (p.createdAt >= :dateActual AND p.createdAt <= :dateSiguiente )
  1554. //                        ORDER BY p.createdAt DESC
  1555. //                      ';
  1556.                 $dql 'SELECT p
  1557.                         FROM App:Vacations p
  1558.                         WHERE p.idu = :idu 
  1559.                         ORDER BY p.createdAt DESC
  1560.                       ';
  1561.                 $query $em->createQuery($dql)->setParameters($parameters);
  1562.                 $vacations$query->getResult();
  1563.                 $dataF = array();
  1564.                 if(!empty($vacations)){
  1565.                     foreach($vacations as $item) {
  1566.                         $dataF = array();
  1567.                         $validation $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$item->getId()),array('date'=>'ASC'));
  1568.                         // d($validation);
  1569.                         $num=sizeof($validation);
  1570.                         $users $em->getRepository(User::class)->findOneBy(
  1571.                             array(
  1572.                                 'id'=>$item->getIdu(),
  1573.                                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1574.                             )
  1575.                         )
  1576.                         ;
  1577.                         foreach($validation as $itemF) {
  1578.                             $itemF->getStatus()?$status='Approved':$status='Rejected';
  1579.                             if(is_null($itemF->getStatus()) ){
  1580.                                 $status='Pending';
  1581.                             }
  1582.                             $dataF[] = array(
  1583.                                 'id' => $itemF->getId(),
  1584.                                 'idv' => $itemF->getIdv(),
  1585.                                 'date' => $itemF->getDate(),
  1586.                                 'status' => $status,
  1587.                             );
  1588.                         }
  1589.                         $item->getStatusLeader()?$statLeader='Validated':$statLeader='Pending';
  1590.                         //$item->getStatusLeader()?$color='#66BB6A':$color='#42A5F5';
  1591.                         $item->getStatus()==1?$stat='Validated':$stat='Pending';
  1592.                         //$item->getStatus()?$color='#66BB6A':$color='#42A5F5';
  1593.                         if($statLeader=='Validated' ){
  1594.                             $color='#66BB6A';
  1595.                         }else{
  1596.                             $color='#42A5F5';
  1597.                         }
  1598.                         $data[] = array(
  1599.                             'idv' => $item->getId(),
  1600.                             'idu'=>$users->getId(),
  1601.                             'fullname'=> $users->getName().' '.$users->getLastname(),
  1602.                             'description'=>$item->getDescription(),
  1603.                             'validation'=>$dataF,
  1604.                             'status'=>$statLeader,
  1605.                             'statusLeader'=>$statLeader,
  1606.                             'days'=>$num,
  1607.                             'color'=>$color,
  1608.                             'created'=>$item->getCreatedAt(),
  1609.                         );
  1610.                     }
  1611.                 }else{
  1612.                     // $data = array();
  1613.                 }
  1614.             }
  1615.         }else{
  1616.             $flag=0;
  1617.         }
  1618.         return $this->render('vacations/list-vacations-team-leader.html.twig', array(
  1619.             'data' => $data,
  1620.             'isTeamLeader'=>$flag
  1621.         ));
  1622.     }
  1623. //    /**
  1624. //     * @Route("/vacations/list/{status}", defaults={"status" = "0"}, name="validate_vacations_list")
  1625. //     * @param Request $request
  1626. //     * @param $status
  1627. //     * @return Response
  1628. //     */
  1629. //    public function vacationsListAction(Request $request, $status)
  1630. //    {
  1631. //        $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  1632. //        $user_id = $user_logueado->getId();
  1633. //
  1634. //        $em = $this->getDoctrine()->getManager();
  1635. //        // $vacations = $em->getRepository(Vacations::class)->findAll();
  1636. //        $emConfig = $em->getConfiguration();
  1637. //        //$emConfig = $this->getEntityManager()->getConfiguration();
  1638. //        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
  1639. ////        $parameters = array(
  1640. ////            'dateActual'=>date("Y"),
  1641. ////            'status'=> $status,
  1642. ////        );
  1643. ////        $dql = 'SELECT p
  1644. ////                        FROM App:Vacations p
  1645. ////                        WHERE YEAR(p.createdAt) = :dateActual AND p.status = :status
  1646. ////                        ORDER BY p.createdAt DESC
  1647. ////                      ';
  1648. //        // Enero dia 30
  1649. //        $yearActual = date('Y');
  1650. ////        $yearSiguiente = $yearActual +1;
  1651. //        $parameters = array(
  1652. //            'dateActual'=>$yearActual,
  1653. ////            'dateSiguiente'=>$yearSiguiente."-1-30",
  1654. //            'status'=> $status,
  1655. //        );
  1656. ////        $dql = 'SELECT p
  1657. ////                        FROM App:Vacations p
  1658. ////                        WHERE  p.status = :status AND (p.createdAt >= :dateActual AND p.createdAt <= :dateSiguiente )
  1659. ////                        ORDER BY p.createdAt DESC
  1660. ////                      ';
  1661. //        $dql = 'SELECT p
  1662. //                        FROM App:Vacations p
  1663. //                        WHERE  p.status = :status AND p.createdAt >= :dateActual
  1664. //                        ORDER BY p.createdAt DESC
  1665. //                      ';
  1666. //
  1667. //        $query = $em->createQuery($dql)->setParameters($parameters);
  1668. //        $vacations= $query->getResult();
  1669. //
  1670. //        $data = array();
  1671. //        $user= $em->getRepository(User::class)->findOneById(
  1672. //            array(
  1673. //                "id" => $user_id,
  1674. //                "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1675. //            )
  1676. //        )
  1677. //        ;
  1678. //
  1679. //        if(!empty($vacations)){
  1680. //            /**
  1681. //             * @var Vacations   $item
  1682. //             */
  1683. //            foreach($vacations as $item) {
  1684. //                $flag=1;
  1685. ////                $yearActual = $item->getCreatedAt()->format('Y');
  1686. ////                $yearSiguiente = $yearActual +1;
  1687. ////                $parametersval = array(
  1688. ////                    'dateActual'=>$yearActual."-1-30",
  1689. ////                    'dateSiguiente'=>$yearSiguiente."-1-30",
  1690. ////                    'idv'=> $item->getId(),
  1691. ////                );
  1692. ////                $dqlval = 'SELECT p
  1693. ////                        FROM App:VacationsValidation p
  1694. ////                        WHERE p.idv = :idv  AND (p.date >= :dateActual AND p.date <= :dateSiguiente )
  1695. ////                        ORDER BY p.date ASC
  1696. ////                      ';
  1697. ////                $queryvali = $em->createQuery($dqlval)->setParameters($parametersval);
  1698. ////                $validation = $queryvali->getResult();
  1699. //
  1700. //
  1701. //                $validation = $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$item->getId()),array('date'=>'ASC'));
  1702. //                $num=sizeof($validation);
  1703. //                $users = $em->getRepository(User::class)->findOneBy(
  1704. //                    array(
  1705. //                        'id'=>$item->getIdu(),
  1706. //                        "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1707. //                    )
  1708. //                )
  1709. //                ;
  1710. //                if(!empty($users)){
  1711. //
  1712. //                    $dataF = array();
  1713. //                    /**
  1714. //                     * @var VacationsValidation $itemF
  1715. //                     */
  1716. //                    foreach($validation as $itemF) {
  1717. ////                        d($itemF);
  1718. //
  1719. //                        if($itemF->getStatusBoss()==1 ){
  1720. //                            $status='Approved';
  1721. //                        }
  1722. //                        if($itemF->getStatusBoss()==0 ){
  1723. //                            $status='Rejected';
  1724. //                        }
  1725. //                        if(is_null($itemF->getStatusBoss()) ){
  1726. //                            $status='Pending';
  1727. //                            $flag=0;
  1728. //                        }
  1729. //                        $dataF[] = array(
  1730. //                            'id' => $itemF->getId(),
  1731. //                            'idv' => $itemF->getIdv(),
  1732. //                            'date' => $itemF->getDate(),
  1733. //                            'status' => $status,
  1734. //
  1735. //                        );
  1736. //                    }
  1737. //
  1738. //                    $item->getStatus()?$stat='Approved':$stat='Pending';
  1739. //                    $item->getStatus()?$color='#66BB6A':$color='#42A5F5';
  1740. //                    $data[] = array(
  1741. //                        'idv' => $item->getId(),
  1742. //                        'idu'=>$users->getId(),
  1743. //                        'fullname'=> $users->getName().' '.$users->getLastname(),
  1744. //                        'description'=>$item->getDescription(),
  1745. //                        'validation'=>$dataF,
  1746. //                        'status'=>$stat,
  1747. //                        'days'=>$num,
  1748. //                        'color'=>$color,
  1749. //                        'created'=>$item->getCreatedAt(),
  1750. //                        'validate'=>$flag
  1751. //                    );
  1752. //
  1753. //                }
  1754. //
  1755. //            }
  1756. //
  1757. //        }
  1758. //        return $this->render('vacations/list-vacations.html.twig', array(
  1759. //            'data' => $data,
  1760. //            'role'=>$user->getRole(),
  1761. //            "status" => $status
  1762. //        ));
  1763. //    }
  1764.     /**
  1765.      * @Route("/vacations/listHistoric/{status}", defaults={"status" = "1"}, name="validate_vacations_list_Historic")
  1766.      * @param Request $request
  1767.      * @param $status
  1768.      * @return Response
  1769.      */
  1770.     public function vacationsListHistoricAction(Request $request$status)
  1771.     {
  1772.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1773.         $user_id $user_logueado->getId();
  1774.         $em $this->getDoctrine()->getManager();
  1775.         // $vacations = $em->getRepository(Vacations::class)->findAll();
  1776.         $emConfig $em->getConfiguration();
  1777.         //$emConfig = $this->getEntityManager()->getConfiguration();
  1778.         $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  1779. //        $parameters = array(
  1780. //            'dateActual'=>date("Y"),
  1781. //            'status'=> $status,
  1782. //        );
  1783. //        $dql = 'SELECT p
  1784. //                        FROM App:Vacations p
  1785. //                        WHERE YEAR(p.createdAt) = :dateActual AND p.status = :status
  1786. //                        ORDER BY p.createdAt DESC
  1787. //                      ';
  1788.         // Enero dia 30
  1789.         $yearActual date('Y');
  1790. //        $yearSiguiente = $yearActual +1;
  1791.         $parameters = array(
  1792.             'dateActual'=>$yearActual,
  1793. //            'dateSiguiente'=>$yearSiguiente."-1-30",
  1794.             'status'=> $status,
  1795.         );
  1796. //        $dql = 'SELECT p
  1797. //                        FROM App:Vacations p
  1798. //                        WHERE  p.status = :status AND (p.createdAt >= :dateActual AND p.createdAt <= :dateSiguiente )
  1799. //                        ORDER BY p.createdAt DESC
  1800. //                      ';
  1801.         $dql 'SELECT p
  1802.                         FROM App:Vacations p
  1803.                         WHERE  p.status = :status AND p.createdAt < :dateActual
  1804.                         ORDER BY p.createdAt DESC
  1805.                       ';
  1806.         $query $em->createQuery($dql)->setParameters($parameters);
  1807.         $vacations$query->getResult();
  1808.         $data = array();
  1809.         $user$em->getRepository(User::class)->findOneById(
  1810.             array(
  1811.                 "id" => $user_id,
  1812.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1813.             )
  1814.         )
  1815.         ;
  1816.         if(!empty($vacations)){
  1817.             foreach($vacations as $item) {
  1818.                 $flag=1;
  1819. //                $yearActual = $item->getCreatedAt()->format('Y');
  1820. //                $yearSiguiente = $yearActual +1;
  1821. //                $parametersval = array(
  1822. //                    'dateActual'=>$yearActual."-1-30",
  1823. //                    'dateSiguiente'=>$yearSiguiente."-1-30",
  1824. //                    'idv'=> $item->getId(),
  1825. //                );
  1826. //                $dqlval = 'SELECT p
  1827. //                        FROM App:VacationsValidation p
  1828. //                        WHERE p.idv = :idv  AND (p.date >= :dateActual AND p.date <= :dateSiguiente )
  1829. //                        ORDER BY p.date ASC
  1830. //                      ';
  1831. //                $queryvali = $em->createQuery($dqlval)->setParameters($parametersval);
  1832. //                $validation = $queryvali->getResult();
  1833.                 $validation $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$item->getId()),array('date'=>'ASC'));
  1834.                 $num=sizeof($validation);
  1835.                 $users $em->getRepository(User::class)->findOneBy(
  1836.                     array(
  1837.                         'id'=>$item->getIdu(),
  1838.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1839.                     )
  1840.                 )
  1841.                 ;
  1842.                 if(!empty($users)){
  1843.                     $dataF = array();
  1844.                     foreach($validation as $itemF) {
  1845. //                        d($itemF);
  1846.                         if($itemF->getStatus()==){
  1847.                             $status='Approved';
  1848.                         }
  1849.                         if($itemF->getStatus()==){
  1850.                             $status='Rejected';
  1851.                         }
  1852.                         if(is_null($itemF->getStatus()) ){
  1853.                             $status='Pending';
  1854.                             $flag=0;
  1855.                         }
  1856.                         $dataF[] = array(
  1857.                             'id' => $itemF->getId(),
  1858.                             'idv' => $itemF->getIdv(),
  1859.                             'date' => $itemF->getDate(),
  1860.                             'status' => $status,
  1861.                         );
  1862.                     }
  1863.                     $item->getStatus()?$stat='Approved':$stat='Pending';
  1864.                     $item->getStatus()?$color='#66BB6A':$color='#42A5F5';
  1865.                     $data[] = array(
  1866.                         'idv' => $item->getId(),
  1867.                         'idu'=>$users->getId(),
  1868.                         'fullname'=> $users->getName().' '.$users->getLastname(),
  1869.                         'description'=>$item->getDescription(),
  1870.                         'validation'=>$dataF,
  1871.                         'status'=>$stat,
  1872.                         'days'=>$num,
  1873.                         'color'=>$color,
  1874.                         'created'=>$item->getCreatedAt(),
  1875.                         'validate'=>$flag
  1876.                     );
  1877.                 }
  1878.             }
  1879.         }
  1880.         return $this->render('vacations/list-vacations.html.twig', array(
  1881.             'data' => $data,
  1882.             'role'=>$user->getRole(),
  1883.             "status" => $status,
  1884.             'year' => $yearActual
  1885.         ));
  1886.     }
  1887.     /**
  1888.      * @deprecated  No longer called
  1889.      * @Route("/vacations/fastValidateBoss/{idv}", name="fast_validate_boss_vacations")
  1890.      * @param Request $request
  1891.      * @param Swift_Mailer $mailer
  1892.      * @param $idv
  1893.      * @return JsonResponse
  1894.      */
  1895.     public function vacationsBossFastValidationAction(Request $request, \Swift_Mailer $mailer$idv )
  1896.     {
  1897.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1898.         $user_id $user_logueado->getId();
  1899.         $em $this->getDoctrine()->getManager();
  1900.         $vacations=$em->getRepository(Vacations::class)->findOneById($idv);
  1901.         $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  1902.         if (!empty($vacations))
  1903.         {
  1904. //            $vacations->setStatus(true);
  1905.             try{
  1906.                 if (!empty($vacationsDay))
  1907.                 {
  1908.                     foreach($vacationsDay as $itemB) {
  1909.                         $itemB->setStatusBoss($itemB->getStatus());
  1910.                         $em->persist($itemB);
  1911.                         $em->flush();
  1912.                     }
  1913.                 }
  1914.                 $em->persist($vacations);
  1915.                 $em->flush();
  1916.                 $data=array();
  1917.                 $vacations=$em->getRepository(Vacations::class)->findOneById($idv);
  1918.                 $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  1919.                 $user=$em->getRepository(User::class)->findOneById(
  1920.                     array(
  1921.                         "id" => $vacations->getIdu(),
  1922.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1923.                     )
  1924.                 )
  1925.                 ;
  1926.                 if (!empty($vacationsDay))
  1927.                 {
  1928.                     foreach($vacationsDay as $itemB) {
  1929.                         $itemB->getStatus()?$status='Approved':$status='Rejected';
  1930.                         if(is_null($itemB->getStatus())){
  1931.                             $status='Pending';
  1932.                         }
  1933.                         $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  1934.                         if(is_null($itemB->getStatusBoss())){
  1935.                             $statusB='Pending';
  1936.                         }
  1937.                         $dataB[] = array(
  1938.                             'id' => $itemB->getId(),
  1939.                             'date' => $itemB->getDate(),
  1940.                             'status' => $status,
  1941.                             'statusBoss' => $statusB,
  1942.                         );
  1943.                     }
  1944.                     $data = array(
  1945.                         'idv' => $idv,
  1946.                         'days' =>$dataB,
  1947.                         'fullname'=>$user->getName().' '.$user->getLastName(),
  1948.                         'date'=>$vacations->getCreatedAt(),
  1949.                         'role'=>$user->getRole()
  1950.                     );
  1951.                 }
  1952.                 $message = (new \Swift_Message())
  1953.                     ->setSubject('Solicitud de Vacaciones')
  1954.                     ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  1955.                     ->setTo($user->getEmail())
  1956.                     ->setBody(
  1957.                         $this->renderView(
  1958.                             'vacations/vacations-email-user-report.html.twig',
  1959.                             array('data' => $data)
  1960.                         ),'text/html'
  1961.                     );
  1962.                 $mailer->send($message);
  1963.                 $teamLeader=$em->getRepository(User::class)->findOneBy(array(
  1964.                         'team'=>$user->getTeam(),
  1965.                         'teamleader'=>VacationsConstants::IS_TEAM_LEADER,
  1966.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  1967.                     )
  1968.                 );
  1969.                 if(!empty($teamLeader)) {
  1970.                     $message = (new \Swift_Message())
  1971.                         ->setSubject('Solicitud de Vacaciones Validada')
  1972.                         ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  1973.                         ->setTo($teamLeader->getEmail())
  1974.                         ->setBody(
  1975.                             $this->renderView(
  1976.                                 'vacations/vacations-email-report.html.twig',
  1977.                                 array('data' => $data)
  1978.                             ),'text/html'
  1979.                         );
  1980.                     $mailer->send($message);
  1981.                 }
  1982.                 $message=1;
  1983.             }
  1984.             catch (\Exception $e){
  1985.                 $event 'An error occurred: '.$e->getMessage();
  1986.                 /* Para el log */
  1987.                 // $logger->error($event);
  1988.                 /* Para el usuario */
  1989.                 $errorMessage $this->translator->trans($event);
  1990.                 $this->addFlash('mensajeholidayserror'$errorMessage);
  1991.                 $message0;
  1992.             }
  1993.         }
  1994.         $event 'The request has ben Validated.';
  1995.         $successMessage $this->translator->trans($event);
  1996.         $this->addFlash('mensajeholidays'$successMessage);
  1997. //        return $this->redirect('/vacations/list');
  1998.         $response = new JsonResponse($message);
  1999.         return $response;
  2000.     }
  2001.     /**
  2002.      * @Route("/vacations/preView/{idu}/{idv}", name="preview_vacations")
  2003.      * @param $idu
  2004.      * @param $idv
  2005.      * @param Request $request
  2006.      * @return Response
  2007.      */
  2008.     public function vacationsPreviewAction($idu$idvRequest $request)
  2009.     {
  2010.         $em $this->getDoctrine()->getManager();
  2011.         $emConfig $em->getConfiguration();
  2012.         $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  2013. //        $parameters = array(
  2014. //            'dateActual'=>date("Y"),
  2015. //            'userId'=>$idu,
  2016. //        );
  2017. //        $dql = 'SELECT p
  2018. //                        FROM App:Vacations p
  2019. //                        WHERE YEAR(p.createdAt) = :dateActual
  2020. //                        AND p.idu = :userId
  2021. //                        ORDER BY p.createdAt DESC
  2022. //                      ';
  2023.         $solicitudperiodo $em->getRepository(Vacations::class)->findOneById($idv);
  2024.         // Enero dia 30
  2025. //        $yearActual = date('Y');
  2026.         $yearActual $solicitudperiodo->getCreatedAt()->format('Y');
  2027.         $yearSiguiente $yearActual +1;
  2028.         $parameters = array(
  2029.             'idu' => $idu,
  2030.             'dateActual'=>$yearActual,
  2031. //            'dateSiguiente'=>$yearSiguiente."-1-30",
  2032.         );
  2033.         // (p.createdAt >= :dateActual AND p.createdAt <= :dateSiguiente )
  2034.         $dql 'SELECT p
  2035.                         FROM App:Vacations p
  2036.                         WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  2037.                         ORDER BY p.createdAt DESC
  2038.                       ';
  2039.         $query $em->createQuery($dql)->setParameters($parameters);
  2040.         $vacations$query->getResult();
  2041.         $approved=0;
  2042.         $pending=0;
  2043.         $rejected=0;
  2044. //        $total=22;
  2045.         if(!empty($vacations)){
  2046.             foreach ($vacations as $vacation){
  2047.                 $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$vacation->getId()));
  2048.                 if(!empty($vacationsDay)){
  2049. //                $total=count($vacationsDay);
  2050.                     foreach ($vacationsDay as $itemVacations){
  2051.                         if($itemVacations->getStatusBoss()==1){
  2052.                             $approved++;
  2053.                         }else{
  2054.                             is_null($itemVacations->getStatusBoss())?$pending++:$rejected++;
  2055.                         }
  2056.                     }
  2057.                 }
  2058.             }
  2059.         }
  2060.         $user=$em->getRepository(User::class)->findOneBy(
  2061.             array(
  2062.                 "id" => intval($idu),
  2063.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2064.             )
  2065.         )
  2066.         ;
  2067.         // SACAR LOS DIAS ASIGNADOS POR EL AÑO $uservacationday
  2068.         $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  2069.             array(
  2070.                 'userId' => $idu,
  2071.                 'year' => $yearActual,
  2072.             )
  2073.         );
  2074.         if (empty($uservacationday)){
  2075.             $daysVacation =  $this->translator->trans("Not Assigned");
  2076.             $left 0-$approved;
  2077.         }else{
  2078.             $daysVacation $uservacationday->getDays();
  2079.             $left $daysVacation-$approved;
  2080.         }
  2081.         // aqui sustituir user por año dias de vacaciones
  2082.         $data=array(
  2083.             'idu'=>$idu,
  2084.             'name'=>$user->getName().' '.$user->getLastname(),
  2085.             'approved'=>$approved,
  2086.             'rejected'=>$rejected,
  2087.             'pending'=>$pending,
  2088.             'left'=>$left,
  2089.             'total'=>$daysVacation,
  2090.             'periodoinicio'=>"01/01/".$yearActual,
  2091.             'periodofin'=>"30/01/".$yearSiguiente,
  2092.         );
  2093.         $uservacationdescripctionday $em->getRepository('App\Entity\UserVacationsDescription')->findBy(
  2094.             array(
  2095.                 'userId' => $idu,
  2096.                 'year' => $yearActual,
  2097.                 'type' => "vacations",
  2098.             )
  2099.         );
  2100.         $descriptionday = array();
  2101.         foreach($uservacationdescripctionday as $descvacauser) {
  2102.             $descriptionday[] = $descvacauser;
  2103.         }
  2104.         return $this->render('vacations/modal-preview.html.twig', array(
  2105.             'data' => $data,
  2106.             'descriptionday' => $descriptionday,
  2107.         ));
  2108.     }
  2109.     /**
  2110.      * @Route("/vacations/viewadmin/{idu}/{year}", name="view_Admin_vacations")
  2111.      */
  2112.     public function vacationsViewAdminAction($idu$yearRequest $request)
  2113.     {
  2114.         $em $this->getDoctrine()->getManager();
  2115.         $emConfig $em->getConfiguration();
  2116.         $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  2117. //        $parameters = array(
  2118. //            'dateActual'=>date("Y"),
  2119. //            'userId'=>$idu,
  2120. //        );
  2121. //        $dql = 'SELECT p
  2122. //                        FROM App:Vacations p
  2123. //                        WHERE YEAR(p.createdAt) = :dateActual
  2124. //                        AND p.idu = :userId
  2125. //                        ORDER BY p.createdAt DESC
  2126. //                      ';
  2127.         $yearActual $year;
  2128.         $yearSiguiente $yearActual +1;
  2129.         $parameters = array(
  2130.             'idu' => $idu,
  2131.             'dateActual'=>$yearActual,
  2132. //            'dateSiguiente'=>$yearSiguiente."-1-30",
  2133.         );
  2134.         // (p.createdAt >= :dateActual AND p.createdAt <= :dateSiguiente )
  2135.         $dql 'SELECT p
  2136.                         FROM App:Vacations p
  2137.                         WHERE p.idu = :idu  AND YEAR(p.createdAt) = :dateActual
  2138.                         ORDER BY p.createdAt DESC
  2139.                       ';
  2140.         $query $em->createQuery($dql)->setParameters($parameters);
  2141.         $vacations$query->getResult();
  2142.         $approved=0;
  2143.         $pending=0;
  2144.         $rejected=0;
  2145. //        $total=22;
  2146.         if(!empty($vacations)){
  2147.             foreach ($vacations as $vacation){
  2148.                 $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$vacation->getId()));
  2149.                 if(!empty($vacationsDay)){
  2150. //                $total=count($vacationsDay);
  2151.                     foreach ($vacationsDay as $itemVacations){
  2152.                         if($itemVacations->getStatusBoss()==1){
  2153.                             $approved++;
  2154.                         }else{
  2155.                             is_null($itemVacations->getStatusBoss())?$pending++:$rejected++;
  2156.                         }
  2157.                     }
  2158.                 }
  2159.             }
  2160.         }
  2161.         $user=$em->getRepository(User::class)->findOneById(
  2162.             array(
  2163.                 "id" => $idu,
  2164.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2165.             )
  2166.         )
  2167.         ;
  2168.         // SACAR LOS DIAS ASIGNADOS POR EL AÑO $uservacationday
  2169.         $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  2170.             array(
  2171.                 'userId' => $idu,
  2172.                 'year' => $yearActual,
  2173.             )
  2174.         );
  2175.         if (empty($uservacationday)){
  2176.             $daysVacation =  $this->translator->trans("Not Assigned");
  2177.             $left 0-$approved;
  2178.         }else{
  2179.             $daysVacation $uservacationday->getDays();
  2180.             $left $daysVacation-$approved;
  2181.         }
  2182.         // aqui sustituir user por año dias de vacaciones
  2183.         $data=array(
  2184.             'idu'=>$idu,
  2185.             'name'=>$user->getName().' '.$user->getLastname(),
  2186.             'approved'=>$approved,
  2187.             'rejected'=>$rejected,
  2188.             'pending'=>$pending,
  2189.             'left'=>$left,
  2190.             'total'=>$daysVacation,
  2191.             'periodoinicio'=>"01/01/".$yearActual,
  2192.             'periodofin'=>"30/01/".$yearSiguiente,
  2193.         );
  2194.         $uservacationdescripctionday $em->getRepository('App\Entity\UserVacationsDescription')->findBy(
  2195.             array(
  2196.                 'userId' => $idu,
  2197.                 'year' => $yearActual,
  2198.                 'type' => "vacations",
  2199.             )
  2200.         );
  2201.         $descriptionday = array();
  2202.         foreach($uservacationdescripctionday as $descvacauser) {
  2203.             $descriptionday[] = $descvacauser;
  2204.         }
  2205.         return $this->render('vacations/modal-preview.html.twig', array(
  2206.             'data' => $data,
  2207.             'descriptionday' => $descriptionday,
  2208.         ));
  2209.     }
  2210.     /**
  2211.      * @deprecated No longer used
  2212.      * @Route("/vacations/validateBoss/{idv}", name="validate_boss_vacations")
  2213.      * @param Request $request
  2214.      * @param Swift_Mailer $mailer
  2215.      * @param $idv
  2216.      * @return RedirectResponse
  2217.      */
  2218.     public function vacationsBossValidationAction(Request $request, \Swift_Mailer $mailer$idv)
  2219.     {
  2220.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2221.         $user_id $user_logueado->getId();
  2222.         $em $this->getDoctrine()->getManager();
  2223.         $data=array();
  2224.         $vacations=$em->getRepository(Vacations::class)->findOneById($idv);
  2225.         $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  2226.         $user=$em->getRepository(User::class)->findOneById(
  2227.             array(
  2228.                 "id" => $vacations->getIdu(),
  2229.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2230.             )
  2231.         )
  2232.         ;
  2233.         if (!empty($vacationsDay))
  2234.         {
  2235.             foreach($vacationsDay as $itemB) {
  2236.                 $itemB->getStatus()?$status='Approved':$status='Rejected';
  2237.                 if(is_null($itemB->getStatus())){
  2238.                     $status='Pending';
  2239.                 }
  2240.                 $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  2241.                 if(is_null($itemB->getStatusBoss())){
  2242.                     $statusB='Pending';
  2243.                 }
  2244.                 $dataB[] = array(
  2245.                     'id' => $itemB->getId(),
  2246.                     'date' => $itemB->getDate(),
  2247.                     'status' => $status,
  2248.                     'statusBoss' => $statusB,
  2249.                 );
  2250.             }
  2251.             $data = array(
  2252.                 'idv' => $idv,
  2253.                 'days' =>$dataB,
  2254.                 'fullname'=>$user->getName().' '.$user->getLastName(),
  2255.                 'date'=>$vacations->getCreatedAt(),
  2256.                 'role'=>$user->getRole()
  2257.             );
  2258.         }
  2259.         if (!empty($vacations))
  2260.         {
  2261.             $vacations->setStatus(1);
  2262.             try{
  2263.                 $em->persist($vacations);
  2264.                 $em->flush();
  2265.                 $message = (new \Swift_Message())
  2266.                     ->setSubject('Solicitud de Vacaciones Validada')
  2267.                     ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  2268.                     ->setTo($user->getEmail())
  2269.                     ->setBody(
  2270.                         $this->renderView(
  2271.                             'vacations/vacations-email-user-report.html.twig',
  2272.                             array('data' => $data)
  2273.                         ),'text/html'
  2274.                     );
  2275.                 $mailer->send($message);
  2276.                 $teamLeader=$em->getRepository(User::class)->findOneBy(array(
  2277.                         'team'=>$user->getTeam(),
  2278.                         'teamleader'=>VacationsConstants::IS_TEAM_LEADER,
  2279.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2280.                     )
  2281.                 );
  2282.                 if(!empty($teamLeader)) {
  2283.                     $emailarray $teamLeader->getEmail();
  2284.                     $message = (new \Swift_Message())
  2285.                         ->setSubject('Solicitud de Vacaciones Validada')
  2286.                         ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  2287.                         ->setTo($emailarray)
  2288.                         ->setBody(
  2289.                             $this->renderView(
  2290.                                 'vacations/vacations-email-report.html.twig',
  2291.                                 array('data' => $data)
  2292.                             ),'text/html'
  2293.                         );
  2294.                     $mailer->send($message);
  2295.                 }
  2296.             }
  2297.             catch (\Exception $e){
  2298.                 $event 'An error occurred: '.$e->getMessage();
  2299.                 $errorMessage $this->translator->trans($event);
  2300.                 $this->addFlash('mensajeholidayserror'$errorMessage);
  2301.             }
  2302.         }
  2303.         $event 'The request has ben Validated.';
  2304.         $successMessage $this->translator->trans($event);
  2305.         $this->addFlash('mensajeholidays'$successMessage);
  2306.         return $this->redirect('/vacations/manage');
  2307.     }
  2308.     /**
  2309.      * @Route("/vacations/validateLeader/{idv}", name="validate_leader_vacations")
  2310.      */
  2311.     public function vacationsLeaderValidationAction($idvRequest $request, \Swift_Mailer $mailer)
  2312.     {
  2313.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2314.         $user_id $user_logueado->getId();
  2315.         $em $this->getDoctrine()->getManager();
  2316.         $data=array();
  2317.         $vacations=$em->getRepository(Vacations::class)->findOneById($idv);
  2318.         $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  2319.         $user=$em->getRepository(User::class)->findOneById(
  2320.             array(
  2321.                 "id" => $vacations->getIdu(),
  2322.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2323.             )
  2324.         )
  2325.         ;
  2326.         //$vac_num=$user->getVacations();
  2327.         if (!empty($vacationsDay))
  2328.         {
  2329.             foreach($vacationsDay as $itemB) {
  2330.                 $itemB->getStatus()?$status='Approved':$status='Rejected';
  2331.                 if(is_null($itemB->getStatus())){
  2332.                     $status='Pending';
  2333.                 }
  2334.                 $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  2335.                 if(is_null($itemB->getStatusBoss())){
  2336.                     $statusB='Pending';
  2337.                 }
  2338.                 $dataB[] = array(
  2339.                     'id' => $itemB->getId(),
  2340.                     'date' => $itemB->getDate(),
  2341.                     'status' => $status,
  2342.                     'statusBoss' => $statusB,
  2343.                 );
  2344.             }
  2345.             $data = array(
  2346.                 'idv' => $idv,
  2347.                 'days' =>$dataB,
  2348.                 'fullname'=>$user->getName().' '.$user->getLastName(),
  2349.                 'date'=>$vacations->getCreatedAt(),
  2350.                 'role'=>$user->getRole()
  2351.             );
  2352.         }
  2353.         $teamLeader=$em->getRepository(User::class)->findOneBy(array(
  2354.                 'team'=>$user->getTeam(),
  2355.                 'teamleader'=>VacationsConstants::IS_TEAM_LEADER,
  2356.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2357.             )
  2358.         );
  2359.         if (!empty($vacations) and !empty($vacationsDay))
  2360.             $emailarray = array();
  2361.         $usermails $em->getRepository(User::class)->findByRole('ROLE_ADMIN');
  2362.         foreach($usermails as $usermail){
  2363.             $emailarray[] = $usermail->getEmail();
  2364.         }
  2365.         {
  2366.             $vacations->setStatusLeader(1);
  2367.             try{
  2368.                 $em->persist($vacations);
  2369.                 $em->flush();
  2370.                 $message = (new \Swift_Message())
  2371.                     ->setSubject('Solicitud de Vacaciones')
  2372.                     ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  2373.                     ->setTo($emailarray)
  2374.                     ->setBody(
  2375.                         $this->renderView(
  2376.                             'vacations/vacations-email-report.html.twig',
  2377.                             array('data' => $data)
  2378.                         ),'text/html'
  2379.                     );
  2380.                 $mailer->send($message);
  2381.                 //d($data,$emailarray);
  2382.                 //exit();
  2383.             }
  2384.             catch (\Exception $e){
  2385.                 $event 'An error occurred: '.$e->getMessage();
  2386.                 /* Para el log */
  2387.                 // $logger->error($event);
  2388.                 /* Para el usuario */
  2389.                 $errorMessage $this->translator->trans($event);
  2390.                 $this->addFlash('mensajeholidayserror'$errorMessage);
  2391.             }
  2392.         }
  2393.         $event 'The request has ben Validated.';
  2394.         $successMessage $this->translator->trans($event);
  2395.         $this->addFlash('mensajeholidays'$successMessage);
  2396.         // d($data,$vacationsAll);
  2397.         return $this->redirect('/vacations/listTeamLeader');
  2398.     }
  2399.     /**
  2400.      * @Route("/vacations/edit/{idu}/{idv}", name="edit_vacations")
  2401.      */
  2402.     public function vacationsEditAction($idu$idvRequest $request)
  2403.     {
  2404.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2405.         $user_id $user_logueado->getId();
  2406.         $em $this->getDoctrine()->getManager();
  2407.         $vacations $em->getRepository(Vacations::class)->findOneBy(array('id'=>$idv));
  2408.         $yearActual $vacations->getCreatedAt()->format('Y');
  2409.         $data = array();
  2410.         $vacationsAll=array();
  2411.         $approved=0;
  2412.         $rejected=0;
  2413.         $pending=0;
  2414.         $solicitadasNum=0;
  2415.         $dataB = array();
  2416.         $statusB null;
  2417.         $status null;
  2418.         if(!empty($vacations)){
  2419.             $users $em->getRepository(User::class)->findOneBy(
  2420.                 array(
  2421.                     'id'=>$idu,
  2422.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2423.                 )
  2424.             )
  2425.             ;
  2426.             $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  2427.                 array(
  2428.                     'userId' => $vacations->getIdu(),
  2429.                     'year' => $yearActual,
  2430.                 )
  2431.             );
  2432.             if (empty($uservacationday)){
  2433.                 $total =  $this->translator->trans("Not Assigned");
  2434.                 $totaln =  0;
  2435.             }else{
  2436.                 $total $uservacationday->getDays();
  2437.                 $totaln $uservacationday->getDays();
  2438.             }
  2439.             $data = array(
  2440.                 'idv' => $vacations->getId(),
  2441.                 'idu'=>$idu,
  2442.                 'fullname'=> $users->getName().' '.$users->getLastname(),
  2443.                 'totalvacations'=>$total,
  2444.             );
  2445.             // Enero dia 15
  2446. //            $yearActual = date('Y');
  2447.             $yearSiguiente $yearActual +1;
  2448.             $parameters = array(
  2449.                 'idu' => $idu,
  2450.                 'yearActual' => $yearActual,
  2451.                 'dateActual'=>$yearActual."-1-01",
  2452.                 'dateSiguiente'=>$yearSiguiente."-1-30",
  2453.             );
  2454.             $em $this->getDoctrine()->getManager();
  2455.             $emConfig $em->getConfiguration();
  2456.             $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  2457. //            $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
  2458. //            $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
  2459.             $dql 'SELECT p
  2460.                         FROM App:VacationsValidation p
  2461.                         WHERE p.idu = :idu  AND (p.date >= :dateActual AND p.date <= :dateSiguiente ) AND YEAR(p.createdAt) = :yearActual
  2462.                         ORDER BY p.date DESC
  2463.                       ';
  2464.             $query $em->createQuery($dql)->setParameters($parameters);
  2465.             $vacationsAll$query->getResult();
  2466.             $solicitadasNum=sizeof($vacationsAll);
  2467.             if(!empty($vacationsAll)){
  2468.                 foreach ($vacationsAll as $itemVacations){
  2469.                     if($itemVacations->getStatusBoss()==1){
  2470.                         $approved++;
  2471.                     }else{
  2472.                         is_null($itemVacations->getStatusBoss())?$pending++:$rejected++;
  2473.                     }
  2474.                 }
  2475.             }
  2476.         }
  2477.         // d($data,$vacationsAll);
  2478.         return $this->render('vacations/edit-vacations.html.twig', array(
  2479.             'data' => $data,
  2480.             'days' => $totaln,
  2481.             'left' => $totaln $approved,
  2482.             'id'=>$vacations->getId(),
  2483.             'allVacations'=>$vacationsAll,
  2484.             'totalOld'=>$solicitadasNum,
  2485.             'approved'=>$approved,
  2486.             'rejected'=>$rejected,
  2487.             'pending'=>$pending,
  2488.             'periodoinicio'=>"01/01/".$yearActual,
  2489.             'periodofin'=>"30/01/".$yearSiguiente,
  2490.         ));
  2491.     }
  2492. //    /**
  2493. //     * @Route("/vacations/edit/{idu}/{idv}", name="edit_vacations")
  2494. //     */
  2495. //    public function vacationsEditAction($idu, $idv, Request $request)
  2496. //    {
  2497. //        $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  2498. //        $user_id = $user_logueado->getId();
  2499. //
  2500. //        $em = $this->getDoctrine()->getManager();
  2501. //        $vacations = $em->getRepository(Vacations::class)->findOneBy(array('id'=>$idv));
  2502. //        $yearActual = $vacations->getCreatedAt()->format('Y');
  2503. //        $data = array();
  2504. //        $vacationsAll=array();
  2505. //        $approved=0;
  2506. //        $rejected=0;
  2507. //        $pending=0;
  2508. //        $solicitadasNum=0;
  2509. //        $dataB = array();
  2510. //        $statusB = null;
  2511. //        $status = null;
  2512. //        if(!empty($vacations)){
  2513. //
  2514. ////            $bossVal = $em->getRepository(VacationsValidation::class)->findBy(
  2515. ////                array('idv'=>$idv),
  2516. ////                array('date' => 'DESC')
  2517. ////            );
  2518. ////
  2519. ////            foreach($bossVal as $itemB) {
  2520. ////
  2521. ////                $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  2522. ////                if(is_null($itemB->getStatusBoss())){
  2523. ////                    $statusB='Pending';
  2524. ////                }
  2525. ////
  2526. ////                $itemB->getStatus()?$status='Approved':$status='Rejected';
  2527. ////                if(is_null($itemB->getStatus())){
  2528. ////                    $status='Pending';
  2529. ////                }
  2530. ////
  2531. ////                $dataB[] = array(
  2532. ////                    'id' => $itemB->getId(),
  2533. ////                    'idv' => $itemB->getIdv(),
  2534. ////                    'date' => $itemB->getDate(),
  2535. ////                    'status' => $status,
  2536. ////                    'statusBoss' => $statusB,
  2537. ////                );
  2538. ////            }
  2539. //            $users = $em->getRepository(User::class)->findOneBy(array('id'=>$idu));
  2540. //
  2541. //            $total=$users->getVacations();
  2542. //            $requested=sizeof($bossVal);
  2543. //            $left=$total-$requested;
  2544. //            $data = array(
  2545. //                'idv' => $vacations->getId(),
  2546. //                'idu'=>$idu,
  2547. //                'fullname'=> $users->getName().' '.$users->getLastname(),
  2548. //                'bossVal' =>$dataB,
  2549. //                'totalvacations'=>$total,
  2550. //                'requested'=>$requested,
  2551. //                'left'=>$left
  2552. //
  2553. //            );
  2554. //
  2555. //            // Enero dia 15
  2556. ////            $yearActual = date('Y');
  2557. //
  2558. //            $yearSiguiente = $yearActual +1;
  2559. ////            $yearActualMasUno = strtotime ( '+1 year' , strtotime ( $yearActual ) ) ;
  2560. ////            d($yearActual);
  2561. //            $parameters = array(
  2562. //                //'idv' => $idv,
  2563. //                'idu' => $idu,
  2564. //                'dateActual'=>$yearActual."-1-30",
  2565. //                'dateSiguiente'=>$yearSiguiente."-1-30",
  2566. ////                'dateActual'=>date('Y'),
  2567. //            );
  2568. //            $em = $this->getDoctrine()->getManager();
  2569. //            $emConfig = $em->getConfiguration();
  2570. //            //$emConfig = $this->getEntityManager()->getConfiguration();
  2571. //            $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
  2572. //
  2573. ////            $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
  2574. ////            $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
  2575. //
  2576. //
  2577. ////            $dql = 'SELECT p
  2578. ////                        FROM App:VacationsValidation p
  2579. ////                        WHERE p.idu = :idu  AND YEAR(p.date) = :dateActual
  2580. ////                        ORDER BY p.date DESC
  2581. ////                      ';
  2582. //            $dql = 'SELECT p
  2583. //                        FROM App:VacationsValidation p
  2584. //                        WHERE p.idu = :idu  AND (p.date >= :dateActual AND p.date <= :dateSiguiente )
  2585. //                        ORDER BY p.date DESC
  2586. //                      ';
  2587. //            $query = $em->createQuery($dql)->setParameters($parameters);
  2588. //            $vacationsAll= $query->getResult();
  2589. //
  2590. //            $solicitadasNum=sizeof($vacationsAll);
  2591. //
  2592. //            if(!empty($vacationsAll)){
  2593. //                foreach ($vacationsAll as $itemVacations){
  2594. //
  2595. //                    if($itemVacations->getStatusBoss()==1){
  2596. //                        $approved++;
  2597. //                    }else{
  2598. //                        is_null($itemVacations->getStatusBoss())?$pending++:$rejected++;
  2599. //                    }
  2600. ////                    if($itemVacations->getStatusBoss()==0){
  2601. ////
  2602. ////                    }
  2603. ////
  2604. ////                    if(is_null($itemVacations->getStatusBoss())){
  2605. ////                        $pending++;
  2606. ////                    }
  2607. //                }
  2608. //
  2609. //            }
  2610. //
  2611. //
  2612. //        }
  2613. //
  2614. //       // d($data,$vacationsAll);
  2615. //        return $this->render('vacations/edit-vacations.html.twig', array(
  2616. //            'data' => $data,
  2617. //            'id'=>$vacations->getId(),
  2618. //            'allVacations'=>$vacationsAll,
  2619. //            'totalOld'=>$solicitadasNum,
  2620. //            'approved'=>$approved,
  2621. //            'rejected'=>$rejected,
  2622. //            'pending'=>$pending,
  2623. //        ));
  2624. //    }
  2625.     /**
  2626.      * @Route("/vacations/view/{idv}", name="view_vacations")
  2627.      */
  2628.     public function vacationsViewAction($idvRequest $request)
  2629.     {
  2630.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2631.         $user_id $user_logueado->getId();
  2632.         $em $this->getDoctrine()->getManager();
  2633.         $vacations $em->getRepository(Vacations::class)->findOneBy(array('id'=>$idv));
  2634.         $yearActual $vacations->getCreatedAt()->format('Y');
  2635.         $data = array();
  2636.         $vacationsAll=array();
  2637.         $approved=0;
  2638.         $rejected=0;
  2639.         $pending=0;
  2640.         $solicitadasNum=0;
  2641.         if(!empty($vacations)){
  2642.             $bossVal $em->getRepository(VacationsValidation::class)->findBy(
  2643.                 array('idv'=>$vacations->getId()),
  2644.                 array('date' => 'ASC')
  2645.             );
  2646.             foreach($bossVal as $itemB) {
  2647.                 $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  2648.                 if(is_null($itemB->getStatusBoss())){
  2649.                     $statusB='Pending';
  2650.                 }
  2651.                 $itemB->getStatus()?$status='Approved':$status='Rejected';
  2652.                 if(is_null($itemB->getStatus())){
  2653.                     $status='Pending';
  2654.                 }
  2655.                 if($itemB->getStatusBoss()==1){
  2656.                     $approved++;
  2657.                 }else{
  2658.                     is_null($itemB->getStatusBoss())?$pending++:$rejected++;
  2659.                 }
  2660.                 $dataB[] = array(
  2661.                     'id' => $itemB->getId(),
  2662.                     'idv' => $itemB->getIdv(),
  2663.                     'date' => $itemB->getDate(),
  2664.                     'status' => $status,
  2665.                     'statusBoss' => $statusB,
  2666.                 );
  2667.             }
  2668.             $users $em->getRepository(User::class)->findOneBy(
  2669.                 array(
  2670.                     'id'=>$vacations->getIdu(),
  2671.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2672.                 )
  2673.             )
  2674.             ;
  2675.             $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  2676.                 array(
  2677.                     'userId' => $vacations->getIdu(),
  2678.                     'year' => $yearActual,
  2679.                 )
  2680.             );
  2681.             if (empty($uservacationday)){
  2682.                 $total =  $this->translator->trans("Not Assigned");
  2683.                 $totaln =  0;
  2684.                 $requested=sizeof($bossVal);
  2685.                 $left 0-$approved;
  2686.             }else{
  2687.                 $total $uservacationday->getDays();
  2688.                 $totaln $uservacationday->getDays();
  2689.                 $requested=sizeof($bossVal);
  2690.                 $left $total-$approved;
  2691.             }
  2692.             $data = array(
  2693.                 'idv' => $vacations->getId(),
  2694.                 'idu'=>$users->getId(),
  2695.                 'fullname'=> $users->getName().' '.$users->getLastname(),
  2696.                 'bossVal' =>$dataB,
  2697.                 'totalvacations'=>$total,
  2698.                 'requested'=>$requested,
  2699.                 'left'=>$left
  2700.             );
  2701.             $totales $totaln-$approved;
  2702.         }else{
  2703.         }
  2704.         //d($data,$vacationsAll);
  2705.         return $this->render('vacations/view-vacations.html.twig', array(
  2706.             'data' => $data,
  2707.             'days' => $total,
  2708.             'id'=>$vacations->getId(),
  2709.             'allVacations'=>$vacationsAll,
  2710.             'totalOld'=>$solicitadasNum+$requested,
  2711.             'approved'=>$approved,
  2712.             'rejected'=>$rejected,
  2713.             'totales'=>$totales,
  2714.         ));
  2715.     }
  2716.     /**
  2717.      * @Route("/vacations/checkTeamLeader/{idv}", name="team_leader_check_vacations")
  2718.      * @param Request $request
  2719.      * @param $idv
  2720.      * @return Response
  2721.      */
  2722.     public function vacationsCheckTeamLeaderAction(Request $request$idv)
  2723.     {
  2724.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2725.         $user_id $user_logueado->getId();
  2726.         $em $this->getDoctrine()->getManager();
  2727.         $vacations $em->getRepository(Vacations::class)->findOneBy(array('id'=>$idv));
  2728.         $yearActual $vacations->getCreatedAt()->format('Y');
  2729.         $data = array();
  2730.         $vacationsAll=array();
  2731.         $approved=0;
  2732.         $rejected=0;
  2733.         $pending=0;
  2734.         $totales=0;
  2735.         $solicitadasNum=0;
  2736.         if(!empty($vacations)){
  2737.             $bossVal $em->getRepository(VacationsValidation::class)->findBy(
  2738.                 array('idv'=>$vacations->getId()),
  2739.                 array('date' => 'ASC')
  2740.             );
  2741.             foreach($bossVal as $itemB) {
  2742.                 $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  2743.                 if(is_null($itemB->getStatusBoss())){
  2744.                     $statusB='Pending';
  2745.                 }
  2746.                 $itemB->getStatus()?$status='Approved':$status='Rejected';
  2747.                 if(is_null($itemB->getStatus())){
  2748.                     $status='Pending';
  2749.                 }
  2750.                 $dataB[] = array(
  2751.                     'id' => $itemB->getId(),
  2752.                     'idv' => $itemB->getIdv(),
  2753.                     'date' => $itemB->getDate(),
  2754.                     'status' => $status,
  2755.                     'statusBoss' => $statusB,
  2756.                 );
  2757.             }
  2758.             $users $em->getRepository(User::class)->findOneBy(
  2759.                 array(
  2760.                     'id'=>$vacations->getIdu(),
  2761.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2762.                 )
  2763.             )
  2764.             ;
  2765.             $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  2766.                 array(
  2767.                     'userId' => $vacations->getIdu(),
  2768.                     'year' => $yearActual,
  2769.                 )
  2770.             );
  2771.             if (empty($uservacationday)){
  2772.                 $total =  $this->translator->trans("Not Assigned");
  2773.                 $totaln =  0;
  2774.                 $requested=sizeof($bossVal);
  2775.                 $left 0-$approved;
  2776.             }else{
  2777.                 $total $uservacationday->getDays();
  2778.                 $totaln $uservacationday->getDays();
  2779.                 $requested=sizeof($bossVal);
  2780.                 $left $total-$requested;
  2781.             }
  2782.             $data = array(
  2783.                 'idv' => $vacations->getId(),
  2784.                 'idu'=>$users->getId(),
  2785.                 'fullname'=> $users->getName().' '.$users->getLastname(),
  2786.                 'bossVal' =>$dataB,
  2787.                 'totalvacations'=>$total,
  2788.                 'requested'=>$requested,
  2789.                 'left'=>$left
  2790.             );
  2791. //            $parameters = array(
  2792. //                'idv' => $idv,
  2793. //                'idu' => $users->getId(),
  2794. //                'dateActual'=>date("Y"),
  2795. //            );
  2796.             // Enero dia 15
  2797. //            $yearActual = date('Y');
  2798.             $yearSiguiente $yearActual +1;
  2799.             $parameters = array(
  2800.                 'idv' => $idv,
  2801.                 'idu' => $users->getId(),
  2802.                 'yearActual' => $yearActual,
  2803.                 'dateActual'=>$yearActual."-1-01",
  2804.                 'dateSiguiente'=>$yearSiguiente."-1-30",
  2805.             );
  2806.             $em $this->getDoctrine()->getManager();
  2807.             $emConfig $em->getConfiguration();
  2808.             $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  2809. //            $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
  2810. //            $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
  2811.             $dql 'SELECT p
  2812.                         FROM App:VacationsValidation p
  2813.                         WHERE p.idu = :idu AND p.idv <> :idv AND (p.date >= :dateActual AND p.date <= :dateSiguiente ) AND YEAR(p.createdAt) = :yearActual
  2814.                         AND 1=(SELECT q.status
  2815.                             FROM App:Vacations q
  2816.                             WHERE q.id = p.idv)
  2817.                       ';
  2818.             $query $em->createQuery($dql)->setParameters($parameters);
  2819.             $vacationsAll$query->getResult();
  2820.             $solicitadasNum=sizeof($vacationsAll);
  2821.             if(!empty($vacationsAll)){
  2822.                 foreach ($vacationsAll as $itemVacations){
  2823.                     if($itemVacations->getStatusBoss()==1){
  2824.                         $approved++;
  2825.                     }else{
  2826.                         is_null($itemVacations->getStatusBoss())?$pending++:$rejected++;
  2827.                     }
  2828.                 }
  2829.             }
  2830.             $totales $totaln-$approved;
  2831.         }else{
  2832.         }
  2833.         // d($data,$vacationsAll);
  2834.         return $this->render('vacations/team-leader-validate-vacations.html.twig', array(
  2835.             'data' => $data,
  2836.             'id'=>$vacations->getId(),
  2837.             'allVacations'=>$vacationsAll,
  2838.             'totalOld'=>$solicitadasNum+$requested,
  2839.             'approved'=>$approved,
  2840.             'rejected'=>$rejected,
  2841.             'totales'=>$totales,
  2842.             'periodoinicio'=>"01/01/".$yearActual,
  2843.             'periodofin'=>"30/01/".$yearSiguiente,
  2844.             'datesolicitud'=>$vacations->getCreatedAt()->format('d/m/Y')
  2845.         ));
  2846.     }
  2847.     /**
  2848.      * @Route("/vacations/check/{idv}", name="check_vacations")
  2849.      */
  2850.     public function vacationsCheckAction($idvRequest $request)
  2851.     {
  2852.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  2853.         $user_id $user_logueado->getId();
  2854.         $em $this->getDoctrine()->getManager();
  2855.         $helper  = new VacationsHelper($em);
  2856.         $vacations $em->getRepository(Vacations::class)->findOneBy(array('id'=>$idv));
  2857.         $yearActual $vacations->getCreatedAt()->format('Y');
  2858.         $data = array();
  2859.         $vacationsAll=array();
  2860.         $approved=0;
  2861.         $rejected=0;
  2862.         $pending=0;
  2863.         $solicitadasNum=0;
  2864.         $totales=0;
  2865.         $dataB=array();
  2866.         if(!empty($vacations)){
  2867.             $bossVal $em->getRepository(VacationsValidation::class)->findBy(
  2868.                 array('idv'=>$vacations->getId()),
  2869.                 array('date' => 'ASC')
  2870.             );
  2871.             foreach($bossVal as $itemB) {
  2872.                 $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  2873.                 if(is_null($itemB->getStatusBoss())){
  2874.                     $statusB='Pending';
  2875.                 }
  2876.                 $itemB->getStatus()?$status='Approved':$status='Rejected';
  2877.                 if(is_null($itemB->getStatus())){
  2878.                     $status='Pending';
  2879.                 }
  2880.                 $dataB[] = array(
  2881.                     'id' => $itemB->getId(),
  2882.                     'idv' => $itemB->getIdv(),
  2883.                     'date' => $itemB->getDate(),
  2884.                     'status' => $status,
  2885.                     'statusBoss' => $statusB,
  2886.                 );
  2887.             }
  2888.             $users $em->getRepository(User::class)->findOneBy(
  2889.                 array(
  2890.                     'id'=>$vacations->getIdu(),
  2891.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  2892.                 )
  2893.             )
  2894.             ;
  2895.             $uservacationday $em->getRepository('App\Entity\UserVacationYearDay')->findOneBy(
  2896.                 array(
  2897.                     'userId' => $vacations->getIdu(),
  2898.                     'year' => $yearActual,
  2899.                 )
  2900.             );
  2901.             if (empty($uservacationday)){
  2902.                 $total =  $this->translator->trans("Not Assigned");
  2903.                 $totaln =  0;
  2904.                 $requested=sizeof($bossVal);
  2905.                 $left 0-$approved;
  2906.             }else{
  2907.                 $total $uservacationday->getDays();
  2908.                 $totaln $uservacationday->getDays();
  2909.                 $requested=sizeof($bossVal);
  2910.                 $left $total-$requested;
  2911.             }
  2912.             $data = array(
  2913.                 'idv' => $vacations->getId(),
  2914.                 'idu'=>$users->getId(),
  2915.                 'fullname'=> $users->getName().' '.$users->getLastname(),
  2916.                 'bossVal' =>$dataB,
  2917.                 'totalvacations'=>$total,
  2918.                 'requested'=>$requested,
  2919.                 'left'=>$left
  2920.             );
  2921. //            $parameters = array(
  2922. //                'idv' => $idv,
  2923. //                'idu' => $users->getId(),
  2924. //                'dateActual'=>date("Y"),
  2925. //            );
  2926.             // Enero dia 15
  2927. //            $yearActual = date('Y');
  2928.             $yearSiguiente $yearActual +1;
  2929.             $parameters = array(
  2930.                 'idv' => $idv,
  2931.                 'idu' => $users->getId(),
  2932. //                'yearActual' => $yearActual,
  2933.                 'dateActual'=>$yearActual."-1-01",
  2934.                 'dateSiguiente'=>$yearSiguiente."-1-30",
  2935.             );
  2936.             $em $this->getDoctrine()->getManager();
  2937. //            $emConfig = $em->getConfiguration();
  2938. //            $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
  2939. //            $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
  2940. //            $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
  2941. //            $dql = 'SELECT p
  2942. //                        FROM App:VacationsValidation p
  2943. //                        WHERE p.idu = :idu AND p.idv <> :idv AND YEAR(p.date) = :dateActual
  2944. //                        AND 1=(SELECT q.status
  2945. //                            FROM App:Vacations q
  2946. //                            WHERE q.id = p.idv)
  2947. //                      ';
  2948.             $dql 'SELECT p
  2949.                         FROM App:VacationsValidation p
  2950.                         WHERE p.idu = :idu AND p.idv <> :idv AND ( p.date >= :dateActual AND p.date <= :dateSiguiente ) 
  2951.                         AND 1=(SELECT q.status
  2952.                             FROM App:Vacations q
  2953.                             WHERE q.id = p.idv)
  2954.                       ';
  2955.             $query $em->createQuery($dql)->setParameters($parameters);
  2956.             $vacationsAll$query->getResult();
  2957.             $solicitadasNum=sizeof($vacationsAll);
  2958.             if(!empty($vacationsAll)){
  2959.                 foreach ($vacationsAll as $itemVacations){
  2960.                     if($itemVacations->getStatusBoss()==1){
  2961.                         $approved++;
  2962.                     }else{
  2963.                         is_null($itemVacations->getStatusBoss())?$pending++:$rejected++;
  2964.                     }
  2965.                 }
  2966.             }
  2967.             $totales $totaln-$approved;
  2968.         }
  2969.         $yearnow date('Y');
  2970.         if ($yearActual >= $yearnow){
  2971.             $transferyear null;
  2972.         }else{
  2973.             $transferyear $yearSiguiente;
  2974.         }
  2975.         return $this->render('vacations/validate-vacations.html.twig', array(
  2976.             'data' => $data,
  2977.             'id'=>$vacations->getId(),
  2978.             'allVacations'=>$vacationsAll,
  2979.             'totalOld'=>$solicitadasNum+$requested,
  2980.             'approved'=>$approved,
  2981.             'rejected'=>$rejected,
  2982.             'totales'=>$totales,
  2983.             'periodoinicio'=>"01/01/".$yearActual,
  2984.             'periodofin'=>"30/01/".$yearSiguiente,
  2985.             'transferyear'=>$transferyear,
  2986.             'yearnow'=>$yearnow,
  2987.             'datesolicitud'=>$vacations->getCreatedAt()->format('d/m/Y'),
  2988.             'teamName' => $helper->getTeamNameByUserID($vacations->getIdu())
  2989.         ));
  2990.     }
  2991.     /**
  2992.      * @Route("/vacations/notesUser/{idu}", name="get_vacations_notes_user")
  2993.      */
  2994.     public function widgetUserVacatioNotestAction($iduRequest $request) {
  2995.         $em $this->getDoctrine()->getManager();
  2996.         $emConfig $em->getConfiguration();
  2997.         $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  2998. //        $parameters = array(
  2999. //            'dateActual'=>date("Y"),
  3000. //            'idu'=>$idu
  3001. //        );
  3002. //        $dql = 'SELECT p
  3003. //                        FROM App:VacationsValidation p
  3004. //                        WHERE p.idu = :idu AND YEAR(p.date) = :dateActual
  3005. //                        ORDER BY p.date DESC
  3006. //                      ';
  3007.         // Enero dia 30
  3008.         $yearActual date('Y');
  3009.         $yearSiguiente $yearActual +1;
  3010.         $parameters = array(
  3011.             'idu' => $idu,
  3012.             'dateActual'=>$yearActual."-1-30",
  3013.             'dateSiguiente'=>$yearSiguiente."-1-30",
  3014.         );
  3015.         $dql 'SELECT p
  3016.                         FROM App:VacationsValidation p
  3017.                         WHERE p.idu = :idu AND (p.date >= :dateActual AND p.date <= :dateSiguiente )
  3018.                         ORDER BY p.date DESC 
  3019.                       ';
  3020.         $query $em->createQuery($dql)->setParameters($parameters);
  3021.         $vacationsV$query->getResult();
  3022.         $data = array();
  3023.         if(!empty($vacationsV)){
  3024.             //d($vacationsV);
  3025.             foreach($vacationsV as $itemB) {
  3026.                 $vacations $em->getRepository(Vacations::class)->findOneById($itemB->getIdv());
  3027.                 if( $itemB->getStatusBoss()==1){
  3028.                     $status='Approved';
  3029.                     $color='#66BB6A';
  3030.                 }
  3031.                 if( $itemB->getStatusBoss()==0){
  3032.                     $status='Rejected';
  3033.                     $color='#EF5350';
  3034.                 }
  3035.                 if(is_null($itemB->getStatusBoss()) ){
  3036.                     $status='Pending';
  3037.                     $color='#42A5F5';
  3038.                 }
  3039.                 $dataB[] = array(
  3040.                     'date' => $itemB->getDate(),
  3041.                     'status' => $status,
  3042.                     'color'=>$color,
  3043.                     'url'=>''
  3044.                 );
  3045.                 $users $em->getRepository(User::class)->findOneBy(
  3046.                     array(
  3047.                         'id'=>$itemB->getIdu(),
  3048.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3049.                     )
  3050.                 )
  3051.                 ;
  3052.                 $data[] = array(
  3053.                     'id'=>$itemB->getId(),
  3054.                     'idv' => $itemB->getIdv(),
  3055.                     'idu'=>$users->getId(),
  3056.                     'fullname'=> $users->getName().' '.$users->getLastname(),
  3057.                     'description'=>$vacations->getDescription(),
  3058.                     'color'=>$color,
  3059.                     'date' =>$itemB->getDate(),
  3060.                 );
  3061.             }
  3062.             //}
  3063.         }else{
  3064.         }
  3065.         $return = array(
  3066.             'notes' => $data,
  3067.         );
  3068.         $response = new JsonResponse($return);
  3069.         return $response;
  3070.     }
  3071.     /**
  3072.      * @Route("/vacations/notesApproved/{idu}", name="get_vacations_notes_all_approved")
  3073.      */
  3074.     public function widgetApprovedVacationsAction($iduRequest $request)
  3075.     {
  3076.         $em $this->getDoctrine()->getManager();
  3077.         $emConfig $em->getConfiguration();
  3078.         $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  3079.         // Obtener el año actual una sola vez
  3080.         $currentYear date("Y");
  3081.         // Obtener el usuario actual y validar su existencia
  3082.         $userActual $em->getRepository(User::class)->findOneBy([
  3083.             "id" => $idu,
  3084.             "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3085.         ]);
  3086.         if (!$userActual) {
  3087.             return new JsonResponse(['error' => 'Usuario no encontrado o inactivo.'], 404);
  3088.         }
  3089.         $isAdmin $userActual->getRole() === 'ROLE_ADMIN';
  3090.         // Definir parámetros y DQL para VacationsValidation
  3091.         if ($isAdmin) {
  3092.             $vacationsParameters = [
  3093.                 'dateActual' => $currentYear,
  3094.             ];
  3095.             $vacationsDql '
  3096.                 SELECT p
  3097.                 FROM App:VacationsValidation p
  3098.                 WHERE p.statusBoss = 1 
  3099.                 AND YEAR(p.date) >= :dateActual
  3100.             ';
  3101.         } else {
  3102.             // Determinar los equipos relevantes
  3103.             $teamsID VacationsConstants::isThisTeamIDIsAnyReservationsTeam($userActual->getTeam())
  3104.                 ? VacationsConstants::$mixedReservationsTeams
  3105.                 : [$userActual->getTeam()];
  3106.             $vacationsParameters = [
  3107.                 'dateActual' => $currentYear,
  3108.                 'team' => $teamsID,
  3109.             ];
  3110.             $vacationsDql '
  3111.                 SELECT p
  3112.                 FROM App:VacationsValidation p
  3113.                 WHERE p.statusBoss = 1 
  3114.                 AND YEAR(p.date) >= :dateActual
  3115.                 AND p.idu IN (
  3116.                     SELECT q.id
  3117.                     FROM App\Entity\User q
  3118.                     WHERE q.team IN (:team)
  3119.                 )
  3120.             ';
  3121.         }
  3122.         // Ejecutar la consulta para VacationsValidation
  3123.         $vacationsV $em->createQuery($vacationsDql)
  3124.                         ->setParameters($vacationsParameters)
  3125.                         ->getResult();
  3126.         // Definir parámetros y DQL para HalfDayValidation
  3127.         if ($isAdmin) {
  3128.             $halfDayParameters = [
  3129.                 'dateActual' => $currentYear,
  3130.             ];
  3131.             $halfDayDql '
  3132.                 SELECT p
  3133.                 FROM App:HalfDayValidation p
  3134.                 WHERE p.statusBoss = 1 
  3135.                 AND YEAR(p.date) >= :dateActual
  3136.                 AND 1 = (
  3137.                     SELECT q.status
  3138.                     FROM App:HalfDay q
  3139.                     WHERE q.id = p.idv
  3140.                 )
  3141.             ';
  3142.         } else {
  3143.             $halfDayParameters = [
  3144.                 'dateActual' => $currentYear,
  3145.                 'team' => $userActual->getTeam(),
  3146.             ];
  3147.             $halfDayDql '
  3148.                 SELECT p
  3149.                 FROM App:HalfDayValidation p
  3150.                 WHERE p.statusBoss = 1 
  3151.                 AND YEAR(p.date) >= :dateActual
  3152.                 AND 1 = (
  3153.                     SELECT r.status
  3154.                     FROM App:HalfDay r
  3155.                     WHERE r.id = p.idv
  3156.                 )
  3157.                 AND p.idu IN (
  3158.                     SELECT q.id
  3159.                     FROM App\Entity\User q
  3160.                     WHERE q.team = :team
  3161.                 )
  3162.             ';
  3163.         }
  3164.         // Ejecutar la consulta para HalfDayValidation
  3165.         $halfH $em->createQuery($halfDayDql)
  3166.                 ->setParameters($halfDayParameters)
  3167.                 ->getResult();
  3168.         $data = [];
  3169.         // Procesar VacationsValidation
  3170.         if (!empty($vacationsV)) {
  3171.             foreach ($vacationsV as $itemB) {
  3172.                 $vacation $em->getRepository(Vacations::class)->find($itemB->getIdv());
  3173.                 $user $em->getRepository(User::class)->findOneBy([
  3174.                     'id' => $itemB->getIdu(),
  3175.                     'status' => VacationsConstants::PAYROLL_STAFF_STATUS
  3176.                 ]);
  3177.                 if ($user && $vacation) {
  3178.                     $data[] = [
  3179.                         'idv' => $itemB->getIdv(),
  3180.                         'idu' => $user->getId(),
  3181.                         'fullname' => '(VAC.) ' $user->getName() . ' ' $user->getLastname(),
  3182.                         'description' => "VACACIONES: " $vacation->getDescription(),
  3183.                         'color' => '#4B4B4B',
  3184.                         'date' => $itemB->getDate(),
  3185.                     ];
  3186.                 }
  3187.             }
  3188.         }
  3189.         // Procesar HalfDayValidation
  3190.         if (!empty($halfH)) {
  3191.             foreach ($halfH as $itemB) {
  3192.                 $halfday $em->getRepository(HalfDay::class)->find($itemB->getIdv());
  3193.                 $user $em->getRepository(User::class)->findOneBy([
  3194.                     'id' => $itemB->getIdu(),
  3195.                     'status' => VacationsConstants::PAYROLL_STAFF_STATUS
  3196.                 ]);
  3197.                 if ($user && $halfday) {
  3198.                     $data[] = [
  3199.                         'idv' => $itemB->getIdv(),
  3200.                         'idu' => $user->getId(),
  3201.                         'fullname' => '(MDD.) ' $user->getName() . ' ' $user->getLastname(),
  3202.                         'description' => "MEDIO DIA: " $halfday->getDescription(),
  3203.                         'color' => '#9c9c9c',
  3204.                         'date' => $itemB->getDate(),
  3205.                     ];
  3206.                 }
  3207.             }
  3208.         }
  3209.         // Preparar la respuesta
  3210.         $responseData = [
  3211.             'notes' => $data,
  3212.         ];
  3213.         return new JsonResponse($responseData);
  3214.     }
  3215.     /**
  3216.      * @Route("/vacations/notesAll", name="get_vacations_notes_all")
  3217.      */
  3218.     public function widgetAllVacatioNotestAction(Request $request) {
  3219.         $em $this->getDoctrine()->getManager();
  3220.         $emConfig $em->getConfiguration();
  3221.         $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  3222.         $parameters = array(
  3223.             'dateActual'=>date("Y"),
  3224.         );
  3225.         $dql 'SELECT p
  3226.                         FROM App:VacationsValidation p
  3227.                         WHERE YEAR(p.date) = :dateActual 
  3228.                       ';
  3229.         $query $em->createQuery($dql)->setParameters($parameters);
  3230.         $vacationsV$query->getResult();
  3231.         $data = array();
  3232.         if(!empty($vacationsV)){
  3233.             //d($vacationsV);
  3234.             foreach($vacationsV as $itemB) {
  3235.                 $vacations $em->getRepository(Vacations::class)->findOneById($itemB->getIdv());
  3236.                 if( $itemB->getStatusBoss()==1){
  3237.                     $status='Approved';
  3238.                     $color='#66BB6A';
  3239.                 }
  3240.                 if( $itemB->getStatusBoss()==0){
  3241.                     $status='Rejected';
  3242.                     $color='#EF5350';
  3243.                 }
  3244.                 if(is_null($itemB->getStatusBoss()) ){
  3245.                     $status='Pending';
  3246.                     $color='#42A5F5';
  3247.                 }
  3248.                 $dataB[] = array(
  3249.                     'date' => $itemB->getDate(),
  3250.                     'status' => $status,
  3251.                     'color'=>$color,
  3252.                     'url'=>''
  3253.                 );
  3254.                 $users $em->getRepository(User::class)->findOneBy(
  3255.                     array(
  3256.                         'id'=>$itemB->getIdu(),
  3257.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3258.                     )
  3259.                 )
  3260.                 ;
  3261.                 $data[] = array(
  3262.                     'idv' => $itemB->getIdv(),
  3263.                     'idu'=>$users->getId(),
  3264.                     'fullname'=> $users->getName().' '.$users->getLastname(),
  3265.                     'description'=>$vacations->getDescription(),
  3266.                     'color'=>$color,
  3267.                     'date' =>$itemB->getDate(),
  3268.                 );
  3269.             }
  3270.             //}
  3271.         }else{
  3272.         }
  3273.         $return = array(
  3274.             'notes' => $data,
  3275.         );
  3276.         $response = new JsonResponse($return);
  3277.         return $response;
  3278.     }
  3279.     /**
  3280.      * @Route("/vacations/notesAll/{id}", name="get_vacations_notes_all_user")
  3281.      */
  3282.     public function widgetAllVacatioUserNotestAction($idRequest $request) {
  3283.         $em $this->getDoctrine()->getManager();
  3284.         $emConfig $em->getConfiguration();
  3285.         $emConfig->addCustomDatetimeFunction('YEAR''DoctrineExtensions\Query\Mysql\Year');
  3286.         $userActual $em->getRepository(User::class)->findOneById(
  3287.             array(
  3288.                 "id" => $id,
  3289.                 "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3290.             )
  3291.         )
  3292.         ;
  3293.         if($userActual->getRole()=='ROLE_ADMIN'){
  3294.             $parameters = array(
  3295.                 'dateActual'=>date("Y"),
  3296.             );
  3297.             $dql 'SELECT p
  3298.                         FROM App:VacationsValidation p
  3299.                         WHERE YEAR(p.date) = :dateActual 
  3300.                       ';
  3301.         }else{
  3302.             $parameters = array(
  3303.                 'dateActual'=>date("Y"),
  3304.                 'team'=> $userActual->getTeam(),
  3305.             );
  3306.             $dql 'SELECT p
  3307.                         FROM App:VacationsValidation p
  3308.                         WHERE YEAR(p.date) = :dateActual AND
  3309.                         p.idu=(SELECT q.id
  3310.                             FROM App\Entity\User q
  3311.                             WHERE q.team = :team)
  3312.                       ';
  3313.         }
  3314.         $query $em->createQuery($dql)->setParameters($parameters);
  3315.         $vacationsV$query->getResult();
  3316.         $data = array();
  3317.         if(!empty($vacationsV)){
  3318.             //d($vacationsV);
  3319.             foreach($vacationsV as $itemB) {
  3320.                 $vacations $em->getRepository(Vacations::class)->findOneById($itemB->getIdv());
  3321.                 if( $itemB->getStatusBoss()==1){
  3322.                     $status='Approved';
  3323.                     $color='#66BB6A';
  3324.                 }
  3325.                 if( $itemB->getStatusBoss()==0){
  3326.                     $status='Rejected';
  3327.                     $color='#EF5350';
  3328.                 }
  3329.                 if(is_null($itemB->getStatusBoss()) ){
  3330.                     $status='Pending';
  3331.                     $color='#42A5F5';
  3332.                 }
  3333.                 $dataB[] = array(
  3334.                     'date' => $itemB->getDate(),
  3335.                     'status' => $status,
  3336.                     'color'=>$color,
  3337.                     'url'=>''
  3338.                 );
  3339.                 $users $em->getRepository(User::class)->findOneBy(
  3340.                     array(
  3341.                         'id'=>$itemB->getIdu(),
  3342.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3343.                     )
  3344.                 )
  3345.                 ;
  3346.                 $data[] = array(
  3347.                     'idv' => $itemB->getIdv(),
  3348.                     'idu'=>$users->getId(),
  3349.                     'fullname'=> $users->getName().' '.$users->getLastname(),
  3350.                     'description'=>$vacations->getDescription(),
  3351.                     'color'=>$color,
  3352.                     'date' =>$itemB->getDate(),
  3353.                 );
  3354.             }
  3355.             //}
  3356.         }else{
  3357.         }
  3358.         $return = array(
  3359.             'notes' => $data,
  3360.         );
  3361.         $response = new JsonResponse($return);
  3362.         return $response;
  3363.     }
  3364.     /**
  3365.      * @Route("/vacations/notes/{idv}", name="get_vacations_notes_select")
  3366.      * @param $idv
  3367.      * @param Request $request
  3368.      * @return JsonResponse
  3369.      * @throws Exception
  3370.      */
  3371.     public function widgetVacationNotesAction($idvRequest $request) {
  3372.         $em $this->getDoctrine()->getManager();
  3373.         $vacations $em->getRepository(Vacations::class)->findOneById($idv);
  3374. //        $data = array();
  3375.         $dataForTheCalendar = array();
  3376.         if(!empty($vacations)){
  3377.             //$firstVal = $em->getRepository('App:VacationsFirstValidation')->findBy(array('idv'=>$item->getId()));
  3378.             $bossVal $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$vacations->getId()));
  3379.             foreach($bossVal as $itemB) {
  3380. //                    $itemB->getStatus()?$status='Approved':$status='Rejected';
  3381. //                    if(is_null($itemB->getStatus())){
  3382. //                        $status='Pending';
  3383. //                    }
  3384.                 if( $itemB->getStatusBoss()==1){
  3385.                     $status='Approved';
  3386.                     $color='#66BB6A';
  3387.                 }
  3388.                 if( $itemB->getStatusBoss()==0){
  3389.                     $status='Rejected';
  3390.                     $color='#EF5350';
  3391.                 }
  3392.                 if(is_null($itemB->getStatusBoss()) ){
  3393.                     $status='Pending';
  3394. //                    $color='#42A5F5';
  3395.                     $color='#f0ad4e';
  3396.                 }
  3397.                 $dataB[] = array(
  3398.                     'date' => $itemB->getDate(),
  3399.                     'status' => $status,
  3400.                     'color'=>$color,
  3401.                     'url'=>''
  3402.                 );
  3403.             }
  3404.             $users $em->getRepository(User::class)->findOneBy(
  3405.                 array(
  3406.                     'id'=>$vacations->getIdu(),
  3407.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3408.                 )
  3409.             )
  3410.             ;
  3411. //            $data = array(
  3412. //                'idv' => $vacations->getId(),
  3413. //                'idu'=>$users->getId(),
  3414. //                'fullname'=> $users->getName().' '.$users->getLastname(),
  3415. //                'date' =>$dataB,
  3416. //                'description'=>$vacations->getDescription()
  3417. //            );
  3418.             $helper  = new VacationsHelper($em);
  3419.             $dataForTheCalendar $helper->retrieveDataForTheCalendar(
  3420.                 $users->getId(),
  3421.                 $bossVal);
  3422.         }
  3423.         $return = array(
  3424.             'dataForTheCalendar' => $dataForTheCalendar
  3425.         );
  3426.         $response = new JsonResponse($return);
  3427.         return $response;
  3428.     }
  3429.     /**
  3430.      * @Route("/vacations/notificationFromTeamLeader/{idv}", name="notificationFromTeamLeader_vacations")
  3431.      * @param $idv
  3432.      * @param Request $request
  3433.      * @return RedirectResponse
  3434.      */
  3435.     public function notificationFromTeamLeaderVacationsAction($idvRequest $request) {
  3436.         $em $this->getDoctrine()->getManager();
  3437.         $helper = new VacationsHelper($em);
  3438.         $vacation $em->getRepository(Vacations::class)->find($idv);
  3439.         if (!is_null($vacation) && !empty($vacation)) {
  3440.             $vacationsValidations $em->getRepository(VacationsValidation::class)
  3441.                 ->findBy(
  3442.                     array(
  3443.                         'idv' => $idv
  3444.                     )
  3445.                 )
  3446.             ;
  3447.             if (!is_null($vacationsValidations) && !empty($vacationsValidations)) {
  3448.                 $vacationCreationDay $vacation->getCreatedAt();
  3449.                 $idu $vacation->getIdu();
  3450.                 $token $vacation->getToken();
  3451.                 $user $em->getRepository(User::class)->find($idu);
  3452.                 if (!is_null($user) && !empty($user)) {
  3453.                     $userRole $user->getRole();
  3454.                     $requestedDays = array();
  3455.                     /**
  3456.                      * @var VacationsValidation $vacationsValidation
  3457.                      */
  3458.                     foreach ($vacationsValidations as $vacationsValidation) {
  3459.                         $requestedDays[] = $vacationsValidation;
  3460.                     }
  3461.                     $data = array(
  3462.                         'idv' => $idv,
  3463.                         'days' => $requestedDays,
  3464.                         'fullname' => $user->getFullName(),
  3465.                         'date' => $vacationCreationDay,
  3466.                         'role' => $userRole,
  3467.                     );
  3468.                     // Recopilamos las direcciones de los administradores
  3469.                     $adminEmails $helper->getEmailsByRole(VacationsConstants::ROLE_ADMIN);
  3470.                     if (!is_null($adminEmails) && !empty($adminEmails)) {
  3471.                         // Formateamos el asunto del mensaje
  3472.                         $teamLeaderOfThisUser $helper->getTeamLeaderByUserID($user->getId());
  3473.                         $subjectTeamLeader VacationsConstants::EMAIL_FROM_TEAMLEADER_SUBJECT;
  3474.                         if (!is_null($teamLeaderOfThisUser) && !empty($teamLeaderOfThisUser)) {
  3475.                             // Si hay jefe de equipo, concatenamos su nombre al asunto.
  3476.                             $teamLeaderFullName $teamLeaderOfThisUser->getFullName();
  3477.                             $subjectTeamLeader $subjectTeamLeader " Por " $teamLeaderFullName;
  3478.                         }
  3479.                         $emailService = new EmailService();
  3480.                         $emailsDelivered $emailService->sendHTMLEmail(
  3481.                             $adminEmails//TO ADDRESS
  3482.                             $subjectTeamLeader,
  3483.                             $this->renderView(
  3484.                                 'vacations/vacations-email-report.html.twig',
  3485.                                 array(
  3486.                                     'data' => $data,
  3487.                                     'token' => $token,
  3488.                                     'idTeamLeader' => $teamLeaderOfThisUser->getId(),
  3489.                                     'isBoss' => true
  3490.                                 )
  3491.                             )
  3492.                         );
  3493.                         if ($emailsDelivered) {
  3494.                             $message $this->translator->trans("Message Correctly Sent");
  3495.                             $messageType 'mensajeholidays';
  3496.                         } else {
  3497.                             $message $this->translator->trans("Your message was not sent");
  3498.                             $messageType 'mensajeholidayserror';
  3499.                         }
  3500.                     } else {
  3501.                         $noAdminUsers $this->translator->trans("No admin users were found");
  3502.                         $messageNotSent $this->translator->trans("Your message was not sent");
  3503.                         $message $noAdminUsers ":" $messageNotSent;
  3504.                         $messageType 'mensajeholidayserror';
  3505.                     }
  3506.                     $this->addFlash($messageType$message);
  3507.                 }
  3508.             }
  3509.         }
  3510.         return $this->redirect('/vacations/check/'.$idv);
  3511.     }
  3512.     /**
  3513.      * @Route("/vacations/dateRange/{idu}/{startDate}", name="dateRange_vacations")
  3514.      * @param $idu
  3515.      * @param $startDate
  3516.      * @param Request $request
  3517.      * @return JsonResponse
  3518.      * @throws Exception
  3519.      */
  3520.     public function getVacationsInDateRange($idu$startDateRequest $request) {
  3521.         $em $this->getDoctrine()->getManager();
  3522.         $isUserIDValid = (!is_null($idu) && !empty($idu));
  3523.         $isStartDateValid = (!is_null($startDate) && !empty($startDate));
  3524.         $endDate date("Y-m-t"strtotime($startDate));
  3525.         $dataForTheCalendar = array();
  3526.         if ($isUserIDValid && $isStartDateValid) {
  3527.             $vacationsValidations $em->getRepository(VacationsValidation::class)
  3528.                 ->getRequestedDaysOfVacationsByUserID($idu$startDate$endDate);
  3529.             if(!empty($vacationsValidations)){
  3530.                 foreach($vacationsValidations as $vacationsValidation) {
  3531.                     if( $vacationsValidation->getStatusBoss()==1){
  3532.                         $status='Approved';
  3533.                         $color='#66BB6A';
  3534.                     }
  3535.                     if( $vacationsValidation->getStatusBoss()==0){
  3536.                         $status='Rejected';
  3537.                         $color='#EF5350';
  3538.                     }
  3539.                     if(is_null($vacationsValidation->getStatusBoss()) ){
  3540.                         $status='Pending';
  3541. //                    $color='#42A5F5';
  3542.                         $color='#f0ad4e';
  3543.                     }
  3544.                     $dataB[] = array(
  3545.                         'date' => $vacationsValidation->getDate(),
  3546.                         'status' => $status,
  3547.                         'color'=>$color,
  3548.                         'url'=>''
  3549.                     );
  3550.                 }
  3551.                 $users $em->getRepository(User::class)->findOneBy(
  3552.                     array(
  3553.                         'id'=>$idu,
  3554.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3555.                     )
  3556.                 )
  3557.                 ;
  3558. d($vacationsValidations);
  3559.                 $helper  = new VacationsHelper($em);
  3560.                 $dataForTheCalendar $helper->retrieveDataForTheCalendar(
  3561.                     $users->getId(),
  3562.                     $vacationsValidations);
  3563.             }
  3564.         }
  3565.         $return = array(
  3566.             'dataForTheCalendar' => $dataForTheCalendar
  3567.         );
  3568.         $response = new JsonResponse($return);
  3569.         return $response;
  3570.     }
  3571.     /**
  3572.      * @Route("/vacations/notesTeamLeader/{idv}", name="get_vacations_notes_team_leader_select")
  3573.      * @param $idv
  3574.      * @param Request $request
  3575.      * @return JsonResponse
  3576.      */
  3577.     public function widgetVacatioNotesTeamLeadertAction($idvRequest $request) {
  3578.         $em $this->getDoctrine()->getManager();
  3579.         $vacations $em->getRepository(Vacations::class)->findOneById($idv);
  3580.         $data = array();
  3581.         if(!empty($vacations)){
  3582.             $bossVal $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$vacations->getId()));
  3583.             foreach($bossVal as $itemB) {
  3584. //                    $itemB->getStatus()?$status='Approved':$status='Rejected';
  3585. //                    if(is_null($itemB->getStatus())){
  3586. //                        $status='Pending';
  3587. //                    }
  3588.                 if( $itemB->getStatus()==1){
  3589.                     $status='Approved';
  3590.                     $color='#66BB6A';
  3591.                 }
  3592.                 if( $itemB->getStatus()==0){
  3593.                     $status='Rejected';
  3594.                     $color='#EF5350';
  3595.                 }
  3596.                 if(is_null($itemB->getStatus()) ){
  3597.                     $status='Pending';
  3598. //                    $color='#42A5F5';
  3599.                     $color='#f0ad4e';
  3600.                 }
  3601.                 $dataB[] = array(
  3602.                     'date' => $itemB->getDate(),
  3603.                     'status' => $status,
  3604.                     'color'=>$color,
  3605.                     'url'=>''
  3606.                 );
  3607.             }
  3608.             $users $em->getRepository(User::class)->findOneBy(
  3609.                 array(
  3610.                     'id'=>$vacations->getIdu(),
  3611.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3612.                 )
  3613.             )
  3614.             ;
  3615.             $data = array(
  3616.                 'idv' => $vacations->getId(),
  3617.                 'idu'=>$users->getId(),
  3618.                 'fullname'=> $users->getName().' '.$users->getLastname(),
  3619.                 'date' =>$dataB,
  3620.                 'description'=>$vacations->getDescription()
  3621.             );
  3622.         }else{
  3623.         }
  3624.         $return = array(
  3625.             'notes' => $data
  3626.         );
  3627.         $response = new JsonResponse($return);
  3628.         return $response;
  3629.     }
  3630.     /**
  3631.      * @Route("/vacations/change/{idd}/{value}", name="change_vacations_notes_select")
  3632.      * @param $idd
  3633.      * @param $value
  3634.      * @param Request $request
  3635.      * @return JsonResponse
  3636.      */
  3637.     public function changeWidgetVacatioNotestAction($idd$valueRequest $request) {
  3638.         $em $this->getDoctrine()->getManager();
  3639.         $helper = new VacationsHelper($em);
  3640.         $message $helper->changeVacationsNote($idd$value);
  3641.         $response = new JsonResponse($message);
  3642.         return $response;
  3643.     }
  3644.     /**
  3645.      * @Route("/vacations/updateVacationsExecutiveBoss/{idv}/{idu}/{idCollection}/{value}", name="updateVacations_executiveBoss")
  3646.      * @param Request $request
  3647.      * @param $idv
  3648.      * @param $idu
  3649.      * @param $idCollection
  3650.      * @param $value
  3651.      * @param LoggerInterface $logger
  3652.      * @param Swift_Mailer $mailer
  3653.      * @return JsonResponse
  3654.      * @throws Exception
  3655.      */
  3656.     public function updateVacationExecutiveBossAction(Request $request$idv$idu$idCollection$valueLoggerInterface $loggerSwift_Mailer $mailer )
  3657.     {
  3658.         $em $this->getDoctrine()->getManager();
  3659.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  3660.         $user_id $user_logueado->getId();
  3661.         if (!is_null($idCollection)) {
  3662.             $thePostIdArray explode(','$idCollection);
  3663.             $em $this->getDoctrine()->getManager();
  3664.             // Actualizamos el número total de días de vacaciones en el caso de aprobarlas.
  3665.             if (VacationsConstants::VACATIONS_ACCEPTED_STATUS === intval($value)) {
  3666.                 $numApprovedDays count($thePostIdArray);
  3667.                 $helper = new VacationsHelper($em);
  3668.                 $helper->updateApprovedDaysOfVacations($idu$numApprovedDays);
  3669.             }
  3670.             $storedVacations true;
  3671.             foreach ($thePostIdArray as $vacationID) {
  3672.                 /**
  3673.                  * @var VacationsValidation $validation
  3674.                  */
  3675.                 $validation $em->getRepository(VacationsValidation::class)->findOneBy(array('id' => $vacationID));
  3676.                 if (!empty($validation)) {
  3677.                     try {
  3678.                         if ("null" === $value) {
  3679.                             $value NULL;
  3680.                         }
  3681.                         $validation->setUpdatedId($user_id);
  3682.                         $validation->setStatusBoss($value);
  3683.                         $em->persist($validation);
  3684.                         $em->flush();
  3685.                     } catch (Exception $e) {
  3686.                         $event 'An error occurred: '.$e->getMessage();
  3687.                         /* Para el log */
  3688.                         $logger->error($event);
  3689.                         /* Para el usuario */
  3690.                         $errorMessage $this->translator->trans($event);
  3691.                         $this->addFlash('mensajeholidayserror'$errorMessage);
  3692.                         $storedVacations false;
  3693.                     }
  3694.                 }
  3695.             }
  3696.             if($storedVacations) {
  3697.                 /**
  3698.                  * @var Vacations   $vacations
  3699.                  */
  3700.                 $vacations=$em->getRepository(Vacations::class)->findOneById($idv);
  3701.                 $vacationsDay $em->getRepository(VacationsValidation::class)->findBy(array('idv'=>$idv));
  3702.                 /**
  3703.                  * @var User    $user
  3704.                  */
  3705.                 $user=$em->getRepository(User::class)->findOneBy(
  3706.                     array(
  3707.                         "id" => $vacations->getIdu(),
  3708.                         "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3709.                     )
  3710.                 );
  3711.                 if (!empty($vacationsDay))
  3712.                 {
  3713.                     $dataB = array();
  3714.                     foreach($vacationsDay as $itemB) {
  3715.                         $itemB->getStatus()?$status='Approved':$status='Rejected';
  3716.                         if(is_null($itemB->getStatus())){
  3717.                             $status='Pending';
  3718.                         }
  3719.                         $itemB->getStatusBoss()?$statusB='Approved':$statusB='Rejected';
  3720.                         if(is_null($itemB->getStatusBoss())){
  3721.                             $statusB='Pending';
  3722.                         }
  3723.                         $dataB[] = array(
  3724.                             'id' => $itemB->getId(),
  3725.                             'date' => $itemB->getDate(),
  3726.                             'status' => $status,
  3727.                             'statusBoss' => $statusB,
  3728.                         );
  3729.                     }
  3730.                     $data = array(
  3731.                         'idv' => $idv,
  3732.                         'days' =>$dataB,
  3733.                         'fullname'=>$user->getFullName(),
  3734.                         'date'=>$vacations->getCreatedAt(),
  3735.                         'role'=>$user->getRole()
  3736.                     );
  3737.                     $message = (new \Swift_Message())
  3738.                         ->setSubject('Solicitud de Vacaciones')
  3739.                         ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  3740.                         ->setTo($user->getEmail())
  3741.                         ->setBody(
  3742.                             $this->renderView(
  3743.                                 'vacations/vacations-email-user-report.html.twig',
  3744.                                 array('data' => $data)
  3745.                             ),'text/html'
  3746.                         );
  3747.                     $mailer->send($message);
  3748.                 }
  3749.             }
  3750.         }
  3751.         $dataForTheCalendar = array();
  3752.         $dataForTheCalendar['numDays'] = 0;
  3753.         // If the $value is for denying all requested days, we aren't going to retrieve data for the calendar
  3754.         $bossVal $em->getRepository(VacationsValidation::class)->findBy(
  3755.             array('idv' => $idv),
  3756.             array('date' => 'ASC')
  3757.         );
  3758.         $dataForTheCalendar = (new VacationsHelper($em))->retrieveDataForTheCalendar(
  3759.             $idu,
  3760.             $bossVal);
  3761.         $return = array(
  3762.             'dataForTheCalendar' => $dataForTheCalendar
  3763.         );
  3764.         $response = new JsonResponse($return);
  3765.         return $response;
  3766.     }
  3767.     /**
  3768.      * @Route("/vacations/updateVacationsTeamLeader/{idv}/{idu}/{idCollection}/{value}", name="updateVacations_teamLeader")
  3769.      * @param Request $request
  3770.      * @param $idv
  3771.      * @param $idu
  3772.      * @param $idCollection
  3773.      * @param $value
  3774.      * @param LoggerInterface $logger
  3775.      * @return JsonResponse
  3776.      * @throws Exception
  3777.      */
  3778.     public function updateVacationTeamLeaderAction(Request $request$idv$idu$idCollection$valueLoggerInterface $logger)
  3779.     {
  3780.         /**
  3781.          * @var User    $loggedUser
  3782.          */
  3783.         $loggedUser $this->get('security.token_storage')->getToken()->getUser();
  3784.         $loggedUserID $loggedUser->getId();
  3785.         if (!is_null($idCollection)) {
  3786.             $thePostIdArray explode(','$idCollection);
  3787.             $em $this->getDoctrine()->getManager();
  3788.             foreach ($thePostIdArray as $vacationID) {
  3789.                 /**
  3790.                  * @var VacationsValidation $validation
  3791.                  */
  3792.                 $validation $em->getRepository(VacationsValidation::class)->findOneBy(array('id' => $vacationID));
  3793.                 if (!empty($validation)) {
  3794.                     try {
  3795.                         $em $this->getDoctrine()->getManager();
  3796.                         if ("null" === $value) {
  3797.                             $value NULL;
  3798.                         }
  3799.                         $validation->setUpdatedId($loggedUserID);
  3800.                         $validation->setStatus($value);
  3801.                         // Si el equipo del usuario logueado (un jefe de equipo) pertenece a uno de los equipos
  3802.                         // dados de alta en la base de datos de equipos autorizados entonces
  3803.                         // su decisión se replicará al jefe ejecutivo
  3804.                         // 1. Recojo el team del $loggedUser
  3805.                         $loggedUserTeam $loggedUser->getTeam();
  3806.                         $isTeamLeaderAsExecutiveBoss VacationsConstants::isTeamLeaderAsExecutiveBoss($loggedUserTeam);
  3807.                         if ($isTeamLeaderAsExecutiveBoss) {
  3808.                             $validation->setStatusBoss($value);
  3809.                         }
  3810.                         // Fin de esta sección
  3811.                         $em->persist($validation);
  3812.                         $em->flush();
  3813.                     } catch (Exception $e) {
  3814. //                        $event = 'An error occurred: '.$e->getMessage();
  3815. //                        /* Para el log */
  3816. //                        $logger->error($event);
  3817. //                        /* Para el usuario */
  3818. //                        $errorMessage = $this->translator->trans($event);
  3819. //                        $this->addFlash('mensajeholidayserror', $errorMessage);
  3820.                     }
  3821.                 }
  3822.             }
  3823.         }
  3824.         $dataForTheCalendar = array();
  3825.         $dataForTheCalendar['numDays'] = 0;
  3826.         // If the $value is for denying all requested days, we aren't going to retrieve data for the calendar
  3827.         $bossVal $em->getRepository(VacationsValidation::class)->findBy(
  3828.             array('idv' => $idv),
  3829.             array('date' => 'ASC')
  3830.         );
  3831.         $dataForTheCalendar = (new VacationsHelper($em))->retrieveDataForTheCalendar(
  3832.             $idu,
  3833.             $bossVal);
  3834.         $return = array(
  3835.             'dataForTheCalendar' => $dataForTheCalendar
  3836.         );
  3837.         $response = new JsonResponse($return);
  3838.         return $response;
  3839.     }
  3840.     /**
  3841.      * @Route("/vacations/changeTeamLeader/{idd}/{value}", name="change_vacations_notes_select_team_leader")
  3842.      * @param $idd
  3843.      * @param $value
  3844.      * @param Request $request
  3845.      * @return JsonResponse
  3846.      */
  3847.     public function changeWidgetVacationTeamLeaderNotestAction($idd,$valueRequest $request) {
  3848.         if($value=='null'$value='';
  3849.         $em $this->getDoctrine()->getManager();
  3850.         $Validation $em->getRepository(VacationsValidation::class)->findOneBy(array('id'=>$idd));
  3851.         if($value=='')$value=null;
  3852.         $message='Error';
  3853.         if(!empty($Validation)) {
  3854.             $message='OK';
  3855.             try{
  3856.                 $Validation->setStatus($value);
  3857.                 $em->persist($Validation);
  3858.                 $em->flush();
  3859.             }catch (\Exception $e){
  3860.                 $message=$e->getMessage();
  3861.             }
  3862.         }
  3863.         $response = new JsonResponse($message);
  3864.         return $response;
  3865.     }
  3866.     /**
  3867.      * @Route("/vacations/transferyear/{idv}", name="user_vacations_tranfer_year")
  3868.      * @param $idv
  3869.      * @param Request $request
  3870.      * @param LoggerInterface $logger
  3871.      * @return RedirectResponse
  3872.      * @throws Exception
  3873.      */
  3874.     public function userTransferYearAction($idvRequest $requestLoggerInterface $logger)
  3875.     {
  3876.         $em $this->getDoctrine()->getManager();
  3877.         $vacationsDay $em->getRepository(Vacations::class)->findOneById($idv);
  3878.         if(!empty($vacationsDay)){
  3879.             $vacationsDayvalidation $em->getRepository(VacationsValidation::class)->findByIdv($idv);
  3880.             foreach($vacationsDayvalidation as $dayvalidate) {
  3881.                 $dayvalidate->setCreatedAt( new \DateTime('now') );
  3882.                 $em->persist($dayvalidate);
  3883.             }
  3884.             try{
  3885.                 $vacationsDay->setCreatedAt( new \DateTime('now') );
  3886.                 $em->persist($vacationsDay);
  3887.                 $em->flush();
  3888.             }catch (\Exception $e){
  3889.                 $event 'An error occurred: '.$e->getMessage();
  3890.                 /* Para el log */
  3891.                 $logger->error($event);
  3892.                 /* Para el usuario */
  3893.                 $errorMessage $this->translator->trans($event);
  3894.                 $this->addFlash('mensajeholidayserror'$errorMessage);
  3895.             }
  3896.         }
  3897.         $event 'The Item has been Updated.';
  3898.         $successMessage $this->translator->trans($event);
  3899.         $this->addFlash('mensajeholidays'$successMessage);
  3900.         /* Fin Gestión de eventos en Log */
  3901.         return $this->redirectToRoute('check_vacations',
  3902.             array(
  3903.                 'idv' => $idv
  3904.             )
  3905.         );
  3906.     }
  3907.     /**
  3908.      * @Route("/vacations/requestedDays/cancel/{token}&{isBoss}", name="cancel_requestedDays_vacations")
  3909.      * @param $token
  3910.      * @param $isBoss
  3911.      * @param Request $request
  3912.      * @param LoggerInterface $logger
  3913.      * @return Response
  3914.      */
  3915.     public function cancelRequestedDaysVacationsAction($token$isBossRequest $requestLoggerInterface $logger)
  3916.     {
  3917.         $em $this->getDoctrine()->getManager();
  3918.         $vacation $em->getRepository(Vacations::class)
  3919.             ->findOneBy(array(
  3920.                             'token' => $token
  3921.                         )
  3922.             )
  3923.         ;
  3924.         $isBoss = ("false" === $isBoss) ? false true;
  3925.         // We fetch the data user who requested these days to show the fullname.
  3926.         $user $em->getRepository(User::class)
  3927.             ->findOneBy(
  3928.                 array(
  3929.                     'id' => $vacation->getIdu(),
  3930.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3931.                 )
  3932.             )
  3933.         ;
  3934.         $idv $vacation->getId();
  3935.         // Once we have fetched the $vacation object, we are going to fetch $vacations_validation with this $idv
  3936.         $vacations_validations $em->getRepository(VacationsValidation::class)
  3937.             ->findBy(array(
  3938.                             'idv' => $idv
  3939.                         )
  3940.             )
  3941.         ;
  3942.         $requestedDays = array();
  3943.         $data = array();
  3944.         if (!empty($vacations_validations)) {
  3945.             foreach ($vacations_validations as $vacations_validation) {
  3946.                 if (!$isBoss) {
  3947.                     $vacations_validation->setStatus(false);
  3948.                 } else {
  3949.                     $vacations_validation->setStatusBoss(false);
  3950.                 }
  3951.                 $em->persist($vacations_validation);
  3952.                 $em->flush();
  3953.                 $requestedDays[] = array(
  3954.                     'date' => $vacations_validation->getDate()
  3955.                 );
  3956.             }
  3957.             $data = array(
  3958.                 'days' =>$requestedDays
  3959.             );
  3960.         }
  3961.         return $this->render(
  3962.             'vacations/vacations-validation-cancelled.html.twig',
  3963.             array(
  3964.                 'data' => $data,
  3965.                 'fullname'=> $user->getName().' '.$user->getLastName(),
  3966.                 'token' => $token,
  3967.                 'isBoss' => $isBoss
  3968.             )
  3969.         )
  3970.         ;
  3971.     }
  3972.     /**
  3973.      * @Route("/vacations/requestedDays/approve/{token}/{isBoss}/", name="approve_requestedDays_vacations")
  3974.      * @param $token
  3975.      * @param $isBoss
  3976.      * @param Request $request
  3977.      * @param LoggerInterface $logger
  3978.      * @return Response
  3979.      */
  3980.     public function approveRequestedDaysVacationsAction($token$isBossRequest $requestLoggerInterface $logger)
  3981.     {
  3982.         $isBoss = ("false" === $isBoss) ? false true;
  3983.         $em $this->getDoctrine()->getManager();
  3984.         $vacation $em->getRepository(Vacations::class)
  3985.             ->findOneBy(array(
  3986.                     'token' => $token
  3987.                 )
  3988.             )
  3989.         ;
  3990.         // We fetch the data user who requested these days to show the fullname.
  3991.         $user $em->getRepository(User::class)
  3992.             ->findOneBy(
  3993.                 array(
  3994.                     'id' => $vacation->getIdu(),
  3995.                     "status" => VacationsConstants::PAYROLL_STAFF_STATUS
  3996.                 )
  3997.             )
  3998.         ;
  3999.         $idv $vacation->getId();
  4000.         // Once we have fetched the $vacation object, we are going to fetch $vacations_validation with this $idv
  4001.         $vacations_validations $em->getRepository(VacationsValidation::class)
  4002.             ->findBy(array(
  4003.                     'idv' => $idv
  4004.                 )
  4005.             )
  4006.         ;
  4007.         $requestedDays = array();
  4008.         $data = array();
  4009.         if (!empty($vacations_validations)) {
  4010.             foreach ($vacations_validations as $vacations_validation) {
  4011.                 if (!$isBoss) {
  4012.                     $vacations_validation->setStatus(true);
  4013.                 } else {
  4014.                     $vacations_validation->setStatusBoss(true);
  4015.                 }
  4016.                 $em->persist($vacations_validation);
  4017.                 $em->flush();
  4018.                 $requestedDays[] = array(
  4019.                     'date' => $vacations_validation->getDate(),
  4020.                     'statusBoss' => ''
  4021.                 );
  4022.             }
  4023.             $data = array(
  4024.                 'days' =>$requestedDays,
  4025.                 'fullname' => $user->getFullName(),
  4026.                 'idv' => $idv,
  4027.                 'date' => $vacation->getCreatedAt(),
  4028.                 'role' => $user->getRole()
  4029.             );
  4030.         }
  4031.         $adminLeaders=$em->getRepository(User::class)->findBy(
  4032.             array(
  4033.                 'role'=>'ROLE_ADMIN',
  4034.                 'status'=>VacationsConstants::PAYROLL_STAFF_STATUS,
  4035.             )
  4036.         )
  4037.         ;
  4038.         $dani $em->getRepository(User::class)->findOneById(16);
  4039.         if (!in_array($dani,$adminLeaders)){
  4040.             $adminLeaders[] = $dani// Agrega a Daniel Guerrero, en caso de que no se encuentre en el arreglo
  4041.         }
  4042.         if(!empty($adminLeaders)) {
  4043.             foreach($adminLeaders as $adminLeader) {
  4044.                 $adminLeaderID $adminLeader->getId();
  4045.                 $adminLeaderEmail=$adminLeader->getEmail();
  4046.                 if (!$isBoss) {
  4047.                     $emailService = new EmailService();
  4048.                     $emailsDelivered $emailService->sendHTMLEmail(
  4049.                         $adminLeaderEmail//TO ADDRESS
  4050.                         'Solicitud de Vacaciones',
  4051.                         $this->renderView(
  4052.                             'vacations/vacations-email-report.html.twig',
  4053.                             array('data' => $data,
  4054.                                 'token'=> $token,
  4055.                                 'idTeamLeader' => $adminLeaderID,
  4056.                                 'isBoss' => true)
  4057.                         )//,
  4058. //                        "desarrollo@develup.solutions",
  4059. //                        "System Mante 3.0"
  4060.                     )
  4061.                     ;
  4062.                 }
  4063.             }
  4064.         }
  4065.         return $this->render(
  4066.             'vacations/vacations-validation-approved.html.twig',
  4067.             array(
  4068.                 'data' => $data,
  4069.                 'fullname'=> $user->getName().' '.$user->getLastName(),
  4070.                 'token'=> $token,
  4071.                 'isBoss' => $isBoss
  4072.             )
  4073.         )
  4074.         ;
  4075.     }
  4076. //    /**
  4077. //     * @Route("/vacations/getMembersOfThisGroup/{teamID}", name="getMembersOfThisGroup_vacations")
  4078. //     * @param Request $request
  4079. //     * @param $teamID
  4080. //     * @return JsonResponse
  4081. //     */
  4082. //    public function getMembersOfThisGroupAction(Request $request, $teamID) {
  4083. //
  4084. //        $em = $this->getDoctrine()->getManager();
  4085. //
  4086. //        $membersOfThisGroup = $em->getRepository(User::class)
  4087. //            ->findBy(array(
  4088. //                    'team' => $teamID,
  4089. //                    'status' => VacationsConstants::PAYROLL_STAFF_STATUS
  4090. //                )
  4091. //            )
  4092. //        ;
  4093. //        foreach($membersOfThisGroup as $memberOfThisGroup){
  4094. //            $datos[] = array(
  4095. //                "id" => $memberOfThisGroup->getId(),
  4096. //                "name" => $memberOfThisGroup->getFullName(),
  4097. //            );
  4098. //        }
  4099. //
  4100. //        $return = array(
  4101. //            'membersOfThisGroup' => $datos,
  4102. //        );
  4103. //
  4104. //        $response = new JsonResponse($return);
  4105. //        return $response;
  4106. //
  4107. //
  4108. //        /* We retrieve the whole collection of members of the group this user belongs to */
  4109. //    }
  4110.     /**
  4111.      * @Route("/vacations/getVacationsByMonth/", name="getVacationsByMonth_vacations")
  4112.      * @param Request $request
  4113.      * @return Response
  4114.      */
  4115.     public function vacationsByMonthAction(Request $request)
  4116.     {
  4117.         $em $this->getDoctrine()->getManager();
  4118.         $helper = new VacationsHelper($em);
  4119.         $month date('n');
  4120.         $vacationsByMonthData $helper->vacationsByMonthData($month);
  4121.         return $this->render(
  4122.             'vacations/vacations-month-list.html.twig', array(
  4123.                 'monthList' => $vacationsByMonthData["monthList"],
  4124.                 'month'=> $month,
  4125.                 'daysOfMonth' => intval($vacationsByMonthData["daysOfMonth"]),
  4126.                 'dataPerDay' => $vacationsByMonthData["dataDay"]
  4127.             )
  4128.         )
  4129.         ;
  4130.     }
  4131.     /**
  4132.      * @Route("/vacations/postVacationsByMonth", name="postVacationsByMonth_vacations")
  4133.      * @param Request $request
  4134.      * @return JsonResponse
  4135.      */
  4136.     public function postVacationsByMonthAction(Request $request) {
  4137.         $em $this->getDoctrine()->getManager();
  4138.         $helper = new VacationsHelper($em);
  4139.         $month $request->request->get("month");
  4140.         if (is_null($month)) {
  4141.             $month date('m');
  4142.         }
  4143.         $vacationsByMonthData $helper->vacationsByMonthData($month);
  4144.         $literalsHeader = array(
  4145.             "days" => $this->translator->trans('Days'),
  4146.             "approvedString" => $this->translator->trans('Staff with approved vacations'),
  4147.             "pendingString" => $this->translator->trans('Staff with pending vacations')
  4148.         );
  4149.         $response = array(
  4150.             "data" => array(
  4151.                 "monthList" =>  $vacationsByMonthData["monthList"],
  4152.                 'month'=> $month,
  4153.                 'daysOfMonth' => intval($vacationsByMonthData["daysOfMonth"]),
  4154.                 'literals' => $literalsHeader,
  4155.                 'dataPerDay' => $vacationsByMonthData["dataDay"]
  4156.             )
  4157.         );
  4158.         return new JsonResponse($response);
  4159.     }
  4160.     /**
  4161.      * @Route("/vacations/exportTo/{month}", name="exportToFormat_vacations")
  4162.      * @param $month
  4163.      * @return StreamedResponse
  4164.      * @throws PhpSpreadsheetException
  4165.      */
  4166.     public function exportToExcelAction($month) {
  4167.         $em $this->getDoctrine()->getManager();
  4168.         $helper = new VacationsHelper($em);
  4169.         $response null;
  4170.         try{
  4171.             $phpExcelObject = new Spreadsheet();
  4172.             $excelData $helper->getExcelData($month);
  4173.             // Crea el writer
  4174.             $writer = new Xlsx($helper->exportToExcel($phpExcelObject,$excelData));
  4175.             // Envia la respuesta del controlador
  4176.             $response = new StreamedResponse(
  4177.                 function () use ($writer) {
  4178.                     $writer->save('php://output');
  4179.                 }
  4180.             );
  4181.             // Agrega los headers requeridos
  4182.             $month++; // Conversión locale inglés al español necesaria para el nombre del fichero.
  4183.             $dispositionHeader $response->headers->makeDisposition(
  4184.                 ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  4185.                 DateHelper::getCurrentYear() . $month VacationsConstants::EXCEL_MONTH_REPORT_FILENAME.".xlsx"
  4186.             );
  4187.             $response->headers->set('Content-Type''application/vnd.ms-excel; charset=utf-8');
  4188.             $response->headers->set('Pragma''public');
  4189.             $response->headers->set('Cache-Control''maxage=1');
  4190.             $response->headers->set('Content-Disposition'$dispositionHeader);
  4191.             return $response;
  4192.         } catch(PhpSpreadsheetException $excelException) {
  4193.         }
  4194. //        $daysOfMonth = DateHelper::getDaysByMonth($month, date(DateConstants::YEAR));
  4195. //        $dataDay = $helper->getDataVacationsValidationOfThisDate($daysOfMonth, $month);
  4196. //
  4197. //        $header = array(
  4198. //            "data" => DateHelper::getMonthNameByID($month)
  4199. //        );
  4200. //        $subheader = array(
  4201. //            "Día", "Personal con vacaciones aceptadas", "Personal con vacaciones pendientes"
  4202. //        );
  4203. //        $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();
  4204. //
  4205. //        $excelArray = array(
  4206. //            'header' => $header,
  4207. //            'subheader' => $subheader,
  4208. //            'data' => $dataDay,
  4209. //            'daysOfMonth' => $daysOfMonth
  4210. //        )
  4211. //        ;
  4212. //
  4213. //        // Crea el writer
  4214. //        $writer = $this->get('phpexcel')->createWriter(
  4215. //            $helper->exportToExcel($phpExcelObject,$excelArray), 'Excel2007');
  4216. //        // Envia la respuesta del controlador
  4217. //        $response = $this->get('phpexcel')->createStreamedResponse($writer);
  4218. //        // Agrega los headers requeridos
  4219. //
  4220. //        $month = $month + 1;
  4221. //        $dispositionHeader = $response->headers->makeDisposition(
  4222. //            ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  4223. //            DateHelper::getCurrentYear() . $month . '_Lista de ausentes y pendientes.xlsx'
  4224. //        );
  4225. //
  4226. //        $response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
  4227. //        $response->headers->set('Pragma', 'public');
  4228. //        $response->headers->set('Cache-Control', 'maxage=1');
  4229. //        $response->headers->set('Content-Disposition', $dispositionHeader);
  4230.         return $response;
  4231.     }
  4232.     /**
  4233.      * @Route("/vacations/manage/{status}", defaults={"status" = "Pending"}, name="vacations_manage")
  4234.      * @param Request $request
  4235.      * @param integer $status 0: rejected; null: pending; 1: approved
  4236.      * @return Response
  4237.      */
  4238.     public function getRequestedDaysListAction($statusRequest $request) {
  4239.         /* Obtengo usuario logueado */
  4240.         /**
  4241.          * @var User    $loggedUserIn
  4242.          */
  4243.         $loggedUserIn $this->get('security.token_storage')->getToken()->getUser();
  4244.         $em $this->getDoctrine()->getManager();
  4245.         $year date('Y');
  4246.         $helper = new VacationsHelper($em);
  4247.         $singleRequestDTOList $helper->getVacationsListByYear(
  4248.             $loggedUserIn,
  4249.             $status,
  4250.             $year
  4251.             )
  4252.         ;
  4253.         return $this->render('vacations/list-vacations.html.twig', array(
  4254.             'requestedDayList' => $singleRequestDTOList,
  4255.             'status' => strval($status),
  4256.             'year' => $year
  4257.         ));
  4258.     }
  4259.     /**
  4260.      * @Route("/vacations/manage/historic/{status}/{year}", name="vacations_manage_historic")
  4261.      * @param $status
  4262.      * @param $year
  4263.      * @param Request $request
  4264.      * @return Response
  4265.      */
  4266.     public function getHistoricRequestedDaysListAction($status$yearRequest $request) {
  4267.         /**
  4268.          * @var User    $loggedUserIn
  4269.          */
  4270.         $loggedUserIn $this->get('security.token_storage')->getToken()->getUser();
  4271.         $em $this->getDoctrine()->getManager();
  4272.         $helper = new VacationsHelper($em);
  4273.         $singleRequestDTOList $helper->getVacationsListByYear(
  4274.             $loggedUserIn,
  4275.             $status,
  4276.             intval($year)
  4277.         )
  4278.         ;
  4279.         return $this->render('vacations/list-vacations.html.twig', array(
  4280.             'requestedDayList' => $singleRequestDTOList,
  4281.             'status' => $status,
  4282.             'year' => $year
  4283.         ));
  4284.     }
  4285. }