- Repository BovineRepository avec getInventoryStats en DQL - Sécurité ApiProperty ROLE_ADMIN sur pricePerKg et finalPrice - Endpoint inventory-export passe en ROLE_ADMIN - Composable useBovineColumns mutualisé entre inventory et case (admin/user séparés) - Stats par tranche d'âge filtrables par buildingCaseId - Légende avec cartes colorées pleines + texte blanc - Coloration de la cellule Age (badge) au lieu de toute la ligne - Décalage couleurs : red ≥ 24, orange 22-24, yellow 20-22 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Bovine;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Bovine>
|
|
*/
|
|
final class BovineRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Bovine::class);
|
|
}
|
|
|
|
/**
|
|
* Compteurs des bovins actifs par tranche d'âge.
|
|
*
|
|
* @return array{total: int, over24: int, between22And24: int, between20And22: int}
|
|
*/
|
|
public function getInventoryStats(?int $buildingCaseId = null): array
|
|
{
|
|
$qb = $this->createQueryBuilder('b')
|
|
->select(
|
|
'COUNT(b.id) AS total',
|
|
'SUM(CASE WHEN b.ageMonths >= 24 THEN 1 ELSE 0 END) AS over24',
|
|
'SUM(CASE WHEN b.ageMonths >= 22 AND b.ageMonths < 24 THEN 1 ELSE 0 END) AS between22And24',
|
|
'SUM(CASE WHEN b.ageMonths >= 20 AND b.ageMonths < 22 THEN 1 ELSE 0 END) AS between20And22',
|
|
)
|
|
->where('b.exitedAt IS NULL')
|
|
;
|
|
|
|
if (null !== $buildingCaseId) {
|
|
$qb->andWhere('b.buildingCase = :caseId')
|
|
->setParameter('caseId', $buildingCaseId)
|
|
;
|
|
}
|
|
|
|
$row = $qb->getQuery()->getSingleResult();
|
|
|
|
return [
|
|
'total' => (int) ($row['total'] ?? 0),
|
|
'over24' => (int) ($row['over24'] ?? 0),
|
|
'between22And24' => (int) ($row['between22And24'] ?? 0),
|
|
'between20And22' => (int) ($row['between20And22'] ?? 0),
|
|
];
|
|
}
|
|
}
|