src/Repository/stock/ProduitRepository.php line 109

Open in your IDE?
  1. <?php
  2. namespace App\Repository\stock;
  3. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use App\Types\user\TypeEtat;
  6. use App\ControllerModel\user\paramUtilTrait;
  7. use App\Entity\stock\Produit;
  8. /**
  9.  * ProduitRepository
  10.  *
  11.  * This class was generated by the Doctrine ORM. Add your own custom
  12.  * repository methods below.
  13.  */
  14. class ProduitRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryProduit::class);
  19.     }
  20.     
  21.     //
  22.     use paramUtilTrait;
  23.     
  24.     /**
  25.      * Retourne tous les produits.
  26.      *
  27.      * @return type
  28.      */
  29.     public function getAllProduit($abonneId)
  30.     {
  31.         $qb $this->createQueryBuilder('r')
  32.           
  33.                 ->innerJoin('r.abonne','a')
  34.                 ->where('r.etatProduit != '.TypeEtat::SUPPRIME)
  35.                // ->andWhere('r.seuilProduit = 2 ')
  36.                 ->andWhere('a.id=:abonneId')
  37.                 ->setParameter('abonneId',$abonneId)
  38.                 ->orderBy('r.id''ASC');
  39.         return $qb->getQuery()->getResult();
  40.     }
  41.     /**
  42.      * Retourne tous les produits.
  43.      *
  44.      * @return type
  45.      */
  46.     public function getAllProduitSysteme()
  47.     {
  48.         $qb $this->createQueryBuilder('r')
  49.                 ->where('r.etatProduit != '.TypeEtat::SUPPRIME)
  50.                 ->orderBy('r.id''ASC');
  51.         return $qb->getQuery()->getResult();
  52.     }
  53.     public function getAllProduitCategorieSysteme($idC) {        
  54.         $sql =  ' SELECT p '
  55.             .' FROM App\Entity\stock\Produit p  '
  56.             .' INNER JOIN p.categorie c'
  57.           
  58.             .' WHERE c.id =:idC AND p.etatProduit = 1  AND p.siSysteme = 1   ORDER By p.nomProduit ASC ';
  59.                         
  60.         $query $this->_em->createQuery($sql);
  61.         $query->setParameters(array('idC'=>$idC));
  62.         return $query->getResult();
  63.         
  64.     }
  65.     public function getAllProduitCategorie($idC) {        
  66.         $sql =  ' SELECT p '
  67.             .' FROM App\Entity\stock\Produit p  '
  68.             .' INNER JOIN p.categorie c'
  69.           
  70.             .' WHERE c.id =:idC AND p.etatProduit = 1     ORDER By p.nomProduit ASC ';
  71.                         
  72.         $query $this->_em->createQuery($sql);
  73.         $query->setParameters(array('idC'=>$idC));
  74.         return $query->getResult();
  75.         
  76.     }
  77.     /**
  78.      * Retourne tous les produits.
  79.      *
  80.      * @return type
  81.      */
  82.     public function getAllProduitTransformation($abonneId=0)
  83.     {
  84.         $qb $this->createQueryBuilder('r')
  85.                 
  86.                 ->innerJoin('r.abonne','a')
  87.                 ->where('r.etatProduit != '.TypeEtat::SUPPRIME)
  88.                 ->andWhere('r.siTransformation = 1 ')
  89.                 ->andWhere('a.id=:abonneId')
  90.                 ->setParameter('abonneId',$abonneId)
  91.                 ->orderBy('r.id''ASC');
  92.         return $qb->getQuery()->getResult();
  93.     }
  94.     public function getAllProduitTransformationAjax($produitId=0$siCategorie,$partenaireId=0$typeAction=0$abonneId=0) {        
  95.         $sql =  ' SELECT DISTINCT(p.id) as id, p.nomProduit '
  96.         .' FROM App\Entity\stock\Produit p 
  97.         '
  98.         .' INNER JOIN p.categorie c
  99.             INNER JOIN p.produit pr ';
  100.         
  101.         if($typeAction != 0){
  102.             $sql .= " INNER JOIN p.produitabonnes pas ";
  103.             $sql .= " INNER JOIN pas.abonne a ";
  104.             if($typeAction == &&  $partenaireId != 0)
  105.                 $sql .= " INNER JOIN pas.partenaire pt ";
  106.         }else{
  107.             $sql .= " INNER JOIN p.abonne a";
  108.             
  109.         }
  110.         $sql .=' WHERE  p.etatProduit = 1   '//and pr.etatPrixRigueur = 1  and and pr.typePrixRigueur =1
  111.         $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $sql .= ' AND c.id = :siCategorie';
  112.             if($typeAction == || $typeAction == 1)
  113.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  114.         else
  115.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  116.         
  117.         $sql .=' ORDER By p.nomProduit ASC ';  
  118.         ( $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $param['siCategorie'] = $siCategorie;
  119.         if($typeAction == || $typeAction == 1)
  120.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  121.         else
  122.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  123.                     
  124.         $query $this->_em->createQuery($sql);
  125.         $query->setParameters($param);
  126.         //var_dump($query->getSql());exit;
  127.         return $query->getResult();
  128. }
  129. public function getAllVarieteProduitPartenaire($produitId=0$siCategorie,$partenaireId=0$typeAction=0$abonneId=0) {        
  130.     $param= array();
  131.     $sql =  ' SELECT p '
  132.     .' FROM App\Entity\stock\Produit p 
  133.     '
  134.     .' INNER JOIN p.categorie c
  135.         INNER JOIN p.produit pr ';
  136.     
  137.     if($typeAction != 0){
  138.         $sql .= " INNER JOIN p.produitabonnes pas ";
  139.         $sql .= " INNER JOIN pas.abonne a ";
  140.         if($typeAction == &&  $partenaireId != 0)
  141.             $sql .= " INNER JOIN pas.partenaire pt ";
  142.     }else{
  143.         $sql .= " INNER JOIN p.abonne a";
  144.         
  145.     }
  146.     $sql .=' WHERE  p.etatProduit = 1 and p.siAgricole =1 and p.siAgricoleParent =0  '//and pr.etatPrixRigueur = 1  and and pr.typePrixRigueur =1
  147.     $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $sql .= ' AND c.id = :siCategorie';
  148.     if($typeAction == || $typeAction == 1)
  149.         ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  150.     else
  151.         ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  152.     
  153.     $sql .=' ORDER By p.nomProduit ASC ';  
  154.     ( $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $param['siCategorie'] = $siCategorie;
  155.     if($typeAction == || $typeAction == 1)
  156.         ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  157.     else
  158.         ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  159.                 
  160.     $query $this->_em->createQuery($sql);
  161.     $query->setParameters($param);
  162.     return $query->getResult();
  163. }
  164. public function getAllVarieteProduit($produitId=0) {
  165.         
  166.     $sql =  ' SELECT p '
  167.            .' FROM App\Entity\stock\Produit p 
  168.               
  169.               INNER JOIN p.abonne a
  170.               INNER JOIN p.categorie c    
  171.               INNER JOIN p.produit pr ';
  172.             $sql .=' WHERE  pr.id = :produitId  AND p.etatProduit != 2 ';
  173.             //$sql .=' AND  c.id = :siCategorie ';
  174.     $query $this->_em->createQuery($sql);
  175.     $query->setParameter('produitId'$produitId);
  176.    // $query->setParameter('siCategorie', $siCategorie);
  177.     return $query->getResult();
  178. }
  179. public function getAllVarieteCategorieProduit($produitId=0$siCategorie=){
  180.         
  181.     $sql =  ' SELECT p '
  182.            .' FROM App\Entity\stock\Produit p 
  183.               
  184.               INNER JOIN p.abonne a
  185.               INNER JOIN p.categorie c    
  186.               INNER JOIN p.produit pr ';
  187.             $sql .=' WHERE  pr.id = :produitId  AND p.etatProduit != 2 ';
  188.             $sql .=' AND  c.id = :siCategorie ';
  189.     $query $this->_em->createQuery($sql);
  190.     $query->setParameter('produitId'$produitId);
  191.     $query->setParameter('siCategorie'$siCategorie);
  192.     return $query->getResult();
  193. }
  194. public function getAllProduitAjax$abonneId=0) {        
  195.     $sql =  ' SELECT p.id, p.montantHtVente, p.tauxTva, p.autreTaxe, p.nomProduit, p.codeProduit, p.montantHtAchat '
  196.            .' FROM App\Entity\stock\Produit p INNER JOIN p.abonne a  ';
  197.            $sql .=' WHERE 1=1 AND  a.id = :abonneId  AND p.etatProduit != 2 ';
  198.           
  199.     
  200.     $query $this->_em->createQuery($sql);
  201.     $query->setParameter('abonneId'$abonneId);
  202.     return $query->getResult();
  203.     
  204. }
  205. public function getAllFournisseurProduitAjax$abonneId=0$fourId=0) {        
  206.     $sql =  ' SELECT p.id, p.montantHtVente, p.tauxTva, p.autreTaxe, p.nomProduit, p.codeProduit, p.montantHtAchat '
  207.            .' FROM App\Entity\stock\Produit p 
  208.                     INNER JOIN p.abonne a 
  209.                     INNER JOIN p.fournisseurproduits fp 
  210.                     INNER JOIN fp.fournisseur f ';
  211.            $sql .=' WHERE 1=1 AND  a.id = :abonneId AND p.etatProduit != 2  ';
  212.            $sql .=' AND  f.id = :fourId ';
  213.           
  214.     
  215.     $query $this->_em->createQuery($sql);
  216.     //var_dump($query ->getSql(),$fourId,$abonneId );exit;
  217.     $query->setParameters(['abonneId'=>$abonneId'fourId'=>$fourId]);
  218.     return $query->getResult();
  219.     
  220. }
  221.   /**
  222.      * Retourne un array_map($transform, $query->getScalarResult());
  223.      *
  224.      * @return type
  225.      */
  226.     public function getAllProduitCaisseAjax($abonneId=0$caisseId=0)
  227.     {
  228.          $query $this->_em->createQuery(
  229.                        'SELECT  p.id, p.montantHtVente, p.tauxTva, p.autreTaxe, p.nomProduit, p.codeProduit, p.montantHtAchat 
  230.                         FROM App\Entity\stock\Produit  p
  231.                         INNER JOIN p.abonne a
  232.                         INNER JOIN p.categorie cat
  233.                         INNER JOIN p.caisseproduits cp
  234.                         INNER JOIN cp.caisse c 
  235.                         WHERE  a.id =:abonneId and c.id =:caisseId '
  236.                             )
  237.                  ->setParameters(["abonneId"=>$abonneId"caisseId"=>$caisseId]);
  238.                  //var_dump($query->getSql());exit;
  239.       
  240.         return $query->getResult();
  241.     }
  242. public function getAllProduitConditionne($produitId=0$siCategorie$abonneId=0,$partenaireId=0$typeAction=0) {
  243.         
  244.     $sql =  ' SELECT p.id as idParent, pr.id as id, p.nomProduit as prodParent, pr.nomProduit as nomProduit '
  245.            .' FROM App\Entity\stock\Produit p 
  246.               INNER JOIN p.carateristiqueproduits cp 
  247.               INNER JOIN cp.produitparent pr
  248.               INNER JOIN p.abonne a
  249.               ';
  250.               /*if($typeAction != 0){
  251.                 $sql .= "                          
  252.                           INNER JOIN cp.produitabonne pas          
  253.                 ";
  254.                 $sql .= " INNER JOIN pas.abonne a ";
  255.                 if($typeAction == 2 &&  $partenaireId != 0)
  256.                     $sql .= " INNER JOIN pas.partenaire pt ";
  257.                 }else{
  258.                     $sql .= "
  259.                     INNER JOIN p.abonne a"; 
  260.                 }*/
  261.             $sql .=' INNER JOIN pr.categorie c   WHERE  1=1  AND p.etatProduit != 2 ';
  262.             ( $produitId == '0' || $produitId == '') ? $sql .= '' $sql .= ' AND p.id = :produitId';
  263.             ( $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $sql .= ' AND c.typeCategorie = :siCategorie';
  264.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  265.             /*if($typeAction == 0 || $typeAction == 1)
  266.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' : $sql .= '  AND a.id = :abonneId ';
  267.             else
  268.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' : $sql .= '  AND pt.id = :partenaireId ';
  269.             */
  270.             $sql .=' ORDER By p.nomProduit ASC ';  
  271.             ( $produitId == '0' || $produitId == '') ? $sql .= '' $param['produitId'] = $produitId;
  272.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  273.             ( $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $param['siCategorie'] = $siCategorie;
  274.             /*if($typeAction == 0 || $typeAction == 1)
  275.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' : $param['abonneId'] = $abonneId;
  276.             else
  277.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' : $param['partenaireId'] = $partenaireId;
  278.              */           
  279.             
  280.             $query $this->_em->createQuery($sql);
  281.             $query->setParameters($param);
  282.         //var_dump($produitId, $siCategorie, $query->getSql());exit;
  283.         return $query->getResult();
  284. }
  285. public function getAllListeProduitConditionne($produitId=0$siCategorie$abonneId=0,$partenaireId=0$typeAction=0) {
  286.         
  287.     $sql =  ' SELECT DISTINCT(p.id) as id,   p.nomProduit as nom, c.code as prodCodeGenere,  
  288.                      p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere, pr.infoPrixRigueur as prixAchat, 
  289.                      p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, 
  290.                      p.enStockProduit, p.siSemence,  0 as libelleDevise, cp.id  as carateristiqueproduitId '
  291.             .
  292.                FROM App\Entity\stock\Produit p 
  293.                INNER JOIN p.carateristiqueproduit cp
  294.                INNER JOIN cp.produitparent pp
  295.               '
  296.           
  297.             .' INNER JOIN p.prixrigueurs pr ';
  298.               if($typeAction != 0){
  299.                 $sql .= "                          
  300.                           INNER JOIN cp.produitabonne pas          
  301.                 ";
  302.                 $sql .= " INNER JOIN pas.abonne a ";
  303.             if($typeAction == &&  $partenaireId != 0)
  304.                 $sql .= " INNER JOIN pas.partenaire pt ";
  305.             }else{
  306.                 $sql .= "
  307.                 INNER JOIN p.abonne a"
  308.             }
  309.            
  310.             $sql .=' INNER JOIN pp.categorie c   WHERE  1=1 ';
  311.             ( $produitId == '0' || $produitId == '') ? $sql .= '' $sql .= ' AND p.id = :produitId';
  312.             ( $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $sql .= ' AND c.typeCategorie = :siCategorie';
  313.             if($typeAction == || $typeAction == 1)
  314.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  315.             else
  316.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  317.     
  318.             $sql .=' ORDER By p.nomProduit ASC ';  
  319.             ( $produitId == '0' || $produitId == '') ? $sql .= '' $param['produitId'] = $produitId;
  320.             ( $siCategorie == '0' || $siCategorie == '') ? $sql .= '' $param['siCategorie'] = $siCategorie;
  321.             if($typeAction == || $typeAction == 1)
  322.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  323.             else
  324.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  325.                         
  326.             
  327.             $query $this->_em->createQuery($sql);
  328.     $query->setParameters($param);
  329.    // var_dump($query->getSql());exit;
  330.     return $query->getResult();
  331. }
  332. public function getToutCarateristqueProduit($produitId=0$abonneId=0) {
  333.         
  334.     $sql =  ' SELECT p.id as produitId, pr.id as produitparentId, cp.id carateristiqueProduitId, pr.nomProduit '
  335.             .' FROM App\Entity\stock\CarateristiqueProduit cp 
  336.                INNER JOIN cp.produit p 
  337.                INNER JOIN cp.produitparent pr
  338.               '
  339.             "
  340.                 INNER JOIN cp.abonne a"
  341.             
  342.             $sql .='  WHERE  1=1 ';
  343.                 ( $produitId == '0' || $produitId == '') ? $sql .= '' $sql .= ' AND pr.id = :produitId';
  344.            
  345.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  346.             
  347.     
  348.             $sql .=' ORDER By p.nomProduit ASC ';  
  349.             
  350.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  351.                 ( $produitId == '0' || $produitId == '') ? $sql .= '' $param['produitId'] = $produitId;
  352.               
  353.             
  354.             $query $this->_em->createQuery($sql);
  355.     $query->setParameters($param);
  356.    // var_dump($query->getSql());exit;
  357.     return $query->getResult();
  358. }
  359. public function getAllCarateristqueProduit($abonneId=0) {
  360.         
  361.     $sql =  ' SELECT p.id as produitId, pr.id as produitparentId, cp.id carateristiqueProduitId, pr.nomProduit '
  362.             .' FROM App\Entity\stock\CarateristiqueProduit cp 
  363.                INNER JOIN cp.produit p 
  364.                INNER JOIN cp.produitparent pr
  365.               '
  366.             "
  367.                 INNER JOIN cp.abonne a"
  368.             
  369.             $sql .='  WHERE  1=1 ';
  370.             
  371.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  372.             
  373.     
  374.             $sql .=' ORDER By p.nomProduit ASC ';  
  375.             
  376.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  377.                     
  378.             
  379.             $query $this->_em->createQuery($sql);
  380.     $query->setParameters($param);
  381.    // var_dump($query->getSql());exit;
  382.     return $query->getResult();
  383. }
  384. public function getAllEtapeCroissanceProduit($produitId=0) {
  385.         
  386.     $sql =  ' SELECT pec.id as produitEtapeCroissanceId, ec.id as id,  p.nomProduit, ec.nomEtapeCroissance, pec.siDebut, pec.periode '
  387.            .' FROM App\Entity\prod\ProduitEtapeCroissance pec 
  388.               INNER JOIN pec.etapecroissance ec
  389.               INNER JOIN pec.produit p 
  390.              
  391.               ';
  392.               
  393.             $sql .=' WHERE  p.id = :produitId AND pec.etatProduitEtapeCroissance !=3 ORDER By pec.ordre ASC';
  394.            
  395.     $query $this->_em->createQuery($sql);
  396.     $query->setParameter('produitId'$produitId);
  397.     
  398.     return $query->getResult();
  399. }
  400. public function getAllEtapeCroissanceProduitTache($produitEtapeCroissanceId=0) {
  401.         
  402.     $sql =  ' SELECT tpec.id as id, t.id as activiteId, ec.id as etapeCroissanceId , t.titreActivite '
  403.            .' FROM App\Entity\prod\TacheProduitEtapeCroissance tpec 
  404.               INNER JOIN tpec.produitetapecroissance pec
  405.               INNER JOIN pec.etapecroissance ec
  406.               INNER JOIN tpec.activite t ';
  407.             $sql .=' WHERE  pec.id = :produitEtapeCroissanceId AND pec.etatProduitEtapeCroissance !=3 AND tpec.etatTacheProduitEtapeCroissance !=3  ORDER By tpec.ordre ASC';
  408.            
  409.     $query $this->_em->createQuery($sql);
  410.     $query->setParameter('produitEtapeCroissanceId'$produitEtapeCroissanceId);
  411.     
  412.     return $query->getResult();
  413. }
  414.     /**
  415.      * Retourne tous les produits.
  416.      *
  417.      * @return type
  418.      */
  419.     public function getAllProduitAccueil($abonneId)
  420.     {
  421.         $qb $this->createQueryBuilder('r')
  422.                  ->join('r.abonne','a')
  423.                 ->where('r.etatProduit != '.TypeEtat::SUPPRIME)
  424.                 ->andWhere('r.siAccueil = 1 ')
  425.                 ->andWhere('a.id=:abonneId')
  426.                 ->setParameter('abonneId',$abonneId)
  427.                 ->orderBy('r.id''ASC');
  428.         return $qb->getQuery()->getResult();
  429.     }
  430.     /**
  431.      * Retourne tous les produits.
  432.      *
  433.      * @return type
  434.      */
  435.     public function getAllVariete($idProduit)
  436.     {
  437.         
  438.         $qb $this->createQueryBuilder('p')
  439.                 ->leftJoin('p.produit''pr')    
  440.                 ->where('p.etatProduit != '.TypeEtat::SUPPRIME)
  441.                 ->andWhere('pr.id = '.$idProduit)
  442.                 ->orderBy('p.id''ASC');
  443.         return $qb->getQuery()->getResult();
  444.     }
  445.     public function getOneProduit($id)
  446.     {
  447.         $qb $this->createQueryBuilder('p')
  448.                 ->select('p')
  449.                 ->innerJoin('p.categorie''c')    
  450.                 
  451.                                 
  452.                 ->where('p.id = '.$id);
  453.         return $qb->getQuery()->getResult();
  454.     }    
  455.     
  456.     public function getCategorieProduit($categorie=0$idfournisseur=0$type=1) {
  457.         
  458.             $sql =  ' SELECT DISTINCT p.id, p.nomProduit, p.montantHtAchat, p.tauxTva '
  459.                    .' FROM App\Entity\stock\Produit p inner join p.categorie c ';
  460.                     if($type==1){
  461.                      $sql .=' inner join p.fournisseur f';
  462.                     }
  463.                      $sql .=' WHERE  c.id = :cid ';
  464.                  if($type==1){
  465.                    $sql .='    and    f.id = :cidfourn ';
  466.                  }
  467.                    $sql .=' ORDER BY p.nomProduit DESC ';
  468.             $query $this->_em->createQuery($sql);
  469.             
  470.             //var_dump($sql);exit;
  471.             $query->setParameter('cid'$categorie);
  472.             if($type==1){
  473.                 $query->setParameter('cidfourn'$idfournisseur);
  474.             }
  475.             return $query->getResult();
  476.     }
  477.     
  478.     public function getProduit($idProduit) {        
  479.             $sql =  ' SELECT p.id, p.montantHtVente, p.tauxTva, p.autreTaxe, p.nomProduit, p.codeProduit, p.montantHtAchat '
  480.                    .' FROM App\Entity\stock\Produit p'
  481.                    .' WHERE  p.id = :pid ';
  482.             
  483.             $query $this->_em->createQuery($sql);
  484.             $query->setParameter('pid'$idProduit);
  485.            
  486.             return $query->getOneOrNullResult();
  487.             
  488.     }
  489.     /**
  490.      * Retourne tous les produits.
  491.      *
  492.      * @return type
  493.      */
  494.     public function getAllProduitRupture()
  495.     {
  496.         $qb $this->createQueryBuilder('r')
  497.                 ->where('r.etatProduit != '.TypeEtat::SUPPRIME)
  498.                 ->andWhere('r.seuilProduit > r.enStockProduit')
  499.                 ->orderBy('r.nomProduit''ASC');
  500.         return $qb->getQuery()->getResult();
  501.     }   
  502.     
  503.     
  504.     public function getVariete($idProduit) {        
  505.             $etatPrix =1;
  506.             $sql =  ' SELECT p.id as id, pa.id as id2,  p.nomProduit as nom , pr.infoPrixRigueur as prixAchat, p.montantHtAchat as rendement ' 
  507.                 .' FROM App\Entity\stock\Produit p'
  508.                 
  509.                 .' INNER JOIN p.prixrigueurs pr '
  510.                 .' WHERE  pa.id = :pid  AND pr.etatPrixRigueur =:prix';
  511.             
  512.             $query $this->_em->createQuery($sql);
  513.             $query->setParameter('pid'$idProduit);
  514.             $query->setParameter('prix'$etatPrix);
  515.             //var_dump($query->getSQL());exit;
  516.             return $query->getResult();
  517.             
  518.     }      
  519.     
  520.     public function getAllCurrentVariete($abonneId) {        
  521.         $etatPrix =1;
  522.         $sql =  ' SELECT p ' 
  523.         
  524.             .' FROM App\Entity\stock\Produit p'
  525.             .' INNER JOIN  p.produitabonnes pa'
  526.             .' INNER JOIN  pa.abonne a'
  527.             .' WHERE  p.siAgricole = :siAgricole  AND p.siAgricoleParent !=:siAgricoleParent AND a.id =:abonneId ';
  528.         
  529.         $query $this->_em->createQuery($sql);
  530.         $query->setParameter('siAgricole'1);
  531.         $query->setParameter('siAgricoleParent'1);
  532.         $query->setParameter('abonneId'$abonneId);
  533.         //var_dump($query->getSQL());exit;
  534.         return $query->getResult();
  535.     }  
  536.     public function getAllProduitCategorieAjax($idC$abonneId$siAgricole=0,  $siAgricoleParent=0,$partenaireId=0$typeAction=0) {        
  537.         $sql =  ' SELECT p '
  538.             .' FROM App\Entity\stock\Produit p 
  539.             '
  540.             .' INNER JOIN p.categorie c';
  541.            
  542.             if($typeAction != 0){
  543.                 $sql .= " INNER JOIN p.produitabonnes pas ";
  544.                 $sql .= " INNER JOIN pas.abonne a ";
  545.                 if($typeAction == &&  $partenaireId != 0)
  546.                     $sql .= " INNER JOIN pas.partenaire pt ";
  547.             }else{
  548.                 $sql .= " INNER JOIN p.abonne a";
  549.                 
  550.             }
  551.             //.' INNER JOIN p.prixrigueurs pr'
  552.             
  553.             
  554.         $sql .=' WHERE  p.etatProduit = 1   '//and pr.etatPrixRigueur = 1  and and pr.typePrixRigueur =1
  555.             $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' AND c.id = :idC';
  556.             ( $siAgricole == '0' || $siAgricole == '') ? $sql .= '' $sql .= ' AND p.siAgricole = :siAgricole';
  557.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent = :siAgricoleParent';
  558.             if($typeAction == || $typeAction == 1)
  559.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  560.             else
  561.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  562.             
  563.             $sql .=' ORDER By p.nomProduit ASC ';  
  564.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  565.             if($typeAction == || $typeAction == 1)
  566.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  567.             else
  568.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  569.             ( $siAgricole == '0' || $siAgricole == '') ? $sql .= '' $param['siAgricole'] = $siAgricole;
  570.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  571.                         
  572.             $query $this->_em->createQuery($sql);
  573.         
  574.         //var_dump( $sql);exit;
  575.         $query->setParameters($param);
  576.         return $query->getResult();
  577.         
  578.     }
  579.     public function getAllProduitCategorieAPI($idC$abonneId,$partenaireId=0$typeAction=0) {    
  580.         $param=[];    
  581.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom, 0 as prixAchat,   p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere , p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.siSemence, p.actionComptable , p.siEcommerce as siCommerce ';
  582.         $sql .=' FROM App\Entity\stock\Produit p
  583.             ';
  584.         $sql .=' INNER JOIN p.categorie c ';
  585.         if($typeAction != 0){
  586.             $sql .= " INNER JOIN p.produitabonnes pas ";
  587.             $sql .= " INNER JOIN pas.abonne a ";
  588.             if($typeAction == &&  $partenaireId != 0)
  589.                 $sql .= " INNER JOIN pas.partenaire pt ";
  590.         }else{
  591.             // $sql .= " INNER JOIN p.abonne a";
  592.             $sql .= " INNER JOIN p.abonne a";
  593.             
  594.         }
  595.         $sql .=' WHERE 1 = 1  AND p.etatProduit = 1  ';  //AND p.siSemence is null 
  596.         
  597.         if($typeAction == || $typeAction == 1)
  598.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  599.         else
  600.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  601.     
  602.         ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  603.         ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  604.         if($typeAction == || $typeAction == 1)
  605.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  606.         else
  607.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  608.         $query $this->_em->createQuery($sql);
  609.         $query->setParameters($param);
  610.        $listeSemence $this->getAllProduitCategorieSiSemenceAPI($idC$abonneId,$partenaireId=0$typeAction=0);
  611.         
  612.         $tabProduit array_merge($query->getResult(), $listeSemence);
  613.         //var_dump($tabProduit);exit;
  614.         return $tabProduit;
  615.         
  616.     }
  617.     public function getAllProduitCategorieSiSemenceAPI($idC$abonneId,$partenaireId=0$typeAction=0) {    
  618.         $param=[];    
  619.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom, 0 as prixAchat,   p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere , pd.codeGenere as codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.siSemence';
  620.         $sql .=' FROM App\Entity\stock\Produit p
  621.             ';
  622.         $sql .=' INNER JOIN p.categorie c ';
  623.         $sql .=' INNER JOIN p.produit pd ';
  624.         if($typeAction != 0){
  625.             $sql .= " INNER JOIN p.produitabonnes pas ";
  626.             $sql .= " INNER JOIN pas.abonne a ";
  627.             if($typeAction == &&  $partenaireId != 0)
  628.                 $sql .= " INNER JOIN pas.partenaire pt ";
  629.         }else{
  630.             // $sql .= " INNER JOIN p.abonne a";
  631.             $sql .= " INNER JOIN p.abonne a";
  632.             
  633.         }
  634.         $sql .=' WHERE 1 = 1  AND p.etatProduit = 1  AND p.siSemence = 1';
  635.         
  636.         if($typeAction == || $typeAction == 1)
  637.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  638.         else
  639.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  640.     
  641.         ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  642.         ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  643.         if($typeAction == || $typeAction == 1)
  644.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  645.         else
  646.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  647.         $query $this->_em->createQuery($sql);
  648.         $query->setParameters($param);
  649.         //var_dump($query->getSql());exit;
  650.         return $query->getResult();
  651.         
  652.     }
  653.     public function getAllProduitMobileAPI($idC$abonneId) {    
  654.         $param=[];    
  655.         $sql =  ' SELECT DISTINCT(p.id) as id,   p.nomProduit as nom, pr.infoPrixRigueur as prixAchat, p1.codeGenere as prodCodeGenere,   p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere , p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.siSemence, i.urlImage '
  656.             .' FROM App\Entity\stock\Produit p
  657.                '
  658.             .' INNER JOIN p.categorie c '
  659.             .' INNER JOIN p.abonne a ' 
  660.             .' INNER JOIN p.prixrigueurs pr ' 
  661.             
  662.             .' INNER JOIN p.produit p1 ' 
  663.             .' INNER JOIN p.images i ' 
  664.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 ';
  665.             
  666.             
  667.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  668.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  669.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  670.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  671.             $query $this->_em->createQuery($sql);
  672.             $query->setParameters($param);
  673.             //var_dump($query->getSql());exit;
  674.             return $query->getResult();
  675.         
  676.     }
  677.     public function getAllProduitClientMobileAPI($idC$abonneId,$clientId$codeProdGenere =0) {    
  678.         $param=[];    
  679.         $sql =  ' SELECT DISTINCT(p.id)  as id,   p.nomProduit as nom,';
  680.         if($clientId != 0)
  681.             $sql .=  'cp.infoPrix as prixAchat,';
  682.         else
  683.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  684.         $sql .=  'p1.codeGenere as prodCodeGenere,   p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere , p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.enStockProduit, p.siSemence, i.urlImage, d.libelle as libelleDevise '
  685.             .' FROM App\Entity\stock\Produit p '
  686.             .' INNER JOIN p.categorie c '
  687.             .' INNER JOIN p.abonne a ' 
  688.             .' INNER JOIN a.devise d ' 
  689.             .' INNER JOIN p.prixrigueurs pr ';
  690.             if($clientId != 0){
  691.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  692.                 $sql .= ' INNER JOIN cp.client cl ' ;
  693.             }
  694.             $sql .= ' INNER JOIN p.produit p1 ' 
  695.             .' INNER JOIN p.images i ' 
  696.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 and p.siEcommerce = 1';
  697.             
  698.             
  699.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  700.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p1.codeGenere =:codeProdGenere ';
  701.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  702.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  703.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  704.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  705.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  706.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  707.             $query $this->_em->createQuery($sql);
  708.             $query->setParameters($param);
  709.            //var_dump($sql,$abonneId );exit;
  710.            //var_dump($query->getSql());exit;
  711.             return $query->getResult();
  712.         
  713.     }
  714.     public function getAllProduitClientSiteWebAPI($idC$abonneId,$clientId$codeProdGenere =0) {    
  715.         $param=[];    
  716.         $sql =  ' SELECT DISTINCT(p.id)  as id,   p.nomProduit as nom,';
  717.         if($clientId != 0)
  718.             $sql .=  'cp.infoPrix as prixAchat,';
  719.         else
  720.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  721.         $sql .=  'p1.codeGenere as prodCodeGenere,   p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere , p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.enStockProduit, p.siSemence, i.urlImage, d.libelle as libelleDevise '
  722.             .' FROM App\Entity\stock\Produit p '
  723.             .' INNER JOIN p.categorie c '
  724.             .' INNER JOIN p.abonne a ' 
  725.             .' INNER JOIN a.devise d ' 
  726.             .' INNER JOIN p.prixrigueurs pr ';
  727.             if($clientId != 0){
  728.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  729.                 $sql .= ' INNER JOIN cp.client cl ' ;
  730.             }
  731.             $sql .= ' INNER JOIN p.produit p1 ' 
  732.             .' INNER JOIN p.images i ' 
  733.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 and  p.etatProduit = 1 AND p.siEcommerce = 1';
  734.             
  735.             
  736.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  737.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p1.codeGenere =:codeProdGenere ';
  738.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' AND c.id =:idC ';
  739.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  740.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  741.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  742.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  743.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  744.             $query $this->_em->createQuery($sql);
  745.             $query->setParameters($param);
  746.            //var_dump($sql,$abonneId );exit;
  747.            //var_dump($query->getSql());exit;
  748.             return $query->getResult();
  749.         
  750.     }
  751.     public function getOneProduitAPI($idC$abonneId,$clientId$codeProdGenere =0) {    
  752.         $param=[];    
  753.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom,';
  754.         if($clientId != 0)
  755.             $sql .=  'cp.infoPrix as prixAchat,';
  756.         else
  757.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  758.         $sql .=  'p.codeGenere as prodCodeGenere,   p.montantHtAchat as rendement, p.descriptionProduit as description, c.id as idCategorie, p.codeGenere , p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.enStockProduit, p.siSemence, i.urlImage, d.libelle as libelleDevise '
  759.             .' FROM App\Entity\stock\Produit p '
  760.             .' INNER JOIN p.categorie c '
  761.             .' INNER JOIN p.abonne a ' 
  762.             .' INNER JOIN a.devise d ' 
  763.             .' INNER JOIN p.prixrigueurs pr ';
  764.             if($clientId != 0){
  765.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  766.                 $sql .= ' INNER JOIN cp.client cl ' ;
  767.             }
  768.             $sql .= ' INNER JOIN p.images i ' 
  769.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 and p.siEcommerce = 1';
  770.             
  771.             
  772.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  773.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p.codeGenere =:codeProdGenere ';
  774.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  775.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  776.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  777.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  778.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  779.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  780.             $query $this->_em->createQuery($sql);
  781.             $query->setParameters($param);
  782.            //var_dump($sql);exit;
  783.            //var_dump($query->getSql());exit;
  784.             return $query->getResult();
  785.         
  786.     }
  787.            //var_dump($sql);exit;
  788.     public function getAllCategorieMobileAPI($idC$abonneId$siAgricoleParent ) {    
  789.         $param=[];    
  790.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom, 0 as prixAchat,   p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere , p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.siSemence, i.urlImage '
  791.             .' FROM App\Entity\stock\Produit p
  792.                '
  793.             .' INNER JOIN p.categorie c '
  794.             .' INNER JOIN p.abonne a ' 
  795.             .' INNER JOIN p.images i '
  796.             .' WHERE 1 = 1  ';
  797.             
  798.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  799.            
  800.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  801.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  802.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  803.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  804.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  805.             $query $this->_em->createQuery($sql);
  806.             $query->setParameters($param);
  807.             //var_dump($query->getSql());exit;
  808.             return $query->getResult();
  809.         
  810.     }
  811.     public function getAllCategorieProduitParent($idC$abonneId$siAgricoleParent ) {    
  812.         $param=[];    
  813.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom, 0 as prixAchat, p.codeGenere as codeGenere'
  814.             .' FROM App\Entity\stock\Produit p
  815.                '
  816.             .' INNER JOIN p.categorie c '
  817.             .' INNER JOIN p.abonne a ' 
  818.             .' INNER JOIN p.images i '
  819.             .' INNER JOIN p.produits pr '
  820.             .' WHERE 1 = 1  and pr.siEcommerce = 1 ';
  821.             
  822.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  823.            
  824.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  825.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  826.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  827.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  828.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  829.             
  830.             $query $this->_em->createQuery($sql);
  831.             $query->setParameters($param);
  832.             //var_dump($query->getSql());exit;
  833.             return $query->getResult();
  834.         
  835.     }
  836.     public function getAllInventaireProduitParent($idC$abonneId ) {    
  837.         $param=[];    
  838.         $sql =  ' SELECT p '
  839.             .' FROM App\Entity\stock\Produit p
  840.                '
  841.             .' INNER JOIN p.categorie c '
  842.             .' INNER JOIN p.abonne a ' 
  843.             
  844.             .' WHERE 1 = 1  and p.siEcommerce = 1 ';
  845.             
  846.             //( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' : $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  847.            
  848.             $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  849.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  850.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  851.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  852.             //( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' : $param['siAgricoleParent'] = $siAgricoleParent;
  853.             
  854.             $query $this->_em->createQuery($sql);
  855.             $query->setParameters($param);
  856.             //var_dump($query->getSql(), $idC, $abonneId, $siAgricoleParent);exit;
  857.             return $query->getResult();
  858.         
  859.     }
  860.     
  861.     public function getAllCategorieProduitFini($idC$abonneId$siAgricoleParent ) {    
  862.         $param=[];    
  863.         $sql =  ' SELECT  DISTINCT(c.id) as id,   c.nom as nom, 0 as prixAchat, c.code as codeGenere '
  864.             .' FROM App\Entity\stock\CategorieProduit c
  865.                '
  866.             .' INNER JOIN c.produits p '
  867.             .' INNER JOIN p.abonne a ' 
  868.             .' INNER JOIN p.images i '
  869.             
  870.             .' WHERE 1 = 1  and p.siEcommerce = 1 ';
  871.             
  872.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  873.            
  874.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  875.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  876.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  877.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  878.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  879.             $query $this->_em->createQuery($sql);
  880.             $query->setParameters($param);
  881.             //var_dump($query->getSql());exit;
  882.             return $query->getResult();
  883.         
  884.     }
  885.     public function getAllProduitProduitFini($idC$abonneId,$clientId$codeProdGenere =0) {    
  886.         $param=[];    
  887.         $sql =  ' SELECT DISTINCT(p.id) as id,   p.nomProduit as nom,';
  888.         if($clientId != 0)
  889.             $sql .=  'cp.infoPrix as prixAchat,';
  890.         else
  891.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  892.         $sql .=  'c.code as prodCodeGenere,   p.montantHtAchat as rendement, c.id as idCategorie, p.codeGenere , p.codeBarre, c.typeCategorie, p.siAgricole, p.siAgricoleParent, p.enStockProduit, p.siSemence, i.urlImage, d.libelle as libelleDevise '
  893.             .' FROM App\Entity\stock\Produit p
  894.                '
  895.             .' INNER JOIN p.categorie c '
  896.             .' INNER JOIN p.abonne a ' 
  897.             .' INNER JOIN a.devise d ' 
  898.             .' INNER JOIN p.prixrigueurs pr ';
  899.             if($clientId != 0){
  900.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  901.                 $sql .= ' INNER JOIN cp.client cl ' ;
  902.             }
  903.             
  904.             $sql .= ' ' 
  905.             .' INNER JOIN p.images i ' 
  906.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1  AND p.etatProduit = 1 and p.siEcommerce = 1 and c.id != 3 ';
  907.             
  908.             
  909.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  910.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p1.codeGenere =:codeProdGenere ';
  911.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  912.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  913.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  914.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  915.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  916.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  917.             $query $this->_em->createQuery($sql);
  918.             $query->setParameters($param);
  919.            //var_dump($sql);exit;
  920.            //var_dump($query->getSql());exit;
  921.             return $query->getResult();
  922.         
  923.     }
  924.     public function getAllCategorieTransforme($idC$abonneId$siAgricoleParent ) {    
  925.         $param=[];    
  926.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom, 0 as prixAchat '
  927.                 .' FROM App\Entity\stock\Produit p
  928.                 '
  929.                 .' INNER JOIN p.categorie c '
  930.                 .' INNER JOIN p.abonne a ' 
  931.                 .' INNER JOIN p.images i '
  932.                 .' INNER JOIN p.produits pr '
  933.                 .' WHERE 1 = 1  and pr.siEcommerce = 1 ';
  934.             
  935.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  936.            
  937.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  938.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  939.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  940.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  941.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  942.             $query $this->_em->createQuery($sql);
  943.             $query->setParameters($param);
  944.             //var_dump($query->getSql());exit;
  945.             return $query->getResult();
  946.         
  947.     }
  948.     /**
  949.      * Retourne un array_map($transform, $query->getScalarResult());
  950.      *
  951.      * @return type
  952.      */
  953.      public function getAllProduitCaisseAPI($abonneId=0$caisseId=0)
  954.      {
  955.             $query $this->_em->createQuery(
  956.                         'SELECT  p.id as id,   p.nomProduit as nom, 0 as prixAchat,   p.montantHtAchat as rendement, cat.id as idCategorie, p.codeGenere , p.codeBarre, cat.typeCategorie, p.siAgricole, p.siSemence, p.siAgricoleParent, p.actionComptable, p.siEcommerce as siCommerce 
  957.                          FROM App\Entity\stock\Produit  p
  958.                          INNER JOIN p.categorie cat
  959.                          INNER JOIN p.abonne a
  960.                          INNER JOIN p.caisseproduits cp
  961.                          INNER JOIN cp.caisse c 
  962.                          WHERE  a.id =:abonneId and c.id =:caisseId  and p.etatProduit = 1   ' //and  p.siSemence !=1
  963.                              )
  964.                   ->setParameters(["abonneId"=>$abonneId"caisseId"=>$caisseId]);
  965.             
  966.                   //var_dump($query->getSql());exit;
  967.        
  968.          return $query->getResult();
  969.  
  970.      }
  971.          /**
  972.      * Retourne un array_map($transform, $query->getScalarResult());
  973.      *
  974.      * @return type
  975.      */
  976.     public function getAllProduitIdActive($abonneId=0)
  977.     {
  978.          $query $this->_em->createQuery(
  979.                        'SELECT p.id as idP, ps.id as id
  980.                         FROM App\Entity\stock\Produit  p
  981.                         INNER JOIN p.abonne a
  982.                         INNER JOIN p.produitsysteme ps
  983.                         
  984.                         WHERE  a.id =:abonneId '
  985.                             )
  986.                  ->setParameters(["abonneId"=>$abonneId]);
  987.         $transform = function($item){
  988.             return $item['id'];
  989.         };
  990.         
  991.          // var_dump(array_map($transform, $query->getScalarResult()));exit;
  992.           return array_map($transform$query->getScalarResult());
  993.     }
  994.     /**
  995.      * Retourne un array_map($transform, $query->getScalarResult());
  996.      *
  997.      * @return type
  998.      */
  999.     public function getAllProduitCaisseIdActive($abonneId=0$caisseId=0)
  1000.     {
  1001.          $query $this->_em->createQuery(
  1002.                        'SELECT  p.id as id
  1003.                         FROM App\Entity\stock\Produit  p
  1004.                         INNER JOIN p.categorie cet
  1005.                         INNER JOIN p.abonne a
  1006.                         INNER JOIN p.caisseproduits cp
  1007.                         INNER JOIN cp.caisse c 
  1008.                         
  1009.                         
  1010.                         WHERE  a.id =:abonneId and c.id =:caisseId '
  1011.                             )
  1012.                  ->setParameters(["abonneId"=>$abonneId"caisseId"=>$caisseId]);
  1013.         $transform = function($item){
  1014.             return $item['id'];
  1015.         };
  1016.          // var_dump(array_map($transform, $query->getScalarResult()));exit;
  1017.           return array_map($transform$query->getScalarResult());
  1018.     }
  1019.     /**
  1020.      * Retourne un array_map($transform, $query->getScalarResult());
  1021.      *
  1022.      * @return type
  1023.      */
  1024.     public function getAllProduitCaisse($abonneId=0$caisseId=0$categorieId=1)
  1025.     {
  1026.          $query $this->_em->createQuery(
  1027.                        'SELECT  p
  1028.                         FROM App\Entity\stock\Produit  p
  1029.                         INNER JOIN p.abonne a
  1030.                         INNER JOIN p.categorie cat
  1031.                         INNER JOIN p.caisseproduits cp
  1032.                         INNER JOIN cp.caisse c 
  1033.                         WHERE  a.id =:abonneId and c.id =:caisseId  ' //and cat.typeCategorie =:categorieId
  1034.                             )
  1035.                  ->setParameters(["abonneId"=>$abonneId"caisseId"=>$caisseId]);
  1036.                  //var_dump($query->getSql());exit;
  1037.       
  1038.         return $query->getResult();
  1039.     }
  1040.       /**
  1041.      * Retourne un array_map($transform, $query->getScalarResult());
  1042.      *
  1043.      * @return type
  1044.      */
  1045.     public function getAllProduitCaisseWithPrix($abonneId=0$caisseId=0$categorieId=1)
  1046.     {
  1047.         $sql "
  1048.                 SELECT  p.nomProduit, p.id as id, pr.infoPrixRigueur
  1049.                 FROM App\Entity\stock\Produit  p
  1050.                 INNER JOIN p.abonne a
  1051.                 INNER JOIN p.categorie cat
  1052.         ";
  1053.         
  1054.         ( $caisseId == '0' || $caisseId == '') ? $sql .= '' $sql .=" INNER JOIN p.caisseproduits cp INNER JOIN cp.caisse c"
  1055.         $sql .= "
  1056.                 INNER JOIN p.prixrigueurs pr
  1057.                 WHERE 1=1 AND pr.typePrixRigueur = 2 AND p.etatProduit = 1 AND pr.etatPrixRigueur = 1
  1058.             ";
  1059.         //var_dump( $sql);exit;
  1060.         $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  1061.         ( $categorieId == '0' || $categorieId == '') ? $sql .= '' $sql .= ' AND cat.id =:categorieId ';
  1062.         ( $caisseId == '0' || $caisseId == '') ? $sql .= '' $sql .= ' AND c.id =:caisseId ';
  1063.         ( $categorieId == '0' || $categorieId == '') ? $sql .= '' $param['categorieId'] = $categorieId;
  1064.         ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  1065.         ( $caisseId == '0' || $caisseId == '') ? $sql .= '' $param['caisseId'] = $caisseId;  
  1066.         $query $this->_em->createQuery($sql);
  1067.         $query->setParameters($param);
  1068.        // var_dump($query->getSql(), $abonneId, $caisseId, $categorieId);exit;
  1069.         return $query->getResult();
  1070.     }
  1071.     public function getOneProduitAjax($prodId) {        
  1072.         
  1073.         $sql =  ' SELECT p.id, p.nomProduit ' 
  1074.             .' FROM App\Entity\stock\Produit p'
  1075.             
  1076.             .' WHERE  p.id = :prodId ';
  1077.         
  1078.         $query $this->_em->createQuery($sql);
  1079.         $query->setParameter('prodId'$prodId);
  1080.         //var_dump($query->getSQL());exit;
  1081.         return $query->getResult();
  1082.         
  1083. }  
  1084.     
  1085.     
  1086. }