src/Controller/Statistiques/StatistiqueController.php line 2521

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Statistiques;
  3. use App\Entity\Articles\RaisonMouvementStock;
  4. use App\Entity\Clients\Categorie;
  5. use App\Entity\FO\Societe;
  6. use App\Entity\GestionComerciale\Commande;
  7. use App\Service\Articles\ArticleService;
  8. use App\Service\Statistiques\StatsService;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Knp\Snappy\Pdf;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\Validator\Validator\ValidatorInterface;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  19. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  20. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  21. class StatistiqueController extends AbstractController
  22. {
  23.     /**
  24.      * @Route("/stats/articles/pdf", name="dtc_stats_articles_pdf")
  25.      */
  26.     public function statsArticlesPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  27.     {
  28.         $param        $request->query->all();
  29.         $repoCommande $em->getRepository(Commande::class);
  30.         $retour       $repoCommande->statArticles($param['param']);
  31.         $dateN1Debut \DateTime::createFromFormat('d/m/Y'$param['param']['date_debut']);
  32.         $dateN1Debut->setTime(000000);
  33.         $dateN1Debut->sub(new \DateInterval('P1Y'));
  34.         $dateN1Fin \DateTime::createFromFormat('d/m/Y'$param['param']['date_fin']);
  35.         $dateN1Fin->setTime(235959);
  36.         $dateN1Fin->sub(new \DateInterval('P1Y'));
  37.         $societe $em->getRepository(Societe::class)->find(1);
  38.         $chemin_pdf 'PDF/STATS/articles.pdf';
  39.         $dateDebut \DateTime::createFromFormat('d/m/Y'$param['param']['date_debut']);
  40.         $dateDebut->setTime(000000);
  41.         $dateFin \DateTime::createFromFormat('d/m/Y'$param['param']['date_fin']);
  42.         $dateFin->setTime(235959);
  43.         if (file_exists($chemin_pdf)) {
  44.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  45.             unlink($chemin_pdf);
  46.         }
  47.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  48.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  49.         $header "";
  50.         $snappy->setOption('orientation'"Landscape");
  51.         $snappy->setOption('header-html'$header);
  52.         $snappy->setOption('footer-html'$footer);
  53.         $snappy->setOption('margin-bottom'"10");
  54.         $categorie_enfants       = [];
  55.         $repo_categorie_client   $em->getRepository(Categorie::class);
  56.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  57.         if (array_key_exists('categorie_client'$param['param']) and $param['param']["categorie_client"] > 0) {
  58.             $parent $repo_categorie_client->find($param['param']["categorie_client"]);
  59.             if (is_object($parent)) {
  60.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  61.             }
  62.         }
  63.         $snappy->generateFromHtml(
  64.             $this->renderView(
  65.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  66.                 'Statistiques/Statistique/stats_articles_pdf.html.twig',
  67.                 [
  68.                     'societe'               => $societe,
  69.                     'parametres'            => $param['param'],
  70.                     'articles'              => $retour,
  71.                     "categorie_client"      => $categorie_client_racine,
  72.                     "sous_categorie_client" => $categorie_enfants,
  73.                     "dateN1Debut"           => $dateN1Debut,
  74.                     "dateN1Fin"             => $dateN1Fin,
  75.                     "dateDebut"             => $dateDebut,
  76.                     "dateFin"               => $dateFin,
  77.                 ]
  78.             ),
  79.             $chemin_pdf
  80.         );
  81.         if ($retour == true) {
  82.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  83.         }
  84.     }
  85.     /**
  86.      * @Route("/stats/articles", name="dtc_stats_articles")
  87.      */
  88.     public function statsArticlesAction(Request $requestEntityManagerInterface $em)
  89.     {
  90.         $dateN1Debut = new \DateTime();
  91.         $dateN1Fin   = new \DateTime();
  92.         $dateDebut = new \DateTime();
  93.         $dateFin   = new \DateTime();
  94.         $retour                  = ["articles" => []];
  95.         $categorie_enfants       = [];
  96.         $repo_categorie_client   $em->getRepository(Categorie::class);
  97.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  98.         $articles = [];
  99.         $param    $request->query->all();
  100.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  101.             //print_r($_GET);
  102.             $repoCommande $em->getRepository(Commande::class);
  103.             $retour       $repoCommande->statArticles($param);
  104.             $dateDebut \DateTime::createFromFormat('d/m/Y'$param['date_debut']);
  105.             $dateDebut->setTime(000000);
  106.             $dateN1Debut \DateTime::createFromFormat('d/m/Y'$param['date_debut']);
  107.             $dateN1Debut->setTime(000000);
  108.             $dateN1Debut->sub(new \DateInterval('P1Y'));
  109.             $dateFin \DateTime::createFromFormat('d/m/Y'$param['date_fin']);
  110.             $dateFin->setTime(235959);
  111.             $dateN1Fin \DateTime::createFromFormat('d/m/Y'$param['date_fin']);
  112.             $dateN1Fin->setTime(235959);
  113.             $dateN1Fin->sub(new \DateInterval('P1Y'));
  114.         }
  115.         if (array_key_exists('categorie_client'$param) and $param["categorie_client"] > 0) {
  116.             $parent $repo_categorie_client->find($param["categorie_client"]);
  117.             if (is_object($parent)) {
  118.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  119.             }
  120.         }
  121.         return $this->render('Statistiques/Statistique/stats_articles.html.twig', [
  122.             "articles"              => $articles,
  123.             'parametres'            => $param,
  124.             "categorie_client"      => $categorie_client_racine,
  125.             "sous_categorie_client" => $categorie_enfants,
  126.             "param"                 => $param,
  127.             'articles'              => $retour,
  128.             "dateN1Debut" => $dateN1Debut,
  129.             "dateN1Fin"   => $dateN1Fin,
  130.             "dateDebut"   => $dateDebut,
  131.             "dateFin"     => $dateFin,
  132.         ]);
  133.     }
  134.     /**
  135.      * @Route("/stats/articles/xls", name="dtc_stats_articles_xls")
  136.      */
  137.     public function statsArticlesXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $em)
  138.     {
  139.         $param        $request->query->all();
  140.         $repoCommande $em->getRepository(Commande::class);
  141.         $retour       $repoCommande->statArticles($param['param']);
  142.         $dateN1Debut \DateTime::createFromFormat('d/m/Y'$param['param']['date_debut']);
  143.         $dateN1Debut->setTime(000000);
  144.         $dateN1Debut->sub(new \DateInterval('P1Y'));
  145.         $dateN1Fin \DateTime::createFromFormat('d/m/Y'$param['param']['date_fin']);
  146.         $dateN1Fin->setTime(235959);
  147.         $dateN1Fin->sub(new \DateInterval('P1Y'));
  148.         $societe $em->getRepository(Societe::class)->find(1);
  149.         $spreadsheet = new Spreadsheet();
  150.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Réf');
  151.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Nom');
  152.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('C1''Total HT');
  153.         // Create your Office 2007 Excel (XLSX Format)
  154.         $writer = new Xlsx($spreadsheet);
  155.         // Create a Temporary file in the system
  156.         $fileName 'stat_articles.xlsx';
  157.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  158.         // Create the excel file in the tmp directory of the system
  159.         $writer->save($temp_file);
  160.         // Return the excel file as an attachment
  161.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  162.     }
  163.     /**
  164.      * @Route("/stats/hit/articles", name="dtc_top_articles")
  165.      */
  166.     public function topArticlesAction(Request $requestEntityManagerInterface $em)
  167.     {
  168.         $categorie_enfants       = [];
  169.         $repo_categorie_client   $em->getRepository(Categorie::class);
  170.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  171.         $articles = [];
  172.         $param    $request->query->all();
  173.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  174.             //print_r($_GET);
  175.             $repoCommande $em->getRepository(Commande::class);
  176.             $articles     $repoCommande->topArticles($param);
  177.         } else {
  178.             $dateN1Debut = new \DateTime();
  179.             $dateN1Debut->setTime(000000);
  180.             $dateN1Debut->sub(new \DateInterval('P1M'));
  181.             $dateN1Fin = new \DateTime();
  182.             $param               = [];
  183.             $param['date_debut'] = $dateN1Debut->format("d/m/Y");
  184.             $param['date_fin']   = $dateN1Fin->format("d/m/Y");
  185.             $param['nbel']       = 500;
  186.             $param['nbelgraphe'] = 10;
  187.             //print_r($param);
  188.             $repoCommande $em->getRepository(Commande::class);
  189.             $articles     $repoCommande->topArticles($param);
  190.         }
  191.         if (array_key_exists('categorie_client'$param) and $param["categorie_client"] > 0) {
  192.             $parent $repo_categorie_client->find($param["categorie_client"]);
  193.             if (is_object($parent)) {
  194.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  195.             }
  196.         }
  197.         return $this->render('Statistiques/Statistique/top_articles.html.twig', [
  198.             "articles"              => $articles,
  199.             'parametres'            => $param,
  200.             "categorie_client"      => $categorie_client_racine,
  201.             "sous_categorie_client" => $categorie_enfants,
  202.             "param"                 => $param,
  203.         ]);
  204.     }
  205.     /**
  206.      * @Route("/stats/hit/articles/xls", name="dtc_top_articles_xls")
  207.      */
  208.     public function topArticlesXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $emStatsService $statService)
  209.     {
  210.         $param        $request->query->all();
  211.         $repoCommande $em->getRepository(Commande::class);
  212.         $articles     $repoCommande->topArticles($param['param']);
  213.         $societe $em->getRepository(Societe::class)->find(1);
  214.          $spreadsheet = new Spreadsheet();
  215.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Réf');
  216.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Nom');
  217.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('C1''Qte');
  218.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('D1''Total HT');
  219.         $n1 "0";
  220.         if (array_key_exists('param'$param) && array_key_exists('n1'$param["param"]) and $param["param"]['n1'] == "1") {
  221.             $n1 "1";
  222.         }
  223.         if ($n1 == "1") {
  224.             $spreadsheet->setActiveSheetIndex(0)->setCellValue('E1''Qté n-1');
  225.             $spreadsheet->setActiveSheetIndex(0)->setCellValue('F1''Total HT n-1');
  226.         }
  227.         $row 2;
  228.         $col 0;
  229.         for ($i 0$i count($articles); $i++) {
  230.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  231.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['reference']));
  232.             $col++;
  233.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['libelle']));
  234.             $col++;
  235.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['total_quantite']));
  236.             $col++;
  237.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['total']));
  238.             $col++;
  239.             if ($n1 == "1") {
  240.                 /*
  241.                       {% set totalN1 = dtc_stats.getTopClientn1(parametres,c.client_id) %}
  242.                   */
  243.                 $totalN1 $statService->getTopArticlen1($param["param"], $articles[$i]['article_id']);
  244.                 //print_r($totalN1);
  245.                 //exit;
  246.                 $totalTemp $totalN1["total"];
  247.                 $qteTemp   $totalN1["total_quantite"];
  248.                 if ($totalTemp == "") {
  249.                     $totalTemp "0";
  250.                 }
  251.                 if ($qteTemp == "") {
  252.                     $qteTemp "0";
  253.                 }
  254.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$qteTemp);
  255.                 $col++;
  256.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalTemp);
  257.                 $col++;
  258.             }
  259.             $col 0;
  260.             $row++;
  261.         }
  262.         // Create your Office 2007 Excel (XLSX Format)
  263.         $writer = new Xlsx($spreadsheet);
  264.         // Create a Temporary file in the system
  265.         $fileName 'top_articles.xlsx';
  266.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  267.         // Create the excel file in the tmp directory of the system
  268.         $writer->save($temp_file);
  269.         // Return the excel file as an attachment
  270.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  271.     }
  272.     /**
  273.      * @Route("/stats/hit/articles/pdf", name="dtc_top_articles_pdf")
  274.      */
  275.     public function topArticlesPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  276.     {
  277.         $param        $request->query->all();
  278.         $repoCommande $em->getRepository(Commande::class);
  279.         $articles     $repoCommande->topArticles($param['param']);
  280.         $societe $em->getRepository(Societe::class)->find(1);
  281.         $chemin_pdf 'PDF/HIT/articles.pdf';
  282.         if (file_exists($chemin_pdf)) {
  283.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  284.             unlink($chemin_pdf);
  285.         }
  286.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  287.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  288.         $header "";
  289.         $snappy->setOption('header-html'$header);
  290.         $snappy->setOption('footer-html'$footer);
  291.         $snappy->setOption('margin-bottom'"10");
  292.         $categorie_enfants       = [];
  293.         $repo_categorie_client   $em->getRepository(Categorie::class);
  294.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  295.         if (array_key_exists('categorie_client'$param['param']) and $param['param']["categorie_client"] > 0) {
  296.             $parent $repo_categorie_client->find($param['param']["categorie_client"]);
  297.             if (is_object($parent)) {
  298.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  299.             }
  300.         }
  301.         $snappy->generateFromHtml(
  302.             $this->renderView(
  303.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  304.                 'Statistiques/Statistique/top_articles_pdf.html.twig',
  305.                 [
  306.                     'societe'               => $societe,
  307.                     'parametres'            => $param['param'],
  308.                     'articles'              => $articles,
  309.                     "categorie_client"      => $categorie_client_racine,
  310.                     "sous_categorie_client" => $categorie_enfants,
  311.                 ]
  312.             ),
  313.             $chemin_pdf
  314.         );
  315.         if ($retour == true) {
  316.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  317.         }
  318.     }
  319.     /**
  320.      * @Route("/stats/suivi-consommation", name="dtc_suivi_consommation")
  321.      */
  322.     public function suiviConsommationAction(Request $requestEntityManagerInterface $em)
  323.     {
  324.         $articles  = [];
  325.         $param     $request->query->all();
  326.         $moisDebut "";
  327.         $moisFin   "";
  328.         $valeurs   = ["articles" => """mois" => """total" => ""];
  329.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  330.             $repoCommande $em->getRepository(Commande::class);
  331.             $valeurs      $repoCommande->suiviConsommation($param);
  332.         } else {
  333.             $dateN1Debut = new \DateTime();
  334.             $dateN1Debut->setTime(000000);
  335.             //$dateN1Debut->sub(new \DateInterval('P1Y'));
  336.             $dateN1Debut->sub(new \DateInterval('P6M'));
  337.             $dateN1Fin             = new \DateTime();
  338.             $param                 = [];
  339.             $param['date_debut']   = $dateN1Debut->format("m/Y");
  340.             $param['date_fin']     = $dateN1Fin->format("m/Y");
  341.             $param['consommation'] = "vente";
  342.             $param['non_mouv']     = "0";
  343.             //$param['nbel']=500;
  344.             //$param['nbelgraphe']=10;
  345.             $repoCommande $em->getRepository(Commande::class);
  346.             $valeurs      $repoCommande->suiviConsommation($param);
  347.         }
  348.         //print_r($param);
  349.         return $this->render('Statistiques/Statistique/suivi_consommation.html.twig', [
  350.             "articles"   => $valeurs['articles'],
  351.             "mois"       => $valeurs['mois'],
  352.             "total"      => $valeurs['total'],
  353.             "parametres" => $param,
  354.         ]);
  355.     }
  356.     /**
  357.      * @Route("/stats/suivi-consommation/xls", name="dtc_suivi_consommation_xls")
  358.      */
  359.     public function suiviConsommationXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $em)
  360.     {
  361.         $param        $request->query->all();
  362.         $repoCommande $em->getRepository(Commande::class);
  363.         $valeurs      $repoCommande->suiviConsommation($param['param']);
  364.         $societe      $em->getRepository(Societe::class)->find(1);
  365.          $spreadsheet = new Spreadsheet();
  366.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Ref');
  367.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Libellé');
  368.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('C1''Qté totale');
  369.         $row 1;
  370.         $col 3;
  371.         for ($i 0$i count($valeurs['mois']); $i++) {
  372.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  373.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['mois'][$i]);
  374.             $col++;
  375.         }
  376.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Stock");
  377.         $col++;
  378.         $row 2;
  379.         $col 0;
  380.         for ($i 0$i count($valeurs['articles']); $i++) {
  381.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  382.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['articles'][$i]["reference"]);
  383.             $col++;
  384.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['articles'][$i]["libelle"]);
  385.             $col++;
  386.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['articles'][$i]["total"]);
  387.             $col++;
  388.             for ($z 0$z count($valeurs['articles'][$i]['valeurs']); $z++) {
  389.                 if ($valeurs['articles'][$i]['valeurs'][$z]['quantite'] == "") {
  390.                     $valeurs['articles'][$i]['valeurs'][$z]['quantite'] = 0;
  391.                 }
  392.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['articles'][$i]['valeurs'][$z]['quantite']);
  393.                 $col++;
  394.             }
  395.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['articles'][$i]["stock"]);
  396.             $row++;
  397.             $col 0;
  398.         }/*->setCellValue('B1', 'Libellé')
  399.            ->setCellValue('C1', 'Qtité')
  400.           */;
  401.         $boucle 2;
  402.         // Create your Office 2007 Excel (XLSX Format)
  403.         $writer = new Xlsx($spreadsheet);
  404.         // Create a Temporary file in the system
  405.         $fileName 'suivi_conso.xlsx';
  406.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  407.         // Create the excel file in the tmp directory of the system
  408.         $writer->save($temp_file);
  409.         // Return the excel file as an attachment
  410.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  411.     }
  412.     /**
  413.      * @Route("/stats/suivi-consommation/pdf", name="dtc_suivi_consommation_pdf")
  414.      */
  415.     public function suiviConsommationPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  416.     {
  417.         $param        $request->query->all();
  418.         $repoCommande $em->getRepository(Commande::class);
  419.         $valeurs      $repoCommande->suiviConsommation($param['param']);
  420.         $societe      $em->getRepository(Societe::class)->find(1);
  421.         $chemin_pdf 'PDF/SUIVI/suivi_consommation.pdf';
  422.         if (file_exists($chemin_pdf)) {
  423.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  424.             unlink($chemin_pdf);
  425.         }
  426.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  427.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  428.         $header "";
  429.         $snappy->setOption('header-html'$header);
  430.         $snappy->setOption('footer-html'$footer);
  431.         $snappy->setOption('margin-bottom'"10");
  432.         $snappy->setOption('orientation'"Landscape");
  433.         $snappy->generateFromHtml(
  434.             $this->renderView(
  435.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  436.                 'Statistiques/Statistique/suivi_consommation_pdf.html.twig',
  437.                 [
  438.                     'societe'    => $societe,
  439.                     "articles"   => $valeurs['articles'],
  440.                     "mois"       => $valeurs['mois'],
  441.                     "parametres" => $param['param'],
  442.                     "total"      => $valeurs['total'],
  443.                 ]
  444.             ),
  445.             $chemin_pdf
  446.         );
  447.         if ($retour == true) {
  448.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  449.         }
  450.     }
  451.     /**
  452.      * @Route("", name="")
  453.      */
  454.     public function topClientsDetailPdfAction(Request $request$parametres = [], EntityManagerInterface $em)
  455.     {
  456.         $get          $request->query->all();
  457.         $get          $parametres;
  458.         $repoCommande $em->getRepository(Commande::class);
  459.         $articles     $repoCommande->topClientsDetails($parametres);
  460.         return $this->render(
  461.             'Statistiques/Statistique/top_clients_detail.html.twig',
  462.             ["client_id" => $parametres["client"], "articles" => $articles"parametres" => $parametres]
  463.         );
  464.     }
  465.     /**
  466.      * @Route("", name="")
  467.      */
  468.     public function topClientsDetailAction(Request $requestEntityManagerInterface $em)
  469.     {
  470.         $get       $request->query->all();
  471.         $client_id trim($get["client"]);
  472.         $repoCommande $em->getRepository(Commande::class);
  473.         $articles     $repoCommande->topClientsDetails($get);
  474.         $rendu        $this->renderView(
  475.             'Statistiques/Statistique/top_clients_detail.html.twig',
  476.             ["client_id" => $get["client_id"], "articles" => $articles"parametres" => $get]
  477.         );
  478.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '']);
  479.     }
  480.     /**
  481.      * @Route("/stats/hit/clients", name="dtc_top_clients")
  482.      */
  483.     public function topClientsAction(Request $requestEntityManagerInterface $em)
  484.     {
  485.         $categorie_enfants       = [];
  486.         $repo_categorie_client   $em->getRepository(Categorie::class);
  487.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  488.         $clients = [];
  489.         $param   $request->query->all();
  490.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  491.             //print_r($_GET);
  492.             $repoCommande $em->getRepository(Commande::class);
  493.             $clients      $repoCommande->topClients($param);
  494.         } else {
  495.             $dateN1Debut = new \DateTime();
  496.             $dateN1Debut->setTime(000000);
  497.             $dateN1Debut->sub(new \DateInterval('P1M'));
  498.             $dateN1Fin = new \DateTime();
  499.             $param               = [];
  500.             $param['date_debut'] = $dateN1Debut->format("d/m/Y");
  501.             $param['date_fin']   = $dateN1Fin->format("d/m/Y");
  502.             $param['nbel']       = 500;
  503.             $param['nbelgraphe'] = 10;
  504.             //print_r($param);
  505.             $repoCommande $em->getRepository(Commande::class);
  506.             $clients      $repoCommande->topClients($param);
  507.         }
  508.         if (array_key_exists('categorie_client'$param) and $param["categorie_client"] > 0) {
  509.             $parent $repo_categorie_client->find($param["categorie_client"]);
  510.             if (is_object($parent)) {
  511.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  512.             }
  513.         }
  514.         return $this->render('Statistiques/Statistique/top_clients.html.twig', [
  515.             "clients"               => $clients,
  516.             'parametres'            => $param,
  517.             "categorie_client"      => $categorie_client_racine,
  518.             "sous_categorie_client" => $categorie_enfants,
  519.             "param"                 => $param,
  520.         ]);
  521.     }
  522.     /**
  523.      * @Route("/stats/hit/clients/xls", name="dtc_top_clients_xls")
  524.      */
  525.     public function topClientsXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $emStatsService $statService)
  526.     {
  527.         $param  $request->query->all();
  528.         $detail "0";
  529.         if (array_key_exists('detail'$param) and $param['detail'] == "1") {
  530.             $detail "1";
  531.         }
  532.         $n1 "0";
  533.         if (array_key_exists('param'$param) && array_key_exists('n1'$param["param"]) and $param["param"]['n1'] == "1") {
  534.             $n1 "1";
  535.         }
  536.         $repoCommande $em->getRepository(Commande::class);
  537.         $clients      $repoCommande->topClients($param['param']);
  538.         $societe $em->getRepository(Societe::class)->find(1);
  539.          $spreadsheet = new Spreadsheet();
  540.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Réf');
  541.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Nom');
  542.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('C1''Qté');
  543.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('D1''Factures');
  544.         if ($n1 == "1") {
  545.             $spreadsheet->setActiveSheetIndex(0)->setCellValue('E1''Qté n-1');
  546.             $spreadsheet->setActiveSheetIndex(0)->setCellValue('F1''Factures n-1');
  547.         }
  548.         //echo $param["n1"];
  549.         //$articleService = $this->container->get('dtc.article');
  550.         $row 2;
  551.         $col 0;
  552.         for ($i 0$i count($clients); $i++) {
  553.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  554.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($clients[$i]['reference']));
  555.             $col++;
  556.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($clients[$i]['prenom'])." ".trim($clients[$i]['nom']));
  557.             $col++;
  558.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($clients[$i]['qte']));
  559.             $col++;
  560.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($clients[$i]['total']));
  561.             $col++;
  562.             if ($n1 == "1") {
  563.                 /*
  564.                       {% set totalN1 = dtc_stats.getTopClientn1(parametres,c.client_id) %}
  565.                   */
  566.                 $totalN1 $statService->getTopClientn1($param["param"], $clients[$i]['client_id']);
  567.                 $totalTemp $totalN1["total"];
  568.                 $qteTemp   $totalN1["qte"];
  569.                 if ($totalTemp == "") {
  570.                     $totalTemp "0";
  571.                 }
  572.                 if ($qteTemp == "") {
  573.                     $qteTemp "0";
  574.                 }
  575.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$qteTemp);
  576.                 $col++;
  577.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalTemp);
  578.                 $col++;
  579.             }
  580.             if ($detail == 1) {
  581.                 $row++;
  582.                 $col                        0;
  583.                 $param_details              $param['param'];
  584.                 $param_details["client"]    = $clients[$i]['client_id'];
  585.                 $param_details["client_id"] = $clients[$i]['client_id'];
  586.                 $articles $repoCommande->topClientsDetails($param_details);
  587.                 if (count($articles) > 0) {
  588.                     for ($f 0$f count($articles); $f++) {
  589.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"");
  590.                         $col++;
  591.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$f]["reference"]." ".$articles[$f]["libelle"]);
  592.                         $col++;
  593.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$f]["total_qte"]));
  594.                         $col++;
  595.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$f]["total"]));
  596.                         $col++;
  597.                         if ($n1 == "1") {
  598.                             $tabDetailsN1              $param["param"];
  599.                             $tabDetailsN1["client"]    = $clients[$i]['client_id'];
  600.                             $tabDetailsN1["client_id"] = $clients[$i]['client_id'];
  601.                             $transporteur_id "";
  602.                             if (array_key_exists('transporteur_id'$articles[$f]) and $articles[$f]['transporteur_id'] != "") {
  603.                                 $transporteur_id $articles[$f]['transporteur_id'];
  604.                             }
  605.                             $totalN1 $statService->getTopClientn1Details($tabDetailsN1$articles[$f]['article_id'], $transporteur_id);
  606.                             $totalTemp $totalN1["total"];
  607.                             $qteTemp   $totalN1["total_qte"];
  608.                             if ($totalTemp == "") {
  609.                                 $totalTemp "0";
  610.                             }
  611.                             if ($qteTemp == "") {
  612.                                 $qteTemp "0";
  613.                             }
  614.                             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$qteTemp);
  615.                             $col++;
  616.                             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalTemp);
  617.                             $col++;
  618.                             /*
  619.                                 {% set totalN1 = dtc_stats.getTopClientn1Details(parametres,a.article_id) %}
  620.                                 <td style="text-align:right;">{{totalN1.total_qte|number_format(2, '.', '&nbsp;')|replace({".00" : ""})|raw}}</td>
  621.                                 <td style="text-align:right;">{{totalN1.total|number_format(2, '.', '&nbsp;')|replace({".00" : ""})|raw}}</td>
  622.                             */
  623.                         }
  624.                         $col 0;
  625.                         $row++;
  626.                     }
  627.                 }
  628.             }
  629.             $col 0;
  630.             $row++;
  631.         }
  632.         // Create your Office 2007 Excel (XLSX Format)
  633.         $writer = new Xlsx($spreadsheet);
  634.         // Create a Temporary file in the system
  635.         $fileName 'top_clients.xlsx';
  636.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  637.         // Create the excel file in the tmp directory of the system
  638.         $writer->save($temp_file);
  639.         // Return the excel file as an attachment
  640.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  641.     }
  642.     /**
  643.      * @Route("/stats/hit/clients/pdf", name="dtc_top_clients_pdf")
  644.      */
  645.     public function topClientsPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  646.     {
  647.         $param        $request->query->all();
  648.         $repoCommande $em->getRepository(Commande::class);
  649.         $clients      $repoCommande->topClients($param['param']);
  650.         $get    $request->query->all();
  651.         $detail "0";
  652.         if (array_key_exists('detail'$get) and $get['detail'] == "1") {
  653.             $detail "1";
  654.         }
  655.         $societe $em->getRepository(Societe::class)->find(1);
  656.         $chemin_pdf 'PDF/HIT/client.pdf';
  657.         if (file_exists($chemin_pdf)) {
  658.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  659.             unlink($chemin_pdf);
  660.         }
  661.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  662.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  663.         $header "";
  664.         $snappy->setOption('header-html'$header);
  665.         $snappy->setOption('footer-html'$footer);
  666.         $snappy->setOption('margin-bottom'"10");
  667.         $categorie_enfants       = [];
  668.         $repo_categorie_client   $em->getRepository(Categorie::class);
  669.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  670.         if (array_key_exists('categorie_client'$param['param']) and $param['param']["categorie_client"] > 0) {
  671.             $parent $repo_categorie_client->find($param['param']["categorie_client"]);
  672.             if (is_object($parent)) {
  673.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  674.             }
  675.         }
  676.         $snappy->generateFromHtml(
  677.             $this->renderView(
  678.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  679.                 'Statistiques/Statistique/top_clients_pdf.html.twig',
  680.                 [
  681.                     'detail'                => $detail,
  682.                     'societe'               => $societe,
  683.                     'parametres'            => $param['param'],
  684.                     'clients'               => $clients,
  685.                     "categorie_client"      => $categorie_client_racine,
  686.                     "sous_categorie_client" => $categorie_enfants,
  687.                 ]
  688.             ),
  689.             $chemin_pdf
  690.         );
  691.         if ($retour == true) {
  692.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  693.         }
  694.     }
  695.     /**
  696.      * @Route("/statistiques", name="dtc_statistiques")
  697.      */
  698.     public function indexAction(Request $request)
  699.     {
  700.         return $this->render('Statistiques/Statistique/index.html.twig', []);
  701.     }
  702.     /**
  703.      * @Route("/stats/port/suivi-consommation", name="dtc_suivi_consommation_frais_port")
  704.      */
  705.     public function suiviConsommationPortAction(Request $requestEntityManagerInterface $em)
  706.     {
  707.         $articles  = [];
  708.         $param     $request->query->all();
  709.         $moisDebut "";
  710.         $moisFin   "";
  711.         $valeurs   = ["articles" => """mois" => """total" => ""];
  712.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  713.             $repoCommande $em->getRepository(Commande::class);
  714.             $valeurs      $repoCommande->suiviConsommationPort($param);
  715.         } else {
  716.             $dateN1Debut = new \DateTime();
  717.             $dateN1Debut->setTime(000000);
  718.             $dateN1Debut->sub(new \DateInterval('P1Y'));
  719.             $dateN1Fin           = new \DateTime();
  720.             $param               = [];
  721.             $param['date_debut'] = $dateN1Debut->format("m/Y");
  722.             $param['date_fin']   = $dateN1Fin->format("m/Y");
  723.             //$param['nbel']=500;
  724.             //$param['nbelgraphe']=10;
  725.             $repoCommande $em->getRepository(Commande::class);
  726.             $valeurs      $repoCommande->suiviConsommationPort($param);
  727.         }
  728.         //print_r($param);
  729.         return $this->render('Statistiques/Statistique/suivi_consommation_frais_port.html.twig', [
  730.             "transporteurs" => $valeurs['transporteurs'],
  731.             "mois"          => $valeurs['mois'],
  732.             "total"         => $valeurs['total'],
  733.             "parametres"    => $param,
  734.         ]);
  735.     }
  736.     /**
  737.      * @Route("/stats/port/suivi-consommation/xls", name="dtc_suivi_consommation_frais_port_xls")
  738.      */
  739.     public function suiviConsommationPortXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $em)
  740.     {
  741.         $param        $request->query->all();
  742.         $repoCommande $em->getRepository(Commande::class);
  743.         $valeurs      $repoCommande->suiviConsommationPort($param['param']);
  744.         $societe      $em->getRepository(Societe::class)->find(1);
  745.          $spreadsheet = new Spreadsheet();
  746.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Transporteur');
  747.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Total');
  748.         $row 1;
  749.         $col 2;
  750.         for ($i 0$i count($valeurs['mois']); $i++) {
  751.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  752.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['mois'][$i]);
  753.             $col++;
  754.         }
  755.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total");
  756.         $col++;
  757.         $row 2;
  758.         $col 0;
  759.         for ($i 0$i count($valeurs['transporteurs']); $i++) {
  760.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  761.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['transporteurs'][$i]["libelle"]);
  762.             $col++;
  763.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['transporteurs'][$i]["total"]." (".$valeurs['transporteurs'][$i]["expedition"].")");
  764.             $col++;
  765.             for ($z 0$z count($valeurs['transporteurs'][$i]['valeurs']); $z++) {
  766.                 if ($valeurs['transporteurs'][$i]['valeurs'][$z]['quantite'] == "") {
  767.                     $valeurs['transporteurs'][$i]['valeurs'][$z]['quantite'] = 0;
  768.                 }
  769.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow(
  770.                     $col,
  771.                     $row,
  772.                     $valeurs['transporteurs'][$i]['valeurs'][$z]['quantite']." (".$valeurs['transporteurs'][$i]['valeurs'][$z]['expedition'].")"
  773.                 );
  774.                 $col++;
  775.             }
  776.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['transporteurs'][$i]["total"]." (".$valeurs['transporteurs'][$i]["expedition"].")");
  777.             $row++;
  778.             $col 0;
  779.         }
  780.         $col 0;
  781.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total");
  782.         $col++;
  783.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['total']["valeur"]."(".$valeurs['total']["expedition"].")");
  784.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['total']["valeur"]."(".$valeurs['total']["expedition"].")");
  785.         $col++;
  786.         //print_r($valeurs['total']['totalMois']);
  787.         foreach ($valeurs['total']['totalMois'] as $cle => $valeur) {
  788.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeur."(".$valeurs['total']['expeditionMois'][$cle].")");
  789.             $col++;
  790.         }
  791.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$valeurs['total']["valeur"]."(".$valeurs['total']["expedition"].")");
  792.         // Create your Office 2007 Excel (XLSX Format)
  793.         $writer = new Xlsx($spreadsheet);
  794.         // Create a Temporary file in the system
  795.         $fileName 'suivi_conso_port.xlsx';
  796.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  797.         // Create the excel file in the tmp directory of the system
  798.         $writer->save($temp_file);
  799.         // Return the excel file as an attachment
  800.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  801.     }
  802.     /**
  803.      * @Route("/stats/port/suivi-consommation/pdf", name="dtc_suivi_consommation_frais_port_pdf")
  804.      */
  805.     public function suiviConsommationPortPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  806.     {
  807.         $param        $request->query->all();
  808.         $repoCommande $em->getRepository(Commande::class);
  809.         $valeurs      $repoCommande->suiviConsommationPort($param['param']);
  810.         $societe      $em->getRepository(Societe::class)->find(1);
  811.         $chemin_pdf 'PDF/SUIVI/suivi_consommation_frais_port.pdf';
  812.         if (file_exists($chemin_pdf)) {
  813.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  814.             unlink($chemin_pdf);
  815.         }
  816.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  817.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  818.         $header "";
  819.         $snappy->setOption('header-html'$header);
  820.         $snappy->setOption('footer-html'$footer);
  821.         $snappy->setOption('margin-bottom'"10");
  822.         $snappy->setOption('orientation'"Landscape");
  823.         $snappy->generateFromHtml(
  824.             $this->renderView(
  825.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  826.                 'Statistiques/Statistique/suivi_consommation_frais_port_pdf.html.twig',
  827.                 [
  828.                     'societe'       => $societe,
  829.                     "transporteurs" => $valeurs['transporteurs'],
  830.                     "mois"          => $valeurs['mois'],
  831.                     "parametres"    => $param['param'],
  832.                     "total"         => $valeurs['total'],
  833.                 ]
  834.             ),
  835.             $chemin_pdf
  836.         );
  837.         if ($retour == true) {
  838.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  839.         }
  840.     }
  841.     /**
  842.      * @Route("", name="")
  843.      */
  844.     public function _suiviConsommationPortPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  845.     {
  846.         $param        $request->query->all();
  847.         $repoCommande $em->getRepository(Commande::class);
  848.         $valeurs      $repoCommande->suiviConsommation($param['param']);
  849.         $societe      $em->getRepository(Societe::class)->find(1);
  850.         //echo "AAA";
  851.         $param        $request->query->all();
  852.         $repoCommande $em->getRepository(Commande::class);
  853.         $valeurs      $repoCommande->suiviConsommationPort($param['param']);
  854.         $societe      $em->getRepository(Societe::class)->find(1);
  855.         $chemin_pdf 'PDF/SUIVI/suivi_consommation_frais_port.pdf';
  856.         print_r($param);
  857.         if (file_exists($chemin_pdf)) {
  858.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  859.             unlink($chemin_pdf);
  860.         }
  861.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  862.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  863.         $header "";
  864.         $snappy->setOption('header-html'$header);
  865.         $snappy->setOption('footer-html'$footer);
  866.         $snappy->setOption('margin-bottom'"10");
  867.         $snappy->setOption('orientation'"Landscape");
  868.         $snappy->generateFromHtml(
  869.             $this->renderView(
  870.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  871.                 'Statistiques/Statistique/suivi_consommation_frais_port_pdf.html.twig',
  872.                 [
  873.                     'societe'       => $societe,
  874.                     "transporteurs" => $valeurs['transporteurs'],
  875.                     "mois"          => $valeurs['mois'],
  876.                     "total"         => $valeurs['total'],
  877.                     "parametres"    => $param,
  878.                 ]
  879.             ),
  880.             $chemin_pdf
  881.         );
  882.         if ($retour == true) {
  883.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  884.         }
  885.     }
  886.     /**
  887.      * @Route("/stats/mouvementes/articles/xls", name="dtc_vivant_articles_xls")
  888.      */
  889.     public function vivantArticlesXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $em)
  890.     {
  891.         $param        $request->query->all();
  892.         $repoCommande $em->getRepository(Commande::class);
  893.         $articles     $repoCommande->vivantArticles($param['param']);
  894.         $societe $em->getRepository(Societe::class)->find(1);
  895.          $spreadsheet = new Spreadsheet();
  896.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Réf');
  897.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Libellé');
  898.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('C1''Date');
  899.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('D1''Qté');
  900.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('E1''Raison');
  901.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('F1''Equipier');
  902.         //$spreadsheet->setActiveSheetIndex(0)->setCellValue('C1', 'Catégorie');
  903.         //$spreadsheet->setActiveSheetIndex(0)->setCellValue('D1', 'Dern. Entrée');
  904.         //$spreadsheet->setActiveSheetIndex(0)->setCellValue('E1', 'Dern. Sortie');
  905.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('G1''Stock');
  906.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('H1''Cump');
  907.         $row 2;
  908.         $col 0;
  909.         for ($i 0$i count($articles); $i++) {
  910.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['reference']));
  911.             $col++;
  912.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['libelle']));
  913.             $col++;
  914.             $date_mouvement = new \Datetime($articles[$i]['date_mouvement']);
  915.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$date_mouvement->format("d/m/Y H:i:s"));
  916.             $col++;
  917.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$i]['quantite']);
  918.             $col++;
  919.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$i]['raison_libelle']);
  920.             $col++;
  921.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$i]['utilisateur_libelle']);
  922.             $col++;
  923.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$i]['stock']);
  924.             $col++;
  925.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowround($articles[$i]['pump'], 2));
  926.             $col++;
  927.             $col 0;
  928.             $row++;
  929.         }
  930.         // Create your Office 2007 Excel (XLSX Format)
  931.         $writer = new Xlsx($spreadsheet);
  932.         // Create a Temporary file in the system
  933.         $fileName 'mort_articles.xlsx';
  934.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  935.         // Create the excel file in the tmp directory of the system
  936.         $writer->save($temp_file);
  937.         // Return the excel file as an attachment
  938.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  939.     }
  940.     /**
  941.      * @Route("/stats/non-mouvementes/articles/xls", name="dtc_mort_articles_xls")
  942.      */
  943.     public function mortArticlesXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $emArticleService $articleService)
  944.     {
  945.         $param        $request->query->all();
  946.         $repoCommande $em->getRepository(Commande::class);
  947.         $articles     $repoCommande->mortArticles($param['param']);
  948.         $societe $em->getRepository(Societe::class)->find(1);
  949.          $spreadsheet = new Spreadsheet();
  950.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Réf');
  951.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Libellé');
  952.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('C1''Catégorie');
  953.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('D1''Dern. Entrée');
  954.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('E1''Dern. Sortie');
  955.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('F1''Stock');
  956.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('G1''Cump');
  957.         $row 2;
  958.         $col 0;
  959.         for ($i 0$i count($articles); $i++) {
  960.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  961.             $dernier_entree      $articleService->derniereEntreeStock($articles[$i]['article_id'], []);
  962.             $date_dernier_entree = new \DateTime($dernier_entree["dernier"]);
  963.             $dernier_sortie      $articleService->derniereSortieStock($articles[$i]['article_id'], []);
  964.             $date_dernier_sortie = new \DateTime($dernier_sortie["dernier"]);
  965.             $categories       $articleService->getCategorieNiveauUn($articles[$i]['article_id']);
  966.             $string_categorie "";
  967.             if (count($categories) > 0) {
  968.                 foreach ($categories as $c) {
  969.                     $string_categorie .= $c["libelle"]." ";
  970.                 }
  971.             }
  972.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['reference']));
  973.             $col++;
  974.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$i]['libelle']));
  975.             $col++;
  976.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$string_categorie);
  977.             $col++;
  978.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$date_dernier_entree->format("d/m/Y"));
  979.             $col++;
  980.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$date_dernier_sortie->format("d/m/Y"));
  981.             $col++;
  982.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$i]['stock']);
  983.             $col++;
  984.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$i]['cpump']);
  985.             $col++;
  986.             $col 0;
  987.             $row++;
  988.         }
  989.         // Create your Office 2007 Excel (XLSX Format)
  990.         $writer = new Xlsx($spreadsheet);
  991.         // Create a Temporary file in the system
  992.         $fileName 'mort_articles.xlsx';
  993.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  994.         // Create the excel file in the tmp directory of the system
  995.         $writer->save($temp_file);
  996.         // Return the excel file as an attachment
  997.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  998.     }
  999.     /**
  1000.      * @Route("/stats/non-mouvementes/articles/pdf", name="dtc_mort_articles_pdf")
  1001.      */
  1002.     public function mortArticlesPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  1003.     {
  1004.         $param        $request->query->all();
  1005.         $repoCommande $em->getRepository(Commande::class);
  1006.         $articles     $repoCommande->mortArticles($param['param']);
  1007.         $societe $em->getRepository(Societe::class)->find(1);
  1008.         $chemin_pdf 'PDF/MORT/articles.pdf';
  1009.         if (file_exists($chemin_pdf)) {
  1010.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  1011.             unlink($chemin_pdf);
  1012.         }
  1013.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  1014.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  1015.         $header "";
  1016.         $snappy->setOption('header-html'$header);
  1017.         $snappy->setOption('footer-html'$footer);
  1018.         $snappy->setOption('margin-bottom'"10");
  1019.         $repo_raison_mvmt $em->getRepository(RaisonMouvementStock::class);
  1020.         $raisons_mvmt     $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
  1021.         $snappy->generateFromHtml(
  1022.             $this->renderView(
  1023.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  1024.                 'Statistiques/Statistique/mort_articles_pdf.html.twig',
  1025.                 [
  1026.                     'societe'      => $societe,
  1027.                     'parametres'   => $param['param'],
  1028.                     'articles'     => $articles,
  1029.                     'raisons_mvmt' => $raisons_mvmt,
  1030.                 ]
  1031.             ),
  1032.             $chemin_pdf
  1033.         );
  1034.         if ($retour == true) {
  1035.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  1036.         }
  1037.     }
  1038.     /**
  1039.      * @Route("/stats/mouvementes/articles/pdf", name="dtc_vivant_articles_pdf")
  1040.      */
  1041.     public function vivantArticlesPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  1042.     {
  1043.         $param        $request->query->all();
  1044.         $repoCommande $em->getRepository(Commande::class);
  1045.         $articles     $repoCommande->vivantArticles($param['param']);
  1046.         $societe $em->getRepository(Societe::class)->find(1);
  1047.         $chemin_pdf 'PDF/VIVANT/articles.pdf';
  1048.         if (file_exists($chemin_pdf)) {
  1049.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  1050.             unlink($chemin_pdf);
  1051.         }
  1052.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  1053.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  1054.         $header "";
  1055.         $snappy->setOption('header-html'$header);
  1056.         $snappy->setOption('footer-html'$footer);
  1057.         $snappy->setOption('margin-bottom'"10");
  1058.         $repo_raison_mvmt $em->getRepository(RaisonMouvementStock::class);
  1059.         $raisons_mvmt     $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
  1060.         $snappy->generateFromHtml(
  1061.             $this->renderView(
  1062.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  1063.                 'Statistiques/Statistique/vivant_articles_pdf.html.twig',
  1064.                 [
  1065.                     'societe'      => $societe,
  1066.                     'parametres'   => $param['param'],
  1067.                     'articles'     => $articles,
  1068.                     'raisons_mvmt' => $raisons_mvmt,
  1069.                 ]
  1070.             ),
  1071.             $chemin_pdf
  1072.         );
  1073.         if ($retour == true) {
  1074.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  1075.         }
  1076.     }
  1077.     /**
  1078.      * @Route("/stats/mouvementes/articles", name="dtc_vivant_articles")
  1079.      */
  1080.     public function vivantArticlesAction(Request $requestEntityManagerInterface $em)
  1081.     {
  1082.         $categorie_enfants     = [];
  1083.         $repo_categorie_client $em->getRepository(Categorie::class);
  1084.         $repo_raison_mvmt $em->getRepository(RaisonMouvementStock::class);
  1085.         $raisons_mvmt     $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
  1086.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  1087.         $articles = [];
  1088.         $param    $request->query->all();
  1089.         //print_r($param);
  1090.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  1091.             //print_r($_GET);
  1092.             $repoCommande $em->getRepository(Commande::class);
  1093.             $articles     $repoCommande->vivantArticles($param);
  1094.         } else {
  1095.             $dateN1Debut = new \DateTime();
  1096.             $dateN1Debut->setTime(000000);
  1097.             $dateN1Debut->sub(new \DateInterval('P1M'));
  1098.             $dateN1Fin = new \DateTime();
  1099.             $param               = [];
  1100.             $param['date_debut'] = $dateN1Debut->format("d/m/Y");
  1101.             $param['date_fin']   = $dateN1Fin->format("d/m/Y");
  1102.             $param['nbel']       = -1;
  1103.             $param['nbelgraphe'] = 10;
  1104.             //print_r($param);
  1105.             if (count($raisons_mvmt) > 0) {
  1106.                 foreach ($raisons_mvmt as $rm) {
  1107.                     if (
  1108.                         $rm->getId() != 1
  1109.                         &&
  1110.                         $rm->getId() != 3
  1111.                         &&
  1112.                         $rm->getId() != 15
  1113.                         &&
  1114.                         $rm->getId() != 8
  1115.                         &&
  1116.                         $rm->getId() != 10
  1117.                         &&
  1118.                         $rm->getId() != 18
  1119.                     ) {
  1120.                         $param["origine_".$rm->getId()] = $rm->getId();
  1121.                     }
  1122.                 }
  1123.             }
  1124.             $repoCommande $em->getRepository(Commande::class);
  1125.             //$articles =  $repoCommande->mortArticles($param);
  1126.             $articles = [];
  1127.         }
  1128.         if (array_key_exists('categorie_client'$param) and $param["categorie_client"] > 0) {
  1129.             $parent $repo_categorie_client->find($param["categorie_client"]);
  1130.             if (is_object($parent)) {
  1131.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  1132.             }
  1133.         }
  1134.         return $this->render('Statistiques/Statistique/vivant_articles.html.twig', [
  1135.             "articles"              => $articles,
  1136.             'parametres'            => $param,
  1137.             'raisons_mvmt'          => $raisons_mvmt,
  1138.             "categorie_client"      => $categorie_client_racine,
  1139.             "sous_categorie_client" => $categorie_enfants,
  1140.             "param"                 => $param,
  1141.         ]);
  1142.     }
  1143.     /**
  1144.      * @Route("/stats/non-mouvementes/articles", name="dtc_mort_articles")
  1145.      */
  1146.     public function mortArticlesAction(Request $requestEntityManagerInterface $em)
  1147.     {
  1148.         $categorie_enfants     = [];
  1149.         $repo_categorie_client $em->getRepository(Categorie::class);
  1150.         $repo_raison_mvmt $em->getRepository(RaisonMouvementStock::class);
  1151.         $raisons_mvmt     $repo_raison_mvmt->findBy([], ['libelle' => 'ASC']);
  1152.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  1153.         $articles = [];
  1154.         $param    $request->query->all();
  1155.         //print_r($param);
  1156.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  1157.             //print_r($_GET);
  1158.             $repoCommande $em->getRepository(Commande::class);
  1159.             $articles     $repoCommande->mortArticles($param);
  1160.         } else {
  1161.             $dateN1Debut = new \DateTime();
  1162.             $dateN1Debut->setTime(000000);
  1163.             $dateN1Debut->sub(new \DateInterval('P1Y'));
  1164.             $dateN1Fin = new \DateTime();
  1165.             $param               = [];
  1166.             $param['date_debut'] = $dateN1Debut->format("d/m/Y");
  1167.             $param['date_fin']   = $dateN1Fin->format("d/m/Y");
  1168.             $param['nbel']       = -1;
  1169.             $param['nbelgraphe'] = 10;
  1170.             //print_r($param);
  1171.             $repoCommande $em->getRepository(Commande::class);
  1172.             //$articles =  $repoCommande->mortArticles($param);
  1173.             $articles = [];
  1174.         }
  1175.         if (array_key_exists('categorie_client'$param) and $param["categorie_client"] > 0) {
  1176.             $parent $repo_categorie_client->find($param["categorie_client"]);
  1177.             if (is_object($parent)) {
  1178.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  1179.             }
  1180.         }
  1181.         return $this->render('Statistiques/Statistique/mort_articles.html.twig', [
  1182.             "articles"              => $articles,
  1183.             'parametres'            => $param,
  1184.             'raisons_mvmt'          => $raisons_mvmt,
  1185.             "categorie_client"      => $categorie_client_racine,
  1186.             "sous_categorie_client" => $categorie_enfants,
  1187.             "param"                 => $param,
  1188.         ]);
  1189.     }
  1190.     /**
  1191.      * @Route("/stats/ca-articles", name="dtc_stats_ca_articles")
  1192.      */
  1193.     public function statsCaArticlesAction(Request $requestEntityManagerInterface $em)
  1194.     {
  1195.         $articles  = [];
  1196.         $param     $request->query->all();
  1197.         $moisDebut "";
  1198.         $moisFin   "";
  1199.         $valeurs   = ["articles" => """mois" => """total" => ""];
  1200.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  1201.             $repoCommande $em->getRepository(Commande::class);
  1202.             //$valeurs =  $repoCommande->statCaArticles($param);
  1203.             $statsPort $repoCommande->suiviConsommationPort($param);
  1204.         } else {
  1205.             $dateN1Debut = new \DateTime();
  1206.             $dateN1Debut->setTime(000000);
  1207.             $dateN1Debut->sub(new \DateInterval('P1Y'));
  1208.             $dateN1Fin             = new \DateTime();
  1209.             $param                 = [];
  1210.             $param['date_debut']   = $dateN1Debut->format("m/Y");
  1211.             $param['date_fin']     = $dateN1Fin->format("m/Y");
  1212.             $param['consommation'] = "vente";
  1213.             //$param['nbel']=500;
  1214.             //$param['nbelgraphe']=10;
  1215.             $repoCommande $em->getRepository(Commande::class);
  1216.             $statsPort $repoCommande->suiviConsommationPort($param);
  1217.             //$valeurs =  $repoCommande->statCaArticles($param);
  1218.         }
  1219.         //print_r($statsPort);
  1220.         $dateDebut \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1221.         $dateDebut->setTime(000000);
  1222.         $dateFin \DateTime::createFromFormat('m/Y'$param['date_fin']);
  1223.         $dateFin->modify('last day of this month');
  1224.         $dateFin->setTime(235959);
  1225.         $dateFinBoucle \DateTime::createFromFormat('m/Y'$param['date_fin']);
  1226.         $dateFinBoucle->modify('last day of this month');
  1227.         $dateFinBoucle->setTime(235959);
  1228.         //var_dump($dateFinBoucle->format('d/m/Y'));
  1229.         $dateDebutBoucle \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1230.         $dateDebutBoucle->setTime(000000);
  1231.         $dateDebutBoucleN1 \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1232.         $dateDebutBoucleN1->setTime(000000);
  1233.         $dateDebutBoucleN1->sub(new \DateInterval('P1Y'));
  1234.         $mois_boucle    = [];
  1235.         $mois_boucle_n1 = [];
  1236.         while ($dateDebutBoucle $dateFinBoucle) {
  1237.             $mois_boucle[]    = $dateDebutBoucle->format("m/Y");
  1238.             $mois_boucle_n1[] = $dateDebutBoucleN1->format("m/Y");
  1239.             $dateDebutBoucle->add(new \DateInterval('P1M'));
  1240.             $dateDebutBoucleN1->add(new \DateInterval('P1M'));
  1241.         }
  1242.         //print_r($mois_boucle);
  1243.         return $this->render('Statistiques/Statistique/stats_ca_articles.html.twig', [
  1244.             "articles"       => $valeurs['articles'],
  1245.             "mois"           => $valeurs['mois'],
  1246.             "total"          => $valeurs['total'],
  1247.             "parametres"     => $param,
  1248.             "mois_boucle"    => $mois_boucle,
  1249.             "mois_boucle_n1" => $mois_boucle_n1,
  1250.             "stats_ports"    => $statsPort,
  1251.         ]);
  1252.     }
  1253.     /**
  1254.      * @Route("/stats/ca-articles/pdf", name="dtc_stats_ca_articles_pdf")
  1255.      */
  1256.     public function statsCaArticlesPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  1257.     {
  1258.         $articles = [];
  1259.         $param    $request->query->all();
  1260.         $param    $param["param"];
  1261.         //print_r($param);
  1262.         $moisDebut "";
  1263.         $moisFin   "";
  1264.         $valeurs   = ["articles" => """mois" => """total" => ""];
  1265.         if (array_key_exists('operation'$param)) {
  1266.             //if($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"]=="valider") {
  1267.             //echo "GGG";
  1268.             $repoCommande $em->getRepository(Commande::class);
  1269.             $statsPort    $repoCommande->suiviConsommationPort($param);
  1270.             //$valeurs =  $repoCommande->statCaArticles($param);
  1271.         } else {
  1272.             //echo "RRRRR";
  1273.             $dateN1Debut = new \DateTime();
  1274.             $dateN1Debut->setTime(000000);
  1275.             $dateN1Debut->sub(new \DateInterval('P1Y'));
  1276.             $dateN1Fin           = new \DateTime();
  1277.             $param               = [];
  1278.             $param['date_debut'] = $dateN1Debut->format("m/Y");
  1279.             $param['date_fin']   = $dateN1Fin->format("m/Y");
  1280.             $repoCommande $em->getRepository(Commande::class);
  1281.             $statsPort    $repoCommande->suiviConsommationPort($param);
  1282.             //$valeurs =  $repoCommande->statCaArticles($param);
  1283.         }
  1284.         $societe $em->getRepository(Societe::class)->find(1);
  1285.         $chemin_pdf 'PDF/STATS/ca_articles.pdf';
  1286.         if (file_exists($chemin_pdf)) {
  1287.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  1288.             unlink($chemin_pdf);
  1289.         }
  1290.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  1291.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  1292.         $header "";
  1293.         $snappy->setOption('orientation'"Landscape");
  1294.         $snappy->setOption('header-html'$header);
  1295.         $snappy->setOption('footer-html'$footer);
  1296.         $snappy->setOption('margin-bottom'"10");
  1297.         $categorie_enfants       = [];
  1298.         $repo_categorie_client   $em->getRepository(Categorie::class);
  1299.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  1300.         $dateDebut \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1301.         $dateDebut->setTime(000000);
  1302.         $dateFin \DateTime::createFromFormat('m/Y'$param['date_fin']);
  1303.         $dateFin->setTime(235959);
  1304.         $dateFinBoucle \DateTime::createFromFormat('m/Y'$param['date_fin']);
  1305.         $dateFinBoucle->setTime(235959);
  1306.         $dateDebutBoucle \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1307.         $dateDebutBoucle->setTime(000000);
  1308.         $dateDebutBoucleN1 \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1309.         $dateDebutBoucleN1->setTime(000000);
  1310.         $dateDebutBoucleN1->sub(new \DateInterval('P1Y'));
  1311.         $mois_boucle    = [];
  1312.         $mois_boucle_n1 = [];
  1313.         while ($dateDebutBoucle $dateFinBoucle) {
  1314.             $mois_boucle[]    = $dateDebutBoucle->format("m/Y");
  1315.             $mois_boucle_n1[] = $dateDebutBoucleN1->format("m/Y");
  1316.             $dateDebutBoucle->add(new \DateInterval('P1M'));
  1317.             $dateDebutBoucleN1->add(new \DateInterval('P1M'));
  1318.         }
  1319.         $snappy->generateFromHtml(
  1320.             $this->renderView(
  1321.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  1322.                 'Statistiques/Statistique/stats_ca_articles_pdf.html.twig',
  1323.                 [
  1324.                     'societe'        => $societe,
  1325.                     "articles"       => $valeurs['articles'],
  1326.                     "mois"           => $valeurs['mois'],
  1327.                     "total"          => $valeurs['total'],
  1328.                     "parametres"     => $param,
  1329.                     "mois_boucle"    => $mois_boucle,
  1330.                     "mois_boucle_n1" => $mois_boucle_n1,
  1331.                     "stats_ports"    => $statsPort,
  1332.                 ]
  1333.             ),
  1334.             $chemin_pdf
  1335.         );
  1336.         if ($retour == true) {
  1337.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  1338.         }
  1339.     }
  1340.     /**
  1341.      * @Route("/stats/ca-articles/xls", name="dtc_stats_ca_articles_xls")
  1342.      */
  1343.     public function statsCaArticlesXlsAction(Request $requestEntityManagerInterface $emStatsService $statsService)
  1344.     {
  1345.         $articles  = [];
  1346.         $param     $request->query->all();
  1347.         $moisDebut "";
  1348.         $moisFin   "";
  1349.         $valeurs   = ["articles" => """mois" => """total" => ""];
  1350.         $param $param["param"];
  1351.         if ($request->isMethod('GET')) {
  1352.             $repoCommande $em->getRepository(Commande::class);
  1353.             //$valeurs =  $repoCommande->statCaArticles($param);
  1354.             $statsPort $repoCommande->suiviConsommationPort($param);
  1355.         } else {
  1356.             $dateN1Debut = new \DateTime();
  1357.             $dateN1Debut->setTime(000000);
  1358.             $dateN1Debut->sub(new \DateInterval('P1Y'));
  1359.             $dateN1Fin             = new \DateTime();
  1360.             $param                 = [];
  1361.             $param['date_debut']   = $dateN1Debut->format("m/Y");
  1362.             $param['date_fin']     = $dateN1Fin->format("m/Y");
  1363.             $param['consommation'] = "vente";
  1364.             //$param['nbel']=500;
  1365.             //$param['nbelgraphe']=10;
  1366.             $repoCommande $em->getRepository(Commande::class);
  1367.             $statsPort $repoCommande->suiviConsommationPort($param);
  1368.             //$valeurs =  $repoCommande->statCaArticles($param);
  1369.         }
  1370.         $dateDebut \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1371.         $dateDebut->setTime(000000);
  1372.         $dateFin \DateTime::createFromFormat('m/Y'$param['date_fin']);
  1373.         $dateFin->setTime(235959);
  1374.         $dateFinBoucle \DateTime::createFromFormat('m/Y'$param['date_fin']);
  1375.         $dateFinBoucle->setTime(235959);
  1376.         $dateDebutBoucle \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1377.         $dateDebutBoucle->setTime(000000);
  1378.         $dateDebutBoucleN1 \DateTime::createFromFormat('d/m/Y''01/'.$param['date_debut']);
  1379.         $dateDebutBoucleN1->setTime(000000);
  1380.         $dateDebutBoucleN1->sub(new \DateInterval('P1Y'));
  1381.         $mois_boucle    = [];
  1382.         $mois_boucle_n1 = [];
  1383.         while ($dateDebutBoucle $dateFinBoucle) {
  1384.             $mois_boucle[]    = $dateDebutBoucle->format("m/Y");
  1385.             $mois_boucle_n1[] = $dateDebutBoucleN1->format("m/Y");
  1386.             $dateDebutBoucle->add(new \DateInterval('P1M'));
  1387.             $dateDebutBoucleN1->add(new \DateInterval('P1M'));
  1388.         }
  1389.         $societe $em->getRepository(Societe::class)->find(1);
  1390.          $spreadsheet = new Spreadsheet();
  1391.         $row 1;
  1392.         $col 0;
  1393.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"");
  1394.         $col++;
  1395.         $avecN1 false;
  1396.         $typeCa = ["Atelier MO""Mag Atelier""Magasin""VO""PO""PE"];
  1397.         $intgereBl false;
  1398.         $intgereN1 false;
  1399.         if (array_key_exists('n1'$param) && $param["n1"] == "1") {
  1400.             $intgereN1 true;
  1401.         }
  1402.         if (array_key_exists('bl'$param) && $param["bl"] == "1") {
  1403.             $intgereBl true;
  1404.         }
  1405.         $indice 0;
  1406.         foreach ($mois_boucle as $mois) {
  1407.             //print_r($mois);
  1408.             //echo "AAA";
  1409.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($mois));
  1410.             $col++;
  1411.             if ($intgereN1) {
  1412.                 //echo "BBBB";
  1413.                 $avecN1 true;
  1414.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($mois_boucle_n1[$indice]));
  1415.                 $col++;
  1416.             }
  1417.             $indice++;
  1418.         }
  1419.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total N");
  1420.         $col++;
  1421.         if ($intgereN1) {
  1422.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total N-1");
  1423.             $col++;
  1424.         }
  1425.         /*
  1426.         {% for a in typeCa %}
  1427.         {% set cle = 0 %}
  1428.         {% set totalLigne = 0 %}
  1429.         {% set totalLigneN1 = 0 %}
  1430.         */
  1431.         $totaux   = [];
  1432.         $totauxN1 = [];
  1433.         foreach ($typeCa as $a) {
  1434.             $row++;
  1435.             $col 0;
  1436.             $cle          "0";
  1437.             $totalLigne   "0";
  1438.             $totalLigneN1 "0";
  1439.             if ($a == "PO") {
  1440.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Pcs occasion");
  1441.             } elseif ($a == "PE") {
  1442.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Pcs export");
  1443.             } else {
  1444.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$a);
  1445.             }
  1446.             foreach ($mois_boucle as $q) {
  1447.                 $cle++;
  1448.                 //{% set totalCa = dtc_stats.calculCaPeriode(a,q,intgereBl,false) %}
  1449.                 $totalCa round($statsService->calculCaPeriode($a$q$intgereBlfalse), 2);
  1450.                 $totalLigne += $totalCa;
  1451.                 if (array_key_exists($cle$totaux)) {
  1452.                     $totaux[$cle] += $totalCa;
  1453.                 } else {
  1454.                     $totaux[$cle] = $totalCa;
  1455.                 }
  1456.                 $col++;
  1457.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalCa);
  1458.                 if ($intgereN1) {
  1459.                     $cle++;
  1460.                     $col++;
  1461.                     $totalCaN1 round($statsService->calculCaPeriode($a$q$intgereBltrue), 2);
  1462.                     if (array_key_exists($cle$totaux)) {
  1463.                         $totaux[$cle] += $totalCaN1;
  1464.                     } else {
  1465.                         $totaux[$cle] = $totalCaN1;
  1466.                     }
  1467.                     $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalCaN1);
  1468.                     $totalLigneN1 += $totalCaN1;
  1469.                 }
  1470.             }
  1471.             $col++;
  1472.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowround($totalLigne2), \PHPExcel_Cell_DataType::TYPE_NUMERIC);
  1473.             if ($intgereN1) {
  1474.                 $col++;
  1475.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowround($totalLigneN12), \PHPExcel_Cell_DataType::TYPE_NUMERIC);
  1476.             }
  1477.         }
  1478.         if (count($statsPort) > 0) {
  1479.             $cle "0";
  1480.             $row++;
  1481.             $col 0;
  1482.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Frais de port");
  1483.             $totaGlobalPort 0;
  1484.             foreach ($statsPort["total"]["totalMois"] as $key => $value) {
  1485.                 $cle++;
  1486.                 $totaGlobalPort += $value;
  1487.                 $col++;
  1488.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$value);
  1489.                 if (array_key_exists($cle$totaux)) {
  1490.                     $totaux[$cle] += $value;
  1491.                 } else {
  1492.                     $totaux[$cle] = $value;
  1493.                 }
  1494.             }
  1495.             $col++;
  1496.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totaGlobalPort);
  1497.         }
  1498.         $totalLigne   0;
  1499.         $totalLigneN1 0;
  1500.         $row++;
  1501.         $col 0;
  1502.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total");
  1503.         $indice 1;
  1504.         foreach ($totaux as $q) {
  1505.             $col++;
  1506.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$q);
  1507.             if ($intgereN1) {
  1508.                 if ($intgereN1 && $indice == 0) {
  1509.                     $totalLigneN1 += $q;
  1510.                 } else {
  1511.                     $totalLigne += $q;
  1512.                 }
  1513.             } else {
  1514.                 $totalLigne += $q;
  1515.             }
  1516.             $indice++;
  1517.         }
  1518.         $col++;
  1519.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalLigne);
  1520.         if ($intgereN1) {
  1521.             $col++;
  1522.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalLigneN1);
  1523.         }
  1524.         // Create your Office 2007 Excel (XLSX Format)
  1525.         $writer = new Xlsx($spreadsheet);
  1526.         // Create a Temporary file in the system
  1527.         $fileName 'stat_ca_articles.xlsx';
  1528.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  1529.         // Create the excel file in the tmp directory of the system
  1530.         $writer->save($temp_file);
  1531.         // Return the excel file as an attachment
  1532.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  1533.     }
  1534.     /**
  1535.      * @Route("", name="")
  1536.      */
  1537.     public function ___statsCaArticlesXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator
  1538.     ) {
  1539.         $articles = [];
  1540.         $param    $request->query->all();
  1541.         $param    $param["param"];
  1542.         //print_r($param);
  1543.         $moisDebut "";
  1544.         $moisFin   "";
  1545.         $valeurs   = ["articles" => """mois" => """total" => ""];
  1546.         if (array_key_exists('operation'$param)) {
  1547.             //if($request->isMethod('GET') and array_key_exists('operation', $param) and $param["operation"]=="valider") {
  1548.             //echo "GGG";
  1549.             $repoCommande $em->getRepository(Commande::class);
  1550.             $valeurs      $repoCommande->statCaArticles($param);
  1551.         } else {
  1552.             //echo "RRRRR";
  1553.             $dateN1Debut = new \DateTime();
  1554.             $dateN1Debut->setTime(000000);
  1555.             $dateN1Debut->sub(new \DateInterval('P1Y'));
  1556.             $dateN1Fin           = new \DateTime();
  1557.             $param               = [];
  1558.             $param['date_debut'] = $dateN1Debut->format("m/Y");
  1559.             $param['date_fin']   = $dateN1Fin->format("m/Y");
  1560.             $repoCommande $em->getRepository(Commande::class);
  1561.             $valeurs      $repoCommande->statCaArticles($param);
  1562.         }
  1563.         $societe $em->getRepository(Societe::class)->find(1);
  1564.          $spreadsheet = new Spreadsheet();
  1565.         $row 1;
  1566.         $col 0;
  1567.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"");
  1568.         $col++;
  1569.         $avecN1 false;
  1570.         foreach ($valeurs['mois'] as $mois) {
  1571.             //print_r($mois);
  1572.             if (array_key_exists('0'$mois)) {
  1573.                 //echo "AAA";
  1574.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($mois[0]));
  1575.                 $col++;
  1576.             }
  1577.             if (array_key_exists('1'$mois)) {
  1578.                 //echo "BBBB";
  1579.                 $avecN1 true;
  1580.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($mois[1]));
  1581.                 $col++;
  1582.             }
  1583.         }
  1584.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total N");
  1585.         $col++;
  1586.         if ($avecN1) {
  1587.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total N-1");
  1588.             $col++;
  1589.         }
  1590.         //exit;
  1591.         $totaux = [];
  1592.         foreach ($valeurs['articles'] as $article) {
  1593.             $totalLigne   0;
  1594.             $totalLigneN1 0;
  1595.             $row++;
  1596.             $col 0;
  1597.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($article["libelle"]));
  1598.             $col++;
  1599.             $cle "0";
  1600.             foreach ($article['valeurs'] as $valeur) {
  1601.                 $cle++;
  1602.                 if ( ! array_key_exists($cle$totaux)) {
  1603.                     $totaux[$cle] = "";
  1604.                 }
  1605.                 $montant $valeur["quantite"];
  1606.                 $montant round($montant2);
  1607.                 $montant str_replace(".00"""$montant);
  1608.                 if ($montant == "0") {
  1609.                     $montant "";
  1610.                 }
  1611.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($montant));
  1612.                 $col++;
  1613.                 $totaux[$cle] = $totaux[$cle] + $montant;
  1614.                 $totalLigne $totalLigne $montant;
  1615.                 if ($avecN1) {
  1616.                     $cle++;
  1617.                     if ( ! array_key_exists($cle$totaux)) {
  1618.                         //echo "<div>creation cle : ".$cle."</div>";
  1619.                         $totaux[$cle] = "";
  1620.                     }
  1621.                     $montant $valeur["quantite_n1"];
  1622.                     $montant round($montant2);
  1623.                     $montant str_replace(".00"""$montant);
  1624.                     if ($montant == "0") {
  1625.                         $montant "";
  1626.                     }
  1627.                     $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($montant));
  1628.                     $col++;
  1629.                     $totaux[$cle] = $totaux[$cle] + $montant;
  1630.                     $totalLigneN1 $totalLigneN1 $montant;
  1631.                 }
  1632.             }
  1633.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($totalLigne));
  1634.             $col++;
  1635.             if ($avecN1) {
  1636.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($totalLigneN1));
  1637.                 $col++;
  1638.             }
  1639.         }
  1640.         $row++;
  1641.         $col 0;
  1642.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"Total");
  1643.         $col++;
  1644.         //exit;
  1645.         $compteur     0;
  1646.         $totalLigne   0;
  1647.         $totalLigneN1 0;
  1648.         foreach ($totaux as $total) {
  1649.             $compteur++;
  1650.             $montant $total;
  1651.             $montant round($montant2);
  1652.             $montant str_replace(".00"""$montant);
  1653.             if ($montant == "0") {
  1654.                 $montant "";
  1655.             }
  1656.             if ($compteur == 0) {
  1657.                 $totalLigneN1 $totalLigneN1 $montant;
  1658.             } else {
  1659.                 $totalLigne $totalLigne $montant;
  1660.             }
  1661.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($montant));
  1662.             $col++;
  1663.         }
  1664.         if ($totalLigne == "0") {
  1665.             $totalLigne "";
  1666.         }
  1667.         if ($totalLigneN1 == "0") {
  1668.             $totalLigneN1 "";
  1669.         }
  1670.         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($totalLigne));
  1671.         $col++;
  1672.         if ($avecN1) {
  1673.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($totalLigneN1));
  1674.             $col++;
  1675.         }
  1676.         // Create your Office 2007 Excel (XLSX Format)
  1677.         $writer = new Xlsx($spreadsheet);
  1678.         // Create a Temporary file in the system
  1679.         $fileName 'stat_ca_articles.xlsx';
  1680.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  1681.         // Create the excel file in the tmp directory of the system
  1682.         $writer->save($temp_file);
  1683.         // Return the excel file as an attachment
  1684.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  1685.     }
  1686.     /**
  1687.      * @Route("/stats/hit/clients/detail", name="dtc_top_clients_detail")
  1688.      */
  1689.     public function __topClientsDetailAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  1690.     {
  1691.         $get       $request->query->all();
  1692.         $client_id trim($get["client"]);
  1693.         $repoCommande $em->getRepository(Commande::class);
  1694.         $articles     $repoCommande->topClientsDetails($get);
  1695.         $rendu        $this->renderView(
  1696.             'Statistiques/Statistique/top_clients_detail.html.twig',
  1697.             ["client_id" => $get["client_id"], "articles" => $articles"parametres" => $get]
  1698.         );
  1699.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '']);
  1700.     }
  1701.     /**
  1702.      * @Route("/stats/hit/marques", name="dtc_top_marques")
  1703.      */
  1704.     public function topMarquesAction(Request $requestEntityManagerInterface $em)
  1705.     {
  1706.         $categorie_enfants       = [];
  1707.         $repo_categorie_client   $em->getRepository(Categorie::class);
  1708.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  1709.         $articles = [];
  1710.         $param    $request->query->all();
  1711.         if ($request->isMethod('GET') and array_key_exists('operation'$param) and $param["operation"] == "valider") {
  1712.             //print_r($_GET);
  1713.             $repoCommande $em->getRepository(Commande::class);
  1714.             $marques      $repoCommande->topMarques($param);
  1715.         } else {
  1716.             $dateN1Debut = new \DateTime();
  1717.             $dateN1Debut->setTime(000000);
  1718.             $dateN1Debut->sub(new \DateInterval('P1M'));
  1719.             $dateN1Fin = new \DateTime();
  1720.             $param               = [];
  1721.             $param['date_debut'] = $dateN1Debut->format("d/m/Y");
  1722.             $param['date_fin']   = $dateN1Fin->format("d/m/Y");
  1723.             $param['nbel']       = 500;
  1724.             $param['nbelgraphe'] = 10;
  1725.             //print_r($param);
  1726.             $repoCommande $em->getRepository(Commande::class);
  1727.             $marques      $repoCommande->topMarques($param);
  1728.         }
  1729.         if (array_key_exists('categorie_client'$param) and $param["categorie_client"] > 0) {
  1730.             $parent $repo_categorie_client->find($param["categorie_client"]);
  1731.             if (is_object($parent)) {
  1732.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  1733.             }
  1734.         }
  1735.         return $this->render('Statistiques/Statistique/top_marques.html.twig', [
  1736.             "marques"               => $marques,
  1737.             'parametres'            => $param,
  1738.             "categorie_client"      => $categorie_client_racine,
  1739.             "sous_categorie_client" => $categorie_enfants,
  1740.             "param"                 => $param,
  1741.         ]);
  1742.     }
  1743.     /**
  1744.      * @Route("/stats/hit/marques/xls", name="dtc_top_marques_xls")
  1745.      */
  1746.     public function topMarquesXlsAction(Request $request$param = [], $retour trueEntityManagerInterface $emStatsService $statService)
  1747.     {
  1748.         $param  $request->query->all();
  1749.         $detail "0";
  1750.         if (array_key_exists('detail'$param) and $param['detail'] == "1") {
  1751.             $detail "1";
  1752.         }
  1753.         $n1 "0";
  1754.         if (array_key_exists('param'$param) && array_key_exists('n1'$param["param"]) and $param["param"]['n1'] == "1") {
  1755.             $n1 "1";
  1756.         }
  1757.         $repoCommande $em->getRepository(Commande::class);
  1758.         $marques      $repoCommande->topMarques($param['param']);
  1759.         $societe $em->getRepository(Societe::class)->find(1);
  1760.          $spreadsheet = new Spreadsheet();
  1761.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('A1''Réf');
  1762.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('B1''Nom');
  1763.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('C1''Qté');
  1764.         $spreadsheet->setActiveSheetIndex(0)->setCellValue('D1''Total HT');
  1765.         if ($n1 == "1") {
  1766.             $spreadsheet->setActiveSheetIndex(0)->setCellValue('E1''Qté n-1');
  1767.             $spreadsheet->setActiveSheetIndex(0)->setCellValue('F1''Total HT n-1');
  1768.         }
  1769.         //echo $param["n1"];
  1770.         //$articleService = $this->container->get('dtc.article');
  1771.         $row 2;
  1772.         $col 0;
  1773.         for ($i 0$i count($marques); $i++) {
  1774.             //$spreadsheet->setActiveSheetIndex(0)->setCellValue('A1', 'Article');
  1775.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($marques[$i]['reference']));
  1776.             $col++;
  1777.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($marques[$i]['libelle']));
  1778.             $col++;
  1779.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($marques[$i]['total_quantite']));
  1780.             $col++;
  1781.             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($marques[$i]['total']));
  1782.             $col++;
  1783.             if ($n1 == "1") {
  1784.                 /*
  1785.                       {% set totalN1 = dtc_stats.getTopClientn1(parametres,c.client_id) %}
  1786.                   */
  1787.                 //{% set totalN1 = dtc_stats.getTopMarquen1(parametres,a.marque_id) %}
  1788.                 //$totalN1 = $statService->getTopClientn1($param["param"],$marques[$i]['marque_id']);
  1789.                 $totalN1 $statService->getTopMarquen1($param["param"], $marques[$i]['marque_id']);
  1790.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($totalN1['total_quantite']));
  1791.                 $col++;
  1792.                 $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($totalN1['total']));
  1793.                 $col++;
  1794.             }
  1795.             if ($detail == 1) {
  1796.                 $row++;
  1797.                 $col                        0;
  1798.                 $param_details              $param['param'];
  1799.                 $param_details["marque"]    = $marques[$i]['marque_id'];
  1800.                 $param_details["marque_id"] = $marques[$i]['marque_id'];
  1801.                 $articles $repoCommande->topMarquesDetails($param_details);
  1802.                 if (count($articles) > 0) {
  1803.                     for ($f 0$f count($articles); $f++) {
  1804.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row"");
  1805.                         $col++;
  1806.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$articles[$f]["reference"]." ".$articles[$f]["libelle"]);
  1807.                         $col++;
  1808.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$f]["total_qte"]));
  1809.                         $col++;
  1810.                         $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$rowtrim($articles[$f]["total"]));
  1811.                         $col++;
  1812.                         if ($n1 == "1") {
  1813.                             $tabDetailsN1              $param["param"];
  1814.                             $tabDetailsN1["marque"]    = $marques[$i]['marque_id'];
  1815.                             $tabDetailsN1["marque_id"] = $marques[$i]['marque_id'];
  1816.                             $totalN1 $statService->getTopMarquen1Details($tabDetailsN1$articles[$f]['article_id']);
  1817.                             $totalTemp $totalN1["total"];
  1818.                             $qteTemp   $totalN1["total_qte"];
  1819.                             if ($totalTemp == "") {
  1820.                                 $totalTemp "0";
  1821.                             }
  1822.                             if ($qteTemp == "") {
  1823.                                 $qteTemp "0";
  1824.                             }
  1825.                             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$qteTemp);
  1826.                             $col++;
  1827.                             $spreadsheet->getActiveSheet()->setCellValueByColumnAndRow($col$row$totalTemp);
  1828.                             $col++;
  1829.                             /*
  1830.                                 {% set totalN1 = dtc_stats.getTopClientn1Details(parametres,a.article_id) %}
  1831.                                 <td style="text-align:right;">{{totalN1.total_qte|number_format(2, '.', '&nbsp;')|replace({".00" : ""})|raw}}</td>
  1832.                                 <td style="text-align:right;">{{totalN1.total|number_format(2, '.', '&nbsp;')|replace({".00" : ""})|raw}}</td>
  1833.                             */
  1834.                         }
  1835.                         $col 0;
  1836.                         $row++;
  1837.                     }
  1838.                 }
  1839.             }
  1840.             $col 0;
  1841.             $row++;
  1842.         }
  1843.         // Create your Office 2007 Excel (XLSX Format)
  1844.         $writer = new Xlsx($spreadsheet);
  1845.         // Create a Temporary file in the system
  1846.         $fileName 'top_marques.xlsx';
  1847.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  1848.         // Create the excel file in the tmp directory of the system
  1849.         $writer->save($temp_file);
  1850.         // Return the excel file as an attachment
  1851.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  1852.     }
  1853.     /**
  1854.      * @Route("/stats/hit/marques/pdf", name="dtc_top_marques_pdf")
  1855.      */
  1856.     public function topMarquesPdfAction(Request $request$param = [], $retour trueEntityManagerInterface $emPdf $snappy)
  1857.     {
  1858.         $param        $request->query->all();
  1859.         $repoCommande $em->getRepository(Commande::class);
  1860.         $marques      $repoCommande->topMarques($param['param']);
  1861.         $get    $request->query->all();
  1862.         $detail "0";
  1863.         if (array_key_exists('detail'$get) and $get['detail'] == "1") {
  1864.             $detail "1";
  1865.         }
  1866.         $societe $em->getRepository(Societe::class)->find(1);
  1867.         $chemin_pdf 'PDF/HIT/marques.pdf';
  1868.         if (file_exists($chemin_pdf)) {
  1869.             //return $this->render('FO/PDF/conteneur_pdf.html.twig', array('chemin_pdf' =>'/'.$chemin_pdf));
  1870.             unlink($chemin_pdf);
  1871.         }
  1872.         $footer $this->renderView('FO/PDF/footer_pagination_pdf.html.twig', ['societe' => $societe]);
  1873.         //$header = $this->renderView('FO/PDF/header_bl_pdf.html.twig', array('societe'  => $societe,'commande'  => $bonPreparation));
  1874.         $header "";
  1875.         $snappy->setOption('header-html'$header);
  1876.         $snappy->setOption('footer-html'$footer);
  1877.         $snappy->setOption('margin-bottom'"10");
  1878.         $categorie_enfants       = [];
  1879.         $repo_categorie_client   $em->getRepository(Categorie::class);
  1880.         $categorie_client_racine $repo_categorie_client->findBy(["modifiable" => 0]);
  1881.         if (array_key_exists('categorie_client'$param['param']) and $param['param']["categorie_client"] > 0) {
  1882.             $parent $repo_categorie_client->find($param['param']["categorie_client"]);
  1883.             if (is_object($parent)) {
  1884.                 $categorie_enfants $repo_categorie_client->findBy(["categorieParent" => $parent]);
  1885.             }
  1886.         }
  1887.         $snappy->generateFromHtml(
  1888.             $this->renderView(
  1889.             //'GestionComerciale/BonLivraison/template_pdf.html.twig',
  1890.                 'Statistiques/Statistique/top_marques_pdf.html.twig',
  1891.                 [
  1892.                     'detail'                => $detail,
  1893.                     'societe'               => $societe,
  1894.                     'parametres'            => $param['param'],
  1895.                     'marques'               => $marques,
  1896.                     "categorie_client"      => $categorie_client_racine,
  1897.                     "sous_categorie_client" => $categorie_enfants,
  1898.                 ]
  1899.             ),
  1900.             $chemin_pdf
  1901.         );
  1902.         if ($retour == true) {
  1903.             return $this->render('FO/PDF/conteneur_pdf.html.twig', ['chemin_pdf' => '/'.$chemin_pdf]);
  1904.         }
  1905.     }
  1906.     /**
  1907.      * @Route("/stats/hit/marques/detail", name="dtc_top_marques_detail")
  1908.      */
  1909.     public function topMarquesDetailAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  1910.     {
  1911.         $get $request->query->all();
  1912.         $marque_id trim($get["marque_id"]);
  1913.         $repoCommande $em->getRepository(Commande::class);
  1914.         $articles     $repoCommande->topMarquesDetails($get);
  1915.         $rendu        $this->renderView(
  1916.             'Statistiques/Statistique/top_marques_detail.html.twig',
  1917.             ["marque_id" => $get["marque_id"], "articles" => $articles"parametres" => $get]
  1918.         );
  1919.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '']);
  1920.     }
  1921.     /**
  1922.      * @Route("", name="")
  1923.      */
  1924.     public function topMarquesDetailPdfAction(Request $request$parametres = [], EntityManagerInterface $em)
  1925.     {
  1926.         $get       $request->query->all();
  1927.         $get       $parametres;
  1928.         $marque_id trim($get["marque_id"]);
  1929.         $repoCommande $em->getRepository(Commande::class);
  1930.         $articles     $repoCommande->topMarquesDetails($parametres);
  1931.         return $this->render(
  1932.             'Statistiques/Statistique/top_marques_detail.html.twig',
  1933.             ["marque_id" => $parametres["marque"], "articles" => $articles"parametres" => $parametres]
  1934.         );
  1935.     }
  1936.     /**
  1937.      * @Route("", name="")
  1938.      */
  1939.     public function __topClientsDetailPdfAction(Request $request$parametres = [], EntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  1940.     {
  1941.         $get          $request->query->all();
  1942.         $get          $parametres;
  1943.         $repoCommande $em->getRepository(Commande::class);
  1944.         $articles     $repoCommande->topClientsDetails($parametres);
  1945.         return $this->render(
  1946.             'Statistiques/Statistique/top_clients_detail.html.twig',
  1947.             ["client_id" => $parametres["client"], "articles" => $articles"parametres" => $parametres]
  1948.         );
  1949.     }
  1950. }