<?php
namespace App\Repository\Kanban;
use App\Entity\Kanban\Fiche;
use DateInterval;
use Datetime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* FicheRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class FicheRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Fiche::class);
}
public function getTotalAffaireClient($client) {
$query = $this->createQueryBuilder('p')
->select("COUNT(p.id) as total")
->where('p.client = :client AND p.dateSuppression IS NULL AND (p.statutFiche is NULL or p.statutFiche = :gagne or p.statutFiche = :perdu)')
->setParameters(['client' => $client, 'gagne' =>'1', 'perdu' =>'2'])
;
$res = $query->getQuery()->getOneOrNullResult();
return $res;
}
public function nbAffaireGagnee($parametres = [], $user) {
$where_equipiers = "";
if (array_key_exists('equipiers', $parametres) && count($parametres["equipiers"]) > 0) {
foreach($parametres["equipiers"] as $e) {
$where_equipiers .= $e.",";
}
}
if($where_equipiers != "") {
$where_equipiers = trim($where_equipiers,',');
//$where_equipiers = " AND utilisateur_id IN (".$where_equipiers.")";
$where_equipiers = " AND (utilisateur_id IN (".$where_equipiers.") or id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$where_equipiers.") ) )";
}
if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
//$where_equipiers = " AND utilisateur_id IN (".$user->getId().")";
$where_equipiers = " AND (utilisateur_id IN (".$user->getId().") or id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$user->getId().") ) )";
}
$sql = 'select count(*) as total
from kanban__fiche kf
where
kf.dateSuppression is NULL
and
kf.statut_fiche_id = 1
'.$where_equipiers.'
';
//echo $sql.'<br/><br/>';
$em = $this->getEntityManager();
$stmt = $em->getConnection()->prepare($sql);
$res = $stmt->executeQuery()->fetchAllAssociative();
return $res[0]["total"];
}
public function nbAffairePerdue($parametres = [], $user) {
$where_equipiers = "";
if (array_key_exists('equipiers', $parametres) && count($parametres["equipiers"]) > 0) {
foreach($parametres["equipiers"] as $e) {
$where_equipiers .= $e.",";
}
}
if($where_equipiers != "") {
$where_equipiers = trim($where_equipiers,',');
//$where_equipiers = " AND utilisateur_id IN (".$where_equipiers.")";
$where_equipiers = " AND (utilisateur_id IN (".$where_equipiers.") or id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$where_equipiers.") ) )";
}
if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
//$where_equipiers = " AND utilisateur_id IN (".$user->getId().")";
$where_equipiers = " AND (utilisateur_id IN (".$user->getId().") or id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$user->getId().") ) )";
}
$sql = 'select count(*) as total
from kanban__fiche kf
where
kf.dateSuppression is NULL
and
kf.statut_fiche_id = 2
'.$where_equipiers.'
';
//echo $sql.'<br/><br/>';
$em = $this->getEntityManager();
$stmt = $em->getConnection()->prepare($sql);
$res = $stmt->executeQuery()->fetchAllAssociative();
return $res[0]["total"];
}
public function nbAffaireEnCours($parametres = [], $user) {
$where_equipiers = "";
if (array_key_exists('equipiers', $parametres) && count($parametres["equipiers"]) > 0) {
foreach($parametres["equipiers"] as $e) {
$where_equipiers .= $e.",";
}
}
if($where_equipiers != "") {
$where_equipiers = trim($where_equipiers,',');
//$where_equipiers = " AND utilisateur_id IN (".$where_equipiers.")";
$where_equipiers = " AND (utilisateur_id IN (".$where_equipiers.") or id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$where_equipiers.") ) )";
}
if(!is_object($user->getType()) or ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
//$where_equipiers = " AND utilisateur_id IN (".$user->getId().")";
$where_equipiers = " AND (utilisateur_id IN (".$user->getId().") or id IN (select fiche_id FROM kanban__equipe WHERE utilisateur_id IN (".$user->getId().") ) )";
}
$sql = 'select count(*) as total
from kanban__fiche kf
where
kf.dateSuppression is NULL
and
kf.statut_fiche_id is null
'.$where_equipiers.'
';
//echo $sql.'<br/><br/>';
$em = $this->getEntityManager();
$stmt = $em->getConnection()->prepare($sql);
$res = $stmt->executeQuery()->fetchAllAssociative();
return $res[0]["total"];
}
public function getTotalFiches() {
$sql = 'select count(*) as total
from kanban__fiche kf
where
kf.dateSuppression is NULL
';
//echo $sql.'<br/><br/>';
$em = $this->getEntityManager();
$stmt = $em->getConnection()->prepare($sql);
$res = $stmt->executeQuery()->fetchAllAssociative();
return $res[0]["total"];
}
public function getFichesDate($periode, $param = [], $user, $chefProjet='') {
//print_r($periode);
$query = $this->createQueryBuilder('p');
$dateDebut = new Datetime($periode["date"]);
$dateDebut->setTime(00,00,00);
//echo "<div>".$dateDebut->format("Y-m-d H:i:s")."</div>";
$dateFin= new Datetime($periode["date"]);
$dateFin->setTime(00,00,00);
$dateFin->add(new DateInterval('P1M'));
//echo "<div>".$dateFin->format("Y-m-d H:i:s")."</div>";
$param['parametres'] = $param;
$parametres = ["dateDebut" =>$dateDebut, "dateFin" =>$dateFin];
$where = "";
$join = '';
$query->leftjoin('p.statutFiche', 'sf');
$where = "(sf.id IS NULL OR sf.id NOT IN (3))";
$query->leftjoin('p.client', 'c');
/*if(array_key_exists('etat', $param['parametres']) and in_array($param['parametres']['etat'], array("1",'2','4')) ) {
//$qb->join('x.marque', 'm', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
if($where != '') $where .= ' and ';
$where .= "p.statutFiche = :statutFiche";
$parametres['statutFiche']=$param['parametres']['etat'];
}
else if(empty($param['parametres']['etat']) || $param['parametres']['etat'] == 'NULL') {
//else if(array_key_exists('etat', $param['parametres']) and ($param['parametres']['etat'] == "NULL")) {
//$qb->join('x.marque', 'm', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
if($where != '') $where .= ' and ';
$where .="p.statutFiche is NULL";
//$parametres['statutFiche']=$param['parametres']['etat'];
}
else if(array_key_exists('etat', $param['parametres']) and ($param['parametres']['etat'] == "all")) {
//$where .= "AND p.statutFiche is NULL";
} else {
//$where .= " AND p.statutFiche is NULL";
if($where != '') $where .= ' and ';
$where .= "(p.statutFiche != :statutFicheSupprime or p.statutFiche is NULL)";
$parametres['statutFicheSupprime']=3;
}
*/
if(array_key_exists('regions', $param["parametres"]) && $param["parametres"]["regions"]> 0) {
if($where != '') $where .= ' and ';
$where .= "p.region = :region";
$parametres['region']=$param['parametres']['regions'];
}
if(array_key_exists('sansactivites', $param["parametres"])) {
// 1 A faire
// 2 Fait
//$query->Join('p.notes', 'no', 'with', 'no.fiche = p.id AND no.statut != 1');
$qBLu = $this->createQueryBuilder('f2')
->select("f2.id")
->leftJoin('f2.notes', 'no2')
->where('no2.statut = :noteStatut2')
//->setParameters(array("noteStatut2"=>"1"))
//->setMaxResults(1);
;
if($where != '') $where .= ' and ';
$where .= 'p.id NOT IN (' . $qBLu->getDQL() . ')';
$parametres['noteStatut2']=1;
}
if(array_key_exists('client', $param['parametres']) and ($param['parametres']['client'] != "")) {
$query->leftjoin('p.client', 'c');
if($where != '') $where .= ' and ';
$where .= "c.id = :client";
$parametres['client'] = $param['parametres']['client'];
}
if(array_key_exists('contact', $param['parametres']) and ($param['parametres']['contact'] != "")) {
$query->leftjoin('p.contact', 'ct');
if($where != '') $where .= ' and ';
$where .= "ct.id = :contact";
$parametres['contact'] = $param['parametres']['contact'];
}
if(array_key_exists('u', $param['parametres']) and count($param['parametres']['u'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.utilisateur IN (:utilisateurs)";
foreach($param['parametres']['u'] as $key=>$value) {
$parametres['utilisateurs'][]=$value;
}
}
if(is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
/*
$where .= " AND p.utilisateur IN (:utilisateurs)";
$parametres['utilisateurs'][]=array($user->getId());
*/
if($where != '') $where .= ' and ';
$where .= "( p.utilisateur IN (:utilisateurs) OR eq.utilisateur = :equipier )";
$parametres['utilisateurs'][]= [$user->getId()];
$parametres['equipier'][]=$user->getId();
}
else if(array_key_exists('filtre-utilisateurs', $param['parametres']) and count($param['parametres']['filtre-utilisateurs'])>0) {
if($where != '') $where .= ' and ';
$where .= "( p.utilisateur IN (:utilisateurs) OR eq.utilisateur IN (:equipier) )";
foreach($param['parametres']['filtre-utilisateurs'] as $key=>$value) {
$parametres['utilisateurs'][]=$value;
$parametres['equipier'][]=$value;
}
}
if(array_key_exists('filtre-apporteurs', $param['parametres']) and count($param['parametres']['filtre-apporteurs'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.apporteur IN (:apporteurs)";
foreach($param['parametres']['filtre-apporteurs'] as $key=>$value) {
$parametres['apporteurs'][]=$value;
}
}
if(array_key_exists('filtre-commerciaux', $param['parametres']) and count($param['parametres']['filtre-commerciaux'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.commercial IN (:commerciaux)";
foreach($param['parametres']['filtre-commerciaux'] as $key=>$value) {
$parametres['commerciaux'][]=$value;
}
}
if(array_key_exists('filtre-chefsProjet', $param['parametres']) and count($param['parametres']['filtre-chefsProjet'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.chefProjet IN (:chefsProjet)";
foreach($param['parametres']['filtre-chefsProjet'] as $key=>$value) {
$parametres['chefsProjet'][]=$value;
}
if(!empty($chefProjet)){
if($where != '') $where .= ' and ';
$where .= "eq.role = :chefProjetArticle";
$parametres['chefProjetArticle'] = $chefProjet;
}
}
if(array_key_exists('tunnel', $param['parametres']) and ($param['parametres']['tunnel'] != "")) {
//$em = $this->getDoctrine()->getManager();
//$repo_kanban = $em->getRepository('DTCKanbanBundle:Kanban');
//$repo_colonne = $em->getRepository('DTCKanbanBundle:Colonne');
$sql = "SELECT colonne_id FROM kanban__kanban WHERE id = ".$param['parametres']['tunnel'];
$sql = trim($sql);
$em = $this->getEntityManager();
$stmt = $em->getConnection()->prepare($sql);
$kanban_obj = $stmt->executeQuery()->fetchAllAssociative();
//$kanban_obj = $repo_kanban->find($param['parametres']['tunnel']);
if(!is_null($kanban_obj[0]["colonne_id"]))
//if(is_object($kanban_obj) && is_object($kanban_obj->getColonne()) )
{
$colids = [];
//$colids = $repo_colonne->findBy(array("kanban"=>$kanban_obj));
$sql = "SELECT id FROM kanban__colonne WHERE kanban_id = ".$param['parametres']['tunnel'];
$sql = trim($sql);
$em = $this->getEntityManager();
$stmt = $em->getConnection()->prepare($sql);
$colids = $stmt->executeQuery()->fetchAllAssociative();
$query->leftjoin('p.colonne', 'col');
if($where != '') $where .= ' and ';
$where .= 'col.id IN (:colids)';
$parametres['colids']=$colids;
}
else {
if($where != "") $where .= " AND ";
$where .= "p.kanban = :kanban";
$parametres['kanban']=$param['parametres']['tunnel'];
}
}
/*
if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
//echo "AAAAAA(".$param['parametres']['or'].")";
$query->leftjoin('p.ficheOrigine', 'fo');
$where .= " AND fo.origine = :origine";
$parametres['origine'] = $param['parametres']['or'];
}
*/
if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
$query->leftjoin('p.origineCommande', 'fo');
if($where != '') $where .= ' and ';
$where .= "fo.id = :origine";
$parametres['origine'] = $param['parametres']['or'];
}
if(array_key_exists('marche', $param['parametres']) and ($param['parametres']['marche'] != "")) {
$query->leftjoin('p.marche', 'mr');
if($where != '') $where .= ' and ';
$where .= "mr.id = :marche";
$parametres['marche'] = $param['parametres']['marche'];
}
if(!empty($param['parametres']['apporteur'])) {
$query->leftjoin('p.apporteur', 'ap');
if($where != '') $where .= ' and ';
$where .= "ap.id = :apporteur";
$parametres['apporteur'] = $param['parametres']['apporteur'];
}
if(array_key_exists('domaine', $param['parametres']) and ($param['parametres']['domaine'] != "")) {
$query->leftjoin('p.projetDomaines', 'pd');
$query->leftjoin('pd.domaine', 'do');
if($where != '') $where .= ' and ';
$where .= "do.id = :domaine";
$parametres['domaine'] = $param['parametres']['domaine'];
}
if(array_key_exists('activite', $param['parametres']) and ($param['parametres']['activite'] != "")) {
$query->leftjoin('p.projetActivites', 'pa');
$query->leftjoin('pa.activite', 'paa');
if($where != '') $where .= ' and ';
$where .= "paa.id = :activite";
$parametres['activite'] = $param['parametres']['activite'];
}
/*
if(array_key_exists('partenaire', $param['parametres']) and ($param['parametres']['partenaire'] != "")) {
$query->leftjoin('p.commandes', 'cmd');
$query->leftjoin('cmd.articleCommande', 'accmd');
$query->leftjoin('cmd.statutCommande', 'scmd');
$query->leftjoin('cmd.typeDocumentCommercial', 'tcmd');
if($where != '') $where .= ' and ';
$where .= "scmd.ordre NOT IN (0) AND tcmd.id IN (1) AND accmd.fournisseur = :partenaire";
$parametres['partenaire'] = $param['parametres']['partenaire'];
}
*/
if($where != "") $where .= " AND ";
$where .= '(p.archive = 0 OR p.archive IS NULL) and p.date >= :dateDebut and p.date < :dateFin';
$query
//->join('c.kanban', 'k')
//->leftjoin('p.statutFiche', 's')
//->leftjoin('p.equipe', 'eq')
->leftjoin('p.projetUtilisateurs', 'eq')
->where($where)
->setParameters($parametres)
->orderBy('p.date', 'DESC')
->groupBy('p.id')
;
if(array_key_exists('favoris', $param['parametres']) and ($param['parametres']['favoris'] == "1")) {
$query->join('p.favoris', 'f');
}
else {
$query->leftjoin('p.favoris', 'f');
}
$query->orderBy('f.date', 'DESC');
$res = $query->getQuery()->getResult();
return $res;
}
public function getFiches($kanban, $param = [], $user, $chefProjet='') {
$query = $this->createQueryBuilder('p');
$param['parametres'] = $param;
$parametres = [];
//$parametres = array("kanban"=>$kanban->getId());
$where = "";
$query->leftjoin('p.statutFiche', 'sf');
$where = "(sf.id IS NULL OR sf.id NOT IN (3))";//supprime
//print_r($param);
if(array_key_exists('regions', $param["parametres"]) && $param["parametres"]["regions"]> 0) {
if($where != '') $where .= ' and ';
$where .= "p.region = :region";
$parametres['region']=$param['parametres']['regions'];
}
if(array_key_exists('date_debut', $param['parametres']) and ($param['date_debut'] != "")) {
$dateDebut = DateTime::createFromFormat('d/m/Y',$param['date_debut']);
$dateDebut->setTime(00,00,00);
if($where != '') $where .= ' and ';
$where .= "p.date >= :dateDebut";
$parametres['dateDebut']= $dateDebut->format('Y-m-d H:i:s');
}
if(array_key_exists('date_fin', $param['parametres']) and ($param['date_fin'] != "")) {
$dateFin = DateTime::createFromFormat('d/m/Y',$param['date_fin']);
$dateFin->setTime(23,59,59);
if($where != '') $where .= ' and ';
$where .= "p.date <= :dateFin";
$parametres['dateFin']= $dateFin->format('Y-m-d H:i:s');
}
if(array_key_exists('sansactivites', $param["parametres"])) {
// 1 A faire
// 2 Fait
/*$qBLu = $this->createQueryBuilder('f2')
->select("f2.id")
->leftJoin('f2.notes', 'no2')
->where('no2.statut = :noteStatut2')
//->setParameters(array("noteStatut2"=>"1"))
//->setMaxResults(1);
;
if($where != '') $where .= ' and ';
$where .= 'p.id NOT IN (' . $qBLu->getDQL() . ')';
$parametres['noteStatut2']=1;*/
$query->leftjoin('p.notes', 'notes');
if($where != '') $where .= ' and ';
$where .= "notes.statut = 1 AND CURRENT_DATE() >= notes.dateFin";
}
if(array_key_exists('u', $param['parametres']) and count($param['parametres']['u'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.utilisateur IN (:utilisateurs)";
foreach($param['parametres']['u'] as $key=>$value) {
$parametres['utilisateurs'][]=$value;
}
}
if(is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
/*
$where .= " AND p.utilisateur IN (:utilisateurs)";
$parametres['utilisateurs'][]=array($user->getId());
*/
if($where != '') $where .= ' and ';
$where .= "( p.utilisateur IN (:utilisateurs) OR (eq.utilisateur = :equipier) )";
$parametres['utilisateurs'][]= [$user->getId()];
$parametres['equipier'][]=$user->getId();
}
else if(array_key_exists('filtre-utilisateurs', $param['parametres']) and count($param['parametres']['filtre-utilisateurs'])>0) {
if($where != '') $where .= ' and ';
$where .= "( p.utilisateur IN (:utilisateurs) OR (eq.utilisateur IN (:equipier)) )";
foreach($param['parametres']['filtre-utilisateurs'] as $key=>$value) {
$parametres['utilisateurs'][]=$value;
$parametres['equipier'][]=$value;
}
}
if(array_key_exists('filtre-apporteurs', $param['parametres']) and count($param['parametres']['filtre-apporteurs'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.apporteur IN (:apporteurs)";
foreach($param['parametres']['filtre-apporteurs'] as $key=>$value) {
$parametres['apporteurs'][]=$value;
}
}
if(array_key_exists('filtre-commerciaux', $param['parametres']) and count($param['parametres']['filtre-commerciaux'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.commercial IN (:commerciaux)";
foreach($param['parametres']['filtre-commerciaux'] as $key=>$value) {
$parametres['commerciaux'][]=$value;
}
}
if(array_key_exists('filtre-chefsProjet', $param['parametres']) and count($param['parametres']['filtre-chefsProjet'])>0) {
if($where != '') $where .= ' and ';// where projetUtilisateurs.utilisateur == filtre and projetUtilisateurs.role.id =
$where .= "projetU.utilisateur IN (:chefsProjet)";
foreach($param['parametres']['filtre-chefsProjet'] as $key=>$value) {
$parametres['chefsProjet'][]=$value;
}
if(!empty($chefProjet)){
if($where != '') $where .= ' and ';
$where .= "eq.role = :chefProjetArticle";
$parametres['chefProjetArticle'] = $chefProjet;
}
}
if(array_key_exists('client', $param['parametres']) and ($param['parametres']['client'] != "")) {
$query->leftjoin('p.client', 'cli');
if($where != '') $where .= ' and ';
$where .= "cli.id = :client";
$parametres['client'] = $param['parametres']['client'];
}
if(array_key_exists('contact', $param['parametres']) and ($param['parametres']['contact'] != "")) {
$query->leftjoin('p.contact', 'ct');
if($where != '') $where .= ' and ';
$where .= "ct.id = :contact";
$parametres['contact'] = $param['parametres']['contact'];
}
if(array_key_exists('filtre-fiche', $param['parametres']) and ($param['parametres']['filtre-fiche'] != "")) {
if($where != '') $where .= ' and ';
$where .= "p.id = :fiche";
$parametres['fiche'] = $param['parametres']['filtre-fiche'];
}
/*
if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
//echo "AAAAAA(".$param['parametres']['or'].")";
$query->leftjoin('p.ficheOrigine', 'fo');
$where .= " AND fo.origine = :origine";
$parametres['origine'] = $param['parametres']['or'];
}
*/
if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
$query->leftjoin('p.origineCommande', 'fo');
if($where != '') $where .= ' and ';
$where .= "fo.id = :origine";
$parametres['origine'] = $param['parametres']['or'];
}
if(array_key_exists('marche', $param['parametres']) and ($param['parametres']['marche'] != "")) {
$query->leftjoin('p.marche', 'mr');
if($where != '') $where .= ' and ';
$where .= "mr.id = :marche";
$parametres['marche'] = $param['parametres']['marche'];
}
if(!empty($param['parametres']['apporteur'])) {
$query->leftjoin('p.apporteur', 'ap');
if($where != '') $where .= ' and ';
$where .= "ap.id = :apporteur";
$parametres['apporteur'] = $param['parametres']['apporteur'];
}
if(array_key_exists('domaine', $param['parametres']) and ($param['parametres']['domaine'] != "")) {
$query->leftjoin('p.projetDomaines', 'pd');
$query->leftjoin('pd.domaine', 'do');
if($where != '') $where .= ' and ';
$where .= "do.id = :domaine";
$parametres['domaine'] = $param['parametres']['domaine'];
}
if(array_key_exists('activite', $param['parametres']) and ($param['parametres']['activite'] != "")) {
$query->leftjoin('p.projetActivites', 'pa');
$query->leftjoin('pa.activite', 'paa');
if($where != '') $where .= ' and ';
$where .= "paa.id = :activite";
$parametres['activite'] = $param['parametres']['activite'];
}
/*
if(array_key_exists('filtre-fournisseurs', $param['parametres']) and ($param['parametres']['filtre-fournisseurs'] != "")) {
if($where != '') $where .= ' and ';
$where .= "scmd.ordre NOT IN (0) AND tcmd.id IN (1) AND accmd.fournisseur IN (:partenaire)";
$parametres['partenaire'] = $param['parametres']['filtre-fournisseurs'];
}
if(array_key_exists('consortium', $param['parametres']) and ($param['parametres']['consortium'] != "")) {
if($where != '') $where .= ' and ';
$where .= "accmd.fournisseur IS NOT NULL AND four.consortium = 1";
}
*/
if($where != "") $where .= " AND ";
$where .= '(k.id = :kanban or kck.id = :kanban or kckck = :kanban) AND (p.archive = 0 OR p.archive IS NULL)';
//print_r($parametres);
//echo $where;
/*
$query
->join('p.colonne', 'c')
->join('c.kanban', 'k')
->leftjoin('p.equipe', 'eq')
//->where('k.id = :kanban '.$where)
//->setParameters($parametres)
->where("1=1 ".$where)
->setParameters($parametres)
->groupBy('p.id')
;
*/
$parametres['kanban'] = $kanban;
$query
->join('p.colonne', 'c')
->join('c.kanban', 'k')
->leftJoin('k.colonne', 'kc')
->leftJoin('kc.kanban', 'kck')
->leftJoin('kck.colonne', 'kckc')
->leftJoin('kckc.kanban', 'kckck')
//->leftjoin('p.equipe', 'eq')
->leftjoin('p.projetUtilisateurs', 'eq')
/*
->leftjoin('p.commandes', 'cmd')
->leftjoin('cmd.articleCommande', 'accmd')
->leftjoin('cmd.statutCommande', 'scmd')
->leftjoin('cmd.typeDocumentCommercial', 'tcmd')
*/
//->leftjoin('accmd.fournisseur', 'four')
//->leftjoin('p.projetUtilisateurs', 'projetU')
->where($where)
//->setParameters($parametres)
//->where("1=1 ".$where)
->setParameters($parametres)
->groupBy('p.id')
;
if(array_key_exists('favoris', $param['parametres']) and ($param['parametres']['favoris'] == "1")) {
$query->join('p.favoris', 'f');
}
else {
$query->leftjoin('p.favoris', 'f');
}
//$query->orderBy('f.date', 'DESC');
$query->orderBy('p.libelle', 'ASC');
//echo $where;
$res = $query->getQuery()->getResult();
return $res;
}
public function getFichesByColonne($colonne, $param = [], $user, $chefProjet='') {
$query = $this->createQueryBuilder('p');
$param['parametres'] = $param;
$parametres = [];
//$parametres = array("kanban"=>$kanban->getId());
$where = "";
$query->leftjoin('p.statutFiche', 'sf');
$where = "(sf.id IS NULL OR sf.id NOT IN (3))";//supprime
//print_r($param);
if(array_key_exists('regions', $param["parametres"]) && $param["parametres"]["regions"]> 0) {
if($where != '') $where .= ' and ';
$where .= "p.region = :region";
$parametres['region']=$param['parametres']['regions'];
}
if(array_key_exists('date_debut', $param['parametres']) and ($param['date_debut'] != "")) {
$dateDebut = DateTime::createFromFormat('d/m/Y',$param['date_debut']);
$dateDebut->setTime(00,00,00);
if($where != '') $where .= ' and ';
$where .= "p.date >= :dateDebut";
$parametres['dateDebut']= $dateDebut->format('Y-m-d H:i:s');
}
if(array_key_exists('date_fin', $param['parametres']) and ($param['date_fin'] != "")) {
$dateFin = DateTime::createFromFormat('d/m/Y',$param['date_fin']);
$dateFin->setTime(23,59,59);
if($where != '') $where .= ' and ';
$where .= "p.date <= :dateFin";
$parametres['dateFin']= $dateFin->format('Y-m-d H:i:s');
}
if(array_key_exists('sansactivites', $param["parametres"])) {
// 1 A faire
// 2 Fait
/*$qBLu = $this->createQueryBuilder('f2')
->select("f2.id")
->leftJoin('f2.notes', 'no2')
->where('no2.statut = :noteStatut2')
//->setParameters(array("noteStatut2"=>"1"))
//->setMaxResults(1);
;
if($where != '') $where .= ' and ';
$where .= 'p.id NOT IN (' . $qBLu->getDQL() . ')';
$parametres['noteStatut2']=1;*/
$query->leftjoin('p.notes', 'notes');
if($where != '') $where .= ' and ';
$where .= "notes.statut = 1 AND CURRENT_DATE() >= notes.dateFin";
}
if(array_key_exists('u', $param['parametres']) and count($param['parametres']['u'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.utilisateur IN (:utilisateurs)";
foreach($param['parametres']['u'] as $key=>$value) {
$parametres['utilisateurs'][]=$value;
}
}
if(is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
/*
$where .= " AND p.utilisateur IN (:utilisateurs)";
$parametres['utilisateurs'][]=array($user->getId());
*/
if($where != '') $where .= ' and ';
$where .= "( p.utilisateur IN (:utilisateurs) OR (eq.utilisateur = :equipier) )";
$parametres['utilisateurs'][]= [$user->getId()];
$parametres['equipier'][]=$user->getId();
}
else if(array_key_exists('filtre-utilisateurs', $param['parametres']) and count($param['parametres']['filtre-utilisateurs'])>0) {
if($where != '') $where .= ' and ';
$where .= "( p.utilisateur IN (:utilisateurs) OR (eq.utilisateur IN (:equipier)) )";
foreach($param['parametres']['filtre-utilisateurs'] as $key=>$value) {
$parametres['utilisateurs'][]=$value;
$parametres['equipier'][]=$value;
}
}
if(array_key_exists('filtre-apporteurs', $param['parametres']) and count($param['parametres']['filtre-apporteurs'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.apporteur IN (:apporteurs)";
foreach($param['parametres']['filtre-apporteurs'] as $key=>$value) {
$parametres['apporteurs'][]=$value;
}
}
if(array_key_exists('filtre-commerciaux', $param['parametres']) and count($param['parametres']['filtre-commerciaux'])>0) {
if($where != '') $where .= ' and ';
$where .= "p.commercial IN (:commerciaux)";
foreach($param['parametres']['filtre-commerciaux'] as $key=>$value) {
$parametres['commerciaux'][]=$value;
}
}
if(array_key_exists('filtre-chefsProjet', $param['parametres']) and count($param['parametres']['filtre-chefsProjet'])>0) {
if($where != '') $where .= ' and ';// where projetUtilisateurs.utilisateur == filtre and projetUtilisateurs.role.id =
$where .= "projetU.utilisateur IN (:chefsProjet)";
foreach($param['parametres']['filtre-chefsProjet'] as $key=>$value) {
$parametres['chefsProjet'][]=$value;
}
if(!empty($chefProjet)){
if($where != '') $where .= ' and ';
$where .= "eq.role = :chefProjetArticle";
$parametres['chefProjetArticle'] = $chefProjet;
}
}
if(array_key_exists('client', $param['parametres']) and ($param['parametres']['client'] != "")) {
$query->leftjoin('p.client', 'cli');
if($where != '') $where .= ' and ';
$where .= "cli.id = :client";
$parametres['client'] = $param['parametres']['client'];
}
if(array_key_exists('contact', $param['parametres']) and ($param['parametres']['contact'] != "")) {
$query->leftjoin('p.contact', 'ct');
if($where != '') $where .= ' and ';
$where .= "ct.id = :contact";
$parametres['contact'] = $param['parametres']['contact'];
}
if(array_key_exists('filtre-fiche', $param['parametres']) and ($param['parametres']['filtre-fiche'] != "")) {
if($where != '') $where .= ' and ';
$where .= "p.id = :fiche";
$parametres['fiche'] = $param['parametres']['filtre-fiche'];
}
/*
if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
//echo "AAAAAA(".$param['parametres']['or'].")";
$query->leftjoin('p.ficheOrigine', 'fo');
$where .= " AND fo.origine = :origine";
$parametres['origine'] = $param['parametres']['or'];
}
*/
if(array_key_exists('or', $param['parametres']) and ($param['parametres']['or'] != "")) {
$query->leftjoin('p.origineCommande', 'fo');
if($where != '') $where .= ' and ';
$where .= "fo.id = :origine";
$parametres['origine'] = $param['parametres']['or'];
}
if(array_key_exists('marche', $param['parametres']) and ($param['parametres']['marche'] != "")) {
$query->leftjoin('p.marche', 'mr');
if($where != '') $where .= ' and ';
$where .= "mr.id = :marche";
$parametres['marche'] = $param['parametres']['marche'];
}
if(!empty($param['parametres']['apporteur'])) {
$query->leftjoin('p.apporteur', 'ap');
if($where != '') $where .= ' and ';
$where .= "ap.id = :apporteur";
$parametres['apporteur'] = $param['parametres']['apporteur'];
}
if(array_key_exists('domaine', $param['parametres']) and ($param['parametres']['domaine'] != "")) {
$query->leftjoin('p.projetDomaines', 'pd');
$query->leftjoin('pd.domaine', 'do');
if($where != '') $where .= ' and ';
$where .= "do.id = :domaine";
$parametres['domaine'] = $param['parametres']['domaine'];
}
if(array_key_exists('activite', $param['parametres']) and ($param['parametres']['activite'] != "")) {
$query->leftjoin('p.projetActivites', 'pa');
$query->leftjoin('pa.activite', 'paa');
if($where != '') $where .= ' and ';
$where .= "paa.id = :activite";
$parametres['activite'] = $param['parametres']['activite'];
}
/*
if(array_key_exists('filtre-fournisseurs', $param['parametres']) and ($param['parametres']['filtre-fournisseurs'] != "")) {
if($where != '') $where .= ' and ';
$where .= "scmd.ordre NOT IN (0) AND tcmd.id IN (1) AND accmd.fournisseur IN (:partenaire)";
$parametres['partenaire'] = $param['parametres']['filtre-fournisseurs'];
}
if(array_key_exists('consortium', $param['parametres']) and ($param['parametres']['consortium'] != "")) {
if($where != '') $where .= ' and ';
$where .= "accmd.fournisseur IS NOT NULL AND four.consortium = 1";
}
*/
if($where != "") $where .= " AND ";
//$where .= '(k.id = :kanban or kck.id = :kanban or kckck = :kanban) AND (p.archive = 0 OR p.archive IS NULL)';
$where .= 'c.id = :colonne AND (p.archive = 0 OR p.archive IS NULL)';
//print_r($parametres);
//echo $where;
/*
$query
->join('p.colonne', 'c')
->join('c.kanban', 'k')
->leftjoin('p.equipe', 'eq')
//->where('k.id = :kanban '.$where)
//->setParameters($parametres)
->where("1=1 ".$where)
->setParameters($parametres)
->groupBy('p.id')
;
*/
//$parametres['kanban'] = $kanban;
$parametres['colonne'] = $colonne;
$query
->join('p.colonne', 'c')
->join('c.kanban', 'k')
->leftJoin('k.colonne', 'kc')
->leftJoin('kc.kanban', 'kck')
->leftJoin('kck.colonne', 'kckc')
->leftJoin('kckc.kanban', 'kckck')
//->leftjoin('p.equipe', 'eq')
->leftjoin('p.projetUtilisateurs', 'eq')
/*
->leftjoin('p.commandes', 'cmd')
->leftjoin('cmd.articleCommande', 'accmd')
->leftjoin('cmd.statutCommande', 'scmd')
->leftjoin('cmd.typeDocumentCommercial', 'tcmd')
*/
//->leftjoin('accmd.fournisseur', 'four')
//->leftjoin('p.projetUtilisateurs', 'projetU')
->where($where)
//->setParameters($parametres)
//->where("1=1 ".$where)
->setParameters($parametres)
->groupBy('p.id')
;
if(array_key_exists('favoris', $param['parametres']) and ($param['parametres']['favoris'] == "1")) {
$query->join('p.favoris', 'f');
}
else {
$query->leftjoin('p.favoris', 'f');
}
//$query->orderBy('f.date', 'DESC');
$query->orderBy('p.libelle', 'ASC');
//echo $where;
$res = $query->getQuery()->getResult();
return $res;
}
public function getRechercheFiche($recherche,$client_id = "", $maxResults = 500) {
$cond = $recherche . "%";
if (strpos($cond, "*") !== false) {
$cond = str_replace("*","%",$cond);
}
$parameters = ['cond' => $cond];
$where_supp = "";
if($client_id != "") {
$where_supp = " AND c.id = :client_id";
$parameters["client_id"]=$client_id;
}
$query = $this->createQueryBuilder('p')
//CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(p.reference, ' : '), p.libelle),' ('),p.reference),')') as libelle
->select("CONCAT(CONCAT(CONCAT(CONCAT(p.libelle, ' :'), ' ('),p.reference),')') as libelle, CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(p.reference, ' : '), p.libelle),' ('),c.nom),')') as reference, p.id, c.nom,c.id as clientId")
//->select("CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(p.reference, ' : '), p.libelle),' ('),c.nom),')') as reference,p.libelle, p.id, c.nom,c.id as clientId")
->leftjoin('p.client', 'c')
->where('(p.libelle LIKE :cond or p.reference LIKE :cond or p.description LIKE :cond) '.$where_supp)
->setParameters($parameters)
->setFirstResult(0)
->setMaxResults($maxResults)
->orderBy('p.reference', 'ASC');
$res = $query->getQuery()->getResult();
return $res;
}
public function getRechercheFicheFiltre($recherche,$client_id = "", $maxResults = 500) {
$cond = $recherche . "%";
if (strpos($cond, "*") !== false) {
$cond = str_replace("*","%",$cond);
}
$parameters = ['cond' => $cond, 'gagne' =>'1', 'perdu' =>'2'];
$where_supp = "";
if($client_id != "") {
$where_supp = " AND c.id = :client_id";
$parameters["client_id"]=$client_id;
}
$query = $this->createQueryBuilder('p')
//CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(p.reference, ' : '), p.libelle),' ('),p.reference),')') as libelle
//->select("CONCAT(CONCAT(CONCAT(CONCAT(p.libelle, ' :'), ' ('),p.id),')') as libelle, CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(p.id, ' : '), p.libelle),' ('),c.nom),')') as reference, p.id, c.nom,c.id as clientId")
->select("CONCAT(CONCAT(CONCAT(CONCAT(p.reference, ' :'), ' ('),p.libelle),')') as libelle, CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(p.reference, ' : '), p.libelle),' ('),c.nom),')') as reference, p.id, c.nom,c.id as clientId")
//->select("CONCAT(CONCAT(CONCAT(CONCAT(CONCAT(p.reference, ' : '), p.libelle),' ('),c.nom),')') as reference,p.libelle, p.id, c.nom,c.id as clientId")
->leftjoin('p.client', 'c')
->where('(p.statutFiche is NULL or p.statutFiche = :gagne or p.statutFiche = :perdu) AND (p.libelle LIKE :cond or p.reference LIKE :cond or p.description LIKE :cond or p.id LIKE :cond) '.$where_supp)
->setParameters($parameters)
->setFirstResult(0)
->setMaxResults($maxResults)
->orderBy('p.reference', 'ASC');
$res = $query->getQuery()->getResult();
return $res;
}
public function getMontantPondereFiche($fiche)
{
$budget = $fiche->getBudget();
if(!empty($fiche->getPropabilite())){
return $budget * floatval($fiche->getPropabilite()) / 100;
} else if ($fiche->getColonne() && !is_null($fiche->getColonne()->getProbabilite()))
{
$probabilite = $fiche->getColonne()->getProbabilite()/100;
return $budget * $probabilite;
} elseif ($fiche->getColonne() && $fiche->getColonne()->getKanban() && $fiche->getColonne()->getKanban()->getColonne()
&& !is_null($fiche->getColonne()->getKanban()->getColonne()->getProbabilite())){
$probabilite = $fiche->getColonne()->getKanban()->getColonne()->getProbabilite()/100;
return $budget * $probabilite;
}
return $budget;
}
}