Commit daf30138 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Possibilité de lancer le calcul des formules pour une année donnée.

Tri décroissant des années possibles et fait pour les formules
parent fdd9e74d
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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);

+11 −5
Original line number Diff line number Diff line
@@ -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,18 +37,22 @@ 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) {
            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;
    }