src/Repository/stock/OperationRepository.php line 185

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\Entity\stock\Operation;
  6. use Doctrine\ORM\RepositoryRepository;
  7. use App\Types\user\TypeEtat;
  8. use DateInterval;
  9. use App\ControllerModel\user\paramUtilTrait;
  10. /**
  11.  * OperationRepository
  12.  *
  13.  * This class was generated by the Doctrine ORM. Add your own custom
  14.  * repository methods below.
  15.  */
  16. class OperationRepository extends ServiceEntityRepository
  17. {
  18.     use paramUtilTrait;
  19.     public function __construct(ManagerRegistry $registry)
  20.     {
  21.         parent::__construct($registryOperation::class);
  22.     }
  23.     
  24.     public function getListeOperationCommande($id) {
  25.         $query $this->_em->createQuery(
  26.                         'SELECT o,c
  27.                         FROM App\Entity\stock\Operation o INNER JOIN o.commande c 
  28.                         WHERE c.id = :id'
  29.                 )->setParameter('id'$id);
  30.         return $query->getResult();
  31.     }
  32.     /**
  33.      * Retourne tous les fournisseurs.
  34.      *
  35.      * @return type
  36.      */
  37.     public function getAllOperation() {
  38.         $qb $this->createQueryBuilder('r')
  39.                 ->where('r.etatOperation != ' TypeEtat::SUPPRIME)
  40.                 ->orderBy('r.id''ASC');
  41.         return $qb->getQuery()->getResult();
  42.     }
  43.     public function getOperationsCaisseBrouillardOld($caisse$typedate$datedeb$datefin$typeop$idprod$idab '0'$compte '0'$details '0') {
  44.         $param = array();
  45.         $paramdeb $datedeb//implode('/', array_reverse( explode('-',$datedeb) ) ) ;
  46.         $paramfin $datefin//implode('/', array_reverse( explode('-',$datefin) ) ) ;
  47.         
  48.         // o.soldeLigne,o.chrgjr,
  49.         $sql "SELECT DISTINCT o.id,  o.sensOperation AS sens ,  o.dateOperation, o.montant , o.numMvt, o.libOperation, o.planAnalytique,  o.refFacture , p.compte                       
  50.                 FROM   App\Entity\stock\Operation o ";
  51.         if ($idab == '0') {
  52.             /* $sql .= " INNER JOIN o.produit c
  53.               INNER JOIN c.categorie ca "; */
  54.         } else {
  55.             $compte 'CPTE001';
  56.         }
  57.         $sql .= " INNER JOIN o.typeoperation t 
  58.                        INNER JOIN o.plancomptable p 
  59.                        LEFT JOIN o.commande co 
  60.                 WHERE  1=1  ";
  61.         if ($idab == '0') {
  62.             /**  debut critère recherche  * */
  63.             // ( ($deb == null) || ($deb == 0) )? $sql.="' : $sql.=' AND  o.dateValeur >= :deb and o.dateValeur <= :fin ';
  64.             if ($typedate == 0) {
  65.                 ( $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.dateOperation >= " " '" $paramdeb "' " $sql .= '';
  66.                 ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.dateOperation <= " " '" $paramfin "' " $sql .= '';
  67.             } else {
  68.                 ( $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.dateValeur >= " " '" $paramdeb "' " $sql .= '';
  69.                 ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.dateValeur <= " " '" $paramfin "' " $sql .= '';
  70.             }
  71.         }
  72.         ($caisse == 0) ? $sql .= '' $sql .= 'AND c.id = :caisse ';
  73.         ($details == '0' ) ? $sql .= '' $sql .= 'AND o.libOperation like :details  ';
  74.         ($compte == '0') ? $sql .= '' $sql .= 'and p.compte = :compte';
  75.         ( trim($typeop) == 0) ? $sql .= '' $sql .= ' AND o.refFacture = :typeop ';
  76.         ( trim($idprod) == 0) ? $sql .= '' $sql .= ' AND co.id = :idprod ';
  77.         ( trim($idab) == '0') ? $sql .= '' $sql .= ' AND o.idAbonne = :idab ';
  78.         /** Fin critère recherche * */
  79.         $sql .= ' ORDER BY o.id DESC';
  80.         /**  debut parametres  * */
  81.         if (trim($typeop) != 0) {
  82.             $param['typeop'] = $typeop;
  83.         }
  84.         if (trim($idprod) != 0) {
  85.             $param['idprod'] = $idprod;
  86.         }
  87.         if (trim($idab) != '0') {
  88.             $param['idab'] = $idab;
  89.         }
  90.         if (trim($details) != '0') {
  91.             $param['details'] = '%' $details '%';
  92.         }
  93.         if (trim($caisse) != 0) {
  94.             $param['caisse'] = $caisse;
  95.         }
  96.         if (trim($compte) != '0') {
  97.             $param['compte'] = $compte;
  98.         }
  99.         //var_dump( $sql);exit;
  100.         /** Fin parametres et valeur * */
  101.         $query $this->_em->createQuery($sql);
  102.         $query->setParameters($param);
  103.         return $query->getResult();
  104.     }
  105.     public function getTotalOperationsBrouillard($caisse$datedeb$datefin$typeop$typedate) {
  106.         $param = array();
  107.         $paramdeb implode('-'array_reverse(explode('-'$datedeb)));
  108.         $paramfin implode('-'array_reverse(explode('-'$datefin)));
  109.         /* $sql = 'SELECT count(o.id)                   
  110.           FROM   App\Entity\stock\Operation o
  111.           INNER JOIN o.caisse c
  112.           INNER JOIN o.typeoperation t
  113.           WHERE  1 = 1  '; */
  114.         $sql "SELECT count(o.id)                 
  115.                 FROM   App\Entity\stock\Operation o
  116.                        INNER JOIN o.caisse c
  117.                        INNER JOIN o.typeoperation t 
  118.                        INNER JOIN o.plancomptable p 
  119.                       
  120.                 WHERE  p.compte = c.plancomptable  ";
  121.         /**  debut critère recherche  * */
  122.         // ( ($deb == null) || ($deb == 0) )? $sql.='' : $sql.=' AND  o.dateValeur >= :deb and o.dateValeur <= :fin ';
  123.         if ($typedate == 0) {
  124.             ( $datedeb != ) ? $sql .= " AND  o.dateOperation >= " " '" $paramdeb "' " $sql .= '';
  125.             ( $datefin != ) ? $sql .= " AND  o.dateOperation <= " " '" $paramfin "' " $sql .= '';
  126.         } else {
  127.             ( $datedeb != ) ? $sql .= " AND  o.dateValeur >= " " '" $paramdeb "' " $sql .= '';
  128.             ( $datefin != ) ? $sql .= " AND  o.dateValeur <= " " '" $paramfin "' " $sql .= '';
  129.         }
  130.         ($caisse == 0) ? $sql .= '' $sql .= 'AND c.id = :caisse ';
  131.         ( trim($typeop) == 0) ? $sql .= '' $sql .= ' AND t.id = :typeop ';
  132.         /** Fin critère recherche * */
  133.         /**  debut parametres  * */
  134.         if (trim($typeop) != 0) {
  135.             $param['typeop'] = $typeop;
  136.         }
  137.         if (trim($caisse) != 0) {
  138.             $param['caisse'] = $caisse;
  139.         }
  140.         /** Fin parametres et valeur * */
  141.         $query $this->_em->createQuery($sql);
  142.         $query->setParameters($param);
  143.         try {
  144.             //$lavaleur = $query->getResult();
  145.             $lavaleur $query->getSingleScalarResult();
  146.         } catch (\Doctrine\ORM\NoResultException $e) {
  147.             $lavaleur 0;
  148.         }
  149.         return $lavaleur;
  150.     }
  151.     public function getOperationsCaisseBrouillard($caisse$typedate$datedeb$datefin$typeop=0$total$page$articles_per_page$idprod$idfour$compte '0'$details '0'$ville '0'$silivre '0'$abonneId '0'$clientId '0'$producteurId '0'$partenaireId '0',  $fournisseurId '0') {
  152.         $param = array();
  153.         $datedebarray = array();
  154.         $datefinarray = array();
  155.         
  156.         if ($datedeb == && $datefin == && $producteurId == 0) {
  157.             $dateJour = new \DateTime();
  158.             $premierDate $this->dateDuPremierDuMois($dateJour);
  159.             $datedeb $premierDate->format("d/m/Y 00:00:00");
  160.             $dateMoi $premierDate->add(new DateInterval('P1M'));
  161.             $datefin $dateMoi->format("d/m/Y 00:00:00");
  162.         }
  163.         
  164.         $heureDebut explode(' ',  $datedeb);
  165.         $heureFin explode(' ',  $datefin);
  166.         
  167.         $datedebarray $this->traiterDateFormat($datedeb);
  168.         $datefinarray $this->traiterDateFormat($datefin);
  169.         
  170.         $paramdeb implode("-"$datedebarray);
  171.         $paramfin implode("-"$datefinarray);
  172.         $sql "SELECT o.id,  o.sensOperation AS sens ,  o.dateOperation, o.montant , o.numMvt, o.libOperation, v.nomVille ,o.refFacture, o.planAnalytique , p.compte, p.infoCompte                        
  173.                 FROM   App\Entity\stock\Operation o ";
  174.         if ($idfour != '0') {
  175.             $sql .= " LEFT JOIN o.commande c
  176.                        LEFT JOIN c.fournisseur f ";
  177.         }
  178.         $sql .= " LEFT JOIN o.produit pr
  179.                        INNER JOIN o.typeoperation t 
  180.                        INNER JOIN o.plancomptable p 
  181.                 ";
  182.         //if($ville !='0'){
  183.         $sql .= " LEFT JOIN o.ville v ";
  184.         if (trim($abonneId) != '0') {
  185.             $sql .= " INNER JOIN o.abonne a ";
  186.         }
  187.         if ($partenaireId != '0') {
  188.             $sql .= " INNER JOIN o.partenaire pa ";
  189.         }
  190.         if ($producteurId != '0' && $producteurId != '' ) {
  191.             $sql .= " INNER JOIN o.producteur pd ";
  192.         }
  193.         if ($fournisseurId != '0') {
  194.             $sql .= " INNER JOIN o.fournisseur four ";
  195.         }
  196.         if (trim($caisse) != '0') {
  197.             $sql .= " INNER JOIN o.caisse c ";
  198.         }
  199.         if (trim($clientId) != '0') {
  200.             $sql .= " INNER JOIN o.client cl ";
  201.         }
  202.         //}   
  203.         $sql .= " WHERE  1=1  ";
  204.        
  205.         /**  debut critère recherche  * */
  206.         // ( ($deb == null) || ($deb == 0) )? $sql.="' : $sql.=' AND  o.dateValeur >= :deb and o.dateValeur <= :fin ';
  207.         if (($datedeb == && $datefin == && $producteurId == 0) or ($datedeb != or $datefin != ) ) {
  208.             $sql .= " AND  o.dateOperation >= " " '" $paramdeb." ".$heureDebut[1] . "' ";
  209.             $sql .= " AND  o.dateOperation <= " " '" $paramfin." ".$heureFin[1] . "' ";
  210.         }
  211.         ($caisse == 0) ? $sql .= '' $sql .= 'AND c.id = :caisse ';
  212.         ($ville == '0') ? $sql .= '' $sql .= 'AND v.id = :ville ';
  213.         //($silivre == '0') ? $sql .= '' : $sql .= 'AND o.idAbonne = :silivre ';
  214.        
  215.         ($details == '0' or $details == '' ) ? $sql .= '' $sql .= 'AND o.libOperation like :details  ';
  216.         // ($typeop == '0' ) ? $sql .= '' : $sql .= 'AND t.id =:idtypeop  ';
  217.         ($compte == '0') ? $sql .= '' $sql .= ' AND p.compte = :compte';
  218.         
  219.         ($idfour == '0') ? $sql .= '' $sql .= ' AND f.id = :idfour';
  220.         ($idprod == '0') ? $sql .= '' $sql .= ' AND  pr.id = :idprod';
  221.         ($abonneId == '0') ? $sql .= '' $sql .= ' AND  a.id = :abonneId';
  222.         ($clientId == '0') ? $sql .= '' $sql .= ' AND  cl.id = :clientId';
  223.         ($idfour == '0') ? $sql .= '' $sql .= ' AND f.id = :idfour';
  224.         ($typeop != &&  $typeop != "") ? $sql .= ' AND t.id = :typeop ' $sql .= '';
  225.         ($partenaireId == '0') ? $sql .= '' $sql .= ' AND  pa.id = :partenaireId';
  226.         ($producteurId != '0' && $producteurId != '') ? $sql .= ' AND  pd.id = :producteurId' $sql .= ' ';
  227.         ($fournisseurId == '0') ? $sql .= '' $sql .= ' AND  four.id = :fournisseurId';
  228.         //var_dump($caisse, $sql,$compte);exit;
  229.         /** Fin critère recherche * */
  230.         $sql .= ' ORDER BY o.dateOperation DESC';
  231.         /**  debut parametres  * */
  232.         //var_dump($sql,$caisse, $typedate,$datedeb, $datefin, $typeop, $total, $page, $articles_per_page, $idprod, $idfour,$compte, $details, $ville,$silivre); exit;
  233.         if ($typeop != &&  $typeop != "") {
  234.             $param['typeop'] = $typeop;
  235.         }
  236.         if (trim($idprod) != '0') {
  237.             $param['idprod'] = $idprod;
  238.         }
  239.         if ($partenaireId != '0') {
  240.             $param['partenaireId'] = $partenaireId;
  241.         }
  242.         if ($producteurId != '0' && $producteurId != '') {
  243.             $param['producteurId'] = $producteurId;
  244.         }
  245.         if ($fournisseurId != 0) {
  246.             $param['fournisseurId'] = $fournisseurId;
  247.         }
  248.         if ($details != '0' && $details != '') {
  249.             $param['details'] = '%' $details '%';
  250.         }
  251.         if (trim($caisse) != 0) {
  252.             $param['caisse'] = $caisse;
  253.         }
  254.         if (trim($ville) != 0) {
  255.             $param['ville'] = $ville;
  256.         }
  257.         if (trim($clientId) != '0') {
  258.             $param['clientId'] = $clientId;
  259.         }
  260.        /* if (trim($silivre) != 0) {
  261.             $param['silivre'] = $silivre;
  262.         }*/
  263.         if (trim($compte) != '0') {
  264.             $param['compte'] = $compte;
  265.         }
  266.         if (trim($idfour) != '0') {
  267.             $param['idfour'] = $idfour;
  268.         }
  269.         if (trim($abonneId) != '0') {
  270.             $param['abonneId'] = $abonneId;
  271.         }
  272.        // var_dump($sql, $typeop);exit;
  273.         // exit;
  274.         /** Fin parametres et valeur * */
  275.         $query $this->_em->createQuery($sql);
  276.         $query->setParameters($param);
  277.        // var_dump($query->getSQL(),  $compte, $caisse, $abonneId );exit;
  278.         return $query->getResult();
  279.     }
  280.     public function getOperationsSuivieLivraison($datedeb$datefin$typeop$ville '0') {
  281.         $param = array();
  282.         $datedebarray = array();
  283.         $datefinarray = array();
  284.         //var_dump($datedeb, $datefin);exit;
  285.         if ($datedeb == && $datefin == 0) {
  286.             $dateJour = new \DateTime();
  287.             $premierDate $this->dateDuPremierDuMois($dateJour);
  288.             $datedeb $premierDate->format("d/m/Y");
  289.             $dateMoi $premierDate->add(new DateInterval('P1M'));
  290.             $datefin $dateMoi->format("d/m/Y");
  291.         }
  292.         //traitement des tableaux
  293.         //heure debut
  294.         $datedebarray $this->traiterDateFormat($datedeb);
  295.         $datefinarray $this->traiterDateFormat($datefin);
  296.         //var_dump($silivre);exit;
  297.         $paramdeb implode("-"$datedebarray);
  298.         $paramfin implode("-"$datefinarray);
  299.         $sql "SELECT s                        
  300.                 FROM   App\Entity\stock\SuivieLivraison s ";
  301.         if (trim($ville) != 0) {
  302.             $sql .= " INNER JOIN s.ville v ";
  303.         }
  304.         $sql .= " WHERE  1=1  ";
  305.         $sql .= " AND  s.dateSuivie >= " " '" $paramdeb "' ";
  306.         $sql .= " AND  s.dateSuivie <= " " '" $paramfin "' ";
  307.         ($ville == '0') ? $sql .= '' $sql .= 'AND v.id = :ville ';
  308.         ( trim($typeop) == 0) ? $sql .= '' $sql .= ' AND t.id = :typeop ';
  309.         /** Fin critère recherche * */
  310.         $sql .= ' ORDER BY s.dateSuivie DESC';
  311.         
  312. //        var_dump($sql);exit;
  313.         if (trim($typeop) != 0) {
  314.             $param['typeop'] = $typeop;
  315.         }        
  316.         if (trim($ville) != 0) {
  317.             $param['ville'] = $ville;
  318.         }
  319.         $query $this->_em->createQuery($sql);
  320.         $query->setParameters($param);
  321.         //var_dump($query->getSQL());exit;
  322.         return $query->getResult();
  323.     }
  324. }