Commit f1811e42 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Backup

parent 20577508
Loading
Loading
Loading
Loading
Loading
+26 −13
Changes for module/Oscar/src/Oscar/Command/OscarTimesheetDeclarerRecallCommand.php: 26 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract
    const OPT_FORCE         = "force";
    const OPT_DECLARER      = "declarer";
    const OPT_PERIOD        = "period";
    const OPT_PROCESSDATE        = "processdate";

    const ARG_ALL        = "all";

@@ -51,6 +52,7 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract
            ->addOption(self::OPT_FORCE, 'f', InputOption::VALUE_NONE, "Forcer le mode non-interactif")
            ->addOption(self::OPT_DECLARER, 'd', InputOption::VALUE_REQUIRED, "Identifiant du déclarant")
            ->addOption(self::OPT_PERIOD, 'p', InputOption::VALUE_OPTIONAL, "Période")
            ->addOption(self::OPT_PROCESSDATE, 'c', InputOption::VALUE_OPTIONAL, "Date de relance (par défaut date actuelle)")
            ->addArgument(self::ARG_ALL, InputArgument::OPTIONAL, "Déclencher pour tous les déclarants", false);
        ;
    }
@@ -66,6 +68,13 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract

        /// OPTIONS and PARAMETERS
        $declarerId = $input->getOption(self::OPT_DECLARER);
        $processDate = $input->getOption(self::OPT_PROCESSDATE);

        if( $processDate ){
            $processDate = new \DateTime($processDate);
        } else {
            $processDate = new \DateTime();
        }

        if( $all == false && $declarerId == null ){
            $io->writeln("Utiliser l'option --declarant=ID");
@@ -95,22 +104,23 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract
            /** @var Person $declarer */
            foreach ($declarants['persons'] as $personId=>$datas) {
                try {
                    $result = $this->recallDeclarer($personId, $declarerPeriod, $io);
                    $result = $this->recallDeclarer($personId, $declarerPeriod, $io, $processDate);
                } catch (\Exception $e) {
                    $io->warning($e->getMessage());
                }
            }
        } else {
            $result = $this->recallDeclarer($declarerId, $declarerPeriod, $io);
            $result = $this->recallDeclarer($declarerId, $declarerPeriod, $io, $processDate);
        }
    }

    protected function recallDeclarer($declarerId, $declarerPeriod, SymfonyStyle $io)
    protected function recallDeclarer($declarerId, $declarerPeriod, SymfonyStyle $io, $processDate = null)
    {
        /** @var Person $declarer */
        $declarer = $this->getPersonService()->getPersonById($declarerId);

        $result = $this->declarerPeriod($declarerId, $declarerPeriod);
        $result = $this->declarerPeriod($declarerId, $declarerPeriod, $processDate);
        if( $result ) {
            $io->title($result['person']);
            $io->writeln(sprintf("Message : <options=bold>%s</>", $result['message']));
            $io->writeln(sprintf("Mail ? <options=bold>%s</>", $result['needSend'] ? 'Oui' : 'Non'));
@@ -120,6 +130,10 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract
            $io->writeln(sprintf("Mail requis : <options=bold>%s</>", $result['mailRequired'] ? "Oui" : "Non"));
            $io->writeln(sprintf("Mail envoyé : <options=bold>%s</>", $result['mailSend'] ? "Oui" : "Non"));
            $io->writeln(sprintf("Status : <options=bold>%s</>", $result['status']));
        }
        else {

        }

    }

@@ -128,11 +142,7 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract
     */
    protected function getMailer()
    {
        static $mailer;
        if( $mailer === null ){
            $mailer = $this->getServicemanager()->get(MailingService::class);
        }
        return $mailer;
        return $this->getServicemanager()->get(MailingService::class);
    }

    /**
@@ -151,8 +161,11 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract

    //public function declarerRecall

    public function declarerPeriod( $declarerId, $period ){
        return $this->getTimesheetService()->recallProcess($declarerId, $period);
    public function declarerPeriod( $declarerId, $period, $processDate = null ){
        if( $processDate == null ){
            $processDate = new \DateTime();
        }
        return $this->getTimesheetService()->recallProcess($declarerId, $period, $processDate);
    }

    public function declarer( InputInterface $input, OutputInterface $output, $declarerId ){
@@ -181,9 +194,9 @@ class OscarTimesheetDeclarerRecallCommand extends OscarCommandAbstract
            $out = [];
            /** @var Person $declarer */
            foreach ($declarants['persons'] as $personId=>$datas) {
                $out[] = [$personId, $datas['displayname'], $datas['affectation'], count($datas['declarations'])];
                $out[] = [$personId, $datas['displayname'], $datas['login'], $datas['affectation'], count($datas['declarations'])];
            }
            $headers = ['ID', 'Déclarant', 'Affectation', 'Déclaration(s)'];
            $headers = ['ID', 'login', 'Déclarant', 'Affectation', 'Déclaration(s)'];
            $io->table($headers, $out);

            $io->comment("Entrez la commande '".self::getName()." --". self::OPT_DECLARER . "=<ID>' pour afficher les détails");
+16 −1
Changes for module/Oscar/src/Oscar/Command/OscarTimesheetRecallsCommand.php: 16 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -49,13 +49,28 @@ class OscarTimesheetRecallsCommand extends OscarCommandAbstract
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->addOutputStyle($output);
        $io = new SymfonyStyle($input, $output);

        $recalls = $this->getTimesheetService()->getRecalls();

        $headers = ["ID", "Date", "Depuis", "Déclarants", "Période"];
        $rows = [];

        $moment = new Moment();

        /** @var RecallDeclaration $recall */
        foreach ($recalls as $recall) {
            echo "$recall\n";
            $moment = new Moment($recall->getLastSend()->getTimestamp());
            $row = [
                $recall->getId(),
                $recall->getLastSend()->format('Y-m-d H:i:s'),
                $moment->fromNow()->getRelative(),
                $recall->getPerson()->__toString(),
                sprintf("%s %s", $recall->getPeriodMonth(), $recall->getPeriodYear())
            ];
            $rows[] = $row;
        }
        $io->table($headers, $rows);
        /// OPTIONS and PARAMETERS

    }
+1 −0
Changes for module/Oscar/src/Oscar/Entity/Person.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -810,6 +810,7 @@ class Person implements ResourceInterface
            'firstName'             => $this->getFirstname(),
            'lastName'              => $this->getLastname(),
            'displayname'           => $this->getDisplayName(),
            'login'                 => $this->getLadapLogin(),
            'label'                 => $this->getDisplayName(),
            'text'                  => $this->getDisplayName(),
            'email'                 => $this->getEmail(),
+40 −8
Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 40 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -2583,7 +2583,6 @@ class TimesheetService implements UseOscarUserContextService, UseOscarConfigurat
            throw new OscarException("Format de date inattendu !");
        }


        $declarer = $this->getPersonService()->getPersonById($declarerId);
        $result = $this->getPersonRecallDeclarationPeriod($declarerId, $period);
        $result['mailSend'] = false;
@@ -2595,35 +2594,68 @@ class TimesheetService implements UseOscarUserContextService, UseOscarConfigurat
        $periodMonth = $periodInfos['month'];
        $periodYear = $periodInfos['year'];

        // Configuration de la relance
        $declarerFirstDay = $this->getOscarConfigurationService()->getDeclarersRelanceJour1();
        $declarerSecondDay = $this->getOscarConfigurationService()->getDeclarersRelanceJour2();
        $declarerFirstMsg = $this->getOscarConfigurationService()->getDeclarersRelance1();
        $declarerSecondMsg = $this->getOscarConfigurationService()->getDeclarersRelance2();

        $recalls = $recallDeclarationRepository->getRecallDeclarationsPersonPeriod($declarerId, $periodYear, $periodMonth);

        // Premier rappel
        if( count($recalls) == 0 ){
            // On test si le jour d'envois est valide (Valeur de J1)
            $processDay = (int)$processDate->format('d');

            if( $declarerFirstDay <= $processDay ){
                $result['needSend'] = true;
                $recallSend = new RecallDeclaration();
                $this->getEntityManager()->persist($recallSend);
                $recallSend->setStartProcess($processDate);
            } else {
                return null;
            }
        }
        elseif (count($recalls) == 1 ){
            /** @var RecallDeclaration $recallSend */
            $recallSend = $recalls[0];

            // Date d'envois
            $lastSend = $recallSend->getLastSend();
            $daySend = (int) $lastSend->format('d');
            echo "Dernier envoi jour : " . $daySend . "\n";

            /** @var \DateInterval $interval */
            $interval = $lastSend->diff($processDate);
            $nextSendDay = $declarerSecondDay + $daySend;
            echo "Prochain envoi : $nextSendDay\n";

            echo "JOURS : " . $interval->days . "\n";

            /** @var \DateInterval $interval */
            $interval = $lastSend->diff($processDate);
            $effectifDaysSinceLastSend = $interval->days;
            echo "JOURS écoulés depuis le dernier envois : " . $effectifDaysSinceLastSend . "\n";

            die("TEST : Calcule de l'écart entre le dernier envoi et la date de processing");
            if( $effectifDaysSinceLastSend >= $declarerSecondDay ){
                echo "Envoi de la relance";
                $result['needSend'] = true;
            } else {
                return null;
            }
        } else {
            throw new OscarException("Doublon présent pour le système de contrôle des rappels pour $declarer");
        }


        if ($result['needSend']) {
            $message = $this->getPersonService()->getMailingService()->newMessage("[OSCAR] Déclaration de temps $declarer", "CONTENU : " . $result['message']);
            $body = $declarerSecondMsg;

            // Replace
            $find       = [ "{PERSON}",     "{PERIOD}"];
            $replace    = [ "$declarer",    $periodInfos['periodLabel'] ];
            $body       = str_ireplace($find, $replace, $body);

            $message = $this->getPersonService()->getMailingService()->newMessage("[OSCAR] Déclaration de temps $declarer pour " . $periodInfos['periodLabel']);
            $message->setTo($declarer->getEmail());
            $message->setBody("Message : " . $result['message']);
            $message->setBody($body);

            try {
                $this->getPersonService()->getMailingService()->send($message);
@@ -2632,7 +2664,7 @@ class TimesheetService implements UseOscarUserContextService, UseOscarConfigurat
                // Enregistrement du rappel
                $recallSend->setContext('declarer')
                    ->addHistory(sprintf("[%s] Envois d'un rappel", $processDate->format('Y-m-d')))
                    ->setLastSend(new \DateTime())
                    ->setLastSend($processDate)
                    ->setPeriodMonth($periodMonth)
                    ->setPeriodYear($periodYear)
                    ->setPerson($declarer);