. */ 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); } }