feat : refonte de l'affichage des âges et restriction des prix aux admins

- 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>
This commit is contained in:
2026-04-27 17:09:13 +02:00
parent b3b7746bc5
commit 569d3b373f
9 changed files with 204 additions and 79 deletions

View File

@@ -7,7 +7,8 @@ namespace App\State\Bovin;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\BovineInventoryStats;
use Doctrine\DBAL\Connection;
use App\Repository\BovineRepository;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* @implements ProviderInterface<BovineInventoryStats>
@@ -15,26 +16,22 @@ use Doctrine\DBAL\Connection;
final class BovineInventoryStatsProvider implements ProviderInterface
{
public function __construct(
private Connection $connection,
private BovineRepository $bovineRepository,
private RequestStack $requestStack,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): BovineInventoryStats
{
$row = $this->connection->fetchAssociative(<<<'SQL'
SELECT
COUNT(*) AS total,
COUNT(*) FILTER (WHERE age_months >= 24) AS over_24,
COUNT(*) FILTER (WHERE age_months >= 22 AND age_months < 24) AS between_22_and_24,
COUNT(*) FILTER (WHERE age_months >= 20 AND age_months < 22) AS between_20_and_22
FROM bovine
WHERE exited_at IS NULL
SQL);
$rawCaseId = $this->requestStack->getCurrentRequest()?->query->get('buildingCaseId');
$caseId = null !== $rawCaseId && ctype_digit((string) $rawCaseId) ? (int) $rawCaseId : null;
$row = $this->bovineRepository->getInventoryStats($caseId);
$stats = new BovineInventoryStats();
$stats->total = (int) ($row['total'] ?? 0);
$stats->over24 = (int) ($row['over_24'] ?? 0);
$stats->between22And24 = (int) ($row['between_22_and_24'] ?? 0);
$stats->between20And22 = (int) ($row['between_20_and_22'] ?? 0);
$stats->total = $row['total'];
$stats->over24 = $row['over24'];
$stats->between22And24 = $row['between22And24'];
$stats->between20And22 = $row['between20And22'];
return $stats;
}