<?php
namespace App\Repository;
use App\Entity\Client;
use App\Entity\Commercial;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use function Doctrine\ORM\QueryBuilder;
/**
* @extends ServiceEntityRepository<Client>
*
* @method Client|null find($id, $lockMode = null, $lockVersion = null)
* @method Client|null findOneBy(array $criteria, array $orderBy = null)
* @method Client[] findAll()
* @method Client[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ClientRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Client::class);
}
public function add(Client $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Client $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
/**
* @return Client[] Returns an array of Client objects
*/
public function findAllClientNotIn($listeIdClients): array
{
if(sizeof($listeIdClients) != 0){
return $this->createQueryBuilder('c')
->andWhere('c.actif = true')
->andWhere('c.atelier = false')
->andWhere('c.id NOT IN(:liste)')
->setParameter(':liste', $listeIdClients)
->orderBy('c.id', 'DESC')
->getQuery()
->getResult();
} else {
return $this->createQueryBuilder('c')
->andWhere('c.actif = true')
->getQuery()
->getResult();
}
}
public function findProspectsWithoutAtelier(): array
{
return $this->createQueryBuilder('c')
->where('c.atelier IS NULL OR c.atelier = false') // Inclure les null et false pour atelier
->andWhere('c.prospect IS NULL OR c.prospect IN (:prospectValues)') // Inclure prospects true, false et null
->setParameter('prospectValues', [true, false]) // Facultatif mais explicite
->orderBy('c.actif', 'DESC') // Les inactifs (false) à la fin
->addOrderBy('c.codeClient', 'ASC') // Puis tri par code client ASC
->getQuery()
->getResult();
}
// public function findOneBySomeField($value): ?Client
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}