src/Controller/ArticleController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use RuntimeException;
  4. use App\Entity\PUnite;
  5. use App\Entity\PStatut;
  6. use App\Entity\UArticle;
  7. use App\Entity\PArticleNiveau;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  10. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  11. use Symfony\Component\HttpClient\HttpClient;
  12. use Symfony\Component\Serializer\Serializer;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use PhpOffice\PhpSpreadsheet\Reader\Xlsx as Reader;
  18. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  19. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  20. use Symfony\Contracts\HttpClient\HttpClientInterface;
  21. use Symfony\Component\String\Slugger\SluggerInterface;
  22. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  23. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  24. use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  27. #[Route('/article')]
  28. class ArticleController extends AbstractController
  29. {
  30.     private $em;
  31.     public function __construct(ManagerRegistry $doctrine)
  32.     {
  33.         $this->em $doctrine->getManager();
  34.     }
  35.     #[Route('/'name'article_index')]
  36.     public function index(): Response
  37.     {
  38.         $niveaux $this->em->getRepository(PArticleNiveau::class)->findBy(['parent' => null]);
  39.         $unites $this->em->getRepository(PUnite::class)->findAll();
  40.         return $this->render('article/index.html.twig' , [
  41.             'niveaux' => $niveaux,
  42.             'unites' => $unites
  43.         ]);
  44.     }
  45.     #[Route('/list'name'article_list')]
  46.     public function list(Request $request): Response
  47.     {
  48.         $params $request->query;
  49.         // dd($params);
  50.         $where $totalRows $sqlRequest "";
  51.         $filtre "where article.active = 1 ";
  52.         // dd($params->get('columns')[0]);
  53.         
  54.         if (!empty($params->get('columns')[0]['search']['value'])) {
  55.             $niveaux $this->em->getRepository(PArticleNiveau::class)->find($params->get('columns')[0]['search']['value']);
  56.             $arrayOfIds ApiController::pluck($niveaux);
  57.             
  58.             $filtre .= " and niv.id in (" implode(",",$arrayOfIds) . ") ";
  59.         }
  60.          if (!empty($params->get('columns')[1]['search']['value'])) {  
  61.             if($params->get('columns')[1]['search']['value'] == "nv")   {
  62.                 $filtre .= " and pstatut.id = 1 ";
  63.             }  else if($params->get('columns')[1]['search']['value'] == "ni") {
  64.                 $filtre .= " and pstatut.id = 2 ";
  65.             }
  66.         }
  67.         $columns = array(
  68.             array( 'db' => 'article.titre','dt' => 0),
  69.             array( 'db' => 'UPPER(unite.designation)','dt' => 1),
  70.             array( 'db' => 'LOWER(niv.designation)','dt' => 2),
  71.             array( 'db' => 'UPPER(niv.id)','dt' => 3),
  72.             array( 'db' => 'UPPER(niv.niveau)','dt' => 5),
  73.             array( 'db' => 'article.id','dt' => 6),
  74.              array( 'db' => 'pstatut.designation','dt' => 7),
  75.             array( 'db' => 'article.active','dt' => 8),
  76.            
  77.             
  78.         );
  79.         $sql "SELECT " implode(", "DatatablesController::Pluck($columns'db')) . "
  80.         
  81.         FROM uarticle article
  82.         left join punite unite on unite.id = article.unite_id
  83.         inner join pstatut on pstatut.id = article.statut_id 
  84.         inner join particle_niveau niv on niv.id = article.niveau_id 
  85.         
  86.         
  87.         
  88.         $filtre "
  89.         ;
  90.         $totalRows .= $sql;
  91.         $sqlRequest .= $sql;
  92.         $stmt $this->em->getConnection()->prepare($sql);
  93.         $newstmt $stmt->executeQuery();
  94.         $totalRecords count($newstmt->fetchAll());
  95.         $my_columns DatatablesController::Pluck($columns'db');
  96.             
  97.         // search 
  98.         $where DatatablesController::Search($request$columns);
  99.         if (isset($where) && $where != '') {
  100.             $sqlRequest .= $where;
  101.         }
  102.         $sqlRequest .= DatatablesController::Order($request$columns);
  103.         $stmt $this->em->getConnection()->prepare($sqlRequest);
  104.         $resultSet $stmt->executeQuery();
  105.         $result $resultSet->fetchAll();
  106.         
  107.         
  108.         $data = array();
  109.         $i 1;
  110.         foreach ($result as $key => $row) {
  111.             $nestedData = array();
  112.             $currentNiveau $row['UPPER(niv.id)'];
  113.             $arrayOfNiveaux = [];
  114.             for ($i=$row['UPPER(niv.niveau)']; $i 0$i--) { 
  115.                 $niveau $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  116.                 array_push($arrayOfNiveaux, [$niveau->getDesignation(), $niveau->getStatut()->getDesignation(), $niveau->getId()]);
  117.                 if($niveau->getParent()) {
  118.                     $currentNiveau $niveau->getParent()->getId();
  119.                 } else {
  120.                     break;
  121.                 }
  122.             }
  123.             $arrayOfNiveaux array_reverse($arrayOfNiveaux);
  124.             $diffrence count($arrayOfNiveaux);
  125.             if($diffrence 0){
  126.                 for($i 1$i <= $diffrence$i++){
  127.                     array_push($arrayOfNiveaux, ["-""-""-"]);
  128.                 }
  129.             }
  130.             $cd $row['id'];
  131.             $check "";
  132.             if($row['designation'] == "Intégrer" or $row['designation'] == "Updated"){
  133.                 $check "checked disabled='disabled'";
  134.             }
  135.             $nestedData[] = "<input type ='checkbox' class='check_article' id ='$cd$check>";
  136.             $nestedData[] = $cd;
  137.             $currentClass "";
  138.             foreach ($arrayOfNiveaux as $niveau) {
  139.                 if($niveau[1] == "En Cours") {
  140.                     // $nestedData[] = "<span class='danger' id='$niveau[2]'>".$niveau[0]."</span>";                
  141.                     if(strlen($niveau[0]) >= 20)
  142.                     {
  143.                         $nestedData[] = "<span class='danger' id='$niveau[2]'>".mb_substr($niveau[0],0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$niveau[0].'"> ''&nbsp;...' .'</span></span>';
  144.                     }
  145.                     else {
  146.                         $nestedData[] = "<span class='danger' id='$niveau[2]'>".$niveau[0]."</span>"
  147.                     }
  148.                     $currentClass "danger";
  149.                 } else if($niveau[1] == "Valider") {
  150.                     if(strlen($niveau[0]) >= 20)
  151.                     {
  152.                         $nestedData[] = "<span class='success' >".mb_substr($niveau[0],0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$niveau[0].'"> ''&nbsp;...' .'</span></span>';
  153.                     }
  154.                     else {
  155.                         $nestedData[] = "<span class='success' >".$niveau[0]."</span>"
  156.                     }
  157.                     $currentClass "success";
  158.                 }else if($niveau[1] == "Intégrer") {
  159.                     // $nestedData[] = "<span class='' >".$niveau[0]."</span>";             
  160.                     if(strlen($niveau[0]) >= 20)
  161.                     {
  162.                         $nestedData[] = "<span class='' >".mb_substr($niveau[0],0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$niveau[0].'"> ''&nbsp;...' .'</span></span>';
  163.                     }
  164.                     else {
  165.                         $nestedData[] = "<span class='' >".$niveau[0]."</span>"
  166.                     }
  167.                     $currentClass "";
  168.                 }else {
  169.                     if(strlen($niveau[0]) >= 20)
  170.                     {
  171.                         $nestedData[] = "<span class='$currentClass' >".mb_substr($niveau[0],0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$niveau[0].'"> ''&nbsp;...' .'</span></span>';
  172.                     }
  173.                     else {
  174.                         $nestedData[] = "<span class='$currentClass' >".$niveau[0]."</span>"
  175.                     }
  176.                     // $nestedData[] = "<span class='$currentClass' >".$niveau[0]."</span>"; 
  177.                 }            
  178.             }
  179.             foreach (array_values($row) as $key => $value) {
  180.                 if($key 2) {
  181.                     if($row["designation"] == "En Cours"){
  182.                         // $nestedData[] = "<span class='dangerArticle' id='$cd'>".$value."</span>";                
  183.                         if(strlen($value) >= 20)
  184.                         {
  185.                             $nestedData[] = "<span class='dangerArticle' id='$cd' >".mb_substr($value,0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$value.'"> ''&nbsp;...' .'</span></span>';
  186.                         }
  187.                         else {
  188.                             $nestedData[] = "<span class='dangerArticle' id='$cd'>".$value."</span>"
  189.                         }
  190.                     } else if($row["designation"] == "Valider") {
  191.                         // $nestedData[] = "<span class='successArticle'  id='$cd'>".$value."</span>";                
  192.                         if(strlen($value) >= 20)
  193.                         {
  194.                             $nestedData[] = "<span class='successArticle' id='$cd' >".mb_substr($value,0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$value.'"> ''&nbsp;...' .'</span></span>';
  195.                         }
  196.                         else {
  197.                             $nestedData[] = "<span class='successArticle' id='$cd'>".$value."</span>"
  198.                         }
  199.                     } 
  200.                     
  201.                     else if($row["designation"] == "Updated") {
  202.                         // $nestedData[] = "<span class='successArticle'  id='$cd'>".$value."</span>";                
  203.                         if(strlen($value) >= 20)
  204.                         {
  205.                             $nestedData[] = "<span class='UpdatedArticle' id='$cd' >".mb_substr($value,0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$value.'"> ''&nbsp;...' .'</span></span>';
  206.                         }
  207.                         else {
  208.                             $nestedData[] = "<span class='UpdatedArticle' id='$cd'>".$value."</span>"
  209.                         }
  210.                     } else {
  211.                         if(strlen($value) >= 20)
  212.                         {
  213.                             $nestedData[] = "<span id='$cd' >".mb_substr($value,0,20).'<span style="position: absolute; font-weight:bold; cursor:pointer" class="hint--top" aria-label="'.$value.'"> ''&nbsp;...' .'</span></span>';
  214.                         }
  215.                         else {
  216.                             $nestedData[] = "<span id='$cd'>".$value."</span>"
  217.                         }
  218.                         // $nestedData[] = "<span  id='$cd'>".$value."</span>";                
  219.                     }
  220.                 }
  221.             }
  222.             $nestedData [] = $row['active'] == 'oui' 'non';
  223.             $html '<div class="btn-group dropdown-btn-action ">
  224.             <button type="button" class="btn btn-secondary-outline btn-sm  dropdown-toggle btn-dropdown" id="dropdown_table" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  225.             <i class="fa fa-ellipsis-h"></i>
  226.             </button>
  227.             <div class="dropdown-menu dropdown-menu-right">
  228.                 <button  type="button" class="dropdown-item getArticleDetails" id="'.$cd.'">
  229.                     Details 
  230.                 </button> ';    
  231.             if ($this->isGranted('ROLE_CREATEUR')){
  232.             $html .= '<button  type="button" class="dropdown-item getArticleUpdate" id="'.$cd.'">
  233.                 Modifier 
  234.             </button>';
  235.             }
  236.             if ($row['active'] == 1){
  237.                 $html .= '<button  type="button" class="dropdown-item switchenable" id="'.$cd.'">
  238.                     Désactiver 
  239.                 </button>';
  240.             } else {
  241.                 $html .= '<button  type="button" class="dropdown-item switchenable" id="'.$cd.'">
  242.                     Active 
  243.                 </button>';
  244.             }
  245.                                                                                
  246.             $html .= '</div>
  247.                     </div>';
  248.             $nestedData [] = $html;
  249.                               
  250.                             
  251.             // $nestedData["DT_RowId"] = $cd;
  252.             // $nestedData["DT_RowClass"] = $cd;
  253.             $data[] = $nestedData;
  254.             $i++;
  255.         }
  256.         $json_data = array(
  257.             "draw" => intval($params->get('draw')),
  258.             "recordsTotal" => intval($totalRecords),
  259.             "recordsFiltered" => intval($totalRecords),
  260.             "data" => $data   
  261.         );
  262.         // die;
  263.         // $json_data = mb_convert_encoding($json_data, "UTF-8", "auto");
  264.         // dd($json_data);
  265.         $json json_encode($json_data);
  266.         
  267.         if (json_last_error() !== JSON_ERROR_NONE) {
  268.             throw new RuntimeException(json_last_error_msg());
  269.         }
  270.         // dd("amine");
  271.         return new Response(json_encode($json_data));
  272.     }
  273.     #[Route('/niveau/details/{niveau}'name'article_niveau_details')]
  274.     public function niveauDetails(PArticleNiveau $niveau): Response
  275.     {
  276.         return new JsonResponse([
  277.             'niveau' => $niveau->getNiveau(),
  278.             'designation' => $niveau->getDesignation(),
  279.             'cca1' => $niveau->getCCA1(),
  280.             'cca2' => $niveau->getCCA2(),
  281.             'cca3' => $niveau->getCCA3(),
  282.             'cca4' => $niveau->getCCA4(),
  283.             ]);
  284.     }
  285.     #[Route('/niveau/update/{niveau}'name'article_niveau_update')]
  286.     public function niveauUpdate(PArticleNiveau $niveauRequest $request): Response
  287.     {
  288.         $niveau->setDesignation($request->get("designation"));
  289.         $niveau->setStatut($this->em->getRepository(PStatut::class)->find(2));
  290.         if($niveau->getParent()){
  291.             $parentNiveau $niveau->getParent();
  292.             if($request->get('cca1') == "" && $request->get('cca2') == "" && $request->get('cca3') == "" && $request->get('cca4') == "") {
  293.                 $niveau->setCCA1($parentNiveau->getCCA1());
  294.                 $niveau->setCCA2($parentNiveau->getCCA2());
  295.                 $niveau->setCCA3($parentNiveau->getCCA3());
  296.                 $niveau->setCCA4($parentNiveau->getCCA4());
  297.             } else {
  298.                 $niveau->setCCA1($request->get('cca1') != "" ?  $request->get('cca1') : null);
  299.                 $niveau->setCCA2($request->get('cca2') != "" ?  $request->get('cca2') : null);
  300.                 $niveau->setCCA3($request->get('cca3') != "" ?  $request->get('cca3') : null);
  301.                 $niveau->setCCA4($request->get('cca4') != "" ?  $request->get('cca4') : null);
  302.                 if($niveau->getNiveaux()) {
  303.                     $niveauChilds $niveau->getNiveaux();
  304.                     foreach ($niveauChilds as $niveauChild) {
  305.                         $niveauChild->setCCA1($niveau->getCCA1());
  306.                         $niveauChild->setCCA2($niveau->getCCA2());
  307.                         $niveauChild->setCCA3($niveau->getCCA3());
  308.                         $niveauChild->setCCA4($niveau->getCCA4());
  309.                         
  310.                         if($niveauChild->getNiveaux()) {
  311.                             $niveauChilds $niveauChild->getNiveaux();
  312.                             foreach ($niveauChilds as $niveauChild) {
  313.                                 $niveauChild->setCCA1($niveau->getCCA1());
  314.                                 $niveauChild->setCCA2($niveau->getCCA2());
  315.                                 $niveauChild->setCCA3($niveau->getCCA3());
  316.                                 $niveauChild->setCCA4($niveau->getCCA4());
  317.                                 if($niveauChild->getNiveaux()) {
  318.                                     $niveauChilds $niveauChild->getNiveaux();
  319.                                     foreach ($niveauChilds as $niveauChild) {
  320.                                         $niveauChild->setCCA1($niveau->getCCA1());
  321.                                         $niveauChild->setCCA2($niveau->getCCA2());
  322.                                         $niveauChild->setCCA3($niveau->getCCA3());
  323.                                         $niveauChild->setCCA4($niveau->getCCA4());
  324.                                         if($niveauChild->getNiveaux()) {
  325.                                             $niveauChilds $niveauChild->getNiveaux();
  326.                                             foreach ($niveauChilds as $niveauChild) {
  327.                                                 $niveauChild->setCCA1($niveau->getCCA1());
  328.                                                 $niveauChild->setCCA2($niveau->getCCA2());
  329.                                                 $niveauChild->setCCA3($niveau->getCCA3());
  330.                                                 $niveauChild->setCCA4($niveau->getCCA4());
  331.                                                 if($niveauChild->getNiveaux()) {
  332.                                                     $niveauChilds $niveauChild->getNiveaux();
  333.                                                     foreach ($niveauChilds as $niveauChild) {
  334.                                                         $niveauChild->setCCA1($niveau->getCCA1());
  335.                                                         $niveauChild->setCCA2($niveau->getCCA2());
  336.                                                         $niveauChild->setCCA3($niveau->getCCA3());
  337.                                                         $niveauChild->setCCA4($niveau->getCCA4());
  338.                                     
  339.                                                     }
  340.                                                 }
  341.                                             }
  342.                                         }
  343.                                     }
  344.                                 }
  345.                             }
  346.                         }
  347.                     }
  348.                 }
  349.             }
  350.         } else {
  351.             $niveau->setCCA1($request->get('cca1') != "" ?  $request->get('cca1') : null);
  352.             $niveau->setCCA2($request->get('cca2') != "" ?  $request->get('cca2') : null);
  353.             $niveau->setCCA3($request->get('cca3') != "" ?  $request->get('cca3') : null);
  354.             $niveau->setCCA4($request->get('cca4') != "" ?  $request->get('cca4') : null);
  355.             if($niveau->getNiveaux()) {
  356.                 $niveauChilds $niveau->getNiveaux();
  357.                 foreach ($niveauChilds as $niveauChild) {
  358.                     $niveauChild->setCCA1($niveau->getCCA1());
  359.                     $niveauChild->setCCA2($niveau->getCCA2());
  360.                     $niveauChild->setCCA3($niveau->getCCA3());
  361.                     $niveauChild->setCCA4($niveau->getCCA4());
  362.                     
  363.                     if($niveauChild->getNiveaux()) {
  364.                         $niveauChilds $niveauChild->getNiveaux();
  365.                         foreach ($niveauChilds as $niveauChild) {
  366.                             $niveauChild->setCCA1($niveau->getCCA1());
  367.                             $niveauChild->setCCA2($niveau->getCCA2());
  368.                             $niveauChild->setCCA3($niveau->getCCA3());
  369.                             $niveauChild->setCCA4($niveau->getCCA4());
  370.                             if($niveauChild->getNiveaux()) {
  371.                                 $niveauChilds $niveauChild->getNiveaux();
  372.                                 foreach ($niveauChilds as $niveauChild) {
  373.                                     $niveauChild->setCCA1($niveau->getCCA1());
  374.                                     $niveauChild->setCCA2($niveau->getCCA2());
  375.                                     $niveauChild->setCCA3($niveau->getCCA3());
  376.                                     $niveauChild->setCCA4($niveau->getCCA4());
  377.                                     if($niveauChild->getNiveaux()) {
  378.                                         $niveauChilds $niveauChild->getNiveaux();
  379.                                         foreach ($niveauChilds as $niveauChild) {
  380.                                             $niveauChild->setCCA1($niveau->getCCA1());
  381.                                             $niveauChild->setCCA2($niveau->getCCA2());
  382.                                             $niveauChild->setCCA3($niveau->getCCA3());
  383.                                             $niveauChild->setCCA4($niveau->getCCA4());
  384.                                             if($niveauChild->getNiveaux()) {
  385.                                                 $niveauChilds $niveauChild->getNiveaux();
  386.                                                 foreach ($niveauChilds as $niveauChild) {
  387.                                                     $niveauChild->setCCA1($niveau->getCCA1());
  388.                                                     $niveauChild->setCCA2($niveau->getCCA2());
  389.                                                     $niveauChild->setCCA3($niveau->getCCA3());
  390.                                                     $niveauChild->setCCA4($niveau->getCCA4());
  391.                                 
  392.                                                 }
  393.                                             }
  394.                                         }
  395.                                     }
  396.                                 }
  397.                             }
  398.                         }
  399.                     }
  400.                 }
  401.             }
  402.         }
  403.         $this->em->flush();
  404.         return new JsonResponse("Bien Enregistre"200);
  405.     }
  406.     #[Route('/article/details/{article}'name'article_article_details')]
  407.     public function articleDetails(UArticle $article): Response
  408.     {
  409.         $html $this->render("article/pages/form_valide.html.twig", [
  410.             'article' => $article
  411.         ])->getContent();
  412.         return new JsonResponse([
  413.             "html" => $html,
  414.             'title' => $article->getTitre()
  415.         ]);
  416.     }
  417.      #[Route('/article/siwtchactive/{article}'name'article_article_siwtchactive')]
  418.     public function siwtchactive(UArticle $article,  HttpClientInterface $client): Response
  419.     {
  420.         $article->setActive(!$article->getActive());
  421.         
  422.         $response $client->request('POST'$this->getParameter("api")."/api/article/siwtchactive/".$article->getId(), [
  423.             'body' => [
  424.                 'active' => $article->getActive(),
  425.             ],
  426.         ]);
  427.         if($response->getContent() == "good") {
  428.            $this->em->flush();
  429.            return new JsonResponse('Bien enregister!');
  430.         }
  431.         return new JsonResponse('Something went wrong!'500);
  432.         
  433.     }
  434.     #[Route('/article/valide'name'article_article_valide')]
  435.     public function articleValidate(Request $request): Response
  436.     {
  437.         $idArticles json_decode($request->get('articles'));
  438.         // dd($idArticles);
  439.         foreach($idArticles as $idArticle) {
  440.             $article $this->em->getRepository(UArticle::class)->find($idArticle);
  441.             if($article->getStatut()->getDesignation() == "En Cours") {
  442.                 $article->setStatut($this->em->getRepository(PStatut::class)->find(2));
  443.                 $currentNiveau $article->getNiveau()->getId();
  444.                 for ($j$article->getNiveau()->getNiveau(); $j 0$j--) { 
  445.                     $niveau $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  446.                     if($niveau->getStatut()->getDesignation() == "En Cours"){
  447.                         $niveau->setStatut($this->em->getRepository(PStatut::class)->find(2));
  448.                     }
  449.                     if($niveau->getParent()) {
  450.                         $currentNiveau $niveau->getParent()->getId();
  451.                     } else {
  452.                         break;
  453.                     }
  454.                 }
  455.             }
  456.         }
  457.         $this->em->flush();
  458.         return new JsonResponse("Bien Enregistre"200);
  459.     }
  460.     #[Route('/niveau/add'name'article_niveau_add')]
  461.     public function niveauAdd(Request $request): Response
  462.     {
  463.         // dd($request);
  464.         $niveau = new PArticleNiveau();
  465.         if($request->get("parent") != "null"){
  466.             $parentNiveau $this->em->getRepository(PArticleNiveau::class)->find($request->get("parent"));
  467.             $niveau->setParent($parentNiveau);
  468.             if($request->get('cca1') == "" && $request->get('cca2') == "" && $request->get('cca3') == "" && $request->get('cca4') == "") {
  469.                 $niveau->setCCA1($parentNiveau->getCCA1());
  470.                 $niveau->setCCA2($parentNiveau->getCCA2());
  471.                 $niveau->setCCA3($parentNiveau->getCCA3());
  472.                 $niveau->setCCA4($parentNiveau->getCCA4());
  473.             } else {
  474.                 $niveau->setCCA1($request->get('cca1') != "" ?  $request->get('cca1') : null);
  475.                 $niveau->setCCA2($request->get('cca2') != "" ?  $request->get('cca2') : null);
  476.                 $niveau->setCCA3($request->get('cca3') != "" ?  $request->get('cca3') : null);
  477.                 $niveau->setCCA4($request->get('cca4') != "" ?  $request->get('cca4') : null);
  478.             }
  479.         } else {
  480.             $niveau->setCCA1($request->get('cca1') != "" ?  $request->get('cca1') : null);
  481.             $niveau->setCCA2($request->get('cca2') != "" ?  $request->get('cca2') : null);
  482.             $niveau->setCCA3($request->get('cca3') != "" ?  $request->get('cca3') : null);
  483.             $niveau->setCCA4($request->get('cca4') != "" ?  $request->get('cca4') : null);
  484.         }
  485.         $niveau->setNiveau($request->get('niveau'));
  486.         $niveau->setDesignation($request->get('designation'));
  487.         $niveau->setStatut(
  488.             $this->em->getRepository(PStatut::class)->find(1)
  489.         );
  490.         $this->em->persist($niveau);
  491.         $this->em->flush();
  492.         return new JsonResponse(['id' => $niveau->getId(), "designation" => $niveau->getDesignation()], 200);
  493.     }
  494.     #[Route('/article/add'name'article_article_add')]
  495.     public function articleAdd(Request $request): Response
  496.     {
  497.         // dd($request);
  498.         $article $this->em->getRepository(UArticle::class)->findOneBy(['titre' => trim($request->get("titre"))]);
  499.         // dd($article, trim($request->get("titre")));
  500.         if($article) {
  501.             return new JsonResponse("Article déja existe",500);
  502.         }
  503.         $article = new UArticle();
  504.         $article->setTitre(
  505.             $request->get("titre") != "" $request->get("titre") : null
  506.         );
  507.         $article->setPoid(
  508.             $request->get("poid") != "" $request->get("poid") : null
  509.         );
  510.         $article->setUnite(
  511.             $request->get("unite") != "" $this->em->getRepository(PUnite::class)->find($request->get("unite")) : null
  512.         );
  513.         $article->setLongeur(
  514.             $request->get("longeur") != "" $request->get("longeur") : null
  515.         );
  516.         $article->setLargeur(
  517.             $request->get("largeur") != "" $request->get("largeur") : null
  518.         );
  519.         $article->setHauteur(
  520.             $request->get("hauteur") != "" $request->get("hauteur") : null
  521.         );
  522.         $article->setSurface(
  523.             $request->get("surface") != "" $request->get("surface") : null
  524.         );
  525.         $article->setVolume(
  526.             $request->get("volume") != "" $request->get("volume") : null
  527.         );
  528.         $article->setPrixVente(
  529.             $request->get("prix_vente") != "" $request->get("prix_vente") : null
  530.         );
  531.         $article->setPrixVenteMin(
  532.             $request->get("prix_vente_min") != "" $request->get("prix_vente_min") : null
  533.         );
  534.         $article->setPrixVenteMax(
  535.             $request->get("prix_vente_max") != "" $request->get("prix_vente_max") : null
  536.         );
  537.         if($request->get("prix_vente_max") >= && $request->get("prix_vente_min") >= 0) {
  538.             if(($request->get("prix_vente_max") + $request->get("prix_vente_min")) == 0) {
  539.                 $article->setPrixVenteMoyenne(0);
  540.             } else {
  541.                 $article->setPrixVenteMoyenne(($request->get("prix_vente_max") + $request->get("prix_vente_min")) / 2);
  542.                 
  543.             }
  544.         }
  545.         $article->setPrixAchat(
  546.             $request->get("prix_achat") != "" $request->get("prix_achat") : null
  547.         );
  548.         $article->setPrixAchatMin(
  549.             $request->get("prix_achat_min") != "" $request->get("prix_achat_min") : null
  550.         );
  551.         $article->setPrixAchatMax(
  552.             $request->get("prix_achat_max") != "" $request->get("prix_achat_max") : null
  553.         );
  554.         if($request->get("prix_achat_max") >= && $request->get("prix_achat_min") >= 0) {
  555.             if(($request->get("prix_achat_max") + $request->get("prix_achat_min")) == 0) {
  556.                 $article->setPrixAchatMoyenne(0);
  557.             } else {
  558.                 $article->setPrixAchatMoyenne(($request->get("prix_achat_max") + $request->get("prix_achat_min")) / 2);
  559.                 
  560.             }
  561.         }
  562.         $article->setAutreInformation(
  563.             $request->get("autre_infromation") != "" $request->get("autre_infromation") : null
  564.         );
  565.         $article->setDescriptionDetail(
  566.             $request->get("desicription_detail") != "" $request->get("desicription_detail") : null
  567.         );
  568.         $article->setGererEnStock(
  569.             $request->get("gerer_en_stock") ? true false
  570.         );
  571.         $article->setVerificationStock(
  572.             $request->get("verification_stock") ? true false
  573.         );
  574.         $article->setCodeBarre(
  575.             $request->get("code_barre") != "" $request->get("code_barre") : null
  576.         );
  577.         $article->setTva(
  578.             $request->get("tva") != "" $request->get("tva") : null
  579.         );
  580.         $article->setDosage(
  581.             $request->get("dosage") != "" $request->get("dosage") : null
  582.         );
  583.         $article->setDci(
  584.             $request->get("dci") != "" $request->get("dci") : null
  585.         );
  586.         $article->setRemise(
  587.             $request->get("remise") != "" $request->get("remise") : null
  588.         );
  589.         $article->setPrixReference(
  590.             $request->get("prix_reference") != "" $request->get("prix_reference") : null
  591.         );
  592.         $article->setTaille(
  593.             $request->get("taille") != "" $request->get("taille") : null
  594.         );
  595.         $article->setMatiere(
  596.             $request->get("matiere") != "" $request->get("matiere") : null
  597.         );
  598.         $article->setConditionnement(
  599.             $request->get("conditionnement") != "" $request->get("conditionnement") : null
  600.         );
  601.         $article->setMarque(
  602.             $request->get("marque") != "" $request->get("marque") : null
  603.         );
  604.         $article->setMA(
  605.             $request->get("ma") != "" $request->get("ma") : null
  606.         );
  607.         $article->setRefInterne(
  608.             $request->get("reference_interne") != "" $request->get("reference_interne") : null
  609.         );
  610.         $article->setSNS(
  611.             $request->get("sns") != "" $request->get("sns") : null
  612.         );
  613.         $article->setNiveau(
  614.             $this->em->getRepository(PArticleNiveau::class)->find($request->get('niveau'))
  615.         );
  616.         $article->setStatut(
  617.             $this->em->getRepository(PStatut::class)->find(1)
  618.         );
  619.         $article->setActive(true);
  620.         $article->setQteStock($request->get("QTE_STOCK") != "" $request->get("QTE_STOCK") : null);
  621.         $article->setFonCode($request->get("FON_CODE") != "" $request->get("FON_CODE") : null);
  622.         $article->setSpecialiteProduit($request->get("SPECIALITE_PRODUIT") != "" $request->get("SPECIALITE_PRODUIT") : null);
  623.         $article->setSpeCode($request->get("SPE_CODE") != "" $request->get("SPE_CODE") : null);
  624.         $article->setAncienCode($request->get("ANCIEN_CODE") != "" $request->get("ANCIEN_CODE") : null);
  625.         $article->setCodeCat($request->get("CODE_CAT") != "" $request->get("CODE_CAT") : null);
  626.         $article->setClasseProduit($request->get("CLASSE_PRODUIT") != "" $request->get("CLASSE_PRODUIT") : null);
  627.         $article->setSegmentsProduit($request->get("SEGMENTS_PRODUIT") != "" $request->get("SEGMENTS_PRODUIT") : null);
  628.         $article->setSousSegmentsProduit($request->get("SOUS-SEGMENT_PRODUIT") != "" $request->get("SOUS-SEGMENT_PRODUIT") : null);
  629.         $article->setReference($request->get("REFERENCE") != "" $request->get("REFERENCE") : null);
  630.         $article->setVoieAdministration($request->get("VOIE_ADMINISTRATION") != "" $request->get("VOIE_ADMINISTRATION") : null);
  631.         $article->setPresentation($request->get("PRESENTATION") != "" $request->get("PRESENTATION") : null);
  632.         $article->setFabricant($request->get("FABRICANT") != "" $request->get("FABRICANT") : null);
  633.         $article->setFournisseur($request->get("FOURNISSEUR") != "" $request->get("FOURNISSEUR") : null);
  634.         $article->setCodeDci($request->get("CODE_DCI") != "" $request->get("CODE_DCI") : null);
  635.         $article->setEan($request->get("EAN") != "" $request->get("EAN") : null);
  636.         $article->setAtc($request->get("ATC") != "" $request->get("ATC") : null);
  637.         $article->setCodeImm($request->get("CODE_IMM") != "" $request->get("CODE_IMM") : null);
  638.         $article->setEanAccess($request->get("EAN_ACCESS") != "" $request->get("EAN_ACCESS") : null);
  639.         $article->setPrixVentePh($request->get("PRIX_VENTE_PH") != "" $request->get("PRIX_VENTE_PH") : null);
  640.         $article->setPrixVentePpv($request->get("PRIX_VENTE_PPV") != "" $request->get("PRIX_VENTE_PPV") : null);
  641.         $article->setPrixVentePpc($request->get("PRIX_VENTE_PPC") != "" $request->get("PRIX_VENTE_PPC") : null);
  642.         $article->setCleReference($request->get("CLE_REFERENCE") != "" $request->get("CLE_REFERENCE") : null);
  643.         $this->em->persist($article);
  644.         $this->em->flush();
  645.         $article->setCode('ART'str_pad($article->getId(), 6'0'STR_PAD_LEFT));
  646.         $this->em->flush();
  647.         return new JsonResponse("Bien Enregistre",200);
  648.     }
  649.     #[Route('/exporter'name'article_article_exporter')]
  650.       public function exporter(Request $request): Response
  651.     {
  652.         /** @var UArticle[] */
  653.         $articles $this->em->getRepository(UArticle::class)->findAll();
  654.         $array = [];
  655.         foreach ($articles as $article) {
  656.             $arrayOfNiveaux = [];
  657.             if($article->getNiveau()) {
  658.                 $currentNiveau =  $article->getNiveau()->getId();
  659.     
  660.                 for ($j$article->getNiveau()->getNiveau(); $j 0$j--) { 
  661.                     $niveau $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  662.                     array_push($arrayOfNiveaux, [$niveau->getDesignation(), $niveau->getId()]);
  663.                     if($niveau->getParent()) {
  664.                         $currentNiveau $niveau->getParent()->getId();
  665.                     } else {
  666.                         break;
  667.                     }
  668.     
  669.                 }
  670.             }
  671.             // dump($arrayOfNiveaux);
  672.             $arrayOfNiveaux array_reverse($arrayOfNiveaux);
  673.             // dd($arrayOfNiveaux);
  674.             $diffrence count($arrayOfNiveaux);
  675.             if($diffrence 0){
  676.                 for($k 1$k <= $diffrence$k++){
  677.                     array_push($arrayOfNiveaux, [""""]);
  678.                 }
  679.             }
  680.         
  681.             array_push($array, [
  682.                 'id' => $article->getId(),
  683.                 'code' => $article->getCode(),
  684.                 'unite_id' => $article->getUnite()? $article->getUnite()->getId() : "",
  685.                 'unite' => $article->getUnite()? $article->getUnite()->getDesignation() : "",
  686.                 'id_niveau_affecte' =>$article->getNiveau() ? $article->getNiveau()->getId() : "",
  687.                 'id_dossier' =>$arrayOfNiveaux[0][1],
  688.                 'dossier' =>$arrayOfNiveaux[0][0],
  689.                 'id_sous_dossier' =>$arrayOfNiveaux[1][1],
  690.                 'sous_dossier' =>$arrayOfNiveaux[1][0],
  691.                 'id_group' =>$arrayOfNiveaux[2][1],
  692.                 'group' =>$arrayOfNiveaux[2][0],
  693.                 'id_categorie' =>$arrayOfNiveaux[3][1],
  694.                 'categorie' =>$arrayOfNiveaux[3][0],
  695.                 'id_type' =>$arrayOfNiveaux[4][1],
  696.                 'type' =>$arrayOfNiveaux[4][0],
  697.                 'id_famille' =>$arrayOfNiveaux[5][1],
  698.                 'famille' =>$arrayOfNiveaux[5][0],
  699.                 'titre' =>$article->getTitre(),
  700.                 'description' =>$article->getDescription(),
  701.                 'poid' =>$article->getPoid(),
  702.                 'longeur' =>$article->getLongeur(),
  703.                 'largeur' =>$article->getLargeur(),
  704.                 'hauteur' =>$article->getHauteur(),
  705.                 'surface' =>$article->getSurface(),
  706.                 'volume' =>$article->getVolume(),
  707.                 'prixe_vente' =>$article->getPrixVente(),
  708.                 'prix_vente_min' =>$article->getPrixVenteMin(),
  709.                 'prix_vente_max' =>$article->getPrixVenteMax(),
  710.                 'prix_vente_moynne' =>$article->getPrixVenteMoyenne(),
  711.                 'prix_achat' =>$article->getPrixAchat(),
  712.                 'prix_achat_min' =>$article->getPrixAchatMin(),
  713.                 'prix_achat_max' =>$article->getPrixAchatMax(),
  714.                 'prix_achat_moyenne' =>$article->getPrixAchatMoyenne(),
  715.                 'autre_information' =>$article->getAutreInformation(),
  716.                 'description_detail' =>$article->getDescriptionDetail(),
  717.                 'gerer_en_stock' =>$article->getGererEnStock() ? "oui" "non",
  718.                 'verification_stock' =>$article->getVerificationStock() ? "oui" "non",
  719.                 'code_barre' =>$article->getCodeBarre(),
  720.                 'tva' =>$article->getTva(),
  721.                 'dosage' =>$article->getDosage(),
  722.                 'dci' =>$article->getDci(),
  723.                 'remise' =>$article->getRemise(),
  724.                 'prix_reference' =>$article->getPrixReference(),
  725.                 'taille' =>$article->getTaille(),
  726.                 'matiere' =>$article->getMatiere(),
  727.                 'conditionnement' =>$article->getConditionnement(),
  728.                 'notation_technique' =>$article->getNotationTechnique(),
  729.                 'marque' =>$article->getMarque(),
  730.                 'ma' =>$article->getMA(),
  731.                 'famille_article' =>$article->getFamille(),
  732.                 'categorie_article' =>$article->getCategorie(),
  733.                 'ref_interne' =>$article->getRefInterne(),
  734.                 'sns' =>$article->getSNS(),
  735.                 'statut' => $article->getStatut()->getDesignation(),
  736.                 'active' => $article->getActive() ? 'oui' 'non'
  737.             ]);
  738.            
  739.          
  740.         }
  741.         
  742.         return new JsonResponse($array);
  743.     }
  744.     // public function exporter(Request $request): Response
  745.     // {
  746.     //     $articles = $this->em->getRepository(UArticle::class)->findAll();
  747.     //     $spreadsheet = new Spreadsheet();
  748.     //     $sheet = $spreadsheet->getActiveSheet();
  749.     //     $sheet->setCellValue('A1', 'id');
  750.     //     $sheet->setCellValue('B1', 'code');
  751.     //     $sheet->setCellValue('C1', 'unite_id');
  752.     //     $sheet->setCellValue('D1', 'unite');
  753.     //     $sheet->setCellValue('E1', 'id_niveau_affecte');
  754.     //     $sheet->setCellValue('F1', 'id');
  755.     //     $sheet->setCellValue('G1', 'Dossier');
  756.     //     $sheet->setCellValue('H1', 'id');
  757.     //     $sheet->setCellValue('I1', 'Sous dossier');
  758.     //     $sheet->setCellValue('J1', 'id');
  759.     //     $sheet->setCellValue('K1', 'Group');
  760.     //     $sheet->setCellValue('L1', 'id');
  761.     //     $sheet->setCellValue('M1', 'Catégorie');
  762.     //     $sheet->setCellValue('N1', 'id');
  763.     //     $sheet->setCellValue('O1', 'Type');
  764.     //     $sheet->setCellValue('P1', 'id');
  765.     //     $sheet->setCellValue('Q1', 'Famille');
  766.     //     $sheet->setCellValue('R1', 'Titre');
  767.     //     $sheet->setCellValue('S1', 'Description');
  768.     //     $sheet->setCellValue('T1', 'Poid');
  769.     //     $sheet->setCellValue('U1', 'Longeur');
  770.     //     $sheet->setCellValue('V1', 'Largeur');
  771.     //     $sheet->setCellValue('W1', 'Hauteur');
  772.     //     $sheet->setCellValue('X1', 'Surface');
  773.     //     $sheet->setCellValue('Y1', 'Volume');
  774.     //     $sheet->setCellValue('Z1', 'Prix vente');
  775.     //     $sheet->setCellValue('AA1', 'Prix vente min');
  776.     //     $sheet->setCellValue('AB1', 'Prix vente max');
  777.     //     $sheet->setCellValue('AC1', 'Prix vente moyenne');
  778.     //     $sheet->setCellValue('AD1', 'Prix Achat');
  779.     //     $sheet->setCellValue('AE1', 'Prix Achat min');
  780.     //     $sheet->setCellValue('AF1', 'Prix Achat max');
  781.     //     $sheet->setCellValue('AG1', 'Prix Achat moyenne');
  782.     //     $sheet->setCellValue('AH1', 'Autre information');
  783.     //     $sheet->setCellValue('AI1', 'Description detail');
  784.     //     $sheet->setCellValue('AJ1', 'Gerer en stock');
  785.     //     $sheet->setCellValue('AK1', 'Verification stcok');
  786.     //     $sheet->setCellValue('AL1', 'Code Barre');
  787.     //     $sheet->setCellValue('AM1', 'TVA');
  788.     //     $sheet->setCellValue('AN1', 'Dosage');
  789.     //     $sheet->setCellValue('AO1', 'DCI');
  790.     //     $sheet->setCellValue('AP1', 'Remise');
  791.     //     $sheet->setCellValue('AQ1', 'Prix reference');
  792.     //     $sheet->setCellValue('AR1', 'Taille');
  793.     //     $sheet->setCellValue('AS1', 'Matiere');
  794.     //     $sheet->setCellValue('AT1', 'Conditionnement');
  795.     //     $sheet->setCellValue('AU1', 'Notation technique');
  796.     //     $sheet->setCellValue('AV1', 'Marque');
  797.     //     $sheet->setCellValue('AW1', 'M/A');
  798.     //     $sheet->setCellValue('AX1', 'Reference Interne');
  799.     //     $sheet->setCellValue('AY1', 'S/NS');
  800.     //     $sheet->setCellValue('AZ1', 'Statut');
  801.     //     $i = 2;
  802.     //     foreach ($articles as $article) {
  803.     //         $sheet->setCellValue('A'.$i, $article->getId());
  804.     //         $sheet->setCellValue('B'.$i, $article->getCode());
  805.     //         $sheet->setCellValue('C'.$i, $article->getUnite()? $article->getUnite()->getId() : "");
  806.     //         $sheet->setCellValue('D'.$i, $article->getUnite() ? $article->getUnite()->getDesignation() : "");
  807.     //         $sheet->setCellValue('E'.$i, $article->getNiveau() ? $article->getNiveau()->getId() : "");
  808.     //         $arrayOfNiveaux = [];
  809.     //         if($article->getNiveau()) {
  810.     //             $currentNiveau =  $article->getNiveau()->getId();
  811.     
  812.     //             for ($j= $article->getNiveau()->getNiveau(); $j > 0; $j--) { 
  813.     //                 $niveau = $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  814.     //                 array_push($arrayOfNiveaux, [$niveau->getDesignation(), $niveau->getId()]);
  815.     //                 if($niveau->getParent()) {
  816.     //                     $currentNiveau = $niveau->getParent()->getId();
  817.     //                 } else {
  818.     //                     break;
  819.     //                 }
  820.     
  821.     //             }
  822.     //         }
  823.     //         // dump($arrayOfNiveaux);
  824.     //         $arrayOfNiveaux = array_reverse($arrayOfNiveaux);
  825.     //         // dd($arrayOfNiveaux);
  826.     //         $diffrence = 6 - count($arrayOfNiveaux);
  827.     //         if($diffrence > 0){
  828.     //             for($k = 1; $k <= $diffrence; $k++){
  829.     //                 array_push($arrayOfNiveaux, ["", ""]);
  830.     //             }
  831.     //         }
  832.     //         $sheet->setCellValue('F'.$i, $arrayOfNiveaux[0][1]);
  833.     //         $sheet->setCellValue('G'.$i, $arrayOfNiveaux[0][0]);
  834.     //         $sheet->setCellValue('H'.$i, $arrayOfNiveaux[1][1]);
  835.     //         $sheet->setCellValue('I'.$i, $arrayOfNiveaux[1][0]);
  836.     //         $sheet->setCellValue('J'.$i, $arrayOfNiveaux[2][1]);
  837.     //         $sheet->setCellValue('K'.$i, $arrayOfNiveaux[2][0]);
  838.     //         $sheet->setCellValue('L'.$i, $arrayOfNiveaux[3][1]);
  839.     //         $sheet->setCellValue('M'.$i, $arrayOfNiveaux[3][0]);
  840.     //         $sheet->setCellValue('N'.$i, $arrayOfNiveaux[4][1]);
  841.     //         $sheet->setCellValue('O'.$i, $arrayOfNiveaux[4][0]);
  842.     //         $sheet->setCellValue('P'.$i, $arrayOfNiveaux[5][1]);
  843.     //         $sheet->setCellValue('Q'.$i, $arrayOfNiveaux[5][0]);
  844.     //         $sheet->setCellValue('R'.$i, $article->getTitre());
  845.     //         $sheet->setCellValue('S'.$i, $article->getDescription());
  846.     //         $sheet->setCellValue('T'.$i, $article->getPoid());
  847.     //         $sheet->setCellValue('U'.$i, $article->getLongeur());
  848.     //         $sheet->setCellValue('V'.$i, $article->getLargeur());
  849.     //         $sheet->setCellValue('W'.$i, $article->getHauteur());
  850.     //         $sheet->setCellValue('X'.$i, $article->getSurface());
  851.     //         $sheet->setCellValue('Y'.$i, $article->getVolume());
  852.     //         $sheet->setCellValue('Z'.$i, $article->getPrixVente());
  853.     //         $sheet->setCellValue('AA'.$i, $article->getPrixVenteMin());
  854.     //         $sheet->setCellValue('AB'.$i, $article->getPrixVenteMax());
  855.     //         $sheet->setCellValue('AC'.$i, $article->getPrixVenteMoyenne());
  856.     //         $sheet->setCellValue('AD'.$i, $article->getPrixAchat());
  857.     //         $sheet->setCellValue('AE'.$i, $article->getPrixAchatMin());
  858.     //         $sheet->setCellValue('AF'.$i, $article->getPrixAchatMax());
  859.     //         $sheet->setCellValue('AG'.$i, $article->getPrixAchatMoyenne());
  860.     //         $sheet->setCellValue('AH'.$i, $article->getAutreInformation());
  861.     //         $sheet->setCellValue('AI'.$i, $article->getDescriptionDetail());
  862.     //         $sheet->setCellValue('AJ'.$i, $article->getGererEnStock() ? "oui" : "non");
  863.     //         $sheet->setCellValue('AK'.$i, $article->getVerificationStock() ? "oui" : "non");
  864.     //         $sheet->setCellValue('AL'.$i, $article->getCodeBarre());
  865.     //         $sheet->setCellValue('AM'.$i, $article->getTva());
  866.     //         $sheet->setCellValue('AN'.$i, $article->getDosage());
  867.     //         $sheet->setCellValue('AO'.$i, $article->getDci());
  868.     //         $sheet->setCellValue('AP'.$i, $article->getRemise());
  869.     //         $sheet->setCellValue('AQ'.$i, $article->getPrixReference());
  870.     //         $sheet->setCellValue('AR'.$i, $article->getTaille());
  871.     //         $sheet->setCellValue('AS'.$i, $article->getMatiere());
  872.     //         $sheet->setCellValue('AT'.$i, $article->getConditionnement());
  873.     //         $sheet->setCellValue('AU'.$i, $article->getNotationTechnique());
  874.     //         $sheet->setCellValue('AV'.$i, $article->getMarque());
  875.     //         $sheet->setCellValue('AW'.$i, $article->getMA());
  876.     //         $sheet->setCellValue('AX'.$i, $article->getRefInterne());
  877.     //         $sheet->setCellValue('AY'.$i, $article->getSNS());
  878.     //         $sheet->setCellValue('AZ'.$i, $article->getStatut()->getDesignation());
  879.     //         $i++;
  880.     //     }
  881.         
  882.     //     $writer = new Xlsx($spreadsheet);
  883.     //     $fileName = 'articles.xlsx';
  884.     //     $temp_file = tempnam(sys_get_temp_dir(), $fileName);
  885.     //     $writer->save($temp_file);
  886.     //     return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
  887.     //     return new JsonResponse(['id' => $niveau->getId(), "designation" => $niveau->getDesignation()], 200);
  888.     // }
  889.     #[Route('/article/import'name'article_article_import')]
  890.     public function articleImport(Request $request SluggerInterface $slugger): Response
  891.     {
  892.         $file $request->files->get('file');
  893.         // dd($file);
  894.         if(!$file){
  895.             return new JsonResponse('Prière d\'importer le fichier',500);
  896.         }
  897.         if($file->guessExtension() !== 'xlsx'){
  898.             return new JsonResponse('Prière d\'enregister un fichier xlsx'500);            
  899.         }
  900.         $originalFilename pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  901.         // this is needed to safely include the file name as part of the URL
  902.         $safeFilename $slugger->slug($originalFilename);
  903.         $newFilename $safeFilename.'-'.uniqid().'_'.$this->getUser()->getUsername().'.'.$file->guessExtension();
  904.         // Move the file to the directory where brochures are stored
  905.         try {
  906.             $file->move(
  907.                 $this->getParameter('artice_directory'),
  908.                 $newFilename
  909.             );
  910.         } catch (FileException $e) {
  911.             throw new \Exception($e);
  912.         }
  913.         $reader = new reader();
  914.         $spreadsheet $reader->load($this->getParameter('artice_directory').'/'.$newFilename);
  915.         $worksheet $spreadsheet->getActiveSheet();
  916.         $spreadSheetArys $worksheet->toArray();
  917.         unset($spreadSheetArys[0]);
  918.         $sheetCount count($spreadSheetArys);
  919.         foreach ($spreadSheetArys as $sheet) {
  920.             if(trim($sheet[4]) == ""){
  921.                 return new JsonResponse('Veuillez remplir Id niveau',500);
  922.             }
  923.         }
  924.         foreach ($spreadSheetArys as $sheet) {
  925.             // dd();
  926.             $article $this->em->getRepository(UArticle::class)->findOneBy(['titre' => trim($request->get("titre"))]);
  927.         // dd($article, trim($request->get("titre")));
  928.             if(!$article) {
  929.                 $article = new UArticle();
  930.                 $article->setTitre(
  931.                     $sheet[11]
  932.                 );
  933.                 $article->setUnite(
  934.                     $sheet[2] > $this->em->getRepository(PUnite::class)->find($sheet[2]) : null
  935.                 );
  936.                 $article->setDescription(
  937.                     $sheet[12]
  938.                 );
  939.                 $article->setPoid($sheet[13]);
  940.                 $article->setLongeur($sheet[14]);
  941.                 $article->setLargeur($sheet[15]);
  942.                 $article->setHauteur($sheet[16]);
  943.                 $article->setSurface($sheet[17]);
  944.                 $article->setVolume($sheet[18]);
  945.                 $article->setPrixVente($sheet[19]);
  946.                 $article->setPrixVenteMin($sheet[20]);
  947.                 $article->setPrixVenteMax($sheet[21]);
  948.                 if($sheet[21] >= && $sheet[20] >= 0) {
  949.                     if(($sheet[21] + $sheet[20]) == 0) {
  950.                         $article->setPrixVenteMoyenne(0);
  951.                     } else {
  952.                         $article->setPrixVenteMoyenne(($sheet[21] + $sheet[20]) / 2);
  953.                         
  954.                     }
  955.                 }
  956.                 $article->setPrixAchat($sheet[23]);
  957.                 $article->setPrixAchatMin($sheet[24]);
  958.                 $article->setPrixAchatMax($sheet[25]);
  959.                 if($sheet[25] >= && $sheet[24] >= 0) {
  960.                     if(($sheet[25] + $sheet[24]) == 0) {
  961.                         $article->setPrixAchatMoyenne(0);
  962.                     } else {
  963.                         $article->setPrixAchatMoyenne(($sheet[24] + $sheet[25]) / 2);
  964.                         
  965.                     }
  966.                 }
  967.                 $article->setAutreInformation($sheet[27]);
  968.                 $article->setDescriptionDetail($sheet[28]);
  969.                 $article->setGererEnStock($sheet[29] == "oui" true false);
  970.                 $article->setVerificationStock($sheet[30] == "oui" true false);
  971.                 $article->setCodeBarre($sheet[31]);
  972.                 $article->setTva($sheet[32]);
  973.                 $article->setDosage($sheet[33]);
  974.                 $article->setDci($sheet[34]);
  975.                 $article->setRemise($sheet[35]);
  976.                 $article->setPrixReference($sheet[36]);
  977.                 $article->setTaille($sheet[37]);
  978.                 $article->setMatiere($sheet[38]);
  979.                 $article->setConditionnement($sheet[39]);
  980.                 $article->setNotationTechnique($sheet[40]);
  981.                 $article->setMarque($sheet[41]);
  982.                 $article->setMA($sheet[42]);
  983.                 $article->setRefInterne((float)$sheet[43]);
  984.                 $article->setSNS($sheet[44]);
  985.                 $article->setQteStock($sheet[45]);
  986.                 $article->setFonCode($sheet[46]);
  987.                 $article->setSpecialiteProduit($sheet[47]);
  988.                 $article->setSpeCode($sheet[48]);
  989.                 $article->setAncienCode($sheet[49]);
  990.                 $article->setCodeCat($sheet[50]);
  991.                 $article->setClasseProduit($sheet[51]);
  992.                 $article->setSegmentsProduit($sheet[52]);
  993.                 $article->setSousSegmentsProduit($sheet[53]);
  994.                 $article->setReference($sheet[54]);
  995.                 $article->setVoieAdministration($sheet[55]);
  996.                 $article->setPresentation($sheet[56]);
  997.                 $article->setFabricant($sheet[57]);
  998.                 $article->setFournisseur($sheet[58]);
  999.                 $article->setCodeDci($sheet[59]);
  1000.                 $article->setEan($sheet[60]);
  1001.                 $article->setAtc($sheet[61]);
  1002.                 $article->setCodeImm($sheet[62]);
  1003.                 $article->setEanAccess($sheet[63]);
  1004.                 $article->setPrixVentePh($sheet[64]);
  1005.                 $article->setPrixVentePpv($sheet[65]);
  1006.                 $article->setPrixVentePpc($sheet[66]);
  1007.                 $article->setCleReference($sheet[67]);
  1008.                 $article->setNiveau(
  1009.                     $sheet[4] > $this->em->getRepository(PArticleNiveau::class)->find($sheet[4]) : null
  1010.                 );
  1011.                 $article->setStatut(
  1012.                     $this->em->getRepository(PStatut::class)->find(1)
  1013.                 );
  1014.                 $article->setActive(true);
  1015.                 $this->em->persist($article);
  1016.                 $this->em->flush();
  1017.                 $article->setCode('ART'str_pad($article->getId(), 6'0'STR_PAD_LEFT));
  1018.                 $this->em->flush();
  1019.             }
  1020.             
  1021.         }
  1022.         return new JsonResponse("Total des articles crée est ".$sheetCount);
  1023.         
  1024.     }
  1025.     #[Route('/article/miseajour'name'article_article_miseajour')]
  1026.     public function articleMiseAJour(Request $request SluggerInterface $slugger): Response
  1027.     {
  1028.         $file $request->files->get('file');
  1029.         // dd($file);
  1030.         if(!$file){
  1031.             return new JsonResponse('Prière d\'importer le fichier',500);
  1032.         }
  1033.         if($file->guessExtension() !== 'xlsx'){
  1034.             return new JsonResponse('Prière d\'enregister un fichier xlsx'500);            
  1035.         }
  1036.         $originalFilename pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  1037.         // this is needed to safely include the file name as part of the URL
  1038.         $safeFilename $slugger->slug($originalFilename);
  1039.         $newFilename $safeFilename.'-'.uniqid().'_'.$this->getUser()->getUsername().'.'.$file->guessExtension();
  1040.         // Move the file to the directory where brochures are stored
  1041.         try {
  1042.             $file->move(
  1043.                 $this->getParameter('artice_directory'),
  1044.                 $newFilename
  1045.             );
  1046.         } catch (FileException $e) {
  1047.             throw new \Exception($e);
  1048.         }
  1049.         $reader = new reader();
  1050.         $spreadsheet $reader->load($this->getParameter('artice_directory').'/'.$newFilename);
  1051.         $worksheet $spreadsheet->getActiveSheet();
  1052.         $spreadSheetArys $worksheet->toArray();
  1053.         unset($spreadSheetArys[0]);
  1054.         $sheetCount count($spreadSheetArys);
  1055.         foreach ($spreadSheetArys as $sheet) {
  1056.             // dd();
  1057.             $article $this->em->getRepository(UArticle::class)->find($sheet[0]);
  1058.             if($article) {
  1059.                 $article->setTitre(
  1060.                     $sheet[11]
  1061.                 );
  1062.                 $article->setUnite(
  1063.                     $sheet[2] > $this->em->getRepository(PUnite::class)->find($sheet[2]) : null
  1064.                 );
  1065.                 $article->setDescription(
  1066.                     $sheet[12]
  1067.                 );
  1068.                 $article->setPoid($sheet[13]);
  1069.                 $article->setLongeur($sheet[14]);
  1070.                 $article->setLargeur($sheet[15]);
  1071.                 $article->setHauteur($sheet[16]);
  1072.                 $article->setSurface($sheet[17]);
  1073.                 $article->setVolume($sheet[18]);
  1074.                 $article->setPrixVente($sheet[19]);
  1075.                 $article->setPrixVenteMin($sheet[20]);
  1076.                 $article->setPrixVenteMax($sheet[21]);
  1077.                 if($sheet[21] >= && $sheet[20] >= 0) {
  1078.                     if(($sheet[21] + $sheet[20]) == 0) {
  1079.                         $article->setPrixVenteMoyenne(0);
  1080.                     } else {
  1081.                         $article->setPrixVenteMoyenne(($sheet[21] + $sheet[20]) / 2);
  1082.                         
  1083.                     }
  1084.                 }
  1085.                 $article->setPrixAchat($sheet[23]);
  1086.                 $article->setPrixAchatMin($sheet[24]);
  1087.                 $article->setPrixAchatMax($sheet[25]);
  1088.                 if($sheet[25] >= && $sheet[24] >= 0) {
  1089.                     if(($sheet[25] + $sheet[24]) == 0) {
  1090.                         $article->setPrixAchatMoyenne(0);
  1091.                     } else {
  1092.                         $article->setPrixAchatMoyenne(($sheet[24] + $sheet[25]) / 2);
  1093.                         
  1094.                     }
  1095.                 }
  1096.                 $article->setAutreInformation($sheet[27]);
  1097.                 $article->setDescriptionDetail($sheet[28]);
  1098.                 $article->setGererEnStock($sheet[29] == "oui" true false);
  1099.                 $article->setVerificationStock($sheet[30] == "oui" true false);
  1100.                 $article->setCodeBarre($sheet[31]);
  1101.                 $article->setTva($sheet[32]);
  1102.                 $article->setDosage($sheet[33]);
  1103.                 $article->setDci($sheet[34]);
  1104.                 $article->setRemise($sheet[35]);
  1105.                 $article->setPrixReference($sheet[36]);
  1106.                 $article->setTaille($sheet[37]);
  1107.                 $article->setMatiere($sheet[38]);
  1108.                 $article->setConditionnement($sheet[39]);
  1109.                 $article->setMarque($sheet[40]);
  1110.                 $article->setMA($sheet[41]);
  1111.                 $article->setRefInterne($sheet[42]);
  1112.                 $article->setSNS($sheet[43]);
  1113.                 $article->setNiveau(
  1114.                     $sheet[4] > $this->em->getRepository(PArticleNiveau::class)->find($sheet[4]) : null
  1115.                 );
  1116.                 
  1117.             }
  1118.             $this->em->flush();
  1119.             
  1120.         }
  1121.         return new JsonResponse("Total des articles à jour est ".$sheetCount);
  1122.         
  1123.     }
  1124.     #[Route('/article/details/update/{article}'name'article_article_details_update')]
  1125.     public function articleDetailsUpdate(UArticle $article): Response
  1126.     {
  1127.         $arrayOfNiveaux = [];
  1128.         $currentNiveau $article->getNiveau()->getId();
  1129.         for ($j$article->getNiveau()->getNiveau(); $j 0$j--) { 
  1130.             $niveau $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  1131.             array_push($arrayOfNiveaux$niveau);
  1132.             if($niveau->getParent()) {
  1133.                 $currentNiveau $niveau->getParent()->getId();
  1134.             } else {
  1135.                 break;
  1136.             }
  1137.         }
  1138.         // dump($arrayOfNiveaux);
  1139.         $arrayOfNiveaux array_reverse($arrayOfNiveaux);
  1140.         // dd($arrayOfNiveaux);
  1141.         $diffrence count($arrayOfNiveaux);
  1142.         if($diffrence 0){
  1143.             for($k 1$k <= $diffrence$k++){
  1144.                 array_push($arrayOfNiveauxnull);
  1145.             }
  1146.         }
  1147.         $html $this->render("article/pages/form_update.html.twig", [
  1148.             'article' => $article,
  1149.             'niveauxAffecte' => $arrayOfNiveaux,
  1150.             'niveaux' => $this->em->getRepository(PArticleNiveau::class)->findBy(['parent' => null]),
  1151.             'unites' => $this->em->getRepository(PUnite::class)->findAll()
  1152.         ])->getContent();
  1153.         return new JsonResponse([
  1154.             "html" => $html,
  1155.             'title' => $article->getTitre()
  1156.         ]);
  1157.     }
  1158.     #[Route('/article/update/{article}'name'article_article_details_update_save')]
  1159.     public function articleUpdate(Request $requestUArticle $article): Response
  1160.     {
  1161.         $article->setTitre(
  1162.             $request->get("titre") != "" $request->get("titre") : null
  1163.         );
  1164.         $article->setPoid(
  1165.             $request->get("poid") != "" $request->get("poid") : null
  1166.         );
  1167.         $article->setUnite(
  1168.             $request->get("unite") != "" $this->em->getRepository(PUnite::class)->find($request->get("unite")) : null
  1169.         );
  1170.         $article->setLongeur(
  1171.             $request->get("longeur") != "" $request->get("longeur") : null
  1172.         );
  1173.         $article->setLargeur(
  1174.             $request->get("largeur") != "" $request->get("largeur") : null
  1175.         );
  1176.         $article->setHauteur(
  1177.             $request->get("hauteur") != "" $request->get("hauteur") : null
  1178.         );
  1179.         $article->setSurface(
  1180.             $request->get("surface") != "" $request->get("surface") : null
  1181.         );
  1182.         $article->setVolume(
  1183.             $request->get("volume") != "" $request->get("volume") : null
  1184.         );
  1185.         $article->setPrixVente(
  1186.             $request->get("prix_vente") != "" $request->get("prix_vente") : null
  1187.         );
  1188.         $article->setPrixVenteMin(
  1189.             $request->get("prix_vente_min") != "" $request->get("prix_vente_min") : null
  1190.         );
  1191.         $article->setPrixVenteMax(
  1192.             $request->get("prix_vente_max") != "" $request->get("prix_vente_max") : null
  1193.         );
  1194.         if($request->get("prix_vente_max") >= && $request->get("prix_vente_min") >= 0) {
  1195.             if(($request->get("prix_vente_max") + $request->get("prix_vente_min")) == 0) {
  1196.                 $article->setPrixVenteMoyenne(0);
  1197.             } else {
  1198.                 $article->setPrixVenteMoyenne(($request->get("prix_vente_max") + $request->get("prix_vente_min")) / 2);
  1199.                 
  1200.             }
  1201.         }
  1202.         $article->setPrixAchat(
  1203.             $request->get("prix_achat") != "" $request->get("prix_achat") : null
  1204.         );
  1205.         $article->setPrixAchatMin(
  1206.             $request->get("prix_achat_min") != "" $request->get("prix_achat_min") : null
  1207.         );
  1208.         $article->setPrixAchatMax(
  1209.             $request->get("prix_achat_max") != "" $request->get("prix_achat_max") : null
  1210.         );
  1211.         if($request->get("prix_achat_max") >= && $request->get("prix_achat_min") >= 0) {
  1212.             if(($request->get("prix_achat_max") + $request->get("prix_achat_min")) == 0) {
  1213.                 $article->setPrixAchatMoyenne(0);
  1214.             } else {
  1215.                 $article->setPrixAchatMoyenne(($request->get("prix_achat_max") + $request->get("prix_achat_min")) / 2);
  1216.                 
  1217.             }
  1218.         }
  1219.         $article->setAutreInformation(
  1220.             $request->get("autre_infromation") != "" $request->get("autre_infromation") : null
  1221.         );
  1222.         $article->setDescriptionDetail(
  1223.             $request->get("desicription_detail") != "" $request->get("desicription_detail") : null
  1224.         );
  1225.         $article->setGererEnStock(
  1226.             $request->get("gerer_en_stock") ? true false
  1227.         );
  1228.         $article->setVerificationStock(
  1229.             $request->get("verification_stock") ? true false
  1230.         );
  1231.         $article->setCodeBarre(
  1232.             $request->get("code_barre") != "" $request->get("code_barre") : null
  1233.         );
  1234.         $article->setTva(
  1235.             $request->get("tva") != "" $request->get("tva") : null
  1236.         );
  1237.         $article->setDosage(
  1238.             $request->get("dosage") != "" $request->get("dosage") : null
  1239.         );
  1240.         $article->setDci(
  1241.             $request->get("dci") != "" $request->get("dci") : null
  1242.         );
  1243.         $article->setRemise(
  1244.             $request->get("remise") != "" $request->get("remise") : null
  1245.         );
  1246.         $article->setPrixReference(
  1247.             $request->get("prix_reference") != "" $request->get("prix_reference") : null
  1248.         );
  1249.         $article->setTaille(
  1250.             $request->get("taille") != "" $request->get("taille") : null
  1251.         );
  1252.         $article->setMatiere(
  1253.             $request->get("matiere") != "" $request->get("matiere") : null
  1254.         );
  1255.         $article->setConditionnement(
  1256.             $request->get("conditionnement") != "" $request->get("conditionnement") : null
  1257.         );
  1258.         $article->setMarque(
  1259.             $request->get("marque") != "" $request->get("marque") : null
  1260.         );
  1261.         $article->setMA(
  1262.             $request->get("ma") != "" $request->get("ma") : null
  1263.         );
  1264.         $article->setRefInterne(
  1265.             $request->get("reference_interne") != "" $request->get("reference_interne") : null
  1266.         );
  1267.         $article->setSNS(
  1268.             $request->get("sns") != "" $request->get("sns") : null
  1269.         );
  1270.         $article->setNiveau(
  1271.             $this->em->getRepository(PArticleNiveau::class)->find($request->get('niveau'))
  1272.         );
  1273.         $article->setQteStock($request->get("QTE_STOCK") != "" $request->get("QTE_STOCK") : null);
  1274.         $article->setFonCode($request->get("FON_CODE") != "" $request->get("FON_CODE") : null);
  1275.         $article->setSpecialiteProduit($request->get("SPECIALITE_PRODUIT") != "" $request->get("SPECIALITE_PRODUIT") : null);
  1276.         $article->setSpeCode($request->get("SPE_CODE") != "" $request->get("SPE_CODE") : null);
  1277.         $article->setAncienCode($request->get("ANCIEN_CODE") != "" $request->get("ANCIEN_CODE") : null);
  1278.         $article->setCodeCat($request->get("CODE_CAT") != "" $request->get("CODE_CAT") : null);
  1279.         $article->setClasseProduit($request->get("CLASSE_PRODUIT") != "" $request->get("CLASSE_PRODUIT") : null);
  1280.         $article->setSegmentsProduit($request->get("SEGMENTS_PRODUIT") != "" $request->get("SEGMENTS_PRODUIT") : null);
  1281.         $article->setSousSegmentsProduit($request->get("SOUS-SEGMENT_PRODUIT") != "" $request->get("SOUS-SEGMENT_PRODUIT") : null);
  1282.         $article->setReference($request->get("REFERENCE") != "" $request->get("REFERENCE") : null);
  1283.         $article->setVoieAdministration($request->get("VOIE_ADMINISTRATION") != "" $request->get("VOIE_ADMINISTRATION") : null);
  1284.         $article->setPresentation($request->get("PRESENTATION") != "" $request->get("PRESENTATION") : null);
  1285.         $article->setFabricant($request->get("FABRICANT") != "" $request->get("FABRICANT") : null);
  1286.         $article->setFournisseur($request->get("FOURNISSEUR") != "" $request->get("FOURNISSEUR") : null);
  1287.         $article->setCodeDci($request->get("CODE_DCI") != "" $request->get("CODE_DCI") : null);
  1288.         $article->setEan($request->get("EAN") != "" $request->get("EAN") : null);
  1289.         $article->setAtc($request->get("ATC") != "" $request->get("ATC") : null);
  1290.         $article->setCodeImm($request->get("CODE_IMM") != "" $request->get("CODE_IMM") : null);
  1291.         $article->setEanAccess($request->get("EAN_ACCESS") != "" $request->get("EAN_ACCESS") : null);
  1292.         $article->setPrixVentePh($request->get("PRIX_VENTE_PH") != "" $request->get("PRIX_VENTE_PH") : null);
  1293.         $article->setPrixVentePpv($request->get("PRIX_VENTE_PPV") != "" $request->get("PRIX_VENTE_PPV") : null);
  1294.         $article->setPrixVentePpc($request->get("PRIX_VENTE_PPC") != "" $request->get("PRIX_VENTE_PPC") : null);
  1295.         $article->setCleReference($request->get("CLE_REFERENCE") != "" $request->get("CLE_REFERENCE") : null);
  1296.         if($article->getStatut()->getDesignation() == "Intégrer") {
  1297.             $article->setStatut(
  1298.                 $this->em->getRepository(PStatut::class)->find(4)
  1299.             );
  1300.         }
  1301.         
  1302.         $this->em->flush();
  1303.         return new JsonResponse("Bien Enregistre",200);
  1304.     }
  1305.     #[Route('/article/integere'name'article_article_integere')]
  1306.     public function articleintegere(Request $requestHttpClientInterface $client): Response
  1307.     {   
  1308.         $insert 0;
  1309.         $updated 0;
  1310.         /** @var UArticle[] */
  1311.         $articles $this->em->getRepository(UArticle::class)->findBy(['statut' => $this->em->getRepository(PStatut::class)->find(4)]);
  1312.         // dd($articles);
  1313.         
  1314.         foreach($articles as $article) {
  1315.                 // dd($this->getParameter("api")."/api/insert/article");
  1316.             $response $client->request('POST'$this->getParameter("api")."/api/insert/article", [
  1317.                 'body' => [
  1318.                     'id' => $article->getId(),
  1319.                     'unite' => $article->getUnite() ? $article->getUnite()->getId() : null,
  1320.                     'niveau' => $article->getNiveau()->getId(),
  1321.                     'code' => $article->getCode(),
  1322.                     'titre' => $article->getTitre(),
  1323.                     'description' => $article->getDescription(),
  1324.                     'poid' => $article->getPoid(),
  1325.                     'longeur' => $article->getLongeur(),
  1326.                     'largeur' => $article->getLargeur(),
  1327.                     'hauteur' => $article->getHauteur(),
  1328.                     'surface' => $article->getSurface(),
  1329.                     'famille_article' =>$article->getFamille(),
  1330.                     'categorie_article' =>$article->getCategorie(),
  1331.                     'volume' => $article->getVolume(),
  1332.                     'prix_vente' => $article->getPrixVente(),
  1333.                     'prix_vente_min' => $article->getPrixVenteMin(),
  1334.                     'prix_vente_max' => $article->getPrixVenteMax(),
  1335.                     'prix_vente_moyenne' => $article->getPrixVenteMoyenne(),
  1336.                     'prix_achat' => $article->getPrixAchat(),
  1337.                     'prix_achat_min' => $article->getPrixAchatMin(),
  1338.                     'prix_achat_max' => $article->getPrixAchatMax(),
  1339.                     'prix_achat_moyenne' => $article->getPrixAchatMoyenne(),
  1340.                     'active' => $article->getActive(),
  1341.                     'autre_information' => $article->getAutreInformation(),
  1342.                     'descirption_detail' => $article->getDescriptionDetail(),
  1343.                     'gerer_en_stock' => $article->getGererEnStock(),
  1344.                     'verification_stock' => $article->getVerificationStock(),
  1345.                     'code_barre' => $article->getCodeBarre(),
  1346.                     'tva' => $article->getTVA(),
  1347.                     'dosage' => $article->getDosage(),
  1348.                     'dci' => $article->getDCI(),
  1349.                     'remise' => $article->getRemise(),
  1350.                     'prix_reference' => $article->getPrixReference(),
  1351.                     'taille' => $article->getTaille(),
  1352.                     'matiere' => $article->getMatiere(),
  1353.                     'conditionnement' => $article->getConditionnement(),
  1354.                     'notation_technique' => $article->getNotationTechnique(),
  1355.                     'marque' => $article->getMarque(),
  1356.                     'ai' => $article->getAi(),
  1357.                     'av' => $article->getAv(),
  1358.                     'ma' => $article->getMa(),
  1359.                     'ref_interne' => $article->getRefInterne(),
  1360.                     'sns' => $article->getSns(),
  1361.                     'statut_id' => $article->getStatut()->getId(),
  1362.                     'etat_achat' => $article->getEtatAchat(),
  1363.                     'etat_vente' => $article->getEtatVente(),
  1364.                     'qte_stock' => $article->getQteStock(),
  1365.                     'fon_code' => $article->getFonCode(),
  1366.                     'specialite_produit' => $article->getSpecialiteProduit(),
  1367.                     'spe_code' => $article->getSpeCode(),
  1368.                     'ancien_code' => $article->getAncienCode(),
  1369.                     'code_cat' => $article->getCodeCat(),
  1370.                     'classe_produit' => $article->getClasseProduit(),
  1371.                     'segments_produit' => $article->getSegmentsProduit(),
  1372.                     'sous_segment_produit' => $article->getSousSegmentsProduit(),
  1373.                     'reference' => $article->getReference(),
  1374.                     'voie_administration' => $article->getVoieAdministration(),
  1375.                     'presentation' => $article->getPresentation(),
  1376.                     'fabricant' => $article->getFabricant(),
  1377.                     'fournisseur' => $article->getFournisseur(),
  1378.                     'code_dci' => $article->getCodeDci(),
  1379.                     'ean' => $article->getEan(),
  1380.                     'atc' => $article->getAtc(),
  1381.                     'code_imm' => $article->getCodeImm(),
  1382.                     'ean_access' => $article->getEanAccess(),
  1383.                     'prix_vente_ph' => $article->getPrixVentePh(),
  1384.                     'prix_vente_ppv' => $article->getPrixVentePpv(),
  1385.                     'prix_vente_ppc' => $article->getPrixVentePpc(),
  1386.                     'cle_reference' => $article->getCleReference(),
  1387.                 ],
  1388.             ]);
  1389.             if($response->getContent() == "good") {
  1390.                 $article->setStatut(
  1391.                     $this->em->getRepository(PStatut::class)->find(3)
  1392.                 );
  1393.                 $updated++;
  1394.             }
  1395.             
  1396.            
  1397.             
  1398.         }
  1399.         $idArticles json_decode($request->get('articles'));
  1400.         foreach($idArticles as $idArticle) {
  1401.             $article $this->em->getRepository(UArticle::class)->find($idArticle);
  1402.             if($article->getStatut()->getDesignation() == "Valider"){
  1403.                 // dd($this->getParameter("api")."/api/insert/article");
  1404.                 
  1405.                 $idNiveaux ApiController::pluckParent($article->getNiveau());
  1406.                 // i reversed the array because [18051, 18050, X, Y, Z, A]
  1407.                 // imagine 18051 is the Level 6 and 18050 is the level 5 and both are new levels not inserted in ugouv.
  1408.                 // when u try to insert the first value means the level 6 he will try to find the parent id in ugouv but also the lvl 5 not inserted yet will persist a null on parent id 
  1409.                 // thats why i reversed the array to start with the revent level to the last level to prevent that bug
  1410.                 $idNiveauxReversed array_reverse($idNiveaux);
  1411.                 foreach($idNiveauxReversed as $idNiveau) {
  1412.                     
  1413.                     $niveau $this->em->getRepository(PArticleNiveau::class)->find($idNiveau);
  1414.                     if($niveau->getStatut()->getDesignation() == "Valider") {
  1415.                         $response $client->request('POST'$this->getParameter("api")."/api/insert/niveau", [
  1416.                             'body' => [
  1417.                                 'id' => $niveau->getId(),
  1418.                                 'parent' => $niveau->getParent() ? $niveau->getParent()->getId() : '',
  1419.                                 'niveau' => $niveau->getNiveau(),
  1420.                                 'designation' => $niveau->getDesignation(),
  1421.                                 'cca1' => $niveau->getCCA1(),
  1422.                                 'cca2' => $niveau->getCCA2(),
  1423.                                 'cca3' => $niveau->getCCA3(),
  1424.                                 'cca4' => $niveau->getCCA4(),
  1425.                                 
  1426.                             ],
  1427.                         ]);
  1428.                         // dd($response->getContent());
  1429.                         if($response->getContent() == "good") {
  1430.                             $niveau->setStatut(
  1431.                                 $this->em->getRepository(PStatut::class)->find(3)
  1432.                             );
  1433.                         }
  1434.                         // dump($response->getContent());
  1435.                     }
  1436.                     
  1437.                 }
  1438.                 // die;
  1439.                 $response $client->request('POST'$this->getParameter("api")."/api/insert/article", [
  1440.                     
  1441.                     'body' => [
  1442.                         'id' => $article->getId(),
  1443.                         'unite' => $article->getUnite() ? $article->getUnite()->getId() : null,
  1444.                         'niveau' => $article->getNiveau()->getId(),
  1445.                         'code' => $article->getCode(),
  1446.                         'titre' => $article->getTitre(),
  1447.                         'description' => $article->getDescription(),
  1448.                         'poid' => $article->getPoid(),
  1449.                         'longeur' => $article->getLongeur(),
  1450.                         'largeur' => $article->getLargeur(),
  1451.                         'hauteur' => $article->getHauteur(),
  1452.                         'surface' => $article->getSurface(),
  1453.                         'famille_article' =>$article->getFamille(),
  1454.                         'categorie_article' =>$article->getCategorie(),
  1455.                         'volume' => $article->getVolume(),
  1456.                         'prix_vente' => $article->getPrixVente(),
  1457.                         'prix_vente_min' => $article->getPrixVenteMin(),
  1458.                         'prix_vente_max' => $article->getPrixVenteMax(),
  1459.                         'prix_vente_moyenne' => $article->getPrixVenteMoyenne(),
  1460.                         'prix_achat' => $article->getPrixAchat(),
  1461.                         'prix_achat_min' => $article->getPrixAchatMin(),
  1462.                         'prix_achat_max' => $article->getPrixAchatMax(),
  1463.                         'prix_achat_moyenne' => $article->getPrixAchatMoyenne(),
  1464.                         'active' => $article->getActive(),
  1465.                         'autre_information' => $article->getAutreInformation(),
  1466.                         'descirption_detail' => $article->getDescriptionDetail(),
  1467.                         'gerer_en_stock' => $article->getGererEnStock(),
  1468.                         'verification_stock' => $article->getVerificationStock(),
  1469.                         'code_barre' => $article->getCodeBarre(),
  1470.                         'tva' => $article->getTVA(),
  1471.                         'dosage' => $article->getDosage(),
  1472.                         'dci' => $article->getDCI(),
  1473.                         'remise' => $article->getRemise(),
  1474.                         'prix_reference' => $article->getPrixReference(),
  1475.                         'taille' => $article->getTaille(),
  1476.                         'matiere' => $article->getMatiere(),
  1477.                         'conditionnement' => $article->getConditionnement(),
  1478.                         'notation_technique' => $article->getNotationTechnique(),
  1479.                         'marque' => $article->getMarque(),
  1480.                         'ai' => $article->getAi(),
  1481.                         'av' => $article->getAv(),
  1482.                         'ma' => $article->getMa(),
  1483.                         'ref_interne' => $article->getRefInterne(),
  1484.                         'sns' => $article->getSns(),
  1485.                         'statut_id' => $article->getStatut()->getId(),
  1486.                         'etat_achat' => $article->getEtatAchat(),
  1487.                         'etat_vente' => $article->getEtatVente(),
  1488.                         'cle_reference' => $article->getCleReference(),
  1489.                     ],
  1490.                 ]);
  1491.                 if($response->getContent() == "good") {
  1492.                     $article->setStatut(
  1493.                         $this->em->getRepository(PStatut::class)->find(3)
  1494.                     );
  1495.                     $insert++;
  1496.                 }
  1497.                 
  1498.             }
  1499.         }
  1500.         
  1501.         
  1502.         $this->em->flush();
  1503.         return new JsonResponse(['insert' => $insert'updated' => $updated],200);
  1504.     }
  1505. }