mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-25 19:49:34 +00:00
Added 'low stock' statistics.
This commit is contained in:
parent
6fa2003d32
commit
226fe2f4ba
3 changed files with 43 additions and 0 deletions
|
|
@ -44,6 +44,7 @@ namespace App\Repository;
|
|||
|
||||
use App\Entity\Parts\PartLot;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
class PartRepository extends NamedDBElementRepository
|
||||
{
|
||||
|
|
@ -84,4 +85,31 @@ class PartRepository extends NamedDBElementRepository
|
|||
|
||||
return (int) ($query->getSingleScalarResult() ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of parts that are low in stock.
|
||||
*
|
||||
* That is, it's total amount is smaller than the minimal amount.
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function getPartCountWithLowStock(): int
|
||||
{
|
||||
/* Query to get total amount for every part.
|
||||
* As sub-queries are not supported -> resort to native SQL request.*/
|
||||
$rsm = new ResultSetMapping;
|
||||
$rsm->addScalarResult("cnt", "count", 'integer');
|
||||
$query = $this->getEntityManager()->createNativeQuery('
|
||||
SELECT COUNT(DISTINCT parts.id) as cnt FROM parts
|
||||
INNER JOIN (
|
||||
SELECT parts.id FROM part_lots
|
||||
INNER JOIN parts ON parts.id=part_lots.id_part
|
||||
GROUP BY parts.id
|
||||
HAVING SUM(part_lots.amount)<parts.minamount
|
||||
) AS low
|
||||
ON low.id=parts.id',$rsm);
|
||||
|
||||
return (int) ($query->getSingleScalarResult() ?? 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,17 @@ class StatisticsHelper
|
|||
return $this->part_repo->getPartsCountWithPrice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of all parts with low stock.
|
||||
*
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function getPartCountWithLowStock(): int
|
||||
{
|
||||
return $this->part_repo->getPartCountWithLowStock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of datastructures for the given type.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -48,6 +48,10 @@
|
|||
<td>{% trans %}statistics.parts_with_price{% endtrans %}</td>
|
||||
<td>{{ helper.partsCountWithPrice }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{% trans %}statistics.parts_low_stock{% endtrans %}</td>
|
||||
<td>{{ helper.partCountWithLowStock }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue