src/Controller/HomeController.php line 99

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Client;
  4. use App\Entity\ClientContact;
  5. use App\Entity\MailDelivery;
  6. use App\Entity\SettingsRol;
  7. use App\Entity\Supplier;
  8. use App\Entity\User;
  9. use App\Entity\WidgetNotes;
  10. use App\Form\WidgetNotesType;
  11. use App\MDS\EventsBundle\Entity\Proposal;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpFoundation\Session\Session;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Google_Client;
  19. use Google_Service_Calendar;
  20. use Swift_Mailer;
  21. use Swift_SmtpTransport;
  22. use Symfony\Contracts\Translation\TranslatorInterface;
  23. class HomeController extends AbstractController
  24. {
  25.     protected $googleCalendar;
  26.     private $translator;
  27.     public function __construct(TranslatorInterface $translator)
  28.     {
  29.         //        $redirect_uri='urn:ietf:wg:oauth:2.0:oob';
  30.         $redirect_uri 'https://' $_SERVER['HTTP_HOST'] . '/calendar/token';
  31.         $googleCalendar = new Google_Client();
  32.         $googleCalendar->setApplicationName('Google Calendar API PHP Quickstart');
  33.         //campos a extraer de la base de datos User
  34.         $googleCalendar->setClientId('2790497987-57qc3vu4pr7vb0s8phpub2me58pe34lb.apps.googleusercontent.com');
  35.         $googleCalendar->setClientSecret('nj2C7unaTO68DRhyORsyipSj');
  36.         //fin campos user
  37.         //        $api_key = "AIzaSyBR84cS1IU2BPvk5V3VnbqdkJESlv440Ac";
  38.         //        $client->setDeveloperKey($api_key);
  39.         $googleCalendar->setRedirectUri($redirect_uri);
  40.         $googleCalendar->addScope(Google_Service_Calendar::CALENDAR);
  41.         $guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
  42.         $googleCalendar->setHttpClient($guzzleClient);
  43.         $this->googleCalendar $googleCalendar;
  44.         $this->translator $translator;
  45.     }
  46.     /**
  47.      * @Route("/connectGoogle", name="homepage_Connect_Google")
  48.      */
  49.     public function indexConnectGoogleAction(Request $request)
  50.     {
  51.         $session = new Session();
  52.         $token $session->get('tokenGoogleCalendar');
  53.         //        d($token);
  54.         if (!is_null($token)) {
  55.             $this->googleCalendar->setAccessToken($token);
  56.         }
  57.         // If there is no previous token or it's expired.
  58.         $data = array();
  59.         if ($this->googleCalendar->isAccessTokenExpired()) {
  60.             // Refresh the token if possible, else fetch a new one.
  61.             if ($this->googleCalendar->getRefreshToken()) {
  62.                 $this->googleCalendar->fetchAccessTokenWithRefreshToken($this->googleCalendar->getRefreshToken());
  63.             } else {
  64.                 // Request authorization from the user.
  65.                 $authUrl $this->googleCalendar->createAuthUrl();
  66.                 return $this->redirect($authUrl);
  67.             }
  68.         }
  69.         return $this->redirectToRoute('homepage');
  70.     }
  71.     /**
  72.      * @Route("/", name="homepage")
  73.      */
  74.     public function indexAction(Request $request, \Swift_Mailer $mailer)
  75.     {
  76.         $session = new Session();
  77.         $token $session->get('tokenGoogleCalendar');
  78.         if (!is_null($token)) {
  79.             $this->googleCalendar->setAccessToken($token);
  80.             $connectGoogle "1";
  81.         } else {
  82.             $connectGoogle "0";
  83.         }
  84.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  85.         $user_userrol $user_logueado->getUserrol();
  86.         $user_id $user_logueado->getId();
  87.         $em $this->getDoctrine()->getManager();
  88.         $modules $em->getRepository(SettingsRol::class)->findOneById($user_userrol);
  89.         $request->getSession()->set('_modules'$modules);
  90.         if ($user_logueado->getTeam() == 16) { return $this->redirectToRoute('gp_cvr_calendar'); }
  91.         if ($user_logueado->getTeam() == 17) { return $this->redirectToRoute('ht_calendar'); }
  92.         // ALL LO QUE HAY -- PROPOSAL NO ASIGNADOS
  93.         $parameterspc = array(
  94.             'pending' => 'Pending',
  95.             'confirmed' => 'Confirmed',
  96.         );
  97.         $dqlpc 'SELECT pc FROM EventsBundle:Proposal pc WHERE pc.agentId is null AND (pc.status = :pending or pc.status = :confirmed)';
  98.         $querypc $em->createQuery($dqlpc)->setParameters($parameterspc);
  99.         $cantidadpc $querypc->getResult();
  100.         $request->getSession()->set('_proposal_unassigned'count($cantidadpc));
  101.         /* ALL LO QUE HAY -- ALERTAS DE ToDo */
  102.         $parametersB = array(
  103.             'user_id' => $user_id,
  104.         );
  105.         $dqlB 'SELECT COUNT (tdl.id) 
  106.                 FROM App:ToDoLogs tdl
  107.                 WHERE tdl.readed = FALSE AND tdl.ownerToDoLog = :user_id';
  108.         $query $em->createQuery($dqlB)->setParameters($parametersB);;
  109.         $alertTodo $query->getResult()[0][1];
  110.         $request->getSession()->set('_todoalert'$alertTodo);
  111.         $hoy date('Y-m-d');
  112.         $hoy_datatime = new \DateTime($hoy);
  113.         $parametersA = array(
  114.             'commercialId' => $user_id,
  115.             'alertAt' => $hoy_datatime,
  116.         );
  117.         /* ALL LO QUE HAY  */
  118.         $dql 'SELECT ct.alertAt, ct, cl.title, cn.name, cn.lastName
  119.                 FROM CommercialBundle:CommercialTracking ct
  120.                 INNER JOIN App:Client cl WITH cl.id = ct.clientId
  121.                 INNER JOIN App:ClientContact cn WITH cn.id = ct.contactId
  122.                 WHERE ct.commercialId = :commercialId AND ct.alertAt = :alertAt';
  123.         $query $em->createQuery($dql)->setParameters($parametersA);;
  124.         $commercial_tracking $query->getResult();
  125.         $wnotes = new WidgetNotes();
  126.         $wnotes->setDateAt(new \DateTime("now"));
  127.         $form $this->createWidgetNotesCreateForm($wnotes);
  128.         // EJECUTAR ENVIO DE REPORTE COMERCIAL
  129.         $dia date("l");
  130.         $hora date("H:m");
  131.         //Si es el dia Friday y la hora 17:00
  132.         if ($dia == "Friday" and $hora >= "17:00") {
  133.             //si ya no se hizo antes
  134.             $hoy date("Y-m-d");
  135.             $hoy_datatime = new \DateTime($hoy);
  136.             $consultaMail $em->getRepository(MailDelivery::class)->findOneBy(
  137.                 array(
  138.                     'dateAt' => $hoy_datatime,
  139.                     'system' => 'Informe Seguimiento Commercial Mante3',
  140.                     'send' => 'si'
  141.                 )
  142.             );
  143.             
  144.             if (is_null($consultaMail)) {
  145.                 $this->MandarCorreoSeguimientoComercial($request$mailer);
  146.             }
  147.         }
  148.         if ($user_id == 122) {
  149.             return $this->redirectToRoute('list_news');
  150.         } else {
  151.             return $this->render(
  152.                 'home/index.html.twig',
  153.                 array(
  154.                     'tracking' => $commercial_tracking,
  155.                     'alertTodo' => $alertTodo,
  156.                     'form' => $form->createView(),
  157.                     'user' => $user_id,
  158.                     'token' => $user_logueado->getAccessKey(),
  159.                     'connectGoogle' => $connectGoogle,
  160.                 )
  161.             );
  162.         }
  163.     }
  164.     /**
  165.      * @Route("/calendar-admin", name="calendar-admin")
  166.      */
  167.     public function calendarAdminAction(Request $request)
  168.     {
  169.         $session = new Session();
  170.         $token $session->get('tokenGoogleCalendar');
  171.         if (!is_null($token)) {
  172.             $this->googleCalendar->setAccessToken($token);
  173.             $connectGoogle "1";
  174.         } else {
  175.             $connectGoogle "0";
  176.         }
  177.         //        $em = $this->getDoctrine()->getManager();
  178.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  179.         $user_userrol $user_logueado->getUserrol();
  180.         $user_id $user_logueado->getId();
  181.         $wnotes = new WidgetNotes();
  182.         $wnotes->setDateAt(new \DateTime("now"));
  183.         $form $this->createWidgetNotesCreateForm($wnotes);
  184.         //
  185.         //
  186.         //
  187.         //        $hoy = date('Y-m-d');
  188.         //        $parameters= array(
  189.         //            'createdId' => $user_id,
  190.         //            'hoy' => $hoy
  191.         //        );
  192.         //        $dqlA = 'SELECT wn
  193.         //                    FROM App:WidgetNotes wn
  194.         //                    WHERE wn.createdId = :createdId AND wn.dateAt >= :hoy
  195.         //                    ORDER BY wn.dateAt ASC';
  196.         //        $query = $em->createQuery($dqlA)->setParameters($parameters);
  197.         //        $notes = $query->getResult();
  198.         //
  199.         //        $parametersB= array(
  200.         //            'user_id' => $user_id,
  201.         //        );
  202.         //        $dqlB = 'SELECT COUNT (tdl.id)
  203.         //                FROM App:ToDoLogs tdl
  204.         //                WHERE tdl.readed = FALSE AND tdl.ownerToDoLog = :user_id';
  205.         //        $query = $em->createQuery($dqlB)->setParameters($parametersB);;
  206.         //        $alertTodo = $query->getResult()[0][1];
  207.         //
  208.         //        $hoy_datatime = new \DateTime($hoy);
  209.         //
  210.         //        $parametersA = array(
  211.         //            'commercialId' => $user_id,
  212.         //            'alertAt' => $hoy_datatime,
  213.         //        );
  214.         //        /* ALL LO QUE HAY  */
  215.         //        $dql = 'SELECT ct.alertAt, ct, cl.title, cn.name, cn.lastName
  216.         //                FROM CommercialBundle:CommercialTracking ct
  217.         //                INNER JOIN App:Client cl WITH cl.id = ct.clientId
  218.         //                INNER JOIN App:ClientContact cn WITH cn.id = ct.contactId
  219.         //                WHERE ct.commercialId = :commercialId AND ct.alertAt = :alertAt';
  220.         //
  221.         //        $query = $em->createQuery($dql)->setParameters($parametersA);;
  222.         //        $commercial_tracking = $query->getResult();
  223.         return $this->render(
  224.             'home/calendar-admin.html.twig',
  225.             array(
  226.                 //            'tracking' => $commercial_tracking,
  227.                 //            'alertTodo' => $alertTodo,
  228.                 //            'notes' => $notes,
  229.                 'form' => $form->createView(),
  230.                 'user' => $user_id,
  231.                 'connectGoogle' => $connectGoogle,
  232.                 //            'token' => $user_logueado->getAccessKey(),
  233.             )
  234.         );
  235.     }
  236.     private function createWidgetNotesCreateForm(WidgetNotes $entity)
  237.     {
  238.         $form $this->createForm(WidgetNotesType::class, $entity, array(
  239.             'action' => $this->generateUrl('widget_notes_create'),
  240.             'method' => 'POST'
  241.         ));
  242.         return $form;
  243.     }
  244.     private function createWidgetNotesEditForm(WidgetNotes $entity$id)
  245.     {
  246.         $form $this->createForm(WidgetNotesType::class, $entity, array(
  247.             'action' => $this->generateUrl(
  248.                 'widget_notes_edit',
  249.                 array(
  250.                     'id' => $id
  251.                 )
  252.             ),
  253.             'method' => 'PUT'
  254.         ));
  255.         return $form;
  256.     }
  257.     /**
  258.      * @Route("/ChangeLanguage/{idioma}", name="change_language")
  259.      */
  260.     public function cambioIdioma(Request $request$idioma)
  261.     {
  262.         $this->translator->setLocale($idioma);
  263.         $this->get('session')->set('_locale'$idioma);
  264.         return $this->redirect($request->headers->get('referer'));
  265.     }
  266.     /**
  267.      * @Route("/calendar-full", name="calendar-full")
  268.      */
  269.     public function calendarFullAction(Request $request)
  270.     {
  271.         $token $request->request->get('token');
  272.         $em $this->getDoctrine()->getManager();
  273.         $user_logueado $em->getRepository(User::class)->findOneByAccessKey($token);
  274.         $user_id $user_logueado->getId();
  275.         $wnotes = new WidgetNotes();
  276.         $wnotes->setDateAt(new \DateTime("now"));
  277.         $form $this->createWidgetNotesCreateForm($wnotes);
  278.         $hoy date('Y-m-d');
  279.         $parameters = array(
  280.             'createdId' => $user_id,
  281.             'hoy' => $hoy
  282.         );
  283.         $dqlA 'SELECT wn
  284.                     FROM App:WidgetNotes wn
  285.                     WHERE wn.createdId = :createdId AND wn.dateAt >= :hoy
  286.                     ORDER BY wn.dateAt ASC';
  287.         $query $em->createQuery($dqlA)->setParameters($parameters);
  288.         $notes $query->getResult();
  289.         $parametersB = array(
  290.             'user_id' => $user_id,
  291.         );
  292.         $dqlB 'SELECT COUNT (tdl.id) 
  293.                 FROM App:ToDoLogs tdl
  294.                 WHERE tdl.readed = FALSE AND tdl.ownerToDoLog = :user_id';
  295.         $query $em->createQuery($dqlB)->setParameters($parametersB);;
  296.         $alertTodo $query->getResult()[0][1];
  297.         $hoy_datatime = new \DateTime($hoy);
  298.         $parametersA = array(
  299.             'commercialId' => $user_id,
  300.             'alertAt' => $hoy_datatime,
  301.         );
  302.         /* ALL LO QUE HAY  */
  303.         $dql 'SELECT ct.alertAt, ct, cl.title, cn.name, cn.lastName
  304.                 FROM CommercialBundle:CommercialTracking ct
  305.                 INNER JOIN App:Client cl WITH cl.id = ct.clientId
  306.                 INNER JOIN App:ClientContact cn WITH cn.id = ct.contactId
  307.                 WHERE ct.commercialId = :commercialId AND ct.alertAt = :alertAt';
  308.         $query $em->createQuery($dql)->setParameters($parametersA);;
  309.         $commercial_tracking $query->getResult();
  310.         return $this->render(
  311.             'home/calendar-fullscreen.html.twig',
  312.             array(
  313.                 'tracking' => $commercial_tracking,
  314.                 'alertTodo' => $alertTodo,
  315.                 'notes' => $notes,
  316.                 'form' => $form->createView(),
  317.                 'user' => $user_id,
  318.                 'token' => $token,
  319.             )
  320.         );
  321.     }
  322.     /**
  323.      * @Route("/pdf/calendar-full/{token}", name="calendar-full-pdf")
  324.      */
  325.     public function calendarTokenFullAction($tokenRequest $request)
  326.     {
  327.         //        $token = $request->request->get('token');
  328.         //        d($token);exit();
  329.         $em $this->getDoctrine()->getManager();
  330.         $user_logueado $em->getRepository(User::class)->findOneByAccessKey($token);
  331.         $user_id $user_logueado->getId();
  332.         //        $wnotes = new WidgetNotes();
  333.         //        $wnotes->setDateAt(new \DateTime("now"));
  334.         //        $form = $this->createWidgetNotesCreateForm($wnotes);
  335.         $hoy date('Y-m-d');
  336.         $parameters = array(
  337.             'createdId' => $user_id,
  338.             'hoy' => $hoy
  339.         );
  340.         $dqlA 'SELECT wn
  341.                     FROM App:WidgetNotes wn
  342.                     WHERE wn.createdId = :createdId AND wn.dateAt >= :hoy
  343.                     ORDER BY wn.dateAt ASC';
  344.         $query $em->createQuery($dqlA)->setParameters($parameters);
  345.         $notes $query->getResult();
  346.         $parametersB = array(
  347.             'user_id' => $user_id,
  348.         );
  349.         $dqlB 'SELECT COUNT (tdl.id) 
  350.                 FROM App:ToDoLogs tdl
  351.                 WHERE tdl.readed = FALSE AND tdl.ownerToDoLog = :user_id';
  352.         $query $em->createQuery($dqlB)->setParameters($parametersB);;
  353.         $alertTodo $query->getResult()[0][1];
  354.         $hoy_datatime = new \DateTime($hoy);
  355.         $parametersA = array(
  356.             'commercialId' => $user_id,
  357.             'alertAt' => $hoy_datatime,
  358.         );
  359.         /* ALL LO QUE HAY  */
  360.         $dql 'SELECT ct.alertAt, ct, cl.title, cn.name, cn.lastName
  361.                 FROM CommercialBundle:CommercialTracking ct
  362.                 INNER JOIN App:Client cl WITH cl.id = ct.clientId
  363.                 INNER JOIN App:ClientContact cn WITH cn.id = ct.contactId
  364.                 WHERE ct.commercialId = :commercialId AND ct.alertAt = :alertAt';
  365.         $query $em->createQuery($dql)->setParameters($parametersA);;
  366.         $commercial_tracking $query->getResult();
  367.         return $this->render(
  368.             'home/calendar-pdf.html.twig',
  369.             array(
  370.                 'tracking' => $commercial_tracking,
  371.                 'alertTodo' => $alertTodo,
  372.                 'notes' => $notes,
  373.                 //                'form' => $form->createView(),
  374.                 'user' => $user_id,
  375.                 'token' => $token,
  376.             )
  377.         );
  378.     }
  379.     /**
  380.      * @Route("/calendar-admin-fullscreen", name="calendar-admin-fullscreen")
  381.      */
  382.     public function calendarAdminFullScreenAction(Request $request)
  383.     {
  384.         //        $em = $this->getDoctrine()->getManager();
  385.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  386.         $user_userrol $user_logueado->getUserrol();
  387.         $user_id $user_logueado->getId();
  388.         $wnotes = new WidgetNotes();
  389.         $wnotes->setDateAt(new \DateTime("now"));
  390.         $form $this->createWidgetNotesCreateForm($wnotes);
  391.         //
  392.         //
  393.         //
  394.         //        $hoy = date('Y-m-d');
  395.         //        $parameters= array(
  396.         //            'createdId' => $user_id,
  397.         //            'hoy' => $hoy
  398.         //        );
  399.         //        $dqlA = 'SELECT wn
  400.         //                    FROM App:WidgetNotes wn
  401.         //                    WHERE wn.createdId = :createdId AND wn.dateAt >= :hoy
  402.         //                    ORDER BY wn.dateAt ASC';
  403.         //        $query = $em->createQuery($dqlA)->setParameters($parameters);
  404.         //        $notes = $query->getResult();
  405.         //
  406.         //        $parametersB= array(
  407.         //            'user_id' => $user_id,
  408.         //        );
  409.         //        $dqlB = 'SELECT COUNT (tdl.id)
  410.         //                FROM App:ToDoLogs tdl
  411.         //                WHERE tdl.readed = FALSE AND tdl.ownerToDoLog = :user_id';
  412.         //        $query = $em->createQuery($dqlB)->setParameters($parametersB);;
  413.         //        $alertTodo = $query->getResult()[0][1];
  414.         //
  415.         //        $hoy_datatime = new \DateTime($hoy);
  416.         //
  417.         //        $parametersA = array(
  418.         //            'commercialId' => $user_id,
  419.         //            'alertAt' => $hoy_datatime,
  420.         //        );
  421.         //        /* ALL LO QUE HAY  */
  422.         //        $dql = 'SELECT ct.alertAt, ct, cl.title, cn.name, cn.lastName
  423.         //                FROM CommercialBundle:CommercialTracking ct
  424.         //                INNER JOIN App:Client cl WITH cl.id = ct.clientId
  425.         //                INNER JOIN App:ClientContact cn WITH cn.id = ct.contactId
  426.         //                WHERE ct.commercialId = :commercialId AND ct.alertAt = :alertAt';
  427.         //
  428.         //        $query = $em->createQuery($dql)->setParameters($parametersA);;
  429.         //        $commercial_tracking = $query->getResult();
  430.         return $this->render(
  431.             'home/calendar-admin-fullscreen.html.twig',
  432.             array(
  433.                 //            'tracking' => $commercial_tracking,
  434.                 //            'alertTodo' => $alertTodo,
  435.                 //            'notes' => $notes,
  436.                 'form' => $form->createView(),
  437.                 'user' => $user_id,
  438.                 //            'token' => $user_logueado->getAccessKey(),
  439.             )
  440.         );
  441.     }
  442.     /**
  443.      * @Route("/external/calendar-reservation/okyh759ofiuytd573450j8sdlwdf2", name="calendar-external-fullscreen")
  444.      */
  445.     public function calendarExternalReservasFullScreenAction(Request $request)
  446.     {
  447.         return $this->render('home/calendar-reservation.html.twig');
  448.     }
  449.     /**
  450.      * @Route("/external/proposals/events-reservation", name="calendar_datos_external_reservation")
  451.      */
  452.     public function proposalAdminExternalSelectAction(Request $request)
  453.     {
  454.         $em $this->getDoctrine()->getManager();
  455.         $proposals $em->getRepository(Proposal::class)->findBy(
  456.             array(
  457.                 'status' => array('Confirmed''Invoiced'),
  458.             ),
  459.             array('dateEventStarAt' => 'ASC')
  460.         );
  461.         $datos = array();
  462.         if (!empty($proposals)) {
  463.             foreach ($proposals as $proposal) {
  464.                 $client $em->getRepository(Clientent::class)->findOneById($proposal->getClientId());
  465.                 $user $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  466.                 if (empty($user) || is_null($user)) {
  467.                     //                    d($proposal->getAgentTwoId());
  468.                     if (!is_null($proposal->getTeamId())) {
  469.                         $userAsignar $em->getRepository(User::class)->findOneBy(array('team' => $proposal->getTeamId(), 'teamleader' => 1));
  470.                         $id $userAsignar->getId();
  471.                     } else {
  472.                         $admin $em->getRepository(User::class)->findOneByRole('ROLE_ADMIN');
  473.                         $id $admin->getId();
  474.                     }
  475.                     //                    d($id);
  476.                     $proposal->setAgentId($id);
  477.                     $em->persist($proposal);
  478.                     $em->flush();
  479.                     $user $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  480.                 }
  481.                 $colorHay $user->getColor();
  482.                 if (empty($colorHay)) {
  483.                     $color "#ff0000";
  484.                 } else {
  485.                     $color $user->getColor();
  486.                 }
  487.                 if (is_null($user->getPicture())) {
  488.                     $picture "";
  489.                 } else {
  490.                     $picture "<img src='https://" $_SERVER['HTTP_HOST'] . '/' $user->getPicture() . "' class='img-circle img-lg'><br>";
  491.                 }
  492.                 $tooltip $picture " " .
  493.                     $user->getName() . " " $user->getLastname() . "<br>" .
  494.                     $client->getName() . "<br>" .
  495.                     $proposal->getName() . "</b><br>";
  496.                 $datos[] = array(
  497.                     "id" => $proposal->getId(),
  498.                     "title" => $user->getName() . " " $user->getLastname() . " | " $client->getName() . ": " $proposal->getName(),
  499.                     "tooltip" => $tooltip,
  500.                     "start" => $proposal->getDateEventStarAt(),
  501.                     "end" => $proposal->getDateEventEndAt(),
  502.                     "color" => $color,
  503.                     "url" => null
  504.                 );
  505.             }
  506.         } else {
  507.             $datos = [];
  508.         }
  509.         $return = array(
  510.             'proposal' => $datos,
  511.         );
  512.         $response = new JsonResponse($return);
  513.         return $response;
  514.     }
  515.     /**
  516.      * @Route("/external/envioinformecomercial/ftdkwu6df6dfwyjdfvwsdjvdjyde6w", name="external_informe_comercial_ejecute")
  517.      */
  518.     public function envioInformeComercialxAction(Request $request, \Swift_Mailer $mailer)
  519.     {
  520.         $em $this->getDoctrine()->getManager();
  521.         // EJECUTAR ENVIO DE REPORTE COMERCIAL
  522.         $dia date("l");
  523.         $hora date("H:m");
  524.         //Si es el dia Friday y la hora 17:00
  525.         //        if( $dia == "Friday" AND $hora >= "17:00"){
  526.         //si ya no se hizo antes
  527.         $hoy date("Y-m-d");
  528.         $hoy_datatime = new \DateTime($hoy);
  529.         $consultaMail $em->getRepository('App:MailDelivery')->findOneBy(
  530.             array(
  531.                 'dateAt' => $hoy_datatime,
  532.                 'system' => 'Informe Seguimiento Commercial Mante3',
  533.                 'send' => 'si'
  534.             )
  535.         );
  536.         if (is_null($consultaMail)) {
  537.             $enviarCorreos $this->MandarCorreoSeguimientoComercial($request$mailer);
  538.         }
  539.         //        }
  540.         $response = new Response("enviado"200);
  541.         return $response;
  542.     }
  543.     private function MandarCorreoSeguimientoComercial(Request $request, \Swift_Mailer $mailer)
  544.     {
  545.         $em $this->getDoctrine()->getManager();
  546.         $hoy date("Y-m-d");
  547.         $hoy_datatime = new \DateTime($hoy);
  548. //        $ellunes = date('Y-m-d', strtotime('-4 day'));
  549.         $ellunes date('Y-m-d'strtotime('last monday'));
  550.         $consultaMail $em->getRepository(MailDelivery::class)->findOneBy(
  551.             array(
  552.                 'dateAt' => $hoy_datatime,
  553.                 'system' => 'Informe Seguimiento Commercial Mante3',
  554.                 'send' => 'si'
  555.             )
  556.         );
  557.         if (is_null($consultaMail)) {
  558.             $mailDelivery = new MailDelivery();
  559.             $mailDelivery->setDateAt($hoy_datatime);
  560.             $mailDelivery->setSystem('Informe Seguimiento Commercial Mante3');
  561.             $mailDelivery->setSend('si');
  562.             $em->persist($mailDelivery);
  563.             $em->flush();
  564.             $parametersA = array(
  565.                 'hoy' => $hoy ' 00:00:00',
  566.                 'elLunes' => $ellunes ' 00:00:00',
  567.             );
  568.             $dqlA 'SELECT c
  569.                     FROM CommercialBundle:CommercialTracking c
  570.                     WHERE c.dateAt >= :elLunes AND c.dateAt <= :hoy
  571.                     ORDER BY c.dateAt DESC';
  572.             $queryA $em->createQuery($dqlA)->setParameters($parametersA);
  573.             $tracking $queryA->getResult();
  574.             $data = array();
  575.             foreach ($tracking as $trackings) {
  576.                 $user $em->getRepository(User::class)->findOneById($trackings->getCommercialId());
  577.                 $client $em->getRepository(Client::class)->findOneById($trackings->getClientId());
  578.                 $contact $em->getRepository(ClientContact::class)->findOneById($trackings->getContactId());
  579.                 $fecha $trackings->getDateAt()->format('d/m/Y');
  580.                 // El desarrollo de los proveedores al parecer Jorge no lo finalizo, por eso este condicional se agrega para evitar error 500
  581.                 if (empty($client)) {
  582.                     $client $em->getRepository(Supplier::class)->findOneById($trackings->getSupplierId());
  583.                 }
  584.                 $data[$user->getName() . ' ' $user->getLastName()][] = array(
  585.                     'fecha' => $fecha,
  586.                     'hourIn' => $trackings->getTimeStart()->format('H:m'),
  587.                     'hourOut' => $trackings->getTimeEnd()->format('H:m'),
  588.                     'client' => $client->getName(),
  589.                     'contact' => $contact->getName() . ' ' $contact->getLastName(),
  590.                     'situation' => $this->translator->trans($trackings->getSituation()),
  591.                     'commercial' => $user->getName() . ' ' $user->getLastName(),
  592.                     'observation' => $trackings->getMessage(),
  593.                 );
  594.             }
  595.             $dqlZ 'SELECT c
  596.                     FROM App:Client c
  597.                     WHERE c.createdAt >= :elLunes AND c.createdAt <= :hoy 
  598.                     ORDER BY c.createdAt DESC';
  599.             $queryZ $em->createQuery($dqlZ)->setParameters($parametersA);
  600.             $clientsStoreLastWeek $queryZ->getResult();
  601.             $commercialAgents $em->getRepository(User::class)->findBy(array('team' => 7));  // Grupo Comercial (7)
  602.             $commercialAgentsId = array();
  603.             $dataB = array();
  604.             foreach ($commercialAgents as $item) { $commercialAgentsId[$item->getId()] = $item->getName() . ' ' $item->getLastName(); }
  605.             foreach ($clientsStoreLastWeek as $item) {
  606.                 foreach ($commercialAgentsId as $key => $elem) { if ($item->getCreatedId() == $key) { $dataB[] = array($elem$item); } }
  607.             }
  608.             // Buscamos los correos de los administradores
  609.             $emailarray = array();
  610.             $usermails $em->getRepository(User::class)->findByRole('ROLE_ADMIN');
  611.             foreach ($usermails as $usermail) {
  612.                 $emailarray[] = $usermail->getEmail();
  613.             }
  614.             //            $emailarray = 'gustavo.ayala@develup.solutions';
  615.             $transporter = new Swift_SmtpTransport();
  616.             $transporter->setHost('smtp.gmail.com')
  617.                 ->setEncryption('ssl')//ssl / tls
  618.                 ->setPort(465)// 465 / 587
  619.                 ->setUsername('desarrollo@develup.solutions')
  620.                 ->setPassword('MeDITeRRANeAN_Develup30102023#');
  621.             $mailer = new Swift_Mailer($transporter);
  622.             $message = (new \Swift_Message())
  623.                 ->setSubject('Informe Seguimiento Commercial Mante3')
  624.                 ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  625.                 ->setTo($emailarray)
  626.                 ->setBody(
  627.                     $this->renderView(
  628.                         'MDS/CommercialBundle/emails/list-email-report.html.twig',
  629.                         array('data' => $data'dataB' => $dataB)
  630.                     ),
  631.                     'text/html'
  632.                 );
  633.             $mailer->send($message);
  634.         }
  635.     }
  636. }