src/Controller/GestionComerciale/ActionAjaxController.php line 3282

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GestionComerciale;
  3. use App\Entity\Adresses\Adresse;
  4. use App\Entity\Articles\Article;
  5. use App\Entity\Articles\ArticleCategorie;
  6. use App\Entity\Articles\Categorie;
  7. use App\Entity\Articles\ConditionAchat;
  8. use App\Entity\Rangements\Caisse;
  9. use App\Entity\Articles\ConditionnementAchat;
  10. use App\Entity\Articles\ConditionVente;
  11. use App\Entity\Clients\Client;
  12. use App\Entity\FO\CompteBancaire;
  13. use App\Entity\Fournisseurs\Fournisseur;
  14. use App\Entity\GestionComerciale\Acompte;
  15. use App\Entity\GestionComerciale\ArticleCommande;
  16. use App\Entity\GestionComerciale\Commande;
  17. use App\Entity\GestionComerciale\CommandeFournisseur;
  18. use App\Entity\GestionComerciale\Fabrication;
  19. use App\Entity\GestionComerciale\FabricationMultiple;
  20. use App\Model\GestionCommerciale\TypeDocumentCommercial;
  21. use App\Entity\Taxes\Taxe;
  22. use App\Entity\Traductions\Traduction;
  23. use App\Form\GestionComercialeBundle\CopiesLignesType;
  24. use App\Service\Articles\ArticleService;
  25. use App\Service\FO\DateService;
  26. use App\Service\Fournisseurs\FournisseurService;
  27. use App\Service\GestionComerciale\CommandeService;
  28. use App\Service\GestionComerciale\FabricationService;
  29. use App\Service\Utilisateur\ColonneTableauService;
  30. use Doctrine\ORM\EntityManagerInterface;
  31. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  32. use Symfony\Component\Form\FormError;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\HttpFoundation\JsonResponse;
  35. use Symfony\Component\HttpFoundation\Response;
  36. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  37. use Symfony\Component\Routing\Annotation\Route;
  38. use Symfony\Component\Validator\Validator\ValidatorInterface;
  39. use Symfony\Contracts\Translation\TranslatorInterface;
  40. class ActionAjaxController extends AbstractController
  41. {
  42.     /**
  43.      * @Route("/commande-article/interchanger/{commande}/{article}", name="dtc_article_est_interchangeable")
  44.      */
  45.     public function articleEstInterchangeableAction(Request $requestCommande $commandeArticle $articleEntityManagerInterface $em)
  46.     {
  47.         $rendu           true;
  48.         $typeBon         TypeDocumentCommercial::BP;
  49.         $bonPreparations $em->getRepository(Commande::class)->findBy(["commande" => $commande"typeDocumentCommercial" => $typeBon]);
  50.         $repo_article_commande $em->getRepository(ArticleCommande::class);
  51.         foreach ($bonPreparations as $b) {
  52.             if ( ! is_object($b->getStatutCommande()) or (is_object($b->getStatutCommande()) and $b->getStatutCommande()->getOrdre() != 0)) {
  53.                 $articleBon $repo_article_commande->findBy(["commande" => $b"article" => $article]);
  54.                 foreach ($articleBon as $ab) {
  55.                     $rendu false;
  56.                 }
  57.             }
  58.         }
  59.         return new JsonResponse(['rendu' => $rendu]);
  60.     }
  61.     /**
  62.      * @Route("/vente/commande/ajax/detail/{id}", name="dtc_commande_detail_ajax")
  63.      */
  64.     public function detailCommandeAction(Request $requestCommande $commande)
  65.     {
  66.         $get  $request->query->all();
  67.         $mode "";
  68.         if ( ! empty($get["mode"])) {
  69.             $mode $get["mode"];
  70.         }
  71.         $rendu $this->renderView('GestionComerciale/Commande/detail_datatable.html.twig', ['commande' => $commande"mode" => $mode]);
  72.         return new JsonResponse(['rendu' => $rendu]);
  73.     }
  74.     /**
  75.      * @Route("/vente/ofm/ajax/detail/{id}", name="dtc_ofm_detail_ajax")
  76.      */
  77.     public function detailOfmAction(Request $requestFabricationMultiple $ofm)
  78.     {
  79.         $rendu $this->renderView('GestionComerciale/FabricationMultiple/detail_datatable.html.twig', ['ofm' => $ofm]);
  80.         return new JsonResponse(['rendu' => $rendu,]);
  81.     }
  82.     /**
  83.      * @Route("/vente/caisse/ajax/detail/{id}", name="dtc_caisse_detail_ajax")
  84.      */
  85.     public function detailCaisseAction(Request $requestCaisse $caisseEntityManagerInterface $em)
  86.     {
  87.         $repo_fabrication $em->getRepository(Fabrication::class);
  88.         $fabrications $repo_fabrication->findBy(["caisse"=>$caisse,'statutFabrication'=>11]);
  89.         $rendu $this->renderView('Rangements/CaisseEmballer/detail_datatable.html.twig', ['caisse' => $caisse,'fabrications'=>$fabrications]);
  90.         return new JsonResponse(['rendu' => $rendu,]);
  91.     }
  92.     /**
  93.      * @Route("/vente/commande-fournisseur/ajax/detail/{id}", name="dtc_commande_fournisseur_detail_ajax")
  94.      */
  95.     public function detailCommandeFournisseurAction(Request $requestCommandeFournisseur $commande)
  96.     {
  97.         $rendu $this->renderView('GestionComerciale/CommandeFournisseur/detail_datatable.html.twig', ['commande' => $commande]);
  98.         return new JsonResponse(['rendu' => $rendu,]);
  99.     }
  100.     /**
  101.      * @Route("/commande-article/interchanger/{commande}/{article}", name="dtc_article_est_interchangeable")
  102.      * @Route("/commentaire/nouveau/", name="dtc_construire_ligne_commentaire_commande")
  103.      */
  104.     public function construireLigneCommentaireCommandeAction(Request               $requestEntityManagerInterface $emArticleService $serviceArticleCommandeService $commandeService,
  105.                                                              ColonneTableauService $serviceColonne
  106.     ) {
  107.         $conn $em->getConnection();
  108.         $conn->getConfiguration()->setSQLLogger(null);
  109.         $repo_article          $em->getRepository(Article::class);
  110.         $repo_commande         $em->getRepository(Commande::class);
  111.         $repo_article_commande $em->getRepository(ArticleCommande::class);
  112.         $commandeId            $request->query->get('commande');
  113.         $article $repo_article->find($this->getParameter('article_commentaire'));
  114.         $quantite  $request->query->get('quantite');
  115.         $client_id $request->query->get('client');
  116.         $cible     $request->query->get('cible');
  117.         $type      '';
  118.         $a                          = [];
  119.         $a['quantiteDejaPreparee']  = 0;
  120.         $a['articleCommandeRepris'] = "";
  121.         $a['position']              = "";
  122.         $a['action']                = "insert";
  123.         $a['article']               = $article;
  124.         $a['libelle']               = $article->getLibelle();
  125.         $a['libelleSecondaire']     = $article->getLibelleSecondaire();
  126.         $a['quantite']              = "1";
  127.         $a['quantitePrepa']         = "1";
  128.         $a['fraisPort']             = "0";
  129.         $a['estCommentaire']       = $article->getEstCommentaire();
  130.         $a['commentaire']          = "";
  131.         $a['commentaireSuppl']     = "";
  132.         $a['commentairePrive']     = "";
  133.         $a['remise']               = 0;
  134.         $a['remiseSupplementaire'] = 0;
  135.         //$a['ecocontribution']= floatval($article->getEcocontribution());
  136.         $a['ecocontribution'] = 0;
  137.         $a['totalHt']         = $article->getPrixVente();
  138.         $a['totalHtV2']       = $article->getPrixVente();
  139.         $a['couleur'] = $serviceArticle->getCouleurEtatStock($article$a['quantite']);
  140.         $commande null;
  141.         if ($commandeId != '') {
  142.             $commande $repo_commande->find($commandeId);
  143.             //$type = 'commande';
  144.         }
  145.         $a['position'] = 0;
  146.         if (is_object($commande)) {
  147.             $a['commande'] = $commande;
  148.             $a['position'] = count($commande->getArticleCommande());
  149.         } else {
  150.             $a['commande'] = null;
  151.         }
  152.         //sauvegarde auto
  153.         if (is_object($commande)) {
  154.             if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
  155.                 $type 'commande';
  156.             }
  157.             //modification des donnees pour l'enregistrement
  158.             if (is_object($a['article'])) {
  159.                 $a['article_id'] = $a['article']->getId();
  160.             }
  161.             if (is_object($a['commande'])) {
  162.                 $a['commande_id'] = $a['commande']->getId();
  163.             }
  164.             $a['libelle_secondaire'] = $a['libelleSecondaire'];
  165.             $a['frais_port']         = $a['fraisPort'];
  166.             $a['ral_client']         = $a['quantite'];
  167.             //$a['est_commentaire'] = $a['estCommentaire'];
  168.             $a['commentaire_suppl']     = $a['commentaireSuppl'];
  169.             $a['commentaire_prive']     = $a['commentairePrive'];
  170.             $a['remise_supplementaire'] = $a['remiseSupplementaire'];
  171.             $a['total_ht']              = $a['totalHt'];
  172.             //$a['total_ht_v2'] = $a['totalHtV2'];
  173.             $a['quantite_deja_preparee'] = $a['quantiteDejaPreparee'];
  174.             $a['date']                   = (new \Datetime)->format('Y-m-d H:i:s');
  175.             if (is_object($a['articleCommandeRepris'])) {
  176.                 $a['article_commande_repris_id'] = $a['articleCommandeRepris']->getId();
  177.             }
  178.             unset($a['articleCommandeRepris']);
  179.             unset($a['transporteur']);
  180.             unset($a['article']);
  181.             unset($a['commande']);
  182.             unset($a['action']);
  183.             unset($a['libelleSecondaire']);
  184.             unset($a['fraisPort']);
  185.             unset($a['quantitePrepa']);
  186.             //unset($a['ralClient']);
  187.             unset($a['estCommentaire']);
  188.             unset($a['commentaireSuppl']);
  189.             unset($a['commentairePrive']);
  190.             unset($a['remiseSupplementaire']);
  191.             unset($a['totalHt']);
  192.             unset($a['totalHtV2']);
  193.             unset($a['couleur']);
  194.             unset($a['quantiteDejaPreparee']);
  195.             $conn->insert('commerciale__article_commande'$a);
  196.             //$a['id'] = $conn->lastInsertId();
  197.             $a $repo_article_commande->find($conn->lastInsertId());
  198.             $commandeService->creerHistorique($commande'ajout-ligne', ['articleCommande' => $a]);
  199.         } else {
  200.             $a['id'] = 'tmp-'.time();
  201.         }
  202.         /*
  203.          {% set tabColonneUser = tabColonneUser|merge({'id': 1}) %}
  204.          {% set tabColonneUser = tabColonneUser|merge({'reference': 1}) %}
  205.          {% set tabColonneUser = tabColonneUser|merge({'libelle': 1}) %}
  206.          {% set tabColonneUser = tabColonneUser|merge({'quantite': 1}) %}
  207.          {% set tabColonneUser = tabColonneUser|merge({'quantitePrepa': 1}) %}
  208.          {% set tabColonneUser = tabColonneUser|merge({'quantiteDejaPrepa': 1}) %}
  209.          {% set tabColonneUser = tabColonneUser|merge({'quantiteCmde': 1}) %}
  210.          {% set tabColonneUser = tabColonneUser|merge({'prixHT': 1}) %}
  211.          {% set tabColonneUser = tabColonneUser|merge({'remise': 1}) %}
  212.          {% set tabColonneUser = tabColonneUser|merge({'prixHTCalc': 1}) %}
  213.          {% set tabColonneUser = tabColonneUser|merge({'totalHT': 1}) %}
  214.          {% set tabColonneUser = tabColonneUser|merge({'stock': 1}) %}
  215.          */
  216.         if ($cible == "or") {
  217.             $colspan                             13;
  218.             $tabColonneUser                      = [];
  219.             $tabColonneUser["id"]                = 1;
  220.             $tabColonneUser["reference"]         = 1;
  221.             $tabColonneUser["libelle"]           = 1;
  222.             $tabColonneUser["quantite"]          = 1;
  223.             $tabColonneUser["quantitePrepa"]     = 1;
  224.             $tabColonneUser["quantiteDejaPrepa"] = 1;
  225.             $tabColonneUser["quantiteCmde"]      = 1;
  226.             $tabColonneUser["prixHT"]            = 1;
  227.             $tabColonneUser["remise"]            = 1;
  228.             $tabColonneUser["prixHTCalc"]        = 1;
  229.             $tabColonneUser["totalHT"]           = 1;
  230.             $tabColonneUser["stock"]             = 1;
  231.             // TODO CHANGE THIS
  232.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormOrdreRep";
  233.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'id') == false) {
  234.                 $colspan--;
  235.                 $tabColonneUser["id"] = 0;
  236.             }
  237.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'reference') == false) {
  238.                 $colspan--;
  239.                 $tabColonneUser["reference"] = 0;
  240.             }
  241.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelle') == false) {
  242.                 $colspan--;
  243.                 $tabColonneUser["libelle"] = 0;
  244.             }
  245.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantite') == false) {
  246.                 $colspan--;
  247.                 $tabColonneUser["quantite"] = 0;
  248.             }
  249.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantitePrepa') == false) {
  250.                 $colspan--;
  251.                 $tabColonneUser["quantitePrepa"] = 0;
  252.             }
  253.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantiteDejaPrepa') == false) {
  254.                 $colspan--;
  255.                 $tabColonneUser["quantiteDejaPrepa"] = 0;
  256.             }
  257.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantiteCmde') == false) {
  258.                 $colspan--;
  259.                 $tabColonneUser["quantiteCmde"] = 0;
  260.             }
  261.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixHT') == false) {
  262.                 $colspan--;
  263.                 $tabColonneUser["prixHT"] = 0;
  264.             }
  265.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'remise') == false) {
  266.                 $colspan--;
  267.                 $tabColonneUser["remise"] = 0;
  268.             }
  269.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'remise') == false) {
  270.                 $colspan--;
  271.                 $tabColonneUser["remise"] = 0;
  272.             }
  273.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixHTCalc') == false) {
  274.                 $colspan--;
  275.                 $tabColonneUser["prixHTCalc"] = 0;
  276.             }
  277.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'totalHT') == false) {
  278.                 $colspan--;
  279.                 $tabColonneUser["totalHT"] = 0;
  280.             }
  281.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'stock') == false) {
  282.                 $colspan--;
  283.                 $tabColonneUser["stock"] = 0;
  284.             }
  285.         } else {
  286.             /*
  287.             $serviceColonne = $this->get('dtc.colonne.tableau');
  288.             $colonneUtilisateur = "App\\Entity\\GestionComerciale\\FormCommande";
  289.             $colspan = 11;
  290.             $tabColonneUser = array();
  291.             $tabColonneUser["id"]=1;
  292.             $tabColonneUser["reference"]=1;
  293.             $tabColonneUser["libelle"]=1;
  294.             $tabColonneUser["quantite"]=1;
  295.             $tabColonneUser["prixHT"]=1;
  296.             $tabColonneUser["remise"]=1;
  297.             $tabColonneUser["remiseSuppl"]=1;
  298.             $tabColonneUser["montantHT"]=1;
  299.             $tabColonneUser["totalHT"]=1;
  300.             $tabColonneUser["pump"]=1;
  301.             $tabColonneUser["stock"]=1;
  302.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'id') == false) {
  303.                 $colspan--;
  304.                 $tabColonneUser["id"]=0;
  305.             }
  306.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'reference') == false) {
  307.                 $colspan--;
  308.                 $tabColonneUser["reference"]=0;
  309.             }
  310.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'libelle') == false) {
  311.                 $colspan--;
  312.                 $tabColonneUser["libelle"]=0;
  313.             }
  314.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'quantite') == false) {
  315.                 $colspan--;
  316.                 $tabColonneUser["quantite"]=0;
  317.             }
  318.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'prixHT') == false) {
  319.                 $colspan--;
  320.                 $tabColonneUser["prixHT"]=0;
  321.             }
  322.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remise') == false) {
  323.                 $colspan--;
  324.                 $tabColonneUser["remise"]=0;
  325.             }
  326.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remiseSuppl') == false) {
  327.                 $colspan--;
  328.                 $tabColonneUser["remiseSuppl"]=0;
  329.             }
  330.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'montantHT') == false) {
  331.                 $colspan--;
  332.                 $tabColonneUser["montantHT"]=0;
  333.             }
  334.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'totalHT') == false) {
  335.                 $colspan--;
  336.                 $tabColonneUser["totalHT"]=0;
  337.             }
  338.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'pump') == false) {
  339.                 $colspan--;
  340.                 $tabColonneUser["pump"]=0;
  341.             }
  342.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'stock') == false) {
  343.                 $colspan--;
  344.                 $tabColonneUser["stock"]=0;
  345.             }
  346.             */
  347.             // TODO change this
  348.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommande";
  349.             if ($cible == "comptoir") {
  350.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormComptoir";
  351.             }
  352.             if ($cible == "bp") {
  353.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormBP";
  354.             }
  355.             if ($cible == "devis") {
  356.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormDevis";
  357.             }
  358.             if ($cible == "") {
  359.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormDevis";
  360.             }
  361.             $colonneUtilisateur2 $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
  362.             $tabColonneUser      $colonneUtilisateur2['tabColonneUser'];
  363.             $colspan             $colonneUtilisateur2['colspan'];
  364.         }
  365.         $variables = ['a' => $a'boucle' => "0"'numeroLigne' => "0"'colspan' => $colspan'tabColonneUser' => $tabColonneUser'type' => $type];
  366.         if ($cible == "or") {
  367.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig'$variables);
  368.         } elseif ($cible == "regularisation") {
  369.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig'$variables);
  370.         } else {
  371.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig'$variables);
  372.         }
  373.         $commentairePonctuel $article->getCommentairePonctuel();
  374.         if ($article->getArretGamme()) {
  375.             $commentairePonctuel .= "<div>Attention article en arrêt de gamme</div>";
  376.         }
  377.         return new JsonResponse(['rendu' => $rendu'id' => $article->getId(), 'commentairePonctuel' => $commentairePonctuel]
  378.         );
  379.     }
  380.     /**
  381.      * @Route("/commande-article/nouveau/{id}", name="dtc_construire_ligne_article_commande")
  382.      */
  383.     public function construireLigneArticleCommandeAction(Request        $requestArticle $articleEntityManagerInterface $emColonneTableauService $serviceColonne,
  384.                                                          ArticleService $serviceArticleCommandeService $commandeService
  385.     ) {
  386.         $enregAuto false;
  387.         $conn      $em->getConnection();
  388.         $conn->getConfiguration()->setSQLLogger(null);
  389.         $quantite            $request->query->get('quantite');
  390.         $quantiteSurCommande $request->query->get('quantiteSurCommande');
  391.         $client_id  $request->query->get('client');
  392.         $cible      $request->query->get('cible');
  393.         $commandeId $request->query->get('commande');
  394.         $adresse    $request->query->get('adresse');
  395.         $articleImpression $this->getParameter('article_impression');
  396.         if ($adresse != '') {
  397.             $adresse $em->getRepository(Adresse::class)->find($adresse);
  398.         }
  399.         $type '';
  400.         $repo_client           $em->getRepository(Client::class);
  401.         $repo_article          $em->getRepository(Article::class);
  402.         $repo_commande         $em->getRepository(Commande::class);
  403.         $repo_article_commande $em->getRepository(ArticleCommande::class);
  404.         $consigne "";
  405.         if ($cible == "or") {
  406.             // TODO CHANGE THIS
  407.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormOrdreRep";
  408.             $colspan            13;
  409.             $tabColonneUser                      = [];
  410.             $tabColonneUser["id"]                = 1;
  411.             $tabColonneUser["reference"]         = 1;
  412.             $tabColonneUser["libelle"]           = 1;
  413.             $tabColonneUser["quantite"]          = 1;
  414.             $tabColonneUser["quantitePrepa"]     = 1;
  415.             $tabColonneUser["quantiteDejaPrepa"] = 1;
  416.             $tabColonneUser["quantiteCmde"]      = 1;
  417.             $tabColonneUser["prixHT"]            = 1;
  418.             $tabColonneUser["remise"]            = 1;
  419.             $tabColonneUser["prixHTCalc"]        = 1;
  420.             $tabColonneUser["totalHT"]           = 1;
  421.             $tabColonneUser["dispo"]             = 1;
  422.             $tabColonneUser["stock"]             = 1;
  423.             $tabColonneUser["transporteur"]      = 1;
  424.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'id') == false) {
  425.                 $colspan--;
  426.                 $tabColonneUser["id"] = 0;
  427.             }
  428.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'reference') == false) {
  429.                 $colspan--;
  430.                 $tabColonneUser["reference"] = 0;
  431.             }
  432.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelle') == false) {
  433.                 $colspan--;
  434.                 $tabColonneUser["libelle"] = 0;
  435.             }
  436.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantite') == false) {
  437.                 $colspan--;
  438.                 $tabColonneUser["quantite"] = 0;
  439.             }
  440.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantitePrepa') == false) {
  441.                 $colspan--;
  442.                 $tabColonneUser["quantitePrepa"] = 0;
  443.             }
  444.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantiteDejaPrepa') == false) {
  445.                 $colspan--;
  446.                 $tabColonneUser["quantiteDejaPrepa"] = 0;
  447.             }
  448.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'quantiteCmde') == false) {
  449.                 $colspan--;
  450.                 $tabColonneUser["quantiteCmde"] = 0;
  451.             }
  452.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixHT') == false) {
  453.                 $colspan--;
  454.                 $tabColonneUser["prixHT"] = 0;
  455.             }
  456.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'remise') == false) {
  457.                 $colspan--;
  458.                 $tabColonneUser["remise"] = 0;
  459.             }
  460.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'remise') == false) {
  461.                 $colspan--;
  462.                 $tabColonneUser["remise"] = 0;
  463.             }
  464.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixHTCalc') == false) {
  465.                 $colspan--;
  466.                 $tabColonneUser["prixHTCalc"] = 0;
  467.             }
  468.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'totalHT') == false) {
  469.                 $colspan--;
  470.                 $tabColonneUser["totalHT"] = 0;
  471.             }
  472.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'dispo') == false) {
  473.                 $colspan--;
  474.                 $tabColonneUser["dispo"] = 0;
  475.             }
  476.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'stock') == false) {
  477.                 $colspan--;
  478.                 $tabColonneUser["stock"] = 0;
  479.             }
  480.             if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'transporteur') == false) {
  481.                 $colspan--;
  482.                 $tabColonneUser["transporteur"] = 0;
  483.             }
  484.         } else {
  485.             // TODO CHANGE THIS
  486.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommande";
  487.             if ($cible == "comptoir") {
  488.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormComptoir";
  489.             }
  490.             if ($cible == "bp") {
  491.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormBP";
  492.             }
  493.             if ($cible == "devis") {
  494.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormDevis";
  495.             }
  496.             if ($cible == "") {
  497.                 $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormDevis";
  498.             }
  499.             $colonneUtilisateur2 $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
  500.             $tabColonneUser      $colonneUtilisateur2['tabColonneUser'];
  501.             $colspan             $colonneUtilisateur2['colspan'];
  502.             /*
  503.             $colspan = 11;
  504.             $tabColonneUser = array();
  505.             $tabColonneUser["id"]=1;
  506.             $tabColonneUser["reference"]=1;
  507.             $tabColonneUser["libelle"]=1;
  508.             $tabColonneUser["quantite"]=1;
  509.             $tabColonneUser["prixHT"]=1;
  510.             $tabColonneUser["remise"]=1;
  511.             $tabColonneUser["remiseSuppl"]=1;
  512.             $tabColonneUser["montantHT"]=1;
  513.             $tabColonneUser["totalHT"]=1;
  514.             $tabColonneUser["pump"]=1;
  515.             $tabColonneUser["dispo"]=1;
  516.             $tabColonneUser["stock"]=1;
  517.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'id') == false) {
  518.                 $colspan--;
  519.                 $tabColonneUser["id"]=0;
  520.             }
  521.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'reference') == false) {
  522.                 $colspan--;
  523.                 $tabColonneUser["reference"]=0;
  524.             }
  525.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'libelle') == false) {
  526.                 $colspan--;
  527.                 $tabColonneUser["libelle"]=0;
  528.             }
  529.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'quantite') == false) {
  530.                 $colspan--;
  531.                 $tabColonneUser["quantite"]=0;
  532.             }
  533.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'prixHT') == false) {
  534.                 $colspan--;
  535.                 $tabColonneUser["prixHT"]=0;
  536.             }
  537.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remise') == false) {
  538.                 $colspan--;
  539.                 $tabColonneUser["remise"]=0;
  540.             }
  541.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'remiseSuppl') == false) {
  542.                 $colspan--;
  543.                 $tabColonneUser["remiseSuppl"]=0;
  544.             }
  545.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'montantHT') == false) {
  546.                 $colspan--;
  547.                 $tabColonneUser["montantHT"]=0;
  548.             }
  549.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'totalHT') == false) {
  550.                 $colspan--;
  551.                 $tabColonneUser["totalHT"]=0;
  552.             }
  553.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'pump') == false) {
  554.                 $colspan--;
  555.                 $tabColonneUser["pump"]=0;
  556.             }
  557.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'dispo') == false) {
  558.                 $colspan--;
  559.                 $tabColonneUser["dispo"]=0;
  560.             }
  561.             if($serviceColonne->getColonneUtilisateur($colonneUtilisateur,'stock') == false) {
  562.                 $colspan--;
  563.                 $tabColonneUser["stock"]=0;
  564.             }
  565.  *
  566.  */
  567.             /*
  568.             {% set tabColonneUser = tabColonneUser|merge({'id': 1}) %}
  569.              {% set tabColonneUser = tabColonneUser|merge({'reference': 1}) %}
  570.              {% set tabColonneUser = tabColonneUser|merge({'libelle': 1}) %}
  571.              {% set tabColonneUser = tabColonneUser|merge({'quantite': 1}) %}
  572.              {% set tabColonneUser = tabColonneUser|merge({'prixHT': 1}) %}
  573.              {% set tabColonneUser = tabColonneUser|merge({'remise': 1}) %}
  574.              {% set tabColonneUser = tabColonneUser|merge({'remiseSuppl': 1}) %}
  575.              {% set tabColonneUser = tabColonneUser|merge({'montantHT': 1}) %}
  576.              {% set tabColonneUser = tabColonneUser|merge({'totalHT': 1}) %}
  577.              {% set tabColonneUser = tabColonneUser|merge({'pump': 1}) %}
  578.              {% set tabColonneUser = tabColonneUser|merge({'stock': 1}) %}
  579.             */
  580.         }
  581.         $rendu               '';
  582.         $commentairePonctuel '';
  583.         $articlesTmp      = [
  584.             [
  585.                 'article'  => $article,
  586.                 'quantite' => $quantite,
  587.             ],
  588.         ];
  589.         $articlesAssocies $article->getArticlesAssociesParent();
  590.         //$articlesAssocies = $em->getRepository('DTCArticlesBundle:ArticleAssocie')->findByParent($article);
  591.         if (count($articlesAssocies)) {
  592.             foreach ($articlesAssocies as $articleAssocie) {
  593.                 $articlesTmp[] = [
  594.                     'article'  => $articleAssocie->getEnfant(),
  595.                     'quantite' => $articleAssocie->getQuantite(),
  596.                 ];
  597.             }
  598.         }
  599.         $idArticleCommandeTmp   'tmp-'.time();
  600.         $articleCommandeAssocie null;
  601.         $countTmp               0;
  602.         foreach ($articlesTmp as $articleTmp) {
  603.             $a = [];
  604.             /*
  605.         if($countTmp == 0){
  606.             $a['id'] = $idArticleCommandeTmp;
  607.         } else {
  608.             $a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
  609.         }
  610.         $countTmp++;
  611.         */
  612.             $article  $articleTmp['article'];
  613.             $quantite $articleTmp['quantite'];
  614.             if ( ! empty($request->query->get('choix_matiere'))) {
  615.                 if ($article->getId() == $articleImpression) {
  616.                 }
  617.                 $poidsImpression       0;
  618.                 $prixImpression        $request->query->get('prixImpression');
  619.                 $designationImpression $request->query->get('designation');
  620.                 $poidsImpression       $request->query->get('poids');
  621.                 $largeur_impression    $request->query->get('largeur_impression');
  622.                 $longueur_impression   $request->query->get('longueur_impression');
  623.                 $reference_impression  $request->query->get('reference_impression');
  624.                 if ($longueur_impression == "") {
  625.                     $longueur_impression null;
  626.                 } else {
  627.                     $longueur_impression $longueur_impression 10;
  628.                 }
  629.                 if ($largeur_impression == "") {
  630.                     $largeur_impression null;
  631.                 } else {
  632.                     $largeur_impression $largeur_impression 10;
  633.                 }
  634.                 // $prixImpression = str_replace(".",",",$prixImpression);
  635.                 $descriptionImpression $designationImpression;
  636.                 $designationImpression strtok($designationImpression"\n");
  637.                 if ($poidsImpression != '' && is_numeric($quantite) && $quantite 0) {
  638.                     $poidsImpression round($poidsImpression $quantite2);
  639.                 }
  640.                 $prixImpression round($prixImpression2);
  641.             }
  642.             if ( ! empty($request->query->get('choix_matiere'))) {
  643.                 //echo "ABCDEFG";
  644.                 $poidsImpression 0;
  645.                 //$prixImpression = $request->query->get('prixImpression');
  646.                 $prixImpression        $request->query->get('prix_impression');
  647.                 $designationImpression $request->query->get('designation');
  648.                 //$poidsImpression = $request->query->get('poids');
  649.                 $poidsImpression      $request->query->get('poids_impression');
  650.                 $largeur_impression   $request->query->get('largeur_impression');
  651.                 $longueur_impression  $request->query->get('longueur_impression');
  652.                 $reference_impression $request->query->get('reference_impression');
  653.                 if ($longueur_impression == "") {
  654.                     $longueur_impression null;
  655.                 } else {
  656.                     $longueur_impression $longueur_impression 10;
  657.                 }
  658.                 if ($largeur_impression == "") {
  659.                     $largeur_impression null;
  660.                 } else {
  661.                     $largeur_impression $largeur_impression 10;
  662.                 }
  663.                 // $prixImpression = str_replace(".",",",$prixImpression);
  664.                 $descriptionImpression $designationImpression;
  665.                 $designationImpression strtok($designationImpression"\n");
  666.                 if ($poidsImpression != '' && is_numeric($quantite) && $quantite 0) {
  667.                     $poidsImpression round($poidsImpression $quantite2);
  668.                 }
  669.                 $prixImpression round($prixImpression2);
  670.                 if ($article->getId() == $articleImpression) {
  671.                     /*
  672.                 $poidsImpression = 0;
  673.                 $prixImpression = $request->query->get('prixImpression');
  674.                 $designationImpression = $request->query->get('designation');
  675.                 $poidsImpression = $request->query->get('poids');
  676.                 $largeur_impression = $request->query->get('largeur_impression');
  677.                 $longueur_impression = $request->query->get('longueur_impression');
  678.                 $reference_impression = $request->query->get('reference_impression');
  679.                 if($longueur_impression=="") $longueur_impression = NULL;
  680.                 else $longueur_impression = $longueur_impression/10;
  681.                 if($largeur_impression=="") $largeur_impression = NULL;
  682.                 else $largeur_impression = $largeur_impression/10;
  683.             // $prixImpression = str_replace(".",",",$prixImpression);
  684.                 $descriptionImpression = $designationImpression;
  685.                 $designationImpression = strtok($designationImpression, "\n");
  686.                 if ($poidsImpression != '' && is_numeric($quantite) && $quantite > 0) $poidsImpression = round($poidsImpression/$quantite,2);
  687.                 $prixImpression = round($prixImpression,2);
  688.                 */
  689.                     $dateC = new \Datetime();
  690.                     $tableau_donnee         = [];
  691.                     $tableau_donnee["date"] = $dateC->format("Y-m-d H:i:s");
  692.                     if ($reference_impression != "") {
  693.                         $tableau_donnee["reference"] = $reference_impression."-".time();
  694.                     } else {
  695.                         $tableau_donnee["reference"] = $article->getReference()."-".time();
  696.                     }
  697.                     $tableau_donnee["ral_fournisseur"] = "0";
  698.                     $tableau_donnee["parent_id"]       = $article->getId();
  699.                     $tableau_donnee["libelle"]         = $designationImpression;
  700.                     $tableau_donnee["reference_client"]      = $article->getReferenceClient();
  701.                     $tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
  702.                     $tableau_donnee["prix_base"]             = $prixImpression;
  703.                     if ($article->getDateMaj() != "") {
  704.                         $tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
  705.                     }
  706.                     if ($article->getDateMajPrix() != "") {
  707.                         $tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
  708.                     }
  709.                     if ($article->getDateSuppression() != "") {
  710.                         $tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
  711.                     }
  712.                     if (is_object($article->getMarque())) {
  713.                         $tableau_donnee["marque_id"] = $article->getMarque()->getId();
  714.                     }
  715.                     $tableau_donnee["description"]        = $descriptionImpression;
  716.                     $tableau_donnee["description_courte"] = $article->getDescriptionCourte();
  717.                     $tableau_donnee["stock"]              = "0";
  718.                     if ($article->getStatut() === true) {
  719.                         $tableau_donnee["statut"] = 1;
  720.                     } else {
  721.                         $tableau_donnee["statut"] = 0;
  722.                     }
  723.                     $tableau_donnee["largeur"] = $largeur_impression;;
  724.                     $tableau_donnee["profondeur"] = $longueur_impression;
  725.                     $tableau_donnee["hauteur"]    = $article->getHauteur();
  726.                     $tableau_donnee["poids"]      = $poidsImpression;
  727.                     if ($article->getAConsigner() === true) {
  728.                         $tableau_donnee["a_consigner"] = 1;
  729.                     } else {
  730.                         $tableau_donnee["a_consigner"] = 0;
  731.                     }
  732.                     if ($article->getStockAuto()) {
  733.                         $tableau_donnee["stock_auto"] = 1;
  734.                     } else {
  735.                         $tableau_donnee["stock_auto"] = 0;
  736.                     }
  737.                     if ($article->getArretGamme()) {
  738.                         $tableau_donnee["arret_gamme"] = "1";
  739.                     } else {
  740.                         $tableau_donnee["arret_gamme"] = "0";
  741.                     }
  742.                     if (is_object($article->getUtilisateur())) {
  743.                         $tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
  744.                     }
  745.                     if (is_object($article->getRegleTaxe())) {
  746.                         $tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  747.                     }
  748.                     $tableau_donnee["remise_max"]            = $article->getRemiseMax();
  749.                     $tableau_donnee["type_remise_max"]       = $article->getTypeRemiseMax();
  750.                     $tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  751.                     $tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  752.                     if (is_object($article->getNiveauUn())) {
  753.                         $tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
  754.                     }
  755.                     if (is_object($article->getNiveauDeux())) {
  756.                         $tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
  757.                     }
  758.                     if (is_object($article->getNiveauTrois())) {
  759.                         $tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
  760.                     }
  761.                     if (is_object($article->getNiveauQuatre())) {
  762.                         $tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
  763.                     }
  764.                     $tableau_donnee["pump"]        = $article->getCpump();
  765.                     $tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
  766.                     if ($article->getVirtuel() === true) {
  767.                         $tableau_donnee["virtuel"] = 1;
  768.                     } else {
  769.                         $tableau_donnee["virtuel"] = 0;
  770.                     }
  771.                     //$tableau_donnee["prix_vente"]=$article->getLibelle();
  772.                     $tableau_donnee["prix_vente"]      = $prixImpression;
  773.                     $tableau_donnee["taux_marge"]      = $article->getTauxMarge();
  774.                     $tableau_donnee["marge"]           = $article->getMarge();
  775.                     $tableau_donnee["marge_reelle"]    = $article->getMargeReelle();
  776.                     $tableau_donnee["ecotaxe"]         = $article->getEcotaxe();
  777.                     $tableau_donnee["conditionnement"] = $article->getConditionnement();
  778.                     $tableau_donnee["stock_reserve"]   = $article->getStockReserve();
  779.                     if (is_object($article->getFournisseurDefaut())) {
  780.                         $tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  781.                     }
  782.                     $tableau_donnee["ral_fournisseur"] = "0";
  783.                     $tableau_donnee["id_import"]       = "";
  784.                     $tableau_donnee["donnees_import"]  = "";
  785.                     if ($article->getMajPrix()) {
  786.                         $tableau_donnee["maj_prix"] = 1;
  787.                     } else {
  788.                         $tableau_donnee["maj_prix"] = 0;
  789.                     }
  790.                     $tableau_donnee["unite_mesure_id"] = 6;
  791.                     if ($article->getAfficherComposantPdfInterne() === true) {
  792.                         $tableau_donnee["afficher_composant_pdf_interne"] = 1;
  793.                     } else {
  794.                         $tableau_donnee["afficher_composant_pdf_interne"] = 0;
  795.                     }
  796.                     if ($article->getAfficherComposantPdfExterne() === true) {
  797.                         $tableau_donnee["afficher_composant_pdf_externe"] = 1;
  798.                     } else {
  799.                         $tableau_donnee["afficher_composant_pdf_externe"] = 0;
  800.                     }
  801.                     if (is_object($article->getCategorieRemiseArticle())) {
  802.                         $tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  803.                     }
  804.                     if ($article->getTemporaire()) {
  805.                         $tableau_donnee["temporaire"] = 1;
  806.                     } else {
  807.                         $tableau_donnee["temporaire"] = null;
  808.                     }
  809.                     $tableau_donnee["libelle_secondaire"]       = $article->getLibelleSecondaire();
  810.                     $tableau_donnee["a_commander"]              = "1";
  811.                     $tableau_donnee["a_fabriquer"]              = "0";
  812.                     $tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  813.                     $tableau_donnee["quantite_conseillee"]      = $article->getQuantiteConseillee();
  814.                     $tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
  815.                     $tableau_donnee["archive"] = "0";
  816.                     //$tableau_donnee["archive"]=$article->getArchive();
  817.                     $tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  818.                     $tableau_donnee["nom_web"]                      = $article->getNomWeb();
  819.                     $tableau_donnee["reference_web"]                = $article->getReferenceWeb();
  820.                     $tableau_donnee["reference_fournisseur_web"]    = $article->getReferenceFournisseurWeb();
  821.                     $tableau_donnee["description_web"]              = $article->getDescriptionWeb();
  822.                     $tableau_donnee["resume_web"]                   = $article->getResumeWeb();
  823.                     $tableau_donnee["frais_ports_texte_web"]        = $article->getFraisPortsTexteWeb();
  824.                     $tableau_donnee["message_qd_en_stock"]          = $article->getMessageQdEnStockWeb();
  825.                     if (is_object($article->getArticleEnconsigne())) {
  826.                         $tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
  827.                     }
  828.                     $tableau_donnee["reference_appel_1"]  = null;
  829.                     $tableau_donnee["reference_appel_2"]  = null;
  830.                     $tableau_donnee["reference_appel_3"]  = null;
  831.                     $tableau_donnee["reference_appel_4"]  = null;
  832.                     $tableau_donnee["reference_appel_5"]  = null;
  833.                     $tableau_donnee["reference_appel_6"]  = null;
  834.                     $tableau_donnee["reference_appel_7"]  = null;
  835.                     $tableau_donnee["reference_appel_8"]  = null;
  836.                     $tableau_donnee["reference_appel_9"]  = null;
  837.                     $tableau_donnee["reference_appel_10"] = null;
  838.                     $tableau_donnee["reference_appel_11"] = str_replace([' ''-''.'], ''$tableau_donnee["reference"]);
  839.                     if ($article->getMainOeuvre()) {
  840.                         $tableau_donnee["main_oeuvre"] = "1";
  841.                     } else {
  842.                         $tableau_donnee["main_oeuvre"] = "0";
  843.                     }
  844.                     //$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
  845.                     $tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
  846.                     if (is_object($article->getType())) {
  847.                         $tableau_donnee["type_id"] = $article->getType()->getId();
  848.                     }
  849.                     if (is_object($article->getFamilleCompta())) {
  850.                         $tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
  851.                     }
  852.                     if ($article->getPrestation() === true) {
  853.                         $tableau_donnee["prestation"] = 1;
  854.                     } else {
  855.                         $tableau_donnee["prestation"] = 0;
  856.                     }
  857.                     if ($article->getNonStocke()) {
  858.                         $tableau_donnee["non_stocke"] = "1";
  859.                     } else {
  860.                         $tableau_donnee["non_stocke"] = "0";
  861.                     }
  862.                     //$tableau_donnee["non_stocke"]=$article->getNonStocke();
  863.                     if ($article->getNonCommandable() === true) {
  864.                         $tableau_donnee["non_commandable"] = 1;
  865.                     } else {
  866.                         $tableau_donnee["non_commandable"] = 0;
  867.                     }
  868.                     if (is_object($article->getParent())) {
  869.                         $tableau_donnee["parent_id"] = $article->getParent()->getId();
  870.                     }
  871.                     if ($article->getDivers()) {
  872.                         $tableau_donnee["divers"] = 1;
  873.                     } else {
  874.                         $tableau_donnee["divers"] = 0;
  875.                     }
  876.                     if ($article->getMouvemente()) {
  877.                         $tableau_donnee["mouvemente"] = "1";
  878.                     } else {
  879.                         $tableau_donnee["mouvemente"] = "0";
  880.                     }
  881.                     //$tableau_donnee["mouvemente"]=$article->getMouvemente();
  882.                     if ($article->getNumSerieObligatoire() === true) {
  883.                         $tableau_donnee["num_serie_obligatoire"] = 1;
  884.                     } else {
  885.                         $tableau_donnee["num_serie_obligatoire"] = 0;
  886.                     }
  887.                     if (is_object($article->getArticleRemplacement())) {
  888.                         $tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  889.                     }
  890.                     if ($article->getMajPoids()) {
  891.                         $tableau_donnee["maj_poids"] = 1;
  892.                     } else {
  893.                         $tableau_donnee["maj_poids"] = 0;
  894.                     }
  895.                     if ($article->getMajPrixBase()) {
  896.                         $tableau_donnee["maj_prix_base"] = 1;
  897.                     } else {
  898.                         $tableau_donnee["maj_prix_base"] = 0;
  899.                     }
  900.                     if ($article->getEstCommentaire()) {
  901.                         $tableau_donnee["est_commentaire"] = 1;
  902.                     } else {
  903.                         $tableau_donnee["est_commentaire"] = 0;
  904.                     }
  905.                     $tableau_donnee["cond_achat"]     = $article->getConditionnementAchat();
  906.                     $tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
  907.                     $conn->insert('article__article'$tableau_donnee);
  908.                     $idNouveauArticle $conn->lastInsertId();
  909.                     $article          $repo_article->find($idNouveauArticle);
  910.                 } else {
  911.                     //mise à jour des données impression
  912.                     $descriptionImpression         $request->query->get('designation');
  913.                     $tableau_donnee["libelle"]     = $designationImpression;
  914.                     $designationImpression         strtok($designationImpression"\n");
  915.                     $tableau_donnee["description"] = $descriptionImpression;
  916.                     $tableau_donnee["reference"] = $request->query->get('reference_impression')."-".time();
  917.                     $prixImpression               $request->query->get('prix_impression');
  918.                     $tableau_donnee["prix_base"]  = $prixImpression;
  919.                     $tableau_donnee["prix_vente"] = $prixImpression;
  920.                     $tableau_donnee["largeur"] = $request->query->get('largeur');
  921.                     $tableau_donnee["hauteur"] = $request->query->get('hauteur');
  922.                     $tableau_donnee["poids"]   = $request->query->get('poids_impression');
  923.                     $conn->update('article__article'$tableau_donnee, ['id' => $article->getId()]);
  924.                     $em->refresh($article);
  925.                     if ( ! empty($request->query->get('articleCommande'))) {
  926.                         $a['id'] = $request->query->get('articleCommande');
  927.                     }
  928.                 }
  929.                 //maj des composants de l'article
  930.                 //suppression des composants
  931.                 $req $conn->prepare('DELETE FROM article__article_composant WHERE article_compose_id = :article');
  932.                 $req->executeQuery(['article' => $article->getId()]);
  933.                 //ajouter les composants
  934.                 $tableau_donnee = [];
  935.                 $composantsRef  = [];
  936.                 if ( ! empty($request->query->get('choix_matiere'))) {
  937.                     $composantsRef[] = $request->query->get('choix_matiere');
  938.                 }
  939.                 if ( ! empty($request->query->get('choix_finition'))) {
  940.                     $composantsRef[] = $request->query->get('choix_finition');
  941.                 }
  942.                 $articlesCategorie $em->getRepository(ArticleCategorie::class)->findBy(['categorie' => $this->getParameter('categorie_options')]);
  943.                 if (count($articlesCategorie)) {
  944.                     foreach ($articlesCategorie as $articleCategorie) {
  945.                         if ( ! empty($request->query->get($articleCategorie->getArticle()->getReference()))) {
  946.                             $composantsRef[$articleCategorie->getArticle()->getReference()] = $request->query->get($articleCategorie->getArticle()->getReference());
  947.                         }
  948.                     }
  949.                 }
  950.                 $categories $em->getRepository(Categorie::class)->findBy(['categorieParent' => $this->getParameter('categorie_options')]);
  951.                 if (count($categories)) {
  952.                     foreach ($categories as $categorie) {
  953.                         //$articlesCategorie = $em->getRepository('DTCArticlesBundle:ArticleCategorie')->findBy(array('categorie'=>$categorie));
  954.                         if ( ! empty($request->query->get($categorie->getReference()))) {
  955.                             $composantsRef[$categorie->getReference()] = $request->query->get($categorie->getReference());
  956.                         }
  957.                     }
  958.                 }
  959.                 if (count($composantsRef)) {
  960.                     foreach ($composantsRef as $composantRef) {
  961.                         $composant $repo_article->findOneBy(['reference' => $composantRef]);
  962.                         if (is_object($composant)) {
  963.                             $conn->insert(
  964.                                 'article__article_composant',
  965.                                 ['article_compose_id' => $article->getId(), 'article_id' => $composant->getId(), 'date' => (new \Datetime)->format('Y-m-d H:i:s')]
  966.                             );
  967.                         }
  968.                     }
  969.                 }
  970.             } elseif ($article->getId() == $articleImpression) {
  971.                 //echo "ABCDEFG";
  972.                 $poidsImpression       0;
  973.                 $prixImpression        $request->query->get('prixImpression');
  974.                 $designationImpression $request->query->get('designation');
  975.                 $poidsImpression       $request->query->get('poids');
  976.                 $largeur_impression    $request->query->get('largeur_impression');
  977.                 $longueur_impression   $request->query->get('longueur_impression');
  978.                 $reference_impression  $request->query->get('reference_impression');
  979.                 if ($longueur_impression == "") {
  980.                     $longueur_impression null;
  981.                 } else {
  982.                     $longueur_impression $longueur_impression 10;
  983.                 }
  984.                 if ($largeur_impression == "") {
  985.                     $largeur_impression null;
  986.                 } else {
  987.                     $largeur_impression $largeur_impression 10;
  988.                 }
  989.                 // $prixImpression = str_replace(".",",",$prixImpression);
  990.                 $descriptionImpression $designationImpression;
  991.                 $designationImpression strtok($designationImpression"\n");
  992.                 if ($poidsImpression != '' && is_numeric($quantite) && $quantite 0) {
  993.                     $poidsImpression round($poidsImpression $quantite2);
  994.                 }
  995.                 $prixImpression round($prixImpression2);
  996.                 $dateC = new \Datetime();
  997.                 $conn $em->getConnection();
  998.                 $conn->getConfiguration()->setSQLLogger(null);
  999.                 $tableau_donnee         = [];
  1000.                 $tableau_donnee["date"] = $dateC->format("Y-m-d H:i:s");
  1001.                 if ($reference_impression != "") {
  1002.                     $tableau_donnee["reference"] = $reference_impression."-".time();
  1003.                 } else {
  1004.                     $tableau_donnee["reference"] = $article->getReference()."-".time();
  1005.                 }
  1006.                 $tableau_donnee["ral_fournisseur"] = "0";
  1007.                 $tableau_donnee["parent_id"]       = $article->getId();
  1008.                 $tableau_donnee["libelle"]         = $designationImpression;
  1009.                 $tableau_donnee["reference_client"]      = $article->getReferenceClient();
  1010.                 $tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
  1011.                 $tableau_donnee["prix_base"]             = $prixImpression;
  1012.                 if ($article->getDateMaj() != "") {
  1013.                     $tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
  1014.                 }
  1015.                 if ($article->getDateMajPrix() != "") {
  1016.                     $tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
  1017.                 }
  1018.                 if ($article->getDateSuppression() != "") {
  1019.                     $tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
  1020.                 }
  1021.                 if (is_object($article->getMarque())) {
  1022.                     $tableau_donnee["marque_id"] = $article->getMarque()->getId();
  1023.                 }
  1024.                 $tableau_donnee["description"]        = $descriptionImpression;
  1025.                 $tableau_donnee["description_courte"] = $article->getDescriptionCourte();
  1026.                 $tableau_donnee["stock"]              = "0";
  1027.                 if ($article->getStatut() === true) {
  1028.                     $tableau_donnee["statut"] = 1;
  1029.                 } else {
  1030.                     $tableau_donnee["statut"] = 0;
  1031.                 }
  1032.                 $tableau_donnee["largeur"] = $largeur_impression;;
  1033.                 $tableau_donnee["profondeur"] = $longueur_impression;
  1034.                 $tableau_donnee["hauteur"]    = $article->getHauteur();
  1035.                 $tableau_donnee["poids"]      = $poidsImpression;
  1036.                 if ($article->getAConsigner() === true) {
  1037.                     $tableau_donnee["a_consigner"] = 1;
  1038.                 } else {
  1039.                     $tableau_donnee["a_consigner"] = 0;
  1040.                 }
  1041.                 if ($article->getStockAuto()) {
  1042.                     $tableau_donnee["stock_auto"] = 1;
  1043.                 } else {
  1044.                     $tableau_donnee["stock_auto"] = 0;
  1045.                 }
  1046.                 if ($article->getArretGamme()) {
  1047.                     $tableau_donnee["arret_gamme"] = "1";
  1048.                 } else {
  1049.                     $tableau_donnee["arret_gamme"] = "0";
  1050.                 }
  1051.                 if (is_object($article->getUtilisateur())) {
  1052.                     $tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
  1053.                 }
  1054.                 if (is_object($article->getRegleTaxe())) {
  1055.                     $tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  1056.                 }
  1057.                 $tableau_donnee["remise_max"]            = $article->getRemiseMax();
  1058.                 $tableau_donnee["type_remise_max"]       = $article->getTypeRemiseMax();
  1059.                 $tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  1060.                 $tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  1061.                 if (is_object($article->getNiveauUn())) {
  1062.                     $tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
  1063.                 }
  1064.                 if (is_object($article->getNiveauDeux())) {
  1065.                     $tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
  1066.                 }
  1067.                 if (is_object($article->getNiveauTrois())) {
  1068.                     $tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
  1069.                 }
  1070.                 if (is_object($article->getNiveauQuatre())) {
  1071.                     $tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
  1072.                 }
  1073.                 $tableau_donnee["pump"]        = $article->getCpump();
  1074.                 $tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
  1075.                 if ($article->getVirtuel() === true) {
  1076.                     $tableau_donnee["virtuel"] = 1;
  1077.                 } else {
  1078.                     $tableau_donnee["virtuel"] = 0;
  1079.                 }
  1080.                 //$tableau_donnee["prix_vente"]=$article->getLibelle();
  1081.                 $tableau_donnee["prix_vente"]      = $prixImpression;
  1082.                 $tableau_donnee["taux_marge"]      = $article->getTauxMarge();
  1083.                 $tableau_donnee["marge"]           = $article->getMarge();
  1084.                 $tableau_donnee["marge_reelle"]    = $article->getMargeReelle();
  1085.                 $tableau_donnee["ecotaxe"]         = $article->getEcotaxe();
  1086.                 $tableau_donnee["conditionnement"] = $article->getConditionnement();
  1087.                 $tableau_donnee["stock_reserve"]   = $article->getStockReserve();
  1088.                 if (is_object($article->getFournisseurDefaut())) {
  1089.                     $tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  1090.                 }
  1091.                 $tableau_donnee["ral_fournisseur"] = "0";
  1092.                 $tableau_donnee["id_import"]       = "";
  1093.                 $tableau_donnee["donnees_import"]  = "";
  1094.                 if ($article->getMajPrix()) {
  1095.                     $tableau_donnee["maj_prix"] = 1;
  1096.                 } else {
  1097.                     $tableau_donnee["maj_prix"] = 0;
  1098.                 }
  1099.                 $tableau_donnee["unite_mesure_id"] = 6;
  1100.                 if ($article->getAfficherComposantPdfInterne() === true) {
  1101.                     $tableau_donnee["afficher_composant_pdf_interne"] = 1;
  1102.                 } else {
  1103.                     $tableau_donnee["afficher_composant_pdf_interne"] = 0;
  1104.                 }
  1105.                 if ($article->getAfficherComposantPdfExterne() === true) {
  1106.                     $tableau_donnee["afficher_composant_pdf_externe"] = 1;
  1107.                 } else {
  1108.                     $tableau_donnee["afficher_composant_pdf_externe"] = 0;
  1109.                 }
  1110.                 if (is_object($article->getCategorieRemiseArticle())) {
  1111.                     $tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  1112.                 }
  1113.                 if ($article->getTemporaire()) {
  1114.                     $tableau_donnee["temporaire"] = 1;
  1115.                 } else {
  1116.                     $tableau_donnee["temporaire"] = null;
  1117.                 }
  1118.                 $tableau_donnee["libelle_secondaire"]       = $article->getLibelleSecondaire();
  1119.                 $tableau_donnee["a_commander"]              = "1";
  1120.                 $tableau_donnee["a_fabriquer"]              = "0";
  1121.                 $tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  1122.                 $tableau_donnee["quantite_conseillee"]      = $article->getQuantiteConseillee();
  1123.                 $tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
  1124.                 $tableau_donnee["archive"] = "0";
  1125.                 //$tableau_donnee["archive"]=$article->getArchive();
  1126.                 $tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  1127.                 $tableau_donnee["nom_web"]                      = $article->getNomWeb();
  1128.                 $tableau_donnee["reference_web"]                = $article->getReferenceWeb();
  1129.                 $tableau_donnee["reference_fournisseur_web"]    = $article->getReferenceFournisseurWeb();
  1130.                 $tableau_donnee["description_web"]              = $article->getDescriptionWeb();
  1131.                 $tableau_donnee["resume_web"]                   = $article->getResumeWeb();
  1132.                 $tableau_donnee["frais_ports_texte_web"]        = $article->getFraisPortsTexteWeb();
  1133.                 $tableau_donnee["message_qd_en_stock"]          = $article->getMessageQdEnStockWeb();
  1134.                 if (is_object($article->getArticleEnconsigne())) {
  1135.                     $tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
  1136.                 }
  1137.                 $tableau_donnee["reference_appel_1"]  = null;
  1138.                 $tableau_donnee["reference_appel_2"]  = null;
  1139.                 $tableau_donnee["reference_appel_3"]  = null;
  1140.                 $tableau_donnee["reference_appel_4"]  = null;
  1141.                 $tableau_donnee["reference_appel_5"]  = null;
  1142.                 $tableau_donnee["reference_appel_6"]  = null;
  1143.                 $tableau_donnee["reference_appel_7"]  = null;
  1144.                 $tableau_donnee["reference_appel_8"]  = null;
  1145.                 $tableau_donnee["reference_appel_9"]  = null;
  1146.                 $tableau_donnee["reference_appel_10"] = null;
  1147.                 $tableau_donnee["reference_appel_11"] = str_replace([' ''-''.'], ''$tableau_donnee["reference"]);
  1148.                 if ($article->getMainOeuvre()) {
  1149.                     $tableau_donnee["main_oeuvre"] = "1";
  1150.                 } else {
  1151.                     $tableau_donnee["main_oeuvre"] = "0";
  1152.                 }
  1153.                 //$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
  1154.                 $tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
  1155.                 if (is_object($article->getType())) {
  1156.                     $tableau_donnee["type_id"] = $article->getType()->getId();
  1157.                 }
  1158.                 if (is_object($article->getFamilleCompta())) {
  1159.                     $tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
  1160.                 }
  1161.                 if ($article->getPrestation() === true) {
  1162.                     $tableau_donnee["prestation"] = 1;
  1163.                 } else {
  1164.                     $tableau_donnee["prestation"] = 0;
  1165.                 }
  1166.                 if ($article->getNonStocke()) {
  1167.                     $tableau_donnee["non_stocke"] = "1";
  1168.                 } else {
  1169.                     $tableau_donnee["non_stocke"] = "0";
  1170.                 }
  1171.                 //$tableau_donnee["non_stocke"]=$article->getNonStocke();
  1172.                 if ($article->getNonCommandable() === true) {
  1173.                     $tableau_donnee["non_commandable"] = 1;
  1174.                 } else {
  1175.                     $tableau_donnee["non_commandable"] = 0;
  1176.                 }
  1177.                 if (is_object($article->getParent())) {
  1178.                     $tableau_donnee["parent_id"] = $article->getParent()->getId();
  1179.                 }
  1180.                 if ($article->getDivers()) {
  1181.                     $tableau_donnee["divers"] = 1;
  1182.                 } else {
  1183.                     $tableau_donnee["divers"] = 0;
  1184.                 }
  1185.                 if ($article->getMouvemente()) {
  1186.                     $tableau_donnee["mouvemente"] = "1";
  1187.                 } else {
  1188.                     $tableau_donnee["mouvemente"] = "0";
  1189.                 }
  1190.                 //$tableau_donnee["mouvemente"]=$article->getMouvemente();
  1191.                 if ($article->getNumSerieObligatoire() === true) {
  1192.                     $tableau_donnee["num_serie_obligatoire"] = 1;
  1193.                 } else {
  1194.                     $tableau_donnee["num_serie_obligatoire"] = 0;
  1195.                 }
  1196.                 if (is_object($article->getArticleRemplacement())) {
  1197.                     $tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  1198.                 }
  1199.                 if ($article->getMajPoids()) {
  1200.                     $tableau_donnee["maj_poids"] = 1;
  1201.                 } else {
  1202.                     $tableau_donnee["maj_poids"] = 0;
  1203.                 }
  1204.                 if ($article->getMajPrixBase()) {
  1205.                     $tableau_donnee["maj_prix_base"] = 1;
  1206.                 } else {
  1207.                     $tableau_donnee["maj_prix_base"] = 0;
  1208.                 }
  1209.                 if ($article->getEstCommentaire()) {
  1210.                     $tableau_donnee["est_commentaire"] = 1;
  1211.                 } else {
  1212.                     $tableau_donnee["est_commentaire"] = 0;
  1213.                 }
  1214.                 $tableau_donnee["cond_achat"]     = $article->getConditionnementAchat();
  1215.                 $tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
  1216.                 $conn->insert('article__article'$tableau_donnee);
  1217.                 $idNouveauArticle $conn->lastInsertId();
  1218.                 $article          $repo_article->find($idNouveauArticle);
  1219.             } elseif ($article->getDiversComposes() == 1) {
  1220.                 $dateC = new \Datetime();
  1221.                 $conn $em->getConnection();
  1222.                 $conn->getConfiguration()->setSQLLogger(null);
  1223.                 $tableau_donnee                    = [];
  1224.                 $tableau_donnee["divers_composes"] = 1;
  1225.                 $tableau_donnee["produit_interne"] = 1;
  1226.                 $tableau_donnee["date"]            = $dateC->format("Y-m-d H:i:s");
  1227.                 $tableau_donnee["reference"]       = $article->getReference()."-".time();
  1228.                 $tableau_donnee["ral_fournisseur"] = "0";
  1229.                 $tableau_donnee["parent_id"]       = $article->getId();
  1230.                 $tableau_donnee["libelle"]         = $article->getLibelle();
  1231.                 $tableau_donnee["reference_client"]      = $article->getReferenceClient();
  1232.                 $tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
  1233.                 $tableau_donnee["prix_base"]             = $article->getPrixBase();
  1234.                 if ($article->getDateMaj() != "") {
  1235.                     $tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
  1236.                 }
  1237.                 if ($article->getDateMajPrix() != "") {
  1238.                     $tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
  1239.                 }
  1240.                 if ($article->getDateSuppression() != "") {
  1241.                     $tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
  1242.                 }
  1243.                 if (is_object($article->getMarque())) {
  1244.                     $tableau_donnee["marque_id"] = $article->getMarque()->getId();
  1245.                 }
  1246.                 $tableau_donnee["description"]        = $article->getDescription();
  1247.                 $tableau_donnee["description_courte"] = $article->getDescriptionCourte();
  1248.                 $tableau_donnee["stock"]              = "0";
  1249.                 if ($article->getStatut() === true) {
  1250.                     $tableau_donnee["statut"] = 1;
  1251.                 } else {
  1252.                     $tableau_donnee["statut"] = 0;
  1253.                 }
  1254.                 $tableau_donnee["largeur"]    = $article->getLargeur();
  1255.                 $tableau_donnee["profondeur"] = $article->getProfondeur();
  1256.                 $tableau_donnee["hauteur"]    = $article->getHauteur();
  1257.                 $tableau_donnee["poids"]      = $article->getPoids();
  1258.                 if ($article->getAConsigner() === true) {
  1259.                     $tableau_donnee["a_consigner"] = 1;
  1260.                 } else {
  1261.                     $tableau_donnee["a_consigner"] = 0;
  1262.                 }
  1263.                 if ($article->getStockAuto()) {
  1264.                     $tableau_donnee["stock_auto"] = 1;
  1265.                 } else {
  1266.                     $tableau_donnee["stock_auto"] = 0;
  1267.                 }
  1268.                 if ($article->getArretGamme()) {
  1269.                     $tableau_donnee["arret_gamme"] = "1";
  1270.                 } else {
  1271.                     $tableau_donnee["arret_gamme"] = "0";
  1272.                 }
  1273.                 if (is_object($article->getUtilisateur())) {
  1274.                     $tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
  1275.                 }
  1276.                 if (is_object($article->getRegleTaxe())) {
  1277.                     $tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  1278.                 }
  1279.                 $tableau_donnee["remise_max"]            = $article->getRemiseMax();
  1280.                 $tableau_donnee["type_remise_max"]       = $article->getTypeRemiseMax();
  1281.                 $tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  1282.                 $tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  1283.                 if (is_object($article->getNiveauUn())) {
  1284.                     $tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
  1285.                 }
  1286.                 if (is_object($article->getNiveauDeux())) {
  1287.                     $tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
  1288.                 }
  1289.                 if (is_object($article->getNiveauTrois())) {
  1290.                     $tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
  1291.                 }
  1292.                 if (is_object($article->getNiveauQuatre())) {
  1293.                     $tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
  1294.                 }
  1295.                 $tableau_donnee["pump"]        = $article->getCpump();
  1296.                 $tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
  1297.                 if ($article->getVirtuel() === true) {
  1298.                     $tableau_donnee["virtuel"] = 1;
  1299.                 } else {
  1300.                     $tableau_donnee["virtuel"] = 0;
  1301.                 }
  1302.                 //$tableau_donnee["prix_vente"]=$article->getLibelle();
  1303.                 $tableau_donnee["prix_vente"]      = 0;
  1304.                 $tableau_donnee["taux_marge"]      = $article->getTauxMarge();
  1305.                 $tableau_donnee["marge"]           = $article->getMarge();
  1306.                 $tableau_donnee["marge_reelle"]    = $article->getMargeReelle();
  1307.                 $tableau_donnee["ecotaxe"]         = $article->getEcotaxe();
  1308.                 $tableau_donnee["conditionnement"] = $article->getConditionnement();
  1309.                 $tableau_donnee["stock_reserve"]   = "0";
  1310.                 if (is_object($article->getFournisseurDefaut())) {
  1311.                     $tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  1312.                 }
  1313.                 $tableau_donnee["ral_fournisseur"] = "0";
  1314.                 $tableau_donnee["id_import"]       = "";
  1315.                 $tableau_donnee["donnees_import"]  = "";
  1316.                 if ($article->getMajPrix()) {
  1317.                     $tableau_donnee["maj_prix"] = 1;
  1318.                 } else {
  1319.                     $tableau_donnee["maj_prix"] = 0;
  1320.                 }
  1321.                 if (is_object($article->getUniteMesure())) {
  1322.                     $tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
  1323.                 }
  1324.                 if ($article->getAfficherComposantPdfInterne() === true) {
  1325.                     $tableau_donnee["afficher_composant_pdf_interne"] = 1;
  1326.                 } else {
  1327.                     $tableau_donnee["afficher_composant_pdf_interne"] = 0;
  1328.                 }
  1329.                 if ($article->getAfficherComposantPdfExterne() === true) {
  1330.                     $tableau_donnee["afficher_composant_pdf_externe"] = 1;
  1331.                 } else {
  1332.                     $tableau_donnee["afficher_composant_pdf_externe"] = 0;
  1333.                 }
  1334.                 if (is_object($article->getCategorieRemiseArticle())) {
  1335.                     $tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  1336.                 }
  1337.                 if ($article->getTemporaire()) {
  1338.                     $tableau_donnee["temporaire"] = 1;
  1339.                 } else {
  1340.                     $tableau_donnee["temporaire"] = null;
  1341.                 }
  1342.                 $tableau_donnee["libelle_secondaire"]       = $article->getLibelleSecondaire();
  1343.                 $tableau_donnee["a_commander"]              = "1";
  1344.                 $tableau_donnee["a_fabriquer"]              = "0";
  1345.                 $tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  1346.                 $tableau_donnee["quantite_conseillee"]      = $article->getQuantiteConseillee();
  1347.                 $tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
  1348.                 if ($article->getArchive()) {
  1349.                     $tableau_donnee["archive"] = "1";
  1350.                 } else {
  1351.                     $tableau_donnee["archive"] = "0";
  1352.                 }
  1353.                 //$tableau_donnee["archive"]=$article->getArchive();
  1354.                 $tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  1355.                 $tableau_donnee["nom_web"]                      = $article->getNomWeb();
  1356.                 $tableau_donnee["reference_web"]                = $article->getReferenceWeb();
  1357.                 $tableau_donnee["reference_fournisseur_web"]    = $article->getReferenceFournisseurWeb();
  1358.                 $tableau_donnee["description_web"]              = $article->getDescriptionWeb();
  1359.                 $tableau_donnee["resume_web"]                   = $article->getResumeWeb();
  1360.                 $tableau_donnee["frais_ports_texte_web"]        = $article->getFraisPortsTexteWeb();
  1361.                 $tableau_donnee["message_qd_en_stock"]          = $article->getMessageQdEnStockWeb();
  1362.                 if (is_object($article->getArticleEnconsigne())) {
  1363.                     $tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
  1364.                 }
  1365.                 $tableau_donnee["reference_appel_1"]  = $article->getReferenceAppel1();
  1366.                 $tableau_donnee["reference_appel_2"]  = $article->getReferenceAppel2();
  1367.                 $tableau_donnee["reference_appel_3"]  = $article->getReferenceAppel3();
  1368.                 $tableau_donnee["reference_appel_4"]  = $article->getReferenceAppel4();
  1369.                 $tableau_donnee["reference_appel_5"]  = $article->getReferenceAppel5();
  1370.                 $tableau_donnee["reference_appel_6"]  = $article->getReferenceAppel6();
  1371.                 $tableau_donnee["reference_appel_7"]  = $article->getReferenceAppel7();
  1372.                 $tableau_donnee["reference_appel_8"]  = $article->getReferenceAppel8();
  1373.                 $tableau_donnee["reference_appel_9"]  = $article->getReferenceAppel9();
  1374.                 $tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
  1375.                 $tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
  1376.                 if ($article->getMainOeuvre()) {
  1377.                     $tableau_donnee["main_oeuvre"] = "1";
  1378.                 } else {
  1379.                     $tableau_donnee["main_oeuvre"] = "0";
  1380.                 }
  1381.                 //$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
  1382.                 $tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
  1383.                 if (is_object($article->getType())) {
  1384.                     $tableau_donnee["type_id"] = $article->getType()->getId();
  1385.                 }
  1386.                 if (is_object($article->getFamilleCompta())) {
  1387.                     $tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
  1388.                 }
  1389.                 if ($article->getPrestation() === true) {
  1390.                     $tableau_donnee["prestation"] = 1;
  1391.                 } else {
  1392.                     $tableau_donnee["prestation"] = 0;
  1393.                 }
  1394.                 if ($article->getNonStocke()) {
  1395.                     $tableau_donnee["non_stocke"] = "1";
  1396.                 } else {
  1397.                     $tableau_donnee["non_stocke"] = "0";
  1398.                 }
  1399.                 //$tableau_donnee["non_stocke"]=$article->getNonStocke();
  1400.                 if ($article->getNonCommandable() === true) {
  1401.                     $tableau_donnee["non_commandable"] = 1;
  1402.                 } else {
  1403.                     $tableau_donnee["non_commandable"] = 0;
  1404.                 }
  1405.                 if (is_object($article->getParent())) {
  1406.                     $tableau_donnee["parent_id"] = $article->getParent()->getId();
  1407.                 }
  1408.                 if ($article->getDivers()) {
  1409.                     $tableau_donnee["divers"] = 1;
  1410.                 } else {
  1411.                     $tableau_donnee["divers"] = 0;
  1412.                 }
  1413.                 if ($article->getMouvemente()) {
  1414.                     $tableau_donnee["mouvemente"] = "1";
  1415.                 } else {
  1416.                     $tableau_donnee["mouvemente"] = "0";
  1417.                 }
  1418.                 //$tableau_donnee["mouvemente"]=$article->getMouvemente();
  1419.                 if ($article->getNumSerieObligatoire() === true) {
  1420.                     $tableau_donnee["num_serie_obligatoire"] = 1;
  1421.                 } else {
  1422.                     $tableau_donnee["num_serie_obligatoire"] = 0;
  1423.                 }
  1424.                 if (is_object($article->getArticleRemplacement())) {
  1425.                     $tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  1426.                 }
  1427.                 if ($article->getMajPoids()) {
  1428.                     $tableau_donnee["maj_poids"] = 1;
  1429.                 } else {
  1430.                     $tableau_donnee["maj_poids"] = 0;
  1431.                 }
  1432.                 if ($article->getMajPrixBase()) {
  1433.                     $tableau_donnee["maj_prix_base"] = 1;
  1434.                 } else {
  1435.                     $tableau_donnee["maj_prix_base"] = 0;
  1436.                 }
  1437.                 if ($article->getEstCommentaire()) {
  1438.                     $tableau_donnee["est_commentaire"] = 1;
  1439.                 } else {
  1440.                     $tableau_donnee["est_commentaire"] = 0;
  1441.                 }
  1442.                 $tableau_donnee["cond_achat"]     = $article->getConditionnementAchat();
  1443.                 $tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
  1444.                 $conn->insert('article__article'$tableau_donnee);
  1445.                 $idNouveauArticle $conn->lastInsertId();
  1446.                 $article          $repo_article->find($idNouveauArticle);
  1447.             } elseif ($article->getDivers() == 1) {
  1448.                 /*
  1449.             $articleTmp = clone $article;
  1450.             $newRef = $articleTmp->getReference().'-'.time();
  1451.             $articleTmp->setReference($newRef);
  1452.             $articleTmp->setParent($article);
  1453.             $articleTmp->setIdImport($article->getIdImport().'-duplique');
  1454.             $em->persist($articleTmp);
  1455.              $em->flush();
  1456.             $article = $articleTmp;
  1457.             */
  1458.                 $dateC = new \Datetime();
  1459.                 $conn $em->getConnection();
  1460.                 $conn->getConfiguration()->setSQLLogger(null);
  1461.                 $tableau_donnee                    = [];
  1462.                 $tableau_donnee["date"]            = $dateC->format("Y-m-d H:i:s");
  1463.                 $tableau_donnee["reference"]       = $article->getReference()."-".time();
  1464.                 $tableau_donnee["ral_fournisseur"] = "0";
  1465.                 $tableau_donnee["parent_id"]       = $article->getId();
  1466.                 $tableau_donnee["libelle"]         = $article->getLibelle();
  1467.                 $tableau_donnee["reference_client"]      = $article->getReferenceClient();
  1468.                 $tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
  1469.                 $tableau_donnee["prix_base"]             = $article->getPrixBase();
  1470.                 if ($article->getDateMaj() != "") {
  1471.                     $tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
  1472.                 }
  1473.                 if ($article->getDateMajPrix() != "") {
  1474.                     $tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
  1475.                 }
  1476.                 if ($article->getDateSuppression() != "") {
  1477.                     $tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
  1478.                 }
  1479.                 if (is_object($article->getMarque())) {
  1480.                     $tableau_donnee["marque_id"] = $article->getMarque()->getId();
  1481.                 }
  1482.                 $tableau_donnee["description"]        = $article->getDescription();
  1483.                 $tableau_donnee["description_courte"] = $article->getDescriptionCourte();
  1484.                 $tableau_donnee["stock"]              = "0";
  1485.                 if ($article->getStatut() === true) {
  1486.                     $tableau_donnee["statut"] = 1;
  1487.                 } else {
  1488.                     $tableau_donnee["statut"] = 0;
  1489.                 }
  1490.                 $tableau_donnee["largeur"]    = $article->getLargeur();
  1491.                 $tableau_donnee["profondeur"] = $article->getProfondeur();
  1492.                 $tableau_donnee["hauteur"]    = $article->getHauteur();
  1493.                 $tableau_donnee["poids"]      = $article->getPoids();
  1494.                 if ($article->getAConsigner() === true) {
  1495.                     $tableau_donnee["a_consigner"] = 1;
  1496.                 } else {
  1497.                     $tableau_donnee["a_consigner"] = 0;
  1498.                 }
  1499.                 if ($article->getStockAuto()) {
  1500.                     $tableau_donnee["stock_auto"] = 1;
  1501.                 } else {
  1502.                     $tableau_donnee["stock_auto"] = 0;
  1503.                 }
  1504.                 if ($article->getArretGamme()) {
  1505.                     $tableau_donnee["arret_gamme"] = "1";
  1506.                 } else {
  1507.                     $tableau_donnee["arret_gamme"] = "0";
  1508.                 }
  1509.                 if (is_object($article->getUtilisateur())) {
  1510.                     $tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
  1511.                 }
  1512.                 if (is_object($article->getRegleTaxe())) {
  1513.                     $tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  1514.                 }
  1515.                 $tableau_donnee["remise_max"]            = $article->getRemiseMax();
  1516.                 $tableau_donnee["type_remise_max"]       = $article->getTypeRemiseMax();
  1517.                 $tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  1518.                 $tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  1519.                 if (is_object($article->getNiveauUn())) {
  1520.                     $tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
  1521.                 }
  1522.                 if (is_object($article->getNiveauDeux())) {
  1523.                     $tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
  1524.                 }
  1525.                 if (is_object($article->getNiveauTrois())) {
  1526.                     $tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
  1527.                 }
  1528.                 if (is_object($article->getNiveauQuatre())) {
  1529.                     $tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
  1530.                 }
  1531.                 $tableau_donnee["pump"]        = $article->getCpump();
  1532.                 $tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
  1533.                 if ($article->getVirtuel() === true) {
  1534.                     $tableau_donnee["virtuel"] = 1;
  1535.                 } else {
  1536.                     $tableau_donnee["virtuel"] = 0;
  1537.                 }
  1538.                 //$tableau_donnee["prix_vente"]=$article->getLibelle();
  1539.                 $tableau_donnee["prix_vente"]      = 0;
  1540.                 $tableau_donnee["taux_marge"]      = $article->getTauxMarge();
  1541.                 $tableau_donnee["marge"]           = $article->getMarge();
  1542.                 $tableau_donnee["marge_reelle"]    = $article->getMargeReelle();
  1543.                 $tableau_donnee["ecotaxe"]         = $article->getEcotaxe();
  1544.                 $tableau_donnee["conditionnement"] = $article->getConditionnement();
  1545.                 $tableau_donnee["stock_reserve"]   = $article->getStockReserve();
  1546.                 if (is_object($article->getFournisseurDefaut())) {
  1547.                     $tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  1548.                 }
  1549.                 $tableau_donnee["ral_fournisseur"] = "0";
  1550.                 $tableau_donnee["id_import"]       = "";
  1551.                 $tableau_donnee["donnees_import"]  = "";
  1552.                 if ($article->getMajPrix()) {
  1553.                     $tableau_donnee["maj_prix"] = 1;
  1554.                 } else {
  1555.                     $tableau_donnee["maj_prix"] = 0;
  1556.                 }
  1557.                 if (is_object($article->getUniteMesure())) {
  1558.                     $tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
  1559.                 }
  1560.                 if ($article->getAfficherComposantPdfInterne() === true) {
  1561.                     $tableau_donnee["afficher_composant_pdf_interne"] = 1;
  1562.                 } else {
  1563.                     $tableau_donnee["afficher_composant_pdf_interne"] = 0;
  1564.                 }
  1565.                 if ($article->getAfficherComposantPdfExterne() === true) {
  1566.                     $tableau_donnee["afficher_composant_pdf_externe"] = 1;
  1567.                 } else {
  1568.                     $tableau_donnee["afficher_composant_pdf_externe"] = 0;
  1569.                 }
  1570.                 if (is_object($article->getCategorieRemiseArticle())) {
  1571.                     $tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  1572.                 }
  1573.                 if ($article->getTemporaire()) {
  1574.                     $tableau_donnee["temporaire"] = 1;
  1575.                 } else {
  1576.                     $tableau_donnee["temporaire"] = null;
  1577.                 }
  1578.                 $tableau_donnee["libelle_secondaire"]       = $article->getLibelleSecondaire();
  1579.                 $tableau_donnee["a_commander"]              = "1";
  1580.                 $tableau_donnee["a_fabriquer"]              = "0";
  1581.                 $tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  1582.                 $tableau_donnee["quantite_conseillee"]      = $article->getQuantiteConseillee();
  1583.                 $tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
  1584.                 if ($article->getArchive()) {
  1585.                     $tableau_donnee["archive"] = "1";
  1586.                 } else {
  1587.                     $tableau_donnee["archive"] = "0";
  1588.                 }
  1589.                 //$tableau_donnee["archive"]=$article->getArchive();
  1590.                 $tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  1591.                 $tableau_donnee["nom_web"]                      = $article->getNomWeb();
  1592.                 $tableau_donnee["reference_web"]                = $article->getReferenceWeb();
  1593.                 $tableau_donnee["reference_fournisseur_web"]    = $article->getReferenceFournisseurWeb();
  1594.                 $tableau_donnee["description_web"]              = $article->getDescriptionWeb();
  1595.                 $tableau_donnee["resume_web"]                   = $article->getResumeWeb();
  1596.                 $tableau_donnee["frais_ports_texte_web"]        = $article->getFraisPortsTexteWeb();
  1597.                 $tableau_donnee["message_qd_en_stock"]          = $article->getMessageQdEnStockWeb();
  1598.                 if (is_object($article->getArticleEnconsigne())) {
  1599.                     $tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
  1600.                 }
  1601.                 $tableau_donnee["reference_appel_1"]  = $article->getReferenceAppel1();
  1602.                 $tableau_donnee["reference_appel_2"]  = $article->getReferenceAppel2();
  1603.                 $tableau_donnee["reference_appel_3"]  = $article->getReferenceAppel3();
  1604.                 $tableau_donnee["reference_appel_4"]  = $article->getReferenceAppel4();
  1605.                 $tableau_donnee["reference_appel_5"]  = $article->getReferenceAppel5();
  1606.                 $tableau_donnee["reference_appel_6"]  = $article->getReferenceAppel6();
  1607.                 $tableau_donnee["reference_appel_7"]  = $article->getReferenceAppel7();
  1608.                 $tableau_donnee["reference_appel_8"]  = $article->getReferenceAppel8();
  1609.                 $tableau_donnee["reference_appel_9"]  = $article->getReferenceAppel9();
  1610.                 $tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
  1611.                 $tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
  1612.                 if ($article->getMainOeuvre()) {
  1613.                     $tableau_donnee["main_oeuvre"] = "1";
  1614.                 } else {
  1615.                     $tableau_donnee["main_oeuvre"] = "0";
  1616.                 }
  1617.                 //$tableau_donnee["main_oeuvre"]=$article->getMainOeuvre();
  1618.                 $tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
  1619.                 if (is_object($article->getType())) {
  1620.                     $tableau_donnee["type_id"] = $article->getType()->getId();
  1621.                 }
  1622.                 if (is_object($article->getFamilleCompta())) {
  1623.                     $tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
  1624.                 }
  1625.                 if ($article->getPrestation() === true) {
  1626.                     $tableau_donnee["prestation"] = 1;
  1627.                 } else {
  1628.                     $tableau_donnee["prestation"] = 0;
  1629.                 }
  1630.                 if ($article->getNonStocke()) {
  1631.                     $tableau_donnee["non_stocke"] = "1";
  1632.                 } else {
  1633.                     $tableau_donnee["non_stocke"] = "0";
  1634.                 }
  1635.                 //$tableau_donnee["non_stocke"]=$article->getNonStocke();
  1636.                 if ($article->getNonCommandable() === true) {
  1637.                     $tableau_donnee["non_commandable"] = 1;
  1638.                 } else {
  1639.                     $tableau_donnee["non_commandable"] = 0;
  1640.                 }
  1641.                 if (is_object($article->getParent())) {
  1642.                     $tableau_donnee["parent_id"] = $article->getParent()->getId();
  1643.                 }
  1644.                 if ($article->getDivers()) {
  1645.                     $tableau_donnee["divers"] = 1;
  1646.                 } else {
  1647.                     $tableau_donnee["divers"] = 0;
  1648.                 }
  1649.                 if ($article->getMouvemente()) {
  1650.                     $tableau_donnee["mouvemente"] = "1";
  1651.                 } else {
  1652.                     $tableau_donnee["mouvemente"] = "0";
  1653.                 }
  1654.                 //$tableau_donnee["mouvemente"]=$article->getMouvemente();
  1655.                 if ($article->getNumSerieObligatoire() === true) {
  1656.                     $tableau_donnee["num_serie_obligatoire"] = 1;
  1657.                 } else {
  1658.                     $tableau_donnee["num_serie_obligatoire"] = 0;
  1659.                 }
  1660.                 if (is_object($article->getArticleRemplacement())) {
  1661.                     $tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  1662.                 }
  1663.                 if ($article->getMajPoids()) {
  1664.                     $tableau_donnee["maj_poids"] = 1;
  1665.                 } else {
  1666.                     $tableau_donnee["maj_poids"] = 0;
  1667.                 }
  1668.                 if ($article->getMajPrixBase()) {
  1669.                     $tableau_donnee["maj_prix_base"] = 1;
  1670.                 } else {
  1671.                     $tableau_donnee["maj_prix_base"] = 0;
  1672.                 }
  1673.                 if ($article->getEstCommentaire()) {
  1674.                     $tableau_donnee["est_commentaire"] = 1;
  1675.                 } else {
  1676.                     $tableau_donnee["est_commentaire"] = 0;
  1677.                 }
  1678.                 $tableau_donnee["cond_achat"]     = $article->getConditionnementAchat();
  1679.                 $tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
  1680.                 $conn->insert('article__article'$tableau_donnee);
  1681.                 $idNouveauArticle $conn->lastInsertId();
  1682.                 $article          $repo_article->find($idNouveauArticle);
  1683.             }
  1684.             if ($article->getArretGamme() and is_object($article->getArticleRemplacement())) {
  1685.                 $stockEpuise $article->getStock() - $article->getStockReserve();
  1686.                 while ($stockEpuise <= && $article->getArretGamme() and is_object($article->getArticleRemplacement())) {
  1687.                     $article     $article->getArticleRemplacement();
  1688.                     $stockEpuise $article->getStock() - $article->getStockReserve();
  1689.                 }
  1690.             }
  1691.             $commande null;
  1692.             if ($commandeId != '') {
  1693.                 $commande $repo_commande->find($commandeId);
  1694.                 //$type = 'commande';
  1695.             }
  1696.             $a['position'] = 0;
  1697.             if (is_object($commande)) {
  1698.                 $a['commande'] = $commande;
  1699.                 $a['position'] = count($commande->getArticleCommande());
  1700.             } else {
  1701.                 $a['commande'] = null;
  1702.             }
  1703.             $a['action'] = "insert";
  1704.             $a['article']           = $article;
  1705.             $a['libelle']           = $article->getLibelle();
  1706.             $a['libelleSecondaire'] = $article->getLibelleSecondaire();
  1707.             //$a['ecocontribution']= floatval($article->getEcocontribution());
  1708.             $a['ecocontribution'] = 0;
  1709.             $a['fraisPort'] = "0";
  1710.             if ($quantite != '' && is_numeric($quantite)) {
  1711.                 $a['quantite']      = $quantite;
  1712.                 $a['quantitePrepa'] = $quantite;
  1713.             } else {
  1714.                 if ($article->getConditionnement() > 0) {
  1715.                     $a['quantite']      = $article->getConditionnement();
  1716.                     $a['quantitePrepa'] = $article->getConditionnement();
  1717.                 } else {
  1718.                     $repo_cond_vente $em->getRepository(ConditionVente::class);
  1719.                     $condVenteMini   $repo_cond_vente->findQuantiteMini($article""$adresse);
  1720.                     if (is_object($condVenteMini)) {
  1721.                         $a['quantite']      = $condVenteMini->getDebut();
  1722.                         $a['quantitePrepa'] = $condVenteMini->getDebut();
  1723.                     } elseif ($article->getConditionnement() > 0) {
  1724.                         $a['quantite']      = $article->getConditionnement();
  1725.                         $a['quantitePrepa'] = $article->getConditionnement();
  1726.                     } else {
  1727.                         $a['quantite']      = "1";
  1728.                         $a['quantitePrepa'] = "1";
  1729.                     }
  1730.                     //$a['quantite']="1";
  1731.                     //$a['quantitePrepa']="1";
  1732.                 }
  1733.             }
  1734.             $a['ralClient']     = $a['quantite'];
  1735.             $a['quantiteDispo'] = $a['quantite'];
  1736.             $client             '';
  1737.             if ($client_id != '') {
  1738.                 $client $repo_client->find($client_id);
  1739.                 if (is_object($client)) {
  1740.                     $variables['client'] = $client;
  1741.                     if (is_object($client->getLangue())) {
  1742.                         $repo_trad $em->getRepository(Traduction::class);
  1743.                         $trad      $repo_trad->findOneBy(["article" => $article"langue" => $client->getLangue()]);
  1744.                         if (is_object($trad)) {
  1745.                             $a['libelle']           = $trad->getLibelle();
  1746.                             $a['libelleSecondaire'] = $trad->getLibelleSecondaire();
  1747.                         }
  1748.                     }
  1749.                 }
  1750.             }
  1751.             if ($article->getEstCommentaire()) {
  1752.                 $a['estCommentaire'] = 1;
  1753.             } else {
  1754.                 $a['estCommentaire'] = 0;
  1755.             }
  1756.             $a['commentaire']          = "";
  1757.             $a['commentaireSuppl']     = "";
  1758.             $a['commentairePrive']     = "";
  1759.             $a['remise']               = "0";
  1760.             $a['remiseSupplementaire'] = "0";
  1761.             $a['totalHt']              = floatval($article->getPrixVente());
  1762.             $a['totalHtV2'] = floatval($article->getPrixVente());
  1763.             $quantiteSurCommande       floatval($quantiteSurCommande) + $a['quantite'];
  1764.             $a['couleur']              = $serviceArticle->getCouleurEtatStock($article$quantiteSurCommande);
  1765.             $a['quantiteDejaPreparee'] = 0;
  1766.             $a['transporteur']         = $article->getTransporteur();
  1767.             $a['poids']                = floatval($article->getPoids());
  1768.             $taxe                      $serviceArticle->getTaxe($article$client$adresse);
  1769.             if (is_object($taxe)) {
  1770.                 $a['taxe'] = $taxe;
  1771.                 $a['tva']  = $taxe->getTaux();
  1772.             }
  1773.             //sauvegarde auto
  1774.             if (is_object($commande)) {
  1775.                 $enregAuto true;
  1776.                 //modification des donnees pour l'enregistrement
  1777.                 $a['prix_base'] = floatval($article->getPrixVente());
  1778.                 if (is_object($a['article'])) {
  1779.                     $a['article_id'] = $a['article']->getId();
  1780.                 }
  1781.                 if (is_object($a['transporteur'])) {
  1782.                     $a['transporteur_id'] = $a['transporteur']->getId();
  1783.                 }
  1784.                 if (is_object($a['commande'])) {
  1785.                     $a['commande_id'] = $a['commande']->getId();
  1786.                 }
  1787.                 $a['libelle_secondaire'] = $a['libelleSecondaire'];
  1788.                 $a['frais_port']         = $a['fraisPort'];
  1789.                 $a['ral_client']         = $a['ralClient'];
  1790.                 //$a['est_commentaire'] = $a['estCommentaire'];
  1791.                 $a['commentaire_suppl']     = $a['commentaireSuppl'];
  1792.                 $a['commentaire_prive']     = $a['commentairePrive'];
  1793.                 $a['remise_supplementaire'] = $a['remiseSupplementaire'];
  1794.                 $a['total_ht']              = $a['totalHt'];
  1795.                 //$a['total_ht_v2'] = $a['totalHtV2'];
  1796.                 $a['quantite_deja_preparee'] = $a['quantiteDejaPreparee'];
  1797.                 $a['quantite_dispo']         = $a['quantiteDispo'];
  1798.                 $a['date'] = (new \Datetime)->format('Y-m-d H:i:s');
  1799.                 if (array_key_exists('taxe'$a) && is_object($a['taxe'])) {
  1800.                     $a['taxe_id'] = $a['taxe']->getId();
  1801.                 }
  1802.                 unset($a['remise']);
  1803.                 unset($a['transporteur']);
  1804.                 unset($a['article']);
  1805.                 unset($a['commande']);
  1806.                 unset($a['action']);
  1807.                 unset($a['libelleSecondaire']);
  1808.                 unset($a['fraisPort']);
  1809.                 unset($a['quantitePrepa']);
  1810.                 unset($a['ralClient']);
  1811.                 unset($a['estCommentaire']);
  1812.                 unset($a['commentaireSuppl']);
  1813.                 unset($a['commentairePrive']);
  1814.                 unset($a['remiseSupplementaire']);
  1815.                 unset($a['totalHt']);
  1816.                 unset($a['totalHtV2']);
  1817.                 unset($a['couleur']);
  1818.                 unset($a['quantiteDejaPreparee']);
  1819.                 unset($a['quantiteDispo']);
  1820.                 if (array_key_exists('taxe'$a)) {
  1821.                     unset($a['taxe']);
  1822.                 }
  1823.                 //print_r($a);
  1824.                 $conn->insert('commerciale__article_commande'$a);
  1825.                 //$a['id'] = $conn->lastInsertId();
  1826.                 $a $repo_article_commande->find($conn->lastInsertId());
  1827.                 $commandeService->creerHistorique($commande'ajout-ligne', ['articleCommande' => $a]);
  1828.                 //echo "toto";
  1829.                 if ($countTmp == 0) {
  1830.                     $articleCommandeAssocie $conn->lastInsertId();
  1831.                 } else {
  1832.                     //$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
  1833.                     //$a->setArticleCommandeAssocie($articleCommandeAssocie);
  1834.                     $articleCommandeAssocie $conn->lastInsertId();
  1835.                 }
  1836.                 //reservation de stock
  1837.                 if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
  1838.                     $type             'commande';
  1839.                     $ralClientArtComm floatval($a->getQuantite());
  1840.                     $reserve          $ralClientArtComm floatval($article->getStockReserve());
  1841.                     if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true) {
  1842.                         $article->setStockReserve(0);
  1843.                         if ($article->getProduitInterne() == true) {
  1844.                             $variation floatval($a->getQuantite());
  1845.                             $serviceArticle->modifierStockReserveComposants($article$variation);
  1846.                         }
  1847.                     } elseif (floatval($a->getQuantite()) != 0) {
  1848.                         $article->setStockReserve($reserve);
  1849.                         $em->persist($article);
  1850.                     }
  1851.                     $em->flush();
  1852.                 }
  1853.             } else {
  1854.                 if ($countTmp == 0) {
  1855.                     $a['id'] = $idArticleCommandeTmp;
  1856.                 } else {
  1857.                     $a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
  1858.                 }
  1859.             }
  1860.             $countTmp++;
  1861.             $variables = [
  1862.                 'a'              => $a,
  1863.                 'boucle'         => "0",
  1864.                 'numeroLigne'    => "0",
  1865.                 'tabColonneUser' => $tabColonneUser,
  1866.                 'colspan'        => $colspan,
  1867.                 'type'           => $type,
  1868.                 'enregAuto'      => $enregAuto,
  1869.                 'adresse'        => $adresse,
  1870.             ];
  1871.             if ($client_id != '') {
  1872.                 $client $repo_client->find($client_id);
  1873.                 if (is_object($client)) {
  1874.                     $variables['client'] = $client;
  1875.                 }
  1876.             }
  1877.             if ($cible == "or") {
  1878.                 $rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig'$variables);
  1879.             } elseif ($cible == "regularisation") {
  1880.                 $rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig'$variables);
  1881.             } else {
  1882.                 $rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig'$variables);
  1883.             }
  1884.             $commentairePonctuel .= $article->getCommentairePonctuel();
  1885.             $stockEpuise $article->getStock() - $article->getStockReserve();
  1886.             if ($article->getArretGamme() && $stockEpuise <= 0) {
  1887.                 $commentairePonctuel .= "<div>Article en arrêt de gamme sans article de remplacement.</div>";
  1888.             }
  1889.             if (floatVal($article->getPrixVente()) < floatVal($article->getCpump())) {
  1890.                 //message_popin += ">Attention : Le prix de vente "+parseFloat(donnees[0].prixVente)+" &euro; est inférieur au PUMP "+parseFloat(donnees[0].pump)+". &euro;<br/>";
  1891.                 //$commentairePonctuel .= "<div>Le prix de vente (".floatVal($article->getPrixVente())."  &euro;) est inférieur au PUMP (".round(floatVal($article->getPump()),2)."  &euro;)</div>";
  1892.             }
  1893.             if ($article->getAConsigner() == "1" and is_object($article->getArticleEnConsigne())) {
  1894.                 $consigne $article->getArticleEnConsigne()->getId();
  1895.             }
  1896.         }
  1897.         $articleCommentaire 0;
  1898.         if ($article->getEstCommentaire()) {
  1899.             $articleCommentaire 1;
  1900.         }
  1901.         return new JsonResponse([
  1902.                                     'consigne'            => $consigne,
  1903.                                     'rendu'               => $rendu,
  1904.                                     'id'                  => $article->getId(),
  1905.                                     'articleCommentaire'  => $articleCommentaire,
  1906.                                     'commentairePonctuel' => $commentairePonctuel,
  1907.                                     'couleur'             => '',
  1908.                                     'type'                => $type,
  1909.                                 ]);
  1910.     }
  1911.     /**
  1912.      * @Route("/commande-fournisseur-reprise-article/nouveau/{id}", name="dtc_construire_ligne_article_commande_fournisseur_reprise")
  1913.      */
  1914.     public function construireLigneArticleCommandeFournisseurRepriseAction(Request            $requestArticleCommande $articleCommandeEntityManagerInterface $em,
  1915.                                                                            ArticleService     $articleServiceArticleService $serviceArticleDateService $dateService,
  1916.                                                                            FournisseurService $fournisseurServiceColonneTableauService $serviceColonne
  1917.     ) {
  1918.         $em   $this->getDoctrine();
  1919.         $conn $em->getConnection();
  1920.         $conn->getConfiguration()->setSQLLogger(null);
  1921.         $repoFournisseur            $em->getRepository(Fournisseur::class);
  1922.         $repo_taxe                  $em->getRepository(Taxe::class);
  1923.         $fournisseur                $request->query->get('fournisseur');
  1924.         $articlesCommandeSource     $request->query->get('articlesCommandeSource');
  1925.         $fournisseur                $articleCommande->getCommandeFournisseur()->getFournisseur()->getId();
  1926.         $repo_article_commande      $em->getRepository(ArticleCommande::class);
  1927.         $articlesCommandeSource_obj $repo_article_commande->find($articlesCommandeSource);
  1928.         $commandeId $request->query->get('commandeId');;
  1929.         $quantite     $request->query->get('quantite');
  1930.         $repo_article $em->getRepository(Article::class);
  1931.         $article                $articleCommande->getArticle();
  1932.         $quantite               $request->query->get('quantite');
  1933.         $quantiteSurCommande    $request->query->get('quantiteSurCommande');
  1934.         $client_id              $request->query->get('client');
  1935.         $cible                  $request->query->get('cible');
  1936.         $articlesCommandeSource $request->query->get('articlesCommandeSource');
  1937.         $type                   '';
  1938.         $repo_article_commande      $em->getRepository(ArticleCommande::class);
  1939.         $articlesCommandeSource_obj $repo_article_commande->find($articlesCommandeSource);
  1940.         if (!= and $article->getDivers() == && ! is_object($article->getParent())) {
  1941.             $conn $em->getConnection();
  1942.             $conn->getConfiguration()->setSQLLogger(null);
  1943.             $referenceDivers                    $articleService->getReferenceDivers($article);
  1944.             $tableau_donnee                     = [];
  1945.             $tableau_donnee["reference"]        = $article->getReference()."-".$referenceDivers['reference'];
  1946.             $tableau_donnee["numero_reference"] = $referenceDivers['numero_reference'];
  1947.             $tableau_donnee["ral_fournisseur"]  = "0";
  1948.             $tableau_donnee["parent_id"]        = $article->getId();
  1949.             $tableau_donnee["libelle"]          = $article->getLibelle();
  1950.             $tableau_donnee["reference_client"]      = $article->getReferenceClient();
  1951.             $tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
  1952.             $tableau_donnee["prix_base"]             = $article->getPrixBase();
  1953.             $dateTmp                                 = new \Datetime;
  1954.             $tableau_donnee["date"]                  = $dateTmp->format("Y-m-d H:i:s");
  1955.             if ($article->getDateMaj() != "") {
  1956.                 $tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
  1957.             }
  1958.             if ($article->getDateMajPrix() != "") {
  1959.                 $tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
  1960.             }
  1961.             if ($article->getDateSuppression() != "") {
  1962.                 $tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
  1963.             }
  1964.             if (is_object($article->getMarque())) {
  1965.                 $tableau_donnee["marque_id"] = $article->getMarque()->getId();
  1966.             }
  1967.             $tableau_donnee["description"]        = $article->getDescription();
  1968.             $tableau_donnee["description_courte"] = $article->getDescriptionCourte();
  1969.             $tableau_donnee["stock"]              = "0";
  1970.             if ($article->getStatut() === true) {
  1971.                 $tableau_donnee["statut"] = 1;
  1972.             } else {
  1973.                 $tableau_donnee["statut"] = 0;
  1974.             }
  1975.             $tableau_donnee["largeur"]    = $article->getLargeur();
  1976.             $tableau_donnee["profondeur"] = $article->getProfondeur();
  1977.             $tableau_donnee["hauteur"]    = $article->getHauteur();
  1978.             $tableau_donnee["poids"]      = $article->getPoids();
  1979.             if ($article->getAConsigner()) {
  1980.                 $tableau_donnee["a_consigner"] = 1;
  1981.             } else {
  1982.                 $tableau_donnee["a_consigner"] = 0;
  1983.             }
  1984.             if ($article->getStockAuto()) {
  1985.                 $tableau_donnee["stock_auto"] = 1;
  1986.             } else {
  1987.                 $tableau_donnee["stock_auto"] = 0;
  1988.             }
  1989.             if ($article->getArretGamme() === true) {
  1990.                 $tableau_donnee["arret_gamme"] = 1;
  1991.             } else {
  1992.                 $tableau_donnee["arret_gamme"] = 0;
  1993.             }
  1994.             if (is_object($article->getUtilisateur())) {
  1995.                 $tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
  1996.             }
  1997.             if (is_object($article->getRegleTaxe())) {
  1998.                 $tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  1999.             }
  2000.             $tableau_donnee["remise_max"]            = $article->getRemiseMax();
  2001.             $tableau_donnee["type_remise_max"]       = $article->getTypeRemiseMax();
  2002.             $tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  2003.             $tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  2004.             if (is_object($article->getNiveauUn())) {
  2005.                 $tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
  2006.             }
  2007.             if (is_object($article->getNiveauDeux())) {
  2008.                 $tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
  2009.             }
  2010.             if (is_object($article->getNiveauTrois())) {
  2011.                 $tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
  2012.             }
  2013.             if (is_object($article->getNiveauQuatre())) {
  2014.                 $tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
  2015.             }
  2016.             $tableau_donnee["pump"]        = $article->getCpump();
  2017.             $tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
  2018.             if ($article->getVirtuel()) {
  2019.                 $tableau_donnee["virtuel"] = 1;
  2020.             } else {
  2021.                 $tableau_donnee["virtuel"] = 0;
  2022.             }
  2023.             //$tableau_donnee["prix_vente"]=$article->getLibelle();
  2024.             $tableau_donnee["prix_vente"]      = 0;
  2025.             $tableau_donnee["taux_marge"]      = $article->getTauxMarge();
  2026.             $tableau_donnee["marge"]           = $article->getMarge();
  2027.             $tableau_donnee["marge_reelle"]    = $article->getMargeReelle();
  2028.             $tableau_donnee["ecotaxe"]         = $article->getEcotaxe();
  2029.             $tableau_donnee["conditionnement"] = $article->getConditionnement();
  2030.             $tableau_donnee["stock_reserve"]   = $article->getStockReserve();
  2031.             if (is_object($article->getFournisseurDefaut())) {
  2032.                 $tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  2033.             }
  2034.             $tableau_donnee["ral_fournisseur"] = "0";
  2035.             $tableau_donnee["id_import"]       = "";
  2036.             $tableau_donnee["donnees_import"]  = "";
  2037.             if ($article->getMajPrix()) {
  2038.                 $tableau_donnee["maj_prix"] = 1;
  2039.             } else {
  2040.                 $tableau_donnee["maj_prix"] = 0;
  2041.             }
  2042.             if (is_object($article->getUniteMesure())) {
  2043.                 $tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
  2044.             }
  2045.             if ($article->getAfficherComposantPdfInterne()) {
  2046.                 $tableau_donnee["afficher_composant_pdf_interne"] = 1;
  2047.             } else {
  2048.                 $tableau_donnee["afficher_composant_pdf_interne"] = 0;
  2049.             }
  2050.             if ($article->getAfficherComposantPdfExterne()) {
  2051.                 $tableau_donnee["afficher_composant_pdf_externe"] = 1;
  2052.             } else {
  2053.                 $tableau_donnee["afficher_composant_pdf_externe"] = 0;
  2054.             }
  2055.             if (is_object($article->getCategorieRemiseArticle())) {
  2056.                 $tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  2057.             }
  2058.             $tableau_donnee["temporaire"]               = $article->getTemporaire();
  2059.             $tableau_donnee["libelle_secondaire"]       = $article->getLibelleSecondaire();
  2060.             $tableau_donnee["a_commander"]              = "1";
  2061.             $tableau_donnee["a_fabriquer"]              = "0";
  2062.             $tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  2063.             $tableau_donnee["quantite_conseillee"]      = $article->getQuantiteConseillee();
  2064.             $tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
  2065.             if ($article->getArchive() === true) {
  2066.                 $tableau_donnee["archive"] = 1;
  2067.             } else {
  2068.                 $tableau_donnee["archive"] = 0;
  2069.             }
  2070.             $tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  2071.             $tableau_donnee["nom_web"]                      = $article->getNomWeb();
  2072.             $tableau_donnee["reference_web"]                = $article->getReferenceWeb();
  2073.             $tableau_donnee["reference_fournisseur_web"]    = $article->getReferenceFournisseurWeb();
  2074.             $tableau_donnee["description_web"]              = $article->getDescriptionWeb();
  2075.             $tableau_donnee["resume_web"]                   = $article->getResumeWeb();
  2076.             $tableau_donnee["frais_ports_texte_web"]        = $article->getFraisPortsTexteWeb();
  2077.             $tableau_donnee["message_qd_en_stock"]          = $article->getMessageQdEnStockWeb();
  2078.             if (is_object($article->getArticleEnconsigne())) {
  2079.                 $tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
  2080.             }
  2081.             $tableau_donnee["reference_appel_1"]  = $article->getReferenceAppel1();
  2082.             $tableau_donnee["reference_appel_2"]  = $article->getReferenceAppel2();
  2083.             $tableau_donnee["reference_appel_3"]  = $article->getReferenceAppel3();
  2084.             $tableau_donnee["reference_appel_4"]  = $article->getReferenceAppel4();
  2085.             $tableau_donnee["reference_appel_5"]  = $article->getReferenceAppel5();
  2086.             $tableau_donnee["reference_appel_6"]  = $article->getReferenceAppel6();
  2087.             $tableau_donnee["reference_appel_7"]  = $article->getReferenceAppel7();
  2088.             $tableau_donnee["reference_appel_8"]  = $article->getReferenceAppel8();
  2089.             $tableau_donnee["reference_appel_9"]  = $article->getReferenceAppel9();
  2090.             $tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
  2091.             $tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
  2092.             if ($article->getMainOeuvre() === true) {
  2093.                 $tableau_donnee["main_oeuvre"] = 1;
  2094.             } else {
  2095.                 $tableau_donnee["main_oeuvre"] = 0;
  2096.             }
  2097.             $tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
  2098.             if (is_object($article->getType())) {
  2099.                 $tableau_donnee["type_id"] = $article->getType()->getId();
  2100.             }
  2101.             if (is_object($article->getFamilleCompta())) {
  2102.                 $tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
  2103.             }
  2104.             if ($article->getPrestation()) {
  2105.                 $tableau_donnee["prestation"] = 1;
  2106.             } else {
  2107.                 $tableau_donnee["prestation"] = 0;
  2108.             }
  2109.             if ($article->getNonStocke() === true) {
  2110.                 $tableau_donnee["non_stocke"] = 1;
  2111.             } else {
  2112.                 $tableau_donnee["non_stocke"] = 0;
  2113.             }
  2114.             if ($article->getNonCommandable()) {
  2115.                 $tableau_donnee["non_commandable"] = 1;
  2116.             } else {
  2117.                 $tableau_donnee["non_commandable"] = 0;
  2118.             }
  2119.             if (is_object($article->getParent())) {
  2120.                 $tableau_donnee["parent_id"] = $article->getParent()->getId();
  2121.             }
  2122.             $tableau_donnee["divers"] = $article->getDivers();
  2123.             if ($article->getMouvemente() === true) {
  2124.                 $tableau_donnee["mouvemente"] = 1;
  2125.             } else {
  2126.                 $tableau_donnee["mouvemente"] = 0;
  2127.             }
  2128.             if ($article->getNumSerieObligatoire()) {
  2129.                 $tableau_donnee["num_serie_obligatoire"] = 1;
  2130.             } else {
  2131.                 $tableau_donnee["num_serie_obligatoire"] = 0;
  2132.             }
  2133.             if (is_object($article->getArticleRemplacement())) {
  2134.                 $tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  2135.             }
  2136.             if ($article->getMajPoids()) {
  2137.                 $tableau_donnee["maj_poids"] = 1;
  2138.             } else {
  2139.                 $tableau_donnee["maj_poids"] = 0;
  2140.             }
  2141.             if ($article->getMajPrixBase()) {
  2142.                 $tableau_donnee["maj_prix_base"] = 1;
  2143.             } else {
  2144.                 $tableau_donnee["maj_prix_base"] = 0;
  2145.             }
  2146.             if ($article->getEstCommentaire()) {
  2147.                 $tableau_donnee["est_commentaire"] = 1;
  2148.             } else {
  2149.                 $tableau_donnee["est_commentaire"] = 0;
  2150.             }
  2151.             $tableau_donnee["cond_achat"]     = $article->getConditionnementAchat();
  2152.             $tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
  2153.             if (is_object($article->getRegleTaxeAchat())) {
  2154.                 $tableau_donnee["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
  2155.             }
  2156.             $tableau_donnee["maj_prix"] = 1;
  2157.             $conn->insert('article__article'$tableau_donnee);
  2158.             $idNouveauArticle $conn->lastInsertId();
  2159.             $article          $repo_article->find($idNouveauArticle);
  2160.         }
  2161.         $a = [];
  2162.         //$a['id'] = 'tmp-'.time();
  2163.         $a['position']              = "";
  2164.         $a['article']               = $article;
  2165.         $a['ecocontribution']       = floatval($article->getEcocontribution());
  2166.         $a['libelle']               = $articleCommande->getLibelle();
  2167.         $a['articleCommandeRepris'] = $articleCommande;
  2168.         if ($quantite != '' && is_numeric($quantite)) {
  2169.             $a['quantite'] = -$quantite;
  2170.             $a['ral']      = -$quantite;
  2171.         } else {
  2172.             $a['quantite'] = "-1";
  2173.             $a['ral']      = "-1";
  2174.         }
  2175.         //$a['estCommentaire']=$article->getEstCommentaire();
  2176.         if ($article->getEstCommentaire()) {
  2177.             $a['estCommentaire'] = 1;
  2178.         } else {
  2179.             $a['estCommentaire'] = 0;
  2180.         }
  2181.         $a['articleCommandeRepris'] = $articleCommande;
  2182.         $a['commentaire']           = "Reprise sur facture n°".$articleCommande->getCommandeFournisseur()->getReference();
  2183.         //$a['commentaire']="";
  2184.         $a['commentaireSuppl']     = "";
  2185.         $a['commentairePrive']     = "";
  2186.         $a['remise']               = $articleCommande->getRemise();
  2187.         $a['remiseSupplementaire'] = $articleCommande->getRemiseSupplementaire();
  2188.         //$a['totalHt']=$article->getPrixBase();
  2189.         $a['totalHt'] = -($articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite);
  2190.         //$a['totalHtV2'] = -($articleCommande->getTotalHt()/$articleCommande->getQuantite()*$quantite);
  2191.         $a['prixBase'] = $articleCommande->getPrixBase();
  2192.         $condition     '';
  2193.         //recuperer la condition d'achat par défaut
  2194.         $repoConditionsAchat $em->getRepository(ConditionAchat::class);
  2195.         //$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
  2196.         if ($fournisseur != '') {
  2197.             $condition $repoConditionsAchat->findOneBy([
  2198.                                                              'article'     => $article->getId(),
  2199.                                                              'fournisseur' => $fournisseur,
  2200.                                                              'defaut'      => 1,
  2201.                                                          ]);
  2202.         }
  2203.         if ( ! isset($condition) || ! is_object($condition)) {
  2204.             /*
  2205.         $condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId(),
  2206.         'fournisseur' => $fournisseur,
  2207.     ));
  2208.     */
  2209.             //$conditions = $repoConditionsAchat->findBy(array('article' => $article->getId(),'fournisseur' => $fournisseur,), array('quantite'=>'ASC'), 1, 0);
  2210.             //if(count($conditions)) $condition = $conditions[0];
  2211.         }
  2212.         $condition $articleCommande->getConditionAchat();
  2213.         $a['coefficientConditionnement'] = 1;
  2214.         $a['fraisAnnexes']               = 0;
  2215.         $a['dateApproximativeReception'] = null;
  2216.         if (is_object($condition)) {
  2217.             $a['conditionAchat'] = $condition;
  2218.             $a['fraisAnnexes']   = $condition->getFraisAnnexes();
  2219.         }
  2220.         if (is_object($condition) and != 1) {
  2221.             $a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
  2222.             if ($condition->getPrixNet() and != 1) {
  2223.                 $a['remise']               = "0";
  2224.                 $a['remiseSupplementaire'] = "0";
  2225.                 if ($condition->getPrixAchatNet() != '') {
  2226.                     //$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
  2227.                     $a['prixBase'] = $condition->getPrixAchatNet();
  2228.                 }
  2229.             } elseif (!= 1) {
  2230.                 if ($condition->getTauxRemise() != '') {
  2231.                     $a['remise'] = $condition->getTauxRemise();
  2232.                 }
  2233.                 if ($condition->getTauxRemiseSupplementaire() != '') {
  2234.                     $a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
  2235.                 }
  2236.                 if ($condition->getPrixAchatBrut() != '') {
  2237.                     //$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
  2238.                     $a['prixBase'] = $condition->getPrixAchatBrut();
  2239.                 }
  2240.             }
  2241.             if ($condition->getLibelle() != '' and != 1) {
  2242.                 $a['libelle'] = $condition->getLibelle();
  2243.             }
  2244.             if ($quantite != '' && is_numeric($quantite)) {
  2245.                 $a['quantite'] = -$quantite;
  2246.             } elseif ($condition->getQuantite() != '' and != 1) {
  2247.                 //$a['quantite']=$condition->getQuantite();
  2248.                 $conditionnement 1;
  2249.                 if ($condition->getConditionnement() != '') {
  2250.                     $conditionnement floatval($condition->getConditionnement());
  2251.                 }
  2252.                 $quantite floatval($condition->getQuantite());
  2253.                 $i        1;
  2254.                 while ($quantite $conditionnement != 0) {
  2255.                     $quantite++;
  2256.                 }
  2257.                 $a['quantite']             = -$quantite;
  2258.                 $a['ral']                  = -$quantite;
  2259.                 $a['referenceFournisseur'] = $condition->getReferenceFournisseur();
  2260.             }
  2261.             $a['conditionAchat'] = $condition;
  2262.             $a['fraisAnnexes'] = $condition->getFraisAnnexes();
  2263.             if (floatval($condition->getDelai()) > 0) {
  2264.                 $joursLivraison         = ["lundi""mardi""mercredi""jeudi""vendredi"];
  2265.                 $dateLivraisonTheorique $dateService->date_addWorkingDays(strtotime((new \Datetime)->format("Y-m-d")), floatval($condition->getDelai()), $joursLivraison);
  2266.                 //$a['dateApproximativeReception'] = (new \Datetime)->modify('+ '.floatval($condition->getDelai()).' days');
  2267.                 $a['dateApproximativeReception'] = $dateLivraisonTheorique;
  2268.             }
  2269.         }
  2270.         $a['couleur'] = $serviceArticle->getCouleurEtatStock($article$a['quantite']);
  2271.         if ($fournisseur != "") {
  2272.             $fournisseur $repoFournisseur->find($fournisseur);
  2273.         }
  2274.         $taxe $repo_taxe->find(5);
  2275.         if (is_object($fournisseur)) {
  2276.             $taxe $fournisseurService->getTaxe($fournisseur$article);
  2277.         }
  2278.         $a['tva']  = $taxe->getTaux();
  2279.         $a['taxe'] = $taxe;
  2280.         $a['tva']  = $articleCommande->getTva();
  2281.         $a['taxe'] = $taxe;
  2282.         if (is_object($articleCommande->getTaxe())) {
  2283.             $a['taxe'] = $articleCommande->getTaxe();
  2284.         }
  2285.         $a['prixAchatUnitaireAvecFrais'] = $a['prixBase'];
  2286.         //sauvegarde auto
  2287.         if (is_object($articlesCommandeSource_obj) && is_object($articlesCommandeSource_obj->getCommandeFournisseur())) {
  2288.             //modification des donnees pour l'enregistrement
  2289.         } else {
  2290.             $a['id'] = 'tmp-'.time();
  2291.         }
  2292. //echo "JJJJ ".$fournisseur->getLibelle();
  2293.         $colspan                                      14;
  2294.         $tabColonneUser                               = [];
  2295.         $tabColonneUser["id"]                         = 1;
  2296.         $tabColonneUser["reference"]                  = 1;
  2297.         $tabColonneUser["referenceF"]                 = 1;
  2298.         $tabColonneUser["libelle"]                    = 1;
  2299.         $tabColonneUser["libelleF"]                   = 1;
  2300.         $tabColonneUser["qteMini"]                    = 1;
  2301.         $tabColonneUser["qteMaxi"]                    = 1;
  2302.         $tabColonneUser["ralC"]                       = 1;
  2303.         $tabColonneUser["ralF"]                       = 1;
  2304.         $tabColonneUser["qteStockCommande"]           = 1;
  2305.         $tabColonneUser["uniteVente"]                 = 1;
  2306.         $tabColonneUser["qte"]                        = 1;
  2307.         $tabColonneUser["uniteAchat"]                 = 1;
  2308.         $tabColonneUser["prixAchatUnitaire"]          = 1;
  2309.         $tabColonneUser["prixHT"]                     = 1;
  2310.         $tabColonneUser["CC"]                         = 1;
  2311.         $tabColonneUser["qteMiniAchat"]               = 1;
  2312.         $tabColonneUser["conditionnement"]            = 1;
  2313.         $tabColonneUser["txRem"]                      = 1;
  2314.         $tabColonneUser["txRemSuppl"]                 = 1;
  2315.         $tabColonneUser["fraisAnnexes"]               = 1;
  2316.         $tabColonneUser["ecocontribution"]            = 1;
  2317.         $tabColonneUser["montantHt"]                  = 1;
  2318.         $tabColonneUser["totalHT"]                    = 1;
  2319.         $tabColonneUser["pump"]                       = 1;
  2320.         $tabColonneUser["stock"]                      = 1;
  2321.         $tabColonneUser["dateApproximativeReception"] = 1;
  2322.         // TODO CHANGE THIS
  2323.         $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommandeFournisseur";
  2324.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'id') == false) {
  2325.             $colspan--;
  2326.             $tabColonneUser["id"] = 0;
  2327.         }
  2328.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'reference') == false) {
  2329.             $colspan--;
  2330.             $tabColonneUser["reference"] = 0;
  2331.         }
  2332.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'referenceF') == false) {
  2333.             $colspan--;
  2334.             $tabColonneUser["referenceF"] = 0;
  2335.         }
  2336.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelle') == false) {
  2337.             $colspan--;
  2338.             $tabColonneUser["libelle"] = 0;
  2339.         }
  2340.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelleF') == false) {
  2341.             $colspan--;
  2342.             $tabColonneUser["libelleF"] = 0;
  2343.         }
  2344.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMini') == false) {
  2345.             $colspan--;
  2346.             $tabColonneUser["qteMini"] = 0;
  2347.         }
  2348.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMaxi') == false) {
  2349.             $colspan--;
  2350.             $tabColonneUser["qteMaxi"] = 0;
  2351.         }
  2352.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ralC') == false) {
  2353.             $colspan--;
  2354.             $tabColonneUser["ralC"] = 0;
  2355.         }
  2356.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ralF') == false) {
  2357.             $colspan--;
  2358.             $tabColonneUser["ralF"] = 0;
  2359.         }
  2360.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteStockCommande') == false) {
  2361.             $colspan--;
  2362.             $tabColonneUser["qteStockCommande"] = 0;
  2363.         }
  2364.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'uniteVente') == false) {
  2365.             $colspan--;
  2366.             $tabColonneUser["uniteVente"] = 0;
  2367.         }
  2368.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qte') == false) {
  2369.             $colspan--;
  2370.             $tabColonneUser["qte"] = 0;
  2371.         }
  2372.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'uniteAchat') == false) {
  2373.             $colspan--;
  2374.             $tabColonneUser["uniteAchat"] = 0;
  2375.         }
  2376.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixAchatUnitaire') == false) {
  2377.             $colspan--;
  2378.             $tabColonneUser["prixAchatUnitaire"] = 0;
  2379.         }
  2380.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixHT') == false) {
  2381.             $colspan--;
  2382.             $tabColonneUser["prixHT"] = 0;
  2383.         }
  2384.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'CC') == false) {
  2385.             $colspan--;
  2386.             $tabColonneUser["CC"] = 0;
  2387.         }
  2388.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMiniAchat') == false) {
  2389.             $colspan--;
  2390.             $tabColonneUser["qteMiniAchat"] = 0;
  2391.         }
  2392.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'conditionnement') == false) {
  2393.             $colspan--;
  2394.             $tabColonneUser["conditionnement"] = 0;
  2395.         }
  2396.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'txRem') == false) {
  2397.             $colspan--;
  2398.             $tabColonneUser["txRem"] = 0;
  2399.         }
  2400.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'txRemSuppl') == false) {
  2401.             $colspan--;
  2402.             $tabColonneUser["txRemSuppl"] = 0;
  2403.         }
  2404.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'fraisAnnexes') == false) {
  2405.             $colspan--;
  2406.             $tabColonneUser["fraisAnnexes"] = 0;
  2407.         }
  2408.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ecocontribution') == false) {
  2409.             $colspan--;
  2410.             $tabColonneUser["ecocontribution"] = 0;
  2411.         }
  2412.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'montantHt') == false) {
  2413.             $colspan--;
  2414.             $tabColonneUser["montantHt"] = 0;
  2415.         }
  2416.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'totalHT') == false) {
  2417.             $colspan--;
  2418.             $tabColonneUser["totalHT"] = 0;
  2419.         }
  2420.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'pump') == false) {
  2421.             $colspan--;
  2422.             $tabColonneUser["pump"] = 0;
  2423.         }
  2424.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'stock') == false) {
  2425.             $colspan--;
  2426.             $tabColonneUser["stock"] = 0;
  2427.         }
  2428.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'dateApproximativeReception') == false) {
  2429.             $colspan--;
  2430.             $tabColonneUser["dateApproximativeReception"] = 0;
  2431.         }
  2432.         $rendu $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
  2433.             'a'              => $a,
  2434.             'boucle'         => "0",
  2435.             'numeroLigne'    => "0",
  2436.             'fournisseur'    => $fournisseur,
  2437.             'commandeId'     => $commandeId,
  2438.             'tabColonneUser' => $tabColonneUser,
  2439.         ]);
  2440.         return new JsonResponse(['rendu' => $rendu'commentairePonctuel' => $article->getCommentairePonctuel()]);
  2441.     }
  2442.     /**
  2443.      * @Route("/commande-reprise_article/nouveau/{id}", name="dtc_construire_ligne_article_commande_reprise")
  2444.      */
  2445.     public function construireLigneArticleCommandeRepriseAction(Request               $requestArticleCommande $articleCommandeEntityManagerInterface $em,
  2446.                                                                 ColonneTableauService $serviceColonne
  2447.     ) {
  2448.         $conn $em->getConnection();
  2449.         $conn->getConfiguration()->setSQLLogger(null);
  2450.         $article                $articleCommande->getArticle();
  2451.         $quantite               $request->query->get('quantite');
  2452.         $quantiteSurCommande    $request->query->get('quantiteSurCommande');
  2453.         $client_id              $request->query->get('client');
  2454.         $cible                  $request->query->get('cible');
  2455.         $articlesCommandeSource $request->query->get('articlesCommandeSource');
  2456.         $type                   '';
  2457.         $repo_article_commande      $em->getRepository(ArticleCommande::class);
  2458.         $articlesCommandeSource_obj $repo_article_commande->find($articlesCommandeSource);
  2459.         //echo "toto ".$articlesCommandeSource;
  2460.         //exit;
  2461.         $repo_client $em->getRepository(Client::class);
  2462.         if ($article->getDivers() == 1) {
  2463.             $articleTmp = clone $article;
  2464.             $newRef     $articleTmp->getReference().'-'.time();
  2465.             $articleTmp->setReference($newRef);
  2466.             $articleTmp->setParent($article);
  2467.             $articleTmp->setIdImport($article->getIdImport().'-duplique');
  2468.             $em->persist($articleTmp);
  2469.             $em->flush();
  2470.             $article $articleTmp;
  2471.         }
  2472.         $a                          = [];
  2473.         $a['commande']              = "";
  2474.         $a['quantiteDejaPreparee']  = 0;
  2475.         $a['action']                = "insert";
  2476.         $a['position']              = 0;
  2477.         $a['article']               = $article;
  2478.         $a['libelle']               = $articleCommande->getLibelle();
  2479.         $a['libelleSecondaire']     = $articleCommande->getLibelleSecondaire();
  2480.         $a['quantite']              = -$quantite;
  2481.         $a['quantitePrepa']         = -$quantite;
  2482.         $a['fraisPort']             = "0";
  2483.         $a['articleCommandeRepris'] = $articleCommande;
  2484.         $a['transporteur']          = $articleCommande->getTransporteur();
  2485.         $a['estCommentaire']             = $article->getEstCommentaire();
  2486.         $commande                        $articleCommande->getCommande();
  2487.         $date                            date_format($commande->getDate(), 'd/m/Y');
  2488.         $utilisateur                     $commande->getUtilisateur();
  2489.         $a['commentaire']                = "Reprise sur facture n° ".$commande->getReference()." du ".$date.' saisie par '.$utilisateur->getNom().' '.$utilisateur->getPrenom();
  2490.         $a['commentaireSuppl']           = "";
  2491.         $a['commentairePrive']           = "";
  2492.         $a['prixBase']                   = $articleCommande->getPrixBase();
  2493.         $a['prixAchatUnitaireAvecFrais'] = $articleCommande->getPrixAchatUnitaireAvecFrais();
  2494.         $a['remise']                     = $articleCommande->getRemise();
  2495.         $a['remiseSupplementaire']       = $articleCommande->getRemiseSupplementaire();
  2496.         //$a['ecocontribution']= floatval($articleCommande->getEcocontribution());
  2497.         $a['ecocontribution'] = $articleCommande->getEcocontribution();
  2498.         $a['totalHt']         = -($articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite);
  2499.         $a['totalHtV2']       = -($articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite);
  2500.         /*
  2501.         $serviceArticle = $this->get('dtc.article');
  2502.                 $quantiteSurCommande = floatval($quantiteSurCommande) + $a['quantite'];
  2503.         $a['couleur']= $serviceArticle->getCouleurEtatStock($article,$quantiteSurCommande);
  2504.                  *
  2505.                  */
  2506.         $a['couleur'] = '';
  2507.         //sauvegarde auto
  2508.         if (is_object($articlesCommandeSource_obj) && is_object($articlesCommandeSource_obj->getCommande())) {
  2509.             //modification des donnees pour l'enregistrement
  2510.             if (is_object($a['article'])) {
  2511.                 $a['article_id'] = $a['article']->getId();
  2512.             }
  2513.             if (is_object($a['transporteur'])) {
  2514.                 $a['transporteur_id'] = $a['transporteur']->getId();
  2515.             }
  2516.             $a['commande_id']        = $articlesCommandeSource_obj->getCommande()->getId();
  2517.             $a['libelle_secondaire'] = $a['libelleSecondaire'];
  2518.             $a['frais_port']         = $a['fraisPort'];
  2519.             //$a['ral_client'] = $a['ralClient'];
  2520.             $a['ral_client'] = $a['quantite'];
  2521.             //$a['est_commentaire'] = $a['estCommentaire'];
  2522.             $a['commentaire_suppl']     = $a['commentaireSuppl'];
  2523.             $a['commentaire_prive']     = $a['commentairePrive'];
  2524.             $a['remise_supplementaire'] = $a['remiseSupplementaire'];
  2525.             $a['total_ht']              = $a['totalHt'];
  2526.             $a['tva_vente']             = -$articlesCommandeSource_obj->getTvaVente();
  2527.             //$a['prix_base'] = -$a['prixBase'];
  2528.             //$a['total_ht_v2'] = $a['totalHtV2'];
  2529.             $a['quantite_deja_preparee']         = $a['quantiteDejaPreparee'];
  2530.             $a['date']                           = (new \Datetime)->format('Y-m-d H:i:s');
  2531.             $a['prix_base']                      = $a['prixBase'];
  2532.             $a['prix_achat_unitaire_avec_frais'] = $a['prixAchatUnitaireAvecFrais'];
  2533.             if (is_object($a['articleCommandeRepris'])) {
  2534.                 $a['article_commande_repris_id'] = $a['articleCommandeRepris']->getId();
  2535.             }
  2536.             //$a['prix_base'] = $a['prixBase'];
  2537.             unset($a['prixBase']);
  2538.             unset($a['prixAchatUnitaireAvecFrais']);
  2539.             unset($a['articleCommandeRepris']);
  2540.             unset($a['transporteur']);
  2541.             unset($a['article']);
  2542.             unset($a['commande']);
  2543.             unset($a['action']);
  2544.             unset($a['libelleSecondaire']);
  2545.             unset($a['fraisPort']);
  2546.             unset($a['quantitePrepa']);
  2547.             unset($a['ralClient']);
  2548.             unset($a['estCommentaire']);
  2549.             unset($a['commentaireSuppl']);
  2550.             unset($a['commentairePrive']);
  2551.             unset($a['remiseSupplementaire']);
  2552.             unset($a['totalHt']);
  2553.             unset($a['totalHtV2']);
  2554.             unset($a['couleur']);
  2555.             unset($a['quantiteDejaPreparee']);
  2556.             //print_r($a);
  2557.             $conn->update('commerciale__article_commande'$a, ['id' => $articlesCommandeSource_obj->getId()]);
  2558.             //$a['id'] = $conn->lastInsertId();
  2559.             //$a['id'] = $conn->lastInsertId();
  2560.             $a $em->getRepository(ArticleCommande::class)->find($articlesCommandeSource_obj->getId());
  2561.             $em->refresh($a);
  2562.             /*
  2563.             if($countTmp == 0){
  2564.                 $articleCommandeAssocie = $conn->lastInsertId();
  2565.             } else {
  2566.                 //$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
  2567.                 $a->setArticleCommandeAssocie($articleCommandeAssocie);
  2568.             }
  2569.             */
  2570.             //reservation de stock
  2571.             $commande $articlesCommandeSource_obj->getCommande();
  2572.             if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
  2573.                 $type             'commande';
  2574.                 $ralClientArtComm floatval($a->getQuantite());
  2575.                 //$reserve = $ralClientArtComm + floatval($article->getStockReserve());
  2576.                 //$reserve = floatval($article->getStockReserve())-$ralClientArtComm;
  2577.                 if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true) {
  2578.                     $article->setStockReserve(0);
  2579.                     if ($article->getProduitInterne() == true) {
  2580.                         $variation floatval($a->getQuantite());
  2581.                         //    $articleService->modifierStockReserveComposants($article, $variation);
  2582.                     }
  2583.                 } elseif (floatval($a->getQuantite()) != 0) {
  2584.                     //$article->setStockReserve($reserve);
  2585.                     //$em->persist($article);
  2586.                 }
  2587.                 $em->flush();
  2588.             }
  2589.         } else {
  2590.             $a['id'] = 'tmp-'.time();
  2591.         }
  2592.         // TODO CHANGE THIS
  2593.         $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommande";
  2594.         $type               $cible;
  2595.         if ($cible == "comptoir") {
  2596.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormComptoir";
  2597.         }
  2598.         if ($cible == "bp") {
  2599.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormBP";
  2600.         }
  2601.         if ($cible == "devis") {
  2602.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormDevis";
  2603.         }
  2604.         if ($cible == "") {
  2605.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommande";
  2606.             $type               "commande";
  2607.         }
  2608.         $colonneUtilisateur2 $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
  2609.         $tabColonneUser      $colonneUtilisateur2['tabColonneUser'];
  2610.         $colspan             $colonneUtilisateur2['colspan'];
  2611.         $variables = ['a' => $a'boucle' => "0"'numeroLigne' => "0"'reprise' => true'tabColonneUser' => $tabColonneUser'colspan' => $colspan'type' => $type];
  2612.         if ($client_id != '') {
  2613.             $client $repo_client->find($client_id);
  2614.             if (is_object($client)) {
  2615.                 $variables['client'] = $client;
  2616.             }
  2617.         }
  2618.         //echo $cible."azertyui";
  2619.         if ($cible == "or") {
  2620.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig'$variables);
  2621.         } elseif ($cible == "regularisation") {
  2622.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig'$variables);
  2623.         } else {
  2624.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig'$variables);
  2625.         }
  2626.         $commentairePonctuel $article->getCommentairePonctuel();
  2627.         if ($article->getArretGamme()) {
  2628.             $commentairePonctuel .= "<div>Attention article en arrêt de gamme</div>";
  2629.         }
  2630.         return new JsonResponse(['rendu' => $rendu'id' => $article->getId(), 'commentairePonctuel' => $commentairePonctuel'couleur' => '']);
  2631.     }
  2632.     public function _____construireLigneArticleCommandeRepriseAction(Request             $requestArticleCommande $articleCommandeEntityManagerInterface $em,
  2633.                                                                      TranslatorInterface $translatorValidatorInterface $validatorColonneTableauService $serviceColonne
  2634.     ) {
  2635.         $conn $em->getConnection();
  2636.         $conn->getConfiguration()->setSQLLogger(null);
  2637.         $article             $articleCommande->getArticle();
  2638.         $quantite            $request->query->get('quantite');
  2639.         $quantiteSurCommande $request->query->get('quantiteSurCommande');
  2640.         $client_id           $request->query->get('client');
  2641.         $cible               $request->query->get('cible');
  2642.         $type                '';
  2643.         $repo_client $em->getRepository(Client::class);
  2644.         if ($article->getDivers() == 1) {
  2645.             $articleTmp = clone $article;
  2646.             $newRef     $articleTmp->getReference().'-'.time();
  2647.             $articleTmp->setReference($newRef);
  2648.             $articleTmp->setParent($article);
  2649.             $articleTmp->setIdImport($article->getIdImport().'-duplique');
  2650.             $em->persist($articleTmp);
  2651.             $em->flush();
  2652.             $article $articleTmp;
  2653.         }
  2654.         $a                          = [];
  2655.         $a['commande']              = "";
  2656.         $a['quantiteDejaPreparee']  = 0;
  2657.         $a['action']                = "insert";
  2658.         $a['position']              = 0;
  2659.         $a['article']               = $article;
  2660.         $a['libelle']               = $articleCommande->getLibelle();
  2661.         $a['libelleSecondaire']     = $articleCommande->getLibelleSecondaire();
  2662.         $a['quantite']              = -$quantite;
  2663.         $a['quantitePrepa']         = -$quantite;
  2664.         $a['fraisPort']             = "0";
  2665.         $a['articleCommandeRepris'] = $articleCommande;
  2666.         $a['transporteur']          = $articleCommande->getTransporteur();
  2667.         $a['estCommentaire']       = $article->getEstCommentaire();
  2668.         $commande                  $articleCommande->getCommande();
  2669.         $date                      date_format($commande->getDate(), 'd/m/Y');
  2670.         $utilisateur               $commande->getUtilisateur();
  2671.         $a['commentaire']          = "Reprise sur facture n° ".$commande->getReference()." du ".$date.' saisie par '.$utilisateur->getNom().' '.$utilisateur->getPrenom();
  2672.         $a['commentaireSuppl']     = "";
  2673.         $a['commentairePrive']     = "";
  2674.         $a['prixBase']             = $articleCommande->getPrixBase();
  2675.         $a['remise']               = $articleCommande->getRemise();
  2676.         $a['remiseSupplementaire'] = $articleCommande->getRemiseSupplementaire();
  2677.         //$a['ecocontribution']= floatval($articleCommande->getEcocontribution());
  2678.         $a['ecocontribution'] = 0;
  2679.         $a['totalHt']         = $articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite;
  2680.         $a['totalHtV2']       = $articleCommande->getTotalHt() / $articleCommande->getQuantite() * $quantite;
  2681.         /*
  2682.         $serviceArticle = $this->get('dtc.article');
  2683.                 $quantiteSurCommande = floatval($quantiteSurCommande) + $a['quantite'];
  2684.         $a['couleur']= $serviceArticle->getCouleurEtatStock($article,$quantiteSurCommande);
  2685.                  *
  2686.                  */
  2687.         $a['couleur'] = '';
  2688.         //sauvegarde auto
  2689.         if (is_object($articleCommande->getCommande())) {
  2690.             //modification des donnees pour l'enregistrement
  2691.             if (is_object($a['article'])) {
  2692.                 $a['article_id'] = $a['article']->getId();
  2693.             }
  2694.             if (is_object($a['transporteur'])) {
  2695.                 $a['transporteur_id'] = $a['transporteur']->getId();
  2696.             }
  2697.             $a['commande_id']        = $articleCommande->getCommande()->getId();
  2698.             $a['libelle_secondaire'] = $a['libelleSecondaire'];
  2699.             $a['frais_port']         = $a['fraisPort'];
  2700.             //$a['ral_client'] = $a['ralClient'];
  2701.             $a['ral_client'] = $a['quantite'];
  2702.             //$a['est_commentaire'] = $a['estCommentaire'];
  2703.             $a['commentaire_suppl']     = $a['commentaireSuppl'];
  2704.             $a['commentaire_prive']     = $a['commentairePrive'];
  2705.             $a['remise_supplementaire'] = $a['remiseSupplementaire'];
  2706.             $a['total_ht']              = $a['totalHt'];
  2707.             //$a['total_ht_v2'] = $a['totalHtV2'];
  2708.             $a['quantite_deja_preparee'] = $a['quantiteDejaPreparee'];
  2709.             $a['date']                   = (new \Datetime)->format('Y-m-d H:i:s');
  2710.             if (is_object($a['articleCommandeRepris'])) {
  2711.                 $a['article_commande_repris_id'] = $a['articleCommandeRepris']->getId();
  2712.             }
  2713.             $a['prix_base'] = $a['prixBase'];
  2714.             unset($a['prixBase']);
  2715.             unset($a['articleCommandeRepris']);
  2716.             unset($a['transporteur']);
  2717.             unset($a['article']);
  2718.             unset($a['commande']);
  2719.             unset($a['action']);
  2720.             unset($a['libelleSecondaire']);
  2721.             unset($a['fraisPort']);
  2722.             unset($a['quantitePrepa']);
  2723.             unset($a['ralClient']);
  2724.             unset($a['estCommentaire']);
  2725.             unset($a['commentaireSuppl']);
  2726.             unset($a['commentairePrive']);
  2727.             unset($a['remiseSupplementaire']);
  2728.             unset($a['totalHt']);
  2729.             unset($a['totalHtV2']);
  2730.             unset($a['couleur']);
  2731.             unset($a['quantiteDejaPreparee']);
  2732.             $conn->update('commerciale__article_commande'$a, ['id' => $articleCommande->getId()]);
  2733.             //$a['id'] = $conn->lastInsertId();
  2734.             $a $em->getRepository(ArticleCommande::class)->find($articleCommande->getId());
  2735.             /*
  2736.             if($countTmp == 0){
  2737.                 $articleCommandeAssocie = $conn->lastInsertId();
  2738.             } else {
  2739.                 //$a['articleCommandeAssocie']['id'] = $idArticleCommandeTmp;
  2740.                 $a->setArticleCommandeAssocie($articleCommandeAssocie);
  2741.             }
  2742.             */
  2743.             //reservation de stock
  2744.             if (is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::COMMANDE])) {
  2745.                 $type             'commande';
  2746.                 $ralClientArtComm floatval($a->getQuantite());
  2747.                 $reserve          $ralClientArtComm floatval($article->getStockReserve());
  2748.                 if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true) {
  2749.                     $article->setStockReserve(0);
  2750.                     if ($article->getProduitInterne() == true) {
  2751.                         $variation floatval($a->getQuantite());
  2752.                         $articleService->modifierStockReserveComposants($article$variation);
  2753.                     }
  2754.                 } elseif (floatval($a->getQuantite()) != 0) {
  2755.                     $article->setStockReserve($reserve);
  2756.                     $em->persist($article);
  2757.                 }
  2758.                 $em->flush();
  2759.             }
  2760.         } else {
  2761.             $a['id'] = 'tmp-'.time();
  2762.         }
  2763.         // TODO change this
  2764.         $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommande";
  2765.         $type               $cible;
  2766.         if ($cible == "comptoir") {
  2767.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormComptoir";
  2768.         }
  2769.         if ($cible == "bp") {
  2770.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormBP";
  2771.         }
  2772.         if ($cible == "devis") {
  2773.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormDevis";
  2774.         }
  2775.         if ($cible == "") {
  2776.             $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommande";
  2777.             $type               "commande";
  2778.         }
  2779.         $colonneUtilisateur2 $serviceColonne->getColonneUtilisateur2($colonneUtilisateur);
  2780.         $tabColonneUser      $colonneUtilisateur2['tabColonneUser'];
  2781.         $colspan             $colonneUtilisateur2['colspan'];
  2782.         $variables = ['a' => $a'boucle' => "0"'numeroLigne' => "0"'reprise' => true'tabColonneUser' => $tabColonneUser'colspan' => $colspan'type' => $type];
  2783.         if ($client_id != '') {
  2784.             $client $repo_client->find($client_id);
  2785.             if (is_object($client)) {
  2786.                 $variables['client'] = $client;
  2787.             }
  2788.         }
  2789.         //echo $cible."azertyui";
  2790.         if ($cible == "or") {
  2791.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_or_tr.html.twig'$variables);
  2792.         } elseif ($cible == "regularisation") {
  2793.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_regulation_tr.html.twig'$variables);
  2794.         } else {
  2795.             $rendu $this->renderView('GestionComerciale/ArticleCommande/template_tr.html.twig'$variables);
  2796.         }
  2797.         $commentairePonctuel $article->getCommentairePonctuel();
  2798.         if ($article->getArretGamme()) {
  2799.             $commentairePonctuel .= "<div>Attention article en arrêt de gamme</div>";
  2800.         }
  2801.         return new JsonResponse(
  2802.             ['rendu' => $rendu'id' => $article->getId(), 'commentairePonctuel' => $commentairePonctuel'couleur' => '']
  2803.         );
  2804.     }
  2805.     /**
  2806.      * @Route("/commande-article/recharger/{id}/{quantite}", name="dtc_recharger_ligne_article_commande")
  2807.      */
  2808.     public function rechargerLigneArticleCommandeAction(Request        $requestArticle $article$quantiteEntityManagerInterface $em,
  2809.                                                         ArticleService $serviceArticle
  2810.     ) {
  2811.         $fournisseur $request->query->get('fournisseur');
  2812.         $ac          $request->query->get('idArticleCommande');
  2813.         $id_client   $request->query->get('id_client');
  2814.         $id_adresse  $request->query->get('id_adresse');
  2815.         $prix        '';
  2816.         $acObjet     '';
  2817.         $client      "";
  2818.         $adresse     "";
  2819.         //
  2820.         if ($fournisseur != '' && $fournisseur != "undefined") {
  2821.             $couleur $serviceArticle->getCouleurQteF($article$quantite$fournisseur);
  2822.         } else {
  2823.             $acObjet $em->getRepository(ArticleCommande::class)->find($ac);
  2824.             if (is_object($acObjet)) {
  2825.                 $commande $acObjet->getCommande();
  2826.                 $couleur  $serviceArticle->getCouleurEtatStock($article$quantite$commande);
  2827.             } else {
  2828.                 $couleur $serviceArticle->getCouleurEtatStock($article$quantite);
  2829.             }
  2830.             if ($id_client != "") {
  2831.                 $client $em->getRepository(Client::class)->find($id_client);
  2832.             }
  2833.             if ($id_adresse != "") {
  2834.                 $adresse $em->getRepository(Adresse::class)->find($id_adresse);
  2835.                 if ( ! is_object($client) && is_object($adresse)) {
  2836.                     $client $adresse->getClient();
  2837.                 }
  2838.             }
  2839.         }
  2840.         $prix  $serviceArticle->getPrixEncoursConditionVente($article$acObjet$client$quantite$adresse);
  2841.         $rendu "";
  2842.         return new JsonResponse(['prix' => floatVal($prix), 'rendu' => $rendu'couleur' => $couleur'tutu' => $couleur]);
  2843.     }
  2844.     /**
  2845.      * @Route("/commande-article/recharger-prix/{id}/{client}", name="dtc_recharger_prix_article_commande")
  2846.      */
  2847.     public function rechargerPrixArticleCommandeAction(Request $requestArticle $article$client ''EntityManagerInterface $emArticleService $serviceArticle)
  2848.     {
  2849.         $montantTotal $request->query->get('montantTotal');
  2850.         $prix         $request->query->get('prix');
  2851.         $adresse      $request->query->get('adresse');
  2852.         $quantite     $request->query->get('quantite');
  2853.         $quantite     1;
  2854.         if ($client != "") {
  2855.             $client $em->getRepository(Client::class)->find($client);
  2856.         }
  2857.         if ($adresse != "") {
  2858.             $adresse $em->getRepository(Adresse::class)->find($adresse);
  2859.         }
  2860.         $a                         = [];
  2861.         $a['quantiteDejaPreparee'] = 0;
  2862.         $a['article']              = $article;
  2863.         $a['libelle']              = $article->getLibelle();
  2864.         $a['libelleSecondaire']    = $article->getLibelleSecondaire();
  2865.         $a['commentaire']          = "";
  2866.         $a['remise']               = "0";
  2867.         $a['totalHt']              = $article->getPrixVente();
  2868.         $a['totalHtV2']            = $article->getPrixVente();
  2869.         $remise $serviceArticle->getRemiseCategorieClient($a$client$montantTotal$article->getPrixVente());
  2870.         //public function          getPrixEncours( $article,$articleCommande = '',$client, $reprise = false,$quantite="",$adresse="",$enregAuto =false) {
  2871.         $prix $serviceArticle->getPrixEncours($article''$clientfalse$quantite$adressefalse);
  2872.         return new JsonResponse(['prix' => $prix'remise' => $remise]);
  2873.     }
  2874.     /**
  2875.      * @Route("/commande-article/achat/commentaire/", name="dtc_construire_ligne_commentaire_commande_fournisseur")
  2876.      */
  2877.     public function construireLigneCommentaireCommandeFournisseurAction(Request $requestEntityManagerInterface $emArticleService $serviceArticle)
  2878.     {
  2879.         $repo_article $em->getRepository(Article::class);
  2880.         //$article = $repo_article->findOneBy(array("est_commentaire"=>1));
  2881.         $article $repo_article->find($this->getParameter('article_commentaire'));
  2882.         $repoFournisseur            $em->getRepository(Fournisseur::class);
  2883.         $fournisseur                $request->query->get('fournisseur');
  2884.         $commandeId                 $request->query->get('commandeId');
  2885.         $quantite                   $request->query->get('quantite');
  2886.         $a                          = [];
  2887.         $a['id']                    = 'tmp-'.time();
  2888.         $a['quantiteDejaPreparee']  = 0;
  2889.         $a['articleCommandeRepris'] = "";
  2890.         $a['position']              = "";
  2891.         $a['article']               = $article;
  2892.         $a['libelle']               = $article->getLibelle();
  2893.         $a['quantite']              = "1";
  2894.         $a['ral']                   = "1";
  2895.         $a['commentaireSuppl']      = "";
  2896.         $a['commentairePrive']      = "";
  2897.         $a['estCommentaire']        = $article->getEstCommentaire();
  2898.         $a['commentaire']           = "";
  2899.         $a['remise']                = "0";
  2900.         $a['remiseSupplementaire']  = "0";
  2901.         //$a['ecocontribution']= floatval($article->getEcocontribution());
  2902.         $a['ecocontribution'] = 0;
  2903.         $a['totalHt']         = $article->getPrixBase();
  2904.         $a['prixBase']        = $article->getPrixBase();
  2905.         //recuperer la condition d'achat par défaut
  2906.         $repoConditionsAchat $em->getRepository(ConditionAchat::class);
  2907.         //$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
  2908.         if ($fournisseur != '') {
  2909.             $condition $repoConditionsAchat->findOneBy([
  2910.                                                              'article'     => $article->getId(),
  2911.                                                              'fournisseur' => $fournisseur,
  2912.                                                              'defaut'      => 1,
  2913.                                                          ]);
  2914.         }
  2915.         if ( ! isset($condition) || ! is_object($condition)) {
  2916.             $condition $repoConditionsAchat->findOneBy([
  2917.                                                              'article'     => $article->getId(),
  2918.                                                              'fournisseur' => $fournisseur,
  2919.                                                          ]);
  2920.         }
  2921.         /*
  2922.                 if(count($condition) > 0)
  2923.                     $condition = $condition[0];
  2924.                 else
  2925.                     $condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
  2926.                  *
  2927.                  */
  2928.         if (is_object($condition)) {
  2929.             if ($condition->getTauxRemise() != '') {
  2930.                 $a['remise'] = $condition->getTauxRemise();
  2931.             }
  2932.             if ($condition->getTauxRemiseSupplementaire() != '') {
  2933.                 $a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
  2934.             }
  2935.             if ($condition->getPrixAchatBrut() != '') {
  2936.                 //$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
  2937.                 $a['prixBase'] = $condition->getPrixAchatBrut();
  2938.             }
  2939.             if ($condition->getLibelle() != '') {
  2940.                 $a['libelle'] = $condition->getLibelle();
  2941.             }
  2942.             if ($quantite != '' && is_numeric($quantite)) {
  2943.                 $a['quantite'] = $quantite;
  2944.             } elseif ($condition->getQuantite() != '') {
  2945.                 $a['quantite'] = $condition->getQuantite();
  2946.             }
  2947.             $a['conditionAchat'] = $condition;
  2948.             $a['fraisAnnexes']   = $condition->getFraisAnnexes();
  2949.         }
  2950.         $a['couleur'] = $serviceArticle->getCouleurEtatStock($article$a['quantite']);
  2951.         $fournisseur $repoFournisseur->find($fournisseur);
  2952.         $rendu $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
  2953.             'a'           => $a,
  2954.             'boucle'      => "0",
  2955.             'numeroLigne' => "0",
  2956.             'fournisseur' => $fournisseur,
  2957.             'commandeId'  => $commandeId,
  2958.         ]);
  2959.         return new JsonResponse(['rendu' => $rendu'commentairePonctuel' => $article->getCommentairePonctuel()]);
  2960.     }
  2961.     /**
  2962.      * @Route("/commande-article/achat/nouveau/{id}", name="dtc_construire_ligne_article_commande_fournisseur")
  2963.      */
  2964.     public function construireLigneArticleCommandeFournisseurAction(Request        $requestArticle $articleEntityManagerInterface $emColonneTableauService $serviceColonne,
  2965.                                                                     ArticleService $articleServiceDateService $dateServiceFournisseurService $fournisseurService
  2966.     ) {
  2967.         $repoFournisseur $em->getRepository(Fournisseur::class);
  2968.         $repo_taxe       $em->getRepository(Taxe::class);
  2969.         $fournisseur     $request->query->get('fournisseur');
  2970.         $commandeId      $request->query->get('commandeId');
  2971.         $quantite        $request->query->get('quantite');
  2972.         $repo_article    $em->getRepository(Article::class);
  2973.         $colspan                                      14;
  2974.         $tabColonneUser                               = [];
  2975.         $tabColonneUser["id"]                         = 1;
  2976.         $tabColonneUser["reference"]                  = 1;
  2977.         $tabColonneUser["referenceF"]                 = 1;
  2978.         $tabColonneUser["libelle"]                    = 1;
  2979.         $tabColonneUser["libelleF"]                   = 1;
  2980.         $tabColonneUser["qteMini"]                    = 1;
  2981.         $tabColonneUser["qteMaxi"]                    = 1;
  2982.         $tabColonneUser["ralC"]                       = 1;
  2983.         $tabColonneUser["ralF"]                       = 1;
  2984.         $tabColonneUser["qteStockCommande"]           = 1;
  2985.         $tabColonneUser["uniteVente"]                 = 1;
  2986.         $tabColonneUser["qte"]                        = 1;
  2987.         $tabColonneUser["uniteAchat"]                 = 1;
  2988.         $tabColonneUser["prixAchatUnitaire"]          = 1;
  2989.         $tabColonneUser["prixHT"]                     = 1;
  2990.         $tabColonneUser["CC"]                         = 1;
  2991.         $tabColonneUser["qteMiniAchat"]               = 1;
  2992.         $tabColonneUser["conditionnement"]            = 1;
  2993.         $tabColonneUser["txRem"]                      = 1;
  2994.         $tabColonneUser["txRemSuppl"]                 = 1;
  2995.         $tabColonneUser["fraisAnnexes"]               = 1;
  2996.         $tabColonneUser["ecocontribution"]            = 1;
  2997.         $tabColonneUser["montantHt"]                  = 1;
  2998.         $tabColonneUser["totalHT"]                    = 1;
  2999.         $tabColonneUser["pump"]                       = 1;
  3000.         $tabColonneUser["stock"]                      = 1;
  3001.         $tabColonneUser["dateApproximativeReception"] = 1;
  3002.         $tabColonneUser["emplacement"]                = 1;
  3003.         // TODO CHANGE THIS
  3004.         $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommandeFournisseur";
  3005.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'id') == false) {
  3006.             $colspan--;
  3007.             $tabColonneUser["id"] = 0;
  3008.         }
  3009.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'reference') == false) {
  3010.             $colspan--;
  3011.             $tabColonneUser["reference"] = 0;
  3012.         }
  3013.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'referenceF') == false) {
  3014.             $colspan--;
  3015.             $tabColonneUser["referenceF"] = 0;
  3016.         }
  3017.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelle') == false) {
  3018.             $colspan--;
  3019.             $tabColonneUser["libelle"] = 0;
  3020.         }
  3021.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelleF') == false) {
  3022.             $colspan--;
  3023.             $tabColonneUser["libelleF"] = 0;
  3024.         }
  3025.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMini') == false) {
  3026.             $colspan--;
  3027.             $tabColonneUser["qteMini"] = 0;
  3028.         }
  3029.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMaxi') == false) {
  3030.             $colspan--;
  3031.             $tabColonneUser["qteMaxi"] = 0;
  3032.         }
  3033.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ralC') == false) {
  3034.             $colspan--;
  3035.             $tabColonneUser["ralC"] = 0;
  3036.         }
  3037.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ralF') == false) {
  3038.             $colspan--;
  3039.             $tabColonneUser["ralF"] = 0;
  3040.         }
  3041.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteStockCommande') == false) {
  3042.             $colspan--;
  3043.             $tabColonneUser["qteStockCommande"] = 0;
  3044.         }
  3045.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'uniteVente') == false) {
  3046.             $colspan--;
  3047.             $tabColonneUser["uniteVente"] = 0;
  3048.         }
  3049.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qte') == false) {
  3050.             $colspan--;
  3051.             $tabColonneUser["qte"] = 0;
  3052.         }
  3053.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'uniteAchat') == false) {
  3054.             $colspan--;
  3055.             $tabColonneUser["uniteAchat"] = 0;
  3056.         }
  3057.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixAchatUnitaire') == false) {
  3058.             $colspan--;
  3059.             $tabColonneUser["prixAchatUnitaire"] = 0;
  3060.         }
  3061.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixHT') == false) {
  3062.             $colspan--;
  3063.             $tabColonneUser["prixHT"] = 0;
  3064.         }
  3065.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'CC') == false) {
  3066.             $colspan--;
  3067.             $tabColonneUser["CC"] = 0;
  3068.         }
  3069.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMiniAchat') == false) {
  3070.             $colspan--;
  3071.             $tabColonneUser["qteMiniAchat"] = 0;
  3072.         }
  3073.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'conditionnement') == false) {
  3074.             $colspan--;
  3075.             $tabColonneUser["conditionnement"] = 0;
  3076.         }
  3077.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'txRem') == false) {
  3078.             $colspan--;
  3079.             $tabColonneUser["txRem"] = 0;
  3080.         }
  3081.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'txRemSuppl') == false) {
  3082.             $colspan--;
  3083.             $tabColonneUser["txRemSuppl"] = 0;
  3084.         }
  3085.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'fraisAnnexes') == false) {
  3086.             $colspan--;
  3087.             $tabColonneUser["fraisAnnexes"] = 0;
  3088.         }
  3089.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ecocontribution') == false) {
  3090.             $colspan--;
  3091.             $tabColonneUser["ecocontribution"] = 0;
  3092.         }
  3093.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'montantHt') == false) {
  3094.             $colspan--;
  3095.             $tabColonneUser["montantHt"] = 0;
  3096.         }
  3097.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'totalHT') == false) {
  3098.             $colspan--;
  3099.             $tabColonneUser["totalHT"] = 0;
  3100.         }
  3101.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'pump') == false) {
  3102.             $colspan--;
  3103.             $tabColonneUser["pump"] = 0;
  3104.         }
  3105.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'stock') == false) {
  3106.             $colspan--;
  3107.             $tabColonneUser["stock"] = 0;
  3108.         }
  3109.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'dateApproximativeReception') == false) {
  3110.             $colspan--;
  3111.             $tabColonneUser["dateApproximativeReception"] = 0;
  3112.         }
  3113.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'emplacement') == false) {
  3114.             $colspan--;
  3115.             $tabColonneUser["emplacement"] = 0;
  3116.         }
  3117.         $conn $em->getConnection();
  3118.         $conn->getConfiguration()->setSQLLogger(null);
  3119.         $rendu               '';
  3120.         $commentairePonctuel '';
  3121.         $articles            = [$article];
  3122.         if (is_object($article->getArticleEnconsigne())) {
  3123.             $articles[] = $article->getArticleEnconsigne();
  3124.         }
  3125.         foreach ($articles as $article) {
  3126.             if ($article->getDivers() == && ! is_object($article->getParent())) {
  3127.                 /*
  3128.                 $articleTmp = clone $article;
  3129.                 $newRef = $articleTmp->getReference().'-'.time();
  3130.                 $articleTmp->setReference($newRef);
  3131.                 $articleTmp->setParent($article);
  3132.                 $articleTmp->setIdImport($article->getIdImport().'-duplique');
  3133.                 $em->persist($articleTmp);
  3134.                 $em->flush();
  3135.                 $article = $articleTmp;
  3136.                 */
  3137.                 $referenceDivers                    $articleService->getReferenceDivers($article);
  3138.                 $tableau_donnee                     = [];
  3139.                 $tableau_donnee["reference"]        = $article->getReference()."-".$referenceDivers['reference'];
  3140.                 $tableau_donnee["numero_reference"] = $referenceDivers['numero_reference'];
  3141.                 $tableau_donnee["ral_fournisseur"]  = "0";
  3142.                 $tableau_donnee["parent_id"]        = $article->getId();
  3143.                 $tableau_donnee["libelle"]          = $article->getLibelle();
  3144.                 $tableau_donnee["reference_client"]      = $article->getReferenceClient();
  3145.                 $tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
  3146.                 $tableau_donnee["prix_base"]             = $article->getPrixBase();
  3147.                 $dateTmp                                 = new \Datetime;
  3148.                 $tableau_donnee["date"]                  = $dateTmp->format("Y-m-d H:i:s");
  3149.                 if ($article->getDateMaj() != "") {
  3150.                     $tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
  3151.                 }
  3152.                 if ($article->getDateMajPrix() != "") {
  3153.                     $tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
  3154.                 }
  3155.                 if ($article->getDateSuppression() != "") {
  3156.                     $tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
  3157.                 }
  3158.                 if (is_object($article->getMarque())) {
  3159.                     $tableau_donnee["marque_id"] = $article->getMarque()->getId();
  3160.                 }
  3161.                 $tableau_donnee["description"]        = $article->getDescription();
  3162.                 $tableau_donnee["description_courte"] = $article->getDescriptionCourte();
  3163.                 $tableau_donnee["stock"]              = "0";
  3164.                 if ($article->getStatut() === true) {
  3165.                     $tableau_donnee["statut"] = 1;
  3166.                 } else {
  3167.                     $tableau_donnee["statut"] = 0;
  3168.                 }
  3169.                 $tableau_donnee["largeur"]    = $article->getLargeur();
  3170.                 $tableau_donnee["profondeur"] = $article->getProfondeur();
  3171.                 $tableau_donnee["hauteur"]    = $article->getHauteur();
  3172.                 $tableau_donnee["poids"]      = $article->getPoids();
  3173.                 if ($article->getAConsigner()) {
  3174.                     $tableau_donnee["a_consigner"] = 1;
  3175.                 } else {
  3176.                     $tableau_donnee["a_consigner"] = 0;
  3177.                 }
  3178.                 if ($article->getStockAuto()) {
  3179.                     $tableau_donnee["stock_auto"] = 1;
  3180.                 } else {
  3181.                     $tableau_donnee["stock_auto"] = 0;
  3182.                 }
  3183.                 if ($article->getArretGamme() === true) {
  3184.                     $tableau_donnee["arret_gamme"] = 1;
  3185.                 } else {
  3186.                     $tableau_donnee["arret_gamme"] = 0;
  3187.                 }
  3188.                 if (is_object($article->getUtilisateur())) {
  3189.                     $tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
  3190.                 }
  3191.                 if (is_object($article->getRegleTaxe())) {
  3192.                     $tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  3193.                 }
  3194.                 $tableau_donnee["remise_max"]            = $article->getRemiseMax();
  3195.                 $tableau_donnee["type_remise_max"]       = $article->getTypeRemiseMax();
  3196.                 $tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  3197.                 $tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  3198.                 if (is_object($article->getNiveauUn())) {
  3199.                     $tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
  3200.                 }
  3201.                 if (is_object($article->getNiveauDeux())) {
  3202.                     $tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
  3203.                 }
  3204.                 if (is_object($article->getNiveauTrois())) {
  3205.                     $tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
  3206.                 }
  3207.                 if (is_object($article->getNiveauQuatre())) {
  3208.                     $tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
  3209.                 }
  3210.                 $tableau_donnee["pump"]        = $article->getCpump();
  3211.                 $tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
  3212.                 if ($article->getVirtuel()) {
  3213.                     $tableau_donnee["virtuel"] = 1;
  3214.                 } else {
  3215.                     $tableau_donnee["virtuel"] = 0;
  3216.                 }
  3217.                 //$tableau_donnee["prix_vente"]=$article->getLibelle();
  3218.                 $tableau_donnee["prix_vente"]      = 0;
  3219.                 $tableau_donnee["taux_marge"]      = $article->getTauxMarge();
  3220.                 $tableau_donnee["marge"]           = $article->getMarge();
  3221.                 $tableau_donnee["marge_reelle"]    = $article->getMargeReelle();
  3222.                 $tableau_donnee["ecotaxe"]         = $article->getEcotaxe();
  3223.                 $tableau_donnee["conditionnement"] = $article->getConditionnement();
  3224.                 $tableau_donnee["stock_reserve"]   = $article->getStockReserve();
  3225.                 if (is_object($article->getFournisseurDefaut())) {
  3226.                     $tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  3227.                 }
  3228.                 $tableau_donnee["ral_fournisseur"] = "0";
  3229.                 $tableau_donnee["id_import"]       = "";
  3230.                 $tableau_donnee["donnees_import"]  = "";
  3231.                 if ($article->getMajPrix()) {
  3232.                     $tableau_donnee["maj_prix"] = 1;
  3233.                 } else {
  3234.                     $tableau_donnee["maj_prix"] = 0;
  3235.                 }
  3236.                 if (is_object($article->getUniteMesure())) {
  3237.                     $tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
  3238.                 }
  3239.                 if ($article->getAfficherComposantPdfInterne()) {
  3240.                     $tableau_donnee["afficher_composant_pdf_interne"] = 1;
  3241.                 } else {
  3242.                     $tableau_donnee["afficher_composant_pdf_interne"] = 0;
  3243.                 }
  3244.                 if ($article->getAfficherComposantPdfExterne()) {
  3245.                     $tableau_donnee["afficher_composant_pdf_externe"] = 1;
  3246.                 } else {
  3247.                     $tableau_donnee["afficher_composant_pdf_externe"] = 0;
  3248.                 }
  3249.                 if (is_object($article->getCategorieRemiseArticle())) {
  3250.                     $tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  3251.                 }
  3252.                 $tableau_donnee["temporaire"]               = $article->getTemporaire();
  3253.                 $tableau_donnee["libelle_secondaire"]       = $article->getLibelleSecondaire();
  3254.                 $tableau_donnee["a_commander"]              = "1";
  3255.                 $tableau_donnee["a_fabriquer"]              = "0";
  3256.                 $tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  3257.                 $tableau_donnee["quantite_conseillee"]      = $article->getQuantiteConseillee();
  3258.                 $tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
  3259.                 if ($article->getArchive() === true) {
  3260.                     $tableau_donnee["archive"] = 1;
  3261.                 } else {
  3262.                     $tableau_donnee["archive"] = 0;
  3263.                 }
  3264.                 $tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  3265.                 $tableau_donnee["nom_web"]                      = $article->getNomWeb();
  3266.                 $tableau_donnee["reference_web"]                = $article->getReferenceWeb();
  3267.                 $tableau_donnee["reference_fournisseur_web"]    = $article->getReferenceFournisseurWeb();
  3268.                 $tableau_donnee["description_web"]              = $article->getDescriptionWeb();
  3269.                 $tableau_donnee["resume_web"]                   = $article->getResumeWeb();
  3270.                 $tableau_donnee["frais_ports_texte_web"]        = $article->getFraisPortsTexteWeb();
  3271.                 $tableau_donnee["message_qd_en_stock"]          = $article->getMessageQdEnStockWeb();
  3272.                 if (is_object($article->getArticleEnconsigne())) {
  3273.                     $tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
  3274.                 }
  3275.                 $tableau_donnee["reference_appel_1"]  = $article->getReferenceAppel1();
  3276.                 $tableau_donnee["reference_appel_2"]  = $article->getReferenceAppel2();
  3277.                 $tableau_donnee["reference_appel_3"]  = $article->getReferenceAppel3();
  3278.                 $tableau_donnee["reference_appel_4"]  = $article->getReferenceAppel4();
  3279.                 $tableau_donnee["reference_appel_5"]  = $article->getReferenceAppel5();
  3280.                 $tableau_donnee["reference_appel_6"]  = $article->getReferenceAppel6();
  3281.                 $tableau_donnee["reference_appel_7"]  = $article->getReferenceAppel7();
  3282.                 $tableau_donnee["reference_appel_8"]  = $article->getReferenceAppel8();
  3283.                 $tableau_donnee["reference_appel_9"]  = $article->getReferenceAppel9();
  3284.                 $tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
  3285.                 $tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
  3286.                 if ($article->getMainOeuvre() === true) {
  3287.                     $tableau_donnee["main_oeuvre"] = 1;
  3288.                 } else {
  3289.                     $tableau_donnee["main_oeuvre"] = 0;
  3290.                 }
  3291.                 $tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
  3292.                 if (is_object($article->getType())) {
  3293.                     $tableau_donnee["type_id"] = $article->getType()->getId();
  3294.                 }
  3295.                 if (is_object($article->getFamilleCompta())) {
  3296.                     $tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
  3297.                 }
  3298.                 if ($article->getPrestation()) {
  3299.                     $tableau_donnee["prestation"] = 1;
  3300.                 } else {
  3301.                     $tableau_donnee["prestation"] = 0;
  3302.                 }
  3303.                 if ($article->getNonStocke() === true) {
  3304.                     $tableau_donnee["non_stocke"] = 1;
  3305.                 } else {
  3306.                     $tableau_donnee["non_stocke"] = 0;
  3307.                 }
  3308.                 if ($article->getNonCommandable()) {
  3309.                     $tableau_donnee["non_commandable"] = 1;
  3310.                 } else {
  3311.                     $tableau_donnee["non_commandable"] = 0;
  3312.                 }
  3313.                 if (is_object($article->getParent())) {
  3314.                     $tableau_donnee["parent_id"] = $article->getParent()->getId();
  3315.                 }
  3316.                 $tableau_donnee["divers"] = $article->getDivers();
  3317.                 if ($article->getMouvemente() === true) {
  3318.                     $tableau_donnee["mouvemente"] = 1;
  3319.                 } else {
  3320.                     $tableau_donnee["mouvemente"] = 0;
  3321.                 }
  3322.                 if ($article->getNumSerieObligatoire()) {
  3323.                     $tableau_donnee["num_serie_obligatoire"] = 1;
  3324.                 } else {
  3325.                     $tableau_donnee["num_serie_obligatoire"] = 0;
  3326.                 }
  3327.                 if (is_object($article->getArticleRemplacement())) {
  3328.                     $tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  3329.                 }
  3330.                 if ($article->getMajPoids()) {
  3331.                     $tableau_donnee["maj_poids"] = 1;
  3332.                 } else {
  3333.                     $tableau_donnee["maj_poids"] = 0;
  3334.                 }
  3335.                 if ($article->getMajPrixBase()) {
  3336.                     $tableau_donnee["maj_prix_base"] = 1;
  3337.                 } else {
  3338.                     $tableau_donnee["maj_prix_base"] = 0;
  3339.                 }
  3340.                 if ($article->getEstCommentaire()) {
  3341.                     $tableau_donnee["est_commentaire"] = 1;
  3342.                 } else {
  3343.                     $tableau_donnee["est_commentaire"] = 0;
  3344.                 }
  3345.                 $tableau_donnee["cond_achat"]     = $article->getConditionnementAchat();
  3346.                 $tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
  3347.                 if (is_object($article->getRegleTaxeAchat())) {
  3348.                     $tableau_donnee["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
  3349.                 }
  3350.                 $tableau_donnee["maj_prix"] = 1;
  3351.                 $conn->insert('article__article'$tableau_donnee);
  3352.                 $idNouveauArticle $conn->lastInsertId();
  3353.                 $article          $repo_article->find($idNouveauArticle);
  3354.             }
  3355.             $a                    = [];
  3356.             $a['id']              = 'tmp-'.time();
  3357.             $a['position']        = "";
  3358.             $a['article']         = $article;
  3359.             $a['ecocontribution'] = floatval($article->getEcocontribution());
  3360.             $a['libelle']         = $article->getLibelle();
  3361.             if ($quantite != '' && is_numeric($quantite)) {
  3362.                 $a['quantite'] = $quantite;
  3363.                 $a['ral']      = $quantite;
  3364.             } else {
  3365.                 $a['quantite'] = "1";
  3366.                 $a['ral']      = "1";
  3367.             }
  3368.             //$a['estCommentaire']=$article->getEstCommentaire();
  3369.             if ($article->getEstCommentaire()) {
  3370.                 $a['estCommentaire'] = 1;
  3371.             } else {
  3372.                 $a['estCommentaire'] = 0;
  3373.             }
  3374.             $a['commentaire']          = "";
  3375.             $a['commentaireSuppl']     = "";
  3376.             $a['commentairePrive']     = "";
  3377.             $a['remise']               = "0";
  3378.             $a['remiseSupplementaire'] = "0";
  3379.             $a['totalHt']              = $article->getPrixBase();
  3380.             $a['prixBase']             = $article->getPrixBase();
  3381.             $condition                 '';
  3382.             //recuperer la condition d'achat par défaut
  3383.             $repoConditionsAchat $em->getRepository(ConditionAchat::class);
  3384.             //$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
  3385.             if ($fournisseur != '') {
  3386.                 $condition $repoConditionsAchat->findOneBy([
  3387.                                                                  'article'     => $article->getId(),
  3388.                                                                  'fournisseur' => $fournisseur,
  3389.                                                                  'defaut'      => 1,
  3390.                                                              ]);
  3391.             }
  3392.             if ( ! isset($condition) || ! is_object($condition)) {
  3393.                 /*
  3394.                         $condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId(),
  3395.                                                                             'fournisseur' => $fournisseur,
  3396.                             ));
  3397.                             */
  3398.                 $conditions $repoConditionsAchat->findBy(['article' => $article->getId(), 'fournisseur' => $fournisseur,], ['quantite' => 'ASC'], 10);
  3399.                 if (count($conditions)) {
  3400.                     $condition $conditions[0];
  3401.                 }
  3402.             }
  3403.             /*
  3404.                     if(count($condition) > 0)
  3405.                         $condition = $condition[0];
  3406.                     else
  3407.                         $condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
  3408.                     *
  3409.                     */
  3410.             $a['coefficientConditionnement'] = 1;
  3411.             $a['fraisAnnexes']               = 0;
  3412.             $a['dateApproximativeReception'] = null;
  3413.             if (is_object($condition)) {
  3414.                 $a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
  3415.                 if ($condition->getPrixNet()) {
  3416.                     $a['remise']               = "0";
  3417.                     $a['remiseSupplementaire'] = "0";
  3418.                     if ($condition->getPrixAchatNet() != '') {
  3419.                         //$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
  3420.                         $a['prixBase'] = $condition->getPrixAchatNet();
  3421.                     }
  3422.                 } else {
  3423.                     if ($condition->getTauxRemise() != '') {
  3424.                         $a['remise'] = $condition->getTauxRemise();
  3425.                     }
  3426.                     if ($condition->getTauxRemiseSupplementaire() != '') {
  3427.                         $a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
  3428.                     }
  3429.                     if ($condition->getPrixAchatBrut() != '') {
  3430.                         //$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
  3431.                         $a['prixBase'] = $condition->getPrixAchatBrut();
  3432.                     }
  3433.                 }
  3434.                 if ($condition->getLibelle() != '') {
  3435.                     $a['libelle'] = $condition->getLibelle();
  3436.                 }
  3437.                 if ($quantite != '' && is_numeric($quantite)) {
  3438.                     $a['quantite'] = $quantite;
  3439.                 } elseif ($condition->getQuantite() != '') {
  3440.                     //$a['quantite']=$condition->getQuantite();
  3441.                     $conditionnement 1;
  3442.                     if ($condition->getConditionnement() != '') {
  3443.                         $conditionnement floatval($condition->getConditionnement());
  3444.                     }
  3445.                     $quantite floatval($condition->getQuantite());
  3446.                     $i        1;
  3447.                     while ($quantite $conditionnement != 0) {
  3448.                         $quantite++;
  3449.                     }
  3450.                     $a['quantite']             = $quantite;
  3451.                     $a['ral']                  = $quantite;
  3452.                     $a['referenceFournisseur'] = $condition->getReferenceFournisseur();
  3453.                 }
  3454.                 $a['conditionAchat'] = $condition;
  3455.                 $a['fraisAnnexes']   = $condition->getFraisAnnexes();
  3456.                 if (floatval($condition->getDelai()) > 0) {
  3457.                     $joursLivraison         = ["lundi""mardi""mercredi""jeudi""vendredi"];
  3458.                     $dateLivraisonTheorique $dateService->date_addWorkingDays(strtotime((new \Datetime)->format("Y-m-d")), floatval($condition->getDelai()), $joursLivraison);
  3459.                     //$a['dateApproximativeReception'] = (new \Datetime)->modify('+ '.floatval($condition->getDelai()).' days');
  3460.                     $a['dateApproximativeReception'] = $dateLivraisonTheorique;
  3461.                 }
  3462.             } else {
  3463.                 continue;
  3464.             }
  3465.             $a['couleur'] = $articleService->getCouleurEtatStock($article$a['quantite']);
  3466.             $fournisseur $repoFournisseur->find($fournisseur);
  3467.             $taxe $repo_taxe->find(5);
  3468.             if (is_object($fournisseur)) {
  3469.                 $taxe $fournisseurService->getTaxe($fournisseur$article);
  3470.             }
  3471.             $a['tva']                        = $taxe->getTaux();
  3472.             $a['taxe']                       = $taxe;
  3473.             $a['prixAchatUnitaireAvecFrais'] = $a['prixBase'];
  3474.             $commentairePonctuel             .= $article->getCommentairePonctuel().'<br>';
  3475.             $rendu                           .= $this->render('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
  3476.                 'a'              => $a,
  3477.                 'boucle'         => "0",
  3478.                 'numeroLigne'    => "0",
  3479.                 'fournisseur'    => $fournisseur,
  3480.                 'commandeId'     => $commandeId,
  3481.                 'tabColonneUser' => $tabColonneUser,
  3482.             ]);
  3483.         }
  3484.         /*
  3485.         $rendu = $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', array(
  3486.             'a'=>$a,
  3487.             'boucle'=>"0",
  3488.             'numeroLigne'=>"0",
  3489.             'fournisseur'=>$fournisseur,
  3490.             'commandeId' => $commandeId,
  3491.             'tabColonneUser' => $tabColonneUser
  3492.         ));
  3493.         */
  3494.         return new JsonResponse(['rendu' => $rendu'commentairePonctuel' => $commentairePonctuel]);
  3495.     }
  3496.     /**
  3497.      * @Route("/commande-article/achat/condition-achat/{id}", name="dtc_condition_achat_commande_fournisseur")
  3498.      */
  3499.     public function conditionAchatCommandeFournisseurAction(Request $requestArticle $articleEntityManagerInterface $emArticleService $articleService
  3500.     ) {
  3501.         $fournisseur         $request->query->get('fournisseur');
  3502.         $commandeFournisseur $request->query->get('commandeFournisseur');
  3503.         $repoConditionsAchat $em->getRepository(ConditionAchat::class);
  3504.         $conditions          $repoConditionsAchat->findBy(['article' => $article->getId(), 'fournisseur' => $fournisseur]);
  3505.         $repoArticleCommande $em->getRepository(ArticleCommande::class);
  3506.         $ralFourn            $repoArticleCommande->getRalFournisseur($article);
  3507.         $retour $articleService->getQteConseillee($article);
  3508.         $quantiteMin $retour['qteMini'];
  3509.         $quantiteMax $retour['qteMaxi'];
  3510.         $quantite $request->query->get('quantite');
  3511.         $retours = [];
  3512.         foreach ($conditions as $condition) {
  3513.             $qteConseillee                      $articleService->getQteConseillee($article$condition);
  3514.             $retour                             = [];
  3515.             $retour['quantite']                 = $qteConseillee['qteConseillee'];
  3516.             $retour['id']                       = $condition->getId();
  3517.             $retour['quantiteCond']             = $condition->getQuantite();
  3518.             $retour['prixAchatBrut']            = $condition->getPrixAchatBrut();
  3519.             $retour['tauxRemise']               = $condition->getTauxRemise();
  3520.             $retour['tauxRemiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
  3521.             $retour['defaut']                   = $condition->getDefaut();
  3522.             $retour['conditionnement']          = $condition->getConditionnement();
  3523.             $retour['quantiteMin']              = $qteConseillee['qteMini'];
  3524.             $retour['quantiteMax']              = $qteConseillee['qteMaxi'];
  3525.             //$retour['reference'] = $article->getReference().' / '.$condition->getReferenceFournisseur();
  3526.             $retour['reference'] = $article->getReference();
  3527.             $retour['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
  3528.             $retour['fraisAnnexes']               = $condition->getFraisAnnexes();
  3529.             $retour['condition']                  = $condition;
  3530.             $retours[]                            = $retour;
  3531.         }
  3532.         //print_r($retour);
  3533.         $titreModal 'Conditions d\'achat';
  3534.         $rendu      $this->renderView('GestionComerciale/ArticleCommande/condition_achat.html.twig', [
  3535.             'conditions'          => $retours,
  3536.             'article'             => $article,
  3537.             'quantite'            => $quantite,
  3538.             //'quantiteMin'=>$quantiteMin,
  3539.             //'quantiteMax'=>$quantiteMax,
  3540.             'ralFournisseur'      => $ralFourn,
  3541.             'cond'                => $request->query->get('cond'),
  3542.             'commandeFournisseur' => $commandeFournisseur,
  3543.         ]);
  3544.         return new JsonResponse(['rendu' => $rendu'titre' => $titreModal]);
  3545.     }
  3546.     /**
  3547.      * @Route("/conditions-achat/article/{id}", name="dtc_condition_achat_article")
  3548.      */
  3549.     public function conditionAchatArticleAction(Request $requestArticle $articleEntityManagerInterface $emArticleService $articleService
  3550.     ) {
  3551.         $repoConditionsAchat $em->getRepository(ConditionAchat::class);
  3552.         $conditions          $repoConditionsAchat->findBy(['article' => $article->getId()]);
  3553.         $repoArticleCommande $em->getRepository(ArticleCommande::class);
  3554.         $ralFourn            $repoArticleCommande->getRalFournisseur($article);
  3555.         $retour $articleService->getQteConseillee($article);
  3556.         $quantiteMin $retour['qteMini'];
  3557.         $quantiteMax $retour['qteMaxi'];
  3558.         $quantite $request->query->get('quantite');
  3559.         $retours = [];
  3560.         foreach ($conditions as $condition) {
  3561.             $qteConseillee                        $articleService->getQteConseillee($article$condition);
  3562.             $retour                               = [];
  3563.             $retour['quantite']                   = $qteConseillee['qteConseillee'];
  3564.             $retour['id']                         = $condition->getId();
  3565.             $retour['quantiteCond']               = $condition->getQuantite();
  3566.             $retour['prixAchatBrut']              = $condition->getPrixAchatBrut();
  3567.             $retour['tauxRemise']                 = $condition->getTauxRemise();
  3568.             $retour['tauxRemiseSupplementaire']   = $condition->getTauxRemiseSupplementaire();
  3569.             $retour['defaut']                     = $condition->getDefaut();
  3570.             $retour['conditionnement']            = $condition->getConditionnement();
  3571.             $retour['quantiteConseillee']         = $qteConseillee['qteConseillee'];
  3572.             $retour['quantiteMin']                = $qteConseillee['qteMini'];
  3573.             $retour['quantiteMax']                = $qteConseillee['qteMaxi'];
  3574.             $retour['reference']                  = $article->getReference().' / '.$condition->getReferenceFournisseur();
  3575.             $retour['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
  3576.             $retour['fraisAnnexes']               = $condition->getFraisAnnexes();
  3577.             $retour['condition']                  = $condition;
  3578.             $retours[]                            = $retour;
  3579.         }
  3580.         //print_r($retour);
  3581.         $titreModal 'Conditions d\'achat';
  3582.         $rendu      $this->renderView('Articles/ConditionAchat/conditions-achat-article-modal.html.twig', [
  3583.             'conditions'     => $retours,
  3584.             'article'        => $article,
  3585.             'ralFournisseur' => $ralFourn,
  3586.             'quantite'       => $quantite,
  3587.         ]);
  3588.         return new JsonResponse(['rendu' => $rendu'titre' => $titreModal]);
  3589.     }
  3590.     /**
  3591.      * @Route("/commande/facturable/verifier", name="dtc_commande_facturable")
  3592.      */
  3593.     public function verifierCommandeFacturableAction(Request $requestEntityManagerInterface $emCommandeService $commandeService)
  3594.     {
  3595.         $infos                 '';
  3596.         $repo_commande         $em->getRepository(Commande::class);
  3597.         $repo_article_commande $em->getRepository(ArticleCommande::class);
  3598.         $commande              $repo_commande->find($request->query->get('id_commande'));
  3599.         $articlesCommandeIds   $request->query->get('articlesCommandeIds');
  3600.         $qtes                  $request->query->get('qte');
  3601.         //modifier les quantités
  3602.         /*
  3603.         $commandeAtester = new Commande;
  3604.         $commandeAtester->setTypeDocumentCommercial($commande->getTypeDocumentCommercial());
  3605.          *
  3606.          */
  3607.         foreach ($commande->getArticleCommande() as $articleCommande) {
  3608.             $commande->removeArticleCommande($articleCommande);
  3609.         }
  3610.         foreach ($articlesCommandeIds as $key => $articleCommandeId) {
  3611.             $articleCommande      $repo_article_commande->find($articleCommandeId);
  3612.             $articleCommandeClone = clone $articleCommande;
  3613.             $articleCommandeClone->setQuantite($qtes[$key]);
  3614.             $commande->addArticleCommande($articleCommandeClone);
  3615.             $infos $qtes[$key];
  3616.         }
  3617.         $data $commandeService->estFacturable($commande);
  3618.         return new JsonResponse(['data' => $data'infos' => $infos]);
  3619.     }
  3620.     /**
  3621.      * @Route("/client/{id}/facturable/verifier", name="dtc_client_facturable")
  3622.      */
  3623.     public function verifierClientFacturableAction(Request $requestClient $client)
  3624.     {
  3625.         $infos '';
  3626.         //$repo_client = $em->getRepository('DTCClientsBundle:Client');
  3627.         //$serviceCommande = $this->get('dtc.commande');
  3628.         //$data = $serviceCommande->estFacturable($commande);
  3629.         /*
  3630.         if(is_object($client->getModeReglement()) && $client->getModeReglement()->getId() == 6)
  3631.             $facturable = 'false';
  3632.         else
  3633.             $facturable = 'true';
  3634.          *
  3635.          */
  3636.         if ($client->getFacturationMultiBL() == false) {
  3637.             $facturable 'true';
  3638.         } else {
  3639.             $facturable 'false';
  3640.         }
  3641.         return new JsonResponse(['facturable' => $facturable'infos' => $infos]);
  3642.     }
  3643.     /**
  3644.      * @Route("/compte-bancaire/{id}/recharger", name="dtc_recharger_infos_bancaires")
  3645.      */
  3646.     public function rechargerInfosBancairesAction(Request $request$idEntityManagerInterface $em)
  3647.     {
  3648.         $compteBancaire $em->getRepository(CompteBancaire::class)->getInfos($id);
  3649.         return new JsonResponse(['compteBancaire' => $compteBancaire]);
  3650.     }
  3651.     /**
  3652.      * @Route("/facture-article/achat/nouveau/{id}", name="dtc_construire_ligne_article_facture_fournisseur")
  3653.      */
  3654.     public function construireLigneArticleFactureFournisseurAction(Request            $requestArticle $articleEntityManagerInterface $emArticleService $serviceArticle,
  3655.                                                                    FournisseurService $fournisseurService
  3656.     ) {
  3657.         $fournisseur               $request->query->get('fournisseur');
  3658.         $quantite                  $request->query->get('quantite');
  3659.         $a                         = [];
  3660.         $a['quantiteDejaPreparee'] = 0;
  3661.         $a['commandeFournisseur']  = $request->query->get('commandeFournisseur');
  3662.         $a['majCondAchat']         = '';
  3663.         $a['position']             = "";
  3664.         $a['fraisAnnexes']         = 0;
  3665.         $a['ecocontribution']      = floatval($article->getEcocontribution());
  3666.         $a['article']              = $article;
  3667.         $a['libelle']              = $article->getLibelle();
  3668.         if ($quantite != '' && is_numeric($quantite)) {
  3669.             $a['quantite'] = $quantite;
  3670.             $a['ral']      = $quantite;
  3671.         } else {
  3672.             $a['quantite'] = "1";
  3673.             $a['ral']      = "1";
  3674.         }
  3675.         $a['commentaire']          = "";
  3676.         $a['remise']               = "0";
  3677.         $a['remiseSupplementaire'] = "0";
  3678.         $a['totalHt']              = $article->getPrixBase();
  3679.         $a['prixBase']             = $article->getPrixBase();
  3680.         //recuperer la condition d'achat par défaut
  3681.         $repoConditionsAchat $em->getRepository(ConditionAchat::class);
  3682.         //$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
  3683.         if ($fournisseur != '') {
  3684.             $condition $repoConditionsAchat->findOneBy([
  3685.                                                              'article'     => $article->getId(),
  3686.                                                              'fournisseur' => $fournisseur,
  3687.                                                              'defaut'      => 1,
  3688.                                                          ]);
  3689.         }
  3690.         if ( ! isset($condition) || ! is_object($condition)) {
  3691.             $condition $repoConditionsAchat->findOneBy([
  3692.                                                              'article'     => $article->getId(),
  3693.                                                              'fournisseur' => $fournisseur,
  3694.                                                          ]);
  3695.         }
  3696.         /*
  3697.                 if(count($condition) > 0)
  3698.                     $condition = $condition[0];
  3699.                 else
  3700.                     $condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
  3701.                  *
  3702.                  */
  3703.         $a['coefficientConditionnement'] = 1;
  3704.         if (is_object($condition)) {
  3705.             if ($condition->getTauxRemise() != '') {
  3706.                 $a['remise'] = $condition->getTauxRemise();
  3707.             }
  3708.             if ($condition->getTauxRemiseSupplementaire() != '') {
  3709.                 $a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
  3710.             }
  3711.             if ($condition->getPrixAchatNet() != '') {
  3712.                 $a['prixBase'] = $condition->getPrixAchatNet();
  3713.             }
  3714.             if ($condition->getLibelle() != '') {
  3715.                 $a['libelle'] = $condition->getLibelle();
  3716.             }
  3717.             if ($condition->getfraisAnnexes() != '') {
  3718.                 $a['fraisAnnexes'] = $condition->getfraisAnnexes();
  3719.             }
  3720.             if ($quantite != '' && is_numeric($quantite)) {
  3721.                 $a['quantite'] = $quantite;
  3722.             } elseif ($condition->getQuantite() != '') {
  3723.                 $a['quantite'] = $condition->getQuantite();
  3724.             }
  3725.             if ($condition->getCoefficientConditionnement() != '') {
  3726.                 $a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
  3727.             }
  3728.         }
  3729.         $a['couleur'] = $serviceArticle->getCouleurEtatStock($article$a['quantite']);
  3730.         $repo_fournisseur $em->getRepository(Fournisseur::class);
  3731.         $fournisseur      $repo_fournisseur->find($fournisseur);
  3732.         $repo_taxe $em->getRepository(Taxe::class);
  3733.         $taxes     $repo_taxe->findAll();
  3734.         $taxe      $repo_taxe->find(5);
  3735.         if (is_object($fournisseur)) {
  3736.             $taxe $fournisseurService->getTaxe($fournisseur$article);
  3737.         }
  3738.         if (is_object($taxe)) {
  3739.             $a['taxe'] = $taxe;
  3740.         }
  3741.         $rendu $this->renderView(
  3742.             'GestionComerciale/ArticleCommande/template_tr_facture_fournisseur.html.twig',
  3743.             ['a' => $a'boucle' => "0"'numeroLigne' => "0"'fournisseur' => $fournisseur'taxes' => $taxes]
  3744.         );
  3745.         return new JsonResponse(['rendu' => $rendu'commentairePonctuel' => $article->getCommentairePonctuel()]);
  3746.     }
  3747.     /**
  3748.      * @Route("/fabrication-multiple/fabrication/ajouter/{id}", name="dtc_construire_ligne_fabrication_multiple")
  3749.      */
  3750.     public function construireLigneFabricationMultipleAction(Request $request$idEntityManagerInterface $emArticleService $articleService)
  3751.     {
  3752.         $date = new \DateTime();
  3753.         //$quantite = $request->query->get('quantite');
  3754.         $repoArticle $em->getRepository(Article::class);
  3755.         $article     $repoArticle->find($id);
  3756.         $quantite    $repoArticle->getQuantiteAFabriquer($article);
  3757.         $quantite    $articleService->quantiteAfabriquer($article);
  3758.         $fabrication = new Fabrication();
  3759.         $fabrication->setArticle($article);
  3760.         $fabrication->setDate($date);
  3761.         $fabrication->setQuantite($quantite);
  3762.         $em->persist($fabrication);
  3763.         $em->flush();
  3764.         $hide          $request->query->get('hide');
  3765.         $cump          $articleService->getCumpFabrication3($articletrue$quantite);
  3766.         $trFabrication $this->renderView('GestionComerciale/FabricationMultiple/table-compose-tr.html.twig', ['fabrication' => $fabrication'cumpTmp' => $cump]);
  3767.         $jsFabrication $this->renderView('GestionComerciale/FabricationMultiple/table-compose-js.html.twig', ['fabrication' => $fabrication]);
  3768.         $detailFabrication $this->renderView('GestionComerciale/FabricationMultiple/detail-fabrication.html.twig', ['fabrication' => $fabrication'hide' => $hide]);
  3769.         return new Response(json_encode(['trFabrication' => $trFabrication'jsFabrication' => $jsFabrication'detailFabrication' => $detailFabrication]));
  3770.     }
  3771.     /**
  3772.      * @Route("/charger-dernier-prix/article/{article}/client/{client}/quantite/{quantite}", name="dtc_charger_dernier_prix")
  3773.      */
  3774.     public function chargerDernierPrixAction(Request $request$article$client$quantiteEntityManagerInterface $em)
  3775.     {
  3776.         $repo_article $em->getRepository(Article::class);
  3777.         $objet        $repo_article->find($article);
  3778.         $get          $request->query->all();
  3779.         $articleCommandeSource "";
  3780.         if ( ! empty($get["articleCommandeId"])) {
  3781.             $articleCommandeSource $get["articleCommandeId"];
  3782.         }
  3783.         $repoArticleCommande $em->getRepository(ArticleCommande::class);
  3784.         $articlesCommande $repoArticleCommande->chargerDernierPrix($article$client)->getQuery()->getResult();
  3785.         $retour           $this->renderView('GestionComerciale/ArticleCommande/liste-dernieres-ventes.html.twig', [
  3786.             'articlesCommande'       => $articlesCommande,
  3787.             'articlesCommandeSource' => $articleCommandeSource,
  3788.             'quantite'               => $quantite,
  3789.         ]);
  3790.         $titre "Dernières factures du produit : ".$objet->getReference();
  3791.         return new JsonResponse(['retour' => $retour'titre' => $titre]);
  3792.     }
  3793.     /**
  3794.      * @Route("/charger-dernier-prix-fournisseur/article/{article}/fournisseur/{fournisseur}/quantite/{quantite}", name="dtc_charger_dernier_prix_fournisseur")
  3795.      */
  3796.     public function chargerDernierPrixFournisseurAction(Request $request$article$fournisseur$quantiteEntityManagerInterface $em)
  3797.     {
  3798.         $repo_article $em->getRepository(Article::class);
  3799.         $objet        $repo_article->find($article);
  3800.         $get          $request->query->all();
  3801.         $articleCommandeSource "";
  3802.         if ( ! empty($get["articleCommandeId"])) {
  3803.             $articleCommandeSource $get["articleCommandeId"];
  3804.         }
  3805.         $repoArticleCommande $em->getRepository(ArticleCommande::class);
  3806.         $articlesCommande $repoArticleCommande->chargerDernierPrixFournisseur($article$fournisseur)->getQuery()->getResult();
  3807.         $retour           $this->renderView('GestionComerciale/ArticleCommande/liste-dernieres-ventes-fournisseur.html.twig', [
  3808.             'articlesCommande'       => $articlesCommande,
  3809.             'articlesCommandeSource' => $articleCommandeSource,
  3810.             'quantite'               => $quantite,
  3811.         ]);
  3812.         $titre "Dernières factures du produit : ".$objet->getReference();
  3813.         return new JsonResponse(['retour' => $retour'titre' => $titre]);
  3814.     }
  3815.     /**
  3816.      * @Route("/commande-fournisseur/recharger-total-article/{articleId}", name="dtc_total_prestation")
  3817.      */
  3818.     public function getTotalPrestationAction(Request $request$articlePrestation ''$fabrications = [], EntityManagerInterface $em)
  3819.     {
  3820.         $repo_fabrication              $em->getRepository(Fabrication::class);
  3821.         $donnees                       = [];
  3822.         $donnees['quantitePrestation'] = 0;
  3823.         $fabrications                  $request->query->get('fabrications');
  3824.         if (count($fabrications) > 0) {
  3825.             foreach ($fabrications as $fabricationId) {
  3826.                 $fabrication $repo_fabrication->find($fabricationId);
  3827.                 if (is_object($fabrication)) {
  3828.                     $donnees['quantitePrestation'] += $fabrication->getQuantitePrestation();
  3829.                 }
  3830.             }
  3831.         }
  3832.         return new JsonResponse(['retour' => $donnees]);
  3833.     }
  3834.     /**
  3835.      * @Route("/commande/{id}/commandes/modifier/client/{idClient}", name="dtc_ajax_get_commande_a_modifier")
  3836.      */
  3837.     public function getCommandesModifierClientAction(Request $requestCommande $commande$idClientEntityManagerInterface $em)
  3838.     {
  3839.         $donnees = [];
  3840.         $routes        = [];
  3841.         $route         'dtc_commande_modifier';
  3842.         $hasAcomptes   'false';
  3843.         $repo_commande $em->getRepository(Commande::class);
  3844.         $commandes     $repo_commande->getDocumentClientAmodifier($commande)->getQuery()->getResult();
  3845.         if (is_object($commande->getClient()) && $commande->getClient()->getId() != $idClient) {
  3846.             $repo_client $em->getRepository(Client::class);
  3847.             $client_obj  $repo_client->find($idClient);
  3848.             if (is_object($client_obj)) {
  3849.                 $commande->setClient($client_obj);
  3850.                 $em->persist($commande);
  3851.                 $em->flush();
  3852.             }
  3853.         }
  3854.         if (count($commandes) > 0) {
  3855.             $hasAcomptes 'false';
  3856.             foreach ($commandes as $commande) {
  3857.                 if ($commande->getClient()->getId() != $idClient) {
  3858.                     $route 'dtc_commande_modifier';
  3859.                     if (is_int($commande->getTypeDocumentCommercial())) {
  3860.                         $typeDocId $commande->getTypeDocumentCommercial();
  3861.                         switch ($typeDocId) {
  3862.                             case 1:
  3863.                                 $route 'dtc_devis_modifier';
  3864.                                 break;
  3865.                             case 2:
  3866.                                 $route 'dtc_commande_modifier';
  3867.                                 break;
  3868.                             case 3:
  3869.                                 $route 'dtc_ordre_reparation_modifier';
  3870.                                 break;
  3871.                             case 4:
  3872.                                 $route 'dtc_bon_preparation_modifier';
  3873.                                 break;
  3874.                             case 5:
  3875.                                 $route 'dtc_bon_livraison_modifier';
  3876.                                 break;
  3877.                             case 6:
  3878.                                 $route 'dtc_facture_afficher';
  3879.                                 break;
  3880.                             case 7:
  3881.                                 $route 'dtc_avoir_modifier';
  3882.                                 break;
  3883.                             default:
  3884.                                 $route 'dtc_commande_modifier';
  3885.                                 break;
  3886.                         }
  3887.                     }
  3888.                     if (count($commande->getAcomptes()) > || count($commande->getReglements()) > 0) {
  3889.                         $hasAcomptes 'true';
  3890.                     }
  3891.                     $donnees[] = [
  3892.                         'id'        => $commande->getId(),
  3893.                         'reference' => $commande->getReference(),
  3894.                         'url'       => $this->generateUrl($route, ['id' => $commande->getId()]),
  3895.                         //'acomptes' => $hasAcomptes
  3896.                     ];
  3897.                 }
  3898.             }
  3899.         }
  3900.         return new JsonResponse(['commandes' => $donnees'hasAcomptes' => $hasAcomptes]);
  3901.     }
  3902.     /**
  3903.      * @Route("/lettrage/facture-et-reglements", name="dtc_lettrage_reglements_et_facture")
  3904.      */
  3905.     public function lettrerAction(Request $requestEntityManagerInterface $em)
  3906.     {
  3907.         $allPost $request->request->all();
  3908.         $objets  $request->request->get('objets');
  3909.         $valid   1;
  3910.         $repo_commande $em->getRepository(Commande::class);
  3911.         $repo_acompte  $em->getRepository(Acompte::class);
  3912.         $numeroLettrage 0;
  3913.         $count          0;
  3914.         foreach ($objets as $objet) {
  3915.             if ($objet['objet'] == 'acompte') {
  3916.                 $objetAmodifier $repo_acompte->find($objet['id']);
  3917.             } elseif ($objet['objet'] == 'commande') {
  3918.                 $objetAmodifier $repo_commande->find($objet['id']);
  3919.             } else {
  3920.                 $objetAmodifier '';
  3921.             }
  3922.             if ($count == && is_object($objetAmodifier)) {
  3923.                 $client $objetAmodifier->getClient();
  3924.                 if (is_object($client)) {
  3925.                     $numeroLettrage $repo_commande->getNumeroLettrage($client);
  3926.                 }
  3927.             }
  3928.             $count++;
  3929.             if (is_object($objetAmodifier)) {
  3930.                 $client $objetAmodifier->getClient();
  3931.                 $objetAmodifier->setNumeroLettrage($numeroLettrage);
  3932.                 $em->persist($objetAmodifier);
  3933.             } else {
  3934.                 $valid 0;
  3935.             }
  3936.         }
  3937.         if ($valid == 1) {
  3938.             $em->flush();
  3939.         }
  3940.         $response = new JsonResponse();
  3941.         $response->setData([
  3942.                                'post'  => $allPost,
  3943.                                'valid' => $valid
  3944.                                //'test' => json_encode(array('essaiT'=>'essaiV'))
  3945.                            ]);
  3946.         return $response;
  3947.     }
  3948.     /**
  3949.      * @Route("/delettrage/facture-et-reglements", name="dtc_delettrage_reglements_et_facture")
  3950.      */
  3951.     public function delettrerAction(Request $requestEntityManagerInterface $em)
  3952.     {
  3953.         $allPost $request->request->all();
  3954.         $objets  $request->request->get('objets');
  3955.         $valid   1;
  3956.         $repo_commande $em->getRepository(Commande::class);
  3957.         $repo_acompte  $em->getRepository(Acompte::class);
  3958.         $numeroLettrage null;
  3959.         foreach ($objets as $objet) {
  3960.             if ($objet['objet'] == 'acompte') {
  3961.                 $objetAmodifier $repo_acompte->find($objet['id']);
  3962.             } elseif ($objet['objet'] == 'commande') {
  3963.                 $objetAmodifier $repo_commande->find($objet['id']);
  3964.             } else {
  3965.                 $objetAmodifier '';
  3966.             }
  3967.             if (is_object($objetAmodifier)) {
  3968.                 $numeroLettrage $objetAmodifier->getNumeroLettrage();
  3969.                 $client         $objetAmodifier->getClient();
  3970.                 if (is_object($client)) {
  3971.                     $acomptesAmodifier $repo_acompte->findBy([
  3972.                                                                    'numeroLettrage' => $numeroLettrage,
  3973.                                                                    'client'         => $client,
  3974.                                                                ]);
  3975.                     if (count($acomptesAmodifier)) {
  3976.                         foreach ($acomptesAmodifier as $acompteAmodifier) {
  3977.                             $acompteAmodifier->setNumeroLettrage(null);
  3978.                             $em->persist($acompteAmodifier);
  3979.                         }
  3980.                     }
  3981.                     $commandesAmodifier $repo_commande->findBy([
  3982.                                                                      'numeroLettrage' => $numeroLettrage,
  3983.                                                                      'client'         => $client,
  3984.                                                                  ]);
  3985.                     if (count($commandesAmodifier)) {
  3986.                         foreach ($commandesAmodifier as $commandeAmodifier) {
  3987.                             $commandeAmodifier->setNumeroLettrage(null);
  3988.                             $em->persist($commandeAmodifier);
  3989.                         }
  3990.                     }
  3991.                 }
  3992.             } else {
  3993.                 $valid 0;
  3994.             }
  3995.         }
  3996.         if ($valid == 1) {
  3997.             $em->flush();
  3998.         }
  3999.         $response = new JsonResponse();
  4000.         $response->setData([
  4001.                                'post'  => $allPost,
  4002.                                'valid' => $valid
  4003.                                //'test' => json_encode(array('essaiT'=>'essaiV'))
  4004.                            ]);
  4005.         return $response;
  4006.     }
  4007.     /*
  4008.      * @Route("/historique/{entity}/{id}", name="dtc_ajax_historique")
  4009.      */
  4010.     public function historiqueAction(Request $request$id$entityEntityManagerInterface $em)
  4011.     {
  4012.         $audits = [];
  4013.         switch ($entity) {
  4014.             case 'adresse':
  4015.                 $totalCount $em->getRepository(Adresse::class)->getHistorique($idtrue);
  4016.                 $audits     $em->getRepository(Adresse::class)->getHistorique($idfalse);
  4017.                 break;
  4018.             default:
  4019.                 break;
  4020.         }
  4021.         $titreModal 'Historique des modifications';
  4022.         $rendu $this->renderView('FO/Historique/historique.html.twig', [
  4023.             'audits' => $audits,
  4024.         ]);
  4025.         return new JsonResponse(['rendu' => $rendu'titre' => $titreModal]);
  4026.     }
  4027.     /**
  4028.      * @Route("/fabrication-multiple/load/{id}", name="dtc_ajax_fabrication_multiple_load")
  4029.      */
  4030.     public function fabricationMultipleLoadAction(Request $requestFabricationMultiple $fabricationMultipleArticleService $serviceArticleFabricationService $serviceFabrication
  4031.     ) {
  4032.         $data = [];
  4033.         /*
  4034.         foreach($fabricationMultiple->getFabrications() as $fab){
  4035.             $dataTmp = array();
  4036.             $dataTmp['id'] = $fab->getId();
  4037.             $cump = $serviceArticle->getCumpFabrication3($fab->getArticle(), true, $fab->getQuantite());
  4038.             $dataTmp['view'] = $this->renderView('GestionComerciale/FabricationMultiple/table-compose-tr.html.twig', array(
  4039.                 'fabrication' => $fab,
  4040.                 'cumpTmp'=> $cump,
  4041.                 ));
  4042.             $data['fabrications'][] = $dataTmp;
  4043.         }
  4044. */
  4045.         foreach ($fabricationMultiple->getFabrications() as $fab) {
  4046.             foreach ($fab->getArticleCommande() as $ac) {
  4047.                 $dataTmp                    = [];
  4048.                 $dataTmp['id']              = $ac->getId();
  4049.                 $dataTmp['cump']            = $serviceArticle->getCumpOuPrixCondHaAc($ac->getArticle(), ''$ac->getQuantite());
  4050.                 $dataTmp['cumpArrondi']     = round($dataTmp['cump'], 2);
  4051.                 $dataTmp['montantCump']     = round($dataTmp['cump'] * $ac->getQuantite(), 2);
  4052.                 $dataTmp['raf']             = $serviceFabrication->raf($ac->getArticle(), $fab->getId());
  4053.                 $data['articlecommandes'][] = $dataTmp;
  4054.             }
  4055.             $dataTmp                = [];
  4056.             $dataTmp['id']          = $fab->getId();
  4057.             $cump                   $serviceArticle->getCumpFabrication3($fab->getArticle(), true$fab->getQuantite());
  4058.             $dataTmp['view']        = $this->renderView('GestionComerciale/FabricationMultiple/table-compose-tr.html.twig', [
  4059.                 'fabrication' => $fab,
  4060.                 'cumpTmp'     => $cump,
  4061.             ]);
  4062.             $data['fabrications'][] = $dataTmp;
  4063.         }
  4064.         $response = new JsonResponse;
  4065.         $response->setData($data);
  4066.         return $response;
  4067.     }
  4068.     /**
  4069.      * @Route("/fabrication/article/load/{article}/{quantite}", name="dtc_ajax_fabrication_article_load")
  4070.      */
  4071.     public function fabricationArticleLoadAction(Request $request$article$quantiteArticleService $serviceArticle)
  4072.     {
  4073.         $data = [];
  4074.         $dataTmp                = [];
  4075.         $dataTmp['id']          = $article;
  4076.         $dataTmp['cump']        = $serviceArticle->getCumpOuPrixCondHaAc($article''$quantite);
  4077.         $dataTmp['cumpArrondi'] = round($dataTmp['cump'], 2);
  4078.         $dataTmp['montantCump'] = round($dataTmp['cump'] * $quantite2);
  4079.         $data['articles'][]     = $dataTmp;
  4080.         $response = new JsonResponse;
  4081.         $response->setData($data);
  4082.         return $response;
  4083.     }
  4084.     /**
  4085.      * @Route("/commande-article/achat/nouveaux", name="dtc_construire_lignes_article_commande_fournisseur")
  4086.      */
  4087.     public function construireLignesArticleCommandeFournisseurAction(Request        $requestEntityManagerInterface $emColonneTableauService $serviceColonne,
  4088.                                                                      ArticleService $articleServiceFournisseurService $fournisseurService
  4089.     ) {
  4090.         $repoFournisseur $em->getRepository(Fournisseur::class);
  4091.         $repo_taxe       $em->getRepository(Taxe::class);
  4092.         $fournisseur     $request->query->get('fournisseur');
  4093.         $commandeId      $request->query->get('commandeId');
  4094.         //$quantite = $request->query->get('quantite');
  4095.         $repo_article $em->getRepository(Article::class);
  4096.         $data $request->get('dataTables');
  4097.         if (empty($data['actions'])) {
  4098.             $ids = [];
  4099.         } else {
  4100.             $ids $data['actions'];
  4101.         }
  4102.         $qtes $request->get('qte');
  4103.         $rendu               '';
  4104.         $commentairePonctuel '';
  4105.         //return new JsonResponse(array('rendu'=>$rendu,), 200, array('Content-Type'=>'application/json'));
  4106.         $colspan                             13;
  4107.         $tabColonneUser                      = [];
  4108.         $tabColonneUser["id"]                = 1;
  4109.         $tabColonneUser["reference"]         = 1;
  4110.         $tabColonneUser["referenceF"]        = 1;
  4111.         $tabColonneUser["libelle"]           = 1;
  4112.         $tabColonneUser["libelleF"]          = 1;
  4113.         $tabColonneUser["qteMini"]           = 1;
  4114.         $tabColonneUser["qteMaxi"]           = 1;
  4115.         $tabColonneUser["ralC"]              = 1;
  4116.         $tabColonneUser["ralF"]              = 1;
  4117.         $tabColonneUser["qteStockCommande"]  = 1;
  4118.         $tabColonneUser["uniteVente"]        = 1;
  4119.         $tabColonneUser["qte"]               = 1;
  4120.         $tabColonneUser["uniteAchat"]        = 1;
  4121.         $tabColonneUser["prixAchatUnitaire"] = 1;
  4122.         $tabColonneUser["prixHT"]            = 1;
  4123.         $tabColonneUser["CC"]                = 1;
  4124.         $tabColonneUser["qteMiniAchat"]      = 1;
  4125.         $tabColonneUser["conditionnement"]   = 1;
  4126.         $tabColonneUser["txRem"]             = 1;
  4127.         $tabColonneUser["txRemSuppl"]        = 1;
  4128.         $tabColonneUser["fraisAnnexes"]      = 1;
  4129.         $tabColonneUser["ecocontribution"]   = 1;
  4130.         $tabColonneUser["montantHt"]         = 1;
  4131.         $tabColonneUser["totalHT"]           = 1;
  4132.         $tabColonneUser["pump"]              = 1;
  4133.         $tabColonneUser["stock"]             = 1;
  4134.         // TODO CHANGE THIS
  4135.         $colonneUtilisateur "App\\Entity\\GestionComerciale\\FormCommandeFournisseur";
  4136.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'id') == false) {
  4137.             $colspan--;
  4138.             $tabColonneUser["id"] = 0;
  4139.         }
  4140.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'reference') == false) {
  4141.             $colspan--;
  4142.             $tabColonneUser["reference"] = 0;
  4143.         }
  4144.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'referenceF') == false) {
  4145.             $colspan--;
  4146.             $tabColonneUser["referenceF"] = 0;
  4147.         }
  4148.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelle') == false) {
  4149.             $colspan--;
  4150.             $tabColonneUser["libelle"] = 0;
  4151.         }
  4152.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'libelleF') == false) {
  4153.             $colspan--;
  4154.             $tabColonneUser["libelleF"] = 0;
  4155.         }
  4156.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMini') == false) {
  4157.             $colspan--;
  4158.             $tabColonneUser["qteMini"] = 0;
  4159.         }
  4160.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMaxi') == false) {
  4161.             $colspan--;
  4162.             $tabColonneUser["qteMaxi"] = 0;
  4163.         }
  4164.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ralC') == false) {
  4165.             $colspan--;
  4166.             $tabColonneUser["ralC"] = 0;
  4167.         }
  4168.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ralF') == false) {
  4169.             $colspan--;
  4170.             $tabColonneUser["ralF"] = 0;
  4171.         }
  4172.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteStockCommande') == false) {
  4173.             $colspan--;
  4174.             $tabColonneUser["qteStockCommande"] = 0;
  4175.         }
  4176.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'uniteVente') == false) {
  4177.             $colspan--;
  4178.             $tabColonneUser["uniteVente"] = 0;
  4179.         }
  4180.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qte') == false) {
  4181.             $colspan--;
  4182.             $tabColonneUser["qte"] = 0;
  4183.         }
  4184.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'uniteAchat') == false) {
  4185.             $colspan--;
  4186.             $tabColonneUser["uniteAchat"] = 0;
  4187.         }
  4188.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixAchatUnitaire') == false) {
  4189.             $colspan--;
  4190.             $tabColonneUser["prixAchatUnitaire"] = 0;
  4191.         }
  4192.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'prixHT') == false) {
  4193.             $colspan--;
  4194.             $tabColonneUser["prixHT"] = 0;
  4195.         }
  4196.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'CC') == false) {
  4197.             $colspan--;
  4198.             $tabColonneUser["CC"] = 0;
  4199.         }
  4200.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'qteMiniAchat') == false) {
  4201.             $colspan--;
  4202.             $tabColonneUser["qteMiniAchat"] = 0;
  4203.         }
  4204.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'conditionnement') == false) {
  4205.             $colspan--;
  4206.             $tabColonneUser["conditionnement"] = 0;
  4207.         }
  4208.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'txRem') == false) {
  4209.             $colspan--;
  4210.             $tabColonneUser["txRem"] = 0;
  4211.         }
  4212.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'txRemSuppl') == false) {
  4213.             $colspan--;
  4214.             $tabColonneUser["txRemSuppl"] = 0;
  4215.         }
  4216.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'fraisAnnexes') == false) {
  4217.             $colspan--;
  4218.             $tabColonneUser["fraisAnnexes"] = 0;
  4219.         }
  4220.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'ecocontribution') == false) {
  4221.             $colspan--;
  4222.             $tabColonneUser["ecocontribution"] = 0;
  4223.         }
  4224.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'montantHt') == false) {
  4225.             $colspan--;
  4226.             $tabColonneUser["montantHt"] = 0;
  4227.         }
  4228.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'totalHT') == false) {
  4229.             $colspan--;
  4230.             $tabColonneUser["totalHT"] = 0;
  4231.         }
  4232.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'pump') == false) {
  4233.             $colspan--;
  4234.             $tabColonneUser["pump"] = 0;
  4235.         }
  4236.         if ($serviceColonne->getColonneUtilisateur($colonneUtilisateur'stock') == false) {
  4237.             $colspan--;
  4238.             $tabColonneUser["stock"] = 0;
  4239.         }
  4240.         foreach ($ids as $id) {
  4241.             if ( ! empty($qtes[$id])) {
  4242.                 $quantite floatval($qtes[$id]);
  4243.                 $article  $repo_article->find($id);
  4244.                 if (is_object($article)) {
  4245.                     if ($article->getDivers() == 1) {
  4246.                         /*
  4247.                         $articleTmp = clone $article;
  4248.                         $newRef = $articleTmp->getReference().'-'.time();
  4249.                         $articleTmp->setReference($newRef);
  4250.                         $articleTmp->setParent($article);
  4251.                         $articleTmp->setIdImport($article->getIdImport().'-duplique');
  4252.                         $em->persist($articleTmp);
  4253.                         $em->flush();
  4254.                         $article = $articleTmp;
  4255.                         */
  4256.                         $conn $em->getConnection();
  4257.                         $conn->getConfiguration()->setSQLLogger(null);
  4258.                         $tableau_donnee                    = [];
  4259.                         $tableau_donnee["reference"]       = $article->getReference()."-".time();
  4260.                         $tableau_donnee["ral_fournisseur"] = "0";
  4261.                         $tableau_donnee["parent_id"]       = $article->getId();
  4262.                         $tableau_donnee["libelle"]         = $article->getLibelle();
  4263.                         $tableau_donnee["reference_client"]      = $article->getReferenceClient();
  4264.                         $tableau_donnee["reference_fournisseur"] = $article->getReferenceFournisseur();
  4265.                         $tableau_donnee["prix_base"]             = $article->getPrixBase();
  4266.                         $dateTmp                                 = new \Datetime;
  4267.                         $tableau_donnee["date"]                  = $dateTmp->format("Y-m-d H:i:s");
  4268.                         if ($article->getDateMaj() != "") {
  4269.                             $tableau_donnee["date_maj"] = $article->getDateMaj()->format("Y-m-d H:i:s");
  4270.                         }
  4271.                         if ($article->getDateMajPrix() != "") {
  4272.                             $tableau_donnee["date_maj_prix"] = $article->getDateMajPrix()->format("Y-m-d H:i:s");
  4273.                         }
  4274.                         if ($article->getDateSuppression() != "") {
  4275.                             $tableau_donnee["date_supression"] = $article->getDateSuppression()->format("Y-m-d H:i:s");
  4276.                         }
  4277.                         if (is_object($article->getMarque())) {
  4278.                             $tableau_donnee["marque_id"] = $article->getMarque()->getId();
  4279.                         }
  4280.                         $tableau_donnee["description"]        = $article->getDescription();
  4281.                         $tableau_donnee["description_courte"] = $article->getDescriptionCourte();
  4282.                         $tableau_donnee["stock"]              = "0";
  4283.                         if ($article->getStatut() === true) {
  4284.                             $tableau_donnee["statut"] = 1;
  4285.                         } else {
  4286.                             $tableau_donnee["statut"] = 0;
  4287.                         }
  4288.                         $tableau_donnee["largeur"]    = $article->getLargeur();
  4289.                         $tableau_donnee["profondeur"] = $article->getProfondeur();
  4290.                         $tableau_donnee["hauteur"]    = $article->getHauteur();
  4291.                         $tableau_donnee["poids"]      = $article->getPoids();
  4292.                         if ($article->getAConsigner()) {
  4293.                             $tableau_donnee["a_consigner"] = 1;
  4294.                         } else {
  4295.                             $tableau_donnee["a_consigner"] = 0;
  4296.                         }
  4297.                         if ($article->getStockAuto()) {
  4298.                             $tableau_donnee["stock_auto"] = 1;
  4299.                         } else {
  4300.                             $tableau_donnee["stock_auto"] = 0;
  4301.                         }
  4302.                         if ($article->getArretGamme() === true) {
  4303.                             $tableau_donnee["arret_gamme"] = 1;
  4304.                         } else {
  4305.                             $tableau_donnee["arret_gamme"] = 0;
  4306.                         }
  4307.                         if (is_object($article->getUtilisateur())) {
  4308.                             $tableau_donnee["utilisateur_id"] = $article->getUtilisateur()->getId();
  4309.                         }
  4310.                         if (is_object($article->getRegleTaxe())) {
  4311.                             $tableau_donnee["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  4312.                         }
  4313.                         $tableau_donnee["remise_max"]            = $article->getRemiseMax();
  4314.                         $tableau_donnee["type_remise_max"]       = $article->getTypeRemiseMax();
  4315.                         $tableau_donnee["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  4316.                         $tableau_donnee["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  4317.                         if (is_object($article->getNiveauUn())) {
  4318.                             $tableau_donnee["niveau_un_id"] = $article->getNiveauUn()->getId();
  4319.                         }
  4320.                         if (is_object($article->getNiveauDeux())) {
  4321.                             $tableau_donnee["niveau_deux_id"] = $article->getNiveauDeux()->getId();
  4322.                         }
  4323.                         if (is_object($article->getNiveauTrois())) {
  4324.                             $tableau_donnee["niveau_trois_id"] = $article->getNiveauTrois()->getId();
  4325.                         }
  4326.                         if (is_object($article->getNiveauQuatre())) {
  4327.                             $tableau_donnee["niveau_quatre_id"] = $article->getNiveauQuatre()->getId();
  4328.                         }
  4329.                         $tableau_donnee["pump"]        = $article->getCpump();
  4330.                         $tableau_donnee["commentaire"] = $article->getCommentairePonctuel();
  4331.                         if ($article->getVirtuel()) {
  4332.                             $tableau_donnee["virtuel"] = 1;
  4333.                         } else {
  4334.                             $tableau_donnee["virtuel"] = 0;
  4335.                         }
  4336.                         //$tableau_donnee["prix_vente"]=$article->getLibelle();
  4337.                         $tableau_donnee["prix_vente"]      = 0;
  4338.                         $tableau_donnee["taux_marge"]      = $article->getTauxMarge();
  4339.                         $tableau_donnee["marge"]           = $article->getMarge();
  4340.                         $tableau_donnee["marge_reelle"]    = $article->getMargeReelle();
  4341.                         $tableau_donnee["ecotaxe"]         = $article->getEcotaxe();
  4342.                         $tableau_donnee["conditionnement"] = $article->getConditionnement();
  4343.                         $tableau_donnee["stock_reserve"]   = $article->getStockReserve();
  4344.                         if (is_object($article->getFournisseurDefaut())) {
  4345.                             $tableau_donnee["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  4346.                         }
  4347.                         $tableau_donnee["ral_fournisseur"] = "0";
  4348.                         $tableau_donnee["id_import"]       = "";
  4349.                         $tableau_donnee["donnees_import"]  = "";
  4350.                         if ($article->getMajPrix()) {
  4351.                             $tableau_donnee["maj_prix"] = 1;
  4352.                         } else {
  4353.                             $tableau_donnee["maj_prix"] = 0;
  4354.                         }
  4355.                         if (is_object($article->getUniteMesure())) {
  4356.                             $tableau_donnee["unite_mesure_id"] = $article->getUniteMesure()->getId();
  4357.                         }
  4358.                         if ($article->getAfficherComposantPdfInterne()) {
  4359.                             $tableau_donnee["afficher_composant_pdf_interne"] = 1;
  4360.                         } else {
  4361.                             $tableau_donnee["afficher_composant_pdf_interne"] = 0;
  4362.                         }
  4363.                         if ($article->getAfficherComposantPdfExterne()) {
  4364.                             $tableau_donnee["afficher_composant_pdf_externe"] = 1;
  4365.                         } else {
  4366.                             $tableau_donnee["afficher_composant_pdf_externe"] = 0;
  4367.                         }
  4368.                         if (is_object($article->getCategorieRemiseArticle())) {
  4369.                             $tableau_donnee["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  4370.                         }
  4371.                         $tableau_donnee["temporaire"]               = $article->getTemporaire();
  4372.                         $tableau_donnee["libelle_secondaire"]       = $article->getLibelleSecondaire();
  4373.                         $tableau_donnee["a_commander"]              = "1";
  4374.                         $tableau_donnee["a_fabriquer"]              = "0";
  4375.                         $tableau_donnee["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  4376.                         $tableau_donnee["quantite_conseillee"]      = $article->getQuantiteConseillee();
  4377.                         $tableau_donnee["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();
  4378.                         if ($article->getArchive() === true) {
  4379.                             $tableau_donnee["archive"] = 1;
  4380.                         } else {
  4381.                             $tableau_donnee["archive"] = 0;
  4382.                         }
  4383.                         $tableau_donnee["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  4384.                         $tableau_donnee["nom_web"]                      = $article->getNomWeb();
  4385.                         $tableau_donnee["reference_web"]                = $article->getReferenceWeb();
  4386.                         $tableau_donnee["reference_fournisseur_web"]    = $article->getReferenceFournisseurWeb();
  4387.                         $tableau_donnee["description_web"]              = $article->getDescriptionWeb();
  4388.                         $tableau_donnee["resume_web"]                   = $article->getResumeWeb();
  4389.                         $tableau_donnee["frais_ports_texte_web"]        = $article->getFraisPortsTexteWeb();
  4390.                         $tableau_donnee["message_qd_en_stock"]          = $article->getMessageQdEnStockWeb();
  4391.                         if (is_object($article->getArticleEnconsigne())) {
  4392.                             $tableau_donnee["article_enconsigne_id"] = $article->getArticleEnconsigne()->getId();
  4393.                         }
  4394.                         $tableau_donnee["reference_appel_1"]  = $article->getReferenceAppel1();
  4395.                         $tableau_donnee["reference_appel_2"]  = $article->getReferenceAppel2();
  4396.                         $tableau_donnee["reference_appel_3"]  = $article->getReferenceAppel3();
  4397.                         $tableau_donnee["reference_appel_4"]  = $article->getReferenceAppel4();
  4398.                         $tableau_donnee["reference_appel_5"]  = $article->getReferenceAppel5();
  4399.                         $tableau_donnee["reference_appel_6"]  = $article->getReferenceAppel6();
  4400.                         $tableau_donnee["reference_appel_7"]  = $article->getReferenceAppel7();
  4401.                         $tableau_donnee["reference_appel_8"]  = $article->getReferenceAppel8();
  4402.                         $tableau_donnee["reference_appel_9"]  = $article->getReferenceAppel9();
  4403.                         $tableau_donnee["reference_appel_10"] = $article->getReferenceAppel10();
  4404.                         $tableau_donnee["reference_appel_11"] = $article->getReferenceAppel11();
  4405.                         if ($article->getMainOeuvre() === true) {
  4406.                             $tableau_donnee["main_oeuvre"] = 1;
  4407.                         } else {
  4408.                             $tableau_donnee["main_oeuvre"] = 0;
  4409.                         }
  4410.                         $tableau_donnee["stock_reserve_fabrication"] = $article->getStockReserveFabrication();
  4411.                         if (is_object($article->getType())) {
  4412.                             $tableau_donnee["type_id"] = $article->getType()->getId();
  4413.                         }
  4414.                         if (is_object($article->getFamilleCompta())) {
  4415.                             $tableau_donnee["famille_compta_id"] = $article->getFamilleCompta()->getId();
  4416.                         }
  4417.                         if ($article->getPrestation()) {
  4418.                             $tableau_donnee["prestation"] = 1;
  4419.                         } else {
  4420.                             $tableau_donnee["prestation"] = 0;
  4421.                         }
  4422.                         if ($article->getNonStocke() === true) {
  4423.                             $tableau_donnee["non_stocke"] = 1;
  4424.                         } else {
  4425.                             $tableau_donnee["non_stocke"] = 0;
  4426.                         }
  4427.                         if ($article->getNonCommandable()) {
  4428.                             $tableau_donnee["non_commandable"] = 1;
  4429.                         } else {
  4430.                             $tableau_donnee["non_commandable"] = 0;
  4431.                         }
  4432.                         if (is_object($article->getParent())) {
  4433.                             $tableau_donnee["parent_id"] = $article->getParent()->getId();
  4434.                         }
  4435.                         $tableau_donnee["divers"] = $article->getDivers();
  4436.                         if ($article->getMouvemente() === true) {
  4437.                             $tableau_donnee["mouvemente"] = 1;
  4438.                         } else {
  4439.                             $tableau_donnee["mouvemente"] = 0;
  4440.                         }
  4441.                         if ($article->getNumSerieObligatoire()) {
  4442.                             $tableau_donnee["num_serie_obligatoire"] = 1;
  4443.                         } else {
  4444.                             $tableau_donnee["num_serie_obligatoire"] = 0;
  4445.                         }
  4446.                         if (is_object($article->getArticleRemplacement())) {
  4447.                             $tableau_donnee["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  4448.                         }
  4449.                         if ($article->getMajPoids()) {
  4450.                             $tableau_donnee["maj_poids"] = 1;
  4451.                         } else {
  4452.                             $tableau_donnee["maj_poids"] = 0;
  4453.                         }
  4454.                         if ($article->getMajPrixBase()) {
  4455.                             $tableau_donnee["maj_prix_base"] = 1;
  4456.                         } else {
  4457.                             $tableau_donnee["maj_prix_base"] = 0;
  4458.                         }
  4459.                         if ($article->getEstCommentaire()) {
  4460.                             $tableau_donnee["est_commentaire"] = 1;
  4461.                         } else {
  4462.                             $tableau_donnee["est_commentaire"] = 0;
  4463.                         }
  4464.                         $tableau_donnee["cond_achat"]     = $article->getConditionnementAchat();
  4465.                         $tableau_donnee["seuil_critique"] = $article->getSeuilCritique();
  4466.                         if (is_object($article->getRegleTaxeAchat())) {
  4467.                             $tableau_donnee["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
  4468.                         }
  4469.                         $conn->insert('article__article'$tableau_donnee);
  4470.                         $idNouveauArticle $conn->lastInsertId();
  4471.                         $article          $repo_article->find($idNouveauArticle);
  4472.                     }
  4473.                     $a                    = [];
  4474.                     $a['position']        = "";
  4475.                     $a['article']         = $article;
  4476.                     $a['ecocontribution'] = floatval($article->getEcocontribution());
  4477.                     $a['libelle']         = $article->getLibelle();
  4478.                     if ($quantite != '' && is_numeric($quantite)) {
  4479.                         $a['quantite'] = $quantite;
  4480.                         $a['ral']      = $quantite;
  4481.                     } else {
  4482.                         $a['quantite'] = "1";
  4483.                         $a['ral']      = "1";
  4484.                     }
  4485.                     //$a['estCommentaire']=$article->getEstCommentaire();
  4486.                     if ($article->getEstCommentaire()) {
  4487.                         $a['estCommentaire'] = 1;
  4488.                     } else {
  4489.                         $a['estCommentaire'] = 0;
  4490.                     }
  4491.                     $a['commentaire']          = "";
  4492.                     $a['commentaireSuppl']     = "";
  4493.                     $a['commentairePrive']     = "";
  4494.                     $a['remise']               = "0";
  4495.                     $a['remiseSupplementaire'] = "0";
  4496.                     $a['totalHt']              = $article->getPrixBase();
  4497.                     $a['prixBase']             = $article->getPrixBase();
  4498.                     //recuperer la condition d'achat par défaut
  4499.                     $repoConditionsAchat $em->getRepository(ConditionAchat::class);
  4500.                     //$condition = $repoConditionsAchat->findBy(array('article' => $article->getId(), 'defaut' => 1), array('id'=>'ASC'),1,0);
  4501.                     if ($fournisseur != '') {
  4502.                         $condition $repoConditionsAchat->findOneBy([
  4503.                                                                          'article'     => $article->getId(),
  4504.                                                                          'fournisseur' => $fournisseur,
  4505.                                                                          'defaut'      => 1,
  4506.                                                                      ]);
  4507.                     }
  4508.                     if ( ! isset($condition) || ! is_object($condition)) {
  4509.                         $condition $repoConditionsAchat->findOneBy([
  4510.                                                                          'article'     => $article->getId(),
  4511.                                                                          'fournisseur' => $fournisseur,
  4512.                                                                      ]);
  4513.                     }
  4514.                     /*
  4515.                             if(count($condition) > 0)
  4516.                                 $condition = $condition[0];
  4517.                             else
  4518.                                 $condition = $repoConditionsAchat->findOneBy(array('article' => $article->getId()));
  4519.                             *
  4520.                             */
  4521.                     $a['coefficientConditionnement'] = 1;
  4522.                     $a['fraisAnnexes']               = 0;
  4523.                     if (is_object($condition)) {
  4524.                         $a['coefficientConditionnement'] = $condition->getCoefficientConditionnement();
  4525.                         if ($condition->getTauxRemise() != '') {
  4526.                             $a['remise'] = $condition->getTauxRemise();
  4527.                         }
  4528.                         if ($condition->getTauxRemiseSupplementaire() != '') {
  4529.                             $a['remiseSupplementaire'] = $condition->getTauxRemiseSupplementaire();
  4530.                         }
  4531.                         if ($condition->getPrixAchatBrut() != '') {
  4532.                             //$a['prixBase']= $condition->getPrixAchatBrut() * $condition->getConditionnement() / $condition->getCoefficientConditionnement() ;
  4533.                             $a['prixBase'] = $condition->getPrixAchatBrut();
  4534.                         }
  4535.                         if ($condition->getLibelle() != '') {
  4536.                             $a['libelle'] = $condition->getLibelle();
  4537.                         }
  4538.                         if ($quantite != '' && is_numeric($quantite)) {
  4539.                             $a['quantite'] = $quantite;
  4540.                         } elseif ($condition->getQuantite() != '') {
  4541.                             $a['quantite'] = $condition->getQuantite();
  4542.                         }
  4543.                         $a['conditionAchat'] = $condition;
  4544.                         $a['fraisAnnexes']   = $condition->getFraisAnnexes();
  4545.                     }
  4546.                     $a['couleur'] = $articleService->getCouleurEtatStock($article$a['quantite']);
  4547.                     $fournisseur $repoFournisseur->find($fournisseur);
  4548.                     $taxe $repo_taxe->find(5);
  4549.                     if (is_object($fournisseur)) {
  4550.                         $taxe $fournisseurService->getTaxe($fournisseur$article);
  4551.                     }
  4552.                     $a['tva']  = $taxe->getTaux();
  4553.                     $a['taxe'] = $taxe;
  4554.                     $rendu .= $this->renderView('GestionComerciale/ArticleCommande/template_tr_fournisseur.html.twig', [
  4555.                         'a'              => $a,
  4556.                         'boucle'         => "0",
  4557.                         'numeroLigne'    => "0",
  4558.                         'fournisseur'    => $fournisseur,
  4559.                         'commandeId'     => $commandeId,
  4560.                         'tabColonneUser' => $tabColonneUser,
  4561.                     ]);
  4562.                     $commentairePonctuel .= $article->getCommentairePonctuel();
  4563.                 }
  4564.             }
  4565.         }
  4566.         return new JsonResponse(['rendu' => $rendu'commentairePonctuel' => $commentairePonctuel]);
  4567.     }
  4568.     /**
  4569.      * @Route("/article/conditionnement-achat/recherche", name="dtc_ajax_conditionnement_achat_recherche")
  4570.      */
  4571.     public function articleConditionnementAchatRechercheAction(Request $requestEntityManagerInterface $em)
  4572.     {
  4573.         $conditionnementsAchat = [];
  4574.         $q                     $request->request->get('q');
  4575.         if ($q != '') {
  4576.             $conditionnements $em->getRepository(ConditionnementAchat::class)->findByIdentifiant($q);
  4577.             if (count($conditionnements) > 0) {
  4578.                 foreach ($conditionnements as $conditionnement) {
  4579.                     $conditionnementsAchat[] = [
  4580.                         'article'  => $conditionnement->getArticle()->getId(),
  4581.                         'quantite' => $conditionnement->getQuantite(),
  4582.                     ];
  4583.                 }
  4584.             }
  4585.         }
  4586.         $response = new JsonResponse();
  4587.         $response->setData([
  4588.                                'conditionnements' => $conditionnementsAchat,
  4589.                            ]);
  4590.         return $response;
  4591.     }
  4592.     /**
  4593.      * @Route("/article/ajax/recherche", name="dtc_ajax_article_recherche")
  4594.      */
  4595.     public function articleAjaxRechercheAction(Request $requestEntityManagerInterface $em)
  4596.     {
  4597.         $articles = [];
  4598.         $q        $request->request->get('q');
  4599.         if ($q != '') {
  4600.             //$article = $em->getRepository('DTCArticlesBundle:Article')->findOneBy(array('reference'=>$q));
  4601.             $article $em->getRepository(Article::class)->getArticleParReference($q, ["mouvemente" => "1"]);
  4602.             if ( ! is_object($article)) {
  4603.                 $article $em->getRepository(Article::class)->getArticleParReference($q, ["mouvemente" => "0"]);
  4604.             }
  4605.             if (is_object($article)) {
  4606.                 $quantite 1;
  4607.                 if (count($article->getConditionnementAchatEan()) > 0) {
  4608.                     foreach ($article->getConditionnementAchatEan() as $condAchatEan) {
  4609.                         if ($condAchatEan->getIdentifiant() == $q) {
  4610.                             $quantite $condAchatEan->getQuantite();
  4611.                             break;
  4612.                         }
  4613.                     }
  4614.                 }
  4615.                 $articles[] = [
  4616.                     'article'  => $article->getId(),
  4617.                     'quantite' => $quantite,
  4618.                 ];
  4619.             }
  4620.         }
  4621.         $response = new JsonResponse();
  4622.         $response->setData([
  4623.                                'articles' => $articles,
  4624.                            ]);
  4625.         return $response;
  4626.     }
  4627.     /**
  4628.      * @Route("", name="")
  4629.      */
  4630.     public function __articleAjaxRechercheAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  4631.     {
  4632.         $articles = [];
  4633.         $q        $request->request->get('q');
  4634.         if ($q != '') {
  4635.             $article $em->getRepository(Article::class)->findOneBy(['reference' => $q]);
  4636.             if (is_object($article)) {
  4637.                 $articles[] = [
  4638.                     'article'  => $article->getId(),
  4639.                     'quantite' => 1,
  4640.                 ];
  4641.             }
  4642.         }
  4643.         $response = new JsonResponse();
  4644.         $response->setData([
  4645.                                'articles' => $articles,
  4646.                            ]);
  4647.         return $response;
  4648.     }
  4649.     /**
  4650.      * @Route("/commande/{commande}/recharger-numeros-serie", name="dtc_ajax_recharger_numeros_serie")
  4651.      */
  4652.     public function rechargerNumerosSerieAction(Request $requestCommande $commande)
  4653.     {
  4654.         $rendu $this->renderView('GestionComerciale/Commande/numeros-series.html.twig', [
  4655.             'commande' => $commande,
  4656.         ]);
  4657.         $response = new JsonResponse;
  4658.         $response->setData(["rendu" => $rendu]);
  4659.         return $response;
  4660.     }
  4661.     /**
  4662.      * @Route("/vente/commande/ajax/verifier-action/{id}", name="dtc_commande_verifier_action")
  4663.      */
  4664.     public function verifierActionAction(Request $requestCommande $commandeEntityManagerInterface $emTranslatorInterface $translator)
  4665.     {
  4666.         $action         $request->request->get('action');
  4667.         $statutCommande $commande->getStatutCommande();
  4668.         $valide         0;
  4669.         $rendu          '';
  4670.         //$erreur = '';
  4671.         if (is_object($statutCommande)) {
  4672.             switch ($action) {
  4673.                 case 'preparer':
  4674.                     if (in_array($statutCommande->getOrdre(), [112])) {
  4675.                         //à préparer, mise en attente préparation
  4676.                         $valide 1;
  4677.                     } else {
  4678.                         $this->addFlash('warning'$translator->trans('Le statut de commande actuel ne permet pas cette action!'));
  4679.                     }
  4680.                     break;
  4681.                 case 'emballer':
  4682.                     if (in_array($statutCommande->getOrdre(), [313])) {
  4683.                         //préparé, mise en attente emballage
  4684.                         $valide 1;
  4685.                     } else {
  4686.                         $this->addFlash('warning'$translator->trans('Le statut de commande actuel ne permet pas cette action!'));
  4687.                     }
  4688.                     break;
  4689.             }
  4690.         }
  4691.         if ( ! $valide) {
  4692.             $rendu $this->renderView('layout-errors.html.twig', [//'erreur' => array('test'),
  4693.             ]);
  4694.         }
  4695.         $response = new JsonResponse;
  4696.         $response->setData(["valide" => $valide'rendu' => $rendu]);
  4697.         return $response;
  4698.     }
  4699.     /**
  4700.      * @Route("/commande-article/recharger/tva", name="dtc_recharger_tva_article_commande")
  4701.      */
  4702.     public function rechargerTvaLigneArticleCommandeAction(Request $requestEntityManagerInterface $emArticleService $serviceArticle)
  4703.     {
  4704.         $articlesIds $request->query->get('articlesIds');
  4705.         $id_client   $request->query->get('id_client');
  4706.         $id_adresse  $request->query->get('id_adresse');
  4707.         $code_iso    $request->query->get('code_iso');
  4708.         $client      '';
  4709.         $adresse     '';
  4710.         if ( ! empty($id_adresse)) {
  4711.             $adresse $em->getRepository(Adresse::class)->find($id_adresse);
  4712.         }
  4713.         if ( ! empty($id_client)) {
  4714.             $client $em->getRepository(Client::class)->find($id_client);
  4715.         }
  4716.         $repo_article $em->getRepository(Article::class);
  4717.         $taxes = [];
  4718.         if (is_array($articlesIds) && count($articlesIds)) {
  4719.             foreach ($articlesIds as $articleId) {
  4720.                 if (empty($taxes[$articleId])) {
  4721.                     $article $repo_article->find($articleId);
  4722.                     if (is_object($article)) {
  4723.                         $taxe $serviceArticle->getTaxe($article$client$adresse);
  4724.                         if (is_object($taxe)) {
  4725.                             $taxes[$articleId] = ['id' => $taxe->getId(), 'taux' => $taxe->getTaux()];
  4726.                         }
  4727.                     }
  4728.                 }
  4729.             }
  4730.         }
  4731.         $taxeCommandeRetour = ['id' => '''taux' => ''];
  4732.         $taxeCommande       $serviceArticle->getTaxe(''$client$adresse$code_iso);
  4733.         if (is_object($taxeCommande)) {
  4734.             $taxeCommandeRetour = ['id' => $taxeCommande->getId(), 'taux' => $taxeCommande->getTaux()];
  4735.         }
  4736.         return new JsonResponse([
  4737.                                     'taxes'        => $taxes,
  4738.                                     'taxeCommande' => $taxeCommandeRetour,
  4739.                                 ]
  4740.         );
  4741.     }
  4742.     /**
  4743.      * @Route("/commande/copies-lignes/{id}", name="dtc_commande_copies_lignes")
  4744.      */
  4745.     public function copiesLignesAction(Request        $requestCommande $commandeEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator,
  4746.                                        ArticleService $articleServiceCommandeService $commandeService
  4747.     ) {
  4748.         $titre_modal "Copies lignes";
  4749.         $get         $request->query->all();
  4750.         //$ids=$get['ids'];
  4751.         $copieLigne = new Commande();
  4752.         //print_r($ids);
  4753.         $form   $this->createForm(CopiesLignesType::class, $copieLigne);
  4754.         $errors "";
  4755.         $form->handleRequest($request);
  4756.         $tab_lignes            = [];
  4757.         $repo_article_commande $em->getRepository(ArticleCommande::class);
  4758.         $tab_lignes $repo_article_commande->findBy(["commande" => $commande]);
  4759.         if ($form->isSubmitted()) {
  4760.             $form_valide false;
  4761.             $post        $request->request->all();
  4762.             $url         "";
  4763.             //print_r($post);
  4764.             //exit;
  4765.             if ( ! empty($post["choixCopie"]) && ! empty($post["articleCopies"])) {
  4766.                 $form_valide true;
  4767.             }
  4768.             if ( ! $form_valide) {
  4769.                 $error = new FormError("Vous devez sélectionnez au moins une ligne à copier !");
  4770.                 $form->get('reference')->addError($error);
  4771.             } else {
  4772.             }
  4773.             if ($form->isValid()) {
  4774.                 if ( ! empty($post["choixCopie"])) {
  4775.                     $tabCopies = [];
  4776.                     if (count($post["articleCopies"])) {
  4777.                         foreach ($post["articleCopies"] as $copie) {
  4778.                             $tabCopies["articles"]["idArticleCommande"][] = $copie;
  4779.                         }
  4780.                     }
  4781.                     //http://lbdp.local.tl/app_dev.php/vente/comptoir/nouveau?forceEnregistrement=devis&copies[articles][idArticleCommande][0]=802433&copies[articles][idArticleCommande][1]=802434
  4782.                     if ($post["choixCopie"] == "devis") {
  4783.                         $url $this->generateUrl('dtc_comptoir_ajouter', ["forceEnregistrement" => "devis""copies" => $tabCopies]);
  4784.                     } elseif ($post["choixCopie"] == "commande") {
  4785.                         $url $this->generateUrl('dtc_comptoir_ajouter', ["forceEnregistrement" => "commande""copies" => $tabCopies]);
  4786.                     } elseif ($post["choixCopie"] == "existant") {
  4787.                         $repo_commande $em->getRepository(Commande::class);
  4788.                         $commande_obj  $repo_commande->find($post["doc_existant_id"]);
  4789.                         if (is_object($commande_obj) && is_object($commande_obj->getTypeDocumentCommercial())) {
  4790.                             $copies           $tabCopies;
  4791.                             $lancerSauvegarde false;
  4792.                             /*
  4793.                                     COPIES DE LIGNE DEPUIS UN AUTRE DEVIS / COMMANDE
  4794.                                 */
  4795.                             //echo "YYYYYYY";
  4796.                             $tab_article_commande_copies = [];
  4797.                             if ($copies != '') {
  4798.                                 $repo_article_commande $em->getRepository(ArticleCommande::class);
  4799.                                 $positionDepart        count($commande_obj->getArticleCommande());
  4800.                                 if ( ! empty($this->getParameter('article_frais_facturation'))) {
  4801.                                     $position_ff $positionDepart count($copies['articles']['idArticleCommande']);
  4802.                                     $ac_ff_obj   $repo_article_commande->findOneBy(["article" => $this->getParameter('article_frais_facturation'), "commande" => $commande_obj]);
  4803.                                     if (is_object($ac_ff_obj)) {
  4804.                                         $positionDepart--;
  4805.                                         $conn                      $em->getConnection();
  4806.                                         $tableau_donnee_article_ff = ["position" => $position_ff];
  4807.                                         $conn->update('commerciale__article_commande'$tableau_donnee_article_ff, ['id' => $ac_ff_obj->getId()]);
  4808.                                     }
  4809.                                 }
  4810.                                 for ($i 0$i count($copies['articles']['idArticleCommande']); $i++) {
  4811.                                     $articleCommandeClone $repo_article_commande->find($copies['articles']['idArticleCommande'][$i]);
  4812.                                     //echo "lll===>".$articleCommandeClone->getLibelle();
  4813.                                     //exit;
  4814.                                     if (is_object($articleCommandeClone)) {
  4815.                                         //$forceEnregistrement = true;
  4816.                                         $lancerSauvegarde true;
  4817.                                         $articleCommande  = new ArticleCommande();
  4818.                                         $articleCommande->setArticle($articleCommandeClone->getArticle());
  4819.                                         $articleCommande->setLibelle($articleCommandeClone->getLibelle());
  4820.                                         $articleCommande->setLibelleSecondaire($articleCommandeClone->getLibelleSecondaire());
  4821.                                         $articleCommande->setPrixBase($articleCommandeClone->getPrixBase());
  4822.                                         $articleCommande->setQuantite($articleCommandeClone->getQuantite());
  4823.                                         //$articleCommande->setRal($articleCommandeClone->getQuantite());
  4824.                                         $articleCommande->setRalClient($articleCommandeClone->getQuantite());
  4825.                                         $articleCommande->setRemise($articleCommandeClone->getRemise());
  4826.                                         $articleCommande->setCommentaire($articleCommandeClone->getCommentaire());
  4827.                                         $articleCommande->setCommentaireSuppl($articleCommandeClone->getCommentaireSuppl());
  4828.                                         $articleCommande->setCommentairePrive($articleCommandeClone->getCommentairePrive());
  4829.                                         $articleCommande->setEcocontribution($articleCommandeClone->getEcocontribution());
  4830.                                         $articleCommande->setRemiseSupplementaire($articleCommandeClone->getRemiseSupplementaire());
  4831.                                         $articleCommande->setDate(new \DateTime());
  4832.                                         $articleCommande->setDateMaj(new \DateTime());
  4833.                                         $articleCommande->setDateLivraisonTheorique(null);
  4834.                                         $articleCommande->setTransporteur(null);
  4835.                                         $articleCommande->setFraisPort(0);
  4836.                                         $articleCommande->setLitige(null);
  4837.                                         $articleCommande->setPosition($i $positionDepart);
  4838.                                         $articleCommande->setDevis(null);
  4839.                                         $articleCommande->setFabrication(null);
  4840.                                         $articleCommande->setArticleCommande(null);
  4841.                                         $articleCommande->setArticleCommandeParent(null);
  4842.                                         $articleCommande->setConditionAchat(null);
  4843.                                         //$articleCommande->setidFusion(NULL);
  4844.                                         $articleCommande->setRemiseInitial(null);
  4845.                                         $articleCommande->setArticleAssocie(null);
  4846.                                         $articleCommande->setQuantiteReprise(0);
  4847.                                         $articleCommande->setQuantiteDejaPreparee(0);
  4848.                                         $articleCommande->setQuantiteDejaPrepareeSimplifie(0);
  4849.                                         $articleCommande->setForce(0);
  4850.                                         $articleCommande->setCommande(null);
  4851.                                         $articleCommande->setPoids($articleCommandeClone->getPoids());
  4852.                                         $articleCommande->setTotalHt($articleCommandeClone->getTotalHt());
  4853.                                         $articleCommande->setTva($articleCommandeClone->getTva());
  4854.                                         $articleCommande->setResteAreprendre($articleCommandeClone->getquantite());
  4855.                                         $articleCommande->setTaxe($articleCommandeClone->getTaxe());
  4856.                                         $articleCommande->setQuantiteDispo($articleCommandeClone->getQuantiteDispo());
  4857.                                         $articleCommande->setCoefficientConditionnement($articleCommandeClone->getCoefficientConditionnement());
  4858.                                         $articleCommande->setArticleCommandeAssocie(null);
  4859.                                         $tab_article_commande_copies[] = $articleCommandeClone;
  4860.                                         $commande_obj->addArticleCommande($articleCommande);
  4861.                                         $articleCommande->setCommande($commande_obj);
  4862.                                         $em->persist($articleCommande);
  4863.                                         if ($commande_obj->getTypeDocumentCommercial() == TypeDocumentCommercial::COMMANDE) {
  4864.                                             $article               $articleCommande->getArticle();
  4865.                                             $reserveDiversComposes = ! $article->getDiversComposes() || ($article->getDiversComposes() && $article->getNomenclatureValidee());
  4866.                                             //if($reservationPrestashop && $premiereReservationPrestashop && ($operation == "commande" || $operation == "bp") && $reserveDiversComposes) {
  4867.                                             if ($reserveDiversComposes) {
  4868.                                                 if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre(
  4869.                                                     ) == true) {
  4870.                                                     $article->setStockReserve(0);
  4871.                                                     if ($article->getProduitInterne() == true) {
  4872.                                                         $variation floatval($articleCommande->getQuantite());
  4873.                                                         $articleService->modifierStockReserveComposants($article$variation);
  4874.                                                     }
  4875.                                                 } elseif (floatval($articleCommande->getQuantite()) != 0) {
  4876.                                                     //$commande->setCommentaire('tt '.$article->getStockReserve().' / '.$a->getQuantite());
  4877.                                                     $article->setStockReserve(floatval($article->getStockReserve()) + floatval($articleCommande->getQuantite()));
  4878.                                                 }
  4879.                                                 $em->persist($article);
  4880.                                             }
  4881.                                             $commande_obj->setStatutAmodifier(1);
  4882.                                         }
  4883.                                     }
  4884.                                 }
  4885.                             }
  4886.                             if (count($tab_article_commande_copies) > 0) {
  4887.                                 foreach ($tab_article_commande_copies as $copie) {
  4888.                                     $commandeService->creerHistorique(
  4889.                                         $commande_obj,
  4890.                                         'copie-ligne',
  4891.                                         [
  4892.                                             "message" => " - Ajout de l'article ".$copie->getArticle()->getReference()." depuis ".$copie->getCommande()->getReference(),
  4893.                                         ]
  4894.                                     );
  4895.                                 }
  4896.                             }
  4897.                             $em->flush();
  4898.                             if ($commande_obj->getTypeDocumentCommercial() == TypeDocumentCommercial::DEVIS) {
  4899.                                 $url $this->generateUrl('dtc_devis_modifier', ["id" => $commande_obj->getId(), 'sauvegarde' => 1]);
  4900.                             } elseif ($commande_obj->getTypeDocumentCommercial() == TypeDocumentCommercial::COMMANDE) {
  4901.                                 $url $this->generateUrl('dtc_commande_modifier', ["id" => $commande_obj->getId(), 'sauvegarde' => 1]);
  4902.                             }
  4903.                         }
  4904.                     }
  4905.                 }
  4906.                 $this->addFlash('notice'$translator->trans('Lignes copiées avec succès !'));
  4907.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  4908.             } else {
  4909.                 $errors $validator->validate($copieLigne);
  4910.                 $rendu $this->renderView(
  4911.                     'GestionComerciale/ArticleCommande/copies_lignes.html.twig',
  4912.                     ['tabLignes' => $tab_lignes'form' => $form->createView(), 'errors' => $errors]
  4913.                 );
  4914.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  4915.             }
  4916.         }
  4917.         $rendu $this->renderView('GestionComerciale/ArticleCommande/copies_lignes.html.twig', [
  4918.             'tabLignes' => $tab_lignes,
  4919.             'form'      => $form->createView(),
  4920.             'errors'    => $errors,
  4921.         ]);
  4922.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal'width' => 900]);
  4923.     }
  4924. }