src/Controller/Articles/ArticleController.php line 381

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Articles;
  3. use App\Entity\Articles\Article;
  4. use App\Entity\Clients\ClientMarque;
  5. use App\Entity\Articles\ArticleComplementOption;
  6. use App\Entity\Articles\ArticleComposant;
  7. use App\Entity\Articles\ArticleCategorie;
  8. use App\Entity\Articles\Categorie;
  9. use App\Entity\Articles\ConditionAchat;
  10. use App\Entity\Articles\FamilleCompta;
  11. use App\Entity\Articles\HistoriqueArticle;
  12. use App\Entity\Articles\Image;
  13. use App\Entity\Articles\Marque;
  14. use App\Entity\Articles\MouvementStock;
  15. use App\Entity\Articles\RaisonMouvementStock;
  16. use App\Entity\Articles\RefsEquivalentes;
  17. use App\Entity\Articles\Type;
  18. use App\Entity\FO\FoDocument;
  19. use App\Entity\FO\Societe;
  20. use App\Entity\FO\FoDocumentArticle;
  21. use App\Entity\Fournisseurs\Fournisseur;
  22. use App\Entity\Ged\Fichier;
  23. use App\Entity\GestionComerciale\Commande;
  24. use App\Model\GestionCommerciale\TypeDocumentCommercial;
  25. use App\Entity\GestionComerciale\ArticleCommande;
  26. use App\Entity\GestionComerciale\StatutCommande;
  27. use App\Entity\MarketPlace\ArticleMarketPlace;
  28. use App\Entity\MarketPlace\ArticleMarketPlaceCaracteristique;
  29. use App\Entity\MarketPlace\ArticleMarketPlaceImage;
  30. use App\Entity\MarketPlace\Caracteristiques;
  31. use App\Entity\MarketPlace\CategorieErpCategorieMarketPlace;
  32. use App\Entity\MarketPlace\CompteMarketPlace;
  33. use App\Entity\MarketPlace\ErreurPublicationArticleMarketPlace;
  34. use App\Entity\MarketPlace\MarketPlace;
  35. use App\Entity\MarketPlace\Profil;
  36. use App\Entity\MarketPlace\StatutArticle;
  37. use App\Entity\MarketPlace\TarifModeLivraison;
  38. use App\Entity\Vehicules\Application;
  39. use App\Entity\Vehicules\Modele;
  40. use App\Entity\Vehicules\Type as VehiculesType;
  41. use App\Form\Articles\ArticleDiversType;
  42. use App\Form\Articles\ArticleRechercheType;
  43. use App\Form\Articles\ArticleType;
  44. use App\Library\Datatable\Util\Datatable;
  45. use App\Library\Uploader\Services\FileUploader;
  46. use App\Security\Voter\EntityVoter;
  47. use App\Service\Articles\ArticleCategorieService;
  48. use App\Service\Articles\ArticleService;
  49. use App\Service\Articles\DocumentArticle;
  50. use App\Service\Articles\ImageArticleService;
  51. use App\Service\MarketPlace\ArticleMarketPlaceService;
  52. use App\Service\Utilisateur\ColonneTableauService;
  53. use Doctrine\ORM\EntityManagerInterface;
  54. use DTS\eBaySDK\FileTransfer\Types\Data;
  55. use JMS\Serializer\SerializerBuilder;
  56. use Knp\Component\Pager\PaginatorInterface;
  57. use Knp\Snappy\Pdf;
  58. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  59. use Symfony\Component\HttpFoundation\Request;
  60. use Symfony\Component\HttpFoundation\JsonResponse;
  61. use Symfony\Component\HttpFoundation\Response;
  62. use Symfony\Component\Routing\Annotation\Route;
  63. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  64. use Symfony\Component\Validator\Validator\ValidatorInterface;
  65. use Symfony\Contracts\Translation\TranslatorInterface;
  66. use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
  67. use JMS\Serializer\SerializationContext;
  68. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  69. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  70. class ArticleController extends AbstractController
  71. {
  72.     /**
  73.      * @Route("/catalogue", name="dtc_article_liste")
  74.      */
  75.     public function listerAction(Request $requestEntityManagerInterface $emColonneTableauService $serviceColonneTableauDatatable $datatable,TranslatorInterface $translator,$parent null)
  76.     {
  77.         $categorie_enfants         = [];
  78.         $categorie_enfants_enfants = [];
  79.         $repo_categorie_article    $em->getRepository(Categorie::class);
  80.         $categorie_article_racine  $repo_categorie_article->findBy(["categorieParent" => 1]);
  81.         $encartCatalogue    $em->getRepository(FoDocument::class)->getEncartCatalogue(false);
  82.         $encartCatalogueMobile    $em->getRepository(FoDocument::class)->getEncartCatalogue(true);
  83.         $repo_marque_article $em->getRepository(Marque::class);
  84.         $marque_article      $repo_marque_article->findBy([], ['libelle' => 'ASC']);
  85.         $repo_type_article $em->getRepository(Type::class);
  86.         $type_article      $repo_type_article->findBy([], ['libelle' => 'ASC']);
  87.         $param $request->query->all();
  88.         //if(count($param) == 0) $param['mouvemente'] = '0';
  89.         if (array_key_exists('categorie_article'$param) and $param["categorie_article"] > 0) {
  90.             $parent $repo_categorie_article->find($param["categorie_article"]);
  91.             if (is_object($parent)) {
  92.                 $categorie_enfants $repo_categorie_article->findBy(["categorieParent" => $parent]);
  93.             }
  94.         }
  95.         //\Doctrine\Common\Util\Debug::dump($param);
  96.         //    $param["mouvemente"]=1;
  97.         $this->datatable($datatable$request$em$translator);
  98.         $tableau_class_cellule = array();
  99.         $tableau_class_cellule[] = ["searchable" => true,"className"  => "","targets"=> [0],"visible"=> false,];
  100.         $tableau_class_cellule[] = [
  101.             "searchable" => true,
  102.             "className"  => "",
  103.             "targets"    => [1],
  104.             "visible"    => false,
  105.         ];
  106.         $tableau_class_cellule[] = [
  107.             "searchable" => true,
  108.             "className"  => "",
  109.             "targets"    => [2],
  110.             "visible"    => false,
  111.         ];
  112.         $tableau_class_cellule[] = [
  113.             "searchable" => true,
  114.             "className"  => "",
  115.             "targets"    => [4],
  116.             "visible"    => false,
  117.         ];
  118.         if (array_key_exists('mc'$param) or array_key_exists('p'$param) or array_key_exists('c'$param) or array_key_exists('m'$param)) {
  119.             return $this->render('Articles/Article/lister.html.twig', [
  120.                 'name'                        => 'article',
  121.                 'tableauClassColonne'         => $tableau_class_cellule,
  122.                 'parametres'                  => $param,
  123.                 "categorie_article"           => $categorie_article_racine,
  124.                 "sous_categorie_article"      => $categorie_enfants,
  125.                 "sous_sous_categorie_article" => $categorie_enfants_enfants,
  126.                 "marque"                      => $marque_article,
  127.                 "type"                        => $type_article,
  128.                 "parent"                      => $parent,
  129.                 "encartCatalogueMobile"                      => $encartCatalogueMobile,
  130.                 "encartCatalogue"                      => $encartCatalogue,
  131.                 //'mouvemente' => $mouvemente
  132.             ]);
  133.         } else {
  134.             return $this->render('Articles/Article/recherche.html.twig', [
  135.                 'name'                        => 'article',
  136.                 'tableauClassColonne'         => $tableau_class_cellule,
  137.                 'parametres'                  => $param,
  138.                 "categorie_article"           => $categorie_article_racine,
  139.                 "sous_categorie_article"      => $categorie_enfants,
  140.                 "sous_sous_categorie_article" => $categorie_enfants_enfants,
  141.                 "marque"                      => $marque_article,
  142.                 "type"                        => $type_article,
  143.                 "parent"                      => $parent,
  144.                 "encartCatalogueMobile"                      => $encartCatalogueMobile,
  145.                 "encartCatalogue"                      => $encartCatalogue,
  146.             ]);
  147.         }
  148.     }
  149.     /**
  150.      * set datatable configs
  151.      *
  152.      * @return \App\Library\Datatable\Util\Datatable
  153.      */
  154.     private function datatable(Datatable $datatableRequest $requestEntityManagerInterface $emTranslatorInterface $translator)
  155.     {
  156.         $clientId 0;
  157.         if($this->getUser() && $this->getUser()->getClient()) $clientId $this->getUser()->getClient()->getId();
  158.         $param      $request->query->all();
  159.         $parametres = [];
  160.         $parent     $request->query->get('parent');
  161.         if ($parent == '') {
  162.             $where " AND x.parent is null";
  163.         } else {
  164.             $where " AND x.parent = :parent";
  165.             $parametres['parent'] = $parent;
  166.         }
  167.         if ( ! array_key_exists('parametres'$param)) {
  168.             $param["parametres"] = $param;
  169.         }
  170.         $conn $em->getConnection();
  171.         $conn->getConfiguration()->setSQLLogger(null);
  172.         $qb $em->createQueryBuilder();
  173.         $qb->select(
  174.             "
  175.             x.id as x_id,               
  176.             x.dateProchaineDispo as x_dateProchaineDispo,
  177.             x.libelle as x_libelle,
  178.             x.reference as x_reference,
  179.             x.descriptionCourte as x_descriptionCourte,
  180.             x.description as x_description,
  181.             x.libelleSecondaire as x_libelleSecondaire,
  182.             x.prixVente as x_prixVente,
  183.             x.prixBase as x_prixBase,
  184.             x.tauxMarge as x_tauxMarge,"
  185.             //."x.cpump as x_cpump,"
  186.             ."x.pump as x_pump,"
  187.             ."x.stock as x_stock,
  188.             x.dispo as x_dispo,
  189.             x.statut as x_statut,
  190.             m.libelle as m_libelle,
  191.             m.logo as m_logo,
  192.             m.id as m_id,                             
  193.             r.id as r_id,
  194.             r.tauxDefaut as r_tauxDefaut,
  195.             x.referenceAppel10 as x_referenceAppel10
  196.             "
  197.             )
  198.             ->orderBy('x.id''DESC')
  199.             ->from(Article::class, "x")
  200.             ->leftJoin('x.marque''m')
  201.             ->leftJoin('App\Entity\Clients\ClientMarque','ccm',\Doctrine\ORM\Query\Expr\Join::WITH'ccm.marque = x.marque AND ccm.client = :clientId')
  202.             ->leftJoin('x.regleTaxe''r'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  203.         $parametres['clientId']=$clientId;
  204.         $where .= " AND (m.statut = 1)";
  205.         $where .= " AND ccm.id IS NULL";
  206.         if (array_key_exists('p'$param['parametres']) and count($param['parametres']['p'])>0) {
  207.             $where .= " AND x.id IN (:produits)";
  208.             $parametres['produits'] = $param['parametres']['p'];
  209.         }
  210.         if (array_key_exists('st'$param['parametres']) and $param['parametres']['st'] == "1") {
  211.             $where .= " AND (x.dispo > 0)";
  212.         }
  213.         if (array_key_exists('mc'$param['parametres']) and $param['parametres']['mc'] != "" and $param['parametres']['mc'] != "" and $param['parametres']['mc'] != "0") {
  214.             //$cond = "%".trim($param['parametres']['mc'])."%";
  215.             //$where .= " AND (x.reference LIKE :recherche or x.libelle LIKE :recherche)";
  216.             //$parametres['recherche'] = $cond;
  217.             $search trim($param['parametres']['mc']);
  218.             $words preg_split('/\s+/'$search);
  219.             $conditions = [];
  220.             foreach ($words as $index => $word) {
  221.                 $key 'recherche_' $index;
  222.                 $conditions[] = "(x.reference LIKE :$key OR x.libelle LIKE :$key)";
  223.                 $parametres[$key] = '%' $word '%';
  224.             }
  225.             if (!empty($conditions)) {
  226.                 $where .= " AND (" implode(' AND '$conditions) . ")";
  227.             }
  228.         }
  229.         if (array_key_exists('cn3'$param['parametres']) and $param['parametres']['cn3'] != "" and $param['parametres']['cn3'] != "0") {
  230.             $qb->join('x.articleCategorie''ac3'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  231.             $qb->join('ac3.categorie''cat3'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  232.             $where .= " AND cat3.id = :categorie3";
  233.             $parametres['categorie3'] = $param['parametres']['cn3'];
  234.         }
  235.         else if (array_key_exists('cn2'$param['parametres']) and $param['parametres']['cn2'] != "" and $param['parametres']['cn2'] != "0") {
  236.             $qb->join('x.articleCategorie''ac2'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  237.             $qb->join('ac2.categorie''cat2'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  238.             $where .= " AND cat2.id = :categorie2";
  239.             $parametres['categorie2'] = $param['parametres']['cn2'];
  240.         }
  241.         else if (array_key_exists('c'$param['parametres']) and $param['parametres']['c'] != "" and $param['parametres']['c'] != "0") {
  242.             $qb->join('x.articleCategorie''ac'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  243.             $qb->join('ac.categorie''cat'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  244.             $where .= " AND cat.id = :categorie";
  245.             $parametres['categorie'] = $param['parametres']['c'];
  246.         }
  247.         if (array_key_exists('m'$param['parametres']) and $param['parametres']['m'] != "" and $param['parametres']['m'] != "0") {
  248.             //$qb->join('x.marque', 'm', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  249.             $where                .= " AND x.marque = :marque";
  250.             $parametres['marque'] = $param['parametres']['m'];
  251.         }
  252.         if (array_key_exists('tv'$param['parametres']) and $param['parametres']['tv'] != "" and $param['parametres']['tv'] != "0") {
  253.              $qb->leftJoin('x.articleApplication''aa'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  254.             //$where .= " AND (x.universel = 1)";
  255.             $where .= " AND (aa.type = :typeVehicule or x.universel = 1)";
  256.             $parametres['typeVehicule'] = $param['parametres']['tv'];
  257.         }
  258.         else if (array_key_exists('mov'$param['parametres']) and $param['parametres']['mov'] != "" and $param['parametres']['mov'] != "0") {
  259.             $qb->leftJoin('x.articleApplication''aa'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  260.             $where .= " AND (aa.modele = :modeleVehicule or x.universel = 1)";
  261.             $parametres['modeleVehicule'] = $param['parametres']['mov'];
  262.         }
  263.         else if (array_key_exists('mv'$param['parametres']) and $param['parametres']['mv'] != "" and $param['parametres']['mv'] != "0") {
  264.             $qb->leftJoin('x.articleApplication''aa'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  265.             $where .= " AND ( aa.marque = :marqueVehicule OR x.universel = 1 )";
  266.             //$where .= " AND (aa.marque = :marqueVehicule or (aa.id is null and x.universel = 1))";
  267.             $parametres['marqueVehicule'] = $param['parametres']['mv'];
  268.         }
  269.         //echo $where;
  270.         //print_r($parametres);
  271.         //$qb->where('x.temporaire is null and (x.archive = 0 or x.archive is null)'.$where);
  272.         $where .= " AND (
  273.             (x.virtuel != 1
  274.             )
  275.             OR NOT EXISTS (
  276.                 SELECT ac_check.id
  277.                 FROM App\Entity\Articles\ArticleComposant ac_check
  278.                 JOIN ac_check.article a_child
  279.                 WHERE ac_check.articleCompose = x
  280.                 AND ((a_child.archive = 1) OR (a_child.arretGamme = 1))
  281.              
  282.             )
  283.         )";
  284.         $qb->where('x.temporaire is null AND (x.statut is null or x.statut = 1) AND (x.arretGamme = 0 or x.arretGamme is null ) AND (x.archive = 0 or x.archive is null ) '.$where);
  285.         $qb->distinct();
  286.         if (count($parametres) > 0) {
  287.             $qb->setParameters($parametres);
  288.         }
  289.         $qb->orderBy("x.position""desc");
  290.         $datatable $datatable
  291.             ->setFields(
  292.                 [
  293.                     $translator->trans("ID")          => 'x.id',
  294.                     $translator->trans("Img")         => 'x.reference',
  295.                     $translator->trans("Réf")         => 'x.reference',
  296.                     $translator->trans("Libelle")         => 'x.libelle',
  297.                     "_identifier_"                  => 'x.id'
  298.                 ]
  299.             )
  300.             ->setRenderers(
  301.                 [
  302.                     => [
  303.                         'view'   => 'FO/DataTable/article_id.html.twig',
  304.                         'params' => [
  305.                             'edit_route' => 'dtc_article_liste',
  306.                         ],
  307.                     ],
  308.                     => [
  309.                         'view'   => 'FO/DataTable/article_image.html.twig',
  310.                         'params' => [
  311.                             'edit_route' => 'dtc_article_liste',
  312.                         ],
  313.                     ],
  314.                     => [
  315.                         'view'   => 'FO/DataTable/detail_produit.html.twig',
  316.                         'params' => [
  317.                             'edit_route' => 'dtc_article_liste',
  318.                         ],
  319.                     ],
  320.                 ]
  321.             )
  322.             ->setSearch(true)
  323.             ->setGlobalSearch(1)
  324.             //->setFilteringType([2 => 'e', 3 => 'e'])
  325.             //->setSearchFields([2, 3])
  326.             ->setMultiple(
  327.                 [
  328.                     'delete' => [
  329.                         'title' => 'Non disponible',
  330.                         'route' => 'dtc_article_liste',
  331.                     ],
  332.                 ]
  333.             )
  334.             ->setOrder("x.id""desc")
  335.             ;
  336.         $datatable->getQueryBuilder()->setDoctrineQueryBuilder($qb);
  337.         return $datatable;
  338.     }
  339.     /**
  340.      * @Route("/articles/grid", name="dtc_article_liste_grid")
  341.      */
  342.     public function gridAction(Request $requestDatatable $datatableEntityManagerInterface $entityManagerTranslatorInterface $translator)
  343.     {
  344.         return $this->datatable($datatable$request$entityManager$translator)->execute();
  345.     }
  346.     /**
  347.      * @Route("/produits/{slug}-{id}", name="dtc_article_afficher", requirements={"id"="\d+", "slug"="[a-z0-9\-]+"})
  348.      */
  349.     public function AfficherAction(Request                 $requestArticle $articleEntityManagerInterface $em,  ImageArticleService $imageArticleService,
  350.                                    ArticleCategorieService $articleCategorieServiceValidatorInterface $validatorDocumentArticle $documentArticleArticleService $articleService,
  351.                                    Datatable $datatableTranslatorInterface $translatorFileUploader $fileUploader
  352.     ) {
  353.         $user $this->getUser();
  354.         $client_id 0;
  355.         $marque_visible true;
  356.         if($user && is_object($user->getClient())) {
  357.             $client_id $user->getClient()->getId();
  358.             $marqueClient $em->getRepository(ClientMarque::class)->findOneBy(["client"=>$user->getClient(),"marque"=>$article->getMarque()]);
  359.             if(is_object($marqueClient)) $marque_visible false;
  360.         }
  361.         if (!$marque_visible or ($article->getArchive()) or ($article->getArretGamme())  or (!$article->getStatut() && !is_null($article->getStatut())) or (is_object($article->getMarque()) && !$article->getMarque()->getStatut()))
  362.         {
  363.             throw $this->createNotFoundException('La ressource demandée n’existe pas.');
  364.         }
  365.         //$articleOptions = $em->getRepository(ArticleComplementOption::class)->findBy(["parent"=>$article,'type'=>'option']);
  366.         $articleOptions $em->getRepository(ArticleComplementOption::class)->findEnfantsByParentAndStatus($article->getid(), $status 1,'option',$client_id);
  367.         $articleComplements $em->getRepository(ArticleComplementOption::class)->findEnfantsByParentAndStatus($article->getid(), $status 1,'complement',$client_id);
  368.         $catalogues $em->getRepository(FoDocumentArticle::class)->findBy(["article"=>$article]);
  369.         $articleComposants = [];
  370.         if($article->getVirtuel()) {
  371.             $articleComposants $em->getRepository(ArticleComposant::class)->findComposantsByParentAndStatus($article->getid(), $status 1,$client_id);
  372.             if(count($articleComposants)>0) {
  373.                 foreach($articleComposants as $ac) {
  374.                     if(!$ac->getArticle()->getStatut() || ($ac->getArticle()->getArchive() && !is_null($ac->getArticle()->getArchive())) || $ac->getArticle()->getArretGamme()) {
  375.                         $articleComposants = [];
  376.                         throw $this->createNotFoundException('La ressource demandée n’existe pas.');
  377.                         break;
  378.                     }
  379.                 }
  380.             }
  381.         }
  382.         return $this->render(
  383.             'Articles/Article/afficher.html.twig',
  384.             [
  385.                 'article'                     => $article,
  386.                 'articleOptions'                     => $articleOptions,
  387.                 'articleComplements'                     => $articleComplements,
  388.                 'articleComposants'                     => $articleComposants,
  389.                 'catalogues'                     => $catalogues,
  390.             ]
  391.         );
  392.     }
  393.     /**
  394.      * @Route("/article/recherche", name="dtc_article_recherche")
  395.      */
  396.     public function rechercheAction(Request $requestEntityManagerInterface $emPaginatorInterface $paginatorArticleService $articleServiceImageArticleService $imageArticleService,CacheManager $cacheManager)
  397.     {
  398.         //exit;
  399.         $user $this->getUser();
  400.         $tabMarqueExclure = [];
  401.         if($user && is_object($user->getClient())) {
  402.             $marqueClient $em->getRepository(ClientMarque::class)->findBy(["client"=>$user->getClient()]);
  403.             if(count($marqueClient)>0) {
  404.                 foreach($marqueClient as $mc) {
  405.                     if(is_object($mc->getMarque())) {
  406.                         $tabMarqueExclure[]=$mc->getMarque()->getId();
  407.                     }
  408.                 }
  409.             }
  410.         }
  411.         $q $request->query->get('q');
  412.         $produitInterne $request->query->get('interne');
  413.         $articleAExclure  $request->query->get('article');
  414.         $articlesAExclure = [];
  415.         if ($articleAExclure !== null && $articleAExclure != '') {
  416.             $article $em->getRepository(Article::class)->find($articleAExclure);
  417.             $articlesAExclure[] = $articleAExclure;
  418.             if (is_object($article)) {
  419.                 foreach ($article->getArticlesComposants() as $articleComposant) {
  420.                     $articlesAExclure[] = $articleComposant->getArticle()->getId();
  421.                 }
  422.             }
  423.         }
  424.         $page $request->query->getInt('page'1);
  425.         $repo $em->getRepository(Article::class);
  426.         $tri_reference $request->query->get('tri_reference');
  427.         $tri_libelle   $request->query->get('tri_libelle');
  428.         $tri_prix      $request->query->get('tri_prix');
  429.         $tri_stock     $request->query->get('tri_stock');
  430.        if(1==1) {
  431.             $results $repo->getRechercheArticleSelectObi(
  432.                 $q,
  433.                 $produitInterne,
  434.                 $request->query->get('fournisseur'),
  435.                 $articlesAExclure,
  436.                 $request->query->get('stock'),
  437.                 $request->query->get('reference_search'),
  438.                 $request->query->get('libelle_search'),
  439.                 $request->query->get('prix_search'),
  440.                 $tri_reference,
  441.                 $tri_libelle,
  442.                 $tri_prix,
  443.                 $tri_stock,
  444.                 $request->query->get('categorie'),
  445.                 $request->query->get('mouvemente'),
  446.                 $request->query->get('inventaire'),
  447.                 $request->query->get('declinaisons')
  448.             );
  449.         }
  450.         $triRechercheArticle      "";
  451.         $ordreTriRechercheArticle "";
  452.         $majTri                   false;
  453.         if ($request->query->get('mouvemente') != "") {
  454.             if ($request->query->get('mouvemente') == "1" && ( ! $user->getMouvementeRechercheArticle() or is_null($user->getMouvementeRechercheArticle()))) {
  455.                 $user->setMouvementeRechercheArticle(true);
  456.                 $em->persist($user);
  457.                 $em->flush();
  458.             } elseif ($request->query->get('mouvemente') == "0" && ($user->getMouvementeRechercheArticle() or is_null($user->getMouvementeRechercheArticle()))) {
  459.                 $user->setMouvementeRechercheArticle(false);
  460.                 $em->persist($user);
  461.                 $em->flush();
  462.             }
  463.         }
  464.         if ($request->query->get('tri_reference') != "") {
  465.             $triRechercheArticle      "tri_reference";
  466.             $ordreTriRechercheArticle $request->query->get('tri_reference');
  467.             $majTri                   true;
  468.         } elseif ($request->query->get('tri_libelle') != "") {
  469.             $triRechercheArticle      "tri_libelle";
  470.             $ordreTriRechercheArticle $request->query->get('tri_libelle');
  471.             $majTri                   true;
  472.         } elseif ($request->query->get('tri_prix') != "") {
  473.             $triRechercheArticle      "tri_prix";
  474.             $ordreTriRechercheArticle $request->query->get('tri_prix');
  475.             $majTri                   true;
  476.         } elseif ($request->query->get('tri_stock') != "") {
  477.             $triRechercheArticle      "tri_stock";
  478.             $ordreTriRechercheArticle $request->query->get('tri_stock');
  479.             $majTri                   true;
  480.         }
  481.         //echo $user->getEmail();
  482.         if ($majTri) {
  483.             $user->setTriRechercheArticle($triRechercheArticle);
  484.             $user->setOrdreTriRechercheArticle($ordreTriRechercheArticle);
  485.             $em->persist($user);
  486.             $em->flush();
  487.         }
  488.         $pagination $paginator->paginate(
  489.             $results/* query NOT result */
  490.             $request->query->getInt('page'$page)/*page number*/,
  491.             20/*limit per page*/
  492.         );
  493.         $pagination_results $pagination->getItems();
  494.         $tabPremiereLigne = [
  495.             "libelle_secondaire"     => "",
  496.             "reference_appel_2"     => "",
  497.             "reference_appel_3"     => "",
  498.             "reference_appel_4"     => "",
  499.             "reference_appel_5"     => "",
  500.             "reference_appel_6"     => "",
  501.             "reference_appel_7"     => "",
  502.             "reference_appel_8"     => "",
  503.             "reference_appel_9"     => "",
  504.             "reference_appel_10"    => "",
  505.             "reference_appel_11"    => "",
  506.             "arret_gamme"           => "",
  507.             "virtuel"               => "",
  508.             "libelle"               => "Sélectionnez",
  509.             "libelle_construit"     => "Sélectionnez",
  510.             "id"                    => "",
  511.             "reference_fournisseur" => "",
  512.             "prixVente"             => "",
  513.             "prixAchat"             => "",
  514.             "poids"                 => "",
  515.             "stock"                 => 0,
  516.             "stock_reserve"         => 0,
  517.             "cpump"                 => "",
  518.             "reference"             => "",
  519.             "dispo"                 => "",
  520.             "image"                 => "",
  521.             "marque"                 => "",
  522.             "virtuel"                 => "",
  523.             "afficher_composant_pdf_externe"                 => "",
  524.         ];
  525.         //$option_placeholde = array("libelle"=>"Sélectionnez","id"=>"","stock"=>"","stock_reserve"=>"");
  526.         $option_placeholde $tabPremiereLigne;
  527.         if ($request->query->getInt('page'1) == 1) {
  528.             array_unshift($pagination_results$option_placeholde);
  529.         }
  530.         $pagination->setItems($pagination_results);
  531.         /*if($q == "" && $page < 2) {
  532.              $option_placeholde = array("libelle"=>"Recherche à partir du libellé ou de la référence article","id"=>"","reference"=>"Réf","prixVente"=>"Prix","stock"=>"Stock");
  533.             array_unshift($pagination_results, $option_placeholde);
  534.             $pagination->setItems($pagination_results);
  535.         }
  536.         */
  537.         $option_placeholde = [
  538.             "libelle"             => "Sélectionnez",
  539.             "id"                  => "",
  540.             "reference"           => "",
  541.             "prixVente"           => "",
  542.             "stock"               => 0,
  543.             "prixAchat"           => "",
  544.             "dispo"               => "d",
  545.             "nbArticleInventaire" => "",
  546.         ];
  547.         if ($request->query->getInt('page'1) == 1) {
  548.             array_unshift($pagination_results$option_placeholde);
  549.         }
  550.         //print_r($pagination_results);
  551.         $tabFinal = [];
  552.         //foreach($pagination as $p) {
  553.         for ($i 1$i count($pagination_results); $i++) {
  554.             //print_r($pagination_results[$i]);
  555.             $tabTemp = [];
  556.             $continuer true;
  557.             if ($request->query->get('declinaisons') == true) {
  558.                 $enfants $repo->findBy(["articleDeclinaisonParent" => $pagination_results[$i]["id"]]);
  559.                 if (count($enfants) > 0) {
  560.                     //echo "TEST ".$pagination_results[$i]["id"];
  561.                     $continuer false;
  562.                 }
  563.             }
  564.             if ($continuer) {
  565.                 $tabTemp $pagination_results[$i];
  566.                 $tabTemp["affichagePrix"] = "TTC";
  567.                 $tabTemp["prixVenteTtc"] = 0;
  568.                 if($user) {
  569.                     $tabTemp["affichagePrix"] = "HT";
  570.                 }
  571.                 else {
  572.                     if($pagination_results[$i]["id"]>0$tabTemp["prixVenteTtc"] = $articleService->getPrixVenteTtc($pagination_results[$i]["id"]);
  573.                 }
  574.                 if ( ! array_key_exists('virtuel'$tabTemp) or $tabTemp["virtuel"] == "") {
  575.                     $tabTemp["virtuel"] = 0;
  576.                 }
  577.                 $tabTemp["dateProchaineDispo"]=null;
  578.                 if( $tabTemp["dispo"] <= 0) {
  579.                     if(count($articleService->getDatesProchainesDispo($tabTemp["id"]))>0$tabTemp["dateProchaineDispo"]="ok";
  580.                 }
  581.                 /*
  582.                 $tabTemp["dispo"] = 0;
  583.                 if ($tabTemp["virtuel"] === 0) {
  584.                     $tabTemp["dispo"] = $tabTemp["stock"] - $tabTemp["stock_reserve"];
  585.                 } else {
  586.                     //echo "HHHH";
  587.                     //{% set dispo = dtc_article.getStock(a.article)  %}
  588.                     $objArticle       = $em->getRepository(Article::class)->find($tabTemp["id"]);
  589.                     $tabTemp["dispo"] = $articleService->getStock($objArticle);
  590.                 }
  591.                 */
  592.                 if($pagination_results[$i]["id"]>0$tabTemp["slug"] = $articleService->getslugifArticle($pagination_results[$i]["id"]);
  593.                 $tabTemp["dispo"] = max(0$tabTemp["dispo"]);
  594.                 // {% set images = dtc_image_article.getImageDefaut(dt_obj.x_id) %}
  595.                 $images $imageArticleService->getImageDefaut($tabTemp["id"]);
  596.                 $tabTemp["image"] = "";
  597.                 $URL_IMAGE_DISTANT $this->getParameter('URL_IMAGE_DISTANT');
  598.                 if(count($images)>0) {
  599.                     foreach($images as $img) {
  600.                         //<img src="{{ asset(images[0].getUploadDir ~ '/' ~ dt_obj.x_id ~ '/' ~ images[0].url) | imagine_filter('400x300') }}" style="max-width:100%;">
  601.                         //$tabTemp["image"] = "/".$img->getUploadDir()."/".$img->getArticle()->getId()."/".$img->getUrl();
  602.                         //$tabTemp["image"] = $cacheManager->getBrowserPath($tabTemp["image"], "400x300");
  603.                         $tabTemp["image"] = $URL_IMAGE_DISTANT."/image/400/300/".$img->getUlid();
  604.                         break;
  605.                     }
  606.                 }
  607.                 else {
  608.                     $tabTemp["image"] ="/images/defaut-img-product.jpg";
  609.                 }
  610.                 if($pagination_results[$i]["id"]>0) {
  611.                     $tabTemp["remiseId"] = NULL;
  612.                     $tabTemp["valeurRemise"] = NULL;
  613.                     $tabTemp["prixRemise"] = NULL;
  614.                     if($user) {
  615.                         $remise_article $articleService->getRemisesPossibleArticleClient(['article'=>$pagination_results[$i]["id"]],$user->getClient());
  616.                         $tabTemp["remiseId"] = $remise_article["remiseId"];
  617.                         $tabTemp["valeurRemise"] = $remise_article["valeur"];
  618.                         $tabTemp["prixRemise"] = $remise_article["prixRemise"];
  619.                     }
  620.                 }
  621.                 if(array_key_exists('logo_marque'$tabTemp) &&  $tabTemp["logo_marque"] != "") {
  622.                     $tabTemp["logo_marque"] = "/uploads/logos/marques/"$tabTemp["id_marque"]."/".$tabTemp["logo_marque"];
  623.                     $tabTemp["logo_marque"] = $cacheManager->getBrowserPath($tabTemp["logo_marque"], "400x300");
  624.                 }
  625.                 if(!array_key_exists('id_marque'$tabTemp) or !in_array($tabTemp["id_marque"],$tabMarqueExclure)) {
  626.                     $client_id 0;
  627.                     if($user && is_object($user->getClient())) {
  628.                         $client_id $user->getClient()->getId();
  629.                     }
  630.                    $ajouter_article true;
  631.                     if($pagination_results[$i]["virtuel"]==1) {
  632.                         $articleComposants $em->getRepository(ArticleComposant::class)->findComposantsByParentAndStatus($pagination_results[$i]["id"], $status 1,$client_id);
  633.                         if(count($articleComposants)>0) {
  634.                             foreach($articleComposants as $ac) {
  635.                                 if(!$ac->getArticle()->getStatut() || ($ac->getArticle()->getArchive() && !is_null($ac->getArticle()->getArchive())) || $ac->getArticle()->getArretGamme()) {
  636.                                     $ajouter_article false;
  637.                                     break;
  638.                                 }
  639.                             }
  640.                         }
  641.                     }
  642.                     if($ajouter_article$tabFinal[] = $tabTemp;
  643.                 }
  644.             }
  645.         }
  646.         //print_r($tabFinal);
  647.         //print_r($tabFinal);
  648.         //$pagination->setItems($pagination_results);
  649.         $pagination->setItems($tabFinal);
  650.         //print_r($pagination);
  651.         //$em->getConnection()->close();
  652.         $context SerializationContext::create()->setSerializeNull(true);
  653.         $serializer SerializerBuilder::create()->build();
  654.         return JsonResponse::fromJsonString($serializer->serialize($pagination'json',
  655.             $context));
  656.     }
  657.     /**
  658.      * @Route("/article/complement/{id}", name="dtc_article_complement_modal")
  659.      */
  660.     public function ArticleComplementModalAction(Request$requestArticle $articleEntityManagerInterface $em,TranslatorInterface $translator,ValidatorInterface $validator)
  661.     {
  662.         $titre_modal "Optimisez votre commande : pensez aux essentiels qui vont avec !";
  663.         $articleComplements $em->getRepository(ArticleComplementOption::class)->findEnfantsByParentAndStatus($article->getid(), $status 1,'complement');
  664.         $rendu     $this->renderView('Articles/Article/complement_modal.html.twig',["articleComplements"=>$articleComplements]);
  665.         // $rendu = $this->renderView('FO/Supprimer/supprimer_impossible.html.twig', ['errors' => $erreur]);
  666.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  667.     }
  668. }