src/Controller/ClientListController.php line 3242

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions
  4.  * User: jorge.defreitas@develup.solutions
  5.  * Date: 04/07/2017
  6.  * Time: 17:02
  7.  */
  8. namespace App\Controller;
  9. use App\Entity\Cities;
  10. use App\Entity\Client;
  11. use App\Entity\Country;
  12. use App\Entity\Group;
  13. use App\Entity\Regions;
  14. use App\Entity\User;
  15. use App\Helper\ClientHelper;
  16. use App\MDS\CommercialBundle\Entity\CommercialTracking;
  17. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  23. use PhpOffice\PhpSpreadsheet\Style\Fill;
  24. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  25. use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
  26. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  27. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  28. use Symfony\Component\HttpFoundation\StreamedResponse;
  29. use Symfony\Contracts\Translation\TranslatorInterface;
  30. class ClientListController extends AbstractController
  31. {
  32.     private $translator;
  33.     public function __construct(TranslatorInterface $translator) {
  34.         $this->translator = $translator;
  35.     }
  36.     
  37.     /**
  38.      * @Route("/client", name="client_list")
  39.      */
  40.     public function ClienteListAction(Request $request)
  41.     {
  42. //        $data = $this->primtListClientAction($request);
  43.         $em = $this->getDoctrine()->getManager();
  44.         /* POR GRUPOS EXISTENTES */
  45. //        $dql = 'SELECT cl, gr.title, c.country, p.region, r.city
  46. //                FROM App\Entity\Client cl
  47. //                INNER JOIN App\Entity\Group gr WITH gr.id = cl.groupId
  48. //                INNER JOIN App:Country c WITH c.id = cl.country
  49. //                INNER JOIN App:Regions p WITH p.id = cl.province
  50. //                INNER JOIN App:Cities r WITH r.id = cl.population';
  51.         /* ALL LO QUE HAY  */
  52.         $dql = 'SELECT cl,  c.country, p.name, re.region, r.city
  53.                 FROM App\Entity\Client cl
  54.                 INNER JOIN App:Country c WITH c.id = cl.country
  55.                 INNER JOIN App:Regions re WITH re.id = cl.region
  56.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  57.                 INNER JOIN App:Cities r WITH r.id = cl.population';
  58. //                WHERE p.dateProposedAt >= :desde AND p.dateProposedAt <= :hasta
  59. //                ORDER BY p.dateProposedAt DESC';
  60.         $query = $em->createQuery($dql);
  61.         $clients = $query->getResult();
  62.         foreach($clients as $client){
  63.             $group = $em->getRepository(Group::class)->findOneById($client[0]->getGroupId());
  64.             $parameters = array(
  65.                 'clientId' => $client[0]->getId()
  66.             );
  67.             $dqlc = 'SELECT cc,  u.name, u.lastname
  68.                 FROM App\Entity\ClientContact cc
  69.                 INNER JOIN App\Entity\User u WITH u.id = cc.assignedAgent
  70.                 WHERE cc.clientId = :clientId ';
  71.             $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  72.             $contacts = $queryc->getResult();
  73.             $data_clients[] = array(
  74.                 'client' => $client,
  75.                 'group' => $group,
  76.                 'contacts' => $contacts,
  77.             );
  78.         }
  79.         return $this->render('client/clients-general-list.html.twig',  array( 'datosclientes' => $data_clients, ) );
  80.     }
  81.     /**
  82.      * @Route("/clientsearch", name="client_search")
  83.      */
  84.     public function ClientSearchAction(Request $request)
  85.     {
  86.         $em = $this->getDoctrine()->getManager();
  87.         $dql = 'SELECT cl
  88.                 FROM App\MDS\CommercialBundle\Entity\CommercialTracking cl
  89.                 GROUP BY cl.createdId';
  90.         $query = $em->createQuery($dql);
  91.         $comtrack = $query->getResult();
  92.         $agents = array();
  93.         foreach ($comtrack as $item) {
  94.             $userCreator = $em->getRepository(User::class)->findOneById($item->getCreatedId());
  95.             if (!empty($userCreator)){ $agents[$userCreator->getName() . ' '. $userCreator->getLastName()] = $userCreator; }
  96.         }
  97.         ksort($agents);
  98.         $background = 'assets/images/bg-10.jpg';
  99.         return $this->render('client/clients-search.html.twig', array(
  100.                 'background' => $background,
  101.                 'agents' => $agents,
  102.             )
  103.         );
  104.     }
  105.     /**
  106.      * @Route("/clientsearchzipcode", name="client_search_zipcode")
  107.      */
  108.     public function ClientSearchZipCodeAction(Request $request)
  109.     {
  110.         $em = $this->getDoctrine()->getManager();
  111.         $dato = $_POST['name'];
  112.         $standar = $_POST['criterio'];
  113.         $background = 'assets/images/bg-10.jpg';
  114.         switch ($standar){
  115.             case 'company':
  116.                 $parameters = array();
  117.                 $dqlc = "SELECT cc
  118.                 FROM App\Entity\Client cc
  119.                 WHERE cc.name LIKE '%".$dato."%'  OR cc.title LIKE '%".$dato."%' ";
  120.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  121.                 $competencyClients = $queryc->getResult();
  122.                 $clientList = array();
  123.                 foreach($competencyClients as $client){
  124.                     $picture = $client->getPicture();
  125.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  126.                     //Ordenamos desde el tracking as reciente al mas antiguo
  127.                     $parameters = array( 'clientId' => $client->getId() );
  128.                     $dqlc = 'SELECT ct
  129.                              FROM CommercialBundle:CommercialTracking ct
  130.                              WHERE ct.clientId = :clientId
  131.                              ORDER BY ct.dateAt DESC';
  132.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  133.                     $allClientTrackings = $queryc->getResult();
  134.                     $newTableData = array();
  135.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  136.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  137.                     foreach ($allClientTrackings as $track) {
  138.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  139.                         if (!empty($contactClientInfo)){
  140.                             // allPhones tendrá los telefonos y moviles
  141.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  142.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  143.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  144.                             $arrayContactClientInfo = array(
  145.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  146.                                 'email' => $contactClientInfo->getEmail(),
  147.                                 'allPhones' => $allPhones,
  148.                             );
  149.                         } else {
  150.                             $arrayContactClientInfo = array(
  151.                                 'fullName' => '',
  152.                                 'email' => '',
  153.                                 'allPhones' => '',
  154.                             );
  155.                         }
  156.                         $xlsObservations = $track->getMessage();
  157.                         if(!empty($xlsObservations)){
  158.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  159.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  160.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  161.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  162.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  163.                         }
  164.                         $newTableData[] = array(
  165.                             'id' => $client->getId(),
  166.                             'name' => $client->getName(),
  167.                             'title' => $client->getTitle(),
  168.                             'address' => $client->getAddress(),
  169.                             'addressNumber' => $client->getAddressNumber(),
  170.                             'cityClient' => $cityClient,
  171.                             'zipCode' => $client->getZipCode(),
  172.                             'volume' => $track->getVolume(),
  173.                             'payment' => $track->getPayment(),
  174.                             'situation' => $track->getSituation(),
  175.                             'competency' => $client->getCompetency(),
  176.                             'picture' => $picture,
  177.                             'contact' => $arrayContactClientInfo['fullName'],
  178.                             'email' => $arrayContactClientInfo['email'],
  179.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  180.                             'trackMessage' => $xlsObservations,
  181.                             'trackStatus' => $track->getStatus(),
  182.                             'trackDateAt' => $track->getDateAt(),
  183.                         );
  184.                     }
  185.                     // Si no hay comercial tracking se debe dejar vacio
  186.                     if (empty($newTableData)){
  187.                         $newTableData[] = array(
  188.                             'id' => $client->getId(),
  189.                             'name' => $client->getName(),
  190.                             'title' => $client->getTitle(),
  191.                             'address' => $client->getAddress(),
  192.                             'addressNumber' => $client->getAddressNumber(),
  193.                             'cityClient' => $cityClient,
  194.                             'zipCode' => $client->getZipCode(),
  195.                             'volume' => '',
  196.                             'payment' => '',
  197.                             'situation' => '',
  198.                             'competency' => $client->getCompetency(),
  199.                             'picture' => $picture,
  200.                             'contact' => '',
  201.                             'email' => '',
  202.                             'allPhones' => '',
  203.                             'trackMessage' => '',
  204.                             'trackStatus' => '',
  205.                             'trackDateAt' => '',
  206.                         );
  207.                     }
  208.                     $clientList[] = $newTableData;
  209.                 }
  210.             break;
  211.             case 'zipCode':
  212.                 $parameters = array( 'zipCode' => $dato );
  213.                 $dqlc = 'SELECT cc
  214.                 FROM App\Entity\Client cc
  215.                 WHERE cc.zipCode = :zipCode ';
  216.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  217.                 $competencyClients = $queryc->getResult();
  218.                 $clientList = array();
  219.                 foreach($competencyClients as $client){
  220.                     $picture = $client->getPicture();
  221.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  222.                     //Ordenamos desde el tracking as reciente al mas antiguo
  223.                     $parameters = array( 'clientId' => $client->getId() );
  224.                     $dqlc = 'SELECT ct
  225.                              FROM CommercialBundle:CommercialTracking ct
  226.                              WHERE ct.clientId = :clientId
  227.                              ORDER BY ct.dateAt DESC';
  228.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  229.                     $allClientTrackings = $queryc->getResult();
  230.                     $newTableData = array();
  231.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  232.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  233.                     foreach ($allClientTrackings as $track) {
  234.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  235.                         if (!empty($contactClientInfo)){
  236.                             // allPhones tendrá los telefonos y moviles
  237.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  238.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  239.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  240.                             $arrayContactClientInfo = array(
  241.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  242.                                 'email' => $contactClientInfo->getEmail(),
  243.                                 'allPhones' => $allPhones,
  244.                             );
  245.                         } else {
  246.                             $arrayContactClientInfo = array(
  247.                                 'fullName' => '',
  248.                                 'email' => '',
  249.                                 'allPhones' => '',
  250.                             );
  251.                         }
  252.                         $xlsObservations = $track->getMessage();
  253.                         if(!empty($xlsObservations)){
  254.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  255.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  256.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  257.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  258.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  259.                         }
  260.                         $newTableData[] = array(
  261.                             'id' => $client->getId(),
  262.                             'name' => $client->getName(),
  263.                             'title' => $client->getTitle(),
  264.                             'address' => $client->getAddress(),
  265.                             'addressNumber' => $client->getAddressNumber(),
  266.                             'cityClient' => $cityClient,
  267.                             'zipCode' => $client->getZipCode(),
  268.                             'volume' => $track->getVolume(),
  269.                             'payment' => $track->getPayment(),
  270.                             'situation' => $track->getSituation(),
  271.                             'competency' => $client->getCompetency(),
  272.                             'picture' => $picture,
  273.                             'contact' => $arrayContactClientInfo['fullName'],
  274.                             'email' => $arrayContactClientInfo['email'],
  275.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  276.                             'trackMessage' => $xlsObservations,
  277.                             'trackStatus' => $track->getStatus(),
  278.                             'trackDateAt' => $track->getDateAt(),
  279.                         );
  280.                     }
  281.                     // Si no hay comercial tracking se debe dejar vacio
  282.                     if (empty($newTableData)){
  283.                         $newTableData[] = array(
  284.                             'id' => $client->getId(),
  285.                             'name' => $client->getName(),
  286.                             'title' => $client->getTitle(),
  287.                             'address' => $client->getAddress(),
  288.                             'addressNumber' => $client->getAddressNumber(),
  289.                             'cityClient' => $cityClient,
  290.                             'zipCode' => $client->getZipCode(),
  291.                             'volume' => '',
  292.                             'payment' => '',
  293.                             'situation' => '',
  294.                             'competency' => $client->getCompetency(),
  295.                             'picture' => $picture,
  296.                             'contact' => '',
  297.                             'email' => '',
  298.                             'allPhones' => '',
  299.                             'trackMessage' => '',
  300.                             'trackStatus' => '',
  301.                             'trackDateAt' => '',
  302.                         );
  303.                     }
  304.                     $clientList[] = $newTableData;
  305.                 }
  306. //                $parameters = array( 'zipCode' => $dato );
  307. //                $dqlc = 'SELECT cc
  308. //                FROM App\Entity\Client cc
  309. //                WHERE cc.zipCode = :zipCode ';
  310. //
  311. //                $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  312. //                $zipCodeClients = $queryc->getResult();
  313. //
  314. //                $clientList = array();
  315. //
  316. //                foreach($zipCodeClients as $client){
  317. //
  318. //                    $picture = $client->getPicture();
  319. //                    if(!empty($picture) or $picture !== null){
  320. //                        $picture = $client->getPicture();
  321. //                    }else{
  322. //                        $picture = 'assets/images/placeholder.jpg';
  323. //                    }
  324. //                    $contacts = array();
  325. //                    $contactsInfo = $em->getRepository('App\Entity\ClientContact')->findByClientId($client->getId());
  326. //
  327. //                    foreach ($contactsInfo as $contact){
  328. //                        $contacts[] = array(
  329. //                            'name' => $contact->getName().' '.$contact->getLastName(),
  330. //                        );
  331. //                    }
  332. //                    $clientList[] = array(
  333. //                        'id' => $client->getId(),
  334. //                        'name' => $client->getName(),
  335. //                        'title' => $client->getTitle(),
  336. //                        'competency' => $client->getCompetency(),
  337. //                        'picture' => $picture,
  338. //                        'contact' => $contacts,
  339. //                        'filter' => 'Código Postal',
  340. //                        'data' => $dato,
  341. //                    );
  342. //                }
  343.             break;
  344.             case 'direction':
  345.                 $parameters = array();
  346.                 //                ---DIRECCIÓN---
  347.                 $dqlc = "SELECT cc
  348.                 FROM App\Entity\Client cc
  349.                 WHERE cc.address LIKE '%".$dato."%' ";
  350.                 $queryc = $em->createQuery($dqlc);
  351.                 $directionsPart1 = $queryc->getResult();
  352. //                ---DIRECCIÓN NÚMERO---
  353.                 $dqlc = "SELECT cc
  354.                 FROM App\Entity\Client cc
  355.                 WHERE cc.addressNumber LIKE '%".$dato."%' ";
  356.                 $queryc = $em->createQuery($dqlc);
  357.                 $directionsPart2 = $queryc->getResult();
  358.                 $competencyClients = array_merge($directionsPart1, $directionsPart2);
  359.                 $clientList = array();
  360.                 foreach($competencyClients as $client){
  361.                     $picture = $client->getPicture();
  362.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  363.                     //Ordenamos desde el tracking as reciente al mas antiguo
  364.                     $parameters = array( 'clientId' => $client->getId() );
  365.                     $dqlc = 'SELECT ct
  366.                              FROM CommercialBundle:CommercialTracking ct
  367.                              WHERE ct.clientId = :clientId
  368.                              ORDER BY ct.dateAt DESC';
  369.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  370.                     $allClientTrackings = $queryc->getResult();
  371.                     $newTableData = array();
  372.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  373.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  374.                     foreach ($allClientTrackings as $track) {
  375.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  376.                         if (!empty($contactClientInfo)){
  377.                             // allPhones tendrá los telefonos y moviles
  378.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  379.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  380.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  381.                             $arrayContactClientInfo = array(
  382.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  383.                                 'email' => $contactClientInfo->getEmail(),
  384.                                 'allPhones' => $allPhones,
  385.                             );
  386.                         } else {
  387.                             $arrayContactClientInfo = array(
  388.                                 'fullName' => '',
  389.                                 'email' => '',
  390.                                 'allPhones' => '',
  391.                             );
  392.                         }
  393.                         $xlsObservations = $track->getMessage();
  394.                         if(!empty($xlsObservations)){
  395.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  396.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  397.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  398.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  399.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  400.                         }
  401.                         $newTableData[] = array(
  402.                             'id' => $client->getId(),
  403.                             'name' => $client->getName(),
  404.                             'title' => $client->getTitle(),
  405.                             'address' => $client->getAddress(),
  406.                             'addressNumber' => $client->getAddressNumber(),
  407.                             'cityClient' => $cityClient,
  408.                             'zipCode' => $client->getZipCode(),
  409.                             'volume' => $track->getVolume(),
  410.                             'payment' => $track->getPayment(),
  411.                             'situation' => $track->getSituation(),
  412.                             'competency' => $client->getCompetency(),
  413.                             'picture' => $picture,
  414.                             'contact' => $arrayContactClientInfo['fullName'],
  415.                             'email' => $arrayContactClientInfo['email'],
  416.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  417.                             'trackMessage' => $xlsObservations,
  418.                             'trackStatus' => $track->getStatus(),
  419.                             'trackDateAt' => $track->getDateAt(),
  420.                         );
  421.                     }
  422.                     // Si no hay comercial tracking se debe dejar vacio
  423.                     if (empty($newTableData)){
  424.                         $newTableData[] = array(
  425.                             'id' => $client->getId(),
  426.                             'name' => $client->getName(),
  427.                             'title' => $client->getTitle(),
  428.                             'address' => $client->getAddress(),
  429.                             'addressNumber' => $client->getAddressNumber(),
  430.                             'cityClient' => $cityClient,
  431.                             'zipCode' => $client->getZipCode(),
  432.                             'volume' => '',
  433.                             'payment' => '',
  434.                             'situation' => '',
  435.                             'competency' => $client->getCompetency(),
  436.                             'picture' => $picture,
  437.                             'contact' => '',
  438.                             'email' => '',
  439.                             'allPhones' => '',
  440.                             'trackMessage' => '',
  441.                             'trackStatus' => '',
  442.                             'trackDateAt' => '',
  443.                         );
  444.                     }
  445.                     $clientList[] = $newTableData;
  446.                 }
  447.                 break;
  448.             case 'contact':
  449.                 $arrayDatos = explode(" ", $dato);
  450.                 $parameters = array();
  451.                 $clientsContacts = array();
  452.                 foreach ($arrayDatos as $item){
  453.                     if (strlen($item) > 3) {    // Descartar "la" "de" "del"
  454.                         $dqlc = "SELECT cc
  455.                             FROM App\Entity\ClientContact cc
  456.                             WHERE cc.name LIKE '%" . $item . "%' OR  cc.lastName LIKE '%" . $item . "%'";
  457.                         $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  458.                         $clientsContacts = array_merge($clientsContacts, $queryc->getResult());
  459.                     }
  460.                 }
  461.                 $arrayClients = array();
  462.                 $competencyClients = array();
  463.                 foreach ($clientsContacts as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  464.                 foreach ($arrayClients as $item){
  465.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  466.                     $competencyClients[] = $cli;
  467.                 }
  468.                 $clientList = array();
  469.                 foreach($competencyClients as $client){
  470.                     $picture = $client->getPicture();
  471.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  472.                     //Ordenamos desde el tracking as reciente al mas antiguo
  473.                     $parameters = array( 'clientId' => $client->getId() );
  474.                     $dqlc = 'SELECT ct
  475.                              FROM CommercialBundle:CommercialTracking ct
  476.                              WHERE ct.clientId = :clientId
  477.                              ORDER BY ct.dateAt DESC';
  478.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  479.                     $allClientTrackings = $queryc->getResult();
  480.                     $newTableData = array();
  481.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  482.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  483.                     foreach ($allClientTrackings as $track) {
  484.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  485.                         if (!empty($contactClientInfo)){
  486.                             // allPhones tendrá los telefonos y moviles
  487.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  488.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  489.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  490.                             $arrayContactClientInfo = array(
  491.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  492.                                 'email' => $contactClientInfo->getEmail(),
  493.                                 'allPhones' => $allPhones,
  494.                             );
  495.                         } else {
  496.                             $arrayContactClientInfo = array(
  497.                                 'fullName' => '',
  498.                                 'email' => '',
  499.                                 'allPhones' => '',
  500.                             );
  501.                         }
  502.                         $xlsObservations = $track->getMessage();
  503.                         if(!empty($xlsObservations)){
  504.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  505.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  506.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  507.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  508.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  509.                         }
  510.                         $newTableData[] = array(
  511.                             'id' => $client->getId(),
  512.                             'name' => $client->getName(),
  513.                             'title' => $client->getTitle(),
  514.                             'address' => $client->getAddress(),
  515.                             'addressNumber' => $client->getAddressNumber(),
  516.                             'cityClient' => $cityClient,
  517.                             'zipCode' => $client->getZipCode(),
  518.                             'volume' => $track->getVolume(),
  519.                             'payment' => $track->getPayment(),
  520.                             'situation' => $track->getSituation(),
  521.                             'competency' => $client->getCompetency(),
  522.                             'picture' => $picture,
  523.                             'contact' => $arrayContactClientInfo['fullName'],
  524.                             'email' => $arrayContactClientInfo['email'],
  525.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  526.                             'trackMessage' => $xlsObservations,
  527.                             'trackStatus' => $track->getStatus(),
  528.                             'trackDateAt' => $track->getDateAt(),
  529.                         );
  530.                     }
  531.                     // Si no hay comercial tracking se debe dejar vacio
  532.                     if (empty($newTableData)){
  533.                         $newTableData[] = array(
  534.                             'id' => $client->getId(),
  535.                             'name' => $client->getName(),
  536.                             'title' => $client->getTitle(),
  537.                             'address' => $client->getAddress(),
  538.                             'addressNumber' => $client->getAddressNumber(),
  539.                             'cityClient' => $cityClient,
  540.                             'zipCode' => $client->getZipCode(),
  541.                             'volume' => '',
  542.                             'payment' => '',
  543.                             'situation' => '',
  544.                             'competency' => $client->getCompetency(),
  545.                             'picture' => $picture,
  546.                             'contact' => '',
  547.                             'email' => '',
  548.                             'allPhones' => '',
  549.                             'trackMessage' => '',
  550.                             'trackStatus' => '',
  551.                             'trackDateAt' => '',
  552.                         );
  553.                     }
  554.                     $clientList[] = $newTableData;
  555.                 }
  556.                 break;
  557.             case 'competencies':
  558.                 $parameters = array();
  559.                 $dqlc = "SELECT cc
  560.                 FROM App\Entity\Client cc
  561.                 WHERE cc.competency LIKE '%".$dato."%' ";
  562.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  563.                 $competencyClients = $queryc->getResult();
  564.                 $clientList = array();
  565.                 foreach($competencyClients as $client){
  566.                     $picture = $client->getPicture();
  567.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  568.                     //Ordenamos desde el tracking as reciente al mas antiguo
  569.                     $parameters = array( 'clientId' => $client->getId() );
  570.                     $dqlc = 'SELECT ct
  571.                              FROM CommercialBundle:CommercialTracking ct
  572.                              WHERE ct.clientId = :clientId
  573.                              ORDER BY ct.dateAt DESC';
  574.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  575.                     $allClientTrackings = $queryc->getResult();
  576.                     $newTableData = array();
  577.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  578.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  579.                     foreach ($allClientTrackings as $track) {
  580.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  581.                         if (!empty($contactClientInfo)){
  582.                             // allPhones tendrá los telefonos y moviles
  583.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  584.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  585.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  586.                             $arrayContactClientInfo = array(
  587.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  588.                                 'email' => $contactClientInfo->getEmail(),
  589.                                 'allPhones' => $allPhones,
  590.                             );
  591.                         } else {
  592.                             $arrayContactClientInfo = array(
  593.                                 'fullName' => '',
  594.                                 'email' => '',
  595.                                 'allPhones' => '',
  596.                             );
  597.                         }
  598.                         $xlsObservations = $track->getMessage();
  599.                         if(!empty($xlsObservations)){
  600.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  601.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  602.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  603.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  604.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  605.                         }
  606.                         $newTableData[] = array(
  607.                             'id' => $client->getId(),
  608.                             'name' => $client->getName(),
  609.                             'title' => $client->getTitle(),
  610.                             'address' => $client->getAddress(),
  611.                             'addressNumber' => $client->getAddressNumber(),
  612.                             'cityClient' => $cityClient,
  613.                             'zipCode' => $client->getZipCode(),
  614.                             'volume' => $track->getVolume(),
  615.                             'payment' => $track->getPayment(),
  616.                             'situation' => $track->getSituation(),
  617.                             'competency' => $client->getCompetency(),
  618.                             'picture' => $picture,
  619.                             'contact' => $arrayContactClientInfo['fullName'],
  620.                             'email' => $arrayContactClientInfo['email'],
  621.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  622.                             'trackMessage' => $xlsObservations,
  623.                             'trackStatus' => $track->getStatus(),
  624.                             'trackDateAt' => $track->getDateAt(),
  625.                         );
  626.                     }
  627.                     // Si no hay comercial tracking se debe dejar vacio
  628.                     if (empty($newTableData)){
  629.                         $newTableData[] = array(
  630.                             'id' => $client->getId(),
  631.                             'name' => $client->getName(),
  632.                             'title' => $client->getTitle(),
  633.                             'address' => $client->getAddress(),
  634.                             'addressNumber' => $client->getAddressNumber(),
  635.                             'cityClient' => $cityClient,
  636.                             'zipCode' => $client->getZipCode(),
  637.                             'volume' => '',
  638.                             'payment' => '',
  639.                             'situation' => '',
  640.                             'competency' => $client->getCompetency(),
  641.                             'picture' => $picture,
  642.                             'contact' => '',
  643.                             'email' => '',
  644.                             'allPhones' => '',
  645.                             'trackMessage' => '',
  646.                             'trackStatus' => '',
  647.                             'trackDateAt' => '',
  648.                         );
  649.                     }
  650.                     $clientList[] = $newTableData;
  651.                 }
  652.                 break;
  653.             case 'email':
  654.                 $parameters = array();
  655.                 $dqlc = "SELECT cc
  656.                 FROM App\Entity\ClientContact cc
  657.                 WHERE cc.email LIKE '%".$dato."%' ";
  658.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  659.                 $arrayCompetencyClients = $queryc->getResult();
  660.                 $arrayClients = array();
  661.                 $competencyClients = array();
  662.                 foreach ($arrayCompetencyClients as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  663.                 foreach ($arrayClients as $item){
  664.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  665.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  666.                 }
  667.                 $dqlc = "SELECT cc
  668.                 FROM App\Entity\Client cc
  669.                 WHERE cc.email LIKE '%".$dato."%' ";
  670.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  671.                 $competencyClients = array_merge($competencyClients, $queryc->getResult());
  672.                 $clientList = array();
  673.                 foreach($competencyClients as $client){
  674.                     $picture = $client->getPicture();
  675.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  676.                     //Ordenamos desde el tracking as reciente al mas antiguo
  677.                     $parameters = array( 'clientId' => $client->getId() );
  678.                     $dqlc = 'SELECT ct
  679.                              FROM CommercialBundle:CommercialTracking ct
  680.                              WHERE ct.clientId = :clientId
  681.                              ORDER BY ct.dateAt DESC';
  682.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  683.                     $allClientTrackings = $queryc->getResult();
  684.                     $newTableData = array();
  685.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  686.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  687.                     foreach ($allClientTrackings as $track) {
  688.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  689.                         if (!empty($contactClientInfo)){
  690.                             // allPhones tendrá los telefonos y moviles
  691.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  692.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  693.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  694.                             $arrayContactClientInfo = array(
  695.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  696.                                 'email' => $contactClientInfo->getEmail(),
  697.                                 'allPhones' => $allPhones,
  698.                             );
  699.                         } else {
  700.                             $arrayContactClientInfo = array(
  701.                                 'fullName' => '',
  702.                                 'email' => '',
  703.                                 'allPhones' => '',
  704.                             );
  705.                         }
  706.                         $xlsObservations = $track->getMessage();
  707.                         if(!empty($xlsObservations)){
  708.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  709.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  710.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  711.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  712.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  713.                         }
  714.                         $newTableData[] = array(
  715.                             'id' => $client->getId(),
  716.                             'name' => $client->getName(),
  717.                             'title' => $client->getTitle(),
  718.                             'address' => $client->getAddress(),
  719.                             'addressNumber' => $client->getAddressNumber(),
  720.                             'cityClient' => $cityClient,
  721.                             'zipCode' => $client->getZipCode(),
  722.                             'volume' => $track->getVolume(),
  723.                             'payment' => $track->getPayment(),
  724.                             'situation' => $track->getSituation(),
  725.                             'competency' => $client->getCompetency(),
  726.                             'picture' => $picture,
  727.                             'contact' => $arrayContactClientInfo['fullName'],
  728.                             'email' => $arrayContactClientInfo['email'],
  729.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  730.                             'trackMessage' => $xlsObservations,
  731.                             'trackStatus' => $track->getStatus(),
  732.                             'trackDateAt' => $track->getDateAt(),
  733.                         );
  734.                     }
  735.                     // Si no hay comercial tracking se debe dejar vacio
  736.                     if (empty($newTableData)){
  737.                         $newTableData[] = array(
  738.                             'id' => $client->getId(),
  739.                             'name' => $client->getName(),
  740.                             'title' => $client->getTitle(),
  741.                             'address' => $client->getAddress(),
  742.                             'addressNumber' => $client->getAddressNumber(),
  743.                             'cityClient' => $cityClient,
  744.                             'zipCode' => $client->getZipCode(),
  745.                             'volume' => '',
  746.                             'payment' => '',
  747.                             'situation' => '',
  748.                             'competency' => $client->getCompetency(),
  749.                             'picture' => $picture,
  750.                             'contact' => '',
  751.                             'email' => '',
  752.                             'allPhones' => '',
  753.                             'trackMessage' => '',
  754.                             'trackStatus' => '',
  755.                             'trackDateAt' => '',
  756.                         );
  757.                     }
  758.                     $clientList[] = $newTableData;
  759.                 }
  760.                 break;
  761.             case 'phone':
  762.                 $parameters = array();
  763.                 $dqlc = "SELECT cc
  764.                 FROM App\Entity\ClientContact cc
  765.                 WHERE cc.phone LIKE '%".$dato."%' OR cc.mobile LIKE '%".$dato."%' ";
  766.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  767.                 $arrayCompetencyClients = $queryc->getResult();
  768.                 $arrayClients = array();
  769.                 $competencyClients = array();
  770.                 foreach ($arrayCompetencyClients as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  771.                 foreach ($arrayClients as $item){
  772.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  773.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  774.                 }
  775.                 $dqlc = "SELECT cc
  776.                 FROM App\Entity\Client cc
  777.                 WHERE cc.telephone LIKE '%".$dato."%' ";
  778.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  779.                 $competencyClients = array_merge($competencyClients, $queryc->getResult());
  780.                 $clientList = array();
  781.                 foreach($competencyClients as $client){
  782.                     $picture = $client->getPicture();
  783.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  784.                     //Ordenamos desde el tracking as reciente al mas antiguo
  785.                     $parameters = array( 'clientId' => $client->getId() );
  786.                     $dqlc = 'SELECT ct
  787.                              FROM CommercialBundle:CommercialTracking ct
  788.                              WHERE ct.clientId = :clientId
  789.                              ORDER BY ct.dateAt DESC';
  790.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  791.                     $allClientTrackings = $queryc->getResult();
  792.                     $newTableData = array();
  793.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  794.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  795.                     foreach ($allClientTrackings as $track) {
  796.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  797.                         if (!empty($contactClientInfo)){
  798.                             // allPhones tendrá los telefonos y moviles
  799.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  800.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  801.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  802.                             $arrayContactClientInfo = array(
  803.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  804.                                 'email' => $contactClientInfo->getEmail(),
  805.                                 'allPhones' => $allPhones,
  806.                             );
  807.                         } else {
  808.                             $arrayContactClientInfo = array(
  809.                                 'fullName' => '',
  810.                                 'email' => '',
  811.                                 'allPhones' => '',
  812.                             );
  813.                         }
  814.                         $xlsObservations = $track->getMessage();
  815.                         if(!empty($xlsObservations)){
  816.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  817.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  818.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  819.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  820.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  821.                         }
  822.                         $newTableData[] = array(
  823.                             'id' => $client->getId(),
  824.                             'name' => $client->getName(),
  825.                             'title' => $client->getTitle(),
  826.                             'address' => $client->getAddress(),
  827.                             'addressNumber' => $client->getAddressNumber(),
  828.                             'cityClient' => $cityClient,
  829.                             'zipCode' => $client->getZipCode(),
  830.                             'volume' => $track->getVolume(),
  831.                             'payment' => $track->getPayment(),
  832.                             'situation' => $track->getSituation(),
  833.                             'competency' => $client->getCompetency(),
  834.                             'picture' => $picture,
  835.                             'contact' => $arrayContactClientInfo['fullName'],
  836.                             'email' => $arrayContactClientInfo['email'],
  837.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  838.                             'trackMessage' => $xlsObservations,
  839.                             'trackStatus' => $track->getStatus(),
  840.                             'trackDateAt' => $track->getDateAt(),
  841.                         );
  842.                     }
  843.                     // Si no hay comercial tracking se debe dejar vacio
  844.                     if (empty($newTableData)){
  845.                         $newTableData[] = array(
  846.                             'id' => $client->getId(),
  847.                             'name' => $client->getName(),
  848.                             'title' => $client->getTitle(),
  849.                             'address' => $client->getAddress(),
  850.                             'addressNumber' => $client->getAddressNumber(),
  851.                             'cityClient' => $cityClient,
  852.                             'zipCode' => $client->getZipCode(),
  853.                             'volume' => '',
  854.                             'payment' => '',
  855.                             'situation' => '',
  856.                             'competency' => $client->getCompetency(),
  857.                             'picture' => $picture,
  858.                             'contact' => '',
  859.                             'email' => '',
  860.                             'allPhones' => '',
  861.                             'trackMessage' => '',
  862.                             'trackStatus' => '',
  863.                             'trackDateAt' => '',
  864.                         );
  865.                     }
  866.                     $clientList[] = $newTableData;
  867.                 }
  868.                 break;
  869.             case 'volumeless':
  870.                 $allComTrack = $em->getRepository(CommercialTracking::class)->findAll();
  871.                 $arrayComTrack = array();
  872.                 foreach ($allComTrack as $item){
  873.                     // 200.000; 1050.000 es numero
  874.                     // 2.000.000; 200 000; 200,000; 90000 €; Desconocido; Null, no es un numero
  875.                     $datoVol = str_replace('.','',$item->getVolume());      // Los .
  876.                     $datoVol = str_replace(' ','',$datoVol);                // Los ' '
  877.                     $datoVol = str_replace(',','',$datoVol);                // Los ' '
  878.                     $datoVol = str_replace('€','',$datoVol);                // Los €
  879.                     $datoVol = str_replace('$','',$datoVol);                // Los $
  880.                     // Se busca hasta el volumen indicado. Victor Muñoz
  881.                     if (is_numeric($datoVol)){ if ($datoVol <= $dato) { $arrayComTrack[] = $item; } }
  882.                 }
  883.                 $arrayClients = array();
  884.                 $competencyClients = array();
  885.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  886.                 foreach ($arrayClients as $item){
  887.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  888.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  889.                 }
  890.                 $clientList = array();
  891.                 foreach($competencyClients as $client){
  892.                     $picture = $client->getPicture();
  893.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  894.                     //Ordenamos desde el tracking as reciente al mas antiguo
  895.                     $parameters = array( 'clientId' => $client->getId() );
  896.                     $dqlc = 'SELECT ct
  897.                              FROM CommercialBundle:CommercialTracking ct
  898.                              WHERE ct.clientId = :clientId
  899.                              ORDER BY ct.dateAt DESC';
  900.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  901.                     $allClientTrackings = $queryc->getResult();
  902.                     $newTableData = array();
  903.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  904.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  905.                     foreach ($allClientTrackings as $track) {
  906.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  907.                         if (!empty($contactClientInfo)){
  908.                             // allPhones tendrá los telefonos y moviles
  909.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  910.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  911.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  912.                             $arrayContactClientInfo = array(
  913.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  914.                                 'email' => $contactClientInfo->getEmail(),
  915.                                 'allPhones' => $allPhones,
  916.                             );
  917.                         } else {
  918.                             $arrayContactClientInfo = array(
  919.                                 'fullName' => '',
  920.                                 'email' => '',
  921.                                 'allPhones' => '',
  922.                             );
  923.                         }
  924.                         $xlsObservations = $track->getMessage();
  925.                         if(!empty($xlsObservations)){
  926.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  927.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  928.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  929.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  930.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  931.                         }
  932.                         $newTableData[] = array(
  933.                             'id' => $client->getId(),
  934.                             'name' => $client->getName(),
  935.                             'title' => $client->getTitle(),
  936.                             'address' => $client->getAddress(),
  937.                             'addressNumber' => $client->getAddressNumber(),
  938.                             'cityClient' => $cityClient,
  939.                             'zipCode' => $client->getZipCode(),
  940.                             'volume' => $track->getVolume(),
  941.                             'payment' => $track->getPayment(),
  942.                             'situation' => $track->getSituation(),
  943.                             'competency' => $client->getCompetency(),
  944.                             'picture' => $picture,
  945.                             'contact' => $arrayContactClientInfo['fullName'],
  946.                             'email' => $arrayContactClientInfo['email'],
  947.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  948.                             'trackMessage' => $xlsObservations,
  949.                             'trackStatus' => $track->getStatus(),
  950.                             'trackDateAt' => $track->getDateAt(),
  951.                         );
  952.                     }
  953.                     // Si no hay comercial tracking se debe dejar vacio
  954.                     if (empty($newTableData)){
  955.                         $newTableData[] = array(
  956.                             'id' => $client->getId(),
  957.                             'name' => $client->getName(),
  958.                             'title' => $client->getTitle(),
  959.                             'address' => $client->getAddress(),
  960.                             'addressNumber' => $client->getAddressNumber(),
  961.                             'cityClient' => $cityClient,
  962.                             'zipCode' => $client->getZipCode(),
  963.                             'volume' => '',
  964.                             'payment' => '',
  965.                             'situation' => '',
  966.                             'competency' => $client->getCompetency(),
  967.                             'picture' => $picture,
  968.                             'contact' => '',
  969.                             'email' => '',
  970.                             'allPhones' => '',
  971.                             'trackMessage' => '',
  972.                             'trackStatus' => '',
  973.                             'trackDateAt' => '',
  974.                         );
  975.                     }
  976.                     $clientList[] = $newTableData;
  977.                 }
  978.                 break;
  979.             case 'volumegreat':
  980.                 $allComTrack = $em->getRepository(CommercialTracking::class)->findAll();
  981.                 $arrayComTrack = array();
  982.                 foreach ($allComTrack as $item){
  983.                     // 200.000; 1050.000 es numero
  984.                     // 2.000.000; 200 000; 200,000; 90000 €; Desconocido; Null, no es un numero
  985.                     $datoVol = str_replace('.','',$item->getVolume());      // Los .
  986.                     $datoVol = str_replace(' ','',$datoVol);                // Los ' '
  987.                     $datoVol = str_replace(',','',$datoVol);                // Los ' '
  988.                     $datoVol = str_replace('€','',$datoVol);                // Los €
  989.                     $datoVol = str_replace('$','',$datoVol);                // Los $
  990.                     // Se busca hasta el volumen indicado. Victor Muñoz
  991.                     if (is_numeric($datoVol)){ if ($datoVol >= $dato) { $arrayComTrack[] = $item; } }
  992.                 }
  993.                 $arrayClients = array();
  994.                 $competencyClients = array();
  995.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  996.                 foreach ($arrayClients as $item){
  997.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  998.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  999.                 }
  1000.                 $clientList = array();
  1001.                 foreach($competencyClients as $client){
  1002.                     $picture = $client->getPicture();
  1003.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1004.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1005.                     $parameters = array( 'clientId' => $client->getId() );
  1006.                     $dqlc = 'SELECT ct
  1007.                              FROM CommercialBundle:CommercialTracking ct
  1008.                              WHERE ct.clientId = :clientId
  1009.                              ORDER BY ct.dateAt DESC';
  1010.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1011.                     $allClientTrackings = $queryc->getResult();
  1012.                     $newTableData = array();
  1013.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1014.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1015.                     foreach ($allClientTrackings as $track) {
  1016.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1017.                         if (!empty($contactClientInfo)){
  1018.                             // allPhones tendrá los telefonos y moviles
  1019.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1020.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1021.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1022.                             $arrayContactClientInfo = array(
  1023.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1024.                                 'email' => $contactClientInfo->getEmail(),
  1025.                                 'allPhones' => $allPhones,
  1026.                             );
  1027.                         } else {
  1028.                             $arrayContactClientInfo = array(
  1029.                                 'fullName' => '',
  1030.                                 'email' => '',
  1031.                                 'allPhones' => '',
  1032.                             );
  1033.                         }
  1034.                         $xlsObservations = $track->getMessage();
  1035.                         if(!empty($xlsObservations)){
  1036.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1037.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1038.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1039.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1040.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1041.                         }
  1042.                         $newTableData[] = array(
  1043.                             'id' => $client->getId(),
  1044.                             'name' => $client->getName(),
  1045.                             'title' => $client->getTitle(),
  1046.                             'address' => $client->getAddress(),
  1047.                             'addressNumber' => $client->getAddressNumber(),
  1048.                             'cityClient' => $cityClient,
  1049.                             'zipCode' => $client->getZipCode(),
  1050.                             'volume' => $track->getVolume(),
  1051.                             'payment' => $track->getPayment(),
  1052.                             'situation' => $track->getSituation(),
  1053.                             'competency' => $client->getCompetency(),
  1054.                             'picture' => $picture,
  1055.                             'contact' => $arrayContactClientInfo['fullName'],
  1056.                             'email' => $arrayContactClientInfo['email'],
  1057.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1058.                             'trackMessage' => $xlsObservations,
  1059.                             'trackStatus' => $track->getStatus(),
  1060.                             'trackDateAt' => $track->getDateAt(),
  1061.                         );
  1062.                     }
  1063.                     // Si no hay comercial tracking se debe dejar vacio
  1064.                     if (empty($newTableData)){
  1065.                         $newTableData[] = array(
  1066.                             'id' => $client->getId(),
  1067.                             'name' => $client->getName(),
  1068.                             'title' => $client->getTitle(),
  1069.                             'address' => $client->getAddress(),
  1070.                             'addressNumber' => $client->getAddressNumber(),
  1071.                             'cityClient' => $cityClient,
  1072.                             'zipCode' => $client->getZipCode(),
  1073.                             'volume' => '',
  1074.                             'payment' => '',
  1075.                             'situation' => '',
  1076.                             'competency' => $client->getCompetency(),
  1077.                             'picture' => $picture,
  1078.                             'contact' => '',
  1079.                             'email' => '',
  1080.                             'allPhones' => '',
  1081.                             'trackMessage' => '',
  1082.                             'trackStatus' => '',
  1083.                             'trackDateAt' => '',
  1084.                         );
  1085.                     }
  1086.                     $clientList[] = $newTableData;
  1087.                 }
  1088.                 break;
  1089.             case 'volumeblone':
  1090.                 // Bloque de 0 a 50K
  1091.                 $allComTrack = $em->getRepository(CommercialTracking::class)->findAll();
  1092.                 $arrayComTrack = array();
  1093.                 foreach ($allComTrack as $item){
  1094.                     // 200.000; 1050.000 es numero
  1095.                     // 2.000.000; 200 000; 200,000; 90000 €; Desconocido; Null, no es un numero
  1096.                     $datoVol = str_replace('.','',$item->getVolume());      // Los .
  1097.                     $datoVol = str_replace(' ','',$datoVol);                // Los ' '
  1098.                     $datoVol = str_replace(',','',$datoVol);                // Los ' '
  1099.                     $datoVol = str_replace('€','',$datoVol);                // Los €
  1100.                     $datoVol = str_replace('$','',$datoVol);                // Los $
  1101.                     // Se busca por bloque. Daniel Guerrero
  1102.                     if (is_numeric($datoVol)){ if (($datoVol >= 0) and ($datoVol <= 50000)) { $arrayComTrack[] = $item; } }
  1103.                 }
  1104.                 $arrayClients = array();
  1105.                 $competencyClients = array();
  1106.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  1107.                 foreach ($arrayClients as $item){
  1108.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  1109.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  1110.                 }
  1111.                 $clientList = array();
  1112.                 foreach($competencyClients as $client){
  1113.                     $picture = $client->getPicture();
  1114.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1115.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1116.                     $parameters = array( 'clientId' => $client->getId() );
  1117.                     $dqlc = 'SELECT ct
  1118.                              FROM CommercialBundle:CommercialTracking ct
  1119.                              WHERE ct.clientId = :clientId
  1120.                              ORDER BY ct.dateAt DESC';
  1121.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1122.                     $allClientTrackings = $queryc->getResult();
  1123.                     $newTableData = array();
  1124.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1125.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1126.                     foreach ($allClientTrackings as $track) {
  1127.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1128.                         if (!empty($contactClientInfo)){
  1129.                             // allPhones tendrá los telefonos y moviles
  1130.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1131.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1132.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1133.                             $arrayContactClientInfo = array(
  1134.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1135.                                 'email' => $contactClientInfo->getEmail(),
  1136.                                 'allPhones' => $allPhones,
  1137.                             );
  1138.                         } else {
  1139.                             $arrayContactClientInfo = array(
  1140.                                 'fullName' => '',
  1141.                                 'email' => '',
  1142.                                 'allPhones' => '',
  1143.                             );
  1144.                         }
  1145.                         $xlsObservations = $track->getMessage();
  1146.                         if(!empty($xlsObservations)){
  1147.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1148.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1149.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1150.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1151.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1152.                         }
  1153.                         $newTableData[] = array(
  1154.                             'id' => $client->getId(),
  1155.                             'name' => $client->getName(),
  1156.                             'title' => $client->getTitle(),
  1157.                             'address' => $client->getAddress(),
  1158.                             'addressNumber' => $client->getAddressNumber(),
  1159.                             'cityClient' => $cityClient,
  1160.                             'zipCode' => $client->getZipCode(),
  1161.                             'volume' => $track->getVolume(),
  1162.                             'payment' => $track->getPayment(),
  1163.                             'situation' => $track->getSituation(),
  1164.                             'competency' => $client->getCompetency(),
  1165.                             'picture' => $picture,
  1166.                             'contact' => $arrayContactClientInfo['fullName'],
  1167.                             'email' => $arrayContactClientInfo['email'],
  1168.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1169.                             'trackMessage' => $xlsObservations,
  1170.                             'trackStatus' => $track->getStatus(),
  1171.                             'trackDateAt' => $track->getDateAt(),
  1172.                         );
  1173.                     }
  1174.                     // Si no hay comercial tracking se debe dejar vacio
  1175.                     if (empty($newTableData)){
  1176.                         $newTableData[] = array(
  1177.                             'id' => $client->getId(),
  1178.                             'name' => $client->getName(),
  1179.                             'title' => $client->getTitle(),
  1180.                             'address' => $client->getAddress(),
  1181.                             'addressNumber' => $client->getAddressNumber(),
  1182.                             'cityClient' => $cityClient,
  1183.                             'zipCode' => $client->getZipCode(),
  1184.                             'volume' => '',
  1185.                             'payment' => '',
  1186.                             'situation' => '',
  1187.                             'competency' => $client->getCompetency(),
  1188.                             'picture' => $picture,
  1189.                             'contact' => '',
  1190.                             'email' => '',
  1191.                             'allPhones' => '',
  1192.                             'trackMessage' => '',
  1193.                             'trackStatus' => '',
  1194.                             'trackDateAt' => '',
  1195.                         );
  1196.                     }
  1197.                     $clientList[] = $newTableData;
  1198.                 }
  1199.                 break;
  1200.             case 'volumebltwo':
  1201.                 // Bloque de 50K a 200K
  1202.                 $allComTrack = $em->getRepository(CommercialTracking::class)->findAll();
  1203.                 $arrayComTrack = array();
  1204.                 foreach ($allComTrack as $item){
  1205.                     // 200.000; 1050.000 es numero
  1206.                     // 2.000.000; 200 000; 200,000; 90000 €; Desconocido; Null, no es un numero
  1207.                     $datoVol = str_replace('.','',$item->getVolume());      // Los .
  1208.                     $datoVol = str_replace(' ','',$datoVol);                // Los ' '
  1209.                     $datoVol = str_replace(',','',$datoVol);                // Los ' '
  1210.                     $datoVol = str_replace('€','',$datoVol);                // Los €
  1211.                     $datoVol = str_replace('$','',$datoVol);                // Los $
  1212.                     // Se busca por bloque. Daniel Guerrero
  1213.                     if (is_numeric($datoVol)){ if (($datoVol >= 50000) and ($datoVol <= 200000)) { $arrayComTrack[] = $item; } }
  1214.                 }
  1215.                 $arrayClients = array();
  1216.                 $competencyClients = array();
  1217.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  1218.                 foreach ($arrayClients as $item){
  1219.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  1220.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  1221.                 }
  1222.                 $clientList = array();
  1223.                 foreach($competencyClients as $client){
  1224.                     $picture = $client->getPicture();
  1225.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1226.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1227.                     $parameters = array( 'clientId' => $client->getId() );
  1228.                     $dqlc = 'SELECT ct
  1229.                              FROM CommercialBundle:CommercialTracking ct
  1230.                              WHERE ct.clientId = :clientId
  1231.                              ORDER BY ct.dateAt DESC';
  1232.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1233.                     $allClientTrackings = $queryc->getResult();
  1234.                     $newTableData = array();
  1235.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1236.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1237.                     foreach ($allClientTrackings as $track) {
  1238.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1239.                         if (!empty($contactClientInfo)){
  1240.                             // allPhones tendrá los telefonos y moviles
  1241.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1242.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1243.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1244.                             $arrayContactClientInfo = array(
  1245.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1246.                                 'email' => $contactClientInfo->getEmail(),
  1247.                                 'allPhones' => $allPhones,
  1248.                             );
  1249.                         } else {
  1250.                             $arrayContactClientInfo = array(
  1251.                                 'fullName' => '',
  1252.                                 'email' => '',
  1253.                                 'allPhones' => '',
  1254.                             );
  1255.                         }
  1256.                         $xlsObservations = $track->getMessage();
  1257.                         if(!empty($xlsObservations)){
  1258.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1259.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1260.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1261.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1262.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1263.                         }
  1264.                         $newTableData[] = array(
  1265.                             'id' => $client->getId(),
  1266.                             'name' => $client->getName(),
  1267.                             'title' => $client->getTitle(),
  1268.                             'address' => $client->getAddress(),
  1269.                             'addressNumber' => $client->getAddressNumber(),
  1270.                             'cityClient' => $cityClient,
  1271.                             'zipCode' => $client->getZipCode(),
  1272.                             'volume' => $track->getVolume(),
  1273.                             'payment' => $track->getPayment(),
  1274.                             'situation' => $track->getSituation(),
  1275.                             'competency' => $client->getCompetency(),
  1276.                             'picture' => $picture,
  1277.                             'contact' => $arrayContactClientInfo['fullName'],
  1278.                             'email' => $arrayContactClientInfo['email'],
  1279.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1280.                             'trackMessage' => $xlsObservations,
  1281.                             'trackStatus' => $track->getStatus(),
  1282.                             'trackDateAt' => $track->getDateAt(),
  1283.                         );
  1284.                     }
  1285.                     // Si no hay comercial tracking se debe dejar vacio
  1286.                     if (empty($newTableData)){
  1287.                         $newTableData[] = array(
  1288.                             'id' => $client->getId(),
  1289.                             'name' => $client->getName(),
  1290.                             'title' => $client->getTitle(),
  1291.                             'address' => $client->getAddress(),
  1292.                             'addressNumber' => $client->getAddressNumber(),
  1293.                             'cityClient' => $cityClient,
  1294.                             'zipCode' => $client->getZipCode(),
  1295.                             'volume' => '',
  1296.                             'payment' => '',
  1297.                             'situation' => '',
  1298.                             'competency' => $client->getCompetency(),
  1299.                             'picture' => $picture,
  1300.                             'contact' => '',
  1301.                             'email' => '',
  1302.                             'allPhones' => '',
  1303.                             'trackMessage' => '',
  1304.                             'trackStatus' => '',
  1305.                             'trackDateAt' => '',
  1306.                         );
  1307.                     }
  1308.                     $clientList[] = $newTableData;
  1309.                 }
  1310.                 break;
  1311.             case 'volumeblthr':
  1312.                 // Bloque de 200K a 500K
  1313.                 $allComTrack = $em->getRepository(CommercialTracking::class)->findAll();
  1314.                 $arrayComTrack = array();
  1315.                 foreach ($allComTrack as $item){
  1316.                     // 200.000; 1050.000 es numero
  1317.                     // 2.000.000; 200 000; 200,000; 90000 €; Desconocido; Null, no es un numero
  1318.                     $datoVol = str_replace('.','',$item->getVolume());      // Los .
  1319.                     $datoVol = str_replace(' ','',$datoVol);                // Los ' '
  1320.                     $datoVol = str_replace(',','',$datoVol);                // Los ' '
  1321.                     $datoVol = str_replace('€','',$datoVol);                // Los €
  1322.                     $datoVol = str_replace('$','',$datoVol);                // Los $
  1323.                     // Se busca por bloque. Daniel Guerrero
  1324.                     if (is_numeric($datoVol)){ if (($datoVol >= 200000) and ($datoVol <= 500000)) { $arrayComTrack[] = $item; } }
  1325.                 }
  1326.                 $arrayClients = array();
  1327.                 $competencyClients = array();
  1328.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  1329.                 foreach ($arrayClients as $item){
  1330.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  1331.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  1332.                 }
  1333.                 $clientList = array();
  1334.                 foreach($competencyClients as $client){
  1335.                     $picture = $client->getPicture();
  1336.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1337.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1338.                     $parameters = array( 'clientId' => $client->getId() );
  1339.                     $dqlc = 'SELECT ct
  1340.                              FROM CommercialBundle:CommercialTracking ct
  1341.                              WHERE ct.clientId = :clientId
  1342.                              ORDER BY ct.dateAt DESC';
  1343.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1344.                     $allClientTrackings = $queryc->getResult();
  1345.                     $newTableData = array();
  1346.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1347.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1348.                     foreach ($allClientTrackings as $track) {
  1349.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1350.                         if (!empty($contactClientInfo)){
  1351.                             // allPhones tendrá los telefonos y moviles
  1352.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1353.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1354.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1355.                             $arrayContactClientInfo = array(
  1356.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1357.                                 'email' => $contactClientInfo->getEmail(),
  1358.                                 'allPhones' => $allPhones,
  1359.                             );
  1360.                         } else {
  1361.                             $arrayContactClientInfo = array(
  1362.                                 'fullName' => '',
  1363.                                 'email' => '',
  1364.                                 'allPhones' => '',
  1365.                             );
  1366.                         }
  1367.                         $xlsObservations = $track->getMessage();
  1368.                         if(!empty($xlsObservations)){
  1369.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1370.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1371.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1372.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1373.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1374.                         }
  1375.                         $newTableData[] = array(
  1376.                             'id' => $client->getId(),
  1377.                             'name' => $client->getName(),
  1378.                             'title' => $client->getTitle(),
  1379.                             'address' => $client->getAddress(),
  1380.                             'addressNumber' => $client->getAddressNumber(),
  1381.                             'cityClient' => $cityClient,
  1382.                             'zipCode' => $client->getZipCode(),
  1383.                             'volume' => $track->getVolume(),
  1384.                             'payment' => $track->getPayment(),
  1385.                             'situation' => $track->getSituation(),
  1386.                             'competency' => $client->getCompetency(),
  1387.                             'picture' => $picture,
  1388.                             'contact' => $arrayContactClientInfo['fullName'],
  1389.                             'email' => $arrayContactClientInfo['email'],
  1390.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1391.                             'trackMessage' => $xlsObservations,
  1392.                             'trackStatus' => $track->getStatus(),
  1393.                             'trackDateAt' => $track->getDateAt(),
  1394.                         );
  1395.                     }
  1396.                     // Si no hay comercial tracking se debe dejar vacio
  1397.                     if (empty($newTableData)){
  1398.                         $newTableData[] = array(
  1399.                             'id' => $client->getId(),
  1400.                             'name' => $client->getName(),
  1401.                             'title' => $client->getTitle(),
  1402.                             'address' => $client->getAddress(),
  1403.                             'addressNumber' => $client->getAddressNumber(),
  1404.                             'cityClient' => $cityClient,
  1405.                             'zipCode' => $client->getZipCode(),
  1406.                             'volume' => '',
  1407.                             'payment' => '',
  1408.                             'situation' => '',
  1409.                             'competency' => $client->getCompetency(),
  1410.                             'picture' => $picture,
  1411.                             'contact' => '',
  1412.                             'email' => '',
  1413.                             'allPhones' => '',
  1414.                             'trackMessage' => '',
  1415.                             'trackStatus' => '',
  1416.                             'trackDateAt' => '',
  1417.                         );
  1418.                     }
  1419.                     $clientList[] = $newTableData;
  1420.                 }
  1421.                 break;
  1422.             case 'volumeblfour':
  1423.                 // Bloque de 500K en adelante
  1424.                 $allComTrack = $em->getRepository(CommercialTracking::class)->findAll();
  1425.                 $arrayComTrack = array();
  1426.                 foreach ($allComTrack as $item){
  1427.                     // 200.000; 1050.000 es numero
  1428.                     // 2.000.000; 200 000; 200,000; 90000 €; Desconocido; Null, no es un numero
  1429.                     $datoVol = str_replace('.','',$item->getVolume());      // Los .
  1430.                     $datoVol = str_replace(' ','',$datoVol);                // Los ' '
  1431.                     $datoVol = str_replace(',','',$datoVol);                // Los ' '
  1432.                     $datoVol = str_replace('€','',$datoVol);                // Los €
  1433.                     $datoVol = str_replace('$','',$datoVol);                // Los $
  1434.                     // Se busca por bloque. Daniel Guerrero
  1435.                     if (is_numeric($datoVol)){ if ($datoVol >= 500000) { $arrayComTrack[] = $item; } }
  1436.                 }
  1437.                 $arrayClients = array();
  1438.                 $competencyClients = array();
  1439.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  1440.                 foreach ($arrayClients as $item){
  1441.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  1442.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  1443.                 }
  1444.                 $clientList = array();
  1445.                 foreach($competencyClients as $client){
  1446.                     $picture = $client->getPicture();
  1447.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1448.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1449.                     $parameters = array( 'clientId' => $client->getId() );
  1450.                     $dqlc = 'SELECT ct
  1451.                              FROM CommercialBundle:CommercialTracking ct
  1452.                              WHERE ct.clientId = :clientId
  1453.                              ORDER BY ct.dateAt DESC';
  1454.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1455.                     $allClientTrackings = $queryc->getResult();
  1456.                     $newTableData = array();
  1457.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1458.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1459.                     foreach ($allClientTrackings as $track) {
  1460.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1461.                         if (!empty($contactClientInfo)){
  1462.                             // allPhones tendrá los telefonos y moviles
  1463.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1464.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1465.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1466.                             $arrayContactClientInfo = array(
  1467.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1468.                                 'email' => $contactClientInfo->getEmail(),
  1469.                                 'allPhones' => $allPhones,
  1470.                             );
  1471.                         } else {
  1472.                             $arrayContactClientInfo = array(
  1473.                                 'fullName' => '',
  1474.                                 'email' => '',
  1475.                                 'allPhones' => '',
  1476.                             );
  1477.                         }
  1478.                         $xlsObservations = $track->getMessage();
  1479.                         if(!empty($xlsObservations)){
  1480.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1481.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1482.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1483.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1484.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1485.                         }
  1486.                         $newTableData[] = array(
  1487.                             'id' => $client->getId(),
  1488.                             'name' => $client->getName(),
  1489.                             'title' => $client->getTitle(),
  1490.                             'address' => $client->getAddress(),
  1491.                             'addressNumber' => $client->getAddressNumber(),
  1492.                             'cityClient' => $cityClient,
  1493.                             'zipCode' => $client->getZipCode(),
  1494.                             'volume' => $track->getVolume(),
  1495.                             'payment' => $track->getPayment(),
  1496.                             'situation' => $track->getSituation(),
  1497.                             'competency' => $client->getCompetency(),
  1498.                             'picture' => $picture,
  1499.                             'contact' => $arrayContactClientInfo['fullName'],
  1500.                             'email' => $arrayContactClientInfo['email'],
  1501.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1502.                             'trackMessage' => $xlsObservations,
  1503.                             'trackStatus' => $track->getStatus(),
  1504.                             'trackDateAt' => $track->getDateAt(),
  1505.                         );
  1506.                     }
  1507.                     // Si no hay comercial tracking se debe dejar vacio
  1508.                     if (empty($newTableData)){
  1509.                         $newTableData[] = array(
  1510.                             'id' => $client->getId(),
  1511.                             'name' => $client->getName(),
  1512.                             'title' => $client->getTitle(),
  1513.                             'address' => $client->getAddress(),
  1514.                             'addressNumber' => $client->getAddressNumber(),
  1515.                             'cityClient' => $cityClient,
  1516.                             'zipCode' => $client->getZipCode(),
  1517.                             'volume' => '',
  1518.                             'payment' => '',
  1519.                             'situation' => '',
  1520.                             'competency' => $client->getCompetency(),
  1521.                             'picture' => $picture,
  1522.                             'contact' => '',
  1523.                             'email' => '',
  1524.                             'allPhones' => '',
  1525.                             'trackMessage' => '',
  1526.                             'trackStatus' => '',
  1527.                             'trackDateAt' => '',
  1528.                         );
  1529.                     }
  1530.                     $clientList[] = $newTableData;
  1531.                 }
  1532.                 break;
  1533.             case 'agent':
  1534.                 $dato = $_POST['agentes'];
  1535.                 $parameters = array( 'userid' => $dato );
  1536.                 $dqlc = 'SELECT ct
  1537.                          FROM CommercialBundle:CommercialTracking ct
  1538.                          WHERE ct.createdId = :userid OR ct.updatedId = :userid';
  1539.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1540.                 $arrayComTrack = $queryc->getResult();
  1541.                 $arrayClients = array();
  1542.                 $competencyClients = array();
  1543.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  1544.                 foreach ($arrayClients as $item){
  1545.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  1546.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  1547.                 }
  1548.                 $clientList = array();
  1549.                 foreach($competencyClients as $client){
  1550.                     $picture = $client->getPicture();
  1551.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1552.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1553.                     $parameters = array( 'clientId' => $client->getId() );
  1554.                     $dqlc = 'SELECT ct
  1555.                              FROM CommercialBundle:CommercialTracking ct
  1556.                              WHERE ct.clientId = :clientId
  1557.                              ORDER BY ct.dateAt DESC';
  1558.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1559.                     $allClientTrackings = $queryc->getResult();
  1560.                     $newTableData = array();
  1561.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1562.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1563.                     foreach ($allClientTrackings as $track) {
  1564.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1565.                         if (!empty($contactClientInfo)){
  1566.                             // allPhones tendrá los telefonos y moviles
  1567.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1568.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1569.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1570.                             $arrayContactClientInfo = array(
  1571.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1572.                                 'email' => $contactClientInfo->getEmail(),
  1573.                                 'allPhones' => $allPhones,
  1574.                             );
  1575.                         } else {
  1576.                             $arrayContactClientInfo = array(
  1577.                                 'fullName' => '',
  1578.                                 'email' => '',
  1579.                                 'allPhones' => '',
  1580.                             );
  1581.                         }
  1582.                         $xlsObservations = $track->getMessage();
  1583.                         if(!empty($xlsObservations)){
  1584.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1585.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1586.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1587.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1588.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1589.                         }
  1590.                         $newTableData[] = array(
  1591.                             'id' => $client->getId(),
  1592.                             'name' => $client->getName(),
  1593.                             'title' => $client->getTitle(),
  1594.                             'address' => $client->getAddress(),
  1595.                             'addressNumber' => $client->getAddressNumber(),
  1596.                             'cityClient' => $cityClient,
  1597.                             'zipCode' => $client->getZipCode(),
  1598.                             'volume' => $track->getVolume(),
  1599.                             'payment' => $track->getPayment(),
  1600.                             'situation' => $track->getSituation(),
  1601.                             'competency' => $client->getCompetency(),
  1602.                             'picture' => $picture,
  1603.                             'contact' => $arrayContactClientInfo['fullName'],
  1604.                             'email' => $arrayContactClientInfo['email'],
  1605.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1606.                             'trackMessage' => $xlsObservations,
  1607.                             'trackStatus' => $track->getStatus(),
  1608.                             'trackDateAt' => $track->getDateAt(),
  1609.                         );
  1610.                     }
  1611.                     // Si no hay comercial tracking se debe dejar vacio
  1612.                     if (empty($newTableData)){
  1613.                         $newTableData[] = array(
  1614.                             'id' => $client->getId(),
  1615.                             'name' => $client->getName(),
  1616.                             'title' => $client->getTitle(),
  1617.                             'address' => $client->getAddress(),
  1618.                             'addressNumber' => $client->getAddressNumber(),
  1619.                             'cityClient' => $cityClient,
  1620.                             'zipCode' => $client->getZipCode(),
  1621.                             'volume' => '',
  1622.                             'payment' => '',
  1623.                             'situation' => '',
  1624.                             'competency' => $client->getCompetency(),
  1625.                             'picture' => $picture,
  1626.                             'contact' => '',
  1627.                             'email' => '',
  1628.                             'allPhones' => '',
  1629.                             'trackMessage' => '',
  1630.                             'trackStatus' => '',
  1631.                             'trackDateAt' => '',
  1632.                         );
  1633.                     }
  1634.                     $clientList[] = $newTableData;
  1635.                 }
  1636.                 break;
  1637.             case 'pay':
  1638.                 $dato = $_POST['pago'];
  1639.                 $parameters = array( 'pay' => $dato );
  1640.                 $dqlc = 'SELECT ct
  1641.                          FROM CommercialBundle:CommercialTracking ct
  1642.                          WHERE ct.payment = :pay';
  1643.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1644.                 $arrayComTrack = $queryc->getResult();
  1645.                 $arrayClients = array();
  1646.                 $competencyClients = array();
  1647.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  1648.                 foreach ($arrayClients as $item){
  1649.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  1650.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  1651.                 }
  1652.                 $clientList = array();
  1653.                 foreach($competencyClients as $client){
  1654.                     $picture = $client->getPicture();
  1655.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1656.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1657.                     $parameters = array( 'clientId' => $client->getId() );
  1658.                     $dqlc = 'SELECT ct
  1659.                              FROM CommercialBundle:CommercialTracking ct
  1660.                              WHERE ct.clientId = :clientId
  1661.                              ORDER BY ct.dateAt DESC';
  1662.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1663.                     $allClientTrackings = $queryc->getResult();
  1664.                     $newTableData = array();
  1665.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1666.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1667.                     foreach ($allClientTrackings as $track) {
  1668.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1669.                         if (!empty($contactClientInfo)){
  1670.                             // allPhones tendrá los telefonos y moviles
  1671.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1672.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1673.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1674.                             $arrayContactClientInfo = array(
  1675.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1676.                                 'email' => $contactClientInfo->getEmail(),
  1677.                                 'allPhones' => $allPhones,
  1678.                             );
  1679.                         } else {
  1680.                             $arrayContactClientInfo = array(
  1681.                                 'fullName' => '',
  1682.                                 'email' => '',
  1683.                                 'allPhones' => '',
  1684.                             );
  1685.                         }
  1686.                         $xlsObservations = $track->getMessage();
  1687.                         if(!empty($xlsObservations)){
  1688.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1689.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1690.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1691.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1692.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1693.                         }
  1694.                         $newTableData[] = array(
  1695.                             'id' => $client->getId(),
  1696.                             'name' => $client->getName(),
  1697.                             'title' => $client->getTitle(),
  1698.                             'address' => $client->getAddress(),
  1699.                             'addressNumber' => $client->getAddressNumber(),
  1700.                             'cityClient' => $cityClient,
  1701.                             'zipCode' => $client->getZipCode(),
  1702.                             'volume' => $track->getVolume(),
  1703.                             'payment' => $track->getPayment(),
  1704.                             'situation' => $track->getSituation(),
  1705.                             'competency' => $client->getCompetency(),
  1706.                             'picture' => $picture,
  1707.                             'contact' => $arrayContactClientInfo['fullName'],
  1708.                             'email' => $arrayContactClientInfo['email'],
  1709.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1710.                             'trackMessage' => $xlsObservations,
  1711.                             'trackStatus' => $track->getStatus(),
  1712.                             'trackDateAt' => $track->getDateAt(),
  1713.                         );
  1714.                     }
  1715.                     // Si no hay comercial tracking se debe dejar vacio
  1716.                     if (empty($newTableData)){
  1717.                         $newTableData[] = array(
  1718.                             'id' => $client->getId(),
  1719.                             'name' => $client->getName(),
  1720.                             'title' => $client->getTitle(),
  1721.                             'address' => $client->getAddress(),
  1722.                             'addressNumber' => $client->getAddressNumber(),
  1723.                             'cityClient' => $cityClient,
  1724.                             'zipCode' => $client->getZipCode(),
  1725.                             'volume' => '',
  1726.                             'payment' => '',
  1727.                             'situation' => '',
  1728.                             'competency' => $client->getCompetency(),
  1729.                             'picture' => $picture,
  1730.                             'contact' => '',
  1731.                             'email' => '',
  1732.                             'allPhones' => '',
  1733.                             'trackMessage' => '',
  1734.                             'trackStatus' => '',
  1735.                             'trackDateAt' => '',
  1736.                         );
  1737.                     }
  1738.                     $clientList[] = $newTableData;
  1739.                 }
  1740.                 break;
  1741.             case 'situation':
  1742.                 $dato = $_POST['situacion'];
  1743.                 $parameters = array( 'situation' => $dato );
  1744.                 $dqlc = 'SELECT ct
  1745.                          FROM CommercialBundle:CommercialTracking ct
  1746.                          WHERE ct.situation = :situation';
  1747.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1748.                 $arrayComTrack = $queryc->getResult();
  1749.                 $arrayClients = array();
  1750.                 $competencyClients = array();
  1751.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  1752.                 foreach ($arrayClients as $item){
  1753.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  1754.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  1755.                 }
  1756.                 $clientList = array();
  1757.                 foreach($competencyClients as $client){
  1758.                     $picture = $client->getPicture();
  1759.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1760.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1761.                     $parameters = array( 'clientId' => $client->getId() );
  1762.                     $dqlc = 'SELECT ct
  1763.                              FROM CommercialBundle:CommercialTracking ct
  1764.                              WHERE ct.clientId = :clientId
  1765.                              ORDER BY ct.dateAt DESC';
  1766.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1767.                     $allClientTrackings = $queryc->getResult();
  1768.                     $newTableData = array();
  1769.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1770.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1771.                     foreach ($allClientTrackings as $track) {
  1772.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1773.                         if (!empty($contactClientInfo)){
  1774.                             // allPhones tendrá los telefonos y moviles
  1775.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1776.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1777.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1778.                             $arrayContactClientInfo = array(
  1779.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1780.                                 'email' => $contactClientInfo->getEmail(),
  1781.                                 'allPhones' => $allPhones,
  1782.                             );
  1783.                         } else {
  1784.                             $arrayContactClientInfo = array(
  1785.                                 'fullName' => '',
  1786.                                 'email' => '',
  1787.                                 'allPhones' => '',
  1788.                             );
  1789.                         }
  1790.                         $xlsObservations = $track->getMessage();
  1791.                         if(!empty($xlsObservations)){
  1792.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1793.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1794.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1795.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1796.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1797.                         }
  1798.                         $newTableData[] = array(
  1799.                             'id' => $client->getId(),
  1800.                             'name' => $client->getName(),
  1801.                             'title' => $client->getTitle(),
  1802.                             'address' => $client->getAddress(),
  1803.                             'addressNumber' => $client->getAddressNumber(),
  1804.                             'cityClient' => $cityClient,
  1805.                             'zipCode' => $client->getZipCode(),
  1806.                             'volume' => $track->getVolume(),
  1807.                             'payment' => $track->getPayment(),
  1808.                             'situation' => $track->getSituation(),
  1809.                             'competency' => $client->getCompetency(),
  1810.                             'picture' => $picture,
  1811.                             'contact' => $arrayContactClientInfo['fullName'],
  1812.                             'email' => $arrayContactClientInfo['email'],
  1813.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1814.                             'trackMessage' => $xlsObservations,
  1815.                             'trackStatus' => $track->getStatus(),
  1816.                             'trackDateAt' => $track->getDateAt(),
  1817.                         );
  1818.                     }
  1819.                     // Si no hay comercial tracking se debe dejar vacio
  1820.                     if (empty($newTableData)){
  1821.                         $newTableData[] = array(
  1822.                             'id' => $client->getId(),
  1823.                             'name' => $client->getName(),
  1824.                             'title' => $client->getTitle(),
  1825.                             'address' => $client->getAddress(),
  1826.                             'addressNumber' => $client->getAddressNumber(),
  1827.                             'cityClient' => $cityClient,
  1828.                             'zipCode' => $client->getZipCode(),
  1829.                             'volume' => '',
  1830.                             'payment' => '',
  1831.                             'situation' => '',
  1832.                             'competency' => $client->getCompetency(),
  1833.                             'picture' => $picture,
  1834.                             'contact' => '',
  1835.                             'email' => '',
  1836.                             'allPhones' => '',
  1837.                             'trackMessage' => '',
  1838.                             'trackStatus' => '',
  1839.                             'trackDateAt' => '',
  1840.                         );
  1841.                     }
  1842.                     $clientList[] = $newTableData;
  1843.                 }
  1844.                 break;
  1845.             case 'competency':
  1846.                 $parameters = array();
  1847.                 $dqlc = "SELECT cc
  1848.                 FROM App\Entity\Client cc
  1849.                 WHERE cc.competency LIKE '%".$dato."%' ";
  1850.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1851.                 $competencyClients = $queryc->getResult();
  1852.                 $clientList = array();
  1853.                 foreach($competencyClients as $client){
  1854.                     $picture = $client->getPicture();
  1855.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1856.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1857.                     $parameters = array( 'clientId' => $client->getId() );
  1858.                     $dqlc = 'SELECT ct
  1859.                              FROM CommercialBundle:CommercialTracking ct
  1860.                              WHERE ct.clientId = :clientId
  1861.                              ORDER BY ct.dateAt DESC';
  1862.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1863.                     $allClientTrackings = $queryc->getResult();
  1864.                     $newTableData = array();
  1865.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  1866.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  1867.                     foreach ($allClientTrackings as $track) {
  1868.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  1869.                         if (!empty($contactClientInfo)){
  1870.                             // allPhones tendrá los telefonos y moviles
  1871.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  1872.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  1873.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  1874.                             $arrayContactClientInfo = array(
  1875.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  1876.                                 'email' => $contactClientInfo->getEmail(),
  1877.                                 'allPhones' => $allPhones,
  1878.                             );
  1879.                         } else {
  1880.                             $arrayContactClientInfo = array(
  1881.                                 'fullName' => '',
  1882.                                 'email' => '',
  1883.                                 'allPhones' => '',
  1884.                             );
  1885.                         }
  1886.                         $xlsObservations = $track->getMessage();
  1887.                         if(!empty($xlsObservations)){
  1888.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  1889.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  1890.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  1891.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  1892.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  1893.                         }
  1894.                         $newTableData[] = array(
  1895.                             'id' => $client->getId(),
  1896.                             'name' => $client->getName(),
  1897.                             'title' => $client->getTitle(),
  1898.                             'address' => $client->getAddress(),
  1899.                             'addressNumber' => $client->getAddressNumber(),
  1900.                             'cityClient' => $cityClient,
  1901.                             'zipCode' => $client->getZipCode(),
  1902.                             'volume' => $track->getVolume(),
  1903.                             'payment' => $track->getPayment(),
  1904.                             'situation' => $track->getSituation(),
  1905.                             'competency' => $client->getCompetency(),
  1906.                             'picture' => $picture,
  1907.                             'contact' => $arrayContactClientInfo['fullName'],
  1908.                             'email' => $arrayContactClientInfo['email'],
  1909.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  1910.                             'trackMessage' => $xlsObservations,
  1911.                             'trackStatus' => $track->getStatus(),
  1912.                             'trackDateAt' => $track->getDateAt(),
  1913.                         );
  1914.                     }
  1915.                     // Si no hay comercial tracking se debe dejar vacio
  1916.                     if (empty($newTableData)){
  1917.                         $newTableData[] = array(
  1918.                             'id' => $client->getId(),
  1919.                             'name' => $client->getName(),
  1920.                             'title' => $client->getTitle(),
  1921.                             'address' => $client->getAddress(),
  1922.                             'addressNumber' => $client->getAddressNumber(),
  1923.                             'cityClient' => $cityClient,
  1924.                             'zipCode' => $client->getZipCode(),
  1925.                             'volume' => '',
  1926.                             'payment' => '',
  1927.                             'situation' => '',
  1928.                             'competency' => $client->getCompetency(),
  1929.                             'picture' => $picture,
  1930.                             'contact' => '',
  1931.                             'email' => '',
  1932.                             'allPhones' => '',
  1933.                             'trackMessage' => '',
  1934.                             'trackStatus' => '',
  1935.                             'trackDateAt' => '',
  1936.                         );
  1937.                     }
  1938.                     $clientList[] = $newTableData;
  1939.                 }
  1940. //                $parameters = array( 'zipCode' => $dato );
  1941. //                $dqlc = 'SELECT cc
  1942. //                FROM App\Entity\Client cc
  1943. //                WHERE cc.zipCode = :zipCode ';
  1944. //
  1945. //                $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1946. //                $zipCodeClients = $queryc->getResult();
  1947. //
  1948. //                $clientList = array();
  1949. //
  1950. //                foreach($zipCodeClients as $client){
  1951. //
  1952. //                    $picture = $client->getPicture();
  1953. //                    if(!empty($picture) or $picture !== null){
  1954. //                        $picture = $client->getPicture();
  1955. //                    }else{
  1956. //                        $picture = 'assets/images/placeholder.jpg';
  1957. //                    }
  1958. //                    $contacts = array();
  1959. //                    $contactsInfo = $em->getRepository('App\Entity\ClientContact')->findByClientId($client->getId());
  1960. //
  1961. //                    foreach ($contactsInfo as $contact){
  1962. //                        $contacts[] = array(
  1963. //                            'name' => $contact->getName().' '.$contact->getLastName(),
  1964. //                        );
  1965. //                    }
  1966. //                    $clientList[] = array(
  1967. //                        'id' => $client->getId(),
  1968. //                        'name' => $client->getName(),
  1969. //                        'title' => $client->getTitle(),
  1970. //                        'competency' => $client->getCompetency(),
  1971. //                        'picture' => $picture,
  1972. //                        'contact' => $contacts,
  1973. //                        'filter' => 'Código Postal',
  1974. //                        'data' => $dato,
  1975. //                    );
  1976. //                }
  1977.                 break;
  1978.             case 'zone':
  1979.                 $parameters = array();
  1980.                 $dqlc = "SELECT cc
  1981.                         FROM App\Entity\Cities cc
  1982.                         WHERE cc.city LIKE '%" . $dato . "%'";
  1983.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  1984.                 $arrayCities = $queryc->getResult();
  1985.                 $competencyClients = array();
  1986.                 if(!empty($arrayCities)){
  1987.                     foreach ($arrayCities as $item){
  1988.                         $cli = $em->getRepository(Client::class)->findByPopulation($item->getId());
  1989.                         if (!empty($cli)){ foreach ($cli as $elem) { $competencyClients[] = $elem; } }
  1990.                     }
  1991.                 }
  1992.                 $clientList = array();
  1993.                 foreach($competencyClients as $client){
  1994.                     $picture = $client->getPicture();
  1995.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  1996.                     //Ordenamos desde el tracking as reciente al mas antiguo
  1997.                     $parameters = array( 'clientId' => $client->getId() );
  1998.                     $dqlc = 'SELECT ct
  1999.                              FROM CommercialBundle:CommercialTracking ct
  2000.                              WHERE ct.clientId = :clientId
  2001.                              ORDER BY ct.dateAt DESC';
  2002.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2003.                     $allClientTrackings = $queryc->getResult();
  2004.                     $newTableData = array();
  2005.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  2006.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  2007.                     foreach ($allClientTrackings as $track) {
  2008.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  2009.                         if (!empty($contactClientInfo)){
  2010.                             // allPhones tendrá los telefonos y moviles
  2011.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  2012.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  2013.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  2014.                             $arrayContactClientInfo = array(
  2015.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  2016.                                 'email' => $contactClientInfo->getEmail(),
  2017.                                 'allPhones' => $allPhones,
  2018.                             );
  2019.                         } else {
  2020.                             $arrayContactClientInfo = array(
  2021.                                 'fullName' => '',
  2022.                                 'email' => '',
  2023.                                 'allPhones' => '',
  2024.                             );
  2025.                         }
  2026.                         $xlsObservations = $track->getMessage();
  2027.                         if(!empty($xlsObservations)){
  2028.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  2029.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  2030.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  2031.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  2032.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  2033.                         }
  2034.                         $newTableData[] = array(
  2035.                             'id' => $client->getId(),
  2036.                             'name' => $client->getName(),
  2037.                             'title' => $client->getTitle(),
  2038.                             'address' => $client->getAddress(),
  2039.                             'addressNumber' => $client->getAddressNumber(),
  2040.                             'cityClient' => $cityClient,
  2041.                             'zipCode' => $client->getZipCode(),
  2042.                             'volume' => $track->getVolume(),
  2043.                             'payment' => $track->getPayment(),
  2044.                             'situation' => $track->getSituation(),
  2045.                             'competency' => $client->getCompetency(),
  2046.                             'picture' => $picture,
  2047.                             'contact' => $arrayContactClientInfo['fullName'],
  2048.                             'email' => $arrayContactClientInfo['email'],
  2049.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  2050.                             'trackMessage' => $xlsObservations,
  2051.                             'trackStatus' => $track->getStatus(),
  2052.                             'trackDateAt' => $track->getDateAt(),
  2053.                         );
  2054.                     }
  2055.                     // Si no hay comercial tracking se debe dejar vacio
  2056.                     if (empty($newTableData)){
  2057.                         $newTableData[] = array(
  2058.                             'id' => $client->getId(),
  2059.                             'name' => $client->getName(),
  2060.                             'title' => $client->getTitle(),
  2061.                             'address' => $client->getAddress(),
  2062.                             'addressNumber' => $client->getAddressNumber(),
  2063.                             'cityClient' => $cityClient,
  2064.                             'zipCode' => $client->getZipCode(),
  2065.                             'volume' => '',
  2066.                             'payment' => '',
  2067.                             'situation' => '',
  2068.                             'competency' => $client->getCompetency(),
  2069.                             'picture' => $picture,
  2070.                             'contact' => '',
  2071.                             'email' => '',
  2072.                             'allPhones' => '',
  2073.                             'trackMessage' => '',
  2074.                             'trackStatus' => '',
  2075.                             'trackDateAt' => '',
  2076.                         );
  2077.                     }
  2078.                     $clientList[] = $newTableData;
  2079.                 }
  2080.                 break;
  2081.             case 'datetracking':
  2082.                 $dato = new \DateTime($_POST['fechaseguimiento']);
  2083.                 $startDate = $dato->setTime(0, 0, 0);
  2084.                 $endDate = clone $startDate;
  2085.                 $endDate = $endDate->modify('+1 day');
  2086.                 $parameters = array( 'startDate' => $startDate, 'endDate' => $endDate );
  2087.                 $dqlc = 'SELECT ct
  2088.                          FROM CommercialBundle:CommercialTracking ct
  2089.                          WHERE ct.createdAt >= :startDate AND ct.createdAt < :endDate';
  2090.                 $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2091.                 $arrayComTrack = $queryc->getResult();
  2092.                 $arrayClients = array();
  2093.                 $competencyClients = array();
  2094.                 foreach ($arrayComTrack as $item){ $arrayClients[$item->getClientId()] = $item->getClientId(); }
  2095.                 foreach ($arrayClients as $item){
  2096.                     $cli = $em->getRepository(Client::class)->findOneById($item);
  2097.                     if (!empty($cli)) { $competencyClients[] = $cli; }
  2098.                 }
  2099.                 $clientList = array();
  2100.                 foreach($competencyClients as $client){
  2101.                     $picture = $client->getPicture();
  2102.                     if(!empty($picture) or $picture !== null){ $picture = $client->getPicture(); } else { $picture = 'assets/images/placeholder.jpg'; }
  2103.                     //Ordenamos desde el tracking as reciente al mas antiguo
  2104.                     $parameters = array( 'clientId' => $client->getId() );
  2105.                     $dqlc = 'SELECT ct
  2106.                              FROM CommercialBundle:CommercialTracking ct
  2107.                              WHERE ct.clientId = :clientId
  2108.                              ORDER BY ct.dateAt DESC';
  2109.                     $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2110.                     $allClientTrackings = $queryc->getResult();
  2111.                     $newTableData = array();
  2112.                     $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  2113.                     if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  2114.                     foreach ($allClientTrackings as $track) {
  2115.                         $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  2116.                         if (!empty($contactClientInfo)){
  2117.                             // allPhones tendrá los telefonos y moviles
  2118.                             $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  2119.                             $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  2120.                             $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  2121.                             $arrayContactClientInfo = array(
  2122.                                 'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  2123.                                 'email' => $contactClientInfo->getEmail(),
  2124.                                 'allPhones' => $allPhones,
  2125.                             );
  2126.                         } else {
  2127.                             $arrayContactClientInfo = array(
  2128.                                 'fullName' => '',
  2129.                                 'email' => '',
  2130.                                 'allPhones' => '',
  2131.                             );
  2132.                         }
  2133.                         $xlsObservations = $track->getMessage();
  2134.                         if(!empty($xlsObservations)){
  2135.                             $xlsObservations = str_replace('</p><p>',PHP_EOL,$xlsObservations);
  2136.                             $xlsObservations = str_replace('<p>','',$xlsObservations);
  2137.                             $xlsObservations = str_replace('</p>','',$xlsObservations);
  2138.                             $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  2139.                             $xlsObservations = str_replace('<br>',PHP_EOL,$xlsObservations);
  2140.                         }
  2141.                         $newTableData[] = array(
  2142.                             'id' => $client->getId(),
  2143.                             'name' => $client->getName(),
  2144.                             'title' => $client->getTitle(),
  2145.                             'address' => $client->getAddress(),
  2146.                             'addressNumber' => $client->getAddressNumber(),
  2147.                             'cityClient' => $cityClient,
  2148.                             'zipCode' => $client->getZipCode(),
  2149.                             'volume' => $track->getVolume(),
  2150.                             'payment' => $track->getPayment(),
  2151.                             'situation' => $track->getSituation(),
  2152.                             'competency' => $client->getCompetency(),
  2153.                             'picture' => $picture,
  2154.                             'contact' => $arrayContactClientInfo['fullName'],
  2155.                             'email' => $arrayContactClientInfo['email'],
  2156.                             'allPhones' => $arrayContactClientInfo['allPhones'],
  2157.                             'trackMessage' => $xlsObservations,
  2158.                             'trackStatus' => $track->getStatus(),
  2159.                             'trackDateAt' => $track->getDateAt(),
  2160.                         );
  2161.                     }
  2162.                     // Si no hay comercial tracking se debe dejar vacio
  2163.                     if (empty($newTableData)){
  2164.                         $newTableData[] = array(
  2165.                             'id' => $client->getId(),
  2166.                             'name' => $client->getName(),
  2167.                             'title' => $client->getTitle(),
  2168.                             'address' => $client->getAddress(),
  2169.                             'addressNumber' => $client->getAddressNumber(),
  2170.                             'cityClient' => $cityClient,
  2171.                             'zipCode' => $client->getZipCode(),
  2172.                             'volume' => '',
  2173.                             'payment' => '',
  2174.                             'situation' => '',
  2175.                             'competency' => $client->getCompetency(),
  2176.                             'picture' => $picture,
  2177.                             'contact' => '',
  2178.                             'email' => '',
  2179.                             'allPhones' => '',
  2180.                             'trackMessage' => '',
  2181.                             'trackStatus' => '',
  2182.                             'trackDateAt' => '',
  2183.                         );
  2184.                     }
  2185.                     $clientList[] = $newTableData;
  2186.                 }
  2187.                 break;
  2188.             default: break;
  2189.         };
  2190.         $clientCount = count($clientList);
  2191.         $dql = 'SELECT cl
  2192.                 FROM App\MDS\CommercialBundle\Entity\CommercialTracking cl
  2193.                 GROUP BY cl.createdId';
  2194.         $query = $em->createQuery($dql);
  2195.         $comtrack = $query->getResult();
  2196.         $agents = array();
  2197.         foreach ($comtrack as $item) {
  2198.             $userCreator = $em->getRepository(User::class)->findOneById($item->getCreatedId());
  2199.             if (!empty($userCreator)){ $agents[$userCreator->getName() . ' '. $userCreator->getLastName()] = $userCreator; }
  2200.         }
  2201.         ksort($agents);
  2202.         return $this->render('client/clients-find.html.twig',
  2203.             array(
  2204.                 'clients' => $clientList,
  2205.                 'clientsCount' => $clientCount,
  2206.                 'background' => $background,
  2207.                 'searchCriteria' => $standar,
  2208.                 'dato' => $dato,
  2209.                 'agents' => $agents,
  2210.             )
  2211.         );
  2212.     }
  2213.     /**
  2214.      * @Route("/xlsclientsearchcompetencies/", name="client_search_competencies_xls_empty")
  2215.      * Una busqueda con dato empty da 404, se crea esta ruta para solucionarlo
  2216.      */
  2217.     public function XlsEmptyClientSearchCompetenciesAction(Request $request){
  2218.         return $this->redirectToRoute('client_search_competencies_xls', array( 'dato' => 'zzz666zzz' ));
  2219.     }
  2220.     /**
  2221.      * @Route("/xlsclientsearchcompetencies/{dato}", name="client_search_competencies_xls")
  2222.      */
  2223.     public function XlsClientSearchCompetenciesAction($dato, Request $request){
  2224.         $em = $this->getDoctrine()->getManager();
  2225.         $parameters = array();
  2226.         $dqlc = "SELECT cc
  2227.                 FROM App\Entity\Client cc
  2228.                 WHERE cc.competency LIKE '%".$dato."%' ";
  2229.         if ($dato == 'zzz666zzz'){ $dqlc = 'SELECT cc FROM App\Entity\Client cc'; }
  2230.         $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2231.         $competencyClients = $queryc->getResult();
  2232.         $clientList = array();
  2233.         foreach($competencyClients as $client){
  2234.             $picture = $client->getPicture();
  2235.             if(!empty($picture) or $picture !== null){
  2236.                 $picture = $client->getPicture();
  2237.             }else{
  2238.                 $picture = 'assets/images/placeholder.jpg';
  2239.             }
  2240.             //Ordenamos desde el tracking as reciente al mas antiguo
  2241.             $parameters = array( 'clientId' => $client->getId() );
  2242.             $dqlc = 'SELECT ct
  2243.                      FROM CommercialBundle:CommercialTracking ct
  2244.                      WHERE ct.clientId = :clientId
  2245.                      ORDER BY ct.dateAt DESC';
  2246.             $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2247.             $allClientTrackings = $queryc->getResult();
  2248.             // Por indicaciones de Victor Muñoz solo mostraremos el comercial tracking mas reciente cuando la busqueda es sobre todos los clientes asi se evita error por desbordamiento de memoria
  2249.             if ($dato == 'zzz666zzz') { if (!empty($allClientTrackings)) { $allClientTrackings = array('0' => reset($allClientTrackings)); } }
  2250.             $newTableData = array();
  2251.             $cityClient = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  2252.             if (!empty($cityClient)){ $cityClient = $cityClient->getCity(); }
  2253.             foreach ($allClientTrackings as $track) {
  2254.                 $contactClientInfo = $em->getRepository('App\Entity\ClientContact')->findOneById($track->getContactId());
  2255.                 if (!empty($contactClientInfo)){
  2256.                     // allPhones tendrá los telefonos y moviles
  2257.                     $allPhones = !empty($contactClientInfo->getPhone()) ? $contactClientInfo->getPhone() : null;
  2258.                     $allMob = !empty($contactClientInfo->getMobile()) ? $contactClientInfo->getMobile() : null;
  2259.                     $allPhones = (!empty($allPhones) and !empty($allMob)) ? $allPhones.' - '.$allMob : (!empty($allPhones) ? $allPhones : $allMob);
  2260.                     $arrayContactClientInfo = array(
  2261.                         'fullName' => $contactClientInfo->getName().' '.$contactClientInfo->getLastName(),
  2262.                         'email' => $contactClientInfo->getEmail(),
  2263.                         'allPhones' => $allPhones,
  2264.                     );
  2265.                 } else {
  2266.                     $arrayContactClientInfo = array(
  2267.                         'fullName' => '',
  2268.                         'email' => '',
  2269.                         'allPhones' => '',
  2270.                     );
  2271.                 }
  2272.                 $xlsObservations = $track->getMessage();
  2273.                 if(!empty($xlsObservations)){
  2274.                     $xlsObservations = str_replace('</p><p>',PHP_EOL.' ',$xlsObservations);
  2275.                     $xlsObservations = str_replace('<p>','',$xlsObservations);
  2276.                     $xlsObservations = str_replace('</p>',' ',$xlsObservations);
  2277.                     $xlsObservations = str_replace('&nbsp;',' ',$xlsObservations);
  2278.                     $xlsObservations = str_replace('<br>',PHP_EOL.' ',$xlsObservations);
  2279.                 }
  2280.                 $newTableData[] = array(
  2281.                     'id' => $client->getId(),
  2282.                     'name' => $client->getName(),
  2283.                     'title' => $client->getTitle(),
  2284.                     'address' => $client->getAddress(),
  2285.                     'addressNumber' => $client->getAddressNumber(),
  2286.                     'cityClient' => $cityClient,
  2287.                     'zipCode' => $client->getZipCode(),
  2288.                     'volume' => $track->getVolume(),
  2289.                     'payment' => $track->getPayment(),
  2290.                     'situation' => $track->getSituation(),
  2291.                     'competency' => $client->getCompetency(),
  2292.                     'picture' => $picture,
  2293.                     'contact' => $arrayContactClientInfo['fullName'],
  2294.                     'email' => $arrayContactClientInfo['email'],
  2295.                     'allPhones' => $arrayContactClientInfo['allPhones'],
  2296.                     'trackMessage' => $xlsObservations,
  2297.                     'trackStatus' => $track->getStatus(),
  2298.                     'trackDateAt' => $track->getDateAt(),
  2299.                 );
  2300.             }
  2301.             // Si no hay comercial tracking se debe dejar vacio
  2302.             if (empty($newTableData)){
  2303.                 $newTableData[] = array(
  2304.                     'id' => $client->getId(),
  2305.                     'name' => $client->getName(),
  2306.                     'title' => $client->getTitle(),
  2307.                     'address' => $client->getAddress(),
  2308.                     'addressNumber' => $client->getAddressNumber(),
  2309.                     'cityClient' => $cityClient,
  2310.                     'zipCode' => $client->getZipCode(),
  2311.                     'volume' => '',
  2312.                     'payment' => '',
  2313.                     'situation' => '',
  2314.                     'competency' => $client->getCompetency(),
  2315.                     'picture' => $picture,
  2316.                     'contact' => '',
  2317.                     'email' => '',
  2318.                     'allPhones' => '',
  2319.                     'trackMessage' => '',
  2320.                     'trackStatus' => '',
  2321.                     'trackDateAt' => '',
  2322.                 );
  2323.             }
  2324.             $clientList[] = $newTableData;
  2325.         }
  2326.         if ($dato == 'zzz666zzz'){ $dato = ''; }
  2327.         // Solicita el servicio de excel
  2328.         $phpExcelObject = new Spreadsheet();
  2329.         $phpExcelObject->getProperties()->setCreator("InOut Travel")
  2330.             ->setLastModifiedBy("InOut Travel")
  2331.             ->setTitle("InOut Travel")
  2332.             ->setSubject("InOut Travel")
  2333.             ->setDescription("InOut Travel, generado usando clases de PHP")
  2334.             ->setKeywords("office 2005 openxml php")
  2335.             ->setCategory("Competencias");
  2336.         $fill = new Fill();
  2337.         $numberFormat = new NumberFormat();
  2338.         $alignment = new Alignment();
  2339.         $estilo = array(
  2340.             'alignment' => array(
  2341.                 'horizontal' => $alignment::HORIZONTAL_RIGHT,
  2342.             )
  2343.         );
  2344.         $i = 8;
  2345.         $indiceInicial = 9;
  2346.         $indiceFinal = 9;
  2347.         $activesheet = $phpExcelObject->getActiveSheet();
  2348.         $drawingobject = new Drawing();
  2349.         $drawingobject->setName('Image name');
  2350.         $drawingobject->setDescription('Image description');
  2351.         $drawingobject->setPath(getcwd().'/assets/images/logo/logo2022.png');
  2352.         $drawingobject->setHeight(60);
  2353.         $drawingobject->setOffsetY(20);
  2354.         $drawingobject->setCoordinates('B1');
  2355.         $drawingobject->setWorksheet($activesheet);
  2356.         $phpExcelObject
  2357.             ->getActiveSheet()
  2358.             ->getStyle('B6:AH6')
  2359.             ->getFill()
  2360.             ->setFillType($fill::FILL_SOLID)
  2361.             ->getStartColor()
  2362.             ->setRGB('FFA420');
  2363.         $phpExcelObject->setActiveSheetIndex(0)
  2364.             ->setCellValue('C6','Competencias con "'.$dato.'"')
  2365.         ;
  2366.         $phpExcelObject
  2367.             ->getActiveSheet()
  2368.             ->getStyle('B'.$i.':AH'.$i)
  2369.             ->getFill()
  2370.             ->setFillType($fill::FILL_SOLID)
  2371.             ->getStartColor()
  2372.             ->setRGB('9c9c9c');
  2373.         $phpExcelObject->setActiveSheetIndex(0)
  2374.             ->setCellValue('B'.$i, 'Fecha')//
  2375.             ->setCellValue('D'.$i, 'Empresa')
  2376.             ->setCellValue('F'.$i, 'Contacto')
  2377.             ->setCellValue('H'.$i, 'Correo Electrónico')//
  2378.             ->setCellValue('K'.$i, 'Teléfono')
  2379.             ->setCellValue('M'.$i, 'Dirección')
  2380.             ->setCellValue('P'.$i, 'Número')
  2381.             ->setCellValue('Q'.$i, 'Zona')
  2382.             ->setCellValue('S'.$i, 'Código Postal')
  2383.             ->setCellValue('T'.$i, 'Agencia')//
  2384.             ->setCellValue('V'.$i, 'Volumen')
  2385.             ->setCellValue('W'.$i, 'Pago')
  2386.             ->setCellValue('Y'.$i, 'Situación')
  2387. //            ->setCellValue('X'.$i, 'Prioridad')
  2388.             ->setCellValue('AA'.$i, 'Observaciones')
  2389.         ;
  2390.     foreach ($clientList as $elem) {
  2391.         foreach ($elem as $item) {
  2392.             $xlsDate = empty($item['trackDateAt']) ? '' : $item['trackDateAt']->format('d/m/Y');
  2393.             $phpExcelObject->setActiveSheetIndex(0)
  2394.                 ->setCellValue('B' . ($i + 1), $xlsDate)
  2395.                 ->setCellValue('D' . ($i + 1), $item['name'])
  2396.                 ->setCellValue('F' . ($i + 1), $item['contact'])
  2397.                 ->setCellValue('H' . ($i + 1), $item['email'])
  2398.                 ->setCellValue('K' . ($i + 1), $item['allPhones'])
  2399.                 ->setCellValue('M' . ($i + 1), $item['address'])
  2400.                 ->setCellValue('P' . ($i + 1), $item['addressNumber'])
  2401.                 ->setCellValue('Q' . ($i + 1), $item['cityClient'])
  2402.                 ->setCellValue('S' . ($i + 1), $item['zipCode'])
  2403.                 ->setCellValue('T' . ($i + 1), $item['competency'])
  2404.                 ->setCellValue('V' . ($i + 1), $item['volume'])
  2405.                 ->setCellValue('W' . ($i + 1), $item['payment'])
  2406.                 ->setCellValue('Y' . ($i + 1), $item['situation'])
  2407. //                ->setCellValue('W'.($i+1), $item['priority'])
  2408.                 ->setCellValue('AA' . ($i + 1), $item['trackMessage']);
  2409.             $i++;
  2410.             $indiceFinal++;
  2411.         }
  2412.     }
  2413.         $indiceFinal--;
  2414.         $indicesResta = $indiceFinal - $indiceInicial + 1;
  2415.         $phpExcelObject->getActiveSheet()->setTitle('Competencias');
  2416.         // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  2417.         $phpExcelObject->setActiveSheetIndex(0);
  2418.         // Crea el writer
  2419.         $writer = new Xlsx($phpExcelObject);
  2420.         // Envia la respuesta del controlador
  2421.         $response = new StreamedResponse(
  2422.             function () use ($writer) {
  2423.                 $writer->save('php://output');
  2424.             }
  2425.         );
  2426.         // Agrega los headers requeridos
  2427.         $dispositionHeader = $response->headers->makeDisposition(
  2428.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  2429.             'InOut_Competencias'.'.xlsx'
  2430.         );
  2431.         $response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
  2432.         $response->headers->set('Pragma', 'public');
  2433.         $response->headers->set('Cache-Control', 'maxage=1');
  2434.         $response->headers->set('Content-Disposition', $dispositionHeader);
  2435.         return $response;
  2436.     }
  2437.     /**
  2438.      * @Route("/clientprofile/{id}", name="client_profile_id")
  2439.      */
  2440.     public function ClientProfileAction(Request $request, $id)
  2441.     {
  2442.         $em = $this->getDoctrine()->getManager();
  2443.         $clientInfo = $em->getRepository(Client::class)->findOneById($id);
  2444.         $clientContact = $em->getRepository('App\Entity\ClientContact')->findByClientId($id);
  2445.         $placeholder = 'assets/images/placeholder.jpg';
  2446.         d($clientInfo);
  2447.         return $this->render('client/clients-profile.html.twig',
  2448.             array(
  2449.                 'client' => $clientInfo,
  2450.                 'contacts' => $clientContact,
  2451.                 'placeholder' => $placeholder,
  2452.             )
  2453.         );
  2454.     }
  2455.     /* Lista Mis Client*/
  2456.     /**
  2457.      * @Route("/client/myclients", name="client_list_MyClients")
  2458.      */
  2459.     public function MyClienteListAction(Request $request)
  2460.     {
  2461.         $em = $this->getDoctrine()->getManager();
  2462.         /* Obtengo usuario logueado */
  2463.         $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  2464.         $user_id = $user_logueado->getId();
  2465.         $parametersA = array(
  2466.             'assignedAgent' => $user_id
  2467.         );
  2468.         /* ALL LO QUE HAY  */
  2469.         $dql = 'SELECT cl, c.country, p.region, r.city, cc.id, pr.name as province
  2470.                 FROM App\Entity\Client cl
  2471.                 INNER JOIN App:Country c WITH c.id = cl.country
  2472.                 INNER JOIN App:Regions p WITH p.id = cl.region
  2473.                 INNER JOIN App:Provinces pr WITH pr.id = cl.province
  2474.                 INNER JOIN App:Cities r WITH r.id = cl.population
  2475.                 INNER JOIN App\Entity\ClientContact cc WITH  cc.clientId = cl.id
  2476.                 WHERE cc.assignedAgent = :assignedAgent ';
  2477. //                ORDER BY p.dateProposedAt DESC';
  2478.         $query = $em->createQuery($dql)->setParameters($parametersA);;
  2479.         $clients = $query->getResult();
  2480.         // Ve todos los clientes, si es un administrador o un usuario especial
  2481.         if (($user_logueado->getRole() == "ROLE_ADMIN") or ($user_id == 133)){
  2482.             $parametersA = array();
  2483.             $dql = 'SELECT cl, c.country, p.region, r.city, cc.id, pr.name as province
  2484.                 FROM App\Entity\Client cl
  2485.                 INNER JOIN App:Country c WITH c.id = cl.country
  2486.                 INNER JOIN App:Regions p WITH p.id = cl.region
  2487.                 INNER JOIN App:Provinces pr WITH pr.id = cl.province
  2488.                 INNER JOIN App:Cities r WITH r.id = cl.population
  2489.                 INNER JOIN App\Entity\ClientContact cc WITH  cc.clientId = cl.id
  2490.                 WHERE cc.assignedAgent IS NOT NULL ';
  2491.             $query = $em->createQuery($dql)->setParameters($parametersA);;
  2492.             $clients = $query->getResult();
  2493.         }
  2494.         $data_clients = array();
  2495.         foreach($clients as $client){
  2496.             $group = $em->getRepository(Group::class)->findOneById($client[0]->getGroupId());
  2497.             $parameters = array(
  2498.                 'clientId' => $client[0]->getId()
  2499.             );
  2500.             $dqlc = 'SELECT cc,  u.name, u.lastname
  2501.                 FROM App\Entity\ClientContact cc
  2502.                 INNER JOIN App\Entity\User u WITH u.id = cc.assignedAgent
  2503.                 WHERE cc.clientId = :clientId ';
  2504.             $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2505.             $contacts = $queryc->getResult();
  2506.             $data_clients[] = array(
  2507.                 'client' => $client,
  2508.                 'group' => $group,
  2509.                 'contacts' => $contacts,
  2510.             );
  2511.         }
  2512.         return $this->render('client/clients-general-list.html.twig', array( 'datosclientes' => $data_clients, )
  2513.         );
  2514.     }
  2515.     /* Lista Yes Client*/
  2516.     /**
  2517.      * @Route("/client/yesclient", name="client_list_YesClient")
  2518.      */
  2519.     public function YesClienteListAction(Request $request)
  2520.     {
  2521. //        $data = $this->primtListClientAction($request);
  2522.         $em = $this->getDoctrine()->getManager();
  2523.         $parametersA = array(
  2524.             'action' => 'Client'
  2525.         );
  2526.         /* ALL LO QUE HAY  */
  2527.         $dql = 'SELECT cl,  c.country, p.region, r.city, pr.name as province
  2528.                 FROM App\Entity\Client cl
  2529.                 INNER JOIN App:Country c WITH c.id = cl.country
  2530.                 INNER JOIN App:Regions p WITH p.id = cl.region
  2531.                 INNER JOIN App:Provinces pr WITH pr.id = cl.province
  2532.                 INNER JOIN App:Cities r WITH r.id = cl.population
  2533.                 WHERE cl.action = :action ';
  2534. //                ORDER BY p.dateProposedAt DESC';
  2535.         $query = $em->createQuery($dql)->setParameters($parametersA);;
  2536.         $clients = $query->getResult();
  2537.         $data_clients= array();
  2538.         foreach($clients as $client){
  2539.             $group = $em->getRepository(Group::class)->findOneById($client[0]->getGroupId());
  2540.             $parameters = array(
  2541.                 'clientId' => $client[0]->getId()
  2542.             );
  2543.             $dqlc = 'SELECT cc,  u.name, u.lastname
  2544.                 FROM App\Entity\ClientContact cc
  2545.                 INNER JOIN App\Entity\User u WITH u.id = cc.assignedAgent
  2546.                 WHERE cc.clientId = :clientId ';
  2547.             $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2548.             $contacts = $queryc->getResult();
  2549.             $data_clients[] = array(
  2550.                 'client' => $client,
  2551.                 'group' => $group,
  2552.                 'contacts' => $contacts,
  2553.             );
  2554.         }
  2555.         return $this->render('client/clients-general-list.html.twig',
  2556.             array(
  2557.                 'datosclientes' => $data_clients,
  2558.             )
  2559.         );
  2560.     }
  2561.     /* Lista Not Client*/
  2562.     /**
  2563.      * @Route("/client/notclient", name="client_list_NoClient")
  2564.      */
  2565.     public function NotClienteListAction(Request $request)
  2566.     {
  2567. //        $data = $this->primtListClientAction($request);
  2568.         $em = $this->getDoctrine()->getManager();
  2569.         $parametersA = array(
  2570.             'action' => 'Not Client'
  2571.         );
  2572.         /* ALL LO QUE HAY  */
  2573.         $dql = 'SELECT cl,  c.country, re.region, p.name, r.city
  2574.                 FROM App\Entity\Client cl
  2575.                 INNER JOIN App:Country c WITH c.id = cl.country
  2576.                 INNER JOIN App:Regions re WITH re.id = cl.region
  2577.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  2578.                 INNER JOIN App:Cities r WITH r.id = cl.population
  2579.                 WHERE cl.action = :action ';
  2580. //                ORDER BY p.dateProposedAt DESC';
  2581.         $query = $em->createQuery($dql)->setParameters($parametersA);;
  2582.         $clients = $query->getResult();
  2583.         $data_clients= array();     //Gustavo Ayala: agregué esta línea para incializar el array ya que si no hay clientes, no entraba en el for each y daba error return $this->render('client/clients-general-list.html.twig', array('datosclientes' => $data_clients,) por variable no definida
  2584.         foreach($clients as $client){
  2585.             $group = $em->getRepository(Group::class)->findOneById($client[0]->getGroupId());
  2586.             $parameters = array(
  2587.                 'clientId' => $client[0]->getId()
  2588.             );
  2589.             $dqlc = 'SELECT cc,  u.name, u.lastname
  2590.                 FROM App\Entity\ClientContact cc
  2591.                 INNER JOIN App\Entity\User u WITH u.id = cc.assignedAgent
  2592.                 WHERE cc.clientId = :clientId ';
  2593.             $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2594.             $contacts = $queryc->getResult();
  2595.             $data_clients[] = array(
  2596.                 'client' => $client,
  2597.                 'group' => $group,
  2598.                 'contacts' => $contacts,
  2599.             );
  2600.         }
  2601.         return $this->render('client/clients-general-list.html.twig',
  2602.             array(
  2603.                 'datosclientes' => $data_clients,
  2604.             )
  2605.         );
  2606.     }
  2607.     /**
  2608.      * @Route("/client/map", name="client_map")
  2609.      */
  2610.     public function ClienteMapAction(Request $request)
  2611.     {
  2612. //        $data = $this->primtListClientAction($request);
  2613.         $em = $this->getDoctrine()->getManager();
  2614.         $clients = $em->getRepository(Client::class)->findAll();
  2615.         foreach($clients as $client){
  2616.             $contact = $em->getRepository('App\Entity\ClientContact')->findByClientId($client->getId());
  2617.             $group = $em->getRepository(Group::class)->findOneById($client->getGroupId());
  2618.             $data[] = array(
  2619.                 'client' => $client,
  2620.                 'group' => $group,
  2621.                 'contact' => $contact,
  2622.             );
  2623.         }
  2624.         return $this->render('client/clients-general-hierarchy.html.twig',
  2625.             array(
  2626.                 'datosclientes' => $data,
  2627.             )
  2628.         );
  2629.     }
  2630.     public function primtListClientAction(Request $request)
  2631.     {
  2632.         $em = $this->getDoctrine()->getManager();
  2633.         $clients = $em->getRepository(Client::class)->findAll();
  2634.         $data_clients = array();
  2635.         $datos_agent = array();
  2636.         foreach($clients as $client){
  2637.             $idclient = $client->getId();
  2638.             $idcountry = $client->getCountry();
  2639.             $contacts = $em->getRepository('App\Entity\ClientContact')->findByClientId($idclient);
  2640.             /*
  2641.              * Si tiene contactos el cliente:
  2642.              *
  2643.              * */
  2644.             if (!empty($contacts)){
  2645.                 foreach($contacts as $contact){
  2646.                     $agentid = $contact->getAssignedAgent();
  2647.                     $datos_contacto[$idclient][] = array(
  2648.                         'cid'             => $contact->getId(),
  2649.                         'cposition'       => $contact->getPosition(),
  2650.                         'cdepartment'     => $contact->getDepartment(),
  2651.                         'cname'           => $contact->getName(),
  2652.                         'clastname'       => $contact->getLastName(),
  2653.                         'cemail'          => $contact->getEmail(),
  2654.                         'cphone'          => $contact->getPhone(),
  2655.                         'cmobile'         => $contact->getMobile(),
  2656.                         'cbirthday'       => $contact->getBirthday(),
  2657.                         'cagentlastname'  => $contact->getAssignedAgent(),
  2658.                     );
  2659.                 }
  2660.                 $user = $em->getRepository(User::class)->findOneById($agentid);
  2661.                 $datos_agent = array(
  2662.                     'aid'        => $user->getId(),
  2663.                     'aname'      => $user->getName(),
  2664.                     'alastname'  => $user->getLastname(),
  2665.                 );
  2666.             } else {
  2667.                 $datos_contacto[$idclient][] = array(
  2668.                     'cid'             => '0',
  2669.                     'cposition'       => $this->translator->trans('Empty'),
  2670.                     'cdepartment'     => '',
  2671.                     'cname'           => $this->translator->trans('Client Non-contact'),
  2672.                     'clastname'       => '',
  2673.                     'cemail'          => '',
  2674.                     'cphone'          => '',
  2675.                     'cmobile'         => '',
  2676.                     'cbirthday'       => '',
  2677.                     'cagentlastname'  => '',
  2678.                 );
  2679.             }
  2680.             if ($client->getGroupId() != 0){
  2681.                 $grupo = $em->getRepository(Group::class)->findOneById($client->getGroupId());
  2682.                 $datos_grupo = array(
  2683.                     'gid'    => $grupo->getId(),
  2684.                     'gtitle' => $grupo->getTitle(),
  2685.                     'gdesc'  => $grupo->getDescription(),
  2686.                 );
  2687.             }else{
  2688.                 $datos_grupo = array(
  2689.                     'gid'    => '',
  2690.                     'gtitle' => '',
  2691.                     'gdesc'  => '',
  2692.                 );
  2693.             }
  2694.             $country= $em->getRepository(Country::class)->findOneById($idcountry);
  2695.             $datos_country= array(
  2696.                 'pid'        => $country->getId(),
  2697.                 'iso'        => $country->getCode(),
  2698.                 'pname'      => $country->getCountry(),
  2699.             );
  2700.             $region= $em->getRepository(Regions::class)->findOneById($client->getProvince());
  2701.             $datos_region= $region->getRegion();
  2702.             $city= $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  2703.             $datos_city= $city->getCity();
  2704.             $data_clients[] = array(
  2705.                 'id'           => $client->getId(),
  2706.                 'picture'      => $client->getPicture(),
  2707.                 'name'         => $client->getName(),
  2708.                 'title'        => $client->getTitle(),
  2709.                 'address'      => $client->getAddress(),
  2710.                 'addressNumber'      => $client->getAddressNumber(),
  2711.                 'googlemap'    => str_replace(" ", "+", $client->getAddress()),
  2712.                 'zipcode'      => $client->getZipCode(),
  2713.                 'population'   => $datos_city,
  2714.                 'province'     => $datos_region,
  2715.                 'telephone'    => $client->getTelephone(),
  2716.                 'fax'          => $client->getFax(),
  2717.                 'email'        => $client->getEmail(),
  2718.                 'codegds'      => $client->getGds(),
  2719.                 'iddocument'   => $client->getIdDocument(),
  2720.                 'observation'  => $client->getObservation(),
  2721.                 'competency'   => $client->getCompetency(),
  2722.                 'contactos'  => $datos_contacto[$idclient],
  2723.                 'grupo'  => $datos_grupo,
  2724.                 'agent'  => $datos_agent,
  2725.                 'country'  => $datos_country,
  2726.             );
  2727.         }
  2728.         return $data_clients;
  2729.         //d($data_clients);
  2730. //        return $this->render('client/list-clientgroup-list.html.twig',
  2731. //            array(
  2732. //                'datosclientes' => $data_clients,
  2733. //            )
  2734. //        );
  2735.     }
  2736.     /**
  2737.      * @Route("/client/searchForNameOrTitle/",  name="client_searchForNameOrTitle")
  2738.      * @param Request $request
  2739.      * @return JsonResponse
  2740.      */
  2741.     public function searchForNameOrTitleAction(Request $request) {
  2742.         $term = $request->query->get('q');
  2743.         $em = $this->getDoctrine()->getManager();
  2744.         $clients = [
  2745.             "items" => array()
  2746.         ]
  2747.         ;
  2748.         $helper = new ClientHelper($em);
  2749.         $clientsCollection = $helper->searchForNameOrTitle($term);
  2750.         /**
  2751.          * @var Client  $client
  2752.          */
  2753.         foreach($clientsCollection as $client) {
  2754. //            $baseURL = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . "/";
  2755. //            $picture = (is_null($client->getPicture()))
  2756. //                        ? ""
  2757. //                        : $baseURL . $client->getPicture()
  2758. //            ;
  2759.             $items = [
  2760.                     "id" => $client->getId(),
  2761.                     "full_name" => $client->getName(),
  2762.                     "description" => $client->getTitle(),
  2763. //                    "img" => $picture,
  2764.             ]
  2765.             ;
  2766.             $clients["items"][] = $items;
  2767.         }
  2768.         $response = new JsonResponse($clients, 200 );
  2769.         return $response;
  2770.     }
  2771.     /**
  2772.      * @Route("/clientlistsimple/{ind}", defaults={"ind" = 0}, name="client_list_simple")
  2773.      */
  2774.     public function ClientListSimpleAction($ind, Request $request)
  2775.     {
  2776.         $em = $this->getDoctrine()->getManager();
  2777.         /* ALL LO QUE HAY  */
  2778.         $dql = 'SELECT cl,  c.country, p.name, re.region, r.city
  2779.                 FROM App\Entity\Client cl
  2780.                 INNER JOIN App:Country c WITH c.id = cl.country
  2781.                 INNER JOIN App:Regions re WITH re.id = cl.region
  2782.                 INNER JOIN App:Provinces p WITH p.id = cl.province
  2783.                 INNER JOIN App:Cities r WITH r.id = cl.population
  2784.                 ORDER BY cl.name ASC ';
  2785.         $query = $em->createQuery($dql);
  2786.         $clientsBigArray = $query->getResult();
  2787.         $ind = $ind * 250;
  2788.         $clients = array_slice($clientsBigArray, $ind, 250);
  2789.         // Generando el arreglo de la botonera para los saltos de pagina
  2790.         $indStart = 0;
  2791.         $indEndArray = sizeof($clientsBigArray) - 1;
  2792.         $arrayBoton = array();
  2793.         for($indStart = 0; $indStart <= $indEndArray; $indStart = $indStart + 250){
  2794.             if($indStart + 250 > $indEndArray){
  2795.                 //Ya tienes el ultimo elemento
  2796.                 $indEnd = $indEndArray;
  2797.             } else {
  2798.                 $indEnd = $indStart + 249;
  2799.             }
  2800.             //Buscamos las letras y compañias de inicio y fin
  2801.             $companyInicio = $clientsBigArray[$indStart][0]->getName();
  2802.             $letraInicio = substr($companyInicio, 0,1);
  2803.             $companyFin = $clientsBigArray[$indEnd][0]->getName();
  2804.             $letraFin = substr($companyFin, 0,1);
  2805.             $elem = array(
  2806.                 'indInicio' => $indStart,
  2807.                 'indFin' => $indEnd,
  2808.                 'letraInicio' => $letraInicio,
  2809.                 'companyInicio' => $companyInicio,
  2810.                 'letraFin' => $letraFin,
  2811.                 'companyFin' => $companyFin,
  2812.             );
  2813.             $arrayBoton[] = $elem;
  2814.         }
  2815.         $data_clients = array();
  2816.         foreach($clients as $client){
  2817.             $group = $em->getRepository(Group::class)->findOneById($client[0]->getGroupId());
  2818.             $parameters = array(
  2819.                 'clientId' => $client[0]->getId()
  2820.             );
  2821.             $dqlc = 'SELECT cc,  u.name, u.lastname
  2822.                 FROM App\Entity\ClientContact cc
  2823.                 INNER JOIN App\Entity\User u WITH u.id = cc.assignedAgent
  2824.                 WHERE cc.clientId = :clientId ';
  2825.             $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  2826.             $contacts = $queryc->getResult();
  2827.             $data_clients[] = array(
  2828.                 'client' => $client,
  2829.                 'group' => $group,
  2830.                 'contacts' => $contacts,
  2831.             );
  2832.         }
  2833.         return $this->render('client/clients-general-list-simple.html.twig',
  2834.             array(
  2835.                 'datosclientes' => $data_clients,
  2836.                 'arrayBoton' => $arrayBoton,
  2837.             )
  2838.         );
  2839.     }
  2840.     /**
  2841.      * @Route("/clientlistsimpleletters/{ind}", name="client_list_simple_letters")
  2842.      */
  2843.     public function clientListSimpleLettersAction($ind, Request $request)
  2844.     {
  2845.         $em = $this->getDoctrine()->getManager();
  2846.         $data_clients = array();
  2847.         if (true){
  2848.             // Creacion de la Botonera
  2849.             $arrayBoton = array();
  2850.             $elem = array('letra' => '0'); $arrayBoton['0'] = $elem;
  2851.             $elem = array('letra' => 'A'); $arrayBoton['A'] = $elem;
  2852.             $elem = array('letra' => 'B'); $arrayBoton['B'] = $elem;
  2853.             $elem = array('letra' => 'C'); $arrayBoton['C'] = $elem;
  2854.             $elem = array('letra' => 'D'); $arrayBoton['D'] = $elem;
  2855.             $elem = array('letra' => 'E'); $arrayBoton['E'] = $elem;
  2856.             $elem = array('letra' => 'F'); $arrayBoton['F'] = $elem;
  2857.             $elem = array('letra' => 'G'); $arrayBoton['G'] = $elem;
  2858.             $elem = array('letra' => 'H'); $arrayBoton['H'] = $elem;
  2859.             $elem = array('letra' => 'I'); $arrayBoton['I'] = $elem;
  2860.             $elem = array('letra' => 'J'); $arrayBoton['J'] = $elem;
  2861.             $elem = array('letra' => 'K'); $arrayBoton['K'] = $elem;
  2862.             $elem = array('letra' => 'L'); $arrayBoton['L'] = $elem;
  2863.             $elem = array('letra' => 'M'); $arrayBoton['M'] = $elem;
  2864.             $elem = array('letra' => 'N'); $arrayBoton['N'] = $elem;
  2865.             $elem = array('letra' => 'Ñ'); $arrayBoton['Ñ'] = $elem;
  2866.             $elem = array('letra' => 'O'); $arrayBoton['O'] = $elem;
  2867.             $elem = array('letra' => 'P'); $arrayBoton['P'] = $elem;
  2868.             $elem = array('letra' => 'Q'); $arrayBoton['Q'] = $elem;
  2869.             $elem = array('letra' => 'R'); $arrayBoton['R'] = $elem;
  2870.             $elem = array('letra' => 'S'); $arrayBoton['S'] = $elem;
  2871.             $elem = array('letra' => 'T'); $arrayBoton['T'] = $elem;
  2872.             $elem = array('letra' => 'U'); $arrayBoton['U'] = $elem;
  2873.             $elem = array('letra' => 'V'); $arrayBoton['V'] = $elem;
  2874.             $elem = array('letra' => 'W'); $arrayBoton['W'] = $elem;
  2875.             $elem = array('letra' => 'X'); $arrayBoton['X'] = $elem;
  2876.             $elem = array('letra' => 'Y'); $arrayBoton['Y'] = $elem;
  2877.             $elem = array('letra' => 'Z'); $arrayBoton['Z'] = $elem;
  2878.         }
  2879.         if ($ind == '0'){
  2880.             // Caso base, viene vacio se mostraran los que no empiezan por letra
  2881.             $arrayClientsZero = $em->getRepository(Client::class)->findAll();
  2882.             $arrayClients = array();
  2883.             // Creamos un arreglo con los indices
  2884.             foreach ($arrayClientsZero as $item){
  2885.                 $arrayClients[$item->getId()] = $item;
  2886.             }
  2887.             //Eliminamos del arreglo los elelmentos que se deban listar en A,B,C,...,Y,Z
  2888.             if (true){
  2889.                 $indice = 'a';
  2890.                 $parameters = array(
  2891.                     'namelist' => $indice.'%'
  2892.                 );
  2893.                 $dql = 'SELECT i
  2894.                 FROM App\Entity\Client i
  2895.                 WHERE i.name LIKE :namelist
  2896.                 ORDER BY i.name ASC';
  2897.                 $query = $em->createQuery($dql)->setParameters($parameters);
  2898.                 $clients = $query->getResult();
  2899.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  2900.                 foreach ($clients as $item){
  2901.                     if (array_key_exists($item->getId(),$arrayClients)){
  2902.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  2903.                         unset($arrayClients[$item->getId()]);
  2904.                     }
  2905.                 }
  2906.             }
  2907.             if (true){
  2908.                 $indice = 'b';
  2909.                 $parameters = array(
  2910.                     'namelist' => $indice.'%'
  2911.                 );
  2912.                 $dql = 'SELECT i
  2913.                 FROM App\Entity\Client i
  2914.                 WHERE i.name LIKE :namelist
  2915.                 ORDER BY i.name ASC';
  2916.                 $query = $em->createQuery($dql)->setParameters($parameters);
  2917.                 $clients = $query->getResult();
  2918.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  2919.                 foreach ($clients as $item){
  2920.                     if (array_key_exists($item->getId(),$arrayClients)){
  2921.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  2922.                         unset($arrayClients[$item->getId()]);
  2923.                     }
  2924.                 }
  2925.             }
  2926.             if (true){
  2927.                 $indice = 'c';
  2928.                 $parameters = array(
  2929.                     'namelist' => $indice.'%'
  2930.                 );
  2931.                 $dql = 'SELECT i
  2932.                 FROM App\Entity\Client i
  2933.                 WHERE i.name LIKE :namelist
  2934.                 ORDER BY i.name ASC';
  2935.                 $query = $em->createQuery($dql)->setParameters($parameters);
  2936.                 $clients = $query->getResult();
  2937.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  2938.                 foreach ($clients as $item){
  2939.                     if (array_key_exists($item->getId(),$arrayClients)){
  2940.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  2941.                         unset($arrayClients[$item->getId()]);
  2942.                     }
  2943.                 }
  2944.             }
  2945.             if (true){
  2946.                 $indice = 'd';
  2947.                 $parameters = array(
  2948.                     'namelist' => $indice.'%'
  2949.                 );
  2950.                 $dql = 'SELECT i
  2951.                 FROM App\Entity\Client i
  2952.                 WHERE i.name LIKE :namelist
  2953.                 ORDER BY i.name ASC';
  2954.                 $query = $em->createQuery($dql)->setParameters($parameters);
  2955.                 $clients = $query->getResult();
  2956.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  2957.                 foreach ($clients as $item){
  2958.                     if (array_key_exists($item->getId(),$arrayClients)){
  2959.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  2960.                         unset($arrayClients[$item->getId()]);
  2961.                     }
  2962.                 }
  2963.             }
  2964.             if (true){
  2965.                 $indice = 'e';
  2966.                 $parameters = array(
  2967.                     'namelist' => $indice.'%'
  2968.                 );
  2969.                 $dql = 'SELECT i
  2970.                 FROM App\Entity\Client i
  2971.                 WHERE i.name LIKE :namelist
  2972.                 ORDER BY i.name ASC';
  2973.                 $query = $em->createQuery($dql)->setParameters($parameters);
  2974.                 $clients = $query->getResult();
  2975.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  2976.                 foreach ($clients as $item){
  2977.                     if (array_key_exists($item->getId(),$arrayClients)){
  2978.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  2979.                         unset($arrayClients[$item->getId()]);
  2980.                     }
  2981.                 }
  2982.             }
  2983.             if (true){
  2984.                 $indice = 'f';
  2985.                 $parameters = array(
  2986.                     'namelist' => $indice.'%'
  2987.                 );
  2988.                 $dql = 'SELECT i
  2989.                 FROM App\Entity\Client i
  2990.                 WHERE i.name LIKE :namelist
  2991.                 ORDER BY i.name ASC';
  2992.                 $query = $em->createQuery($dql)->setParameters($parameters);
  2993.                 $clients = $query->getResult();
  2994.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  2995.                 foreach ($clients as $item){
  2996.                     if (array_key_exists($item->getId(),$arrayClients)){
  2997.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  2998.                         unset($arrayClients[$item->getId()]);
  2999.                     }
  3000.                 }
  3001.             }
  3002.             if (true){
  3003.                 $indice = 'g';
  3004.                 $parameters = array(
  3005.                     'namelist' => $indice.'%'
  3006.                 );
  3007.                 $dql = 'SELECT i
  3008.                 FROM App\Entity\Client i
  3009.                 WHERE i.name LIKE :namelist
  3010.                 ORDER BY i.name ASC';
  3011.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3012.                 $clients = $query->getResult();
  3013.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3014.                 foreach ($clients as $item){
  3015.                     if (array_key_exists($item->getId(),$arrayClients)){
  3016.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3017.                         unset($arrayClients[$item->getId()]);
  3018.                     }
  3019.                 }
  3020.             }
  3021.             if (true){
  3022.                 $indice = 'h';
  3023.                 $parameters = array(
  3024.                     'namelist' => $indice.'%'
  3025.                 );
  3026.                 $dql = 'SELECT i
  3027.                 FROM App\Entity\Client i
  3028.                 WHERE i.name LIKE :namelist
  3029.                 ORDER BY i.name ASC';
  3030.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3031.                 $clients = $query->getResult();
  3032.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3033.                 foreach ($clients as $item){
  3034.                     if (array_key_exists($item->getId(),$arrayClients)){
  3035.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3036.                         unset($arrayClients[$item->getId()]);
  3037.                     }
  3038.                 }
  3039.             }
  3040.             if (true){
  3041.                 $indice = 'i';
  3042.                 $parameters = array(
  3043.                     'namelist' => $indice.'%'
  3044.                 );
  3045.                 $dql = 'SELECT i
  3046.                 FROM App\Entity\Client i
  3047.                 WHERE i.name LIKE :namelist
  3048.                 ORDER BY i.name ASC';
  3049.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3050.                 $clients = $query->getResult();
  3051.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3052.                 foreach ($clients as $item){
  3053.                     if (array_key_exists($item->getId(),$arrayClients)){
  3054.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3055.                         unset($arrayClients[$item->getId()]);
  3056.                     }
  3057.                 }
  3058.             }
  3059.             if (true){
  3060.                 $indice = 'j';
  3061.                 $parameters = array(
  3062.                     'namelist' => $indice.'%'
  3063.                 );
  3064.                 $dql = 'SELECT i
  3065.                 FROM App\Entity\Client i
  3066.                 WHERE i.name LIKE :namelist
  3067.                 ORDER BY i.name ASC';
  3068.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3069.                 $clients = $query->getResult();
  3070.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3071.                 foreach ($clients as $item){
  3072.                     if (array_key_exists($item->getId(),$arrayClients)){
  3073.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3074.                         unset($arrayClients[$item->getId()]);
  3075.                     }
  3076.                 }
  3077.             }
  3078.             if (true){
  3079.                 $indice = 'k';
  3080.                 $parameters = array(
  3081.                     'namelist' => $indice.'%'
  3082.                 );
  3083.                 $dql = 'SELECT i
  3084.                 FROM App\Entity\Client i
  3085.                 WHERE i.name LIKE :namelist
  3086.                 ORDER BY i.name ASC';
  3087.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3088.                 $clients = $query->getResult();
  3089.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3090.                 foreach ($clients as $item){
  3091.                     if (array_key_exists($item->getId(),$arrayClients)){
  3092.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3093.                         unset($arrayClients[$item->getId()]);
  3094.                     }
  3095.                 }
  3096.             }
  3097.             if (true){
  3098.                 $indice = 'l';
  3099.                 $parameters = array(
  3100.                     'namelist' => $indice.'%'
  3101.                 );
  3102.                 $dql = 'SELECT i
  3103.                 FROM App\Entity\Client i
  3104.                 WHERE i.name LIKE :namelist
  3105.                 ORDER BY i.name ASC';
  3106.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3107.                 $clients = $query->getResult();
  3108.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3109.                 foreach ($clients as $item){
  3110.                     if (array_key_exists($item->getId(),$arrayClients)){
  3111.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3112.                         unset($arrayClients[$item->getId()]);
  3113.                     }
  3114.                 }
  3115.             }
  3116.             if (true){
  3117.                 $indice = 'm';
  3118.                 $parameters = array(
  3119.                     'namelist' => $indice.'%'
  3120.                 );
  3121.                 $dql = 'SELECT i
  3122.                 FROM App\Entity\Client i
  3123.                 WHERE i.name LIKE :namelist
  3124.                 ORDER BY i.name ASC';
  3125.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3126.                 $clients = $query->getResult();
  3127.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3128.                 foreach ($clients as $item){
  3129.                     if (array_key_exists($item->getId(),$arrayClients)){
  3130.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3131.                         unset($arrayClients[$item->getId()]);
  3132.                     }
  3133.                 }
  3134.             }
  3135.             if (true){
  3136.                 $indice = 'n';
  3137.                 $parameters = array(
  3138.                     'namelist' => $indice.'%'
  3139.                 );
  3140.                 $dql = 'SELECT i
  3141.                 FROM App\Entity\Client i
  3142.                 WHERE i.name LIKE :namelist
  3143.                 ORDER BY i.name ASC';
  3144.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3145.                 $clients = $query->getResult();
  3146.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3147.                 foreach ($clients as $item){
  3148.                     if (array_key_exists($item->getId(),$arrayClients)){
  3149.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3150.                         unset($arrayClients[$item->getId()]);
  3151.                     }
  3152.                 }
  3153.             }
  3154.             if (true){
  3155.                 $indice = 'ñ';
  3156.                 $parameters = array(
  3157.                     'namelist' => $indice.'%'
  3158.                 );
  3159.                 $dql = 'SELECT i
  3160.                 FROM App\Entity\Client i
  3161.                 WHERE i.name LIKE :namelist
  3162.                 ORDER BY i.name ASC';
  3163.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3164.                 $clients = $query->getResult();
  3165.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3166.                 foreach ($clients as $item){
  3167.                     if (array_key_exists($item->getId(),$arrayClients)){
  3168.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3169.                         unset($arrayClients[$item->getId()]);
  3170.                     }
  3171.                 }
  3172.             }
  3173.             if (true){
  3174.                 $indice = 'o';
  3175.                 $parameters = array(
  3176.                     'namelist' => $indice.'%'
  3177.                 );
  3178.                 $dql = 'SELECT i
  3179.                 FROM App\Entity\Client i
  3180.                 WHERE i.name LIKE :namelist
  3181.                 ORDER BY i.name ASC';
  3182.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3183.                 $clients = $query->getResult();
  3184.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3185.                 foreach ($clients as $item){
  3186.                     if (array_key_exists($item->getId(),$arrayClients)){
  3187.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3188.                         unset($arrayClients[$item->getId()]);
  3189.                     }
  3190.                 }
  3191.             }
  3192.             if (true){
  3193.                 $indice = 'p';
  3194.                 $parameters = array(
  3195.                     'namelist' => $indice.'%'
  3196.                 );
  3197.                 $dql = 'SELECT i
  3198.                 FROM App\Entity\Client i
  3199.                 WHERE i.name LIKE :namelist
  3200.                 ORDER BY i.name ASC';
  3201.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3202.                 $clients = $query->getResult();
  3203.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3204.                 foreach ($clients as $item){
  3205.                     if (array_key_exists($item->getId(),$arrayClients)){
  3206.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3207.                         unset($arrayClients[$item->getId()]);
  3208.                     }
  3209.                 }
  3210.             }
  3211.             if (true){
  3212.                 $indice = 'q';
  3213.                 $parameters = array(
  3214.                     'namelist' => $indice.'%'
  3215.                 );
  3216.                 $dql = 'SELECT i
  3217.                 FROM App\Entity\Client i
  3218.                 WHERE i.name LIKE :namelist
  3219.                 ORDER BY i.name ASC';
  3220.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3221.                 $clients = $query->getResult();
  3222.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3223.                 foreach ($clients as $item){
  3224.                     if (array_key_exists($item->getId(),$arrayClients)){
  3225.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3226.                         unset($arrayClients[$item->getId()]);
  3227.                     }
  3228.                 }
  3229.             }
  3230.             if (true){
  3231.                 $indice = 'r';
  3232.                 $parameters = array(
  3233.                     'namelist' => $indice.'%'
  3234.                 );
  3235.                 $dql = 'SELECT i
  3236.                 FROM App\Entity\Client i
  3237.                 WHERE i.name LIKE :namelist
  3238.                 ORDER BY i.name ASC';
  3239.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3240.                 $clients = $query->getResult();
  3241.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3242.                 foreach ($clients as $item){
  3243.                     if (array_key_exists($item->getId(),$arrayClients)){
  3244.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3245.                         unset($arrayClients[$item->getId()]);
  3246.                     }
  3247.                 }
  3248.             }
  3249.             if (true){
  3250.                 $indice = 's';
  3251.                 $parameters = array(
  3252.                     'namelist' => $indice.'%'
  3253.                 );
  3254.                 $dql = 'SELECT i
  3255.                 FROM App\Entity\Client i
  3256.                 WHERE i.name LIKE :namelist
  3257.                 ORDER BY i.name ASC';
  3258.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3259.                 $clients = $query->getResult();
  3260.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3261.                 foreach ($clients as $item){
  3262.                     if (array_key_exists($item->getId(),$arrayClients)){
  3263.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3264.                         unset($arrayClients[$item->getId()]);
  3265.                     }
  3266.                 }
  3267.             }
  3268.             if (true){
  3269.                 $indice = 't';
  3270.                 $parameters = array(
  3271.                     'namelist' => $indice.'%'
  3272.                 );
  3273.                 $dql = 'SELECT i
  3274.                 FROM App\Entity\Client i
  3275.                 WHERE i.name LIKE :namelist
  3276.                 ORDER BY i.name ASC';
  3277.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3278.                 $clients = $query->getResult();
  3279.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3280.                 foreach ($clients as $item){
  3281.                     if (array_key_exists($item->getId(),$arrayClients)){
  3282.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3283.                         unset($arrayClients[$item->getId()]);
  3284.                     }
  3285.                 }
  3286.             }
  3287.             if (true){
  3288.                 $indice = 'u';
  3289.                 $parameters = array(
  3290.                     'namelist' => $indice.'%'
  3291.                 );
  3292.                 $dql = 'SELECT i
  3293.                 FROM App\Entity\Client i
  3294.                 WHERE i.name LIKE :namelist
  3295.                 ORDER BY i.name ASC';
  3296.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3297.                 $clients = $query->getResult();
  3298.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3299.                 foreach ($clients as $item){
  3300.                     if (array_key_exists($item->getId(),$arrayClients)){
  3301.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3302.                         unset($arrayClients[$item->getId()]);
  3303.                     }
  3304.                 }
  3305.             }
  3306.             if (true){
  3307.                 $indice = 'v';
  3308.                 $parameters = array(
  3309.                     'namelist' => $indice.'%'
  3310.                 );
  3311.                 $dql = 'SELECT i
  3312.                 FROM App\Entity\Client i
  3313.                 WHERE i.name LIKE :namelist
  3314.                 ORDER BY i.name ASC';
  3315.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3316.                 $clients = $query->getResult();
  3317.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3318.                 foreach ($clients as $item){
  3319.                     if (array_key_exists($item->getId(),$arrayClients)){
  3320.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3321.                         unset($arrayClients[$item->getId()]);
  3322.                     }
  3323.                 }
  3324.             }
  3325.             if (true){
  3326.                 $indice = 'w';
  3327.                 $parameters = array(
  3328.                     'namelist' => $indice.'%'
  3329.                 );
  3330.                 $dql = 'SELECT i
  3331.                 FROM App\Entity\Client i
  3332.                 WHERE i.name LIKE :namelist
  3333.                 ORDER BY i.name ASC';
  3334.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3335.                 $clients = $query->getResult();
  3336.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3337.                 foreach ($clients as $item){
  3338.                     if (array_key_exists($item->getId(),$arrayClients)){
  3339.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3340.                         unset($arrayClients[$item->getId()]);
  3341.                     }
  3342.                 }
  3343.             }
  3344.             if (true){
  3345.                 $indice = 'x';
  3346.                 $parameters = array(
  3347.                     'namelist' => $indice.'%'
  3348.                 );
  3349.                 $dql = 'SELECT i
  3350.                 FROM App\Entity\Client i
  3351.                 WHERE i.name LIKE :namelist
  3352.                 ORDER BY i.name ASC';
  3353.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3354.                 $clients = $query->getResult();
  3355.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3356.                 foreach ($clients as $item){
  3357.                     if (array_key_exists($item->getId(),$arrayClients)){
  3358.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3359.                         unset($arrayClients[$item->getId()]);
  3360.                     }
  3361.                 }
  3362.             }
  3363.             if (true){
  3364.                 $indice = 'y';
  3365.                 $parameters = array(
  3366.                     'namelist' => $indice.'%'
  3367.                 );
  3368.                 $dql = 'SELECT i
  3369.                 FROM App\Entity\Client i
  3370.                 WHERE i.name LIKE :namelist
  3371.                 ORDER BY i.name ASC';
  3372.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3373.                 $clients = $query->getResult();
  3374.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3375.                 foreach ($clients as $item){
  3376.                     if (array_key_exists($item->getId(),$arrayClients)){
  3377.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3378.                         unset($arrayClients[$item->getId()]);
  3379.                     }
  3380.                 }
  3381.             }
  3382.             if (true){
  3383.                 $indice = 'z';
  3384.                 $parameters = array(
  3385.                     'namelist' => $indice.'%'
  3386.                 );
  3387.                 $dql = 'SELECT i
  3388.                 FROM App\Entity\Client i
  3389.                 WHERE i.name LIKE :namelist
  3390.                 ORDER BY i.name ASC';
  3391.                 $query = $em->createQuery($dql)->setParameters($parameters);
  3392.                 $clients = $query->getResult();
  3393.                 // Buscamos los elementos de esta letra y los removemos del arreglo
  3394.                 foreach ($clients as $item){
  3395.                     if (array_key_exists($item->getId(),$arrayClients)){
  3396.                         // Si el elemento se encuentra en el arreglo lo quitamos por que pertenece al listado de la letra
  3397.                         unset($arrayClients[$item->getId()]);
  3398.                     }
  3399.                 }
  3400.             }
  3401.             $clients = $arrayClients;
  3402.         } else {
  3403.             $parameters = array(
  3404.                 'namelist' => $ind.'%'
  3405.             );
  3406.             $dql = 'SELECT i
  3407.                 FROM App\Entity\Client i
  3408.                 WHERE i.name LIKE :namelist
  3409.                 ORDER BY i.name ASC';
  3410.             $query = $em->createQuery($dql)->setParameters($parameters);
  3411.             $clients = $query->getResult();
  3412.         }
  3413.         foreach($clients as $client){
  3414.             $group = $em->getRepository(Group::class)->findOneById($client->getGroupId());
  3415.             $parameters = array(
  3416.                 'clientId' => $client->getId()
  3417.             );
  3418.             $dqlc = 'SELECT cc,  u.name, u.lastname
  3419.                 FROM App\Entity\ClientContact cc
  3420.                 INNER JOIN App\Entity\User u WITH u.id = cc.assignedAgent
  3421.                 WHERE cc.clientId = :clientId ';
  3422.             $queryc = $em->createQuery($dqlc)->setParameters($parameters);
  3423.             $contacts = $queryc->getResult();
  3424.             $data_clients[] = array(
  3425.                 'client' => array( 'id' =>$client->getId(), 'name' => $client->getName(), 'title' => $client->getTitle()),
  3426.                 'group' => $group,
  3427.                 'contacts' => $contacts,
  3428.             );
  3429.         }
  3430.         return $this->render('client/clients-general-list-letters.html.twig',
  3431.             array(
  3432.                 'datosclientes' => $data_clients,
  3433.                 'arrayBoton' => $arrayBoton,
  3434.             )
  3435.         );
  3436.     }
  3437. }