src/Controller/Common/CommonController.php line 218

Open in your IDE?
  1. <?php
  2.     /******************************************************************************
  3.      * Copyright (c) Echo-numeric 2020-2023.                                      *
  4.      ******************************************************************************/
  5.     namespace App\Controller\Common;
  6.     use App\Constants\Platform;
  7.     use App\Entity\CustomerProduct;
  8.     use App\Entity\Parameter;
  9.     use App\Entity\PointTransaction;
  10.     use App\Entity\PointTransactionType;
  11.     use App\Entity\Purchase;
  12.     use App\Entity\PurchaseProduct;
  13.     use App\Entity\PurchaseProductItem;
  14.     use App\Entity\SaleOrder;
  15.     use App\Entity\Setting;
  16.     use App\Entity\User;
  17.     use App\Exception\CatalogueException;
  18.     use App\Exception\PurchaseDeclarationException;
  19.     use App\Factory\Platform\MailerFactory;
  20.     use App\Factory\PointFactory;
  21.     use App\Model\Period;
  22.     use App\Services\Common\Email\MailTypes;
  23.     use App\Services\Common\MailerService;
  24.     use App\Services\Common\PlatformService;
  25.     use App\Services\Common\Point\UserPointServiceInterface;
  26.     use App\Services\Common\SaleOrderService;
  27.     use App\Services\ConfigService;
  28.     use App\Services\DTV\YamlConfig\YamlReader;
  29.     use App\Services\Front\Catalogue\JsonCatalogueService;
  30.     use DateTime;
  31.     use Doctrine\ORM\EntityManagerInterface;
  32.     use Doctrine\ORM\NonUniqueResultException;
  33.     use Exception;
  34.     use Psr\Log\LoggerInterface;
  35.     use ReflectionException;
  36.     use Symfony\Bundle\FrameworkBundle\Console\Application;
  37.     use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  38.     use Symfony\Component\Console\Input\ArrayInput;
  39.     use Symfony\Component\Console\Output\BufferedOutput;
  40.     use Symfony\Component\HttpFoundation\BinaryFileResponse;
  41.     use Symfony\Component\HttpFoundation\JsonResponse;
  42.     use Symfony\Component\HttpFoundation\RedirectResponse;
  43.     use Symfony\Component\HttpFoundation\Request;
  44.     use Symfony\Component\HttpFoundation\Response;
  45.     use Symfony\Component\HttpKernel\KernelInterface;
  46.     use Symfony\Component\Routing\Annotation\Route;
  47.     use Symfony\Component\Stopwatch\Stopwatch;
  48.     use Symfony\Component\Yaml\Yaml;
  49.     use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  50.     use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  51.     use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  52.     use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  53.     use Symfony\Contracts\Translation\TranslatorInterface;
  54.     class CommonController extends AbstractController
  55.     {
  56.         private KernelInterface           $kernel;
  57.         private LoggerInterface           $logger;
  58.         private EntityManagerInterface    $em;
  59.         private ConfigService             $configService;
  60.         private PlatformService           $platformService;
  61.         private YamlReader                $yamlReader;
  62.         private UserPointServiceInterface $userPointService;
  63.         private JsonCatalogueService $jsonCatalogueService;
  64.         private SaleOrderService $saleOrderService;
  65.         /**
  66.          * @throws Exception
  67.          */
  68.         public function __construct(
  69.             KernelInterface $kernel,
  70.             LoggerInterface $logger,
  71.             EntityManagerInterface $em,
  72.             ConfigService $configService,
  73.             PlatformService $platformService,
  74.             YamlReader $yamlReader,
  75.             PointFactory $pointFactory,
  76.             JsonCatalogueService $jsonCatalogueService,
  77.             SaleOrderService $saleOrderService
  78.         ) {
  79.             $this->kernel               $kernel;
  80.             $this->logger               $logger;
  81.             $this->em                   $em;
  82.             $this->configService        $configService;
  83.             $this->platformService      $platformService;
  84.             $this->yamlReader           $yamlReader;
  85.             $this->userPointService     $pointFactory->getUserPointService();
  86.             $this->jsonCatalogueService $jsonCatalogueService;
  87.             $this->saleOrderService     $saleOrderService;
  88.         }
  89.         /**
  90.          * @return RedirectResponse
  91.          */
  92.         public function backRedirection(): RedirectResponse
  93.         {
  94.             return $this->redirectToRoute('back_dashboard');
  95.         }
  96.         /**
  97.          * @param   string  $folder
  98.          * @param   string  $fileName
  99.          *
  100.          * @return BinaryFileResponse
  101.          *
  102.          * @throws Exception
  103.          */
  104.         public function exposeFolderFile(string $folderstring $fileName): BinaryFileResponse
  105.         {
  106.             $path $this->getParameter('kernel.project_dir').'/medias/'.$this->platformService->getDomain().'/'.$folder.'/';
  107.             $file $path.$fileName;
  108.             if (!file_exists($file)) {
  109.                 throw $this->createNotFoundException("Cette ressource n'existe pas");
  110.             }
  111.             return new BinaryFileResponse($file200);
  112.         }
  113.         /**
  114.          * @param   string  $fileName
  115.          *
  116.          * @return object|BinaryFileResponse
  117.          *
  118.          * @throws Exception
  119.          */
  120.         public function exposeProjectFile(string $fileName)
  121.         {
  122.             $folder $this->platformService->getDomain().'/';
  123.             $path   $this->getParameter('kernel.project_dir').'/medias/'.$folder;
  124.             $file   $path.$fileName;
  125.             if (!file_exists($file)) {
  126.                 throw $this->createNotFoundException('La ressource n\'existe pas');
  127.             }
  128.             return new BinaryFileResponse($file200);
  129.         }
  130.         /**
  131.          * Route qui ne sert qu'à évaluer le temps nécessaire à fournir l'image
  132.          *
  133.          * @param   string  $fileName
  134.          *
  135.          * @return Response
  136.          *
  137.          * @throws Exception
  138.          */
  139.         public function exposeProjectFileBody(string $fileName): Response
  140.         {
  141.             $folder $this->platformService->getDomain().'/';
  142.             $path   $this->getParameter('kernel.project_dir').'/medias/'.$folder;
  143.             $file   $path.$fileName;
  144.             if (!file_exists($file)) {
  145.                 throw $this->createNotFoundException('La ressource n\'existe pas');
  146.             }
  147.             return new Response('<body>'.$file.'</body>');
  148.         }
  149.         /**
  150.          * @param   string  $file
  151.          * @param           $size
  152.          *
  153.          * @return BinaryFileResponse
  154.          */
  155.         public function getPicture(string $file$size): BinaryFileResponse
  156.         {
  157.             $src "http://bo.37deux.com/pictures/$size/$file";
  158.             $dir  $this->getParameter('kernel.project_dir')."/medias/$size";
  159.             $dest "$dir/$file";
  160.             if (!is_dir($dir)) {
  161.                 mkdir($dir0755);
  162.             }
  163.             if (!file_exists($dest)) {
  164.                 $data $this->get_content($src);
  165.                 file_put_contents($dest$data);
  166.             }
  167.             return new BinaryFileResponse($dest200);
  168.         }
  169.         /**
  170.          * @param   string  $URL
  171.          *
  172.          * @return bool|string
  173.          */
  174.         private function get_content(string $URL)
  175.         {
  176.             $ch curl_init();
  177.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  178.             curl_setopt($chCURLOPT_URL$URL);
  179.             $data curl_exec($ch);
  180.             curl_close($ch);
  181.             return $data;
  182.         }
  183.         /**
  184.          * @param   string  $slug
  185.          *
  186.          * @return Response
  187.          */
  188.         public function getDocument(string $slug): Response
  189.         {
  190.             $document $this->em->getRepository(Parameter::class)->findOneBy(
  191.                 [
  192.                     'slug' => $slug,
  193.                 ]
  194.             );
  195.             if (empty($document)) {
  196.                 throw $this->createNotFoundException("Ce document n'existe pas");
  197.             }
  198.             // on vérifie si le document est public
  199.             if (!$document->isPublic() && $this->getUser() === NULL) {
  200.                 $this->addFlash('info'"Vous n'avez pas le droit d'accéder à ce document");
  201.                 throw $this->createAccessDeniedException("Vous n'avez pas le droit de consulter ce document");
  202.             }
  203.             if ($document->getFileName() !== NULL) {
  204.                 return $this->redirectToRoute('static_file_folder', [
  205.                     'folder'   => $this->getParameter('app.path.general_documents'),
  206.                     'fileName' => $document->getFileName(),
  207.                 ]);
  208.             }
  209.             return $this->render($this->configService->getTemplateDependingDomain('front/common/document.html.twig'), [
  210.                 'document' => $document,
  211.             ]);
  212.         }
  213.         /**
  214.          * @TODO: check si toujours utilisée
  215.          *
  216.          * @param   string  $slug
  217.          *
  218.          * @return JsonResponse
  219.          */
  220.         public function getAjaxDocumentHtml(string $slug): JsonResponse
  221.         {
  222.             /** @var Parameter $document */
  223.             $document $this->em->getRepository(Parameter::class)->findOneBy(
  224.                 [
  225.                     'slug' => $slug,
  226.                 ]
  227.             );
  228.             if (!empty($document) && NULL !== $document->getValue()) {
  229.                 $html     $this->renderView('front/common/document-panel.html.twig', [
  230.                     'document' => $document,
  231.                 ]);
  232.                 $redirect FALSE;
  233.             } else {
  234.                 $html     '';
  235.                 $redirect TRUE;
  236.             }
  237.             return new JsonResponse(
  238.                 [
  239.                     'redirect' => $redirect,
  240.                     'html'     => $html,
  241.                     'title'    => $document->getTitle(),
  242.                 ]
  243.             );
  244.         }
  245.         /**
  246.          * @return Response
  247.          *
  248.          * @throws Exception
  249.          */
  250.         public function BddUp(): Response
  251.         {
  252.             $application = new Application($this->kernel);
  253.             $application->setAutoExit(FALSE);
  254.             $input = new ArrayInput(
  255.                 [
  256.                     'command' => 'dtv:bdd-update',
  257.                     // (optional) define the value of command arguments
  258.                     'project' => $this->yamlReader->getGlobal()[ 'subdomain' ],
  259.                 ]
  260.             );
  261.             // You can use NullOutput() if you don't need the output
  262.             $output = new BufferedOutput();
  263.             $application->run($input$output);
  264.             // return the output, don't use if you used NullOutput()
  265.             $content $output->fetch();
  266.             $content .= '<a href="/">retour au site</a>';
  267.             // return new Response(""), if you used NullOutput()
  268.             return new Response('<pre>'.$content.'</pre>');
  269.         }
  270.         /**
  271.          * @param   Request  $request
  272.          *
  273.          * @return Response
  274.          */
  275.         public function showUserStatusDaikin(Request $request): Response
  276.         {
  277.             /** @var User $currentUser */
  278.             $currentUser $this->getUser();
  279.             if (!$currentUser->isDeveloper() && !$currentUser->isSuperAdmin() && !$currentUser->isAdmin()) {
  280.                 return new Response('Page non trouvée'404);
  281.             }
  282.             $thisYear = (new DateTime())->format('Y') * 1;
  283.             $lastYear $thisYear 1;
  284.             $nextYear $thisYear 1;
  285.             $period   = new Period("$thisYear/01/01 00:00:00""$thisYear/12/31 23:59:59");
  286.             $newUser       $request->request->get('newUser'FALSE);
  287.             $pointThisYear $request->request->get('pointThisYear'0);
  288.             $pointLastYear $request->request->get('pointLastYear'0);
  289.             if ($pointLastYear >= 1000) {
  290.                 $levelLastYear 2;
  291.             } elseif ($pointLastYear >= 500) {
  292.                 $levelLastYear 1;
  293.             } else {
  294.                 $levelLastYear 0;
  295.             }
  296.             if ($pointThisYear >= 1000) {
  297.                 $levelThisYear 2;
  298.             } elseif ($pointThisYear >= 500) {
  299.                 $levelThisYear 1;
  300.             } else {
  301.                 $levelThisYear 0;
  302.             }
  303.             $data = [
  304.                 'thisYear'      => $thisYear,
  305.                 'lastYear'      => $lastYear,
  306.                 'nextYear'      => $nextYear,
  307.                 'period'        => $period,
  308.                 'pointThisYear' => $pointThisYear,
  309.                 'pointLastYear' => $pointLastYear,
  310.                 'newUser'       => $newUser,
  311.                 'levelLastYear' => $levelLastYear,
  312.                 'levelThisYear' => $levelThisYear,
  313.             ];
  314.             $data'data' ] = $this->userPointService->getUserStatusDaikinFormatted($data);
  315.             return $this->render('front/common/test-user-status.html.twig'$data);
  316.         }
  317.         /**
  318.          * @return Response
  319.          *
  320.          * @throws Exception
  321.          */
  322.         public function getUsersDaikin(): Response
  323.         {
  324.             /** @var User $currentUser */
  325.             $currentUser $this->getUser();
  326.             if (!$currentUser->isDeveloper()) {
  327.                 return new Response('Page non trouvée'404);
  328.             }
  329.             set_time_limit(0);
  330.             $users      $this->em->getRepository(User::class)->findAll();
  331.             $countUsers = [];
  332.             $response '<table>';
  333.             for ($year 2021$year <= 2022$year++) {
  334.                 for ($month 1$month <= 12$month++) {
  335.                     $fin date("Ymt"strtotime($year.'-'.$month.'-1'));
  336.                     $formattedDate = (new DateTime($year.'-'.$month.'-1'))->format('M Y');
  337.                     /**
  338.                      * @var      $index
  339.                      * @var User $user
  340.                      */
  341.                     foreach ($users as $user) {
  342.                         if (!$user->isInstaller()) {
  343.                             continue;
  344.                         }
  345.                         if ($user->getCguAt() == NULL) {
  346.                             continue;
  347.                         }
  348.                         if ($user->isDeleted()) {
  349.                             continue;
  350.                         }
  351.                         $created_at $user->getCreatedAt()->format('Ymd');
  352.                         if ($created_at $fin) {
  353.                             continue;
  354.                         }
  355.                         if ($user->getArchivedAt() != NULL) {
  356.                             $archived_at $user->getArchivedAt()->format('Ymd');
  357.                             if ($archived_at <= $fin) {
  358.                                 continue;
  359.                             }
  360.                         }
  361.                         $countUsers$formattedDate ][ 'total' ] = ($countUsers$formattedDate ][ 'total' ] ?? 0) + 1;
  362.                         if ( TRUE ) {
  363.                             $cgu_at $user->getCguAt()->format('Ymd');
  364.                             if ($cgu_at <= $fin) {
  365.                                 $purchases $this->em->getRepository(Purchase::class)
  366.                                                       ->getPurchaseUserAtDate($user->getId(), $fin)
  367.                                 ;if (!empty($purchases)) {
  368.                                     $countUsers$formattedDate ][ 'actif' ] = ($countUsers$formattedDate ][ 'actif' ] ?? 0) + 1;
  369.                                 }
  370.                             }
  371.                         } elseif ($user->isEnabled()) {
  372.                             $purchases $this->em->getRepository(Purchase::class)
  373.                                                   ->getPurchaseUserAtDate($user->getId(), $fin)
  374.                             ;
  375.                             if (!empty($purchases)) {
  376.                                 $countUsers$formattedDate ][ 'actif' ] = ($countUsers$formattedDate ][ 'actif' ] ?? 0) + 1;
  377.                             }
  378.                         }
  379.                     }
  380.                     $response .= '<tr>';
  381.                     $response .= '<td>'.$countUsers$formattedDate ][ 'total' ].'</td>';
  382.                     $response .= '<td>'.$countUsers$formattedDate ][ 'actif' ].'</td>';
  383.                     $response .= '</tr>';
  384.                 }
  385.             }
  386.             $response .= '</table>';
  387.             return new Response($response);
  388.         }
  389.         /**
  390.          * @param   Request  $request
  391.          *
  392.          * @return Response
  393.          *
  394.          * @throws PurchaseDeclarationException
  395.          */
  396.         public function getStatusAndPointsOfUser(Request $request): Response
  397.         {
  398.             /** @var User $currentUser */
  399.             $currentUser $this->getUser();
  400.             if (!$currentUser->isDeveloper()) {
  401.                 return new Response('Page non trouvée'404);
  402.             }
  403.             $id    $request->query->get('id''0');
  404.             $email $request->query->get('email''');
  405.             $force $request->query->get('force'TRUE);
  406.             $force strtolower($force) !== 'false';
  407.             $user  $this->em->getRepository(User::class)->find($id);
  408.             if (is_null($user)) {
  409.                 $user $this->em->getRepository(User::class)->findOneBy(
  410.                     [
  411.                         'email' => $email,
  412.                     ]
  413.                 );
  414.             }
  415.             if (is_null($user)) {
  416.                 return new Response('User '.$email.' not found !');
  417.             }
  418.             $period = new Period('2010-01-01''2023-01-01 00:00:00');
  419.             $userPoints $this->userPointService->getPointsOfUser($userNULL$force);
  420.             $newPoints  $this->userPointService->getAvailablePoints($user);
  421.             if (!is_null($request->get('update'))) {
  422.                 if ($newPoints 0) {
  423.                     $corrections $this->em->getRepository(PointTransaction::class)->findBy(
  424.                         [
  425.                             'label' => [
  426.                                 'Balance de points pour la nouvelle version du site',
  427.                                 'Balance de points période précédente',
  428.                                 'Balance de points après expiration',
  429.                             ],
  430.                             'user'  => $user,
  431.                         ]
  432.                     );
  433.                     if (!empty($corrections)) {
  434.                         foreach ($corrections as $correction) {
  435.                             $this->em->remove($correction);
  436.                         }
  437.                         $this->em->flush();
  438.                     }
  439.                     $userPoints $this->userPointService->getPointsOfUser($user$period$force);
  440.                     $newPoints  $userPoints'availablePoints' ];
  441.                     /** @var PointTransaction $firstPointTransaction */
  442.                     $firstPointTransaction $this->em->getRepository(PointTransaction::class)->findOneBy(
  443.                         [
  444.                             'user' => $user,
  445.                         ],
  446.                         [
  447.                             'createdAt' => 'ASC',
  448.                         ]
  449.                     );
  450.                     $date $firstPointTransaction->getCreatedAt()->modify('-1 day');
  451.                     $ptt $this->em->getRepository(PointTransactionType::class)->findOneBy(
  452.                         [
  453.                             'slug' => PointTransactionType::EXCEPTIONAL,
  454.                         ]
  455.                     );
  456.                     $newPt = (new PointTransaction())
  457.                         ->setCreatedAt($date)
  458.                         ->setUpdatedAt($date)
  459.                         ->setEffectiveAt($date)
  460.                         ->setUser($user)
  461.                         ->setValue(abs($newPoints))
  462.                         ->setLabel('Balance de points période précédente')
  463.                         ->setExpiredAt(NULL)
  464.                         ->setTransactionType($ptt)
  465.                     ;
  466.                     $this->em->persist($newPt);
  467.                     $this->em->flush();
  468.                     $userPoints $this->userPointService->getPointsOfUser($user$period$force);
  469.                     $newPoints  $userPoints'availablePoints' ];
  470.                     if ($newPoints 0) {
  471.                         $date  = new DateTime('2021-07-01 00:00:00');
  472.                         $newPt = (new PointTransaction())
  473.                             ->setCreatedAt($date)
  474.                             ->setUpdatedAt($date)
  475.                             ->setEffectiveAt($date)
  476.                             ->setUser($user)
  477.                             ->setValue(abs($newPoints))
  478.                             ->setLabel('Balance de points après expiration')
  479.                             ->setExpiredAt(NULL)
  480.                             ->setTransactionType($ptt)
  481.                         ;
  482.                         $this->em->persist($newPt);
  483.                         $this->em->flush();
  484.                         $userPoints $this->userPointService->getPointsOfUser($user$period$force);
  485.                         $newPoints  $userPoints'availablePoints' ];
  486.                         if ($newPoints 0) {
  487.                             return new Response('erreur : $newPoints < 0');
  488.                         }
  489.                     }
  490.                 }
  491.                 $userPoints $this->userPointService->getPointsOfUser($user$period$force);
  492.             }
  493.             $levels = [
  494.                 'Level le 01/01/20 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2019/01/01')),
  495.                 'Level le 31/12/20 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2019/12/31')),
  496.                 'Level le 01/01/21 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2020/01/01')),
  497.                 'Level le 01/04/21 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2020/12/31')),
  498.                 'Level le 01/01/22 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2021/01/01')),
  499.                 'Level le 01/02/22 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2021/12/31')),
  500.                 'Level le 01/04/22 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2022/01/01')),
  501.                 'Level le 01/06/22 : '.$this->userPointService->getLevelOneDate($user, new DateTime('2022/12/31')),
  502.             ];
  503.             $labelLevel = [
  504.                 => '',
  505.                 => 'vip',
  506.                 => 'ambassadeur',
  507.             ];
  508.             return $this->render('front/common/test-user-point-2.html.twig', [
  509.                 'rows'        => $userPoints,
  510.                 'user_labels' => $labelLevel,
  511.                 'user'        => $user,
  512.                 'levels'      => $levels,
  513.                 'version '    => $this->userPointService->getVersion(),
  514.             ]);
  515.         }
  516.         /**
  517.          * @return Response
  518.          */
  519.         public function getVersion(): Response
  520.         {
  521.             $maintenance $this->platformService->maintenanceMode();
  522.             $saleOrders $this->em->getRepository(SaleOrder::class)->findBy(
  523.                 [
  524.                     'status'              => \App\Constants\SaleOrder::ALL_PENDING_STATUS,
  525.                     'isManagedByCustomer' => FALSE,
  526.                 ]
  527.             );
  528.             if (count($saleOrders) > 0) {
  529.                 /** @var SaleOrder $saleOrder */
  530.                 foreach ($saleOrders as $index => $saleOrder) {
  531.                     if (count($saleOrder->getItems()) == 0) {
  532.                         unset($saleOrders$index ]);
  533.                     }
  534.                 }
  535.             }
  536.             return new JsonResponse(
  537.                 [
  538.                     'version'            => $this->yamlReader->getVersion(),
  539.                     'type'               => Platform::MODULES$this->yamlReader->getType() ] ?? 'N/C',
  540.                     'mailer'             => $this->yamlReader->getMailer()[ 'intercept_emails' ] ?? FALSE,
  541.                     'glady'              => $this->yamlReader->getGlady()[ 'enabled' ] ?? FALSE,
  542.                     'maintenance'        => $maintenance'enabled' ] ?? FALSE,
  543.                     'admin_confirmation' => $this->yamlReader->getCheckout()[ 'admin_confirmation' ][ 'enabled' ] ?? FALSE,
  544.                     'saleOrders'         => count($saleOrders),
  545.                 ]
  546.             );
  547.         }
  548.         /**
  549.          * @return Response
  550.          */
  551.         public function customerProductJson(): Response
  552.         {
  553.             /** @var User $currentUser */
  554.             $currentUser $this->getUser();
  555.             if (!$currentUser->isDeveloper()) {
  556.                 return new Response('Page non trouvée'404);
  557.             }
  558.             return new Response(
  559.                 '<html lang="fr"><body>'.$this->em->getRepository(CustomerProduct::class)
  560.                                                   ->getAllEnabledJson().'</body></html>'
  561.             );
  562.         }
  563.         /**
  564.          * Route pour tester l'envoi d'email
  565.          *
  566.          * @param   MailerService  $mailerService
  567.          *
  568.          * @return Response
  569.          * @throws ReflectionException
  570.          * @throws ClientExceptionInterface
  571.          * @throws RedirectionExceptionInterface
  572.          * @throws ServerExceptionInterface
  573.          * @throws TransportExceptionInterface
  574.          * @throws Exception
  575.          */
  576.         public function testEmail(MailerService $mailerService): Response
  577.         {
  578.             $currentUser $this->getUser();
  579.             if (!$currentUser->isDeveloper()) {
  580.                 return new Response('Page non trouvée'404);
  581.             }
  582.             $mailerService->createApiMailRequest(MailTypes::UPDATE_POINTS)
  583.                           ->addRecipientToRequest(
  584.                               $currentUser,
  585.                               MailerFactory::buildUpdatePoints(100)
  586.                           )
  587.                           ->send()
  588.             ;
  589.             return new Response("<html><body></body></html>");
  590.         }
  591.         /**
  592.          * Route pour tester la traduction
  593.          *
  594.          * @param   TranslatorInterface  $translator
  595.          *
  596.          * @return Response
  597.          * @throws Exception
  598.          */
  599.         public function testTranslation(TranslatorInterface $translator): Response
  600.         {
  601.             /** @var User $currentUser */
  602.             $currentUser $this->getUser();
  603.             if (!$currentUser->isDeveloper()) {
  604.                 return new Response('Page non trouvée'404);
  605.             }
  606.             // Calcul des performances
  607.             $stopwatch = new Stopwatch();
  608.             $stopwatch->start('first_translation');
  609.             $trad1  $translator->trans('bienvenue');
  610.             $event1 $stopwatch->stop('first_translation');
  611.             $stopwatch->start('second_translation');
  612.             $trad2  $translator->trans('mes informations');
  613.             $event2 $stopwatch->stop('second_translation');
  614.             $stopwatch->start('third_translation');
  615.             $trad3  $translator->trans('point.expire', ['count' => 2'date' => '01/01/2021''point' => 2]);
  616.             $event3 $stopwatch->stop('third_translation');
  617.             $results = [
  618.                 'bienvenue'                   => $event1->getDuration().' ms',
  619.                 'mes informations'            => $event2->getDuration().' ms',
  620.                 'point.expire'                => $event3->getDuration().' ms',
  621.                 'CGU'                         => $translator->trans("je donne mon consentement et j'accepte les cgu", [
  622.                     "path" => 'https://www.google.com/',
  623.                     "foo"  => 'bla',
  624.                 ]),
  625.                 'bienvenue dans votre espace' => $translator->trans("bienvenue dans votre espace", ["name" => 'Yop']),
  626.             ];
  627.             return $this->render('test/trans.html.twig');
  628.         }
  629.         /**
  630.          * @return Response
  631.          */
  632.         public function compareTwoYaml(): Response
  633.         {
  634.             /** @var User $currentUser */
  635.             $currentUser $this->getUser();
  636.             if (!$currentUser->isDeveloper()) {
  637.                 return new Response('Page non trouvée'404);
  638.             }
  639.             $url1  $this->getParameter('kernel.project_dir').'/config/platform.loc/animation-lpm.dtv.loc.yaml';
  640.             $url2  $this->getParameter('kernel.project_dir').'/config/platform.loc/lecercledaikin.dtv.loc.yaml';
  641.             $file1 Yaml::parseFile($url1);
  642.             $file2 Yaml::parseFile($url2);
  643.             $diff = [];
  644.             /**
  645.              * @param          $file1
  646.              * @param          $file2
  647.              * @param   array  $diff
  648.              * @param   int    $level
  649.              *
  650.              * @return mixed
  651.              */
  652.             function compare_keys_html($file1$file2, array $diffint $level 1)
  653.             {
  654.                 $keys_diff      array_diff_key($file1$file2);
  655.                 $keys_added     array_diff_key($file2$file1);
  656.                 $keys_identical array_intersect_key($file1$file2);
  657.                 if (!empty($keys_diff)) {
  658.                     foreach ($keys_diff as $key => $value) {
  659.                         if (is_array($value) && isset($file1$key ]) && isset($file2$key ])) {
  660.                             $diff[] = "<li style='color:red;'> $key: <ul>";
  661.                             $diff   compare_keys_html($file1$key ], $file2$key ], $diff$level 1);
  662.                             $diff[] = '</ul></li>';
  663.                         } else {
  664.                             $diff[] = "<li style='color:red;'> $key: ".json_encode($value)." </li>";
  665.                         }
  666.                     }
  667.                 }
  668.                 if (!empty($keys_added)) {
  669.                     foreach ($keys_added as $key => $value) {
  670.                         if (is_array($value) && isset($file1$key ]) && isset($file2$key ])) {
  671.                             $diff[] = "<li style='color:green;'> $key: <ul>";
  672.                             $diff   compare_keys_html($file1$key ], $file2$key ], $diff$level 1);
  673.                             $diff[] = '</ul></li>';
  674.                         } else {
  675.                             $diff[] = "<li style='color:green;'> $key:".json_encode($value)." </li>";
  676.                         }
  677.                     }
  678.                 }
  679.                 if (!empty($keys_identical)) {
  680.                     foreach ($keys_identical as $key => $value) {
  681.                         if (is_array($value) && isset($file1$key ]) && isset($file2$key ])) {
  682.                             $diff[] = "<li style='color:black;'> $key: <ul>";
  683.                             $diff   compare_keys_html($file1$key ], $file2$key ], $diff$level 1);
  684.                             $diff[] = '</ul></li>';
  685.                         } else {
  686.                             $diff[] = "<li style='color:black;'> $key: ".json_encode($value)." </li>";
  687.                         }
  688.                     }
  689.                 }
  690.                 return $diff;
  691.             }
  692.             $diff compare_keys_html($file1$file2$diff);
  693.             $response '';
  694.             if (!empty($diff)) {
  695.                 $response "<ul>".implode(''$diff)."</ul>";
  696.             }
  697.             return new Response($response);
  698.         }
  699.         /**
  700.          * @return Response
  701.          */
  702.         public function closedPlatform(): Response
  703.         {
  704.             return $this->redirectToRoute();
  705.             $messageCloturePlateform $this->em->getRepository(Setting::class)->findOneBy(['name' => 'CLOSE_SITE_MESSAGE']
  706.             );
  707.             $message $messageCloturePlateform->getValue();
  708.             return $this->render('common/closed/default.html.twig', [
  709.                 'closeSiteMessage' => $message,
  710.             ]);
  711.         }
  712.         /**
  713.          * Méthode qui permet de vérifier les prix des commandes et les corriger si besoin
  714.          *
  715.          * @return Response|void
  716.          *
  717.          * @throws CatalogueException
  718.          */
  719.         public function checkSaleOrderPrices()
  720.         {
  721.             /** @var User $currentUser */
  722.             $currentUser $this->getUser();
  723.             if (!$currentUser->isDeveloper()) {
  724.                 return new Response('Page non trouvée'404);
  725.             }
  726.             $global     $this->yamlReader->getGlobal();
  727.             $rate       $global'point' ][ 'rate' ];
  728.             $saleOrders $this->em->getRepository(SaleOrder::class)->findAll();
  729.             /** @var SaleOrder $saleOrder */
  730.             foreach ($saleOrders as $saleOrder) {
  731.                 echo '<br>'.($saleOrder->getTotal() / $rate).'<br>';
  732.                 $total 0;
  733.                 foreach ($saleOrder->getItems() as $item) {
  734.                     $sku     $item->getSku();
  735.                     $gamme   $item->getGamme();
  736.                     $product $this->jsonCatalogueService->getProductBySkuFromCatalogue($sku$gamme);
  737.                     if (!is_null($product)) {
  738.                         $price $product->getSalePrice();
  739.                         echo $saleOrder->getId().' --- '.$sku.' - '.$gamme.' '.$item->getName().' : '.$item->getPriceHT().' vs '.$price.'<br>';
  740.                         $item->setPriceHT($price);
  741.                         $total += $price $item->getQuantity();
  742.                     } else {
  743.                         echo $sku.' non présent dans le catalogue<br>';
  744.                     }
  745.                 }
  746.                 $saleOrder
  747.                     ->setTotal($total)
  748.                     ->setOrderRate($rate)
  749.                 ;
  750.             }
  751.             $this->em->flush();
  752.             die();
  753.         }
  754.         /**
  755.          * @return RedirectResponse|Response
  756.          *
  757.          * @throws NonUniqueResultException
  758.          */
  759.         public function purchaseProductToBooster()
  760.         {
  761.             $purchaseProducts $this->em->getRepository(PurchaseProduct::class)->findPurchaseProductsWithOldBoost();
  762.             $purchaseProductItems $this->em->getRepository(PurchaseProductItem::class)->findBy(
  763.                 [
  764.                     'purchase' => NULL,
  765.                 ]
  766.             );
  767.             if (count($purchaseProductItems) > 0) {
  768.                 foreach ($purchaseProductItems as $purchaseProductItem) {
  769.                     $this->em->remove($purchaseProductItem);
  770.                 }
  771.                 $this->em->flush();
  772.             }
  773.             $total             0;
  774.             $formattedProducts = [];
  775.             /** @var PurchaseProduct $purchaseProduct */
  776.             foreach ($purchaseProducts as $purchaseProduct) {
  777.                 $reference $name '';
  778.                 $referenceExplode explode(' Boost'$purchaseProduct->getReference());
  779.                 if (count($referenceExplode) > 1) {
  780.                     $reference $referenceExplode];
  781.                 }
  782.                 $nameExplode explode('- Booster'$purchaseProduct->getName());
  783.                 if (count($nameExplode) > 1) {
  784.                     $reference $purchaseProduct->getReference();
  785.                     $name      $nameExplodearray_key_last($nameExplode) ];
  786.                 }
  787.                 $nameExplode explode('Boost '$purchaseProduct->getName());
  788.                 if (count($nameExplode) > 1) {
  789.                     $reference $purchaseProduct->getReference();
  790.                     $name      $nameExplodearray_key_last($nameExplode) ];
  791.                 }
  792.                 switch ($name) {
  793.                     case 'DKN ALT 3 H HT_UExt   14kW 1ph':
  794.                         $name 'DKN ALTHERMA 3 H HT_UExt   14kW 1ph';
  795.                         break;
  796.                     case 'DKN ALT 3 H HT_UExt   16kW 1ph':
  797.                         $name 'DKN ALTHERMA 3 H HT_UExt   16kW 1ph';
  798.                         break;
  799.                     case 'DKN ALT 3 H HT_UExt   18kW 1ph':
  800.                         $name 'DKN ALTHERMA 3 H HT_UExt   18kW 1ph';
  801.                         break;
  802.                     case 'DKN ALT 3 H HT_UExt   14kW 3ph':
  803.                         $name 'DKN ALTHERMA 3 H HT_UExt   14kW 3ph';
  804.                         break;
  805.                     case 'DKN ALT 3 H HT_UExt   16kW 3ph':
  806.                         $name 'DKN ALTHERMA 3 H HT_UExt   16kW 3ph';
  807.                         break;
  808.                     case 'DKN ALT 3 H HT_UExt   18kW 3ph':
  809.                         $name 'DKN ALTHERMA 3 H HT_UExt   18kW 3ph';
  810.                         break;
  811.                 }
  812.                 /** @var PurchaseProduct $parent */
  813.                 $parent $this->em->getRepository(PurchaseProduct::class)->findOneBy(
  814.                     [
  815.                         'reference' => $reference,
  816.                         'name'      => $name,
  817.                     ]
  818.                 );
  819.                 if (!$parent instanceof PurchaseProduct) {
  820.                     $parentTpms $this->em->getRepository(PurchaseProduct::class)->findBy(
  821.                         [
  822.                             'reference' => $reference,
  823.                         ],
  824.                         [
  825.                             'value' => 'asc',
  826.                         ]
  827.                     );
  828.                     $parent $parentTpms];
  829.                 }
  830.                 $qb $this->em->createQueryBuilder()
  831.                                ->from(PurchaseProductItem::class, 'ppi')
  832.                                ->select('ppi')
  833.                                ->leftJoin('ppi.product''p')
  834.                                ->leftJoin('ppi.purchase''pu')
  835.                                ->andWhere('p.id = :pId')
  836.                                ->setParameter('pId'$purchaseProduct->getId())
  837.                                ->orderBy('pu.invoiceDate''ASC')
  838.                                ->setFirstResult(0)
  839.                                ->setMaxResults(1)
  840.                 ;
  841.                 $qb->orderBy('pu.invoiceDate''DESC');
  842.                 $qb->select('ppi.id')
  843.                    ->setMaxResults(NULL)
  844.                 ;
  845.                 $ids $qb->getQuery()->getArrayResult();
  846.                 if (count($ids) > 0) {
  847.                     $formattedProducts$parent->getId() ] = $ids;
  848.                     $total                                 += count($ids);
  849.                     if ($total 200) {
  850.                         break;
  851.                     }
  852.                 }
  853.             }
  854.             foreach ($formattedProducts as $ppiId => $ppiIDs) {
  855.                 $qb $this->em->createQueryBuilder();
  856.                 $qb->from(PurchaseProductItem::class, 'ppi')
  857.                    ->select('ppi')
  858.                    ->andWhere('ppi.id IN (:ppiIDs)')
  859.                    ->setParameter('ppiIDs'$ppiIDs)->setMaxResults(10)
  860.                 ;
  861.                 $ppis    $qb->getQuery()->getResult();
  862.                 $product $this->em->getRepository(PurchaseProduct::class)->find($ppiId);
  863.                 /** @var PurchaseProductItem $ppi */
  864.                 foreach ($ppis as $ppi) {
  865.                     $ppi->setProduct($product);
  866.                 }
  867.             }
  868.             if (count($formattedProducts) > 0) {
  869.                 $this->em->flush();
  870.                 return $this->redirectToRoute('test_purchase_products_to_booster');
  871.             }
  872.             /** @var PurchaseProduct $purchaseProduct */
  873.             foreach ($purchaseProducts as $purchaseProduct) {
  874.                 if (count(
  875.                         $this->em->getRepository(PurchaseProductItem::class)
  876.                                  ->findBy(['product' => $purchaseProduct])
  877.                     ) > 0) {
  878.                     return new Response(' PurchaseProductItem.length > 0');
  879.                 }
  880.                 $this->em->remove($purchaseProduct);
  881.             }
  882.             $this->em->flush();
  883.             return new Response(TRUE);
  884.         }
  885.         /**
  886.          * @return Response
  887.          *
  888.          * @throws ClientExceptionInterface
  889.          * @throws RedirectionExceptionInterface
  890.          * @throws ServerExceptionInterface
  891.          */
  892.         public function getSaleOrderItemFees(): Response
  893.         {
  894.             /** @var User $currentUser */
  895.             $currentUser $this->getUser();
  896.             if (!$currentUser->isDeveloper()) {
  897.                 return new Response('Page non trouvée'404);
  898.             }
  899.             return new Response("<html><body></body></html>");
  900.         }
  901.         /**
  902.          * @Route("/get-user-point-at/657sqd9f46q8sf4/{date}", name="getUserPointAt")
  903.          *
  904.          * @param      $date
  905.          *
  906.          * @return JsonResponse
  907.          *
  908.          * @throws PurchaseDeclarationException
  909.          * @throws Exception
  910.          */
  911.         public function getUserPointAt$date ): JsonResponse
  912.         {
  913.             $date   = new DateTime$date );
  914.             $period = new Period'2010-01-01 00:00:00'$date );
  915.             $users      $this->em->getRepositoryUser::class )->findAll();
  916.             $finalUsers = [];
  917.             /** @var User $user */
  918.             foreach ( $users as $user ) {
  919.                 if ( $user->isInstaller() ) {
  920.                     $finalUsers[] = [
  921.                         'email'  => $user->getEmail(),
  922.                         'id'     => $user->getId(),
  923.                         'points' => $this->userPointService->getAvailablePoints$user$period ),
  924.                         'level'  => $this->userPointService->getLevelOneDate$user$date ),
  925.                     ];
  926.                 }
  927.             }
  928.             return new JsonResponse(
  929.                 $finalUsers
  930.             );
  931.         }
  932.     }