Dont return null in getPartsInstockSum() function, when no part lots are defined yet.

This should fix issue #38.
This commit is contained in:
Jan Böhmer 2020-04-08 16:41:04 +02:00
parent 64964f3b4d
commit a28747b7ba
2 changed files with 6 additions and 6 deletions

View file

@ -50,12 +50,12 @@ class PartRepository extends NamedDBElementRepository
/** /**
* Gets the summed up instock of all parts (only parts without an measurent unit). * Gets the summed up instock of all parts (only parts without an measurent unit).
* *
* @return string * @return float
* *
* @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException * @throws \Doctrine\ORM\NonUniqueResultException
*/ */
public function getPartsInstockSum(): string public function getPartsInstockSum(): float
{ {
$qb = new QueryBuilder($this->getEntityManager()); $qb = new QueryBuilder($this->getEntityManager());
$qb->select('SUM(part_lot.amount)') $qb->select('SUM(part_lot.amount)')
@ -65,7 +65,7 @@ class PartRepository extends NamedDBElementRepository
$query = $qb->getQuery(); $query = $qb->getQuery();
return $query->getSingleScalarResult(); return (float) ($query->getSingleScalarResult() ?? 0.0);
} }
/** /**
@ -86,6 +86,6 @@ class PartRepository extends NamedDBElementRepository
$query = $qb->getQuery(); $query = $qb->getQuery();
return (int) $query->getSingleScalarResult(); return (int) ($query->getSingleScalarResult() ?? 0);
} }
} }

View file

@ -61,12 +61,12 @@ class StatisticsHelper
/** /**
* Returns the summed instocked over all parts (only parts without a measurement unit). * Returns the summed instocked over all parts (only parts without a measurement unit).
* *
* @return string * @return float
* *
* @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException * @throws \Doctrine\ORM\NonUniqueResultException
*/ */
public function getPartsInstockSum(): string public function getPartsInstockSum(): float
{ {
return $this->part_repo->getPartsInstockSum(); return $this->part_repo->getPartsInstockSum();
} }