. */ declare(strict_types=1); namespace App\Repository; use App\Entity\Parts\PartLot; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NoResultException; use Doctrine\ORM\QueryBuilder; class PartRepository extends NamedDBElementRepository { /** * Gets the summed up instock of all parts (only parts without an measurent unit). * * @throws NoResultException * @throws NonUniqueResultException */ public function getPartsInstockSum(): float { $qb = new QueryBuilder($this->getEntityManager()); $qb->select('SUM(part_lot.amount)') ->from(PartLot::class, 'part_lot') ->leftJoin('part_lot.part', 'part') ->where('part.partUnit IS NULL'); $query = $qb->getQuery(); return (float) ($query->getSingleScalarResult() ?? 0.0); } /** * Gets the number of parts that has price informations. * * @throws NoResultException * @throws NonUniqueResultException */ public function getPartsCountWithPrice(): int { $qb = $this->createQueryBuilder('part'); $qb->select('COUNT(DISTINCT part)') ->innerJoin('part.orderdetails', 'orderdetail') ->innerJoin('orderdetail.pricedetails', 'pricedetail') ->where('pricedetail.price > 0.0'); $query = $qb->getQuery(); return (int) ($query->getSingleScalarResult() ?? 0); } public function autocompleteSearch(string $query, int $max_limits = 50): array { $qb = $this->createQueryBuilder('part'); $qb->select('part') ->leftJoin('part.category', 'category') ->leftJoin('part.footprint', 'footprint') ->where('part.name LIKE :query') ->orWhere('part.description LIKE :query') ->orWhere('category.name LIKE :query') ->orWhere('footprint.name LIKE :query') ; $qb->setParameter('query', '%'.$query.'%'); $qb->setMaxResults($max_limits); $qb->orderBy('part.name', 'ASC'); return $qb->getQuery()->getResult(); } }