*/ class ContactRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Contact::class); } /** * Find contacts by type (debtor, creditor, or both) */ public function findByType(?bool $isDebtor = null, ?bool $isCreditor = null): array { $qb = $this->createQueryBuilder('c') ->where('c.isActive = :active') ->setParameter('active', true) ->orderBy('c.companyName', 'ASC'); if ($isDebtor !== null) { $qb->andWhere('c.isDebtor = :isDebtor') ->setParameter('isDebtor', $isDebtor); } if ($isCreditor !== null) { $qb->andWhere('c.isCreditor = :isCreditor') ->setParameter('isCreditor', $isCreditor); } return $qb->getQuery()->getResult(); } /** * Search contacts by company name, contact person, or email */ public function search(string $searchTerm): array { return $this->createQueryBuilder('c') ->leftJoin('c.contactPersons', 'cp') ->where('c.companyName LIKE :search') ->orWhere('c.email LIKE :search') ->orWhere('c.city LIKE :search') ->orWhere('cp.firstName LIKE :search') ->orWhere('cp.lastName LIKE :search') ->orWhere('cp.email LIKE :search') ->setParameter('search', '%' . $searchTerm . '%') ->orderBy('c.companyName', 'ASC') ->getQuery() ->getResult(); } }