Loading module/Oscar/src/Oscar/Command/OscarTimesheetRecallsCommand.php 0 → 100644 +69 −0 Changes for module/Oscar/src/Oscar/Command/OscarTimesheetRecallsCommand.php: 69 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: bouvry * Date: 04/10/19 * Time: 11:49 */ namespace Oscar\Command; use Moment\Moment; use Oscar\Entity\Authentification; use Oscar\Entity\LogActivity; use Oscar\Entity\Person; use Oscar\Entity\RecallDeclaration; use Oscar\Entity\Role; use Oscar\Entity\WorkPackage; use Oscar\Entity\WorkPackagePerson; use Oscar\Service\ConnectorService; use Oscar\Service\OscarConfigurationService; use Oscar\Service\OscarUserContext; use Oscar\Service\PersonService; use Oscar\Service\TimesheetService; use Oscar\Utils\DateTimeUtils; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\Validator\Date; class OscarTimesheetRecallsCommand extends OscarCommandAbstract { protected static $defaultName = 'timesheets:recalls'; const OPT_DECLARER = "declarer"; const OPT_PERIOD = "period"; protected function configure() { $this ->setDescription("Afficher les relances") ; } protected function execute(InputInterface $input, OutputInterface $output) { $this->addOutputStyle($output); $recalls = $this->getTimesheetService()->getRecalls(); /** @var RecallDeclaration $recall */ foreach ($recalls as $recall) { echo "$recall\n"; } /// OPTIONS and PARAMETERS } /** * @return TimesheetService */ protected function getTimesheetService(){ return $this->getServicemanager()->get(TimesheetService::class); } } No newline at end of file module/Oscar/src/Oscar/Entity/RecallDeclaration.php +14 −3 Changes for module/Oscar/src/Oscar/Entity/RecallDeclaration.php: 14 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use Doctrine\ORM\Mapping as ORM; * Cette classe référence les rôles GLOBAUX sur l'application. * * @ORM\Entity * @ORM\Entity(repositoryClass="RecallDeclarationRepository") */ class RecallDeclaration { Loading Loading @@ -141,6 +142,7 @@ class RecallDeclaration return $this; } /** * @return \DateTime */ Loading Loading @@ -184,13 +186,22 @@ class RecallDeclaration } /** * @param string $history * @param string $historyLine * @return $this */ public function setHistory(string $history): self public function addHistory( string $historyLine ) :self { $this->history = $history; if( $this->history == null ){ $this->history = ""; } $this->history .= $historyLine."\n"; return $this; } public function __toString() { return sprintf('[%s] Envoyé le %s à %s pour la période %s-%s', $this->getId(), $this->getLastSend()->format('Y-m-d H:i:s'), $this->getPerson(), $this->getPeriodYear(), $this->getPeriodMonth()); } } No newline at end of file module/Oscar/src/Oscar/Entity/RecallDeclarationRepository.php +10 −2 Changes for module/Oscar/src/Oscar/Entity/RecallDeclarationRepository.php: 10 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -10,12 +10,20 @@ namespace Oscar\Entity; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NoResultException; use phpDocumentor\Reflection\Types\Integer; class RecallDeclarationRepository extends EntityRepository { 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([ 'person' => $personId, 'periodYear' => $periodYear, 'periodMonth' => $periodMonth, ]) ->getQuery() ->getResult(); } } No newline at end of file module/Oscar/src/Oscar/Service/TimesheetService.php +70 −6 Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 70 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Oscar\Entity\Organization; use Oscar\Entity\Person; use Oscar\Entity\ProjectGrantRepository; use Oscar\Entity\RecallDeclaration; use Oscar\Entity\RecallDeclarationRepository; use Oscar\Entity\Referent; use Oscar\Entity\TimeSheet; use Oscar\Entity\TimesheetCommentPeriod; Loading Loading @@ -2556,31 +2557,94 @@ class TimesheetService implements UseOscarUserContextService, UseOscarConfigurat ]; } public function recallProcess($declarerId, $period) public function getRecalls() { return $this->getRecallDeclarationRepository()->findAll(); } public function getRecallDeclarationRepository(): RecallDeclarationRepository { return $this->getEntityManager()->getRepository(RecallDeclaration::class); } public function recallProcess($declarerId, $period, $processDate = null) { // Récupération de la date de rappel référente if( $processDate == null ){ $processDate = new \DateTime(); } elseif (is_string($processDate)) { $processDate = new \DateTime($processDate); } elseif ( is_object($processDate) && get_class($processDate) == \DateTime::class ) { // ok } else { throw new OscarException("Format de date inattendu !"); } $declarer = $this->getPersonService()->getPersonById($declarerId); $result = $this->getPersonRecallDeclarationPeriod($declarerId, $period); $result['mailSend'] = false; // Vérification du dernier envois /** @var RecallDeclarationRepository $recallDeclarationRepository */ $recallDeclarationRepository = $this->getEntityManager()->getRepository(RecallDeclaration::class); $recallDeclarationRepository = $this->getRecallDeclarationRepository(); $periodInfos = DateTimeUtils::extractPeriodDatasFromString($period); $periodMonth = $periodInfos['month']; $periodYear = $periodInfos['year']; $recalls = $recallDeclarationRepository->getRecallDeclarationsPersonPeriod($declarerId, $periodYear, $periodMonth); if( count($recalls) == 0 ){ $result['needSend'] = true; $recallSend = new RecallDeclaration(); $this->getEntityManager()->persist($recallSend); $recallSend->setStartProcess($processDate); } elseif (count($recalls) == 1 ){ /** @var RecallDeclaration $recallSend */ $recallSend = $recalls[0]; $lastSend = $recallSend->getLastSend(); /** @var \DateInterval $interval */ $interval = $lastSend->diff($processDate); echo "JOURS : " . $interval->days . "\n"; die("TEST : Calcule de l'écart entre le dernier envoi et la date de processing"); } else { throw new OscarException("Doublon présent pour le système de contrôle des rappels pour $declarer"); } if ($result['needSend']) { $declarer = $this->getPersonService()->getPersonById($declarerId); $message = $this->getPersonService()->getMailingService()->newMessage("[OSCAR] Déclaration de temps $declarer", "CONTENU : " . $result['message']); $message->setTo($declarer->getEmail()); $message->setBody("Message : " . $result['message']); try { $this->getPersonService()->getMailingService()->send($message); $result['mailSend'] = true; // Enregistrement du rappel $recallSend->setContext('declarer') ->addHistory(sprintf("[%s] Envois d'un rappel", $processDate->format('Y-m-d'))) ->setLastSend(new \DateTime()) ->setPeriodMonth($periodMonth) ->setPeriodYear($periodYear) ->setPerson($declarer); $this->getEntityManager()->flush($recallSend); } catch (\Exception $e) { throw new OscarException("Un problème est survenu lors de la procédure de rappel pour $declarer pour la période $period"); } } return $result; } public function getPersonPeriods(Person $person, $period) { Loading Loading
module/Oscar/src/Oscar/Command/OscarTimesheetRecallsCommand.php 0 → 100644 +69 −0 Changes for module/Oscar/src/Oscar/Command/OscarTimesheetRecallsCommand.php: 69 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: bouvry * Date: 04/10/19 * Time: 11:49 */ namespace Oscar\Command; use Moment\Moment; use Oscar\Entity\Authentification; use Oscar\Entity\LogActivity; use Oscar\Entity\Person; use Oscar\Entity\RecallDeclaration; use Oscar\Entity\Role; use Oscar\Entity\WorkPackage; use Oscar\Entity\WorkPackagePerson; use Oscar\Service\ConnectorService; use Oscar\Service\OscarConfigurationService; use Oscar\Service\OscarUserContext; use Oscar\Service\PersonService; use Oscar\Service\TimesheetService; use Oscar\Utils\DateTimeUtils; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\Validator\Date; class OscarTimesheetRecallsCommand extends OscarCommandAbstract { protected static $defaultName = 'timesheets:recalls'; const OPT_DECLARER = "declarer"; const OPT_PERIOD = "period"; protected function configure() { $this ->setDescription("Afficher les relances") ; } protected function execute(InputInterface $input, OutputInterface $output) { $this->addOutputStyle($output); $recalls = $this->getTimesheetService()->getRecalls(); /** @var RecallDeclaration $recall */ foreach ($recalls as $recall) { echo "$recall\n"; } /// OPTIONS and PARAMETERS } /** * @return TimesheetService */ protected function getTimesheetService(){ return $this->getServicemanager()->get(TimesheetService::class); } } No newline at end of file
module/Oscar/src/Oscar/Entity/RecallDeclaration.php +14 −3 Changes for module/Oscar/src/Oscar/Entity/RecallDeclaration.php: 14 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use Doctrine\ORM\Mapping as ORM; * Cette classe référence les rôles GLOBAUX sur l'application. * * @ORM\Entity * @ORM\Entity(repositoryClass="RecallDeclarationRepository") */ class RecallDeclaration { Loading Loading @@ -141,6 +142,7 @@ class RecallDeclaration return $this; } /** * @return \DateTime */ Loading Loading @@ -184,13 +186,22 @@ class RecallDeclaration } /** * @param string $history * @param string $historyLine * @return $this */ public function setHistory(string $history): self public function addHistory( string $historyLine ) :self { $this->history = $history; if( $this->history == null ){ $this->history = ""; } $this->history .= $historyLine."\n"; return $this; } public function __toString() { return sprintf('[%s] Envoyé le %s à %s pour la période %s-%s', $this->getId(), $this->getLastSend()->format('Y-m-d H:i:s'), $this->getPerson(), $this->getPeriodYear(), $this->getPeriodMonth()); } } No newline at end of file
module/Oscar/src/Oscar/Entity/RecallDeclarationRepository.php +10 −2 Changes for module/Oscar/src/Oscar/Entity/RecallDeclarationRepository.php: 10 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -10,12 +10,20 @@ namespace Oscar\Entity; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NoResultException; use phpDocumentor\Reflection\Types\Integer; class RecallDeclarationRepository extends EntityRepository { 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([ 'person' => $personId, 'periodYear' => $periodYear, 'periodMonth' => $periodMonth, ]) ->getQuery() ->getResult(); } } No newline at end of file
module/Oscar/src/Oscar/Service/TimesheetService.php +70 −6 Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 70 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Oscar\Entity\Organization; use Oscar\Entity\Person; use Oscar\Entity\ProjectGrantRepository; use Oscar\Entity\RecallDeclaration; use Oscar\Entity\RecallDeclarationRepository; use Oscar\Entity\Referent; use Oscar\Entity\TimeSheet; use Oscar\Entity\TimesheetCommentPeriod; Loading Loading @@ -2556,31 +2557,94 @@ class TimesheetService implements UseOscarUserContextService, UseOscarConfigurat ]; } public function recallProcess($declarerId, $period) public function getRecalls() { return $this->getRecallDeclarationRepository()->findAll(); } public function getRecallDeclarationRepository(): RecallDeclarationRepository { return $this->getEntityManager()->getRepository(RecallDeclaration::class); } public function recallProcess($declarerId, $period, $processDate = null) { // Récupération de la date de rappel référente if( $processDate == null ){ $processDate = new \DateTime(); } elseif (is_string($processDate)) { $processDate = new \DateTime($processDate); } elseif ( is_object($processDate) && get_class($processDate) == \DateTime::class ) { // ok } else { throw new OscarException("Format de date inattendu !"); } $declarer = $this->getPersonService()->getPersonById($declarerId); $result = $this->getPersonRecallDeclarationPeriod($declarerId, $period); $result['mailSend'] = false; // Vérification du dernier envois /** @var RecallDeclarationRepository $recallDeclarationRepository */ $recallDeclarationRepository = $this->getEntityManager()->getRepository(RecallDeclaration::class); $recallDeclarationRepository = $this->getRecallDeclarationRepository(); $periodInfos = DateTimeUtils::extractPeriodDatasFromString($period); $periodMonth = $periodInfos['month']; $periodYear = $periodInfos['year']; $recalls = $recallDeclarationRepository->getRecallDeclarationsPersonPeriod($declarerId, $periodYear, $periodMonth); if( count($recalls) == 0 ){ $result['needSend'] = true; $recallSend = new RecallDeclaration(); $this->getEntityManager()->persist($recallSend); $recallSend->setStartProcess($processDate); } elseif (count($recalls) == 1 ){ /** @var RecallDeclaration $recallSend */ $recallSend = $recalls[0]; $lastSend = $recallSend->getLastSend(); /** @var \DateInterval $interval */ $interval = $lastSend->diff($processDate); echo "JOURS : " . $interval->days . "\n"; die("TEST : Calcule de l'écart entre le dernier envoi et la date de processing"); } else { throw new OscarException("Doublon présent pour le système de contrôle des rappels pour $declarer"); } if ($result['needSend']) { $declarer = $this->getPersonService()->getPersonById($declarerId); $message = $this->getPersonService()->getMailingService()->newMessage("[OSCAR] Déclaration de temps $declarer", "CONTENU : " . $result['message']); $message->setTo($declarer->getEmail()); $message->setBody("Message : " . $result['message']); try { $this->getPersonService()->getMailingService()->send($message); $result['mailSend'] = true; // Enregistrement du rappel $recallSend->setContext('declarer') ->addHistory(sprintf("[%s] Envois d'un rappel", $processDate->format('Y-m-d'))) ->setLastSend(new \DateTime()) ->setPeriodMonth($periodMonth) ->setPeriodYear($periodYear) ->setPerson($declarer); $this->getEntityManager()->flush($recallSend); } catch (\Exception $e) { throw new OscarException("Un problème est survenu lors de la procédure de rappel pour $declarer pour la période $period"); } } return $result; } public function getPersonPeriods(Person $person, $period) { Loading