src/Repository/Kanban/ColonneRepository.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Kanban;
  3. use App\Entity\Kanban\Colonne;
  4. use App\Entity\Kanban\Fiche;
  5. use App\Entity\Kanban\StatutFiche;
  6. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. /**
  9.  * ColonneRepository
  10.  *
  11.  * This class was generated by the Doctrine ORM. Add your own custom
  12.  * repository methods below.
  13.  */
  14. class ColonneRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryColonne::class);
  19.     }
  20.     public function getTotalOffres($colonne$param = [], $user)
  21.     {
  22.         $param["parametres"] = $param;
  23.         //and
  24.         //kf.statut_fiche_id is null
  25.         $where "";
  26.         $inner "";
  27.         $inner .= " LEFT JOIN kanban__statut_fiche sf ON sf.id = kf.statut_fiche_id";
  28.         $where .= " AND (sf.id IS NULL OR sf.id NOT IN (3))";
  29.         if (array_key_exists('favoris'$param['parametres']) and ($param['parametres']['favoris'] == "1")) {
  30.             $inner .= " INNER JOIN kanban__favoris ON kf.id = kanban__favoris.fiche_id";
  31.         }
  32.         if (array_key_exists('client'$param['parametres']) and ($param['parametres']['client'] != "")) {
  33.             $inner .= ' LEFT JOIN client__client cli ON cli.id = kf.client_id';
  34.             $where .= " AND cli.id = ".$param['parametres']['client'];
  35.         }
  36.         if (array_key_exists('u'$param['parametres']) and count($param['parametres']['u']) > 0) {
  37.             $where .= " AND kf.utilisateur_id IN (";
  38.             $in    "";
  39.             foreach ($param['parametres']['u'] as $key => $value) {
  40.                 $in .= $value.",";
  41.             }
  42.             $in    trim($in",");
  43.             $where .= $in.")";
  44.         }
  45.         if (is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  46.             /*
  47.                 $where .= " AND kf.utilisateur_id IN (";
  48.                 $in = "";
  49.                     $in .= $user->getId().",";
  50.                 $in = trim($in,",");
  51.                 $where .= $in.")";
  52.                 */
  53.             $where .= " AND (kf.utilisateur_id IN (".$user->getId().") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$user->getId().") ) )";
  54.         } elseif (array_key_exists('filtre-utilisateurs'$param['parametres']) and count($param['parametres']['filtre-utilisateurs']) > 0) {
  55.             /*
  56.             $where .= " AND kf.utilisateur IN (:utilisateurs)";
  57.             foreach($param['parametres']['filtre-utilisateurs'] as $key=>$value) {
  58.                 $parametres['utilisateurs'][]=$value;
  59.             }
  60.             */
  61.             //$where .= " AND kf.utilisateur_id IN (";
  62.             $in "";
  63.             foreach ($param['parametres']['filtre-utilisateurs'] as $key => $value) {
  64.                 $in .= $value.",";
  65.             }
  66.             $in trim($in",");
  67.             //$where .= $in.")";
  68.             $where .= " AND (kf.utilisateur_id IN (".$in.") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$in.") ) )";
  69.         }
  70.         if (array_key_exists('filtre-apporteurs'$param['parametres']) and count($param['parametres']['filtre-apporteurs']) > 0) {
  71.             $in "";
  72.             foreach ($param['parametres']['filtre-apporteurs'] as $key => $value) {
  73.                 $in .= $value.",";
  74.             }
  75.             $in    trim($in",");
  76.             $where .= " AND kf.apporteur_id IN (".$in.")";
  77.         }
  78.         if (array_key_exists('filtre-commerciaux'$param['parametres']) and count($param['parametres']['filtre-commerciaux']) > 0) {
  79.             $in "";
  80.             foreach ($param['parametres']['filtre-commerciaux'] as $key => $value) {
  81.                 $in .= $value.",";
  82.             }
  83.             $in    trim($in",");
  84.             $where .= " AND kf.commercial_id IN (".$in.")";
  85.         }
  86.         if (array_key_exists('filtre-chefsProjet'$param['parametres']) and count($param['parametres']['filtre-chefsProjet']) > 0) {
  87.             $in "";
  88.             foreach ($param['parametres']['filtre-chefsProjet'] as $key => $value) {
  89.                 $in .= $value.",";
  90.             }
  91.             $in    trim($in",");
  92.             $where .= " AND kf.chef_projet_id IN (".$in.")";
  93.         }
  94.         if (array_key_exists('filtre-fiche'$param['parametres']) and ($param['parametres']['filtre-fiche'] != "")) {
  95.             $where .= " AND kf.id = ".$param['parametres']['filtre-fiche'];
  96.             //$parametres['fiche'] = $param['parametres']['filtre-fiche'];
  97.         }
  98.         /*
  99.         if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
  100.               //$query->join('p.ficheOrigine', 'fo');
  101.               //$where .= " AND fo.origine = :origine";
  102.             //$parametres['origine'] = $param['parametres']['or'];
  103.             $where .= " AND  kf.id IN (select fiche_id FROM kanban__fiche_origine WHERE fiche_id = kf.id and origine_id = '".$param['parametres']['or']."'  )";
  104.         }
  105.         */
  106.         if (array_key_exists('or'$param['parametres']) and ($param['parametres']['or'] != "")) {
  107.             $where .= " AND kf.origine_commande_id = ".$param['parametres']['or'];
  108.         }
  109.         if (array_key_exists('marche'$param['parametres']) and ($param['parametres']['marche'] != "")) {
  110.             $inner .= ' LEFT JOIN article__marche mr ON mr.id = kf.marche_id';
  111.             $where .= " AND mr.id = ".$param['parametres']['marche'];
  112.         }
  113.         if ( ! empty($param['parametres']['apporteur'])) {
  114.             $inner .= ' LEFT JOIN utilisateur__contact co ON co.id = kf.apporteur_id';
  115.             $where .= " AND co.id = ".$param['parametres']['apporteur'];
  116.         }
  117.         if (array_key_exists('domaine'$param['parametres']) and ($param['parametres']['domaine'] != "")) {
  118.             $inner .= ' LEFT JOIN projet__projet_domaine pd ON pd.fiche_id = kf.id';
  119.             $inner .= ' LEFT JOIN projet__domaine do ON pd.domaine_id = do.id';
  120.             $where .= " AND do.id = ".$param['parametres']['domaine'];
  121.         }
  122.         if (array_key_exists('activite'$param['parametres']) and ($param['parametres']['activite'] != "")) {
  123.             $inner .= ' LEFT JOIN projet__projet_activite pa ON pa.fiche_id = kf.id';
  124.             $inner .= ' LEFT JOIN projet__activite paa ON pa.activite_id = paa.id';
  125.             $where .= " AND paa.id = ".$param['parametres']['activite'];
  126.         }
  127.         if (array_key_exists('partenaire'$param['parametres']) and ($param['parametres']['partenaire'] != "")) {
  128.             $inner .= ' LEFT JOIN commerciale__commande cmd ON cmd.fiche_id = kf.id';
  129.             $inner .= ' LEFT JOIN commerciale__article_commande accmd ON accmd.commande_id = cmd.id';
  130.             $inner .= ' LEFT JOIN commerciale__statut_commande scmd ON cmd.statut_commande_id = scmd.id';
  131.             $inner .= ' LEFT JOIN commerciale__type_document_commercial tcmd ON cmd.type_document_commercial_id = tcmd.id';
  132.             $where .= " AND scmd.ordre NOT IN (0) AND tcmd.id IN (1) AND accmd.fournisseur_id = ".$param['parametres']['partenaire'];
  133.         }
  134.         $where .= " AND ";
  135.         $where .= '(kf.archive = 0 OR kf.archive IS NULL)';
  136.         $sql 'select count(DISTINCT(kf.id)) as total 
  137.                     from kanban__fiche kf'
  138.                .' JOIN kanban__colonne kc ON kf.colonne_id = kc.id'
  139.                .' LEFT JOIN kanban__kanban k ON kc.kanban_id = k.id'
  140.                .' LEFT JOIN kanban__colonne kcc ON kcc.id = k.colonne_id'
  141.                .' LEFT JOIN kanban__kanban kk ON kcc.kanban_id = kk.id'
  142.                .' LEFT JOIN kanban__colonne kccc ON kccc.id = kk.colonne_id'
  143.                .$inner
  144.                .' where 
  145.                     kf.dateSuppression is NULL
  146.                     and (kf.colonne_id = '.$colonne->getId().' OR kcc.id = '.$colonne->getId().' OR kccc.id = '.$colonne->getId().')'
  147.                .$where//.' GROUP By kf.id'
  148.         ;
  149.         $em   $this->getEntityManager();
  150.         $stmt $em->getConnection()->prepare($sql);
  151.         $res $stmt->executeQuery()->fetchAllAssociative();
  152.         return $res[0]["total"];
  153.     }
  154.     public function getTotalBudgetColonne($in_colonne ""$param = [], $user)
  155.     {
  156.         $param["parametres"] = $param;
  157.         $where               "";
  158.         $inner               "";
  159.         $inner .= " LEFT JOIN kanban__statut_fiche sf ON sf.id = kf.statut_fiche_id";
  160.         $where .= " AND (sf.id IS NULL OR sf.id NOT IN (3))";
  161.         if (array_key_exists('favoris'$param['parametres']) and ($param['parametres']['favoris'] == "1")) {
  162.             $inner .= "INNER JOIN kanban__favoris ON kf.id = kanban__favoris.fiche_id";
  163.         }
  164.         if (array_key_exists('client'$param['parametres']) and ($param['parametres']['client'] != "")) {
  165.             $inner .= ' LEFT JOIN client__client cli ON cli.id = kf.client_id';
  166.             $where .= " AND cli.id = ".$param['parametres']['client'];
  167.         }
  168.         if (array_key_exists('u'$param['parametres']) and count($param['parametres']['u']) > 0) {
  169.             $where .= " AND kf.utilisateur_id IN (";
  170.             $in    "";
  171.             foreach ($param['parametres']['u'] as $key => $value) {
  172.                 $in .= $value.",";
  173.             }
  174.             $in    trim($in",");
  175.             $where .= $in.")";
  176.         }
  177.         if (array_key_exists('regions'$param["parametres"]) && $param["parametres"]["regions"] > 0) {
  178.             $where .= " AND kf.region_id = ".$param['parametres']['regions'];
  179.         }
  180.         if (is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  181.             /*
  182.                 $where .= " AND kf.utilisateur_id IN (";
  183.                 $in = "";
  184.                     $in .= $user->getId().",";
  185.                 $in = trim($in,",");
  186.                 $where .= $in.")";
  187.                 */
  188.             $where .= " AND (kf.utilisateur_id IN (".$user->getId().") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$user->getId().") ) )";
  189.         } elseif (array_key_exists('filtre-utilisateurs'$param['parametres']) and count($param['parametres']['filtre-utilisateurs']) > 0) {
  190.             /*
  191.             $where .= " AND kf.utilisateur IN (:utilisateurs)";
  192.             foreach($param['parametres']['filtre-utilisateurs'] as $key=>$value) {
  193.                 $parametres['utilisateurs'][]=$value;
  194.             }
  195.             */
  196.             //$where .= " AND kf.utilisateur_id IN (";
  197.             $in "";
  198.             foreach ($param['parametres']['filtre-utilisateurs'] as $key => $value) {
  199.                 $in .= $value.",";
  200.             }
  201.             $in trim($in",");
  202.             //$where .= $in.")";
  203.             $where .= " AND (kf.utilisateur_id IN (".$in.") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$in.") ) )";
  204.         }
  205.         if (array_key_exists('filtre-apporteurs'$param['parametres']) and count($param['parametres']['filtre-apporteurs']) > 0) {
  206.             $in "";
  207.             foreach ($param['parametres']['filtre-apporteurs'] as $key => $value) {
  208.                 $in .= $value.",";
  209.             }
  210.             $in    trim($in",");
  211.             $where .= " AND kf.apporteur_id IN (".$in.")";
  212.         }
  213.         if (array_key_exists('filtre-commerciaux'$param['parametres']) and count($param['parametres']['filtre-commerciaux']) > 0) {
  214.             $in "";
  215.             foreach ($param['parametres']['filtre-commerciaux'] as $key => $value) {
  216.                 $in .= $value.",";
  217.             }
  218.             $in    trim($in",");
  219.             $where .= " AND kf.commercial_id IN (".$in.")";
  220.         }
  221.         if (array_key_exists('filtre-chefsProjet'$param['parametres']) and count($param['parametres']['filtre-chefsProjet']) > 0) {
  222.             $in "";
  223.             foreach ($param['parametres']['filtre-chefsProjet'] as $key => $value) {
  224.                 $in .= $value.",";
  225.             }
  226.             $in    trim($in",");
  227.             $where .= " AND kf.chef_projet_id IN (".$in.")";
  228.         }
  229.         /*
  230.         if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
  231.               //$query->join('p.ficheOrigine', 'fo');
  232.               //$where .= " AND fo.origine = :origine";
  233.             //$parametres['origine'] = $param['parametres']['or'];
  234.             $where .= " AND  kf.id IN (select fiche_id FROM kanban__fiche_origine WHERE fiche_id = kf.id and origine_id = '".$param['parametres']['or']."'  )";
  235.         }
  236.         */
  237.         if (array_key_exists('or'$param['parametres']) and ($param['parametres']['or'] != "")) {
  238.             $where .= " AND kf.origine_commande_id = ".$param['parametres']['or'];
  239.         }
  240.         if (array_key_exists('marche'$param['parametres']) and ($param['parametres']['marche'] != "")) {
  241.             $inner .= ' LEFT JOIN article__marche mr ON mr.id = kf.marche_id';
  242.             $where .= " AND mr.id = ".$param['parametres']['marche'];
  243.         }
  244.         if ( ! empty($param['parametres']['apporteur'])) {
  245.             $inner .= ' LEFT JOIN utilisateur__contact co ON co.id = kf.apporteur_id';
  246.             $where .= " AND co.id = ".$param['parametres']['apporteur'];
  247.         }
  248.         if (array_key_exists('domaine'$param['parametres']) and ($param['parametres']['domaine'] != "")) {
  249.             $inner .= ' LEFT JOIN projet__projet_domaine pd ON pd.fiche_id = kf.id';
  250.             $inner .= ' LEFT JOIN projet__domaine do ON pd.domaine_id = do.id';
  251.             $where .= " AND do.id = ".$param['parametres']['domaine'];
  252.         }
  253.         if (array_key_exists('activite'$param['parametres']) and ($param['parametres']['activite'] != "")) {
  254.             $inner .= ' LEFT JOIN projet__projet_activite pa ON pa.fiche_id = kf.id';
  255.             $inner .= ' LEFT JOIN projet__activite paa ON pa.activite_id = paa.id';
  256.             $where .= " AND paa.id = ".$param['parametres']['activite'];
  257.         }
  258.         if (array_key_exists('partenaire'$param['parametres']) and ($param['parametres']['partenaire'] != "")) {
  259.             $inner .= ' LEFT JOIN commerciale__commande cmd ON cmd.fiche_id = kf.id';
  260.             $inner .= ' LEFT JOIN commerciale__article_commande accmd ON accmd.commande_id = cmd.id';
  261.             $inner .= ' LEFT JOIN commerciale__statut_commande scmd ON cmd.statut_commande_id = scmd.id';
  262.             $inner .= ' LEFT JOIN commerciale__type_document_commercial tcmd ON cmd.type_document_commercial_id = tcmd.id';
  263.             $where .= " AND scmd.ordre NOT IN (0) AND tcmd.id IN (1) AND accmd.fournisseur_id = ".$param['parametres']['partenaire'];
  264.         }
  265.         if (array_key_exists('filtre-fiche'$param['parametres']) and ($param['parametres']['filtre-fiche'] != "")) {
  266.             $where .= " AND kf.id = ".$param['parametres']['filtre-fiche'];
  267.         }
  268.         //if($where != "")
  269.         $where .= " AND ";
  270.         $where .= '(kf.archive = 0 OR kf.archive IS NULL)';
  271.         /*
  272.         $sql = 'select sum(budget) as total
  273.                     from kanban__fiche kf
  274.                     '.$inner.'
  275.                     where
  276.                     kf.dateSuppression is NULL
  277.                     and
  278.                     kf.colonne_id IN ('.$in_colonne.')
  279.                     '.$where.'
  280.                     ';
  281.         $em = $this->getEntityManager();
  282.         $stmt = $em->getConnection()->prepare($sql);
  283.         $stmt->execute();
  284.         $res =  $stmt->fetchAll();
  285.         if($res[0]["total"] == "") $res[0]["total"]="0";
  286.         return $res[0]["total"];
  287.         */
  288.         if ($in_colonne != "") {
  289.             $sql 'select kf.budget, kc.probabilite, kf.propabilite as ficheProbabilite, kcc.probabilite as colonneParenteProbabilite
  290.                     from kanban__fiche kf
  291.                     '.$inner
  292.                    .' JOIN kanban__colonne kc ON kf.colonne_id = kc.id'
  293.                    .' LEFT JOIN kanban__kanban k ON kc.kanban_id = k.id'
  294.                    .' LEFT JOIN kanban__colonne kcc ON kcc.id = k.colonne_id'
  295.                    .' LEFT JOIN kanban__kanban kk ON kcc.kanban_id = kk.id'
  296.                    .' LEFT JOIN kanban__colonne kccc ON kccc.id = kk.colonne_id'
  297.                    .' where 
  298.                     kf.dateSuppression is NULL'
  299.                    //.' and kf.colonne_id IN ('.$in_colonne.')'
  300.                    .' and (kf.colonne_id IN ('.$in_colonne.') OR kcc.id IN ('.$in_colonne.') OR kccc.id IN ('.$in_colonne.'))
  301.                     '.$where
  302.                    .' GROUP BY kf.id';
  303.         } else {
  304.             $sql 'select kf.budget, kc.probabilite, kf.propabilite as ficheProbabilite
  305.                     from kanban__fiche kf
  306.                     '.$inner
  307.                    .' JOIN kanban__colonne kc ON kf.colonne_id = kc.id'
  308.                    .' where 
  309.                     kf.dateSuppression is NULL
  310.                     '.$where
  311.                    .' GROUP BY kf.id';
  312.         }
  313.         $em   $this->getEntityManager();
  314.         $stmt $em->getConnection()->prepare($sql);
  315.         $res   $stmt->executeQuery()->fetchAllAssociative();
  316.         $total 0;
  317.         foreach ($res as $resultat) {
  318.             if ( ! empty($resultat['ficheProbabilite'])) {
  319.                 $total += floatval($resultat['ficheProbabilite']) * floatval($resultat['budget']) / 100;
  320.             } elseif ( ! empty($resultat['colonneParenteProbabilite'])) {
  321.                 $total += floatval($resultat['colonneParenteProbabilite']) * floatval($resultat['budget']) / 100;
  322.             } else {
  323.                 $total += floatval($resultat['probabilite']) * floatval($resultat['budget']) / 100;
  324.             }
  325.         }
  326.         return $total;
  327.     }
  328.     public function getTotalBudgetSansPourcentagesColonne($colonne$parametres = [], $user$chefProjet '')
  329.     {
  330.         $param['parametres'] = $parametres;
  331.         $id                  $colonne->getId();
  332.         $inner               "";
  333.         $where               'c.id ='.$id.' AND (kf.archive = 0 OR kf.archive IS NULL)'
  334.                                ." AND (sf.id IS NULL OR sf.id NOT IN (3))";
  335.         if (array_key_exists('favoris'$param['parametres']) and ($param['parametres']['favoris'] == "1")) {
  336.             $inner .= " INNER JOIN kanban__favoris ON kf.id = kanban__favoris.fiche_id";
  337.         }
  338.         if (array_key_exists('client'$param['parametres']) and ($param['parametres']['client'] != "")) {
  339.             $inner .= ' LEFT JOIN client__client cli ON cli.id = kf.client_id';
  340.             $where .= " AND cli.id = ".$param['parametres']['client'];
  341.         }
  342.         if (array_key_exists('u'$param['parametres']) and count($param['parametres']['u']) > 0) {
  343.             $where .= " AND kf.utilisateur_id IN (";
  344.             $in    "";
  345.             foreach ($param['parametres']['u'] as $key => $value) {
  346.                 $in .= $value.",";
  347.             }
  348.             $in    trim($in",");
  349.             $where .= $in.")";
  350.         }
  351.         if (is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  352.             /*
  353.                 $where .= " AND kf.utilisateur_id IN (";
  354.                 $in = "";
  355.                     $in .= $user->getId().",";
  356.                 $in = trim($in,",");
  357.                 $where .= $in.")";
  358.                 */
  359.             $where .= " AND (kf.utilisateur_id IN (".$user->getId().") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$user->getId().") ) )";
  360.         } elseif (array_key_exists('filtre-utilisateurs'$param['parametres']) and count($param['parametres']['filtre-utilisateurs']) > 0) {
  361.             /*
  362.             $where .= " AND kf.utilisateur IN (:utilisateurs)";
  363.             foreach($param['parametres']['filtre-utilisateurs'] as $key=>$value) {
  364.                 $parametres['utilisateurs'][]=$value;
  365.             }
  366.             */
  367.             //$where .= " AND kf.utilisateur_id IN (";
  368.             $in "";
  369.             foreach ($param['parametres']['filtre-utilisateurs'] as $key => $value) {
  370.                 $in .= $value.",";
  371.             }
  372.             $in trim($in",");
  373.             //$where .= $in.")";
  374.             $where .= " AND (kf.utilisateur_id IN (".$in.") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$in.") ) )";
  375.         }
  376.         if (array_key_exists('filtre-apporteurs'$param['parametres']) and count($param['parametres']['filtre-apporteurs']) > 0) {
  377.             $in "";
  378.             foreach ($param['parametres']['filtre-apporteurs'] as $key => $value) {
  379.                 $in .= $value.",";
  380.             }
  381.             $in    trim($in",");
  382.             $where .= " AND kf.apporteur_id IN (".$in.")";
  383.         }
  384.         if (array_key_exists('filtre-commerciaux'$param['parametres']) and count($param['parametres']['filtre-commerciaux']) > 0) {
  385.             $in "";
  386.             foreach ($param['parametres']['filtre-commerciaux'] as $key => $value) {
  387.                 $in .= $value.",";
  388.             }
  389.             $in    trim($in",");
  390.             $where .= " AND kf.commercial_id IN (".$in.")";
  391.         }
  392.         if (array_key_exists('filtre-chefsProjet'$param['parametres']) and count($param['parametres']['filtre-chefsProjet']) > 0) {
  393.             $in "";
  394.             foreach ($param['parametres']['filtre-chefsProjet'] as $key => $value) {
  395.                 $in .= $value.",";
  396.             }
  397.             $in    trim($in",");
  398.             $where .= " AND (kf.chef_projet_id IN (".$in.") OR (pu.id IS NOT NULL AND pu.utilisateur_id IN (".$in.") )";
  399.             if ( ! empty($chefProjet)) {
  400.                 if ($where != '') {
  401.                     $where .= ' and ';
  402.                 }
  403.                 $where .= "pu.role_id = ".$chefProjet;
  404.             }
  405.             $where .= ")";
  406.         }
  407.         if (array_key_exists('filtre-fiche'$param['parametres']) and ($param['parametres']['filtre-fiche'] != "")) {
  408.             $where .= " AND kf.id = ".$param['parametres']['filtre-fiche'];
  409.             //$parametres['fiche'] = $param['parametres']['filtre-fiche'];
  410.         }
  411.         /*
  412.         if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
  413.               //$query->join('p.ficheOrigine', 'fo');
  414.               //$where .= " AND fo.origine = :origine";
  415.             //$parametres['origine'] = $param['parametres']['or'];
  416.             $where .= " AND  kf.id IN (select fiche_id FROM kanban__fiche_origine WHERE fiche_id = kf.id and origine_id = '".$param['parametres']['or']."'  )";
  417.         }
  418.         */
  419.         if (array_key_exists('or'$param['parametres']) and ($param['parametres']['or'] != "")) {
  420.             $where .= " AND kf.origine_commande_id = ".$param['parametres']['or'];
  421.         }
  422.         if (array_key_exists('marche'$param['parametres']) and ($param['parametres']['marche'] != "")) {
  423.             $inner .= ' LEFT JOIN article__marche mr ON mr.id = kf.marche_id';
  424.             $where .= " AND mr.id = ".$param['parametres']['marche'];
  425.         }
  426.         if ( ! empty($param['parametres']['apporteur'])) {
  427.             $inner .= ' LEFT JOIN utilisateur__contact co ON co.id = kf.apporteur_id';
  428.             $where .= " AND co.id = ".$param['parametres']['apporteur'];
  429.         }
  430.         if (array_key_exists('domaine'$param['parametres']) and ($param['parametres']['domaine'] != "")) {
  431.             $inner .= ' LEFT JOIN projet__projet_domaine pd ON pd.fiche_id = kf.id';
  432.             $inner .= ' LEFT JOIN projet__domaine do ON pd.domaine_id = do.id';
  433.             $where .= " AND do.id = ".$param['parametres']['domaine'];
  434.         }
  435.         if (array_key_exists('activite'$param['parametres']) and ($param['parametres']['activite'] != "")) {
  436.             $inner .= ' LEFT JOIN projet__projet_activite pa ON pa.fiche_id = kf.id';
  437.             $inner .= ' LEFT JOIN projet__activite paa ON pa.activite_id = paa.id';
  438.             $where .= " AND paa.id = ".$param['parametres']['activite'];
  439.         }
  440.         if (array_key_exists('partenaire'$param['parametres']) and ($param['parametres']['partenaire'] != "")) {
  441.             $inner .= ' LEFT JOIN commerciale__commande cmd ON cmd.fiche_id = kf.id';
  442.             $inner .= ' LEFT JOIN commerciale__article_commande accmd ON accmd.commande_id = cmd.id';
  443.             $inner .= ' LEFT JOIN commerciale__statut_commande scmd ON cmd.statut_commande_id = scmd.id';
  444.             $inner .= ' LEFT JOIN commerciale__type_document_commercial tcmd ON cmd.type_document_commercial_id = tcmd.id';
  445.             $where .= " AND scmd.ordre NOT IN (0) AND tcmd.id IN (1) AND accmd.fournisseur_id = ".$param['parametres']['partenaire'];
  446.         }
  447.         $sql 'SELECT kf.id FROM kanban__fiche as kf '
  448.                .'JOIN kanban__colonne c ON kf.colonne_id = c.id '
  449.                .'LEFT JOIN kanban__kanban k ON c.kanban_id = k.id '
  450.                //.'LEFT JOIN kanban__colonne kc ON kc.id = k.colonne_id '
  451.                //.'LEFT JOIN kanban__kanban kck ON kc.kanban_id = kck.id '
  452.                //.'LEFT JOIN kanban__colonne kckc ON kckc.id = kck.colonne_id '
  453.                ."LEFT JOIN kanban__statut_fiche sf ON sf.id = kf.statut_fiche_id "
  454.                ."LEFT JOIN projet__projet_utilisateur pu ON pu.fiche_id = kf.id "
  455.                //.'LEFT JOIN kanban__kanban kckck ON kckc.kanban_id = kckck.id '
  456.                //.'WHERE (c.id ='.$id.' or kc.id ='.$id.' or kckc.id ='.$id.') AND (kf.archive = 0 OR kf.archive IS NULL)'
  457.                //." AND (sf.id IS NULL OR sf.id NOT IN (3))"
  458.                .$inner
  459.                .' WHERE '.$where;
  460.         $em         $this->getEntityManager();
  461.         $repo_fiche $em->getRepository(Fiche::class);
  462.         $stmt       $em->getConnection()->prepare($sql);
  463.         $res   $stmt->executeQuery()->fetchAllAssociative();
  464.         $total 0;
  465.         foreach ($res as $ficheId) {
  466.             $fiche $repo_fiche->find($ficheId);
  467.             $total += $fiche->getBudget();
  468.         }
  469.         return $total;
  470.     }
  471.     public function getRecherche($recherche$kanban$maxResults 500)
  472.     {
  473.         //$recherche = "N";
  474.         $cond "%".$recherche."%";
  475.         if (strpos($cond"*") !== false) {
  476.             $cond str_replace("*""%"$cond);
  477.         }
  478.         $where      'p.libelle LIKE :cond AND p.dateSuppression IS NULL';
  479.         $parameters = ['cond' => $cond];
  480.         if (is_object($kanban)) {
  481.             $where                .= ' AND k = :kanban';
  482.             $parameters['kanban'] = $kanban->getId();
  483.         }
  484.         $query $this->createQueryBuilder('p')
  485.                       ->select("CONCAT(p.libelle, ' (', COALESCE(p.probabilite, '--'), '%)') as libelle, p.id")
  486.                       ->join('p.kanban''k')
  487.                       ->where($where)
  488.                       ->setParameters($parameters)
  489.             //->orderBy('p.prenom', 'ASC');
  490.                       ->setFirstResult(0)
  491.                       ->setMaxResults($maxResults)
  492.                       ->orderBy('p.probabilite ASC, p.id''ASC');
  493.         $res $query->getQuery()->getResult();
  494.         return $res;
  495.     }
  496.     public function getStatutFicheColonne($fiche$colonne)
  497.     {
  498.         $em               $this->getEntityManager();
  499.         $repo_statutFiche $em->getRepository(StatutFiche::class);
  500.         $statut           null;
  501.         if ($colonne->getId() == 11) {
  502.             $statut $repo_statutFiche->find(1);//Gagné
  503.         } elseif ($colonne->getId() == 15) {
  504.             $statut $repo_statutFiche->find(2);//Perdu
  505.         } elseif ($colonne->getId() == 14) {//Terminé, on garde le même statut
  506.             $statut $fiche->getStatutFiche();
  507.         }
  508.         return $statut;
  509.     }
  510.     public function getTotalBudgetPondereColonne($colonne$parametres = [], $user$chefProjet '')
  511.     {
  512.         $param['parametres'] = $parametres;
  513.         $id                  $colonne->getId();
  514.         $inner               "";
  515.         $where               'c.id ='.$id.' AND (kf.archive = 0 OR kf.archive IS NULL)'
  516.                                ." AND (sf.id IS NULL OR sf.id NOT IN (3))";
  517.         if (array_key_exists('favoris'$param['parametres']) and ($param['parametres']['favoris'] == "1")) {
  518.             $inner .= " INNER JOIN kanban__favoris ON kf.id = kanban__favoris.fiche_id";
  519.         }
  520.         if (array_key_exists('client'$param['parametres']) and ($param['parametres']['client'] != "")) {
  521.             $inner .= ' LEFT JOIN client__client cli ON cli.id = kf.client_id';
  522.             $where .= " AND cli.id = ".$param['parametres']['client'];
  523.         }
  524.         if (array_key_exists('u'$param['parametres']) and count($param['parametres']['u']) > 0) {
  525.             $where .= " AND kf.utilisateur_id IN (";
  526.             $in    "";
  527.             foreach ($param['parametres']['u'] as $key => $value) {
  528.                 $in .= $value.",";
  529.             }
  530.             $in    trim($in",");
  531.             $where .= $in.")";
  532.         }
  533.         if (is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  534.             /*
  535.                 $where .= " AND kf.utilisateur_id IN (";
  536.                 $in = "";
  537.                     $in .= $user->getId().",";
  538.                 $in = trim($in,",");
  539.                 $where .= $in.")";
  540.                 */
  541.             $where .= " AND (kf.utilisateur_id IN (".$user->getId().") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$user->getId().") ) )";
  542.         } elseif (array_key_exists('filtre-utilisateurs'$param['parametres']) and count($param['parametres']['filtre-utilisateurs']) > 0) {
  543.             /*
  544.             $where .= " AND kf.utilisateur IN (:utilisateurs)";
  545.             foreach($param['parametres']['filtre-utilisateurs'] as $key=>$value) {
  546.                 $parametres['utilisateurs'][]=$value;
  547.             }
  548.             */
  549.             //$where .= " AND kf.utilisateur_id IN (";
  550.             $in "";
  551.             foreach ($param['parametres']['filtre-utilisateurs'] as $key => $value) {
  552.                 $in .= $value.",";
  553.             }
  554.             $in trim($in",");
  555.             //$where .= $in.")";
  556.             $where .= " AND (kf.utilisateur_id IN (".$in.") or kf.id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$in.") ) )";
  557.         }
  558.         if (array_key_exists('filtre-apporteurs'$param['parametres']) and count($param['parametres']['filtre-apporteurs']) > 0) {
  559.             $in "";
  560.             foreach ($param['parametres']['filtre-apporteurs'] as $key => $value) {
  561.                 $in .= $value.",";
  562.             }
  563.             $in    trim($in",");
  564.             $where .= " AND kf.apporteur_id IN (".$in.")";
  565.         }
  566.         if (array_key_exists('filtre-commerciaux'$param['parametres']) and count($param['parametres']['filtre-commerciaux']) > 0) {
  567.             $in "";
  568.             foreach ($param['parametres']['filtre-commerciaux'] as $key => $value) {
  569.                 $in .= $value.",";
  570.             }
  571.             $in    trim($in",");
  572.             $where .= " AND kf.commercial_id IN (".$in.")";
  573.         }
  574.         if (array_key_exists('filtre-chefsProjet'$param['parametres']) and count($param['parametres']['filtre-chefsProjet']) > 0) {
  575.             $in "";
  576.             foreach ($param['parametres']['filtre-chefsProjet'] as $key => $value) {
  577.                 $in .= $value.",";
  578.             }
  579.             $in    trim($in",");
  580.             $where .= " AND (kf.chef_projet_id IN (".$in.") OR (pu.id IS NOT NULL AND pu.utilisateur_id IN (".$in.") )";
  581.             if ( ! empty($chefProjet)) {
  582.                 if ($where != '') {
  583.                     $where .= ' and ';
  584.                 }
  585.                 $where .= "pu.role_id = ".$chefProjet;
  586.             }
  587.             $where .= ")";
  588.         }
  589.         if (array_key_exists('filtre-fiche'$param['parametres']) and ($param['parametres']['filtre-fiche'] != "")) {
  590.             $where .= " AND kf.id = ".$param['parametres']['filtre-fiche'];
  591.             //$parametres['fiche'] = $param['parametres']['filtre-fiche'];
  592.         }
  593.         /*
  594.         if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
  595.               //$query->join('p.ficheOrigine', 'fo');
  596.               //$where .= " AND fo.origine = :origine";
  597.             //$parametres['origine'] = $param['parametres']['or'];
  598.             $where .= " AND  kf.id IN (select fiche_id FROM kanban__fiche_origine WHERE fiche_id = kf.id and origine_id = '".$param['parametres']['or']."'  )";
  599.         }
  600.         */
  601.         if (array_key_exists('or'$param['parametres']) and ($param['parametres']['or'] != "")) {
  602.             $where .= " AND kf.origine_commande_id = ".$param['parametres']['or'];
  603.         }
  604.         if (array_key_exists('marche'$param['parametres']) and ($param['parametres']['marche'] != "")) {
  605.             $inner .= ' LEFT JOIN article__marche mr ON mr.id = kf.marche_id';
  606.             $where .= " AND mr.id = ".$param['parametres']['marche'];
  607.         }
  608.         if ( ! empty($param['parametres']['apporteur'])) {
  609.             $inner .= ' LEFT JOIN utilisateur__contact co ON co.id = kf.apporteur_id';
  610.             $where .= " AND co.id = ".$param['parametres']['apporteur'];
  611.         }
  612.         if (array_key_exists('domaine'$param['parametres']) and ($param['parametres']['domaine'] != "")) {
  613.             $inner .= ' LEFT JOIN projet__projet_domaine pd ON pd.fiche_id = kf.id';
  614.             $inner .= ' LEFT JOIN projet__domaine do ON pd.domaine_id = do.id';
  615.             $where .= " AND do.id = ".$param['parametres']['domaine'];
  616.         }
  617.         if (array_key_exists('activite'$param['parametres']) and ($param['parametres']['activite'] != "")) {
  618.             $inner .= ' LEFT JOIN projet__projet_activite pa ON pa.fiche_id = kf.id';
  619.             $inner .= ' LEFT JOIN projet__activite paa ON pa.activite_id = paa.id';
  620.             $where .= " AND paa.id = ".$param['parametres']['activite'];
  621.         }
  622.         if (array_key_exists('partenaire'$param['parametres']) and ($param['parametres']['partenaire'] != "")) {
  623.             $inner .= ' LEFT JOIN commerciale__commande cmd ON cmd.fiche_id = kf.id';
  624.             $inner .= ' LEFT JOIN commerciale__article_commande accmd ON accmd.commande_id = cmd.id';
  625.             $inner .= ' LEFT JOIN commerciale__statut_commande scmd ON cmd.statut_commande_id = scmd.id';
  626.             $inner .= ' LEFT JOIN commerciale__type_document_commercial tcmd ON cmd.type_document_commercial_id = tcmd.id';
  627.             $where .= " AND scmd.ordre NOT IN (0) AND tcmd.id IN (1) AND accmd.fournisseur_id = ".$param['parametres']['partenaire'];
  628.         }
  629.         $sql 'SELECT kf.id FROM kanban__fiche as kf '
  630.                .'JOIN kanban__colonne c ON kf.colonne_id = c.id '
  631.                .'LEFT JOIN kanban__kanban k ON c.kanban_id = k.id '
  632.                //.'LEFT JOIN kanban__colonne kc ON kc.id = k.colonne_id '
  633.                //.'LEFT JOIN kanban__kanban kck ON kc.kanban_id = kck.id '
  634.                //.'LEFT JOIN kanban__colonne kckc ON kckc.id = kck.colonne_id '
  635.                ."LEFT JOIN kanban__statut_fiche sf ON sf.id = kf.statut_fiche_id "
  636.                ."LEFT JOIN projet__projet_utilisateur pu ON pu.fiche_id = kf.id "
  637.                //.'LEFT JOIN kanban__kanban kckck ON kckc.kanban_id = kckck.id '
  638.                .$inner
  639.                .' WHERE '.$where;
  640.         $em         $this->getEntityManager();
  641.         $repo_fiche $em->getRepository(Fiche::class);
  642.         $stmt       $em->getConnection()->prepare($sql);
  643.         $res          $stmt->executeQuery()->fetchAllAssociative();
  644.         $totalPondere 0;
  645.         foreach ($res as $ficheId) {
  646.             $fiche $repo_fiche->find($ficheId);
  647.             $totalPondere += $repo_fiche->getMontantPondereFiche($fiche);
  648.         }
  649.         return $totalPondere;
  650.     }
  651. }