src/Service/Kanban/KanbanService.php line 1589

Open in your IDE?
  1. <?php
  2. namespace App\Service\Kanban;
  3. use App\Entity\GestionComerciale\ArticleCommande;
  4. use App\Entity\GestionComerciale\Commande;
  5. use App\Entity\Kanban\Equipe;
  6. use App\Entity\Notes\Note;
  7. use App\Entity\Utilisateur\Contact;
  8. use Doctrine\ORM\EntityManager;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\DependencyInjection\Container;
  11. use App\Entity\Kanban\Favoris;
  12. use App\Entity\Kanban\Fiche;
  13. use App\Entity\Kanban\Kanban;
  14. use App\Entity\Kanban\Region;
  15. use App\Entity\Kanban\Raison;
  16. use App\Entity\Kanban\Colonne;
  17. use App\Entity\Utilisateur\Utilisateur;
  18. use App\Entity\Notes\Categorie;
  19. use App\Entity\Clients\Client;
  20. use Symfony\Component\Form\FormError;
  21. use Symfony\Component\Security\Core\Security;
  22. use Symfony\Component\Validator\ExecutionContext;
  23. class KanbanService {
  24.     private $em;
  25.     private Security $security;
  26.     public function __construct(EntityManagerInterface $emSecurity $security)
  27.     {
  28.         $this->em $em;
  29.         $this->security $security;
  30.     }
  31.     
  32.    
  33.    
  34.     public function est_autorise_voir_fiche($id_fiche) {
  35.     
  36.         $user $this->security->getUser();
  37.         if(is_object($user->getType()) and ($user->getType()->getId() == "1" or $user->getType()->getId() == "2")) {
  38.             return true;
  39.         } 
  40.         else if(is_object($user->getType())) {
  41.             $repo_fiche $this->em->getRepository(Fiche::class);
  42.             $fiche $repo_fiche->find($id_fiche);
  43.             
  44.             if($fiche->getUtilisateur()->getId() == $user->getId()) {
  45.                 return true;
  46.             }
  47.             else {
  48.                 $repo_equipe $this->em->getRepository(Equipe::class);
  49.                 $equipier_obj $repo_equipe->findOneBy(["fiche" =>$fiche"utilisateur" =>$user]);
  50.                 if(is_object($equipier_obj)) return true;
  51.             }
  52.             
  53.         }
  54.         
  55.         return false;
  56.     }
  57.     
  58.     public function getTunnels() {
  59.         
  60.         $repo_kanban $this->em->getRepository(Kanban::class);
  61.         $tunnels $repo_kanban->getTunnels();
  62.         return $tunnels;
  63.         
  64.         
  65.         
  66.     }
  67.     
  68.     public function equipierDebutee($parametres = []) {
  69.         
  70.         $conn $this->em->getConnection();
  71.         $sql 'SELECT utilisateur_id,sum(budget) as budget_total
  72.                 FROM 
  73.                 kanban__fiche 
  74.                 WHERE                 
  75.                 dateSuppression is null
  76.                 AND 
  77.                 date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  78.                 AND                
  79.                 date <= "'.$parametres["fin_filtre_date"].' 23:59:59"    
  80.                 GROUP BY utilisateur_id
  81.                 ORDER BY budget_total desc
  82.                 ';
  83.         
  84.         $stmt $conn->executeQuery($sql);
  85.         $total $stmt->fetchAllAssociative();
  86.         
  87.         //print_r($total);
  88.         //echo "<br/><br/>";
  89.         
  90.         if(is_array($total) && count($total)>0) {
  91.             return $total[0];
  92.         }
  93.         return [];
  94.         //return $total[0]["total"];
  95.     }
  96.     public function equipierConclue($parametres = []) {
  97.         
  98.         $conn $this->em->getConnection();
  99.         $sql 'SELECT utilisateur_gagne_perdu_id as utilisateur_id,sum(budget) as budget_total
  100.                 FROM 
  101.                 kanban__fiche 
  102.                 WHERE     
  103.                 utilisateur_gagne_perdu_id is not NULL
  104.                 AND 
  105.                 statut_fiche_id = 1 
  106.                 AND           
  107.                 dateSuppression is null
  108.                 AND 
  109.                 date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  110.                 AND                
  111.                 date <= "'.$parametres["fin_filtre_date"].' 23:59:59"    
  112.                 GROUP BY utilisateur_gagne_perdu_id
  113.                 ORDER BY budget_total desc
  114.                 ';
  115.         
  116.         $stmt $conn->executeQuery($sql);
  117.         $total $stmt->fetchAllAssociative();
  118.         
  119.         //print_r($total);
  120.         //echo "<br/><br/>";
  121.         
  122.         if(is_array($total) && count($total)>0) {
  123.             return $total[0];
  124.         }
  125.         return [];
  126.         //return $total[0]["total"];
  127.     }
  128.     
  129.     
  130.     public function totalGagneesAffaireCa($parametres = []) {
  131.            
  132.            $user $this->security->getUser();
  133.                     
  134.         $where_equipiers "";
  135.         $where_activite "";
  136.         $where_type_produit "";
  137.         $join_client "";
  138.         
  139.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  140.             //activite        
  141.             $in_type_produit_id "";                
  142.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  143.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  144.             }
  145.             if($in_type_produit_id != "") {
  146.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  147.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  148.             }
  149.         }
  150.         
  151.         
  152.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  153.             //activite                        
  154.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  155.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  156.         }
  157.        
  158.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  159.             foreach($parametres["equipiers"] as $e) {
  160.                 $where_equipiers .= $e.",";
  161.             }
  162.         }
  163.        
  164.        if($where_equipiers != "") {
  165.            $where_equipiers trim($where_equipiers,',');
  166.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  167.        }      
  168.        
  169.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  170.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  171.        }          
  172.        
  173.        $where_tunnel "";  
  174.         if (array_key_exists('tunnel'$parametres) && count($parametres["tunnel"]) > 0) {
  175.             
  176.             $in_kanban "";            
  177.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  178.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  179.             $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  180.             $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  181.             
  182.             $where "";
  183.             $in_colonne "";
  184.             
  185.             if(is_object($kanban_obj->getColonne())) 
  186.             {
  187.                 
  188.                 $colids = [];
  189.                 $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  190.                 
  191.                 foreach($colids as $coll) {
  192.                     $in_colonne .= $coll->getId().",";
  193.                 }                                
  194.                 $in_colonne trim($in_colonne,",,");                    
  195.                 $where_tunnel ' AND colonne_id IN ('.$in_colonne.')';                                            
  196.             }
  197.             else {
  198.                 
  199.                 $where_tunnel 'AND kanban_id IN ('.$parametres["tunnel"].')';
  200.             }
  201.         }
  202.         
  203.         $sql_region "";    
  204.            if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  205.             $sql_region " AND f.region_id = ".$parametres['region'];         
  206.             //kanban__fiche   
  207.              
  208.         
  209.                 
  210.         $conn $this->em->getConnection();
  211.         $sql 'SELECT SUM(budget) as total
  212.                 FROM 
  213.                 kanban__fiche as f
  214.                 '.$join_client.'
  215.                 WHERE 
  216.                 statut_fiche_id = 1    
  217.                 AND 
  218.                 dateSuppression is null
  219.                 AND 
  220.                 f.date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  221.                 AND                
  222.                 f.date <= "'.$parametres["fin_filtre_date"].' 23:59:59"    
  223.                 '.$where_equipiers.'            
  224.                 '.$where_tunnel.'
  225.                 '.$where_activite.'            
  226.                 '.$where_type_produit.'            
  227.                 '.$sql_region.'            
  228.                 ';
  229.         
  230.         $stmt $conn->executeQuery($sql);
  231.         $total $stmt->fetchAllAssociative();
  232.         return $total[0]["total"];
  233.     }
  234.     
  235.     
  236.     public function totalGagneesAffaire($parametres = []) {
  237.              
  238.            $user $this->security->getUser();  
  239.         $where_equipiers "";        
  240.         $where_activite "";
  241.         $join_client "";
  242.         $where_type_produit "";
  243.         
  244.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  245.             //activite        
  246.             $in_type_produit_id "";                
  247.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  248.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  249.             }
  250.             if($in_type_produit_id != "") {
  251.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  252.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  253.             }
  254.         }
  255.         
  256.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  257.             //activite                        
  258.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  259.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  260.         }
  261.        
  262.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  263.             foreach($parametres["equipiers"] as $e) {
  264.                 $where_equipiers .= $e.",";
  265.             }
  266.         }
  267.        
  268.        if($where_equipiers != "") {
  269.            $where_equipiers trim($where_equipiers,',');
  270.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  271.        }                   
  272.                
  273.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  274.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  275.        }
  276.        
  277.        $where_tunnel "";  
  278.         if (array_key_exists('tunnel'$parametres) && count($parametres["tunnel"]) > 0) {
  279.             
  280.             $in_kanban "";            
  281.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  282.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  283.             $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  284.             $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  285.             
  286.             $where "";
  287.             $in_colonne "";
  288.             
  289.             if(is_object($kanban_obj->getColonne())) 
  290.             {
  291.                 
  292.                 $colids = [];
  293.                 $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  294.                 
  295.                 foreach($colids as $coll) {
  296.                     $in_colonne .= $coll->getId().",";
  297.                 }                                
  298.                 $in_colonne trim($in_colonne,",,");                    
  299.                 $where_tunnel ' AND colonne_id IN ('.$in_colonne.')';                                            
  300.             }
  301.             else {
  302.                 
  303.                 $where_tunnel 'AND kanban_id IN ('.$parametres["tunnel"].')';
  304.             }
  305.         }
  306.               
  307.                $sql_region "";    
  308.             if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  309.             $sql_region " AND f.region_id = ".$parametres['region'];         
  310.             //kanban__fiche   
  311.              
  312.         }            
  313.                 
  314.         $conn $this->em->getConnection();
  315.         $sql 'SELECT count(*) as total
  316.                 FROM 
  317.                 kanban__fiche as f
  318.                 '.$join_client.'
  319.                 WHERE 
  320.                 statut_fiche_id = 1    
  321.                 AND 
  322.                 dateSuppression is null
  323.                 AND 
  324.                 f.date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  325.                 AND                
  326.                 f.date <= "'.$parametres["fin_filtre_date"].' 23:59:59"
  327.                 '.$where_equipiers.'                
  328.                 '.$where_tunnel.'                
  329.                 '.$where_activite.'
  330.                 '.$where_type_produit.'
  331.                 '.$sql_region.'
  332.                 ';
  333.         
  334.         $stmt $conn->executeQuery($sql);
  335.         $total $stmt->fetchAllAssociative();
  336.         return $total[0]["total"];
  337.     }
  338.     
  339.     
  340.     public function totalPerduesAffaireCa($parametres = []) {
  341.         
  342.         $user $this->security->getUser();
  343.         $where_equipiers "";
  344.         $where_activite "";
  345.         $where_type_produit "";
  346.         $join_client "";
  347.         
  348.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  349.             //activite        
  350.             $in_type_produit_id "";                
  351.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  352.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  353.             }
  354.             if($in_type_produit_id != "") {
  355.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  356.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  357.             }
  358.         }
  359.         
  360.         
  361.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  362.             //activite                        
  363.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  364.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  365.         }
  366.        
  367.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  368.             foreach($parametres["equipiers"] as $e) {
  369.                 $where_equipiers .= $e.",";
  370.             }
  371.         }
  372.        
  373.        if($where_equipiers != "") {
  374.            $where_equipiers trim($where_equipiers,',');
  375.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  376.        }
  377.            
  378.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  379.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  380.        }
  381.        
  382.        $where_tunnel "";  
  383.         if (array_key_exists('tunnel'$parametres) && count($parametres["tunnel"]) > 0) {
  384.             
  385.             $in_kanban "";            
  386.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  387.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  388.             $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  389.             $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  390.             
  391.             $where "";
  392.             $in_colonne "";
  393.             
  394.             if(is_object($kanban_obj->getColonne())) 
  395.             {
  396.                 
  397.                 $colids = [];
  398.                 $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  399.                 
  400.                 foreach($colids as $coll) {
  401.                     $in_colonne .= $coll->getId().",";
  402.                 }                                
  403.                 $in_colonne trim($in_colonne,",,");                    
  404.                 $where_tunnel ' AND colonne_id IN ('.$in_colonne.')';                                            
  405.             }
  406.             else {
  407.                 
  408.                 $where_tunnel 'AND kanban_id IN ('.$parametres["tunnel"].')';
  409.             }
  410.         }
  411.         
  412.         $sql_region "";    
  413.             if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  414.             $sql_region " AND f.region_id = ".$parametres['region'];         
  415.             //kanban__fiche   
  416.              
  417.         }     
  418.            
  419.         $conn $this->em->getConnection();
  420.         $sql 'SELECT SUM(budget) as total
  421.                 FROM 
  422.                 kanban__fiche as f
  423.                 '.$join_client.'
  424.                 WHERE 
  425.                 statut_fiche_id = 2    
  426.                 AND 
  427.                 dateSuppression is null
  428.                 AND 
  429.                 f.date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  430.                 AND                
  431.                 f.date <= "'.$parametres["fin_filtre_date"].' 23:59:59"    
  432.                 '.$where_equipiers.'            
  433.                 '.$where_tunnel.'    
  434.                 '.$where_activite.'        
  435.                 '.$where_type_produit.'        
  436.                 '.$sql_region.'        
  437.                 ';
  438.         
  439.         $stmt $conn->executeQuery($sql);
  440.         $total $stmt->fetchAllAssociative();
  441.         return $total[0]["total"];
  442.     }
  443.     
  444.     
  445.     public function totalPerduesAffaire($parametres = []) {
  446.         
  447.         $user $this->security->getUser();
  448.         $where_equipiers "";
  449.         $where_activite "";
  450.         $where_type_produit "";
  451.         $join_client "";
  452.         
  453.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  454.             //activite        
  455.             $in_type_produit_id "";                
  456.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  457.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  458.             }
  459.             if($in_type_produit_id != "") {
  460.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  461.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  462.             }
  463.         }
  464.         
  465.         
  466.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  467.             //activite                        
  468.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  469.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  470.         }
  471.        
  472.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  473.             foreach($parametres["equipiers"] as $e) {
  474.                 $where_equipiers .= $e.",";
  475.             }
  476.         }
  477.        
  478.        if($where_equipiers != "") {
  479.            $where_equipiers trim($where_equipiers,',');
  480.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  481.        }
  482.        
  483.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  484.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  485.        }
  486.        
  487.        $where_tunnel "";  
  488.         if (array_key_exists('tunnel'$parametres) && count($parametres["tunnel"]) > 0) {
  489.             
  490.             $in_kanban "";            
  491.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  492.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  493.             $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  494.             $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  495.             
  496.             $where "";
  497.             $in_colonne "";
  498.             
  499.             if(is_object($kanban_obj->getColonne())) 
  500.             {
  501.                 
  502.                 $colids = [];
  503.                 $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  504.                 
  505.                 foreach($colids as $coll) {
  506.                     $in_colonne .= $coll->getId().",";
  507.                 }                                
  508.                 $in_colonne trim($in_colonne,",,");                    
  509.                 $where_tunnel ' AND colonne_id IN ('.$in_colonne.')';                                            
  510.             }
  511.             else {
  512.                 
  513.                 $where_tunnel 'AND kanban_id IN ('.$parametres["tunnel"].')';
  514.             }
  515.         }
  516.                 
  517.                $sql_region "";    
  518.             if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  519.             $sql_region " AND f.region_id = ".$parametres['region'];         
  520.             //kanban__fiche   
  521.              
  522.         }         
  523.                 
  524.         $conn $this->em->getConnection();
  525.         $sql 'SELECT count(*) as total
  526.                 FROM 
  527.                 kanban__fiche as f
  528.                 '.$join_client.'
  529.                 WHERE 
  530.                 statut_fiche_id = 2    
  531.                 AND 
  532.                 dateSuppression is null
  533.                 AND 
  534.                 f.date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  535.                 AND                
  536.                 f.date <= "'.$parametres["fin_filtre_date"].' 23:59:59"        
  537.                 '.$where_equipiers.'        
  538.                 '.$where_tunnel.'        
  539.                 '.$where_activite.'
  540.                 '.$where_type_produit.'
  541.                 '.$sql_region.'
  542.                 ';
  543.         
  544.         $stmt $conn->executeQuery($sql);
  545.         $total $stmt->fetchAllAssociative();
  546.         return $total[0]["total"];
  547.     }
  548.     
  549.     
  550.     public function totalInitieesAffaireCa($parametres = []) {
  551.         
  552.         
  553.         $user $this->security->getUser();
  554.         
  555.                         
  556.         $where_equipiers "";
  557.         $where_activite "";
  558.         $where_type_produit "";
  559.         $join_client "";
  560.         
  561.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  562.             //activite        
  563.             $in_type_produit_id "";                
  564.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  565.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  566.             }
  567.             if($in_type_produit_id != "") {
  568.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  569.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  570.             }
  571.         }
  572.         
  573.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  574.             //activite                        
  575.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  576.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  577.         }
  578.        
  579.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  580.             foreach($parametres["equipiers"] as $e) {
  581.                 $where_equipiers .= $e.",";
  582.             }
  583.         }
  584.        
  585.        if($where_equipiers != "") {
  586.            $where_equipiers trim($where_equipiers,',');
  587.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  588.        }
  589.        
  590.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  591.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  592.        }
  593.               
  594.         $where_tunnel "";  
  595.         if (array_key_exists('tunnel'$parametres) && count($parametres["tunnel"]) > 0) {
  596.             
  597.             $in_kanban "";            
  598.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  599.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  600.             $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  601.             $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  602.             
  603.             $where "";
  604.             $in_colonne "";
  605.             
  606.             if(is_object($kanban_obj->getColonne())) 
  607.             {
  608.                 
  609.                 $colids = [];
  610.                 $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  611.                 
  612.                 foreach($colids as $coll) {
  613.                     $in_colonne .= $coll->getId().",";
  614.                 }                                
  615.                 $in_colonne trim($in_colonne,",,");                    
  616.                 $where_tunnel ' AND colonne_id IN ('.$in_colonne.')';                                            
  617.             }
  618.             else {
  619.                 
  620.                 $where_tunnel 'AND kanban_id IN ('.$parametres["tunnel"].')';
  621.             }
  622.         }       
  623.             $sql_region "";    
  624.             if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  625.             $sql_region " AND f.region_id = ".$parametres['region'];         
  626.             //kanban__fiche   
  627.              
  628.         }
  629.          
  630.                 
  631.         $conn $this->em->getConnection();
  632.         $sql 'SELECT SUM(budget) as total
  633.                 FROM 
  634.                 kanban__fiche as f
  635.                 '.$join_client.'
  636.                 WHERE 
  637.                 statut_fiche_id IS NULL    
  638.                 AND 
  639.                 dateSuppression is null
  640.                 AND 
  641.                 f.date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  642.                 AND                
  643.                 f.date <= "'.$parametres["fin_filtre_date"].' 23:59:59"        
  644.                 '.$where_equipiers.'        
  645.                 '.$where_tunnel.'        
  646.                 '.$where_activite.'
  647.                 '.$where_type_produit.'
  648.                 '.$sql_region.'
  649.                 ';
  650.         
  651.         
  652.         
  653.         $stmt $conn->executeQuery($sql);
  654.         $total $stmt->fetchAllAssociative();
  655.         return $total[0]["total"];
  656.     }
  657.     
  658.     
  659.     public function totalInitieesAffaire($parametres = []) {
  660.         
  661.         $user $this->security->getUser();
  662.         $where_equipiers "";
  663.         
  664.         $where_activite "";
  665.         $where_type_produit "";
  666.         $join_client "";
  667.        
  668.        
  669.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  670.             //activite        
  671.             $in_type_produit_id "";                
  672.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  673.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  674.             }
  675.             if($in_type_produit_id != "") {
  676.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  677.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  678.             }
  679.         }
  680.         
  681.         
  682.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  683.             //activite                        
  684.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  685.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  686.         }
  687.        
  688.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  689.             foreach($parametres["equipiers"] as $e) {
  690.                 $where_equipiers .= $e.",";
  691.             }
  692.         }
  693.        
  694.        if($where_equipiers != "") {
  695.            $where_equipiers trim($where_equipiers,',');
  696.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  697.        }
  698.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  699.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  700.        }
  701.        
  702.        $where_tunnel "";  
  703.         if (array_key_exists('tunnel'$parametres) && count($parametres["tunnel"]) > 0) {
  704.             
  705.             $in_kanban "";            
  706.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  707.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  708.             $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  709.             $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  710.             
  711.             $where "";
  712.             $in_colonne "";
  713.             
  714.             if(is_object($kanban_obj->getColonne())) 
  715.             {
  716.                 
  717.                 $colids = [];
  718.                 $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  719.                 
  720.                 foreach($colids as $coll) {
  721.                     $in_colonne .= $coll->getId().",";
  722.                 }                                
  723.                 $in_colonne trim($in_colonne,",,");                    
  724.                 $where_tunnel ' AND colonne_id IN ('.$in_colonne.')';                                            
  725.             }
  726.             else {
  727.                 
  728.                 $where_tunnel 'AND kanban_id IN ('.$parametres["tunnel"].')';
  729.             }
  730.         }
  731.         
  732.             $sql_region "";    
  733.             if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  734.             $sql_region " AND f.region_id = ".$parametres['region'];         
  735.             //kanban__fiche   
  736.              
  737.         }
  738.             
  739.         $conn $this->em->getConnection();
  740.         $sql 'SELECT count(*) as total
  741.                 FROM 
  742.                 kanban__fiche as f
  743.                 '.$join_client.'
  744.                 WHERE 
  745.                 statut_fiche_id IS NULL    
  746.                 AND 
  747.                 dateSuppression is null
  748.                 AND 
  749.                 f.date >= "'.$parametres["debut_filtre_date"].' 00:00:00"
  750.                 AND                
  751.                 f.date <= "'.$parametres["fin_filtre_date"].' 23:59:59"    
  752.                 '.$where_equipiers.'            
  753.                 '.$where_tunnel.'            
  754.                 '.$where_activite.'            
  755.                 '.$where_type_produit.'            
  756.                 '.$sql_region.'            
  757.                 ';
  758.         
  759.         $stmt $conn->executeQuery($sql);
  760.         $total $stmt->fetchAllAssociative();
  761.         return $total[0]["total"];
  762.     }
  763.     
  764.     
  765.     
  766.     
  767.     
  768.     public function totalAffaireCommandeesTypeProduit($typeProduit="",$parametres = []) {
  769.         
  770.         $user $this->security->getUser();
  771.         $where_equipiers "";
  772.        
  773.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  774.             foreach($parametres["equipiers"] as $e) {
  775.                 $where_equipiers .= $e.",";
  776.             }
  777.         }
  778.        
  779.        if($where_equipiers != "") {
  780.            $where_equipiers trim($where_equipiers,',');
  781.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  782.        }
  783.                
  784.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  785.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  786.        }
  787.         
  788.         $conn $this->em->getConnection();
  789.         $sql 'SELECT count(*) as total
  790.                 FROM 
  791.                 kanban__fiche     
  792.                 WHERE 
  793.                 statut_fiche_id = 1    
  794.                 '.$where_equipiers.'        
  795.                 ';
  796.         
  797.         
  798.         if($typeProduit != "") {
  799.             $sql .= "AND id IN (SELECT fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id =".$typeProduit.")";
  800.         }
  801.         
  802.         $stmt $conn->executeQuery($sql);
  803.         $total $stmt->fetchAllAssociative();
  804.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  805.         
  806.         return $total[0]["total"];
  807.     }
  808.     
  809.      
  810.     public function totalAffairePerduesTypeProduit($typeProduit="",$parametres = []) {
  811.         $user $this->security->getUser();
  812.         $where_equipiers "";
  813.        
  814.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  815.             foreach($parametres["equipiers"] as $e) {
  816.                 $where_equipiers .= $e.",";
  817.             }
  818.         }
  819.        
  820.        if($where_equipiers != "") {
  821.            $where_equipiers trim($where_equipiers,',');
  822.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  823.        }
  824.         
  825.         if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  826.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  827.         }
  828.         
  829.         
  830.         $conn $this->em->getConnection();
  831.         $sql 'SELECT count(*) as total
  832.                 FROM 
  833.                 kanban__fiche 
  834.                 WHERE 
  835.                 statut_fiche_id = 2    
  836.                 '.$where_equipiers.'    
  837.                 ';
  838.                 
  839.         if($typeProduit != "") {
  840.             $sql .= "AND id IN (SELECT fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id =".$typeProduit.")";
  841.         }
  842.                 
  843.         $stmt $conn->executeQuery($sql);
  844.         $total $stmt->fetchAllAssociative();
  845.         
  846.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  847.         
  848.         return $total[0]["total"];
  849.     } 
  850.     
  851.     
  852.         
  853.     
  854.     
  855.     public function totalAffaireCommandees($colonne="",$parametres = []) {
  856.         
  857.         $user $this->security->getUser();
  858.         $where_equipiers "";
  859.        
  860.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  861.             foreach($parametres["equipiers"] as $e) {
  862.                 $where_equipiers .= $e.",";
  863.             }
  864.         }
  865.        
  866.        if($where_equipiers != "") {
  867.            $where_equipiers trim($where_equipiers,',');
  868.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  869.        }
  870.         
  871.         if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  872.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  873.         }
  874.         
  875.         $conn $this->em->getConnection();
  876.         $sql 'SELECT count(*) as total
  877.                 FROM 
  878.                 kanban__fiche 
  879.                 WHERE 
  880.                 statut_fiche_id = 1    
  881.                 '.$where_equipiers.'                
  882.                 ';
  883.         if($colonne != "") {
  884.             $in_colonne $colonne;
  885.             
  886.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  887.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  888.             
  889.             $colonne_obj $repo_colonnes->find($colonne);
  890.             $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne_obj]);
  891.                     
  892.             
  893.             //if($colonne == 4) {
  894.             if(is_object($colonne_obj) && is_object($kanban_colonne_obj)) {
  895.                 $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  896.                 
  897.                 $in_colonne "";
  898.                 foreach ($colonnes as $c) {
  899.                     $in_colonne .= $c->getId().",";
  900.                 }
  901.                 $in_colonne trim($in_colonne,",,");
  902.             }
  903.             
  904.             //echo "<div>IN ".$in_colonne."</div>";
  905.             
  906.             $sql .= " AND colonne_id IN (".$in_colonne.")";
  907.         }
  908.         $stmt $conn->executeQuery($sql);
  909.         $total $stmt->fetchAllAssociative();
  910.                         
  911.         //echo $sql;        
  912.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  913.         
  914.         return $total[0]["total"];
  915.     } 
  916.     
  917.     
  918.     
  919.     public function totalAffairePerdues($colonne="",$parametres = []) {
  920.         
  921.         $user $this->security->getUser();
  922.         $where_equipiers "";
  923.        
  924.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  925.             foreach($parametres["equipiers"] as $e) {
  926.                 $where_equipiers .= $e.",";
  927.             }
  928.         }
  929.        
  930.        if($where_equipiers != "") {
  931.            $where_equipiers trim($where_equipiers,',');
  932.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  933.        }
  934.        
  935.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  936.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  937.        }
  938.         
  939.         
  940.         $conn $this->em->getConnection();
  941.         $sql 'SELECT count(*) as total
  942.                 FROM 
  943.                 kanban__fiche 
  944.                 WHERE 
  945.                 statut_fiche_id = 2    
  946.                 '.$where_equipiers.'    
  947.                 ';
  948.         
  949.         if($colonne != "") {
  950.             $in_colonne $colonne;
  951.             
  952.             $repo_colonnes =  $this->em->getRepository(Colonne::class);
  953.             $repo_kanban =  $this->em->getRepository(Kanban::class);
  954.             
  955.             $colonne_obj $repo_colonnes->find($colonne);
  956.             $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne_obj]);
  957.                     
  958.             
  959.             //if($colonne == 4) {
  960.             if(is_object($colonne_obj) && is_object($kanban_colonne_obj)) {
  961.                 $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  962.                 
  963.                 $in_colonne "";
  964.                 foreach ($colonnes as $c) {
  965.                     $in_colonne .= $c->getId().",";
  966.                 }
  967.                 $in_colonne trim($in_colonne,",,");
  968.             }
  969.             
  970.             //echo "<div>IN ".$in_colonne."</div>";
  971.             
  972.             $sql .= " AND colonne_id IN (".$in_colonne.")";
  973.         }
  974.     
  975.         $stmt $conn->executeQuery($sql);
  976.         $total $stmt->fetchAllAssociative();
  977.         
  978.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  979.         
  980.         return $total[0]["total"];
  981.     } 
  982.        
  983.     public function statColonneStatut(Colonne $colonne,$statut_affaire,$parametres = []) {
  984.         //print_r($parametres);
  985.         //echo "<div>".$utilisateur->getReference()."</div>";
  986.         
  987.         $conn $this->em->getConnection();        
  988.         $in_colonne $colonne->getId();        
  989.         //if(is_object($colonne->getKanban()) && is_object($colonne->getKanban()->getColonne())) {
  990.             
  991.         
  992.             
  993.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  994.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  995.         $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne]);
  996.         
  997.         if(is_object($kanban_colonne_obj)) {
  998.             $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  999.             
  1000.             $in_colonne "";
  1001.             foreach ($colonnes as $c) {
  1002.                 $in_colonne .= $c->getId().",";
  1003.             }
  1004.             $in_colonne trim($in_colonne,",,");
  1005.         }
  1006.         
  1007.         
  1008.         
  1009.         
  1010.         
  1011.         /*    
  1012.         if($colonne->getId() == 4) {
  1013.             
  1014.             $repo_colonnes =  $this->em->getRepository(Colonne::class);    
  1015.             $colonnes = $repo_colonnes->findBy(array("kanban"=>2));
  1016.             
  1017.             $in_colonne = "";
  1018.             foreach ($colonnes as $c) {
  1019.                 $in_colonne .= $c->getId().",";
  1020.             }
  1021.             $in_colonne = trim($in_colonne,",,");
  1022.         }
  1023.         */
  1024.         
  1025.         if($statut_affaire == "O") {
  1026.              $sql 'SELECT SUM(budget) as total
  1027.                 FROM 
  1028.                 kanban__fiche 
  1029.                 WHERE 
  1030.                 statut_fiche_id IS NULL                
  1031.                 AND
  1032.                 colonne_id IN ('.$in_colonne.')
  1033.                 ';
  1034.         }
  1035.         else {
  1036.              $sql 'SELECT SUM(budget) as total
  1037.                 FROM 
  1038.                 kanban__fiche 
  1039.                 WHERE 
  1040.                 statut_fiche_id = '.$statut_affaire.'                
  1041.                 AND
  1042.                 colonne_id IN ('.$in_colonne.')
  1043.                 ';
  1044.         }
  1045.         
  1046.                
  1047.         
  1048.         if (array_key_exists('date_debut'$parametres) and $parametres['date_debut']!="") {            
  1049.             $dateDebut \DateTime::createFromFormat('d/m/Y',$parametres['date_debut']);
  1050.             $dateDebut->setTime(00,00,00);                    
  1051.             $sql .= " AND date >= '".$dateDebut->format('Y-m-d H:i:s')."'"
  1052.         }
  1053.         
  1054.         
  1055.         if (array_key_exists('date_fin'$parametres) and $parametres['date_fin']!="") {            
  1056.             $dateFin \DateTime::createFromFormat('d/m/Y',$parametres['date_fin']);
  1057.             $dateFin->setTime(23,59,59);                
  1058.             $sql .= " AND date <= '".$dateFin->format('Y-m-d H:i:s')."'";        
  1059.         }
  1060.         
  1061.         
  1062.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  1063.             $sql .= " AND region_id = ".$parametres["region"];
  1064.         }
  1065.         
  1066.         
  1067.         //echo "<div>".$sql."</div>";
  1068.         
  1069.         
  1070.         
  1071.         $stmt $conn->executeQuery($sql);
  1072.         $total $stmt->fetchAllAssociative();
  1073.         
  1074.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  1075.         
  1076.         return $total[0]["total"];
  1077.         
  1078.     }
  1079.     
  1080.     
  1081.         public function entreeSortie($entree_sortie =  NULL$parametres = [], $colonne_id NULL) {
  1082.         
  1083.            $conn $this->em->getConnection();
  1084.         $dateDebut NULL;
  1085.         $dateFin NULL;
  1086.         $sql "";
  1087.         $sql_region "";
  1088.         $join "";
  1089.         //echo "<div>".$utilisateur->getId()."</div>";        
  1090.         //print_r($parametres);
  1091.         /*
  1092.         if (array_key_exists('region', $parametres) and $parametres['region']!="") {
  1093.             $sql_region = " AND region_id = ".$parametres['region'];         
  1094.             //kanban__fiche   
  1095.            
  1096.         }
  1097.         */
  1098.         
  1099.         $where_activite "";
  1100.         $where_type_produit "";
  1101.         $join_client "";
  1102.         
  1103.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  1104.             //activite        
  1105.             $in_type_produit_id "";                
  1106.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  1107.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  1108.             }
  1109.             if($in_type_produit_id != "") {
  1110.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  1111.                 $where_type_produit " AND n.fiche_id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  1112.             }
  1113.         }
  1114.         
  1115.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  1116.             //activite                        
  1117.             $join_client "LEFT JOIN client__client as c ON n.client_id = c.id";
  1118.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  1119.         }
  1120.         
  1121.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  1122.             $sql_region " AND f.region_id = ".$parametres['region'];         
  1123.             //kanban__fiche   
  1124.             
  1125.         }
  1126.          $join "INNER JOIN kanban__fiche as f ON n.fiche_id = f.id";
  1127.         
  1128.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  1129.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  1130.         $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  1131.         
  1132.         $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  1133.         
  1134.         $where "";
  1135.         $in_colonne "";
  1136.       
  1137.         
  1138.         if($colonne_id 0) {
  1139.             
  1140.            $in_colonne $colonne_id;
  1141.             
  1142.             $where 'colonne_id IN ('.$colonne_id.')';            
  1143.             $colonne_obj $repo_colonnes->find($colonne_id);
  1144.             $tunnel_enfant $repo_kanban->findOneBy(["colonne" =>$colonne_obj]);
  1145.                         
  1146.             if(is_object($tunnel_enfant)) {
  1147.                 $in_colonne "";
  1148.                 $colonnes_enfants $repo_colonnes->findBy(["kanban" =>$tunnel_enfant]);
  1149.                 foreach($colonnes_enfants as $ce) {
  1150.                     $in_colonne .= $ce->getId().",";
  1151.                 }
  1152.                 $in_colonne trim($in_colonne,",,");                    
  1153.                 $where 'colonne_id IN ('.$in_colonne.')';                
  1154.             }
  1155.             
  1156.         }
  1157.         //echo $where;
  1158.         
  1159.         
  1160.         if (array_key_exists('date_debut'$parametres) and $parametres['date_debut']!="") {            
  1161.             $dateDebut \DateTime::createFromFormat('d/m/Y','01/'.$parametres['date_debut']);
  1162.             $dateDebut->setTime(00,00,00);                    
  1163.             //$sql .= " AND date >= '".$dateDebut->format('Y-m-d H:i:s')."'"; 
  1164.         }
  1165.         
  1166.         
  1167.         if (array_key_exists('date_fin'$parametres) and $parametres['date_fin']!="") {            
  1168.             $dateFin \DateTime::createFromFormat('d/m/Y','30/'.$parametres['date_fin']);
  1169.             $dateFin->setTime(23,59,59);                
  1170.             //$sql .= " AND date <= '".$dateFin->format('Y-m-d H:i:s')."'";        
  1171.         }
  1172.         
  1173.          if($entree_sortie == "entree") {
  1174.                     
  1175.             $sql "
  1176.                 SELECT count(*) as total 
  1177.                 FROM `note__note` as n
  1178.                 ".$join.
  1179.                 ".$join_client.
  1180.                 WHERE 
  1181.                 n.colonne_id IN (".$in_colonne.")
  1182.                 AND
  1183.                 n.dateDebut >= '".$dateDebut->format('Y-m-d H:i:s')."'
  1184.                 AND
  1185.                 n.dateDebut <= '".$dateFin->format('Y-m-d H:i:s')."'
  1186.                 AND            
  1187.                 n.dateDebut IS NOT NULL     
  1188.                 AND
  1189.                 (f.statut_fiche_id is null or f.statut_fiche_id IN (1,2))       
  1190.                 ".$where_activite."
  1191.                 ".$where_type_produit."
  1192.                 ".$sql_region
  1193.                 ;                            
  1194.             
  1195.         }
  1196.        else if($entree_sortie == "sortie") {
  1197.                                    
  1198.              $sql "
  1199.                 SELECT count(*) as total 
  1200.                 FROM `note__note` as n
  1201.                 ".$join.
  1202.                 ".$join_client.
  1203.                 WHERE 
  1204.                 n.colonne_id IN (".$in_colonne.")
  1205.                 AND
  1206.                 n.dateFin >= '".$dateDebut->format('Y-m-d H:i:s')."'
  1207.                 AND
  1208.                 n.dateFin <= '".$dateFin->format('Y-m-d H:i:s')."'
  1209.                 AND            
  1210.                 n.dateFin IS NOT NULL
  1211.                 AND
  1212.                 (f.statut_fiche_id is null or f.statut_fiche_id IN (1,2))  
  1213.                 ".$where_activite."            
  1214.                 ".$where_type_produit."            
  1215.                 ".$sql_region;
  1216.         }    
  1217.                 
  1218.         $stmt $conn->executeQuery($sql);
  1219.         $total $stmt->fetchAllAssociative();
  1220.         return $total[0]["total"];
  1221.         
  1222.     }
  1223.     
  1224.     
  1225.     
  1226.     
  1227.     
  1228.     public function statEtatAffaire($statut_fiche_id =  NULL$parametres = [], $colonne_id NULL) {
  1229.         
  1230.            $conn $this->em->getConnection();
  1231.         $dateDebut NULL;
  1232.         $dateFin NULL;
  1233.         $sql "";
  1234.         $sql_region "";
  1235.         
  1236.         
  1237.         $where_activite "";
  1238.         $where_type_produit "";
  1239.         $join_client "";
  1240.         
  1241.         
  1242.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  1243.             //activite        
  1244.             $in_type_produit_id "";                
  1245.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  1246.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  1247.             }
  1248.             if($in_type_produit_id != "") {
  1249.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  1250.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  1251.             }
  1252.         }
  1253.         
  1254.         
  1255.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  1256.             //activite                        
  1257.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  1258.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  1259.         }
  1260.         
  1261.         //echo "<div>".$utilisateur->getId()."</div>";        
  1262.         //print_r($parametres);
  1263.         
  1264.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  1265.             $sql_region " AND region_id = ".$parametres['region'];         
  1266.             //kanban__fiche   
  1267.            
  1268.         }
  1269.         
  1270.         $in_kanban "";    
  1271.         
  1272.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  1273.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  1274.         $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  1275.         
  1276.         $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  1277.         
  1278.         if(is_array($colonnes_kanban) && count($colonnes_kanban)>0) {
  1279.             foreach($colonnes_kanban as $ck) {
  1280.                 //echo "<div>".$ck->getLibelle()."</div>";
  1281.                 
  1282.                 $kanban_enfant $repo_kanban->findOneBy(["colonne" =>$ck]);
  1283.                 
  1284.                 if(is_object($kanban_enfant)) {
  1285.                     $in_kanban .= $kanban_enfant->getId().",";
  1286.                 }
  1287.                 
  1288.             }
  1289.              
  1290.         }
  1291.         $in_kanban .= $parametres["tunnel"];
  1292.         $in_kanban trim($in_kanban,",,");
  1293.         
  1294.         
  1295.         $where "";
  1296.         $in_colonne "";
  1297.         
  1298.         if(is_object($kanban_obj->getColonne())) 
  1299.         {
  1300.             
  1301.             $colids = [];
  1302.             $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  1303.             
  1304.             foreach($colids as $coll) {
  1305.                 $in_colonne .= $coll->getId().",";
  1306.             }
  1307.             
  1308.             
  1309.             $in_colonne trim($in_colonne,",,");    
  1310.             
  1311.             $where 'colonne_id IN ('.$in_colonne.')';
  1312.                                         
  1313.         }
  1314.         else {
  1315.             
  1316.             $where 'kanban_id IN ('.$parametres["tunnel"].')';
  1317.         }
  1318.         
  1319.         if($colonne_id 0) {
  1320.             
  1321.             $where 'colonne_id IN ('.$colonne_id.')';
  1322.             
  1323.             $colonne_obj $repo_colonnes->find($colonne_id);
  1324.             $tunnel_enfant $repo_kanban->findOneBy(["colonne" =>$colonne_obj]);
  1325.             
  1326.             
  1327.             if(is_object($tunnel_enfant)) {
  1328.                 $in_colonne "";
  1329.                 $colonnes_enfants $repo_colonnes->findBy(["kanban" =>$tunnel_enfant]);
  1330.                 foreach($colonnes_enfants as $ce) {
  1331.                     $in_colonne .= $ce->getId().",";
  1332.                 }
  1333.                 $in_colonne trim($in_colonne,",,");                    
  1334.                 $where 'colonne_id IN ('.$in_colonne.')';
  1335.                 
  1336.             }
  1337.             
  1338.         }
  1339.         //echo $where;
  1340.         
  1341.         if($statut_fiche_id ==  "0") {
  1342.             
  1343.             $sql 'SELECT count(*) as total
  1344.                 FROM kanban__fiche as f
  1345.                 '.$join_client.'
  1346.                 WHERE 
  1347.                 '.$where.'            
  1348.                 AND
  1349.                 (f.statut_fiche_id is null or f.statut_fiche_id IN (1,2))     
  1350.                 '.$where_activite.'
  1351.                 '.$where_type_produit.'
  1352.                 '.$sql_region;
  1353.             
  1354.         }
  1355.         else if(is_null($statut_fiche_id) or $statut_fiche_id == NULL or $statut_fiche_id == "NULL") {
  1356.             
  1357.             
  1358.             
  1359.             $sql 'SELECT count(*) as total
  1360.                 FROM kanban__fiche as f
  1361.                 '.$join_client.'
  1362.                 WHERE 
  1363.                 '.$where.'            
  1364.                 AND
  1365.                 statut_fiche_id IS NULL        
  1366.                 '.$where_activite.'         
  1367.                 '.$where_type_produit.'         
  1368.                 '.$sql_region;
  1369.         }
  1370.         else {
  1371.             
  1372.            
  1373.             
  1374.             $sql 'SELECT count(*) as total
  1375.                 FROM kanban__fiche as f
  1376.                 '.$join_client.'
  1377.                 WHERE 
  1378.                 '.$where.'                
  1379.                 AND
  1380.                 statut_fiche_id = '.$statut_fiche_id.'    
  1381.                 '.$where_activite.'             
  1382.                 '.$where_type_produit.'             
  1383.                 '.$sql_region;
  1384.         }    
  1385.                 
  1386.                         
  1387.                 
  1388.        
  1389.         
  1390.         if (array_key_exists('date_debut'$parametres) and $parametres['date_debut']!="") {            
  1391.             $dateDebut \DateTime::createFromFormat('d/m/Y','01/'.$parametres['date_debut']);
  1392.             $dateDebut->setTime(00,00,00);                    
  1393.             $sql .= " AND f.date >= '".$dateDebut->format('Y-m-d H:i:s')."'"
  1394.         }
  1395.         
  1396.         
  1397.         if (array_key_exists('date_fin'$parametres) and $parametres['date_fin']!="") {            
  1398.             $dateFin \DateTime::createFromFormat('d/m/Y','30/'.$parametres['date_fin']);
  1399.             $dateFin->setTime(23,59,59);                
  1400.             $sql .= " AND f.date <= '".$dateFin->format('Y-m-d H:i:s')."'";        
  1401.         }
  1402.                
  1403.            //echo $sql;
  1404.         //exit;        
  1405.                 
  1406.         $stmt $conn->executeQuery($sql);
  1407.         $total $stmt->fetchAllAssociative();
  1408.         
  1409.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  1410.         
  1411.         
  1412.         
  1413.         
  1414.         return $total[0]["total"];
  1415.         
  1416.         
  1417.         
  1418.     }    
  1419.         
  1420.     public function tempsMiniMaxiAffaire(Colonne $colonne,$parametres = []) {
  1421.         
  1422.         $conn $this->em->getConnection();
  1423.         $sql "";
  1424.         $sql_region "";
  1425.         $join "";
  1426.         //print_r($parametres);
  1427.         $mini_maxi = ["mini" =>0"maxi" =>0"tauxRespect" =>0"totalFiches" =>"0"];
  1428.         
  1429.         $delai_colonne $colonne->getDelai();
  1430.         
  1431.         $where_activite "";
  1432.         $where_type_produit "";
  1433.         $join_client "";
  1434.         
  1435.         
  1436.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  1437.             //activite        
  1438.             $in_type_produit_id "";                
  1439.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  1440.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  1441.             }
  1442.             if($in_type_produit_id != "") {
  1443.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  1444.                 $where_type_produit " AND n.fiche_id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  1445.             }
  1446.         }
  1447.         
  1448.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  1449.             //activite                        
  1450.             $join_client "LEFT JOIN client__client as c ON n.client_id = c.id";
  1451.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  1452.         }
  1453.        
  1454.         
  1455.         $dateDebutBoucle \DateTime::createFromFormat('d/m/Y','01/'.$parametres['date_debut']);
  1456.         $dateDebutBoucle->setTime(00,00,01);
  1457.         
  1458.         $dateFinBoucle \DateTime::createFromFormat('m/Y',$parametres['date_fin']);
  1459.         $dateFinBoucle->modify('last day of this month');
  1460.         $dateFinBoucle->setTime(23,59,59);
  1461.         
  1462.         
  1463.         $in_colonne $colonne->getId();        
  1464.         //if(is_object($colonne->getKanban()) && is_object($colonne->getKanban()->getColonne())) {
  1465.             
  1466.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  1467.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  1468.         $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne]);
  1469.         
  1470.         if(is_object($kanban_colonne_obj)) {
  1471.             $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  1472.             
  1473.             $in_colonne "";
  1474.             foreach ($colonnes as $c) {
  1475.                 $in_colonne .= $c->getId().",";
  1476.             }
  1477.             $in_colonne trim($in_colonne,",,");
  1478.         }        
  1479.         
  1480.         
  1481.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  1482.             $sql_region " AND f.region_id = ".$parametres['region'];         
  1483.             //kanban__fiche   
  1484.              
  1485.         }
  1486.         $join "INNER JOIN kanban__fiche as f ON n.fiche_id = f.id";
  1487.         $sql "
  1488.             SELECT * 
  1489.             FROM `note__note` as n
  1490.             ".$join.
  1491.             ".$join_client.
  1492.             WHERE 
  1493.             n.colonne_id IN (".$in_colonne.")
  1494.             AND
  1495.             n.dateDebut >= '".$dateDebutBoucle->format('Y-m-d H:i:s')."'
  1496.             AND
  1497.             n.dateFin <= '".$dateFinBoucle->format('Y-m-d H:i:s')."'
  1498.             AND 
  1499.             n.dateDebut IS NOT NULL
  1500.             AND
  1501.             dateFin IS NOT NULL
  1502.             AND
  1503.             (f.statut_fiche_id is null or f.statut_fiche_id IN (1,2))            
  1504.             ".$sql_region."
  1505.             ".$where_type_produit."
  1506.             ".$where_activite;
  1507.         
  1508.         
  1509.         //echo "<div>DD : ".$dateDebutBoucle->format('Y-m-d H:i:s')."</div>";
  1510.         //echo "<div>DF : ".$dateFinBoucle->format('Y-m-d H:i:s')."</div>";                
  1511.         //echo $sql."<br/>";
  1512.         
  1513.         
  1514.         $stmt $conn->executeQuery($sql);
  1515.         $fiches $stmt->fetchAllAssociative();
  1516.         
  1517.         $tab_jours = [];
  1518.         
  1519.         $total_fiches count($fiches);
  1520.         $totalFicheDansLeDelais 0;
  1521.         
  1522.         if(is_array($fiches) && count($fiches)>0) {
  1523.             foreach($fiches as $f) {
  1524.                 //echo "<div>F ".$f['fiche_id']." (".$f['dateDebut'].") (".$f['dateFin'].")</div>";
  1525.                 
  1526.                 $date_deb strtotime($f['dateDebut']);
  1527.                 $date_fin strtotime($f['dateFin']);
  1528.                 
  1529.                 $datediff $date_fin $date_deb;
  1530.                 $nb_jours round($datediff / (60 60 24));
  1531.                 
  1532.                 //echo "<div>".$nb_jours."</div>";
  1533.                 $tab_jours[]=$nb_jours;    
  1534.                 
  1535.                 if($nb_jours <= $delai_colonne) {
  1536.                     $totalFicheDansLeDelais++;
  1537.                 }
  1538.                                             
  1539.             }            
  1540.             $mini_maxi["maxi"] = max($tab_jours);
  1541.             $mini_maxi["mini"] = min($tab_jours);
  1542.             
  1543.             
  1544.             //echo "<div>Colonne :".$colonne->getLibelle()."</div>";
  1545.             //echo "<div>totalFicheDansLeDelais:".$totalFicheDansLeDelais."</div>";
  1546.             //echo "<div>total_fiches:".$total_fiches."</div>";
  1547.             
  1548.             $mini_maxi["tauxRespect"] = round($totalFicheDansLeDelais*100/$total_fiches);
  1549.             $mini_maxi["totalFiches"] = $total_fiches;
  1550.             
  1551.             
  1552.         }
  1553.         //exit;    
  1554.         //print_r($tab_jours);            
  1555.         //print_r($mini_maxi);       
  1556.         
  1557.         return $mini_maxi;
  1558.     }
  1559.     
  1560.     
  1561.     
  1562.         
  1563.     
  1564.     
  1565.     
  1566.     
  1567.     public function tempsMoyenAvanceRetardAffaire(Colonne $colonne$parametres = [], $mois_boucle) {
  1568.         
  1569.         $difference 0;
  1570.         $duree $colonne->getDelai();
  1571.         
  1572.         if(is_null($duree) or $duree=="0" or $duree == "") {
  1573.             return 0;
  1574.         }
  1575.         
  1576.         $moyenne $this->tempsMoyenAffaire($colonne,$parametres,$mois_boucle);
  1577.         
  1578.         if($moyenne == "") return "";
  1579.         
  1580.         if($moyenne $duree) {
  1581.             $difference $moyenne-$duree;
  1582.             round($difference);
  1583.             $difference "+".$difference;
  1584.         }
  1585.         elseif($moyenne $duree) {
  1586.             $difference $duree-$moyenne;
  1587.             round($difference);
  1588.             $difference "-".$difference;
  1589.         }
  1590.         elseif($moyenne == $duree) {
  1591.             $difference 0;
  1592.         }
  1593.         
  1594.         //echo "<div>MOYENNE (".$moyenne.")</div>";
  1595.         //echo "<div>DELAI (".$duree.")</div>";
  1596.         //echo "<div>DIFF (".$difference.")</div>";
  1597.         //echo "<hr/>";
  1598.            return $difference;
  1599.     } 
  1600.     
  1601.     
  1602.     
  1603.     
  1604.     
  1605.     
  1606.     
  1607.     
  1608.     
  1609.     public function tempsMoyenAffaireWidget(Colonne $colonne,$parametres = []) {
  1610.         
  1611.         $user $this->security->getUser();
  1612.         $conn $this->em->getConnection();
  1613.         $sql "";
  1614.         $join "";
  1615.         $sql_region "";
  1616.         //print_r($parametres);
  1617.         //exit;
  1618.         $moyenne 0;
  1619.         $region "";
  1620.         
  1621.         $where_equipiers "";
  1622.        
  1623.         if (array_key_exists('equipiers'$parametres) && count($parametres["equipiers"]) > 0) {
  1624.             foreach($parametres["equipiers"] as $e) {
  1625.                 $where_equipiers .= $e.",";
  1626.             }
  1627.         }
  1628.        
  1629.        if($where_equipiers != "") {
  1630.            $where_equipiers trim($where_equipiers,',');
  1631.            $where_equipiers " AND utilisateur_id IN (".$where_equipiers.")";
  1632.        }
  1633.        
  1634.        if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  1635.            $where_equipiers " AND utilisateur_id IN (".$user->getId().")";
  1636.        }
  1637.         
  1638.         $in_colonne $colonne->getId();        
  1639.             
  1640.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  1641.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  1642.         $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne]);
  1643.         
  1644.         if(is_object($kanban_colonne_obj)) {
  1645.             $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  1646.             
  1647.             $in_colonne "";
  1648.             foreach ($colonnes as $c) {
  1649.                 $in_colonne .= $c->getId().",";
  1650.             }
  1651.             $in_colonne trim($in_colonne,",,");
  1652.         }
  1653.         
  1654.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  1655.             $sql_region " AND f.region_id = ".$parametres['region'];         
  1656.             //kanban__fiche   
  1657.              $join "INNER JOIN kanban__fiche as f ON n.fiche_id = f.id";
  1658.         }
  1659.                 
  1660.           $dateDebutBoucle = new \DateTime($parametres["debut_filtre_date"]);
  1661.         $dateDebutBoucle->setTime(00,00,01);
  1662.         
  1663.         $dateFinBoucle = new \DateTime($parametres["fin_filtre_date"]);
  1664.         //$dateFinBoucle->modify('last day of this month');
  1665.         $dateFinBoucle->setTime(23,59,59);
  1666.         $sql "
  1667.             SELECT dateDebut,dateFin
  1668.             FROM `note__note` as n
  1669.             ".$join.
  1670.             WHERE 
  1671.             n.colonne_id IN (".$in_colonne.")            
  1672.             AND
  1673.             n.dateDebut >= '".$dateDebutBoucle->format('Y-m-d H:i:s')."'
  1674.             AND
  1675.             n.dateDebut <= '".$dateFinBoucle->format('Y-m-d H:i:s')."'
  1676.             AND 
  1677.             n.dateDebut IS NOT NULL
  1678.             AND
  1679.             n.dateFin IS NOT NULL
  1680.             ".$sql_region."
  1681.             ".$where_equipiers
  1682.             ;
  1683.         
  1684.         
  1685.         
  1686.         
  1687.         //echo "<div>DD : ".$dateDebutBoucle->format('Y-m-d H:i:s')."</div>";
  1688.         //echo "<div>DF : ".$dateFinBoucle->format('Y-m-d H:i:s')."</div>";                
  1689.         //echo $sql;
  1690.         
  1691.         
  1692.         $stmt $conn->executeQuery($sql);
  1693.         $fiches $stmt->fetchAllAssociative();
  1694.         
  1695.         $tab_jours = [];
  1696.         
  1697.         if(is_array($fiches) && count($fiches)>0) {
  1698.             foreach($fiches as $f) {
  1699.                 //echo "<div>F ".$f['fiche_id']." (".$f['dateDebut'].") (".$f['dateFin'].")</div>";
  1700.                 
  1701.                 $date_deb strtotime($f['dateDebut']);
  1702.                 $date_fin strtotime($f['dateFin']);
  1703.                 
  1704.                 $datediff $date_fin $date_deb;
  1705.                 $nb_jours round($datediff / (60 60 24));
  1706.                 
  1707.                 //echo "<div>".$nb_jours."</div>";
  1708.                 $tab_jours[]=$nb_jours;                                
  1709.             }            
  1710.             $moyenne round(array_sum($tab_jours)/count($fiches));
  1711.         }
  1712.         
  1713.         
  1714.         //print_r($tab_jours);       
  1715.         //echo "<div>AVG :".$moyenne."</div>";
  1716.         
  1717.         //exit;
  1718.         return $moyenne;
  1719.     }     
  1720.     
  1721.     
  1722.         
  1723.     public function tempsMoyenAffaire(Colonne $colonne$parametres = [], $mois_boucle) {
  1724.         
  1725.         $conn $this->em->getConnection();
  1726.         $sql "";
  1727.         $join "";
  1728.         $sql_region "";
  1729.         //print_r($parametres);
  1730.         //exit;
  1731.         $moyenne 0;
  1732.         $region "";
  1733.         
  1734.         $where_activite "";
  1735.         $where_type_produit "";
  1736.         $join_client "";
  1737.         
  1738.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  1739.             //activite        
  1740.             $in_type_produit_id "";                
  1741.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  1742.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  1743.             }
  1744.             if($in_type_produit_id != "") {
  1745.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  1746.                 $where_type_produit " AND n.fiche_id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  1747.             }
  1748.         }
  1749.         
  1750.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  1751.             //activite                        
  1752.             $join_client "LEFT JOIN client__client as c ON n.client_id = c.id";
  1753.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  1754.         }
  1755.         
  1756.         $in_colonne $colonne->getId();        
  1757.             
  1758.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  1759.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  1760.         $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne]);
  1761.         
  1762.         if(is_object($kanban_colonne_obj)) {
  1763.             $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  1764.             
  1765.             $in_colonne "";
  1766.             foreach ($colonnes as $c) {
  1767.                 $in_colonne .= $c->getId().",";
  1768.             }
  1769.             $in_colonne trim($in_colonne,",,");
  1770.         }
  1771.         
  1772.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  1773.             $sql_region " AND f.region_id = ".$parametres['region'];         
  1774.             //kanban__fiche   
  1775.              
  1776.         }
  1777.         
  1778.         $join "INNER JOIN kanban__fiche as f ON n.fiche_id = f.id";
  1779.         
  1780.         //print_r($mois_boucle);
  1781.         
  1782.         $dateDebutBoucle \DateTime::createFromFormat('d/m/Y','01/'.$mois_boucle);
  1783.         $dateDebutBoucle->setTime(00,00,01);
  1784.         
  1785.         $dateFinBoucle \DateTime::createFromFormat('m/Y',$mois_boucle);
  1786.         $dateFinBoucle->modify('last day of this month');
  1787.         $dateFinBoucle->setTime(23,59,59);
  1788.         $sql "
  1789.             SELECT dateDebut,dateFin
  1790.             FROM `note__note` as n
  1791.             ".$join.
  1792.             ".$join_client.
  1793.             WHERE 
  1794.             n.colonne_id IN (".$in_colonne.")            
  1795.             AND
  1796.             n.dateDebut >= '".$dateDebutBoucle->format('Y-m-d H:i:s')."'
  1797.             AND
  1798.             n.dateDebut <= '".$dateFinBoucle->format('Y-m-d H:i:s')."'
  1799.             AND 
  1800.             n.dateDebut IS NOT NULL
  1801.             AND
  1802.             n.dateFin IS NOT NULL
  1803.             AND
  1804.             (f.statut_fiche_id is null or f.statut_fiche_id IN (1,2))
  1805.             ".$where_activite."
  1806.             ".$where_type_produit."
  1807.             ".$sql_region
  1808.             ;
  1809.         
  1810.         
  1811.        
  1812.         
  1813.         //echo "<div>DD : ".$dateDebutBoucle->format('Y-m-d H:i:s')."</div>";
  1814.         //echo "<div>DF : ".$dateFinBoucle->format('Y-m-d H:i:s')."</div>";                
  1815.         //echo $sql."<br/>";
  1816.         
  1817.         
  1818.         $stmt $conn->executeQuery($sql);
  1819.         $fiches $stmt->fetchAllAssociative();
  1820.         
  1821.         $tab_jours = [];
  1822.         
  1823.         if(is_array($fiches) && count($fiches)>0) {
  1824.             
  1825.             
  1826.             
  1827.             
  1828.             foreach($fiches as $f) {
  1829.                 //echo "<div>F ".$f['fiche_id']." (".$f['dateDebut'].") (".$f['dateFin'].")</div>";
  1830.                 
  1831.                 $date_deb strtotime($f['dateDebut']);
  1832.                 $date_fin strtotime($f['dateFin']);
  1833.                 
  1834.                 $datediff $date_fin $date_deb;
  1835.                 $nb_jours round($datediff / (60 60 24));
  1836.                 
  1837.                 //echo "<div>".$nb_jours."</div>";
  1838.                 $tab_jours[]=$nb_jours;                                
  1839.             }            
  1840.             $moyenne round(array_sum($tab_jours)/count($fiches));
  1841.         }
  1842.         else {
  1843.             return "";
  1844.         }
  1845.         
  1846.         
  1847.         //print_r($tab_jours);       
  1848.         //echo "<div>AVG :".$moyenne."</div>";
  1849.         
  1850.         //exit;
  1851.         //echo "<div>MOYENNE : ".$moyenne."</div>";
  1852.         
  1853.         return $moyenne;
  1854.     }     
  1855.     
  1856.     
  1857.         
  1858.     public function statPerduRaison(Utilisateur $utilisateur,Raison $raison,$parametres = []) {
  1859.         $conn $this->em->getConnection();
  1860.         $dateDebut NULL;
  1861.         $dateFin NULL;
  1862.         $sql "";
  1863.         $sql_region "";
  1864.         
  1865.         $where_activite "";
  1866.         $where_type_produit "";
  1867.         $join_client "";
  1868.         
  1869.         if (array_key_exists('typesProduits'$parametres) && count($parametres["typesProduits"]) > 0) {
  1870.             //activite        
  1871.             $in_type_produit_id "";                
  1872.             for($o=0;$o<count($parametres["typesProduits"]);$o++) {                
  1873.                 $in_type_produit_id .= $parametres["typesProduits"][$o].",";                                                    
  1874.             }
  1875.             if($in_type_produit_id != "") {
  1876.                 $in_type_produit_id trim($in_type_produit_id,",,");    
  1877.                 $where_type_produit " AND f.id IN (SELECT distinct fiche_id FROM kanban__fiche_type_produit WHERE type_produit_id IN (".$in_type_produit_id."))";
  1878.             }
  1879.         }
  1880.         
  1881.         if (array_key_exists('activite'$parametres) && $parametres["activite"] > 0) {
  1882.             //activite                        
  1883.             $join_client "LEFT JOIN client__client as c ON f.client_id = c.id";
  1884.             $where_activite " AND c.ape_id = ".$parametres["activite"];
  1885.         }
  1886.         
  1887.         $in_kanban "";    
  1888.         
  1889.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  1890.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  1891.         $colonnes_kanban $repo_colonnes->findBy(["kanban" =>$parametres["tunnel"]]);
  1892.         
  1893.         $kanban_obj $repo_kanban->find($parametres["tunnel"]);
  1894.         
  1895.         if(is_array($colonnes_kanban) && count($colonnes_kanban)>0) {
  1896.             foreach($colonnes_kanban as $ck) {
  1897.                 //echo "<div>".$ck->getLibelle()."</div>";
  1898.                 
  1899.                 $kanban_enfant $repo_kanban->findOneBy(["colonne" =>$ck]);
  1900.                 
  1901.                 if(is_object($kanban_enfant)) {
  1902.                     $in_kanban .= $kanban_enfant->getId().",";
  1903.                 }
  1904.                 
  1905.             }
  1906.              
  1907.         }
  1908.         $in_kanban .= $parametres["tunnel"];
  1909.         $in_kanban trim($in_kanban,",,");
  1910.         
  1911.         
  1912.         $where "";
  1913.         $in_colonne "";
  1914.         
  1915.         if(is_object($kanban_obj->getColonne())) 
  1916.         {
  1917.             
  1918.             $colids = [];
  1919.             $colids $repo_colonnes->findBy(["kanban" =>$kanban_obj]);
  1920.             
  1921.             foreach($colids as $coll) {
  1922.                 $in_colonne .= $coll->getId().",";
  1923.             }
  1924.             
  1925.             
  1926.             $in_colonne trim($in_colonne,",,");    
  1927.             
  1928.             $where 'colonne_id IN ('.$in_colonne.')';
  1929.                                         
  1930.         }
  1931.         else {
  1932.             
  1933.             $where 'kanban_id IN ('.$parametres["tunnel"].')';
  1934.         }
  1935.         
  1936.         
  1937.         
  1938.         //echo "<div>".$utilisateur->getId()."</div>";        
  1939.         //print_r($parametres);
  1940.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  1941.             $sql_region " AND region_id = ".$parametres['region'];         
  1942.             //kanban__fiche   
  1943.            
  1944.         }
  1945.         
  1946.         $sql 'SELECT count(*) as total
  1947.                 FROM kanban__fiche as f
  1948.                 '.$join_client.'
  1949.                 WHERE 
  1950.                 '.$where.'
  1951.                 AND
  1952.                 f.utilisateur_id = '.$utilisateur->getId().'
  1953.                 AND
  1954.                 statut_fiche_id = 2                 
  1955.                 AND
  1956.                 raison_id = '.$raison->getId().'                 
  1957.                 '.$where_activite.'
  1958.                 '.$where_type_produit.'
  1959.                 '.$sql_region;
  1960.         
  1961.         if (array_key_exists('date_debut'$parametres) and $parametres['date_debut']!="") {            
  1962.             $dateDebut \DateTime::createFromFormat('d/m/Y',"01/".$parametres['date_debut']);
  1963.             $dateDebut->setTime(00,00,00);                    
  1964.             $sql .= " AND f.date >= '".$dateDebut->format('Y-m-d H:i:s')."'"
  1965.         }
  1966.         
  1967.         
  1968.         if (array_key_exists('date_fin'$parametres) and $parametres['date_fin']!="") {            
  1969.             $dateFin \DateTime::createFromFormat('d/m/Y',"30/".$parametres['date_fin']);
  1970.             $dateFin->setTime(23,59,59);                
  1971.             $sql .= " AND f.date <= '".$dateFin->format('Y-m-d H:i:s')."'";        
  1972.         }
  1973.                
  1974.            //echo $sql;
  1975.         //exit;        
  1976.                 
  1977.         $stmt $conn->executeQuery($sql);
  1978.         $total $stmt->fetchAllAssociative();
  1979.         
  1980.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  1981.         
  1982.         
  1983.         
  1984.         
  1985.         return $total[0]["total"];
  1986.         
  1987.        
  1988.     }    
  1989.         
  1990.     public function statColonneRegion(Colonne $colonne,Region $region,$parametres = []) {
  1991.         //print_r($parametres);
  1992.         //echo "<div>".$utilisateur->getReference()."</div>";
  1993.         
  1994.         $conn $this->em->getConnection();        
  1995.         $in_colonne $colonne->getId();        
  1996.         //if(is_object($colonne->getKanban()) && is_object($colonne->getKanban()->getColonne())) {
  1997.             
  1998.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  1999.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  2000.         $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne]);
  2001.         
  2002.         if(is_object($kanban_colonne_obj)) {
  2003.             $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  2004.             
  2005.             $in_colonne "";
  2006.             foreach ($colonnes as $c) {
  2007.                 $in_colonne .= $c->getId().",";
  2008.             }
  2009.             $in_colonne trim($in_colonne,",,");
  2010.         }
  2011.             
  2012.             
  2013.         
  2014.         
  2015.         $sql 'SELECT SUM(budget) as total
  2016.                 FROM 
  2017.                 kanban__fiche 
  2018.                 WHERE 
  2019.                 region_id = '.$region->getId().'                
  2020.                 AND
  2021.                 colonne_id IN ('.$in_colonne.')
  2022.                 ';
  2023.         
  2024.         if (array_key_exists('statut_affaire'$parametres)) {
  2025.             
  2026.             if($parametres["statut_affaire"] == "all") {
  2027.                 $sql .= " AND (statut_fiche_id is null or statut_fiche_id IN (1,2))";
  2028.             }
  2029.             else if($parametres["statut_affaire"] == "0") {
  2030.                 $sql .= " AND statut_fiche_id IS NULL";
  2031.             }
  2032.             else $sql .= " AND statut_fiche_id = ".$parametres["statut_affaire"];
  2033.             
  2034.         }
  2035.         if (array_key_exists('date_debut'$parametres) and $parametres['date_debut']!="") {            
  2036.             $dateDebut \DateTime::createFromFormat('d/m/Y',$parametres['date_debut']);
  2037.             $dateDebut->setTime(00,00,00);                    
  2038.             $sql .= " AND date >= '".$dateDebut->format('Y-m-d H:i:s')."'"
  2039.         }
  2040.         
  2041.         
  2042.         if (array_key_exists('date_fin'$parametres) and $parametres['date_fin']!="") {            
  2043.             $dateFin \DateTime::createFromFormat('d/m/Y',$parametres['date_fin']);
  2044.             $dateFin->setTime(23,59,59);                
  2045.             $sql .= " AND date <= '".$dateFin->format('Y-m-d H:i:s')."'";        
  2046.         }
  2047.         
  2048.         
  2049.         if (array_key_exists('commercial'$parametres) and $parametres['commercial']!="") {
  2050.             $sql .= "AND id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id = '".$parametres['commercial']."')";
  2051.             
  2052.         }
  2053.         
  2054.         
  2055.         //echo "<div>".$sql."</div>";
  2056.         
  2057.         
  2058.         $stmt $conn->executeQuery($sql);
  2059.         $total $stmt->fetchAllAssociative();
  2060.         
  2061.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  2062.         
  2063.         return $total[0]["total"];
  2064.         
  2065.     }
  2066.     
  2067.     
  2068.     
  2069.     public function statColonneCommercial(Colonne $colonne,Utilisateur $utilisateur,$parametres = []) {
  2070.         //print_r($parametres);
  2071.         //echo "<div>".$utilisateur->getReference()."</div>";
  2072.         
  2073.         $conn $this->em->getConnection();        
  2074.         $in_colonne $colonne->getId();        
  2075.         //if(is_object($colonne->getKanban()) && is_object($colonne->getKanban()->getColonne())) {
  2076.             
  2077.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  2078.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  2079.         $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne]);
  2080.         
  2081.         if(is_object($kanban_colonne_obj)) {
  2082.             $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  2083.             
  2084.             $in_colonne "";
  2085.             foreach ($colonnes as $c) {
  2086.                 $in_colonne .= $c->getId().",";
  2087.             }
  2088.             $in_colonne trim($in_colonne,",,");
  2089.         }    
  2090.             
  2091.                
  2092.         $sql 'SELECT SUM(budget) as total
  2093.                 FROM 
  2094.                 kanban__fiche 
  2095.                 WHERE 
  2096.                 id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id = '.$utilisateur->getId().')
  2097.                 AND
  2098.                 colonne_id IN ('.$in_colonne.')
  2099.                 ';
  2100.         
  2101.         if (array_key_exists('statut_affaire'$parametres)) {
  2102.             
  2103.             if($parametres["statut_affaire"] == "all") {
  2104.                 $sql .= " AND (statut_fiche_id is null or statut_fiche_id IN (1,2))";
  2105.             }
  2106.             else if($parametres["statut_affaire"] == "0") {
  2107.                 $sql .= " AND statut_fiche_id IS NULL";
  2108.             }
  2109.             else $sql .= " AND statut_fiche_id = ".$parametres["statut_affaire"];
  2110.             
  2111.         }
  2112.         if (array_key_exists('date_debut'$parametres) and $parametres['date_debut']!="") {            
  2113.             $dateDebut \DateTime::createFromFormat('d/m/Y',$parametres['date_debut']);
  2114.             $dateDebut->setTime(00,00,00);                    
  2115.             $sql .= " AND date >= '".$dateDebut->format('Y-m-d H:i:s')."'"
  2116.         }
  2117.         
  2118.         
  2119.         if (array_key_exists('date_fin'$parametres) and $parametres['date_fin']!="") {            
  2120.             $dateFin \DateTime::createFromFormat('d/m/Y',$parametres['date_fin']);
  2121.             $dateFin->setTime(23,59,59);                
  2122.             $sql .= " AND date <= '".$dateFin->format('Y-m-d H:i:s')."'";        
  2123.         }
  2124.         
  2125.         
  2126.         if (array_key_exists('region'$parametres) and $parametres['region']!="") {
  2127.             $sql .= " AND region_id = ".$parametres["region"];
  2128.         }
  2129.         
  2130.         
  2131.         //echo "<div>".$sql."</div>";
  2132.         
  2133.         
  2134.         $stmt $conn->executeQuery($sql);
  2135.         $total $stmt->fetchAllAssociative();
  2136.         
  2137.         //echo "<div>TOTAL ". $total[0]["total"]."</div>";
  2138.         
  2139.         return $total[0]["total"];
  2140.         
  2141.     }
  2142.          
  2143.     
  2144.     
  2145.     public function estEnRetard(Fiche $fiche) {
  2146.         
  2147.         $repo_notes =  $this->em->getRepository(Note::class);
  2148.         $notesEnRetard $repo_notes->getNotesEnRetard($fiche);
  2149.         
  2150.         if(is_array($notesEnRetard) && count($notesEnRetard) > 0) return true;
  2151.         
  2152.         return false;        
  2153.     }
  2154.     
  2155.     public function getTotalActivitesPrevues(Fiche $fiche) {
  2156.         $repo_notes =  $this->em->getRepository(Note::class);
  2157.         $notes $repo_notes->findBy(["fiche" =>$fiche"modifiable" =>"1"], ["dateDebut" =>"DESC"]);
  2158.         
  2159.         return $notes;
  2160.         
  2161.     }
  2162.     
  2163.     
  2164.     public function getColonnesKanban(Kanban $kanban) {
  2165.         $repo_colonnes $this->em->getRepository(Colonne::class);
  2166.         $colonnes $repo_colonnes->findBy(["kanban" =>$kanban], ["position" =>"ASC"]);
  2167.         return $colonnes;
  2168.     }
  2169.     public function getFicheMoisKanban($periode,$parametres = []) {
  2170.         $fiches = [];
  2171.         $user $this->security->getUser();
  2172.        
  2173.         
  2174.         $repo_fiche $this->em->getRepository(Fiche::class);
  2175.         $fiches $repo_fiche->getFichesDate($periode,$parametres,$user$this->container->getParameter('chefProjet'));
  2176.         return $fiches;
  2177.     }
  2178.     public function moisKanban($parametres = []) {
  2179.         
  2180.         $tab = [];
  2181.         
  2182.         $tab_libelle_mois = [];
  2183.         $tab_libelle_mois["01"]="Janvier";
  2184.         $tab_libelle_mois["02"]="Février";
  2185.         $tab_libelle_mois["03"]="Mars";
  2186.         $tab_libelle_mois["04"]="Avril";
  2187.         $tab_libelle_mois["05"]="Mai";
  2188.         $tab_libelle_mois["06"]="Juin";
  2189.         $tab_libelle_mois["07"]="Juillet";
  2190.         $tab_libelle_mois["08"]="Aout";
  2191.         $tab_libelle_mois["09"]="Septembre";
  2192.         $tab_libelle_mois["10"]="Octobre";
  2193.         $tab_libelle_mois["11"]="Novembre";
  2194.         $tab_libelle_mois["12"]="Décembre";
  2195.         
  2196.         if (array_key_exists('date_debut'$parametres) and $parametres['date_debut']!="") {            
  2197.             $dateDebut \DateTime::createFromFormat('d/m/Y',$parametres['date_debut']);
  2198.             $dateDebut->modify('first day of this month');
  2199.             $dateDebut->setTime(00,00,00);    
  2200.             
  2201.             
  2202.             if(array_key_exists('date_fin'$parametres) and $parametres['date_fin']!="") {
  2203.                 $dateFin \DateTime::createFromFormat('d/m/Y',$parametres['date_fin']);
  2204.                 $dateFin->modify('last day of this month');
  2205.                 $dateFin->setTime(00,00,00);    
  2206.             }
  2207.             else {
  2208.                  $dateFin = new \DateTime('last day of this year');
  2209.                  $dateFin->setTime(00,00,00);  
  2210.             }
  2211.             
  2212.             
  2213.             
  2214.             $dateTampon \DateTime::createFromFormat('d/m/Y',$parametres['date_debut']);
  2215.             $dateTampon->modify('first day of this month');
  2216.             $dateTampon->setTime(00,00,00);        
  2217.             
  2218.             while($dateTampon $dateFin) {
  2219.                 //echo "<div>".$dateTampon->format("m")."</div>";                
  2220.                 $annee $dateTampon->format("Y");                
  2221.                 $tab[]= ["libelle" => $tab_libelle_mois[$dateTampon->format("m")]." ".$annee"date" => $annee."-".$dateTampon->format("m")."-01"];
  2222.                 $dateTampon->add(new \DateInterval('P1M'));
  2223.             }                            
  2224.             //print_r($tab);            
  2225.             
  2226.         }
  2227.         else {
  2228.             
  2229.             $date = new \Datetime();
  2230.             $annee $date->format("Y");
  2231.             
  2232.             $tab[]= ["libelle" => "Janvier ".$annee"date" => $annee."-01-01"];
  2233.             $tab[]= ["libelle" => "Février ".$annee"date" => $annee."-02-01"];
  2234.             $tab[]= ["libelle" => "Mars ".$annee"date" => $annee."-03-01"];
  2235.             $tab[]= ["libelle" => "Avril ".$annee"date" => $annee."-04-01"];
  2236.             $tab[]= ["libelle" => "Mai ".$annee"date" => $annee."-05-01"];
  2237.             $tab[]= ["libelle" => "Juin ".$annee"date" => $annee."-06-01"];
  2238.             $tab[]= ["libelle" => "Juillet ".$annee"date" => $annee."-07-01"];
  2239.             $tab[]= ["libelle" => "Aout ".$annee"date" => $annee."-08-01"];
  2240.             $tab[]= ["libelle" => "Septembre ".$annee"date" => $annee."-09-01"];
  2241.             $tab[]= ["libelle" => "Octobre ".$annee"date" => $annee."-10-01"];
  2242.             $tab[]= ["libelle" => "Novembre ".$annee"date" => $annee."-11-01"];
  2243.             $tab[]= ["libelle" => "Décembre ".$annee"date" => $annee."-12-01"];
  2244.         }
  2245.         
  2246.         
  2247.         
  2248.         
  2249.         return $tab;
  2250.     }    
  2251.         
  2252.     public function getContactDefaut(Fiche $fiche) {
  2253.         $repo_contact $this->em->getRepository(Contact::class);
  2254.         $contactDefaut "";
  2255.         if(is_object($fiche->getClient())) $contactDefaut $repo_contact->getContactDefautClient($fiche->getClient());
  2256.         return $contactDefaut;
  2257.     }    
  2258.         
  2259.     public function getTempsPasse(Fiche $fiche) {
  2260.         $tempsRestant "0";
  2261.         $pourcentagePasse "0";
  2262.         $now time(); // or your date as well
  2263.         $your_date strtotime($fiche->getDate()->format("Y-m-d"));
  2264.         $datediff $now $your_date;        
  2265.         $tempsPasse round($datediff / (60 60 24));
  2266.                         
  2267.         if(1!=and is_object($fiche->getDatePrevisionelle())) {
  2268.             $now =  time();// or your date as well
  2269.             $your_date strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  2270.             $datediff $your_date-$now;        
  2271.             $tempsRestant round($datediff / (60 60 24));            
  2272.             
  2273.             $now =  time($fiche->getDate()->format("Y-m-d"));// or your date as well
  2274.             $your_date strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  2275.             $datediff $your_date-$now;    
  2276.             $tempsTotal round($datediff / (60 60 24));
  2277.             
  2278.             
  2279.             //$pourcentagePasse = round($tempsPasse*100/$tempsTotal);
  2280.         }
  2281.         return $tempsPasse;
  2282.     }
  2283.     
  2284.     
  2285.     public function getTempsRestant(Fiche $fiche) {
  2286.         $tempsRestant "0";
  2287.         $pourcentagePasse "0";
  2288.         $now time(); // or your date as well
  2289.         $your_date strtotime($fiche->getDate()->format("Y-m-d"));
  2290.         $datediff $now $your_date;        
  2291.         $tempsPasse round($datediff / (60 60 24));
  2292.                         
  2293.         if(1!=and is_object($fiche->getDatePrevisionelle())) {
  2294.             $now =  time();// or your date as well
  2295.             $your_date strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  2296.             $datediff $your_date-$now;        
  2297.             $tempsRestant round($datediff / (60 60 24));            
  2298.             
  2299.             $now =  time($fiche->getDate()->format("Y-m-d"));// or your date as well
  2300.             $your_date strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  2301.             $datediff $your_date-$now;    
  2302.             $tempsTotal round($datediff / (60 60 24));
  2303.             
  2304.             
  2305.             $pourcentagePasse round($tempsPasse*100/$tempsTotal);
  2306.         }
  2307.         return $tempsRestant;
  2308.     }
  2309.     /*
  2310.     private function getColonnesEnfants($colonne, $colonnes = array()){
  2311.         $colonnes[] = $colonne->getId();
  2312.         $kanban_colonne_obj = $this->em->getRepository(Kanban::class)->findOneBy(array("colonne"=>$colonne));
  2313.         if(is_object($kanban_colonne_obj)) {
  2314.             $colonnesTmp = $this->em->getRepository(Colonne::class)->findBy(array("kanban"=>$kanban_colonne_obj));
  2315.             foreach($colonnesTmp as $colonneTmp){
  2316.                 $colonnes = array_merge($colonnes, $this->getColonnesEnfants($colonneTmp, $colonnes));
  2317.             }
  2318.         }
  2319.         return $colonnes;
  2320.     }
  2321. */
  2322.     public function getDureeFicheColonne(Fiche $fiche,Colonne $colonne) {
  2323.         
  2324.         $duree = ["annee" =>0"mois" =>0"jours" =>"0""heures" =>"0""minutes" =>"0"];
  2325.         $repo_kanban $this->em->getRepository(Kanban::class);
  2326.         $repo_colonne $this->em->getRepository(Colonne::class);
  2327.         $repo_notes $this->em->getRepository(Note::class);
  2328.         
  2329.         $in_colonne $this->getColonnesEnfants($colonne);
  2330.                 
  2331.         $notes $repo_notes->findBy(["fiche" =>$fiche"colonne" =>$in_colonne"modifiable" =>0], ['dateDebut' =>'DESC']);
  2332.         $intervalTotal1 = new \Datetime();
  2333.         $intervalTotal2 = new \Datetime();
  2334.         $datetime2 = new \DateTime();
  2335.         if(is_array($notes) && count($notes)>0) {
  2336.             foreach($notes as $n) {
  2337.                                 
  2338.                 if(!is_null($n->getDateDebut())) {
  2339.                             
  2340.                     $datetime1 = new \DateTime($n->getDateDebut()->format('Y-m-d H:i:s'));
  2341.                     
  2342.                     if(!is_null($n->getDateFin())) $datetime2 = new \DateTime($n->getDateFin()->format('Y-m-d H:i:s'));
  2343.                     //else $datetime2 = new \DateTime();
  2344.                     
  2345.                     $interval $datetime1->diff($datetime2);
  2346.                     $intervalTotal1->add($interval);
  2347.                     $datetime2 = clone $datetime1;
  2348.                 }
  2349.             }
  2350.         }
  2351.         $interval $intervalTotal1->diff($intervalTotal2);
  2352.             $duree["annee"] += $interval->format('%y');
  2353.                     $duree["mois"] += $interval->format('%m');
  2354.                     $duree["jours"] += $interval->format('%d');
  2355.                     $duree["heures"] += $interval->format('%H');
  2356.                     $duree["minutes"] += $interval->format('%I');
  2357.         
  2358.         return $duree;
  2359.     }
  2360.     
  2361.     
  2362.     public function estFavoris(Fiche $fiche,Utilisateur $user) {
  2363.         
  2364.         //$favoris = $this->em->getRepository('DTCKanbanBundle:Favoris')->findOneBy(array("utilisateur"=>$user,"fiche"=>$fiche));
  2365.         $favoris $this->em->getRepository(Favoris::class)->findOneBy(["fiche" =>$fiche]);
  2366.         
  2367.         if(is_object($favoris)) return $favoris;        
  2368.         return false;
  2369.         
  2370.     }
  2371.     
  2372.     public function getTotalOffresColonne(Colonne $colonne,$parametres = []) {
  2373.         $user $this->security->getUser();
  2374.         return $this->em->getRepository(Colonne::class)->getTotalOffres($colonne,$parametres,$user);
  2375.     }
  2376.     
  2377.     public function getTotalBudgetColonne(Colonne $colonne,$parametres = []) {
  2378.         $user $this->security->getUser();
  2379.         $repo_colonnes =  $this->em->getRepository(Colonne::class);
  2380.         $repo_kanban =  $this->em->getRepository(Kanban::class);
  2381.         $kanban_colonne_obj $repo_kanban->findOneBy(["colonne" =>$colonne]);
  2382.         $in_colonne $colonne->getId();
  2383.         if(is_object($kanban_colonne_obj)) {
  2384.             $colonnes $repo_colonnes->findBy(["kanban" =>$kanban_colonne_obj]);
  2385.             
  2386.             $in_colonne "";
  2387.             foreach ($colonnes as $c) {
  2388.                 $in_colonne .= $c->getId().",";
  2389.             }
  2390.             $in_colonne trim($in_colonne,",,");
  2391.         } 
  2392.         
  2393.         
  2394.         return $this->em->getRepository(Colonne::class)->getTotalBudgetColonne($in_colonne,$parametres,$user);
  2395.     }    
  2396.     
  2397.     public function getTotalBudgetSansPourcentagesColonne(Colonne $colonne,$parametres = []) {
  2398.         $user $this->security->getUser();
  2399.         $allColonnes $this->getColonnesEnfants($colonne);
  2400.         $total 0;
  2401.         foreach($allColonnes as $colonneTmp){
  2402.             $total += $this->em->getRepository(Colonne::class)->getTotalBudgetSansPourcentagesColonne($colonneTmp,$parametres$user);
  2403.         }
  2404.         return $total;
  2405.     }
  2406.     public function getTotalBudgetPondereColonne(Colonne $colonne,$parametres = []) {
  2407.         $user $this->security->getUser();
  2408.         $allColonnes $this->getColonnesEnfants($colonne);
  2409.         $total 0;
  2410.         foreach($allColonnes as $colonneTmp){
  2411.             $total += $this->em->getRepository(Colonne::class)->getTotalBudgetPondereColonne($colonneTmp$parametres$user);
  2412.         }
  2413.         return $total;
  2414.     }    
  2415.     
  2416.     public function getTotalColonne(Kanban $kaban) {        
  2417.         return $this->em->getRepository(Kanban::class)->getTotalColonne($kaban);
  2418.     }
  2419.     
  2420.     
  2421.     public function getDureeDerniereNoteFiche(Fiche $fiche,Categorie $categorie) {
  2422.         $repo_note $this->em->getRepository(Note::class);
  2423.         $note $repo_note->findOneBy(["categorie" =>$categorie"fiche" =>$fiche], ["dateDebut" =>"desc"]);
  2424.         
  2425.         $date = new \Datetime();
  2426.         
  2427.         if(is_object($note) && $note->getDateDebut() < $date) {
  2428.             $now time(); // or your date as well
  2429.             $your_date strtotime($note->getDateDebut()->format("Y-m-d"));
  2430.             $datediff $now-$your_date;        
  2431.             $tempsPasse round($datediff / (60 60 24));
  2432.             
  2433.             return $tempsPasse;
  2434.             
  2435.         }
  2436.         else {
  2437.             return "";
  2438.         }                        
  2439.     }
  2440.     
  2441.     public function getNombreNoteFicheParCategorie(Fiche $fiche,Categorie $categorie) {
  2442.         $repo_note $this->em->getRepository(Note::class);
  2443.         $notes $repo_note->findBy(["categorie" =>$categorie"fiche" =>$fiche], ["dateDebut" =>"desc"]);
  2444.         
  2445.         return count($notes);
  2446.     }
  2447.     public function getCompteurFichesClient(Client $client$ficheId=''){
  2448.         if(!empty($ficheId)){
  2449.             $fiche $this->em->getRepository(Fiche::class)->find($ficheId);
  2450.             if(is_object($fiche) && $fiche->getClient() == $client) return $fiche->getNumeroFiche();
  2451.         }
  2452.         
  2453.         $nb 0;
  2454.         $fiches $this->em->getRepository(Fiche::class)->findBy([
  2455.             'client' => $client,
  2456.             'dateSuppression' => NULL
  2457.                                                                  ], ['numeroFiche' =>'DESC'], 10);
  2458.         if(is_array($fiches) && count($fiches)) $nb floatval($fiches[0]->getNumeroFiche());
  2459.         $nb++;
  2460.         $length max(3strlen($nb));
  2461.         while(strlen($nb) < $length){ $nb '0'.$nb; }
  2462.         return $nb;
  2463.     }
  2464.     
  2465.     public function getTotalCaLoopgrade($fiche){
  2466.         $commande $this->em->getRepository(Commande::class)->findAffaireByFiche($fiche);
  2467.         if(is_object($commande)) return $this->em->getRepository(ArticleCommande::class)->getTotalCaLoopgrade($commande);
  2468.         return 0;
  2469.     }
  2470.     
  2471.     public function getMontantPondereFicheService($fiche){
  2472.         return $this->em->getRepository(Fiche::class)->getMontantPondereFiche($fiche);
  2473.         
  2474.     }
  2475.     public function getColonnesEnfants($colonne$retour = [], $count 0){
  2476.         if($count 100) return $retour;
  2477.         $retour[] = $colonne;
  2478.         $kanbans $this->em->getRepository(Kanban::class)->findBy(
  2479.             [
  2480.                 'colonne' => $colonne
  2481.             ]
  2482.         );
  2483.         if(is_array($kanbans) && count($kanbans)){
  2484.             foreach($kanbans as $kanban){
  2485.                 $colonnes $this->em->getRepository(Colonne::class)->findBy(
  2486.                     [
  2487.                         'kanban' => $kanban
  2488.                     ]
  2489.                 );
  2490.                 if(count($colonnes)) {
  2491.                     foreach($colonnes as $colonneTmp)
  2492.                         $retour $this->getColonnesEnfants($colonneTmp$retour$count 1);
  2493.                 }
  2494.             }
  2495.         }
  2496.         return $retour;
  2497.     }
  2498.     
  2499. }