diff --git a/module/Application/src/Service/AnneeService.php b/module/Application/src/Service/AnneeService.php index 1868f9b82b5cc7935650557652a284fff4953130..4b6d86e4bd1e0ef8a0d75cf66f1124c93b88a40b 100755 --- a/module/Application/src/Service/AnneeService.php +++ b/module/Application/src/Service/AnneeService.php @@ -87,9 +87,12 @@ class AnneeService extends AbstractEntityService /** * @return array|Annee[] */ - public function getActives(): array + public function getActives(bool $desc = false): array { $dql = "SELECT a FROM ".Annee::class." a WHERE a.active = 1 ORDER BY a.id"; + if ($desc){ + $dql .= " DESC"; + } $query = $this->getEntityManager()->createQuery($dql); diff --git a/module/Formule/src/Command/CalculCommand.php b/module/Formule/src/Command/CalculCommand.php index 262eff8053e54690dfe6f59035b179aaff84bae0..5ecfd2c2e1d8129e366321cc4e5cf2d0d8da138b 100755 --- a/module/Formule/src/Command/CalculCommand.php +++ b/module/Formule/src/Command/CalculCommand.php @@ -5,6 +5,7 @@ namespace Formule\Command; use Application\Service\Traits\AnneeServiceAwareTrait; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -25,7 +26,8 @@ class CalculCommand extends Command protected function configure(): void { - $this->setDescription('Recalcul de toutes les formules'); + $this->setDescription('Recalcul de toutes les formules') + ->addArgument('anneeId', InputArgument::OPTIONAL, 'Id de l\'année pour laquelle seront lancées les formules');; } @@ -35,17 +37,21 @@ class CalculCommand extends Command $io = new SymfonyStyle($input, $output); $io->title($this->getDescription()); + $anneeId = $input->getArgument('anneeId'); + $io->warning("Ce traitement peut prendre plusieurs minutes"); $this->getServiceTableauBord()->setOnAction(function(Event $event) use ($io){ $this->onEvent($event, $io); }); - $annees = $this->getServiceAnnee()->getActives(); + $annees = $this->getServiceAnnee()->getActives(true); foreach ($annees as $annee) { - $io->comment('Calcul pour l\'année '.$annee->getLibelle()); - $params = ['ANNEE_ID' => $annee->getId()]; - $this->getServiceTableauBord()->calculer('formule', $params); + if ($annee->getId() == $anneeId || $anneeId === null) { + $io->comment('Calcul pour l\'année '.$annee->getLibelle()); + $params = ['ANNEE_ID' => $annee->getId()]; + $this->getServiceTableauBord()->calculer('formule', $params); + } } return Command::SUCCESS;