src/Controller/TicketController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ContratsRepository;
  4. use DateTime;
  5. use App\Library\Excel;
  6. use App\Entity\Actions;
  7. use App\Entity\Tickets;
  8. use App\Service\Securizer;
  9. use App\Repository\StatusRepository;
  10. use App\Repository\ActionsRepository;
  11. use App\Repository\ClientsRepository;
  12. use App\Repository\TicketsRepository;
  13. use App\Repository\ContactsRepository;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use PhpOffice\PhpSpreadsheet\Style\Border;
  16. use App\Repository\LigneDeContratRepository;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Serializer\SerializerInterface;
  20. use Symfony\Component\Validator\Validator\ValidatorInterface;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
  24. class TicketController extends AbstractController
  25. {
  26.     /**
  27.      * @IsGranted("ROLE_USER")
  28.      */
  29.     public function index(TicketsRepository $repoTicketAccessDecisionManagerInterface $accessDecisionManagerContactsRepository $repoContact): Response
  30.     {
  31.         // retourne tickets en fonction des roles de l'utilisateur
  32.         $securizer = new Securizer($accessDecisionManager);
  33.         // recupere le ou les tickets qu'il est possible d'afficher
  34.         $tickets $repoTicket->findTicketAll($this->getUser(), $securizer$repoContact);
  35.         return $this->json($tickets200, [], ['groups' => 'affichageTickets']);
  36.     }
  37.     /**
  38.      * @IsGranted("ROLE_USER")
  39.      */
  40.     public function ticketOpen(TicketsRepository $repoTicketAccessDecisionManagerInterface $accessDecisionManagerContactsRepository $repoContact): Response
  41.     {
  42.         // retourne tickets ouvertes en fonction des roles de l'utilisateur
  43.         try {
  44.             $securizer = new Securizer($accessDecisionManager);
  45.         } catch (\throwable $e) {
  46.             return $this->json([
  47.                 'status' => 400,
  48.                 'message' => $e->getMessage()
  49.             ], 400);
  50.         }
  51.         // recupere le ou les tickets qu'il est possible d'afficher
  52.         $tickets $repoTicket->findTicketStatus($this->getUser(), ["Nouveau""En Cours""En Attente"], $securizer$repoContact);
  53.         header('Accept-Encoding: gzip, compress, br');
  54.         return $this->json($tickets200, [], ['groups' => ['affichageTickets''affichageTicketsActions']]);
  55.     }
  56.     /**
  57.      * @IsGranted("ROLE_USER")
  58.      */
  59.     public function ticketClose($start$finTicketsRepository $repoTicketAccessDecisionManagerInterface $accessDecisionManagerContactsRepository $repoContact): Response
  60.     {
  61.         $securizer = new Securizer($accessDecisionManager);
  62.         $tickets $repoTicket->getTicketsByDate($start$fin$this->getUser(), $securizer$repoContact);
  63.         return $this->json($tickets200, [], ['groups' => 'affichageTickets']);
  64.     }
  65.     /**
  66.      * @IsGranted("ROLE_USER")
  67.      */
  68.     public function voir($idTicketsRepository $repoTicketContactsRepository $repoContactAccessDecisionManagerInterface $accessDecisionManager): Response
  69.     {
  70.         // retourne les details du ticket par id
  71.         $ticket $repoTicket->find($id);
  72.         $securizer = new Securizer($accessDecisionManager);
  73.         $tickets $repoTicket->findTicketAll($this->getUser(), $securizer$repoContact);
  74.         //verifi que le ticket que l'on cherche fait bien partie de la liste de ceux qu'il est possible d'afficher
  75.         if (in_array($repoTicket->find($id), $tickets)) {
  76.             //le ticket a visualiser
  77.             $ticket $repoTicket->find($id);
  78.         } else {
  79.             return $this->json([
  80.                 'status' => 400,
  81.                 'message' => "Vous ne pouvez pas consulter ce ticket"
  82.             ], 400);
  83.         }
  84.         return $this->json($ticket200, [], ['groups' => 'affichageTickets']);
  85.     }
  86.     /**
  87.      * @IsGranted("ROLE_TECH")
  88.      */
  89.     public function delete($idTicketsRepository $repoTicket): Response
  90.     {
  91.         // retourne les details du ticket par id
  92.         $ticket $repoTicket->find($id);
  93.         //verifi que le ticket que l'on cherche fait bien partie de la liste de ceux qu'il est possible d'afficher
  94.         if (count($ticket->getActions()) > || $ticket->getIdStatus()->getStatus() != "Nouveau") {
  95.             return $this->json([
  96.                 'status' => 400,
  97.                 'message' => "Il n'est pas possible de supprimer ce ticket"
  98.             ], 400);
  99.         } else {
  100.             $repoTicket->remove($ticket);
  101.         }
  102.         return $this->json(true200);
  103.     }
  104.     /**
  105.      * @IsGranted("ROLE_CLIENT")
  106.      */
  107.     public function creer(Request $requestStatusRepository $repoStatusValidatorInterface $validatorSerializerInterface $serializerEntityManagerInterface $managerContactsRepository $repoContactSecurizer $securizer): Response
  108.     {
  109.         // creer un nouveau ticket, seul les role client ou superieur peuvent acceder a cette page
  110.         $contacts $repoContact->findContactActif($this->getUser(), $securizer);
  111.         $jsonRecu $request->getContent();
  112.         try {
  113.             //transforme le json reçu en entity
  114.             $ticket $serializer->deserialize($jsonRecuTickets::class, 'json');
  115.             if (in_array($ticket->getBeneficiaire(), $contacts)) {
  116.                 $ticket->setCreateur($this->getUser())
  117.                     ->setDateCreation(new \DateTime())
  118.                     ->setIdStatus($repoStatus->findOneBy(['status' => 'Nouveau']));
  119.                 //validation des données reçus
  120.                 $errors $validator->validate($ticket);
  121.                 //si il y a au moins 1 erreur alors il retourne un json avec l'erreur de validation en message
  122.                 if (count($errors) > 0) {
  123.                     return $this->json($errors400);
  124.                 }
  125.                 $manager->persist($ticket);
  126.                 $manager->flush();
  127.             } else {
  128.                 //retourne un json avec message d'erreur si l'on a pas le droit d'afficher ou si l'id n'existe pas
  129.                 return $this->json([
  130.                     'status' => 400,
  131.                     'message' => "Vous ne pouvez pas lier un ticket à ce contact"
  132.                 ], 400);
  133.             }
  134.         } catch (\throwable $e) {
  135.             //try catch pour les erreurs de syntaxe dans le json
  136.             return $this->json([
  137.                 'status' => 400,
  138.                 'message' => $e->getMessage()
  139.             ], 400);
  140.         }
  141.         return $this->json($ticket201, [], ['groups' => 'affichageTickets']);
  142.     }
  143.     /**
  144.      * @IsGranted("ROLE_TECH")
  145.      */
  146.     public function uploadFile(Request $requestEntityManagerInterface $managerTicketsRepository $repoTicketAccessDecisionManagerInterface $accessDecisionManager): Response
  147.     {
  148.         // charger un fichier a un élément de park, seul les roles tech ou supperieur peuvent accer a cette url
  149.         $securizer = new Securizer($accessDecisionManager);
  150.         if (!$securizer->isGranted($this->getUser(), "ROLE_TECH"))
  151.             return $this->json([
  152.                 'status' => 400,
  153.                 'message' => "Vous ne pouvez pas consulter cet élément"
  154.             ], 400);
  155.         try {
  156.             $file $request->files->get('myFile');
  157.             // ** Vérifier si les dossiers existes et si oui supprimer le contenu
  158.             $path dirname(__DIR__) . '/../documents/tickets/ticket_' $_POST["ticketId"] . "/";
  159.             if (!is_dir($path))
  160.                 mkdir($path0777true);
  161.             // ** Télécharger le fichier
  162.             if (!empty($file)) {
  163.                 $file->move(
  164.                     $path,
  165.                     $_FILES["myFile"]["name"]
  166.                 );
  167.             }
  168.             $ticket $repoTicket->find($_POST["ticketId"]);
  169.             $ticket->setFile($_FILES["myFile"]["name"]);
  170.             $manager->persist($ticket);
  171.             $manager->flush();
  172.         } catch (\throwable $e) {
  173.             return $this->json([
  174.                 'status' => 400,
  175.                 'message' => $e->getMessage()
  176.             ], 400);
  177.         }
  178.         return $this->json($ticket201, [], ['groups' => 'affichageTickets']);
  179.     }
  180.     /**
  181.      * @IsGranted("ROLE_TECH")
  182.      */
  183.     public function getFile($dataAccessDecisionManagerInterface $accessDecisionManager)
  184.     {
  185.         // télécharger un fichier d'un élément de parc, seul les roles tech ou supperieur peuvent accer a cette url
  186.         $securizer = new Securizer($accessDecisionManager);
  187.         if (!$securizer->isGranted($this->getUser(), "ROLE_TECH"))
  188.             return $this->json([
  189.                 'status' => 400,
  190.                 'message' => "Vous ne pouvez pas consulter cet élément"
  191.             ], 400);
  192.         try {
  193.             $path =  dirname(__DIR__) . "/../documents/tickets/ticket_" str_replace("::filename""/"str_replace("::extension""."$data));
  194.             if (!is_file($path))
  195.                 return $this->json([
  196.                     'status' => 400,
  197.                     'message' => "Aucun fichier de ce type n’a été trouvé"
  198.                 ], 400);
  199.         } catch (\throwable $e) {
  200.             return $this->json([
  201.                 'status' => 400,
  202.                 'message' => $e->getMessage()
  203.             ], 400);
  204.         }
  205.         // header('Access-Control-Allow-Origin: ' . "http://localhost:8001");
  206.         header('Access-Control-Allow-Origin: ' "https://extranet.cco-info.fr/");
  207.         header('Access-Control-Allow-Credentials: true');
  208.         header('Access-Control-Allow-Methods: POST');
  209.         header('Access-Control-Allow-Headers: Content-Type');
  210.         header('Content-Description: File Transfer');
  211.         header('Content-Type: application/octet-stream');
  212.         header('Content-Disposition: attachment; filename="' basename($path) . '"');
  213.         header('Expires: 0');
  214.         header('Cache-Control: must-revalidate');
  215.         header('Pragma: public');
  216.         header('Content-Length: ' filesize($path));
  217.         flush(); // Flush system output buffer
  218.         echo readfile($path);
  219.     }
  220.     /**
  221.      * @IsGranted("ROLE_TECH")
  222.      */
  223.     public function modif($idRequest $requestTicketsRepository $repoTicketValidatorInterface $validatorSerializerInterface $serializerEntityManagerInterface $managerContactsRepository $repoContact): Response
  224.     {
  225.         // le ticket a modifier
  226.         $ticket $repoTicket->find($id);
  227.         //si l'id est invalide, retourne un json avec un message d'erreur
  228.         if ($ticket == null) {
  229.             return $this->json([
  230.                 'status' => 400,
  231.                 'message' => "le ticket à modifier n'existe pas"
  232.             ], 400);
  233.         }
  234.         // liste des beneficiare qu'il est possible d'affecter a un ticket pour qu'il reste lié au même client
  235.         $idClientBeneficiaire $ticket->getBeneficiaire()->getIdClient()->getId();
  236.         $contacts $repoContact->findBy(['idClient' => $idClientBeneficiaire]);
  237.         $jsonRecu $request->getContent();
  238.         try {
  239.             $serializer->deserialize($jsonRecuTickets::class, 'json', ['object_to_populate' => $ticket]);
  240.             if (in_array($ticket->getBeneficiaire(), $contacts) && $idClientBeneficiaire == $ticket->getBeneficiaire()->getIdClient()->getId()) {
  241.                 $errors $validator->validate($ticket);
  242.                 if (count($errors) > 0) {
  243.                     return $this->json($errors400);
  244.                 }
  245.                 $manager->persist($ticket);
  246.                 $manager->flush();
  247.             } else {
  248.                 return $this->json([
  249.                     'status' => 400,
  250.                     'message' => "Vous ne pouvez pas lié ce ticket a ce contact"
  251.                 ], 400);
  252.             }
  253.         } catch (\throwable $e) {
  254.             return $this->json([
  255.                 'status' => 400,
  256.                 'message' => $e->getMessage()
  257.             ], 400);
  258.         }
  259.         return $this->json($ticket201, [], ['groups' => 'affichageTickets']);
  260.     }
  261.     /**
  262.      * @IsGranted("ROLE_TECH")
  263.      */
  264.     public function setStatus(Request $requestTicketsRepository $ticketsRepositoryStatusRepository $statusRepoEntityManagerInterface $manager): Response
  265.     {
  266.         $jsonRecu json_decode($request->getContent());
  267.         if (!isset($jsonRecu->idTicket) || empty($jsonRecu->idTicket))
  268.             return $this->json([
  269.                 'status' => 400,
  270.                 'message' => "L'id du ticket est manquant"
  271.             ], 400);
  272.         if (!isset($jsonRecu->idStatus) || empty($jsonRecu->idStatus))
  273.             return $this->json([
  274.                 'status' => 400,
  275.                 'message' => "L'id du status est manquant"
  276.             ], 400);
  277.         $ticket $ticketsRepository->find($jsonRecu->idTicket);
  278.         if (empty($ticket))
  279.             return $this->json([
  280.                 'status' => 400,
  281.                 'message' => sprintf("l'id %d ne correspond pas à un ticket"$jsonRecu->idTicket)
  282.             ], 400);
  283.         $status $statusRepo->find($jsonRecu->idStatus);
  284.         if (empty($status))
  285.             return $this->json([
  286.                 'status' => 400,
  287.                 'message' => sprintf("l'id %d ne correspond pas à un status"$jsonRecu->idStatus)
  288.             ], 400);
  289.         try {
  290.             $ticket->setIdStatus($status);
  291.             // If ticket passe à un statut terminer ou clôturer => incrémenter le champs "hotlineCompteur" du nombre de minute.
  292.             if ($status->getStatus() === "Termine") {
  293.                 $client $ticket->getBeneficiaire()->getIdClient();
  294.                 //modifi la durée consomé de la ligne de contrat de l'intervention
  295.                 $client $client->setHotlineCompteur($client->getHotlineCompteur() + $ticket->getDureeTotale());
  296.                 $manager->persist($client);
  297.             }
  298.             $manager->persist($ticket);
  299.             $action = new Actions();
  300.             $action->setDateAction(new DateTime());
  301.             $action->setMessage($status->getStatus());
  302.             $action->setDuree(0);
  303.             $action->setIntervenant($this->getUser());
  304.             $action->setTicket($ticket);
  305.             $action->setStatusChanged(true);
  306.             $manager->persist($action);
  307.             $manager->flush();
  308.         } catch (\throwable $e) {
  309.             //try catch pour les erreurs de syntaxe dans le json
  310.             return $this->json([
  311.                 'status' => 400,
  312.                 'message' => $e->getMessage()
  313.             ], 400);
  314.         }
  315.         return $this->json($action201, [], ['groups' => 'affichageAction']);
  316.     }
  317.     /**
  318.      * @IsGranted("ROLE_CLIENT")
  319.      */
  320.     public function getTicketByClient(int $idContactsRepository $repoContactClientsRepository $repoClient)
  321.     {
  322.         $client $repoClient->find($id);
  323.         if (empty($client)) {
  324.             return $this->json([
  325.                 'status' => 400,
  326.                 'message' => sprintf("Aucun client n'a �t� trouv� avec l'id %d"$id)
  327.             ], 400);
  328.         }
  329.         $contacts $repoContact->findBy(['idClient' => $client]);
  330.         $tickets = [];
  331.         foreach ($contacts as $contact) {
  332.             foreach ($contact->getTicketBeneficiaire() as $t) {
  333.                 $tickets[] = $t;
  334.             }
  335.         }
  336.         usort($tickets, function ($a$b) {
  337.             if ($a->getDateCreation() < $b->getDateCreation()) {
  338.                 return 1;
  339.             } else if ($a->getDateCreation() > $b->getDateCreation()) {
  340.                 return -1;
  341.             }
  342.             return 0;
  343.         });
  344.         return $this->json($tickets201, [], ['groups' => 'affichageTickets']);
  345.     }
  346.     /**
  347.      * @IsGranted("ROLE_USER")
  348.      */
  349.     public function getTicketByContact(int $idContactsRepository $repoContactClientsRepository $repoClient)
  350.     {
  351.         $contact $repoContact->find($id);
  352.         if (empty($contact)) {
  353.             return $this->json([
  354.                 'status' => 400,
  355.                 'message' => sprintf("Aucun contact n'a �t� trouv� avec l'id %d"$id)
  356.             ], 400);
  357.         }
  358.         $tickets = [];
  359.         foreach ($contact->getTicketBeneficiaire() as $t) {
  360.             $tickets[] = $t;
  361.         }
  362.         return $this->json($tickets201, [], ['groups' => 'affichageTickets']);
  363.     }
  364.     /**
  365.      * @IsGranted("ROLE_COMMERCIAL")
  366.      */
  367.     public function stats(Request $requestAccessDecisionManagerInterface $accessDecisionManagerStatusRepository $statusRepoActionsRepository $actionsRepoTicketsRepository $repoTicketsContactsRepository $repoContact): Response
  368.     {
  369.         $jsonRecu json_decode($request->getContent());
  370.         $securizer = new Securizer($accessDecisionManager);
  371.         $tickets $repoTickets->getTicketsByDate($jsonRecu->startDate$jsonRecu->endDate$this->getUser(), $securizer$repoContact);
  372.         $actions $actionsRepo->getActionsByDate($jsonRecu->startDate$jsonRecu->endDate$this->getUser(), $securizer$repoContact);
  373.         $status $statusRepo->findAll();
  374.         $quantity = [];
  375.         foreach ($status as $key => $value) {
  376.             if (in_array('ticket'$value->getTypes()))
  377.                 $quantity[$value->getStatus()] = 0;
  378.         }
  379.         /** @var Tickets $ticket */
  380.         foreach ($tickets as $key => $ticket) {
  381.             $quantity[$ticket->getIdStatus()->getStatus()] += 1;
  382.         }
  383.         $actionsTime = [];
  384.         $totalTime 0;
  385.         /** @var Actions $action */
  386.         foreach ($actions as $key => $action) {
  387.             if ($action->getDuree() > 0) {
  388.                 if (!isset($actionsTime[$action->getDateAction()->format("d/m/Y")])) $actionsTime[$action->getDateAction()->format("d/m/Y")] = 0;
  389.                 $actionsTime[$action->getDateAction()->format("d/m/Y")] += $action->getDuree();
  390.                 $totalTime += $action->getDuree();
  391.             }
  392.         }
  393.         $general = [
  394.             "Total tickets" => ["total" => count($tickets) . ' tickets'"moyen" => (count($tickets) > round($totalTime count($tickets)) : 0) .  " min""description" => "moyen par ticket"],
  395.             "Total actions" => ["total" => count($actions) . ' actions'"moyen" => (count($tickets) > round(count($actions) / count($tickets)) : 0) . " actions""description" => "moyen par ticket"],
  396.             "Temps Passé" => ["total" => $totalTime " min""moyen" => (count($actions) > round($totalTime count($actions)) : 0) .  " min""description" => "moyen par action"],
  397.         ];
  398.         return $this->json([$quantity$actionsTime$general], 200, [], ['groups' => 'affichageTickets']);
  399.     }
  400.     /**
  401.      * @IsGranted("ROLE_TECH")
  402.      */
  403.     public function export(Request $requestTicketsRepository $repoTickets)
  404.     {
  405.         try {
  406.             $jsonRecu json_decode($request->getContent());
  407.             $path $_SERVER["DOCUMENT_ROOT"] . ($_ENV['APP_ENV'] == "dev" '../documents/' '/ExtranetV2/documents/');
  408.             $excel = new Excel($path'Export tickets history.xlsx');
  409.             $row 1;
  410.             $cols = ["A""B""C""D""E""F",  "G"];
  411.             $heads = ["Ticket N°""Titre""Statut""Date""Client""Bénéficiaire""Temps passe (minutes)"];
  412.             for ($i 0$i count($heads); $i++) {
  413.                 $excel->writeCell($cols[$i] . $row$heads[$i], Excel::_FORMAT_TEXTE_);
  414.             }
  415.             $excel->fontBold('A1:G1');
  416.             $row++;
  417.             /** @var Tickets $ticket */
  418.             for ($i 0$i count($jsonRecu->ids); $i++) {
  419.                 $ticket $repoTickets->find($jsonRecu->ids[$i]);
  420.                 $excel->writeCell("A" $row$ticket->getId(), Excel::_FORMAT_NUMBER_);
  421.                 $excel->writeCell("B" $row$ticket->getTitre(), Excel::_FORMAT_TEXTE_);
  422.                 $excel->writeCell("C" $row$ticket->getIdStatus()->getStatus(), Excel::_FORMAT_TEXTE_);
  423.                 $excel->writeCell("D" $rowdate('d/m/Y'$ticket->getDateCreation()), Excel::_FORMAT_DDMMYYYY_);
  424.                 $excel->writeCell("E" $row$ticket->getBeneficiaire()->getIdClient()->getNom(), Excel::_FORMAT_TEXTE_);
  425.                 $excel->writeCell("F" $row$ticket->getBeneficiaire()->getNom() . " " $ticket->getBeneficiaire()->getPrenom(), Excel::_FORMAT_TEXTE_);
  426.                 $excel->writeCell("G" $row$ticket->getDureeTotale(), Excel::_FORMAT_NUMBER_);
  427.                 $excel->applyBackgroundColorAndColor('A' $row ':G' $row, ($row == 'f5f5f5' 'ffffff'), '424242');
  428.                 $excel->fontBold('G' $row ':G' $row);
  429.                 $row++;
  430.             }
  431.             $excel->applyAllBorder(Border::BORDER_THIN'A1' ':G' . ($row 1));
  432.             $excel->autoSizeColumn('A:G');
  433.             $excel->saveXlsx();
  434.         } catch (\Throwable $th) {
  435.             var_dump($th);
  436.         }
  437.         return $this->json(true200, []);
  438.     }
  439.     public function downloadExport()
  440.     {
  441.         $path $_SERVER["DOCUMENT_ROOT"] . ($_ENV['APP_ENV'] == "dev" '../documents/' '/ExtranetV2/documents/');
  442.         $path .= 'Export tickets history.xlsx';
  443.         // header('Access-Control-Allow-Origin: ' . "http://localhost:8001");
  444.         header('Access-Control-Allow-Origin: ' "https://extranet.cco-info.fr/");
  445.         header('Access-Control-Allow-Credentials: true');
  446.         header('Access-Control-Allow-Methods: POST');
  447.         header('Access-Control-Allow-Headers: Content-Type');
  448.         header('Content-Description: File Transfer');
  449.         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); // Type MIME pour les fichiers Excel
  450.         header('Content-Disposition: attachment; filename="Export tickets history.xlsx"');
  451.         header('Expires: 0');
  452.         header('Cache-Control: must-revalidate');
  453.         header('Pragma: public');
  454.         header('Content-Length: ' filesize($path));
  455.         return readfile($path);
  456.     }
  457.     /**
  458.      * @IsGranted("ROLE_COMMERCIAL")
  459.      */
  460.     public function showHotline(
  461.         Request $request,
  462.         ClientsRepository $clientsRepository,
  463.         ContratsRepository $contratsRepository,
  464.         TicketsRepository $ticketsRepository
  465.     ): Response {
  466. //        $actionsTime = $ticketsRepository->findTimeTicketTelemaintenance();
  467. //        $contractsTime = $contratsRepository->findTimeContratTelemaintenance();
  468. //        $actionsNotClose = $ticketsRepository->findTimeNotCloseTicketTelemaintenance();
  469. //
  470. //        $array = [];
  471. //
  472. //        foreach ($actionsTime as $actionTime) {
  473. //            $count = 0;
  474. //            foreach($actionsNotClose as $actionNotClose) {
  475. //                if ($actionTime['id'] === $actionNotClose['id']) {
  476. //                    $count += $actionNotClose['1'];
  477. //                }
  478. //            }
  479. //
  480. //            $find = false;
  481. //            foreach ($contractsTime as $contractTime) {
  482. //                if ($actionTime['id'] === $contractTime['id']) {
  483. //                    $array[] = [
  484. //                        "nom" => $contractTime['nom'],
  485. //                        "heureConsommee" => $contractTime['1'],
  486. //                        "heureNotClosing" => $count,
  487. //                        "heureTotalTicket" => $actionTime['1'],
  488. //                        "hotlineCompteur" => $actionTime['hotlineCompteur']
  489. //                    ];
  490. //                    $find = true;
  491. //                    break;
  492. //                }
  493. //            }
  494. //
  495. //            if (!$find) {
  496. //                $array[] = [
  497. //                    "nom" => $actionTime['nom'],
  498. //                    "heureConsommee" => "Sans contrat",
  499. //                    "heureNotClosing" => $count,
  500. //                    "heureTotalTicket" => $actionTime['1'],
  501. //                    "hotlineCompteur" => $actionTime['hotlineCompteur']
  502. //                ];
  503. //            }
  504. //        }
  505.         $array $this->findDiffTime($ticketsRepository$contratsRepository);
  506.         return $this->render('ticket/index.html.twig', [
  507.             "bilanHeures" => $array
  508.         ]);
  509.     }
  510.     
  511.     public function findDiffTime(TicketsRepository  $ticketsRepositoryContratsRepository $contratsRepository): array
  512.     {
  513.         $actionsTime $ticketsRepository->findTimeTicketTelemaintenance();
  514.         $contractsTime $contratsRepository->findTimeContratTelemaintenance();
  515.         $actionsNotClose $ticketsRepository->findTimeNotCloseTicketTelemaintenance();
  516.         $array = [];
  517.         foreach ($actionsTime as $actionTime) {
  518.             $count 0;
  519.             foreach($actionsNotClose as $actionNotClose) {
  520.                 if ($actionTime['id'] === $actionNotClose['id']) {
  521.                     $count += $actionNotClose['1'];
  522.                 }
  523.             }
  524.             $find false;
  525.             foreach ($contractsTime as $contractTime) {
  526.                 if ($actionTime['id'] === $contractTime['id']) {
  527.                     $array[] = [
  528.                         "nom" => $contractTime['nom'],
  529.                         "heureConsommee" => $contractTime['1'],
  530.                         "heureNotClosing" => $count,
  531.                         "heureTotalTicket" => $actionTime['1'],
  532.                         "hotlineCompteur" => $actionTime['hotlineCompteur']
  533.                     ];
  534.                     $find true;
  535.                     break;
  536.                 }
  537.             }
  538.             if (!$find) {
  539.                 $array[] = [
  540.                     "nom" => $actionTime['nom'],
  541.                     "heureConsommee" => "Sans contrat",
  542.                     "heureNotClosing" => $count,
  543.                     "heureTotalTicket" => $actionTime['1'],
  544.                     "hotlineCompteur" => $actionTime['hotlineCompteur']
  545.                 ];
  546.             }
  547.         }
  548.         return $array;
  549.     }
  550. }