mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-25 19:49:34 +00:00
Fixed 'low-stock' stats.
This commit is contained in:
parent
0dd95da8de
commit
bfb1e4a8da
1 changed files with 13 additions and 13 deletions
|
|
@ -42,6 +42,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Parts\Part;
|
||||||
use App\Entity\Parts\PartLot;
|
use App\Entity\Parts\PartLot;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\ORM\Query\ResultSetMapping;
|
use Doctrine\ORM\Query\ResultSetMapping;
|
||||||
|
|
@ -96,19 +97,18 @@ class PartRepository extends NamedDBElementRepository
|
||||||
*/
|
*/
|
||||||
public function getPartCountWithLowStock(): int
|
public function getPartCountWithLowStock(): int
|
||||||
{
|
{
|
||||||
/* Query to get total amount for every part.
|
$in = $this->getEntityManager()->createQueryBuilder();
|
||||||
* As sub-queries are not supported -> resort to native SQL request.*/
|
$in->select("parts.id")
|
||||||
$rsm = new ResultSetMapping;
|
->from(Part::class, "parts")
|
||||||
$rsm->addScalarResult("cnt", "count", 'integer');
|
->leftJoin("parts.partLots", "lots")
|
||||||
$query = $this->getEntityManager()->createNativeQuery('
|
->groupBy("parts.id")
|
||||||
SELECT COUNT(DISTINCT parts.id) as cnt FROM parts
|
->having("SUM(lots.amount)<parts.minamount");
|
||||||
INNER JOIN (
|
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||||
SELECT parts.id FROM part_lots
|
$qb->select("COUNT(part.id)")
|
||||||
INNER JOIN parts ON parts.id=part_lots.id_part
|
->from(Part::class, "part")
|
||||||
GROUP BY parts.id
|
->where($qb->expr()->in("part.id", $in->getDQL()));
|
||||||
HAVING SUM(part_lots.amount)<parts.minamount
|
|
||||||
) AS low
|
$query = $qb->getQuery();
|
||||||
ON low.id=parts.id',$rsm);
|
|
||||||
|
|
||||||
return (int) ($query->getSingleScalarResult() ?? 0);
|
return (int) ($query->getSingleScalarResult() ?? 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue