src/Repository/stock/ProduitRepository.php line 331

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 getToutCarateristqueProduit($produitId=0$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.                 ( $produitId == '0' || $produitId == '') ? $sql .= '' $sql .= ' AND pr.id = :produitId';
  340.            
  341.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  342.             
  343.     
  344.             $sql .=' ORDER By p.nomProduit ASC ';  
  345.             
  346.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  347.                 ( $produitId == '0' || $produitId == '') ? $sql .= '' $param['produitId'] = $produitId;
  348.               
  349.             
  350.             $query $this->_em->createQuery($sql);
  351.     $query->setParameters($param);
  352.    // var_dump($query->getSql());exit;
  353.     return $query->getResult();
  354. }
  355. public function getAllCarateristqueProduit($abonneId=0) {
  356.         
  357.     $sql =  ' SELECT p.id as produitId, pr.id as produitparentId, cp.id carateristiqueProduitId, pr.nomProduit '
  358.             .' FROM App\Entity\stock\CarateristiqueProduit cp 
  359.                INNER JOIN cp.produit p 
  360.                INNER JOIN cp.produitparent pr
  361.               '
  362.             "
  363.                 INNER JOIN cp.abonne a"
  364.             
  365.             $sql .='  WHERE  1=1 ';
  366.             
  367.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  368.             
  369.     
  370.             $sql .=' ORDER By p.nomProduit ASC ';  
  371.             
  372.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  373.                     
  374.             
  375.             $query $this->_em->createQuery($sql);
  376.     $query->setParameters($param);
  377.    // var_dump($query->getSql());exit;
  378.     return $query->getResult();
  379. }
  380. public function getAllEtapeCroissanceProduit($produitId=0) {
  381.         
  382.     $sql =  ' SELECT pec.id as produitEtapeCroissanceId, ec.id as id,  p.nomProduit, ec.nomEtapeCroissance, pec.siDebut, pec.periode '
  383.            .' FROM App\Entity\prod\ProduitEtapeCroissance pec 
  384.               INNER JOIN pec.etapecroissance ec
  385.               INNER JOIN pec.produit p 
  386.              
  387.               ';
  388.               
  389.             $sql .=' WHERE  p.id = :produitId AND pec.etatProduitEtapeCroissance !=3 ORDER By pec.ordre ASC';
  390.            
  391.     $query $this->_em->createQuery($sql);
  392.     $query->setParameter('produitId'$produitId);
  393.     
  394.     return $query->getResult();
  395. }
  396. public function getAllEtapeCroissanceProduitTache($produitEtapeCroissanceId=0) {
  397.         
  398.     $sql =  ' SELECT tpec.id as id, t.id as activiteId, ec.id as etapeCroissanceId , t.titreActivite '
  399.            .' FROM App\Entity\prod\TacheProduitEtapeCroissance tpec 
  400.               INNER JOIN tpec.produitetapecroissance pec
  401.               INNER JOIN pec.etapecroissance ec
  402.               INNER JOIN tpec.activite t ';
  403.             $sql .=' WHERE  pec.id = :produitEtapeCroissanceId AND pec.etatProduitEtapeCroissance !=3 AND tpec.etatTacheProduitEtapeCroissance !=3  ORDER By tpec.ordre ASC';
  404.            
  405.     $query $this->_em->createQuery($sql);
  406.     $query->setParameter('produitEtapeCroissanceId'$produitEtapeCroissanceId);
  407.     
  408.     return $query->getResult();
  409. }
  410.     /**
  411.      * Retourne tous les produits.
  412.      *
  413.      * @return type
  414.      */
  415.     public function getAllProduitAccueil($abonneId)
  416.     {
  417.         $qb $this->createQueryBuilder('r')
  418.                  ->join('r.abonne','a')
  419.                 ->where('r.etatProduit != '.TypeEtat::SUPPRIME)
  420.                 ->andWhere('r.siAccueil = 1 ')
  421.                 ->andWhere('a.id=:abonneId')
  422.                 ->setParameter('abonneId',$abonneId)
  423.                 ->orderBy('r.id''ASC');
  424.         return $qb->getQuery()->getResult();
  425.     }
  426.     /**
  427.      * Retourne tous les produits.
  428.      *
  429.      * @return type
  430.      */
  431.     public function getAllVariete($idProduit)
  432.     {
  433.         
  434.         $qb $this->createQueryBuilder('p')
  435.                 ->leftJoin('p.produit''pr')    
  436.                 ->where('p.etatProduit != '.TypeEtat::SUPPRIME)
  437.                 ->andWhere('pr.id = '.$idProduit)
  438.                 ->orderBy('p.id''ASC');
  439.         return $qb->getQuery()->getResult();
  440.     }
  441.     public function getOneProduit($id)
  442.     {
  443.         $qb $this->createQueryBuilder('p')
  444.                 ->select('p')
  445.                 ->innerJoin('p.categorie''c')    
  446.                 
  447.                                 
  448.                 ->where('p.id = '.$id);
  449.         return $qb->getQuery()->getResult();
  450.     }    
  451.     
  452.     public function getCategorieProduit($categorie=0$idfournisseur=0$type=1) {
  453.         
  454.             $sql =  ' SELECT DISTINCT p.id, p.nomProduit, p.montantHtAchat, p.tauxTva '
  455.                    .' FROM App\Entity\stock\Produit p inner join p.categorie c ';
  456.                     if($type==1){
  457.                      $sql .=' inner join p.fournisseur f';
  458.                     }
  459.                      $sql .=' WHERE  c.id = :cid ';
  460.                  if($type==1){
  461.                    $sql .='    and    f.id = :cidfourn ';
  462.                  }
  463.                    $sql .=' ORDER BY p.nomProduit DESC ';
  464.             $query $this->_em->createQuery($sql);
  465.             
  466.             //var_dump($sql);exit;
  467.             $query->setParameter('cid'$categorie);
  468.             if($type==1){
  469.                 $query->setParameter('cidfourn'$idfournisseur);
  470.             }
  471.             return $query->getResult();
  472.     }
  473.     
  474.     public function getProduit($idProduit) {        
  475.             $sql =  ' SELECT p.id, p.montantHtVente, p.tauxTva, p.autreTaxe, p.nomProduit, p.codeProduit, p.montantHtAchat '
  476.                    .' FROM App\Entity\stock\Produit p'
  477.                    .' WHERE  p.id = :pid ';
  478.             
  479.             $query $this->_em->createQuery($sql);
  480.             $query->setParameter('pid'$idProduit);
  481.            
  482.             return $query->getOneOrNullResult();
  483.             
  484.     }
  485.     /**
  486.      * Retourne tous les produits.
  487.      *
  488.      * @return type
  489.      */
  490.     public function getAllProduitRupture()
  491.     {
  492.         $qb $this->createQueryBuilder('r')
  493.                 ->where('r.etatProduit != '.TypeEtat::SUPPRIME)
  494.                 ->andWhere('r.seuilProduit > r.enStockProduit')
  495.                 ->orderBy('r.nomProduit''ASC');
  496.         return $qb->getQuery()->getResult();
  497.     }   
  498.     
  499.     
  500.     public function getVariete($idProduit) {        
  501.             $etatPrix =1;
  502.             $sql =  ' SELECT p.id as id, pa.id as id2,  p.nomProduit as nom , pr.infoPrixRigueur as prixAchat, p.montantHtAchat as rendement ' 
  503.                 .' FROM App\Entity\stock\Produit p'
  504.                 
  505.                 .' INNER JOIN p.prixrigueurs pr '
  506.                 .' WHERE  pa.id = :pid  AND pr.etatPrixRigueur =:prix';
  507.             
  508.             $query $this->_em->createQuery($sql);
  509.             $query->setParameter('pid'$idProduit);
  510.             $query->setParameter('prix'$etatPrix);
  511.             //var_dump($query->getSQL());exit;
  512.             return $query->getResult();
  513.             
  514.     }      
  515.     
  516.     public function getAllCurrentVariete($abonneId) {        
  517.         $etatPrix =1;
  518.         $sql =  ' SELECT p ' 
  519.         
  520.             .' FROM App\Entity\stock\Produit p'
  521.             .' INNER JOIN  p.produitabonnes pa'
  522.             .' INNER JOIN  pa.abonne a'
  523.             .' WHERE  p.siAgricole = :siAgricole  AND p.siAgricoleParent !=:siAgricoleParent AND a.id =:abonneId ';
  524.         
  525.         $query $this->_em->createQuery($sql);
  526.         $query->setParameter('siAgricole'1);
  527.         $query->setParameter('siAgricoleParent'1);
  528.         $query->setParameter('abonneId'$abonneId);
  529.         //var_dump($query->getSQL());exit;
  530.         return $query->getResult();
  531.     }  
  532.     public function getAllProduitCategorieAjax($idC$abonneId$siAgricole=0,  $siAgricoleParent=0,$partenaireId=0$typeAction=0) {        
  533.         $sql =  ' SELECT p '
  534.             .' FROM App\Entity\stock\Produit p 
  535.             '
  536.             .' INNER JOIN p.categorie c';
  537.            
  538.             if($typeAction != 0){
  539.                 $sql .= " INNER JOIN p.produitabonnes pas ";
  540.                 $sql .= " INNER JOIN pas.abonne a ";
  541.                 if($typeAction == &&  $partenaireId != 0)
  542.                     $sql .= " INNER JOIN pas.partenaire pt ";
  543.             }else{
  544.                 $sql .= " INNER JOIN p.abonne a";
  545.                 
  546.             }
  547.             //.' INNER JOIN p.prixrigueurs pr'
  548.             
  549.             
  550.         $sql .=' WHERE  p.etatProduit = 1   '//and pr.etatPrixRigueur = 1  and and pr.typePrixRigueur =1
  551.             $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' AND c.id = :idC';
  552.             ( $siAgricole == '0' || $siAgricole == '') ? $sql .= '' $sql .= ' AND p.siAgricole = :siAgricole';
  553.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent = :siAgricoleParent';
  554.             if($typeAction == || $typeAction == 1)
  555.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  556.             else
  557.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  558.             
  559.             $sql .=' ORDER By p.nomProduit ASC ';  
  560.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  561.             if($typeAction == || $typeAction == 1)
  562.                 ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  563.             else
  564.                 ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  565.             ( $siAgricole == '0' || $siAgricole == '') ? $sql .= '' $param['siAgricole'] = $siAgricole;
  566.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  567.                         
  568.             $query $this->_em->createQuery($sql);
  569.         
  570.         //var_dump( $sql);exit;
  571.         $query->setParameters($param);
  572.         return $query->getResult();
  573.         
  574.     }
  575.     public function getAllProduitCategorieAPI($idC$abonneId,$partenaireId=0$typeAction=0) {    
  576.         $param=[];    
  577.         $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 ';
  578.         $sql .=' FROM App\Entity\stock\Produit p
  579.             ';
  580.         $sql .=' INNER JOIN p.categorie c ';
  581.         if($typeAction != 0){
  582.             $sql .= " INNER JOIN p.produitabonnes pas ";
  583.             $sql .= " INNER JOIN pas.abonne a ";
  584.             if($typeAction == &&  $partenaireId != 0)
  585.                 $sql .= " INNER JOIN pas.partenaire pt ";
  586.         }else{
  587.             // $sql .= " INNER JOIN p.abonne a";
  588.             $sql .= " INNER JOIN p.abonne a";
  589.             
  590.         }
  591.         $sql .=' WHERE 1 = 1  AND p.etatProduit = 1  ';  //AND p.siSemence is null 
  592.         
  593.         if($typeAction == || $typeAction == 1)
  594.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  595.         else
  596.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  597.     
  598.         ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  599.         ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  600.         if($typeAction == || $typeAction == 1)
  601.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  602.         else
  603.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  604.         $query $this->_em->createQuery($sql);
  605.         $query->setParameters($param);
  606.        $listeSemence $this->getAllProduitCategorieSiSemenceAPI($idC$abonneId,$partenaireId=0$typeAction=0);
  607.         
  608.         $tabProduit array_merge($query->getResult(), $listeSemence);
  609.         //var_dump($tabProduit);exit;
  610.         return $tabProduit;
  611.         
  612.     }
  613.     public function getAllProduitCategorieSiSemenceAPI($idC$abonneId,$partenaireId=0$typeAction=0) {    
  614.         $param=[];    
  615.         $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';
  616.         $sql .=' FROM App\Entity\stock\Produit p
  617.             ';
  618.         $sql .=' INNER JOIN p.categorie c ';
  619.         $sql .=' INNER JOIN p.produit pd ';
  620.         if($typeAction != 0){
  621.             $sql .= " INNER JOIN p.produitabonnes pas ";
  622.             $sql .= " INNER JOIN pas.abonne a ";
  623.             if($typeAction == &&  $partenaireId != 0)
  624.                 $sql .= " INNER JOIN pas.partenaire pt ";
  625.         }else{
  626.             // $sql .= " INNER JOIN p.abonne a";
  627.             $sql .= " INNER JOIN p.abonne a";
  628.             
  629.         }
  630.         $sql .=' WHERE 1 = 1  AND p.etatProduit = 1  AND p.siSemence = 1';
  631.         
  632.         if($typeAction == || $typeAction == 1)
  633.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= '  AND a.id = :abonneId ';
  634.         else
  635.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $sql .= '  AND pt.id = :partenaireId ';
  636.     
  637.         ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  638.         ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  639.         if($typeAction == || $typeAction == 1)
  640.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;
  641.         else
  642.             ( $partenaireId == '0' || $partenaireId == '') ? $sql .= '' $param['partenaireId'] = $partenaireId;
  643.         $query $this->_em->createQuery($sql);
  644.         $query->setParameters($param);
  645.         //var_dump($query->getSql());exit;
  646.         return $query->getResult();
  647.         
  648.     }
  649.     public function getAllProduitMobileAPI($idC$abonneId) {    
  650.         $param=[];    
  651.         $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 '
  652.             .' FROM App\Entity\stock\Produit p
  653.                '
  654.             .' INNER JOIN p.categorie c '
  655.             .' INNER JOIN p.abonne a ' 
  656.             .' INNER JOIN p.prixrigueurs pr ' 
  657.             
  658.             .' INNER JOIN p.produit p1 ' 
  659.             .' INNER JOIN p.images i ' 
  660.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 ';
  661.             
  662.             
  663.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  664.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  665.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  666.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  667.             $query $this->_em->createQuery($sql);
  668.             $query->setParameters($param);
  669.             //var_dump($query->getSql());exit;
  670.             return $query->getResult();
  671.         
  672.     }
  673.     public function getAllProduitClientMobileAPI($idC$abonneId,$clientId$codeProdGenere =0) {    
  674.         $param=[];    
  675.         $sql =  ' SELECT DISTINCT(p.id)  as id,   p.nomProduit as nom,';
  676.         if($clientId != 0)
  677.             $sql .=  'cp.infoPrix as prixAchat,';
  678.         else
  679.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  680.         $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 '
  681.             .' FROM App\Entity\stock\Produit p '
  682.             .' INNER JOIN p.categorie c '
  683.             .' INNER JOIN p.abonne a ' 
  684.             .' INNER JOIN a.devise d ' 
  685.             .' INNER JOIN p.prixrigueurs pr ';
  686.             if($clientId != 0){
  687.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  688.                 $sql .= ' INNER JOIN cp.client cl ' ;
  689.             }
  690.             $sql .= ' INNER JOIN p.produit p1 ' 
  691.             .' INNER JOIN p.images i ' 
  692.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 and p.siEcommerce = 1';
  693.             
  694.             
  695.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  696.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p1.codeGenere =:codeProdGenere ';
  697.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  698.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  699.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  700.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  701.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  702.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  703.             $query $this->_em->createQuery($sql);
  704.             $query->setParameters($param);
  705.            //var_dump($sql,$abonneId );exit;
  706.            //var_dump($query->getSql());exit;
  707.             return $query->getResult();
  708.         
  709.     }
  710.     public function getAllProduitClientSiteWebAPI($idC$abonneId,$clientId$codeProdGenere =0) {    
  711.         $param=[];    
  712.         $sql =  ' SELECT DISTINCT(p.id)  as id,   p.nomProduit as nom,';
  713.         if($clientId != 0)
  714.             $sql .=  'cp.infoPrix as prixAchat,';
  715.         else
  716.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  717.         $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 '
  718.             .' FROM App\Entity\stock\Produit p '
  719.             .' INNER JOIN p.categorie c '
  720.             .' INNER JOIN p.abonne a ' 
  721.             .' INNER JOIN a.devise d ' 
  722.             .' INNER JOIN p.prixrigueurs pr ';
  723.             if($clientId != 0){
  724.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  725.                 $sql .= ' INNER JOIN cp.client cl ' ;
  726.             }
  727.             $sql .= ' INNER JOIN p.produit p1 ' 
  728.             .' INNER JOIN p.images i ' 
  729.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 and  p.etatProduit = 1 AND p.siEcommerce = 1';
  730.             
  731.             
  732.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  733.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p1.codeGenere =:codeProdGenere ';
  734.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' AND c.id =:idC ';
  735.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  736.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  737.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  738.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  739.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  740.             $query $this->_em->createQuery($sql);
  741.             $query->setParameters($param);
  742.            //var_dump($sql,$abonneId );exit;
  743.            //var_dump($query->getSql());exit;
  744.             return $query->getResult();
  745.         
  746.     }
  747.     public function getOneProduitAPI($idC$abonneId,$clientId$codeProdGenere =0) {    
  748.         $param=[];    
  749.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom,';
  750.         if($clientId != 0)
  751.             $sql .=  'cp.infoPrix as prixAchat,';
  752.         else
  753.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  754.         $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 '
  755.             .' FROM App\Entity\stock\Produit p '
  756.             .' INNER JOIN p.categorie c '
  757.             .' INNER JOIN p.abonne a ' 
  758.             .' INNER JOIN a.devise d ' 
  759.             .' INNER JOIN p.prixrigueurs pr ';
  760.             if($clientId != 0){
  761.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  762.                 $sql .= ' INNER JOIN cp.client cl ' ;
  763.             }
  764.             $sql .= ' INNER JOIN p.images i ' 
  765.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1 and p.siEcommerce = 1';
  766.             
  767.             
  768.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  769.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p.codeGenere =:codeProdGenere ';
  770.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  771.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  772.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  773.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  774.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  775.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  776.             $query $this->_em->createQuery($sql);
  777.             $query->setParameters($param);
  778.            //var_dump($sql);exit;
  779.            //var_dump($query->getSql());exit;
  780.             return $query->getResult();
  781.         
  782.     }
  783.            //var_dump($sql);exit;
  784.     public function getAllCategorieMobileAPI($idC$abonneId$siAgricoleParent ) {    
  785.         $param=[];    
  786.         $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 '
  787.             .' FROM App\Entity\stock\Produit p
  788.                '
  789.             .' INNER JOIN p.categorie c '
  790.             .' INNER JOIN p.abonne a ' 
  791.             .' INNER JOIN p.images i '
  792.             .' WHERE 1 = 1  ';
  793.             
  794.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  795.            
  796.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  797.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  798.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  799.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  800.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  801.             $query $this->_em->createQuery($sql);
  802.             $query->setParameters($param);
  803.             //var_dump($query->getSql());exit;
  804.             return $query->getResult();
  805.         
  806.     }
  807.     public function getAllCategorieProduitParent($idC$abonneId$siAgricoleParent ) {    
  808.         $param=[];    
  809.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom, 0 as prixAchat, p.codeGenere as codeGenere'
  810.             .' FROM App\Entity\stock\Produit p
  811.                '
  812.             .' INNER JOIN p.categorie c '
  813.             .' INNER JOIN p.abonne a ' 
  814.             .' INNER JOIN p.images i '
  815.             .' INNER JOIN p.produits pr '
  816.             .' WHERE 1 = 1  and pr.siEcommerce = 1 ';
  817.             
  818.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  819.            
  820.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  821.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  822.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  823.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  824.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  825.             
  826.             $query $this->_em->createQuery($sql);
  827.             $query->setParameters($param);
  828.             //var_dump($query->getSql());exit;
  829.             return $query->getResult();
  830.         
  831.     }
  832.     public function getAllInventaireProduitParent($idC$abonneId ) {    
  833.         $param=[];    
  834.         $sql =  ' SELECT p '
  835.             .' FROM App\Entity\stock\Produit p
  836.                '
  837.             .' INNER JOIN p.categorie c '
  838.             .' INNER JOIN p.abonne a ' 
  839.             
  840.             .' WHERE 1 = 1  and p.siEcommerce = 1 ';
  841.             
  842.             //( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' : $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  843.            
  844.             $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  845.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  846.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  847.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  848.             //( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' : $param['siAgricoleParent'] = $siAgricoleParent;
  849.             
  850.             $query $this->_em->createQuery($sql);
  851.             $query->setParameters($param);
  852.             //var_dump($query->getSql(), $idC, $abonneId, $siAgricoleParent);exit;
  853.             return $query->getResult();
  854.         
  855.     }
  856.     
  857.     public function getAllCategorieProduitFini($idC$abonneId$siAgricoleParent ) {    
  858.         $param=[];    
  859.         $sql =  ' SELECT  DISTINCT(c.id) as id,   c.nom as nom, 0 as prixAchat, c.code as codeGenere '
  860.             .' FROM App\Entity\stock\CategorieProduit c
  861.                '
  862.             .' INNER JOIN c.produits p '
  863.             .' INNER JOIN p.abonne a ' 
  864.             .' INNER JOIN p.images i '
  865.             
  866.             .' WHERE 1 = 1  and p.siEcommerce = 1 ';
  867.             
  868.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  869.            
  870.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  871.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  872.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  873.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  874.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  875.             $query $this->_em->createQuery($sql);
  876.             $query->setParameters($param);
  877.             //var_dump($query->getSql());exit;
  878.             return $query->getResult();
  879.         
  880.     }
  881.     public function getAllProduitProduitFini($idC$abonneId,$clientId$codeProdGenere =0) {    
  882.         $param=[];    
  883.         $sql =  ' SELECT DISTINCT(p.id) as id,   p.nomProduit as nom,';
  884.         if($clientId != 0)
  885.             $sql .=  'cp.infoPrix as prixAchat,';
  886.         else
  887.             $sql .=  'pr.infoPrixRigueur as prixAchat,';
  888.         $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 '
  889.             .' FROM App\Entity\stock\Produit p
  890.                '
  891.             .' INNER JOIN p.categorie c '
  892.             .' INNER JOIN p.abonne a ' 
  893.             .' INNER JOIN a.devise d ' 
  894.             .' INNER JOIN p.prixrigueurs pr ';
  895.             if($clientId != 0){
  896.                 $sql .= ' INNER JOIN pr.clientprixs cp ' ;
  897.                 $sql .= ' INNER JOIN cp.client cl ' ;
  898.             }
  899.             
  900.             $sql .= ' ' 
  901.             .' INNER JOIN p.images i ' 
  902.             .' WHERE 1 = 1 and pr.etatPrixRigueur = 1  AND p.etatProduit = 1 and p.siEcommerce = 1 and c.id != 3 ';
  903.             
  904.             
  905.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  906.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $sql .= ' AND p1.codeGenere =:codeProdGenere ';
  907.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  908.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $sql .= ' AND cl.id =:clientId ';
  909.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  910.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId
  911.             ( $codeProdGenere == '0' || $codeProdGenere == '') ? $sql .= '' $param['codeProdGenere'] = $codeProdGenere
  912.             ( $clientId == '0' || $clientId == '') ? $sql .= '' $param['clientId'] = $clientId;   
  913.             $query $this->_em->createQuery($sql);
  914.             $query->setParameters($param);
  915.            //var_dump($sql);exit;
  916.            //var_dump($query->getSql());exit;
  917.             return $query->getResult();
  918.         
  919.     }
  920.     public function getAllCategorieTransforme($idC$abonneId$siAgricoleParent ) {    
  921.         $param=[];    
  922.         $sql =  ' SELECT p.id as id,   p.nomProduit as nom, 0 as prixAchat '
  923.                 .' FROM App\Entity\stock\Produit p
  924.                 '
  925.                 .' INNER JOIN p.categorie c '
  926.                 .' INNER JOIN p.abonne a ' 
  927.                 .' INNER JOIN p.images i '
  928.                 .' INNER JOIN p.produits pr '
  929.                 .' WHERE 1 = 1  and pr.siEcommerce = 1 ';
  930.             
  931.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $sql .= ' AND p.siAgricoleParent =:siAgricoleParent ';
  932.            
  933.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  934.             ( $idC == '0' || $idC == '') ? $sql .= '' $sql .= ' OR c.id =:idC ';
  935.             ( $idC == '0' || $idC == '') ? $sql .= '' $param['idC'] = $idC;
  936.             ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  937.             ( $siAgricoleParent == '0' || $siAgricoleParent == '') ? $sql .= '' $param['siAgricoleParent'] = $siAgricoleParent;
  938.             $query $this->_em->createQuery($sql);
  939.             $query->setParameters($param);
  940.             //var_dump($query->getSql());exit;
  941.             return $query->getResult();
  942.         
  943.     }
  944.     /**
  945.      * Retourne un array_map($transform, $query->getScalarResult());
  946.      *
  947.      * @return type
  948.      */
  949.      public function getAllProduitCaisseAPI($abonneId=0$caisseId=0)
  950.      {
  951.             $query $this->_em->createQuery(
  952.                         '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 
  953.                          FROM App\Entity\stock\Produit  p
  954.                          INNER JOIN p.categorie cat
  955.                          INNER JOIN p.abonne a
  956.                          INNER JOIN p.caisseproduits cp
  957.                          INNER JOIN cp.caisse c 
  958.                          WHERE  a.id =:abonneId and c.id =:caisseId  and p.etatProduit = 1   ' //and  p.siSemence !=1
  959.                              )
  960.                   ->setParameters(["abonneId"=>$abonneId"caisseId"=>$caisseId]);
  961.             
  962.                   //var_dump($query->getSql());exit;
  963.        
  964.          return $query->getResult();
  965.  
  966.      }
  967.          /**
  968.      * Retourne un array_map($transform, $query->getScalarResult());
  969.      *
  970.      * @return type
  971.      */
  972.     public function getAllProduitIdActive($abonneId=0)
  973.     {
  974.          $query $this->_em->createQuery(
  975.                        'SELECT p.id as idP, ps.id as id
  976.                         FROM App\Entity\stock\Produit  p
  977.                         INNER JOIN p.abonne a
  978.                         INNER JOIN p.produitsysteme ps
  979.                         
  980.                         WHERE  a.id =:abonneId '
  981.                             )
  982.                  ->setParameters(["abonneId"=>$abonneId]);
  983.         $transform = function($item){
  984.             return $item['id'];
  985.         };
  986.         
  987.          // var_dump(array_map($transform, $query->getScalarResult()));exit;
  988.           return array_map($transform$query->getScalarResult());
  989.     }
  990.     /**
  991.      * Retourne un array_map($transform, $query->getScalarResult());
  992.      *
  993.      * @return type
  994.      */
  995.     public function getAllProduitCaisseIdActive($abonneId=0$caisseId=0)
  996.     {
  997.          $query $this->_em->createQuery(
  998.                        'SELECT  p.id as id
  999.                         FROM App\Entity\stock\Produit  p
  1000.                         INNER JOIN p.categorie cet
  1001.                         INNER JOIN p.abonne a
  1002.                         INNER JOIN p.caisseproduits cp
  1003.                         INNER JOIN cp.caisse c 
  1004.                         
  1005.                         
  1006.                         WHERE  a.id =:abonneId and c.id =:caisseId '
  1007.                             )
  1008.                  ->setParameters(["abonneId"=>$abonneId"caisseId"=>$caisseId]);
  1009.         $transform = function($item){
  1010.             return $item['id'];
  1011.         };
  1012.          // var_dump(array_map($transform, $query->getScalarResult()));exit;
  1013.           return array_map($transform$query->getScalarResult());
  1014.     }
  1015.     /**
  1016.      * Retourne un array_map($transform, $query->getScalarResult());
  1017.      *
  1018.      * @return type
  1019.      */
  1020.     public function getAllProduitCaisse($abonneId=0$caisseId=0$categorieId=1)
  1021.     {
  1022.          $query $this->_em->createQuery(
  1023.                        'SELECT  p
  1024.                         FROM App\Entity\stock\Produit  p
  1025.                         INNER JOIN p.abonne a
  1026.                         INNER JOIN p.categorie cat
  1027.                         INNER JOIN p.caisseproduits cp
  1028.                         INNER JOIN cp.caisse c 
  1029.                         WHERE  a.id =:abonneId and c.id =:caisseId  ' //and cat.typeCategorie =:categorieId
  1030.                             )
  1031.                  ->setParameters(["abonneId"=>$abonneId"caisseId"=>$caisseId]);
  1032.                  //var_dump($query->getSql());exit;
  1033.       
  1034.         return $query->getResult();
  1035.     }
  1036.       /**
  1037.      * Retourne un array_map($transform, $query->getScalarResult());
  1038.      *
  1039.      * @return type
  1040.      */
  1041.     public function getAllProduitCaisseWithPrix($abonneId=0$caisseId=0$categorieId=1)
  1042.     {
  1043.         $sql "
  1044.                 SELECT  p.nomProduit, p.id as id, pr.infoPrixRigueur
  1045.                 FROM App\Entity\stock\Produit  p
  1046.                 INNER JOIN p.abonne a
  1047.                 INNER JOIN p.categorie cat
  1048.         ";
  1049.         
  1050.         ( $caisseId == '0' || $caisseId == '') ? $sql .= '' $sql .=" INNER JOIN p.caisseproduits cp INNER JOIN cp.caisse c"
  1051.         $sql .= "
  1052.                 INNER JOIN p.prixrigueurs pr
  1053.                 WHERE 1=1 AND pr.typePrixRigueur = 2 AND p.etatProduit = 1 AND pr.etatPrixRigueur = 1
  1054.             ";
  1055.         //var_dump( $sql);exit;
  1056.         $abonneId == '0' || $abonneId == '') ? $sql .= '' $sql .= ' AND a.id =:abonneId ';
  1057.         ( $categorieId == '0' || $categorieId == '') ? $sql .= '' $sql .= ' AND cat.id =:categorieId ';
  1058.         ( $caisseId == '0' || $caisseId == '') ? $sql .= '' $sql .= ' AND c.id =:caisseId ';
  1059.         ( $categorieId == '0' || $categorieId == '') ? $sql .= '' $param['categorieId'] = $categorieId;
  1060.         ( $abonneId == '0' || $abonneId == '') ? $sql .= '' $param['abonneId'] = $abonneId;  
  1061.         ( $caisseId == '0' || $caisseId == '') ? $sql .= '' $param['caisseId'] = $caisseId;  
  1062.         $query $this->_em->createQuery($sql);
  1063.         $query->setParameters($param);
  1064.        // var_dump($query->getSql(), $abonneId, $caisseId, $categorieId);exit;
  1065.         return $query->getResult();
  1066.     }
  1067.     public function getOneProduitAjax($prodId) {        
  1068.         
  1069.         $sql =  ' SELECT p.id, p.nomProduit ' 
  1070.             .' FROM App\Entity\stock\Produit p'
  1071.             
  1072.             .' WHERE  p.id = :prodId ';
  1073.         
  1074.         $query $this->_em->createQuery($sql);
  1075.         $query->setParameter('prodId'$prodId);
  1076.         //var_dump($query->getSQL());exit;
  1077.         return $query->getResult();
  1078.         
  1079. }  
  1080.     
  1081.     
  1082. }