Passed
Push — master ( 159572...890e9f )
by Jan
04:56 queued 10s
created

PartRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPartsInstockSum() 0 10 1
A getPartsCountWithPrice() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
7
 *
8
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
23
 */
24
25
namespace App\Repository;
26
27
use App\Entity\Parts\PartLot;
28
use Doctrine\ORM\EntityRepository;
29
use Doctrine\ORM\QueryBuilder;
30
31
class PartRepository extends EntityRepository
32
{
33
    /**
34
     * Gets the summed up instock of all parts (only parts without an measurent unit)
35
     * @return string
36
     * @throws \Doctrine\ORM\NoResultException
37
     * @throws \Doctrine\ORM\NonUniqueResultException
38
     */
39
    public function getPartsInstockSum(): string
40
    {
41
        $qb = new QueryBuilder($this->getEntityManager());
42
        $qb->select('SUM(part_lot.amount)')
43
            ->from(PartLot::class, 'part_lot')
44
            ->leftJoin('part_lot.part', 'part')
45
            ->where('part.partUnit IS NULL');
46
47
        $query = $qb->getQuery();
48
        return $query->getSingleScalarResult();
49
    }
50
51
    /**
52
     * Gets the number of parts that has price informations.
53
     * @return int
54
     * @throws \Doctrine\ORM\NoResultException
55
     * @throws \Doctrine\ORM\NonUniqueResultException
56
     */
57
    public function getPartsCountWithPrice(): int
58
    {
59
        $qb = $this->createQueryBuilder('part');
60
        $qb->select('COUNT(part)')
61
            ->innerJoin('part.orderdetails', 'orderdetail')
62
            ->innerJoin('orderdetail.pricedetails', 'pricedetail')
63
            ->where('pricedetail.price > 0.0');
64
65
        $query = $qb->getQuery();
66
        return (int) $query->getSingleScalarResult();
67
    }
68
}
69