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->setFamille(
  611.             $request->get("famille_s") != "" $request->get("famille_s") : null
  612.         );
  613.         $article->setCategorie(
  614.             $request->get("categorie_s") != "" $request->get("categorie_s") : null
  615.         );
  616.         $article->setSNS(
  617.             $request->get("sns") != "" $request->get("sns") : null
  618.         );
  619.         $article->setNiveau(
  620.             $this->em->getRepository(PArticleNiveau::class)->find($request->get('niveau'))
  621.         );
  622.         $article->setStatut(
  623.             $this->em->getRepository(PStatut::class)->find(1)
  624.         );
  625.         $article->setActive(true);
  626.         $article->setQteStock($request->get("QTE_STOCK") != "" $request->get("QTE_STOCK") : null);
  627.         $article->setFonCode($request->get("FON_CODE") != "" $request->get("FON_CODE") : null);
  628.         $article->setSpecialiteProduit($request->get("SPECIALITE_PRODUIT") != "" $request->get("SPECIALITE_PRODUIT") : null);
  629.         $article->setSpeCode($request->get("SPE_CODE") != "" $request->get("SPE_CODE") : null);
  630.         $article->setAncienCode($request->get("ANCIEN_CODE") != "" $request->get("ANCIEN_CODE") : null);
  631.         $article->setCodeCat($request->get("CODE_CAT") != "" $request->get("CODE_CAT") : null);
  632.         $article->setClasseProduit($request->get("CLASSE_PRODUIT") != "" $request->get("CLASSE_PRODUIT") : null);
  633.         $article->setSegmentsProduit($request->get("SEGMENTS_PRODUIT") != "" $request->get("SEGMENTS_PRODUIT") : null);
  634.         $article->setSousSegmentsProduit($request->get("SOUS-SEGMENT_PRODUIT") != "" $request->get("SOUS-SEGMENT_PRODUIT") : null);
  635.         $article->setReference($request->get("REFERENCE") != "" $request->get("REFERENCE") : null);
  636.         $article->setVoieAdministration($request->get("VOIE_ADMINISTRATION") != "" $request->get("VOIE_ADMINISTRATION") : null);
  637.         $article->setPresentation($request->get("PRESENTATION") != "" $request->get("PRESENTATION") : null);
  638.         $article->setFabricant($request->get("FABRICANT") != "" $request->get("FABRICANT") : null);
  639.         $article->setFournisseur($request->get("FOURNISSEUR") != "" $request->get("FOURNISSEUR") : null);
  640.         $article->setCodeDci($request->get("CODE_DCI") != "" $request->get("CODE_DCI") : null);
  641.         $article->setEan($request->get("EAN") != "" $request->get("EAN") : null);
  642.         $article->setAtc($request->get("ATC") != "" $request->get("ATC") : null);
  643.         $article->setCodeImm($request->get("CODE_IMM") != "" $request->get("CODE_IMM") : null);
  644.         $article->setEanAccess($request->get("EAN_ACCESS") != "" $request->get("EAN_ACCESS") : null);
  645.         $article->setPrixVentePh($request->get("PRIX_VENTE_PH") != "" $request->get("PRIX_VENTE_PH") : null);
  646.         $article->setPrixVentePpv($request->get("PRIX_VENTE_PPV") != "" $request->get("PRIX_VENTE_PPV") : null);
  647.         $article->setPrixVentePpc($request->get("PRIX_VENTE_PPC") != "" $request->get("PRIX_VENTE_PPC") : null);
  648.         $article->setCleReference($request->get("CLE_REFERENCE") != "" $request->get("CLE_REFERENCE") : null);
  649.         $this->em->persist($article);
  650.         $this->em->flush();
  651.         $article->setCode('ART'str_pad($article->getId(), 6'0'STR_PAD_LEFT));
  652.         $this->em->flush();
  653.         return new JsonResponse("Bien Enregistre",200);
  654.     }
  655.     #[Route('/exporter'name'article_article_exporter')]
  656.       public function exporter(Request $request): Response
  657.     {
  658.         /** @var UArticle[] */
  659.         $articles $this->em->getRepository(UArticle::class)->findAll();
  660.         $array = [];
  661.         foreach ($articles as $article) {
  662.             $arrayOfNiveaux = [];
  663.             if($article->getNiveau()) {
  664.                 $currentNiveau =  $article->getNiveau()->getId();
  665.     
  666.                 for ($j$article->getNiveau()->getNiveau(); $j 0$j--) { 
  667.                     $niveau $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  668.                     array_push($arrayOfNiveaux, [$niveau->getDesignation(), $niveau->getId()]);
  669.                     if($niveau->getParent()) {
  670.                         $currentNiveau $niveau->getParent()->getId();
  671.                     } else {
  672.                         break;
  673.                     }
  674.     
  675.                 }
  676.             }
  677.             // dump($arrayOfNiveaux);
  678.             $arrayOfNiveaux array_reverse($arrayOfNiveaux);
  679.             // dd($arrayOfNiveaux);
  680.             $diffrence count($arrayOfNiveaux);
  681.             if($diffrence 0){
  682.                 for($k 1$k <= $diffrence$k++){
  683.                     array_push($arrayOfNiveaux, [""""]);
  684.                 }
  685.             }
  686.         
  687.             array_push($array, [
  688.                 'id' => $article->getId(),
  689.                 'code' => $article->getCode(),
  690.                 'unite_id' => $article->getUnite()? $article->getUnite()->getId() : "",
  691.                 'unite' => $article->getUnite()? $article->getUnite()->getDesignation() : "",
  692.                 'id_niveau_affecte' =>$article->getNiveau() ? $article->getNiveau()->getId() : "",
  693.                 'id_dossier' =>$arrayOfNiveaux[0][1],
  694.                 'dossier' =>$arrayOfNiveaux[0][0],
  695.                 'id_sous_dossier' =>$arrayOfNiveaux[1][1],
  696.                 'sous_dossier' =>$arrayOfNiveaux[1][0],
  697.                 'id_group' =>$arrayOfNiveaux[2][1],
  698.                 'group' =>$arrayOfNiveaux[2][0],
  699.                 'id_categorie' =>$arrayOfNiveaux[3][1],
  700.                 'categorie' =>$arrayOfNiveaux[3][0],
  701.                 'id_type' =>$arrayOfNiveaux[4][1],
  702.                 'type' =>$arrayOfNiveaux[4][0],
  703.                 'id_famille' =>$arrayOfNiveaux[5][1],
  704.                 'famille' =>$arrayOfNiveaux[5][0],
  705.                 'titre' =>$article->getTitre(),
  706.                 'description' =>$article->getDescription(),
  707.                 'poid' =>$article->getPoid(),
  708.                 'longeur' =>$article->getLongeur(),
  709.                 'largeur' =>$article->getLargeur(),
  710.                 'hauteur' =>$article->getHauteur(),
  711.                 'surface' =>$article->getSurface(),
  712.                 'volume' =>$article->getVolume(),
  713.                 'prixe_vente' =>$article->getPrixVente(),
  714.                 'prix_vente_min' =>$article->getPrixVenteMin(),
  715.                 'prix_vente_max' =>$article->getPrixVenteMax(),
  716.                 'prix_vente_moynne' =>$article->getPrixVenteMoyenne(),
  717.                 'prix_achat' =>$article->getPrixAchat(),
  718.                 'prix_achat_min' =>$article->getPrixAchatMin(),
  719.                 'prix_achat_max' =>$article->getPrixAchatMax(),
  720.                 'prix_achat_moyenne' =>$article->getPrixAchatMoyenne(),
  721.                 'autre_information' =>$article->getAutreInformation(),
  722.                 'description_detail' =>$article->getDescriptionDetail(),
  723.                 'gerer_en_stock' =>$article->getGererEnStock() ? "oui" "non",
  724.                 'verification_stock' =>$article->getVerificationStock() ? "oui" "non",
  725.                 'code_barre' =>$article->getCodeBarre(),
  726.                 'tva' =>$article->getTva(),
  727.                 'dosage' =>$article->getDosage(),
  728.                 'dci' =>$article->getDci(),
  729.                 'remise' =>$article->getRemise(),
  730.                 'prix_reference' =>$article->getPrixReference(),
  731.                 'taille' =>$article->getTaille(),
  732.                 'matiere' =>$article->getMatiere(),
  733.                 'conditionnement' =>$article->getConditionnement(),
  734.                 'notation_technique' =>$article->getNotationTechnique(),
  735.                 'marque' =>$article->getMarque(),
  736.                 'ma' =>$article->getMA(),
  737.                 'famille_article' =>$article->getFamille(),
  738.                 'categorie_article' =>$article->getCategorie(),
  739.                 'ref_interne' =>$article->getRefInterne(),
  740.                 'sns' =>$article->getSNS(),
  741.                 'statut' => $article->getStatut()->getDesignation(),
  742.                 'active' => $article->getActive() ? 'oui' 'non'
  743.             ]);
  744.            
  745.          
  746.         }
  747.         
  748.         return new JsonResponse($array);
  749.     }
  750.     // public function exporter(Request $request): Response
  751.     // {
  752.     //     $articles = $this->em->getRepository(UArticle::class)->findAll();
  753.     //     $spreadsheet = new Spreadsheet();
  754.     //     $sheet = $spreadsheet->getActiveSheet();
  755.     //     $sheet->setCellValue('A1', 'id');
  756.     //     $sheet->setCellValue('B1', 'code');
  757.     //     $sheet->setCellValue('C1', 'unite_id');
  758.     //     $sheet->setCellValue('D1', 'unite');
  759.     //     $sheet->setCellValue('E1', 'id_niveau_affecte');
  760.     //     $sheet->setCellValue('F1', 'id');
  761.     //     $sheet->setCellValue('G1', 'Dossier');
  762.     //     $sheet->setCellValue('H1', 'id');
  763.     //     $sheet->setCellValue('I1', 'Sous dossier');
  764.     //     $sheet->setCellValue('J1', 'id');
  765.     //     $sheet->setCellValue('K1', 'Group');
  766.     //     $sheet->setCellValue('L1', 'id');
  767.     //     $sheet->setCellValue('M1', 'Catégorie');
  768.     //     $sheet->setCellValue('N1', 'id');
  769.     //     $sheet->setCellValue('O1', 'Type');
  770.     //     $sheet->setCellValue('P1', 'id');
  771.     //     $sheet->setCellValue('Q1', 'Famille');
  772.     //     $sheet->setCellValue('R1', 'Titre');
  773.     //     $sheet->setCellValue('S1', 'Description');
  774.     //     $sheet->setCellValue('T1', 'Poid');
  775.     //     $sheet->setCellValue('U1', 'Longeur');
  776.     //     $sheet->setCellValue('V1', 'Largeur');
  777.     //     $sheet->setCellValue('W1', 'Hauteur');
  778.     //     $sheet->setCellValue('X1', 'Surface');
  779.     //     $sheet->setCellValue('Y1', 'Volume');
  780.     //     $sheet->setCellValue('Z1', 'Prix vente');
  781.     //     $sheet->setCellValue('AA1', 'Prix vente min');
  782.     //     $sheet->setCellValue('AB1', 'Prix vente max');
  783.     //     $sheet->setCellValue('AC1', 'Prix vente moyenne');
  784.     //     $sheet->setCellValue('AD1', 'Prix Achat');
  785.     //     $sheet->setCellValue('AE1', 'Prix Achat min');
  786.     //     $sheet->setCellValue('AF1', 'Prix Achat max');
  787.     //     $sheet->setCellValue('AG1', 'Prix Achat moyenne');
  788.     //     $sheet->setCellValue('AH1', 'Autre information');
  789.     //     $sheet->setCellValue('AI1', 'Description detail');
  790.     //     $sheet->setCellValue('AJ1', 'Gerer en stock');
  791.     //     $sheet->setCellValue('AK1', 'Verification stcok');
  792.     //     $sheet->setCellValue('AL1', 'Code Barre');
  793.     //     $sheet->setCellValue('AM1', 'TVA');
  794.     //     $sheet->setCellValue('AN1', 'Dosage');
  795.     //     $sheet->setCellValue('AO1', 'DCI');
  796.     //     $sheet->setCellValue('AP1', 'Remise');
  797.     //     $sheet->setCellValue('AQ1', 'Prix reference');
  798.     //     $sheet->setCellValue('AR1', 'Taille');
  799.     //     $sheet->setCellValue('AS1', 'Matiere');
  800.     //     $sheet->setCellValue('AT1', 'Conditionnement');
  801.     //     $sheet->setCellValue('AU1', 'Notation technique');
  802.     //     $sheet->setCellValue('AV1', 'Marque');
  803.     //     $sheet->setCellValue('AW1', 'M/A');
  804.     //     $sheet->setCellValue('AX1', 'Reference Interne');
  805.     //     $sheet->setCellValue('AY1', 'S/NS');
  806.     //     $sheet->setCellValue('AZ1', 'Statut');
  807.     //     $i = 2;
  808.     //     foreach ($articles as $article) {
  809.     //         $sheet->setCellValue('A'.$i, $article->getId());
  810.     //         $sheet->setCellValue('B'.$i, $article->getCode());
  811.     //         $sheet->setCellValue('C'.$i, $article->getUnite()? $article->getUnite()->getId() : "");
  812.     //         $sheet->setCellValue('D'.$i, $article->getUnite() ? $article->getUnite()->getDesignation() : "");
  813.     //         $sheet->setCellValue('E'.$i, $article->getNiveau() ? $article->getNiveau()->getId() : "");
  814.     //         $arrayOfNiveaux = [];
  815.     //         if($article->getNiveau()) {
  816.     //             $currentNiveau =  $article->getNiveau()->getId();
  817.     
  818.     //             for ($j= $article->getNiveau()->getNiveau(); $j > 0; $j--) { 
  819.     //                 $niveau = $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  820.     //                 array_push($arrayOfNiveaux, [$niveau->getDesignation(), $niveau->getId()]);
  821.     //                 if($niveau->getParent()) {
  822.     //                     $currentNiveau = $niveau->getParent()->getId();
  823.     //                 } else {
  824.     //                     break;
  825.     //                 }
  826.     
  827.     //             }
  828.     //         }
  829.     //         // dump($arrayOfNiveaux);
  830.     //         $arrayOfNiveaux = array_reverse($arrayOfNiveaux);
  831.     //         // dd($arrayOfNiveaux);
  832.     //         $diffrence = 6 - count($arrayOfNiveaux);
  833.     //         if($diffrence > 0){
  834.     //             for($k = 1; $k <= $diffrence; $k++){
  835.     //                 array_push($arrayOfNiveaux, ["", ""]);
  836.     //             }
  837.     //         }
  838.     //         $sheet->setCellValue('F'.$i, $arrayOfNiveaux[0][1]);
  839.     //         $sheet->setCellValue('G'.$i, $arrayOfNiveaux[0][0]);
  840.     //         $sheet->setCellValue('H'.$i, $arrayOfNiveaux[1][1]);
  841.     //         $sheet->setCellValue('I'.$i, $arrayOfNiveaux[1][0]);
  842.     //         $sheet->setCellValue('J'.$i, $arrayOfNiveaux[2][1]);
  843.     //         $sheet->setCellValue('K'.$i, $arrayOfNiveaux[2][0]);
  844.     //         $sheet->setCellValue('L'.$i, $arrayOfNiveaux[3][1]);
  845.     //         $sheet->setCellValue('M'.$i, $arrayOfNiveaux[3][0]);
  846.     //         $sheet->setCellValue('N'.$i, $arrayOfNiveaux[4][1]);
  847.     //         $sheet->setCellValue('O'.$i, $arrayOfNiveaux[4][0]);
  848.     //         $sheet->setCellValue('P'.$i, $arrayOfNiveaux[5][1]);
  849.     //         $sheet->setCellValue('Q'.$i, $arrayOfNiveaux[5][0]);
  850.     //         $sheet->setCellValue('R'.$i, $article->getTitre());
  851.     //         $sheet->setCellValue('S'.$i, $article->getDescription());
  852.     //         $sheet->setCellValue('T'.$i, $article->getPoid());
  853.     //         $sheet->setCellValue('U'.$i, $article->getLongeur());
  854.     //         $sheet->setCellValue('V'.$i, $article->getLargeur());
  855.     //         $sheet->setCellValue('W'.$i, $article->getHauteur());
  856.     //         $sheet->setCellValue('X'.$i, $article->getSurface());
  857.     //         $sheet->setCellValue('Y'.$i, $article->getVolume());
  858.     //         $sheet->setCellValue('Z'.$i, $article->getPrixVente());
  859.     //         $sheet->setCellValue('AA'.$i, $article->getPrixVenteMin());
  860.     //         $sheet->setCellValue('AB'.$i, $article->getPrixVenteMax());
  861.     //         $sheet->setCellValue('AC'.$i, $article->getPrixVenteMoyenne());
  862.     //         $sheet->setCellValue('AD'.$i, $article->getPrixAchat());
  863.     //         $sheet->setCellValue('AE'.$i, $article->getPrixAchatMin());
  864.     //         $sheet->setCellValue('AF'.$i, $article->getPrixAchatMax());
  865.     //         $sheet->setCellValue('AG'.$i, $article->getPrixAchatMoyenne());
  866.     //         $sheet->setCellValue('AH'.$i, $article->getAutreInformation());
  867.     //         $sheet->setCellValue('AI'.$i, $article->getDescriptionDetail());
  868.     //         $sheet->setCellValue('AJ'.$i, $article->getGererEnStock() ? "oui" : "non");
  869.     //         $sheet->setCellValue('AK'.$i, $article->getVerificationStock() ? "oui" : "non");
  870.     //         $sheet->setCellValue('AL'.$i, $article->getCodeBarre());
  871.     //         $sheet->setCellValue('AM'.$i, $article->getTva());
  872.     //         $sheet->setCellValue('AN'.$i, $article->getDosage());
  873.     //         $sheet->setCellValue('AO'.$i, $article->getDci());
  874.     //         $sheet->setCellValue('AP'.$i, $article->getRemise());
  875.     //         $sheet->setCellValue('AQ'.$i, $article->getPrixReference());
  876.     //         $sheet->setCellValue('AR'.$i, $article->getTaille());
  877.     //         $sheet->setCellValue('AS'.$i, $article->getMatiere());
  878.     //         $sheet->setCellValue('AT'.$i, $article->getConditionnement());
  879.     //         $sheet->setCellValue('AU'.$i, $article->getNotationTechnique());
  880.     //         $sheet->setCellValue('AV'.$i, $article->getMarque());
  881.     //         $sheet->setCellValue('AW'.$i, $article->getMA());
  882.     //         $sheet->setCellValue('AX'.$i, $article->getRefInterne());
  883.     //         $sheet->setCellValue('AY'.$i, $article->getSNS());
  884.     //         $sheet->setCellValue('AZ'.$i, $article->getStatut()->getDesignation());
  885.     //         $i++;
  886.     //     }
  887.         
  888.     //     $writer = new Xlsx($spreadsheet);
  889.     //     $fileName = 'articles.xlsx';
  890.     //     $temp_file = tempnam(sys_get_temp_dir(), $fileName);
  891.     //     $writer->save($temp_file);
  892.     //     return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
  893.     //     return new JsonResponse(['id' => $niveau->getId(), "designation" => $niveau->getDesignation()], 200);
  894.     // }
  895.     #[Route('/article/import'name'article_article_import')]
  896.     public function articleImport(Request $request SluggerInterface $slugger): Response
  897.     {
  898.         $file $request->files->get('file');
  899.         // dd($file);
  900.         if(!$file){
  901.             return new JsonResponse('Prière d\'importer le fichier',500);
  902.         }
  903.         if($file->guessExtension() !== 'xlsx'){
  904.             return new JsonResponse('Prière d\'enregister un fichier xlsx'500);            
  905.         }
  906.         $originalFilename pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  907.         // this is needed to safely include the file name as part of the URL
  908.         $safeFilename $slugger->slug($originalFilename);
  909.         $newFilename $safeFilename.'-'.uniqid().'_'.$this->getUser()->getUsername().'.'.$file->guessExtension();
  910.         // Move the file to the directory where brochures are stored
  911.         try {
  912.             $file->move(
  913.                 $this->getParameter('artice_directory'),
  914.                 $newFilename
  915.             );
  916.         } catch (FileException $e) {
  917.             throw new \Exception($e);
  918.         }
  919.         $reader = new reader();
  920.         $spreadsheet $reader->load($this->getParameter('artice_directory').'/'.$newFilename);
  921.         $worksheet $spreadsheet->getActiveSheet();
  922.         $spreadSheetArys $worksheet->toArray();
  923.         unset($spreadSheetArys[0]);
  924.         $sheetCount count($spreadSheetArys);
  925.         foreach ($spreadSheetArys as $sheet) {
  926.             if(trim($sheet[4]) == ""){
  927.                 return new JsonResponse('Veuillez remplir Id niveau',500);
  928.             }
  929.         }
  930.         foreach ($spreadSheetArys as $sheet) {
  931.             // dd();
  932.             $article $this->em->getRepository(UArticle::class)->findOneBy(['titre' => trim($request->get("titre"))]);
  933.         // dd($article, trim($request->get("titre")));
  934.             if(!$article) {
  935.                 $article = new UArticle();
  936.                 $article->setTitre(
  937.                     $sheet[11]
  938.                 );
  939.                 $article->setUnite(
  940.                     $sheet[2] > $this->em->getRepository(PUnite::class)->find($sheet[2]) : null
  941.                 );
  942.                 $article->setDescription(
  943.                     $sheet[12]
  944.                 );
  945.                 $article->setPoid($sheet[13]);
  946.                 $article->setLongeur($sheet[14]);
  947.                 $article->setLargeur($sheet[15]);
  948.                 $article->setHauteur($sheet[16]);
  949.                 $article->setSurface($sheet[17]);
  950.                 $article->setVolume($sheet[18]);
  951.                 $article->setPrixVente($sheet[19]);
  952.                 $article->setPrixVenteMin($sheet[20]);
  953.                 $article->setPrixVenteMax($sheet[21]);
  954.                 if($sheet[21] >= && $sheet[20] >= 0) {
  955.                     if(($sheet[21] + $sheet[20]) == 0) {
  956.                         $article->setPrixVenteMoyenne(0);
  957.                     } else {
  958.                         $article->setPrixVenteMoyenne(($sheet[21] + $sheet[20]) / 2);
  959.                         
  960.                     }
  961.                 }
  962.                 $article->setPrixAchat($sheet[23]);
  963.                 $article->setPrixAchatMin($sheet[24]);
  964.                 $article->setPrixAchatMax($sheet[25]);
  965.                 if($sheet[25] >= && $sheet[24] >= 0) {
  966.                     if(($sheet[25] + $sheet[24]) == 0) {
  967.                         $article->setPrixAchatMoyenne(0);
  968.                     } else {
  969.                         $article->setPrixAchatMoyenne(($sheet[24] + $sheet[25]) / 2);
  970.                         
  971.                     }
  972.                 }
  973.                 $article->setAutreInformation($sheet[27]);
  974.                 $article->setDescriptionDetail($sheet[28]);
  975.                 $article->setGererEnStock($sheet[29] == "oui" true false);
  976.                 $article->setVerificationStock($sheet[30] == "oui" true false);
  977.                 $article->setCodeBarre($sheet[31]);
  978.                 $article->setTva($sheet[32]);
  979.                 $article->setDosage($sheet[33]);
  980.                 $article->setDci($sheet[34]);
  981.                 $article->setRemise($sheet[35]);
  982.                 $article->setPrixReference($sheet[36]);
  983.                 $article->setTaille($sheet[37]);
  984.                 $article->setMatiere($sheet[38]);
  985.                 $article->setConditionnement($sheet[39]);
  986.                 $article->setNotationTechnique($sheet[40]);
  987.                 $article->setMarque($sheet[41]);
  988.                 $article->setMA($sheet[42]);
  989.                 $article->setRefInterne((float)$sheet[43]);
  990.                 $article->setSNS($sheet[44]);
  991.                 $article->setQteStock($sheet[45]);
  992.                 $article->setFonCode($sheet[46]);
  993.                 $article->setSpecialiteProduit($sheet[47]);
  994.                 $article->setSpeCode($sheet[48]);
  995.                 $article->setAncienCode($sheet[49]);
  996.                 $article->setCodeCat($sheet[50]);
  997.                 $article->setClasseProduit($sheet[51]);
  998.                 $article->setSegmentsProduit($sheet[52]);
  999.                 $article->setSousSegmentsProduit($sheet[53]);
  1000.                 $article->setReference($sheet[54]);
  1001.                 $article->setVoieAdministration($sheet[55]);
  1002.                 $article->setPresentation($sheet[56]);
  1003.                 $article->setFabricant($sheet[57]);
  1004.                 $article->setFournisseur($sheet[58]);
  1005.                 $article->setCodeDci($sheet[59]);
  1006.                 $article->setEan($sheet[60]);
  1007.                 $article->setAtc($sheet[61]);
  1008.                 $article->setCodeImm($sheet[62]);
  1009.                 $article->setEanAccess($sheet[63]);
  1010.                 $article->setPrixVentePh($sheet[64]);
  1011.                 $article->setPrixVentePpv($sheet[65]);
  1012.                 $article->setPrixVentePpc($sheet[66]);
  1013.                 $article->setCleReference($sheet[67]);
  1014.                 $article->setFamille($sheet[68]);
  1015.                 $article->setCategorie($sheet[69]);
  1016.                 $article->setNiveau(
  1017.                     $sheet[4] > $this->em->getRepository(PArticleNiveau::class)->find($sheet[4]) : null
  1018.                 );
  1019.                 $article->setStatut(
  1020.                     $this->em->getRepository(PStatut::class)->find(1)
  1021.                 );
  1022.                 $article->setActive(true);
  1023.                 $this->em->persist($article);
  1024.                 $this->em->flush();
  1025.                 $article->setCode('ART'str_pad($article->getId(), 6'0'STR_PAD_LEFT));
  1026.                 $this->em->flush();
  1027.             }
  1028.             
  1029.         }
  1030.         return new JsonResponse("Total des articles crée est ".$sheetCount);
  1031.         
  1032.     }
  1033.     #[Route('/article/miseajour'name'article_article_miseajour')]
  1034.     public function articleMiseAJour(Request $request SluggerInterface $slugger): Response
  1035.     {
  1036.         $file $request->files->get('file');
  1037.         // dd($file);
  1038.         if(!$file){
  1039.             return new JsonResponse('Prière d\'importer le fichier',500);
  1040.         }
  1041.         if($file->guessExtension() !== 'xlsx'){
  1042.             return new JsonResponse('Prière d\'enregister un fichier xlsx'500);            
  1043.         }
  1044.         $originalFilename pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  1045.         // this is needed to safely include the file name as part of the URL
  1046.         $safeFilename $slugger->slug($originalFilename);
  1047.         $newFilename $safeFilename.'-'.uniqid().'_'.$this->getUser()->getUsername().'.'.$file->guessExtension();
  1048.         // Move the file to the directory where brochures are stored
  1049.         try {
  1050.             $file->move(
  1051.                 $this->getParameter('artice_directory'),
  1052.                 $newFilename
  1053.             );
  1054.         } catch (FileException $e) {
  1055.             throw new \Exception($e);
  1056.         }
  1057.         $reader = new reader();
  1058.         $spreadsheet $reader->load($this->getParameter('artice_directory').'/'.$newFilename);
  1059.         $worksheet $spreadsheet->getActiveSheet();
  1060.         $spreadSheetArys $worksheet->toArray();
  1061.         unset($spreadSheetArys[0]);
  1062.         $sheetCount count($spreadSheetArys);
  1063.         foreach ($spreadSheetArys as $sheet) {
  1064.             // dd();
  1065.             $article $this->em->getRepository(UArticle::class)->find($sheet[0]);
  1066.             if($article) {
  1067.                 $article->setTitre(
  1068.                     $sheet[11]
  1069.                 );
  1070.                 $article->setUnite(
  1071.                     $sheet[2] > $this->em->getRepository(PUnite::class)->find($sheet[2]) : null
  1072.                 );
  1073.                 $article->setDescription(
  1074.                     $sheet[12]
  1075.                 );
  1076.                 $article->setPoid($sheet[13]);
  1077.                 $article->setLongeur($sheet[14]);
  1078.                 $article->setLargeur($sheet[15]);
  1079.                 $article->setHauteur($sheet[16]);
  1080.                 $article->setSurface($sheet[17]);
  1081.                 $article->setVolume($sheet[18]);
  1082.                 $article->setPrixVente($sheet[19]);
  1083.                 $article->setPrixVenteMin($sheet[20]);
  1084.                 $article->setPrixVenteMax($sheet[21]);
  1085.                 if($sheet[21] >= && $sheet[20] >= 0) {
  1086.                     if(($sheet[21] + $sheet[20]) == 0) {
  1087.                         $article->setPrixVenteMoyenne(0);
  1088.                     } else {
  1089.                         $article->setPrixVenteMoyenne(($sheet[21] + $sheet[20]) / 2);
  1090.                         
  1091.                     }
  1092.                 }
  1093.                 $article->setPrixAchat($sheet[23]);
  1094.                 $article->setPrixAchatMin($sheet[24]);
  1095.                 $article->setPrixAchatMax($sheet[25]);
  1096.                 if($sheet[25] >= && $sheet[24] >= 0) {
  1097.                     if(($sheet[25] + $sheet[24]) == 0) {
  1098.                         $article->setPrixAchatMoyenne(0);
  1099.                     } else {
  1100.                         $article->setPrixAchatMoyenne(($sheet[24] + $sheet[25]) / 2);
  1101.                         
  1102.                     }
  1103.                 }
  1104.                 $article->setAutreInformation($sheet[27]);
  1105.                 $article->setDescriptionDetail($sheet[28]);
  1106.                 $article->setGererEnStock($sheet[29] == "oui" true false);
  1107.                 $article->setVerificationStock($sheet[30] == "oui" true false);
  1108.                 $article->setCodeBarre($sheet[31]);
  1109.                 $article->setTva($sheet[32]);
  1110.                 $article->setDosage($sheet[33]);
  1111.                 $article->setDci($sheet[34]);
  1112.                 $article->setRemise($sheet[35]);
  1113.                 $article->setPrixReference($sheet[36]);
  1114.                 $article->setTaille($sheet[37]);
  1115.                 $article->setMatiere($sheet[38]);
  1116.                 $article->setConditionnement($sheet[39]);
  1117.                 $article->setMarque($sheet[40]);
  1118.                 $article->setMA($sheet[41]);
  1119.                 $article->setRefInterne($sheet[42]);
  1120.                 $article->setSNS($sheet[43]);
  1121.                 $article->setNiveau(
  1122.                     $sheet[4] > $this->em->getRepository(PArticleNiveau::class)->find($sheet[4]) : null
  1123.                 );
  1124.                 
  1125.             }
  1126.             $this->em->flush();
  1127.             
  1128.         }
  1129.         return new JsonResponse("Total des articles à jour est ".$sheetCount);
  1130.         
  1131.     }
  1132.     #[Route('/article/details/update/{article}'name'article_article_details_update')]
  1133.     public function articleDetailsUpdate(UArticle $article): Response
  1134.     {
  1135.         $arrayOfNiveaux = [];
  1136.         $currentNiveau $article->getNiveau()->getId();
  1137.         for ($j$article->getNiveau()->getNiveau(); $j 0$j--) { 
  1138.             $niveau $this->em->getRepository(PArticleNiveau::class)->find($currentNiveau);
  1139.             array_push($arrayOfNiveaux$niveau);
  1140.             if($niveau->getParent()) {
  1141.                 $currentNiveau $niveau->getParent()->getId();
  1142.             } else {
  1143.                 break;
  1144.             }
  1145.         }
  1146.         // dump($arrayOfNiveaux);
  1147.         $arrayOfNiveaux array_reverse($arrayOfNiveaux);
  1148.         // dd($arrayOfNiveaux);
  1149.         $diffrence count($arrayOfNiveaux);
  1150.         if($diffrence 0){
  1151.             for($k 1$k <= $diffrence$k++){
  1152.                 array_push($arrayOfNiveauxnull);
  1153.             }
  1154.         }
  1155.         $html $this->render("article/pages/form_update.html.twig", [
  1156.             'article' => $article,
  1157.             'niveauxAffecte' => $arrayOfNiveaux,
  1158.             'niveaux' => $this->em->getRepository(PArticleNiveau::class)->findBy(['parent' => null]),
  1159.             'unites' => $this->em->getRepository(PUnite::class)->findAll()
  1160.         ])->getContent();
  1161.         return new JsonResponse([
  1162.             "html" => $html,
  1163.             'title' => $article->getTitre()
  1164.         ]);
  1165.     }
  1166.     #[Route('/article/update/{article}'name'article_article_details_update_save')]
  1167.     public function articleUpdate(Request $requestUArticle $article): Response
  1168.     {
  1169.         $article->setTitre(
  1170.             $request->get("titre") != "" $request->get("titre") : null
  1171.         );
  1172.         $article->setPoid(
  1173.             $request->get("poid") != "" $request->get("poid") : null
  1174.         );
  1175.         $article->setUnite(
  1176.             $request->get("unite") != "" $this->em->getRepository(PUnite::class)->find($request->get("unite")) : null
  1177.         );
  1178.         $article->setLongeur(
  1179.             $request->get("longeur") != "" $request->get("longeur") : null
  1180.         );
  1181.         $article->setLargeur(
  1182.             $request->get("largeur") != "" $request->get("largeur") : null
  1183.         );
  1184.         $article->setHauteur(
  1185.             $request->get("hauteur") != "" $request->get("hauteur") : null
  1186.         );
  1187.         $article->setSurface(
  1188.             $request->get("surface") != "" $request->get("surface") : null
  1189.         );
  1190.         $article->setVolume(
  1191.             $request->get("volume") != "" $request->get("volume") : null
  1192.         );
  1193.         $article->setPrixVente(
  1194.             $request->get("prix_vente") != "" $request->get("prix_vente") : null
  1195.         );
  1196.         $article->setPrixVenteMin(
  1197.             $request->get("prix_vente_min") != "" $request->get("prix_vente_min") : null
  1198.         );
  1199.         $article->setPrixVenteMax(
  1200.             $request->get("prix_vente_max") != "" $request->get("prix_vente_max") : null
  1201.         );
  1202.         if($request->get("prix_vente_max") >= && $request->get("prix_vente_min") >= 0) {
  1203.             if(($request->get("prix_vente_max") + $request->get("prix_vente_min")) == 0) {
  1204.                 $article->setPrixVenteMoyenne(0);
  1205.             } else {
  1206.                 $article->setPrixVenteMoyenne(($request->get("prix_vente_max") + $request->get("prix_vente_min")) / 2);
  1207.                 
  1208.             }
  1209.         }
  1210.         $article->setPrixAchat(
  1211.             $request->get("prix_achat") != "" $request->get("prix_achat") : null
  1212.         );
  1213.         $article->setPrixAchatMin(
  1214.             $request->get("prix_achat_min") != "" $request->get("prix_achat_min") : null
  1215.         );
  1216.         $article->setPrixAchatMax(
  1217.             $request->get("prix_achat_max") != "" $request->get("prix_achat_max") : null
  1218.         );
  1219.         if($request->get("prix_achat_max") >= && $request->get("prix_achat_min") >= 0) {
  1220.             if(($request->get("prix_achat_max") + $request->get("prix_achat_min")) == 0) {
  1221.                 $article->setPrixAchatMoyenne(0);
  1222.             } else {
  1223.                 $article->setPrixAchatMoyenne(($request->get("prix_achat_max") + $request->get("prix_achat_min")) / 2);
  1224.                 
  1225.             }
  1226.         }
  1227.         $article->setAutreInformation(
  1228.             $request->get("autre_infromation") != "" $request->get("autre_infromation") : null
  1229.         );
  1230.         $article->setDescriptionDetail(
  1231.             $request->get("desicription_detail") != "" $request->get("desicription_detail") : null
  1232.         );
  1233.         $article->setGererEnStock(
  1234.             $request->get("gerer_en_stock") ? true false
  1235.         );
  1236.         $article->setVerificationStock(
  1237.             $request->get("verification_stock") ? true false
  1238.         );
  1239.         $article->setCodeBarre(
  1240.             $request->get("code_barre") != "" $request->get("code_barre") : null
  1241.         );
  1242.         $article->setTva(
  1243.             $request->get("tva") != "" $request->get("tva") : null
  1244.         );
  1245.         $article->setDosage(
  1246.             $request->get("dosage") != "" $request->get("dosage") : null
  1247.         );
  1248.         $article->setDci(
  1249.             $request->get("dci") != "" $request->get("dci") : null
  1250.         );
  1251.         $article->setRemise(
  1252.             $request->get("remise") != "" $request->get("remise") : null
  1253.         );
  1254.         $article->setPrixReference(
  1255.             $request->get("prix_reference") != "" $request->get("prix_reference") : null
  1256.         );
  1257.         $article->setTaille(
  1258.             $request->get("taille") != "" $request->get("taille") : null
  1259.         );
  1260.         $article->setMatiere(
  1261.             $request->get("matiere") != "" $request->get("matiere") : null
  1262.         );
  1263.         $article->setConditionnement(
  1264.             $request->get("conditionnement") != "" $request->get("conditionnement") : null
  1265.         );
  1266.         $article->setMarque(
  1267.             $request->get("marque") != "" $request->get("marque") : null
  1268.         );
  1269.         $article->setMA(
  1270.             $request->get("ma") != "" $request->get("ma") : null
  1271.         );
  1272.         $article->setRefInterne(
  1273.             $request->get("reference_interne") != "" $request->get("reference_interne") : null
  1274.         );
  1275.         $article->setSNS(
  1276.             $request->get("sns") != "" $request->get("sns") : null
  1277.         );
  1278.         $article->setNiveau(
  1279.             $this->em->getRepository(PArticleNiveau::class)->find($request->get('niveau'))
  1280.         );
  1281.         $article->setQteStock($request->get("QTE_STOCK") != "" $request->get("QTE_STOCK") : null);
  1282.         $article->setFonCode($request->get("FON_CODE") != "" $request->get("FON_CODE") : null);
  1283.         $article->setSpecialiteProduit($request->get("SPECIALITE_PRODUIT") != "" $request->get("SPECIALITE_PRODUIT") : null);
  1284.         $article->setSpeCode($request->get("SPE_CODE") != "" $request->get("SPE_CODE") : null);
  1285.         $article->setAncienCode($request->get("ANCIEN_CODE") != "" $request->get("ANCIEN_CODE") : null);
  1286.         $article->setCodeCat($request->get("CODE_CAT") != "" $request->get("CODE_CAT") : null);
  1287.         $article->setClasseProduit($request->get("CLASSE_PRODUIT") != "" $request->get("CLASSE_PRODUIT") : null);
  1288.         $article->setSegmentsProduit($request->get("SEGMENTS_PRODUIT") != "" $request->get("SEGMENTS_PRODUIT") : null);
  1289.         $article->setSousSegmentsProduit($request->get("SOUS-SEGMENT_PRODUIT") != "" $request->get("SOUS-SEGMENT_PRODUIT") : null);
  1290.         $article->setReference($request->get("REFERENCE") != "" $request->get("REFERENCE") : null);
  1291.         $article->setVoieAdministration($request->get("VOIE_ADMINISTRATION") != "" $request->get("VOIE_ADMINISTRATION") : null);
  1292.         $article->setPresentation($request->get("PRESENTATION") != "" $request->get("PRESENTATION") : null);
  1293.         $article->setFabricant($request->get("FABRICANT") != "" $request->get("FABRICANT") : null);
  1294.         $article->setFournisseur($request->get("FOURNISSEUR") != "" $request->get("FOURNISSEUR") : null);
  1295.         $article->setCodeDci($request->get("CODE_DCI") != "" $request->get("CODE_DCI") : null);
  1296.         $article->setEan($request->get("EAN") != "" $request->get("EAN") : null);
  1297.         $article->setAtc($request->get("ATC") != "" $request->get("ATC") : null);
  1298.         $article->setCodeImm($request->get("CODE_IMM") != "" $request->get("CODE_IMM") : null);
  1299.         $article->setEanAccess($request->get("EAN_ACCESS") != "" $request->get("EAN_ACCESS") : null);
  1300.         $article->setPrixVentePh($request->get("PRIX_VENTE_PH") != "" $request->get("PRIX_VENTE_PH") : null);
  1301.         $article->setPrixVentePpv($request->get("PRIX_VENTE_PPV") != "" $request->get("PRIX_VENTE_PPV") : null);
  1302.         $article->setPrixVentePpc($request->get("PRIX_VENTE_PPC") != "" $request->get("PRIX_VENTE_PPC") : null);
  1303.         $article->setCleReference($request->get("CLE_REFERENCE") != "" $request->get("CLE_REFERENCE") : null);
  1304.         $article->setFamille(
  1305.             $request->get("famille_s") != "" $request->get("famille_s") : null
  1306.         );
  1307.         $article->setCategorie(
  1308.             $request->get("categorie_s") != "" $request->get("categorie_s") : null
  1309.         );
  1310.         if($article->getStatut()->getDesignation() == "Intégrer") {
  1311.             $article->setStatut(
  1312.                 $this->em->getRepository(PStatut::class)->find(4)
  1313.             );
  1314.         }
  1315.         
  1316.         $this->em->flush();
  1317.         return new JsonResponse("Bien Enregistre",200);
  1318.     }
  1319.     #[Route('/article/integere'name'article_article_integere')]
  1320.     public function articleintegere(Request $requestHttpClientInterface $client): Response
  1321.     {   
  1322.         $insert 0;
  1323.         $updated 0;
  1324.         /** @var UArticle[] */
  1325.         $articles $this->em->getRepository(UArticle::class)->findBy(['statut' => $this->em->getRepository(PStatut::class)->find(4)]);
  1326.         // dd($articles);
  1327.         
  1328.         foreach($articles as $article) {
  1329.                 // dd($this->getParameter("api")."/api/insert/article");
  1330.             $response $client->request('POST'$this->getParameter("api")."/api/insert/article", [
  1331.                 'body' => [
  1332.                     'id' => $article->getId(),
  1333.                     'unite' => $article->getUnite() ? $article->getUnite()->getId() : null,
  1334.                     'niveau' => $article->getNiveau()->getId(),
  1335.                     'code' => $article->getCode(),
  1336.                     'titre' => $article->getTitre(),
  1337.                     'description' => $article->getDescription(),
  1338.                     'poid' => $article->getPoid(),
  1339.                     'longeur' => $article->getLongeur(),
  1340.                     'largeur' => $article->getLargeur(),
  1341.                     'hauteur' => $article->getHauteur(),
  1342.                     'surface' => $article->getSurface(),
  1343.                     'famille_article' =>$article->getFamille(),
  1344.                     'categorie_article' =>$article->getCategorie(),
  1345.                     'volume' => $article->getVolume(),
  1346.                     'prix_vente' => $article->getPrixVente(),
  1347.                     'prix_vente_min' => $article->getPrixVenteMin(),
  1348.                     'prix_vente_max' => $article->getPrixVenteMax(),
  1349.                     'prix_vente_moyenne' => $article->getPrixVenteMoyenne(),
  1350.                     'prix_achat' => $article->getPrixAchat(),
  1351.                     'prix_achat_min' => $article->getPrixAchatMin(),
  1352.                     'prix_achat_max' => $article->getPrixAchatMax(),
  1353.                     'prix_achat_moyenne' => $article->getPrixAchatMoyenne(),
  1354.                     'active' => $article->getActive(),
  1355.                     'autre_information' => $article->getAutreInformation(),
  1356.                     'descirption_detail' => $article->getDescriptionDetail(),
  1357.                     'gerer_en_stock' => $article->getGererEnStock(),
  1358.                     'verification_stock' => $article->getVerificationStock(),
  1359.                     'code_barre' => $article->getCodeBarre(),
  1360.                     'tva' => $article->getTVA(),
  1361.                     'dosage' => $article->getDosage(),
  1362.                     'dci' => $article->getDCI(),
  1363.                     'remise' => $article->getRemise(),
  1364.                     'prix_reference' => $article->getPrixReference(),
  1365.                     'taille' => $article->getTaille(),
  1366.                     'matiere' => $article->getMatiere(),
  1367.                     'conditionnement' => $article->getConditionnement(),
  1368.                     'notation_technique' => $article->getNotationTechnique(),
  1369.                     'marque' => $article->getMarque(),
  1370.                     'ai' => $article->getAi(),
  1371.                     'av' => $article->getAv(),
  1372.                     'ma' => $article->getMa(),
  1373.                     'ref_interne' => $article->getRefInterne(),
  1374.                     'sns' => $article->getSns(),
  1375.                     'statut_id' => $article->getStatut()->getId(),
  1376.                     'etat_achat' => $article->getEtatAchat(),
  1377.                     'etat_vente' => $article->getEtatVente(),
  1378.                     'qte_stock' => $article->getQteStock(),
  1379.                     'fon_code' => $article->getFonCode(),
  1380.                     'specialite_produit' => $article->getSpecialiteProduit(),
  1381.                     'spe_code' => $article->getSpeCode(),
  1382.                     'ancien_code' => $article->getAncienCode(),
  1383.                     'code_cat' => $article->getCodeCat(),
  1384.                     'classe_produit' => $article->getClasseProduit(),
  1385.                     'segments_produit' => $article->getSegmentsProduit(),
  1386.                     'sous_segment_produit' => $article->getSousSegmentsProduit(),
  1387.                     'reference' => $article->getReference(),
  1388.                     'voie_administration' => $article->getVoieAdministration(),
  1389.                     'presentation' => $article->getPresentation(),
  1390.                     'fabricant' => $article->getFabricant(),
  1391.                     'fournisseur' => $article->getFournisseur(),
  1392.                     'code_dci' => $article->getCodeDci(),
  1393.                     'ean' => $article->getEan(),
  1394.                     'atc' => $article->getAtc(),
  1395.                     'code_imm' => $article->getCodeImm(),
  1396.                     'ean_access' => $article->getEanAccess(),
  1397.                     'prix_vente_ph' => $article->getPrixVentePh(),
  1398.                     'prix_vente_ppv' => $article->getPrixVentePpv(),
  1399.                     'prix_vente_ppc' => $article->getPrixVentePpc(),
  1400.                     'cle_reference' => $article->getCleReference(),
  1401.                     'famille' => $article->getFamille(),
  1402.                     'categorie' => $article->getCategorie(),
  1403.                 ],
  1404.             ]);
  1405.             if($response->getContent() == "good") {
  1406.                 $article->setStatut(
  1407.                     $this->em->getRepository(PStatut::class)->find(3)
  1408.                 );
  1409.                 $updated++;
  1410.             }
  1411.             
  1412.            
  1413.             
  1414.         }
  1415.         $idArticles json_decode($request->get('articles'));
  1416.         foreach($idArticles as $idArticle) {
  1417.             $article $this->em->getRepository(UArticle::class)->find($idArticle);
  1418.             if($article->getStatut()->getDesignation() == "Valider"){
  1419.                 // dd($this->getParameter("api")."/api/insert/article");
  1420.                 
  1421.                 $idNiveaux ApiController::pluckParent($article->getNiveau());
  1422.                 // i reversed the array because [18051, 18050, X, Y, Z, A]
  1423.                 // imagine 18051 is the Level 6 and 18050 is the level 5 and both are new levels not inserted in ugouv.
  1424.                 // 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 
  1425.                 // thats why i reversed the array to start with the revent level to the last level to prevent that bug
  1426.                 $idNiveauxReversed array_reverse($idNiveaux);
  1427.                 foreach($idNiveauxReversed as $idNiveau) {
  1428.                     
  1429.                     $niveau $this->em->getRepository(PArticleNiveau::class)->find($idNiveau);
  1430.                     if($niveau->getStatut()->getDesignation() == "Valider") {
  1431.                         $response $client->request('POST'$this->getParameter("api")."/api/insert/niveau", [
  1432.                             'body' => [
  1433.                                 'id' => $niveau->getId(),
  1434.                                 'parent' => $niveau->getParent() ? $niveau->getParent()->getId() : '',
  1435.                                 'niveau' => $niveau->getNiveau(),
  1436.                                 'designation' => $niveau->getDesignation(),
  1437.                                 'cca1' => $niveau->getCCA1(),
  1438.                                 'cca2' => $niveau->getCCA2(),
  1439.                                 'cca3' => $niveau->getCCA3(),
  1440.                                 'cca4' => $niveau->getCCA4(),
  1441.                                 
  1442.                             ],
  1443.                         ]);
  1444.                         // dd($response->getContent());
  1445.                         if($response->getContent() == "good") {
  1446.                             $niveau->setStatut(
  1447.                                 $this->em->getRepository(PStatut::class)->find(3)
  1448.                             );
  1449.                         }
  1450.                         // dump($response->getContent());
  1451.                     }
  1452.                     
  1453.                 }
  1454.                 // die;
  1455.                 $response $client->request('POST'$this->getParameter("api")."/api/insert/article", [
  1456.                     
  1457.                     'body' => [
  1458.                         'id' => $article->getId(),
  1459.                         'unite' => $article->getUnite() ? $article->getUnite()->getId() : null,
  1460.                         'niveau' => $article->getNiveau()->getId(),
  1461.                         'code' => $article->getCode(),
  1462.                         'titre' => $article->getTitre(),
  1463.                         'description' => $article->getDescription(),
  1464.                         'poid' => $article->getPoid(),
  1465.                         'longeur' => $article->getLongeur(),
  1466.                         'largeur' => $article->getLargeur(),
  1467.                         'hauteur' => $article->getHauteur(),
  1468.                         'surface' => $article->getSurface(),
  1469.                         'famille_article' =>$article->getFamille(),
  1470.                         'categorie_article' =>$article->getCategorie(),
  1471.                         'volume' => $article->getVolume(),
  1472.                         'prix_vente' => $article->getPrixVente(),
  1473.                         'prix_vente_min' => $article->getPrixVenteMin(),
  1474.                         'prix_vente_max' => $article->getPrixVenteMax(),
  1475.                         'prix_vente_moyenne' => $article->getPrixVenteMoyenne(),
  1476.                         'prix_achat' => $article->getPrixAchat(),
  1477.                         'prix_achat_min' => $article->getPrixAchatMin(),
  1478.                         'prix_achat_max' => $article->getPrixAchatMax(),
  1479.                         'prix_achat_moyenne' => $article->getPrixAchatMoyenne(),
  1480.                         'active' => $article->getActive(),
  1481.                         'autre_information' => $article->getAutreInformation(),
  1482.                         'descirption_detail' => $article->getDescriptionDetail(),
  1483.                         'gerer_en_stock' => $article->getGererEnStock(),
  1484.                         'verification_stock' => $article->getVerificationStock(),
  1485.                         'code_barre' => $article->getCodeBarre(),
  1486.                         'tva' => $article->getTVA(),
  1487.                         'dosage' => $article->getDosage(),
  1488.                         'dci' => $article->getDCI(),
  1489.                         'remise' => $article->getRemise(),
  1490.                         'prix_reference' => $article->getPrixReference(),
  1491.                         'taille' => $article->getTaille(),
  1492.                         'matiere' => $article->getMatiere(),
  1493.                         'conditionnement' => $article->getConditionnement(),
  1494.                         'notation_technique' => $article->getNotationTechnique(),
  1495.                         'marque' => $article->getMarque(),
  1496.                         'ai' => $article->getAi(),
  1497.                         'av' => $article->getAv(),
  1498.                         'ma' => $article->getMa(),
  1499.                         'ref_interne' => $article->getRefInterne(),
  1500.                         'sns' => $article->getSns(),
  1501.                         'statut_id' => $article->getStatut()->getId(),
  1502.                         'etat_achat' => $article->getEtatAchat(),
  1503.                         'etat_vente' => $article->getEtatVente(),
  1504.                         'qte_stock' => $article->getQteStock(),
  1505.                         'fon_code' => $article->getFonCode(),
  1506.                         'specialite_produit' => $article->getSpecialiteProduit(),
  1507.                         'spe_code' => $article->getSpeCode(),
  1508.                         'ancien_code' => $article->getAncienCode(),
  1509.                         'code_cat' => $article->getCodeCat(),
  1510.                         'classe_produit' => $article->getClasseProduit(),
  1511.                         'segments_produit' => $article->getSegmentsProduit(),
  1512.                         'sous_segment_produit' => $article->getSousSegmentsProduit(),
  1513.                         'reference' => $article->getReference(),
  1514.                         'voie_administration' => $article->getVoieAdministration(),
  1515.                         'presentation' => $article->getPresentation(),
  1516.                         'fabricant' => $article->getFabricant(),
  1517.                         'fournisseur' => $article->getFournisseur(),
  1518.                         'code_dci' => $article->getCodeDci(),
  1519.                         'ean' => $article->getEan(),
  1520.                         'atc' => $article->getAtc(),
  1521.                         'code_imm' => $article->getCodeImm(),
  1522.                         'ean_access' => $article->getEanAccess(),
  1523.                         'prix_vente_ph' => $article->getPrixVentePh(),
  1524.                         'prix_vente_ppv' => $article->getPrixVentePpv(),
  1525.                         'prix_vente_ppc' => $article->getPrixVentePpc(),
  1526.                         'cle_reference' => $article->getCleReference(),
  1527.                         'famille' => $article->getFamille(),
  1528.                         'categorie' => $article->getCategorie(),
  1529.                     ],
  1530.                 ]);
  1531.                 if($response->getContent() == "good") {
  1532.                     $article->setStatut(
  1533.                         $this->em->getRepository(PStatut::class)->find(3)
  1534.                     );
  1535.                     $insert++;
  1536.                 }
  1537.                 
  1538.             }
  1539.         }
  1540.         
  1541.         
  1542.         $this->em->flush();
  1543.         return new JsonResponse(['insert' => $insert'updated' => $updated],200);
  1544.     }
  1545. }