src/Service/Articles/ArticleService.php line 6845

Open in your IDE?
  1. <?php
  2. namespace App\Service\Articles;
  3. use App\Entity\Articles\ArticleCategorie;
  4. use App\Entity\Articles\ArticleComposant;
  5. use App\Entity\Articles\Categorie;
  6. use App\Entity\Articles\Colis;
  7. use App\Entity\Articles\Concurrence;
  8. use App\Entity\Articles\ConditionVente;
  9. use App\Entity\Articles\Declinaison;
  10. use App\Entity\Articles\Devise;
  11. use App\Entity\Articles\Document;
  12. use App\Entity\Articles\Image;
  13. use App\Entity\Articles\NumeroSerie;
  14. use App\Entity\Articles\PrixDegressif;
  15. use App\Entity\Articles\PrixPromo;
  16. use App\Entity\Articles\RaisonMouvementStock;
  17. use App\Entity\Articles\ValeurAttributArticle;
  18. use App\Entity\Clients\Client;
  19. use App\Entity\FO\Parametrage;
  20. use App\Entity\GestionComerciale\Fabrication;
  21. use App\Entity\Localisation\Zone;
  22. use App\Entity\MarketPlace\ArticleMarketPlace;
  23. use App\Entity\MarketPlace\ArticleMarketPlaceImage;
  24. use App\Entity\MarketPlace\CompteMarketPlace;
  25. use App\Entity\Notes\Note;
  26. use App\Entity\QrCode\QrCode;
  27. use App\Entity\Rangements\Emplacement;
  28. use App\Entity\Remises\Remise;
  29. use App\Entity\Taxes\RegleTaxe;
  30. use App\Entity\Taxes\RegleTaxePays;
  31. use App\Entity\Taxes\Taxe;
  32. use App\Entity\Vehicules\Application;
  33. use App\Model\GestionCommerciale\TypeDocumentCommercial;
  34. use App\Service\Clients\ClientService;
  35. use App\Service\MarketPlace\EbayService;
  36. use Doctrine\ORM\EntityManagerInterface;
  37. use App\Entity\Articles\Article;
  38. use App\Entity\GestionComerciale\ArticleCommande;
  39. use App\Entity\GestionComerciale\Commande;
  40. use App\Entity\GestionComerciale\CommandeFournisseur;
  41. use App\Entity\Articles\ConditionAchat;
  42. use App\Entity\Articles\MouvementStock;
  43. use App\Entity\Fournisseurs\Fournisseur;
  44. use App\Entity\FO\Cron;
  45. use App\Entity\Articles\HistoriqueArticle;
  46. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  47. use Symfony\Component\Security\Core\Security;
  48. class ArticleService
  49. {
  50.     private $entityManager;
  51.     private Security $security;
  52.     private MouvementStockService $mouvementStockService;
  53.     private ClientService $clientService;
  54.     private EbayService $ebayService;
  55.     private ImageArticleService $imageArticleService;
  56.     private DocumentArticle $documentArticleService;
  57.     private UrlGeneratorInterface $urlGenerator;
  58.     public function __construct(EntityManagerInterface $entityManagerSecurity $securityMouvementStockService $mouvementStockServiceClientService $clientService,
  59.                                 EbayService            $ebayServiceImageArticleService $imageArticleServiceDocumentArticle $documentArticleServiceUrlGeneratorInterface $urlGenerator
  60.     ) {
  61.         $this->entityManager          $entityManager;
  62.         $this->security               $security;
  63.         $this->mouvementStockService  $mouvementStockService;
  64.         $this->clientService          $clientService;
  65.         $this->ebayService            $ebayService;
  66.         $this->imageArticleService    $imageArticleService;
  67.         $this->documentArticleService $documentArticleService;
  68.         $this->urlGenerator           $urlGenerator;
  69.     }
  70.     public function estArchivable($id)
  71.     {
  72.         $class $this->couleurLigne($id);
  73.         if ($class == "info") {
  74.             return true;
  75.         }
  76.         return false;
  77.     }
  78.     public function getObjet($id)
  79.     {
  80.         $article $this->entityManager->getRepository(Article::class)->find($id);
  81.         return $article;
  82.     }
  83.     public function couleurLigne($articleId)
  84.     {
  85.         $repo_article_market_place $this->entityManager->getRepository(ArticleMarketPlace::class);
  86.         $repo_compte_market_place  $this->entityManager->getRepository(CompteMarketPlace::class);
  87.         $compteMarketPlace         $repo_compte_market_place->findAll();
  88.         $nbAnnonces                     $repo_article_market_place->getNbAnnoncesParArticle($articleId);
  89.         $nbAnnoncesPubliees             $repo_article_market_place->getNbAnnoncesPublieesParArticle($articleId);
  90.         $unCompteMarketPlaceSansAnnonce $repo_article_market_place->unCompteMarketPlaceSansAnnonce($articleId);
  91.         $class 'warning';
  92.         if ($nbAnnoncesPubliees['total'] == || $unCompteMarketPlaceSansAnnonce) {
  93.             $class 'danger';
  94.         } elseif ($nbAnnonces['total'] == $nbAnnoncesPubliees['total']) {
  95.             $class 'success';
  96.         }
  97.         $couleurBleu             true;
  98.         $auMoinsUneAnnoncePublie false;
  99.         foreach ($compteMarketPlace as $cmp) {
  100.             if ($cmp->getId() != 6) {
  101.                 $total  $repo_article_market_place->getNbAnnoncesPublieesParArticleEtCompteMarketPlace($articleId$cmp);
  102.                 $total2 $repo_article_market_place->getNbAnnoncesParArticleEtCompteMarketPlace($articleId$cmp);
  103.                 //$nbAnnonces = $repo_article_market_place->getNbAnnoncesParArticleEtCompteMarketPlace($articleId, $compteMarketPlaceId);
  104.                 if ($total["total"] > && $total2["total"] > 0) {
  105.                     $couleurBleu false;
  106.                 }
  107.                 if ($total2["total"] > 0) {
  108.                     $auMoinsUneAnnoncePublie true;
  109.                 }
  110.                 //echo "<div>CMP : ".$cmp->getLibelle()."</div>";
  111.                 //echo "<div>getNbAnnoncesPublieesParArticleEtMarketPlace : ".$total["total"]."</div>";
  112.                 //echo "<div>getNbAnnoncesParArticleEtMarketPlace : ".$total2["total"]."</div>";
  113.             }
  114.         }
  115.         if ($couleurBleu && $auMoinsUneAnnoncePublie && ! $unCompteMarketPlaceSansAnnonce) {
  116.             $class 'info';
  117.         }
  118.         $infosDebug ' '.$nbAnnonces['total'].'/'.$nbAnnoncesPubliees['total'];
  119.         //$class .= ' nbAnnonces-'.$nbAnnonces['total'].' nbAnnoncesPubliees-'.$nbAnnoncesPubliees['total'].' unCompteMarketPlaceSansAnnonce-'.$unCompteMarketPlaceSansAnnonce;
  120.         //$class = 'info';
  121.         return $class;
  122.     }
  123.     public function testReferenceArticleExiste($reference "")
  124.     {
  125.         if ($reference == "") {
  126.             return true;
  127.         } else {
  128.             $repo_article $this->entityManager->getRepository(Article::class);
  129.             $existe       $repo_article->testReferenceArticleExiste($reference);
  130.             if (count($existe) == 1) {
  131.                 if ($existe[0]["total"] == "0") {
  132.                     return false;
  133.                 }
  134.             }
  135.         }
  136.         return true;
  137.     }
  138.     public function majDeclinaison($id_article_enfant$article)
  139.     {
  140.         $date            = new \Datetime();
  141.         $repo_valeurs    $this->entityManager->getRepository(ValeurAttributArticle::class);
  142.         $repo_article    $this->entityManager->getRepository(Article::class);
  143.         $repo_cond_vente $this->entityManager->getRepository(ConditionVente::class);
  144.         $parametrage     $this->entityManager->getRepository(Parametrage::class)->find(1);
  145.         $regles $parametrage->getReglesDeclinaisonUnserialize();
  146.         $tableau_update = [];
  147.         $tableau_update["reference_client"]      = $article->getReferenceClient();
  148.         $tableau_update["reference_fournisseur"] = null;
  149.         if (array_key_exists('copier_ref_fournisseur'$regles) && $regles["copier_ref_fournisseur"] == "1") {
  150.             $tableau_update["reference_fournisseur"] = $article->getReferenceFournisseur();
  151.         }
  152.         $tableau_update["prix_base"] = $article->getPrixBase();
  153.         if (is_object($article->getMarque())) {
  154.             $tableau_update["marque_id"] = $article->getMarque()->getId();
  155.         } else {
  156.             $tableau_update["marque_id"] = null;
  157.         }
  158.         $tableau_update["date_maj"] = $date->format("Y-m-d H:i:s");
  159.         if (array_key_exists('copier_desc'$regles) && $regles["copier_desc"] == "1") {
  160.             $tableau_update["description"] = $article->getDescription();
  161.         }
  162.         if (array_key_exists('copier_desc_courte'$regles) && $regles["copier_desc_courte"] == "1") {
  163.             $tableau_update["description_courte"] = $article->getDescriptionCourte();
  164.         }
  165.         if (array_key_exists('copier_dim'$regles) && $regles["copier_dim"] == "1") {
  166.             $tableau_update["largeur"]    = $article->getLargeur();
  167.             $tableau_update["profondeur"] = $article->getProfondeur();
  168.             $tableau_update["hauteur"]    = $article->getHauteur();
  169.             $tableau_update["poids"]      = $article->getPoids();
  170.         }
  171.         if ($article->getStatut()) {
  172.             $tableau_update["statut"] = 1;
  173.         } else {
  174.             $tableau_update["statut"] = 0;
  175.         }
  176.         if ($article->getAConsigner()) {
  177.             $tableau_update["a_consigner"] = 1;
  178.         } else {
  179.             $tableau_update["a_consigner"] = 0;
  180.         }
  181.         if ($article->getConsigne()) {
  182.             $tableau_update["consigne"] = 1;
  183.         } else {
  184.             $tableau_update["consigne"] = 0;
  185.         }
  186.         if ($article->getStockAuto()) {
  187.             $tableau_update["stock_auto"] = 1;
  188.         } else {
  189.             $tableau_update["stock_auto"] = 0;
  190.         }
  191.         if ($article->getArretGamme()) {
  192.             $tableau_update["arret_gamme"] = 1;
  193.         } else {
  194.             $tableau_update["arret_gamme"] = 0;
  195.         }
  196.         if (is_object($article->getRegleTaxe())) {
  197.             $tableau_update["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  198.         } else {
  199.             $tableau_update["regle_taxe_id"] = 1;
  200.         }
  201.         $tableau_update["remise_max"]            = $article->getRemiseMax();
  202.         $tableau_update["type_remise_max"]       = $article->getTypeRemiseMax();
  203.         $tableau_update["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  204.         $tableau_update["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  205.         $tableau_update["niveau_un_id"]          = null;
  206.         $tableau_update["niveau_deux_id"]        = null;
  207.         $tableau_update["niveau_trois_id"]       = null;
  208.         $tableau_update["niveau_quatre_id"]      = null;
  209.         $tableau_update["commentaire"] = $article->getCommentairePonctuel();
  210.         if ($article->getVirtuel()) {
  211.             $tableau_update["virtuel"] = 1;
  212.         } else {
  213.             $tableau_update["virtuel"] = 0;
  214.         }
  215.         $tableau_update["prix_vente"]      = $article->getPrixVente();
  216.         $tableau_update["taux_marge"]      = $article->getTauxMarge();
  217.         $tableau_update["marge"]           = $article->getMarge();
  218.         $tableau_update["marge_reelle"]    = $article->getMargeReelle();
  219.         $tableau_update["ecotaxe"]         = $article->getEcotaxe();
  220.         $tableau_update["conditionnement"] = $article->getConditionnement();
  221.         if (is_object($article->getFournisseurDefaut())) {
  222.             $tableau_update["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  223.         } else {
  224.             $tableau_update["fournisseur_defaut_id"] = null;
  225.         }
  226.         $tableau_update["id_import"] = null;
  227.         if ($article->getProduitInterne()) {
  228.             $tableau_update["produit_interne"] = 1;
  229.         } else {
  230.             $tableau_update["produit_interne"] = 0;
  231.         }
  232.         $tableau_update["donnees_import"] = null;
  233.         if ($article->getMajPrix()) {
  234.             $tableau_update["maj_prix"] = 1;
  235.         } else {
  236.             $tableau_update["maj_prix"] = 0;
  237.         }
  238.         if (is_object($article->getUniteMesure())) {
  239.             $tableau_update["unite_mesure_id"] = $article->getUniteMesure()->getId();
  240.         } else {
  241.             $tableau_update["unite_mesure_id"] = null;
  242.         }
  243.         if ($article->getAfficherComposantPdfInterne()) {
  244.             $tableau_update["afficher_composant_pdf_interne"] = 1;
  245.         } else {
  246.             $tableau_update["afficher_composant_pdf_interne"] = 0;
  247.         }
  248.         if ($article->getAfficherComposantPdfExterne()) {
  249.             $tableau_update["afficher_composant_pdf_externe"] = 1;
  250.         } else {
  251.             $tableau_update["afficher_composant_pdf_externe"] = 0;
  252.         }
  253.         if (is_object($article->getCategorieRemiseArticle())) {
  254.             $tableau_update["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  255.         } else {
  256.             $tableau_update["categorie_remise_article_id"] = null;
  257.         }
  258.         $tableau_update["libelle_secondaire"]       = $article->getLibelleSecondaire();
  259.         $tableau_update["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  260.         $tableau_update["quantite_conseillee"]      = $article->getQuantiteConseillee();
  261.         $tableau_update["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();;
  262.         $tableau_update["archive"]                      = 0;
  263.         $tableau_update["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  264.         $tableau_update["reference_appel_1"]  = $article->getReferenceAppel1();
  265.         $tableau_update["reference_appel_2"]  = $article->getReferenceAppel2();
  266.         $tableau_update["reference_appel_3"]  = $article->getReferenceAppel3();
  267.         $tableau_update["reference_appel_4"]  = $article->getReferenceAppel4();
  268.         $tableau_update["reference_appel_5"]  = $article->getReferenceAppel5();
  269.         $tableau_update["reference_appel_6"]  = $article->getReferenceAppel6();
  270.         $tableau_update["reference_appel_7"]  = $article->getReferenceAppel7();
  271.         $tableau_update["reference_appel_8"]  = $article->getReferenceAppel8();
  272.         $tableau_update["reference_appel_9"]  = $article->getReferenceAppel9();
  273.         $tableau_update["reference_appel_10"] = $article->getReferenceAppel10();
  274.         //$tableau_update["reference_appel_11"]=$tab_declinaison["reference"];
  275.         if ($article->getMainOeuvre()) {
  276.             $tableau_update["main_oeuvre"] = 1;
  277.         } else {
  278.             $tableau_update["main_oeuvre"] = 0;
  279.         }
  280.         if (is_object($article->getType())) {
  281.             $tableau_update["type_id"] = $article->getType()->getId();
  282.         } else {
  283.             $tableau_update["type_id"] = null;
  284.         }
  285.         if (is_object($article->getFamilleCompta())) {
  286.             $tableau_update["famille_compta_id"] = $article->getFamilleCompta()->getId();
  287.         } else {
  288.             $tableau_update["famille_compta_id"] = null;
  289.         }
  290.         if ($article->getPrestation()) {
  291.             $tableau_update["prestation"] = 1;
  292.         } else {
  293.             $tableau_update["prestation"] = 0;
  294.         }
  295.         if ($article->getNonStocke()) {
  296.             $tableau_update["non_stocke"] = 1;
  297.         } else {
  298.             $tableau_update["non_stocke"] = 0;
  299.         }
  300.         if ($article->getNonCommandable()) {
  301.             $tableau_update["non_commandable"] = 1;
  302.         } else {
  303.             $tableau_update["non_commandable"] = 0;
  304.         }
  305.         if ($article->getNumSerieObligatoire()) {
  306.             $tableau_update["num_serie_obligatoire"] = 1;
  307.         } else {
  308.             $tableau_update["num_serie_obligatoire"] = 0;
  309.         }
  310.         if (is_object($article->getArticleRemplacement())) {
  311.             $tableau_update["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  312.         } else {
  313.             $tableau_update["article_remplacement_id"] = null;
  314.         }
  315.         $tableau_update["cond_achat"]      = $article->getConditionnementAchat();
  316.         $tableau_update["est_commentaire"] = 0;
  317.         $tableau_update["seuil_critique"]  = $article->getSeuilCritique();
  318.         if (is_object($article->getRegleTaxeAchat())) {
  319.             $tableau_update["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
  320.         } else {
  321.             $tableau_update["regle_taxe_achat_id"] = null;
  322.         }
  323.         if ($article->getUniversel()) {
  324.             $tableau_update["universel"] = 1;
  325.         } else {
  326.             $tableau_update["universel"] = 0;
  327.         }
  328.         $tableau_update["delai_reappro"]          = $article->getDelaiReappro();
  329.         $tableau_update["prix_revient"]           = $article->getPrixRevient();
  330.         $tableau_update["frais_fonctionnement"]   = $article->getFraisFonctionnement();
  331.         $tableau_update["nomenclature_douaniere"] = $article->getNomenclatureDouaniere();
  332.         $tableau_update["unspsc"]                 = $article->getUnspsc();
  333.         if (is_object($article->getTransporteur())) {
  334.             $tableau_update["transporteur_id"] = $article->getTransporteur()->getId();
  335.         } else {
  336.             $tableau_update["transporteur_id"] = null;
  337.         }
  338.         if (is_object($article->getAtelier())) {
  339.             $tableau_update["atelier_id"] = $article->getAtelier()->getId();
  340.         } else {
  341.             $tableau_update["atelier_id"] = null;
  342.         }
  343.         $tableau_update["commentaire_dimensions"] = $article->getCommentaireDimensions();
  344.         $tableau_update["ecocontribution"]        = $article->getEcocontribution();
  345.         if (is_object($article->getFamilleCompta())) {
  346.             $tableau_update['famille_compta_id'] = $article->getFamilleCompta()->getId();
  347.         }
  348.         //$tableau_update['reference'] = $tab_declinaison["reference"];
  349.         //$tableau_update['libelle'] = $tab_declinaison["libelle"];
  350.         $tableau_update['article_declinaison_parent_id'] = $article->getId();
  351.         $conn $this->entityManager->getConnection();
  352.         $conn->update('article__article'$tableau_update, ['id' => $id_article_enfant]);
  353.         $id_article $id_article_enfant;
  354.         if ($id_article != "") {
  355.             $articleClone $repo_article->find($id_article);
  356.             if (is_object($articleClone) && array_key_exists('copier_images'$regles) && $regles["copier_images"] == "1") {
  357.                 $repo_article_image $this->entityManager->getRepository(Image::class);
  358.                 $images_article     $repo_article_image->findBy(["article" => $article]);
  359.                 $sql  "DELETE FROM `article__image` WHERE article_id=".$id_article."";
  360.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  361.                 $stmt->execute();
  362.                 exec(
  363.                     "rm -rf uploads/articles/images/".$articleClone->getDate()->format("Y")."/".$articleClone->getDate()->format("m")."/".$articleClone->getDate()->format(
  364.                         "d"
  365.                     )."/".$articleClone->getId()."/*"
  366.                 );
  367.                 if (count($images_article) > 0) {
  368.                     foreach ($images_article as $imageArticle) {
  369.                         $image_parent = clone $imageArticle;
  370.                         $image_parent->setArticle($articleClone);
  371.                         $image_parent->setDate(new \Datetime());
  372.                         $this->entityManager->persist($image_parent);
  373.                         $tab_dossiers = ["large""medium""originals""small""thumbnails"];
  374.                         for ($t 0$t count($tab_dossiers); $t++) {
  375.                             $chemin_src  "uploads/articles/images/".$article->getDate()->format("Y")."/".$article->getDate()->format("m")."/".$article->getDate()->format(
  376.                                     "d"
  377.                                 )."/".$article->getId()."/".$tab_dossiers[$t]."/".$image_parent->getUrl();
  378.                             $chemin_dest "uploads/articles/images/".$articleClone->getDate()->format("Y")."/".$articleClone->getDate()->format("m")."/".$articleClone->getDate()->format(
  379.                                     "d"
  380.                                 )."/".$articleClone->getId()."/".$tab_dossiers[$t]."/";
  381.                             if ( ! is_dir($chemin_dest)) {
  382.                                 mkdir($chemin_dest0755true);
  383.                                 chown($chemin_dest"www-data");
  384.                                 chgrp($chemin_dest"www-data");
  385.                                 chmod($chemin_dest0755);
  386.                             }
  387.                             exec("cp ".$chemin_src." ".$chemin_dest);
  388.                         }
  389.                     }
  390.                     $this->entityManager->flush();
  391.                 }
  392.             }
  393.             if (is_object($articleClone) && array_key_exists('copier_associes'$regles) && $regles["copier_associes"] == "1") {
  394.                 $sql  "DELETE FROM `article__article_associe` WHERE parent_id=".$id_article."";
  395.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  396.                 $stmt->execute();
  397.                 if (count($article->getArticlesAssociesParent()) > 0) {
  398.                     foreach ($article->getArticlesAssociesParent() as $artAss) {
  399.                         $artAssClone = clone $artAss;
  400.                         $artAssClone->setParent($articleClone);
  401.                         $this->entityManager->persist($artAssClone);
  402.                     }
  403.                     $this->entityManager->flush();
  404.                 }
  405.             }
  406.             if (is_object($articleClone) && array_key_exists('copier_categorie'$regles) && $regles["copier_categorie"] == "1") {
  407.                 $sql  "DELETE FROM `article__article_categorie` WHERE article_id=".$id_article."";
  408.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  409.                 $stmt->execute();
  410.                 if (count($article->getArticleCategorie()) > 0) {
  411.                     foreach ($article->getArticleCategorie() as $ac) {
  412.                         if (is_object($ac->getCategorie())) {
  413.                             $tableau_update_cat                 = [];
  414.                             $tableau_update_cat["categorie_id"] = $ac->getCategorie()->getId();
  415.                             $tableau_update_cat["article_id"]   = $id_article;
  416.                             $tableau_update_cat["position"]     = $ac->getPosition();
  417.                             $conn->insert('article__article_categorie'$tableau_update_cat);
  418.                         }
  419.                     }
  420.                 }
  421.             }
  422.             if (is_object($articleClone) && array_key_exists('copier_condVente'$regles) && $regles["copier_condVente"] == "1") {
  423.                 $sql  "DELETE FROM `article__condition_vente` WHERE article_id=".$id_article."";
  424.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  425.                 $stmt->execute();
  426.                 $conditionsVente $repo_cond_vente->findBy(["article" => $article]);
  427.                 if (count($conditionsVente) > 0) {
  428.                     foreach ($conditionsVente as $condVente) {
  429.                         $condClone = clone $condVente;
  430.                         $condClone->setArticle($articleClone);
  431.                         $this->entityManager->persist($condClone);
  432.                     }
  433.                     $this->entityManager->flush();
  434.                 }
  435.             }
  436.             if (!= and is_object($articleClone) && array_key_exists('copier_emplacements'$regles) && $regles["copier_emplacements"] == "1") {
  437.                 if (count($article->getEmplacements()) > 0) {
  438.                     foreach ($article->getEmplacements() as $emp) {
  439.                         $empClone = clone $emp;
  440.                         $empClone->setArticle($articleClone);
  441.                         $empClone->setStock(0);
  442.                         $empClone->setStockReserve(0);
  443.                         $this->entityManager->persist($empClone);
  444.                     }
  445.                     $this->entityManager->flush();
  446.                 }
  447.             }
  448.             if (is_object($articleClone) && array_key_exists('copier_condHa'$regles) && $regles["copier_condHa"] == "1") {
  449.                 $sql  "UPDATE `article__condition_achat` SET date_supression = '".$date->format("Y-m-d H:i:s")."' WHERE article_id=".$id_article."";
  450.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  451.                 $stmt->execute();
  452.                 if (count($article->getConditionsAchat()) > 0) {
  453.                     foreach ($article->getConditionsAchat() as $cond) {
  454.                         $condClone = clone $cond;
  455.                         $condClone->setArticle($articleClone);
  456.                         $this->entityManager->persist($condClone);
  457.                     }
  458.                     $this->entityManager->flush();
  459.                 }
  460.             }
  461.         }
  462.     }
  463.     public function creerDeclinaison($tab_declinaison$post$article)
  464.     {
  465.         $date            = new \Datetime();
  466.         $repo_valeurs    $this->entityManager->getRepository(ValeurAttributArticle::class);
  467.         $repo_article    $this->entityManager->getRepository(Article::class);
  468.         $repo_cond_vente $this->entityManager->getRepository(ConditionVente::class);
  469.         //echo "ARTPARENT ".$article->getId();
  470.         //print_r($tab_declinaison);
  471.         $tableau_insert = [];
  472.         $tableau_insert["libelle"]               = null;
  473.         $tableau_insert["date"]                  = $date->format("Y-m-d H:i:s");
  474.         $tableau_insert["reference"]             = null;
  475.         $tableau_insert["reference_client"]      = $article->getReferenceClient();
  476.         $tableau_insert["reference_fournisseur"] = null;
  477.         if (array_key_exists('copier_ref_fournisseur'$post) && $post["copier_ref_fournisseur"] == "1") {
  478.             $tableau_insert["reference_fournisseur"] = $article->getReferenceFournisseur();
  479.         }
  480.         $tableau_insert["prix_base"] = $article->getPrixBase();
  481.         if (is_object($article->getMarque())) {
  482.             $tableau_insert["marque_id"] = $article->getMarque()->getId();
  483.         } else {
  484.             $tableau_insert["marque_id"] = null;
  485.         }
  486.         $tableau_insert["date_supression"] = null;
  487.         $tableau_insert["date_maj"]        = $date->format("Y-m-d H:i:s");
  488.         $tableau_insert["date_maj_prix"]   = null;
  489.         $tableau_insert["description"] = null;
  490.         if (array_key_exists('copier_desc'$post) && $post["copier_desc"] == "1") {
  491.             $tableau_insert["description"] = $article->getDescription();
  492.         }
  493.         $tableau_insert["description_courte"] = null;
  494.         if (array_key_exists('copier_desc_courte'$post) && $post["copier_desc_courte"] == "1") {
  495.             $tableau_insert["description_courte"] = $article->getDescriptionCourte();
  496.         }
  497.         $tableau_insert["stock"] = 0;
  498.         $tableau_insert["largeur"]    = 0;
  499.         $tableau_insert["profondeur"] = 0;
  500.         $tableau_insert["hauteur"]    = 0;
  501.         $tableau_insert["poids"]      = 0;
  502.         if (array_key_exists('copier_dim'$post) && $post["copier_dim"] == "1") {
  503.             $tableau_insert["largeur"]    = $article->getLargeur();
  504.             $tableau_insert["profondeur"] = $article->getProfondeur();
  505.             $tableau_insert["hauteur"]    = $article->getHauteur();
  506.             $tableau_insert["poids"]      = $article->getPoids();
  507.         }
  508.         if ($article->getStatut()) {
  509.             $tableau_insert["statut"] = 1;
  510.         } else {
  511.             $tableau_insert["statut"] = 0;
  512.         }
  513.         if ($article->getAConsigner()) {
  514.             $tableau_insert["a_consigner"] = 1;
  515.         } else {
  516.             $tableau_insert["a_consigner"] = 0;
  517.         }
  518.         if ($article->getConsigne()) {
  519.             $tableau_insert["consigne"] = 1;
  520.         } else {
  521.             $tableau_insert["consigne"] = 0;
  522.         }
  523.         if ($article->getStockAuto()) {
  524.             $tableau_insert["stock_auto"] = 1;
  525.         } else {
  526.             $tableau_insert["stock_auto"] = 0;
  527.         }
  528.         if ($article->getArretGamme()) {
  529.             $tableau_insert["arret_gamme"] = 1;
  530.         } else {
  531.             $tableau_insert["arret_gamme"] = 0;
  532.         }
  533.         $tableau_insert["utilisateur_id"] = null;
  534.         if (is_object($article->getRegleTaxe())) {
  535.             $tableau_insert["regle_taxe_id"] = $article->getRegleTaxe()->getId();
  536.         } else {
  537.             $tableau_insert["regle_taxe_id"] = 1;
  538.         }
  539.         $tableau_insert["remise_max"]            = $article->getRemiseMax();
  540.         $tableau_insert["type_remise_max"]       = $article->getTypeRemiseMax();
  541.         $tableau_insert["seuil_commande_f_mini"] = $article->getSeuilMiniCommandeFournisseur();
  542.         $tableau_insert["seuil_commande_f_maxi"] = $article->getSeuilMaxiCommandeFournisseur();
  543.         $tableau_insert["niveau_un_id"]          = null;
  544.         $tableau_insert["niveau_deux_id"]        = null;
  545.         $tableau_insert["niveau_trois_id"]       = null;
  546.         $tableau_insert["niveau_quatre_id"]      = null;
  547.         $tableau_insert["pump"]                  = null;
  548.         $tableau_insert["commentaire"]           = $article->getCommentairePonctuel();
  549.         if ($article->getVirtuel()) {
  550.             $tableau_insert["virtuel"] = 1;
  551.         } else {
  552.             $tableau_insert["virtuel"] = 0;
  553.         }
  554.         $tableau_insert["prix_vente"]      = $article->getPrixVente();
  555.         $tableau_insert["taux_marge"]      = $article->getTauxMarge();
  556.         $tableau_insert["marge"]           = $article->getMarge();
  557.         $tableau_insert["marge_reelle"]    = $article->getMargeReelle();
  558.         $tableau_insert["ecotaxe"]         = $article->getEcotaxe();
  559.         $tableau_insert["conditionnement"] = $article->getConditionnement();
  560.         $tableau_insert["stock_reserve"]   = 0;
  561.         $tableau_insert["ral_fournisseur"] = 0;
  562.         if (is_object($article->getFournisseurDefaut())) {
  563.             $tableau_insert["fournisseur_defaut_id"] = $article->getFournisseurDefaut()->getId();
  564.         } else {
  565.             $tableau_insert["fournisseur_defaut_id"] = null;
  566.         }
  567.         $tableau_insert["id_import"] = null;
  568.         if ($article->getProduitInterne()) {
  569.             $tableau_insert["produit_interne"] = 1;
  570.         } else {
  571.             $tableau_insert["produit_interne"] = 0;
  572.         }
  573.         $tableau_insert["donnees_import"] = null;
  574.         if ($article->getMajPrix()) {
  575.             $tableau_insert["maj_prix"] = 1;
  576.         } else {
  577.             $tableau_insert["maj_prix"] = 0;
  578.         }
  579.         if (is_object($article->getUniteMesure())) {
  580.             $tableau_insert["unite_mesure_id"] = $article->getUniteMesure()->getId();
  581.         } else {
  582.             $tableau_insert["unite_mesure_id"] = null;
  583.         }
  584.         if ($article->getAfficherComposantPdfInterne()) {
  585.             $tableau_insert["afficher_composant_pdf_interne"] = 1;
  586.         } else {
  587.             $tableau_insert["afficher_composant_pdf_interne"] = 0;
  588.         }
  589.         if ($article->getAfficherComposantPdfExterne()) {
  590.             $tableau_insert["afficher_composant_pdf_externe"] = 1;
  591.         } else {
  592.             $tableau_insert["afficher_composant_pdf_externe"] = 0;
  593.         }
  594.         if (is_object($article->getCategorieRemiseArticle())) {
  595.             $tableau_insert["categorie_remise_article_id"] = $article->getCategorieRemiseArticle()->getId();
  596.         } else {
  597.             $tableau_insert["categorie_remise_article_id"] = null;
  598.         }
  599.         $tableau_insert["temporaire"]               = null;
  600.         $tableau_insert["libelle_secondaire"]       = $article->getLibelleSecondaire();
  601.         $tableau_insert["a_commander"]              = 0;
  602.         $tableau_insert["a_fabriquer"]              = 0;
  603.         $tableau_insert["quantite_conseillee_mini"] = $article->getQuantiteConseilleeMini();
  604.         $tableau_insert["quantite_conseillee"]      = $article->getQuantiteConseillee();
  605.         $tableau_insert["quantite_conseillee_maxi"] = $article->getQuantiteConseilleeMaxi();;
  606.         $tableau_insert["archive"]                      = 0;
  607.         $tableau_insert["coefficient_px_base_px_vente"] = $article->getCoefficientPrixBaseVente();
  608.         $tableau_insert["nom_web"]                   = null;
  609.         $tableau_insert["reference_web"]             = null;
  610.         $tableau_insert["reference_fournisseur_web"] = null;
  611.         $tableau_insert["description_web"]           = null;
  612.         $tableau_insert["resume_web"]                = null;
  613.         $tableau_insert["frais_ports_texte_web"]     = null;
  614.         $tableau_insert["message_qd_en_stock"]       = null;
  615.         $tableau_insert["article_enconsigne_id"]     = null;
  616.         $tableau_insert["reference_appel_1"]  = $article->getReferenceAppel1();
  617.         $tableau_insert["reference_appel_2"]  = $article->getReferenceAppel2();
  618.         $tableau_insert["reference_appel_3"]  = $article->getReferenceAppel3();
  619.         $tableau_insert["reference_appel_4"]  = $article->getReferenceAppel4();
  620.         $tableau_insert["reference_appel_5"]  = $article->getReferenceAppel5();
  621.         $tableau_insert["reference_appel_6"]  = $article->getReferenceAppel6();
  622.         $tableau_insert["reference_appel_7"]  = $article->getReferenceAppel7();
  623.         $tableau_insert["reference_appel_8"]  = $article->getReferenceAppel8();
  624.         $tableau_insert["reference_appel_9"]  = $article->getReferenceAppel9();
  625.         $tableau_insert["reference_appel_10"] = $article->getReferenceAppel10();
  626.         $tableau_insert["reference_appel_11"] = $tab_declinaison["reference"];
  627.         if ($article->getMainOeuvre()) {
  628.             $tableau_insert["main_oeuvre"] = 1;
  629.         } else {
  630.             $tableau_insert["main_oeuvre"] = 0;
  631.         }
  632.         $tableau_insert["stock_reserve_fabrication"] = 0;
  633.         if (is_object($article->getType())) {
  634.             $tableau_insert["type_id"] = $article->getType()->getId();
  635.         } else {
  636.             $tableau_insert["type_id"] = null;
  637.         }
  638.         if (is_object($article->getFamilleCompta())) {
  639.             $tableau_insert["famille_compta_id"] = $article->getFamilleCompta()->getId();
  640.         } else {
  641.             $tableau_insert["famille_compta_id"] = null;
  642.         }
  643.         if ($article->getPrestation()) {
  644.             $tableau_insert["prestation"] = 1;
  645.         } else {
  646.             $tableau_insert["prestation"] = 0;
  647.         }
  648.         if ($article->getNonStocke()) {
  649.             $tableau_insert["non_stocke"] = 1;
  650.         } else {
  651.             $tableau_insert["non_stocke"] = 0;
  652.         }
  653.         if ($article->getNonCommandable()) {
  654.             $tableau_insert["non_commandable"] = 1;
  655.         } else {
  656.             $tableau_insert["non_commandable"] = 0;
  657.         }
  658.         $tableau_insert["divers"]     = 0;
  659.         $tableau_insert["parent_id"]  = null;
  660.         $tableau_insert["mouvemente"] = 0;
  661.         if ($article->getNumSerieObligatoire()) {
  662.             $tableau_insert["num_serie_obligatoire"] = 1;
  663.         } else {
  664.             $tableau_insert["num_serie_obligatoire"] = 0;
  665.         }
  666.         if (is_object($article->getArticleRemplacement())) {
  667.             $tableau_insert["article_remplacement_id"] = $article->getArticleRemplacement()->getId();
  668.         } else {
  669.             $tableau_insert["article_remplacement_id"] = null;
  670.         }
  671.         if ($article->getMajPoids()) {
  672.             $tableau_insert["maj_poids"] = 1;
  673.         } else {
  674.             $tableau_insert["maj_poids"] = 0;
  675.         }
  676.         if ($article->getMajPrixBase()) {
  677.             $tableau_insert["maj_prix_base"] = 1;
  678.         } else {
  679.             $tableau_insert["maj_prix_base"] = 0;
  680.         }
  681.         $tableau_insert["cond_achat"]      = $article->getConditionnementAchat();
  682.         $tableau_insert["est_commentaire"] = 0;
  683.         $tableau_insert["seuil_critique"]  = $article->getSeuilCritique();
  684.         if (is_object($article->getRegleTaxeAchat())) {
  685.             $tableau_insert["regle_taxe_achat_id"] = $article->getRegleTaxeAchat()->getId();
  686.         } else {
  687.             $tableau_insert["regle_taxe_achat_id"] = null;
  688.         }
  689.         $tableau_insert["cpump"]          = null;
  690.         $tableau_insert["dateCalculCump"] = null;
  691.         $tableau_insert["sur_prestashop"] = null;
  692.         if ($article->getUniversel()) {
  693.             $tableau_insert["universel"] = 1;
  694.         } else {
  695.             $tableau_insert["universel"] = 0;
  696.         }
  697.         $tableau_insert["delai_reappro"]          = $article->getDelaiReappro();
  698.         $tableau_insert["title_seo_web"]          = null;
  699.         $tableau_insert["url_web"]                = null;
  700.         $tableau_insert["ean"]                    = null;
  701.         $tableau_insert["prix_revient"]           = $article->getPrixRevient();
  702.         $tableau_insert["frais_fonctionnement"]   = $article->getFraisFonctionnement();
  703.         $tableau_insert["nomenclature_douaniere"] = $article->getNomenclatureDouaniere();
  704.         $tableau_insert["unspsc"]                 = $article->getUnspsc();
  705.         $tableau_insert["a_suggerer"]             = 0;
  706.         $tableau_insert["divers_composes"]        = 0;
  707.         $tableau_insert["nomenclature_validee"]   = 0;
  708.         if (is_object($article->getTransporteur())) {
  709.             $tableau_insert["transporteur_id"] = $article->getTransporteur()->getId();
  710.         } else {
  711.             $tableau_insert["transporteur_id"] = null;
  712.         }
  713.         if (is_object($article->getAtelier())) {
  714.             $tableau_insert["atelier_id"] = $article->getAtelier()->getId();
  715.         } else {
  716.             $tableau_insert["atelier_id"] = null;
  717.         }
  718.         $tableau_insert["commentaire_dimensions"]        = $article->getCommentaireDimensions();
  719.         $tableau_insert["condition_achat_defaut_id"]     = null;
  720.         $tableau_insert["ecocontribution"]               = $article->getEcocontribution();
  721.         $tableau_insert["id_import_2"]                   = null;
  722.         $tableau_insert["article_declinaison_parent_id"] = null;
  723.         $tableau_insert["declinaison"]                   = null;
  724.         if (is_object($article->getFamilleCompta())) {
  725.             $tableau_insert['famille_compta_id'] = $article->getFamilleCompta()->getId();
  726.         }
  727.         $tableau_insert['reference']                     = $tab_declinaison["reference"];
  728.         $tableau_insert['libelle']                       = $tab_declinaison["libelle"];
  729.         $tableau_insert['article_declinaison_parent_id'] = $article->getId();
  730.         $conn $this->entityManager->getConnection();
  731.         $conn->insert('article__article'$tableau_insert);
  732.         $id_article $conn->lastInsertId();
  733.         if ($id_article != "") {
  734.             $articleClone $repo_article->find($id_article);
  735.             if (is_object($articleClone) && array_key_exists('copier_images'$post) && $post["copier_images"] == "1") {
  736.                 $repo_article_image $this->entityManager->getRepository(Image::class);
  737.                 $images_article     $repo_article_image->findBy(["article" => $article]);
  738.                 if (count($images_article) > 0) {
  739.                     foreach ($images_article as $imageArticle) {
  740.                         $image_parent = clone $imageArticle;
  741.                         $image_parent->setArticle($articleClone);
  742.                         $image_parent->setDate(new \Datetime());
  743.                         $this->entityManager->persist($image_parent);
  744.                         //$chemin_src ="uploads/articles/images/".$article->getDate()->format("Y")."/".$article->getDate()->format("m")."/".$article->getDate()->format("d")."/".$article->getId()."/*";
  745.                         //$chemin_dest ="uploads/articles/images/".$articleparent->getDate()->format("Y")."/".$articleparent->getDate()->format("m")."/".$articleparent->getDate()->format("d")."/".$articleparent->getId()."/";
  746.                         $tab_dossiers = ["large""medium""originals""small""thumbnails"];
  747.                         for ($t 0$t count($tab_dossiers); $t++) {
  748.                             $chemin_src  "uploads/articles/images/".$article->getDate()->format("Y")."/".$article->getDate()->format("m")."/".$article->getDate()->format(
  749.                                     "d"
  750.                                 )."/".$article->getId()."/".$tab_dossiers[$t]."/".$image_parent->getUrl();
  751.                             $chemin_dest "uploads/articles/images/".$articleClone->getDate()->format("Y")."/".$articleClone->getDate()->format("m")."/".$articleClone->getDate()->format(
  752.                                     "d"
  753.                                 )."/".$articleClone->getId()."/".$tab_dossiers[$t]."/";
  754.                             if ( ! is_dir($chemin_dest)) {
  755.                                 //echo "<div>CREATION</div>";
  756.                                 mkdir($chemin_dest0755true);
  757.                                 chown($chemin_dest"www-data");
  758.                                 chgrp($chemin_dest"www-data");
  759.                                 chmod($chemin_dest0755);
  760.                             }
  761.                             exec("cp ".$chemin_src." ".$chemin_dest);
  762.                         }
  763.                     }
  764.                     $this->entityManager->flush();
  765.                 }
  766.             }
  767.             if (is_object($articleClone) && array_key_exists('copier_associes'$post) && $post["copier_associes"] == "1") {
  768.                 if (count($article->getArticlesAssociesParent()) > 0) {
  769.                     foreach ($article->getArticlesAssociesParent() as $artAss) {
  770.                         $artAssClone = clone $artAss;
  771.                         $artAssClone->setParent($articleClone);
  772.                         $this->entityManager->persist($artAssClone);
  773.                     }
  774.                     $this->entityManager->flush();
  775.                 }
  776.             }
  777.             if (is_object($articleClone) && array_key_exists('copier_categorie'$post) && $post["copier_categorie"] == "1") {
  778.                 if (count($article->getArticleCategorie()) > 0) {
  779.                     foreach ($article->getArticleCategorie() as $ac) {
  780.                         if (is_object($ac->getCategorie())) {
  781.                             $tableau_insert_cat                 = [];
  782.                             $tableau_insert_cat["categorie_id"] = $ac->getCategorie()->getId();
  783.                             $tableau_insert_cat["article_id"]   = $id_article;
  784.                             $tableau_insert_cat["position"]     = $ac->getPosition();
  785.                             $conn->insert('article__article_categorie'$tableau_insert_cat);
  786.                         }
  787.                     }
  788.                 }
  789.             }
  790.             if (is_object($articleClone) && array_key_exists('copier_condVente'$post) && $post["copier_condVente"] == "1") {
  791.                 $conditionsVente $repo_cond_vente->findBy(["article" => $article]);
  792.                 if (count($conditionsVente) > 0) {
  793.                     foreach ($conditionsVente as $condVente) {
  794.                         $condClone = clone $condVente;
  795.                         $condClone->setArticle($articleClone);
  796.                         $this->entityManager->persist($condClone);
  797.                     }
  798.                     $this->entityManager->flush();
  799.                 }
  800.             }
  801.             if (is_object($articleClone) && array_key_exists('copier_emplacements'$post) && $post["copier_emplacements"] == "1") {
  802.                 if (count($article->getEmplacements()) > 0) {
  803.                     foreach ($article->getEmplacements() as $emp) {
  804.                         $empClone = clone $emp;
  805.                         $empClone->setArticle($articleClone);
  806.                         $empClone->setStock(0);
  807.                         $empClone->setStockReserve(0);
  808.                         $this->entityManager->persist($empClone);
  809.                     }
  810.                     $this->entityManager->flush();
  811.                 }
  812.             }
  813.             if (is_object($articleClone) && array_key_exists('copier_condHa'$post) && $post["copier_condHa"] == "1") {
  814.                 if (count($article->getConditionsAchat()) > 0) {
  815.                     foreach ($article->getConditionsAchat() as $cond) {
  816.                         $condClone = clone $cond;
  817.                         $condClone->setArticle($articleClone);
  818.                         $this->entityManager->persist($condClone);
  819.                     }
  820.                     $this->entityManager->flush();
  821.                 }
  822.             }
  823.             if (count($tab_declinaison["caracteritiques"]) > 0) {
  824.                 foreach ($tab_declinaison["caracteritiques"] as $declinaison) {
  825.                     $valeur_obj $repo_valeurs->find($declinaison);
  826.                     if (is_object($valeur_obj)) {
  827.                         $tableau_declinaison                               = [];
  828.                         $tableau_declinaison["article_id"]                 = $id_article;
  829.                         $tableau_declinaison["attribut_article_id"]        = $valeur_obj->getAttributArticle()->getId();
  830.                         $tableau_declinaison["valeur_attribut_article_id"] = $valeur_obj->getId();
  831.                         $conn->insert('article__declinaison'$tableau_declinaison);
  832.                     }
  833.                 }
  834.             }
  835.         }
  836.     }
  837.     public function getValeursAttribut($attribut)
  838.     {
  839.         $repo_valeurs $this->entityManager->getRepository(ValeurAttributArticle::class);
  840.         $valeurs      $repo_valeurs->findBy(["attributArticle" => $attribut]);
  841.         return $valeurs;
  842.     }
  843.     public function getDeclinaisonArticle($article)
  844.     {
  845.         $repo_declinaison $this->entityManager->getRepository(Declinaison::class);
  846.         $attributs        $repo_declinaison->findBy(["article" => $article]);
  847.         return $attributs;
  848.     }
  849.     public function getPrixLignes(Article $articleCommande $commande)
  850.     {
  851.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  852.         $lignes                $repo_article_commande->getPrixLignes($article$commande);
  853.         return $lignes;
  854.     }
  855.     public function getNombreDeLignes(Article $articleCommande $commande)
  856.     {
  857.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  858.         $total                 $repo_article_commande->getNombreDeLignes($article$commande);
  859.         return $total;
  860.     }
  861.     public function getQuantiteTotale(Article $articleCommande $commande)
  862.     {
  863.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  864.         $total                 $repo_article_commande->getQuantiteTotale($article$commande);
  865.         return $total;
  866.     }
  867.     public function qrCodeArticle(Article $article)
  868.     {
  869.         $url $this->urlGenerator->generate('dtc_article_modifier', ["id" => $article->getId()], true);
  870.         $oQRC = new QrCode();
  871.         /*$oQRC->fullName('Pierre-Henry Soria') // Add Full Name
  872.             ->nickName('PH7') // Add Nickname
  873.             ->gender('M') // Add Gender
  874.             ->email('ph7software@gmail.com') // Add Email Address
  875.             ->impp('phs_7@aol.com') // Add Instant Messenger
  876.             ->url('http://ph-7.github.com') // Add URL Website
  877.             ->note('Hello to all! I am a web developer. As hobbies I like climbing and swimming ...') // Add Note
  878.             ->categories('developer,designer,climber,swimmer') // Add Categories
  879.             ->photo('http://files.phpclasses.org/picture/user/1122955.jpg') // Add Avatar
  880.             ->lang('en-US') // Add Language
  881.             ->finish(); // End vCard
  882.         */
  883.         $oQRC
  884.             //->fullName($article->getLibelle()) // Add Full Name
  885.             //->nickName($article->getReference()) // Add Nickname
  886.             //->url($url) // Add URL Website
  887.             ->urlErp($url// Add URL Website
  888.             /*
  889.             ->gender('M') // Add Gender
  890.             ->email('ph7software@gmail.com') // Add Email Address
  891.             ->impp('phs_7@aol.com') // Add Instant Messenger
  892.             ->url('http://ph-7.github.com') // Add URL Website
  893.             ->note('Hello to all! I am a web developer. As hobbies I like climbing and swimming ...') // Add Note
  894.             ->categories('developer,designer,climber,swimmer') // Add Categories
  895.             ->photo('http://files.phpclasses.org/picture/user/1122955.jpg') // Add Avatar
  896.             ->lang('en-US') // Add Language
  897.            */
  898.             ->finish(); // End vCard
  899.         // echo '<p><img src="' . $oQRC->get(300) . '" alt="QR Code" /></p>'; // Generate and display the QR Code
  900.         return $oQRC;
  901.         //$oQRC->display(); // Display
  902.     }
  903.     public function pourcentageTraitementCalculCump(Cron $cron)
  904.     {
  905.         $pourcentage 0;
  906.         //return $pourcentage;
  907.         $nbTotalArticle $cron->getDescription();
  908.         $sql "SELECT count(*) as total
  909.                 FROM article__article
  910.                 WHERE dateCalculCump = '".$cron->getDateDebut()->format("Y-m-d H:i:s")."'
  911.                 ";
  912.         $stmt   $this->entityManager->getConnection()->prepare($sql);
  913.         $existe $stmt->executeQuery()->fetchAllAssociative();
  914.         $nbArticlesCalcule $existe[0]["total"];
  915.         if ($nbTotalArticle 0) {
  916.             $pourcentage $nbArticlesCalcule $nbTotalArticle 100;
  917.         } else {
  918.             $pourcentage 0;
  919.         }
  920.         return $pourcentage;
  921.     }
  922.     public function getConditionsAchat($id)
  923.     {
  924.         $article     $this->entityManager->getRepository(Article::class)->find($id);
  925.         $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  926.         $condHa $repo_condha->getConditionsAchatArticle($article);
  927.         return $condHa;
  928.     }
  929.     public function getLibelle($id)
  930.     {
  931.         $article $this->entityManager->getRepository(Article::class)->find($id);
  932.         return $article->getLibelle();
  933.     }
  934.     public function getRalClientArticle(Article $article)
  935.     {
  936.         $repo_article_composant $this->entityManager->getRepository(ArticleComposant::class);
  937.         $composants             $repo_article_composant->getComposantsComposeVirtuel($article)->getQuery()->getResult();
  938.         $repoCommande        $this->entityManager->getRepository(Commande::class);
  939.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  940.         $reservations        $repoArticleCommande->getRalClientEtCmdAssociees($article$composants);
  941.         if (count($reservations) > 0) {
  942.             foreach ($reservations as $key => $r) {
  943.                 if (array_key_exists('0'$r) && array_key_exists('typeDocInitial'$r[0])) {
  944.                     $reservations[$key][0]["masque"]      = 0;
  945.                     $reservations[$key][0]["ral_calcule"] = $reservations[$key][0]["ral_quantite"];
  946.                 }
  947.                 if (array_key_exists('0'$r) && array_key_exists('typeDocInitial'$r[0]) && $r[0]["typeDocInitial"] == "2") {
  948.                     $ral_quantite $r[0]["ral_quantite"];
  949.                     $commande_id  $r[0]["commandeId"];
  950.                     $article_id   $r[0]["articleId"];
  951.                     $commande $repoCommande->find($commande_id);
  952.                     if (is_object($commande)) {
  953.                         $totalPrepare 0;
  954.                         $sql "SELECT ac.id,ac.article_commande_parent_id
  955.                             FROM commerciale__article_commande ac
  956.                                                         LEFT JOIN commerciale__commande c ON ac.commande_id = c.id
  957.                                                         LEFT JOIN commerciale__statut_commande s ON c.statut_commande_id = s.id
  958.                             WHERE ac.article_id = ".$article_id."
  959.                             AND c.id IN (".$commande_id.")
  960.                                                             AND s.ordre NOT IN (0)
  961.                             LIMIT 0,1000000000
  962.                             ";
  963.                         $stmt   $this->entityManager->getConnection()->prepare($sql);
  964.                         $existe $stmt->executeQuery()->fetchAllAssociative();
  965.                         if (count($existe) > 0) {
  966.                             for ($r 0$r count($existe); $r++) {
  967.                                 //print_r($existe);
  968.                                 $acObjet $repoArticleCommande->find($existe[$r]["id"]);
  969.                                 if (is_object($acObjet)) {
  970.                                     $totalPrepare $totalPrepare $repoArticleCommande->totalPrepare($commande$acObjet$origine "bp");
  971.                                     //echo "<div>totalPrepare BP".$totalPrepare." RAL ".$ral_quantite."</div>";
  972.                                 }
  973.                             }
  974.                         }
  975.                         //echo "<div>totalPrepare BP FINAL ".$totalPrepare." RAL ".$ral_quantite."</div>";
  976.                         if ($totalPrepare >= $ral_quantite) {
  977.                             //unset($reservations[$key]);
  978.                             $reservations[$key][0]["masque"] = 1;
  979.                             $reservations[$key][0]["masque"] = 0;
  980.                         } elseif ($totalPrepare && $totalPrepare $ral_quantite) {
  981.                             $reservations[$key][0]["ral_quantite"] = $reservations[$key][0]["quantite"];
  982.                             $reservations[$key][0]["ral_quantite"] -= $totalPrepare;
  983.                         }
  984.                     }
  985.                 } elseif (array_key_exists('0'$r) && array_key_exists('typeDocInitial'$r[0]) && $r[0]["typeDocInitial"] == "3") {
  986.                     $ral_quantite $r[0]["ral_quantite"];
  987.                     $commande_id  $r[0]["commandeId"];
  988.                     $article_id   $r[0]["articleId"];
  989.                     $commande $repoCommande->find($commande_id);
  990.                     if (is_object($commande)) {
  991.                         $sql "SELECT id,article_commande_parent_id
  992.                             FROM commerciale__article_commande
  993.                             WHERE article_id = ".$article_id."
  994.                             AND commande_id IN (SELECT id FROM commerciale__commande WHERE commande_id = ".$commande_id." AND type_document_commercial_id = ".TypeDocumentCommercial::BPATELIER." AND statut_commande_id = 26)
  995.                             LIMIT 0,1
  996.                             ";
  997.                         $stmt $this->entityManager->getConnection()->prepare($sql);
  998.                         $stmt->execute();
  999.                         $existe $stmt->fetchAllAssociative();
  1000.                         if (count($existe) > 0) {
  1001.                             $acObjet $repoArticleCommande->find($existe[0]["id"]);
  1002.                             if (is_object($acObjet)) {
  1003.                                 $totalPrepare $repoArticleCommande->totalPrepare($commande$acObjet$origine "bpa");
  1004.                                 //echo "<div>totalPrepare ".$totalPrepare."</div>";
  1005.                                 if ($totalPrepare >= $ral_quantite) {
  1006.                                     $reservations[$key][0]["masque"] = 1;
  1007.                                     //unset($reservations[$key]);
  1008.                                 } elseif ($totalPrepare && $totalPrepare $ral_quantite) {
  1009.                                     $reservations[$key][0]["ral_quantite"] -= $totalPrepare;
  1010.                                 }
  1011.                             }
  1012.                         }
  1013.                         //echo "<div>".$sql."</div>";
  1014.                         //echo "<div>(".$key.") typeDocInitial ".$r[0]["typeDocInitial"]."</div>";
  1015.                     }
  1016.                     //totalPrepare(Commande $commande,ArticleCommande $articleCommande,$origine="bpa")
  1017.                 }
  1018.                 //print_r($reservations[$key]);
  1019.                 //    echo "<br/>**************************<br/>";
  1020.             }
  1021.         }
  1022.         return $reservations;
  1023.     }
  1024.     public function getRafArticle(Article $article)
  1025.     {
  1026.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  1027.         $reservations        $repoArticleCommande->getReservationsFabrications($article);
  1028.         return $reservations;
  1029.     }
  1030.     public function majEquivalence($valeurs)
  1031.     {
  1032.         //print_r($valeurs);
  1033.         //echo "<div>--------</div>";
  1034.         //print_r($valeurs['articlesEquivalents']);
  1035.         //echo "<div>--------</div>";
  1036.         if (array_key_exists('articlesEquivalents'$valeurs)) {
  1037.             foreach ($valeurs['articlesEquivalents'] as $key => $value) {
  1038.                 //echo "<div>".$key."--------</div>";
  1039.                 if(!is_array($value)) {
  1040.                     $value = [$value];
  1041.                 }
  1042.                 $reciproque $value;
  1043.                 //print_r($value);
  1044.                 for ($i 0$iMax count($reciproque); $i $iMax$i++) {
  1045.                     $sql  "DELETE FROM `article_article` WHERE article_source=".$reciproque[$i]." and article_target=".$key."";
  1046.                     $stmt $this->entityManager->getConnection()->prepare($sql);
  1047.                     $stmt->execute();
  1048.                 }
  1049.             }
  1050.         }
  1051.         //echo "<div>###############</div>";
  1052.         if (array_key_exists('articles'$valeurs)) {
  1053.             for ($i 0$i count($valeurs['articles']); $i++) {
  1054.                 //echo "<div>ART : ".$valeurs['articles'][$i]."</div>";
  1055.                 $id_article $valeurs['articles'][$i];
  1056.                 $sql  "DELETE FROM `article_article` WHERE article_source=".$id_article."";
  1057.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  1058.                 $stmt->executeQuery();
  1059.                 if (array_key_exists('equivalence'$valeurs)) {
  1060.                     if (array_key_exists($id_article$valeurs['equivalence'])) {
  1061.                         foreach ($valeurs['equivalence'][$id_article] as $key => $value) {
  1062.                             //echo "<div>EQUIVALENCE : ".$key."</div>";
  1063.                             $sql  "INSERT INTO `article_article` (article_source, article_target) VALUES (".$id_article.",".$key.")";
  1064.                             $stmt $this->entityManager->getConnection()->prepare($sql);
  1065.                             $stmt->executeQuery();
  1066.                         }
  1067.                     }
  1068.                 }
  1069.                 //echo "<div>--------</div>";
  1070.                 if (array_key_exists('reciproque'$valeurs)) {
  1071.                     if (array_key_exists($id_article$valeurs['reciproque'])) {
  1072.                         foreach ($valeurs['reciproque'][$id_article] as $key => $value) {
  1073.                             //echo "<div>RECIPROQUE : ".$key."</div>";
  1074.                             $sql  "SELECT count(*) as total FROM `article_article` WHERE article_source=".$key." and article_target=".$id_article."";
  1075.                             $stmt $this->entityManager->getConnection()->prepare($sql);
  1076.                             $query $stmt->executeQuery();
  1077.                             $existe $query->fetchAllAssociative();
  1078.                             if ($existe[0]['total'] == 0) {
  1079.                                 $sql  "INSERT INTO `article_article` (article_source, article_target) VALUES (".$key.",".$id_article.")";
  1080.                                 $stmt $this->entityManager->getConnection()->prepare($sql);
  1081.                                 $stmt->executeQuery();
  1082.                             }
  1083.                         }
  1084.                     }
  1085.                 }
  1086.                 // echo "<div>----------------</div>";
  1087.                 // echo "<div>----------------</div>";
  1088.             }
  1089.         }
  1090.     }
  1091.     public function estUneEquivalenceReciproque($article_equivalent$article_source)
  1092.     {
  1093.         $repo_article   $this->entityManager->getRepository(Article::class);
  1094.         $est_reciproque $repo_article->estUneEquivalenceReciproque($article_equivalent$article_source);
  1095.         return $est_reciproque;
  1096.     }
  1097.     public function getEquivalences($idArticle)
  1098.     {
  1099.         $repo_article $this->entityManager->getRepository(Article::class);
  1100.         $equivalences $repo_article->getArticleEquivalent($idArticle);
  1101.         return $equivalences;
  1102.     }
  1103.     public function getDernierPrixAchat($idArticle$date)
  1104.     {
  1105.         $repo_article $this->entityManager->getRepository(Article::class);
  1106.         $prix         $repo_article->getDernierPrixAchat($idArticle$date);
  1107.         return $prix;
  1108.     }
  1109.     public function getPrixAchat($idArticle$date)
  1110.     {
  1111.         $repo_article $this->entityManager->getRepository(Article::class);
  1112.         $prix         $repo_article->getPrixAchat($idArticle$date);
  1113.         return $prix;
  1114.     }
  1115.     public function getCump($idArticle$date)
  1116.     {
  1117.         $repo_article $this->entityManager->getRepository(MouvementStock::class);
  1118.         $mvt          $repo_article->getDernierMouvementDateHeure($idArticle$date);
  1119.         //print_r($date);
  1120.         return $mvt['cpump'];
  1121.     }
  1122.     public function getStockArticle($idArticle$date)
  1123.     {
  1124.         $repo_article $this->entityManager->getRepository(MouvementStock::class);
  1125.         $mvt          $repo_article->getDernierMouvementDateHeure($idArticle$date);
  1126.         //print_r($date);
  1127.         return floatval($mvt['stock']);
  1128.     }
  1129.     public function getCumpOuPrixCondHa($idArticle$date '')
  1130.     {
  1131.         $repo_article $this->entityManager->getRepository(MouvementStock::class);
  1132.         $mvt          $repo_article->getDernierMouvementDateHeure($idArticle$date);
  1133.         if ($mvt['cpump'] == '' || $mvt['cpump'] == || $mvt['cpump'] == '0') {
  1134.             $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  1135.             $condHa      $repo_condha->findOneBy(["article" => $idArticle"defaut" => 1]);
  1136.             if (is_object($condHa)) {
  1137.                 $prix                       $condHa->getPrixAchatNet();
  1138.                 $coefficientConditionnement $condHa->getCoefficientConditionnement();
  1139.                 if ($coefficientConditionnement != 0) {
  1140.                     $prix $prix $coefficientConditionnement;
  1141.                 }
  1142.                 $fournisseur $condHa->getFournisseur();
  1143.                 if (is_object($fournisseur)) {
  1144.                     $devise $fournisseur->getDevise();
  1145.                     if (is_object($devise)) {
  1146.                         $tauxChange $devise->getTauxChange();
  1147.                         if ($tauxChange != 0) {
  1148.                             $prix $prix $tauxChange;
  1149.                         }
  1150.                     }
  1151.                 }
  1152.                 return $prix;
  1153.             }
  1154.         }
  1155.         return $mvt['cpump'];
  1156.     }
  1157.     public function getCumpOuPrixCondHaAc($idArticle$date ''$quantite)
  1158.     {
  1159.         //$repo_article_commande = $this->em->getRepository(ArticleCommande::class);
  1160.         $repo_article $this->entityManager->getRepository(Article::class);
  1161.         //$ac = $repo_article_commande->find($idArticleCommande);
  1162.         $article       $repo_article->find($idArticle);
  1163.         $qteAfabriquer 0;
  1164.         if ($article->getStock() >= 0) {
  1165.             $qteAfabriquer $quantite $article->getStock();
  1166.         } else {
  1167.             $qteAfabriquer $quantite;
  1168.         }
  1169.         $qteAfabriquer   max(0$qteAfabriquer);
  1170.         $qteStock        $quantite $qteAfabriquer;
  1171.         $cumpStock       0;
  1172.         $cumpFabrication 0;
  1173.         $repo_article $this->entityManager->getRepository(MouvementStock::class);
  1174.         $mvt          $repo_article->getDernierMouvementDateHeure($article->getId(), $date);
  1175.         //si il n'y a pas assez de stock ou si le cump est nul, il faut recuperer le prix de la cond HA
  1176.         if ($mvt['cpump'] == '' || $mvt['cpump'] == || $mvt['cpump'] == '0' || ($qteAfabriquer 0)) {
  1177.             $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  1178.             $condHa      $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  1179.             if (is_object($condHa)) {
  1180.                 $prix                       $condHa->getPrixAchatNet();
  1181.                 $coefficientConditionnement $condHa->getCoefficientConditionnement();
  1182.                 if ($coefficientConditionnement != 0) {
  1183.                     $prix $prix $coefficientConditionnement;
  1184.                 }
  1185.                 $fournisseur $condHa->getFournisseur();
  1186.                 if (is_object($fournisseur)) {
  1187.                     $devise $fournisseur->getDevise();
  1188.                     if (is_object($devise)) {
  1189.                         $tauxChange $devise->getTauxChange();
  1190.                         if ($tauxChange != 0) {
  1191.                             $prix $prix $tauxChange;
  1192.                         }
  1193.                     }
  1194.                 }
  1195.                 //return $prix;
  1196.                 $cumpFabrication $prix;
  1197.                 $cumpStock       $prix;
  1198.             }
  1199.         } else {
  1200.             $cumpStock $mvt['cpump'];
  1201.         }
  1202.         $total = (($qteStock $cumpStock) + ($qteAfabriquer $cumpFabrication)) / $quantite;
  1203.         return $total;
  1204.     }
  1205.     public function getCumpFabrication($article$recursif false)
  1206.     {
  1207.         $total      0;
  1208.         $composants $article->getArticlesComposants();
  1209.         if (count($composants) > 0) {
  1210.             $conditionAchatParDefaut $this->getConditionAchatParDefaut($article);
  1211.             foreach ($composants as $composant) {
  1212.                 $articleTmp $composant->getArticle();
  1213.                 if ($articleTmp->getProduitInterne() == && $recursif) {
  1214.                     $valeur $this->getCumpFabrication($articleTmp$recursif);
  1215.                 } else {
  1216.                     $conditionAchatParDefautTmp "";
  1217.                     if (is_object($conditionAchatParDefaut) && $conditionAchatParDefaut->getFournisseur()->getReference() == '12000') {
  1218.                         $conditionAchatParDefautTmp $this->getConditionAchatParDefaut($articleTmp);
  1219.                     }
  1220.                     if (is_object($conditionAchatParDefautTmp)) {
  1221.                         $valeur    round($conditionAchatParDefautTmp->getPrixAchatNet(), 2);
  1222.                         $coeffCond $conditionAchatParDefautTmp->getCoefficientConditionnement();
  1223.                         if ($coeffCond != 0) {
  1224.                             $valeur $valeur $coeffCond;
  1225.                         }
  1226.                         $devise $conditionAchatParDefautTmp->getFournisseur()->getDevise();
  1227.                         if (is_object($devise) && $devise->getTauxChange() != 0) {
  1228.                             $valeur $valeur floatval($devise->getTauxChange());
  1229.                         }
  1230.                     } elseif ($articleTmp->getCpump() != 0) {
  1231.                         $valeur round(floatval($articleTmp->getCpump()), 2);
  1232.                     } else {
  1233.                         $valeur round(floatval($articleTmp->getPrixBase()), 2);
  1234.                     }
  1235.                 }
  1236.                 $total += $valeur $composant->getQuantite();
  1237.             }
  1238.         }
  1239.         //{% if composant.article.produitInterne == 1 %}
  1240.         return $total;
  1241.     }
  1242.     public function getCumpFabrication2($article$recursif false)
  1243.     {
  1244.         $total      0;
  1245.         $composants $article->getArticlesComposants();
  1246.         if (count($composants) > 0) {
  1247.             foreach ($composants as $composant) {
  1248.                 $articleTmp $composant->getArticle();
  1249.                 if ($articleTmp->getProduitInterne() == && $recursif && $articleTmp->getStock() <= 0) {
  1250.                     $valeur $this->getCumpFabrication2($articleTmp$recursif);
  1251.                 } else {
  1252.                     $valeur $this->getCumpOuPrixCondHa($articleTmp);
  1253.                 }
  1254.                 $total += $valeur $composant->getQuantite();
  1255.             }
  1256.         }
  1257.         //{% if composant.article.produitInterne == 1 %}
  1258.         return $total;
  1259.     }
  1260.     public function getCumpFabrication3($article$recursif false$quantite)
  1261.     {
  1262.         $total      0;
  1263.         $composants $article->getArticlesComposants();
  1264.         if (count($composants) > 0) {
  1265.             foreach ($composants as $composant) {
  1266.                 $articleTmp $composant->getArticle();
  1267.                 if ($articleTmp->getProduitInterne() == && $recursif && $articleTmp->getStock() < $quantite) {
  1268.                     $valeur $this->getCumpFabrication3($articleTmp$recursif$quantite);
  1269.                 } else {
  1270.                     $valeur $this->getCumpOuPrixCondHaAc($articleTmp''$quantite);
  1271.                 }
  1272.                 $total += $valeur $composant->getQuantite();
  1273.             }
  1274.         }
  1275.         //{% if composant.article.produitInterne == 1 %}
  1276.         return $total;
  1277.     }
  1278.     public function getTotalImage(Article $article)
  1279.     {
  1280.         $repo_image $this->entityManager->getRepository(Image::class);
  1281.         $total      $repo_image->getTotalImageArticle($article);
  1282.         return $total['total'];
  1283.     }
  1284.     public function getTotalDocument(Article $article)
  1285.     {
  1286.         $repo_document $this->entityManager->getRepository(Document::class);
  1287.         $total         $repo_document->getTotalDocumentArticle($article);
  1288.         return $total['total'];
  1289.     }
  1290.     public function getTotalPromos(Article $article)
  1291.     {
  1292.         $repo_prix $this->entityManager->getRepository(PrixPromo::class);
  1293.         $total     $repo_prix->getTotalPrixPromoArticle($article);
  1294.         return $total['total'];
  1295.     }
  1296.     public function getTotalVente(Article $article)
  1297.     {
  1298.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  1299.         $total                 $repo_article_commande->getTotalVenteArticle($article);
  1300.         return $total['total'];
  1301.     }
  1302.     public function getTotalApplication(Article $article)
  1303.     {
  1304.         $repo_application $this->entityManager->getRepository(Application::class);
  1305.         $total            $repo_application->getTotalApplicationArticle($article);
  1306.         return $total['total'];
  1307.     }
  1308.     public function getTotalConditionVente(Article $article)
  1309.     {
  1310.         $repo_condition_achat $this->entityManager->getRepository(ConditionVente::class);
  1311.         $total                $repo_condition_achat->getTotalConditionVenteArticle($article);
  1312.         return $total['total'];
  1313.     }
  1314.     public function getTotalPrixDegressif(Article $article)
  1315.     {
  1316.         $repo_condition_achat $this->entityManager->getRepository(PrixDegressif::class);
  1317.         $total                $repo_condition_achat->getTotalPrixDegressifArticle($article);
  1318.         return $total['total'];
  1319.     }
  1320.     public function getTotalColis(Article $article)
  1321.     {
  1322.         $repo_colis $this->entityManager->getRepository(Colis::class);
  1323.         $total      $repo_colis->getTotalColisArticle($article);
  1324.         return $total['total'];
  1325.     }
  1326.     public function getTotalConcurrenceArticle(Article $article)
  1327.     {
  1328.         $repo_concurrence $this->entityManager->getRepository(Concurrence::class);
  1329.         $total            $repo_concurrence->getTotalConcurrenceArticle($article);
  1330.         return $total['total'];
  1331.     }
  1332.     public function getTotalConditionAchat(Article $article)
  1333.     {
  1334.         $repo_condition_achat $this->entityManager->getRepository(ConditionAchat::class);
  1335.         $total                $repo_condition_achat->getTotalConditionAchatArticle($article);
  1336.         return $total['total'];
  1337.     }
  1338.     public function getTotalTvaCommandeParTaux(Commande $commande$taux)
  1339.     {
  1340.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  1341.         $totalTva              $repo_article_commande->getTotalTvaParTaux($commande$taux);
  1342.         return $totalTva;
  1343.     }
  1344.     public function getTotalTvaCommandeParTaxe(Commande $commande$taxe)
  1345.     {
  1346.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  1347.         $totalTva              $repo_article_commande->getTotalTvaParTaxe($commande$taxe);
  1348.         return $totalTva;
  1349.     }
  1350.     public function getTotalTvaCommandeFParTaux($commande$taux)
  1351.     {
  1352.         $taux                  floatval($taux);
  1353.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  1354.         $totalTva              $repo_article_commande->getTotalTvaParTauxCF($commande$taux);
  1355.         return $totalTva;
  1356.     }
  1357.     public function getTotalBaseHTParTaux(Commande $commande$taux)
  1358.     {
  1359.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  1360.         $totalTva $repo_article_commande->getTotalBaseHTParTaux($commande$taux);
  1361.         return $totalTva;
  1362.     }
  1363.     public function getTotalBaseHTParTauxCF(CommandeFournisseur $commande$taux)
  1364.     {
  1365.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  1366.         $totalTva $repo_article_commande->getTotalBaseHTParTauxCF($commande$taux);
  1367.         return $totalTva;
  1368.     }
  1369.     public function getTva(Article $article$facturation ''$client ''$adresse '')
  1370.     {
  1371.         $array     = ['id' => 0'taux' => 0];
  1372.         $tva       "0";
  1373.         $regleTaxe $article->getRegleTaxe();
  1374.         if (is_object($facturation)) {
  1375.         } else {
  1376.             $repo_zone     $this->entityManager->getRepository(Zone::class);
  1377.             $repo_tva_pays $this->entityManager->getRepository(RegleTaxePays::class);
  1378.             $pays          $repo_zone->find(370095);
  1379.             $tvaPays       $repo_tva_pays->findOneBy(["pays" => $pays"regleTaxe" => $regleTaxe]);
  1380.             //if(!is_object($tvaPays)) return "20";
  1381.             //if(!is_object($tvaPays->getTaxe())) return "20";
  1382.             if (is_object($tvaPays)) {
  1383.                 $taxe $tvaPays->getTaxe();
  1384.                 if (is_object($taxe)) {
  1385.                     $array['id']   = $taxe->getId();
  1386.                     $array['taux'] = $taxe->getTaux();
  1387.                 }
  1388.             }
  1389.         }
  1390.         return $array;
  1391.     }
  1392.     public function getTaxe($article ''$client ''$adresse ''$codeIso '')
  1393.     {
  1394.         //Taxe par défaut
  1395.         //$taxe = $this->em->getRepository(Taxe::class)->find(5);//taux nul
  1396.         $taxe      $this->entityManager->getRepository(Taxe::class)->find(1);//Taux standard (20%)
  1397.         $regleTaxe $this->entityManager->getRepository(RegleTaxe::class)->find(1);
  1398.         if ($codeIso != '') {
  1399.             $pays $this->entityManager->getRepository(Zone::class)->findOneBy([
  1400.                                                                                     'dateSuppression' => null,
  1401.                                                                                     'type'            => 1,
  1402.                                                                                     'codeIso'         => $codeIso,
  1403.                                                                                 ]);
  1404.             if (is_object($regleTaxe) && is_object($pays)) {
  1405.                 $tvaPays $this->entityManager->getRepository(RegleTaxePays::class)->findOneBy(["pays" => $pays"regleTaxe" => $regleTaxe]);
  1406.                 if (is_object($tvaPays) && is_object($tvaPays->getTaxe())) {
  1407.                     $taxe $tvaPays->getTaxe();
  1408.                 }
  1409.             }
  1410.         } elseif (is_object($adresse) && is_object($adresse->getPays()) && ! $adresse->getPays()->getEurope()) {
  1411.             //adresse hors UE -> pas de TVA
  1412.             $taxe $this->entityManager->getRepository(Taxe::class)->find(5);//taux nul
  1413.         //} elseif (is_object($client) && ! empty($client->getNumTva()) && $this->clientService->estPro($client) && is_object($adresse) && is_object(
  1414.         } elseif (1!=and is_object($client) && ! empty($client->getNumTva()) && $this->clientService->estPro($client) && is_object($adresse) && is_object(
  1415.                 $adresse->getPays()
  1416.             ) && $adresse->getPays()->getEurope()) {
  1417.             //client pro et adresse UE avec num de tva intracommunautaire -> pas de TVA
  1418.             $taxe $this->entityManager->getRepository(Taxe::class)->find(5);//taux nul
  1419.         } else {
  1420.             // sinon -> TVA
  1421.             // changement au 1/07/2021 -> facturation de la TVA du pays destinataire
  1422.             $pays $this->entityManager->getRepository(Zone::class)->find(370095);
  1423.             if (is_object($adresse) && is_object($adresse->getPays())) {
  1424.                 $pays $adresse->getPays();
  1425.             }
  1426.             if (is_object($article) && is_object($article->getRegleTaxe())) {
  1427.                 $regleTaxe $article->getRegleTaxe();
  1428.             }
  1429.             if (is_object($regleTaxe) && is_object($pays)) {
  1430.                 $tvaPays $this->entityManager->getRepository(RegleTaxePays::class)->findOneBy(["pays" => $pays"regleTaxe" => $regleTaxe]);
  1431.                 if (is_object($tvaPays) && is_object($tvaPays->getTaxe())) {
  1432.                     $taxe $tvaPays->getTaxe();
  1433.                 }
  1434.             }
  1435.         }
  1436.         return $taxe;
  1437.         /*
  1438.         if(is_object($taxe)) {
  1439.             $array['id'] = $taxe->getId();
  1440.             $array['taux'] = $taxe->getTaux();
  1441.         }
  1442.         return $array;
  1443.         */
  1444.     }
  1445.     public function getRemisesPossible($a ''$client ''$montantTotal ''$prix ''$commande '')
  1446.     {
  1447.         $dateJ = new \Datetime();
  1448.         $conn  $this->entityManager->getConnection();
  1449.         if (is_object($a)) {
  1450.             $idArticle   $a->getArticle()->getId();
  1451.             $obj_article $a->getArticle();
  1452.         } else {
  1453.             $idArticle   $a['article']->getId();
  1454.             $obj_article $a['article'];
  1455.         }
  1456.         $idClient '';
  1457.         if (is_object($client)) {
  1458.             $idClient $client->getId();
  1459.         }
  1460.         $idMarque "";
  1461.         if (is_object($obj_article) and is_object($obj_article->getMarque())) {
  1462.             $idMarque $obj_article->getMarque()->getId();
  1463.         }
  1464.         $idCategRemiseArticle "";
  1465.         if (is_object($obj_article->getCategorieRemiseArticle())) {
  1466.             $idCategRemiseArticle $obj_article->getCategorieRemiseArticle()->getId();
  1467.         }
  1468.         $idCategRemiseClient "";
  1469.         if (is_object($client)) {
  1470.             foreach ($client->getcategorieRemiseClientClient() as $crcc) {
  1471.                 if (is_object($crcc->getCategorieRemiseClient())) {
  1472.                     $idCategRemiseClient .= $crcc->getCategorieRemiseClient()->getId().',';
  1473.                 }
  1474.             }
  1475.         }
  1476.         $idCategRemiseClient .= ',|';
  1477.         $idCategRemiseClient str_replace(',,|'''$idCategRemiseClient);
  1478.         $idCategRemiseClient str_replace(',|'''$idCategRemiseClient);
  1479.         $idCategArticle "";
  1480.         foreach ($obj_article->getArticleCategorie() as $ac) {
  1481.             if (is_object($ac->getCategorie())) {
  1482.                 $idCategArticle .= $ac->getCategorie()->getId().',';
  1483.             }
  1484.         }
  1485.         $idCategArticle .= ',|';
  1486.         $idCategArticle str_replace(',,|'''$idCategArticle);
  1487.         $idCategArticle str_replace(',|'''$idCategArticle);
  1488.         $idCategClient "";
  1489.         if (is_object($client)) {
  1490.             foreach ($client->getClientCategorie() as $ac) {
  1491.                 if (is_object($ac->getCategorie())) {
  1492.                     $idCategClient .= $ac->getCategorie()->getId().',';
  1493.                 }
  1494.             }
  1495.         }
  1496.         $idCategClient .= ',|';
  1497.         $idCategClient str_replace(',,|'''$idCategClient);
  1498.         $idCategClient str_replace(',|'''$idCategClient);
  1499.         //echo "<div>AC : ".$a->getId()."</div>";
  1500.         /*
  1501.         echo "<div>ART : ".$idArticle."</div>";
  1502.         echo "<div>C : ".$client->getNom()." (".$idClient.")</div>";
  1503.         echo "<div>MARQUE : ".$idMarque."</div>";
  1504.         echo "<div>ID CAT REM ARTICLE : ".$idCategRemiseArticle."</div>";
  1505.         echo "<div>ID CAT REM CLIENT : ".$idCategRemiseClient."</div>";
  1506.         echo "<div>ID CAT ARTICLE : ".$idCategArticle."</div>";
  1507.         echo "<div>ID CAT CLIENT : ".$idCategClient."</div>";
  1508.         */
  1509.         if ($idCategClient != "") {
  1510.             $sql_categ_client "
  1511.                         AND
  1512.                         (
  1513.                         r.id IN (SELECT remise_id FROM remise__remise_categorie_client m WHERE m.categorie_id IN (".$idCategClient.") AND m.dateSuppression IS NULL)
  1514.                         OR
  1515.                         r.id NOT IN (SELECT remise_id FROM remise__remise_categorie_client m WHERE m.dateSuppression IS NULL)
  1516.                         )
  1517.                         ";
  1518.         } else {
  1519.             $sql_categ_client "
  1520.                         AND
  1521.                         (
  1522.                         r.id NOT IN (SELECT remise_id FROM remise__remise_categorie_client m WHERE m.dateSuppression IS NULL)
  1523.                         )
  1524.                         ";
  1525.         }
  1526.         if ($idCategArticle != "") {
  1527.             $sql_categ_article "
  1528.                         AND
  1529.                         (
  1530.                         r.id IN (SELECT remise_id FROM remise__remise_categorie_article m WHERE m.categorie_id IN (".$idCategArticle.") AND m.dateSuppression IS NULL)
  1531.                         OR
  1532.                         r.id NOT IN (SELECT remise_id FROM remise__remise_categorie_article m WHERE m.dateSuppression IS NULL)
  1533.                         )
  1534.                         ";
  1535.         } else {
  1536.             $sql_categ_article "
  1537.                         AND
  1538.                         (
  1539.                         r.id NOT IN (SELECT remise_id FROM remise__remise_categorie_article m WHERE m.dateSuppression IS NULL)
  1540.                         )
  1541.                         ";
  1542.         }
  1543.         if ($idCategRemiseClient != "") {
  1544.             $sql_categ_remise_client "
  1545.                         AND
  1546.                         (
  1547.                         r.id IN (SELECT remise_id FROM remise__categorie_remise_client_remise m WHERE m.categorie_remise_client_id IN (".$idCategRemiseClient.") AND m.dateSuppression IS NULL)
  1548.                         OR
  1549.                         r.id NOT IN (SELECT remise_id FROM remise__categorie_remise_client_remise m WHERE m.dateSuppression IS NULL)
  1550.                         )
  1551.                         ";
  1552.         } else {
  1553.             $sql_categ_remise_client "
  1554.                         AND
  1555.                         (
  1556.                         r.id NOT IN (SELECT remise_id FROM remise__categorie_remise_client_remise m WHERE m.dateSuppression IS NULL)
  1557.                         )
  1558.                         ";
  1559.         }
  1560.         if ($idMarque != "") {
  1561.             $sql_marque "
  1562.                         AND
  1563.                         (
  1564.                         r.id IN (SELECT remise_id FROM remise__remise_marque_article m WHERE m.marque_id = '".$idMarque."' AND m.dateSuppression IS NULL)
  1565.                         OR
  1566.                         r.id NOT IN (SELECT remise_id FROM remise__remise_marque_article m WHERE m.dateSuppression IS NULL)
  1567.                         )
  1568.                         ";
  1569.         } else {
  1570.             $sql_marque "
  1571.                         AND
  1572.                         (
  1573.                         r.id NOT IN (SELECT remise_id FROM remise__remise_marque_article m WHERE m.dateSuppression IS NULL)
  1574.                         )
  1575.                         ";
  1576.         }
  1577.         if ($idCategRemiseArticle != "") {
  1578.             $sql_categ_remise_article "
  1579.                         AND
  1580.                         (
  1581.                         r.id IN (SELECT remise_id FROM remise__categorie_remise_article_remise m WHERE m.categorie_remise_article_id = '".$idCategRemiseArticle."' AND m.dateSuppression IS NULL)
  1582.                         OR
  1583.                         r.id NOT IN (SELECT remise_id FROM remise__categorie_remise_article_remise m WHERE m.dateSuppression IS NULL)
  1584.                         )
  1585.                         ";
  1586.         } else {
  1587.             $sql_categ_remise_article "
  1588.                         AND
  1589.                         (
  1590.                         r.id NOT IN (SELECT remise_id FROM remise__categorie_remise_article_remise m WHERE m.dateSuppression IS NULL)
  1591.                         )
  1592.                         ";
  1593.         }
  1594.         $sql "SELECT id,libelle
  1595.                 FROM
  1596.                 remise__remise r
  1597.                 WHERE
  1598.                 r.dateSuppression IS NULL
  1599.                 AND
  1600.                 r.statut = 1
  1601.                 AND
  1602.                 r.date_debut <= '".$dateJ->format("Y-m-d H:i:s")."'
  1603.                 AND
  1604.                 r.date_fin >= '".$dateJ->format("Y-m-d H:i:s")."'
  1605.                 AND
  1606.                 r.quantite_restante > 0
  1607.                 AND
  1608.                 r.parent_id IS NULL
  1609.                 AND
  1610.                 (r.article_id IS NULL OR r.article_id = '".$idArticle."')
  1611.                 AND
  1612.                 (r.client_id IS NULL OR r.client_id = '".$idClient."')
  1613.                 ".$sql_marque."
  1614.                 ".$sql_categ_remise_article."
  1615.                 ".$sql_categ_remise_client."
  1616.                 ".$sql_categ_article."
  1617.                 ".$sql_categ_client."
  1618.                ";
  1619.         //echo "<div style='margin-bottom : 20px;margin-top:10px;'>".$sql."</div>";
  1620.         //exit;
  1621.         //$sql = "SELECT id,nom FROM client__client WHERE id='53' or id='4181'";
  1622.         $results $conn->executeQuery($sql)->fetchAllAssociative();
  1623.         //print_r($results);
  1624.         $tab_remise  = [];
  1625.         $repo_remise $this->entityManager->getRepository(Remise::class);
  1626.         for ($i 0$i count($results); $i++) {
  1627.             //echo "<div style='margin-top:10px;'>".$results[$i]['id']." ".$results[$i]['libelle']."</div>";
  1628.             //echo "<hr/>";
  1629.             $tab_remise[] = $repo_remise->find($results[$i]['id']);
  1630.         }
  1631.         //exit;
  1632.         //print_r($tab_remise);
  1633.         return $tab_remise;
  1634.     }
  1635.     //public function getRemiseCategorieClient(Article $article,$client = '',$montantTotal='',$prix='',$commande='',$articleCommande = '') {
  1636.     public function getRemiseCategorieClient($articleCommande ''$client ''$montantTotal ''$prix ''$commande ''$enregAuto false)
  1637.     {
  1638.         $remise_valeurs = ["valeur" => """type" => """remiseEnEuros" => "0""remiseId" => ""];
  1639.         $remise_tampon 0;
  1640.         //exit;
  1641.         //$repo_remise = $this->em->getRepository('DTCRemisesBundle:RemiseCategorieClient');
  1642.         $repo_remise $this->entityManager->getRepository(Remise::class);
  1643.         if (is_object($articleCommande) && ! $enregAuto) {
  1644.             //$remise_valeurs['test'] = "OK AC";
  1645.             $remise "";
  1646.             if (is_object($articleCommande->getRemiseInitial())) {
  1647.                 //$remise = $articleCommande->getRemiseInitial();
  1648.                 $idR $articleCommande->getRemiseInitial()->getId();
  1649.                 //$idR = 996;
  1650.                 $remise $repo_remise->findOneBy(["id" => $idR]);
  1651.                 if (is_object($remise)) {
  1652.                     $liste_remise = [$remise];
  1653.                 } else {
  1654.                     $liste_remise = [];
  1655.                 }
  1656.             } else {
  1657.                 $liste_remise = [];
  1658.             }
  1659.         } else {
  1660.             //$remise_valeurs['test'] = "ERROR AC";
  1661.             //$liste_remise = $repo_remise->getRemises($client);
  1662.             //echo "PPPPPPPPPPPPPP";
  1663.             $liste_remise $this->getRemisesPossible($articleCommande$client$montantTotal$prix$commande);
  1664.         }
  1665.         if (is_array($liste_remise) || is_object($liste_remise)) {
  1666.             foreach ($liste_remise as $remise) {
  1667.                 /** @var Remise $remise */
  1668.                 //echo "<div>".$remise->getId()." ".$remise->getMontant()." ".$remise->getTypeReduction()."</div>";
  1669.                 if (is_object($remise)) {
  1670.                     if ($remise->getTypeReduction() == "montant") {
  1671.                         if ($remise->getMontant() > $remise_tampon) {
  1672.                             $remise_valeurs['valeur']        = $remise->getMontant();
  1673.                             $remise_valeurs['type']          = "&euro;";
  1674.                             $remise_valeurs['remiseEnEuros'] = $remise->getMontant();
  1675.                             $remise_valeurs['remiseId']      = $remise->getId();
  1676.                             $remise_tampon                   $remise->getMontant();
  1677.                         }
  1678.                     } elseif ($remise->getTypeReduction() == "pourcentage") {
  1679.                         $remiseEnEuros $prix $remise->getMontant() / 100;
  1680.                         if ($remiseEnEuros $remise_tampon) {
  1681.                             $remise_valeurs['valeur']        = $remise->getMontant();
  1682.                             $remise_valeurs['type']          = "%";
  1683.                             $remise_valeurs['remiseEnEuros'] = $remiseEnEuros;
  1684.                             $remise_valeurs['remiseId']      = $remise->getId();
  1685.                             $remise_tampon                   $remiseEnEuros;
  1686.                         }
  1687.                     }
  1688.                     /*
  1689.                         echo "<div style='border:1px solid red;margin:15px;'>TEMP : ".$remise_tampon." ==> ".$remiseEnEuros." PRIX ".$prix."</div>";
  1690.                         print_r($remise_valeurs);
  1691.                         echo "<br/><br/>";
  1692.                         */
  1693.                 }
  1694.             }
  1695.         }
  1696.         /*
  1697.         echo "<br/><br/>";
  1698.         print_r($remise_valeurs);
  1699.         exit;
  1700.         */
  1701.         return $remise_valeurs;
  1702.     }
  1703.     /*
  1704.         public function getStock(Article $article){
  1705.             $result = null ;
  1706.             $repoComposant = $this->em->getRepository("DTCArticlesBundle:ArticleComposant");
  1707.             $nbrcompo = $repoComposant->findBy(array('articleCompose'=>$article->getId()));
  1708.             foreach($nbrcompo as $composant){
  1709.                 if($composant->getArticle()->getVirtuel()){
  1710.                         $stock = getStock($article);
  1711.                         if($result == null and $composant->getArticle()->getNonStocke() == false and  $composant->getArticle()->getNonCommandable() == false)$result = (int)$stock ;
  1712.                         if($stock < $result and $composant->getArticle()->getNonStocke() == false and  $composant->getArticle()->getNonCommandable() == false )$result = (int)$stock   ;
  1713.                 }else{
  1714.                         $stock = $composant->getArticle()->getStock()-$composant->getArticle()->getStockReserve();
  1715.                         $stock = $stock / $composant->getQuantite();
  1716.                         if($result === null and $composant->getArticle()->getNonStocke() == false and  $composant->getArticle()->getNonCommandable() == false){
  1717.                             $result = (int)$stock ;
  1718.                         }
  1719.                         if($stock<$result and $composant->getArticle()->getNonStocke() == false and  $composant->getArticle()->getNonCommandable() == false ){
  1720.                             $result = (int)$stock   ;
  1721.                         }
  1722.                 }
  1723.             }
  1724.             if ($result == null)return 0;
  1725.             return $result;
  1726.         }
  1727.         */
  1728.     public function getStock(Article $article$avecStockReserve true)
  1729.     {
  1730.         $results = [];
  1731.         $repoComposant $this->entityManager->getRepository(ArticleComposant::class);
  1732.         $nbrcompo      $repoComposant->findBy(['articleCompose' => $article->getId()]);
  1733.         foreach ($nbrcompo as $composant) {
  1734.             if ($composant->getArticle()->getNonStocke() == false) {
  1735.                 if ($composant->getArticle()->getVirtuel()) {
  1736.                     $stock $this->getStock($composant->getArticle(), $avecStockReserve);
  1737.                 } else {
  1738.                     $stock $composant->getArticle()->getStock();
  1739.                     if ($avecStockReserve) {
  1740.                         $stock -= max(0$composant->getArticle()->getStockReserve());
  1741.                     }
  1742.                 }
  1743.                 if ( ! empty($composant->getQuantite())) {
  1744.                     $stock $stock $composant->getQuantite();
  1745.                 }
  1746.                 $stock     floor($stock);
  1747.                 $stock     max(0$stock);
  1748.                 $results[] = $stock;
  1749.             }
  1750.         }
  1751.         if (count($results)) {
  1752.             return min($results);
  1753.         } else {
  1754.             return 0;
  1755.         }
  1756.     }
  1757.     public function getPrixAchatCompose(Article $article)
  1758.     {
  1759.         $prix          0;
  1760.         $results       = [];
  1761.         $repo_article  $this->entityManager->getRepository(Article::class);
  1762.         $repoComposant $this->entityManager->getRepository(ArticleComposant::class);
  1763.         $nbrcompo      $repoComposant->findBy(['articleCompose' => $article->getId()]);
  1764.         foreach ($nbrcompo as $composant) {
  1765.             /*
  1766.                 if($composant->getArticle()->getVirtuel()){
  1767.                     $pump = $this->getPrixAchatCompose($composant->getArticle());
  1768.                 } else {
  1769.                 }
  1770.                 */
  1771.             $pump $repo_article->getPumpR($composant->getArticle()->getId());
  1772.             if ($pump == 0) {
  1773.                 $pump $this->getPrixAchatNetEuro($composant->getArticle());
  1774.             }
  1775.             if ( ! empty($composant->getQuantite())) {
  1776.                 $pump $pump $composant->getQuantite();
  1777.             }
  1778.             $prix += $pump;
  1779.         }
  1780.         return $prix;
  1781.     }
  1782.     public function getEtatStock(Article $article$quantiteCommande $commande null)
  1783.     {
  1784.         if ($commande === null) {
  1785.             $quantiteSurLaCommande 0;
  1786.         } else {
  1787.             $quantiteSurLaCommande $this->getQuantiteArticleSurCommande($article$commande);
  1788.         }
  1789.         if ($article->getNonStocke() or $article->getNonCommandable()) {
  1790.             return "1";
  1791.         }
  1792.         $couleur           "";
  1793.         $debug             "";
  1794.         $stock_disponible  floatval($article->getStock()) - floatval($article->getStockReserve());
  1795.         $stock_avec_saisie $stock_disponible $quantiteSurLaCommande floatval($quantite);
  1796.         if ($article->getVirtuel()) {
  1797.             $donnees = [];
  1798.             foreach ($article->getArticlesComposants() as $composant) {
  1799.                 $articleTmp       $composant->getArticle();
  1800.                 $quantiteTmp      $composant->getQuantite() * $quantite;
  1801.                 $result           $this->getCouleurEtatStock($articleTmp$quantiteTmp);
  1802.                 $donnees[$result] = $result;
  1803.                 $debug            .= " test_".$result;
  1804.             }
  1805.             if (array_key_exists("cmde_pduit_possible_stock_mini"$donnees)) {
  1806.                 $couleur "1";
  1807.             }
  1808.             if (array_key_exists("cmde_pduit_possible_reappro"$donnees)) {
  1809.                 $couleur "1";
  1810.             }
  1811.             if (array_key_exists("cmde_pduit_impossible"$donnees)) {
  1812.                 $couleur "0";
  1813.             }
  1814.             //$couleur .= $debug;
  1815.         } elseif (floatval($article->getStock()) <= 0) {
  1816.             $couleur "0";
  1817.         } elseif ($stock_avec_saisie 0) {
  1818.             $couleur "1";
  1819.         } else {
  1820.             if ($stock_avec_saisie $article->getSeuilCritique()) {
  1821.                 $couleur "1";
  1822.             }
  1823.         }
  1824.         if ($couleur == "") {
  1825.             $couleur "1";
  1826.         }
  1827.         return $couleur;
  1828.     }
  1829.     public function totalementPrepare($articleCommande)
  1830.     {
  1831.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  1832.         if ( ! is_object($articleCommande)) {
  1833.             return false;
  1834.         }
  1835.         if ($articleCommande->getRalClient() == 0) {
  1836.             return true;
  1837.         }
  1838.         $total $repoArticleCommande->resteApreparer($articleCommande);
  1839.         if ($total == 0) {
  1840.             return true;
  1841.         }
  1842.         return false;
  1843.     }
  1844.     public function qteDejaPreparee($articleCommande$visualisation false)
  1845.     {
  1846.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  1847.         if ( ! is_object($articleCommande)) {
  1848.             return 0;
  1849.         }
  1850.         if ($visualisation == true && is_object($articleCommande->getCommande()) && is_object($articleCommande->getCommande()->getTypeDocumentCommercial())) {
  1851.             $typeDoc $articleCommande->getCommande()->getTypeDocumentCommercial();
  1852.             if ($typeDoc == or $typeDoc == 11) {
  1853.                 return $articleCommande->getQuantite();
  1854.             }
  1855.         }
  1856.         if ($articleCommande->getRalClient() == 0) {
  1857.             return $articleCommande->getQuantite();
  1858.         }
  1859.         $total $repoArticleCommande->getQuantitePreparee($articleCommande);
  1860.         return $total;
  1861.     }
  1862.     public function qtePrepareeOuLivreeOuFacturee($articleCommande)
  1863.     {
  1864.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  1865.         if ( ! is_object($articleCommande)) {
  1866.             return 0;
  1867.         }
  1868.         if ($articleCommande->getRalClient() == && $articleCommande->getQuantite() > 0) {
  1869.             return $articleCommande->getQuantite();
  1870.         }
  1871.         $total $repoArticleCommande->qtePrepareeOuLivreeOuFacturee($articleCommande);
  1872.         return $total;
  1873.     }
  1874.     public function qteDejaLivree($articleCommande)
  1875.     {
  1876.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  1877.         if ( ! is_object($articleCommande)) {
  1878.             return 0;
  1879.         }
  1880.         if ($articleCommande->getRalClient() == && $articleCommande->getQuantite() > 0) {
  1881.             return $articleCommande->getQuantite();
  1882.         }
  1883.         $total $repoArticleCommande->getQuantiteLivree($articleCommande);
  1884.         return $total;
  1885.     }
  1886.     public function qteDejaLivree2($articleCommande)
  1887.     {
  1888.         $articleCommande $this->getArticleCommandeCommande($articleCommande);
  1889.         if (is_object($articleCommande)) {
  1890.             $ralClient $articleCommande->getRalClient();
  1891.             $quantite  $articleCommande->getQuantite();
  1892.             if ($quantite 0) {
  1893.                 $ralClient min(0$ralClient);
  1894.             } else {
  1895.                 $ralClient max(0$ralClient);
  1896.             }
  1897.             $qteDejaLivree $quantite $ralClient;
  1898.             return $qteDejaLivree;
  1899.         } else {
  1900.             return 0;
  1901.         }
  1902.     }
  1903.     private function getArticleCommandeCommande($articleCommande$count 5)
  1904.     {
  1905.         while (is_object($articleCommande)) {
  1906.             $count--;
  1907.             if ($count 0) {
  1908.                 break;
  1909.             }
  1910.             $commande $articleCommande->getCommande();
  1911.             if (is_object($commande) && is_int($commande->getTypeDocumentCommercial()) && $commande->getTypeDocumentCommercial() == TypeDocumentCommercial::COMMANDE) {
  1912.                 return $articleCommande;
  1913.             } else {
  1914.                 $articleCommande $articleCommande->getArticleCommandeParent();
  1915.             }
  1916.         }
  1917.         return $articleCommande;
  1918.     }
  1919.     public function resteApreparer($articleCommande)
  1920.     {
  1921.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  1922.         if ( ! is_object($articleCommande)) {
  1923.             return $articleCommande['quantite'];
  1924.         }
  1925.         if ($articleCommande->getRalClient() == 0) {
  1926.             return 0;
  1927.         }
  1928.         $total $repoArticleCommande->resteApreparer($articleCommande);
  1929.         return $total;
  1930.     }
  1931.     public function getCouleurEtatStock(Article $article$quantiteCommande $commande null)
  1932.     {
  1933.         if ($commande === null) {
  1934.             $quantiteSurLaCommande 0;
  1935.         } else {
  1936.             $quantiteSurLaCommande $this->getQuantiteArticleSurCommande($article$commande);
  1937.         }
  1938.         $couleur "success";
  1939.         if ($article->getNonStocke() or $article->getNonCommandable()) {
  1940.             return $couleur;
  1941.         }
  1942.         $debug            "";
  1943.         $stock_disponible floatval($article->getStock()) - floatval($article->getStockReserve());
  1944.         $stock_disponible += $this->getRalFournisseur($articletrue);
  1945.         //$stock_disponible_avant_commande = floatval($article->getStock()) - floatval($article->getStockReserve());
  1946.         //$stock_disponible = $stock_disponible - floatval($quantite);
  1947.         $stock_avec_saisie $stock_disponible $quantiteSurLaCommande floatval($quantite);
  1948.         if ($article->getVirtuel()) {
  1949.             $donnees = [];
  1950.             foreach ($article->getArticlesComposants() as $composant) {
  1951.                 $articleTmp       $composant->getArticle();
  1952.                 $quantiteTmp      $composant->getQuantite() * $quantite;
  1953.                 $result           $this->getCouleurEtatStock($articleTmp$quantiteTmp);
  1954.                 $donnees[$result] = $result;
  1955.                 $debug            .= " test_".$result;
  1956.             }
  1957.             if (array_key_exists("cmde_pduit_possible_stock_mini"$donnees)) {
  1958.                 $couleur "cmde_pduit_possible_stock_mini";
  1959.             }
  1960.             if (array_key_exists("cmde_pduit_possible_reappro"$donnees)) {
  1961.                 $couleur "cmde_pduit_possible_reappro";
  1962.             }
  1963.             if (array_key_exists("cmde_pduit_impossible"$donnees)) {
  1964.                 $couleur "cmde_pduit_impossible";
  1965.             }
  1966.             $couleur .= $debug;
  1967.         } /*
  1968.         elseif($stock_disponible_avant_commande == 0) $couleur = "cmde_pduit_possible_reappro";
  1969.         else if($stock_disponible < 0) $couleur = "cmde_pduit_impossible";
  1970.         else if($stock_disponible_avant_commande < $quantite ) $couleur = "cmde_pduit_possible_reappro";
  1971.         else {
  1972.             $nouveauStock = $stock_disponible_avant_commande - $quantite;
  1973.             //echo $nouveauStock." ".$article->getSeuilMiniCommandeFournisseur();
  1974.             if($nouveauStock < $article->getSeuilMiniCommandeFournisseur()) $couleur = "cmde_pduit_possible_stock_mini";
  1975.         }
  1976.                  *
  1977.                  */
  1978.         elseif (floatval($article->getStock()) <= 0) {
  1979.             $couleur "cmde_pduit_impossible";
  1980.         } //elseif ($stock_disponible <= 0) $couleur = "cmde_pduit_impossible";
  1981.         elseif ($stock_avec_saisie 0) {
  1982.             $couleur "cmde_pduit_possible_reappro";
  1983.         } else {
  1984.             //if($stock_avec_saisie < $article->getSeuilMiniCommandeFournisseur()) $couleur = "cmde_pduit_possible_stock_mini";
  1985.             if ($stock_avec_saisie $article->getSeuilCritique()) {
  1986.                 //echo "OKOKA ".$stock_avec_saisie." ".$article->getSeuilCritique();
  1987.                 //$couleur = "cmde_pduit_possible_stock_mini";
  1988.                 $couleur "cmde_pduit_possible_stock_critique";
  1989.             }
  1990.         }
  1991.         //echo $couleur;
  1992.         //Article
  1993.         return $couleur;
  1994.     }
  1995.     public function getQuantiteArticleSurCommande(Article $articleCommande $commande)
  1996.     {
  1997.         $repo   $this->entityManager->getRepository(ArticleCommande::class);
  1998.         $retour $repo->getQuantiteArticleSurCommande($article$commande);
  1999.         return $retour;
  2000.     }
  2001.     public function getCouleurQteF2($articleCommande)
  2002.     {
  2003.         $couleur "";
  2004.         if ($articleCommande->getQuantite() < $articleCommande->getConditionAchat()->getQuantite()) {
  2005.             $couleur 'warning';
  2006.         }
  2007.         $retour $this->getQteConseillee($articleCommande->getArticle(), $articleCommande->getConditionAchat());
  2008.         if ($articleCommande->getQuantite() < $retour['qteMini']) {
  2009.             $couleur 'danger';
  2010.         }
  2011.         return $couleur;
  2012.     }
  2013.     public function getCouleurQteF(Article $article$quantite$fournisseur null)
  2014.     {
  2015.         $couleur "";
  2016.         $retour  $this->getQteConseillee($article);
  2017.         /*
  2018.             if ($article->getSeuilMaxiCommandeFournisseur() != '' && $retour['qteMaxi'] != '' && ($quantite > $article->getSeuilMaxiCommandeFournisseur() || $quantite > $retour['qteMaxi']))
  2019.                 $couleur = 'warning';
  2020.              *
  2021.              */
  2022.         //Conditions Achat
  2023.         if ($fournisseur != null) {
  2024.             $repoConditionsAchat $this->entityManager->getRepository(ConditionAchat::class);
  2025.             $conditions          $repoConditionsAchat->findBy(['article' => $article->getId(), 'fournisseur' => $fournisseur]);
  2026.         } else {
  2027.             $conditions $article->getConditionsAchat();
  2028.         }
  2029.         foreach ($conditions as $condition) {
  2030.             if ($quantite $condition->getQuantite()) {
  2031.                 $couleur 'warning';
  2032.             }
  2033.             /*
  2034.                     if($condition->getConditionnement() > 1){
  2035.                         $modulo = $quantite % $condition->getConditionnement();
  2036.                         if ($quantite > $condition->getQuantite() && $modulo != 0){
  2037.                             $couleur = 'danger';
  2038.                             return $couleur;
  2039.                         }
  2040.                     }
  2041.                      *
  2042.                      */
  2043.         }
  2044.         if ($quantite $retour['qteMini']) {
  2045.             $couleur 'danger';
  2046.         }
  2047.         //if ($quantite < $article->getSeuilMiniCommandeFournisseur() || $quantite < $retour['qteMini'])
  2048.         //$couleur = 'couleur'.$retour['qteMini'];
  2049.         return $couleur;
  2050.     }
  2051.     public function sauvegarder($article$categories)
  2052.     {
  2053.         $repo_categorie         $this->entityManager->getRepository(Categorie::class);
  2054.         $repo_article_categorie $this->entityManager->getRepository(ArticleCategorie::class);
  2055.         $articleCategorie       $article->getArticleCategorie();
  2056.         foreach ($articleCategorie as $ac) {
  2057.             if ( ! in_array($ac->getCategorie()->getId(), $categories)) {
  2058.                 $this->entityManager->remove($ac);
  2059.             }
  2060.         }
  2061.         for ($i 0$i count($categories); $i++) {
  2062.             $c $repo_categorie->find($categories[$i]);
  2063.             if (is_object($c)) {
  2064.                 $relation $repo_article_categorie->findOneBy(['article' => $article'categorie' => $c]);
  2065.                 if ( ! is_object($relation)) {
  2066.                     $objet = new ArticleCategorie();
  2067.                     $objet->setCategorie($c);
  2068.                     $objet->setArticle($article);
  2069.                     $this->entityManager->persist($objet);
  2070.                 }
  2071.             }
  2072.         }
  2073.         $this->entityManager->flush();
  2074.     }
  2075.     public function setFournisseurDefaut(Article $article)
  2076.     {
  2077.         $fournisseur '';
  2078.         /*
  2079.             $conditionsAchat = $article->getConditionsAchat();
  2080.             //Le fournisseur de la condition d'achat par defaut
  2081.             foreach($conditionsAchat as $conditionAchat)
  2082.             {
  2083.                 if ($conditionAchat->getDefaut() == true)
  2084.                     $fournisseur = $conditionAchat->getFournisseur();
  2085.             }
  2086.             */
  2087.         $qteConseillee $this->getQteConseillee($article);
  2088.         if ( ! empty($qteConseillee['condition']) && is_object($qteConseillee['condition'])) {
  2089.             $fournisseur $qteConseillee['condition']->getFournisseur();
  2090.         }
  2091.         //Le fournisseur de la premiere condition d'achat ayant un fournisseur
  2092.         if ( ! is_object($fournisseur) && isset($conditionAchat)) {
  2093.             foreach ($conditionsAchat as $conditionAchat) {
  2094.                 if ( ! is_object($fournisseur)) {
  2095.                     $fournisseur $conditionAchat->getFournisseur();
  2096.                 }
  2097.             }
  2098.         }
  2099.         //Le fournisseur du dernier achat.
  2100.         if ( ! is_object($fournisseur)) {
  2101.             $mvtStock $this->entityManager->getRepository(MouvementStock::class)->findOneBy(
  2102.                   [
  2103.                       'article'              => $article->getId(),
  2104.                       'raisonMouvementStock' => 3,
  2105.                   ]
  2106.                 , ['date' => 'DESC']
  2107.             );
  2108.             if (is_object($mvtStock)) {
  2109.                 $fournisseur $mvtStock->getFournisseur();
  2110.             }
  2111.         }
  2112.         if (is_object($fournisseur)) {
  2113.             $article->setFournisseurDefaut($fournisseur);
  2114.             $this->entityManager->persist($article);
  2115.             $this->entityManager->flush();
  2116.         }
  2117.     }
  2118. //}
  2119.     public function getQteConseillee($articleConditionAchat $condition nullFournisseur $fournisseur null)
  2120.     {
  2121.         $qteConseillee 1;
  2122.         $qteMini       1;
  2123.         $qteMaxi       false;
  2124.         //$qteMini = abs($article->getStock()-$article->getStockReserve()+$article->getRalFournisseur());
  2125.         $stockVirtuel $article->getStock() - $article->getStockReserve() + $article->getRalFournisseur();
  2126.         if ($stockVirtuel 0) {
  2127.             $qteMini abs($stockVirtuel);
  2128.         }
  2129.         if ($article->getSeuilMiniCommandeFournisseur() >= 0) {
  2130.             $qteMini $article->getSeuilMiniCommandeFournisseur() - $stockVirtuel;
  2131.         }
  2132.         if ($article->getSeuilMaxiCommandeFournisseur() > 0) {
  2133.             $qteMaxi true;
  2134.             //$qteConseillee = $article->getSeuilMaxiCommandeFournisseur()+$qteMini;
  2135.             $qteConseillee $article->getSeuilMaxiCommandeFournisseur() - $stockVirtuel;
  2136.         } elseif ($article->getSeuilMiniCommandeFournisseur() >= 0) {
  2137.             //$qteConseillee = $article->getSeuilMiniCommandeFournisseur()+$qteMini;
  2138.             $qteConseillee $article->getSeuilMiniCommandeFournisseur() - $stockVirtuel;
  2139.         } elseif ($stockVirtuel 0) {
  2140.             $qteConseillee abs($stockVirtuel);
  2141.         }
  2142.         if ($qteConseillee 0) {
  2143.             $qteConseillee 1;
  2144.         }
  2145.         if ($qteMini 0) {
  2146.             $qteMini 1;
  2147.         }
  2148.         if ( ! is_object($condition)) {
  2149.             $variables = [
  2150.                 'article' => $article->getId(),
  2151.                 'defaut'  => true,
  2152.             ];
  2153.             if (is_object($fournisseur)) {
  2154.                 $variables['fournisseur'] = $fournisseur;
  2155.             }
  2156.             $condition $this->entityManager->getRepository(ConditionAchat::class)->findOneBy($variables);
  2157.         }
  2158.         if ( ! is_object($condition)) {
  2159.             $variables = [
  2160.                 'article' => $article->getId(),
  2161.             ];
  2162.             if (is_object($fournisseur)) {
  2163.                 $variables['fournisseur'] = $fournisseur;
  2164.             }
  2165.             $conditions $this->entityManager->getRepository(ConditionAchat::class)->findBy(
  2166.                 $variables,
  2167.                 ['prixAchatNet' => 'ASC'],
  2168.                 1,
  2169.                 0
  2170.             );
  2171.             if (count($conditions)) {
  2172.                 $condition $conditions[0];
  2173.             }
  2174.         }
  2175.         if (is_object($condition)) {
  2176.             $quantiteMini    $condition->getQuantite();
  2177.             $qteMini         max($quantiteMini$qteMini);
  2178.             $qteConseillee   ceil(max($quantiteMini$qteConseillee));
  2179.             $conditionnement $condition->getConditionnement();
  2180.             if ($conditionnement != 0) {
  2181.                 if ($qteConseillee $conditionnement) {
  2182.                     $qteConseillee $conditionnement;
  2183.                 } elseif ($qteConseillee $conditionnement != 0) {
  2184.                     $qteConseillee ceil($qteConseillee $conditionnement) * $conditionnement;
  2185.                 }
  2186.             }
  2187.             $retour['condition'] = $condition;
  2188.         }
  2189.         $retour['qteConseillee'] = $qteConseillee;
  2190.         $retour['qteMini']       = $qteMini;
  2191.         $retour['qteMaxi']       = $qteMaxi;
  2192.         //print_r($retour);
  2193.         return $retour;
  2194.     }
  2195.     public function majQteConseillee($articleConditionAchat $condition null)
  2196.     {
  2197.         //quantite_conseillee_mini quantite_conseillee quantite_conseillee_maxi
  2198.         $tableau_donnee = [];
  2199.         $retour $this->getQteConseillee($article$condition);
  2200.         if ($article->getQuantiteConseillee() != $retour['qteConseillee']) {
  2201.             //$article->setQuantiteConseillee($retour['qteConseillee']);
  2202.             $tableau_donnee["quantite_conseillee"] = $retour['qteConseillee'];
  2203.         }
  2204.         if ($article->getQuantiteConseilleeMini() != $retour['qteMini']) {
  2205.             //$article->setQuantiteConseilleeMini($retour['qteMini']);
  2206.             $tableau_donnee["quantite_conseillee_mini"] = $retour['qteMini'];
  2207.         }
  2208.         if ( ! in_array($retour['qteMaxi'], [truefalse]) && $article->getQuantiteConseilleeMaxi() != $retour['qteMaxi']) {
  2209.             //$article->setQuantiteConseilleeMaxi($retour['qteMaxi']);
  2210.             $tableau_donnee["quantite_conseillee_maxi"] = $retour['qteMaxi'];
  2211.         }
  2212.         if ( ! empty($retour['condition']) && is_object($retour['condition']) && is_object($retour['condition']->getFournisseur())) {
  2213.             $tableau_donnee["fournisseur_defaut_id"]     = $retour['condition']->getFournisseur()->getId();
  2214.             $tableau_donnee["condition_achat_defaut_id"] = $retour['condition']->getId();
  2215.         }
  2216.         if (count($tableau_donnee) > 0) {
  2217.             $conn $this->entityManager->getConnection();
  2218.             $conn->update('article__article'$tableau_donnee, ['id' => $article->getId()]);
  2219.         }
  2220.         //$this->em->persist($article);
  2221.         //$this->em->flush();
  2222.     }
  2223.     public function ___majQteConseillee($articleConditionAchat $condition null)
  2224.     {
  2225.         /*
  2226.         $qteConseillee = 1;
  2227.         $qteMini = 1;
  2228.         //$qteMini = abs($article->getStock()-$article->getStockReserve()+$article->getRalFournisseur());
  2229.         $stockVirtuel = $article->getStock()-$article->getStockReserve()+$article->getRalFournisseur();
  2230.         if($stockVirtuel < 0) $qteMini = abs($stockVirtuel);
  2231.             if($article->getSeuilMaxiCommandeFournisseur() > 0) {
  2232.                 $qteMaxi = true;
  2233.                 //$qteConseillee = $article->getSeuilMaxiCommandeFournisseur()+$qteMini;
  2234.                 $qteConseillee = $article->getSeuilMaxiCommandeFournisseur()-$stockVirtuel;
  2235.             } else if($article->getSeuilMiniCommandeFournisseur() >= 0){
  2236.                 //$qteConseillee = $article->getSeuilMiniCommandeFournisseur()+$qteMini;
  2237.                 $qteConseillee = $article->getSeuilMiniCommandeFournisseur()-$stockVirtuel;
  2238.                 $qteMaxi = false;
  2239.             } else if($stockVirtuel < 0) {
  2240.                 $qteConseillee = abs($stockVirtuel);
  2241.             }
  2242.         if($qteConseillee < 0) $qteConseillee = 0;
  2243.         if (is_object($condition)){
  2244.             $quantiteMini = $condition->getQuantite();
  2245.             $quantiteConditionnement = $condition->getConditionnement();
  2246.             $quantiteR = max($quantiteMini, $qteConseillee);
  2247.             $qteConseillee = ceil($quantiteR/$quantiteConditionnement)*$quantiteConditionnement;
  2248.             $qteMini = max($quantiteMini, $quantiteConditionnement, $qteMini);
  2249.         }
  2250.          *
  2251.          */
  2252.         $retour $this->getQteConseillee($article$condition);
  2253.         if ($article->getQuantiteConseillee() != $retour['qteConseillee']) {
  2254.             $article->setQuantiteConseillee($retour['qteConseillee']);
  2255.         }
  2256.         if ($article->getQuantiteConseilleeMini() != $retour['qteMini']) {
  2257.             $article->setQuantiteConseilleeMini($retour['qteMini']);
  2258.         }
  2259.         if ($article->getQuantiteConseilleeMaxi() != $retour['qteMaxi']) {
  2260.             $article->setQuantiteConseilleeMaxi($retour['qteMaxi']);
  2261.         }
  2262.         $this->entityManager->persist($article);
  2263.         $this->entityManager->flush();
  2264.     }
  2265.     public function _majQteConseillee($articleConditionAchat $condition null)
  2266.     {
  2267.         $qteConseillee 0;
  2268.         $qteMini       abs($article->getStock() - $article->getStockReserve() + $article->getRalFournisseur());
  2269.         if ($article->getSeuilMaxiCommandeFournisseur() > 0) {
  2270.             $qteMaxi       true;
  2271.             $qteConseillee $article->getSeuilMaxiCommandeFournisseur() + $qteMini;
  2272.         } elseif ($article->getSeuilMiniCommandeFournisseur() >= 0) {
  2273.             $qteConseillee $article->getSeuilMiniCommandeFournisseur() + $qteMini;
  2274.             $qteMaxi       false;
  2275.         } else {
  2276.             $qteConseillee $qteMini;
  2277.         }
  2278.         if (is_object($condition)) {
  2279.             $quantiteMini            $condition->getQuantite();
  2280.             $quantiteConditionnement $condition->getConditionnement();
  2281.             $quantiteR               max($quantiteMini$qteConseillee);
  2282.             $qteConseillee           ceil($quantiteR $quantiteConditionnement) * $quantiteConditionnement;
  2283.             $qteMini                 max($quantiteMini$quantiteConditionnement$qteMini);
  2284.         }
  2285.         $article->setQuantiteConseillee($qteConseillee);
  2286.         $article->setQuantiteConseilleeMini($qteMini);
  2287.         $article->setQuantiteConseilleeMaxi($qteMaxi);
  2288.         $this->entityManager->persist($article);
  2289.         $this->entityManager->flush();
  2290.     }
  2291.     public function majQteConseilleeApresImport()
  2292.     {
  2293.         $repoArticle $this->entityManager->getRepository(Article::class);
  2294.         $repoArticle->updateACommander();
  2295.         $articlesAmaj $repoArticle->findByACommander(true);
  2296.         foreach ($articlesAmaj as $article) {
  2297.             $this->majQteConseillee($article);
  2298.         }
  2299.     }
  2300.     public function getArticlesComposantsAvecArborescence(Article $article$retour$quantite 1)
  2301.     {
  2302.         $articlesComposants $article->getArticlesComposants();
  2303.         $quantiteComposant  $article->getStockReserve();
  2304.         foreach ($articlesComposants as $articleComposant) {
  2305.             $quantiteComposant $articleComposant->getQuantite() * $quantite;
  2306.             $ssArticle         $articleComposant->getArticle();
  2307.             if (count($ssArticle->getArticlesComposants()) > 0) {
  2308.                 $retour2                     "";
  2309.                 $retour2                     $this->getArticlesComposantsAvecArborescence($ssArticle$retour2$quantiteComposant);
  2310.                 $retour[$ssArticle->getId()] = [$articleComposant$retour2];
  2311.             } else {
  2312.                 $articleComposant->setQuantite($quantiteComposant);
  2313.                 $retour[$ssArticle->getId()] = $articleComposant;
  2314.             }
  2315.         }
  2316.         return $retour;
  2317.     }
  2318.     public function majClientsEnRal(Article $article)
  2319.     {
  2320.         //Supprimer tous les liasons clients
  2321.         /*foreach($article->getClientsEnRal() as $client){
  2322.             $article->removeClientsEnRal($client);
  2323.         }*/
  2324.         $conn $this->entityManager->getConnection();
  2325.         $sql  "DELETE FROM `article_client` WHERE article_id = ".$article->getId()."";
  2326.         $stmt $conn->prepare($sql);
  2327.         $stmt->execute();
  2328.         //echo "<div>sql : ".$sql."</div>";
  2329.         //exit;
  2330.         $repoArticle $this->entityManager->getRepository(Article::class);
  2331.         $clients     $repoArticle->getClientsEnRal($article);
  2332.         //Ajouter les clients
  2333.         $repoClient $this->entityManager->getRepository(Client::class);
  2334.         foreach ($clients as $client) {
  2335.             //echo "<div>client : ".$client['id']."</div>";
  2336.             //$client = $repoClient->find($client['id']);
  2337.             //$article->addClientsEnRal($client);
  2338.             $tableau_donnee               = [];
  2339.             $tableau_donnee["client_id"]  = $client['id'];
  2340.             $tableau_donnee["article_id"] = $article->getId();
  2341.             $conn->insert('article_client'$tableau_donnee);
  2342.         }
  2343.         //$this->em->persist($article);
  2344.         //$this->em->flush();
  2345.         //exit;
  2346.     }
  2347.     public function ____majClientsEnRal(Article $article)
  2348.     {
  2349.         //Supprimer tous les liasons clients
  2350.         foreach ($article->getClientsEnRal() as $client) {
  2351.             $article->removeClientsEnRal($client);
  2352.         }
  2353.         $repoArticle $this->entityManager->getRepository(Article::class);
  2354.         $clients     $repoArticle->getClientsEnRal($article);
  2355.         //Ajouter les clients
  2356.         $repoClient $this->entityManager->getRepository(Client::class);
  2357.         foreach ($clients as $client) {
  2358.             $client $repoClient->find($client['id']);
  2359.             $article->addClientsEnRal($client);
  2360.         }
  2361.         $this->entityManager->persist($article);
  2362.         $this->entityManager->flush();
  2363.     }
  2364.     public function modifierStockComposants(Article $composeArticleCommande $ac$variation$raisonMvtStock 1Commande $commande null)
  2365.     {
  2366.         $composants $compose->getArticlesComposants();
  2367.         $repo_raison_mvt_stck $this->entityManager->getRepository(RaisonMouvementStock::class);
  2368.         $repo_emplacement     $this->entityManager->getRepository(Emplacement::class);
  2369.         if ( ! is_object($commande)) {
  2370.             $commande $ac->getCommande();
  2371.         }
  2372.         foreach ($composants as $articleComposant) {
  2373.             $article $articleComposant->getArticle();
  2374.             //echo "<div>COMPOSANT : ".$article->getId()."  VAR(".$variation.") QTE (".floatval($articleComposant->getQuantite()).")</div>";
  2375.             $test        "<div>COMPOSANT : ".$article->getId()."  VAR(".$variation.") QTE (".floatval($articleComposant->getQuantite()).")</div>";
  2376.             $quantiteTmp $variation floatval($articleComposant->getQuantite());
  2377.             if ($article->getVirtuel() == true && $article->getProduitInterne() == true) {
  2378.                 //echo "<div>COMPOSANT COMPOSE: ".$article->getId()."</div>";
  2379.                 $this->modifierStockComposants($article$ac$quantiteTmp$raisonMvtStock$commande);
  2380.             } else {
  2381.                 //Creer un mouvement de stock
  2382.                 $mvtStock = new MouvementStock;
  2383.                 $mvtStock->setArticle($article);
  2384.                 $mvtStock->setArticleCommandeVirtuel($ac);
  2385.                 if (is_object($commande)) {
  2386.                     $mvtStock->setCommandeVirtuel($commande);
  2387.                 }
  2388.                 $mvtStock->setQuantite($quantiteTmp);
  2389.                 if ($raisonMvtStock != '') {
  2390.                     $raisonMouvementStock $repo_raison_mvt_stck->find($raisonMvtStock);
  2391.                     if (is_object($raisonMouvementStock)) {
  2392.                         $mvtStock->setRaisonMouvementStock($raisonMouvementStock);
  2393.                     }
  2394.                     if (is_object($raisonMouvementStock) and ($raisonMouvementStock->getId() == 11 or $raisonMouvementStock->getId() == 12)) {
  2395.                         $quantiteTmp "-".$quantiteTmp;
  2396.                         $quantiteTmp str_replace("--"""$quantiteTmp);
  2397.                         $mvtStock->setQuantite($quantiteTmp);
  2398.                     }
  2399.                 }
  2400.                 $mvtStock->setCommande($ac->getCommande());
  2401.                 $mvtStock->setEstUnComposant(true);
  2402.                 //$mvtStock->setCommentaire("modifierStockComposants ".$test);
  2403.                 /*
  2404.                 $nbEmplacement = count($article->getEmplacements());
  2405.                 //echo "<div>NB E ".$nbEmplacement."</div>";
  2406.                 if($nbEmplacement > 0) {
  2407.                     $compteur = 0;
  2408.                     foreach($article->getEmplacements() as $e) {
  2409.                         //echo "<div>".$e->getLibelle()." cpt : ".$compteur."</div>";
  2410.                         if($compteur == 0) {
  2411.                             $mvtStock->setEmplacement($e);
  2412.                         }
  2413.                         $compteur++;
  2414.                     }
  2415.                 }
  2416.                                          *
  2417.                                          */
  2418.                 //emplacement par défaut
  2419.                 $emplacementPardefaut $repo_emplacement->findOneBy(['article' => $article->getId(), 'defaut' => true'visibilite' => true]);
  2420.                 if ( ! is_object($emplacementPardefaut)) {
  2421.                     $emplacementPardefaut $repo_emplacement->findOneBy(['article' => $article->getId(), 'visibilite' => true]);
  2422.                 }
  2423.                 if (is_object($emplacementPardefaut)) {
  2424.                     $mvtStock->setEmplacement($emplacementPardefaut);
  2425.                 }
  2426.                 $this->entityManager->persist($ac);
  2427.                 $this->entityManager->persist($mvtStock);
  2428.                 $this->mouvementStockService->sauvegarder($mvtStock$article);
  2429.                 /*
  2430.                 $stock = floatval($articleComposant->getArticle()->getStock())+$quantiteTmp;
  2431.                 $articleComposant->setStock($stock);
  2432.                 $this->em->persist($articleComposant);
  2433.                  *
  2434.                  */
  2435.             }
  2436.         }
  2437.         $this->entityManager->flush();
  2438.     }
  2439.     //if($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true){
  2440.     public function modifierStockReserveComposants(Article $compose$variation)
  2441.     {
  2442.         $repo_emplacement $this->entityManager->getRepository(Emplacement::class);
  2443.         $composants       $compose->getArticlesComposants();
  2444.         foreach ($composants as $articleComposant) {
  2445.             $quantiteTmp $variation floatval($articleComposant->getQuantite());
  2446.             $article     $articleComposant->getArticle();
  2447.             //echo "<div>ART ".$article->getReference()."</div>";
  2448.             if ($articleComposant->getArticle()->getVirtuel() == true && $articleComposant->getArticle()->getProduitInterne() == true) {
  2449.                 $this->modifierStockReserveComposants($article$quantiteTmp);
  2450.             } else {
  2451.                 if ($article->getVirtuel() == true or $article->getNonStocke() == true or $article->getNonCommandable() == true or $article->getMainOeuvre() == true) {
  2452.                 } else {
  2453.                     $stockReserve floatval($article->getStockReserve()) + $quantiteTmp;
  2454.                     $stockReserve max(0$stockReserve);
  2455.                     if (!= and $article->getReference() == "SSSEKR115") {
  2456.                         //echo "<div>SR ".$article->getStockReserve()."</div>";
  2457.                         //echo "<div>ARTICLE ".$article->getReference()."</div>";
  2458.                         //echo "<div>variation ".$variation."</div>";
  2459.                         //echo "<div>quantiteTmp ".$quantiteTmp."</div>";
  2460.                         //echo "<div>stockReserve ".$stockReserve."</div>";
  2461.                         //echo "<div>quantiteTmp ".$quantiteTmp."</div>";
  2462.                         //echo "<div><br/><br/></div>";
  2463.                     }
  2464.                     if ($quantiteTmp != 0) {
  2465.                         $article->setStockReserve($stockReserve);
  2466.                         $this->ebayService->publierAnnonce($article->getId());
  2467.                         /*
  2468.                         $nbEmplacement = count($article->getEmplacements());
  2469.                         //echo "<div>NB E ".$nbEmplacement."</div>";
  2470.                         if($nbEmplacement > 0) {
  2471.                             $compteur = 0;
  2472.                             foreach($article->getEmplacements() as $e) {
  2473.                                 //echo "<div>".$e->getLibelle()." cpt : ".$compteur."</div>";
  2474.                                 if($compteur == 0) {
  2475.                                     $e->setStockReserve(floatval($e->getStockReserve())+floatval($quantiteTmp));
  2476.                                     $this->em->persist($e);
  2477.                                 }
  2478.                                 $compteur++;
  2479.                             }
  2480.                         }
  2481.                                 */
  2482.                         //emplacement par défaut
  2483.                         $emplacementPardefaut $repo_emplacement->findOneBy(['article' => $article->getId(), 'defaut' => true'visibilite' => true]);
  2484.                         if ( ! is_object($emplacementPardefaut)) {
  2485.                             $emplacementPardefaut $repo_emplacement->findOneBy(['article' => $article->getId(), 'visibilite' => true]);
  2486.                         }
  2487.                         if (is_object($emplacementPardefaut)) {
  2488.                             $stockReserveEmplacement floatval($emplacementPardefaut->getStockReserve()) + floatval($quantiteTmp);
  2489.                             $stockReserveEmplacement max(0$stockReserveEmplacement);
  2490.                             $emplacementPardefaut->setStockReserve($stockReserveEmplacement);
  2491.                             $this->entityManager->persist($emplacementPardefaut);
  2492.                         }
  2493.                     }
  2494.                     if (!= and $article->getReference() == "SSSEKR115") {
  2495.                         //echo "<div>ARTICLE SR ".$article->getStockReserve()."</div>";
  2496.                         //echo "<div><br/><br/></div>";
  2497.                     }
  2498.                     $this->entityManager->persist($article);
  2499.                     $this->entityManager->flush();
  2500.                 }
  2501.             }
  2502.         }
  2503.         //$this->em->flush();
  2504.         //exit;
  2505.     }
  2506.     public function majConditionAchatImport(Article $article$prix null)
  2507.     {
  2508.         $repo_condition_achat $this->entityManager->getRepository(ConditionAchat::class);
  2509.         $conditionAchat       $repo_condition_achat->findOneBy(['article' => $article'defaut' => true]);
  2510.         if (is_object($conditionAchat)) {
  2511.             if ($prix === null) {
  2512.                 $prix        $article->getPrixBase();
  2513.                 $prixArticle $article->getPrixBase();
  2514.             } else {
  2515.                 $prix        str_replace(",""."$prix);
  2516.                 $prixArticle $prix;
  2517.             }
  2518.             $tauxChange  1;
  2519.             $fournisseur $conditionAchat->getFournisseur();
  2520.             if (is_object($fournisseur)) {
  2521.                 $devise $fournisseur->getDevise();
  2522.             }
  2523.             if (is_object($devise) && $devise->getTauxChange() != 0) {
  2524.                 $tauxChange $devise->getTauxChange();
  2525.             }
  2526.             $prix $prix $tauxChange//prix de base converti en devise
  2527.             $conditionAchat->setPrixAchatBrut($prix);
  2528.             $prixAchatNet $prix * (- ($conditionAchat->getTauxRemise() / 100)) * (- ($conditionAchat->getTauxRemiseSupplementaire() / 100));
  2529.             $coefficient  $conditionAchat->getCoefficient();
  2530.             if ($coefficient != 0) {
  2531.                 $prixAchatNet $prixAchatNet $coefficient;
  2532.             }
  2533.             $prixAchatNet += $conditionAchat->getFraisAnnexes();
  2534.             $conditionAchat->setPrixAchatNet($prixAchatNet);
  2535.             $this->entityManager->persist($conditionAchat);
  2536.             if ($article->getMajPrix() == 1) {
  2537.                 $article->setPrixBase($prixArticle $tauxChange);
  2538.                 $prixVente floatval($article->getPrixVente());
  2539.                 //$prixVente = $article->getCoefficientPrixBaseVente()*$prixArticle;
  2540.                 //$article->setPrixVente($prixVente);
  2541.                 $margeReelle $prixVente $article->getCpump();
  2542.                 $article->setMargeReelle($margeReelle);
  2543.                 $this->entityManager->persist($article);
  2544.             }
  2545.             $this->entityManager->flush();
  2546.         }
  2547.     }
  2548.     public function majEnFonctionDuPrixAchat(Article $article$prix null)
  2549.     {
  2550.         //Si maj auto du prix cochée, le prix de base de l'article = le prix brut de la condition d'achat par défaut
  2551.         if ($article->getMajPrix() == 1) {
  2552.             $repo_condition_achat $this->entityManager->getRepository(ConditionAchat::class);
  2553.             //$conditionAchat = $repo_condition_achat->findOneBy(array('article'=>$article, 'defaut'=>true));
  2554.             $conditionAchat '';
  2555.             $qteConseillee  $this->getQteConseillee($article);
  2556.             if ( ! empty($qteConseillee['condition'])) {
  2557.                 $conditionAchat $qteConseillee['condition'];
  2558.             }
  2559.             if (is_object($conditionAchat)) {
  2560.                 if ($prix === null) {
  2561.                     $prix $conditionAchat->getPrixAchatBrut();
  2562.                 }
  2563.                 if ($conditionAchat->getCoefficientConditionnement() != 0) {
  2564.                     $prix $prix $conditionAchat->getCoefficientConditionnement();
  2565.                 }
  2566.                 $tauxChange  1;
  2567.                 $fournisseur $conditionAchat->getFournisseur();
  2568.                 if (is_object($fournisseur)) {
  2569.                     $devise $fournisseur->getDevise();
  2570.                 }
  2571.                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  2572.                     $tauxChange $devise->getTauxChange();
  2573.                 }
  2574.                 $prix $prix $tauxChange//prix d'achat brut converti en euros
  2575.                 //
  2576.             }
  2577.             $prix round($prix2);
  2578.             $article->setPrixBase($prix);
  2579.         } else {
  2580.             $prix $article->getPrixBase();
  2581.         }
  2582.         if (floatval($article->getCoefficientPrixBaseVente()) == 0) {
  2583.             $article->setCoefficientPrixBaseVente(1);
  2584.             $prixVente $prix;
  2585.         } else {
  2586.             //$prixVente = floatval($article->getCoefficientPrixBaseVente()) * $prix;
  2587.             $prixVente                $article->getPrixVente();
  2588.             $coefficientPrixBaseVente 1;
  2589.             if ($prix != 0) {
  2590.                 $coefficientPrixBaseVente $prixVente $prix;
  2591.             }
  2592.             $article->setCoefficientPrixBaseVente($coefficientPrixBaseVente);
  2593.         }
  2594.         //$article->setPrixVente($prixVente);
  2595.         //$marge = $prixVente - $prix;
  2596.         //recupérer la condition d'achat par défaut
  2597.         /*
  2598.         $repo_condition_achat = $this->em->getRepository(ConditionAchat::class);
  2599.         $conditionAchat = $repo_condition_achat->findOneBy(array('article'=>$article, 'defaut'=>true));
  2600.         if(is_object($conditionAchat)){
  2601.             $prixNetAchat = $conditionAchat->getPrixAchatNet();
  2602.             $marge = $prixVente - $prixNetAchat;
  2603.             $article->setMarge($marge);
  2604.             $tauxMarge = $marge / $prixVente * 100;
  2605.             $article->setTauxMarge($tauxMarge);
  2606.         }
  2607.          *
  2608.          */
  2609.         $margeReelle $prixVente $article->getCpump();
  2610.         $article->setMargeReelle($margeReelle);
  2611.         $this->entityManager->persist($article);
  2612.         if ($article->getMajPrix() == 1) {
  2613.             $message_historique            = [];
  2614.             $message_historique["titre"]   = "Mise Ã  jour du prix suite modification condition d'achat par défaut";
  2615.             $message_historique["message"] = "";
  2616.             $this->creerHistorique($article'defaut'$message_historique);
  2617.         }
  2618.         $this->entityManager->flush();
  2619.     }
  2620.     public function majCondHaEnFonctionPrixBasePourImport(Article $article)
  2621.     {
  2622.         //return "RRRRRR";
  2623.         $repo_fournisseur $this->entityManager->getRepository(Fournisseur::class);
  2624.         $conn             $this->entityManager->getConnection();
  2625.         if ($article->getMajPrix() == 1) {
  2626.             /*
  2627.             $sql = "SELECT * FROM article__condition_achat WHERE article_id = :article_id and statut = :statut LIMIT 0,1";
  2628.             $stmt = $conn->prepare($sql);
  2629.             $stmt->bindValue('article_id',$article->getid());
  2630.             $stmt->bindValue('statut',"1");
  2631.             $stmt->execute();
  2632.             $existe = $stmt->fetchAllAssociative();
  2633.             */
  2634.             $repo_condition_achat $this->entityManager->getRepository(ConditionAchat::class);
  2635.             $conditionAchat       $repo_condition_achat->findOneBy(['article' => $article'defaut' => true]);
  2636.             if (is_object($conditionAchat)) {
  2637.                 $prix       $article->getPrixBase();
  2638.                 $tauxChange 1;
  2639.                 $fournisseur $conditionAchat->getFournisseur();
  2640.                 //$fournisseur = $repo_fournisseur->find($existe["0"]["fournisseur_id"]);
  2641.                 if (is_object($fournisseur)) {
  2642.                     $devise $fournisseur->getDevise();
  2643.                 }
  2644.                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  2645.                     $tauxChange $devise->getTauxChange();
  2646.                 }
  2647.                 $prix $prix $tauxChange//prix de base converti en devise
  2648.                 $conditionAchat->setPrixAchatBrut($prix);
  2649.                 $prixAchatNet $prix * (- ($conditionAchat->getTauxRemise() / 100)) * (- ($conditionAchat->getTauxRemiseSupplementaire() / 100));
  2650.                 $coefficient  $conditionAchat->getCoefficient();
  2651.                 if ($coefficient != 0) {
  2652.                     $prixAchatNet $prixAchatNet $coefficient;
  2653.                 }
  2654.                 $prixAchatNet += $conditionAchat->getFraisAnnexes();
  2655.                 $conditionAchat->setPrixAchatNet($prixAchatNet);
  2656.                 //$this->em->persist($conditionAchat);
  2657.                 //$this->em->flush();
  2658.                 $sql "UPDATE article__condition_achat SET prix_achat_brut='".$prix."' , prix_achat_net='".$prixAchatNet."' WHERE id=".$conditionAchat->getId()." ";
  2659.                 //echo $sql;
  2660.                 $stmt $conn->executeQuery($sql);
  2661.             }
  2662.             //print_r($existe);
  2663.             //exit;
  2664.         }
  2665.         //echo "OUOIUIUIIIO";
  2666.         return true;
  2667.     }
  2668.     public function majCondHaEnFonctionPrixBase(Article $article)
  2669.     {
  2670.         if ($article->getMajPrix() == 1) {
  2671.             $repo_condition_achat $this->entityManager->getRepository(ConditionAchat::class);
  2672.             $conditionAchat       $repo_condition_achat->findOneBy(['article' => $article'defaut' => true]);
  2673.             if (is_object($conditionAchat)) {
  2674.                 $prix $article->getPrixBase();
  2675.                 $cc   floatval($conditionAchat->getCoefficientConditionnement());
  2676.                 if ($cc != 0) {
  2677.                     $prix $prix $cc;
  2678.                 }
  2679.                 $tauxChange  1;
  2680.                 $fournisseur $conditionAchat->getFournisseur();
  2681.                 if (is_object($fournisseur)) {
  2682.                     $devise $fournisseur->getDevise();
  2683.                     if (is_object($devise) && $devise->getTauxChange() != 0) {
  2684.                         $tauxChange $devise->getTauxChange();
  2685.                     }
  2686.                     $prix $prix $tauxChange//prix de base converti en devise
  2687.                 }
  2688.                 $conditionAchat->setPrixAchatBrut($prix);
  2689.                 $prixAchatNet $prix * (- ($conditionAchat->getTauxRemise() / 100)) * (- ($conditionAchat->getTauxRemiseSupplementaire() / 100));
  2690.                 $coefficient  $conditionAchat->getCoefficient();
  2691.                 if ($coefficient != 0) {
  2692.                     $prixAchatNet $prixAchatNet $coefficient;
  2693.                 }
  2694.                 $prixAchatNet += $conditionAchat->getFraisAnnexes();
  2695.                 $conditionAchat->setPrixAchatNet($prixAchatNet);
  2696.                 $this->entityManager->persist($conditionAchat);
  2697.                 $this->entityManager->flush();
  2698.             }
  2699.         }
  2700.     }
  2701.     public function ralClient($articleId)
  2702.     {
  2703.         //$ralClient = $this->em->getRepository(ArticleCommande::class)->getRalClient($articleId);return $ralClient;
  2704.         //return 2;
  2705.         $article      $this->entityManager->getRepository(Article::class)->find($articleId);
  2706.         $ralClient    0;
  2707.         $composants   $this->entityManager->getRepository(ArticleComposant::class)->getComposantsComposeVirtuel($article)->getQuery()->getResult();
  2708.         $reservations $this->entityManager->getRepository(ArticleCommande::class)->getRalClientEtCmdAssociees($article$composants);
  2709.         foreach ($reservations as $reservation) {
  2710.             foreach ($reservation as $res) {
  2711.                 //print_r($res);
  2712.                 if (array_key_exists('ral_quantite'$res)) {
  2713.                     $ralClient += floatval($res['ral_quantite']);
  2714.                     //echo $ralClient.'/ ';
  2715.                 }
  2716.                 /*
  2717.                             if(array_key_exists('quantite', $res))
  2718.                                 $stockReserveNouveau += floatval($res['quantite']);
  2719.                              *
  2720.                              */
  2721.             }
  2722.         }
  2723.         return $ralClient;
  2724.     }
  2725.     public function ralFournisseurPositifNegatif($articleId)
  2726.     {
  2727.         //$ralClient = $this->em->getRepository(ArticleCommande::class)->getRalClient($articleId);return $ralClient;
  2728.         //return 2;
  2729.         $article               $this->entityManager->getRepository(Article::class)->find($articleId);
  2730.         $ralFournisseur        $article->getRalFournisseur();
  2731.         $ralFournisseurPositif 0;
  2732.         $ralFournisseurNegatif 0;
  2733.         $ralFournisseurNegatif $this->getRalFournisseur($articletrue);
  2734.         $ralFournisseurPositif $article->getRalFournisseur() + abs($ralFournisseurNegatif);
  2735.         return ['ralFournisseur' => $ralFournisseur'ralFournisseurPositif' => $ralFournisseurPositif'ralFournisseurNegatif' => $ralFournisseurNegatif];
  2736.     }
  2737.     public function ralClientPositifNegatif($articleId)
  2738.     {
  2739.         //$ralClient = $this->em->getRepository(ArticleCommande::class)->getRalClient($articleId);return $ralClient;
  2740.         //return 2;
  2741.         $article          $this->entityManager->getRepository(Article::class)->find($articleId);
  2742.         $ralClient        0;
  2743.         $ralClientPositif 0;
  2744.         $ralClientNegatif 0;
  2745.         $composants       $this->entityManager->getRepository(ArticleComposant::class)->getComposantsComposeVirtuel($article)->getQuery()->getResult();
  2746.         $reservations     $this->entityManager->getRepository(ArticleCommande::class)->getRalClientEtCmdAssociees($article$composants);
  2747.         //dump($reservations);
  2748.         foreach ($reservations as $reservation) {
  2749.             foreach ($reservation as $res) {
  2750.                 if (array_key_exists('ral_quantite'$res)) {
  2751.                     $ralClient += floatval($res['ral_quantite']);
  2752.                     if ($res['articleId'] != $articleId) {
  2753.                         if (floatval($res['ral_quantite']) > 0) {
  2754.                             $ralClientPositif += floatval($res['ral_quantite']);
  2755.                         }
  2756.                         if (floatval($res['ral_quantite']) < 0) {
  2757.                             $ralClientNegatif += floatval($res['ral_quantite']);
  2758.                         }
  2759.                     }
  2760.                     //if(floatval($res['ral_quantite']) > 0) $ralClientPositif += floatval($res['ral_quantite']);
  2761.                     //if(floatval($res['ral_quantite']) < 0) $ralClientNegatif += floatval($res['ral_quantite']);
  2762.                     //echo $ralClient.'/ ';
  2763.                 }
  2764.                 if ($res['articleId'] == $articleId) {
  2765.                     if (array_key_exists('ral_quantite_positive'$res)) {
  2766.                         $ralClientPositif += floatval($res['ral_quantite_positive']);
  2767.                     }
  2768.                     if (array_key_exists('ral_quantite_negative'$res)) {
  2769.                         $ralClientNegatif += floatval($res['ral_quantite_negative']);
  2770.                     }
  2771.                 }
  2772.             }
  2773.         }
  2774.         return ['ralClient' => $ralClient'ralClientPositif' => $ralClientPositif'ralClientNegatif' => $ralClientNegatif];
  2775.     }
  2776.     public function getMarge($article)
  2777.     {
  2778.         if ( ! is_object($article)) {
  2779.             $repo_article $this->entityManager->getRepository(Article::class);
  2780.             $article      $repo_article->find($article);
  2781.         }
  2782.         $prixVente        $article->getPrixVente();
  2783.         $marge            0;
  2784.         $tauxMarge        0;
  2785.         $prixNetAchatEuro 0;
  2786.         $prixNetAchatEuro $article->getPrixBase();
  2787.         $marge            $prixVente $prixNetAchatEuro;
  2788.         if ($prixVente != '' && $prixVente != 0) {
  2789.             $tauxMarge $marge $prixVente 100;
  2790.         } else {
  2791.             $tauxMarge 0;
  2792.         }
  2793.         $repo_condition_achat $this->entityManager->getRepository(ConditionAchat::class);
  2794.         $conditionAchat       $repo_condition_achat->findOneBy(['article' => $article'defaut' => true]);
  2795.         if (is_object($conditionAchat)) {
  2796.             $prixNetAchat               floatval($conditionAchat->getPrixAchatNet());
  2797.             $coefficientConditionnement floatval($conditionAchat->getCoefficientConditionnement());
  2798.             if ($coefficientConditionnement != && $coefficientConditionnement != 1) {
  2799.                 $prixNetAchat $prixNetAchat $coefficientConditionnement;
  2800.             }
  2801.             $tauxChange  1;
  2802.             $fournisseur $conditionAchat->getFournisseur();
  2803.             if (is_object($fournisseur)) {
  2804.                 $devise $fournisseur->getDevise();
  2805.                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  2806.                     $tauxChange $devise->getTauxChange();
  2807.                 }
  2808.             }
  2809.             $prixNetAchatEuro $prixNetAchat $tauxChange;
  2810.             $marge            $prixVente $prixNetAchatEuro;
  2811.             if ($prixVente != '' && $prixVente != 0) {
  2812.                 $tauxMarge $marge $prixVente 100;
  2813.             } else {
  2814.                 $tauxMarge 0;
  2815.             }
  2816.         }
  2817.         return ['marge' => $marge'tauxMarge' => $tauxMarge'prixNetAchatEuro' => $prixNetAchatEuro];
  2818.     }
  2819.     public function construireRequeteRechercheArticleChaine($param = [], $type "rechercher"$param2 = [])
  2820.     {
  2821.         if ($type == "afficher") {
  2822.             $sql "SELECT id as '0',reference as '1',libelle as '2',prix_vente as '3',stock as '4' FROM article__article as a";
  2823.         } elseif ($type == "rechercher") {
  2824.             $sql "SELECT a.id,libelle,reference FROM article__article as a";
  2825.         } elseif ($type == "modifier") {
  2826.             $sql "SELECT a.id FROM article__article as a";
  2827.         }
  2828.         $where "";
  2829.         $join  "";
  2830.         //print_r($param);
  2831.         if (array_key_exists('dtc_articlesbundle_article'$param)) {
  2832.             $parametre_article $param['dtc_articlesbundle_article'];
  2833.             if (array_key_exists('reference'$parametre_article) && trim($parametre_article['reference']) != "") {
  2834.                 if ($where == "") {
  2835.                     $where .= " WHERE ";
  2836.                 } else {
  2837.                     $where .= " AND ";
  2838.                 }
  2839.                 if (strpos($parametre_article['reference'], "*") !== false) {
  2840.                     $parametre_article['reference'] = str_replace("*""%"$parametre_article['reference']);
  2841.                     $where                          .= "a.reference like '".$parametre_article['reference']."'";
  2842.                 } else {
  2843.                     $where .= "a.reference = '".$parametre_article['reference']."'";
  2844.                 }
  2845.             }
  2846.             for ($i 1$i 12$i++) {
  2847.                 if (array_key_exists('referenceAppel'.$i$parametre_article) && trim($parametre_article['referenceAppel'.$i]) != "") {
  2848.                     if ($where == "") {
  2849.                         $where .= " WHERE ";
  2850.                     } else {
  2851.                         $where .= " AND ";
  2852.                     }
  2853.                     if (strpos($parametre_article['referenceAppel'.$i], "*") !== false) {
  2854.                         $parametre_article['referenceAppel'.$i] = str_replace("*""%"$parametre_article['referenceAppel'.$i]);
  2855.                         $where                                  .= "a.reference_appel_".$i." like '".$parametre_article['referenceAppel'.$i]."'";
  2856.                     } else {
  2857.                         $where .= "a.reference_appel_".$i." = '".$parametre_article['referenceAppel'.$i]."'";
  2858.                     }
  2859.                 }
  2860.             }
  2861.             if (array_key_exists('referenceFournisseur'$parametre_article) && trim($parametre_article['referenceFournisseur']) != "") {
  2862.                 if ($where == "") {
  2863.                     $where .= " WHERE ";
  2864.                 } else {
  2865.                     $where .= " AND ";
  2866.                 }
  2867.                 if (strpos($parametre_article['referenceFournisseur'], "*") !== false) {
  2868.                     $parametre_article['referenceFournisseur'] = str_replace("*""%"$parametre_article['referenceFournisseur']);
  2869.                     $where                                     .= "a.reference_fournisseur like '".$parametre_article['referenceFournisseur']."'";
  2870.                 } else {
  2871.                     $where .= "a.reference_fournisseur = '".$parametre_article['referenceFournisseur']."'";
  2872.                 }
  2873.                 //$where .= "a.reference_fournisseur = '".$parametre_article['referenceFournisseur']."'";
  2874.             }
  2875.             if (array_key_exists('referenceClient'$parametre_article) && trim($parametre_article['referenceClient']) != "") {
  2876.                 if ($where == "") {
  2877.                     $where .= " WHERE ";
  2878.                 } else {
  2879.                     $where .= " AND ";
  2880.                 }
  2881.                 if (strpos($parametre_article['referenceClient'], "*") !== false) {
  2882.                     $parametre_article['referenceClient'] = str_replace("*""%"$parametre_article['referenceClient']);
  2883.                     $where                                .= "a.reference_client like '".$parametre_article['referenceClient']."'";
  2884.                 } else {
  2885.                     $where .= "a.reference_client = '".$parametre_article['referenceClient']."'";
  2886.                 }
  2887.                 //$where .= "a.reference_client = '".$parametre_article['referenceClient']."'";
  2888.             }
  2889.             if (array_key_exists('libelle'$parametre_article) && trim($parametre_article['libelle']) != "") {
  2890.                 if ($where == "") {
  2891.                     $where .= " WHERE ";
  2892.                 } else {
  2893.                     $where .= " AND ";
  2894.                 }
  2895.                 if (strpos($parametre_article['libelle'], "*") !== false) {
  2896.                     $parametre_article['libelle'] = str_replace("*""%"$parametre_article['libelle']);
  2897.                     $where                        .= "a.libelle like '".$parametre_article['libelle']."'";
  2898.                 } else {
  2899.                     $where .= "a.libelle = '".$parametre_article['libelle']."'";
  2900.                 }
  2901.                 //$where .= "a.libelle = '".$parametre_article['libelle']."'";
  2902.             }
  2903.             if (array_key_exists('libelleSecondaire'$parametre_article) && trim($parametre_article['libelleSecondaire']) != "") {
  2904.                 if ($where == "") {
  2905.                     $where .= " WHERE ";
  2906.                 } else {
  2907.                     $where .= " AND ";
  2908.                 }
  2909.                 if (strpos($parametre_article['libelleSecondaire'], "*") !== false) {
  2910.                     $parametre_article['libelleSecondaire'] = str_replace("*""%"$parametre_article['libelleSecondaire']);
  2911.                     $where                                  .= "a.libelle_secondaire like '".$parametre_article['libelleSecondaire']."'";
  2912.                 } else {
  2913.                     $where .= "a.libelle_secondaire = '".$parametre_article['libelleSecondaire']."'";
  2914.                 }
  2915.                 //$where .= "a.libelle_secondaire = '".$parametre_article['libelleSecondaire']."'";
  2916.             }
  2917.             if (array_key_exists('seuilMiniCommandeFournisseur'$parametre_article) && trim($parametre_article['seuilMiniCommandeFournisseur']) != "") {
  2918.                 if ($where == "") {
  2919.                     $where .= " WHERE ";
  2920.                 } else {
  2921.                     $where .= " AND ";
  2922.                 }
  2923.                 $where .= "seuil_commande_f_mini = '".$parametre_article['seuilMiniCommandeFournisseur']."'";
  2924.             }
  2925.             if (array_key_exists('seuilMaxiCommandeFournisseur'$parametre_article) && trim($parametre_article['seuilMaxiCommandeFournisseur']) != "") {
  2926.                 if ($where == "") {
  2927.                     $where .= " WHERE ";
  2928.                 } else {
  2929.                     $where .= " AND ";
  2930.                 }
  2931.                 $where .= "seuil_commande_f_maxi = '".$parametre_article['seuilMaxiCommandeFournisseur']."'";
  2932.             }
  2933.             if (array_key_exists('conditionnement'$parametre_article) && trim($parametre_article['conditionnement']) != "") {
  2934.                 if ($where == "") {
  2935.                     $where .= " WHERE ";
  2936.                 } else {
  2937.                     $where .= " AND ";
  2938.                 }
  2939.                 $where .= "conditionnement = '".$parametre_article['conditionnement']."'";
  2940.             }
  2941.             if (array_key_exists('commentairePonctuel'$parametre_article) && trim($parametre_article['commentairePonctuel']) != "") {
  2942.                 if ($where == "") {
  2943.                     $where .= " WHERE ";
  2944.                 } else {
  2945.                     $where .= " AND ";
  2946.                 }
  2947.                 $where .= "commentaire = '".$parametre_article['commentairePonctuel']."'";
  2948.             }
  2949.             if (array_key_exists('descriptionCourte'$parametre_article) && trim($parametre_article['descriptionCourte']) != "") {
  2950.                 if ($where == "") {
  2951.                     $where .= " WHERE ";
  2952.                 } else {
  2953.                     $where .= " AND ";
  2954.                 }
  2955.                 $where .= "description_courte = '".$parametre_article['descriptionCourte']."'";
  2956.             }
  2957.             if (array_key_exists('description'$parametre_article) && trim($parametre_article['description']) != "") {
  2958.                 if ($where == "") {
  2959.                     $where .= " WHERE ";
  2960.                 } else {
  2961.                     $where .= " AND ";
  2962.                 }
  2963.                 $where .= "description = '".$parametre_article['description']."'";
  2964.             }
  2965.             if (array_key_exists('aConsigner'$parametre_article) && trim($parametre_article['aConsigner']) != "") {
  2966.                 if ($where == "") {
  2967.                     $where .= " WHERE ";
  2968.                 } else {
  2969.                     $where .= " AND ";
  2970.                 }
  2971.                 $where .= "a_consigner = '".$parametre_article['aConsigner']."'";
  2972.             }
  2973.             if (array_key_exists('consigne'$parametre_article) && trim($parametre_article['consigne']) != "") {
  2974.                 if ($where == "") {
  2975.                     $where .= " WHERE ";
  2976.                 } else {
  2977.                     $where .= " AND ";
  2978.                 }
  2979.                 $where .= "consigne = '".$parametre_article['consigne']."'";
  2980.             }
  2981.             if (array_key_exists('produitInterne'$parametre_article) && trim($parametre_article['produitInterne']) != "") {
  2982.                 if ($where == "") {
  2983.                     $where .= " WHERE ";
  2984.                 } else {
  2985.                     $where .= " AND ";
  2986.                 }
  2987.                 $where .= "produit_interne = '".$parametre_article['produitInterne']."'";
  2988.             }
  2989.             if (array_key_exists('virtuel'$parametre_article) && trim($parametre_article['virtuel']) != "") {
  2990.                 if ($where == "") {
  2991.                     $where .= " WHERE ";
  2992.                 } else {
  2993.                     $where .= " AND ";
  2994.                 }
  2995.                 $where .= "virtuel = '".$parametre_article['virtuel']."'";
  2996.             }
  2997.             if (array_key_exists('afficherComposantPdfInterne'$parametre_article) && trim($parametre_article['afficherComposantPdfInterne']) != "") {
  2998.                 if ($where == "") {
  2999.                     $where .= " WHERE ";
  3000.                 } else {
  3001.                     $where .= " AND ";
  3002.                 }
  3003.                 $where .= "afficher_composant_pdf_interne = '".$parametre_article['afficherComposantPdfInterne']."'";
  3004.             }
  3005.             if (array_key_exists('afficherComposantPdfExterne'$parametre_article) && trim($parametre_article['afficherComposantPdfExterne']) != "") {
  3006.                 if ($where == "") {
  3007.                     $where .= " WHERE ";
  3008.                 } else {
  3009.                     $where .= " AND ";
  3010.                 }
  3011.                 $where .= "afficher_composant_pdf_externe = '".$parametre_article['afficherComposantPdfExterne']."'";
  3012.             }
  3013.             if (array_key_exists('nonCommandable'$parametre_article) && trim($parametre_article['nonCommandable']) != "") {
  3014.                 if ($where == "") {
  3015.                     $where .= " WHERE ";
  3016.                 } else {
  3017.                     $where .= " AND ";
  3018.                 }
  3019.                 $where .= "non_commandable = '".$parametre_article['nonCommandable']."'";
  3020.             }
  3021.             if (array_key_exists('stockAuto'$parametre_article) && trim($parametre_article['stockAuto']) != "") {
  3022.                 if ($where == "") {
  3023.                     $where .= " WHERE ";
  3024.                 } else {
  3025.                     $where .= " AND ";
  3026.                 }
  3027.                 $where .= "stock_auto = '".$parametre_article['stockAuto']."'";
  3028.             }
  3029.             if (array_key_exists('nonStocke'$parametre_article) && trim($parametre_article['nonStocke']) != "") {
  3030.                 if ($where == "") {
  3031.                     $where .= " WHERE ";
  3032.                 } else {
  3033.                     $where .= " AND ";
  3034.                 }
  3035.                 $where .= "non_stocke = '".$parametre_article['nonStocke']."'";
  3036.             }
  3037.             if (array_key_exists('majPrix'$parametre_article) && trim($parametre_article['majPrix']) != "") {
  3038.                 if ($where == "") {
  3039.                     $where .= " WHERE ";
  3040.                 } else {
  3041.                     $where .= " AND ";
  3042.                 }
  3043.                 $where .= "maj_prix = '".$parametre_article['majPrix']."'";
  3044.             }
  3045.             if (array_key_exists('arretGamme'$parametre_article) && trim($parametre_article['arretGamme']) != "") {
  3046.                 if ($where == "") {
  3047.                     $where .= " WHERE ";
  3048.                 } else {
  3049.                     $where .= " AND ";
  3050.                 }
  3051.                 $where .= "arret_gamme = '".$parametre_article['arretGamme']."'";
  3052.             }
  3053.             if (array_key_exists('divers'$parametre_article) && trim($parametre_article['divers']) != "") {
  3054.                 if ($where == "") {
  3055.                     $where .= " WHERE ";
  3056.                 } else {
  3057.                     $where .= " AND ";
  3058.                 }
  3059.                 $where .= "divers = '".$parametre_article['divers']."'";
  3060.             }
  3061.             if (array_key_exists('prestation'$parametre_article) && trim($parametre_article['prestation']) != "") {
  3062.                 if ($where == "") {
  3063.                     $where .= " WHERE ";
  3064.                 } else {
  3065.                     $where .= " AND ";
  3066.                 }
  3067.                 $where .= "prestation = '".$parametre_article['prestation']."'";
  3068.             }
  3069.             if (array_key_exists('mainOeuvre'$parametre_article) && trim($parametre_article['mainOeuvre']) != "") {
  3070.                 if ($where == "") {
  3071.                     $where .= " WHERE ";
  3072.                 } else {
  3073.                     $where .= " AND ";
  3074.                 }
  3075.                 $where .= "main_oeuvre = '".$parametre_article['mainOeuvre']."'";
  3076.             }
  3077.             if (array_key_exists('statut'$parametre_article) && trim($parametre_article['statut']) != "") {
  3078.                 if ($where == "") {
  3079.                     $where .= " WHERE ";
  3080.                 } else {
  3081.                     $where .= " AND ";
  3082.                 }
  3083.                 $where .= "statut = '".$parametre_article['statut']."'";
  3084.             }
  3085.             if (array_key_exists('largeur'$parametre_article) && trim($parametre_article['largeur']) != "") {
  3086.                 if ($where == "") {
  3087.                     $where .= " WHERE ";
  3088.                 } else {
  3089.                     $where .= " AND ";
  3090.                 }
  3091.                 $where .= "largeur = '".$parametre_article['largeur']."'";
  3092.             }
  3093.             if (array_key_exists('profondeur'$parametre_article) && trim($parametre_article['profondeur']) != "") {
  3094.                 if ($where == "") {
  3095.                     $where .= " WHERE ";
  3096.                 } else {
  3097.                     $where .= " AND ";
  3098.                 }
  3099.                 $where .= "profondeur = '".$parametre_article['profondeur']."'";
  3100.             }
  3101.             if (array_key_exists('hauteur'$parametre_article) && trim($parametre_article['hauteur']) != "") {
  3102.                 if ($where == "") {
  3103.                     $where .= " WHERE ";
  3104.                 } else {
  3105.                     $where .= " AND ";
  3106.                 }
  3107.                 $where .= "hauteur = '".$parametre_article['hauteur']."'";
  3108.             }
  3109.             if (array_key_exists('poids'$parametre_article) && trim($parametre_article['poids']) != "") {
  3110.                 if ($where == "") {
  3111.                     $where .= " WHERE ";
  3112.                 } else {
  3113.                     $where .= " AND ";
  3114.                 }
  3115.                 $where .= "poids = '".$parametre_article['poids']."'";
  3116.             }
  3117.             if (array_key_exists('nomWeb'$parametre_article) && trim($parametre_article['nomWeb']) != "") {
  3118.                 if ($where == "") {
  3119.                     $where .= " WHERE ";
  3120.                 } else {
  3121.                     $where .= " AND ";
  3122.                 }
  3123.                 if (strpos($parametre_article['nomWeb'], "*") !== false) {
  3124.                     $parametre_article['nomWeb'] = str_replace("*""%"$parametre_article['nomWeb']);
  3125.                     $where                       .= "a.nom_web like '".$parametre_article['nomWeb']."'";
  3126.                 } else {
  3127.                     $where .= "a.nom_web = '".$parametre_article['nomWeb']."'";
  3128.                 }
  3129.                 //$where .= "nom_web = '".$parametre_article['nomWeb']."'";
  3130.             }
  3131.             if (array_key_exists('referenceWeb'$parametre_article) && trim($parametre_article['referenceWeb']) != "") {
  3132.                 if ($where == "") {
  3133.                     $where .= " WHERE ";
  3134.                 } else {
  3135.                     $where .= " AND ";
  3136.                 }
  3137.                 if (strpos($parametre_article['referenceWeb'], "*") !== false) {
  3138.                     $parametre_article['referenceWeb'] = str_replace("*""%"$parametre_article['referenceWeb']);
  3139.                     $where                             .= "a.reference_web like '".$parametre_article['referenceWeb']."'";
  3140.                 } else {
  3141.                     $where .= "a.reference_web = '".$parametre_article['referenceWeb']."'";
  3142.                 }
  3143.                 //$where .= "reference_web = '".$parametre_article['referenceWeb']."'";
  3144.             }
  3145.             if (array_key_exists('referenceFournisseurWeb'$parametre_article) && trim($parametre_article['referenceFournisseurWeb']) != "") {
  3146.                 if ($where == "") {
  3147.                     $where .= " WHERE ";
  3148.                 } else {
  3149.                     $where .= " AND ";
  3150.                 }
  3151.                 if (strpos($parametre_article['referenceFournisseurWeb'], "*") !== false) {
  3152.                     $parametre_article['referenceFournisseurWeb'] = str_replace("*""%"$parametre_article['referenceFournisseurWeb']);
  3153.                     $where                                        .= "a.reference_fournisseur_web like '".$parametre_article['referenceFournisseurWeb']."'";
  3154.                 } else {
  3155.                     $where .= "a.reference_fournisseur_web = '".$parametre_article['referenceFournisseurWeb']."'";
  3156.                 }
  3157.                 //$where .= "reference_fournisseur_web = '".$parametre_article['referenceFournisseurWeb']."'";
  3158.             }
  3159.             if (array_key_exists('descriptionWeb'$parametre_article) && trim($parametre_article['descriptionWeb']) != "") {
  3160.                 if ($where == "") {
  3161.                     $where .= " WHERE ";
  3162.                 } else {
  3163.                     $where .= " AND ";
  3164.                 }
  3165.                 $where .= "description_web = '".$parametre_article['descriptionWeb']."'";
  3166.             }
  3167.             if (array_key_exists('resumeWeb'$parametre_article) && trim($parametre_article['resumeWeb']) != "") {
  3168.                 if ($where == "") {
  3169.                     $where .= " WHERE ";
  3170.                 } else {
  3171.                     $where .= " AND ";
  3172.                 }
  3173.                 $where .= "resume_web = '".$parametre_article['resumeWeb']."'";
  3174.             }
  3175.             if (array_key_exists('ecotaxe'$parametre_article) && trim($parametre_article['ecotaxe']) != "") {
  3176.                 if ($where == "") {
  3177.                     $where .= " WHERE ";
  3178.                 } else {
  3179.                     $where .= " AND ";
  3180.                 }
  3181.                 $where .= "ecotaxe = '".$parametre_article['ecotaxe']."'";
  3182.             }
  3183.             if (array_key_exists('remiseMax'$parametre_article) && trim($parametre_article['remiseMax']) != "") {
  3184.                 if ($where == "") {
  3185.                     $where .= " WHERE ";
  3186.                 } else {
  3187.                     $where .= " AND ";
  3188.                 }
  3189.                 $where .= "remise_max = '".$parametre_article['remiseMax']."'";
  3190.             }
  3191.             if (array_key_exists('marque'$parametre_article) && trim($parametre_article['marque']) != "" && trim($parametre_article['marque']) != "0") {
  3192.                 if ($where == "") {
  3193.                     $where .= " WHERE ";
  3194.                 } else {
  3195.                     $where .= " AND ";
  3196.                 }
  3197.                 $where .= "marque_id = '".$parametre_article['marque']."'";
  3198.             }
  3199.             if (array_key_exists('uniteMesure'$parametre_article) && trim($parametre_article['uniteMesure']) != "" && trim($parametre_article['uniteMesure']) != "0") {
  3200.                 if ($where == "") {
  3201.                     $where .= " WHERE ";
  3202.                 } else {
  3203.                     $where .= " AND ";
  3204.                 }
  3205.                 $where .= "unite_mesure_id = '".$parametre_article['uniteMesure']."'";
  3206.             }
  3207.             if (array_key_exists('categorieRemiseArticle'$parametre_article) && trim($parametre_article['categorieRemiseArticle']) != "" && trim(
  3208.                                                                                                                                                   $parametre_article['categorieRemiseArticle']
  3209.                                                                                                                                               ) != "0") {
  3210.                 if ($where == "") {
  3211.                     $where .= " WHERE ";
  3212.                 } else {
  3213.                     $where .= " AND ";
  3214.                 }
  3215.                 $where .= "categorie_remise_article_id = '".$parametre_article['categorieRemiseArticle']."'";
  3216.             }
  3217.             if (array_key_exists('type'$parametre_article) && trim($parametre_article['type']) != "" && trim($parametre_article['type']) != "0") {
  3218.                 if ($where == "") {
  3219.                     $where .= " WHERE ";
  3220.                 } else {
  3221.                     $where .= " AND ";
  3222.                 }
  3223.                 $where .= "type_id = '".$parametre_article['type']."'";
  3224.             }
  3225.             if (array_key_exists('regleTaxe'$parametre_article) && trim($parametre_article['regleTaxe']) != "" && trim($parametre_article['regleTaxe']) != "0") {
  3226.                 if ($where == "") {
  3227.                     $where .= " WHERE ";
  3228.                 } else {
  3229.                     $where .= " AND ";
  3230.                 }
  3231.                 $where .= "regle_taxe_id = '".$parametre_article['regleTaxe']."'";
  3232.             }
  3233.             /*
  3234.             if (array_key_exists('typeRemiseMax', $parametre_article) && trim($parametre_article['typeRemiseMax']) != "" && trim($parametre_article['typeRemiseMax']) != "0") {
  3235.                 if($where == "") $where .= " WHERE ";
  3236.                 else $where .= " AND ";
  3237.                 $where .= "type_remise_max = '".$parametre_article['typeRemiseMax']."'";
  3238.             }
  3239.             */
  3240.             if (array_key_exists('familleCompta'$parametre_article) && trim($parametre_article['familleCompta']) != "" && trim($parametre_article['familleCompta']) != "0") {
  3241.                 if ($where == "") {
  3242.                     $where .= " WHERE ";
  3243.                 } else {
  3244.                     $where .= " AND ";
  3245.                 }
  3246.                 $where .= "famille_compta_id = '".$parametre_article['familleCompta']."'";
  3247.             }
  3248.             if (array_key_exists('conditionsAchat'$param['dtc_articlesbundle_article'])) {
  3249.                 $parametre_cond_achat $param['dtc_articlesbundle_article']['conditionsAchat'];
  3250.                 //print_r($parametre_cond_achat);
  3251.                 //echo "<div>OK</div>";
  3252.                 $sql_cond_achat   "a.id IN (SELECT article_id FROM article__condition_achat ";
  3253.                 $where_cond_achat "";
  3254.                 if (array_key_exists('referenceFournisseur'$parametre_cond_achat) && trim($parametre_cond_achat['referenceFournisseur']) != "") {
  3255.                     if ($where_cond_achat == "") {
  3256.                         $where_cond_achat .= " WHERE ";
  3257.                     } else {
  3258.                         $where_cond_achat .= " AND ";
  3259.                     }
  3260.                     $where_cond_achat .= "reference_fournisseur = '".$parametre_cond_achat['referenceFournisseur']."'";
  3261.                 }
  3262.                 if (array_key_exists('libelle'$parametre_cond_achat) && trim($parametre_cond_achat['libelle']) != "") {
  3263.                     if ($where_cond_achat == "") {
  3264.                         $where_cond_achat .= " WHERE ";
  3265.                     } else {
  3266.                         $where_cond_achat .= " AND ";
  3267.                     }
  3268.                     $where_cond_achat .= "libelle = '".$parametre_cond_achat['libelle']."'";
  3269.                 }
  3270.                 if (array_key_exists('quantite'$parametre_cond_achat) && trim($parametre_cond_achat['quantite']) != "") {
  3271.                     if ($where_cond_achat == "") {
  3272.                         $where_cond_achat .= " WHERE ";
  3273.                     } else {
  3274.                         $where_cond_achat .= " AND ";
  3275.                     }
  3276.                     $where_cond_achat .= "quantite = '".$parametre_cond_achat['quantite']."'";
  3277.                 }
  3278.                 if (array_key_exists('conditionnement'$parametre_cond_achat) && trim($parametre_cond_achat['conditionnement']) != "") {
  3279.                     if ($where_cond_achat == "") {
  3280.                         $where_cond_achat .= " WHERE ";
  3281.                     } else {
  3282.                         $where_cond_achat .= " AND ";
  3283.                     }
  3284.                     $where_cond_achat .= "conditionnement = '".$parametre_cond_achat['conditionnement']."'";
  3285.                 }
  3286.                 if (array_key_exists('prixAchatBrut'$parametre_cond_achat) && trim($parametre_cond_achat['prixAchatBrut']) != "") {
  3287.                     $parametre_cond_achat['prixAchatBrut'] = str_replace(",""."$parametre_cond_achat['prixAchatBrut']);
  3288.                     if ($where_cond_achat == "") {
  3289.                         $where_cond_achat .= " WHERE ";
  3290.                     } else {
  3291.                         $where_cond_achat .= " AND ";
  3292.                     }
  3293.                     $where_cond_achat .= "prix_achat_brut = '".$parametre_cond_achat['prixAchatBrut']."'";
  3294.                 }
  3295.                 if (array_key_exists('tauxRemise'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemise']) != "") {
  3296.                     if ($where_cond_achat == "") {
  3297.                         $where_cond_achat .= " WHERE ";
  3298.                     } else {
  3299.                         $where_cond_achat .= " AND ";
  3300.                     }
  3301.                     $where_cond_achat .= "taux_remise = '".$parametre_cond_achat['tauxRemise']."'";
  3302.                 }
  3303.                 if (array_key_exists('tauxRemiseSupplementaire'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemiseSupplementaire']) != "") {
  3304.                     if ($where_cond_achat == "") {
  3305.                         $where_cond_achat .= " WHERE ";
  3306.                     } else {
  3307.                         $where_cond_achat .= " AND ";
  3308.                     }
  3309.                     $where_cond_achat .= "taux_remise_supplementaire = '".$parametre_cond_achat['tauxRemiseSupplementaire']."'";
  3310.                 }
  3311.                 if (array_key_exists('prixAchatNet'$parametre_cond_achat) && trim($parametre_cond_achat['prixAchatNet']) != "") {
  3312.                     $parametre_cond_achat['prixAchatNet'] = str_replace(",""."$parametre_cond_achat['prixAchatNet']);
  3313.                     if ($where_cond_achat == "") {
  3314.                         $where_cond_achat .= " WHERE ";
  3315.                     } else {
  3316.                         $where_cond_achat .= " AND ";
  3317.                     }
  3318.                     $where_cond_achat .= "prix_achat_net = '".$parametre_cond_achat['prixAchatNet']."'";
  3319.                 }
  3320.                 if (array_key_exists('fournisseur'$parametre_cond_achat) && trim($parametre_cond_achat['fournisseur']) != "") {
  3321.                     if ($where_cond_achat == "") {
  3322.                         $where_cond_achat .= " WHERE ";
  3323.                     } else {
  3324.                         $where_cond_achat .= " AND ";
  3325.                     }
  3326.                     $where_cond_achat .= "fournisseur_id = '".$parametre_cond_achat['fournisseur']."'";
  3327.                 }
  3328.                 $sql_cond_achat .= $where_cond_achat;
  3329.                 if ($sql_cond_achat != "a.id IN (SELECT article_id FROM article__condition_achat ") {
  3330.                     $sql_cond_achat .= " AND statut = '1')";
  3331.                     if ($where == "") {
  3332.                         $where .= " WHERE ";
  3333.                     } else {
  3334.                         $where .= " AND ";
  3335.                     }
  3336.                     $where .= $sql_cond_achat;
  3337.                 }
  3338.             }
  3339.         }
  3340.         if (array_key_exists('categories'$param) && count($param['categories']) > 0) {
  3341.             $parametre_categorie $param['categories'];
  3342.             //$join .= " LEFT JOIN article__article_categorie cat on cat.article_id = a.id";
  3343.             for ($i 0$i count($parametre_categorie); $i++) {
  3344.                 if ($where == "") {
  3345.                     $where .= " WHERE ";
  3346.                 } else {
  3347.                     $where .= " AND ";
  3348.                 }
  3349.                 $where .= "a.id IN (SELECT article_id FROM article__article_categorie WHERE categorie_id IN (";
  3350.                 $where .= $parametre_categorie[$i].",";
  3351.                 $where .= ",";
  3352.                 $where str_replace(",,"""$where);
  3353.                 $where .= "))";
  3354.             }
  3355.         }
  3356.         if ($param2 != null) {
  3357.             if (array_key_exists('articleEnleve'$param2) && trim($param2['articleEnleve']) != "") {
  3358.                 if ($where == "") {
  3359.                     $where .= " WHERE ";
  3360.                 } else {
  3361.                     $where .= " AND ";
  3362.                 }
  3363.                 $article explode("|"$param2['articleEnleve']);
  3364.                 $i       0;
  3365.                 foreach ($article as $articleEnleve) {
  3366.                     if ($i == 0) {
  3367.                         $where .= " id != '".$articleEnleve." ' ";
  3368.                     } elseif ($i == sizeof($article) - 1) {
  3369.                     } else {
  3370.                         $where .= " AND id != '".$articleEnleve." ' ";
  3371.                     }
  3372.                     $i++;
  3373.                 }
  3374.             }
  3375.         }
  3376.         if ($type == "modifier") {
  3377.             $sql $where;
  3378.         } else {
  3379.             $sql $sql.$join.$where;
  3380.         }
  3381.         //echo "<div><br/>".$sql."</div>";
  3382.         //exit;
  3383.         return $sql;
  3384.     }
  3385.     public function rechercheArticleChaine($param = [], $type "rechercher"$param2 = [])
  3386.     {
  3387.         $results      = [];
  3388.         $countResults 0;
  3389.         $conn         $this->entityManager->getConnection();
  3390.         $sql_recherche $this->construireRequeteRechercheArticleChaine($param$type$param2);
  3391.         $stmt          $conn->prepare(trim($sql_recherche));
  3392.         //echo "<div>".$sql_recherche."</div>";
  3393.         $query        $stmt->executeQuery();
  3394.         $results      $query->fetchAllAssociative();
  3395.         $countResults $query->rowCount();
  3396.         $tabRetour    = ["resultats" => $results"nbResultats" => $countResults];
  3397.         return $tabRetour;
  3398.     }
  3399.     public function modifierArticleChaine($param_recherche = [], $param_valeur = [])
  3400.     {
  3401.         //print_r($param_valeur);
  3402.         $sql_update      "UPDATE `article__article` as a SET";
  3403.         $conn            $this->entityManager->getConnection();
  3404.         $sql_recherche   $this->construireRequeteRechercheArticleChaine($param_recherche"modifier"$param_valeur);
  3405.         $liste_resultats "";
  3406.         if (array_key_exists('dtc_articlesbundle_article'$param_valeur)) {
  3407.             $parametre_article $param_valeur['dtc_articlesbundle_article'];
  3408.             /*
  3409.             if (array_key_exists('libelle', $parametre_article) && trim($parametre_article['libelle']) != "") {
  3410.                $sql_update.= " x.libelle = '".trim($parametre_article['libelle'])."'";
  3411.             }
  3412.             */
  3413.             if (array_key_exists('libelle'$parametre_article) && trim($parametre_article['libelle']) != "") {
  3414.                 $sql_update .= " a.libelle = '".trim($parametre_article['libelle'])."',";
  3415.             }
  3416.             if (array_key_exists('referenceFournisseur'$parametre_article) && trim($parametre_article['referenceFournisseur']) != "") {
  3417.                 $sql_update .= " a.reference_fournisseur = '".$parametre_article['referenceFournisseur']."',";
  3418.             }
  3419.             if (array_key_exists('referenceClient'$parametre_article) && trim($parametre_article['referenceClient']) != "") {
  3420.                 $sql_update .= " a.reference_client = '".$parametre_article['referenceClient']."',";
  3421.             }
  3422.             if (array_key_exists('libelleSecondaire'$parametre_article) && trim($parametre_article['libelleSecondaire']) != "") {
  3423.                 $sql_update .= " a.libelle_secondaire = '".$parametre_article['libelleSecondaire']."',";
  3424.             }
  3425.             if (array_key_exists('seuilMiniCommandeFournisseur'$parametre_article) && trim($parametre_article['seuilMiniCommandeFournisseur']) != "") {
  3426.                 $sql_update .= " seuil_commande_f_mini = '".$parametre_article['seuilMiniCommandeFournisseur']."',";
  3427.             }
  3428.             if (array_key_exists('seuilMaxiCommandeFournisseur'$parametre_article) && trim($parametre_article['seuilMaxiCommandeFournisseur']) != "") {
  3429.                 $sql_update .= " seuil_commande_f_maxi = '".$parametre_article['seuilMaxiCommandeFournisseur']."',";
  3430.             }
  3431.             if (array_key_exists('conditionnement'$parametre_article) && trim($parametre_article['conditionnement']) != "") {
  3432.                 $sql_update .= " conditionnement = '".$parametre_article['conditionnement']."',";
  3433.             }
  3434.             if (array_key_exists('commentairePonctuel'$parametre_article) && trim($parametre_article['commentairePonctuel']) != "") {
  3435.                 $sql_update .= " commentaire = '".$parametre_article['commentairePonctuel']."',";
  3436.             }
  3437.             if (array_key_exists('descriptionCourte'$parametre_article) && trim($parametre_article['descriptionCourte']) != "") {
  3438.                 $sql_update .= " description_courte = '".$parametre_article['descriptionCourte']."',";
  3439.             }
  3440.             if (array_key_exists('description'$parametre_article) && trim($parametre_article['description']) != "") {
  3441.                 $sql_update .= " description = '".$parametre_article['description']."',";
  3442.             }
  3443.             if (array_key_exists('aConsigner'$parametre_article) && trim($parametre_article['aConsigner']) != "") {
  3444.                 $sql_update .= " a_consigner = '".$parametre_article['aConsigner']."',";
  3445.             }
  3446.             if (array_key_exists('consigne'$parametre_article) && trim($parametre_article['consigne']) != "") {
  3447.                 $sql_update .= " consigne = '".$parametre_article['consigne']."',";
  3448.             }
  3449.             if (array_key_exists('produitInterne'$parametre_article) && trim($parametre_article['produitInterne']) != "") {
  3450.                 $sql_update .= " produit_interne = '".$parametre_article['produitInterne']."',";
  3451.             }
  3452.             if (array_key_exists('virtuel'$parametre_article) && trim($parametre_article['virtuel']) != "") {
  3453.                 $sql_update .= " virtuel = '".$parametre_article['virtuel']."',";
  3454.             }
  3455.             if (array_key_exists('afficherComposantPdfInterne'$parametre_article) && trim($parametre_article['afficherComposantPdfInterne']) != "") {
  3456.                 $sql_update .= " afficher_composant_pdf_interne = '".$parametre_article['afficherComposantPdfInterne']."',";
  3457.             }
  3458.             if (array_key_exists('afficherComposantPdfExterne'$parametre_article) && trim($parametre_article['afficherComposantPdfExterne']) != "") {
  3459.                 $sql_update .= " afficher_composant_pdf_externe = '".$parametre_article['afficherComposantPdfExterne']."',";
  3460.             }
  3461.             if (array_key_exists('nonCommandable'$parametre_article) && trim($parametre_article['nonCommandable']) != "") {
  3462.                 $sql_update .= " non_commandable = '".$parametre_article['nonCommandable']."',";
  3463.             }
  3464.             if (array_key_exists('stockAuto'$parametre_article) && trim($parametre_article['stockAuto']) != "") {
  3465.                 $sql_update .= " stock_auto = '".$parametre_article['stockAuto']."',";
  3466.             }
  3467.             if (array_key_exists('nonStocke'$parametre_article) && trim($parametre_article['nonStocke']) != "") {
  3468.                 $sql_update .= " non_stocke = '".$parametre_article['nonStocke']."',";
  3469.             }
  3470.             if (array_key_exists('majPrix'$parametre_article) && trim($parametre_article['majPrix']) != "") {
  3471.                 $sql_update .= " maj_prix = '".$parametre_article['majPrix']."',";
  3472.             }
  3473.             if (array_key_exists('arretGamme'$parametre_article) && trim($parametre_article['arretGamme']) != "") {
  3474.                 $sql_update .= " arret_gamme = '".$parametre_article['arretGamme']."',";
  3475.             }
  3476.             if (array_key_exists('divers'$parametre_article) && trim($parametre_article['divers']) != "") {
  3477.                 $sql_update .= " divers = '".$parametre_article['divers']."',";
  3478.             }
  3479.             if (array_key_exists('prestation'$parametre_article) && trim($parametre_article['prestation']) != "") {
  3480.                 $sql_update .= " prestation = '".$parametre_article['prestation']."',";
  3481.             }
  3482.             if (array_key_exists('mainOeuvre'$parametre_article) && trim($parametre_article['mainOeuvre']) != "") {
  3483.                 $sql_update .= " main_oeuvre = '".$parametre_article['mainOeuvre']."',";
  3484.             }
  3485.             if (array_key_exists('statut'$parametre_article) && trim($parametre_article['statut']) != "") {
  3486.                 $sql_update .= " statut = '".$parametre_article['statut']."',";
  3487.             }
  3488.             if (array_key_exists('largeur'$parametre_article) && trim($parametre_article['largeur']) != "") {
  3489.                 $sql_update .= " largeur = '".$parametre_article['largeur']."',";
  3490.             }
  3491.             if (array_key_exists('profondeur'$parametre_article) && trim($parametre_article['profondeur']) != "") {
  3492.                 $sql_update .= " profondeur = '".$parametre_article['profondeur']."',";
  3493.             }
  3494.             if (array_key_exists('hauteur'$parametre_article) && trim($parametre_article['hauteur']) != "") {
  3495.                 $sql_update .= " hauteur = '".$parametre_article['hauteur']."',";
  3496.             }
  3497.             if (array_key_exists('poids'$parametre_article) && trim($parametre_article['poids']) != "") {
  3498.                 $sql_update .= " poids = '".$parametre_article['poids']."',";
  3499.             }
  3500.             if (array_key_exists('nomWeb'$parametre_article) && trim($parametre_article['nomWeb']) != "") {
  3501.                 $sql_update .= " nom_web = '".$parametre_article['nomWeb']."',";
  3502.             }
  3503.             if (array_key_exists('referenceWeb'$parametre_article) && trim($parametre_article['referenceWeb']) != "") {
  3504.                 $sql_update .= " reference_web = '".$parametre_article['referenceWeb']."',";
  3505.             }
  3506.             if (array_key_exists('referenceFournisseurWeb'$parametre_article) && trim($parametre_article['referenceFournisseurWeb']) != "") {
  3507.                 $sql_update .= " reference_fournisseur_web = '".$parametre_article['referenceFournisseurWeb']."',";
  3508.             }
  3509.             if (array_key_exists('descriptionWeb'$parametre_article) && trim($parametre_article['descriptionWeb']) != "") {
  3510.                 $sql_update .= " description_web = '".$parametre_article['descriptionWeb']."',";
  3511.             }
  3512.             if (array_key_exists('resumeWeb'$parametre_article) && trim($parametre_article['resumeWeb']) != "") {
  3513.                 $sql_update .= " resume_web = '".$parametre_article['resumeWeb']."',";
  3514.             }
  3515.             if (array_key_exists('marque'$parametre_article) && trim($parametre_article['marque']) != "" && trim($parametre_article['marque']) != "0") {
  3516.                 $sql_update .= " marque_id = '".$parametre_article['marque']."',";
  3517.             }
  3518.             if (array_key_exists('categorieRemiseArticle'$parametre_article) && trim($parametre_article['categorieRemiseArticle']) != "" && trim(
  3519.                                                                                                                                                   $parametre_article['categorieRemiseArticle']
  3520.                                                                                                                                               ) != "0") {
  3521.                 $sql_update .= " categorie_remise_article_id = '".$parametre_article['categorieRemiseArticle']."',";
  3522.             }
  3523.             if (array_key_exists('type'$parametre_article) && trim($parametre_article['type']) != "" && trim($parametre_article['type']) != "0") {
  3524.                 $sql_update .= " type_id = '".$parametre_article['type']."',";
  3525.             }
  3526.             if (array_key_exists('regleTaxe'$parametre_article) && trim($parametre_article['regleTaxe']) != "" && trim($parametre_article['regleTaxe']) != "0") {
  3527.                 $sql_update .= " regle_taxe_id = '".$parametre_article['regleTaxe']."',";
  3528.             }
  3529.             if (array_key_exists('familleCompta'$parametre_article) && trim($parametre_article['familleCompta']) != "" && trim($parametre_article['familleCompta']) != "0") {
  3530.                 $sql_update .= " famille_compta_id = '".$parametre_article['familleCompta']."',";
  3531.             }
  3532.             $sql_update .= ",";
  3533.             $sql_update str_replace(",,"""$sql_update);
  3534.         }
  3535.         if ($sql_update == "UPDATE `article__article` as a SET,") {
  3536.             //echo "<div>PAS UPDATE</div>";
  3537.         } else {
  3538.             $sql_update .= $sql_recherche;
  3539.             //echo "<div>SQL UPDATE : ".$sql_update."</div>";
  3540.             $stmt $conn->prepare(trim($sql_update));
  3541.             $nbLignes $stmt->executeQuery()->rowCount();
  3542.             //exit;
  3543.         }
  3544.         if (
  3545.             (array_key_exists('prixBase'$parametre_article) && trim($parametre_article['prixBase']) != "")
  3546.             or
  3547.             (array_key_exists('prixVente'$parametre_article) && trim($parametre_article['prixVente']) != "")
  3548.             or
  3549.             (array_key_exists('coefficientPrixBaseVente'$parametre_article) && trim($parametre_article['coefficientPrixBaseVente']) != "")
  3550.             or
  3551.             (array_key_exists('tauxMarge'$parametre_article) && trim($parametre_article['tauxMarge']) != "")
  3552.         ) {
  3553.             $liste_resultats $this->rechercheArticleChaine($param_recherche"rechercher"$param_valeur);
  3554.             $articles        $liste_resultats["resultats"];
  3555.             $nbLignes        count($articles);
  3556.             $repoArticle     $this->entityManager->getRepository(Article::class);
  3557.             for ($i 0$i count($articles); $i++) {
  3558.                 $article $repoArticle->find($articles[$i]["id"]);
  3559.                 if (is_object($article)) {
  3560.                     //print_r($parametre_article);
  3561.                     //echo "TOTO";
  3562.                     $prixBase                 "";
  3563.                     $prixVente                "";
  3564.                     $coefficientPrixBaseVente "";
  3565.                     $tauxMarge                "";
  3566.                     if (array_key_exists('prixBase'$parametre_article) && trim($parametre_article['prixBase']) != "" && trim($parametre_article['prixBase']) != 0) {
  3567.                         $prixBase trim($parametre_article['prixBase']);
  3568.                     } else {
  3569.                         $prixBase $article->getPrixBase();
  3570.                     }
  3571.                     if (array_key_exists('prixVente'$parametre_article) && trim($parametre_article['prixVente']) != "" && trim($parametre_article['prixVente']) != 0) {
  3572.                         $prixVente trim($parametre_article['prixVente']);
  3573.                     } else {
  3574.                         $prixVente $article->getPrixVente();
  3575.                     }
  3576.                     if (array_key_exists('coefficientPrixBaseVente'$parametre_article) && trim($parametre_article['coefficientPrixBaseVente']) != "" && trim(
  3577.                                                                                                                                                               $parametre_article['coefficientPrixBaseVente']
  3578.                                                                                                                                                           ) != 0) {
  3579.                         $coefficientPrixBaseVente trim($parametre_article['coefficientPrixBaseVente']);
  3580.                     } else {
  3581.                         $coefficientPrixBaseVente $article->getCoefficientPrixBaseVente();
  3582.                     }
  3583.                     if (array_key_exists('tauxMarge'$parametre_article) && trim($parametre_article['tauxMarge']) != "") {
  3584.                         $tauxMarge trim($parametre_article['tauxMarge']);
  3585.                     } else {
  3586.                         $tauxMarge $article->getTauxMarge();
  3587.                     }
  3588.                     if (array_key_exists('prixBase'$parametre_article) && trim($parametre_article['prixBase']) != ""
  3589.                         && array_key_exists('coefficientPrixBaseVente'$parametre_article) && trim($parametre_article['coefficientPrixBaseVente']) != ""
  3590.                         && array_key_exists('prixVente'$parametre_article) && trim($parametre_article['prixVente']) != ""
  3591.                     ) {
  3592.                         $prixVente $prixBase $coefficientPrixBaseVente;
  3593.                         //$article->setCommentairePonctuel('cas 1');
  3594.                     } elseif (array_key_exists('prixBase'$parametre_article) && trim($parametre_article['prixBase']) != "" && trim($parametre_article['prixBase']) != 0
  3595.                               && array_key_exists('coefficientPrixBaseVente'$parametre_article) && trim($parametre_article['coefficientPrixBaseVente']) != ""
  3596.                     ) {
  3597.                         $prixVente $prixBase $coefficientPrixBaseVente;
  3598.                         //$article->setCommentairePonctuel('cas 2');
  3599.                     } elseif (array_key_exists('prixBase'$parametre_article) && trim($parametre_article['prixBase']) != "" && trim($parametre_article['prixBase']) != 0
  3600.                               && array_key_exists('prixVente'$parametre_article) && trim($parametre_article['prixVente']) != "" && trim($parametre_article['prixVente']) != 0
  3601.                     ) {
  3602.                         $coefficientPrixBaseVente $prixVente $prixBase;
  3603.                         //$article->setCommentairePonctuel('cas 3');
  3604.                     } elseif (array_key_exists('prixBase'$parametre_article) && trim($parametre_article['prixBase']) != "" && trim($parametre_article['prixBase']) != 0
  3605.                     ) {
  3606.                         if ($article->getMajPrix()) {
  3607.                             $prixVente $prixBase $coefficientPrixBaseVente;
  3608.                             //$article->setCommentairePonctuel('cas 4');
  3609.                         } else {
  3610.                             $coefficientPrixBaseVente $prixVente $prixBase;
  3611.                             //$article->setCommentairePonctuel('cas 5');
  3612.                         }
  3613.                     } elseif (array_key_exists('coefficientPrixBaseVente'$parametre_article) && trim($parametre_article['coefficientPrixBaseVente']) != ""
  3614.                               && array_key_exists('prixVente'$parametre_article) && trim($parametre_article['prixVente']) != ""
  3615.                     ) {
  3616.                         $prixBase $prixVente $coefficientPrixBaseVente;
  3617.                         //$article->setCommentairePonctuel('cas 6');
  3618.                     } elseif (array_key_exists('prixVente'$parametre_article) && trim($parametre_article['prixVente']) != ""
  3619.                     ) {
  3620.                         $coefficientPrixBaseVente $prixVente $prixBase;
  3621.                         //$article->setCommentairePonctuel('cas 7');
  3622.                     } elseif (array_key_exists('coefficientPrixBaseVente'$parametre_article) && trim($parametre_article['coefficientPrixBaseVente']) != ""
  3623.                     ) {
  3624.                         $prixVente $prixBase $coefficientPrixBaseVente;
  3625.                         //$article->setCommentairePonctuel('cas 8');
  3626.                     } else {
  3627.                         //$article->setCommentairePonctuel('cas 9');
  3628.                     }
  3629.                     $margeReelle round($prixVente $article->getCpump(), 2);
  3630.                     $article->setPrixBase(round($prixBase2));
  3631.                     $article->setPrixVente($prixVente);
  3632.                     $article->setCoefficientPrixBaseVente(round($coefficientPrixBaseVente2));
  3633.                     //$article->setTauxMarge(round($tauxMarge,2));
  3634.                     //$article->setMarge(round($marge,2));
  3635.                     $article->setMargeReelle(round($margeReelle2));
  3636.                     $this->entityManager->persist($article);
  3637.                     //$this->em->refresh($article);
  3638.                     if ($article->getMajPrix()) {
  3639.                         //Mettre a jour la condition d'achat
  3640.                         $this->majCondHaEnFonctionPrixBase($article);
  3641.                     }
  3642.                 }
  3643.             }
  3644.             $this->entityManager->flush();
  3645.         }
  3646.         if (array_key_exists('conditionsAchat'$parametre_article)) {
  3647.             $parametre_cond_achat $parametre_article['conditionsAchat'];
  3648.             //print_r($parametre_cond_achat);
  3649.             //echo "<div>OK cond achat</div>";
  3650.             $maj_cond_achat      false;
  3651.             $maj_cond_achat_prix false;
  3652.             if (
  3653.                 (array_key_exists('referenceFournisseur'$parametre_cond_achat) && trim($parametre_cond_achat['referenceFournisseur']) != "")
  3654.                 or
  3655.                 (array_key_exists('libelle'$parametre_cond_achat) && trim($parametre_cond_achat['libelle']) != "")
  3656.                 or
  3657.                 (array_key_exists('quantite'$parametre_cond_achat) && trim($parametre_cond_achat['quantite']) != "")
  3658.                 or
  3659.                 (array_key_exists('conditionnement'$parametre_cond_achat) && trim($parametre_cond_achat['conditionnement']) != "")
  3660.                 or
  3661.                 (array_key_exists('prixAchatBrut'$parametre_cond_achat) && trim($parametre_cond_achat['prixAchatBrut']) != "")
  3662.                 or
  3663.                 (array_key_exists('tauxRemise'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemise']) != "")
  3664.                 or
  3665.                 (array_key_exists('tauxRemiseSupplementaire'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemiseSupplementaire']) != "")
  3666.                 or
  3667.                 (array_key_exists('prixAchatNet'$parametre_cond_achat) && trim($parametre_cond_achat['prixAchatNet']) != "")
  3668.                 or
  3669.                 (array_key_exists('fournisseur'$parametre_cond_achat) && trim($parametre_cond_achat['fournisseur']) != "")
  3670.                 or
  3671.                 (array_key_exists('fraisAnnexes'$parametre_cond_achat) && trim($parametre_cond_achat['fraisAnnexes']) != "")
  3672.                 or
  3673.                 (array_key_exists('coefficient'$parametre_cond_achat) && trim($parametre_cond_achat['coefficient']) != "")
  3674.             ) {
  3675.                 $maj_cond_achat true;
  3676.             }
  3677.             if ($maj_cond_achat) {
  3678.                 $repoArticle   $this->entityManager->getRepository(Article::class);
  3679.                 $repoCondAchat $this->entityManager->getRepository(ConditionAchat::class);
  3680.                 if ( ! is_array($liste_resultats)) {
  3681.                     $liste_resultats $this->rechercheArticleChaine($param_recherche"rechercher");
  3682.                 }
  3683.                 $articles $liste_resultats["resultats"];
  3684.                 $nbLignes count($articles);
  3685.                 for ($i 0$i count($articles); $i++) {
  3686.                     $sql_cond_achat "UPDATE article__condition_achat SET ";
  3687.                     //echo "<div>ART : ".$articles[$i]["id"]."</div>";
  3688.                     if (array_key_exists('referenceFournisseur'$parametre_cond_achat) && trim($parametre_cond_achat['referenceFournisseur']) != "") {
  3689.                         $sql_cond_achat .= " reference_fournisseur = '".$parametre_cond_achat['referenceFournisseur']."',";
  3690.                     }
  3691.                     if (array_key_exists('libelle'$parametre_cond_achat) && trim($parametre_cond_achat['libelle']) != "") {
  3692.                         $sql_cond_achat .= " libelle = '".$parametre_cond_achat['libelle']."',";
  3693.                     }
  3694.                     if (array_key_exists('quantite'$parametre_cond_achat) && trim($parametre_cond_achat['quantite']) != "") {
  3695.                         $sql_cond_achat .= " quantite = '".$parametre_cond_achat['quantite']."',";
  3696.                     }
  3697.                     if (array_key_exists('conditionnement'$parametre_cond_achat) && trim($parametre_cond_achat['conditionnement']) != "") {
  3698.                         $sql_cond_achat .= " conditionnement = '".$parametre_cond_achat['conditionnement']."',";
  3699.                     }
  3700.                     if (array_key_exists('fournisseur'$parametre_cond_achat) && trim($parametre_cond_achat['fournisseur']) != "") {
  3701.                         $sql_cond_achat .= " fournisseur_id = '".$parametre_cond_achat['fournisseur']."',";
  3702.                     }
  3703.                     if (array_key_exists('fraisAnnexes'$parametre_cond_achat) && trim($parametre_cond_achat['fraisAnnexes']) != "") {
  3704.                         $sql_cond_achat .= " frais_annexes = '".$parametre_cond_achat['fraisAnnexes']."',";
  3705.                     }
  3706.                     if (array_key_exists('coefficient'$parametre_cond_achat) && trim($parametre_cond_achat['coefficient']) != "") {
  3707.                         $sql_cond_achat .= " coefficient = '".$parametre_cond_achat['coefficient']."',";
  3708.                     }
  3709.                     if (
  3710.                         (array_key_exists('prixAchatBrut'$parametre_cond_achat) && trim($parametre_cond_achat['prixAchatBrut']) != "")
  3711.                         or
  3712.                         (array_key_exists('tauxRemise'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemise']) != "")
  3713.                         or
  3714.                         (array_key_exists('tauxRemiseSupplementaire'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemiseSupplementaire']) != "")
  3715.                         or
  3716.                         (array_key_exists('prixAchatNet'$parametre_cond_achat) && trim($parametre_cond_achat['prixAchatNet']) != "")
  3717.                         or
  3718.                         (array_key_exists('coefficient'$parametre_cond_achat) && trim($parametre_cond_achat['coefficient']) != "")
  3719.                         or
  3720.                         (array_key_exists('fraisAnnexes'$parametre_cond_achat) && trim($parametre_cond_achat['fraisAnnexes']) != "")
  3721.                     ) {
  3722.                         $maj_cond_achat_prix true;
  3723.                         $article             $repoArticle->find($articles[$i]["id"]);
  3724.                         if (is_object($article)) {
  3725.                             $condition $repoCondAchat->findOneBy(["article" => $article"defaut" => "1"]);
  3726.                             if (is_object($condition)) {
  3727.                                 //echo "<div>COND ACHAT ".$condition->getId()."</div>";
  3728.                                 $prixAchatBrut            "";
  3729.                                 $tauxRemise               "";
  3730.                                 $tauxRemiseSupplementaire "";
  3731.                                 $prixAchatNet             "";
  3732.                                 if (array_key_exists('prixAchatBrut'$parametre_cond_achat) && trim($parametre_cond_achat['prixAchatBrut']) != "") {
  3733.                                     $condition->setPrixAchatBrut(trim($parametre_cond_achat['prixAchatBrut']));
  3734.                                 }
  3735.                                 if (array_key_exists('tauxRemise'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemise']) != "") {
  3736.                                     $condition->setTauxRemise(trim($parametre_cond_achat['tauxRemise']));
  3737.                                 }
  3738.                                 if (array_key_exists('tauxRemise'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemise']) != "") {
  3739.                                     $condition->setTauxRemise(trim($parametre_cond_achat['tauxRemise']));
  3740.                                 }
  3741.                                 if (array_key_exists('tauxRemiseSupplementaire'$parametre_cond_achat) && trim($parametre_cond_achat['tauxRemiseSupplementaire']) != "") {
  3742.                                     $condition->setTauxRemiseSupplementaire(trim($parametre_cond_achat['tauxRemiseSupplementaire']));
  3743.                                 }
  3744.                                 if (array_key_exists('coefficient'$parametre_cond_achat) && trim($parametre_cond_achat['coefficient']) != "") {
  3745.                                     $condition->setCoefficient(trim($parametre_cond_achat['coefficient']));
  3746.                                 }
  3747.                                 if (array_key_exists('fraisAnnexes'$parametre_cond_achat) && trim($parametre_cond_achat['fraisAnnexes']) != "") {
  3748.                                     $condition->setFraisAnnexes(trim($parametre_cond_achat['fraisAnnexes']));
  3749.                                 }
  3750.                                 //Calcul du prix achat net
  3751.                                 $prixAchatNet $condition->getPrixAchatBrut() * (- ($condition->getTauxRemise() / 100)) * (- ($condition->getTauxRemiseSupplementaire() / 100));
  3752.                                 $coefficient  $condition->getCoefficient();
  3753.                                 if ($coefficient != 0) {
  3754.                                     $prixAchatNet $prixAchatNet $coefficient;
  3755.                                 }
  3756.                                 $prixAchatNet += $condition->getFraisAnnexes();
  3757.                                 $condition->setPrixAchatNet($prixAchatNet);
  3758.                                 //Calcul du coefficient
  3759.                                 /*
  3760.                                     if($prixAchatNet > 0){
  3761.                                         $coefficient = $condition->getPrixAchatBrut() / $prixAchatNet;
  3762.                                         $condition->setCoefficient($coefficient);
  3763.                                     }
  3764.                                              *
  3765.                                              */
  3766.                                 $this->majEnFonctionDuPrixAchat($article$condition->getPrixAchatBrut());
  3767.                                 $this->entityManager->persist($condition);
  3768.                             }
  3769.                         }
  3770.                     }
  3771.                     if ($sql_cond_achat != "UPDATE article__condition_achat SET ") {
  3772.                         $sql_cond_achat .= ",";
  3773.                         $sql_cond_achat str_replace(",,"""$sql_cond_achat);
  3774.                         $sql_cond_achat .= " WHERE article_id = '".$articles[$i]["id"]."' and statut = '1'";
  3775.                         //echo "<div>SQL COND ACHAT : ".$sql_cond_achat." <br/><br/></div>";
  3776.                         $stmt $conn->prepare($sql_cond_achat);
  3777.                         $stmt->executeQuery();
  3778.                     }
  3779.                 }
  3780.                 if ($maj_cond_achat_prix) {
  3781.                     $this->entityManager->flush();
  3782.                 }
  3783.             }
  3784.         }
  3785.         $user $this->security->getUser();
  3786.         $chemin_pic $_SERVER["DOCUMENT_ROOT"]."/uploads/tmp/articles/user/".$user->getId()."/images/".$param_valeur['tokenPicture'];
  3787.         $chemin_doc $_SERVER["DOCUMENT_ROOT"]."/uploads/tmp/documents/user/".$user->getId()."/documents/".$param_valeur['tokenDocument'];
  3788.         if (is_dir($chemin_pic) || is_dir($chemin_doc)) {
  3789.             $repoArticle $this->entityManager->getRepository(Article::class);
  3790.             if ( ! is_array($liste_resultats)) {
  3791.                 $liste_resultats $this->rechercheArticleChaine($param_recherche"rechercher");
  3792.             }
  3793.             $articles $liste_resultats["resultats"];
  3794.             $nbLignes count($articles);
  3795.             for ($i 0$i count($articles); $i++) {
  3796.                 $article $repoArticle->find($articles[$i]["id"]);
  3797.                 if (is_object($article)) {
  3798.                     $this->imageArticleService->sauvegarder($article'images'$param_valeur['tokenPicture'], false$param_valeur['supprimerImgExistant'], $param_valeur['publierImgWeb']);
  3799.                     $this->documentArticleService->sauvegarder(
  3800.                         $article,
  3801.                         'documents',
  3802.                         $param_valeur['tokenDocument'],
  3803.                         false,
  3804.                         $param_valeur['supprimerDocExistant'],
  3805.                         $param_valeur['publierDocWeb']
  3806.                     );
  3807.                     //$imageService->sauvegarder($article,'images',$param_valeur['tokenPicture'],false,false);
  3808.                 }
  3809.             }
  3810.             //$nbLignes = 999999;
  3811.         }
  3812.         if (array_key_exists('categories'$param_valeur) && count($param_valeur['categories']) > 0) {
  3813.             $liste_resultats $this->rechercheArticleChaine($param_recherche"rechercher");
  3814.             $articles        $liste_resultats["resultats"];
  3815.             $nbLignes        count($articles);
  3816.             ///echo "<div>MODIF CATEGORIE</div>";
  3817.             $parametre_categorie $param_valeur['categories'];
  3818.             $sqlCategorie        "DELETE FROM `article__article_categorie` WHERE article_id IN (SELECT * FROM  (".$sql_recherche.") AS tmp)";
  3819.             //echo "<div>sqlCategorie : ".$sqlCategorie."</div>";
  3820.             $stmt $conn->prepare($sqlCategorie);
  3821.             $stmt->executeQuery();
  3822.             for ($z 0$z count($param_valeur['categories']); $z++) {
  3823.                 for ($i 0$i count($articles); $i++) {
  3824.                     //echo "<div>TITITI ".count($param_valeur['categories'])."</div>";
  3825.                     $reqInsert "INSERT INTO `article__article_categorie` (article_id,categorie_id) VALUES ('".$articles[$i]["id"]."','".$param_valeur["categories"][$z]."')";
  3826.                     $stmt      $conn->prepare($reqInsert);
  3827.                     $stmt->executeQuery();
  3828.                     //echo "<div>ARTICLE : ".$articles[$i]["reference"]." ==> ".$reqInsert."</div>";
  3829.                 }
  3830.             }
  3831.         }
  3832.         //$nbLignes = 0;
  3833.         return $nbLignes;
  3834.         //return $tabRetour;
  3835.     }
  3836.     public function construireWhereMajEnChaine($param = [])
  3837.     {
  3838.         $where  "";
  3839.         $select "SELECT id FROM `article__article` as x ";
  3840.         $retour = [];
  3841.         if (array_key_exists('marque'$param) && $param['marque'] != "") {
  3842.             if ($where == "") {
  3843.                 $where .= " WHERE";
  3844.             } else {
  3845.                 $where .= " AND";
  3846.             }
  3847.             $where .= " marque_id = '".$param['marque']."'";
  3848.         }
  3849.         if (array_key_exists('sous_categorie_article_sel'$param) && $param['sous_categorie_article_sel'] != "") {
  3850.             if ($where == "") {
  3851.                 $where .= " WHERE";
  3852.             } else {
  3853.                 $where .= " AND";
  3854.             }
  3855.             $where .= " x.id IN (SELECT article_id FROM `article__article_categorie` WHERE `categorie_id` = ".$param['sous_categorie_article_sel'].")";
  3856.         } elseif (array_key_exists('categorie_article_sel'$param) && $param['categorie_article_sel'] != "") {
  3857.             if ($where == "") {
  3858.                 $where .= " WHERE";
  3859.             } else {
  3860.                 $where .= " AND";
  3861.             }
  3862.             $where .= " x.id IN (SELECT article_id FROM `article__article_categorie` WHERE `categorie_id` = ".$param['categorie_article_sel'].")";
  3863.         }
  3864.         $select           .= $where;
  3865.         $retour["where"]  = $where;
  3866.         $retour["select"] = $select;
  3867.         return $retour;
  3868.     }
  3869.     public function majEnChaine($param = [])
  3870.     {
  3871.         //print_r($param);
  3872.         $param['valeur'] = floatval($param['valeur']);
  3873.         $countUpdated    "";
  3874.         $sql             "";
  3875.         $conn            $this->entityManager->getConnection();
  3876.         $selection       $this->construireWhereMajEnChaine($param);
  3877.         if (array_key_exists('champ'$param) && array_key_exists('valeur'$param)) {
  3878.             if ($param["champ"] == "largeur" || $param["champ"] == "hauteur" || $param["champ"] == "profondeur" || $param["champ"] == "poids") {
  3879.                 $sql "UPDATE `article__article` as x SET ".$param["champ"]."='".$param['valeur']."'".$selection["where"];
  3880.             } elseif ($param["champ"] == "type") {
  3881.                 $sql "UPDATE `article__article` as x SET type_id='".$param['typeArticle']."'".$selection["where"];
  3882.             } elseif ($param["champ"] == "compta") {
  3883.                 $sql "UPDATE `article__article` as x SET famille_compta_id='".$param['familleComptaArticle']."'".$selection["where"];
  3884.             } elseif ($param["champ"] == "image") {
  3885.                 $stmt $conn->prepare($selection["select"]);
  3886.                 $results     $stmt->executeQuery()->fetchAllAssociative();
  3887.                 $repoArticle $this->entityManager->getRepository(Article::class);
  3888.                 for ($i 0$i count($results); $i++) {
  3889.                     $article $repoArticle->find($results[$i]["id"]);
  3890.                     if (is_object($article)) {
  3891.                         $this->imageArticleService->sauvegarder($article'images'$param['tokenPicture'], false$param['supprimerImgExistant']);
  3892.                     }
  3893.                 }
  3894.             } elseif ($param["champ"] == "document") {
  3895.                 $stmt $conn->prepare($selection["select"]);
  3896.                 $results     $stmt->executeQuery()->fetchAllAssociative();
  3897.                 $repoArticle $this->entityManager->getRepository(Article::class);
  3898.                 for ($i 0$i count($results); $i++) {
  3899.                     $article $repoArticle->find($results[$i]["id"]);
  3900.                     if (is_object($article)) {
  3901.                         $this->documentArticleService->sauvegarder($article'documents'$param['tokenDocument'], false$param['supprimerDocExistant']);
  3902.                     }
  3903.                 }
  3904.             } elseif ($param["champ"] == "categorie") {
  3905.                 $stmt $conn->prepare($selection["select"]);
  3906.                 $results     $stmt->executeQuery()->fetchAllAssociative();
  3907.                 $repoArticle $this->entityManager->getRepository(Article::class);
  3908.                 for ($i 0$i count($results); $i++) {
  3909.                     $article $repoArticle->find($results[$i]["id"]);
  3910.                     if (is_object($article)) {
  3911.                         if ($param["supprimerCategorieExistant"]) {
  3912.                             $sqlCategorie "DELETE FROM `article__article_categorie` WHERE article_id = '".$article->getId()."'";
  3913.                             $stmt         $conn->prepare($sqlCategorie);
  3914.                             $stmt->executeQuery();
  3915.                         }
  3916.                         for ($z 0$z count($param["categories"]); $z++) {
  3917.                             $reqExiste "SELECT count(*) as total FROM `article__article_categorie` WHERE categorie_id = '".$param["categories"][$z]."' AND article_id = '".$article->getId(
  3918.                                 )."'";
  3919.                             $stmt      $conn->prepare($reqExiste);
  3920.                             $resultsExiste $stmt->executeQuery()->fetchAllAssociative();
  3921.                             if ($resultsExiste[0]["total"] == 0) {
  3922.                                 $reqInsert "INSERT INTO `article__article_categorie` (article_id,categorie_id) VALUES ('".$article->getId()."','".$param["categories"][$z]."')";
  3923.                                 $stmt      $conn->prepare($reqInsert);
  3924.                                 $stmt->executeQuery();
  3925.                             }
  3926.                         }
  3927.                     }
  3928.                 }
  3929.             } elseif ($param["champ"] == "coefficient") {
  3930.                 $stmt $conn->prepare($selection["select"]);
  3931.                 $results     $stmt->executeQuery()->fetchAllAssociative();
  3932.                 $repoArticle $this->entityManager->getRepository(Article::class);
  3933.                 for ($i 0$i count($results); $i++) {
  3934.                     $article $repoArticle->find($results[$i]["id"]);
  3935.                     if (is_object($article)) {
  3936.                         if ($article->getPrixBase() > 0) {
  3937.                             $prix_vente  round($article->getPrixBase() * $param['valeur'], 2);
  3938.                             $tauxMarge   round(($prix_vente $article->getPrixBase()) * 100 $prix_vente2);
  3939.                             $marge       $prix_vente $article->getPrixBase();
  3940.                             $margeReelle round($prix_vente $article->getCpump(), 2);
  3941.                             $reqUpdate "UPDATE `article__article` as x SET
  3942.                                         `coefficient_px_base_px_vente` = '".$param['valeur']."',
  3943.                                         `prix_vente` = '".$prix_vente."',
  3944.                                         `taux_marge` = '".$tauxMarge."',
  3945.                                         `marge` = '".$marge."',
  3946.                                         `marge_reelle` = '".$margeReelle."'
  3947.                                         WHERE
  3948.                                         `id` = '".$article->getId()."'
  3949.                                         ";
  3950.                             $stmt      $conn->prepare($reqUpdate);
  3951.                             $stmt->executeQuery();
  3952.                             //if($article->getId() == "1005888") echo "<div>".$reqUpdate."</div>";
  3953.                         }
  3954.                     }
  3955.                 }
  3956.             }
  3957.         }
  3958.         if ($sql != "") {
  3959.             $stmt $conn->prepare($sql);
  3960.             $countUpdated $stmt->executeQuery()->rowCount();
  3961.         }
  3962.         //echo "<div>SQL ".$selection["select"]."</div>";
  3963.         //echo "<div>".$sql." <br/><br/>(".$countUpdated.")\n\n</div>";
  3964.         return $countUpdated;
  3965.     }
  3966.     public function besoin(Article $article)
  3967.     {
  3968.         $dispo $article->getStock() - $article->getStockReserve() + $article->getRalFournisseur();
  3969.         if ($dispo >= 0) {
  3970.             return '';
  3971.         }
  3972.         return abs($dispo);
  3973.     }
  3974.     public function conso(Article $article$nbMois 0$nbMoisDecalage 0)
  3975.     {
  3976.         $repo_mvt_stock $this->entityManager->getRepository(MouvementStock::class);
  3977.         $conso          $repo_mvt_stock->getQteVenduSurPeriode($article$nbMois$nbMoisDecalage);
  3978.         return $conso;
  3979.     }
  3980.     public function conditionnement(Article $articleFournisseur $fournisseur)
  3981.     {
  3982.         $repo_condition_achat $this->entityManager->getRepository(ConditionAchat::class);
  3983.         $conditionnement      0;
  3984.         $conditionAchat       $repo_condition_achat->findOneBy([
  3985.                                                                      'article'     => $article->getId(),
  3986.                                                                      'fournisseur' => $fournisseur->getId(),
  3987.                                                                  ]);
  3988.         if (is_object($conditionAchat)) {
  3989.             $conditionnement $conditionAchat->getConditionnement();
  3990.         }
  3991.         return $conditionnement;
  3992.     }
  3993.     public function getTotalEnfants(Article $article)
  3994.     {
  3995.         $repo_article $this->entityManager->getRepository(Article::class);
  3996.         $articles     $repo_article->findByParent($article);
  3997.         return count($articles);
  3998.     }
  3999.     public function articleCommandeSupprimableCommande(ArticleCommande $ac)
  4000.     {
  4001.         $repo_article $this->entityManager->getRepository(Article::class);
  4002.         return $repo_article->articleCommandeSupprimableCommande($ac);
  4003.     }
  4004.     public function getRaf($article)
  4005.     {
  4006.         $repo $this->entityManager->getRepository(Fabrication::class);
  4007.         return $repo->getRaf($article);
  4008.     }
  4009.     public function derniereEntreeStock($id_article$param = [])
  4010.     {
  4011.         $repo_commande  $this->entityManager->getRepository(Commande::class);
  4012.         $dernier_entree $repo_commande->derniereEntreeStock($id_article$param);
  4013.         return $dernier_entree;
  4014.     }
  4015.     public function derniereSortieStock($id_article$param)
  4016.     {
  4017.         $repo_commande  $this->entityManager->getRepository(Commande::class);
  4018.         $dernier_sortie $repo_commande->derniereSortieStock($id_article$param);
  4019.         return $dernier_sortie;
  4020.     }
  4021.     public function getCategorieNiveauUn($id_article)
  4022.     {
  4023.         $repo_categorie $this->entityManager->getRepository(Categorie::class);
  4024.         $categories     $repo_categorie->getCategorieNiveauUn($id_article);
  4025.         return $categories;
  4026.     }
  4027.     public function getRalClientEtCmdAssociees(Article $article)
  4028.     {
  4029.         $repoArticleCommande $this->entityManager->getRepository(ArticleCommande::class);
  4030.         $reservations        $repoArticleCommande->getRalClientEtCmdAssociees($article);
  4031.         //echo "AAAA ".$article->getReference();
  4032.         return $reservations;
  4033.     }
  4034.     public function getRalFournisseur(Article $article$negatif false)
  4035.     {
  4036.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  4037.         $ralFournisseur        $repo_article_commande->getRalFournisseur($article->getId(), $negatif);
  4038.         return $ralFournisseur;
  4039.     }
  4040.     public function quantiteAfabriquer(Article $article)
  4041.     {
  4042.         $dispo $article->getStock() - $article->getStockReserve();
  4043.         $seuil 0;
  4044.         if ($article->getSeuilMiniCommandeFournisseur() > 0) {
  4045.             $seuil $article->getSeuilMiniCommandeFournisseur();
  4046.         }
  4047.         if ($article->getSeuilMaxiCommandeFournisseur() > 0) {
  4048.             $seuil $article->getSeuilMaxiCommandeFournisseur();
  4049.         }
  4050.         $raf      $this->getRaf($article);
  4051.         $quantite $seuil $dispo $raf;
  4052.         if ($quantite <= 0) {
  4053.             $quantite 1;
  4054.         }
  4055.         $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  4056.         $condHa $repo_condha->findOneBy(["defaut" => "1""fournisseur" => 132"article" => $article]);
  4057.         if (is_object($condHa)) {
  4058.             $qteCondHa $condHa->getQuantite();
  4059.             if ($qteCondHa $quantite) {
  4060.                 $quantite $qteCondHa;
  4061.             }
  4062.         }
  4063.         return $quantite;
  4064.     }
  4065.     public function articleAfabriquer(Article $article)
  4066.     {
  4067.         $raf $this->getRaf($article);
  4068.         $dispo $article->getStock() - $article->getStockReserve() + $raf;
  4069.         //return $dispo;
  4070.         if ($dispo 0) {
  4071.             return 1;
  4072.         }
  4073.         if ($article->getSeuilMiniCommandeFournisseur() > 0) {
  4074.             $seuil    $article->getSeuilMiniCommandeFournisseur();
  4075.             $quantite $seuil $dispo;
  4076.             if ($dispo $seuil) {
  4077.                 return 1;
  4078.             }
  4079.         }
  4080.         return 0;
  4081.     }
  4082.     public function getArticlesAfabriquerSeuilMini()
  4083.     {
  4084.         $articles                   = [];
  4085.         $articlesInternesAFabriquer $this->entityManager->getRepository(Article::class)->getArticlesAfabriquerSeuilMini();
  4086.         foreach ($articlesInternesAFabriquer as $articleInternesAFabriquer) {
  4087.             $raf   $this->getRaf($articleInternesAFabriquer);
  4088.             $dispo $articleInternesAFabriquer->getStock() - $articleInternesAFabriquer->getStockReserve() + $raf;
  4089.             if ($articleInternesAFabriquer->getSeuilMiniCommandeFournisseur() > 0) {
  4090.                 $seuil $articleInternesAFabriquer->getSeuilMiniCommandeFournisseur();
  4091.                 if ($dispo $seuil) {
  4092.                     if ($articleInternesAFabriquer->getSeuilMaxiCommandeFournisseur() > 0) {
  4093.                         $seuil $articleInternesAFabriquer->getSeuilMaxiCommandeFournisseur();
  4094.                     }
  4095.                     $articleTmp = [
  4096.                         'article'  => $articleInternesAFabriquer,
  4097.                         'quantite' => $seuil $dispo,
  4098.                     ];
  4099.                     $articles[] = $articleTmp;
  4100.                 }
  4101.             }
  4102.         }
  4103.         return $articles;
  4104.     }
  4105.     public function dispo(Article $article)
  4106.     {
  4107.         $dispo $article->getStock() - $article->getStockReserve();
  4108.         if ($dispo 0) {
  4109.             $dispo 0;
  4110.         }
  4111.         return $dispo;
  4112.     }
  4113.     public function estReservable(Article $article)
  4114.     {
  4115.         if ($article->getMainOeuvre() == 1) {
  4116.             return false;
  4117.         }
  4118.         return true;
  4119.     }
  4120.     public function getPumpR(Article $article)
  4121.     {
  4122.         return $this->entityManager->getRepository(Article::class)->getPumpR($article->getId());
  4123.     }
  4124.     public function getPumpC(Article $article)
  4125.     {
  4126.         return $this->entityManager->getRepository(Article::class)->getPumpC($article->getId());
  4127.     }
  4128.     public function getPumpComposeVirtuel($id$date_debut ""$date_fin ""$type "")
  4129.     {
  4130.         $article        $this->entityManager->getRepository(Article::class)->find($id);
  4131.         $repo_condha    $this->entityManager->getRepository(ConditionAchat::class);
  4132.         $repo_mouvement $this->entityManager->getRepository(MouvementStock::class);
  4133.         $somme_pump 0;
  4134.         //echo "<div>TYPE : ".$type."</div>";
  4135.         if (is_object($article) && $article->getVirtuel() == true && $article->getProduitInterne() == true) {
  4136.             $composants    $article->getArticlesComposants();
  4137.             $nb_composants count($composants);
  4138.             if (count($composants) > 0) {
  4139.                 foreach ($composants as $c) {
  4140.                     $sql "
  4141.                         SELECT
  4142.                         AVG(ac.cpump) as pump_avg
  4143.                         FROM `article__mouvement_stock` as ac
  4144.                         LEFT JOIN article__article as ar on ar.id = ac.article_id
  4145.                         WHERE
  4146.                         ac.cpump is not null and ac.cpump != 0
  4147.                         AND
  4148.                         ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4149.                         AND ar.id = ".$c->getArticle()->getId()."
  4150.                     ";
  4151.                     //echo "<div>SQL ".$sql."</div>";
  4152.                     $stmt $this->entityManager->getConnection()->prepare($sql);
  4153.                     $retour $stmt->executeQuery()->fetchAllAssociative();
  4154.                     //print_r($retour);
  4155.                     //if($c->getArticle()->getPump() > 0) {
  4156.                     if ($retour[0]["pump_avg"] > 0) {
  4157.                         //echo "<div>OK ".$retour[0]["pump_avg"]."</div>";
  4158.                         $somme_pump $somme_pump $retour[0]["pump_avg"];
  4159.                     } else {
  4160.                         $condHa $repo_condha->findOneBy(["article" => $c->getArticle(), "defaut" => 1]);
  4161.                         if (is_object($condHa)) {
  4162.                             $prix $condHa->getPrixAchatNet();
  4163.                             if ($condHa->getCoefficientConditionnement() != 0) {
  4164.                                 $prix $prix $condHa->getCoefficientConditionnement();
  4165.                             }
  4166.                             $tauxChange  1;
  4167.                             $fournisseur $condHa->getFournisseur();
  4168.                             if (is_object($fournisseur)) {
  4169.                                 $devise $fournisseur->getDevise();
  4170.                             }
  4171.                             if (is_object($devise) && $devise->getTauxChange() != 0) {
  4172.                                 $tauxChange $devise->getTauxChange();
  4173.                             }
  4174.                             $prix $prix $tauxChange//prix d'achat brut converti en euros
  4175.                             $somme_pump $somme_pump $prix;
  4176.                         }
  4177.                     }
  4178.                 }
  4179.             }
  4180.         } elseif (is_object($article)) {
  4181.             $compteur_mouvement 0;
  4182.             if ($type == "bl") {
  4183.                 $sql "
  4184.                 SELECT
  4185.                 ac.id,
  4186.                 ac.date_mouvement,
  4187.                 ac.stock as stock,
  4188.                 ac.cpump as cpump
  4189.                 FROM `article__mouvement_stock` as ac
  4190.                 LEFT JOIN commerciale__commande as c on ac.commande_id = c.id
  4191.                 LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  4192.                 LEFT JOIN client__client as u on u.id = c.client_id
  4193.                 LEFT JOIN article__article as ar on ar.id = ac.article_id
  4194.                 WHERE
  4195.                 ac.article_id = ".$id."
  4196.                 AND
  4197.                 ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4198.                 AND
  4199.                 (
  4200.                 ( (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25))
  4201.                 )
  4202.                 AND (c.facture_id is NULL or f.statut_commande_id = 23)
  4203.                 ";
  4204.                 //echo "<div>SQL BL ".$sql."</div>";
  4205.             } else {
  4206.                 $sql "
  4207.                         SELECT
  4208.                         ac.id,
  4209.                         ac.date_mouvement,
  4210.                         ac.stock as stock,
  4211.                         ac.cpump as cpump
  4212.                         FROM `article__mouvement_stock` as ac
  4213.                         LEFT JOIN commerciale__commande as c on ac.commande_id = c.id
  4214.                         LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  4215.                         LEFT JOIN client__client as u on u.id = c.client_id
  4216.                         LEFT JOIN article__article as ar on ar.id = ac.article_id
  4217.                         WHERE
  4218.                         ac.article_id = ".$id."
  4219.                         AND
  4220.                         ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4221.                         AND
  4222.                         (
  4223.                         (  (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25 AND (c.facture_id is NOT NULL and f.statut_commande_id != 23))
  4224.                             OR
  4225.                             ((c.type_document_commercial_id = ".TypeDocumentCommercial::FACTURE." AND c.statut_commande_id != 23) )
  4226.                             OR
  4227.                             (c.type_document_commercial_id = ".TypeDocumentCommercial::AVOIR." AND c.statut_commande_id != 19))
  4228.                         )
  4229.                     ";
  4230.                 //echo "<div>SQL NORMAL ".$sql."</div>";
  4231.                 /*
  4232.                 $sql = "
  4233.                     SELECT
  4234.                     ac.stock as stock,
  4235.                     ac.pump as pump
  4236.                     FROM `article__mouvement_stock` as ac
  4237.                     LEFT JOIN article__article as ar on ar.id = ac.article_id
  4238.                     WHERE
  4239.                     ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4240.                     AND ar.id = ".$article->getId()."
  4241.                 ";
  4242.                 */
  4243.             }
  4244.             //echo "<div>SQL ".$sql."</div>";
  4245.             $stmt $this->entityManager->getConnection()->prepare($sql);
  4246.             $retour $stmt->executeQuery()->fetchAllAssociative();
  4247.             if (count($retour) > 0) {
  4248.                 for ($i 0$i count($retour); $i++) {
  4249.                     if ($retour[$i]["stock"] <= or $retour[$i]["cpump"] <= 0) {
  4250.                         //echo "<div>PUMP PAS OK</div>";
  4251.                         $condHa $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  4252.                         if (is_object($condHa)) {
  4253.                             //echo "<div>CONDHA OK</div>";
  4254.                             $prix $condHa->getPrixAchatNet();
  4255.                             if ($condHa->getCoefficientConditionnement() != 0) {
  4256.                                 $prix $prix $condHa->getCoefficientConditionnement();
  4257.                             }
  4258.                             $tauxChange  1;
  4259.                             $fournisseur $condHa->getFournisseur();
  4260.                             if (is_object($fournisseur)) {
  4261.                                 $devise $fournisseur->getDevise();
  4262.                             }
  4263.                             if (is_object($devise) && $devise->getTauxChange() != 0) {
  4264.                                 $tauxChange $devise->getTauxChange();
  4265.                             }
  4266.                             $prix $prix $tauxChange//prix d'achat brut converti en euros
  4267.                             $compteur_mouvement++;
  4268.                             //echo "<div>PRIX ".$prix."</div>";
  4269.                             $somme_pump $somme_pump $prix;
  4270.                         } else {
  4271.                             $condHa $repo_condha->findOneBy(["article" => $article]);
  4272.                             if (is_object($condHa)) {
  4273.                                 //echo "<div>CONDHA OK</div>";
  4274.                                 $prix $condHa->getPrixAchatNet();
  4275.                                 if ($condHa->getCoefficientConditionnement() != 0) {
  4276.                                     $prix $prix $condHa->getCoefficientConditionnement();
  4277.                                 }
  4278.                                 $tauxChange  1;
  4279.                                 $fournisseur $condHa->getFournisseur();
  4280.                                 if (is_object($fournisseur)) {
  4281.                                     $devise $fournisseur->getDevise();
  4282.                                 }
  4283.                                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  4284.                                     $tauxChange $devise->getTauxChange();
  4285.                                 }
  4286.                                 $prix $prix $tauxChange//prix d'achat brut converti en euros
  4287.                                 $compteur_mouvement++;
  4288.                                 //echo "<div>PRIX ".$prix."</div>";
  4289.                                 $somme_pump $somme_pump $prix;
  4290.                             }
  4291.                         }
  4292.                     } else {
  4293.                         //echo "<div>PUMP OK</div>";
  4294.                         $compteur_mouvement++;
  4295.                         $somme_pump $somme_pump $retour[0]["cpump"];
  4296.                     }
  4297.                 }
  4298.             }
  4299.             //echo "<div>SOMME PUMP ".$somme_pump."</div>";
  4300.             //echo "<div>COMPTEUR MOUVEMNET ".$compteur_mouvement."</div>";
  4301.             if ($compteur_mouvement 0) {
  4302.                 $somme_pump $somme_pump $compteur_mouvement;
  4303.             }
  4304.             //echo "<div>MOYENNE PUMP ".$somme_pump."</div>";
  4305.         }
  4306.         return $somme_pump;
  4307.     }
  4308.     public function getStatsArticle($id$date_debut ""$date_fin ""$integreBl false$parametres = [])
  4309.     {
  4310.         //print_r($parametres);
  4311.         $article        $this->entityManager->getRepository(Article::class)->find($id);
  4312.         $repo_condha    $this->entityManager->getRepository(ConditionAchat::class);
  4313.         $repo_mouvement $this->entityManager->getRepository(MouvementStock::class);
  4314.         $valeurs                  = [];
  4315.         $valeurs["reference"]     = $article->getReference();
  4316.         $valeurs["libelle"]       = $article->getLibelle();
  4317.         $valeurs["quantite"]      = "";
  4318.         $valeurs["ca"]            = "";
  4319.         $valeurs["bl"]            = "";
  4320.         $valeurs["marge"]         = "";
  4321.         $valeurs["margePourcent"] = "";
  4322.         $somme_marge 0;
  4323.         $somme_ca    0;
  4324.         $somme_bl    0;
  4325.         $somme_qte   0;
  4326.         $join_table_client false;
  4327.         $join              "";
  4328.         $where             "";
  4329.         if (array_key_exists('client'$parametres) and $parametres["client"] != "" and $parametres["client"] > 0) {
  4330.             //if(!$join_table_client) $join .= " LEFT JOIN client__client as clt on c.client_id = clt.id";
  4331.             $where .= " AND u.id = '".$parametres["client"]."'";
  4332.             //$join_table_client = true;
  4333.         }
  4334.         if (array_key_exists('categorie_client'$parametres) and $parametres["categorie_client"] > 0) {
  4335.             //if(!$join_table_client) $join .= " LEFT JOIN client__client as clt on c.client_id = clt.id";
  4336.             $join .= " LEFT JOIN client__client_categorie as cltcat on cltcat.client_id = u.id";
  4337.             if (array_key_exists('sous_categorie_client'$parametres) and $parametres["sous_categorie_client"] > 0) {
  4338.                 $where .= " AND (cltcat.categorie_id = '".$parametres["sous_categorie_client"]."' and cltcat.dateSuppression is null)";
  4339.             } else {
  4340.                 $where .= " AND (cltcat.categorie_id = '".$parametres["categorie_client"]."' and cltcat.dateSuppression is null)";
  4341.             }
  4342.             //echo "OK";
  4343.         }
  4344.         //echo "<div>TYPE : ".$type."</div>";
  4345.         $inArticle        $id;
  4346.         $jointureCommande "ac.commande_id";
  4347.         if (is_object($article)) {
  4348.             //echo "test";
  4349.             if (is_object($article) && $article->getVirtuel() == true && $article->getProduitInterne() == true and != 1) {
  4350.                 //echo "<div>COMPOSE</div>";
  4351.                 $composants    $article->getArticlesComposants();
  4352.                 $nb_composants count($composants);
  4353.                 if (count($composants) > 0) {
  4354.                     $tabPumCompose        = [];
  4355.                     $tabArticleComposants = [];
  4356.                     $inArticle            .= ",";
  4357.                     $jointureCommande     "ac.commande_id";
  4358.                     foreach ($composants as $c) {
  4359.                         $inArticle .= $c->getArticle()->getId().",";
  4360.                     }
  4361.                     $inArticle trim($inArticle",");
  4362.                     if ($integreBl) {
  4363.                         //POUR LES BL
  4364.                         $sql "
  4365.                         SELECT
  4366.                         ac.prix_achat,
  4367.                         ac.quantite,
  4368.                         ac.id,
  4369.                         ac.date_mouvement,
  4370.                         ac.stock as stock,
  4371.                         ac.cpump as cpump,
  4372.                         ac.article_id as articleId
  4373.                         FROM `article__mouvement_stock` as ac
  4374.                         LEFT JOIN commerciale__commande as c on ac.commande_id = c.id
  4375.                         LEFT JOIN commerciale__commande as cvirt on ac.commande_virtuel_id = cvirt.id
  4376.                         LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  4377.                         LEFT JOIN commerciale__commande as fvirt on cvirt.facture_id = fvirt.id
  4378.                         LEFT JOIN client__client as u on u.id = c.client_id
  4379.                         LEFT JOIN article__article as ar on ar.id = ac.article_id
  4380.                         ".$join."
  4381.                         WHERE
  4382.                         ac.article_id IN (".$inArticle.")
  4383.                         AND
  4384.                         ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4385.                         AND
  4386.                         (
  4387.                             (
  4388.                                 (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25)
  4389.                                 OR
  4390.                                 (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND cvirt.statut_commande_id != 25 and ac.commande_virtuel_id is not null)
  4391.                             )
  4392.                         )
  4393.                         AND
  4394.                         (
  4395.                             (c.facture_id is NULL or f.statut_commande_id = 23)
  4396.                             OR
  4397.                             ((cvirt.facture_id is NULL or fvirt.statut_commande_id = 23) and ac.commande_virtuel_id is not null)
  4398.                         )
  4399.                         ".$where."
  4400.                         ";
  4401.                         //echo $sql;
  4402.                         $stmt $this->entityManager->getConnection()->prepare($sql);
  4403.                         $retour $stmt->executeQuery()->fetchAllAssociative();
  4404.                         if (count($retour) > 0) {
  4405.                             $quantite_vente 0;
  4406.                             $prix_vente     0;
  4407.                             $cpump_compose  0;
  4408.                             for ($i 0$i count($retour); $i++) {
  4409.                                 //echo "<div><br/>AAAA ===> ".$retour[$i]["articleId"]."</div>";
  4410.                                 if ($retour[$i]["articleId"] == $id) {
  4411.                                     //   echo "<div>RRRRR ===> ".$retour[$i]["articleId"]."</div>";
  4412.                                     $quantite_vente += $retour[$i]["quantite"];
  4413.                                     $prix_vente     $retour[$i]["prix_achat"];
  4414.                                     $prix_vente     $retour[$i]["cpump"];
  4415.                                     $somme_qte += $retour[$i]["quantite"];
  4416.                                     $somme_bl  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  4417.                                 } elseif (!= 1) {
  4418.                                     //echo "<div>WWWW ===> ".$retour[$i]["articleId"]."</div>";
  4419.                                     if ($retour[$i]["stock"] <= or $retour[$i]["cpump"] <= 0) {
  4420.                                         //echo "<div>PUMP PAS OK</div>";
  4421.                                         $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"], "defaut" => 1]);
  4422.                                         if (is_object($condHa)) {
  4423.                                             //echo "<div>CONDHA OK</div>";
  4424.                                             $prix $condHa->getPrixAchatNet();
  4425.                                             if ($condHa->getCoefficientConditionnement() != 0) {
  4426.                                                 $prix $prix $condHa->getCoefficientConditionnement();
  4427.                                             }
  4428.                                             $tauxChange  1;
  4429.                                             $fournisseur $condHa->getFournisseur();
  4430.                                             if (is_object($fournisseur)) {
  4431.                                                 $devise $fournisseur->getDevise();
  4432.                                             }
  4433.                                             if (is_object($devise) && $devise->getTauxChange() != 0) {
  4434.                                                 $tauxChange $devise->getTauxChange();
  4435.                                             }
  4436.                                             $prix          $prix $tauxChange//prix d'achat brut converti en euros
  4437.                                             $cpump_compose $prix;
  4438.                                             //echo "<div>PRIX CHA: ".$prix."</div>";
  4439.                                         } else {
  4440.                                             $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"]]);
  4441.                                             if (is_object($condHa)) {
  4442.                                                 //echo "<div>CONDHA PAS OK</div>";
  4443.                                                 $prix $condHa->getPrixAchatNet();
  4444.                                                 if ($condHa->getCoefficientConditionnement() != 0) {
  4445.                                                     $prix $prix $condHa->getCoefficientConditionnement();
  4446.                                                 }
  4447.                                                 $tauxChange  1;
  4448.                                                 $fournisseur $condHa->getFournisseur();
  4449.                                                 if (is_object($fournisseur)) {
  4450.                                                     $devise $fournisseur->getDevise();
  4451.                                                 }
  4452.                                                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  4453.                                                     $tauxChange $devise->getTauxChange();
  4454.                                                 }
  4455.                                                 $prix          $prix $tauxChange//prix d'achat brut converti en euros
  4456.                                                 $cpump_compose $prix;
  4457.                                             }
  4458.                                         }
  4459.                                     } else {
  4460.                                         //echo "<div>PUMP OK</div>";
  4461.                                         $cpump_compose $retour[0]["cpump"];
  4462.                                     }
  4463.                                     if (array_key_exists($retour[$i]["articleId"], $tabPumCompose)) {
  4464.                                         $tabPumCompose[$retour[$i]["articleId"]]["quantite"] += $retour[$i]["quantite"];
  4465.                                         $tabPumCompose[$retour[$i]["articleId"]]["cump"]     += $cpump_compose $retour[$i]["quantite"];
  4466.                                     } else {
  4467.                                         $tabPumCompose[$retour[$i]["articleId"]] = ["quantite" => $retour[$i]["quantite"], "cump" => $cpump_compose $retour[$i]["quantite"]];
  4468.                                     }
  4469.                                 }
  4470.                             }
  4471.                             $cpump_compose 0;
  4472.                             if (count($tabPumCompose) > 0) {
  4473.                                 foreach ($tabPumCompose as $key => $value) {
  4474.                                     if ($value["quantite"] != 0) {
  4475.                                         $cpump_compose += $value["cump"] / $value["quantite"];
  4476.                                     }
  4477.                                 }
  4478.                             }
  4479.                             //print_r($tabPumCompose);
  4480.                             $marge_tmp   = ($quantite_vente $prix_vente) - ($quantite_vente $cpump_compose);
  4481.                             $somme_marge += $marge_tmp;
  4482.                             //echo "<div>X Q(".$quantite_vente.")</div>";
  4483.                             //echo "<div>X PV(".$prix_vente.")</div>";
  4484.                             //echo "<div>X PUMP(".$cpump_compose.")</div><br/><br/>";
  4485.                         }
  4486.                     }
  4487.                     //echo "<div>SOMME BL ".$somme_bl."</div>";
  4488.                     //print_r($tabPumCompose);
  4489.                     $sql "
  4490.                             SELECT
  4491.                             ac.id,
  4492.                             ac.prix_achat,
  4493.                             ac.date_mouvement,
  4494.                             ac.stock as stock,
  4495.                             ac.quantite,
  4496.                             ac.cpump as cpump,
  4497.                             ac.article_id as articleId
  4498.                             FROM `article__mouvement_stock` as ac
  4499.                             LEFT JOIN commerciale__commande as c on ac.commande_id = c.id
  4500.                             LEFT JOIN commerciale__commande as cvirt on ac.commande_virtuel_id = cvirt.id
  4501.                             LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  4502.                             LEFT JOIN commerciale__commande as fvirt on cvirt.facture_id = fvirt.id
  4503.                             LEFT JOIN client__client as u on u.id = c.client_id
  4504.                             LEFT JOIN article__article as ar on ar.id = ac.article_id
  4505.                             ".$join."
  4506.                             WHERE
  4507.                             ac.article_id IN (".$inArticle.")
  4508.                             AND
  4509.                             ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4510.                             AND
  4511.                             (
  4512.                             (
  4513.                                 (
  4514.                                     (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25 AND (c.facture_id is NOT NULL and f.statut_commande_id != 23))
  4515.                                     OR
  4516.                                     (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND cvirt.statut_commande_id != 25 AND (cvirt.facture_id is NOT NULL and fvirt.statut_commande_id != 23) and ac.commande_virtuel_id is not null)
  4517.                                 )
  4518.                                 OR
  4519.                                 (
  4520.                                     (c.type_document_commercial_id = ".TypeDocumentCommercial::FACTURE." AND c.statut_commande_id != 23)
  4521.                                     OR
  4522.                                     (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::FACTURE." AND cvirt.statut_commande_id != 23 and ac.commande_virtuel_id is not null)
  4523.                                 )
  4524.                                 OR
  4525.                                 (
  4526.                                     (c.type_document_commercial_id = ".TypeDocumentCommercial::AVOIR." AND c.statut_commande_id != 19)
  4527.                                     OR
  4528.                                     (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::AVOIR." AND cvirt.statut_commande_id != 19 and ac.commande_virtuel_id is not null)
  4529.                                 )
  4530.                             )
  4531.                             )
  4532.                             ".$where."
  4533.                         ";
  4534.                     //echo $sql."<br/><hr/>";
  4535.                     $stmt $this->entityManager->getConnection()->prepare($sql);
  4536.                     $retour $stmt->executeQuery()->fetchAllAssociative();
  4537.                     if (count($retour) > 0) {
  4538.                         $quantite_vente 0;
  4539.                         $prix_vente     0;
  4540.                         $cpump_compose  0;
  4541.                         $total_cout 0;
  4542.                         for ($i 0$i count($retour); $i++) {
  4543.                             if ($retour[$i]["articleId"] == $id) {
  4544.                                 //echo "<div>AAA</div>";
  4545.                                 $quantite_vente += $retour[$i]["quantite"];
  4546.                                 $prix_vente     $retour[$i]["prix_achat"];
  4547.                                 $prix_vente     $retour[$i]["cpump"];
  4548.                                 $somme_qte += $retour[$i]["quantite"];
  4549.                                 $somme_ca  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  4550.                                 $total_cout += $retour[$i]["quantite"] * $retour[$i]["cpump"];
  4551.                                 //echo "<div>QQ ".$retour[$i]["quantite"]." CUMP ".$retour[$i]["cpump"]." TOTAL ".$total_cout."</div>";
  4552.                             } elseif (!= 1) {
  4553.                                 //echo "<div>BBB</div>";
  4554.                                 if ($retour[$i]["stock"] <= or $retour[$i]["cpump"] <= 0) {
  4555.                                     //echo "<div>PUMP PAS OK</div>";
  4556.                                     $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"], "defaut" => 1]);
  4557.                                     if (is_object($condHa)) {
  4558.                                         $prix $condHa->getPrixAchatNet();
  4559.                                         if ($condHa->getCoefficientConditionnement() != 0) {
  4560.                                             $prix $prix $condHa->getCoefficientConditionnement();
  4561.                                         }
  4562.                                         $tauxChange  1;
  4563.                                         $fournisseur $condHa->getFournisseur();
  4564.                                         if (is_object($fournisseur)) {
  4565.                                             $devise $fournisseur->getDevise();
  4566.                                         }
  4567.                                         if (is_object($devise) && $devise->getTauxChange() != 0) {
  4568.                                             $tauxChange $devise->getTauxChange();
  4569.                                         }
  4570.                                         $prix $prix $tauxChange//prix d'achat brut converti en euros
  4571.                                         $cpump_compose $prix;
  4572.                                     } else {
  4573.                                         $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"]]);
  4574.                                         if (is_object($condHa)) {
  4575.                                             //echo "<div>CONDHA OK</div>";
  4576.                                             $prix $condHa->getPrixAchatNet();
  4577.                                             if ($condHa->getCoefficientConditionnement() != 0) {
  4578.                                                 $prix $prix $condHa->getCoefficientConditionnement();
  4579.                                             }
  4580.                                             $tauxChange  1;
  4581.                                             $fournisseur $condHa->getFournisseur();
  4582.                                             if (is_object($fournisseur)) {
  4583.                                                 $devise $fournisseur->getDevise();
  4584.                                             }
  4585.                                             if (is_object($devise) && $devise->getTauxChange() != 0) {
  4586.                                                 $tauxChange $devise->getTauxChange();
  4587.                                             }
  4588.                                             $prix          $prix $tauxChange//prix d'achat brut converti en euros
  4589.                                             $cpump_compose $prix;
  4590.                                         }
  4591.                                     }
  4592.                                 } else {
  4593.                                     //echo "<div>PUMP OK</div>";
  4594.                                     $cpump_compose $retour[0]["cpump"];
  4595.                                 }
  4596.                                 if (array_key_exists($retour[$i]["articleId"], $tabPumCompose)) {
  4597.                                     $tabPumCompose[$retour[$i]["articleId"]]["quantite"] += 1;
  4598.                                     $tabPumCompose[$retour[$i]["articleId"]]["cump"]     += $cpump_compose;
  4599.                                 } else {
  4600.                                     $tabPumCompose[$retour[$i]["articleId"]] = ["quantite" => 1"cump" => $cpump_compose];
  4601.                                 }
  4602.                             }
  4603.                         }
  4604.                         $cpump_compose 0;
  4605.                         if (count($tabPumCompose) > 0) {
  4606.                             foreach ($tabPumCompose as $key => $value) {
  4607.                                 if ($value["quantite"] != 0) {
  4608.                                     $cpump_compose += $value["cump"] / $value["quantite"];
  4609.                                 }
  4610.                             }
  4611.                         }
  4612.                         //print_r($tabPumCompose);
  4613.                         $marge_tmp   = ($quantite_vente $prix_vente) - ($quantite_vente $cpump_compose);
  4614.                         $somme_marge += $marge_tmp;
  4615.                         //echo "<div>Z Q(".$quantite_vente.")</div>";
  4616.                         //echo "<div>Z PV(".$prix_vente.")</div>";
  4617.                         //echo "<div>Z PUMP(".$cpump_compose.")</div><br/><br/>";
  4618.                         //echo "<div>somme_marge(".$somme_marge.")</div><br/><br/>";
  4619.                         //echo "<div>total_cout(".$total_cout.")</div><br/><br/>";
  4620.                     }
  4621.                 }
  4622.             } else {
  4623.                 if ($integreBl) {
  4624.                     //POUR LES BL
  4625.                     $sql "
  4626.                         SELECT
  4627.                         ac.prix_achat,
  4628.                         ac.quantite,
  4629.                         ac.id,
  4630.                         ac.date_mouvement,
  4631.                         ac.stock as stock,
  4632.                         ac.cpump as cpump
  4633.                         FROM `article__mouvement_stock` as ac
  4634.                         LEFT JOIN commerciale__commande as c on ".$jointureCommande." = c.id
  4635.                         LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  4636.                         LEFT JOIN client__client as u on u.id = c.client_id
  4637.                         LEFT JOIN article__article as ar on ar.id = ac.article_id
  4638.                         ".$join."
  4639.                         WHERE
  4640.                         ac.article_id IN (".$inArticle.")
  4641.                         AND
  4642.                         ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4643.                         AND
  4644.                         (
  4645.                         ( (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25))
  4646.                         )
  4647.                         AND (c.facture_id is NULL or f.statut_commande_id = 23)
  4648.                         ".$where."
  4649.                         ";
  4650.                     //echo "<div>SQL BL ".$sql."</div>";
  4651.                     $stmt $this->entityManager->getConnection()->prepare($sql);
  4652.                     $retour $stmt->executeQuery()->fetchAllAssociative();
  4653.                     if (count($retour) > 0) {
  4654.                         for ($i 0$i count($retour); $i++) {
  4655.                             //if($retour[$i]["stock"]<=0 or $retour[$i]["cpump"] <=0) {
  4656.                             if ($retour[$i]["cpump"] <= 0) {
  4657.                                 //echo "<div>PUMP PAS OK</div>";
  4658.                                 $condHa $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  4659.                                 if (is_object($condHa)) {
  4660.                                     //echo "<div>CONDHA OK</div>";
  4661.                                     $prix $condHa->getPrixAchatNet();
  4662.                                     if ($condHa->getCoefficientConditionnement() != 0) {
  4663.                                         $prix $prix $condHa->getCoefficientConditionnement();
  4664.                                     }
  4665.                                     $tauxChange  1;
  4666.                                     $fournisseur $condHa->getFournisseur();
  4667.                                     if (is_object($fournisseur)) {
  4668.                                         $devise $fournisseur->getDevise();
  4669.                                     }
  4670.                                     if (is_object($devise) && $devise->getTauxChange() != 0) {
  4671.                                         $tauxChange $devise->getTauxChange();
  4672.                                     }
  4673.                                     $prix $prix $tauxChange//prix d'achat brut converti en euros
  4674.                                     $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  4675.                                     $somme_marge += $marge_tmp;
  4676.                                 } else {
  4677.                                     $condHa $repo_condha->findOneBy(["article" => $article]);
  4678.                                     if (is_object($condHa)) {
  4679.                                         //echo "<div>CONDHA OK</div>";
  4680.                                         $prix $condHa->getPrixAchatNet();
  4681.                                         if ($condHa->getCoefficientConditionnement() != 0) {
  4682.                                             $prix $prix $condHa->getCoefficientConditionnement();
  4683.                                         }
  4684.                                         $tauxChange  1;
  4685.                                         $fournisseur $condHa->getFournisseur();
  4686.                                         if (is_object($fournisseur)) {
  4687.                                             $devise $fournisseur->getDevise();
  4688.                                         }
  4689.                                         if (is_object($devise) && $devise->getTauxChange() != 0) {
  4690.                                             $tauxChange $devise->getTauxChange();
  4691.                                         }
  4692.                                         $prix $prix $tauxChange//prix d'achat brut converti en euros
  4693.                                         $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  4694.                                         $somme_marge += $marge_tmp;
  4695.                                     }
  4696.                                 }
  4697.                             } else {
  4698.                                 //echo "<div>PUMP OK</div>";
  4699.                                 $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $retour[0]["cpump"]);
  4700.                                 $somme_marge += $marge_tmp;
  4701.                             }
  4702.                             $somme_bl  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  4703.                             $somme_qte += $retour[$i]["quantite"];
  4704.                         }
  4705.                     }
  4706.                 }
  4707.                 //$retourBl = $this->calculStatsSql($sql);
  4708.                 $sql "
  4709.                             SELECT
  4710.                             ac.id,
  4711.                             ac.prix_achat,
  4712.                             ac.date_mouvement,
  4713.                             ac.stock as stock,
  4714.                             ac.quantite,
  4715.                             ac.cpump as cpump
  4716.                             FROM `article__mouvement_stock` as ac
  4717.                             LEFT JOIN commerciale__commande as c on ".$jointureCommande." = c.id
  4718.                             LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  4719.                             LEFT JOIN client__client as u on u.id = c.client_id
  4720.                             LEFT JOIN article__article as ar on ar.id = ac.article_id
  4721.                             ".$join."
  4722.                             WHERE
  4723.                             ac.article_id IN (".$inArticle.")
  4724.                             AND
  4725.                             ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4726.                             AND
  4727.                             (
  4728.                             (  (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25 AND (c.facture_id is NOT NULL and f.statut_commande_id != 23))
  4729.                                 OR
  4730.                                 ((c.type_document_commercial_id = ".TypeDocumentCommercial::FACTURE." AND c.statut_commande_id != 23) )
  4731.                                 OR
  4732.                                 (c.type_document_commercial_id = ".TypeDocumentCommercial::AVOIR." AND c.statut_commande_id != 19))
  4733.                             )
  4734.                             ".$where."
  4735.                         ";
  4736.                 //echo $sql."<br/><br/>";
  4737.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  4738.                 $retour $stmt->executeQuery()->fetchAllAssociative();
  4739.                 //echo "<div>TOTAL ".count($retour)."</div>";
  4740.                 if (count($retour) > 0) {
  4741.                     for ($i 0$i count($retour); $i++) {
  4742.                         $sql_mvt_prec 'SELECT mv.cpump,mv.stock,mv.annexe,mv.id,mv.stock as stockMvt,mv.quantite,mv.date_mouvement,mv.cpump,mv.prix_achat as prixAchat,rm.action,rm.id as raison_id
  4743.                                     FROM `article__mouvement_stock` as mv
  4744.                                     LEFT JOIN article__raison_mouvement_stock rm on rm.id = mv.raison_mouvement_stock_id
  4745.                                     where mv.id_import is null
  4746.                                     and mv.date_mouvement <= "'.$retour[$i]["date_mouvement"].'"
  4747.                                     and mv.id < CASE WHEN mv.date_mouvement = "'.$retour[$i]["date_mouvement"].'" THEN '.$retour[$i]["id"].' ELSE 1000000000000000000000000000000 END
  4748.                                     and mv.article_id = '.$article->getId()."
  4749.                                     ORDER BY mv.date_mouvement DESC,id desc
  4750.                                     LIMIT 0,1";
  4751.                         //$output->writeln($sql_mvt_prec);
  4752.                         $mouvement_prec     "";
  4753.                         $stmt_mvt_prec      $this->entityManager->getConnection()->executeQuery($sql_mvt_prec);
  4754.                         $mouvement_prec_tab $stmt_mvt_prec->fetchAllAssociative();
  4755.                         if (count($mouvement_prec_tab) > 0) {
  4756.                             $mouvement_prec $mouvement_prec_tab[0];
  4757.                         }
  4758.                         if ($retour[$i]["cpump"] <= 0) {
  4759.                             //echo "<div>PUMP PAS OK</div>";
  4760.                             $condHa $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  4761.                             if (is_object($condHa)) {
  4762.                                 //echo "<div>CONDHA OK</div>";
  4763.                                 $prix $condHa->getPrixAchatNet();
  4764.                                 if ($condHa->getCoefficientConditionnement() != 0) {
  4765.                                     $prix $prix $condHa->getCoefficientConditionnement();
  4766.                                 }
  4767.                                 $tauxChange  1;
  4768.                                 $fournisseur $condHa->getFournisseur();
  4769.                                 if (is_object($fournisseur)) {
  4770.                                     $devise $fournisseur->getDevise();
  4771.                                 }
  4772.                                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  4773.                                     $tauxChange $devise->getTauxChange();
  4774.                                 }
  4775.                                 $prix $prix $tauxChange//prix d'achat brut converti en euros
  4776.                                 $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  4777.                                 $somme_marge += $marge_tmp;
  4778.                                 //echo "<div>A quantite ".$retour[$i]["quantite"]."</div>";
  4779.                                 //echo "<div>A prix_achat ".$retour[$i]["prix_achat"]."</div>";
  4780.                                 //echo "<div>A cpump ".$retour[$i]["cpump"]." ou ==> ".$prix."</div>";
  4781.                                 //echo "<div><b>A  marge_tmp ".$marge_tmp."</b></div>";
  4782.                                 //echo "<div>A somme_marge ".$somme_marge."<br/><br/></div>";
  4783.                             } else {
  4784.                                 $condHa $repo_condha->findOneBy(["article" => $article]);
  4785.                                 if (is_object($condHa)) {
  4786.                                     //echo "<div>CONDHA OK</div>";
  4787.                                     $prix $condHa->getPrixAchatNet();
  4788.                                     if ($condHa->getCoefficientConditionnement() != 0) {
  4789.                                         $prix $prix $condHa->getCoefficientConditionnement();
  4790.                                     }
  4791.                                     $tauxChange  1;
  4792.                                     $fournisseur $condHa->getFournisseur();
  4793.                                     if (is_object($fournisseur)) {
  4794.                                         $devise $fournisseur->getDevise();
  4795.                                     }
  4796.                                     if (is_object($devise) && $devise->getTauxChange() != 0) {
  4797.                                         $tauxChange $devise->getTauxChange();
  4798.                                     }
  4799.                                     $prix $prix $tauxChange//prix d'achat brut converti en euros
  4800.                                     $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  4801.                                     $somme_marge += $marge_tmp;
  4802.                                     //echo "<div>B quantite ".$retour[$i]["quantite"]."</div>";
  4803.                                     //echo "<div>B prix_achat ".$retour[$i]["prix_achat"]."</div>";
  4804.                                     //echo "<div>B cpump ".$retour[$i]["cpump"]." ou ==> ".$prix."</div>";
  4805.                                     //echo "<div><b>B  marge_tmp ".$marge_tmp."</b></div>";
  4806.                                     //echo "<div>B somme_marge ".$somme_marge."<br/><br/></div>";
  4807.                                 }
  4808.                             }
  4809.                         } else {
  4810.                             $marge_tmp "";
  4811.                             //echo "<div>PUMP OK</div>";
  4812.                             if (is_array($mouvement_prec) && array_key_exists('cpump'$mouvement_prec)) {
  4813.                                 // echo "OK";
  4814.                                 $marge_tmp = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $mouvement_prec["cpump"]);
  4815.                             } else {
  4816.                                 $marge_tmp = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $retour[$i]["cpump"]);
  4817.                             }
  4818.                             //echo "<div>marge_tmp ".$marge_tmp."</div>";
  4819.                             $somme_marge += $marge_tmp;
  4820.                             //echo "<div>quantite ".$retour[$i]["quantite"]."</div>";
  4821.                             //echo "<div>prix_achat ".$retour[$i]["prix_achat"]."</div>";
  4822.                             //echo "<div>cpump ".$retour[$i]["cpump"]."</div>";
  4823.                             //echo "<div><b>marge_tmp ".$marge_tmp."</b></div>";
  4824.                             //echo "<div>somme_marge ".$somme_marge."<br/><br/></div>";
  4825.                         }
  4826.                         $somme_ca  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  4827.                         $somme_qte += $retour[$i]["quantite"];
  4828.                         //echo "<div>somme_qte ".$somme_qte."</div>";
  4829.                         //echo "<div>somme_ca ".$somme_ca."</div>";
  4830.                         //echo "<div>somme_marge ".$somme_marge."</div>";
  4831.                         //echo "<div>--------------------------------------------</div>";
  4832.                     }
  4833.                 }
  4834.                 //echo "<div>inArticle : ".$inArticle."</div>";
  4835.             }
  4836.             //$retourCa = $this->calculStatsSql($sql);
  4837.             //echo "<div>XXXXsomme_marge ".$somme_marge."<br/><br/></div>";
  4838.             $somme_ca_bl $somme_ca $somme_bl;
  4839.             //echo "<div>CA FINAL ".$somme_ca_bl."</div>";
  4840.             $margePourcent "0";
  4841.             if ($somme_ca_bl 0) {
  4842.                 $margePourcent round($somme_marge 100 $somme_ca_bl2);
  4843.             }
  4844.             $valeurs["quantite"]      = $somme_qte;
  4845.             $valeurs["ca"]            = $somme_ca;
  4846.             $valeurs["bl"]            = $somme_bl;
  4847.             $valeurs["marge"]         = $somme_marge;
  4848.             $valeurs["margePourcent"] = $margePourcent;
  4849.             //print_r($valeurs);
  4850.             //echo "<br/><br/>";
  4851.             return $valeurs;
  4852.         }
  4853.     }
  4854.     public function ____getStatsArticle($id$date_debut ""$date_fin ""$integreBl false)
  4855.     {
  4856.         $article        $this->entityManager->getRepository(Article::class)->find($id);
  4857.         $repo_condha    $this->entityManager->getRepository(ConditionAchat::class);
  4858.         $repo_mouvement $this->entityManager->getRepository(MouvementStock::class);
  4859.         $valeurs                  = [];
  4860.         $valeurs["reference"]     = $article->getReference();
  4861.         $valeurs["libelle"]       = $article->getLibelle();
  4862.         $valeurs["quantite"]      = "";
  4863.         $valeurs["ca"]            = "";
  4864.         $valeurs["bl"]            = "";
  4865.         $valeurs["marge"]         = "";
  4866.         $valeurs["margePourcent"] = "";
  4867.         $somme_marge 0;
  4868.         $somme_ca    0;
  4869.         $somme_bl    0;
  4870.         $somme_qte   0;
  4871.         //echo "<div>TYPE : ".$type."</div>";
  4872.         $inArticle        $id;
  4873.         $jointureCommande "ac.commande_id";
  4874.         if (is_object($article)) {
  4875.             //echo "test";
  4876.             if (is_object($article) && $article->getVirtuel() == true && $article->getProduitInterne() == true) {
  4877.                 //echo "<div>COMPOSE</div>";
  4878.                 $composants    $article->getArticlesComposants();
  4879.                 $nb_composants count($composants);
  4880.                 if (count($composants) > 0) {
  4881.                     $tabPumCompose        = [];
  4882.                     $tabArticleComposants = [];
  4883.                     $inArticle            .= ",";
  4884.                     $jointureCommande     "ac.commande_id";
  4885.                     foreach ($composants as $c) {
  4886.                         $inArticle .= $c->getArticle()->getId().",";
  4887.                     }
  4888.                     $inArticle trim($inArticle",");
  4889.                     if ($integreBl) {
  4890.                         //POUR LES BL
  4891.                         $sql "
  4892.                         SELECT
  4893.                         ac.prix_achat,
  4894.                         ac.quantite,
  4895.                         ac.id,
  4896.                         ac.date_mouvement,
  4897.                         ac.stock as stock,
  4898.                         ac.cpump as cpump,
  4899.                         ac.article_id as articleId
  4900.                         FROM `article__mouvement_stock` as ac
  4901.                         LEFT JOIN commerciale__commande as c on ac.commande_id = c.id
  4902.                         LEFT JOIN commerciale__commande as cvirt on ac.commande_virtuel_id = cvirt.id
  4903.                         LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  4904.                         LEFT JOIN commerciale__commande as fvirt on cvirt.facture_id = fvirt.id
  4905.                         LEFT JOIN client__client as u on u.id = c.client_id
  4906.                         LEFT JOIN article__article as ar on ar.id = ac.article_id
  4907.                         WHERE
  4908.                         ac.article_id IN (".$inArticle.")
  4909.                         AND
  4910.                         ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  4911.                         AND
  4912.                         (
  4913.                             (
  4914.                                 (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25)
  4915.                                 OR
  4916.                                 (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND cvirt.statut_commande_id != 25 and ac.commande_virtuel_id is not null)
  4917.                             )
  4918.                         )
  4919.                         AND
  4920.                         (
  4921.                             (c.facture_id is NULL or f.statut_commande_id = 23)
  4922.                             OR
  4923.                             ((cvirt.facture_id is NULL or fvirt.statut_commande_id = 23) and ac.commande_virtuel_id is not null)
  4924.                         )
  4925.                         ";
  4926.                         //echo $sql;
  4927.                         $stmt $this->entityManager->getConnection()->prepare($sql);
  4928.                         $retour $stmt->executeQuery()->fetchAllAssociative();
  4929.                         if (count($retour) > 0) {
  4930.                             $quantite_vente 0;
  4931.                             $prix_vente     0;
  4932.                             $cpump_compose  0;
  4933.                             for ($i 0$i count($retour); $i++) {
  4934.                                 //echo "<div><br/>AAAA ===> ".$retour[$i]["articleId"]."</div>";
  4935.                                 if ($retour[$i]["articleId"] == $id) {
  4936.                                     //   echo "<div>RRRRR ===> ".$retour[$i]["articleId"]."</div>";
  4937.                                     $quantite_vente += $retour[$i]["quantite"];
  4938.                                     $prix_vente     $retour[$i]["prix_achat"];
  4939.                                     $somme_qte += $retour[$i]["quantite"];
  4940.                                     $somme_bl  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  4941.                                 } else {
  4942.                                     //echo "<div>WWWW ===> ".$retour[$i]["articleId"]."</div>";
  4943.                                     if ($retour[$i]["stock"] <= or $retour[$i]["cpump"] <= 0) {
  4944.                                         //echo "<div>PUMP PAS OK</div>";
  4945.                                         $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"], "defaut" => 1]);
  4946.                                         if (is_object($condHa)) {
  4947.                                             //echo "<div>CONDHA OK</div>";
  4948.                                             $prix $condHa->getPrixAchatNet();
  4949.                                             if ($condHa->getCoefficientConditionnement() != 0) {
  4950.                                                 $prix $prix $condHa->getCoefficientConditionnement();
  4951.                                             }
  4952.                                             $tauxChange  1;
  4953.                                             $fournisseur $condHa->getFournisseur();
  4954.                                             if (is_object($fournisseur)) {
  4955.                                                 $devise $fournisseur->getDevise();
  4956.                                             }
  4957.                                             if (is_object($devise) && $devise->getTauxChange() != 0) {
  4958.                                                 $tauxChange $devise->getTauxChange();
  4959.                                             }
  4960.                                             $prix          $prix $tauxChange//prix d'achat brut converti en euros
  4961.                                             $cpump_compose $prix;
  4962.                                             //echo "<div>PRIX CHA: ".$prix."</div>";
  4963.                                         } else {
  4964.                                             $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"]]);
  4965.                                             if (is_object($condHa)) {
  4966.                                                 //echo "<div>CONDHA PAS OK</div>";
  4967.                                                 $prix $condHa->getPrixAchatNet();
  4968.                                                 if ($condHa->getCoefficientConditionnement() != 0) {
  4969.                                                     $prix $prix $condHa->getCoefficientConditionnement();
  4970.                                                 }
  4971.                                                 $tauxChange  1;
  4972.                                                 $fournisseur $condHa->getFournisseur();
  4973.                                                 if (is_object($fournisseur)) {
  4974.                                                     $devise $fournisseur->getDevise();
  4975.                                                 }
  4976.                                                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  4977.                                                     $tauxChange $devise->getTauxChange();
  4978.                                                 }
  4979.                                                 $prix          $prix $tauxChange//prix d'achat brut converti en euros
  4980.                                                 $cpump_compose $prix;
  4981.                                             }
  4982.                                         }
  4983.                                     } else {
  4984.                                         //echo "<div>PUMP OK</div>";
  4985.                                         $cpump_compose $retour[0]["cpump"];
  4986.                                     }
  4987.                                     if (array_key_exists($retour[$i]["articleId"], $tabPumCompose)) {
  4988.                                         $tabPumCompose[$retour[$i]["articleId"]]["quantite"] += $retour[$i]["quantite"];
  4989.                                         $tabPumCompose[$retour[$i]["articleId"]]["cump"]     += $cpump_compose $retour[$i]["quantite"];
  4990.                                     } else {
  4991.                                         $tabPumCompose[$retour[$i]["articleId"]] = ["quantite" => $retour[$i]["quantite"], "cump" => $cpump_compose $retour[$i]["quantite"]];
  4992.                                     }
  4993.                                 }
  4994.                             }
  4995.                             $cpump_compose 0;
  4996.                             if (count($tabPumCompose) > 0) {
  4997.                                 foreach ($tabPumCompose as $key => $value) {
  4998.                                     if ($value["quantite"] != 0) {
  4999.                                         $cpump_compose += $value["cump"] / $value["quantite"];
  5000.                                     }
  5001.                                 }
  5002.                             }
  5003.                             //print_r($tabPumCompose);
  5004.                             $marge_tmp   = ($quantite_vente $prix_vente) - ($quantite_vente $cpump_compose);
  5005.                             $somme_marge += $marge_tmp;
  5006.                             //echo "<div>X Q(".$quantite_vente.")</div>";
  5007.                             //echo "<div>X PV(".$prix_vente.")</div>";
  5008.                             //echo "<div>X PUMP(".$cpump_compose.")</div><br/><br/>";
  5009.                         }
  5010.                     }
  5011.                     //echo "<div>SOMME BL ".$somme_bl."</div>";
  5012.                     //print_r($tabPumCompose);
  5013.                     $sql "
  5014.                             SELECT
  5015.                             ac.id,
  5016.                             ac.prix_achat,
  5017.                             ac.date_mouvement,
  5018.                             ac.stock as stock,
  5019.                             ac.quantite,
  5020.                             ac.cpump as cpump,
  5021.                             ac.article_id as articleId
  5022.                             FROM `article__mouvement_stock` as ac
  5023.                             LEFT JOIN commerciale__commande as c on ac.commande_id = c.id
  5024.                             LEFT JOIN commerciale__commande as cvirt on ac.commande_virtuel_id = cvirt.id
  5025.                             LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  5026.                             LEFT JOIN commerciale__commande as fvirt on cvirt.facture_id = fvirt.id
  5027.                             LEFT JOIN client__client as u on u.id = c.client_id
  5028.                             LEFT JOIN article__article as ar on ar.id = ac.article_id
  5029.                             WHERE
  5030.                             ac.article_id IN (".$inArticle.")
  5031.                             AND
  5032.                             ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  5033.                             AND
  5034.                             (
  5035.                             (
  5036.                                 (
  5037.                                     (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25 AND (c.facture_id is NOT NULL and f.statut_commande_id != 23))
  5038.                                     OR
  5039.                                     (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND cvirt.statut_commande_id != 25 AND (cvirt.facture_id is NOT NULL and fvirt.statut_commande_id != 23) and ac.commande_virtuel_id is not null)
  5040.                                 )
  5041.                                 OR
  5042.                                 (
  5043.                                     (c.type_document_commercial_id = ".TypeDocumentCommercial::FACTURE." AND c.statut_commande_id != 23)
  5044.                                     OR
  5045.                                     (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::FACTURE." AND cvirt.statut_commande_id != 23 and ac.commande_virtuel_id is not null)
  5046.                                 )
  5047.                                 OR
  5048.                                 (
  5049.                                     (c.type_document_commercial_id = ".TypeDocumentCommercial::AVOIR." AND c.statut_commande_id != 19)
  5050.                                     OR
  5051.                                     (cvirt.type_document_commercial_id = ".TypeDocumentCommercial::AVOIR." AND cvirt.statut_commande_id != 19 and ac.commande_virtuel_id is not null)
  5052.                                 )
  5053.                             )
  5054.                             )
  5055.                         ";
  5056.                     //echo $sql;
  5057.                     $stmt $this->entityManager->getConnection()->prepare($sql);
  5058.                     $retour $stmt->executeQuery()->fetchAllAssociative();
  5059.                     if (count($retour) > 0) {
  5060.                         $quantite_vente 0;
  5061.                         $prix_vente     0;
  5062.                         $cpump_compose  0;
  5063.                         for ($i 0$i count($retour); $i++) {
  5064.                             if ($retour[$i]["articleId"] == $id) {
  5065.                                 $quantite_vente += $retour[$i]["quantite"];
  5066.                                 $prix_vente     $retour[$i]["prix_achat"];
  5067.                                 $somme_qte += $retour[$i]["quantite"];
  5068.                                 $somme_ca  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  5069.                             } else {
  5070.                                 if ($retour[$i]["stock"] <= or $retour[$i]["cpump"] <= 0) {
  5071.                                     //echo "<div>PUMP PAS OK</div>";
  5072.                                     $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"], "defaut" => 1]);
  5073.                                     if (is_object($condHa)) {
  5074.                                         $prix $condHa->getPrixAchatNet();
  5075.                                         if ($condHa->getCoefficientConditionnement() != 0) {
  5076.                                             $prix $prix $condHa->getCoefficientConditionnement();
  5077.                                         }
  5078.                                         $tauxChange  1;
  5079.                                         $fournisseur $condHa->getFournisseur();
  5080.                                         if (is_object($fournisseur)) {
  5081.                                             $devise $fournisseur->getDevise();
  5082.                                         }
  5083.                                         if (is_object($devise) && $devise->getTauxChange() != 0) {
  5084.                                             $tauxChange $devise->getTauxChange();
  5085.                                         }
  5086.                                         $prix $prix $tauxChange//prix d'achat brut converti en euros
  5087.                                         $cpump_compose $prix;
  5088.                                     } else {
  5089.                                         $condHa $repo_condha->findOneBy(["article" => $retour[$i]["articleId"]]);
  5090.                                         if (is_object($condHa)) {
  5091.                                             //echo "<div>CONDHA OK</div>";
  5092.                                             $prix $condHa->getPrixAchatNet();
  5093.                                             if ($condHa->getCoefficientConditionnement() != 0) {
  5094.                                                 $prix $prix $condHa->getCoefficientConditionnement();
  5095.                                             }
  5096.                                             $tauxChange  1;
  5097.                                             $fournisseur $condHa->getFournisseur();
  5098.                                             if (is_object($fournisseur)) {
  5099.                                                 $devise $fournisseur->getDevise();
  5100.                                             }
  5101.                                             if (is_object($devise) && $devise->getTauxChange() != 0) {
  5102.                                                 $tauxChange $devise->getTauxChange();
  5103.                                             }
  5104.                                             $prix          $prix $tauxChange//prix d'achat brut converti en euros
  5105.                                             $cpump_compose $prix;
  5106.                                         }
  5107.                                     }
  5108.                                 } else {
  5109.                                     //echo "<div>PUMP OK</div>";
  5110.                                     $cpump_compose $retour[0]["cpump"];
  5111.                                 }
  5112.                                 if (array_key_exists($retour[$i]["articleId"], $tabPumCompose)) {
  5113.                                     $tabPumCompose[$retour[$i]["articleId"]]["quantite"] += 1;
  5114.                                     $tabPumCompose[$retour[$i]["articleId"]]["cump"]     += $cpump_compose;
  5115.                                 } else {
  5116.                                     $tabPumCompose[$retour[$i]["articleId"]] = ["quantite" => 1"cump" => $cpump_compose];
  5117.                                 }
  5118.                             }
  5119.                         }
  5120.                         $cpump_compose 0;
  5121.                         if (count($tabPumCompose) > 0) {
  5122.                             foreach ($tabPumCompose as $key => $value) {
  5123.                                 if ($value["quantite"] != 0) {
  5124.                                     $cpump_compose += $value["cump"] / $value["quantite"];
  5125.                                 }
  5126.                             }
  5127.                         }
  5128.                         //print_r($tabPumCompose);
  5129.                         $marge_tmp   = ($quantite_vente $prix_vente) - ($quantite_vente $cpump_compose);
  5130.                         $somme_marge += $marge_tmp;
  5131.                         //echo "<div>Z Q(".$quantite_vente.")</div>";
  5132.                         //echo "<div>Z PV(".$prix_vente.")</div>";
  5133.                         //echo "<div>Z PUMP(".$cpump_compose.")</div><br/><br/>";
  5134.                     }
  5135.                 }
  5136.             } else {
  5137.                 if ($integreBl) {
  5138.                     //POUR LES BL
  5139.                     $sql "
  5140.                         SELECT
  5141.                         ac.prix_achat,
  5142.                         ac.quantite,
  5143.                         ac.id,
  5144.                         ac.date_mouvement,
  5145.                         ac.stock as stock,
  5146.                         ac.cpump as cpump
  5147.                         FROM `article__mouvement_stock` as ac
  5148.                         LEFT JOIN commerciale__commande as c on ".$jointureCommande." = c.id
  5149.                         LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  5150.                         LEFT JOIN client__client as u on u.id = c.client_id
  5151.                         LEFT JOIN article__article as ar on ar.id = ac.article_id
  5152.                         WHERE
  5153.                         ac.article_id IN (".$inArticle.")
  5154.                         AND
  5155.                         ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  5156.                         AND
  5157.                         (
  5158.                         ( (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25))
  5159.                         )
  5160.                         AND (c.facture_id is NULL or f.statut_commande_id = 23)
  5161.                         ";
  5162.                     //echo "<div>SQL BL ".$sql."</div>";
  5163.                     $stmt $this->entityManager->getConnection()->prepare($sql);
  5164.                     $retour $stmt->executeQuery()->fetchAllAssociative();
  5165.                     if (count($retour) > 0) {
  5166.                         for ($i 0$i count($retour); $i++) {
  5167.                             if ($retour[$i]["stock"] <= or $retour[$i]["cpump"] <= 0) {
  5168.                                 //echo "<div>PUMP PAS OK</div>";
  5169.                                 $condHa $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  5170.                                 if (is_object($condHa)) {
  5171.                                     //echo "<div>CONDHA OK</div>";
  5172.                                     $prix $condHa->getPrixAchatNet();
  5173.                                     if ($condHa->getCoefficientConditionnement() != 0) {
  5174.                                         $prix $prix $condHa->getCoefficientConditionnement();
  5175.                                     }
  5176.                                     $tauxChange  1;
  5177.                                     $fournisseur $condHa->getFournisseur();
  5178.                                     if (is_object($fournisseur)) {
  5179.                                         $devise $fournisseur->getDevise();
  5180.                                     }
  5181.                                     if (is_object($devise) && $devise->getTauxChange() != 0) {
  5182.                                         $tauxChange $devise->getTauxChange();
  5183.                                     }
  5184.                                     $prix $prix $tauxChange//prix d'achat brut converti en euros
  5185.                                     $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  5186.                                     $somme_marge += $marge_tmp;
  5187.                                 } else {
  5188.                                     $condHa $repo_condha->findOneBy(["article" => $article]);
  5189.                                     if (is_object($condHa)) {
  5190.                                         //echo "<div>CONDHA OK</div>";
  5191.                                         $prix $condHa->getPrixAchatNet();
  5192.                                         if ($condHa->getCoefficientConditionnement() != 0) {
  5193.                                             $prix $prix $condHa->getCoefficientConditionnement();
  5194.                                         }
  5195.                                         $tauxChange  1;
  5196.                                         $fournisseur $condHa->getFournisseur();
  5197.                                         if (is_object($fournisseur)) {
  5198.                                             $devise $fournisseur->getDevise();
  5199.                                         }
  5200.                                         if (is_object($devise) && $devise->getTauxChange() != 0) {
  5201.                                             $tauxChange $devise->getTauxChange();
  5202.                                         }
  5203.                                         $prix $prix $tauxChange//prix d'achat brut converti en euros
  5204.                                         $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  5205.                                         $somme_marge += $marge_tmp;
  5206.                                     }
  5207.                                 }
  5208.                             } else {
  5209.                                 //echo "<div>PUMP OK</div>";
  5210.                                 $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $retour[0]["cpump"]);
  5211.                                 $somme_marge += $marge_tmp;
  5212.                             }
  5213.                             $somme_bl  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  5214.                             $somme_qte += $retour[$i]["quantite"];
  5215.                         }
  5216.                     }
  5217.                 }
  5218.                 //$retourBl = $this->calculStatsSql($sql);
  5219.                 $sql "
  5220.                             SELECT
  5221.                             ac.id,
  5222.                             ac.prix_achat,
  5223.                             ac.date_mouvement,
  5224.                             ac.stock as stock,
  5225.                             ac.quantite,
  5226.                             ac.cpump as cpump
  5227.                             FROM `article__mouvement_stock` as ac
  5228.                             LEFT JOIN commerciale__commande as c on ".$jointureCommande." = c.id
  5229.                             LEFT JOIN commerciale__commande as f on c.facture_id = f.id
  5230.                             LEFT JOIN client__client as u on u.id = c.client_id
  5231.                             LEFT JOIN article__article as ar on ar.id = ac.article_id
  5232.                             WHERE
  5233.                             ac.article_id IN (".$inArticle.")
  5234.                             AND
  5235.                             ac.date_mouvement >= '".$date_debut->format('Y-m-d H:i:s')."' AND ac.date_mouvement <= '".$date_fin->format('Y-m-d H:i:s')."'
  5236.                             AND
  5237.                             (
  5238.                             (  (c.type_document_commercial_id = ".TypeDocumentCommercial::BL." AND c.statut_commande_id != 25 AND (c.facture_id is NOT NULL and f.statut_commande_id != 23))
  5239.                                 OR
  5240.                                 ((c.type_document_commercial_id = ".TypeDocumentCommercial::FACTURE." AND c.statut_commande_id != 23) )
  5241.                                 OR
  5242.                                 (c.type_document_commercial_id = ".TypeDocumentCommercial::AVOIR." AND c.statut_commande_id != 19))
  5243.                             )
  5244.                         ";
  5245.                 $stmt $this->entityManager->getConnection()->prepare($sql);
  5246.                 $retour $stmt->executeQuery()->fetchAllAssociative();
  5247.                 if (count($retour) > 0) {
  5248.                     for ($i 0$i count($retour); $i++) {
  5249.                         if ($retour[$i]["cpump"] <= 0) {
  5250.                             //echo "<div>PUMP PAS OK</div>";
  5251.                             $condHa $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  5252.                             if (is_object($condHa)) {
  5253.                                 //echo "<div>CONDHA OK</div>";
  5254.                                 $prix $condHa->getPrixAchatNet();
  5255.                                 if ($condHa->getCoefficientConditionnement() != 0) {
  5256.                                     $prix $prix $condHa->getCoefficientConditionnement();
  5257.                                 }
  5258.                                 $tauxChange  1;
  5259.                                 $fournisseur $condHa->getFournisseur();
  5260.                                 if (is_object($fournisseur)) {
  5261.                                     $devise $fournisseur->getDevise();
  5262.                                 }
  5263.                                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  5264.                                     $tauxChange $devise->getTauxChange();
  5265.                                 }
  5266.                                 $prix $prix $tauxChange//prix d'achat brut converti en euros
  5267.                                 $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  5268.                                 $somme_marge += $marge_tmp;
  5269.                                 //echo "<div>A quantite ".$retour[$i]["quantite"]."</div>";
  5270.                                 //echo "<div>A prix_achat ".$retour[$i]["prix_achat"]."</div>";
  5271.                                 //echo "<div>A cpump ".$retour[$i]["cpump"]." ou ==> ".$prix."</div>";
  5272.                                 //echo "<div><b>A  marge_tmp ".$marge_tmp."</b></div>";
  5273.                                 //echo "<div>A somme_marge ".$somme_marge."<br/><br/></div>";
  5274.                             } else {
  5275.                                 $condHa $repo_condha->findOneBy(["article" => $article]);
  5276.                                 if (is_object($condHa)) {
  5277.                                     //echo "<div>CONDHA OK</div>";
  5278.                                     $prix $condHa->getPrixAchatNet();
  5279.                                     if ($condHa->getCoefficientConditionnement() != 0) {
  5280.                                         $prix $prix $condHa->getCoefficientConditionnement();
  5281.                                     }
  5282.                                     $tauxChange  1;
  5283.                                     $fournisseur $condHa->getFournisseur();
  5284.                                     if (is_object($fournisseur)) {
  5285.                                         $devise $fournisseur->getDevise();
  5286.                                     }
  5287.                                     if (is_object($devise) && $devise->getTauxChange() != 0) {
  5288.                                         $tauxChange $devise->getTauxChange();
  5289.                                     }
  5290.                                     $prix $prix $tauxChange//prix d'achat brut converti en euros
  5291.                                     $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $prix);
  5292.                                     $somme_marge += $marge_tmp;
  5293.                                     //echo "<div>B quantite ".$retour[$i]["quantite"]."</div>";
  5294.                                     //echo "<div>B prix_achat ".$retour[$i]["prix_achat"]."</div>";
  5295.                                     //echo "<div>B cpump ".$retour[$i]["cpump"]." ou ==> ".$prix."</div>";
  5296.                                     //echo "<div><b>B  marge_tmp ".$marge_tmp."</b></div>";
  5297.                                     //echo "<div>B somme_marge ".$somme_marge."<br/><br/></div>";
  5298.                                 }
  5299.                             }
  5300.                         } else {
  5301.                             $marge_tmp "";
  5302.                             //echo "<div>PUMP OK</div>";
  5303.                             $marge_tmp   = ($retour[$i]["quantite"] * $retour[$i]["prix_achat"]) - ($retour[$i]["quantite"] * $retour[$i]["cpump"]);
  5304.                             $somme_marge += $marge_tmp;
  5305.                             //echo "<div>quantite ".$retour[$i]["quantite"]."</div>";
  5306.                             //echo "<div>prix_achat ".$retour[$i]["prix_achat"]."</div>";
  5307.                             //echo "<div>cpump ".$retour[$i]["cpump"]."</div>";
  5308.                             //echo "<div><b>marge_tmp ".$marge_tmp."</b></div>";
  5309.                             //echo "<div>somme_marge ".$somme_marge."<br/><br/></div>";
  5310.                         }
  5311.                         $somme_ca  += $retour[$i]["quantite"] * $retour[$i]["prix_achat"];
  5312.                         $somme_qte += $retour[$i]["quantite"];
  5313.                     }
  5314.                 }
  5315.                 //echo "<div>inArticle : ".$inArticle."</div>";
  5316.             }
  5317.             //$retourCa = $this->calculStatsSql($sql);
  5318.             //echo "<div>XXXXsomme_marge ".$somme_marge."<br/><br/></div>";
  5319.             $somme_ca_bl $somme_ca $somme_bl;
  5320.             //echo "<div>CA FINAL ".$somme_ca_bl."</div>";
  5321.             $margePourcent "0";
  5322.             if ($somme_ca_bl 0) {
  5323.                 $margePourcent round($somme_marge 100 $somme_ca_bl2);
  5324.             }
  5325.             $valeurs["quantite"]      = $somme_qte;
  5326.             $valeurs["ca"]            = $somme_ca;
  5327.             $valeurs["bl"]            = $somme_bl;
  5328.             $valeurs["marge"]         = $somme_marge;
  5329.             $valeurs["margePourcent"] = $margePourcent;
  5330.             return $valeurs;
  5331.         }
  5332.     }
  5333.     public function calculStatsSql($sql "")
  5334.     {
  5335.         $valeur             = [];
  5336.         $compteur_mouvement 0;
  5337.         $somme_pump         0;
  5338.         $stmt               $this->entityManager->getConnection()->prepare($sql);
  5339.         $retour $stmt->executeQuery()->fetchAllAssociative();
  5340.         if (count($retour) > 0) {
  5341.             for ($i 0$i count($retour); $i++) {
  5342.                 if ($retour[$i]["stock"] <= or $retour[$i]["cpump"] <= 0) {
  5343.                     //echo "<div>PUMP PAS OK</div>";
  5344.                     $condHa $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  5345.                     if (is_object($condHa)) {
  5346.                         //echo "<div>CONDHA OK</div>";
  5347.                         $prix $condHa->getPrixAchatNet();
  5348.                         if ($condHa->getCoefficientConditionnement() != 0) {
  5349.                             $prix $prix $condHa->getCoefficientConditionnement();
  5350.                         }
  5351.                         $tauxChange  1;
  5352.                         $fournisseur $condHa->getFournisseur();
  5353.                         if (is_object($fournisseur)) {
  5354.                             $devise $fournisseur->getDevise();
  5355.                         }
  5356.                         if (is_object($devise) && $devise->getTauxChange() != 0) {
  5357.                             $tauxChange $devise->getTauxChange();
  5358.                         }
  5359.                         $prix $prix $tauxChange//prix d'achat brut converti en euros
  5360.                         $compteur_mouvement++;
  5361.                         //echo "<div>PRIX ".$prix."</div>";
  5362.                         $somme_pump $somme_pump $prix;
  5363.                     } else {
  5364.                         $condHa $repo_condha->findOneBy(["article" => $article]);
  5365.                         if (is_object($condHa)) {
  5366.                             //echo "<div>CONDHA OK</div>";
  5367.                             $prix $condHa->getPrixAchatNet();
  5368.                             if ($condHa->getCoefficientConditionnement() != 0) {
  5369.                                 $prix $prix $condHa->getCoefficientConditionnement();
  5370.                             }
  5371.                             $tauxChange  1;
  5372.                             $fournisseur $condHa->getFournisseur();
  5373.                             if (is_object($fournisseur)) {
  5374.                                 $devise $fournisseur->getDevise();
  5375.                             }
  5376.                             if (is_object($devise) && $devise->getTauxChange() != 0) {
  5377.                                 $tauxChange $devise->getTauxChange();
  5378.                             }
  5379.                             $prix $prix $tauxChange//prix d'achat brut converti en euros
  5380.                             $compteur_mouvement++;
  5381.                             //echo "<div>PRIX ".$prix."</div>";
  5382.                             $somme_pump $somme_pump $prix;
  5383.                         }
  5384.                     }
  5385.                 } else {
  5386.                     //echo "<div>PUMP OK</div>";
  5387.                     $compteur_mouvement++;
  5388.                     $somme_pump $somme_pump $retour[0]["cpump"];
  5389.                 }
  5390.             }
  5391.         }
  5392.         if ($compteur_mouvement 0) {
  5393.             $somme_pump $somme_pump $compteur_mouvement;
  5394.         }
  5395.     }
  5396.     public function getQtePriorisee($ac)
  5397.     {
  5398.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  5399.         //$dispo = $ac->getArticle()->getStock();
  5400.         $bps  = [];
  5401.         $cmds = [];
  5402.         if (is_object($ac)) {
  5403.             $article $ac->getArticle();
  5404.         } else {
  5405.             $article $ac['article'];
  5406.         }
  5407.         $dispo $article->getStock();
  5408.         $date null;
  5409.         if (is_object($ac) && is_object($ac->getDatePriorisation())) {
  5410.             $date $ac->getDatePriorisation();
  5411.         }
  5412.         /*
  5413.         else if(!is_object($ac) && isset($ac['commande']) && is_object($ac['commande'])) {
  5414.             $date = $ac['commande']->getDate();
  5415.         } else if(is_object($ac)) {
  5416.             $date = $ac->getCommande()->getDate();
  5417.         } else {
  5418.             $date = NULL;
  5419.         }
  5420.          *
  5421.          */
  5422.         $qtesPriorisees $repo_article_commande->getQtesPriorisees($article$date)->getQuery()->getResult();
  5423.         if (count($qtesPriorisees) > 0) {
  5424.             foreach ($qtesPriorisees as $qtePriorisee) {
  5425.                 if (in_array($qtePriorisee->getCommande()->getTypeDocumentCommercial(), [TypeDocumentCommercial::BPTypeDocumentCommercial::BPATELIER])) {
  5426.                     $bps[] = $qtePriorisee;
  5427.                 } else {
  5428.                     $cmds[] = $qtePriorisee;
  5429.                 }
  5430.                 $dispo -= $qtePriorisee->getQuantiteDispo();
  5431.                 //echo $qtePriorisee->getCommande()->getReference().' ,';
  5432.             }
  5433.         }
  5434.         return ['dispo' => $dispo"bps" => $bps'cmds' => $cmds];
  5435.     }
  5436.     public function getPrixCondHaCompose(Article $articleCompose)
  5437.     {
  5438.         $prix 0;
  5439.         foreach ($articleCompose->getArticlesComposants() as $articleComposant) {
  5440.             $prix += $this->majCondHaComposeGetInfosComposants($articleComposant'', [], $eviterBoucleInfinie 0);
  5441.         }
  5442.         return round($prix3);
  5443.     }
  5444.     private function majCondHaComposeGetInfosComposants($articleComposant$niveau$idMaj$eviterBoucleInfinie)
  5445.     {
  5446.         if ($eviterBoucleInfinie 1000) {
  5447.             return false;
  5448.         } else {
  5449.             $eviterBoucleInfinie++;
  5450.         }
  5451.         $niveau  .= '-';
  5452.         $article $articleComposant->getArticle();
  5453.         $repo_fournisseur $this->entityManager->getRepository(Fournisseur::class);
  5454.         $fournisseur_dtc  $repo_fournisseur->findOneBy(['reference' => 12000]);
  5455.         $repo_cond_ha $this->entityManager->getRepository(ConditionAchat::class);
  5456.         if ($article->getProduitInterne() == && count($article->getArticlesComposants()) && == 0) {
  5457.             $prix 0;
  5458.             foreach ($article->getArticlesComposants() as $composant) {
  5459.                 $prixTmp $this->majCondHaComposeGetInfosComposants($composant$niveau$idMaj$eviterBoucleInfinie);
  5460.                 $prix    += floatVal($prixTmp);
  5461.             }
  5462.         } else {
  5463. //                $condHa = $repo_cond_ha->findOneBy(array("fournisseur"=>$fournisseur_dtc,"article"=>$article));
  5464. //                if(!is_object($condHa))
  5465. //                    $condHa = $repo_cond_ha->findOneBy(array("article"=>$article,"defaut"=>1));
  5466.             $condHa $repo_cond_ha->findOneBy(["article" => $article"defaut" => 1]);
  5467.             if (is_object($condHa)) {
  5468.                 $prix $condHa->getPrixAchatNet();
  5469.                 //coefficientConditionnement
  5470.                 if ($condHa->getCoefficientConditionnement() != 0) {
  5471.                     $prix $prix $condHa->getCoefficientConditionnement();
  5472.                 }
  5473.                 //devise
  5474.                 $fournisseur $condHa->getFournisseur();
  5475.                 if (is_object($fournisseur)) {
  5476.                     $devise $fournisseur->getDevise();
  5477.                     if (is_object($devise) && $devise->getTauxChange() != 0) {
  5478.                         $tauxChange $devise->getTauxChange();
  5479.                         $prix       $prix $tauxChange//prix d'achat brut converti en euros
  5480.                     }
  5481.                 }
  5482.             } else {
  5483.                 $prix $article->getPrixBase();
  5484.             }
  5485.         }
  5486.         $prix $prix $articleComposant->getQuantite();
  5487.         $prix round($prix3);
  5488.         return $prix;
  5489.     }
  5490.     public function getConditionAchatParDefaut(Article $article)
  5491.     {
  5492.         $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  5493.         $condHa      $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  5494.         return $condHa;
  5495.     }
  5496.     public function getNbNumeroSerieByArticle($articleId)
  5497.     {
  5498.         return $this->entityManager->getRepository(NumeroSerie::class)->getNbNumeroSerieByArticle($articleId);
  5499.     }
  5500.     public function nbApplicationsEnfants(Article $article$type ""$id)
  5501.     {
  5502.         $repo_applications $this->entityManager->getRepository(Application::class);
  5503.         $total             "";
  5504.         if ($type == "marque" && $id != "") {
  5505.             $total $repo_applications->totalApplicationEnfantsMarquesArticle($article$id);
  5506.         } elseif ($type == "modele" && $id != "") {
  5507.             $total $repo_applications->totalApplicationEnfantsModelesArticle($article$id);
  5508.         }
  5509.         return $total;
  5510.     }
  5511.     public function hasComposes($article)
  5512.     {
  5513.         if ( ! is_object($article)) {
  5514.             return false;
  5515.         }
  5516.         $composes $this->entityManager->getRepository(ArticleComposant::class)->findByArticle($article);
  5517.         return count($composes);
  5518.     }
  5519.     public function getTotalTache(Article $article)
  5520.     {
  5521.         $repo_note $this->entityManager->getRepository(Note::class);
  5522.         $total     $repo_note->getTotalTacheArticle($article);
  5523.         return $total['total'];
  5524.     }
  5525.     public function _____getPrixEncours(Article $article$articleCommande ''$client$reprise false$quantite ""$adresse ""$enregAuto false$round 2)
  5526.     {
  5527.         $t                  "";
  5528.         $type_compta_client "";
  5529.         if (is_object($client)) {
  5530.             if (is_object($client->getCompta())) {
  5531.                 $type_compta_client $client->getCompta()->getId();
  5532.             }
  5533.         }
  5534.         $array          = ["enPromo" => false];
  5535.         $repo_prixPromo $this->entityManager->getRepository(PrixPromo::class);
  5536.         $promos         $repo_prixPromo->getPromos($article$client);
  5537.         //echo "<div> TC (".$type_compta_client.")</div>";
  5538.         if ($type_compta_client == "2" && == 0) {
  5539.             $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  5540.             $condHa      $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  5541.             if (is_object($condHa)) {
  5542.                 $prix $condHa->getPrixAchatNet();
  5543.                 if ($condHa->getCoefficientConditionnement() != 0) {
  5544.                     $prix $prix $condHa->getCoefficientConditionnement();
  5545.                 }
  5546.                 $tauxChange  1;
  5547.                 $fournisseur $condHa->getFournisseur();
  5548.                 if (is_object($fournisseur)) {
  5549.                     $devise $fournisseur->getDevise();
  5550.                 }
  5551.                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  5552.                     $tauxChange $devise->getTauxChange();
  5553.                 }
  5554.                 $prix $prix $tauxChange//prix d'achat brut converti en euros
  5555.                 //if($condHa->getCoefficientConditionnement() > 0) $prix = $prix / $condHa->getCoefficientConditionnement();
  5556.                 $augmentation $prix 10 100;
  5557.                 $prix         $prix $augmentation;
  5558.                 $prix         round($prix$round);
  5559.             } else {
  5560.                 $prix $article->getPrixVente();
  5561.             }
  5562.         } else {
  5563.             $prix $article->getPrixVente();
  5564.         }
  5565.         //$prix = $article->getPrixVente();
  5566.         $prixArticleCommande false;
  5567.         $array['reduction'] = '';
  5568.         if (is_object($articleCommande) && ! $enregAuto) {
  5569.             //echo "BABARBUBU";
  5570.             $prix                       floatval($articleCommande->getPrixBase());
  5571.             $coefficientConditionnement $articleCommande->getCoefficientConditionnement();
  5572.             if ( ! empty($coefficientConditionnement)) {
  5573.                 $prix $prix $coefficientConditionnement;
  5574.             }
  5575.             $prix                round($prix$round);
  5576.             $prixArticleCommande true;
  5577.         } elseif ($quantite != 0) {
  5578.             $repo_cond_vente $this->entityManager->getRepository(ConditionVente::class);
  5579.             $condVente       $repo_cond_vente->findPrixParQuantite($article$quantite$client$adresse);
  5580.             if (is_object($condVente)) {
  5581.                 $prix $condVente->getPrix();
  5582.                 //echo "<div>ZZZZTUTU ".$prix."</div>";
  5583.             }
  5584.         }
  5585.         if ($reprise == true) {
  5586.             if (is_object($articleCommande)) {
  5587.                 $prix floatval($articleCommande->getPrixBase());
  5588.             } elseif ( ! empty($articleCommande['prixBase'])) {
  5589.                 $prix $articleCommande['prixBase'];
  5590.             }
  5591.             $prixArticleCommande true;
  5592.         }
  5593.         foreach ($promos as $p) {
  5594.             if ($p->getPrix() > && $p->getPrix() < $prix) {
  5595.                 if ( ! $prixArticleCommande) {
  5596.                     $array['promoId']   = $p->getId();
  5597.                     $prix               $p->getPrix();
  5598.                     $array['enPromo']   = true;
  5599.                     $array['reduction'] = '(-'.($article->getPrixVente() - $p->getPrix()).' â‚¬)';
  5600.                 }
  5601.             } elseif ($p->getReduction() > 0) {
  5602.                 if ($p->getTypeReduction() == "montant") {
  5603.                     $calculNouveauPrix $article->getPrixVente() - $p->getReduction();
  5604.                     if ($calculNouveauPrix $prix) {
  5605.                         if ( ! $prixArticleCommande) {
  5606.                             $prix               $calculNouveauPrix;
  5607.                             $array['promoId']   = $p->getId();
  5608.                             $array['enPromo']   = true;
  5609.                             $array['reduction'] = '(-'.$p->getReduction().' â‚¬)';
  5610.                         }
  5611.                     }
  5612.                 } elseif ($p->getTypeReduction() == "pourcentage") {
  5613.                     $calculNouveauPrix $article->getPrixVente() - ($article->getPrixVente() * $p->getReduction() / 100);
  5614.                     if ($calculNouveauPrix $prix) {
  5615.                         if ( ! $prixArticleCommande) {
  5616.                             $array['promoId']   = $p->getId();
  5617.                             $prix               $calculNouveauPrix;
  5618.                             $array['enPromo']   = true;
  5619.                             $array['reduction'] = '(-'.$p->getReduction().'%)';
  5620.                         }
  5621.                     }
  5622.                 }
  5623.             }
  5624.         }
  5625.         $array['prixVente'] = $article->getPrixVente();
  5626.         $array['prix']      = $prix;
  5627.         return $array;
  5628.     }
  5629.     //version cazin
  5630.     public function getPrixEncours(Article $article$articleCommande ''$client$reprise false$quantite ""$adresse ""$enregAuto false$round 2)
  5631.     {
  5632.         //echo "<div>HELLO ".$client->getId()."</div>";
  5633.         $t                  "";
  5634.         $type_compta_client "";
  5635.         /** @var Client $client */
  5636.         if (is_object($client)) {
  5637.             if (is_object($client->getCompta())) {
  5638.                 $type_compta_client $client->getCompta()->getId();
  5639.             }
  5640.         }
  5641.         //$cump = $article->getcpump
  5642.         $array          = ["enPromo" => false];
  5643.         $repo_prixPromo $this->entityManager->getRepository(PrixPromo::class);
  5644.         $repo_devise    $this->entityManager->getRepository(Devise::class);
  5645.         $promos         $repo_prixPromo->getPromos($article$client);
  5646.         $conditionVente false;
  5647.         $prixNet        0;
  5648.         $cump           $article->getCpump();
  5649.         if (is_null($cump) or $cump == 0) {
  5650.             $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  5651.             $condHa      $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  5652.             if (is_object($condHa)) {
  5653.                 $cump $condHa->getPrixAchatNet();
  5654.                 if ($condHa->getCoefficientConditionnement() != 0) {
  5655.                     $cump $cump $condHa->getCoefficientConditionnement();
  5656.                 }
  5657.                 $tauxChange  1;
  5658.                 $fournisseur $condHa->getFournisseur();
  5659.                 $devise $repo_devise->find(1);
  5660.                 if (is_object($fournisseur) and is_object($fournisseur->getDevise())) {
  5661.                     $devise $fournisseur->getDevise();
  5662.                 }
  5663.                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  5664.                     $tauxChange $devise->getTauxChange();
  5665.                 }
  5666.                 $cump $cump $tauxChange//prix d'achat brut converti en euros
  5667.                 $cump round($cump2);
  5668.             }
  5669.         }
  5670.         //Valable que pour DTC ?
  5671.         if ($type_compta_client == "2" and != 1) {
  5672.             $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  5673.             $condHa      $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  5674.             if (is_object($condHa)) {
  5675.                 $prix $condHa->getPrixAchatNet();
  5676.                 if ($condHa->getCoefficientConditionnement() != 0) {
  5677.                     $prix $prix $condHa->getCoefficientConditionnement();
  5678.                 }
  5679.                 $tauxChange  1;
  5680.                 $fournisseur $condHa->getFournisseur();
  5681.                 if (is_object($fournisseur)) {
  5682.                     $devise $fournisseur->getDevise();
  5683.                 }
  5684.                 if (is_object($devise) && $devise->getTauxChange() != 0) {
  5685.                     $tauxChange $devise->getTauxChange();
  5686.                 }
  5687.                 $prix $prix $tauxChange//prix d'achat brut converti en euros
  5688.                 //if($condHa->getCoefficientConditionnement() > 0) $prix = $prix / $condHa->getCoefficientConditionnement();
  5689.                 $augmentation $prix 10 100;
  5690.                 $prix         $prix $augmentation;
  5691.                 $prix         round($prix2);
  5692.             } else {
  5693.                 $prix $article->getPrixVente();
  5694.             }
  5695.         } else {
  5696.             $prix $article->getPrixVente();
  5697.         }
  5698.         //$prix = $article->getPrixVente();
  5699.         $prixArticleCommande false;
  5700.         $array['reduction'] = '';
  5701.         if (is_object($articleCommande) && ! $enregAuto) {
  5702.             $prix                       floatval($articleCommande->getPrixBase());
  5703.             $coefficientConditionnement $articleCommande->getCoefficientConditionnement();
  5704.             if ( ! empty($coefficientConditionnement)) {
  5705.                 $prix $prix $coefficientConditionnement;
  5706.             }
  5707.             $prix                round($prix3);
  5708.             $prixArticleCommande true;
  5709.             $repo_cond_vente $this->entityManager->getRepository(ConditionVente::class);
  5710.             $condVente       $repo_cond_vente->findPrixParQuantite($article$quantite$client$adresse);
  5711.             if (is_object($condVente)) {
  5712.                 //echo "LULU";
  5713.                 if ($prix == $condVente->getPrix()) {
  5714.                     $prixNet 1;
  5715.                 }
  5716.             } else {
  5717.                 //echo "LALA";
  5718.             }
  5719.         } elseif ($quantite != 0) {
  5720.             $repo_cond_vente $this->entityManager->getRepository(ConditionVente::class);
  5721.             $condVente       $repo_cond_vente->findPrixParQuantite($article$quantite$client$adresse);
  5722.             if (is_object($condVente)) {
  5723.                 //echo "LULU";
  5724.                 $prix $condVente->getPrix();
  5725.                 //echo "<div>ZZZZTUTU ".$prix."</div>";
  5726.                 $conditionVente true;
  5727.                 $prixNet        1;
  5728.             } else {
  5729.                 //echo "LALA";
  5730.             }
  5731.         }
  5732.         if ($reprise == true) {
  5733.             if (is_object($articleCommande)) {
  5734.                 $prix floatval($articleCommande->getPrixBase());
  5735.             } elseif ( ! empty($articleCommande['prixBase'])) {
  5736.                 $prix $articleCommande['prixBase'];
  5737.             }
  5738.             $prixArticleCommande true;
  5739.         }
  5740.         foreach ($promos as $p) {
  5741.             if ($p->getPrix() > && $p->getPrix() < $prix) {
  5742.                 if ( ! $prixArticleCommande) {
  5743.                     $array['promoId']   = $p->getId();
  5744.                     $prix               $p->getPrix();
  5745.                     $array['enPromo']   = true;
  5746.                     $array['reduction'] = '(-'.($article->getPrixVente() - $p->getPrix()).' â‚¬)';
  5747.                 }
  5748.             } elseif ($p->getReduction() > 0) {
  5749.                 if ($p->getTypeReduction() == "montant") {
  5750.                     $calculNouveauPrix $article->getPrixVente() - $p->getReduction();
  5751.                     if ($calculNouveauPrix $prix) {
  5752.                         if ( ! $prixArticleCommande) {
  5753.                             $prix               $calculNouveauPrix;
  5754.                             $array['promoId']   = $p->getId();
  5755.                             $array['enPromo']   = true;
  5756.                             $array['reduction'] = '(-'.$p->getReduction().' â‚¬)';
  5757.                         }
  5758.                     }
  5759.                 } elseif ($p->getTypeReduction() == "pourcentage") {
  5760.                     $calculNouveauPrix $article->getPrixVente() - ($article->getPrixVente() * $p->getReduction() / 100);
  5761.                     if ($calculNouveauPrix $prix) {
  5762.                         if ( ! $prixArticleCommande) {
  5763.                             $array['promoId']   = $p->getId();
  5764.                             $prix               $calculNouveauPrix;
  5765.                             $array['enPromo']   = true;
  5766.                             $array['reduction'] = '(-'.$p->getReduction().'%)';
  5767.                         }
  5768.                     }
  5769.                 }
  5770.             }
  5771.         }
  5772.         $array['prixVente']      = $article->getPrixVente();
  5773.         $array['prix']           = $prix;
  5774.         $array['cump']           = $cump;
  5775.         $array['conditionVente'] = $conditionVente;
  5776.         $array['prixNet']        = $prixNet;
  5777.         return $array;
  5778.     }
  5779.     public function getPrixEncoursConditionVente(Article $article$articleCommande ''$client$quantite ""$adresse "")
  5780.     {
  5781.         /*
  5782.         echo "<div>ART ".$article->getId()."</div>";
  5783.         echo "<div>ARTC ".$articleCommande."</div>";
  5784.         echo "<div>client ".$client."</div>";
  5785.         echo "<div>QTE ".$quantite."</div>";
  5786.         */
  5787.         //echo "<div>HELLO ".$client->getId()."</div>";
  5788.         $t "";
  5789.         if (is_object($client)) {
  5790.             //echo "A ".$client->getEmail();
  5791.         }
  5792.         $array               = ["enPromo" => false];
  5793.         $repo_prixPromo      $this->entityManager->getRepository(PrixPromo::class);
  5794.         $promos              $repo_prixPromo->getPromos($article$client);
  5795.         $prix                $article->getPrixVente();
  5796.         $prixArticleCommande false;
  5797.         $array['reduction'] = '';
  5798.         //echo "<div>quantite ".$quantite."</div>";
  5799.         if (is_object($articleCommande) and != 1) {
  5800.             $prix                $articleCommande->getPrixBase();
  5801.             $prixArticleCommande true;
  5802.         } elseif ($quantite != 0) {
  5803.             //echo "<div>ZZZZTUTU ".$prix."</div>";
  5804.             $repo_cond_vente $this->entityManager->getRepository(ConditionVente::class);
  5805.             $condVente       $repo_cond_vente->findPrixParQuantite($article$quantite$client$adresse);
  5806.             if (is_object($condVente)) {
  5807.                 //echo "PPPP";
  5808.                 $prix $condVente->getPrix();
  5809.             } else {
  5810.                 //echo "MMMMMM";
  5811.             }
  5812.         }
  5813.         //  echo "JJJJ";
  5814.         foreach ($promos as $p) {
  5815.             if ($p->getPrix() > && $p->getPrix() < $prix) {
  5816.                 //  echo "<div>PRIXPROMO ".$p->getPrix()."</div>";
  5817.                 if ( ! $prixArticleCommande) {
  5818.                     $array['promoId']   = $p->getId();
  5819.                     $prix               $p->getPrix();
  5820.                     $array['enPromo']   = true;
  5821.                     $array['reduction'] = '(-'.($article->getPrixVente() - $p->getPrix()).' â‚¬)';
  5822.                 }
  5823.             } elseif ($p->getReduction() > 0) {
  5824.                 if ($p->getTypeReduction() == "montant") {
  5825.                     $calculNouveauPrix $article->getPrixVente() - $p->getReduction();
  5826.                     if ($calculNouveauPrix $prix) {
  5827.                         if ( ! $prixArticleCommande) {
  5828.                             $prix               $calculNouveauPrix;
  5829.                             $array['promoId']   = $p->getId();
  5830.                             $array['enPromo']   = true;
  5831.                             $array['reduction'] = '(-'.$p->getReduction().' â‚¬)';
  5832.                         }
  5833.                     }
  5834.                 } elseif ($p->getTypeReduction() == "pourcentage") {
  5835.                     $calculNouveauPrix $article->getPrixVente() - ($article->getPrixVente() * $p->getReduction() / 100);
  5836.                     if ($calculNouveauPrix $prix) {
  5837.                         if ( ! $prixArticleCommande) {
  5838.                             $array['promoId']   = $p->getId();
  5839.                             $prix               $calculNouveauPrix;
  5840.                             $array['enPromo']   = true;
  5841.                             $array['reduction'] = '(-'.$p->getReduction().'%)';
  5842.                         }
  5843.                     }
  5844.                 }
  5845.             }
  5846.         }
  5847.         $array['prixVente'] = $article->getPrixVente();
  5848.         $array['prix']      = $prix;
  5849.         //print_r($array);
  5850.         //exit;
  5851.         return $prix;
  5852.     }
  5853.     public function getComposants($article)
  5854.     {
  5855.         $articles           = [];
  5856.         $articlesComposants $this->entityManager->getRepository(ArticleComposant::class)->findBy(['articleCompose' => $article]);
  5857.         if (count($articlesComposants)) {
  5858.             foreach ($articlesComposants as $compo) {
  5859.                 $articles[] = $compo->getArticle();
  5860.             }
  5861.         }
  5862.         return $articles;
  5863.     }
  5864.     public function mettreAjourCompose($compose)
  5865.     {
  5866.         $poids           0;
  5867.         $ecocontribution 0;
  5868.         $prixBase        0;
  5869.         foreach ($compose->getArticlesComposants() as $composant) {
  5870.             $prixTmp       0;
  5871.             $qteConseillee $this->getQteConseillee($composant->getArticle());
  5872.             if ( ! empty($qteConseillee['condition'])) {
  5873.                 $prixTmp $qteConseillee['condition']->getPrixAchatNet();
  5874.                 if (floatval($qteConseillee['condition']->getCoefficientConditionnement()) != 0) {
  5875.                     $prixTmp $prixTmp floatval($qteConseillee['condition']->getCoefficientConditionnement());
  5876.                 }
  5877.                 if (is_object($qteConseillee['condition']->getFournisseur()) && is_object($qteConseillee['condition']->getFournisseur()->getDevise()) && floatval(
  5878.                                                                                                                                                              $qteConseillee['condition']->getFournisseur(
  5879.                                                                                                                                                              )->getDevise()->getTauxChange()
  5880.                                                                                                                                                          ) != 0) {
  5881.                     $prixTmp $prixTmp floatval($qteConseillee['condition']->getFournisseur()->getDevise()->getTauxChange());
  5882.                 }
  5883.             }
  5884.             $prixBase += $prixTmp floatVal($composant->getQuantite());
  5885.             //$output->writeln("composant ecocontribution ".$composant->getArticle()->getEcocontribution());
  5886.             $poids           += floatVal($composant->getArticle()->getPoids()) * floatVal($composant->getQuantite());
  5887.             $ecocontribution += floatVal($composant->getArticle()->getEcocontribution()) * floatVal($composant->getQuantite());
  5888.         }
  5889.         $compose->setPoids($poids);
  5890.         $compose->setEcocontribution($ecocontribution);
  5891.         $compose->setPrixBase($prixBase);
  5892.         //recalcul du coefficient
  5893.         if (floatval($compose->getPrixBase()) != && floatval($compose->getPrixVente()) != 0) {
  5894.             $coefficient floatval($compose->getPrixVente()) / floatval($compose->getPrixBase());
  5895.             $compose->setCoefficientPrixBaseVente($coefficient);
  5896.         }
  5897.         /*
  5898.         if(floatval($compose->getPrixVente()) == 0){
  5899.             $prixVente = $prixBase * floatval($compose->getCoefficientPrixBaseVente());
  5900.             $compose->setPrixVente($prixVente);
  5901.         }
  5902.         */
  5903.         return $compose;
  5904.     }
  5905.     public function getNbAnnoncesPublieesParArticleEtMarketPlace($articleId$marketPlaceId)
  5906.     {
  5907.         //return $articleId;
  5908.         $repo_article_market_place $this->entityManager->getRepository(ArticleMarketPlace::class);
  5909.         $nbAnnonces                $repo_article_market_place->getNbAnnoncesPublieesParArticleEtMarketPlace($articleId$marketPlaceId);
  5910.         return $nbAnnonces['total'];
  5911.     }
  5912.     public function getNbAnnoncesParArticleEtMarketPlace($articleId$marketPlaceId)
  5913.     {
  5914.         //return $articleId;
  5915.         $repo_article_market_place $this->entityManager->getRepository(ArticleMarketPlace::class);
  5916.         $nbAnnonces                $repo_article_market_place->getNbAnnoncesParArticleEtMarketPlace($articleId$marketPlaceId);
  5917.         return $nbAnnonces['total'];
  5918.     }
  5919.     public function getNbAnnoncesPublieesParArticleEtCompteMarketPlace($articleId$compteMarketPlaceId)
  5920.     {
  5921.         //return $articleId;
  5922.         $repo_article_market_place $this->entityManager->getRepository(ArticleMarketPlace::class);
  5923.         $nbAnnonces                $repo_article_market_place->getNbAnnoncesPublieesParArticleEtCompteMarketPlace($articleId$compteMarketPlaceId);
  5924.         return $nbAnnonces['total'];
  5925.     }
  5926.     public function getNbAnnoncesParArticleEtCompteMarketPlace($articleId$compteMarketPlaceId)
  5927.     {
  5928.         //return $articleId;
  5929.         $repo_article_market_place $this->entityManager->getRepository(ArticleMarketPlace::class);
  5930.         $nbAnnonces                $repo_article_market_place->getNbAnnoncesParArticleEtCompteMarketPlace($articleId$compteMarketPlaceId);
  5931.         return $nbAnnonces['total'];
  5932.     }
  5933.     public function getPremiereImageArticleMarketPlace($articleMarketPlace_id)
  5934.     {
  5935.         $image                           "";
  5936.         $repo_image_article_market_place $this->entityManager->getRepository(ArticleMarketPlaceImage::class);
  5937.         $repo_article_market_place       $this->entityManager->getRepository(ArticleMarketPlace::class);
  5938.         $articleMarketPlace $repo_article_market_place->find($articleMarketPlace_id);
  5939.         $imageArticleMarketPlace $this->getImagesArticleMarketPlaceOrder($articleMarketPlace);
  5940.         $images   $repo_image_article_market_place->findBy(["articleMarketPlace" => $articleMarketPlace], ["ordre" => "asc"]);
  5941.         $tabImage = [];
  5942.         $tabImg   = [];
  5943.         if (count($articleMarketPlace->getArticle()->getImages()) > 0) {
  5944.             foreach ($articleMarketPlace->getArticle()->getImages() as $photo) {
  5945.                 if (array_key_exists($photo->getId(), $imageArticleMarketPlace)) {
  5946.                     $ordre_id $imageArticleMarketPlace[$photo->getId()]["ordre"];
  5947.                     //echo "<div>ORDRE ".$ordre_id."</div>";
  5948.                     //$tabImg['0'.$ordre_id]=$photo;
  5949.                     $tabImg array_merge($tabImg, ['0'.$ordre_id => $photo]);
  5950.                 }
  5951.             }
  5952.         }
  5953.         ksort($tabImg);
  5954.         $compteur 0;
  5955.         if (count($tabImg) > 0) {
  5956.             foreach ($tabImg as $key => $value) {
  5957.                 if ($compteur == 0) {
  5958.                     return $value;
  5959.                 }
  5960.                 $compteur++;
  5961.             }
  5962.         }
  5963.         return $image;
  5964.     }
  5965.     public function getImagesArticleMarketPlaceOrder($articleMarketPlace)
  5966.     {
  5967.         $repo_image_article_market_place $this->entityManager->getRepository(ArticleMarketPlaceImage::class);
  5968.         $images                          $repo_image_article_market_place->findBy(["articleMarketPlace" => $articleMarketPlace], ["ordre" => "asc"]);
  5969.         $tableau_id = [];
  5970.         foreach ($images as $img) {
  5971.             $tableau_id[$img->getImage()->getId()] = ["id" => $img->getImage()->getId(), "ordre" => $img->getOrdre(), "articleMarketPlaceImage" => $img];
  5972.         }
  5973.         //print_r($tableau_id);
  5974.         return $tableau_id;
  5975.     }
  5976.     public function getImagesArticleMarketPlace($articleMarketPlace)
  5977.     {
  5978.         $repo_image_article_market_place $this->entityManager->getRepository(ArticleMarketPlaceImage::class);
  5979.         $images                          $repo_image_article_market_place->findBy(["articleMarketPlace" => $articleMarketPlace]);
  5980.         $tableau_id = [];
  5981.         foreach ($images as $img) {
  5982.             $tableau_id[] = $img->getImage()->getId();
  5983.         }
  5984.         return $tableau_id;
  5985.     }
  5986.     public function getReferenceDivers($article null)
  5987.     {
  5988.         $numero_reference $this->entityManager->getRepository(Article::class)->getMaxNumeroReference($article);
  5989.         $numero_reference++;
  5990.         //$numero_reference = 2896;
  5991.         $numero_reference_retour $numero_reference;
  5992.         $reference               0;
  5993.         $unite            $numero_reference 10;
  5994.         $numero_reference -= $unite;
  5995.         $reference        += $unite;
  5996.         $dizaine          $numero_reference 100;
  5997.         $numero_reference -= $dizaine;
  5998.         $reference        += $dizaine;
  5999.         $centaine         $numero_reference 1000;
  6000.         $numero_reference -= $centaine;
  6001.         $reference        += $centaine;
  6002.         //transformer les milliers en chiffres
  6003.         $lettres        '';
  6004.         $milliers       $numero_reference 1000;
  6005.         $tableauLettres range('A''Z');
  6006.         $nbLettres      floor($milliers count($tableauLettres));
  6007.         for ($i 0$i $nbLettres$i++) {
  6008.             $lettres .= 'Z';
  6009.         }
  6010.         $reste $milliers count($tableauLettres);
  6011.         $lettres .= $tableauLettres[$reste];
  6012.         /*
  6013.         while(strlen($lettres) < 2){
  6014.             $lettres = 'A'.$lettres;
  6015.         }
  6016.         */
  6017.         while (strlen($reference) < 3) {
  6018.             $reference '0'.$reference;
  6019.         }
  6020.         $reference $lettres.$reference;
  6021.         return ['numero_reference' => $numero_reference_retour'reference' => $reference];
  6022.     }
  6023.     public function getCommentaires()
  6024.     {
  6025.         return $this->entityManager->getRepository(Article::class)->findBy([
  6026.                                                                                'est_commentaire' => 1,
  6027.                                                                            ], ['reference' => 'ASC']);
  6028.     }
  6029.     public function capaciteProduction($article$count 0)
  6030.     {
  6031.         $count++;
  6032.         if ($count 100) {
  6033.             return 0;
  6034.         }
  6035.         $capacites = [];
  6036.         foreach ($article->getArticlesComposants() as $composant) {
  6037.             $articleTmp $composant->getArticle();
  6038.             if ( ! $articleTmp->getNonStocke() && ! $articleTmp->getPrestation() && ! $articleTmp->getMainOeuvre()) {
  6039.                 $dispo $articleTmp->getDispo() / $composant->getQuantite();
  6040.                 if ($articleTmp->getProduitInterne()) {
  6041.                     $dispo += $this->capaciteProduction($articleTmp$count);
  6042.                 }
  6043.                 $capacites[] = $dispo;
  6044.             }
  6045.         }
  6046.         if (count($capacites)) {
  6047.             return min($capacites);
  6048.         } else {
  6049.             return 0;
  6050.         }
  6051.     }
  6052.     public function creerHistorique($article$typeMessage$donnees = [])
  6053.     {
  6054.         $enregistrer false;
  6055.         $message     $article->getReference();
  6056.         $user "";
  6057.         if ($this->security->getUser() !== null) {
  6058.             $user $this->security->getUser();
  6059.         }
  6060.         $nbNouvellesLignes 0;
  6061.         $typesMessage = [$typeMessage];
  6062.         foreach ($typesMessage as $typeMessage) {
  6063.             switch ($typeMessage) {
  6064.                 case :
  6065.                     $titre 'Création article';
  6066.                     if (array_key_exists('message'$donnees)) {
  6067.                         $message .= ' '.$donnees['message'];
  6068.                     }
  6069.                     break;
  6070.                 default:
  6071.                     $titre '';
  6072.                     if (array_key_exists('titre'$donnees)) {
  6073.                         $titre $donnees['titre'];
  6074.                     }
  6075.                     if (array_key_exists('message'$donnees)) {
  6076.                         $message .= ' '.$donnees['message'];
  6077.                     }
  6078.                     break;
  6079.             }
  6080.             $historique = new HistoriqueArticle();
  6081.             if ( ! empty($titre)) {
  6082.                 $historique->setTitre($titre);
  6083.                 $historique->setArticle($article);
  6084.                 if (is_object($user)) {
  6085.                     $historique->setUtilisateur($user);
  6086.                 }
  6087.                 if ( ! empty($message)) {
  6088.                     $historique->setMessage($message);
  6089.                 }
  6090.                 $this->entityManager->persist($historique);
  6091.                 $enregistrer true;
  6092.             }
  6093.         }
  6094.         if ($enregistrer) {
  6095.             $this->entityManager->flush();
  6096.         }
  6097.         //return $historique;
  6098.     }
  6099.     function majrefAppelFourSurArticle($article_id)
  6100.     {
  6101.         $conn     $this->entityManager->getConnection();
  6102.         $sql_cond "select id,reference_fournisseur from article__condition_achat where date_supression is null and article_id = ".$article_id;
  6103.         $stmt     $conn->executeQuery($sql_cond);
  6104.         $cond_achats       $stmt->fetchAllAssociative();
  6105.         $total_cond_achats count($cond_achats);
  6106.         $ref_appel "";
  6107.         $tab_appel = [];
  6108.         if ($total_cond_achats 0) {
  6109.             foreach ($cond_achats as $cond_bdd) {
  6110.                 //$output->writeln("REFFOUR:".$cond_bdd["reference_fournisseur"]);
  6111.                 $ref_four_tmp                      $cond_bdd["reference_fournisseur"];
  6112.                 $cond_bdd["reference_fournisseur"] = str_replace("-"""$cond_bdd["reference_fournisseur"]);
  6113.                 $cond_bdd["reference_fournisseur"] = str_replace("."""$cond_bdd["reference_fournisseur"]);
  6114.                 if ( ! in_array($cond_bdd["reference_fournisseur"], $tab_appel)) {
  6115.                     $tab_appel[] = $cond_bdd["reference_fournisseur"];
  6116.                     $ref_appel   .= $cond_bdd["reference_fournisseur"]."-";
  6117.                     $ref_appel   .= $ref_four_tmp."-";
  6118.                 }
  6119.             }
  6120.         }
  6121.         $ref_appel trim($ref_appel"-");
  6122.         $conn->update('article__article', ["reference_appel_10" => $ref_appel], ['id' => $article_id]);
  6123.     }
  6124.     public function getStockPreparable(ArticleCommande $articleCommande)
  6125.     {
  6126.         $stockPreparable       0;
  6127.         $repo_article_commande $this->entityManager->getRepository(ArticleCommande::class);
  6128.         //$quantiteDejaPrepareeSimplifieeGlobal = $repo_article_commande->getQuantiteDejaPrepareeSimplifiee($articleCommande->getArticle()->getId(),$articleCommande->getCommande());
  6129.         $quantiteDejaPrepareeSimplifieeGlobal $repo_article_commande->getQuantiteDejaPrepareeSimplifieeV2($articleCommande->getArticle()->getId());
  6130.         $stockPreparable                      $articleCommande->getArticle()->getStock() - $quantiteDejaPrepareeSimplifieeGlobal;
  6131.         $stockPreparable                      -= $articleCommande->getQuantiteDejaPrepareeSimplifie();
  6132.         $stockPreparable                      max(0$stockPreparable);
  6133.         return $stockPreparable;
  6134.     }
  6135.     public function getComposantsPreparerEmballer($article$quantite)
  6136.     {
  6137.         $articlesComposants = [];
  6138.         if (is_object($article) && $article->getVirtuel()) {
  6139.             foreach ($article->getArticlesComposants() as $articleComposant) {
  6140.                 if (is_object($articleComposant->getArticle()) && $articleComposant->getArticle()->getVirtuel()) {
  6141.                     $articlesComposants array_merge(
  6142.                         $articlesComposants,
  6143.                         $this->getComposantsPreparerEmballer($articleComposant->getArticle(), $articleComposant->getQuantite() * $quantite)
  6144.                     );
  6145.                 } elseif ( ! $articleComposant->getArticle()->getNonPreparable()) {
  6146.                     $articlesComposants[] = ['articleComposant' => $articleComposant'quantite' => $articleComposant->getQuantite() * $quantite];
  6147.                 }
  6148.             }
  6149.         }
  6150.         return $articlesComposants;
  6151.     }
  6152.     public function getPrixAchatNetEuro($article)
  6153.     {
  6154.         $repo_article $this->entityManager->getRepository(Article::class);
  6155.         if ( ! is_object($article)) {
  6156.             $article $repo_article->find($article);
  6157.         }
  6158.         if ($article->getVirtuel()) {
  6159.             $prix $this->getPrixAchatCompose($article);
  6160.         } else {
  6161.             $prix        0;
  6162.             $repo_condha $this->entityManager->getRepository(ConditionAchat::class);
  6163.             $condHa      $repo_condha->findOneBy(["article" => $article"defaut" => 1]);
  6164.             if ( ! is_object($condHa)) {
  6165.                 $condHa $repo_condha->findOneBy(["article" => $article]);
  6166.             }
  6167.             if (is_object($condHa)) {
  6168.                 $prix                       $condHa->getPrixAchatNet();
  6169.                 $coefficientConditionnement $condHa->getCoefficientConditionnement();
  6170.                 if ($coefficientConditionnement != 0) {
  6171.                     $prix $prix $coefficientConditionnement;
  6172.                 }
  6173.                 $fournisseur $condHa->getFournisseur();
  6174.                 if (is_object($fournisseur)) {
  6175.                     $devise $fournisseur->getDevise();
  6176.                     if (is_object($devise)) {
  6177.                         $tauxChange $devise->getTauxChange();
  6178.                         if ($tauxChange != 0) {
  6179.                             $prix $prix $tauxChange;
  6180.                         }
  6181.                     }
  6182.                 }
  6183.             }
  6184.         }
  6185.         return $prix;
  6186.     }
  6187.     public function getArticlesSansReference() {
  6188.         $sql "SELECT count(*) as total
  6189.                 FROM article__article
  6190.                 WHERE reference is null or reference = ''
  6191.                 ";
  6192.         $stmt   $this->entityManager->getConnection()->prepare($sql);
  6193.         $existe $stmt->executeQuery()->fetchAllAssociative();
  6194.         return $existe[0]["total"];
  6195.     }
  6196.     public function getArticlesOqtonManquant() {
  6197.         $sql "SELECT count(*) as total
  6198.                 FROM article__article
  6199.                 WHERE type_id = 1
  6200.                 AND
  6201.                 (oqton_urn is null or oqton_urn = '' or oqton_material_urn is null or oqton_material_urn = '')
  6202.                 ";
  6203.         $stmt   $this->entityManager->getConnection()->prepare($sql);
  6204.         $existe $stmt->executeQuery()->fetchAllAssociative();
  6205.         return $existe[0]["total"];
  6206.     }
  6207. }