feat: ajout du prix au kilo et de l'age moyen bovin + feed bovin via xlsx (!50)
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [x] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #50 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #50.
This commit is contained in:
@@ -25,12 +25,12 @@ final class BovineInventoryExportProvider implements ProviderInterface
|
||||
{
|
||||
private const HEADER_FILL = 'FFF1F5F9';
|
||||
|
||||
private const COLOR_VIOLET = 'FFC4B5FD';
|
||||
|
||||
private const COLOR_RED = 'FFFCA5A5';
|
||||
|
||||
private const COLOR_ORANGE = 'FFFDBA74';
|
||||
|
||||
private const COLOR_YELLOW = 'FFFDE047';
|
||||
|
||||
private const HEADERS = [
|
||||
'N° National',
|
||||
'N° Travail',
|
||||
@@ -155,7 +155,7 @@ final class BovineInventoryExportProvider implements ProviderInterface
|
||||
$this->formatSex($bovine->getSex()),
|
||||
$this->formatDate($bovine->getBirthDate()),
|
||||
$bovine->getAgeMonths(),
|
||||
$bovine->getBreedCode(),
|
||||
$bovine->getBovineType()?->getLabel(),
|
||||
$bovine->getBuildingCase()?->getIdBuilding()?->getLabel(),
|
||||
$bovine->getBuildingCase()?->getCaseNumber(),
|
||||
$this->formatDate($bovine->getArrivalDate()),
|
||||
@@ -182,14 +182,14 @@ final class BovineInventoryExportProvider implements ProviderInterface
|
||||
return null;
|
||||
}
|
||||
if ($ageMonths >= 24) {
|
||||
return self::COLOR_VIOLET;
|
||||
}
|
||||
if ($ageMonths >= 22) {
|
||||
return self::COLOR_RED;
|
||||
}
|
||||
if ($ageMonths >= 20) {
|
||||
if ($ageMonths >= 22) {
|
||||
return self::COLOR_ORANGE;
|
||||
}
|
||||
if ($ageMonths >= 20) {
|
||||
return self::COLOR_YELLOW;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\ApiResource\BovineSyncInventoryResult;
|
||||
use App\Entity\Bovine;
|
||||
use App\Entity\BovineType;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Malio\EdnotifBundle\Bovin\Api\BovinApiInterface;
|
||||
@@ -18,6 +19,11 @@ use Malio\EdnotifBundle\Bovin\Dto\AnimalSummaryDto;
|
||||
*/
|
||||
final class BovineSyncInventoryProcessor implements ProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, BovineType>
|
||||
*/
|
||||
private array $bovineTypeCache = [];
|
||||
|
||||
public function __construct(
|
||||
private BovinApiInterface $bovinApi,
|
||||
private EntityManagerInterface $em,
|
||||
@@ -34,6 +40,13 @@ final class BovineSyncInventoryProcessor implements ProcessorInterface
|
||||
$result = new BovineSyncInventoryResult();
|
||||
$result->total = count($inventory->animals);
|
||||
|
||||
$this->bovineTypeCache = [];
|
||||
foreach ($this->em->getRepository(BovineType::class)->findAll() as $bovineType) {
|
||||
if (null !== $bovineType->getCode()) {
|
||||
$this->bovineTypeCache[$bovineType->getCode()] = $bovineType;
|
||||
}
|
||||
}
|
||||
|
||||
$existingByNationalNumber = [];
|
||||
foreach ($this->em->getRepository(Bovine::class)->findAll() as $bovine) {
|
||||
$existingByNationalNumber[$bovine->getNationalNumber()] = $bovine;
|
||||
@@ -83,7 +96,7 @@ final class BovineSyncInventoryProcessor implements ProcessorInterface
|
||||
$identification = $animal->identification;
|
||||
if (null !== $identification) {
|
||||
$bovine->setSex($identification->sex);
|
||||
$bovine->setBreedCode($identification->breedType);
|
||||
$bovine->setBovineType($this->resolveBovineType($identification->breedType));
|
||||
$bovine->setWorkNumber($identification->workNumber);
|
||||
$bovine->setBirthDate($identification->birthDate?->date);
|
||||
}
|
||||
@@ -102,4 +115,28 @@ final class BovineSyncInventoryProcessor implements ProcessorInterface
|
||||
$bovine->setExitDate($latestExit);
|
||||
$bovine->refreshAgeMonths();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trouve un BovineType existant par code, sinon en crée un placeholder
|
||||
* que l'admin pourra renommer dans /admin/bovin/bovin-list.
|
||||
*/
|
||||
private function resolveBovineType(?string $code): ?BovineType
|
||||
{
|
||||
if (null === $code || '' === $code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($this->bovineTypeCache[$code])) {
|
||||
return $this->bovineTypeCache[$code];
|
||||
}
|
||||
|
||||
$bovineType = new BovineType();
|
||||
$bovineType->setCode($code);
|
||||
$bovineType->setLabel(sprintf('À renommer (%s)', $code));
|
||||
$this->em->persist($bovineType);
|
||||
|
||||
$this->bovineTypeCache[$code] = $bovineType;
|
||||
|
||||
return $bovineType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ final readonly class BuildingCaseWeightsReportProvider implements ProviderInterf
|
||||
continue;
|
||||
}
|
||||
|
||||
$breedCode = $bovine->getBreedCode();
|
||||
$breedCode = $bovine->getBovineType()?->getCode();
|
||||
if (null === $headerBreedCode && null !== $breedCode) {
|
||||
$headerBreedCode = $breedCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user