src/Repository/stock/ProduitRepository.php line 149

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