Commit 54cdc20c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Système de relance des valideurs en cours

parent a23c7028
Loading
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -69,8 +69,11 @@ abstract class OscarAdvancedCommandAbstract extends OscarCommandAbstract

    protected function isForce(): bool
    {
        if ($this->input->hasOption(self::OPTION_FORCE)) {
            return $this->input->getOption(self::OPTION_FORCE) === null;
        }
        return false;
    }

    protected function isQuiet(): bool
    {
+52 −5
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ class OscarTimesheetRecallsCommand extends OscarAdvancedCommandAbstract
    {
        $this
            ->setDescription("Relance automatique des feuilles de temps")
            ->addOption("purge", null, InputOption::VALUE_OPTIONAL, "Suppression des données (dev)", false)
            ->addOption("processdate", null, InputOption::VALUE_OPTIONAL, "Date d'execution", false)
        ;
    }

@@ -48,13 +50,31 @@ class OscarTimesheetRecallsCommand extends OscarAdvancedCommandAbstract
    {
        parent::execute($input, $output);

        $period = PeriodInfos::getPeriodInfosObj(date('Y-m'))->prevMonth();
        $force = false;
        $processArg = $input->getOption('processdate');

        // Date de déclenchement de la procédure
        $purge = $input->getOption('purge');
        if( $purge === null ){
            if($this->ask("Reset complet des procédures de rappel ?")){
                $recalls = $this->getOrganizationService()->getEntityManager()->getRepository(RecallDeclaration::class)->findAll();
                foreach ($recalls as $r) {
                    $this->getOrganizationService()->getEntityManager()->remove($r);
                }
                $this->getOrganizationService()->getEntityManager()->flush();
                die();
            }
        }

        if( !$processArg ){
            $processDate = new \DateTime();
            $period = PeriodInfos::getPeriodInfosObj(date('Y-m'))->prevMonth();
        } else {
            $processDate = new \DateTime($processArg);
            $period = PeriodInfos::getPeriodInfosObj($processDate->format('Y-m'));
        }

        $force = false;

        $this->getIO()->title("Relance pour " . $period->getPeriodLabel());
        $this->getIO()->title("Relance pour les déclarants " . $period->getPeriodLabel());

        $declarers = $this->getPersonService()->getPersonsByIds(
                $this->getPersonService()->getDeclarersIdsPeriod($period->getPeriodCode())
@@ -75,6 +95,33 @@ class OscarTimesheetRecallsCommand extends OscarAdvancedCommandAbstract
            $this->getIO()->writeln(" - <bold>$declarer</bold> : $snd");
        }

        $this->getIO()->title("Relance pour les validateurs " . $period->getPeriodLabel());

        $validators = $this->getPersonService()->getPersonsByIds(
            $this->getPersonService()->getValidatorsIdsPeriod($period->getPeriodCode())
        );

        foreach ($validators as $validator) {
            $result = $this->getTimesheetService()->recallValidatorProcess(
                $validator->getId(),
                $period->getYear(),
                $period->getMonth(),
                $force);

            if( $result['mailSend'] ){
                $snd = "<green>Mail envoyé</green>";
            } else {
                if( $result['blocked'] ){
                    $snd = "<red>Bloqué</red>";
                } else {
                    $snd = "<none>Pas d'envoi</none>";
                }
            }
            $snd = $snd ." ". $result['recall_info'];
            $this->getIO()->writeln(" - <bold>$validator</bold> : $snd");
        }


        return 0;
    }

+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ use Symfony\Component\Console\Style\SymfonyStyle;
use UnicaenApp\Service\Mailer\MailerService;
use Zend\Validator\Date;

class OscarTimesheetValidatorrRecallCommand extends OscarAdvancedCommandAbstract
class OscarTimesheetValidatorRecallCommand extends OscarAdvancedCommandAbstract
{
    protected static $defaultName = 'timesheets:validator-recall';

+4 −1
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@
namespace Oscar\Entity;

use Doctrine\ORM\Mapping as ORM;
use Oscar\Utils\PeriodInfos;

/**
 * Cette classe référence les rôles GLOBAUX sur l'application.
@@ -14,6 +13,10 @@ use Oscar\Utils\PeriodInfos;
 */
class RecallDeclaration
{

    const CONTEXT_DECLARER = 'declarer';
    const CONTEXT_VALIDATOR = 'validator';

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
+53 −10
Original line number Diff line number Diff line
@@ -7,22 +7,65 @@

namespace Oscar\Entity;


use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;


class RecallDeclarationRepository extends EntityRepository
{
    /**
     * Liste des procédures de rappel pour les validateurs.
     *
     * @param int $personId
     * @param int|null $year
     * @param int|null $month
     * @return RecallDeclaration[]
     */
    public function getRecallValidationPerson(int $personId, ?int $year = null, ?int $month = null)
    {
        $qb = $this->createQueryBuilder('r')
            ->where('r.person = :person AND r.context = :context ')
            ->setParameters(
                [
                    'person' => $personId,
                    'context' => RecallDeclaration::CONTEXT_VALIDATOR,
                ]
            );

        if ($year) {
            $qb->andWhere('r.periodYear = :year')->setParameter('year', $year);
        }

        if ($month) {
            $qb->andWhere('r.periodMonth = :month')->setParameter('month', $month);
        }

        return $qb
            ->getQuery()
            ->getResult();
    }

    /**
     * Retourne la procédure de rappel pour un déclarant pour la période.
     *
     * @param int $personId
     * @param int $periodYear
     * @param int $periodMonth
     *
     * @return RecallDeclaration[]
     */
    public function getRecallDeclarationsPersonPeriod(int $personId, int $periodYear, int $periodMonth)
    {
        return $this->createQueryBuilder('r')
            ->where('r.person = :person AND r.periodYear = :periodYear AND r.periodMonth = :periodMonth')
            ->setParameters([
            ->where(
                'r.person = :person AND r.periodYear = :periodYear AND r.periodMonth = :periodMonth AND r.context = :context'
            )
            ->setParameters(
                [
                    'person' => $personId,
                    'periodYear' => $periodYear,
                    'periodMonth' => $periodMonth,
            ])
                    'context' => RecallDeclaration::CONTEXT_DECLARER,
                ]
            )
            ->getQuery()
            ->getResult();
    }
Loading